From 69127a3a8db1599f4c8b3f69b38c8b8631b3a052 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Sun, 5 Jul 2015 22:09:29 +0000 Subject: [PATCH] Add several generic integer pairs printing functions 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 | 10 ++++++++++ util.c | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/defs.h b/defs.h index 35a86e00..ede39b4e 100644 --- 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 98c624b0..ed2da67d 100644 --- 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 * -- 2.40.0