]> granicus.if.org Git - strace/commitdiff
util: provide information whether xlat value has been found
authorEugene Syromyatnikov <evgsyr@gmail.com>
Sun, 27 Nov 2016 15:04:58 +0000 (18:04 +0300)
committerDmitry V. Levin <ldv@altlinux.org>
Tue, 29 Nov 2016 00:23:13 +0000 (00:23 +0000)
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
util.c

diff --git a/defs.h b/defs.h
index 3e0c0745a7e4186aa75a02604b9fbbc163d31879..3a0c0636900f99c62583b68a6882df2f305559f6 100644 (file)
--- 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 57557f3963d32e99a155a5a42cfcdd5129cc88fe..3fa3de31ceecd89b46eaeeeca04ab89160b3e176 100644 (file)
--- 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;
 }
 
 /*