99 lines
2.6 KiB
Diff
99 lines
2.6 KiB
Diff
|
|
From 4bdfb2f2f58e90ddde8144c740882f393b341026 Mon Sep 17 00:00:00 2001
|
||
|
|
From: Eugene Syromyatnikov <evgsyr@gmail.com>
|
||
|
|
Date: Mon, 11 Feb 2019 00:45:37 +0100
|
||
|
|
Subject: [PATCH 226/293] 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.
|
||
|
|
---
|
||
|
|
defs.h | 1 +
|
||
|
|
strace.c | 32 +++++++++++++++-----------------
|
||
|
|
2 files changed, 16 insertions(+), 17 deletions(-)
|
||
|
|
|
||
|
|
diff --git a/defs.h b/defs.h
|
||
|
|
index ca1c39c..53f30f2 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 246eb0c..e083cc3 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(" <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;
|
||
|
|
}
|
||
|
|
|
||
|
|
--
|
||
|
|
1.7.12.4
|
||
|
|
|