]> granicus.if.org Git - strace/commitdiff
ptrace_restart: use xlat-based approach for printing ptrace requests
authorEugene Syromyatnikov <evgsyr@gmail.com>
Sun, 10 Feb 2019 23:45:37 +0000 (00:45 +0100)
committerDmitry V. Levin <ldv@altlinux.org>
Mon, 11 Feb 2019 10:49:50 +0000 (10:49 +0000)
* defs.h (ptrace_cmds): New prototype.
* strace.c (ptrace_op_str): New function.
(ptrace_restart): Use it.

defs.h
strace.c

diff --git a/defs.h b/defs.h
index ca1c39cc057ef50d25c6941f22e4056590a77f62..53f30f26bc1d15e0bfd43271c0237ffd40264a3a 100644 (file)
--- 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[];
index 246eb0c8c0d4302b8aef37bd3ce0e45fb773f64a..e083cc3c27ac2c2dc203b4eb0093224921203650 100644 (file)
--- 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(" <Cannot restart pid %d with ptrace(%s): %s>\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;
 }