From a938b441d687add1f3f306e9a045edec8f9b478c Mon Sep 17 00:00:00 2001 From: Eugene Syromyatnikov Date: Sun, 27 Nov 2016 18:04:58 +0300 Subject: [PATCH] util: provide information whether xlat value has been found This is necessary for the upcoming change in the output format of the val3 argument of the FUTEX_WAKE_OP futex command. * defs.h (printxvals, printxval_searchn): Change return type to int. (printxval64, printxval, printxval_long): Likewise. Forward the value returned by printxvals call. * util.c (printxvals, printxval_searchn): Change return type to int, return 1 if xlat value has been found, 0 otherwise. --- defs.h | 16 ++++++++-------- util.c | 42 +++++++++++++++++++++++++++++++++--------- 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/defs.h b/defs.h index 3e0c0745..3a0c0636 100644 --- a/defs.h +++ b/defs.h @@ -559,9 +559,9 @@ extern int printllval(struct tcb *, const char *, int) ATTRIBUTE_FORMAT((printf, 2, 0)); extern void printaddr_ull(unsigned long long); -extern void printxvals(const uint64_t, const char *, const struct xlat *, ...) +extern int printxvals(const uint64_t, const char *, const struct xlat *, ...) ATTRIBUTE_SENTINEL; -extern void printxval_searchn(const struct xlat *xlat, size_t xlat_size, +extern int printxval_searchn(const struct xlat *xlat, size_t xlat_size, uint64_t val, const char *dflt); #define printxval_search(xlat__, val__, dflt__) \ printxval_searchn(xlat__, ARRAY_SIZE(xlat__), val__, dflt__) @@ -709,22 +709,22 @@ printflags_long(const struct xlat *x, unsigned long flags, const char *dflt) return printflags64(x, flags, dflt); } -static inline void +static inline int printxval64(const struct xlat *x, const uint64_t val, const char *dflt) { - printxvals(val, dflt, x, NULL); + return printxvals(val, dflt, x, NULL); } -static inline void +static inline int printxval(const struct xlat *x, const unsigned int val, const char *dflt) { - printxvals(val, dflt, x, NULL); + return printxvals(val, dflt, x, NULL); } -static inline void +static inline int printxval_long(const struct xlat *x, const unsigned long val, const char *dflt) { - printxvals(val, dflt, x, NULL); + return printxvals(val, dflt, x, NULL); } #ifdef ALPHA diff --git a/util.c b/util.c index 57557f39..3fa3de31 100644 --- a/util.c +++ b/util.c @@ -219,10 +219,18 @@ next_set_bit(const void *bit_array, unsigned cur_bit, unsigned size_bits) pos++; } } -/* + +/** * Print entry in struct xlat table, if there. + * + * @param val Value to search a literal representation for. + * @param dflt String (abbreviated in comment syntax) which should be emitted + * if no appropriate xlat value has been found. + * @param xlat (And the following arguments) Pointers to arrays of xlat values. + * The last argument should be NULL. + * @return 1 if appropriate xlat value has been found, 0 otherwise. */ -void +int printxvals(const uint64_t val, const char *dflt, const struct xlat *xlat, ...) { va_list args; @@ -234,7 +242,7 @@ printxvals(const uint64_t val, const char *dflt, const struct xlat *xlat, ...) if (str) { tprints(str); va_end(args); - return; + return 1; } } /* No hits -- print raw # instead. */ @@ -243,12 +251,25 @@ printxvals(const uint64_t val, const char *dflt, const struct xlat *xlat, ...) tprintf(" /* %s */", dflt); va_end(args); + + return 0; } -/* +/** * Print entry in sorted struct xlat table, if it is there. + * + * @param xlat Pointer to an array of xlat values (not terminated with + * XLAT_END). + * @param xlat_size Number of xlat elements present in array (usually ARRAY_SIZE + * if array is declared in the unit's scope and not + * terminated with XLAT_END). + * @param val Value to search literal representation for. + * @param dflt String (abbreviated in comment syntax) which should be + * emitted if no appropriate xlat value has been found. + * @return 1 if appropriate xlat value has been found, 0 + * otherwise. */ -void +int printxval_searchn(const struct xlat *xlat, size_t xlat_size, uint64_t val, const char *dflt) { @@ -256,11 +277,14 @@ printxval_searchn(const struct xlat *xlat, size_t xlat_size, uint64_t val, if (s) { tprints(s); - } else { - tprintf("%#" PRIx64, val); - if (dflt) - tprintf(" /* %s */", dflt); + return 1; } + + tprintf("%#" PRIx64, val); + if (dflt) + tprintf(" /* %s */", dflt); + + return 0; } /* -- 2.40.0