From 67559ad260fd31c823615f650f5e131818acf20f Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 13 Mar 2012 12:05:27 +0100 Subject: [PATCH] Less ugly debug display of ptrace events * strace.c (trace): Less ugly debug display of ptrace events. Signed-off-by: Denys Vlasenko --- strace.c | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/strace.c b/strace.c index 4129a8a0..4fdf723e 100644 --- a/strace.c +++ b/strace.c @@ -1816,24 +1816,7 @@ trace(void) event = ((unsigned)status >> 16); if (debug) { char buf[sizeof("WIFEXITED,exitcode=%u") + sizeof(int)*3 /*paranoia:*/ + 16]; - if (event != 0) { - static const char *const event_names[] = { - [PTRACE_EVENT_CLONE] = "CLONE", - [PTRACE_EVENT_FORK] = "FORK", - [PTRACE_EVENT_VFORK] = "VFORK", - [PTRACE_EVENT_VFORK_DONE] = "VFORK_DONE", - [PTRACE_EVENT_EXEC] = "EXEC", - [PTRACE_EVENT_EXIT] = "EXIT", - }; - const char *e; - if (event < ARRAY_SIZE(event_names)) - e = event_names[event]; - else { - sprintf(buf, "?? (%u)", event); - e = buf; - } - fprintf(stderr, " PTRACE_EVENT_%s", e); - } + char evbuf[sizeof(",PTRACE_EVENT_?? (%u)") + sizeof(int)*3 /*paranoia:*/ + 16]; strcpy(buf, "???"); if (WIFSIGNALED(status)) #ifdef WCOREDUMP @@ -1852,7 +1835,26 @@ trace(void) if (WIFCONTINUED(status)) strcpy(buf, "WIFCONTINUED"); #endif - fprintf(stderr, " [wait(0x%04x) = %u] %s\n", status, pid, buf); + evbuf[0] = '\0'; + if (event != 0) { + static const char *const event_names[] = { + [PTRACE_EVENT_CLONE] = "CLONE", + [PTRACE_EVENT_FORK] = "FORK", + [PTRACE_EVENT_VFORK] = "VFORK", + [PTRACE_EVENT_VFORK_DONE] = "VFORK_DONE", + [PTRACE_EVENT_EXEC] = "EXEC", + [PTRACE_EVENT_EXIT] = "EXIT", + }; + const char *e; + if (event < ARRAY_SIZE(event_names)) + e = event_names[event]; + else { + sprintf(buf, "?? (%u)", event); + e = buf; + } + sprintf(evbuf, ",PTRACE_EVENT_%s", e); + } + fprintf(stderr, " [wait(0x%04x) = %u] %s%s\n", status, pid, buf, evbuf); } /* Look up 'pid' in our table. */