Add several generic integer pairs printing functions
authorDmitry V. Levin <ldv@altlinux.org>
Sun, 5 Jul 2015 22:09:29 +0000 (22:09 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Thu, 9 Jul 2015 01:41:51 +0000 (01:41 +0000)
Add functions to fetch and print pairs of integer types.
Note that these printers do not attempt to fetch data
in case of exiting(tcp) && syserror(tcp).

printnum_* printers will follow as soon as all callers are made ready
for this change.

* defs.h (printpair_int, printpair_long, printpair_int64): New
prototypes.
* util.c (DEF_PRINTPAIR): New macro.
(printpair_int, printpair_long, printpair_int64): New functions.

defs.h
util.c

diff --git a/defs.h b/defs.h
index 35a86e00d56a2b6a704b0047d6b4eec6ca23f68c..ede39b4e6e413b599a95b28718df9dfc9467254c 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -541,6 +541,16 @@ extern void printnum_long(struct tcb *, long, const char *)
 extern void printnum_int64(struct tcb *, long, const char *)
        ATTRIBUTE_FORMAT((printf, 3, 0));
 #endif
+extern void printpair_int(struct tcb *, long, const char *)
+       ATTRIBUTE_FORMAT((printf, 3, 0));
+extern void printpair_long(struct tcb *, long, const char *)
+       ATTRIBUTE_FORMAT((printf, 3, 0));
+#if SIZEOF_LONG == 8
+# define printpair_int64 printpair_long
+#else
+extern void printpair_int64(struct tcb *, long, const char *)
+       ATTRIBUTE_FORMAT((printf, 3, 0));
+#endif
 extern void printpath(struct tcb *, long);
 extern void printpathn(struct tcb *, long, unsigned int);
 #define TIMESPEC_TEXT_BUFSIZE (sizeof(long)*3 * 2 + sizeof("{%u, %u}"))
diff --git a/util.c b/util.c
index 98c624b0bf40e0935adfb93f78ca76feeaace2fa..ed2da67d7336d6b16bcdc7cdb077660aab5eb737 100644 (file)
--- a/util.c
+++ b/util.c
@@ -400,11 +400,33 @@ printnum_ ## name(struct tcb *tcp, const long addr, const char *fmt)      \
        }                                                               \
 }
 
+#define DEF_PRINTPAIR(name, type) \
+void                                                                   \
+printpair_ ## name(struct tcb *tcp, const long addr, const char *fmt)  \
+{                                                                      \
+       type pair[2];                                                   \
+       if (!addr)                                                      \
+               tprints("NULL");                                        \
+       else if ((exiting(tcp) && syserror(tcp)) ||                     \
+                umove(tcp, addr, &pair) < 0)                           \
+               tprintf("%#lx", addr);                                  \
+       else {                                                          \
+               tprints("[");                                           \
+               tprintf(fmt, pair[0]);                                  \
+               tprints(", ");                                          \
+               tprintf(fmt, pair[1]);                                  \
+               tprints("]");                                           \
+       }                                                               \
+}
+
 DEF_PRINTNUM(long, long)
+DEF_PRINTPAIR(long, long)
 DEF_PRINTNUM(int, int)
+DEF_PRINTPAIR(int, int)
 DEF_PRINTNUM(short, short)
 #if SIZEOF_LONG != 8
 DEF_PRINTNUM(int64, uint64_t)
+DEF_PRINTPAIR(int64, uint64_t)
 #endif
 
 const char *