2 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4 * Copyright (c) 1993-1996 Rick Sladkey <jrs@world.std.com>
5 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
6 * Copyright (c) 2002-2004 Roland McGrath <roland@redhat.com>
7 * Copyright (c) 2004 Ulrich Drepper <drepper@redhat.com>
8 * Copyright (c) 2009-2013 Denys Vlasenko <dvlasenk@redhat.com>
9 * Copyright (c) 2014-2015 Dmitry V. Levin <ldv@altlinux.org>
10 * Copyright (c) 2014-2018 The strace developers.
11 * All rights reserved.
13 * SPDX-License-Identifier: LGPL-2.1-or-later
21 #include "xlat/wait4_options.h"
22 #include "xlat/ptrace_events.h"
25 printstatus(int status)
30 * Here is a tricky presentation problem. This solution
31 * is still not entirely satisfactory but since there
32 * are no wait status constructors it will have to do.
34 if (WIFSTOPPED(status)) {
35 int sig = WSTOPSIG(status);
36 tprintf("[{WIFSTOPPED(s) && WSTOPSIG(s) == %s%s}",
37 sprintsigname(sig & 0x7f),
38 sig & 0x80 ? " | 0x80" : "");
39 status &= ~W_STOPCODE(sig);
40 } else if (WIFSIGNALED(status)) {
41 tprintf("[{WIFSIGNALED(s) && WTERMSIG(s) == %s%s}",
42 sprintsigname(WTERMSIG(status)),
43 WCOREDUMP(status) ? " && WCOREDUMP(s)" : "");
44 status &= ~(W_EXITCODE(0, WTERMSIG(status)) | WCOREFLAG);
45 } else if (WIFEXITED(status)) {
46 tprintf("[{WIFEXITED(s) && WEXITSTATUS(s) == %d}",
49 status &= ~W_EXITCODE(WEXITSTATUS(status), 0);
52 else if (WIFCONTINUED(status)) {
53 tprints("[{WIFCONTINUED(s)}");
54 status &= ~W_CONTINUED;
58 tprintf("[%#x]", status);
63 unsigned int event = (unsigned int) status >> 16;
66 printxval(ptrace_events, event, "PTRACE_EVENT_???");
71 tprintf(" | %#x", status);
79 printwaitn(struct tcb *const tcp,
80 void (*const print_rusage)(struct tcb *, kernel_ulong_t))
83 /* On Linux, kernel-side pid_t is typedef'ed to int
84 * on all arches. Also, glibc-2.8 truncates wait3 and wait4
85 * pid argument to int on 64bit arches, producing,
86 * for example, wait4(4294967295, ...) instead of -1
87 * in strace. We have to use int here, not long.
89 int pid = tcp->u_arg[0];
96 printaddr(tcp->u_arg[1]);
97 else if (!umove_or_printaddr(tcp, tcp->u_arg[1], &status))
101 printflags(wait4_options, tcp->u_arg[2], "W???");
106 print_rusage(tcp, tcp->u_arg[3]);
108 printaddr(tcp->u_arg[3]);
116 return printwaitn(tcp, NULL);
121 return printwaitn(tcp, printrusage);
127 return printwaitn(tcp, printrusage32);
131 #include "xlat/waitid_types.h"
136 printxval(waitid_types, tcp->u_arg[0], "P_???");
137 int pid = tcp->u_arg[1];
138 tprintf(", %d, ", pid);
141 printsiginfo_at(tcp, tcp->u_arg[2]);
144 printflags(wait4_options, tcp->u_arg[3], "W???");
147 printrusage(tcp, tcp->u_arg[4]);