Blame SOURCES/0135-Use-printpid-in-decoders.patch

d811e0
From 4d1964761ad04028a0e6288821ee0feef5ca8fc1 Mon Sep 17 00:00:00 2001
d811e0
From: =?UTF-8?q?=C3=81kos=20Uzonyi?= <uzonyi.akos@gmail.com>
d811e0
Date: Wed, 10 Jun 2020 13:18:50 +0200
d811e0
Subject: [PATCH 135/138] Use printpid in decoders
d811e0
d811e0
* getpid.c: New file.
d811e0
* Makefile.am (libstrace_a_SOURCES): Add it.
d811e0
* linux/dummy.h (sys_getpid, sys_getppid, sys_gettid,
d811e0
sys_setpgid, sys_setpgrp): Remove.
d811e0
* util.c (printfd_pid_tracee_ns): Implement using translate_pid.
d811e0
* defs.h (printnum_pid): New function definition.
d811e0
(printfd_pid_tracee_ns): Update documentation
d811e0
* util.c: (printnum_pid): New function.
d811e0
* print_fields.h (PRINT_FIELD_TID): New macro.
d811e0
(PRINT_FIELD_TGID): Likewise.
d811e0
(PRINT_FIELD_PGID): Likewise.
d811e0
(PRINT_FIELD_SID): Likewise.
d811e0
* affinity.c: Print PIDs with printpid.
d811e0
* block.c: Likewise.
d811e0
* bpf.c: Likewise.
d811e0
* capability.c: Likewise.
d811e0
* clone.c: Likewise.
d811e0
* fcntl.c: Likewise.
d811e0
* get_robust_list.c: Likewise.
d811e0
* ioprio.c: Likewise.
d811e0
* kcmp.c: Likewise.
d811e0
* msghdr.c: Likewise.
d811e0
* net.c: Likewise.
d811e0
* netlink.c: Likewise.
d811e0
* numa.c: Likewise.
d811e0
* pidfd_open.c: Likewise.
d811e0
* printsiginfo.c: Likewise.
d811e0
* process.c: Likewise.
d811e0
* process_vm.c: Likewise.
d811e0
* resource.c: Likewise.
d811e0
* sched.c: Likewise.
d811e0
* signal.c: Likewise.
d811e0
* sockaddr.c: Likewise.
d811e0
* wait.c: Likewise.
d811e0
* kcmp.c (SYS_FUNC(kcmp)): Fix KCMP_FILE pid arguments.
d811e0
* tests/kcmp.c (printpidfd): Print path if VERBOSE_FD.
d811e0
(main): Use our real pid if real fds are used.
d811e0
---
d811e0
 Makefile.am       |  1 +
d811e0
 affinity.c        |  6 ++++--
d811e0
 block.c           |  2 +-
d811e0
 bpf.c             |  2 +-
d811e0
 capability.c      |  4 +++-
d811e0
 clone.c           | 14 +++++++-------
d811e0
 defs.h            |  5 ++++-
d811e0
 fcntl.c           | 24 ++++++++++++++++++++++--
d811e0
 get_robust_list.c |  3 ++-
d811e0
 getpid.c          | 46 ++++++++++++++++++++++++++++++++++++++++++++++
d811e0
 ioprio.c          | 26 ++++++++++++++++++++++----
d811e0
 ipc_shmctl.c      |  4 ++--
d811e0
 kcmp.c            |  5 ++++-
d811e0
 linux/dummy.h     |  8 +-------
d811e0
 msghdr.c          |  2 +-
d811e0
 net.c             |  2 +-
d811e0
 netlink.c         |  5 +++--
d811e0
 numa.c            |  6 ++++--
d811e0
 pidfd_open.c      |  2 +-
d811e0
 print_fields.h    | 24 ++++++++++++++++++++++++
d811e0
 printsiginfo.c    |  2 +-
d811e0
 process.c         |  3 ++-
d811e0
 process_vm.c      |  6 ++++--
d811e0
 resource.c        | 27 ++++++++++++++++++++++++---
d811e0
 sched.c           | 25 ++++++++++++++++---------
d811e0
 signal.c          | 21 +++++++++++++++------
d811e0
 sockaddr.c        |  2 +-
d811e0
 tests/kcmp.c      | 25 ++++++++++++++++++++++---
d811e0
 util.c            | 22 +++++++++++++++-------
d811e0
 wait.c            | 36 ++++++++++++++++++++++++------------
d811e0
 30 files changed, 278 insertions(+), 82 deletions(-)
d811e0
 create mode 100644 getpid.c
d811e0
d811e0
Index: strace-5.7/Makefile.am
d811e0
===================================================================
d811e0
--- strace-5.7.orig/Makefile.am	2020-09-09 15:52:09.159983257 +0200
d811e0
+++ strace-5.7/Makefile.am	2020-09-09 18:49:06.780401433 +0200
d811e0
@@ -135,6 +135,7 @@
d811e0
 	getcpu.c	\
d811e0
 	getcwd.c	\
d811e0
 	getpagesize.c \
d811e0
+	getpid.c	\
d811e0
 	getrandom.c	\
d811e0
 	hdio.c		\
d811e0
 	hostname.c	\
d811e0
Index: strace-5.7/affinity.c
d811e0
===================================================================
d811e0
--- strace-5.7.orig/affinity.c	2020-09-09 15:52:09.159983257 +0200
d811e0
+++ strace-5.7/affinity.c	2020-09-09 15:55:03.979108297 +0200
d811e0
@@ -82,7 +82,8 @@
d811e0
 	const int pid = tcp->u_arg[0];
d811e0
 	const unsigned int len = tcp->u_arg[1];
d811e0
 
d811e0
-	tprintf("%d, %u, ", pid, len);
d811e0
+	printpid(tcp, pid, PT_TGID);
d811e0
+	tprintf(", %u, ", len);
d811e0
 	print_affinitylist(tcp, tcp->u_arg[2], len);
d811e0
 
d811e0
 	return RVAL_DECODED;
d811e0
@@ -94,7 +95,8 @@
d811e0
 	const unsigned int len = tcp->u_arg[1];
d811e0
 
d811e0
 	if (entering(tcp)) {
d811e0
-		tprintf("%d, %u, ", pid, len);
d811e0
+		printpid(tcp, pid, PT_TGID);
d811e0
+		tprintf(", %u, ", len);
d811e0
 	} else {
d811e0
 		print_affinitylist(tcp, tcp->u_arg[2], tcp->u_rval);
d811e0
 	}
d811e0
Index: strace-5.7/block.c
d811e0
===================================================================
d811e0
--- strace-5.7.orig/block.c	2020-09-09 15:52:09.159983257 +0200
d811e0
+++ strace-5.7/block.c	2020-09-09 15:55:03.979108297 +0200
d811e0
@@ -179,7 +179,7 @@
d811e0
 			PRINT_FIELD_U(", ", buts, buf_nr);
d811e0
 			PRINT_FIELD_U(", ", buts, start_lba);
d811e0
 			PRINT_FIELD_U(", ", buts, end_lba);
d811e0
-			PRINT_FIELD_D(", ", buts, pid);
d811e0
+			PRINT_FIELD_TGID(", ", buts, pid, tcp);
d811e0
 			return 0;
d811e0
 		} else {
d811e0
 			struct_blk_user_trace_setup buts;
d811e0
Index: strace-5.7/bpf.c
d811e0
===================================================================
d811e0
--- strace-5.7.orig/bpf.c	2020-09-09 15:52:09.159983257 +0200
d811e0
+++ strace-5.7/bpf.c	2020-09-09 15:55:03.980108298 +0200
d811e0
@@ -927,7 +927,7 @@
d811e0
 	if (entering(tcp)) {
d811e0
 		set_tcb_priv_ulong(tcp, attr.buf_len);
d811e0
 
d811e0
-		PRINT_FIELD_D("{task_fd_query={", attr, pid);
d811e0
+		PRINT_FIELD_TGID("{task_fd_query={", attr, pid, tcp);
d811e0
 		PRINT_FIELD_FD(", ", attr, fd, tcp);
d811e0
 		PRINT_FIELD_U(", ", attr, flags);
d811e0
 		PRINT_FIELD_U(", ", attr, buf_len);
d811e0
Index: strace-5.7/capability.c
d811e0
===================================================================
d811e0
--- strace-5.7.orig/capability.c	2020-09-09 15:52:09.159983257 +0200
d811e0
+++ strace-5.7/capability.c	2020-09-09 15:55:03.980108298 +0200
d811e0
@@ -70,7 +70,9 @@
d811e0
 	tprints("{version=");
d811e0
 	printxval(cap_version, h->version,
d811e0
 		  "_LINUX_CAPABILITY_VERSION_???");
d811e0
-	tprintf(", pid=%d}", h->pid);
d811e0
+	tprints(", pid=");
d811e0
+	printpid(tcp, h->pid, PT_TGID);
d811e0
+	tprints("}");
d811e0
 }
d811e0
 
d811e0
 static void
d811e0
Index: strace-5.7/clone.c
d811e0
===================================================================
d811e0
--- strace-5.7.orig/clone.c	2020-09-09 15:52:09.159983257 +0200
d811e0
+++ strace-5.7/clone.c	2020-09-09 15:55:03.980108298 +0200
d811e0
@@ -114,14 +114,14 @@
d811e0
 		 */
d811e0
 		if ((flags & (CLONE_PARENT_SETTID|CLONE_PIDFD|CLONE_CHILD_SETTID
d811e0
 			      |CLONE_CHILD_CLEARTID|CLONE_SETTLS)) == 0)
d811e0
-			return RVAL_DECODED;
d811e0
+			return RVAL_DECODED | RVAL_TID;
d811e0
 	} else {
d811e0
 		if (flags & (CLONE_PARENT_SETTID|CLONE_PIDFD)) {
d811e0
 			kernel_ulong_t addr = tcp->u_arg[ARG_PTID];
d811e0
 
d811e0
 			tprints(", parent_tid=");
d811e0
 			if (flags & CLONE_PARENT_SETTID)
d811e0
-				printnum_int(tcp, addr, "%u");
d811e0
+				printnum_pid(tcp, addr, PT_TID);
d811e0
 			else
d811e0
 				printnum_fd(tcp, addr);
d811e0
 		}
d811e0
@@ -134,7 +134,7 @@
d811e0
 			printaddr(tcp->u_arg[ARG_CTID]);
d811e0
 		}
d811e0
 	}
d811e0
-	return 0;
d811e0
+	return RVAL_TID;
d811e0
 }
d811e0
 
d811e0
 
d811e0
@@ -229,7 +229,7 @@
d811e0
 
d811e0
 		if ((arg.flags & (CLONE_PIDFD | CLONE_PARENT_SETTID)) ||
d811e0
 		    (size > fetch_size))
d811e0
-			return 0;
d811e0
+			return RVAL_TID;
d811e0
 
d811e0
 		goto out;
d811e0
 	}
d811e0
@@ -256,7 +256,7 @@
d811e0
 
d811e0
 	if (arg.flags & CLONE_PARENT_SETTID) {
d811e0
 		tprintf("%sparent_tid=", pfx);
d811e0
-		printnum_int(tcp, arg.parent_tid, "%d"); /* TID */
d811e0
+		printnum_pid(tcp, arg.parent_tid, PT_TID);
d811e0
 		pfx = ", ";
d811e0
 	}
d811e0
 
d811e0
@@ -279,7 +279,7 @@
d811e0
 out:
d811e0
 	tprintf(", %" PRI_klu, size);
d811e0
 
d811e0
-	return RVAL_DECODED;
d811e0
+	return RVAL_DECODED | RVAL_TID;
d811e0
 }
d811e0
 
d811e0
 
d811e0
@@ -300,5 +300,5 @@
d811e0
 
d811e0
 SYS_FUNC(fork)
d811e0
 {
d811e0
-	return RVAL_DECODED;
d811e0
+	return RVAL_DECODED | RVAL_TGID;
d811e0
 }
d811e0
Index: strace-5.7/defs.h
d811e0
===================================================================
d811e0
--- strace-5.7.orig/defs.h	2020-09-09 15:52:09.159983257 +0200
d811e0
+++ strace-5.7/defs.h	2020-09-09 15:55:03.980108298 +0200
d811e0
@@ -1101,7 +1101,7 @@
d811e0
 
d811e0
 /**
d811e0
  * Print file descriptor fd owned by process with ID pid (from the PID NS
d811e0
- * of the tracee the descriptor tcp).  This is a stub.
d811e0
+ * of the tracee).
d811e0
  */
d811e0
 extern void printfd_pid_tracee_ns(struct tcb *tcp, pid_t pid, int fd);
d811e0
 
d811e0
@@ -1562,6 +1562,9 @@
d811e0
 extern bool
d811e0
 printnum_fd(struct tcb *, kernel_ulong_t addr);
d811e0
 
d811e0
+extern bool
d811e0
+printnum_pid(struct tcb *const tcp, const kernel_ulong_t addr, enum pid_type type);
d811e0
+
d811e0
 static inline bool
d811e0
 printnum_slong(struct tcb *tcp, kernel_ulong_t addr)
d811e0
 {
d811e0
Index: strace-5.7/fcntl.c
d811e0
===================================================================
d811e0
--- strace-5.7.orig/fcntl.c	2020-09-09 15:52:09.159983257 +0200
d811e0
+++ strace-5.7/fcntl.c	2020-09-09 15:55:03.981108298 +0200
d811e0
@@ -28,7 +28,7 @@
d811e0
 	PRINT_FIELD_D(", ", *fl, l_start);
d811e0
 	PRINT_FIELD_D(", ", *fl, l_len);
d811e0
 	if (getlk)
d811e0
-		PRINT_FIELD_D(", ", *fl, l_pid);
d811e0
+		PRINT_FIELD_TGID(", ", *fl, l_pid, tcp);
d811e0
 	tprints("}");
d811e0
 }
d811e0
 
d811e0
@@ -59,7 +59,22 @@
d811e0
 		return;
d811e0
 
d811e0
 	PRINT_FIELD_XVAL("{", owner, type, f_owner_types, "F_OWNER_???");
d811e0
-	PRINT_FIELD_D(", ", owner, pid);
d811e0
+
d811e0
+	enum pid_type pid_type = PT_NONE;
d811e0
+	switch (owner.type)
d811e0
+	{
d811e0
+	case F_OWNER_TID:
d811e0
+		pid_type = PT_TID;
d811e0
+		break;
d811e0
+	case F_OWNER_PID:
d811e0
+		pid_type = PT_TGID;
d811e0
+		break;
d811e0
+	case F_OWNER_PGRP:
d811e0
+		pid_type = PT_PGID;
d811e0
+		break;
d811e0
+	}
d811e0
+	tprints(", pid=");
d811e0
+	printpid(tcp, owner.pid, pid_type);
d811e0
 	tprints("}");
d811e0
 }
d811e0
 
d811e0
@@ -74,6 +89,9 @@
d811e0
 		printflags(fdflags, tcp->u_arg[2], "FD_???");
d811e0
 		break;
d811e0
 	case F_SETOWN:
d811e0
+		tprints(", ");
d811e0
+		printpid_tgid_pgid(tcp, tcp->u_arg[2]);
d811e0
+		break;
d811e0
 	case F_SETPIPE_SZ:
d811e0
 		tprintf(", %" PRI_kld, tcp->u_arg[2]);
d811e0
 		break;
d811e0
@@ -116,6 +134,8 @@
d811e0
 		printsignal(tcp->u_arg[2]);
d811e0
 		break;
d811e0
 	case F_GETOWN:
d811e0
+		return RVAL_DECODED |
d811e0
+		       ((int) tcp->u_rval < 0 ? RVAL_PGID : RVAL_TGID);
d811e0
 	case F_GETPIPE_SZ:
d811e0
 		break;
d811e0
 	case F_GETFD:
d811e0
Index: strace-5.7/get_robust_list.c
d811e0
===================================================================
d811e0
--- strace-5.7.orig/get_robust_list.c	2020-09-09 15:52:09.159983257 +0200
d811e0
+++ strace-5.7/get_robust_list.c	2020-09-09 15:55:03.981108298 +0200
d811e0
@@ -10,7 +10,8 @@
d811e0
 SYS_FUNC(get_robust_list)
d811e0
 {
d811e0
 	if (entering(tcp)) {
d811e0
-		tprintf("%d, ", (int) tcp->u_arg[0]);
d811e0
+		printpid(tcp, tcp->u_arg[0], PT_TID);
d811e0
+		tprints(", ");
d811e0
 	} else {
d811e0
 		printnum_ptr(tcp, tcp->u_arg[1]);
d811e0
 		tprints(", ");
d811e0
Index: strace-5.7/getpid.c
d811e0
===================================================================
d811e0
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
d811e0
+++ strace-5.7/getpid.c	2020-09-09 15:55:03.981108298 +0200
d811e0
@@ -0,0 +1,46 @@
d811e0
+/*
d811e0
+ * Copyright (c) 2020 Ákos Uzonyi <uzonyi.akos@gmail.com>
d811e0
+ * All rights reserved.
d811e0
+ *
d811e0
+ * SPDX-License-Identifier: LGPL-2.1-or-later
d811e0
+ */
d811e0
+
d811e0
+#include "defs.h"
d811e0
+
d811e0
+SYS_FUNC(getpid)
d811e0
+{
d811e0
+	return RVAL_DECODED | RVAL_TGID;
d811e0
+}
d811e0
+
d811e0
+SYS_FUNC(gettid)
d811e0
+{
d811e0
+	return RVAL_DECODED | RVAL_TID;
d811e0
+}
d811e0
+
d811e0
+SYS_FUNC(getpgrp)
d811e0
+{
d811e0
+	return RVAL_DECODED | RVAL_PGID;
d811e0
+}
d811e0
+
d811e0
+SYS_FUNC(getpgid)
d811e0
+{
d811e0
+	printpid(tcp, tcp->u_arg[0], PT_TGID);
d811e0
+
d811e0
+	return RVAL_DECODED | RVAL_PGID;
d811e0
+}
d811e0
+
d811e0
+SYS_FUNC(getsid)
d811e0
+{
d811e0
+	printpid(tcp, tcp->u_arg[0], PT_TGID);
d811e0
+
d811e0
+	return RVAL_DECODED | RVAL_SID;
d811e0
+}
d811e0
+
d811e0
+SYS_FUNC(setpgid)
d811e0
+{
d811e0
+	printpid(tcp, tcp->u_arg[0], PT_TGID);
d811e0
+	tprints(", ");
d811e0
+	printpid(tcp, tcp->u_arg[1], PT_PGID);
d811e0
+
d811e0
+	return RVAL_DECODED;
d811e0
+}
d811e0
Index: strace-5.7/ioprio.c
d811e0
===================================================================
d811e0
--- strace-5.7.orig/ioprio.c	2020-09-09 15:52:09.159983257 +0200
d811e0
+++ strace-5.7/ioprio.c	2020-09-09 15:55:03.981108298 +0200
d811e0
@@ -49,13 +49,30 @@
d811e0
 		? tprints_comment : tprints)(str);
d811e0
 }
d811e0
 
d811e0
+static void
d811e0
+ioprio_print_who(struct tcb *tcp, int which, int who)
d811e0
+{
d811e0
+	switch (which)
d811e0
+	{
d811e0
+	case IOPRIO_WHO_PROCESS:
d811e0
+		printpid(tcp, who, PT_TGID);
d811e0
+		break;
d811e0
+	case IOPRIO_WHO_PGRP:
d811e0
+		printpid(tcp, who, PT_PGID);
d811e0
+		break;
d811e0
+	default:
d811e0
+		tprintf("%d", who);
d811e0
+		break;
d811e0
+	}
d811e0
+}
d811e0
+
d811e0
 SYS_FUNC(ioprio_get)
d811e0
 {
d811e0
 	if (entering(tcp)) {
d811e0
 		/* int which */
d811e0
 		printxval(ioprio_who, tcp->u_arg[0], "IOPRIO_WHO_???");
d811e0
-		/* int who */
d811e0
-		tprintf(", %d", (int) tcp->u_arg[1]);
d811e0
+		tprints(", ");
d811e0
+		ioprio_print_who(tcp, tcp->u_arg[0], tcp->u_arg[1]);
d811e0
 		return 0;
d811e0
 	} else {
d811e0
 		if (syserror(tcp))
d811e0
@@ -72,8 +89,9 @@
d811e0
 {
d811e0
 	/* int which */
d811e0
 	printxval(ioprio_who, tcp->u_arg[0], "IOPRIO_WHO_???");
d811e0
-	/* int who */
d811e0
-	tprintf(", %d, ", (int) tcp->u_arg[1]);
d811e0
+	tprints(", ");
d811e0
+	ioprio_print_who(tcp, tcp->u_arg[0], tcp->u_arg[1]);
d811e0
+	tprints(", ");
d811e0
 	/* int ioprio */
d811e0
 	if (xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV)
d811e0
 		tprintf("%d", (int) tcp->u_arg[2]);
d811e0
Index: strace-5.7/ipc_shmctl.c
d811e0
===================================================================
d811e0
--- strace-5.7.orig/ipc_shmctl.c	2020-09-09 15:52:09.159983257 +0200
d811e0
+++ strace-5.7/ipc_shmctl.c	2020-09-09 15:55:03.981108298 +0200
d811e0
@@ -54,8 +54,8 @@
d811e0
 		PRINT_FIELD_UID(", ", shmid_ds.shm_perm, cgid);
d811e0
 		tprints("}");
d811e0
 		tprintf(", shm_segsz=%u", (unsigned) shmid_ds.shm_segsz);
d811e0
-		PRINT_FIELD_D(", ", shmid_ds, shm_cpid);
d811e0
-		PRINT_FIELD_D(", ", shmid_ds, shm_lpid);
d811e0
+		PRINT_FIELD_TGID(", ", shmid_ds, shm_cpid, tcp);
d811e0
+		PRINT_FIELD_TGID(", ", shmid_ds, shm_lpid, tcp);
d811e0
 		tprintf(", shm_nattch=%u", (unsigned) shmid_ds.shm_nattch);
d811e0
 		tprintf(", shm_atime=%u", (unsigned) shmid_ds.shm_atime);
d811e0
 		tprintf(", shm_dtime=%u", (unsigned) shmid_ds.shm_dtime);
d811e0
Index: strace-5.7/kcmp.c
d811e0
===================================================================
d811e0
--- strace-5.7.orig/kcmp.c	2020-09-09 15:52:09.159983257 +0200
d811e0
+++ strace-5.7/kcmp.c	2020-09-09 15:55:03.981108298 +0200
d811e0
@@ -30,7 +30,10 @@
d811e0
 	kernel_ulong_t idx1 = tcp->u_arg[3];
d811e0
 	kernel_ulong_t idx2 = tcp->u_arg[4];
d811e0
 
d811e0
-	tprintf("%d, %d, ", pid1, pid2);
d811e0
+	printpid(tcp, pid1, PT_TGID);
d811e0
+	tprints(", ");
d811e0
+	printpid(tcp, pid2, PT_TGID);
d811e0
+	tprints(", ");
d811e0
 	printxval(kcmp_types, type, "KCMP_???");
d811e0
 
d811e0
 	switch (type) {
d811e0
Index: strace-5.7/linux/dummy.h
d811e0
===================================================================
d811e0
--- strace-5.7.orig/linux/dummy.h	2020-09-09 15:52:09.159983257 +0200
d811e0
+++ strace-5.7/linux/dummy.h	2020-09-09 15:55:03.982108299 +0200
d811e0
@@ -53,6 +53,7 @@
d811e0
 # define sys_getgid		sys_getuid
d811e0
 # define sys_getgid16		sys_getuid16
d811e0
 # define sys_getpeername		sys_getsockname
d811e0
+# define sys_getppid		sys_getpid
d811e0
 # define sys_getresgid		sys_getresuid
d811e0
 # define sys_getresgid16		sys_getresuid16
d811e0
 # define sys_lstat		sys_stat
d811e0
@@ -87,10 +88,6 @@
d811e0
 # define sys_vfork		sys_fork
d811e0
 
d811e0
 /* printargs does the right thing */
d811e0
-# define sys_getpgrp		printargs
d811e0
-# define sys_getpid		printargs
d811e0
-# define sys_getppid		printargs
d811e0
-# define sys_gettid		printargs
d811e0
 # define sys_idle		printargs
d811e0
 # define sys_munlockall		printargs
d811e0
 # define sys_pause		printargs
d811e0
@@ -108,10 +105,7 @@
d811e0
 
d811e0
 /* printargs_d does the right thing */
d811e0
 # define sys_exit		printargs_d
d811e0
-# define sys_getpgid		printargs_d
d811e0
-# define sys_getsid		printargs_d
d811e0
 # define sys_nice		printargs_d
d811e0
-# define sys_setpgid		printargs_d
d811e0
 # define sys_setpgrp		printargs_d
d811e0
 # define sys_timer_delete	printargs_d
d811e0
 # define sys_timer_getoverrun	printargs_d
d811e0
Index: strace-5.7/msghdr.c
d811e0
===================================================================
d811e0
--- strace-5.7.orig/msghdr.c	2020-09-09 15:52:09.159983257 +0200
d811e0
+++ strace-5.7/msghdr.c	2020-09-09 15:55:03.982108299 +0200
d811e0
@@ -69,7 +69,7 @@
d811e0
 {
d811e0
 	const struct ucred *uc = cmsg_data;
d811e0
 
d811e0
-	PRINT_FIELD_D("{", *uc, pid);
d811e0
+	PRINT_FIELD_TGID("{", *uc, pid, tcp);
d811e0
 	PRINT_FIELD_UID(", ", *uc, uid);
d811e0
 	PRINT_FIELD_UID(", ", *uc, gid);
d811e0
 	tprints("}");
d811e0
Index: strace-5.7/net.c
d811e0
===================================================================
d811e0
--- strace-5.7.orig/net.c	2020-09-09 15:52:09.159983257 +0200
d811e0
+++ strace-5.7/net.c	2020-09-09 15:55:03.982108299 +0200
d811e0
@@ -601,7 +601,7 @@
d811e0
 	if (umoven_or_printaddr(tcp, addr, len, &uc))
d811e0
 		return;
d811e0
 
d811e0
-	PRINT_FIELD_LEN("{", uc, pid, len, PRINT_FIELD_D);
d811e0
+	PRINT_FIELD_LEN("{", uc, pid, len, PRINT_FIELD_TGID, tcp);
d811e0
 	PRINT_FIELD_LEN(", ", uc, uid, len, PRINT_FIELD_UID);
d811e0
 	PRINT_FIELD_LEN(", ", uc, gid, len, PRINT_FIELD_UID);
d811e0
 	tprints("}");
d811e0
Index: strace-5.7/netlink.c
d811e0
===================================================================
d811e0
--- strace-5.7.orig/netlink.c	2020-09-09 15:52:09.159983257 +0200
d811e0
+++ strace-5.7/netlink.c	2020-09-09 15:55:03.982108299 +0200
d811e0
@@ -446,8 +446,9 @@
d811e0
 	decode_nlmsg_flags(nlmsghdr->nlmsg_flags,
d811e0
 			   nlmsghdr->nlmsg_type, family);
d811e0
 
d811e0
-	tprintf(", seq=%u, pid=%d}", nlmsghdr->nlmsg_seq,
d811e0
-		nlmsghdr->nlmsg_pid);
d811e0
+	tprintf(", seq=%u, pid=", nlmsghdr->nlmsg_seq);
d811e0
+	printpid(tcp, nlmsghdr->nlmsg_pid, PT_TGID);
d811e0
+	tprints("}");
d811e0
 }
d811e0
 
d811e0
 static bool
d811e0
Index: strace-5.7/numa.c
d811e0
===================================================================
d811e0
--- strace-5.7.orig/numa.c	2020-09-09 15:52:09.159983257 +0200
d811e0
+++ strace-5.7/numa.c	2020-09-09 15:55:03.982108299 +0200
d811e0
@@ -44,7 +44,8 @@
d811e0
 
d811e0
 SYS_FUNC(migrate_pages)
d811e0
 {
d811e0
-	tprintf("%d, %" PRI_klu ", ", (int) tcp->u_arg[0], tcp->u_arg[1]);
d811e0
+	printpid(tcp, tcp->u_arg[0], PT_TGID);
d811e0
+	tprintf(", %" PRI_klu ", ", tcp->u_arg[1]);
d811e0
 	print_nodemask(tcp, tcp->u_arg[2], tcp->u_arg[1]);
d811e0
 	tprints(", ");
d811e0
 	print_nodemask(tcp, tcp->u_arg[3], tcp->u_arg[1]);
d811e0
@@ -170,7 +171,8 @@
d811e0
 	kernel_ulong_t buf;
d811e0
 
d811e0
 	if (entering(tcp)) {
d811e0
-		tprintf("%d, %" PRI_klu ", ", (int) tcp->u_arg[0], npages);
d811e0
+		printpid(tcp, tcp->u_arg[0], PT_TGID);
d811e0
+		tprintf(", %" PRI_klu ", ", npages);
d811e0
 		print_array(tcp, tcp->u_arg[2], npages, &buf, current_wordsize,
d811e0
 			    tfetch_mem, print_addr, 0);
d811e0
 		tprints(", ");
d811e0
Index: strace-5.7/pidfd_open.c
d811e0
===================================================================
d811e0
--- strace-5.7.orig/pidfd_open.c	2020-09-09 15:52:09.159983257 +0200
d811e0
+++ strace-5.7/pidfd_open.c	2020-09-09 15:55:03.983108300 +0200
d811e0
@@ -10,7 +10,7 @@
d811e0
 SYS_FUNC(pidfd_open)
d811e0
 {
d811e0
 	/* pid_t pid */
d811e0
-	tprintf("%d", (int) tcp->u_arg[0]);
d811e0
+	printpid(tcp, tcp->u_arg[0], PT_TGID);
d811e0
 
d811e0
 	/* unsigned int flags */
d811e0
 	tprintf(", %#x", (unsigned int) tcp->u_arg[1]);
d811e0
Index: strace-5.7/print_fields.h
d811e0
===================================================================
d811e0
--- strace-5.7.orig/print_fields.h	2020-09-09 15:52:09.159983257 +0200
d811e0
+++ strace-5.7/print_fields.h	2020-09-09 15:55:03.983108300 +0200
d811e0
@@ -236,6 +236,30 @@
d811e0
 		printfd((tcp_), (where_).field_);			\
d811e0
 	} while (0)
d811e0
 
d811e0
+# define PRINT_FIELD_TID(prefix_, where_, field_, tcp_)			\
d811e0
+	do {								\
d811e0
+		STRACE_PRINTF("%s%s=", (prefix_), #field_);		\
d811e0
+		printpid((tcp_), (where_).field_, PT_TID);			\
d811e0
+	} while (0)
d811e0
+
d811e0
+# define PRINT_FIELD_TGID(prefix_, where_, field_, tcp_)			\
d811e0
+	do {								\
d811e0
+		STRACE_PRINTF("%s%s=", (prefix_), #field_);		\
d811e0
+		printpid((tcp_), (where_).field_, PT_TGID);			\
d811e0
+	} while (0)
d811e0
+
d811e0
+# define PRINT_FIELD_PGID(prefix_, where_, field_, tcp_)			\
d811e0
+	do {								\
d811e0
+		STRACE_PRINTF("%s%s=", (prefix_), #field_);		\
d811e0
+		printpid((tcp_), (where_).field_, PT_PGID);			\
d811e0
+	} while (0)
d811e0
+
d811e0
+# define PRINT_FIELD_SID(prefix_, where_, field_, tcp_)			\
d811e0
+	do {								\
d811e0
+		STRACE_PRINTF("%s%s=", (prefix_), #field_);		\
d811e0
+		printpid((tcp_), (where_).field_, PT_SID);			\
d811e0
+	} while (0)
d811e0
+
d811e0
 # define PRINT_FIELD_STRN(prefix_, where_, field_, len_, tcp_)		\
d811e0
 	do {								\
d811e0
 		STRACE_PRINTF("%s%s=", (prefix_), #field_);		\
d811e0
Index: strace-5.7/printsiginfo.c
d811e0
===================================================================
d811e0
--- strace-5.7.orig/printsiginfo.c	2020-09-09 15:52:09.159983257 +0200
d811e0
+++ strace-5.7/printsiginfo.c	2020-09-09 15:55:03.983108300 +0200
d811e0
@@ -58,7 +58,7 @@
d811e0
 static void
d811e0
 printsigsource(struct tcb *tcp, const siginfo_t *sip)
d811e0
 {
d811e0
-	PRINT_FIELD_D(", ", *sip, si_pid);
d811e0
+	PRINT_FIELD_TGID(", ", *sip, si_pid, tcp);
d811e0
 	PRINT_FIELD_UID(", ", *sip, si_uid);
d811e0
 }
d811e0
 
d811e0
Index: strace-5.7/process.c
d811e0
===================================================================
d811e0
--- strace-5.7.orig/process.c	2020-09-09 15:52:09.159983257 +0200
d811e0
+++ strace-5.7/process.c	2020-09-09 15:55:03.983108300 +0200
d811e0
@@ -92,7 +92,8 @@
d811e0
 		}
d811e0
 
d811e0
 		/* pid */
d811e0
-		tprintf(", %d", pid);
d811e0
+		tprints(", ");
d811e0
+		printpid(tcp, pid, PT_TGID);
d811e0
 
d811e0
 		/* addr */
d811e0
 		switch (request) {
d811e0
Index: strace-5.7/process_vm.c
d811e0
===================================================================
d811e0
--- strace-5.7.orig/process_vm.c	2020-09-09 15:52:09.159983257 +0200
d811e0
+++ strace-5.7/process_vm.c	2020-09-09 15:55:03.983108300 +0200
d811e0
@@ -13,7 +13,8 @@
d811e0
 {
d811e0
 	if (entering(tcp)) {
d811e0
 		/* arg 1: pid */
d811e0
-		tprintf("%d, ", (int) tcp->u_arg[0]);
d811e0
+		printpid(tcp, tcp->u_arg[0], PT_TGID);
d811e0
+		tprints(", ");
d811e0
 	} else {
d811e0
 		kernel_ulong_t local_iovcnt = tcp->u_arg[2];
d811e0
 		kernel_ulong_t remote_iovcnt = tcp->u_arg[4];
d811e0
@@ -42,7 +43,8 @@
d811e0
 	kernel_ulong_t flags = tcp->u_arg[5];
d811e0
 
d811e0
 	/* arg 1: pid */
d811e0
-	tprintf("%d, ", (int) tcp->u_arg[0]);
d811e0
+	printpid(tcp, tcp->u_arg[0], PT_TGID);
d811e0
+	tprints(", ");
d811e0
 	/* arg 2: local iov */
d811e0
 	tprint_iov(tcp, local_iovcnt, tcp->u_arg[1], IOV_DECODE_STR);
d811e0
 	/* arg 3: local iovcnt */
d811e0
Index: strace-5.7/resource.c
d811e0
===================================================================
d811e0
--- strace-5.7.orig/resource.c	2020-09-09 15:52:09.159983257 +0200
d811e0
+++ strace-5.7/resource.c	2020-09-09 15:55:03.984108300 +0200
d811e0
@@ -142,7 +142,8 @@
d811e0
 SYS_FUNC(prlimit64)
d811e0
 {
d811e0
 	if (entering(tcp)) {
d811e0
-		tprintf("%d, ", (int) tcp->u_arg[0]);
d811e0
+		printpid(tcp, tcp->u_arg[0], PT_TGID);
d811e0
+		tprints(", ");
d811e0
 		printxval(resources, tcp->u_arg[1], "RLIMIT_???");
d811e0
 		tprints(", ");
d811e0
 		print_rlimit64(tcp, tcp->u_arg[2]);
d811e0
@@ -179,10 +180,28 @@
d811e0
 
d811e0
 #include "xlat/priorities.h"
d811e0
 
d811e0
+static void
d811e0
+priority_print_who(struct tcb *tcp, int which, int who)
d811e0
+{
d811e0
+	switch (which)
d811e0
+	{
d811e0
+	case PRIO_PROCESS:
d811e0
+		printpid(tcp, who, PT_TGID);
d811e0
+		break;
d811e0
+	case PRIO_PGRP:
d811e0
+		printpid(tcp, who, PT_PGID);
d811e0
+		break;
d811e0
+	default:
d811e0
+		tprintf("%d", who);
d811e0
+		break;
d811e0
+	}
d811e0
+}
d811e0
+
d811e0
 SYS_FUNC(getpriority)
d811e0
 {
d811e0
 	printxval(priorities, tcp->u_arg[0], "PRIO_???");
d811e0
-	tprintf(", %d", (int) tcp->u_arg[1]);
d811e0
+	tprints(", ");
d811e0
+	priority_print_who(tcp, tcp->u_arg[0], tcp->u_arg[1]);
d811e0
 
d811e0
 	return RVAL_DECODED;
d811e0
 }
d811e0
@@ -190,7 +209,9 @@
d811e0
 SYS_FUNC(setpriority)
d811e0
 {
d811e0
 	printxval(priorities, tcp->u_arg[0], "PRIO_???");
d811e0
-	tprintf(", %d, %d", (int) tcp->u_arg[1], (int) tcp->u_arg[2]);
d811e0
+	tprints(", ");
d811e0
+	priority_print_who(tcp, tcp->u_arg[0], tcp->u_arg[1]);
d811e0
+	tprintf(", %d", (int) tcp->u_arg[2]);
d811e0
 
d811e0
 	return RVAL_DECODED;
d811e0
 }
d811e0
Index: strace-5.7/sched.c
d811e0
===================================================================
d811e0
--- strace-5.7.orig/sched.c	2020-09-09 15:52:09.159983257 +0200
d811e0
+++ strace-5.7/sched.c	2020-09-09 15:55:03.984108300 +0200
d811e0
@@ -21,7 +21,7 @@
d811e0
 SYS_FUNC(sched_getscheduler)
d811e0
 {
d811e0
 	if (entering(tcp)) {
d811e0
-		tprintf("%d", (int) tcp->u_arg[0]);
d811e0
+		printpid(tcp, tcp->u_arg[0], PT_TGID);
d811e0
 	} else if (!syserror(tcp)) {
d811e0
 		tcp->auxstr = xlookup(schedulers, (kernel_ulong_t) tcp->u_rval);
d811e0
 		return RVAL_STR;
d811e0
@@ -31,7 +31,8 @@
d811e0
 
d811e0
 SYS_FUNC(sched_setscheduler)
d811e0
 {
d811e0
-	tprintf("%d, ", (int) tcp->u_arg[0]);
d811e0
+	printpid(tcp, tcp->u_arg[0], PT_TGID);
d811e0
+	tprints(", ");
d811e0
 	printxval(schedulers, tcp->u_arg[1], "SCHED_???");
d811e0
 	tprints(", ");
d811e0
 	printnum_int(tcp, tcp->u_arg[2], "%d");
d811e0
@@ -41,16 +42,19 @@
d811e0
 
d811e0
 SYS_FUNC(sched_getparam)
d811e0
 {
d811e0
-	if (entering(tcp))
d811e0
-		tprintf("%d, ", (int) tcp->u_arg[0]);
d811e0
-	else
d811e0
+	if (entering(tcp)) {
d811e0
+		printpid(tcp, tcp->u_arg[0], PT_TGID);
d811e0
+		tprints(", ");
d811e0
+	} else {
d811e0
 		printnum_int(tcp, tcp->u_arg[1], "%d");
d811e0
+	}
d811e0
 	return 0;
d811e0
 }
d811e0
 
d811e0
 SYS_FUNC(sched_setparam)
d811e0
 {
d811e0
-	tprintf("%d, ", (int) tcp->u_arg[0]);
d811e0
+	printpid(tcp, tcp->u_arg[0], PT_TGID);
d811e0
+	tprints(", ");
d811e0
 	printnum_int(tcp, tcp->u_arg[1], "%d");
d811e0
 
d811e0
 	return RVAL_DECODED;
d811e0
@@ -68,7 +72,8 @@
d811e0
 			 const print_obj_by_addr_fn print_ts)
d811e0
 {
d811e0
 	if (entering(tcp)) {
d811e0
-		tprintf("%d, ", (int) tcp->u_arg[0]);
d811e0
+		printpid(tcp, tcp->u_arg[0], PT_TGID);
d811e0
+		tprints(", ");
d811e0
 	} else {
d811e0
 		if (syserror(tcp))
d811e0
 			printaddr(tcp->u_arg[1]);
d811e0
@@ -160,7 +165,8 @@
d811e0
 SYS_FUNC(sched_setattr)
d811e0
 {
d811e0
 	if (entering(tcp)) {
d811e0
-		tprintf("%d, ", (int) tcp->u_arg[0]);
d811e0
+		printpid(tcp, tcp->u_arg[0], PT_TGID);
d811e0
+		tprints(", ");
d811e0
 		print_sched_attr(tcp, tcp->u_arg[1], 0);
d811e0
 	} else {
d811e0
 		struct sched_attr attr;
d811e0
@@ -179,7 +185,8 @@
d811e0
 SYS_FUNC(sched_getattr)
d811e0
 {
d811e0
 	if (entering(tcp)) {
d811e0
-		tprintf("%d, ", (int) tcp->u_arg[0]);
d811e0
+		printpid(tcp, tcp->u_arg[0], PT_TGID);
d811e0
+		tprints(", ");
d811e0
 	} else {
d811e0
 		const unsigned int size = tcp->u_arg[2];
d811e0
 
d811e0
Index: strace-5.7/signal.c
d811e0
===================================================================
d811e0
--- strace-5.7.orig/signal.c	2020-09-09 15:52:09.159983257 +0200
d811e0
+++ strace-5.7/signal.c	2020-09-09 15:55:03.984108300 +0200
d811e0
@@ -439,7 +439,8 @@
d811e0
 SYS_FUNC(kill)
d811e0
 {
d811e0
 	/* pid */
d811e0
-	tprintf("%d, ", (int) tcp->u_arg[0]);
d811e0
+	printpid_tgid_pgid(tcp, tcp->u_arg[0]);
d811e0
+	tprints(", ");
d811e0
 	/* signal */
d811e0
 	printsignal(tcp->u_arg[1]);
d811e0
 
d811e0
@@ -448,7 +449,7 @@
d811e0
 
d811e0
 SYS_FUNC(tkill)
d811e0
 {
d811e0
-	tprintf("%d", (int) tcp->u_arg[0]);
d811e0
+	printpid(tcp, tcp->u_arg[0], PT_TID);
d811e0
 	tprints(", ");
d811e0
 	printsignal(tcp->u_arg[1]);
d811e0
 
d811e0
@@ -457,8 +458,12 @@
d811e0
 
d811e0
 SYS_FUNC(tgkill)
d811e0
 {
d811e0
-	/* tgid, tid */
d811e0
-	tprintf("%d, %d, ", (int) tcp->u_arg[0], (int) tcp->u_arg[1]);
d811e0
+	/* tgid */
d811e0
+	printpid(tcp, tcp->u_arg[0], PT_TGID);
d811e0
+	tprints(", ");
d811e0
+	/* tid */
d811e0
+	printpid(tcp, tcp->u_arg[1], PT_TID);
d811e0
+	tprints(", ");
d811e0
 	/* signal */
d811e0
 	printsignal(tcp->u_arg[2]);
d811e0
 
d811e0
@@ -624,7 +629,8 @@
d811e0
 
d811e0
 SYS_FUNC(rt_sigqueueinfo)
d811e0
 {
d811e0
-	tprintf("%d, ", (int) tcp->u_arg[0]);
d811e0
+	printpid(tcp, tcp->u_arg[0], PT_TGID);
d811e0
+	tprints(", ");
d811e0
 	print_sigqueueinfo(tcp, tcp->u_arg[1], tcp->u_arg[2]);
d811e0
 
d811e0
 	return RVAL_DECODED;
d811e0
@@ -632,7 +638,10 @@
d811e0
 
d811e0
 SYS_FUNC(rt_tgsigqueueinfo)
d811e0
 {
d811e0
-	tprintf("%d, %d, ", (int) tcp->u_arg[0], (int) tcp->u_arg[1]);
d811e0
+	printpid(tcp, tcp->u_arg[0], PT_TGID);
d811e0
+	tprints(", ");
d811e0
+	printpid(tcp, tcp->u_arg[1], PT_TID);
d811e0
+	tprints(", ");
d811e0
 	print_sigqueueinfo(tcp, tcp->u_arg[2], tcp->u_arg[3]);
d811e0
 
d811e0
 	return RVAL_DECODED;
d811e0
Index: strace-5.7/sockaddr.c
d811e0
===================================================================
d811e0
--- strace-5.7.orig/sockaddr.c	2020-09-09 15:52:09.159983257 +0200
d811e0
+++ strace-5.7/sockaddr.c	2020-09-09 15:55:03.984108300 +0200
d811e0
@@ -416,7 +416,7 @@
d811e0
 {
d811e0
 	const struct sockaddr_nl *const sa_nl = buf;
d811e0
 
d811e0
-	PRINT_FIELD_D("", *sa_nl, nl_pid);
d811e0
+	PRINT_FIELD_TGID("", *sa_nl, nl_pid, tcp);
d811e0
 	PRINT_FIELD_0X(", ", *sa_nl, nl_groups);
d811e0
 }
d811e0
 
d811e0
Index: strace-5.7/tests/kcmp.c
d811e0
===================================================================
d811e0
--- strace-5.7.orig/tests/kcmp.c	2020-09-09 15:52:09.159983257 +0200
d811e0
+++ strace-5.7/tests/kcmp.c	2020-09-09 18:49:06.780401433 +0200
d811e0
@@ -64,7 +64,26 @@
d811e0
 static void
d811e0
 printpidfd(const char *prefix, pid_t pid, unsigned fd)
d811e0
 {
d811e0
-	printf("%s%d", prefix, fd);
d811e0
+	const char *path = NULL;
d811e0
+
d811e0
+# if VERBOSE_FD
d811e0
+	if (pid == getpid()) {
d811e0
+		switch (fd)
d811e0
+		{
d811e0
+		case NULL_FD:
d811e0
+			path = null_path;
d811e0
+			break;
d811e0
+		case ZERO_FD:
d811e0
+			path = zero_path;
d811e0
+			break;
d811e0
+		}
d811e0
+	}
d811e0
+# endif
d811e0
+
d811e0
+	if (path)
d811e0
+		printf("%s%d<%s>", prefix, fd, path);
d811e0
+	else
d811e0
+		printf("%s%d", prefix, fd);
d811e0
 }
d811e0
 
d811e0
 /*
d811e0
@@ -179,7 +198,7 @@
d811e0
 	/* KCMP_FILE is the only type which has additional args */
d811e0
 	do_kcmp(3141592653U, 2718281828U, ARG_STR(KCMP_FILE), bogus_idx1,
d811e0
 		bogus_idx2);
d811e0
-	do_kcmp(-1, -1, ARG_STR(KCMP_FILE), NULL_FD, ZERO_FD);
d811e0
+	do_kcmp(getpid(), getpid(), ARG_STR(KCMP_FILE), NULL_FD, ZERO_FD);
d811e0
 
d811e0
 	/* Types without additional args */
d811e0
 	do_kcmp(-1, -1, ARG_STR(KCMP_VM), bogus_idx1, bogus_idx2);
d811e0
@@ -198,7 +217,7 @@
d811e0
 	for (i = 0; i < ARRAY_SIZE(slot_data); i++) {
d811e0
 		memcpy(slot, slot_data + i, sizeof(*slot));
d811e0
 
d811e0
-		do_kcmp(getpid(), getppid(), ARG_STR(KCMP_EPOLL_TFD), NULL_FD,
d811e0
+		do_kcmp(getpid(), -1, ARG_STR(KCMP_EPOLL_TFD), NULL_FD,
d811e0
 			(uintptr_t) slot, 1);
d811e0
 	}
d811e0
 
d811e0
Index: strace-5.7/util.c
d811e0
===================================================================
d811e0
--- strace-5.7.orig/util.c	2020-09-09 15:52:09.159983257 +0200
d811e0
+++ strace-5.7/util.c	2020-09-09 18:49:07.951402131 +0200
d811e0
@@ -392,6 +392,18 @@
d811e0
 	return true;
d811e0
 }
d811e0
 
d811e0
+bool
d811e0
+printnum_pid(struct tcb *const tcp, const kernel_ulong_t addr, enum pid_type type)
d811e0
+{
d811e0
+	int pid;
d811e0
+	if (umove_or_printaddr(tcp, addr, &pid))
d811e0
+		return false;
d811e0
+	tprints("[");
d811e0
+	printpid(tcp, pid, type);
d811e0
+	tprints("]");
d811e0
+	return true;
d811e0
+}
d811e0
+
d811e0
 /**
d811e0
  * Prints time to a (static internal) buffer and returns pointer to it.
d811e0
  * Returns NULL if the provided time specification is not correct.
d811e0
@@ -616,7 +628,7 @@
d811e0
 printfd_pid(struct tcb *tcp, pid_t pid, int fd)
d811e0
 {
d811e0
 	char path[PATH_MAX + 1];
d811e0
-	if (!number_set_array_is_empty(decode_fd_set, 0)
d811e0
+	if (pid > 0 && !number_set_array_is_empty(decode_fd_set, 0)
d811e0
 	    && getfdpath_pid(pid, fd, path, sizeof(path)) >= 0) {
d811e0
 		tprintf("%d<", (int) fd);
d811e0
 		if (is_number_in_set(DECODE_FD_SOCKET, decode_fd_set) &&
d811e0
@@ -641,12 +653,8 @@
d811e0
 void
d811e0
 printfd_pid_tracee_ns(struct tcb *tcp, pid_t pid, int fd)
d811e0
 {
d811e0
-	/*
d811e0
-	 * TODO: We want to have the same formatting as printfd here,
d811e0
-	 *       but we should figure out first which process in strace's
d811e0
-	 *       PID NS is referred to by pid in tracee's PID NS.
d811e0
-	 */
d811e0
-	tprintf("%d", fd);
d811e0
+	int strace_pid = translate_pid(tcp, pid, PT_TGID, NULL);
d811e0
+	printfd_pid(tcp, strace_pid, fd);
d811e0
 }
d811e0
 
d811e0
 /*
d811e0
Index: strace-5.7/wait.c
d811e0
===================================================================
d811e0
--- strace-5.7.orig/wait.c	2020-09-09 15:52:09.159983257 +0200
d811e0
+++ strace-5.7/wait.c	2020-09-09 15:55:03.985108301 +0200
d811e0
@@ -80,14 +80,8 @@
d811e0
 	   void (*const print_rusage)(struct tcb *, kernel_ulong_t))
d811e0
 {
d811e0
 	if (entering(tcp)) {
d811e0
-		/* On Linux, kernel-side pid_t is typedef'ed to int
d811e0
-		 * on all arches. Also, glibc-2.8 truncates wait3 and wait4
d811e0
-		 * pid argument to int on 64bit arches, producing,
d811e0
-		 * for example, wait4(4294967295, ...) instead of -1
d811e0
-		 * in strace. We have to use int here, not long.
d811e0
-		 */
d811e0
-		int pid = tcp->u_arg[0];
d811e0
-		tprintf("%d, ", pid);
d811e0
+		printpid_tgid_pgid(tcp, tcp->u_arg[0]);
d811e0
+		tprintf(", ");
d811e0
 	} else {
d811e0
 		int status;
d811e0
 
d811e0
@@ -108,7 +102,7 @@
d811e0
 				printaddr(tcp->u_arg[3]);
d811e0
 		}
d811e0
 	}
d811e0
-	return 0;
d811e0
+	return RVAL_TGID;
d811e0
 }
d811e0
 
d811e0
 SYS_FUNC(waitpid)
d811e0
@@ -134,10 +128,28 @@
d811e0
 
d811e0
 SYS_FUNC(waitid)
d811e0
 {
d811e0
+	unsigned int idtype = (unsigned int) tcp->u_arg[0];
d811e0
+	int id = tcp->u_arg[1];
d811e0
+
d811e0
 	if (entering(tcp)) {
d811e0
-		printxval(waitid_types, tcp->u_arg[0], "P_???");
d811e0
-		int pid = tcp->u_arg[1];
d811e0
-		tprintf(", %d, ", pid);
d811e0
+		printxval(waitid_types, idtype, "P_???");
d811e0
+		tprints(", ");
d811e0
+		switch (idtype)
d811e0
+		{
d811e0
+		case P_PID:
d811e0
+			printpid(tcp, id, PT_TGID);
d811e0
+			break;
d811e0
+		case P_PIDFD:
d811e0
+			printfd(tcp, id);
d811e0
+			break;
d811e0
+		case P_PGID:
d811e0
+			printpid(tcp, id, PT_PGID);
d811e0
+			break;
d811e0
+		default:
d811e0
+			tprintf("%d", id);
d811e0
+			break;
d811e0
+		}
d811e0
+		tprints(", ");
d811e0
 	} else {
d811e0
 		/* siginfo */
d811e0
 		printsiginfo_at(tcp, tcp->u_arg[2]);
d811e0
Index: strace-5.7/tests-m32/kcmp.c
d811e0
===================================================================
d811e0
--- strace-5.7.orig/tests-m32/kcmp.c	2020-09-09 15:52:09.159983257 +0200
d811e0
+++ strace-5.7/tests-m32/kcmp.c	2020-09-09 18:49:06.780401433 +0200
d811e0
@@ -64,7 +64,26 @@
d811e0
 static void
d811e0
 printpidfd(const char *prefix, pid_t pid, unsigned fd)
d811e0
 {
d811e0
-	printf("%s%d", prefix, fd);
d811e0
+	const char *path = NULL;
d811e0
+
d811e0
+# if VERBOSE_FD
d811e0
+	if (pid == getpid()) {
d811e0
+		switch (fd)
d811e0
+		{
d811e0
+		case NULL_FD:
d811e0
+			path = null_path;
d811e0
+			break;
d811e0
+		case ZERO_FD:
d811e0
+			path = zero_path;
d811e0
+			break;
d811e0
+		}
d811e0
+	}
d811e0
+# endif
d811e0
+
d811e0
+	if (path)
d811e0
+		printf("%s%d<%s>", prefix, fd, path);
d811e0
+	else
d811e0
+		printf("%s%d", prefix, fd);
d811e0
 }
d811e0
 
d811e0
 /*
d811e0
@@ -179,7 +198,7 @@
d811e0
 	/* KCMP_FILE is the only type which has additional args */
d811e0
 	do_kcmp(3141592653U, 2718281828U, ARG_STR(KCMP_FILE), bogus_idx1,
d811e0
 		bogus_idx2);
d811e0
-	do_kcmp(-1, -1, ARG_STR(KCMP_FILE), NULL_FD, ZERO_FD);
d811e0
+	do_kcmp(getpid(), getpid(), ARG_STR(KCMP_FILE), NULL_FD, ZERO_FD);
d811e0
 
d811e0
 	/* Types without additional args */
d811e0
 	do_kcmp(-1, -1, ARG_STR(KCMP_VM), bogus_idx1, bogus_idx2);
d811e0
@@ -198,7 +217,7 @@
d811e0
 	for (i = 0; i < ARRAY_SIZE(slot_data); i++) {
d811e0
 		memcpy(slot, slot_data + i, sizeof(*slot));
d811e0
 
d811e0
-		do_kcmp(getpid(), getppid(), ARG_STR(KCMP_EPOLL_TFD), NULL_FD,
d811e0
+		do_kcmp(getpid(), -1, ARG_STR(KCMP_EPOLL_TFD), NULL_FD,
d811e0
 			(uintptr_t) slot, 1);
d811e0
 	}
d811e0
 
d811e0
Index: strace-5.7/tests-mx32/kcmp.c
d811e0
===================================================================
d811e0
--- strace-5.7.orig/tests-mx32/kcmp.c	2020-09-09 15:52:09.159983257 +0200
d811e0
+++ strace-5.7/tests-mx32/kcmp.c	2020-09-09 18:49:06.780401433 +0200
d811e0
@@ -64,7 +64,26 @@
d811e0
 static void
d811e0
 printpidfd(const char *prefix, pid_t pid, unsigned fd)
d811e0
 {
d811e0
-	printf("%s%d", prefix, fd);
d811e0
+	const char *path = NULL;
d811e0
+
d811e0
+# if VERBOSE_FD
d811e0
+	if (pid == getpid()) {
d811e0
+		switch (fd)
d811e0
+		{
d811e0
+		case NULL_FD:
d811e0
+			path = null_path;
d811e0
+			break;
d811e0
+		case ZERO_FD:
d811e0
+			path = zero_path;
d811e0
+			break;
d811e0
+		}
d811e0
+	}
d811e0
+# endif
d811e0
+
d811e0
+	if (path)
d811e0
+		printf("%s%d<%s>", prefix, fd, path);
d811e0
+	else
d811e0
+		printf("%s%d", prefix, fd);
d811e0
 }
d811e0
 
d811e0
 /*
d811e0
@@ -179,7 +198,7 @@
d811e0
 	/* KCMP_FILE is the only type which has additional args */
d811e0
 	do_kcmp(3141592653U, 2718281828U, ARG_STR(KCMP_FILE), bogus_idx1,
d811e0
 		bogus_idx2);
d811e0
-	do_kcmp(-1, -1, ARG_STR(KCMP_FILE), NULL_FD, ZERO_FD);
d811e0
+	do_kcmp(getpid(), getpid(), ARG_STR(KCMP_FILE), NULL_FD, ZERO_FD);
d811e0
 
d811e0
 	/* Types without additional args */
d811e0
 	do_kcmp(-1, -1, ARG_STR(KCMP_VM), bogus_idx1, bogus_idx2);
d811e0
@@ -198,7 +217,7 @@
d811e0
 	for (i = 0; i < ARRAY_SIZE(slot_data); i++) {
d811e0
 		memcpy(slot, slot_data + i, sizeof(*slot));
d811e0
 
d811e0
-		do_kcmp(getpid(), getppid(), ARG_STR(KCMP_EPOLL_TFD), NULL_FD,
d811e0
+		do_kcmp(getpid(), -1, ARG_STR(KCMP_EPOLL_TFD), NULL_FD,
d811e0
 			(uintptr_t) slot, 1);
d811e0
 	}
d811e0
 
d811e0
Index: strace-5.7/Makefile.in
d811e0
===================================================================
d811e0
--- strace-5.7.orig/Makefile.in	2020-09-09 15:54:59.569105143 +0200
d811e0
+++ strace-5.7/Makefile.in	2020-09-09 19:06:15.159014394 +0200
d811e0
@@ -322,13 +322,13 @@
d811e0
 	flock.c flock.h fs_x_ioctl.c fsconfig.c fsmount.c fsopen.c \
d811e0
 	fspick.c fstatfs.c fstatfs64.c futex.c gcc_compat.h \
d811e0
 	get_personality.c get_personality.h get_robust_list.c getcpu.c \
d811e0
-	getcwd.c getpagesize.c getrandom.c hdio.c hostname.c inotify.c \
d811e0
-	inotify_ioctl.c io.c io_uring.c ioctl.c ioperm.c iopl.c \
d811e0
-	ioprio.c ipc.c ipc_defs.h ipc_msg.c ipc_msgctl.c ipc_sem.c \
d811e0
-	ipc_shm.c ipc_shmctl.c kcmp.c kernel_dirent.h kernel_rusage.h \
d811e0
-	kernel_timespec.h kernel_timeval.h kernel_timex.h \
d811e0
-	kernel_types.h kernel_v4l2_types.h kexec.c keyctl.c \
d811e0
-	keyctl_kdf_params.h kill_save_errno.h kvm.c \
d811e0
+	getcwd.c getpagesize.c getpid.c getrandom.c hdio.c hostname.c \
d811e0
+	inotify.c inotify_ioctl.c io.c io_uring.c ioctl.c ioperm.c \
d811e0
+	iopl.c ioprio.c ipc.c ipc_defs.h ipc_msg.c ipc_msgctl.c \
d811e0
+	ipc_sem.c ipc_shm.c ipc_shmctl.c kcmp.c kernel_dirent.h \
d811e0
+	kernel_rusage.h kernel_timespec.h kernel_timeval.h \
d811e0
+	kernel_timex.h kernel_types.h kernel_v4l2_types.h kexec.c \
d811e0
+	keyctl.c keyctl_kdf_params.h kill_save_errno.h kvm.c \
d811e0
 	largefile_wrappers.h ldt.c link.c linux/asm_stat.h \
d811e0
 	linux/x32/asm_stat.h linux/x86_64/asm_stat.h list.h listen.c \
d811e0
 	lookup_dcookie.c loop.c lseek.c macros.h mem.c membarrier.c \
d811e0
@@ -443,7 +443,7 @@
d811e0
 	libstrace_a-get_personality.$(OBJEXT) \
d811e0
 	libstrace_a-get_robust_list.$(OBJEXT) \
d811e0
 	libstrace_a-getcpu.$(OBJEXT) libstrace_a-getcwd.$(OBJEXT) \
d811e0
-	libstrace_a-getpagesize.$(OBJEXT) \
d811e0
+	libstrace_a-getpagesize.$(OBJEXT) libstrace_a-getpid.$(OBJEXT) \
d811e0
 	libstrace_a-getrandom.$(OBJEXT) libstrace_a-hdio.$(OBJEXT) \
d811e0
 	libstrace_a-hostname.$(OBJEXT) libstrace_a-inotify.$(OBJEXT) \
d811e0
 	libstrace_a-inotify_ioctl.$(OBJEXT) libstrace_a-io.$(OBJEXT) \
d811e0
@@ -769,6 +769,7 @@
d811e0
 	./$(DEPDIR)/libstrace_a-getcpu.Po \
d811e0
 	./$(DEPDIR)/libstrace_a-getcwd.Po \
d811e0
 	./$(DEPDIR)/libstrace_a-getpagesize.Po \
d811e0
+	./$(DEPDIR)/libstrace_a-getpid.Po \
d811e0
 	./$(DEPDIR)/libstrace_a-getrandom.Po \
d811e0
 	./$(DEPDIR)/libstrace_a-hdio.Po \
d811e0
 	./$(DEPDIR)/libstrace_a-hostname.Po \
d811e0
@@ -1810,13 +1811,13 @@
d811e0
 	flock.c flock.h fs_x_ioctl.c fsconfig.c fsmount.c fsopen.c \
d811e0
 	fspick.c fstatfs.c fstatfs64.c futex.c gcc_compat.h \
d811e0
 	get_personality.c get_personality.h get_robust_list.c getcpu.c \
d811e0
-	getcwd.c getpagesize.c getrandom.c hdio.c hostname.c inotify.c \
d811e0
-	inotify_ioctl.c io.c io_uring.c ioctl.c ioperm.c iopl.c \
d811e0
-	ioprio.c ipc.c ipc_defs.h ipc_msg.c ipc_msgctl.c ipc_sem.c \
d811e0
-	ipc_shm.c ipc_shmctl.c kcmp.c kernel_dirent.h kernel_rusage.h \
d811e0
-	kernel_timespec.h kernel_timeval.h kernel_timex.h \
d811e0
-	kernel_types.h kernel_v4l2_types.h kexec.c keyctl.c \
d811e0
-	keyctl_kdf_params.h kill_save_errno.h kvm.c \
d811e0
+	getcwd.c getpagesize.c getpid.c getrandom.c hdio.c hostname.c \
d811e0
+	inotify.c inotify_ioctl.c io.c io_uring.c ioctl.c ioperm.c \
d811e0
+	iopl.c ioprio.c ipc.c ipc_defs.h ipc_msg.c ipc_msgctl.c \
d811e0
+	ipc_sem.c ipc_shm.c ipc_shmctl.c kcmp.c kernel_dirent.h \
d811e0
+	kernel_rusage.h kernel_timespec.h kernel_timeval.h \
d811e0
+	kernel_timex.h kernel_types.h kernel_v4l2_types.h kexec.c \
d811e0
+	keyctl.c keyctl_kdf_params.h kill_save_errno.h kvm.c \
d811e0
 	largefile_wrappers.h ldt.c link.c linux/asm_stat.h \
d811e0
 	linux/x32/asm_stat.h linux/x86_64/asm_stat.h list.h listen.c \
d811e0
 	lookup_dcookie.c loop.c lseek.c macros.h mem.c membarrier.c \
d811e0
@@ -2835,6 +2836,7 @@
d811e0
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstrace_a-getcpu.Po@am__quote@ # am--include-marker
d811e0
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstrace_a-getcwd.Po@am__quote@ # am--include-marker
d811e0
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstrace_a-getpagesize.Po@am__quote@ # am--include-marker
d811e0
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstrace_a-getpid.Po@am__quote@ # am--include-marker
d811e0
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstrace_a-getrandom.Po@am__quote@ # am--include-marker
d811e0
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstrace_a-hdio.Po@am__quote@ # am--include-marker
d811e0
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstrace_a-hostname.Po@am__quote@ # am--include-marker
d811e0
@@ -5082,6 +5084,20 @@
d811e0
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
d811e0
 @am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstrace_a_CPPFLAGS) $(CPPFLAGS) $(libstrace_a_CFLAGS) $(CFLAGS) -c -o libstrace_a-getpagesize.obj `if test -f 'getpagesize.c'; then $(CYGPATH_W) 'getpagesize.c'; else $(CYGPATH_W) '$(srcdir)/getpagesize.c'; fi`
d811e0
 
d811e0
+libstrace_a-getpid.o: getpid.c
d811e0
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstrace_a_CPPFLAGS) $(CPPFLAGS) $(libstrace_a_CFLAGS) $(CFLAGS) -MT libstrace_a-getpid.o -MD -MP -MF $(DEPDIR)/libstrace_a-getpid.Tpo -c -o libstrace_a-getpid.o `test -f 'getpid.c' || echo '$(srcdir)/'`getpid.c
d811e0
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/libstrace_a-getpid.Tpo $(DEPDIR)/libstrace_a-getpid.Po
d811e0
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='getpid.c' object='libstrace_a-getpid.o' libtool=no @AMDEPBACKSLASH@
d811e0
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
d811e0
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstrace_a_CPPFLAGS) $(CPPFLAGS) $(libstrace_a_CFLAGS) $(CFLAGS) -c -o libstrace_a-getpid.o `test -f 'getpid.c' || echo '$(srcdir)/'`getpid.c
d811e0
+
d811e0
+libstrace_a-getpid.obj: getpid.c
d811e0
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstrace_a_CPPFLAGS) $(CPPFLAGS) $(libstrace_a_CFLAGS) $(CFLAGS) -MT libstrace_a-getpid.obj -MD -MP -MF $(DEPDIR)/libstrace_a-getpid.Tpo -c -o libstrace_a-getpid.obj `if test -f 'getpid.c'; then $(CYGPATH_W) 'getpid.c'; else $(CYGPATH_W) '$(srcdir)/getpid.c'; fi`
d811e0
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/libstrace_a-getpid.Tpo $(DEPDIR)/libstrace_a-getpid.Po
d811e0
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='getpid.c' object='libstrace_a-getpid.obj' libtool=no @AMDEPBACKSLASH@
d811e0
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
d811e0
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstrace_a_CPPFLAGS) $(CPPFLAGS) $(libstrace_a_CFLAGS) $(CFLAGS) -c -o libstrace_a-getpid.obj `if test -f 'getpid.c'; then $(CYGPATH_W) 'getpid.c'; else $(CYGPATH_W) '$(srcdir)/getpid.c'; fi`
d811e0
+
d811e0
 libstrace_a-getrandom.o: getrandom.c
d811e0
 @am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstrace_a_CPPFLAGS) $(CPPFLAGS) $(libstrace_a_CFLAGS) $(CFLAGS) -MT libstrace_a-getrandom.o -MD -MP -MF $(DEPDIR)/libstrace_a-getrandom.Tpo -c -o libstrace_a-getrandom.o `test -f 'getrandom.c' || echo '$(srcdir)/'`getrandom.c
d811e0
 @am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/libstrace_a-getrandom.Tpo $(DEPDIR)/libstrace_a-getrandom.Po
d811e0
@@ -8377,6 +8393,7 @@
d811e0
 	-rm -f ./$(DEPDIR)/libstrace_a-getcpu.Po
d811e0
 	-rm -f ./$(DEPDIR)/libstrace_a-getcwd.Po
d811e0
 	-rm -f ./$(DEPDIR)/libstrace_a-getpagesize.Po
d811e0
+	-rm -f ./$(DEPDIR)/libstrace_a-getpid.Po
d811e0
 	-rm -f ./$(DEPDIR)/libstrace_a-getrandom.Po
d811e0
 	-rm -f ./$(DEPDIR)/libstrace_a-hdio.Po
d811e0
 	-rm -f ./$(DEPDIR)/libstrace_a-hostname.Po
d811e0
@@ -8764,6 +8781,7 @@
d811e0
 	-rm -f ./$(DEPDIR)/libstrace_a-getcpu.Po
d811e0
 	-rm -f ./$(DEPDIR)/libstrace_a-getcwd.Po
d811e0
 	-rm -f ./$(DEPDIR)/libstrace_a-getpagesize.Po
d811e0
+	-rm -f ./$(DEPDIR)/libstrace_a-getpid.Po
d811e0
 	-rm -f ./$(DEPDIR)/libstrace_a-getrandom.Po
d811e0
 	-rm -f ./$(DEPDIR)/libstrace_a-hdio.Po
d811e0
 	-rm -f ./$(DEPDIR)/libstrace_a-hostname.Po