[PATCH v6 2/5] Use printpid in decoders
Dmitry V. Levin
ldv at altlinux.org
Fri Aug 7 19:43:24 UTC 2020
On Thu, Aug 06, 2020 at 09:02:08PM +0200, Ákos Uzonyi wrote:
> * getpid.c: New file.
> * Makefile.am (libstrace_a_SOURCES): Add getpid.c.
By the way, you can use a simpler form "Add it" instead of "Add getpid.c".
> diff --git a/get_robust_list.c b/get_robust_list.c
> index b5aebaff..4b771bac 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);
> + tprints(", ");
The explicit cast used to be need for tprintf, but I don't think
it's still useful in printpid calls like this one.
> diff --git a/ioprio.c b/ioprio.c
> index 873c8ce5..52144884 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]);
> + tprints(", ");
> + ioprio_print_who(tcp, (int) tcp->u_arg[0], (int) tcp->u_arg[1]);
Likewise, I don't think these explicit casts increase readability.
> 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]);
> + tprints(", ");
> + ioprio_print_who(tcp, (int) tcp->u_arg[0], (int) tcp->u_arg[1]);
> + tprints(", ");
Likewise.
> diff --git a/ipc_shmctl.c b/ipc_shmctl.c
> index 8c9e1e7a..71b41651 100644
> --- a/ipc_shmctl.c
> +++ b/ipc_shmctl.c
> @@ -12,6 +12,7 @@
> */
>
> #include "defs.h"
> +#include "print_fields.h"
>
> #include DEF_MPERS_TYPE(shmid_ds_t)
>
> @@ -53,8 +54,8 @@ print_shmid_ds(struct tcb *const tcp, const kernel_ulong_t addr, int cmd)
> PRINT_FIELD_UID(", ", shmid_ds.shm_perm, cgid);
> tprints("}");
> tprintf(", shm_segsz=%u", (unsigned) shmid_ds.shm_segsz);
> - PRINT_FIELD_D(", ", shmid_ds, shm_cpid);
> - PRINT_FIELD_D(", ", shmid_ds, shm_lpid);
> + PRINT_FIELD_TGID(", ", shmid_ds, shm_cpid, tcp);
> + PRINT_FIELD_TGID(", ", shmid_ds, shm_lpid, tcp);
> tprintf(", shm_nattch=%u", (unsigned) shmid_ds.shm_nattch);
> tprintf(", shm_atime=%u", (unsigned) shmid_ds.shm_atime);
> tprintf(", shm_dtime=%u", (unsigned) shmid_ds.shm_dtime);
The #include "print_fields.h" added here is probably a leftover from an
early edition.
> 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]);
Likewise, I don't think this explicit cast increases readability.
> 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);
Likewise.
> 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);
Likewise.
> diff --git a/process_vm.c b/process_vm.c
> index abee1e68..50acb3fd 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);
> + tprints(", ");
Likewise.
> } 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);
> + tprints(", ");
Likewise.
> diff --git a/resource.c b/resource.c
> index 53192ee9..bd21b748 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);
> + tprints(", ");
Likewise.
> 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);
Likewise.
> } 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(", ");
Likewise.
> 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 {
Likewise.
> 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(", ");
Likewise.
> 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(", ");
Likewise.
> } 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(", ");
Likewise.
> 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);
Likewise.
> @@ -448,7 +449,7 @@ SYS_FUNC(kill)
>
> SYS_FUNC(tkill)
> {
> - tprintf("%d", (int) tcp->u_arg[0]);
> + printpid(tcp, (int) tcp->u_arg[0], PT_TID);
Likewise.
> tprints(", ");
> printsignal(tcp->u_arg[1]);
>
> @@ -457,8 +458,12 @@ SYS_FUNC(tkill)
>
> 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);
> + tprints(", ");
> + /* tid */
> + printpid(tcp, (int) tcp->u_arg[1], PT_TID);
> + tprints(", ");
Likewise.
> /* signal */
> printsignal(tcp->u_arg[2]);
>
> @@ -624,7 +629,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);
> + tprints(", ");
Likewise.
> print_sigqueueinfo(tcp, tcp->u_arg[1], tcp->u_arg[2]);
>
> return RVAL_DECODED;
> @@ -632,7 +638,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);
> + tprints(", ");
> + printpid(tcp, (int) tcp->u_arg[1], PT_TID);
> + tprints(", ");
Likewise.
--
ldv
More information about the Strace-devel
mailing list