[PATCH 2/7] Use printpid in decoders
Ákos Uzonyi
uzonyi.akos at gmail.com
Sun Jul 12 19:46:31 UTC 2020
* getpid.c: New file.
* Makefile.am (libstrace_a_SOURCES): Add getpid.c.
* linux/dummy.h (sys_getpid, sys_getppid, sys_gettid,
sys_setpgid, sys_setpgrp): Remove.
* util.c (printfd_pid_tracee_ns): Implement using translate_pid.
* defs.h (printnum_pid): New function definition.
* util.c: (printnum_pid): New function.
* print_fields.h (PRINT_FIELD_TID): New macro.
(PRINT_FIELD_TGID): Likewise.
(PRINT_FIELD_PGID): Likewise.
(PRINT_FIELD_SID): Likewise.
* affinity.c: Print PIDs with printpid.
* block.c: Likewise.
* bpf.c: Likewise.
* capability.c: Likewise.
* clone.c: Likewise.
* fcntl.c: Likewise.
* get_robust_list.c: Likewise.
* ioprio.c: Likewise.
* kcmp.c: Likewise.
* msghdr.c: Likewise.
* net.c: Likewise.
* netlink.c: Likewise.
* numa.c: Likewise.
* pidfd_open.c: Likewise.
* printsiginfo.c: Likewise.
* process.c: Likewise.
* process_vm.c: Likewise.
* resource.c: Likewise.
* sched.c: Likewise.
* signal.c: Likewise.
* sockaddr.c: Likewise.
* wait.c: Likewise.
* kcmp.c (SYS_FUNC(kcmp)): Fix KCMP_FILE pid arguments.
* tests/kcmp.c (printpidfd): Print path if VERBOSE_FD.
(main): Use our real pid if real fds are used.
* tests/bpf.c (BPF_TASK_FD_QUERY_checks): Use smaller PIDs.
* tests/ioctl_block.c (main): Print PID as signed integer.
* pidfd_send_signal.c (main): Likewise.
---
Makefile.am | 1 +
affinity.c | 6 +++--
block.c | 2 +-
bpf.c | 2 +-
capability.c | 4 +++-
clone.c | 14 ++++++------
defs.h | 4 ++++
fcntl.c | 16 +++++++++-----
get_robust_list.c | 3 ++-
getpid.c | 46 +++++++++++++++++++++++++++++++++++++++
ioprio.c | 26 ++++++++++++++++++----
kcmp.c | 7 ++++--
linux/dummy.h | 8 +------
msghdr.c | 2 +-
net.c | 2 +-
netlink.c | 5 +++--
numa.c | 6 +++--
pidfd_open.c | 2 +-
print_fields.h | 24 ++++++++++++++++++++
printsiginfo.c | 5 +++++
process.c | 3 ++-
process_vm.c | 6 +++--
resource.c | 27 ++++++++++++++++++++---
sched.c | 25 +++++++++++++--------
signal.c | 25 ++++++++++++++++-----
sockaddr.c | 5 +++++
tests/bpf.c | 8 +++----
tests/ioctl_block.c | 2 +-
tests/kcmp.c | 25 ++++++++++++++++++---
tests/pidfd_send_signal.c | 4 ++--
util.c | 20 ++++++++++++-----
wait.c | 35 ++++++++++++++++++++++++-----
32 files changed, 289 insertions(+), 81 deletions(-)
create mode 100644 getpid.c
diff --git a/Makefile.am b/Makefile.am
index aa9a8d78..64c3d7de 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -136,6 +136,7 @@ libstrace_a_SOURCES = \
getcpu.c \
getcwd.c \
getpagesize.c \
+ getpid.c \
getrandom.c \
hdio.c \
hostname.c \
diff --git a/affinity.c b/affinity.c
index eb3158b7..f9893adb 100644
--- a/affinity.c
+++ b/affinity.c
@@ -82,7 +82,8 @@ SYS_FUNC(sched_setaffinity)
const int pid = tcp->u_arg[0];
const unsigned int len = tcp->u_arg[1];
- tprintf("%d, %u, ", pid, len);
+ printpid(tcp, pid, PT_TGID);
+ tprintf(", %u, ", len);
print_affinitylist(tcp, tcp->u_arg[2], len);
return RVAL_DECODED;
@@ -94,7 +95,8 @@ SYS_FUNC(sched_getaffinity)
const unsigned int len = tcp->u_arg[1];
if (entering(tcp)) {
- tprintf("%d, %u, ", pid, len);
+ printpid(tcp, pid, PT_TGID);
+ tprintf(", %u, ", len);
} else {
print_affinitylist(tcp, tcp->u_arg[2], tcp->u_rval);
}
diff --git a/block.c b/block.c
index 893269d0..231fa56b 100644
--- a/block.c
+++ b/block.c
@@ -179,7 +179,7 @@ MPERS_PRINTER_DECL(int, block_ioctl, struct tcb *const tcp,
PRINT_FIELD_U(", ", buts, buf_nr);
PRINT_FIELD_U(", ", buts, start_lba);
PRINT_FIELD_U(", ", buts, end_lba);
- PRINT_FIELD_U(", ", buts, pid);
+ PRINT_FIELD_TGID(", ", buts, pid, tcp);
return 0;
} else {
struct_blk_user_trace_setup buts;
diff --git a/bpf.c b/bpf.c
index 469f809a..8aa02ad0 100644
--- a/bpf.c
+++ b/bpf.c
@@ -927,7 +927,7 @@ BEGIN_BPF_CMD_DECODER(BPF_TASK_FD_QUERY)
if (entering(tcp)) {
set_tcb_priv_ulong(tcp, attr.buf_len);
- PRINT_FIELD_U("{task_fd_query={", attr, pid);
+ PRINT_FIELD_TGID("{task_fd_query={", attr, pid, tcp);
PRINT_FIELD_FD(", ", attr, fd, tcp);
PRINT_FIELD_U(", ", attr, flags);
PRINT_FIELD_U(", ", attr, buf_len);
diff --git a/capability.c b/capability.c
index 0e763ee1..f5a447fd 100644
--- a/capability.c
+++ b/capability.c
@@ -70,7 +70,9 @@ print_cap_header(struct tcb *const tcp, const kernel_ulong_t addr,
tprints("{version=");
printxval(cap_version, h->version,
"_LINUX_CAPABILITY_VERSION_???");
- tprintf(", pid=%d}", h->pid);
+ tprintf(", pid=");
+ printpid(tcp, h->pid, PT_TGID);
+ tprintf("}");
}
static void
diff --git a/clone.c b/clone.c
index 487c5c23..45f24065 100644
--- a/clone.c
+++ b/clone.c
@@ -114,14 +114,14 @@ SYS_FUNC(clone)
*/
if ((flags & (CLONE_PARENT_SETTID|CLONE_PIDFD|CLONE_CHILD_SETTID
|CLONE_CHILD_CLEARTID|CLONE_SETTLS)) == 0)
- return RVAL_DECODED;
+ return RVAL_DECODED | RVAL_TID;
} else {
if (flags & (CLONE_PARENT_SETTID|CLONE_PIDFD)) {
kernel_ulong_t addr = tcp->u_arg[ARG_PTID];
tprints(", parent_tid=");
if (flags & CLONE_PARENT_SETTID)
- printnum_int(tcp, addr, "%u");
+ printnum_pid(tcp, addr, PT_TID);
else
printnum_fd(tcp, addr);
}
@@ -134,7 +134,7 @@ SYS_FUNC(clone)
printaddr(tcp->u_arg[ARG_CTID]);
}
}
- return 0;
+ return RVAL_TID;
}
@@ -229,7 +229,7 @@ SYS_FUNC(clone3)
if ((arg.flags & (CLONE_PIDFD | CLONE_PARENT_SETTID)) ||
(size > fetch_size))
- return 0;
+ return RVAL_TID;
goto out;
}
@@ -256,7 +256,7 @@ SYS_FUNC(clone3)
if (arg.flags & CLONE_PARENT_SETTID) {
tprintf("%sparent_tid=", pfx);
- printnum_int(tcp, arg.parent_tid, "%d"); /* TID */
+ printnum_pid(tcp, arg.parent_tid, PT_TID);
pfx = ", ";
}
@@ -279,7 +279,7 @@ SYS_FUNC(clone3)
out:
tprintf(", %" PRI_klu, size);
- return RVAL_DECODED;
+ return RVAL_DECODED | RVAL_TID;
}
@@ -300,5 +300,5 @@ SYS_FUNC(unshare)
SYS_FUNC(fork)
{
- return RVAL_DECODED;
+ return RVAL_DECODED | RVAL_TGID;
}
diff --git a/defs.h b/defs.h
index c765169d..3362ef1f 100644
--- a/defs.h
+++ b/defs.h
@@ -1083,6 +1083,7 @@ printfd(struct tcb *tcp, int fd)
*/
extern void printfd_pid_tracee_ns(struct tcb *tcp, pid_t pid, int fd);
extern void printpid(struct tcb *tcp, int pid, enum pid_type type);
+extern void printpid_translation(struct tcb *tcp, int pid, enum pid_type type);
extern void print_sockaddr(const void *sa, int len);
extern bool
print_inet_addr(int af, const void *addr, unsigned int len, const char *var_name);
@@ -1532,6 +1533,9 @@ DECL_PRINTNUM_ADDR(int64);
extern bool
printnum_fd(struct tcb *, kernel_ulong_t addr);
+extern bool
+printnum_pid(struct tcb *const tcp, const kernel_ulong_t addr, enum pid_type type);
+
static inline bool
printnum_slong(struct tcb *tcp, kernel_ulong_t addr)
{
diff --git a/fcntl.c b/fcntl.c
index 0b4221ce..cc0b00ec 100644
--- a/fcntl.c
+++ b/fcntl.c
@@ -20,7 +20,7 @@
#include "xlat/notifyflags.h"
static void
-print_struct_flock64(const struct_kernel_flock64 *fl, const int getlk)
+print_struct_flock64(struct tcb *const tcp, const struct_kernel_flock64 *fl, const int getlk)
{
tprints("{l_type=");
printxval(lockfcmds, (unsigned short) fl->l_type, "F_???");
@@ -28,8 +28,10 @@ print_struct_flock64(const struct_kernel_flock64 *fl, const int getlk)
printxval(whence_codes, (unsigned short) fl->l_whence, "SEEK_???");
tprintf(", l_start=%" PRId64 ", l_len=%" PRId64,
(int64_t) fl->l_start, (int64_t) fl->l_len);
- if (getlk)
- tprintf(", l_pid=%lu", (unsigned long) fl->l_pid);
+ if (getlk) {
+ tprintf(", l_pid=");
+ printpid(tcp, (unsigned long) fl->l_pid, PT_TGID);
+ }
tprints("}");
}
@@ -39,7 +41,7 @@ printflock64(struct tcb *const tcp, const kernel_ulong_t addr, const int getlk)
struct_kernel_flock64 fl;
if (fetch_struct_flock64(tcp, addr, &fl))
- print_struct_flock64(&fl, getlk);
+ print_struct_flock64(tcp, &fl, getlk);
}
static void
@@ -48,7 +50,7 @@ printflock(struct tcb *const tcp, const kernel_ulong_t addr, const int getlk)
struct_kernel_flock64 fl;
if (fetch_struct_flock(tcp, addr, &fl))
- print_struct_flock64(&fl, getlk);
+ print_struct_flock64(tcp, &fl, getlk);
}
static void
@@ -61,7 +63,9 @@ print_f_owner_ex(struct tcb *const tcp, const kernel_ulong_t addr)
tprints("{type=");
printxval(f_owner_types, owner.type, "F_OWNER_???");
- tprintf(", pid=%d}", owner.pid);
+ tprintf(", pid=");
+ printpid(tcp, owner.pid, PT_TGID);
+ tprintf("}");
}
static int
diff --git a/get_robust_list.c b/get_robust_list.c
index b5aebaff..8c1b377c 100644
--- a/get_robust_list.c
+++ b/get_robust_list.c
@@ -10,7 +10,8 @@
SYS_FUNC(get_robust_list)
{
if (entering(tcp)) {
- tprintf("%d, ", (int) tcp->u_arg[0]);
+ printpid(tcp, (int) tcp->u_arg[0], PT_TID);
+ tprintf(", ");
} else {
printnum_ptr(tcp, tcp->u_arg[1]);
tprints(", ");
diff --git a/getpid.c b/getpid.c
new file mode 100644
index 00000000..5e9a1a29
--- /dev/null
+++ b/getpid.c
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2020 Ákos Uzonyi <uzonyi.akos at gmail.com>
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+#include "defs.h"
+
+SYS_FUNC(getpid)
+{
+ return RVAL_DECODED | RVAL_TGID;
+}
+
+SYS_FUNC(gettid)
+{
+ return RVAL_DECODED | RVAL_TID;
+}
+
+SYS_FUNC(getpgrp)
+{
+ return RVAL_DECODED | RVAL_PGID;
+}
+
+SYS_FUNC(getpgid)
+{
+ printpid(tcp, tcp->u_arg[0], PT_TGID);
+
+ return RVAL_DECODED | RVAL_PGID;
+}
+
+SYS_FUNC(getsid)
+{
+ printpid(tcp, tcp->u_arg[0], PT_TGID);
+
+ return RVAL_DECODED | RVAL_SID;
+}
+
+SYS_FUNC(setpgid)
+{
+ printpid(tcp, tcp->u_arg[0], PT_TGID);
+ tprints(", ");
+ printpid(tcp, tcp->u_arg[1], PT_PGID);
+
+ return RVAL_DECODED;
+}
diff --git a/ioprio.c b/ioprio.c
index 873c8ce5..f41bb6b9 100644
--- a/ioprio.c
+++ b/ioprio.c
@@ -49,13 +49,30 @@ print_ioprio(unsigned int ioprio)
? tprints_comment : tprints)(str);
}
+static void
+ioprio_print_who(struct tcb *tcp, int which, int who)
+{
+ switch (which)
+ {
+ case IOPRIO_WHO_PROCESS:
+ printpid(tcp, who, PT_TGID);
+ break;
+ case IOPRIO_WHO_PGRP:
+ printpid(tcp, who, PT_PGID);
+ break;
+ default:
+ tprintf("%d", who);
+ break;
+ }
+}
+
SYS_FUNC(ioprio_get)
{
if (entering(tcp)) {
/* int which */
printxval(ioprio_who, tcp->u_arg[0], "IOPRIO_WHO_???");
- /* int who */
- tprintf(", %d", (int) tcp->u_arg[1]);
+ tprintf(", ");
+ ioprio_print_who(tcp, (int) tcp->u_arg[0], (int) tcp->u_arg[1]);
return 0;
} else {
if (syserror(tcp))
@@ -72,8 +89,9 @@ SYS_FUNC(ioprio_set)
{
/* int which */
printxval(ioprio_who, tcp->u_arg[0], "IOPRIO_WHO_???");
- /* int who */
- tprintf(", %d, ", (int) tcp->u_arg[1]);
+ tprintf(", ");
+ ioprio_print_who(tcp, (int) tcp->u_arg[0], (int) tcp->u_arg[1]);
+ tprintf(", ");
/* int ioprio */
if (xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV)
tprintf("%d", (int) tcp->u_arg[2]);
diff --git a/kcmp.c b/kcmp.c
index 6819265b..fa70c51c 100644
--- a/kcmp.c
+++ b/kcmp.c
@@ -30,7 +30,10 @@ SYS_FUNC(kcmp)
kernel_ulong_t idx1 = tcp->u_arg[3];
kernel_ulong_t idx2 = tcp->u_arg[4];
- tprintf("%d, %d, ", pid1, pid2);
+ printpid(tcp, pid1, PT_TGID);
+ tprintf(", ");
+ printpid(tcp, pid2, PT_TGID);
+ tprintf(", ");
printxval(kcmp_types, type, "KCMP_???");
switch (type) {
@@ -38,7 +41,7 @@ SYS_FUNC(kcmp)
tprints(", ");
printfd_pid_tracee_ns(tcp, pid1, idx1);
tprints(", ");
- printfd_pid_tracee_ns(tcp, pid1, idx2);
+ printfd_pid_tracee_ns(tcp, pid2, idx2);
break;
diff --git a/linux/dummy.h b/linux/dummy.h
index 2f859a60..ca0d2f0c 100644
--- a/linux/dummy.h
+++ b/linux/dummy.h
@@ -53,6 +53,7 @@
# define sys_getgid sys_getuid
# define sys_getgid16 sys_getuid16
# define sys_getpeername sys_getsockname
+# define sys_getppid sys_getpid
# define sys_getresgid sys_getresuid
# define sys_getresgid16 sys_getresuid16
# define sys_lstat sys_stat
@@ -87,10 +88,6 @@
# define sys_vfork sys_fork
/* printargs does the right thing */
-# define sys_getpgrp printargs
-# define sys_getpid printargs
-# define sys_getppid printargs
-# define sys_gettid printargs
# define sys_idle printargs
# define sys_munlockall printargs
# define sys_pause printargs
@@ -108,10 +105,7 @@
/* printargs_d does the right thing */
# define sys_exit printargs_d
-# define sys_getpgid printargs_d
-# define sys_getsid printargs_d
# define sys_nice printargs_d
-# define sys_setpgid printargs_d
# define sys_setpgrp printargs_d
# define sys_timer_delete printargs_d
# define sys_timer_getoverrun printargs_d
diff --git a/msghdr.c b/msghdr.c
index ec6e77f2..930d72bc 100644
--- a/msghdr.c
+++ b/msghdr.c
@@ -69,7 +69,7 @@ print_scm_creds(struct tcb *tcp, const void *cmsg_data,
{
const struct ucred *uc = cmsg_data;
- PRINT_FIELD_U("{", *uc, pid);
+ PRINT_FIELD_TGID("{", *uc, pid, tcp);
PRINT_FIELD_UID(", ", *uc, uid);
PRINT_FIELD_UID(", ", *uc, gid);
tprints("}");
diff --git a/net.c b/net.c
index 9ea34b22..6e899253 100644
--- a/net.c
+++ b/net.c
@@ -601,7 +601,7 @@ print_get_ucred(struct tcb *const tcp, const kernel_ulong_t addr,
if (umoven_or_printaddr(tcp, addr, len, &uc))
return;
- PRINT_FIELD_LEN("{", uc, pid, len, PRINT_FIELD_D);
+ PRINT_FIELD_LEN("{", uc, pid, len, PRINT_FIELD_TGID, tcp);
PRINT_FIELD_LEN(", ", uc, uid, len, PRINT_FIELD_UID);
PRINT_FIELD_LEN(", ", uc, gid, len, PRINT_FIELD_UID);
tprints("}");
diff --git a/netlink.c b/netlink.c
index 4b4ef448..aeffdd9e 100644
--- a/netlink.c
+++ b/netlink.c
@@ -446,8 +446,9 @@ print_nlmsghdr(struct tcb *tcp,
decode_nlmsg_flags(nlmsghdr->nlmsg_flags,
nlmsghdr->nlmsg_type, family);
- tprintf(", seq=%u, pid=%u}", nlmsghdr->nlmsg_seq,
- nlmsghdr->nlmsg_pid);
+ tprintf(", seq=%u, pid=", nlmsghdr->nlmsg_seq);
+ printpid(tcp, nlmsghdr->nlmsg_pid, PT_TGID);
+ tprintf("}");
}
static bool
diff --git a/numa.c b/numa.c
index cc7a7cc6..37b95397 100644
--- a/numa.c
+++ b/numa.c
@@ -44,7 +44,8 @@ print_nodemask(struct tcb *const tcp, const kernel_ulong_t addr,
SYS_FUNC(migrate_pages)
{
- tprintf("%d, %" PRI_klu ", ", (int) tcp->u_arg[0], tcp->u_arg[1]);
+ printpid(tcp, (int) tcp->u_arg[0], PT_TGID);
+ tprintf(", %" PRI_klu ", ", tcp->u_arg[1]);
print_nodemask(tcp, tcp->u_arg[2], tcp->u_arg[1]);
tprints(", ");
print_nodemask(tcp, tcp->u_arg[3], tcp->u_arg[1]);
@@ -170,7 +171,8 @@ SYS_FUNC(move_pages)
kernel_ulong_t buf;
if (entering(tcp)) {
- tprintf("%d, %" PRI_klu ", ", (int) tcp->u_arg[0], npages);
+ printpid(tcp, (int) tcp->u_arg[0], PT_TGID);
+ tprintf(", %" PRI_klu ", ", npages);
print_array(tcp, tcp->u_arg[2], npages, &buf, current_wordsize,
tfetch_mem, print_addr, 0);
tprints(", ");
diff --git a/pidfd_open.c b/pidfd_open.c
index bbc7f617..10b5003d 100644
--- a/pidfd_open.c
+++ b/pidfd_open.c
@@ -10,7 +10,7 @@
SYS_FUNC(pidfd_open)
{
/* pid_t pid */
- tprintf("%d", (int) tcp->u_arg[0]);
+ printpid(tcp, (int) tcp->u_arg[0], PT_TGID);
/* unsigned int flags */
tprintf(", %#x", (unsigned int) tcp->u_arg[1]);
diff --git a/print_fields.h b/print_fields.h
index d6c96be2..349e8e1b 100644
--- a/print_fields.h
+++ b/print_fields.h
@@ -256,6 +256,30 @@
printfd((tcp_), (where_).field_); \
} while (0)
+# define PRINT_FIELD_TID(prefix_, where_, field_, tcp_) \
+ do { \
+ STRACE_PRINTF("%s%s=", (prefix_), #field_); \
+ printpid((tcp_), (where_).field_, PT_TID); \
+ } while (0)
+
+# define PRINT_FIELD_TGID(prefix_, where_, field_, tcp_) \
+ do { \
+ STRACE_PRINTF("%s%s=", (prefix_), #field_); \
+ printpid((tcp_), (where_).field_, PT_TGID); \
+ } while (0)
+
+# define PRINT_FIELD_PGID(prefix_, where_, field_, tcp_) \
+ do { \
+ STRACE_PRINTF("%s%s=", (prefix_), #field_); \
+ printpid((tcp_), (where_).field_, PT_PGID); \
+ } while (0)
+
+# define PRINT_FIELD_SID(prefix_, where_, field_, tcp_) \
+ do { \
+ STRACE_PRINTF("%s%s=", (prefix_), #field_); \
+ printpid((tcp_), (where_).field_, PT_SID); \
+ } while (0)
+
# define PRINT_FIELD_STRN(prefix_, where_, field_, len_, tcp_) \
do { \
STRACE_PRINTF("%s%s=", (prefix_), #field_); \
diff --git a/printsiginfo.c b/printsiginfo.c
index 133bc24d..c2f70534 100644
--- a/printsiginfo.c
+++ b/printsiginfo.c
@@ -58,6 +58,11 @@
static void
printsigsource(const siginfo_t *sip)
{
+ /*
+ TODO
+ We don't have a tcb here to translate this PID
+ Should I add a tcb parameter to every function in the call hiearchy?
+ */
tprintf(", si_pid=%u, si_uid=%u",
(unsigned int) sip->si_pid,
(unsigned int) sip->si_uid);
diff --git a/process.c b/process.c
index a98c304e..3cce5735 100644
--- a/process.c
+++ b/process.c
@@ -92,7 +92,8 @@ SYS_FUNC(ptrace)
}
/* pid */
- tprintf(", %d", pid);
+ tprintf(", ");
+ printpid(tcp, pid, PT_TGID);
/* addr */
switch (request) {
diff --git a/process_vm.c b/process_vm.c
index abee1e68..2d8855d8 100644
--- a/process_vm.c
+++ b/process_vm.c
@@ -13,7 +13,8 @@ SYS_FUNC(process_vm_readv)
{
if (entering(tcp)) {
/* arg 1: pid */
- tprintf("%d, ", (int) tcp->u_arg[0]);
+ printpid(tcp, (int) tcp->u_arg[0], PT_TGID);
+ tprintf(", ");
} else {
kernel_ulong_t local_iovcnt = tcp->u_arg[2];
kernel_ulong_t remote_iovcnt = tcp->u_arg[4];
@@ -42,7 +43,8 @@ SYS_FUNC(process_vm_writev)
kernel_ulong_t flags = tcp->u_arg[5];
/* arg 1: pid */
- tprintf("%d, ", (int) tcp->u_arg[0]);
+ printpid(tcp, (int) tcp->u_arg[0], PT_TGID);
+ tprintf(", ");
/* arg 2: local iov */
tprint_iov(tcp, local_iovcnt, tcp->u_arg[1], IOV_DECODE_STR);
/* arg 3: local iovcnt */
diff --git a/resource.c b/resource.c
index 53192ee9..c0ae76d8 100644
--- a/resource.c
+++ b/resource.c
@@ -142,7 +142,8 @@ SYS_FUNC(setrlimit)
SYS_FUNC(prlimit64)
{
if (entering(tcp)) {
- tprintf("%d, ", (int) tcp->u_arg[0]);
+ printpid(tcp, (int) tcp->u_arg[0], PT_TGID);
+ tprintf(", ");
printxval(resources, tcp->u_arg[1], "RLIMIT_???");
tprints(", ");
print_rlimit64(tcp, tcp->u_arg[2]);
@@ -179,10 +180,28 @@ SYS_FUNC(osf_getrusage)
#include "xlat/priorities.h"
+static void
+priority_print_who(struct tcb *tcp, int which, int who)
+{
+ switch (which)
+ {
+ case PRIO_PROCESS:
+ printpid(tcp, who, PT_TGID);
+ break;
+ case PRIO_PGRP:
+ printpid(tcp, who, PT_PGID);
+ break;
+ default:
+ tprintf("%d", who);
+ break;
+ }
+}
+
SYS_FUNC(getpriority)
{
printxval(priorities, tcp->u_arg[0], "PRIO_???");
- tprintf(", %d", (int) tcp->u_arg[1]);
+ tprintf(", ");
+ priority_print_who(tcp, tcp->u_arg[0], tcp->u_arg[1]);
return RVAL_DECODED;
}
@@ -190,7 +209,9 @@ SYS_FUNC(getpriority)
SYS_FUNC(setpriority)
{
printxval(priorities, tcp->u_arg[0], "PRIO_???");
- tprintf(", %d, %d", (int) tcp->u_arg[1], (int) tcp->u_arg[2]);
+ tprintf(", ");
+ priority_print_who(tcp, tcp->u_arg[0], tcp->u_arg[1]);
+ tprintf(", %d", (int) tcp->u_arg[2]);
return RVAL_DECODED;
}
diff --git a/sched.c b/sched.c
index 788ef39b..7ae5abe2 100644
--- a/sched.c
+++ b/sched.c
@@ -21,7 +21,7 @@
SYS_FUNC(sched_getscheduler)
{
if (entering(tcp)) {
- tprintf("%d", (int) tcp->u_arg[0]);
+ printpid(tcp, (int) tcp->u_arg[0], PT_TGID);
} else if (!syserror(tcp)) {
tcp->auxstr = xlookup(schedulers, (kernel_ulong_t) tcp->u_rval);
return RVAL_STR;
@@ -31,7 +31,8 @@ SYS_FUNC(sched_getscheduler)
SYS_FUNC(sched_setscheduler)
{
- tprintf("%d, ", (int) tcp->u_arg[0]);
+ printpid(tcp, (int) tcp->u_arg[0], PT_TGID);
+ tprints(", ");
printxval(schedulers, tcp->u_arg[1], "SCHED_???");
tprints(", ");
printnum_int(tcp, tcp->u_arg[2], "%d");
@@ -41,16 +42,19 @@ SYS_FUNC(sched_setscheduler)
SYS_FUNC(sched_getparam)
{
- if (entering(tcp))
- tprintf("%d, ", (int) tcp->u_arg[0]);
- else
+ if (entering(tcp)) {
+ printpid(tcp, (int) tcp->u_arg[0], PT_TGID);
+ tprints(", ");
+ } else {
printnum_int(tcp, tcp->u_arg[1], "%d");
+ }
return 0;
}
SYS_FUNC(sched_setparam)
{
- tprintf("%d, ", (int) tcp->u_arg[0]);
+ printpid(tcp, (int) tcp->u_arg[0], PT_TGID);
+ tprints(", ");
printnum_int(tcp, tcp->u_arg[1], "%d");
return RVAL_DECODED;
@@ -68,7 +72,8 @@ do_sched_rr_get_interval(struct tcb *const tcp,
const print_obj_by_addr_fn print_ts)
{
if (entering(tcp)) {
- tprintf("%d, ", (int) tcp->u_arg[0]);
+ printpid(tcp, (int) tcp->u_arg[0], PT_TGID);
+ tprints(", ");
} else {
if (syserror(tcp))
printaddr(tcp->u_arg[1]);
@@ -160,7 +165,8 @@ end:
SYS_FUNC(sched_setattr)
{
if (entering(tcp)) {
- tprintf("%d, ", (int) tcp->u_arg[0]);
+ printpid(tcp, (int) tcp->u_arg[0], PT_TGID);
+ tprints(", ");
print_sched_attr(tcp, tcp->u_arg[1], 0);
} else {
struct sched_attr attr;
@@ -179,7 +185,8 @@ SYS_FUNC(sched_setattr)
SYS_FUNC(sched_getattr)
{
if (entering(tcp)) {
- tprintf("%d, ", (int) tcp->u_arg[0]);
+ printpid(tcp, (int) tcp->u_arg[0], PT_TGID);
+ tprints(", ");
} else {
const unsigned int size = tcp->u_arg[2];
diff --git a/signal.c b/signal.c
index 3cb54bb3..27e0b9e8 100644
--- a/signal.c
+++ b/signal.c
@@ -439,7 +439,14 @@ SYS_FUNC(sigprocmask)
SYS_FUNC(kill)
{
/* pid */
- tprintf("%d, ", (int) tcp->u_arg[0]);
+ int pid = (int) tcp->u_arg[0];
+ tprintf("%d", pid);
+ if (pid > 0)
+ printpid_translation(tcp, pid, PT_TGID);
+ else if (pid < -1)
+ printpid_translation(tcp, -pid, PT_PGID);
+
+ tprintf(", ");
/* signal */
printsignal(tcp->u_arg[1]);
@@ -448,8 +455,12 @@ SYS_FUNC(kill)
SYS_FUNC(tgkill)
{
- /* tgid, tid */
- tprintf("%d, %d, ", (int) tcp->u_arg[0], (int) tcp->u_arg[1]);
+ /* tgid */
+ printpid(tcp, (int) tcp->u_arg[0], PT_TGID);
+ tprintf(", ");
+ /* tid */
+ printpid(tcp, (int) tcp->u_arg[1], PT_TID);
+ tprintf(", ");
/* signal */
printsignal(tcp->u_arg[2]);
@@ -615,7 +626,8 @@ print_sigqueueinfo(struct tcb *const tcp, const int sig,
SYS_FUNC(rt_sigqueueinfo)
{
- tprintf("%d, ", (int) tcp->u_arg[0]);
+ printpid(tcp, (int) tcp->u_arg[0], PT_TGID);
+ tprintf(", ");
print_sigqueueinfo(tcp, tcp->u_arg[1], tcp->u_arg[2]);
return RVAL_DECODED;
@@ -623,7 +635,10 @@ SYS_FUNC(rt_sigqueueinfo)
SYS_FUNC(rt_tgsigqueueinfo)
{
- tprintf("%d, %d, ", (int) tcp->u_arg[0], (int) tcp->u_arg[1]);
+ printpid(tcp, (int) tcp->u_arg[0], PT_TGID);
+ tprintf(", ");
+ printpid(tcp, (int) tcp->u_arg[1], PT_TID);
+ tprintf(", ");
print_sigqueueinfo(tcp, tcp->u_arg[2], tcp->u_arg[3]);
return RVAL_DECODED;
diff --git a/sockaddr.c b/sockaddr.c
index b6b9aa7d..1d0e54b8 100644
--- a/sockaddr.c
+++ b/sockaddr.c
@@ -411,6 +411,11 @@ print_sockaddr_data_nl(const void *const buf, const int addrlen)
{
const struct sockaddr_nl *const sa_nl = buf;
+ /*
+ TODO
+ We don't have a tcb here to translate this PID
+ Should I add a tcb parameter to sockaddr_printer?
+ */
PRINT_FIELD_D("", *sa_nl, nl_pid);
PRINT_FIELD_0X(", ", *sa_nl, nl_groups);
}
diff --git a/tests/bpf.c b/tests/bpf.c
index 0965eb96..1b7e89fa 100644
--- a/tests/bpf.c
+++ b/tests/bpf.c
@@ -1289,16 +1289,16 @@ static const struct bpf_attr_check BPF_BTF_GET_FD_BY_ID_checks[] = {
static const struct bpf_attr_check BPF_TASK_FD_QUERY_checks[] = {
{
- .data = { .BPF_TASK_FD_QUERY_data = { .pid = 0xdeadbeef } },
+ .data = { .BPF_TASK_FD_QUERY_data = { .pid = 1735928559 } },
.size = offsetofend(struct BPF_TASK_FD_QUERY_struct, pid),
- .str = "task_fd_query={pid=3735928559, fd=0" FD0_PATH
+ .str = "task_fd_query={pid=1735928559, fd=0" FD0_PATH
", flags=0, buf_len=0, buf=NULL, prog_id=0"
", fd_type=BPF_FD_TYPE_RAW_TRACEPOINT"
", probe_offset=0, probe_addr=0}"
},
{ /* 1 */
.data = { .BPF_TASK_FD_QUERY_data = {
- .pid = 0xcafef00d,
+ .pid = 1405705229,
.fd = 0xdeadbeef,
.flags = 0xfacefeed,
.buf_len = 0xdefaced,
@@ -1309,7 +1309,7 @@ static const struct bpf_attr_check BPF_TASK_FD_QUERY_checks[] = {
.probe_addr = 0xfac5fed5fac7fed8
} },
.size = offsetofend(struct BPF_TASK_FD_QUERY_struct, probe_addr),
- .str = "task_fd_query={pid=3405705229"
+ .str = "task_fd_query={pid=1405705229"
", fd=-559038737"
", flags=4207869677"
", buf_len=233811181"
diff --git a/tests/ioctl_block.c b/tests/ioctl_block.c
index 643daf87..67fee35c 100644
--- a/tests/ioctl_block.c
+++ b/tests/ioctl_block.c
@@ -165,7 +165,7 @@ main(void)
ioctl(-1, BLKTRACESETUP, buts);
printf("ioctl(-1, BLKTRACESETUP, {act_mask=%hu, buf_size=%u, buf_nr=%u"
- ", start_lba=%" PRI__u64 ", end_lba=%" PRI__u64 ", pid=%u})"
+ ", start_lba=%" PRI__u64 ", end_lba=%" PRI__u64 ", pid=%d})"
" = -1 EBADF (%m)\n",
buts->act_mask, buts->buf_size, buts->buf_nr,
buts->start_lba, buts->end_lba, buts->pid);
diff --git a/tests/kcmp.c b/tests/kcmp.c
index a46da0ed..dc5ba9a4 100644
--- a/tests/kcmp.c
+++ b/tests/kcmp.c
@@ -64,7 +64,26 @@ static const char zero_path[] = "/dev/zero";
static void
printpidfd(const char *prefix, pid_t pid, unsigned fd)
{
- printf("%s%d", prefix, fd);
+ const char *path = NULL;
+
+# if VERBOSE_FD
+ if (pid == getpid()) {
+ switch (fd)
+ {
+ case NULL_FD:
+ path = null_path;
+ break;
+ case ZERO_FD:
+ path = zero_path;
+ break;
+ }
+ }
+# endif
+
+ if (path)
+ printf("%s%d<%s>", prefix, fd, path);
+ else
+ printf("%s%d", prefix, fd);
}
/*
@@ -179,7 +198,7 @@ main(void)
/* KCMP_FILE is the only type which has additional args */
do_kcmp(3141592653U, 2718281828U, ARG_STR(KCMP_FILE), bogus_idx1,
bogus_idx2);
- do_kcmp(-1, -1, ARG_STR(KCMP_FILE), NULL_FD, ZERO_FD);
+ do_kcmp(getpid(), getpid(), ARG_STR(KCMP_FILE), NULL_FD, ZERO_FD);
/* Types without additional args */
do_kcmp(-1, -1, ARG_STR(KCMP_VM), bogus_idx1, bogus_idx2);
@@ -198,7 +217,7 @@ main(void)
for (i = 0; i < ARRAY_SIZE(slot_data); i++) {
memcpy(slot, slot_data + i, sizeof(*slot));
- do_kcmp(getpid(), getppid(), ARG_STR(KCMP_EPOLL_TFD), NULL_FD,
+ do_kcmp(getpid(), -1, ARG_STR(KCMP_EPOLL_TFD), NULL_FD,
(uintptr_t) slot, 1);
}
diff --git a/tests/pidfd_send_signal.c b/tests/pidfd_send_signal.c
index 4b736815..ca01c04a 100644
--- a/tests/pidfd_send_signal.c
+++ b/tests/pidfd_send_signal.c
@@ -54,10 +54,10 @@ main(void)
sys_pidfd_send_signal(fd, SIGUSR2, si, -1);
printf("pidfd_send_signal(%d, SIGUSR2, {si_signo=SIGUSR1"
- ", si_code=SI_QUEUE, si_errno=%u, si_pid=%u, si_uid=%u"
+ ", si_code=SI_QUEUE, si_errno=%u, si_pid=%d, si_uid=%u"
", si_value={int=%d, ptr=%p}}, %#x) = %s\n",
fd, si->si_errno, si->si_pid, si->si_uid, si->si_int, si->si_ptr,
- -1U, errstr);
+ -1, errstr);
puts("+++ exited with 0 +++");
return 0;
diff --git a/util.c b/util.c
index cde76c13..28d7ef4f 100644
--- a/util.c
+++ b/util.c
@@ -392,6 +392,18 @@ printnum_fd(struct tcb *const tcp, const kernel_ulong_t addr)
return true;
}
+bool
+printnum_pid(struct tcb *const tcp, const kernel_ulong_t addr, enum pid_type type)
+{
+ int pid;
+ if (umove_or_printaddr(tcp, addr, &pid))
+ return false;
+ tprints("[");
+ printpid(tcp, pid, type);
+ tprints("]");
+ return true;
+}
+
/**
* Prints time to a (static internal) buffer and returns pointer to it.
* Returns NULL if the provided time specification is not correct.
@@ -641,12 +653,8 @@ printed:
void
printfd_pid_tracee_ns(struct tcb *tcp, pid_t pid, int fd)
{
- /*
- * TODO: We want to have the same formatting as printfd here,
- * but we should figure out first which process in strace's
- * PID NS is referred to by pid in tracee's PID NS.
- */
- tprintf("%d", fd);
+ int strace_pid = translate_pid(tcp, pid, PT_TGID, NULL);
+ printfd_pid(tcp, strace_pid, fd);
}
/*
diff --git a/wait.c b/wait.c
index 2b9f9807..708b0b48 100644
--- a/wait.c
+++ b/wait.c
@@ -86,8 +86,13 @@ printwaitn(struct tcb *const tcp,
* for example, wait4(4294967295, ...) instead of -1
* in strace. We have to use int here, not long.
*/
- int pid = tcp->u_arg[0];
- tprintf("%d, ", pid);
+ int pid = (int) tcp->u_arg[0];
+ tprintf("%d", pid);
+ if (pid > 0)
+ printpid_translation(tcp, pid, PT_TGID);
+ else if (pid < -1)
+ printpid_translation(tcp, -pid, PT_PGID);
+ tprintf(", ");
} else {
int status;
@@ -108,7 +113,7 @@ printwaitn(struct tcb *const tcp,
printaddr(tcp->u_arg[3]);
}
}
- return 0;
+ return RVAL_TGID;
}
SYS_FUNC(waitpid)
@@ -134,10 +139,28 @@ SYS_FUNC(osf_wait4)
SYS_FUNC(waitid)
{
+ unsigned int idtype = (unsigned int) tcp->u_arg[0];
+ int id = (int) tcp->u_arg[1];
+
if (entering(tcp)) {
- printxval(waitid_types, tcp->u_arg[0], "P_???");
- int pid = tcp->u_arg[1];
- tprintf(", %d, ", pid);
+ printxval(waitid_types, idtype, "P_???");
+ tprintf(", ");
+ switch (idtype)
+ {
+ case P_PID:
+ printpid(tcp, id, PT_TGID);
+ break;
+ case P_PIDFD:
+ printfd(tcp, id);
+ break;
+ case P_PGID:
+ printpid(tcp, id, PT_PGID);
+ break;
+ default:
+ tprintf("%d", id);
+ break;
+ }
+ tprintf(", ");
} else {
/* siginfo */
printsiginfo_at(tcp, tcp->u_arg[2]);
--
2.27.0
More information about the Strace-devel
mailing list