From: Eugene Syromyatnikov Date: Sun, 10 Feb 2019 23:45:37 +0000 (+0100) Subject: ptrace_restart: use xlat-based approach for printing ptrace requests X-Git-Tag: v5.0~65 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4bdfb2f2f58e90ddde8144c740882f393b341026;p=strace ptrace_restart: use xlat-based approach for printing ptrace requests * defs.h (ptrace_cmds): New prototype. * strace.c (ptrace_op_str): New function. (ptrace_restart): Use it. --- diff --git a/defs.h b/defs.h index ca1c39cc..53f30f26 100644 --- a/defs.h +++ b/defs.h @@ -329,6 +329,7 @@ extern const struct xlat nl_netfilter_msg_types[]; extern const struct xlat nl_route_types[]; extern const struct xlat open_access_modes[]; extern const struct xlat open_mode_flags[]; +extern const struct xlat ptrace_cmds[]; extern const struct xlat resource_flags[]; extern const struct xlat routing_scopes[]; extern const struct xlat routing_table_ids[]; diff --git a/strace.c b/strace.c index 246eb0c8..e083cc3c 100644 --- a/strace.c +++ b/strace.c @@ -339,6 +339,18 @@ ptrace_attach_or_seize(int pid) return ptrace_attach_cmd = "PTRACE_INTERRUPT", r; } +static const char * +ptrace_op_str(unsigned int op) +{ + const char *str = xlookup(ptrace_cmds, op); + if (str) + return str; + + static char buf[sizeof(op) * 3]; + xsprintf(buf, "%u", op); + return buf; +} + /* * Used when we want to unblock stopped traced process. * Should be only used with PTRACE_CONT, PTRACE_DETACH and PTRACE_SYSCALL. @@ -350,7 +362,6 @@ static int ptrace_restart(const unsigned int op, struct tcb *const tcp, unsigned int sig) { int err; - const char *msg; errno = 0; ptrace(op, tcp->pid, 0L, (unsigned long) sig); @@ -358,20 +369,6 @@ ptrace_restart(const unsigned int op, struct tcb *const tcp, unsigned int sig) if (!err) return 0; - switch (op) { - case PTRACE_CONT: - msg = "CONT"; - break; - case PTRACE_DETACH: - msg = "DETACH"; - break; - case PTRACE_LISTEN: - msg = "LISTEN"; - break; - default: - msg = "SYSCALL"; - } - /* * Why curcol != 0? Otherwise sometimes we get this: * @@ -383,13 +380,14 @@ ptrace_restart(const unsigned int op, struct tcb *const tcp, unsigned int sig) */ if (current_tcp && current_tcp->curcol != 0) { tprintf(" \n", - tcp->pid, msg, strerror(err)); + tcp->pid, ptrace_op_str(op), strerror(err)); line_ended(); } if (err == ESRCH) return 0; errno = err; - perror_msg("ptrace(PTRACE_%s,pid:%d,sig:%u)", msg, tcp->pid, sig); + perror_msg("ptrace(%s,pid:%d,sig:%u)", + ptrace_op_str(op), tcp->pid, sig); return -1; }