blob: 76d0deb7b57cfe73b83e1646b3e9a0c58d4e5772 [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
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, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00005 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
6 * Copyright (c) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation
7 * Linux for s390 port by D.J. Barrow
8 * <barrow_dj@mail.yahoo.com,djbarrow@de.ibm.com>
9 *
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000010 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
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.
22 *
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.
33 *
34 * $Id$
35 */
36
37#include "defs.h"
38
39#include <fcntl.h>
40#include <sys/stat.h>
41#include <sys/time.h>
42#include <sys/wait.h>
43#include <sys/resource.h>
44#include <sys/utsname.h>
45#include <sys/user.h>
46#include <sys/syscall.h>
47#include <signal.h>
48#ifdef SUNOS4
49#include <machine/reg.h>
50#endif /* SUNOS4 */
51
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000052#ifdef FREEBSD
53#include <sys/ptrace.h>
54#endif
55
Wichert Akkerman00a82ee2001-03-28 20:29:17 +000056#if HAVE_ASM_REG_H
57#ifdef SPARC
58# define fpq kernel_fpq
59# define fq kernel_fq
60# define fpu kernel_fpu
61#endif
62#include <asm/reg.h>
63#ifdef SPARC
64# undef fpq
65# undef fq
66# undef fpu
67#endif
68#endif /* HAVE_ASM_REG_H */
69
Wichert Akkerman36915a11999-07-13 15:45:02 +000070#ifdef HAVE_SYS_REG_H
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000071# include <sys/reg.h>
Wichert Akkerman15dea971999-10-06 13:06:34 +000072#ifndef PTRACE_PEEKUSR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000073# define PTRACE_PEEKUSR PTRACE_PEEKUSER
Wichert Akkerman15dea971999-10-06 13:06:34 +000074#endif
75#ifndef PTRACE_POKEUSR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000076# define PTRACE_POKEUSR PTRACE_POKEUSER
77#endif
Wichert Akkermanfaf72222000-02-19 23:59:03 +000078#elif defined(HAVE_LINUX_PTRACE_H)
79#undef PTRACE_SYSCALL
80#include <linux/ptrace.h>
Wichert Akkerman15dea971999-10-06 13:06:34 +000081#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000082
Wichert Akkermanfaf72222000-02-19 23:59:03 +000083
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000084#ifdef LINUX
Wichert Akkerman2e2553a1999-05-09 00:29:58 +000085#include <asm/posix_types.h>
86#undef GETGROUPS_T
87#define GETGROUPS_T __kernel_gid_t
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000088#endif /* LINUX */
89
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +000090#if defined(LINUX) && defined(IA64)
91# include <asm/ptrace_offsets.h>
92# include <asm/rse.h>
93#endif
94
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000095#ifdef HAVE_PRCTL
96#include <sys/prctl.h>
97#endif
98
99#ifndef WCOREDUMP
100#define WCOREDUMP(status) ((status) & 0200)
101#endif
102
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000103/* WTA: this was `&& !defined(LINUXSPARC)', this seems unneeded though? */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000104#if defined(HAVE_PRCTL)
105static struct xlat prctl_options[] = {
106#ifdef PR_MAXPROCS
107 { PR_MAXPROCS, "PR_MAXPROCS" },
108#endif
109#ifdef PR_ISBLOCKED
110 { PR_ISBLOCKED, "PR_ISBLOCKED" },
111#endif
112#ifdef PR_SETSTACKSIZE
113 { PR_SETSTACKSIZE, "PR_SETSTACKSIZE" },
114#endif
115#ifdef PR_GETSTACKSIZE
116 { PR_GETSTACKSIZE, "PR_GETSTACKSIZE" },
117#endif
118#ifdef PR_MAXPPROCS
119 { PR_MAXPPROCS, "PR_MAXPPROCS" },
120#endif
121#ifdef PR_UNBLKONEXEC
122 { PR_UNBLKONEXEC, "PR_UNBLKONEXEC" },
123#endif
124#ifdef PR_ATOMICSIM
125 { PR_ATOMICSIM, "PR_ATOMICSIM" },
126#endif
127#ifdef PR_SETEXITSIG
128 { PR_SETEXITSIG, "PR_SETEXITSIG" },
129#endif
130#ifdef PR_RESIDENT
131 { PR_RESIDENT, "PR_RESIDENT" },
132#endif
133#ifdef PR_ATTACHADDR
134 { PR_ATTACHADDR, "PR_ATTACHADDR" },
135#endif
136#ifdef PR_DETACHADDR
137 { PR_DETACHADDR, "PR_DETACHADDR" },
138#endif
139#ifdef PR_TERMCHILD
140 { PR_TERMCHILD, "PR_TERMCHILD" },
141#endif
142#ifdef PR_GETSHMASK
143 { PR_GETSHMASK, "PR_GETSHMASK" },
144#endif
145#ifdef PR_GETNSHARE
146 { PR_GETNSHARE, "PR_GETNSHARE" },
147#endif
148#if defined(PR_SET_PDEATHSIG)
149 { PR_SET_PDEATHSIG, "PR_SET_PDEATHSIG" },
150#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +0000151#ifdef PR_COREPID
152 { PR_COREPID, "PR_COREPID" },
153#endif
154#ifdef PR_ATTACHADDRPERM
155 { PR_ATTACHADDRPERM, "PR_ATTACHADDRPERM" },
156#endif
157#ifdef PR_PTHREADEXIT
158 { PR_PTHREADEXIT, "PR_PTHREADEXIT" },
159#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000160#ifdef PR_SET_PDEATHSIG
161 { PR_SET_PDEATHSIG, "PR_SET_PDEATHSIG" },
162#endif
163#ifdef PR_GET_PDEATHSIG
164 { PR_GET_PDEATHSIG, "PR_GET_PDEATHSIG" },
165#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000166#ifdef PR_GET_UNALIGN
167 { PR_GET_UNALIGN, "PR_GET_UNALIGN" },
168#endif
169#ifdef PR_SET_UNALIGN
170 { PR_SET_UNALIGN, "PR_SET_UNALIGN" },
171#endif
172#ifdef PR_GET_KEEPCAPS
173 { PR_GET_KEEPCAPS, "PR_GET_KEEP_CAPS" },
174#endif
175#ifdef PR_SET_KEEPCAPS
176 { PR_SET_KEEPCAPS, "PR_SET_KEEP_CAPS" },
177#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000178 { 0, NULL },
179};
180
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000181
182const char *
183unalignctl_string (unsigned int ctl)
184{
185 static char buf[16];
186
187 switch (ctl) {
188#ifdef PR_UNALIGN_NOPRINT
189 case PR_UNALIGN_NOPRINT:
190 return "NOPRINT";
191#endif
192#ifdef PR_UNALIGN_SIGBUS
193 case PR_UNALIGN_SIGBUS:
194 return "SIGBUS";
195#endif
196 default:
197 break;
198 }
199 sprintf(buf, "%x", ctl);
200 return buf;
201}
202
203
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000204int
205sys_prctl(tcp)
206struct tcb *tcp;
207{
208 int i;
209
210 if (entering(tcp)) {
211 printxval(prctl_options, tcp->u_arg[0], "PR_???");
212 switch (tcp->u_arg[0]) {
213#ifdef PR_GETNSHARE
214 case PR_GETNSHARE:
215 break;
216#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000217#ifdef PR_SET_DEATHSIG
218 case PR_GET_PDEATHSIG:
219 break;
220#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000221#ifdef PR_SET_UNALIGN
222 case PR_SET_UNALIGN:
223 tprintf(", %s", unalignctl_string(tcp->u_arg[1]));
224 break;
225#endif
226#ifdef PR_GET_UNALIGN
227 case PR_GET_UNALIGN:
228 tprintf(", %#lx", tcp->u_arg[1]);
229 break;
230#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000231 default:
232 for (i = 1; i < tcp->u_nargs; i++)
233 tprintf(", %#lx", tcp->u_arg[i]);
234 break;
235 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000236 } else {
237 switch (tcp->u_arg[0]) {
238#ifdef PR_GET_PDEATHSIG
239 case PR_GET_PDEATHSIG:
240 for (i=1; i<tcp->u_nargs; i++)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000241 tprintf(", %#lx", tcp->u_arg[i]);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000242 break;
243#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000244#ifdef PR_SET_UNALIGN
245 case PR_SET_UNALIGN:
246 break;
247#endif
248#ifdef PR_GET_UNALIGN
249 case PR_GET_UNALIGN:
250 {
251 int ctl;
252
253 umove(tcp, tcp->u_arg[1], &ctl);
254 tcp->auxstr = unalignctl_string(ctl);
255 return RVAL_STR;
256 }
257#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000258 default:
259 break;
260 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000261 }
262 return 0;
263}
264
265#endif /* HAVE_PRCTL */
266
267int
268sys_gethostid(tcp)
269struct tcb *tcp;
270{
271 if (exiting(tcp))
272 return RVAL_HEX;
273 return 0;
274}
275
276int
277sys_sethostname(tcp)
278struct tcb *tcp;
279{
280 if (entering(tcp)) {
281 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
282 tprintf(", %lu", tcp->u_arg[1]);
283 }
284 return 0;
285}
286
287int
288sys_gethostname(tcp)
289struct tcb *tcp;
290{
291 if (exiting(tcp)) {
292 if (syserror(tcp))
293 tprintf("%#lx", tcp->u_arg[0]);
294 else
295 printpath(tcp, tcp->u_arg[0]);
296 tprintf(", %lu", tcp->u_arg[1]);
297 }
298 return 0;
299}
300
301int
302sys_setdomainname(tcp)
303struct tcb *tcp;
304{
305 if (entering(tcp)) {
306 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
307 tprintf(", %lu", tcp->u_arg[1]);
308 }
309 return 0;
310}
311
Wichert Akkerman5daa0281999-03-15 19:49:42 +0000312#if !defined(LINUX)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000313
314int
315sys_getdomainname(tcp)
316struct tcb *tcp;
317{
318 if (exiting(tcp)) {
319 if (syserror(tcp))
320 tprintf("%#lx", tcp->u_arg[0]);
321 else
322 printpath(tcp, tcp->u_arg[0]);
323 tprintf(", %lu", tcp->u_arg[1]);
324 }
325 return 0;
326}
327#endif /* !LINUX */
328
329int
330sys_exit(tcp)
331struct tcb *tcp;
332{
333 if (exiting(tcp)) {
334 fprintf(stderr, "_exit returned!\n");
335 return -1;
336 }
337 /* special case: we stop tracing this process, finish line now */
338 tprintf("%ld) ", tcp->u_arg[0]);
339 tabto(acolumn);
340 tprintf("= ?");
341 printtrailer(tcp);
342 return 0;
343}
344
345int
346internal_exit(tcp)
347struct tcb *tcp;
348{
349 if (entering(tcp))
350 tcp->flags |= TCB_EXITING;
351 return 0;
352}
353
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000354#ifdef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000355
356int
357sys_fork(tcp)
358struct tcb *tcp;
359{
360 if (exiting(tcp)) {
361 if (getrval2(tcp)) {
362 tcp->auxstr = "child process";
363 return RVAL_UDECIMAL | RVAL_STR;
364 }
365 }
366 return 0;
367}
368
John Hughes4e36a812001-04-18 15:11:51 +0000369#if UNIXWARE > 2
370
371int
372sys_rfork(tcp)
373struct tcb *tcp;
374{
375 if (entering(tcp)) {
376 tprintf ("%ld", tcp->u_arg[0]);
377 }
378 else {
379 if (getrval2(tcp)) {
380 tcp->auxstr = "child process";
381 return RVAL_UDECIMAL | RVAL_STR;
382 }
383 }
384 return 0;
385}
386
387#endif
388
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000389int
390internal_fork(tcp)
391struct tcb *tcp;
392{
393 struct tcb *tcpchild;
394
395 if (exiting(tcp)) {
396 if (getrval2(tcp))
397 return 0;
398 if (!followfork)
399 return 0;
400 if (nprocs == MAX_PROCS) {
401 tcp->flags &= ~TCB_FOLLOWFORK;
402 fprintf(stderr, "sys_fork: tcb table full\n");
403 return 0;
404 }
405 else
406 tcp->flags |= TCB_FOLLOWFORK;
407 if (syserror(tcp))
408 return 0;
409 if ((tcpchild = alloctcb(tcp->u_rval)) == NULL) {
410 fprintf(stderr, "sys_fork: tcb table full\n");
411 return 0;
412 }
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +0000413 if (proc_open(tcpchild, 2) < 0)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000414 droptcb(tcpchild);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000415 }
416 return 0;
417}
418
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000419#else /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000420
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000421#ifdef LINUX
422
423/* defines copied from linux/sched.h since we can't include that
424 * ourselves (it conflicts with *lots* of libc includes)
425 */
426#define CSIGNAL 0x000000ff /* signal mask to be sent at exit */
427#define CLONE_VM 0x00000100 /* set if VM shared between processes */
428#define CLONE_FS 0x00000200 /* set if fs info shared between processes */
429#define CLONE_FILES 0x00000400 /* set if open files shared between processes */
430#define CLONE_SIGHAND 0x00000800 /* set if signal handlers shared */
431#define CLONE_PID 0x00001000 /* set if pid shared */
432#define CLONE_PTRACE 0x00002000 /* set if we want to let tracing continue on the child too */
433#define CLONE_VFORK 0x00004000 /* set if the parent wants the child to wake it up on mm_release */
434#define CLONE_PARENT 0x00008000 /* set if we want to have the same parent as the cloner */
435
436static struct xlat clone_flags[] = {
437 { CLONE_VM, "CLONE_VM" },
438 { CLONE_FS, "CLONE_FS" },
439 { CLONE_FILES, "CLONE_FILES" },
440 { CLONE_SIGHAND, "CLONE_SIGHAND" },
441 { CLONE_PID, "CLONE_PID" },
442 { CLONE_PTRACE, "CLONE_PTRACE" },
443 { CLONE_VFORK, "CLONE_VFORK" },
444 { CLONE_PARENT, "CLONE_PARENT" },
445 { 0, NULL },
446};
447
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000448int
449sys_clone(tcp)
450struct tcb *tcp;
451{
452 if (exiting(tcp)) {
453 tprintf("child_stack=%#lx, flags=", tcp->u_arg[1]);
454 if (printflags(clone_flags, tcp->u_arg[0]) == 0)
455 tprintf("0");
456 }
457 return 0;
458}
459
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000460#endif
461
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000462int
463sys_fork(tcp)
464struct tcb *tcp;
465{
466 if (exiting(tcp))
467 return RVAL_UDECIMAL;
468 return 0;
469}
470
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000471int
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000472change_syscall(tcp, new)
473struct tcb *tcp;
474int new;
475{
476#if defined(LINUX)
477#if defined(I386)
478 /* Attempt to make vfork into fork, which we can follow. */
479 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(ORIG_EAX * 4), new) < 0)
480 return -1;
481 return 0;
482#elif defined(POWERPC)
Wichert Akkerman5c4c69b2001-04-12 09:00:47 +0000483 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*PT_R0), new) < 0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000484 return -1;
485#elif defined(S390)
486 long pc;
487 if (upeek(tcp->pid, PT_PSWADDR,&pc)<0)
488 return -1;
489 if (ptrace(PTRACE_POKETEXT, tcp->pid, (char*)(pc-4), new)<0)
490 return -1;
491 return 0;
492#elif defined(M68K)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000493 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*PT_ORIG_D0), new)<0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000494 return -1;
495 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000496#elif defined(SPARC)
Wichert Akkerman00a82ee2001-03-28 20:29:17 +0000497 struct regs regs;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000498 if (ptrace(PTRACE_GETREGS, tcp->pid, (char*)&regs, 0)<0)
499 return -1;
Wichert Akkerman00a82ee2001-03-28 20:29:17 +0000500 regs.r_g1=new;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000501 if (ptrace(PTRACE_SETREGS, tcp->pid, (char*)&regs, 0)<0)
502 return -1;
503 return 0;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000504#elif defined(MIPS)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000505 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_V0), new)<0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000506 return -1;
507 return 0;
508#elif defined(ALPHA)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000509 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_A3), new)<0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000510 return -1;
511 return 0;
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000512#elif defined(HPPA)
513 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_GR20), new)<0)
514 return -1;
515 return 0;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000516#else
517#warning Do not know how to handle change_syscall for this architecture
518#endif /* architecture */
519#endif /* LINUX */
520 return -1;
521}
522
523int
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000524setarg(tcp, argnum)
525 struct tcb *tcp;
526 int argnum;
527{
528#if defined (IA64)
529 {
530 unsigned long *bsp, *ap;
531
532 if (upeek(tcp->pid, PT_AR_BSP, (long *) &bsp) , 0)
533 return -1;
534
535 ap = ia64_rse_skip_regs(bsp, argnum);
536 errno = 0;
537 ptrace(PTRACE_POKEDATA, tcp->pid, ap, tcp->u_arg[argnum]);
538 if (errno)
539 return -1;
540
541 }
Wichert Akkerman12f75d12000-02-14 16:23:40 +0000542#elif defined(I386)
543 {
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000544 ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*argnum), tcp->u_arg[argnum]);
Wichert Akkerman12f75d12000-02-14 16:23:40 +0000545 if (errno)
546 return -1;
547 }
Ralf Baechlee3816102000-08-01 00:06:06 +0000548#elif defined(MIPS)
549 {
550 errno = 0;
551 if (argnum < 4)
552 ptrace(PTRACE_POKEUSER, tcp->pid,
553 (char*)(REG_A0 + argnum), tcp->u_arg[argnum]);
554 else {
555 unsigned long *sp;
556
557 if (upeek(tcp->pid, REG_SP, (long *) &sp) , 0)
558 return -1;
559
560 ptrace(PTRACE_POKEDATA, tcp->pid,
561 (char*)(sp + argnum - 4), tcp->u_arg[argnum]);
562 }
563 if (errno)
564 return -1;
565 }
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000566#else
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000567# warning Sorry, setargs not implemented for this architecture.
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000568#endif
569 return 0;
570}
571
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000572#ifdef SYS_clone
573int
574internal_clone(tcp)
575struct tcb *tcp;
576{
Ulrich Drepper90512f01999-12-24 07:22:25 +0000577 struct tcb *tcpchild;
578 int pid;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000579 if (entering(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000580 if (!followfork)
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000581 return 0;
582 if (nprocs == MAX_PROCS) {
583 tcp->flags &= ~TCB_FOLLOWFORK;
584 fprintf(stderr, "sys_fork: tcb table full\n");
585 return 0;
586 }
587 tcp->flags |= TCB_FOLLOWFORK;
588
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000589
590 if (setbpt(tcp) < 0)
591 return 0;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000592 } else {
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000593 int bpt = tcp->flags & TCB_BPTSET;
594
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000595 if (!(tcp->flags & TCB_FOLLOWFORK))
596 return 0;
597
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000598 if (bpt)
599 clearbpt(tcp);
600
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000601 if (syserror(tcp))
602 return 0;
603
604 pid = tcp->u_rval;
605 if ((tcpchild = alloctcb(pid)) == NULL) {
606 fprintf(stderr, " [tcb table full]\n");
607 kill(pid, SIGKILL); /* XXX */
608 return 0;
609 }
610
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000611 /* Attach to the new child */
612 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) < 0) {
613 perror("PTRACE_ATTACH");
614 fprintf(stderr, "Too late?\n");
615 droptcb(tcpchild);
616 return 0;
617 }
618
Ulrich Drepper90512f01999-12-24 07:22:25 +0000619 tcpchild->flags |= TCB_ATTACHED;
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000620 if (bpt) {
621 tcpchild->flags |= TCB_BPTSET;
622 tcpchild->baddr = tcp->baddr;
623 memcpy(tcpchild->inst, tcp->inst,
624 sizeof tcpchild->inst);
625 }
Ulrich Drepper90512f01999-12-24 07:22:25 +0000626 newoutf(tcpchild);
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000627 tcp->nchildren++;
628 if (!qflag)
629 fprintf(stderr, "Process %d attached\n", pid);
630 }
631 return 0;
632}
633#endif
634
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000635int
636internal_fork(tcp)
637struct tcb *tcp;
638{
639 struct tcb *tcpchild;
640 int pid;
Nate Sammonsccd8f211999-03-29 22:57:54 +0000641 int dont_follow = 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000642
643#ifdef SYS_vfork
Nate Sammonsccd8f211999-03-29 22:57:54 +0000644 if (tcp->scno == SYS_vfork) {
Nate Sammonsccd8f211999-03-29 22:57:54 +0000645 /* Attempt to make vfork into fork, which we can follow. */
646 if (!followvfork ||
Pavel Machek9a9f10b2000-02-01 16:22:52 +0000647 change_syscall(tcp, SYS_fork) < 0)
Nate Sammonsccd8f211999-03-29 22:57:54 +0000648 dont_follow = 1;
Nate Sammonsccd8f211999-03-29 22:57:54 +0000649 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000650#endif
651 if (entering(tcp)) {
Nate Sammonsccd8f211999-03-29 22:57:54 +0000652 if (!followfork || dont_follow)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000653 return 0;
654 if (nprocs == MAX_PROCS) {
655 tcp->flags &= ~TCB_FOLLOWFORK;
656 fprintf(stderr, "sys_fork: tcb table full\n");
657 return 0;
658 }
659 tcp->flags |= TCB_FOLLOWFORK;
660 if (setbpt(tcp) < 0)
661 return 0;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000662 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000663 else {
664 int bpt = tcp->flags & TCB_BPTSET;
665
666 if (!(tcp->flags & TCB_FOLLOWFORK))
667 return 0;
668 if (bpt)
669 clearbpt(tcp);
670
671 if (syserror(tcp))
672 return 0;
673
674 pid = tcp->u_rval;
675 if ((tcpchild = alloctcb(pid)) == NULL) {
676 fprintf(stderr, " [tcb table full]\n");
677 kill(pid, SIGKILL); /* XXX */
678 return 0;
679 }
680#ifdef LINUX
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000681#ifdef HPPA
682 /* The child must have run before it can be attached. */
683 /* This must be a bug in the parisc kernel, but I havn't
684 * identified it yet. Seems to be an issue associated
685 * with attaching to a process (which sends it a signal)
686 * before that process has ever been scheduled. When
687 * debugging, I started seeing crashes in
688 * arch/parisc/kernel/signal.c:do_signal(), apparently
689 * caused by r8 getting corrupt over the dequeue_signal()
690 * call. Didn't make much sense though...
691 */
692 {
693 struct timeval tv;
694 tv.tv_sec = 0;
695 tv.tv_usec = 10000;
696 select(0, NULL, NULL, NULL, &tv);
697 }
698#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000699 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) < 0) {
700 perror("PTRACE_ATTACH");
701 fprintf(stderr, "Too late?\n");
702 droptcb(tcpchild);
703 return 0;
704 }
705#endif /* LINUX */
706#ifdef SUNOS4
707#ifdef oldway
708 /* The child must have run before it can be attached. */
709 {
710 struct timeval tv;
711 tv.tv_sec = 0;
712 tv.tv_usec = 10000;
713 select(0, NULL, NULL, NULL, &tv);
714 }
715 if (ptrace(PTRACE_ATTACH, pid, (char *)1, 0) < 0) {
716 perror("PTRACE_ATTACH");
717 fprintf(stderr, "Too late?\n");
718 droptcb(tcpchild);
719 return 0;
720 }
721#else /* !oldway */
722 /* Try to catch the new process as soon as possible. */
723 {
724 int i;
725 for (i = 0; i < 1024; i++)
726 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) >= 0)
727 break;
728 if (i == 1024) {
729 perror("PTRACE_ATTACH");
730 fprintf(stderr, "Too late?\n");
731 droptcb(tcpchild);
732 return 0;
733 }
734 }
735#endif /* !oldway */
736#endif /* SUNOS4 */
737 tcpchild->flags |= TCB_ATTACHED;
738 /* Child has BPT too, must be removed on first occasion */
739 if (bpt) {
740 tcpchild->flags |= TCB_BPTSET;
741 tcpchild->baddr = tcp->baddr;
742 memcpy(tcpchild->inst, tcp->inst,
743 sizeof tcpchild->inst);
744 }
745 newoutf(tcpchild);
746 tcpchild->parent = tcp;
747 tcp->nchildren++;
748 if (!qflag)
749 fprintf(stderr, "Process %d attached\n", pid);
750 }
751 return 0;
752}
753
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000754#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000755
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000756#if defined(SUNOS4) || defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000757
758int
759sys_vfork(tcp)
760struct tcb *tcp;
761{
762 if (exiting(tcp))
763 return RVAL_UDECIMAL;
764 return 0;
765}
766
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000767#endif /* SUNOS4 || LINUX || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000768
769#ifndef LINUX
770
771static char idstr[16];
772
773int
774sys_getpid(tcp)
775struct tcb *tcp;
776{
777 if (exiting(tcp)) {
778 sprintf(idstr, "ppid %lu", getrval2(tcp));
779 tcp->auxstr = idstr;
780 return RVAL_STR;
781 }
782 return 0;
783}
784
785int
786sys_getuid(tcp)
787struct tcb *tcp;
788{
789 if (exiting(tcp)) {
790 sprintf(idstr, "euid %lu", getrval2(tcp));
791 tcp->auxstr = idstr;
792 return RVAL_STR;
793 }
794 return 0;
795}
796
797int
798sys_getgid(tcp)
799struct tcb *tcp;
800{
801 if (exiting(tcp)) {
802 sprintf(idstr, "egid %lu", getrval2(tcp));
803 tcp->auxstr = idstr;
804 return RVAL_STR;
805 }
806 return 0;
807}
808
809#endif /* !LINUX */
810
811#ifdef LINUX
812
813int
814sys_setuid(tcp)
815struct tcb *tcp;
816{
817 if (entering(tcp)) {
818 tprintf("%u", (uid_t) tcp->u_arg[0]);
819 }
820 return 0;
821}
822
823int
824sys_setgid(tcp)
825struct tcb *tcp;
826{
827 if (entering(tcp)) {
828 tprintf("%u", (gid_t) tcp->u_arg[0]);
829 }
830 return 0;
831}
832
833int
834sys_getresuid(tcp)
835 struct tcb *tcp;
836{
837 if (exiting(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000838 __kernel_uid_t uid;
839 if (syserror(tcp))
840 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
841 tcp->u_arg[1], tcp->u_arg[2]);
842 else {
843 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
844 tprintf("%#lx, ", tcp->u_arg[0]);
845 else
846 tprintf("ruid %lu, ", (unsigned long) uid);
847 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
848 tprintf("%#lx, ", tcp->u_arg[0]);
849 else
850 tprintf("euid %lu, ", (unsigned long) uid);
851 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
852 tprintf("%#lx", tcp->u_arg[0]);
853 else
854 tprintf("suid %lu", (unsigned long) uid);
855 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000856 }
857 return 0;
858}
859
860int
861sys_getresgid(tcp)
862struct tcb *tcp;
863{
864 if (exiting(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000865 __kernel_gid_t gid;
866 if (syserror(tcp))
867 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
868 tcp->u_arg[1], tcp->u_arg[2]);
869 else {
870 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
871 tprintf("%#lx, ", tcp->u_arg[0]);
872 else
873 tprintf("rgid %lu, ", (unsigned long) gid);
874 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
875 tprintf("%#lx, ", tcp->u_arg[0]);
876 else
877 tprintf("egid %lu, ", (unsigned long) gid);
878 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
879 tprintf("%#lx", tcp->u_arg[0]);
880 else
881 tprintf("sgid %lu", (unsigned long) gid);
882 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000883 }
884 return 0;
885}
886
887#endif /* LINUX */
888
889int
890sys_setreuid(tcp)
891struct tcb *tcp;
892{
893 if (entering(tcp)) {
894 tprintf("%lu, %lu",
895 (unsigned long) (uid_t) tcp->u_arg[0],
896 (unsigned long) (uid_t) tcp->u_arg[1]);
897 }
898 return 0;
899}
900
901int
902sys_setregid(tcp)
903struct tcb *tcp;
904{
905 if (entering(tcp)) {
906 tprintf("%lu, %lu",
907 (unsigned long) (gid_t) tcp->u_arg[0],
908 (unsigned long) (gid_t) tcp->u_arg[1]);
909 }
910 return 0;
911}
912
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000913#if defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000914int
915sys_setresuid(tcp)
916 struct tcb *tcp;
917{
918 if (entering(tcp)) {
919 tprintf("ruid %u, euid %u, suid %u",
920 (uid_t) tcp->u_arg[0],
921 (uid_t) tcp->u_arg[1],
922 (uid_t) tcp->u_arg[2]);
923 }
924 return 0;
925}
926int
927sys_setresgid(tcp)
928 struct tcb *tcp;
929{
930 if (entering(tcp)) {
931 tprintf("rgid %u, egid %u, sgid %u",
932 (uid_t) tcp->u_arg[0],
933 (uid_t) tcp->u_arg[1],
934 (uid_t) tcp->u_arg[2]);
935 }
936 return 0;
937}
938
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000939#endif /* LINUX || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000940
941int
942sys_setgroups(tcp)
943struct tcb *tcp;
944{
945 int i, len;
946 GETGROUPS_T *gidset;
947
948 if (entering(tcp)) {
949 len = tcp->u_arg[0];
950 tprintf("%u, ", len);
951 if (len <= 0) {
952 tprintf("[]");
953 return 0;
954 }
955 gidset = (GETGROUPS_T *) malloc(len * sizeof(GETGROUPS_T));
956 if (gidset == NULL) {
957 fprintf(stderr, "sys_setgroups: out of memory\n");
958 return -1;
959 }
960 if (!verbose(tcp))
961 tprintf("%#lx", tcp->u_arg[1]);
962 else if (umoven(tcp, tcp->u_arg[1],
963 len * sizeof(GETGROUPS_T), (char *) gidset) < 0)
964 tprintf("[?]");
965 else {
966 tprintf("[");
967 for (i = 0; i < len; i++)
968 tprintf("%s%lu", i ? ", " : "",
969 (unsigned long) gidset[i]);
970 tprintf("]");
971 }
972 free((char *) gidset);
973 }
974 return 0;
975}
976
977int
978sys_getgroups(tcp)
979struct tcb *tcp;
980{
981 int i, len;
982 GETGROUPS_T *gidset;
983
984 if (entering(tcp)) {
985 len = tcp->u_arg[0];
986 tprintf("%u, ", len);
987 } else {
988 len = tcp->u_rval;
989 if (len <= 0) {
990 tprintf("[]");
991 return 0;
992 }
993 gidset = (GETGROUPS_T *) malloc(len * sizeof(GETGROUPS_T));
994 if (gidset == NULL) {
995 fprintf(stderr, "sys_getgroups: out of memory\n");
996 return -1;
997 }
998 if (!tcp->u_arg[1])
999 tprintf("NULL");
1000 else if (!verbose(tcp) || tcp->u_arg[0] == 0)
1001 tprintf("%#lx", tcp->u_arg[1]);
1002 else if (umoven(tcp, tcp->u_arg[1],
1003 len * sizeof(GETGROUPS_T), (char *) gidset) < 0)
1004 tprintf("[?]");
1005 else {
1006 tprintf("[");
1007 for (i = 0; i < len; i++)
1008 tprintf("%s%lu", i ? ", " : "",
1009 (unsigned long) gidset[i]);
1010 tprintf("]");
1011 }
1012 free((char *)gidset);
1013 }
1014 return 0;
1015}
1016
1017int
1018sys_setpgrp(tcp)
1019struct tcb *tcp;
1020{
1021 if (entering(tcp)) {
1022#ifndef SVR4
1023 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1024#endif /* !SVR4 */
1025 }
1026 return 0;
1027}
1028
1029int
1030sys_getpgrp(tcp)
1031struct tcb *tcp;
1032{
1033 if (entering(tcp)) {
1034#ifndef SVR4
1035 tprintf("%lu", tcp->u_arg[0]);
1036#endif /* !SVR4 */
1037 }
1038 return 0;
1039}
1040
1041int
1042sys_getsid(tcp)
1043struct tcb *tcp;
1044{
1045 if (entering(tcp)) {
1046 tprintf("%lu", tcp->u_arg[0]);
1047 }
1048 return 0;
1049}
1050
1051int
1052sys_setsid(tcp)
1053struct tcb *tcp;
1054{
1055 return 0;
1056}
1057
1058int
1059sys_getpgid(tcp)
1060struct tcb *tcp;
1061{
1062 if (entering(tcp)) {
1063 tprintf("%lu", tcp->u_arg[0]);
1064 }
1065 return 0;
1066}
1067
1068int
1069sys_setpgid(tcp)
1070struct tcb *tcp;
1071{
1072 if (entering(tcp)) {
1073 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1074 }
1075 return 0;
1076}
1077
1078void
1079fake_execve(tcp, program, argv, envp)
1080struct tcb *tcp;
1081char *program;
1082char *argv[];
1083char *envp[];
1084{
1085 int i;
1086
1087#ifdef ARM
1088 if (!(qual_flags[SYS_execve - __NR_SYSCALL_BASE] & QUAL_TRACE))
1089 return;
1090#else
1091 if (!(qual_flags[SYS_execve] & QUAL_TRACE))
1092 return;
1093#endif /* !ARM */
1094 printleader(tcp);
1095 tprintf("execve(");
1096 string_quote(program);
1097 tprintf(", [");
1098 for (i = 0; argv[i] != NULL; i++) {
1099 if (i != 0)
1100 tprintf(", ");
1101 string_quote(argv[i]);
1102 }
1103 for (i = 0; envp[i] != NULL; i++)
1104 ;
1105 tprintf("], [/* %d var%s */]) ", i, (i != 1) ? "s" : "");
1106 tabto(acolumn);
1107 tprintf("= 0");
1108 printtrailer(tcp);
1109}
1110
1111static void
1112printargv(tcp, addr)
1113struct tcb *tcp;
1114long addr;
1115{
1116 char *cp;
1117 char *sep;
1118 int max = max_strlen / 2;
1119
1120 for (sep = ""; --max >= 0; sep = ", ") {
1121 if (!abbrev(tcp))
1122 max++;
1123 if (umove(tcp, addr, &cp) < 0) {
1124 tprintf("%#lx", addr);
1125 return;
1126 }
1127 if (cp == 0)
1128 break;
1129 tprintf(sep);
1130 printstr(tcp, (long) cp, -1);
1131 addr += sizeof(char *);
1132 }
1133 if (cp)
1134 tprintf(", ...");
1135}
1136
1137static void
1138printargc(fmt, tcp, addr)
1139char *fmt;
1140struct tcb *tcp;
1141long addr;
1142{
1143 int count;
1144 char *cp;
1145
1146 for (count = 0; umove(tcp, addr, &cp) >= 0 && cp != NULL; count++) {
1147 addr += sizeof(char *);
1148 }
1149 tprintf(fmt, count, count == 1 ? "" : "s");
1150}
1151
1152int
1153sys_execv(tcp)
1154struct tcb *tcp;
1155{
1156 if (entering(tcp)) {
1157 printpath(tcp, tcp->u_arg[0]);
1158 if (!verbose(tcp))
1159 tprintf(", %#lx", tcp->u_arg[1]);
1160#if 0
1161 else if (abbrev(tcp))
1162 printargc(", [/* %d arg%s */]", tcp, tcp->u_arg[1]);
1163#endif
1164 else {
1165 tprintf(", [");
1166 printargv(tcp, tcp->u_arg[1]);
1167 tprintf("]");
1168 }
1169 }
1170 return 0;
1171}
1172
1173int
1174sys_execve(tcp)
1175struct tcb *tcp;
1176{
1177 if (entering(tcp)) {
1178 printpath(tcp, tcp->u_arg[0]);
1179 if (!verbose(tcp))
1180 tprintf(", %#lx", tcp->u_arg[1]);
1181#if 0
1182 else if (abbrev(tcp))
1183 printargc(", [/* %d arg%s */]", tcp, tcp->u_arg[1]);
1184#endif
1185 else {
1186 tprintf(", [");
1187 printargv(tcp, tcp->u_arg[1]);
1188 tprintf("]");
1189 }
1190 if (!verbose(tcp))
1191 tprintf(", %#lx", tcp->u_arg[2]);
1192 else if (abbrev(tcp))
1193 printargc(", [/* %d var%s */]", tcp, tcp->u_arg[2]);
1194 else {
1195 tprintf(", [");
1196 printargv(tcp, tcp->u_arg[2]);
1197 tprintf("]");
1198 }
1199 }
1200#ifdef LINUX
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001201#if defined(ALPHA) || defined(SPARC) || defined(POWERPC) || defined(HPPA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001202 tcp->flags |= TCB_WAITEXECVE;
1203#endif /* ALPHA || SPARC || POWERPC */
1204#endif /* LINUX */
1205 return 0;
1206}
1207
John Hughes4e36a812001-04-18 15:11:51 +00001208#if UNIXWARE > 2
1209
1210int sys_rexecve(tcp)
1211struct tcb *tcp;
1212{
1213 if (entering (tcp)) {
1214 sys_execve (tcp);
1215 tprintf (", %ld", tcp->u_arg[3]);
1216 }
1217 return 0;
1218}
1219
1220#endif
1221
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001222int
1223internal_exec(tcp)
1224struct tcb *tcp;
1225{
1226#ifdef SUNOS4
1227 if (exiting(tcp) && !syserror(tcp) && followfork)
1228 fixvfork(tcp);
1229#endif /* SUNOS4 */
1230 return 0;
1231}
1232
1233#ifdef LINUX
1234#ifndef __WCLONE
1235#define __WCLONE 0x8000000
1236#endif
1237#endif /* LINUX */
1238
1239static struct xlat wait4_options[] = {
1240 { WNOHANG, "WNOHANG" },
1241#ifndef WSTOPPED
1242 { WUNTRACED, "WUNTRACED" },
1243#endif
1244#ifdef WEXITED
1245 { WEXITED, "WEXITED" },
1246#endif
1247#ifdef WTRAPPED
1248 { WTRAPPED, "WTRAPPED" },
1249#endif
1250#ifdef WSTOPPED
1251 { WSTOPPED, "WSTOPPED" },
1252#endif
1253#ifdef WCONTINUED
1254 { WCONTINUED, "WCONTINUED" },
1255#endif
1256#ifdef WNOWAIT
1257 { WNOWAIT, "WNOWAIT" },
1258#endif
1259#ifdef __WCLONE
1260 { __WCLONE, "__WCLONE" },
1261#endif
1262 { 0, NULL },
1263};
1264
1265static int
1266printstatus(status)
1267int status;
1268{
1269 int exited = 0;
1270
1271 /*
1272 * Here is a tricky presentation problem. This solution
1273 * is still not entirely satisfactory but since there
1274 * are no wait status constructors it will have to do.
1275 */
1276 if (WIFSTOPPED(status))
1277 tprintf("[WIFSTOPPED(s) && WSTOPSIG(s) == %s]",
Nate Sammonsce780fc1999-03-29 23:23:13 +00001278 signame(WSTOPSIG(status)));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001279 else if WIFSIGNALED(status)
1280 tprintf("[WIFSIGNALED(s) && WTERMSIG(s) == %s%s]",
Nate Sammonsce780fc1999-03-29 23:23:13 +00001281 signame(WTERMSIG(status)),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001282 WCOREDUMP(status) ? " && WCOREDUMP(s)" : "");
1283 else if WIFEXITED(status) {
1284 tprintf("[WIFEXITED(s) && WEXITSTATUS(s) == %d]",
1285 WEXITSTATUS(status));
1286 exited = 1;
1287 }
1288 else
1289 tprintf("[%#x]", status);
1290 return exited;
1291}
1292
1293static int
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001294printwaitn(tcp, n, bitness)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001295struct tcb *tcp;
1296int n;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001297int bitness;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001298{
1299 int status;
1300 int exited = 0;
1301
1302 if (entering(tcp)) {
1303 tprintf("%ld, ", tcp->u_arg[0]);
1304 } else {
1305 /* status */
1306 if (!tcp->u_arg[1])
1307 tprintf("NULL");
1308 else if (syserror(tcp) || tcp->u_rval == 0)
1309 tprintf("%#lx", tcp->u_arg[1]);
1310 else if (umove(tcp, tcp->u_arg[1], &status) < 0)
1311 tprintf("[?]");
1312 else
1313 exited = printstatus(status);
1314 /* options */
1315 tprintf(", ");
1316 if (!printflags(wait4_options, tcp->u_arg[2]))
1317 tprintf("0");
1318 if (n == 4) {
1319 tprintf(", ");
1320 /* usage */
1321 if (!tcp->u_arg[3])
1322 tprintf("NULL");
1323#ifdef LINUX
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001324 else if (tcp->u_rval > 0) {
1325#ifdef LINUX_64BIT
1326 if (bitness)
1327 printrusage32(tcp, tcp->u_arg[3]);
1328 else
1329#endif
1330 printrusage(tcp, tcp->u_arg[3]);
1331 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001332#endif /* LINUX */
1333#ifdef SUNOS4
1334 else if (tcp->u_rval > 0 && exited)
1335 printrusage(tcp, tcp->u_arg[3]);
1336#endif /* SUNOS4 */
1337 else
1338 tprintf("%#lx", tcp->u_arg[3]);
1339 }
1340 }
1341 return 0;
1342}
1343
1344int
1345internal_wait(tcp)
1346struct tcb *tcp;
1347{
1348 if (entering(tcp)) {
Wichert Akkerman5daa0281999-03-15 19:49:42 +00001349 /* WTA: fix bug with hanging children */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001350 if (!(tcp->u_arg[2] & WNOHANG) && tcp->nchildren > 0) {
1351 /* There are traced children */
1352 tcp->flags |= TCB_SUSPENDED;
1353 tcp->waitpid = tcp->u_arg[0];
1354 }
1355 }
1356 return 0;
1357}
1358
1359#ifdef SVR4
1360
1361int
1362sys_wait(tcp)
1363struct tcb *tcp;
1364{
1365 if (exiting(tcp)) {
1366 /* The library wrapper stuffs this into the user variable. */
1367 if (!syserror(tcp))
1368 printstatus(getrval2(tcp));
1369 }
1370 return 0;
1371}
1372
1373#endif /* SVR4 */
1374
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001375#ifdef FREEBSD
1376int
1377sys_wait(tcp)
1378struct tcb *tcp;
1379{
1380 int status;
1381
1382 if (exiting(tcp)) {
1383 if (!syserror(tcp)) {
1384 if (umove(tcp, tcp->u_arg[0], &status) < 0)
1385 tprintf("%#lx", tcp->u_arg[0]);
1386 else
1387 printstatus(status);
1388 }
1389 }
1390 return 0;
1391}
1392#endif
1393
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001394int
1395sys_waitpid(tcp)
1396struct tcb *tcp;
1397{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001398 return printwaitn(tcp, 3, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001399}
1400
1401int
1402sys_wait4(tcp)
1403struct tcb *tcp;
1404{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001405 return printwaitn(tcp, 4, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001406}
1407
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001408#ifdef ALPHA
1409int
1410sys_osf_wait4(tcp)
1411struct tcb *tcp;
1412{
1413 return printwaitn(tcp, 4, 1);
1414}
1415#endif
1416
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001417#ifdef SVR4
1418
1419static struct xlat waitid_types[] = {
1420 { P_PID, "P_PID" },
1421 { P_PPID, "P_PPID" },
1422 { P_PGID, "P_PGID" },
1423 { P_SID, "P_SID" },
1424 { P_CID, "P_CID" },
1425 { P_UID, "P_UID" },
1426 { P_GID, "P_GID" },
1427 { P_ALL, "P_ALL" },
1428#ifdef P_LWPID
1429 { P_LWPID, "P_LWPID" },
1430#endif
1431 { 0, NULL },
1432};
1433
1434static struct xlat siginfo_codes[] = {
1435#ifdef SI_NOINFO
1436 { SI_NOINFO, "SI_NOINFO" },
1437#endif
1438#ifdef SI_USER
1439 { SI_USER, "SI_USER" },
1440#endif
1441#ifdef SI_LWP
1442 { SI_LWP, "SI_LWP" },
1443#endif
1444#ifdef SI_QUEUE
1445 { SI_QUEUE, "SI_QUEUE" },
1446#endif
1447#ifdef SI_TIMER
1448 { SI_TIMER, "SI_TIMER" },
1449#endif
1450#ifdef SI_ASYNCIO
1451 { SI_ASYNCIO, "SI_ASYNCIO" },
1452#endif
1453#ifdef SI_MESGQ
1454 { SI_MESGQ, "SI_MESGQ" },
1455#endif
1456 { 0, NULL },
1457};
1458
1459static struct xlat sigtrap_codes[] = {
1460 { TRAP_BRKPT, "TRAP_BRKPT" },
1461 { TRAP_TRACE, "TRAP_TRACE" },
1462 { 0, NULL },
1463};
1464
1465static struct xlat sigcld_codes[] = {
1466 { CLD_EXITED, "CLD_EXITED" },
1467 { CLD_KILLED, "CLD_KILLED" },
1468 { CLD_DUMPED, "CLD_DUMPED" },
1469 { CLD_TRAPPED, "CLD_TRAPPED" },
1470 { CLD_STOPPED, "CLD_STOPPED" },
1471 { CLD_CONTINUED,"CLD_CONTINUED" },
1472 { 0, NULL },
1473};
1474
1475static struct xlat sigpoll_codes[] = {
1476 { POLL_IN, "POLL_IN" },
1477 { POLL_OUT, "POLL_OUT" },
1478 { POLL_MSG, "POLL_MSG" },
1479 { POLL_ERR, "POLL_ERR" },
1480 { POLL_PRI, "POLL_PRI" },
1481 { POLL_HUP, "POLL_HUP" },
1482 { 0, NULL },
1483};
1484
1485static struct xlat sigprof_codes[] = {
1486#ifdef PROF_SIG
1487 { PROF_SIG, "PROF_SIG" },
1488#endif
1489 { 0, NULL },
1490};
1491
1492static struct xlat sigill_codes[] = {
1493 { ILL_ILLOPC, "ILL_ILLOPC" },
1494 { ILL_ILLOPN, "ILL_ILLOPN" },
1495 { ILL_ILLADR, "ILL_ILLADR" },
1496 { ILL_ILLTRP, "ILL_ILLTRP" },
1497 { ILL_PRVOPC, "ILL_PRVOPC" },
1498 { ILL_PRVREG, "ILL_PRVREG" },
1499 { ILL_COPROC, "ILL_COPROC" },
1500 { ILL_BADSTK, "ILL_BADSTK" },
1501 { 0, NULL },
1502};
1503
1504static struct xlat sigemt_codes[] = {
1505#ifdef EMT_TAGOVF
1506 { EMT_TAGOVF, "EMT_TAGOVF" },
1507#endif
1508 { 0, NULL },
1509};
1510
1511static struct xlat sigfpe_codes[] = {
1512 { FPE_INTDIV, "FPE_INTDIV" },
1513 { FPE_INTOVF, "FPE_INTOVF" },
1514 { FPE_FLTDIV, "FPE_FLTDIV" },
1515 { FPE_FLTOVF, "FPE_FLTOVF" },
1516 { FPE_FLTUND, "FPE_FLTUND" },
1517 { FPE_FLTRES, "FPE_FLTRES" },
1518 { FPE_FLTINV, "FPE_FLTINV" },
1519 { FPE_FLTSUB, "FPE_FLTSUB" },
1520 { 0, NULL },
1521};
1522
1523static struct xlat sigsegv_codes[] = {
1524 { SEGV_MAPERR, "SEGV_MAPERR" },
1525 { SEGV_ACCERR, "SEGV_ACCERR" },
1526 { 0, NULL },
1527};
1528
1529static struct xlat sigbus_codes[] = {
1530 { BUS_ADRALN, "BUS_ADRALN" },
1531 { BUS_ADRERR, "BUS_ADRERR" },
1532 { BUS_OBJERR, "BUS_OBJERR" },
1533 { 0, NULL },
1534};
1535
1536void
1537printsiginfo(sip)
1538siginfo_t *sip;
1539{
1540 char *code;
1541
1542 tprintf("{si_signo=");
1543 printsignal(sip->si_signo);
1544 code = xlookup(siginfo_codes, sip->si_code);
1545 if (!code) {
1546 switch (sip->si_signo) {
1547 case SIGTRAP:
1548 code = xlookup(sigtrap_codes, sip->si_code);
1549 break;
1550 case SIGCHLD:
1551 code = xlookup(sigcld_codes, sip->si_code);
1552 break;
1553 case SIGPOLL:
1554 code = xlookup(sigpoll_codes, sip->si_code);
1555 break;
1556 case SIGPROF:
1557 code = xlookup(sigprof_codes, sip->si_code);
1558 break;
1559 case SIGILL:
1560 code = xlookup(sigill_codes, sip->si_code);
1561 break;
1562 case SIGEMT:
1563 code = xlookup(sigemt_codes, sip->si_code);
1564 break;
1565 case SIGFPE:
1566 code = xlookup(sigfpe_codes, sip->si_code);
1567 break;
1568 case SIGSEGV:
1569 code = xlookup(sigsegv_codes, sip->si_code);
1570 break;
1571 case SIGBUS:
1572 code = xlookup(sigbus_codes, sip->si_code);
1573 break;
1574 }
1575 }
1576 if (code)
1577 tprintf(", si_code=%s", code);
1578 else
1579 tprintf(", si_code=%#x", sip->si_code);
1580#ifdef SI_NOINFO
1581 if (sip->si_code != SI_NOINFO) {
1582#endif
1583 if (sip->si_errno) {
1584 if (sip->si_errno < 0 || sip->si_errno >= nerrnos)
1585 tprintf(", si_errno=%d", sip->si_errno);
1586 else
1587 tprintf(", si_errno=%s",
1588 errnoent[sip->si_errno]);
1589 }
1590 if (SI_FROMUSER(sip)) {
1591#ifdef SI_QUEUE
1592 tprintf(", si_pid=%ld, si_uid=%ld",
1593 sip->si_pid, sip->si_uid);
1594 switch (sip->si_code) {
1595 case SI_QUEUE:
1596#ifdef SI_TIMER
1597 case SI_TIMER:
1598#endif /* SI_QUEUE */
1599 case SI_ASYNCIO:
1600#ifdef SI_MESGQ
1601 case SI_MESGQ:
1602#endif /* SI_MESGQ */
1603 tprintf(", si_value=%d",
1604 sip->si_value.sival_int);
1605 break;
1606 }
1607#endif /* SI_QUEUE */
1608 }
1609 else {
1610 switch (sip->si_signo) {
1611 case SIGCHLD:
1612 tprintf(", si_pid=%ld, si_status=",
1613 sip->si_pid);
1614 if (sip->si_code == CLD_EXITED)
1615 tprintf("%d", sip->si_status);
1616 else
1617 printsignal(sip->si_status);
1618 break;
1619 case SIGILL: case SIGFPE:
1620 case SIGSEGV: case SIGBUS:
1621 tprintf(", si_addr=%#lx",
1622 (unsigned long) sip->si_addr);
1623 break;
1624 case SIGPOLL:
1625 switch (sip->si_code) {
1626 case POLL_IN: case POLL_OUT: case POLL_MSG:
1627 tprintf(", si_band=%ld",
1628 (long) sip->si_band);
1629 break;
1630 }
1631 break;
1632 }
1633 }
1634 tprintf(", ...");
1635#ifdef SI_NOINFO
1636 }
1637#endif
1638 tprintf("}");
1639}
1640
1641int
1642sys_waitid(tcp)
1643struct tcb *tcp;
1644{
1645 siginfo_t si;
1646 int exited;
1647
1648 if (entering(tcp)) {
1649 printxval(waitid_types, tcp->u_arg[0], "P_???");
1650 tprintf(", %ld, ", tcp->u_arg[1]);
1651 if (tcp->nchildren > 0) {
1652 /* There are traced children */
1653 tcp->flags |= TCB_SUSPENDED;
1654 tcp->waitpid = tcp->u_arg[0];
1655 }
1656 }
1657 else {
1658 /* siginfo */
1659 exited = 0;
1660 if (!tcp->u_arg[2])
1661 tprintf("NULL");
1662 else if (syserror(tcp))
1663 tprintf("%#lx", tcp->u_arg[2]);
1664 else if (umove(tcp, tcp->u_arg[2], &si) < 0)
1665 tprintf("{???}");
1666 else
1667 printsiginfo(&si);
1668 /* options */
1669 tprintf(", ");
1670 if (!printflags(wait4_options, tcp->u_arg[3]))
1671 tprintf("0");
1672 }
1673 return 0;
1674}
1675
1676#endif /* SVR4 */
1677
1678int
1679sys_alarm(tcp)
1680struct tcb *tcp;
1681{
1682 if (entering(tcp))
1683 tprintf("%lu", tcp->u_arg[0]);
1684 return 0;
1685}
1686
1687int
1688sys_uname(tcp)
1689struct tcb *tcp;
1690{
1691 struct utsname uname;
1692
1693 if (exiting(tcp)) {
1694 if (syserror(tcp) || !verbose(tcp))
1695 tprintf("%#lx", tcp->u_arg[0]);
1696 else if (umove(tcp, tcp->u_arg[0], &uname) < 0)
1697 tprintf("{...}");
1698 else if (!abbrev(tcp)) {
1699
1700 tprintf("{sysname=\"%s\", nodename=\"%s\", ",
1701 uname.sysname, uname.nodename);
1702 tprintf("release=\"%s\", version=\"%s\", ",
1703 uname.release, uname.version);
1704 tprintf("machine=\"%s\"", uname.machine);
1705#ifdef LINUX
1706#ifndef __GLIBC__
1707 tprintf(", domainname=\"%s\"", uname.domainname);
1708#endif /* __GLIBC__ */
1709#endif /* LINUX */
1710 tprintf("}");
1711 }
1712 else
1713 tprintf("{sys=\"%s\", node=\"%s\", ...}",
1714 uname.sysname, uname.nodename);
1715 }
1716 return 0;
1717}
1718
1719#ifndef SVR4
1720
1721static struct xlat ptrace_cmds[] = {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001722#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001723 { PTRACE_TRACEME, "PTRACE_TRACEME" },
1724 { PTRACE_PEEKTEXT, "PTRACE_PEEKTEXT", },
1725 { PTRACE_PEEKDATA, "PTRACE_PEEKDATA", },
1726 { PTRACE_PEEKUSER, "PTRACE_PEEKUSER", },
1727 { PTRACE_POKETEXT, "PTRACE_POKETEXT", },
1728 { PTRACE_POKEDATA, "PTRACE_POKEDATA", },
1729 { PTRACE_POKEUSER, "PTRACE_POKEUSER", },
1730 { PTRACE_CONT, "PTRACE_CONT" },
1731 { PTRACE_KILL, "PTRACE_KILL" },
1732 { PTRACE_SINGLESTEP, "PTRACE_SINGLESTEP" },
1733 { PTRACE_ATTACH, "PTRACE_ATTACH" },
1734 { PTRACE_DETACH, "PTRACE_DETACH" },
1735#ifdef SUNOS4
1736 { PTRACE_GETREGS, "PTRACE_GETREGS" },
1737 { PTRACE_SETREGS, "PTRACE_SETREGS" },
1738 { PTRACE_GETFPREGS, "PTRACE_GETFPREGS", },
1739 { PTRACE_SETFPREGS, "PTRACE_SETFPREGS", },
1740 { PTRACE_READDATA, "PTRACE_READDATA" },
1741 { PTRACE_WRITEDATA, "PTRACE_WRITEDATA" },
1742 { PTRACE_READTEXT, "PTRACE_READTEXT" },
1743 { PTRACE_WRITETEXT, "PTRACE_WRITETEXT" },
1744 { PTRACE_GETFPAREGS, "PTRACE_GETFPAREGS" },
1745 { PTRACE_SETFPAREGS, "PTRACE_SETFPAREGS" },
1746#ifdef SPARC
1747 { PTRACE_GETWINDOW, "PTRACE_GETWINDOW" },
1748 { PTRACE_SETWINDOW, "PTRACE_SETWINDOW" },
1749#else /* !SPARC */
1750 { PTRACE_22, "PTRACE_PTRACE_22" },
1751 { PTRACE_23, "PTRACE_PTRACE_23" },
1752#endif /* !SPARC */
1753#endif /* SUNOS4 */
1754 { PTRACE_SYSCALL, "PTRACE_SYSCALL" },
1755#ifdef SUNOS4
1756 { PTRACE_DUMPCORE, "PTRACE_DUMPCORE" },
1757#ifdef I386
1758 { PTRACE_SETWRBKPT, "PTRACE_SETWRBKPT" },
1759 { PTRACE_SETACBKPT, "PTRACE_SETACBKPT" },
1760 { PTRACE_CLRDR7, "PTRACE_CLRDR7" },
1761#else /* !I386 */
1762 { PTRACE_26, "PTRACE_26" },
1763 { PTRACE_27, "PTRACE_27" },
1764 { PTRACE_28, "PTRACE_28" },
1765#endif /* !I386 */
1766 { PTRACE_GETUCODE, "PTRACE_GETUCODE" },
1767#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001768#else /* FREEBSD */
1769 { PT_TRACE_ME, "PT_TRACE_ME" },
1770 { PT_READ_I, "PT_READ_I" },
1771 { PT_READ_D, "PT_READ_D" },
1772 { PT_WRITE_I, "PT_WRITE_I" },
1773 { PT_WRITE_D, "PT_WRITE_D" },
1774 { PT_READ_U, "PT_WRITE_U" },
1775 { PT_CONTINUE, "PT_CONTINUE" },
1776 { PT_KILL, "PT_KILL" },
1777 { PT_STEP, "PT_STEP" },
1778 { PT_ATTACH, "PT_ATTACH" },
1779 { PT_DETACH, "PT_DETACH" },
1780 { PT_GETREGS, "PT_GETREGS" },
1781 { PT_SETREGS, "PT_SETREGS" },
1782 { PT_GETFPREGS, "PT_GETFPREGS" },
1783 { PT_SETFPREGS, "PT_SETFPREGS" },
1784 { PT_GETDBREGS, "PT_GETDBREGS" },
1785 { PT_SETDBREGS, "PT_SETDBREGS" },
1786#endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001787 { 0, NULL },
1788};
1789
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001790#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001791#ifndef SUNOS4_KERNEL_ARCH_KLUDGE
1792static
1793#endif /* !SUNOS4_KERNEL_ARCH_KLUDGE */
1794struct xlat struct_user_offsets[] = {
1795#ifdef LINUX
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001796#ifdef S390
1797 { PT_PSWMASK, "psw_mask" },
1798 { PT_PSWADDR, "psw_addr" },
1799 { PT_GPR0, "gpr0" },
1800 { PT_GPR1, "gpr1" },
1801 { PT_GPR2, "gpr2" },
1802 { PT_GPR3, "gpr3" },
1803 { PT_GPR4, "gpr4" },
1804 { PT_GPR5, "gpr5" },
1805 { PT_GPR6, "gpr6" },
1806 { PT_GPR7, "gpr7" },
1807 { PT_GPR8, "gpr8" },
1808 { PT_GPR9, "gpr9" },
1809 { PT_GPR10, "gpr10" },
1810 { PT_GPR11, "gpr11" },
1811 { PT_GPR12, "gpr12" },
1812 { PT_GPR13, "gpr13" },
1813 { PT_GPR14, "gpr14" },
1814 { PT_GPR15, "gpr15" },
1815 { PT_ACR0, "acr0" },
1816 { PT_ACR1, "acr1" },
1817 { PT_ACR2, "acr2" },
1818 { PT_ACR3, "acr3" },
1819 { PT_ACR4, "acr4" },
1820 { PT_ACR5, "acr5" },
1821 { PT_ACR6, "acr6" },
1822 { PT_ACR7, "acr7" },
1823 { PT_ACR8, "acr8" },
1824 { PT_ACR9, "acr9" },
1825 { PT_ACR10, "acr10" },
1826 { PT_ACR11, "acr11" },
1827 { PT_ACR12, "acr12" },
1828 { PT_ACR13, "acr13" },
1829 { PT_ACR14, "acr14" },
1830 { PT_ACR15, "acr15" },
1831 { PT_ORIGGPR2, "orig_gpr2" },
1832 { PT_FPC, "fpc" },
1833 { PT_FPR0_HI, "fpr0.hi" },
1834 { PT_FPR0_LO, "fpr0.lo" },
1835 { PT_FPR1_HI, "fpr1.hi" },
1836 { PT_FPR1_LO, "fpr1.lo" },
1837 { PT_FPR2_HI, "fpr2.hi" },
1838 { PT_FPR2_LO, "fpr2.lo" },
1839 { PT_FPR3_HI, "fpr3.hi" },
1840 { PT_FPR3_LO, "fpr3.lo" },
1841 { PT_FPR4_HI, "fpr4.hi" },
1842 { PT_FPR4_LO, "fpr4.lo" },
1843 { PT_FPR5_HI, "fpr5.hi" },
1844 { PT_FPR5_LO, "fpr5.lo" },
1845 { PT_FPR6_HI, "fpr6.hi" },
1846 { PT_FPR6_LO, "fpr6.lo" },
1847 { PT_FPR7_HI, "fpr7.hi" },
1848 { PT_FPR7_LO, "fpr7.lo" },
1849 { PT_FPR8_HI, "fpr8.hi" },
1850 { PT_FPR8_LO, "fpr8.lo" },
1851 { PT_FPR9_HI, "fpr9.hi" },
1852 { PT_FPR9_LO, "fpr9.lo" },
1853 { PT_FPR10_HI, "fpr10.hi" },
1854 { PT_FPR10_LO, "fpr10.lo" },
1855 { PT_FPR11_HI, "fpr11.hi" },
1856 { PT_FPR11_LO, "fpr11.lo" },
1857 { PT_FPR12_HI, "fpr12.hi" },
1858 { PT_FPR12_LO, "fpr12.lo" },
1859 { PT_FPR13_HI, "fpr13.hi" },
1860 { PT_FPR13_LO, "fpr13.lo" },
1861 { PT_FPR14_HI, "fpr14.hi" },
1862 { PT_FPR14_LO, "fpr14.lo" },
1863 { PT_FPR15_HI, "fpr15.hi" },
1864 { PT_FPR15_LO, "fpr15.lo" },
1865 { PT_CR_9, "cr9" },
1866 { PT_CR_10, "cr10" },
1867 { PT_CR_11, "cr11" },
1868#endif
1869#if defined(SPARC)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001870 /* XXX No support for these offsets yet. */
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001871#elif defined(HPPA)
1872 /* XXX No support for these offsets yet. */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001873#elif defined(POWERPC)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001874 { 4*PT_R0, "4*PT_R0" },
1875 { 4*PT_R1, "4*PT_R1" },
1876 { 4*PT_R2, "4*PT_R2" },
1877 { 4*PT_R3, "4*PT_R3" },
1878 { 4*PT_R4, "4*PT_R4" },
1879 { 4*PT_R5, "4*PT_R5" },
1880 { 4*PT_R6, "4*PT_R6" },
1881 { 4*PT_R7, "4*PT_R7" },
1882 { 4*PT_R8, "4*PT_R8" },
1883 { 4*PT_R9, "4*PT_R9" },
1884 { 4*PT_R10, "4*PT_R10" },
1885 { 4*PT_R11, "4*PT_R11" },
1886 { 4*PT_R12, "4*PT_R12" },
1887 { 4*PT_R13, "4*PT_R13" },
1888 { 4*PT_R14, "4*PT_R14" },
1889 { 4*PT_R15, "4*PT_R15" },
1890 { 4*PT_R16, "4*PT_R16" },
1891 { 4*PT_R17, "4*PT_R17" },
1892 { 4*PT_R18, "4*PT_R18" },
1893 { 4*PT_R19, "4*PT_R19" },
1894 { 4*PT_R20, "4*PT_R20" },
1895 { 4*PT_R21, "4*PT_R21" },
1896 { 4*PT_R22, "4*PT_R22" },
1897 { 4*PT_R23, "4*PT_R23" },
1898 { 4*PT_R24, "4*PT_R24" },
1899 { 4*PT_R25, "4*PT_R25" },
1900 { 4*PT_R26, "4*PT_R26" },
1901 { 4*PT_R27, "4*PT_R27" },
1902 { 4*PT_R28, "4*PT_R28" },
1903 { 4*PT_R29, "4*PT_R29" },
1904 { 4*PT_R30, "4*PT_R30" },
1905 { 4*PT_R31, "4*PT_R31" },
1906 { 4*PT_NIP, "4*PT_NIP" },
1907 { 4*PT_MSR, "4*PT_MSR" },
1908 { 4*PT_ORIG_R3, "4*PT_ORIG_R3" },
1909 { 4*PT_CTR, "4*PT_CTR" },
1910 { 4*PT_LNK, "4*PT_LNK" },
1911 { 4*PT_XER, "4*PT_XER" },
1912 { 4*PT_CCR, "4*PT_CCR" },
1913 { 4*PT_FPR0, "4*PT_FPR0" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001914#else
1915#ifdef ALPHA
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001916 { 0, "r0" },
1917 { 1, "r1" },
1918 { 2, "r2" },
1919 { 3, "r3" },
1920 { 4, "r4" },
1921 { 5, "r5" },
1922 { 6, "r6" },
1923 { 7, "r7" },
1924 { 8, "r8" },
1925 { 9, "r9" },
1926 { 10, "r10" },
1927 { 11, "r11" },
1928 { 12, "r12" },
1929 { 13, "r13" },
1930 { 14, "r14" },
1931 { 15, "r15" },
1932 { 16, "r16" },
1933 { 17, "r17" },
1934 { 18, "r18" },
1935 { 19, "r19" },
1936 { 20, "r20" },
1937 { 21, "r21" },
1938 { 22, "r22" },
1939 { 23, "r23" },
1940 { 24, "r24" },
1941 { 25, "r25" },
1942 { 26, "r26" },
1943 { 27, "r27" },
1944 { 28, "r28" },
1945 { 29, "gp" },
1946 { 30, "fp" },
1947 { 31, "zero" },
1948 { 32, "fp0" },
1949 { 33, "fp" },
1950 { 34, "fp2" },
1951 { 35, "fp3" },
1952 { 36, "fp4" },
1953 { 37, "fp5" },
1954 { 38, "fp6" },
1955 { 39, "fp7" },
1956 { 40, "fp8" },
1957 { 41, "fp9" },
1958 { 42, "fp10" },
1959 { 43, "fp11" },
1960 { 44, "fp12" },
1961 { 45, "fp13" },
1962 { 46, "fp14" },
1963 { 47, "fp15" },
1964 { 48, "fp16" },
1965 { 49, "fp17" },
1966 { 50, "fp18" },
1967 { 51, "fp19" },
1968 { 52, "fp20" },
1969 { 53, "fp21" },
1970 { 54, "fp22" },
1971 { 55, "fp23" },
1972 { 56, "fp24" },
1973 { 57, "fp25" },
1974 { 58, "fp26" },
1975 { 59, "fp27" },
1976 { 60, "fp28" },
1977 { 61, "fp29" },
1978 { 62, "fp30" },
1979 { 63, "fp31" },
1980 { 64, "pc" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001981#else /* !ALPHA */
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001982#ifdef IA64
1983 { PT_F32, "f32" }, { PT_F33, "f33" }, { PT_F34, "f34" },
1984 { PT_F35, "f35" }, { PT_F36, "f36" }, { PT_F37, "f37" },
1985 { PT_F38, "f38" }, { PT_F39, "f39" }, { PT_F40, "f40" },
1986 { PT_F41, "f41" }, { PT_F42, "f42" }, { PT_F43, "f43" },
1987 { PT_F44, "f44" }, { PT_F45, "f45" }, { PT_F46, "f46" },
1988 { PT_F47, "f47" }, { PT_F48, "f48" }, { PT_F49, "f49" },
1989 { PT_F50, "f50" }, { PT_F51, "f51" }, { PT_F52, "f52" },
1990 { PT_F53, "f53" }, { PT_F54, "f54" }, { PT_F55, "f55" },
1991 { PT_F56, "f56" }, { PT_F57, "f57" }, { PT_F58, "f58" },
1992 { PT_F59, "f59" }, { PT_F60, "f60" }, { PT_F61, "f61" },
1993 { PT_F62, "f62" }, { PT_F63, "f63" }, { PT_F64, "f64" },
1994 { PT_F65, "f65" }, { PT_F66, "f66" }, { PT_F67, "f67" },
1995 { PT_F68, "f68" }, { PT_F69, "f69" }, { PT_F70, "f70" },
1996 { PT_F71, "f71" }, { PT_F72, "f72" }, { PT_F73, "f73" },
1997 { PT_F74, "f74" }, { PT_F75, "f75" }, { PT_F76, "f76" },
1998 { PT_F77, "f77" }, { PT_F78, "f78" }, { PT_F79, "f79" },
1999 { PT_F80, "f80" }, { PT_F81, "f81" }, { PT_F82, "f82" },
2000 { PT_F83, "f83" }, { PT_F84, "f84" }, { PT_F85, "f85" },
2001 { PT_F86, "f86" }, { PT_F87, "f87" }, { PT_F88, "f88" },
2002 { PT_F89, "f89" }, { PT_F90, "f90" }, { PT_F91, "f91" },
2003 { PT_F92, "f92" }, { PT_F93, "f93" }, { PT_F94, "f94" },
2004 { PT_F95, "f95" }, { PT_F96, "f96" }, { PT_F97, "f97" },
2005 { PT_F98, "f98" }, { PT_F99, "f99" }, { PT_F100, "f100" },
2006 { PT_F101, "f101" }, { PT_F102, "f102" }, { PT_F103, "f103" },
2007 { PT_F104, "f104" }, { PT_F105, "f105" }, { PT_F106, "f106" },
2008 { PT_F107, "f107" }, { PT_F108, "f108" }, { PT_F109, "f109" },
2009 { PT_F110, "f110" }, { PT_F111, "f111" }, { PT_F112, "f112" },
2010 { PT_F113, "f113" }, { PT_F114, "f114" }, { PT_F115, "f115" },
2011 { PT_F116, "f116" }, { PT_F117, "f117" }, { PT_F118, "f118" },
2012 { PT_F119, "f119" }, { PT_F120, "f120" }, { PT_F121, "f121" },
2013 { PT_F122, "f122" }, { PT_F123, "f123" }, { PT_F124, "f124" },
2014 { PT_F125, "f125" }, { PT_F126, "f126" }, { PT_F127, "f127" },
2015 /* switch stack: */
2016 { PT_F2, "f2" }, { PT_F3, "f3" }, { PT_F4, "f4" },
2017 { PT_F5, "f5" }, { PT_F10, "f10" }, { PT_F11, "f11" },
2018 { PT_F12, "f12" }, { PT_F13, "f13" }, { PT_F14, "f14" },
2019 { PT_F15, "f15" }, { PT_F16, "f16" }, { PT_F17, "f17" },
2020 { PT_F18, "f18" }, { PT_F19, "f19" }, { PT_F20, "f20" },
2021 { PT_F21, "f21" }, { PT_F22, "f22" }, { PT_F23, "f23" },
2022 { PT_F24, "f24" }, { PT_F25, "f25" }, { PT_F26, "f26" },
2023 { PT_F27, "f27" }, { PT_F28, "f28" }, { PT_F29, "f29" },
2024 { PT_F30, "f30" }, { PT_F31, "f31" }, { PT_R4, "r4" },
2025 { PT_R5, "r5" }, { PT_R6, "r6" }, { PT_R7, "r7" },
2026 { PT_K_B0, "kb0" },
2027 { PT_B1, "b1" }, { PT_B2, "b2" }, { PT_B3, "b3" },
2028 { PT_B4, "b4" }, { PT_B5, "b5" },
2029 { PT_K_AR_PFS, "kar.pfs" },
2030 { PT_AR_LC, "ar.lc" }, { PT_K_AR_UNAT, "kar.unat" },
2031 { PT_K_AR_RNAT, "kar.rnat" }, { PT_K_AR_BSPSTORE, "kar.bspstore" },
2032 { PT_K_PR, "k.pr" },
2033 /* pt_regs */
2034 { PT_CR_IPSR, "cr.ipsr" }, { PT_CR_IIP, "cr.iip" },
2035 { PT_CR_IFS, "cr.ifs" }, { PT_AR_UNAT, "ar.unat" },
2036 { PT_AR_PFS, "ar.pfs" }, { PT_AR_RSC, "ar.rsc" },
2037 { PT_AR_RNAT, "ar.rnat" }, { PT_AR_BSPSTORE, "ar.bspstore" },
2038 { PT_PR, "pr" }, { PT_B6, "b6" }, { PT_AR_BSP, "ar.bsp" },
2039 { PT_R1, "r1" }, { PT_R2, "r2" }, { PT_R3, "r3" },
2040 { PT_R12, "r12" }, { PT_R13, "r13" }, { PT_R14, "r14" },
2041 { PT_R15, "r15" }, { PT_R8, "r8" }, { PT_R9, "r9" },
2042 { PT_R10, "r10" }, { PT_R11, "r11" }, { PT_R16, "r16" },
2043 { PT_R17, "r17" }, { PT_R18, "r18" }, { PT_R19, "r19" },
2044 { PT_R20, "r20" }, { PT_R21, "r21" }, { PT_R22, "r22" },
2045 { PT_R23, "r23" }, { PT_R24, "r24" }, { PT_R25, "r25" },
2046 { PT_R26, "r26" }, { PT_R27, "r27" }, { PT_R28, "r28" },
2047 { PT_R29, "r29" }, { PT_R30, "r30" }, { PT_R31, "r31" },
2048 { PT_AR_CCV, "ar.ccv" }, { PT_AR_FPSR, "ar.fpsr" },
2049 { PT_B0, "b0" }, { PT_B7, "b7" }, { PT_F6, "f6" },
2050 { PT_F7, "f7" }, { PT_F8, "f8" }, { PT_F9, "f9" },
2051#else /* !IA64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002052#ifdef I386
2053 { 4*EBX, "4*EBX" },
2054 { 4*ECX, "4*ECX" },
2055 { 4*EDX, "4*EDX" },
2056 { 4*ESI, "4*ESI" },
2057 { 4*EDI, "4*EDI" },
2058 { 4*EBP, "4*EBP" },
2059 { 4*EAX, "4*EAX" },
2060 { 4*DS, "4*DS" },
2061 { 4*ES, "4*ES" },
2062 { 4*FS, "4*FS" },
2063 { 4*GS, "4*GS" },
2064 { 4*ORIG_EAX, "4*ORIG_EAX" },
2065 { 4*EIP, "4*EIP" },
2066 { 4*CS, "4*CS" },
2067 { 4*EFL, "4*EFL" },
2068 { 4*UESP, "4*UESP" },
2069 { 4*SS, "4*SS" },
2070#else /* !I386 */
2071#ifdef M68K
2072 { 4*PT_D1, "4*PT_D1" },
2073 { 4*PT_D2, "4*PT_D2" },
2074 { 4*PT_D3, "4*PT_D3" },
2075 { 4*PT_D4, "4*PT_D4" },
2076 { 4*PT_D5, "4*PT_D5" },
2077 { 4*PT_D6, "4*PT_D6" },
2078 { 4*PT_D7, "4*PT_D7" },
2079 { 4*PT_A0, "4*PT_A0" },
2080 { 4*PT_A1, "4*PT_A1" },
2081 { 4*PT_A2, "4*PT_A2" },
2082 { 4*PT_A3, "4*PT_A3" },
2083 { 4*PT_A4, "4*PT_A4" },
2084 { 4*PT_A5, "4*PT_A5" },
2085 { 4*PT_A6, "4*PT_A6" },
2086 { 4*PT_D0, "4*PT_D0" },
2087 { 4*PT_USP, "4*PT_USP" },
2088 { 4*PT_ORIG_D0, "4*PT_ORIG_D0" },
2089 { 4*PT_SR, "4*PT_SR" },
2090 { 4*PT_PC, "4*PT_PC" },
2091#endif /* M68K */
2092#endif /* !I386 */
Wichert Akkerman12f75d12000-02-14 16:23:40 +00002093#if !defined(S390) && !defined(MIPS)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002094 { uoff(u_fpvalid), "offsetof(struct user, u_fpvalid)" },
Wichert Akkermanf90da011999-10-31 21:15:38 +00002095#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002096#ifdef I386
2097 { uoff(i387), "offsetof(struct user, i387)" },
2098#else /* !I386 */
2099#ifdef M68K
2100 { uoff(m68kfp), "offsetof(struct user, m68kfp)" },
2101#endif /* M68K */
2102#endif /* !I386 */
2103 { uoff(u_tsize), "offsetof(struct user, u_tsize)" },
2104 { uoff(u_dsize), "offsetof(struct user, u_dsize)" },
2105 { uoff(u_ssize), "offsetof(struct user, u_ssize)" },
2106 { uoff(start_code), "offsetof(struct user, start_code)" },
2107 { uoff(start_stack), "offsetof(struct user, start_stack)" },
2108 { uoff(signal), "offsetof(struct user, signal)" },
Wichert Akkerman12f75d12000-02-14 16:23:40 +00002109#if !defined(S390) && !defined(MIPS)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002110 { uoff(reserved), "offsetof(struct user, reserved)" },
Wichert Akkermanf90da011999-10-31 21:15:38 +00002111#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002112 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00002113#if !defined(ARM) && !defined(MIPS) && !defined(S390)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002114 { uoff(u_fpstate), "offsetof(struct user, u_fpstate)" },
2115#endif
2116 { uoff(magic), "offsetof(struct user, magic)" },
2117 { uoff(u_comm), "offsetof(struct user, u_comm)" },
2118#ifdef I386
2119 { uoff(u_debugreg), "offsetof(struct user, u_debugreg)" },
2120#endif /* I386 */
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002121#endif /* !IA64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002122#endif /* !ALPHA */
2123#endif /* !POWERPC/!SPARC */
2124#endif /* LINUX */
2125#ifdef SUNOS4
2126 { uoff(u_pcb), "offsetof(struct user, u_pcb)" },
2127 { uoff(u_procp), "offsetof(struct user, u_procp)" },
2128 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
2129 { uoff(u_comm[0]), "offsetof(struct user, u_comm[0])" },
2130 { uoff(u_arg[0]), "offsetof(struct user, u_arg[0])" },
2131 { uoff(u_ap), "offsetof(struct user, u_ap)" },
2132 { uoff(u_qsave), "offsetof(struct user, u_qsave)" },
2133 { uoff(u_rval1), "offsetof(struct user, u_rval1)" },
2134 { uoff(u_rval2), "offsetof(struct user, u_rval2)" },
2135 { uoff(u_error), "offsetof(struct user, u_error)" },
2136 { uoff(u_eosys), "offsetof(struct user, u_eosys)" },
2137 { uoff(u_ssave), "offsetof(struct user, u_ssave)" },
2138 { uoff(u_signal[0]), "offsetof(struct user, u_signal)" },
2139 { uoff(u_sigmask[0]), "offsetof(struct user, u_sigmask)" },
2140 { uoff(u_sigonstack), "offsetof(struct user, u_sigonstack)" },
2141 { uoff(u_sigintr), "offsetof(struct user, u_sigintr)" },
2142 { uoff(u_sigreset), "offsetof(struct user, u_sigreset)" },
2143 { uoff(u_oldmask), "offsetof(struct user, u_oldmask)" },
2144 { uoff(u_code), "offsetof(struct user, u_code)" },
2145 { uoff(u_addr), "offsetof(struct user, u_addr)" },
2146 { uoff(u_sigstack), "offsetof(struct user, u_sigstack)" },
2147 { uoff(u_ofile), "offsetof(struct user, u_ofile)" },
2148 { uoff(u_pofile), "offsetof(struct user, u_pofile)" },
2149 { uoff(u_ofile_arr[0]), "offsetof(struct user, u_ofile_arr[0])" },
2150 { uoff(u_pofile_arr[0]),"offsetof(struct user, u_pofile_arr[0])"},
2151 { uoff(u_lastfile), "offsetof(struct user, u_lastfile)" },
2152 { uoff(u_cwd), "offsetof(struct user, u_cwd)" },
2153 { uoff(u_cdir), "offsetof(struct user, u_cdir)" },
2154 { uoff(u_rdir), "offsetof(struct user, u_rdir)" },
2155 { uoff(u_cmask), "offsetof(struct user, u_cmask)" },
2156 { uoff(u_ru), "offsetof(struct user, u_ru)" },
2157 { uoff(u_cru), "offsetof(struct user, u_cru)" },
2158 { uoff(u_timer[0]), "offsetof(struct user, u_timer[0])" },
2159 { uoff(u_XXX[0]), "offsetof(struct user, u_XXX[0])" },
2160 { uoff(u_ioch), "offsetof(struct user, u_ioch)" },
2161 { uoff(u_start), "offsetof(struct user, u_start)" },
2162 { uoff(u_acflag), "offsetof(struct user, u_acflag)" },
2163 { uoff(u_prof.pr_base), "offsetof(struct user, u_prof.pr_base)" },
2164 { uoff(u_prof.pr_size), "offsetof(struct user, u_prof.pr_size)" },
2165 { uoff(u_prof.pr_off), "offsetof(struct user, u_prof.pr_off)" },
2166 { uoff(u_prof.pr_scale),"offsetof(struct user, u_prof.pr_scale)"},
2167 { uoff(u_rlimit[0]), "offsetof(struct user, u_rlimit)" },
2168 { uoff(u_exdata.Ux_A), "offsetof(struct user, u_exdata.Ux_A)" },
2169 { uoff(u_exdata.ux_shell[0]),"offsetof(struct user, u_exdata.ux_shell[0])"},
2170 { uoff(u_lofault), "offsetof(struct user, u_lofault)" },
2171#endif /* SUNOS4 */
Wichert Akkermanc1652e22001-03-27 12:17:16 +00002172#ifndef HPPA
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002173 { sizeof(struct user), "sizeof(struct user)" },
Wichert Akkermanc1652e22001-03-27 12:17:16 +00002174#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002175 { 0, NULL },
2176};
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002177#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002178
2179int
2180sys_ptrace(tcp)
2181struct tcb *tcp;
2182{
2183 char *cmd;
2184 struct xlat *x;
2185 long addr;
2186
2187 cmd = xlookup(ptrace_cmds, tcp->u_arg[0]);
2188 if (!cmd)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002189#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002190 cmd = "PTRACE_???";
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002191#else
2192 cmd = "PT_???";
2193#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002194 if (entering(tcp)) {
2195 tprintf("%s, %lu, ", cmd, tcp->u_arg[1]);
2196 addr = tcp->u_arg[2];
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002197#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002198 if (tcp->u_arg[0] == PTRACE_PEEKUSER
2199 || tcp->u_arg[0] == PTRACE_POKEUSER) {
2200 for (x = struct_user_offsets; x->str; x++) {
2201 if (x->val >= addr)
2202 break;
2203 }
2204 if (!x->str)
2205 tprintf("%#lx, ", addr);
2206 else if (x->val > addr && x != struct_user_offsets) {
2207 x--;
2208 tprintf("%s + %ld, ", x->str, addr - x->val);
2209 }
2210 else
2211 tprintf("%s, ", x->str);
2212 }
2213 else
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002214#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002215 tprintf("%#lx, ", tcp->u_arg[2]);
2216#ifdef LINUX
2217 switch (tcp->u_arg[0]) {
2218 case PTRACE_PEEKDATA:
2219 case PTRACE_PEEKTEXT:
2220 case PTRACE_PEEKUSER:
2221 break;
2222 case PTRACE_CONT:
2223 case PTRACE_SINGLESTEP:
2224 case PTRACE_SYSCALL:
2225 case PTRACE_DETACH:
2226 printsignal(tcp->u_arg[3]);
2227 break;
2228 default:
2229 tprintf("%#lx", tcp->u_arg[3]);
2230 break;
2231 }
2232 } else {
2233 switch (tcp->u_arg[0]) {
2234 case PTRACE_PEEKDATA:
2235 case PTRACE_PEEKTEXT:
2236 case PTRACE_PEEKUSER:
2237 printnum(tcp, tcp->u_arg[3], "%#x");
2238 break;
2239 }
2240 }
2241#endif /* LINUX */
2242#ifdef SUNOS4
2243 if (tcp->u_arg[0] == PTRACE_WRITEDATA ||
2244 tcp->u_arg[0] == PTRACE_WRITETEXT) {
2245 tprintf("%lu, ", tcp->u_arg[3]);
2246 printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]);
2247 } else if (tcp->u_arg[0] != PTRACE_READDATA &&
2248 tcp->u_arg[0] != PTRACE_READTEXT) {
2249 tprintf("%#lx", tcp->u_arg[3]);
2250 }
2251 } else {
2252 if (tcp->u_arg[0] == PTRACE_READDATA ||
2253 tcp->u_arg[0] == PTRACE_READTEXT) {
2254 tprintf("%lu, ", tcp->u_arg[3]);
2255 printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]);
2256 }
2257 }
2258#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002259#ifdef FREEBSD
2260 tprintf("%lu", tcp->u_arg[3]);
2261 }
2262#endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002263 return 0;
2264}
2265
2266#endif /* !SVR4 */