From b9fcbe61129109e1c576497adfb74fd7e61d53a0 Mon Sep 17 00:00:00 2001 From: Eugene Syromyatnikov Date: Sat, 10 Mar 2018 05:12:02 +0100 Subject: [PATCH] Introduce XLAT_STYLE_DEFAULT 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) : 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 | 23 +++++++++++++++++------ strace.c | 3 +++ xlat.c | 18 ++++++++++++++++++ 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/defs.h b/defs.h index 569825ff..edface65 100644 --- 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 diff --git a/strace.c b/strace.c index 97a43b05..f50b6256 100644 --- 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 647786b6..8cddb227 100644 --- a/xlat.c +++ b/xlat.c @@ -33,6 +33,15 @@ #include "xstring.h" #include +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); -- 2.40.0