diff options
author | Masatake YAMATO <yamato@redhat.com> | 2021-09-09 22:43:36 +0900 |
---|---|---|
committer | Dmitry V. Levin <ldv@strace.io> | 2021-11-14 08:00:00 +0000 |
commit | cb1650559273daa41fef08ab91da35860d1cf26f (patch) | |
tree | 07a2114bb9721d065bf505cd7dc8caf9ea879c4b /src/pidns.c | |
parent | 8cebeebcb587d557f1a870c4c544d308fb675362 (diff) | |
download | strace-cb1650559273daa41fef08ab91da35860d1cf26f.tar.gz |
Extend -Y option to decode PIDs in arguments and return values
This change extends -Y/--decode-pids=comm option. In addition to the
information printed before this change, command names would be printed
also for PIDs appeared in syscall arguments and return values.
For example:
getppid() = 3781395<strace>
getpid() = 3781398<a.out>
pidfd_open(1<systemd>, 0) = 3<pid:1<systemd>>
NOTE: The code printing the pid in printclockname() is not changed in
this commit. CLOCKID_TO_FD macro used in printclockname() was removed
from the kernel, so printclockname() may change drastically in the
near future.
* src/defs.h (maybe_printpid_comm): New function declaration.
* src/strace.c (maybe_printpid_comm): New function printing
command name for the given PID.
* src/pidns.c (printpid_translation): Call `maybe_printpid_comm'.
* tests/strace--decode-pids-comm.c (do_default_action): Update expected
output.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Co-authored-by: Dmitry V. Levin <ldv@strace.io>
Diffstat (limited to 'src/pidns.c')
-rw-r--r-- | src/pidns.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/pidns.c b/src/pidns.c index eda87aad9..9b8504f7c 100644 --- a/src/pidns.c +++ b/src/pidns.c @@ -527,12 +527,18 @@ get_proc_pid(int pid) static void printpid_translation(struct tcb *tcp, int pid, enum pid_type type) { - if (!(pid_decoding & PID_DECODING_NS_TRANSLATION)) - return; - - int strace_pid = translate_pid(tcp, pid, type, NULL); - if (strace_pid && strace_pid != pid) - tprintf_comment("%d in strace's PID NS", strace_pid); + if ((pid_decoding & (PID_DECODING_COMM|PID_DECODING_NS_TRANSLATION))) { + int strace_pid = translate_pid(tcp, pid, type, NULL); + if (strace_pid) { + if ((pid_decoding & PID_DECODING_COMM) && + (type == PT_TID || type == PT_TGID)) + maybe_printpid_comm(strace_pid); + if ((pid_decoding & PID_DECODING_NS_TRANSLATION) && + strace_pid != pid) + tprintf_comment("%d in strace's PID NS", + strace_pid); + } + } } void |