[PATCH 1/3] util: change type of struct xlat.val to uint64_t

Jeff Mahoney jeffm at suse.com
Thu Mar 31 01:19:25 UTC 2016


Some ioctls have flags fields that are 64-bit.  A 32-bit val means
these flags will never be matched or printed.

* util.c:
  (xlookup) Use uint64_t for val.
  (xlat_search) Likewise.
  (printxvals) Likewise.
  (addflags) Use uint64_t for val and print with PRIx64 .
  (printflags) Likewise.
  (sprintflags) Likewise.
* defs.h: (struct xlat) Use uint_64 for val.
---
 defs.h | 14 +++++++-------
 util.c | 28 ++++++++++++++--------------
 2 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/defs.h b/defs.h
index f095ff6..0c60f1b 100644
--- a/defs.h
+++ b/defs.h
@@ -361,7 +361,7 @@ typedef uint8_t qualbits_t;
 #define filtered(tcp)	((tcp)->flags & TCB_FILTERED)
 
 struct xlat {
-	unsigned int val;
+	uint64_t val;
 	const char *str;
 };
 #define XLAT(x) { x, #x }
@@ -526,8 +526,8 @@ extern void pathtrace_select(const char *);
 extern int pathtrace_match(struct tcb *);
 extern int getfdpath(struct tcb *, int, char *, unsigned);
 
-extern const char *xlookup(const struct xlat *, const unsigned int);
-extern const char *xlat_search(const struct xlat *, const size_t, const unsigned int);
+extern const char *xlookup(const struct xlat *, const uint64_t);
+extern const char *xlat_search(const struct xlat *, const size_t, const uint64_t);
 
 extern unsigned long get_pagesize(void);
 extern int string_to_uint(const char *str);
@@ -554,15 +554,15 @@ extern int printllval(struct tcb *, const char *, int)
 	ATTRIBUTE_FORMAT((printf, 2, 0));
 
 extern void printaddr(long);
-extern void printxvals(const unsigned int, const char *, const struct xlat *, ...);
+extern void printxvals(const uint64_t, const char *, const struct xlat *, ...);
 #define printxval(xlat, val, dflt) printxvals(val, dflt, xlat, NULL)
 extern int printargs(struct tcb *);
 extern int printargs_u(struct tcb *);
 extern int printargs_d(struct tcb *);
 
-extern void addflags(const struct xlat *, int);
-extern int printflags(const struct xlat *, int, const char *);
-extern const char *sprintflags(const char *, const struct xlat *, int);
+extern void addflags(const struct xlat *, uint64_t);
+extern int printflags(const struct xlat *, uint64_t, const char *);
+extern const char *sprintflags(const char *, const struct xlat *, uint64_t);
 extern const char *sprintmode(int);
 extern const char *sprinttime(time_t);
 extern void dumpiov_in_msghdr(struct tcb *, long, unsigned long);
diff --git a/util.c b/util.c
index 1e5aecc..c601db1 100644
--- a/util.c
+++ b/util.c
@@ -121,7 +121,7 @@ tv_mul(struct timeval *tv, const struct timeval *a, int n)
 }
 
 const char *
-xlookup(const struct xlat *xlat, const unsigned int val)
+xlookup(const struct xlat *xlat, const uint64_t val)
 {
 	for (; xlat->str != NULL; xlat++)
 		if (xlat->val == val)
@@ -132,16 +132,16 @@ xlookup(const struct xlat *xlat, const unsigned int val)
 static int
 xlat_bsearch_compare(const void *a, const void *b)
 {
-	const unsigned int val1 = (const unsigned long) a;
-	const unsigned int val2 = ((const struct xlat *) b)->val;
+	const uint64_t val1 = (const uint64_t) a;
+	const uint64_t val2 = ((const struct xlat *) b)->val;
 	return (val1 > val2) ? 1 : (val1 < val2) ? -1 : 0;
 }
 
 const char *
-xlat_search(const struct xlat *xlat, const size_t nmemb, const unsigned int val)
+xlat_search(const struct xlat *xlat, const size_t nmemb, const uint64_t val)
 {
 	const struct xlat *e =
-		bsearch((const void*) (const unsigned long) val,
+		bsearch((const void*) val,
 			xlat, nmemb, sizeof(*xlat), xlat_bsearch_compare);
 
 	return e ? e->str : NULL;
@@ -208,7 +208,7 @@ next_set_bit(const void *bit_array, unsigned cur_bit, unsigned size_bits)
  * Print entry in struct xlat table, if there.
  */
 void
-printxvals(const unsigned int val, const char *dflt, const struct xlat *xlat, ...)
+printxvals(const uint64_t val, const char *dflt, const struct xlat *xlat, ...)
 {
 	va_list args;
 
@@ -223,7 +223,7 @@ printxvals(const unsigned int val, const char *dflt, const struct xlat *xlat, ..
 		}
 	}
 	/* No hits -- print raw # instead. */
-	tprintf("%#x /* %s */", val, dflt);
+	tprintf("%#" PRIx64 " /* %s */", val, dflt);
 
 	va_end(args);
 }
@@ -303,7 +303,7 @@ printllval(struct tcb *tcp, const char *format, int arg_no)
  * return # of flags printed.
  */
 void
-addflags(const struct xlat *xlat, int flags)
+addflags(const struct xlat *xlat, uint64_t flags)
 {
 	for (; xlat->str; xlat++) {
 		if (xlat->val && (flags & xlat->val) == xlat->val) {
@@ -312,7 +312,7 @@ addflags(const struct xlat *xlat, int flags)
 		}
 	}
 	if (flags) {
-		tprintf("|%#x", flags);
+		tprintf("|%#" PRIx64, flags);
 	}
 }
 
@@ -322,7 +322,7 @@ addflags(const struct xlat *xlat, int flags)
  * Return static string.
  */
 const char *
-sprintflags(const char *prefix, const struct xlat *xlat, int flags)
+sprintflags(const char *prefix, const struct xlat *xlat, uint64_t flags)
 {
 	static char outstr[1024];
 	char *outptr;
@@ -349,14 +349,14 @@ sprintflags(const char *prefix, const struct xlat *xlat, int flags)
 	if (flags) {
 		if (found)
 			*outptr++ = '|';
-		outptr += sprintf(outptr, "%#x", flags);
+		outptr += sprintf(outptr, "%#" PRIx64, flags);
 	}
 
 	return outstr;
 }
 
 int
-printflags(const struct xlat *xlat, int flags, const char *dflt)
+printflags(const struct xlat *xlat, uint64_t flags, const char *dflt)
 {
 	int n;
 	const char *sep;
@@ -378,12 +378,12 @@ printflags(const struct xlat *xlat, int flags, const char *dflt)
 
 	if (n) {
 		if (flags) {
-			tprintf("%s%#x", sep, flags);
+			tprintf("%s%#" PRIx64, sep, flags);
 			n++;
 		}
 	} else {
 		if (flags) {
-			tprintf("%#x", flags);
+			tprintf("%#" PRIx64, flags);
 			if (dflt)
 				tprintf(" /* %s */", dflt);
 		} else {
-- 
2.7.1





More information about the Strace-devel mailing list