]> granicus.if.org Git - strace/commitdiff
Introduce XLAT_STYLE_DEFAULT
authorEugene Syromyatnikov <evgsyr@gmail.com>
Sat, 10 Mar 2018 04:12:02 +0000 (05:12 +0100)
committerEugene Syromyatnikov <evgsyr@gmail.com>
Thu, 12 Apr 2018 22:25:13 +0000 (00:25 +0200)
This will be needed later, with the introduction of user-configurable
xlat style setting (stored in xlat_verbosity variable).

* defs.h (XLAT_STYLE_VERBOSITY_MASK): New macro constant.
(enum xlat_style) <XLAT_STYLE_DEFAULT>: New enumeration entity.
(xlat_verbosity): New external declaration.
(printxvals, printxval_searchn, printxval_search_ex, sprintxval,
sprintflags, printflags64): Use XLAT_STYLE_DEFAULT instead of
XLAT_STYLE_ABBREV.
* strace.c (xlat_verbosity): New variable.
* xlat.c (get_xlat_style): New function.
(printxvals_ex, sprintxval_ex, printxval_searchn_ex, sprintflags_ex,
printflags_ex): Use it.

defs.h
strace.c
xlat.c

diff --git a/defs.h b/defs.h
index 569825ffd3f404a87c2f9ccc1c25a48bf7968ad9..edface65f7f4276361c775b4cd18053e7686c6bd 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -584,7 +584,16 @@ extern int printllval(struct tcb *, const char *, int)
 extern void printaddr64(uint64_t addr);
 extern void printaddr(kernel_ulong_t addr);
 
+#define XLAT_STYLE_VERBOSITY_MASK (XLAT_STYLE_RAW | XLAT_STYLE_ABBREV)
+
 enum xlat_style {
+       /**
+        * Special value that is used for passing to *print{xval,flags}*_ex
+        * routines that indicates that no overriding of user-supplied xlat
+        * verbosity/formatting configuration is intended.
+        */
+       XLAT_STYLE_DEFAULT = 0,
+
        /** Print xlat value as is without xlat processing */
        XLAT_STYLE_RAW     = 1 << 0,
        /**
@@ -597,17 +606,19 @@ enum xlat_style {
        XLAT_STYLE_VERBOSE = XLAT_STYLE_RAW | XLAT_STYLE_ABBREV,
 };
 
+extern enum xlat_style xlat_verbosity;
+
 extern int printxvals_ex(uint64_t val, const char *dflt,
                         enum xlat_style style, const struct xlat *, ...)
        ATTRIBUTE_SENTINEL;
 #define printxvals(val_, dflt_, ...) \
-       printxvals_ex((val_), (dflt_), XLAT_STYLE_ABBREV, __VA_ARGS__)
+       printxvals_ex((val_), (dflt_), XLAT_STYLE_DEFAULT, __VA_ARGS__)
 extern int printxval_searchn_ex(const struct xlat *xlat, size_t xlat_size,
                                uint64_t val, const char *dflt,
                                enum xlat_style style);
 #define printxval_searchn(xlat_, xlat_size_, val_, dflt_) \
        printxval_searchn_ex((xlat_), (xlat_size_), (val_), (dflt_), \
-                            XLAT_STYLE_ABBREV)
+                            XLAT_STYLE_DEFAULT)
 /**
  * Wrapper around printxval_searchn that passes ARRAY_SIZE - 1
  * as the array size, as all arrays are XLAT_END-terminated and
@@ -617,13 +628,13 @@ extern int printxval_searchn_ex(const struct xlat *xlat, size_t xlat_size,
        printxval_searchn(xlat__, ARRAY_SIZE(xlat__) - 1, val__, dflt__)
 #define printxval_search_ex(xlat__, val__, dflt__) \
        printxval_searchn_ex((xlat__), ARRAY_SIZE(xlat__) - 1, (val__), \
-                            (dflt__), XLAT_STYLE_ABBREV)
+                            (dflt__), XLAT_STYLE_DEFAULT)
 extern int sprintxval_ex(char *buf, size_t size, const struct xlat *xlat,
                         unsigned int val, const char *dflt,
                         enum xlat_style style);
 #define sprintxval(buf_, size_, xlat_, val_, dflt_) \
        sprintxval_ex((buf_), (size_), (xlat_), (val_), (dflt_), \
-                     XLAT_STYLE_ABBREV)
+                     XLAT_STYLE_DEFAULT)
 
 extern int printargs(struct tcb *);
 extern int printargs_u(struct tcb *);
@@ -635,7 +646,7 @@ extern int printflags_ex(uint64_t flags, const char *dflt,
 extern const char *sprintflags_ex(const char *prefix, const struct xlat *xlat,
                                  uint64_t flags, enum xlat_style style);
 #define sprintflags(prefix_, xlat_, flags_) \
-       sprintflags_ex((prefix_), (xlat_), (flags_), XLAT_STYLE_ABBREV)
+       sprintflags_ex((prefix_), (xlat_), (flags_), XLAT_STYLE_DEFAULT)
 extern const char *sprinttime(long long sec);
 extern const char *sprinttime_nsec(long long sec, unsigned long long nsec);
 extern const char *sprinttime_usec(long long sec, unsigned long long usec);
@@ -812,7 +823,7 @@ printstr(struct tcb *tcp, kernel_ulong_t addr)
 static inline int
 printflags64(const struct xlat *x, uint64_t flags, const char *dflt)
 {
-       return printflags_ex(flags, dflt, XLAT_STYLE_ABBREV, x, NULL);
+       return printflags_ex(flags, dflt, XLAT_STYLE_DEFAULT, x, NULL);
 }
 
 static inline int
index 97a43b0540a9098f36312605f39451ec0ea4e83f..f50b62568087bce393cade9ed1a5542f20cee32b 100644 (file)
--- a/strace.c
+++ b/strace.c
@@ -147,6 +147,9 @@ unsigned int max_strlen = DEFAULT_STRLEN;
 static int acolumn = DEFAULT_ACOLUMN;
 static char *acolumn_spaces;
 
+/* Default output style for xlat entities */
+enum xlat_style xlat_verbosity = XLAT_STYLE_ABBREV;
+
 static const char *outfname;
 /* If -ff, points to stderr. Else, it's our common output log */
 static FILE *shared_log;
diff --git a/xlat.c b/xlat.c
index 647786b6a48a4872c211c1e6a5733753e68e7f1d..8cddb227a585daf16b44c539b2a8c595b4fc54ef 100644 (file)
--- a/xlat.c
+++ b/xlat.c
 #include "xstring.h"
 #include <stdarg.h>
 
+static inline enum xlat_style
+get_xlat_style(enum xlat_style style)
+{
+       if ((style & XLAT_STYLE_VERBOSITY_MASK) == XLAT_STYLE_DEFAULT)
+               return style | xlat_verbosity;
+
+       return style;
+}
+
 const char *
 xlookup(const struct xlat *xlat, const uint64_t val)
 {
@@ -75,6 +84,8 @@ int
 printxvals_ex(const uint64_t val, const char *dflt, enum xlat_style style,
              const struct xlat *xlat, ...)
 {
+       style = get_xlat_style(style);
+
        if (style == XLAT_STYLE_RAW) {
                tprintf("%#" PRIx64, val);
                return 0;
@@ -112,6 +123,8 @@ sprintxval_ex(char *const buf, const size_t size, const struct xlat *const x,
              const unsigned int val, const char *const dflt,
              enum xlat_style style)
 {
+       style = get_xlat_style(style);
+
        if (style == XLAT_STYLE_RAW)
                return xsnprintf(buf, size, "%#x", val);
 
@@ -148,6 +161,8 @@ int
 printxval_searchn_ex(const struct xlat *xlat, size_t xlat_size, uint64_t val,
                     const char *dflt, enum xlat_style style)
 {
+       style = get_xlat_style(style);
+
        if (style == XLAT_STYLE_RAW) {
                tprintf("%#" PRIx64, val);
                return 0;
@@ -202,6 +217,7 @@ sprintflags_ex(const char *prefix, const struct xlat *xlat, uint64_t flags,
        int found = 0;
 
        outptr = stpcpy(outstr, prefix);
+       style = get_xlat_style(style);
 
        if (style == XLAT_STYLE_RAW) {
                if (!flags)
@@ -283,6 +299,8 @@ int
 printflags_ex(uint64_t flags, const char *dflt, enum xlat_style style,
              const struct xlat *xlat, ...)
 {
+       style = get_xlat_style(style);
+
        if (style == XLAT_STYLE_RAW) {
                if (flags || dflt) {
                        tprintf("%#" PRIx64, flags);