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 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. The name of the author may not be used to endorse or promote products
21 * derived from this software without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 #include "xlat/wait4_options.h"
41 #if !defined WCOREFLAG && defined WCOREFLG
42 # define WCOREFLAG WCOREFLG
45 # define WCOREFLAG 0x80
48 # define WCOREDUMP(status) ((status) & 0200)
51 # define W_STOPCODE(sig) ((sig) << 8 | 0x7f)
54 # define W_EXITCODE(ret, sig) ((ret) << 8 | (sig))
57 # define W_CONTINUED 0xffff
61 #include "xlat/ptrace_events.h"
64 printstatus(int status)
69 * Here is a tricky presentation problem. This solution
70 * is still not entirely satisfactory but since there
71 * are no wait status constructors it will have to do.
73 if (WIFSTOPPED(status)) {
74 int sig = WSTOPSIG(status);
75 tprintf("[{WIFSTOPPED(s) && WSTOPSIG(s) == %s%s}",
77 sig & 0x80 ? " | 0x80" : "");
78 status &= ~W_STOPCODE(sig);
80 else if (WIFSIGNALED(status)) {
81 tprintf("[{WIFSIGNALED(s) && WTERMSIG(s) == %s%s}",
82 signame(WTERMSIG(status)),
83 WCOREDUMP(status) ? " && WCOREDUMP(s)" : "");
84 status &= ~(W_EXITCODE(0, WTERMSIG(status)) | WCOREFLAG);
86 else if (WIFEXITED(status)) {
87 tprintf("[{WIFEXITED(s) && WEXITSTATUS(s) == %d}",
90 status &= ~W_EXITCODE(WEXITSTATUS(status), 0);
93 else if (WIFCONTINUED(status)) {
94 tprints("[{WIFCONTINUED(s)}");
95 status &= ~W_CONTINUED;
99 tprintf("[%#x]", status);
104 unsigned int event = (unsigned int) status >> 16;
107 printxval(ptrace_events, event, "PTRACE_EVENT_???");
112 tprintf(" | %#x", status);
120 printwaitn(struct tcb *tcp, void (*const print_rusage)(struct tcb *, long))
123 /* On Linux, kernel-side pid_t is typedef'ed to int
124 * on all arches. Also, glibc-2.8 truncates wait3 and wait4
125 * pid argument to int on 64bit arches, producing,
126 * for example, wait4(4294967295, ...) instead of -1
127 * in strace. We have to use int here, not long.
129 int pid = tcp->u_arg[0];
130 tprintf("%d, ", pid);
135 if (tcp->u_rval == 0)
136 printaddr(tcp->u_arg[1]);
137 else if (!umove_or_printaddr(tcp, tcp->u_arg[1], &status))
141 printflags(wait4_options, tcp->u_arg[2], "W???");
146 print_rusage(tcp, tcp->u_arg[3]);
148 printaddr(tcp->u_arg[3]);
156 return printwaitn(tcp, NULL);
161 return printwaitn(tcp, printrusage);
167 return printwaitn(tcp, printrusage32);
171 #include "xlat/waitid_types.h"
176 printxval(waitid_types, tcp->u_arg[0], "P_???");
177 int pid = tcp->u_arg[1];
178 tprintf(", %d, ", pid);
181 printsiginfo_at(tcp, tcp->u_arg[2]);
184 printflags(wait4_options, tcp->u_arg[3], "W???");
187 printrusage(tcp, tcp->u_arg[4]);