From 484326dbd8f8e02983e37498b4b5fa990d16b536 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Sat, 11 Jun 2016 01:28:21 +0000 Subject: [PATCH] Consistently use printaddr for printing addresses * bjm.c (SYS_FUNC(init_module)): Use printaddr. * clone.c (SYS_FUNC(clone)): Likewise. * evdev.c (ff_effect_ioctl): Likewise. * mtd.c (decode_mtd_oob_buf): Likewise. * net.c (SYS_FUNC(sendmmsg), SYS_FUNC(recvmmsg), SYS_FUNC(getsockopt)): Likewise. * print_sigevent.c (print_sigevent): Likewise. * printsiginfo.c (printsigval, print_si_info): Likewise. * signal.c (decode_new_sigaction): Likewise. * sysmips.c (SYS_FUNC(sysmips)): Likewise. * util.c (printpathn, printstr, umoven_or_printaddr): Likewise. * v4l2.c (print_v4l2_buffer, print_v4l2_framebuffer, umoven_or_printaddr_ignore_syserror): Likewise. * tests/net-icmp_filter.c (main): Update. Based on patch by Eugene Syromyatnikov . --- bjm.c | 3 ++- clone.c | 21 +++++++++++++++------ evdev.c | 8 ++++---- mtd.c | 5 +++-- net.c | 12 +++++++----- print_sigevent.c | 10 ++++++---- printsiginfo.c | 14 ++++++++------ signal.c | 10 ++++++---- sysmips.c | 5 +++-- tests/net-icmp_filter.c | 2 +- util.c | 14 +++++--------- v4l2.c | 18 ++++++++---------- 12 files changed, 68 insertions(+), 54 deletions(-) diff --git a/bjm.c b/bjm.c index 7ba14982..7a72809a 100644 --- a/bjm.c +++ b/bjm.c @@ -52,7 +52,8 @@ SYS_FUNC(delete_module) SYS_FUNC(init_module) { - tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]); + printaddr(tcp->u_arg[0]); + tprintf(", %lu, ", tcp->u_arg[1]); printstr(tcp, tcp->u_arg[2], -1); return RVAL_DECODED; diff --git a/clone.c b/clone.c index 2fad0b8d..99d0da7f 100644 --- a/clone.c +++ b/clone.c @@ -82,7 +82,9 @@ SYS_FUNC(clone) if (exiting(tcp)) { const char *sep = "|"; unsigned long flags = tcp->u_arg[ARG_FLAGS]; - tprintf("child_stack=%#lx, ", tcp->u_arg[ARG_STACK]); + tprints("child_stack="); + printaddr(tcp->u_arg[ARG_STACK]); + tprints(", "); #ifdef ARG_STACKSIZE if (ARG_STACKSIZE != -1) tprintf("stack_size=%#lx, ", @@ -96,8 +98,10 @@ SYS_FUNC(clone) if ((flags & (CLONE_PARENT_SETTID|CLONE_CHILD_SETTID |CLONE_CHILD_CLEARTID|CLONE_SETTLS)) == 0) return 0; - if (flags & CLONE_PARENT_SETTID) - tprintf(", parent_tidptr=%#lx", tcp->u_arg[ARG_PTID]); + if (flags & CLONE_PARENT_SETTID) { + tprints(", parent_tidptr="); + printaddr(tcp->u_arg[ARG_PTID]); + } if (flags & CLONE_SETTLS) { #if defined I386 || defined X86_64 || defined X32 # ifndef I386 @@ -111,10 +115,15 @@ SYS_FUNC(clone) else # endif #endif /* I386 || X86_64 || X32 */ - tprintf(", tls=%#lx", tcp->u_arg[ARG_TLS]); + { + tprints(", tls="); + printaddr(tcp->u_arg[ARG_TLS]); + } + } + if (flags & (CLONE_CHILD_SETTID|CLONE_CHILD_CLEARTID)) { + tprints(", child_tidptr="); + printaddr(tcp->u_arg[ARG_CTID]); } - if (flags & (CLONE_CHILD_SETTID|CLONE_CHILD_CLEARTID)) - tprintf(", child_tidptr=%#lx", tcp->u_arg[ARG_CTID]); } /* TODO on syscall entry: * We can clear CLONE_PTRACE here since it is an ancient hack diff --git a/evdev.c b/evdev.c index 2e436d6e..b7b64024 100644 --- a/evdev.c +++ b/evdev.c @@ -133,10 +133,10 @@ ff_effect_ioctl(struct tcb *tcp, long arg) ffe.u.periodic.offset, ffe.u.periodic.phase); decode_envelope(&ffe.u.periodic.envelope); - tprintf(", custom_len=%u" - ", custom_data=%#lx}", - ffe.u.periodic.custom_len, - (unsigned long) ffe.u.periodic.custom_data); + tprintf(", custom_len=%u, custom_data=", + ffe.u.periodic.custom_len); + printaddr((unsigned long) ffe.u.periodic.custom_data); + tprints("}"); break; case FF_RUMBLE: tprintf(", rumble={strong_magnitude=%" PRIu16 diff --git a/mtd.c b/mtd.c index 52714ae3..4442b1cc 100644 --- a/mtd.c +++ b/mtd.c @@ -83,8 +83,9 @@ decode_mtd_oob_buf(struct tcb *tcp, const long addr) if (umove_or_printaddr(tcp, addr, &mbuf)) return; - tprintf("{start=%#x, length=%#x, ptr=%#lx}", - mbuf.start, mbuf.length, (unsigned long) mbuf.ptr); + tprintf("{start=%#x, length=%#x, ptr=", mbuf.start, mbuf.length); + printaddr((unsigned long) mbuf.ptr); + tprints("}"); } static void diff --git a/net.c b/net.c index 3349758e..8cc97da1 100644 --- a/net.c +++ b/net.c @@ -930,8 +930,8 @@ SYS_FUNC(sendmmsg) printfd(tcp, tcp->u_arg[0]); tprints(", "); if (!verbose(tcp)) { - tprintf("%#lx, %u, ", - tcp->u_arg[1], (unsigned int) tcp->u_arg[2]); + printaddr(tcp->u_arg[1]); + tprintf(", %u, ", (unsigned int) tcp->u_arg[2]); printflags(msg_flags, tcp->u_arg[3], "MSG_???"); } } else { @@ -1023,7 +1023,8 @@ SYS_FUNC(recvmmsg) */ tcp->auxstr = sprint_timespec(tcp, tcp->u_arg[4]); } else { - tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]); + printaddr(tcp->u_arg[1]); + tprintf(", %u, ", (unsigned int) tcp->u_arg[2]); printflags(msg_flags, tcp->u_arg[3], "MSG_???"); tprints(", "); print_timespec(tcp, tcp->u_arg[4]); @@ -1335,8 +1336,9 @@ SYS_FUNC(getsockopt) int len; if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) { - tprintf("%#lx, %#lx", - tcp->u_arg[3], tcp->u_arg[4]); + printaddr(tcp->u_arg[3]); + tprints(", "); + printaddr(tcp->u_arg[4]); } else { print_getsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3], len); diff --git a/print_sigevent.c b/print_sigevent.c index 1c2b1748..caf1fdfe 100644 --- a/print_sigevent.c +++ b/print_sigevent.c @@ -43,10 +43,12 @@ MPERS_PRINTER_DECL(void, print_sigevent, struct tcb *tcp, const long addr) return; tprints("{"); - if (sev.sigev_value.sival_ptr) - tprintf("sigev_value={int=%d, ptr=%#lx}, ", - sev.sigev_value.sival_int, - (unsigned long) sev.sigev_value.sival_ptr); + if (sev.sigev_value.sival_ptr) { + tprintf("sigev_value={int=%d, ptr=", + sev.sigev_value.sival_int); + printaddr((unsigned long) sev.sigev_value.sival_ptr); + tprints("}, "); + } tprints("sigev_signo="); switch (sev.sigev_notify) { diff --git a/printsiginfo.c b/printsiginfo.c index 98755b28..699460f3 100644 --- a/printsiginfo.c +++ b/printsiginfo.c @@ -76,8 +76,9 @@ printsigsource(const siginfo_t *sip) static void printsigval(const siginfo_t *sip) { - tprintf(", si_value={int=%d, ptr=%#lx}", - sip->si_int, (unsigned long) sip->si_ptr); + tprintf(", si_value={int=%d, ptr=", sip->si_int); + printaddr((unsigned long) sip->si_ptr); + tprints("}"); } static void @@ -176,8 +177,8 @@ print_si_info(const siginfo_t *sip) break; case SIGILL: case SIGFPE: case SIGSEGV: case SIGBUS: - tprintf(", si_addr=%#lx", - (unsigned long) sip->si_addr); + tprints(", si_addr="); + printaddr((unsigned long) sip->si_addr); break; case SIGPOLL: switch (sip->si_code) { @@ -189,8 +190,9 @@ print_si_info(const siginfo_t *sip) break; #ifdef HAVE_SIGINFO_T_SI_SYSCALL case SIGSYS: - tprintf(", si_call_addr=%#lx, si_syscall=__NR_%s, si_arch=", - (unsigned long) sip->si_call_addr, + tprints(", si_call_addr="); + printaddr((unsigned long) sip->si_call_addr); + tprintf(", si_syscall=__NR_%s, si_arch=", syscall_name((unsigned) sip->si_syscall)); printxval(audit_arch, sip->si_arch, "AUDIT_ARCH_???"); break; diff --git a/signal.c b/signal.c index f0890505..8d36675a 100644 --- a/signal.c +++ b/signal.c @@ -559,14 +559,16 @@ decode_new_sigaction(struct tcb *tcp, long addr) * be manipulated by strace. In order to prevent the * compiler from generating code to manipulate * __sa_handler we cast the function pointers to long. */ + tprints("{"); if ((long)sa.__sa_handler == (long)SIG_ERR) - tprints("{SIG_ERR, "); + tprints("SIG_ERR"); else if ((long)sa.__sa_handler == (long)SIG_DFL) - tprints("{SIG_DFL, "); + tprints("SIG_DFL"); else if ((long)sa.__sa_handler == (long)SIG_IGN) - tprints("{SIG_IGN, "); + tprints("SIG_IGN"); else - tprintf("{%#lx, ", (long) sa.__sa_handler); + printaddr((unsigned long) sa.__sa_handler); + tprints(", "); /* * Sigset size is in tcp->u_arg[4] (SPARC) * or in tcp->u_arg[3] (all other), diff --git a/sysmips.c b/sysmips.c index bc3cb8d5..47acfec7 100644 --- a/sysmips.c +++ b/sysmips.c @@ -64,10 +64,11 @@ SYS_FUNC(sysmips) return RVAL_DECODED; } case MIPS_ATOMIC_SET: - tprintf("%#lx, 0x%lx", tcp->u_arg[1], tcp->u_arg[2]); + printaddr(tcp->u_arg[1]); + tprintf(", %#lx", tcp->u_arg[2]); return RVAL_DECODED; case MIPS_FIXADE: - tprintf("0x%lx", tcp->u_arg[1]); + tprintf("%#lx", tcp->u_arg[1]); return RVAL_DECODED; } diff --git a/tests/net-icmp_filter.c b/tests/net-icmp_filter.c index d3f956d3..f3f99f14 100644 --- a/tests/net-icmp_filter.c +++ b/tests/net-icmp_filter.c @@ -36,7 +36,7 @@ int main(void) { getsockopt(-1, SOL_RAW, ICMP_FILTER, 0, 0); - printf("getsockopt(-1, SOL_RAW, ICMP_FILTER, 0, 0) = -1 %s (%m)\n", + printf("getsockopt(-1, SOL_RAW, ICMP_FILTER, NULL, NULL) = -1 %s (%m)\n", errno2name()); setsockopt(-1, SOL_RAW, ICMP_FILTER, NULL, 0); diff --git a/util.c b/util.c index 9c8c9781..de881f41 100644 --- a/util.c +++ b/util.c @@ -761,7 +761,7 @@ printpathn(struct tcb *tcp, long addr, unsigned int n) /* Fetch one byte more to find out whether path length > n. */ nul_seen = umovestr(tcp, addr, n + 1, path); if (nul_seen < 0) - tprintf("%#lx", addr); + printaddr(addr); else { path[n++] = '\0'; print_quoted_string(path, n, QUOTE_0_TERMINATED); @@ -812,7 +812,7 @@ printstr(struct tcb *tcp, long addr, long len) * because string_quote may look one byte ahead. */ if (umovestr(tcp, addr, size + 1, str) < 0) { - tprintf("%#lx", addr); + printaddr(addr); return; } style = QUOTE_0_TERMINATED; @@ -821,7 +821,7 @@ printstr(struct tcb *tcp, long addr, long len) if (size > (unsigned long)len) size = (unsigned long)len; if (umoven(tcp, addr, size, str) < 0) { - tprintf("%#lx", addr); + printaddr(addr); return; } style = 0; @@ -1131,13 +1131,9 @@ int umoven_or_printaddr(struct tcb *tcp, const long addr, const unsigned int len, void *our_addr) { - if (!addr) { - tprints("NULL"); - return -1; - } - if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)) || + if (!addr || !verbose(tcp) || (exiting(tcp) && syserror(tcp)) || umoven(tcp, addr, len, our_addr) < 0) { - tprintf("%#lx", addr); + printaddr(addr); return -1; } return 0; diff --git a/v4l2.c b/v4l2.c index c0cda21c..e80de55c 100644 --- a/v4l2.c +++ b/v4l2.c @@ -359,8 +359,8 @@ print_v4l2_buffer(struct tcb *tcp, const unsigned int code, const long arg) if (b.memory == V4L2_MEMORY_MMAP) { tprintf(", m.offset=%#x", b.m.offset); } else if (b.memory == V4L2_MEMORY_USERPTR) { - tprintf(", m.userptr=%#lx", - (unsigned long) b.m.userptr); + tprints(", m.userptr="); + printaddr((unsigned long) b.m.userptr); } tprintf(", length=%u, bytesused=%u, flags=", @@ -384,8 +384,10 @@ print_v4l2_framebuffer(struct tcb *tcp, const long arg) tprints(", "); if (!umove_or_printaddr(tcp, arg, &b)) { - tprintf("{capability=%#x, flags=%#x, base=%#lx}", - b.capability, b.flags, (unsigned long) b.base); + tprintf("{capability=%#x, flags=%#x, base=", + b.capability, b.flags); + printaddr((unsigned long) b.base); + tprints("}"); } return RVAL_DECODED | 1; @@ -676,12 +678,8 @@ static int umoven_or_printaddr_ignore_syserror(struct tcb *tcp, const long addr, const unsigned int len, void *our_addr) { - if (!addr) { - tprints("NULL"); - return -1; - } - if (umoven(tcp, addr, len, our_addr) < 0) { - tprintf("%#lx", addr); + if (!addr || umoven(tcp, addr, len, our_addr) < 0) { + printaddr(addr); return -1; } return 0; -- 2.40.0