blob: e03be2d39a1f62a8c9972b9f7c53e85e48237407 [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 Akkerman7b3346b2001-10-09 23:47:38 +0000460int
461sys_clone2(tcp)
462struct tcb *tcp;
463{
464 if (exiting(tcp)) {
465 tprintf("child_stack=%#lx, stack_size=%#lx, flags=",
466 tcp->u_arg[1], tcp->u_arg[2]);
467 if (printflags(clone_flags, tcp->u_arg[0]) == 0)
468 tprintf("0");
469 }
470 return 0;
471}
472
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000473#endif
474
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000475int
476sys_fork(tcp)
477struct tcb *tcp;
478{
479 if (exiting(tcp))
480 return RVAL_UDECIMAL;
481 return 0;
482}
483
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000484int
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000485change_syscall(tcp, new)
486struct tcb *tcp;
487int new;
488{
489#if defined(LINUX)
490#if defined(I386)
491 /* Attempt to make vfork into fork, which we can follow. */
492 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(ORIG_EAX * 4), new) < 0)
493 return -1;
494 return 0;
495#elif defined(POWERPC)
Wichert Akkerman5c4c69b2001-04-12 09:00:47 +0000496 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*PT_R0), new) < 0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000497 return -1;
498#elif defined(S390)
499 long pc;
500 if (upeek(tcp->pid, PT_PSWADDR,&pc)<0)
501 return -1;
502 if (ptrace(PTRACE_POKETEXT, tcp->pid, (char*)(pc-4), new)<0)
503 return -1;
504 return 0;
505#elif defined(M68K)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000506 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*PT_ORIG_D0), new)<0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000507 return -1;
508 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000509#elif defined(SPARC)
Wichert Akkerman00a82ee2001-03-28 20:29:17 +0000510 struct regs regs;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000511 if (ptrace(PTRACE_GETREGS, tcp->pid, (char*)&regs, 0)<0)
512 return -1;
Wichert Akkerman00a82ee2001-03-28 20:29:17 +0000513 regs.r_g1=new;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000514 if (ptrace(PTRACE_SETREGS, tcp->pid, (char*)&regs, 0)<0)
515 return -1;
516 return 0;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000517#elif defined(MIPS)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000518 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_V0), new)<0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000519 return -1;
520 return 0;
521#elif defined(ALPHA)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000522 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_A3), new)<0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000523 return -1;
524 return 0;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000525#elif defined(IA64)
526 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_R15), new)<0)
527 return -1;
528 return 0;
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000529#elif defined(HPPA)
530 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_GR20), new)<0)
531 return -1;
532 return 0;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000533#else
534#warning Do not know how to handle change_syscall for this architecture
535#endif /* architecture */
536#endif /* LINUX */
537 return -1;
538}
539
540int
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000541setarg(tcp, argnum)
542 struct tcb *tcp;
543 int argnum;
544{
545#if defined (IA64)
546 {
547 unsigned long *bsp, *ap;
548
549 if (upeek(tcp->pid, PT_AR_BSP, (long *) &bsp) , 0)
550 return -1;
551
552 ap = ia64_rse_skip_regs(bsp, argnum);
553 errno = 0;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000554 ptrace(PTRACE_POKEDATA, tcp->pid, (char *) ap, tcp->u_arg[argnum]);
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000555 if (errno)
556 return -1;
557
558 }
Wichert Akkerman12f75d12000-02-14 16:23:40 +0000559#elif defined(I386)
560 {
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000561 ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*argnum), tcp->u_arg[argnum]);
Wichert Akkerman12f75d12000-02-14 16:23:40 +0000562 if (errno)
563 return -1;
564 }
Ralf Baechlee3816102000-08-01 00:06:06 +0000565#elif defined(MIPS)
566 {
567 errno = 0;
568 if (argnum < 4)
569 ptrace(PTRACE_POKEUSER, tcp->pid,
570 (char*)(REG_A0 + argnum), tcp->u_arg[argnum]);
571 else {
572 unsigned long *sp;
573
574 if (upeek(tcp->pid, REG_SP, (long *) &sp) , 0)
575 return -1;
576
577 ptrace(PTRACE_POKEDATA, tcp->pid,
578 (char*)(sp + argnum - 4), tcp->u_arg[argnum]);
579 }
580 if (errno)
581 return -1;
582 }
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000583#else
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000584# warning Sorry, setargs not implemented for this architecture.
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000585#endif
586 return 0;
587}
588
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000589#ifdef SYS_clone
590int
591internal_clone(tcp)
592struct tcb *tcp;
593{
Ulrich Drepper90512f01999-12-24 07:22:25 +0000594 struct tcb *tcpchild;
595 int pid;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000596 if (entering(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000597 if (!followfork)
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000598 return 0;
599 if (nprocs == MAX_PROCS) {
600 tcp->flags &= ~TCB_FOLLOWFORK;
601 fprintf(stderr, "sys_fork: tcb table full\n");
602 return 0;
603 }
604 tcp->flags |= TCB_FOLLOWFORK;
605
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000606
607 if (setbpt(tcp) < 0)
608 return 0;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000609 } else {
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000610 int bpt = tcp->flags & TCB_BPTSET;
611
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000612 if (!(tcp->flags & TCB_FOLLOWFORK))
613 return 0;
614
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000615 if (syserror(tcp)) {
616 if (bpt)
617 clearbpt(tcp);
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000618 return 0;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000619 }
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000620
621 pid = tcp->u_rval;
622 if ((tcpchild = alloctcb(pid)) == NULL) {
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000623 if (bpt)
624 clearbpt(tcp);
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000625 fprintf(stderr, " [tcb table full]\n");
626 kill(pid, SIGKILL); /* XXX */
627 return 0;
628 }
629
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000630 /* Attach to the new child */
631 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) < 0) {
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000632 if (bpt)
633 clearbpt(tcp);
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000634 perror("PTRACE_ATTACH");
635 fprintf(stderr, "Too late?\n");
636 droptcb(tcpchild);
637 return 0;
638 }
639
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000640 if (bpt)
641 clearbpt(tcp);
642
Ulrich Drepper90512f01999-12-24 07:22:25 +0000643 tcpchild->flags |= TCB_ATTACHED;
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000644 if (bpt) {
645 tcpchild->flags |= TCB_BPTSET;
646 tcpchild->baddr = tcp->baddr;
647 memcpy(tcpchild->inst, tcp->inst,
648 sizeof tcpchild->inst);
649 }
Ulrich Drepper90512f01999-12-24 07:22:25 +0000650 newoutf(tcpchild);
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000651 tcpchild->parent = tcp;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000652 tcp->nchildren++;
653 if (!qflag)
654 fprintf(stderr, "Process %d attached\n", pid);
655 }
656 return 0;
657}
658#endif
659
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000660int
661internal_fork(tcp)
662struct tcb *tcp;
663{
664 struct tcb *tcpchild;
665 int pid;
Nate Sammonsccd8f211999-03-29 22:57:54 +0000666 int dont_follow = 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000667
668#ifdef SYS_vfork
Nate Sammonsccd8f211999-03-29 22:57:54 +0000669 if (tcp->scno == SYS_vfork) {
Nate Sammonsccd8f211999-03-29 22:57:54 +0000670 /* Attempt to make vfork into fork, which we can follow. */
671 if (!followvfork ||
Pavel Machek9a9f10b2000-02-01 16:22:52 +0000672 change_syscall(tcp, SYS_fork) < 0)
Nate Sammonsccd8f211999-03-29 22:57:54 +0000673 dont_follow = 1;
Nate Sammonsccd8f211999-03-29 22:57:54 +0000674 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000675#endif
676 if (entering(tcp)) {
Nate Sammonsccd8f211999-03-29 22:57:54 +0000677 if (!followfork || dont_follow)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000678 return 0;
679 if (nprocs == MAX_PROCS) {
680 tcp->flags &= ~TCB_FOLLOWFORK;
681 fprintf(stderr, "sys_fork: tcb table full\n");
682 return 0;
683 }
684 tcp->flags |= TCB_FOLLOWFORK;
685 if (setbpt(tcp) < 0)
686 return 0;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000687 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000688 else {
689 int bpt = tcp->flags & TCB_BPTSET;
690
691 if (!(tcp->flags & TCB_FOLLOWFORK))
692 return 0;
693 if (bpt)
694 clearbpt(tcp);
695
696 if (syserror(tcp))
697 return 0;
698
699 pid = tcp->u_rval;
700 if ((tcpchild = alloctcb(pid)) == NULL) {
701 fprintf(stderr, " [tcb table full]\n");
702 kill(pid, SIGKILL); /* XXX */
703 return 0;
704 }
705#ifdef LINUX
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000706#ifdef HPPA
707 /* The child must have run before it can be attached. */
708 /* This must be a bug in the parisc kernel, but I havn't
709 * identified it yet. Seems to be an issue associated
710 * with attaching to a process (which sends it a signal)
711 * before that process has ever been scheduled. When
712 * debugging, I started seeing crashes in
713 * arch/parisc/kernel/signal.c:do_signal(), apparently
714 * caused by r8 getting corrupt over the dequeue_signal()
715 * call. Didn't make much sense though...
716 */
717 {
718 struct timeval tv;
719 tv.tv_sec = 0;
720 tv.tv_usec = 10000;
721 select(0, NULL, NULL, NULL, &tv);
722 }
723#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000724 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) < 0) {
725 perror("PTRACE_ATTACH");
726 fprintf(stderr, "Too late?\n");
727 droptcb(tcpchild);
728 return 0;
729 }
730#endif /* LINUX */
731#ifdef SUNOS4
732#ifdef oldway
733 /* The child must have run before it can be attached. */
734 {
735 struct timeval tv;
736 tv.tv_sec = 0;
737 tv.tv_usec = 10000;
738 select(0, NULL, NULL, NULL, &tv);
739 }
740 if (ptrace(PTRACE_ATTACH, pid, (char *)1, 0) < 0) {
741 perror("PTRACE_ATTACH");
742 fprintf(stderr, "Too late?\n");
743 droptcb(tcpchild);
744 return 0;
745 }
746#else /* !oldway */
747 /* Try to catch the new process as soon as possible. */
748 {
749 int i;
750 for (i = 0; i < 1024; i++)
751 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) >= 0)
752 break;
753 if (i == 1024) {
754 perror("PTRACE_ATTACH");
755 fprintf(stderr, "Too late?\n");
756 droptcb(tcpchild);
757 return 0;
758 }
759 }
760#endif /* !oldway */
761#endif /* SUNOS4 */
762 tcpchild->flags |= TCB_ATTACHED;
763 /* Child has BPT too, must be removed on first occasion */
764 if (bpt) {
765 tcpchild->flags |= TCB_BPTSET;
766 tcpchild->baddr = tcp->baddr;
767 memcpy(tcpchild->inst, tcp->inst,
768 sizeof tcpchild->inst);
769 }
770 newoutf(tcpchild);
771 tcpchild->parent = tcp;
772 tcp->nchildren++;
773 if (!qflag)
774 fprintf(stderr, "Process %d attached\n", pid);
775 }
776 return 0;
777}
778
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000779#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000780
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000781#if defined(SUNOS4) || defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000782
783int
784sys_vfork(tcp)
785struct tcb *tcp;
786{
787 if (exiting(tcp))
788 return RVAL_UDECIMAL;
789 return 0;
790}
791
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000792#endif /* SUNOS4 || LINUX || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000793
794#ifndef LINUX
795
796static char idstr[16];
797
798int
799sys_getpid(tcp)
800struct tcb *tcp;
801{
802 if (exiting(tcp)) {
803 sprintf(idstr, "ppid %lu", getrval2(tcp));
804 tcp->auxstr = idstr;
805 return RVAL_STR;
806 }
807 return 0;
808}
809
810int
811sys_getuid(tcp)
812struct tcb *tcp;
813{
814 if (exiting(tcp)) {
815 sprintf(idstr, "euid %lu", getrval2(tcp));
816 tcp->auxstr = idstr;
817 return RVAL_STR;
818 }
819 return 0;
820}
821
822int
823sys_getgid(tcp)
824struct tcb *tcp;
825{
826 if (exiting(tcp)) {
827 sprintf(idstr, "egid %lu", getrval2(tcp));
828 tcp->auxstr = idstr;
829 return RVAL_STR;
830 }
831 return 0;
832}
833
834#endif /* !LINUX */
835
836#ifdef LINUX
837
838int
839sys_setuid(tcp)
840struct tcb *tcp;
841{
842 if (entering(tcp)) {
843 tprintf("%u", (uid_t) tcp->u_arg[0]);
844 }
845 return 0;
846}
847
848int
849sys_setgid(tcp)
850struct tcb *tcp;
851{
852 if (entering(tcp)) {
853 tprintf("%u", (gid_t) tcp->u_arg[0]);
854 }
855 return 0;
856}
857
858int
859sys_getresuid(tcp)
860 struct tcb *tcp;
861{
862 if (exiting(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000863 __kernel_uid_t uid;
864 if (syserror(tcp))
865 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
866 tcp->u_arg[1], tcp->u_arg[2]);
867 else {
868 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
869 tprintf("%#lx, ", tcp->u_arg[0]);
870 else
871 tprintf("ruid %lu, ", (unsigned long) uid);
872 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
873 tprintf("%#lx, ", tcp->u_arg[0]);
874 else
875 tprintf("euid %lu, ", (unsigned long) uid);
876 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
877 tprintf("%#lx", tcp->u_arg[0]);
878 else
879 tprintf("suid %lu", (unsigned long) uid);
880 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000881 }
882 return 0;
883}
884
885int
886sys_getresgid(tcp)
887struct tcb *tcp;
888{
889 if (exiting(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000890 __kernel_gid_t gid;
891 if (syserror(tcp))
892 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
893 tcp->u_arg[1], tcp->u_arg[2]);
894 else {
895 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
896 tprintf("%#lx, ", tcp->u_arg[0]);
897 else
898 tprintf("rgid %lu, ", (unsigned long) gid);
899 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
900 tprintf("%#lx, ", tcp->u_arg[0]);
901 else
902 tprintf("egid %lu, ", (unsigned long) gid);
903 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
904 tprintf("%#lx", tcp->u_arg[0]);
905 else
906 tprintf("sgid %lu", (unsigned long) gid);
907 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000908 }
909 return 0;
910}
911
912#endif /* LINUX */
913
914int
915sys_setreuid(tcp)
916struct tcb *tcp;
917{
918 if (entering(tcp)) {
919 tprintf("%lu, %lu",
920 (unsigned long) (uid_t) tcp->u_arg[0],
921 (unsigned long) (uid_t) tcp->u_arg[1]);
922 }
923 return 0;
924}
925
926int
927sys_setregid(tcp)
928struct tcb *tcp;
929{
930 if (entering(tcp)) {
931 tprintf("%lu, %lu",
932 (unsigned long) (gid_t) tcp->u_arg[0],
933 (unsigned long) (gid_t) tcp->u_arg[1]);
934 }
935 return 0;
936}
937
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000938#if defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000939int
940sys_setresuid(tcp)
941 struct tcb *tcp;
942{
943 if (entering(tcp)) {
944 tprintf("ruid %u, euid %u, suid %u",
945 (uid_t) tcp->u_arg[0],
946 (uid_t) tcp->u_arg[1],
947 (uid_t) tcp->u_arg[2]);
948 }
949 return 0;
950}
951int
952sys_setresgid(tcp)
953 struct tcb *tcp;
954{
955 if (entering(tcp)) {
956 tprintf("rgid %u, egid %u, sgid %u",
957 (uid_t) tcp->u_arg[0],
958 (uid_t) tcp->u_arg[1],
959 (uid_t) tcp->u_arg[2]);
960 }
961 return 0;
962}
963
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000964#endif /* LINUX || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000965
966int
967sys_setgroups(tcp)
968struct tcb *tcp;
969{
970 int i, len;
971 GETGROUPS_T *gidset;
972
973 if (entering(tcp)) {
974 len = tcp->u_arg[0];
975 tprintf("%u, ", len);
976 if (len <= 0) {
977 tprintf("[]");
978 return 0;
979 }
980 gidset = (GETGROUPS_T *) malloc(len * sizeof(GETGROUPS_T));
981 if (gidset == NULL) {
982 fprintf(stderr, "sys_setgroups: out of memory\n");
983 return -1;
984 }
985 if (!verbose(tcp))
986 tprintf("%#lx", tcp->u_arg[1]);
987 else if (umoven(tcp, tcp->u_arg[1],
988 len * sizeof(GETGROUPS_T), (char *) gidset) < 0)
989 tprintf("[?]");
990 else {
991 tprintf("[");
992 for (i = 0; i < len; i++)
993 tprintf("%s%lu", i ? ", " : "",
994 (unsigned long) gidset[i]);
995 tprintf("]");
996 }
997 free((char *) gidset);
998 }
999 return 0;
1000}
1001
1002int
1003sys_getgroups(tcp)
1004struct tcb *tcp;
1005{
1006 int i, len;
1007 GETGROUPS_T *gidset;
1008
1009 if (entering(tcp)) {
1010 len = tcp->u_arg[0];
1011 tprintf("%u, ", len);
1012 } else {
1013 len = tcp->u_rval;
1014 if (len <= 0) {
1015 tprintf("[]");
1016 return 0;
1017 }
1018 gidset = (GETGROUPS_T *) malloc(len * sizeof(GETGROUPS_T));
1019 if (gidset == NULL) {
1020 fprintf(stderr, "sys_getgroups: out of memory\n");
1021 return -1;
1022 }
1023 if (!tcp->u_arg[1])
1024 tprintf("NULL");
1025 else if (!verbose(tcp) || tcp->u_arg[0] == 0)
1026 tprintf("%#lx", tcp->u_arg[1]);
1027 else if (umoven(tcp, tcp->u_arg[1],
1028 len * sizeof(GETGROUPS_T), (char *) gidset) < 0)
1029 tprintf("[?]");
1030 else {
1031 tprintf("[");
1032 for (i = 0; i < len; i++)
1033 tprintf("%s%lu", i ? ", " : "",
1034 (unsigned long) gidset[i]);
1035 tprintf("]");
1036 }
1037 free((char *)gidset);
1038 }
1039 return 0;
1040}
1041
1042int
1043sys_setpgrp(tcp)
1044struct tcb *tcp;
1045{
1046 if (entering(tcp)) {
1047#ifndef SVR4
1048 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1049#endif /* !SVR4 */
1050 }
1051 return 0;
1052}
1053
1054int
1055sys_getpgrp(tcp)
1056struct tcb *tcp;
1057{
1058 if (entering(tcp)) {
1059#ifndef SVR4
1060 tprintf("%lu", tcp->u_arg[0]);
1061#endif /* !SVR4 */
1062 }
1063 return 0;
1064}
1065
1066int
1067sys_getsid(tcp)
1068struct tcb *tcp;
1069{
1070 if (entering(tcp)) {
1071 tprintf("%lu", tcp->u_arg[0]);
1072 }
1073 return 0;
1074}
1075
1076int
1077sys_setsid(tcp)
1078struct tcb *tcp;
1079{
1080 return 0;
1081}
1082
1083int
1084sys_getpgid(tcp)
1085struct tcb *tcp;
1086{
1087 if (entering(tcp)) {
1088 tprintf("%lu", tcp->u_arg[0]);
1089 }
1090 return 0;
1091}
1092
1093int
1094sys_setpgid(tcp)
1095struct tcb *tcp;
1096{
1097 if (entering(tcp)) {
1098 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1099 }
1100 return 0;
1101}
1102
1103void
1104fake_execve(tcp, program, argv, envp)
1105struct tcb *tcp;
1106char *program;
1107char *argv[];
1108char *envp[];
1109{
1110 int i;
1111
1112#ifdef ARM
1113 if (!(qual_flags[SYS_execve - __NR_SYSCALL_BASE] & QUAL_TRACE))
1114 return;
1115#else
1116 if (!(qual_flags[SYS_execve] & QUAL_TRACE))
1117 return;
1118#endif /* !ARM */
1119 printleader(tcp);
1120 tprintf("execve(");
1121 string_quote(program);
1122 tprintf(", [");
1123 for (i = 0; argv[i] != NULL; i++) {
1124 if (i != 0)
1125 tprintf(", ");
1126 string_quote(argv[i]);
1127 }
1128 for (i = 0; envp[i] != NULL; i++)
1129 ;
1130 tprintf("], [/* %d var%s */]) ", i, (i != 1) ? "s" : "");
1131 tabto(acolumn);
1132 tprintf("= 0");
1133 printtrailer(tcp);
1134}
1135
1136static void
1137printargv(tcp, addr)
1138struct tcb *tcp;
1139long addr;
1140{
1141 char *cp;
1142 char *sep;
1143 int max = max_strlen / 2;
1144
1145 for (sep = ""; --max >= 0; sep = ", ") {
1146 if (!abbrev(tcp))
1147 max++;
1148 if (umove(tcp, addr, &cp) < 0) {
1149 tprintf("%#lx", addr);
1150 return;
1151 }
1152 if (cp == 0)
1153 break;
1154 tprintf(sep);
1155 printstr(tcp, (long) cp, -1);
1156 addr += sizeof(char *);
1157 }
1158 if (cp)
1159 tprintf(", ...");
1160}
1161
1162static void
1163printargc(fmt, tcp, addr)
1164char *fmt;
1165struct tcb *tcp;
1166long addr;
1167{
1168 int count;
1169 char *cp;
1170
1171 for (count = 0; umove(tcp, addr, &cp) >= 0 && cp != NULL; count++) {
1172 addr += sizeof(char *);
1173 }
1174 tprintf(fmt, count, count == 1 ? "" : "s");
1175}
1176
1177int
1178sys_execv(tcp)
1179struct tcb *tcp;
1180{
1181 if (entering(tcp)) {
1182 printpath(tcp, tcp->u_arg[0]);
1183 if (!verbose(tcp))
1184 tprintf(", %#lx", tcp->u_arg[1]);
1185#if 0
1186 else if (abbrev(tcp))
1187 printargc(", [/* %d arg%s */]", tcp, tcp->u_arg[1]);
1188#endif
1189 else {
1190 tprintf(", [");
1191 printargv(tcp, tcp->u_arg[1]);
1192 tprintf("]");
1193 }
1194 }
1195 return 0;
1196}
1197
1198int
1199sys_execve(tcp)
1200struct tcb *tcp;
1201{
1202 if (entering(tcp)) {
1203 printpath(tcp, tcp->u_arg[0]);
1204 if (!verbose(tcp))
1205 tprintf(", %#lx", tcp->u_arg[1]);
1206#if 0
1207 else if (abbrev(tcp))
1208 printargc(", [/* %d arg%s */]", tcp, tcp->u_arg[1]);
1209#endif
1210 else {
1211 tprintf(", [");
1212 printargv(tcp, tcp->u_arg[1]);
1213 tprintf("]");
1214 }
1215 if (!verbose(tcp))
1216 tprintf(", %#lx", tcp->u_arg[2]);
1217 else if (abbrev(tcp))
1218 printargc(", [/* %d var%s */]", tcp, tcp->u_arg[2]);
1219 else {
1220 tprintf(", [");
1221 printargv(tcp, tcp->u_arg[2]);
1222 tprintf("]");
1223 }
1224 }
1225#ifdef LINUX
Wichert Akkerman7b3346b2001-10-09 23:47:38 +00001226#if defined(ALPHA) || defined(SPARC) || defined(POWERPC) || defined(IA64) || defined(HPPA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001227 tcp->flags |= TCB_WAITEXECVE;
1228#endif /* ALPHA || SPARC || POWERPC */
1229#endif /* LINUX */
1230 return 0;
1231}
1232
John Hughes4e36a812001-04-18 15:11:51 +00001233#if UNIXWARE > 2
1234
1235int sys_rexecve(tcp)
1236struct tcb *tcp;
1237{
1238 if (entering (tcp)) {
1239 sys_execve (tcp);
1240 tprintf (", %ld", tcp->u_arg[3]);
1241 }
1242 return 0;
1243}
1244
1245#endif
1246
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001247int
1248internal_exec(tcp)
1249struct tcb *tcp;
1250{
1251#ifdef SUNOS4
1252 if (exiting(tcp) && !syserror(tcp) && followfork)
1253 fixvfork(tcp);
1254#endif /* SUNOS4 */
1255 return 0;
1256}
1257
1258#ifdef LINUX
1259#ifndef __WCLONE
1260#define __WCLONE 0x8000000
1261#endif
1262#endif /* LINUX */
1263
1264static struct xlat wait4_options[] = {
1265 { WNOHANG, "WNOHANG" },
1266#ifndef WSTOPPED
1267 { WUNTRACED, "WUNTRACED" },
1268#endif
1269#ifdef WEXITED
1270 { WEXITED, "WEXITED" },
1271#endif
1272#ifdef WTRAPPED
1273 { WTRAPPED, "WTRAPPED" },
1274#endif
1275#ifdef WSTOPPED
1276 { WSTOPPED, "WSTOPPED" },
1277#endif
1278#ifdef WCONTINUED
1279 { WCONTINUED, "WCONTINUED" },
1280#endif
1281#ifdef WNOWAIT
1282 { WNOWAIT, "WNOWAIT" },
1283#endif
1284#ifdef __WCLONE
1285 { __WCLONE, "__WCLONE" },
1286#endif
1287 { 0, NULL },
1288};
1289
1290static int
1291printstatus(status)
1292int status;
1293{
1294 int exited = 0;
1295
1296 /*
1297 * Here is a tricky presentation problem. This solution
1298 * is still not entirely satisfactory but since there
1299 * are no wait status constructors it will have to do.
1300 */
1301 if (WIFSTOPPED(status))
1302 tprintf("[WIFSTOPPED(s) && WSTOPSIG(s) == %s]",
Nate Sammonsce780fc1999-03-29 23:23:13 +00001303 signame(WSTOPSIG(status)));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001304 else if WIFSIGNALED(status)
1305 tprintf("[WIFSIGNALED(s) && WTERMSIG(s) == %s%s]",
Nate Sammonsce780fc1999-03-29 23:23:13 +00001306 signame(WTERMSIG(status)),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001307 WCOREDUMP(status) ? " && WCOREDUMP(s)" : "");
1308 else if WIFEXITED(status) {
1309 tprintf("[WIFEXITED(s) && WEXITSTATUS(s) == %d]",
1310 WEXITSTATUS(status));
1311 exited = 1;
1312 }
1313 else
1314 tprintf("[%#x]", status);
1315 return exited;
1316}
1317
1318static int
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001319printwaitn(tcp, n, bitness)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001320struct tcb *tcp;
1321int n;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001322int bitness;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001323{
1324 int status;
1325 int exited = 0;
1326
1327 if (entering(tcp)) {
1328 tprintf("%ld, ", tcp->u_arg[0]);
1329 } else {
1330 /* status */
1331 if (!tcp->u_arg[1])
1332 tprintf("NULL");
1333 else if (syserror(tcp) || tcp->u_rval == 0)
1334 tprintf("%#lx", tcp->u_arg[1]);
1335 else if (umove(tcp, tcp->u_arg[1], &status) < 0)
1336 tprintf("[?]");
1337 else
1338 exited = printstatus(status);
1339 /* options */
1340 tprintf(", ");
1341 if (!printflags(wait4_options, tcp->u_arg[2]))
1342 tprintf("0");
1343 if (n == 4) {
1344 tprintf(", ");
1345 /* usage */
1346 if (!tcp->u_arg[3])
1347 tprintf("NULL");
1348#ifdef LINUX
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001349 else if (tcp->u_rval > 0) {
1350#ifdef LINUX_64BIT
1351 if (bitness)
1352 printrusage32(tcp, tcp->u_arg[3]);
1353 else
1354#endif
1355 printrusage(tcp, tcp->u_arg[3]);
1356 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001357#endif /* LINUX */
1358#ifdef SUNOS4
1359 else if (tcp->u_rval > 0 && exited)
1360 printrusage(tcp, tcp->u_arg[3]);
1361#endif /* SUNOS4 */
1362 else
1363 tprintf("%#lx", tcp->u_arg[3]);
1364 }
1365 }
1366 return 0;
1367}
1368
1369int
1370internal_wait(tcp)
1371struct tcb *tcp;
1372{
1373 if (entering(tcp)) {
Wichert Akkerman5daa0281999-03-15 19:49:42 +00001374 /* WTA: fix bug with hanging children */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001375 if (!(tcp->u_arg[2] & WNOHANG) && tcp->nchildren > 0) {
1376 /* There are traced children */
1377 tcp->flags |= TCB_SUSPENDED;
1378 tcp->waitpid = tcp->u_arg[0];
1379 }
1380 }
1381 return 0;
1382}
1383
1384#ifdef SVR4
1385
1386int
1387sys_wait(tcp)
1388struct tcb *tcp;
1389{
1390 if (exiting(tcp)) {
1391 /* The library wrapper stuffs this into the user variable. */
1392 if (!syserror(tcp))
1393 printstatus(getrval2(tcp));
1394 }
1395 return 0;
1396}
1397
1398#endif /* SVR4 */
1399
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001400#ifdef FREEBSD
1401int
1402sys_wait(tcp)
1403struct tcb *tcp;
1404{
1405 int status;
1406
1407 if (exiting(tcp)) {
1408 if (!syserror(tcp)) {
1409 if (umove(tcp, tcp->u_arg[0], &status) < 0)
1410 tprintf("%#lx", tcp->u_arg[0]);
1411 else
1412 printstatus(status);
1413 }
1414 }
1415 return 0;
1416}
1417#endif
1418
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001419int
1420sys_waitpid(tcp)
1421struct tcb *tcp;
1422{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001423 return printwaitn(tcp, 3, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001424}
1425
1426int
1427sys_wait4(tcp)
1428struct tcb *tcp;
1429{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001430 return printwaitn(tcp, 4, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001431}
1432
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001433#ifdef ALPHA
1434int
1435sys_osf_wait4(tcp)
1436struct tcb *tcp;
1437{
1438 return printwaitn(tcp, 4, 1);
1439}
1440#endif
1441
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001442#ifdef SVR4
1443
1444static struct xlat waitid_types[] = {
1445 { P_PID, "P_PID" },
1446 { P_PPID, "P_PPID" },
1447 { P_PGID, "P_PGID" },
1448 { P_SID, "P_SID" },
1449 { P_CID, "P_CID" },
1450 { P_UID, "P_UID" },
1451 { P_GID, "P_GID" },
1452 { P_ALL, "P_ALL" },
1453#ifdef P_LWPID
1454 { P_LWPID, "P_LWPID" },
1455#endif
1456 { 0, NULL },
1457};
1458
1459static struct xlat siginfo_codes[] = {
1460#ifdef SI_NOINFO
1461 { SI_NOINFO, "SI_NOINFO" },
1462#endif
1463#ifdef SI_USER
1464 { SI_USER, "SI_USER" },
1465#endif
1466#ifdef SI_LWP
1467 { SI_LWP, "SI_LWP" },
1468#endif
1469#ifdef SI_QUEUE
1470 { SI_QUEUE, "SI_QUEUE" },
1471#endif
1472#ifdef SI_TIMER
1473 { SI_TIMER, "SI_TIMER" },
1474#endif
1475#ifdef SI_ASYNCIO
1476 { SI_ASYNCIO, "SI_ASYNCIO" },
1477#endif
1478#ifdef SI_MESGQ
1479 { SI_MESGQ, "SI_MESGQ" },
1480#endif
1481 { 0, NULL },
1482};
1483
1484static struct xlat sigtrap_codes[] = {
1485 { TRAP_BRKPT, "TRAP_BRKPT" },
1486 { TRAP_TRACE, "TRAP_TRACE" },
1487 { 0, NULL },
1488};
1489
1490static struct xlat sigcld_codes[] = {
1491 { CLD_EXITED, "CLD_EXITED" },
1492 { CLD_KILLED, "CLD_KILLED" },
1493 { CLD_DUMPED, "CLD_DUMPED" },
1494 { CLD_TRAPPED, "CLD_TRAPPED" },
1495 { CLD_STOPPED, "CLD_STOPPED" },
1496 { CLD_CONTINUED,"CLD_CONTINUED" },
1497 { 0, NULL },
1498};
1499
1500static struct xlat sigpoll_codes[] = {
1501 { POLL_IN, "POLL_IN" },
1502 { POLL_OUT, "POLL_OUT" },
1503 { POLL_MSG, "POLL_MSG" },
1504 { POLL_ERR, "POLL_ERR" },
1505 { POLL_PRI, "POLL_PRI" },
1506 { POLL_HUP, "POLL_HUP" },
1507 { 0, NULL },
1508};
1509
1510static struct xlat sigprof_codes[] = {
1511#ifdef PROF_SIG
1512 { PROF_SIG, "PROF_SIG" },
1513#endif
1514 { 0, NULL },
1515};
1516
1517static struct xlat sigill_codes[] = {
1518 { ILL_ILLOPC, "ILL_ILLOPC" },
1519 { ILL_ILLOPN, "ILL_ILLOPN" },
1520 { ILL_ILLADR, "ILL_ILLADR" },
1521 { ILL_ILLTRP, "ILL_ILLTRP" },
1522 { ILL_PRVOPC, "ILL_PRVOPC" },
1523 { ILL_PRVREG, "ILL_PRVREG" },
1524 { ILL_COPROC, "ILL_COPROC" },
1525 { ILL_BADSTK, "ILL_BADSTK" },
1526 { 0, NULL },
1527};
1528
1529static struct xlat sigemt_codes[] = {
1530#ifdef EMT_TAGOVF
1531 { EMT_TAGOVF, "EMT_TAGOVF" },
1532#endif
1533 { 0, NULL },
1534};
1535
1536static struct xlat sigfpe_codes[] = {
1537 { FPE_INTDIV, "FPE_INTDIV" },
1538 { FPE_INTOVF, "FPE_INTOVF" },
1539 { FPE_FLTDIV, "FPE_FLTDIV" },
1540 { FPE_FLTOVF, "FPE_FLTOVF" },
1541 { FPE_FLTUND, "FPE_FLTUND" },
1542 { FPE_FLTRES, "FPE_FLTRES" },
1543 { FPE_FLTINV, "FPE_FLTINV" },
1544 { FPE_FLTSUB, "FPE_FLTSUB" },
1545 { 0, NULL },
1546};
1547
1548static struct xlat sigsegv_codes[] = {
1549 { SEGV_MAPERR, "SEGV_MAPERR" },
1550 { SEGV_ACCERR, "SEGV_ACCERR" },
1551 { 0, NULL },
1552};
1553
1554static struct xlat sigbus_codes[] = {
1555 { BUS_ADRALN, "BUS_ADRALN" },
1556 { BUS_ADRERR, "BUS_ADRERR" },
1557 { BUS_OBJERR, "BUS_OBJERR" },
1558 { 0, NULL },
1559};
1560
1561void
1562printsiginfo(sip)
1563siginfo_t *sip;
1564{
1565 char *code;
1566
1567 tprintf("{si_signo=");
1568 printsignal(sip->si_signo);
1569 code = xlookup(siginfo_codes, sip->si_code);
1570 if (!code) {
1571 switch (sip->si_signo) {
1572 case SIGTRAP:
1573 code = xlookup(sigtrap_codes, sip->si_code);
1574 break;
1575 case SIGCHLD:
1576 code = xlookup(sigcld_codes, sip->si_code);
1577 break;
1578 case SIGPOLL:
1579 code = xlookup(sigpoll_codes, sip->si_code);
1580 break;
1581 case SIGPROF:
1582 code = xlookup(sigprof_codes, sip->si_code);
1583 break;
1584 case SIGILL:
1585 code = xlookup(sigill_codes, sip->si_code);
1586 break;
1587 case SIGEMT:
1588 code = xlookup(sigemt_codes, sip->si_code);
1589 break;
1590 case SIGFPE:
1591 code = xlookup(sigfpe_codes, sip->si_code);
1592 break;
1593 case SIGSEGV:
1594 code = xlookup(sigsegv_codes, sip->si_code);
1595 break;
1596 case SIGBUS:
1597 code = xlookup(sigbus_codes, sip->si_code);
1598 break;
1599 }
1600 }
1601 if (code)
1602 tprintf(", si_code=%s", code);
1603 else
1604 tprintf(", si_code=%#x", sip->si_code);
1605#ifdef SI_NOINFO
1606 if (sip->si_code != SI_NOINFO) {
1607#endif
1608 if (sip->si_errno) {
1609 if (sip->si_errno < 0 || sip->si_errno >= nerrnos)
1610 tprintf(", si_errno=%d", sip->si_errno);
1611 else
1612 tprintf(", si_errno=%s",
1613 errnoent[sip->si_errno]);
1614 }
1615 if (SI_FROMUSER(sip)) {
1616#ifdef SI_QUEUE
1617 tprintf(", si_pid=%ld, si_uid=%ld",
1618 sip->si_pid, sip->si_uid);
1619 switch (sip->si_code) {
1620 case SI_QUEUE:
1621#ifdef SI_TIMER
1622 case SI_TIMER:
1623#endif /* SI_QUEUE */
1624 case SI_ASYNCIO:
1625#ifdef SI_MESGQ
1626 case SI_MESGQ:
1627#endif /* SI_MESGQ */
1628 tprintf(", si_value=%d",
1629 sip->si_value.sival_int);
1630 break;
1631 }
1632#endif /* SI_QUEUE */
1633 }
1634 else {
1635 switch (sip->si_signo) {
1636 case SIGCHLD:
1637 tprintf(", si_pid=%ld, si_status=",
1638 sip->si_pid);
1639 if (sip->si_code == CLD_EXITED)
1640 tprintf("%d", sip->si_status);
1641 else
1642 printsignal(sip->si_status);
1643 break;
1644 case SIGILL: case SIGFPE:
1645 case SIGSEGV: case SIGBUS:
1646 tprintf(", si_addr=%#lx",
1647 (unsigned long) sip->si_addr);
1648 break;
1649 case SIGPOLL:
1650 switch (sip->si_code) {
1651 case POLL_IN: case POLL_OUT: case POLL_MSG:
1652 tprintf(", si_band=%ld",
1653 (long) sip->si_band);
1654 break;
1655 }
1656 break;
1657 }
1658 }
1659 tprintf(", ...");
1660#ifdef SI_NOINFO
1661 }
1662#endif
1663 tprintf("}");
1664}
1665
1666int
1667sys_waitid(tcp)
1668struct tcb *tcp;
1669{
1670 siginfo_t si;
1671 int exited;
1672
1673 if (entering(tcp)) {
1674 printxval(waitid_types, tcp->u_arg[0], "P_???");
1675 tprintf(", %ld, ", tcp->u_arg[1]);
1676 if (tcp->nchildren > 0) {
1677 /* There are traced children */
1678 tcp->flags |= TCB_SUSPENDED;
1679 tcp->waitpid = tcp->u_arg[0];
1680 }
1681 }
1682 else {
1683 /* siginfo */
1684 exited = 0;
1685 if (!tcp->u_arg[2])
1686 tprintf("NULL");
1687 else if (syserror(tcp))
1688 tprintf("%#lx", tcp->u_arg[2]);
1689 else if (umove(tcp, tcp->u_arg[2], &si) < 0)
1690 tprintf("{???}");
1691 else
1692 printsiginfo(&si);
1693 /* options */
1694 tprintf(", ");
1695 if (!printflags(wait4_options, tcp->u_arg[3]))
1696 tprintf("0");
1697 }
1698 return 0;
1699}
1700
1701#endif /* SVR4 */
1702
1703int
1704sys_alarm(tcp)
1705struct tcb *tcp;
1706{
1707 if (entering(tcp))
1708 tprintf("%lu", tcp->u_arg[0]);
1709 return 0;
1710}
1711
1712int
1713sys_uname(tcp)
1714struct tcb *tcp;
1715{
1716 struct utsname uname;
1717
1718 if (exiting(tcp)) {
1719 if (syserror(tcp) || !verbose(tcp))
1720 tprintf("%#lx", tcp->u_arg[0]);
1721 else if (umove(tcp, tcp->u_arg[0], &uname) < 0)
1722 tprintf("{...}");
1723 else if (!abbrev(tcp)) {
1724
1725 tprintf("{sysname=\"%s\", nodename=\"%s\", ",
1726 uname.sysname, uname.nodename);
1727 tprintf("release=\"%s\", version=\"%s\", ",
1728 uname.release, uname.version);
1729 tprintf("machine=\"%s\"", uname.machine);
1730#ifdef LINUX
1731#ifndef __GLIBC__
1732 tprintf(", domainname=\"%s\"", uname.domainname);
1733#endif /* __GLIBC__ */
1734#endif /* LINUX */
1735 tprintf("}");
1736 }
1737 else
1738 tprintf("{sys=\"%s\", node=\"%s\", ...}",
1739 uname.sysname, uname.nodename);
1740 }
1741 return 0;
1742}
1743
1744#ifndef SVR4
1745
1746static struct xlat ptrace_cmds[] = {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001747#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001748 { PTRACE_TRACEME, "PTRACE_TRACEME" },
1749 { PTRACE_PEEKTEXT, "PTRACE_PEEKTEXT", },
1750 { PTRACE_PEEKDATA, "PTRACE_PEEKDATA", },
1751 { PTRACE_PEEKUSER, "PTRACE_PEEKUSER", },
1752 { PTRACE_POKETEXT, "PTRACE_POKETEXT", },
1753 { PTRACE_POKEDATA, "PTRACE_POKEDATA", },
1754 { PTRACE_POKEUSER, "PTRACE_POKEUSER", },
1755 { PTRACE_CONT, "PTRACE_CONT" },
1756 { PTRACE_KILL, "PTRACE_KILL" },
1757 { PTRACE_SINGLESTEP, "PTRACE_SINGLESTEP" },
1758 { PTRACE_ATTACH, "PTRACE_ATTACH" },
1759 { PTRACE_DETACH, "PTRACE_DETACH" },
1760#ifdef SUNOS4
1761 { PTRACE_GETREGS, "PTRACE_GETREGS" },
1762 { PTRACE_SETREGS, "PTRACE_SETREGS" },
1763 { PTRACE_GETFPREGS, "PTRACE_GETFPREGS", },
1764 { PTRACE_SETFPREGS, "PTRACE_SETFPREGS", },
1765 { PTRACE_READDATA, "PTRACE_READDATA" },
1766 { PTRACE_WRITEDATA, "PTRACE_WRITEDATA" },
1767 { PTRACE_READTEXT, "PTRACE_READTEXT" },
1768 { PTRACE_WRITETEXT, "PTRACE_WRITETEXT" },
1769 { PTRACE_GETFPAREGS, "PTRACE_GETFPAREGS" },
1770 { PTRACE_SETFPAREGS, "PTRACE_SETFPAREGS" },
1771#ifdef SPARC
1772 { PTRACE_GETWINDOW, "PTRACE_GETWINDOW" },
1773 { PTRACE_SETWINDOW, "PTRACE_SETWINDOW" },
1774#else /* !SPARC */
1775 { PTRACE_22, "PTRACE_PTRACE_22" },
1776 { PTRACE_23, "PTRACE_PTRACE_23" },
1777#endif /* !SPARC */
1778#endif /* SUNOS4 */
1779 { PTRACE_SYSCALL, "PTRACE_SYSCALL" },
1780#ifdef SUNOS4
1781 { PTRACE_DUMPCORE, "PTRACE_DUMPCORE" },
1782#ifdef I386
1783 { PTRACE_SETWRBKPT, "PTRACE_SETWRBKPT" },
1784 { PTRACE_SETACBKPT, "PTRACE_SETACBKPT" },
1785 { PTRACE_CLRDR7, "PTRACE_CLRDR7" },
1786#else /* !I386 */
1787 { PTRACE_26, "PTRACE_26" },
1788 { PTRACE_27, "PTRACE_27" },
1789 { PTRACE_28, "PTRACE_28" },
1790#endif /* !I386 */
1791 { PTRACE_GETUCODE, "PTRACE_GETUCODE" },
1792#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001793#else /* FREEBSD */
1794 { PT_TRACE_ME, "PT_TRACE_ME" },
1795 { PT_READ_I, "PT_READ_I" },
1796 { PT_READ_D, "PT_READ_D" },
1797 { PT_WRITE_I, "PT_WRITE_I" },
1798 { PT_WRITE_D, "PT_WRITE_D" },
John Hughesa2278142001-09-28 16:21:30 +00001799#ifdef PT_READ_U
1800 { PT_READ_U, "PT_READ_U" },
1801#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001802 { PT_CONTINUE, "PT_CONTINUE" },
1803 { PT_KILL, "PT_KILL" },
1804 { PT_STEP, "PT_STEP" },
1805 { PT_ATTACH, "PT_ATTACH" },
1806 { PT_DETACH, "PT_DETACH" },
1807 { PT_GETREGS, "PT_GETREGS" },
1808 { PT_SETREGS, "PT_SETREGS" },
1809 { PT_GETFPREGS, "PT_GETFPREGS" },
1810 { PT_SETFPREGS, "PT_SETFPREGS" },
1811 { PT_GETDBREGS, "PT_GETDBREGS" },
1812 { PT_SETDBREGS, "PT_SETDBREGS" },
1813#endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001814 { 0, NULL },
1815};
1816
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001817#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001818#ifndef SUNOS4_KERNEL_ARCH_KLUDGE
1819static
1820#endif /* !SUNOS4_KERNEL_ARCH_KLUDGE */
1821struct xlat struct_user_offsets[] = {
1822#ifdef LINUX
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001823#ifdef S390
1824 { PT_PSWMASK, "psw_mask" },
1825 { PT_PSWADDR, "psw_addr" },
1826 { PT_GPR0, "gpr0" },
1827 { PT_GPR1, "gpr1" },
1828 { PT_GPR2, "gpr2" },
1829 { PT_GPR3, "gpr3" },
1830 { PT_GPR4, "gpr4" },
1831 { PT_GPR5, "gpr5" },
1832 { PT_GPR6, "gpr6" },
1833 { PT_GPR7, "gpr7" },
1834 { PT_GPR8, "gpr8" },
1835 { PT_GPR9, "gpr9" },
1836 { PT_GPR10, "gpr10" },
1837 { PT_GPR11, "gpr11" },
1838 { PT_GPR12, "gpr12" },
1839 { PT_GPR13, "gpr13" },
1840 { PT_GPR14, "gpr14" },
1841 { PT_GPR15, "gpr15" },
1842 { PT_ACR0, "acr0" },
1843 { PT_ACR1, "acr1" },
1844 { PT_ACR2, "acr2" },
1845 { PT_ACR3, "acr3" },
1846 { PT_ACR4, "acr4" },
1847 { PT_ACR5, "acr5" },
1848 { PT_ACR6, "acr6" },
1849 { PT_ACR7, "acr7" },
1850 { PT_ACR8, "acr8" },
1851 { PT_ACR9, "acr9" },
1852 { PT_ACR10, "acr10" },
1853 { PT_ACR11, "acr11" },
1854 { PT_ACR12, "acr12" },
1855 { PT_ACR13, "acr13" },
1856 { PT_ACR14, "acr14" },
1857 { PT_ACR15, "acr15" },
1858 { PT_ORIGGPR2, "orig_gpr2" },
1859 { PT_FPC, "fpc" },
1860 { PT_FPR0_HI, "fpr0.hi" },
1861 { PT_FPR0_LO, "fpr0.lo" },
1862 { PT_FPR1_HI, "fpr1.hi" },
1863 { PT_FPR1_LO, "fpr1.lo" },
1864 { PT_FPR2_HI, "fpr2.hi" },
1865 { PT_FPR2_LO, "fpr2.lo" },
1866 { PT_FPR3_HI, "fpr3.hi" },
1867 { PT_FPR3_LO, "fpr3.lo" },
1868 { PT_FPR4_HI, "fpr4.hi" },
1869 { PT_FPR4_LO, "fpr4.lo" },
1870 { PT_FPR5_HI, "fpr5.hi" },
1871 { PT_FPR5_LO, "fpr5.lo" },
1872 { PT_FPR6_HI, "fpr6.hi" },
1873 { PT_FPR6_LO, "fpr6.lo" },
1874 { PT_FPR7_HI, "fpr7.hi" },
1875 { PT_FPR7_LO, "fpr7.lo" },
1876 { PT_FPR8_HI, "fpr8.hi" },
1877 { PT_FPR8_LO, "fpr8.lo" },
1878 { PT_FPR9_HI, "fpr9.hi" },
1879 { PT_FPR9_LO, "fpr9.lo" },
1880 { PT_FPR10_HI, "fpr10.hi" },
1881 { PT_FPR10_LO, "fpr10.lo" },
1882 { PT_FPR11_HI, "fpr11.hi" },
1883 { PT_FPR11_LO, "fpr11.lo" },
1884 { PT_FPR12_HI, "fpr12.hi" },
1885 { PT_FPR12_LO, "fpr12.lo" },
1886 { PT_FPR13_HI, "fpr13.hi" },
1887 { PT_FPR13_LO, "fpr13.lo" },
1888 { PT_FPR14_HI, "fpr14.hi" },
1889 { PT_FPR14_LO, "fpr14.lo" },
1890 { PT_FPR15_HI, "fpr15.hi" },
1891 { PT_FPR15_LO, "fpr15.lo" },
1892 { PT_CR_9, "cr9" },
1893 { PT_CR_10, "cr10" },
1894 { PT_CR_11, "cr11" },
1895#endif
1896#if defined(SPARC)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001897 /* XXX No support for these offsets yet. */
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001898#elif defined(HPPA)
1899 /* XXX No support for these offsets yet. */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001900#elif defined(POWERPC)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001901 { 4*PT_R0, "4*PT_R0" },
1902 { 4*PT_R1, "4*PT_R1" },
1903 { 4*PT_R2, "4*PT_R2" },
1904 { 4*PT_R3, "4*PT_R3" },
1905 { 4*PT_R4, "4*PT_R4" },
1906 { 4*PT_R5, "4*PT_R5" },
1907 { 4*PT_R6, "4*PT_R6" },
1908 { 4*PT_R7, "4*PT_R7" },
1909 { 4*PT_R8, "4*PT_R8" },
1910 { 4*PT_R9, "4*PT_R9" },
1911 { 4*PT_R10, "4*PT_R10" },
1912 { 4*PT_R11, "4*PT_R11" },
1913 { 4*PT_R12, "4*PT_R12" },
1914 { 4*PT_R13, "4*PT_R13" },
1915 { 4*PT_R14, "4*PT_R14" },
1916 { 4*PT_R15, "4*PT_R15" },
1917 { 4*PT_R16, "4*PT_R16" },
1918 { 4*PT_R17, "4*PT_R17" },
1919 { 4*PT_R18, "4*PT_R18" },
1920 { 4*PT_R19, "4*PT_R19" },
1921 { 4*PT_R20, "4*PT_R20" },
1922 { 4*PT_R21, "4*PT_R21" },
1923 { 4*PT_R22, "4*PT_R22" },
1924 { 4*PT_R23, "4*PT_R23" },
1925 { 4*PT_R24, "4*PT_R24" },
1926 { 4*PT_R25, "4*PT_R25" },
1927 { 4*PT_R26, "4*PT_R26" },
1928 { 4*PT_R27, "4*PT_R27" },
1929 { 4*PT_R28, "4*PT_R28" },
1930 { 4*PT_R29, "4*PT_R29" },
1931 { 4*PT_R30, "4*PT_R30" },
1932 { 4*PT_R31, "4*PT_R31" },
1933 { 4*PT_NIP, "4*PT_NIP" },
1934 { 4*PT_MSR, "4*PT_MSR" },
1935 { 4*PT_ORIG_R3, "4*PT_ORIG_R3" },
1936 { 4*PT_CTR, "4*PT_CTR" },
1937 { 4*PT_LNK, "4*PT_LNK" },
1938 { 4*PT_XER, "4*PT_XER" },
1939 { 4*PT_CCR, "4*PT_CCR" },
1940 { 4*PT_FPR0, "4*PT_FPR0" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001941#else
1942#ifdef ALPHA
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001943 { 0, "r0" },
1944 { 1, "r1" },
1945 { 2, "r2" },
1946 { 3, "r3" },
1947 { 4, "r4" },
1948 { 5, "r5" },
1949 { 6, "r6" },
1950 { 7, "r7" },
1951 { 8, "r8" },
1952 { 9, "r9" },
1953 { 10, "r10" },
1954 { 11, "r11" },
1955 { 12, "r12" },
1956 { 13, "r13" },
1957 { 14, "r14" },
1958 { 15, "r15" },
1959 { 16, "r16" },
1960 { 17, "r17" },
1961 { 18, "r18" },
1962 { 19, "r19" },
1963 { 20, "r20" },
1964 { 21, "r21" },
1965 { 22, "r22" },
1966 { 23, "r23" },
1967 { 24, "r24" },
1968 { 25, "r25" },
1969 { 26, "r26" },
1970 { 27, "r27" },
1971 { 28, "r28" },
1972 { 29, "gp" },
1973 { 30, "fp" },
1974 { 31, "zero" },
1975 { 32, "fp0" },
1976 { 33, "fp" },
1977 { 34, "fp2" },
1978 { 35, "fp3" },
1979 { 36, "fp4" },
1980 { 37, "fp5" },
1981 { 38, "fp6" },
1982 { 39, "fp7" },
1983 { 40, "fp8" },
1984 { 41, "fp9" },
1985 { 42, "fp10" },
1986 { 43, "fp11" },
1987 { 44, "fp12" },
1988 { 45, "fp13" },
1989 { 46, "fp14" },
1990 { 47, "fp15" },
1991 { 48, "fp16" },
1992 { 49, "fp17" },
1993 { 50, "fp18" },
1994 { 51, "fp19" },
1995 { 52, "fp20" },
1996 { 53, "fp21" },
1997 { 54, "fp22" },
1998 { 55, "fp23" },
1999 { 56, "fp24" },
2000 { 57, "fp25" },
2001 { 58, "fp26" },
2002 { 59, "fp27" },
2003 { 60, "fp28" },
2004 { 61, "fp29" },
2005 { 62, "fp30" },
2006 { 63, "fp31" },
2007 { 64, "pc" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002008#else /* !ALPHA */
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002009#ifdef IA64
2010 { PT_F32, "f32" }, { PT_F33, "f33" }, { PT_F34, "f34" },
2011 { PT_F35, "f35" }, { PT_F36, "f36" }, { PT_F37, "f37" },
2012 { PT_F38, "f38" }, { PT_F39, "f39" }, { PT_F40, "f40" },
2013 { PT_F41, "f41" }, { PT_F42, "f42" }, { PT_F43, "f43" },
2014 { PT_F44, "f44" }, { PT_F45, "f45" }, { PT_F46, "f46" },
2015 { PT_F47, "f47" }, { PT_F48, "f48" }, { PT_F49, "f49" },
2016 { PT_F50, "f50" }, { PT_F51, "f51" }, { PT_F52, "f52" },
2017 { PT_F53, "f53" }, { PT_F54, "f54" }, { PT_F55, "f55" },
2018 { PT_F56, "f56" }, { PT_F57, "f57" }, { PT_F58, "f58" },
2019 { PT_F59, "f59" }, { PT_F60, "f60" }, { PT_F61, "f61" },
2020 { PT_F62, "f62" }, { PT_F63, "f63" }, { PT_F64, "f64" },
2021 { PT_F65, "f65" }, { PT_F66, "f66" }, { PT_F67, "f67" },
2022 { PT_F68, "f68" }, { PT_F69, "f69" }, { PT_F70, "f70" },
2023 { PT_F71, "f71" }, { PT_F72, "f72" }, { PT_F73, "f73" },
2024 { PT_F74, "f74" }, { PT_F75, "f75" }, { PT_F76, "f76" },
2025 { PT_F77, "f77" }, { PT_F78, "f78" }, { PT_F79, "f79" },
2026 { PT_F80, "f80" }, { PT_F81, "f81" }, { PT_F82, "f82" },
2027 { PT_F83, "f83" }, { PT_F84, "f84" }, { PT_F85, "f85" },
2028 { PT_F86, "f86" }, { PT_F87, "f87" }, { PT_F88, "f88" },
2029 { PT_F89, "f89" }, { PT_F90, "f90" }, { PT_F91, "f91" },
2030 { PT_F92, "f92" }, { PT_F93, "f93" }, { PT_F94, "f94" },
2031 { PT_F95, "f95" }, { PT_F96, "f96" }, { PT_F97, "f97" },
2032 { PT_F98, "f98" }, { PT_F99, "f99" }, { PT_F100, "f100" },
2033 { PT_F101, "f101" }, { PT_F102, "f102" }, { PT_F103, "f103" },
2034 { PT_F104, "f104" }, { PT_F105, "f105" }, { PT_F106, "f106" },
2035 { PT_F107, "f107" }, { PT_F108, "f108" }, { PT_F109, "f109" },
2036 { PT_F110, "f110" }, { PT_F111, "f111" }, { PT_F112, "f112" },
2037 { PT_F113, "f113" }, { PT_F114, "f114" }, { PT_F115, "f115" },
2038 { PT_F116, "f116" }, { PT_F117, "f117" }, { PT_F118, "f118" },
2039 { PT_F119, "f119" }, { PT_F120, "f120" }, { PT_F121, "f121" },
2040 { PT_F122, "f122" }, { PT_F123, "f123" }, { PT_F124, "f124" },
2041 { PT_F125, "f125" }, { PT_F126, "f126" }, { PT_F127, "f127" },
2042 /* switch stack: */
2043 { PT_F2, "f2" }, { PT_F3, "f3" }, { PT_F4, "f4" },
2044 { PT_F5, "f5" }, { PT_F10, "f10" }, { PT_F11, "f11" },
2045 { PT_F12, "f12" }, { PT_F13, "f13" }, { PT_F14, "f14" },
2046 { PT_F15, "f15" }, { PT_F16, "f16" }, { PT_F17, "f17" },
2047 { PT_F18, "f18" }, { PT_F19, "f19" }, { PT_F20, "f20" },
2048 { PT_F21, "f21" }, { PT_F22, "f22" }, { PT_F23, "f23" },
2049 { PT_F24, "f24" }, { PT_F25, "f25" }, { PT_F26, "f26" },
2050 { PT_F27, "f27" }, { PT_F28, "f28" }, { PT_F29, "f29" },
2051 { PT_F30, "f30" }, { PT_F31, "f31" }, { PT_R4, "r4" },
2052 { PT_R5, "r5" }, { PT_R6, "r6" }, { PT_R7, "r7" },
Wichert Akkerman82b162e2001-08-03 11:51:28 +00002053 { PT_B0, "kb0" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002054 { PT_B1, "b1" }, { PT_B2, "b2" }, { PT_B3, "b3" },
2055 { PT_B4, "b4" }, { PT_B5, "b5" },
Wichert Akkerman82b162e2001-08-03 11:51:28 +00002056 { PT_AR_PFS, "kar.pfs" },
2057 { PT_AR_LC, "ar.lc" }, { PT_AR_UNAT, "kar.unat" },
2058 { PT_AR_RNAT, "kar.rnat" }, { PT_AR_BSPSTORE, "kar.bspstore" },
2059 { PT_PR, "k.pr" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002060 /* pt_regs */
2061 { PT_CR_IPSR, "cr.ipsr" }, { PT_CR_IIP, "cr.iip" },
Wichert Akkerman82b162e2001-08-03 11:51:28 +00002062 /*{ PT_CR_IFS, "cr.ifs" },*/ { PT_AR_UNAT, "ar.unat" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002063 { PT_AR_PFS, "ar.pfs" }, { PT_AR_RSC, "ar.rsc" },
2064 { PT_AR_RNAT, "ar.rnat" }, { PT_AR_BSPSTORE, "ar.bspstore" },
2065 { PT_PR, "pr" }, { PT_B6, "b6" }, { PT_AR_BSP, "ar.bsp" },
2066 { PT_R1, "r1" }, { PT_R2, "r2" }, { PT_R3, "r3" },
2067 { PT_R12, "r12" }, { PT_R13, "r13" }, { PT_R14, "r14" },
2068 { PT_R15, "r15" }, { PT_R8, "r8" }, { PT_R9, "r9" },
2069 { PT_R10, "r10" }, { PT_R11, "r11" }, { PT_R16, "r16" },
2070 { PT_R17, "r17" }, { PT_R18, "r18" }, { PT_R19, "r19" },
2071 { PT_R20, "r20" }, { PT_R21, "r21" }, { PT_R22, "r22" },
2072 { PT_R23, "r23" }, { PT_R24, "r24" }, { PT_R25, "r25" },
2073 { PT_R26, "r26" }, { PT_R27, "r27" }, { PT_R28, "r28" },
2074 { PT_R29, "r29" }, { PT_R30, "r30" }, { PT_R31, "r31" },
2075 { PT_AR_CCV, "ar.ccv" }, { PT_AR_FPSR, "ar.fpsr" },
2076 { PT_B0, "b0" }, { PT_B7, "b7" }, { PT_F6, "f6" },
2077 { PT_F7, "f7" }, { PT_F8, "f8" }, { PT_F9, "f9" },
2078#else /* !IA64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002079#ifdef I386
2080 { 4*EBX, "4*EBX" },
2081 { 4*ECX, "4*ECX" },
2082 { 4*EDX, "4*EDX" },
2083 { 4*ESI, "4*ESI" },
2084 { 4*EDI, "4*EDI" },
2085 { 4*EBP, "4*EBP" },
2086 { 4*EAX, "4*EAX" },
2087 { 4*DS, "4*DS" },
2088 { 4*ES, "4*ES" },
2089 { 4*FS, "4*FS" },
2090 { 4*GS, "4*GS" },
2091 { 4*ORIG_EAX, "4*ORIG_EAX" },
2092 { 4*EIP, "4*EIP" },
2093 { 4*CS, "4*CS" },
2094 { 4*EFL, "4*EFL" },
2095 { 4*UESP, "4*UESP" },
2096 { 4*SS, "4*SS" },
2097#else /* !I386 */
2098#ifdef M68K
2099 { 4*PT_D1, "4*PT_D1" },
2100 { 4*PT_D2, "4*PT_D2" },
2101 { 4*PT_D3, "4*PT_D3" },
2102 { 4*PT_D4, "4*PT_D4" },
2103 { 4*PT_D5, "4*PT_D5" },
2104 { 4*PT_D6, "4*PT_D6" },
2105 { 4*PT_D7, "4*PT_D7" },
2106 { 4*PT_A0, "4*PT_A0" },
2107 { 4*PT_A1, "4*PT_A1" },
2108 { 4*PT_A2, "4*PT_A2" },
2109 { 4*PT_A3, "4*PT_A3" },
2110 { 4*PT_A4, "4*PT_A4" },
2111 { 4*PT_A5, "4*PT_A5" },
2112 { 4*PT_A6, "4*PT_A6" },
2113 { 4*PT_D0, "4*PT_D0" },
2114 { 4*PT_USP, "4*PT_USP" },
2115 { 4*PT_ORIG_D0, "4*PT_ORIG_D0" },
2116 { 4*PT_SR, "4*PT_SR" },
2117 { 4*PT_PC, "4*PT_PC" },
2118#endif /* M68K */
2119#endif /* !I386 */
Wichert Akkerman12f75d12000-02-14 16:23:40 +00002120#if !defined(S390) && !defined(MIPS)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002121 { uoff(u_fpvalid), "offsetof(struct user, u_fpvalid)" },
Wichert Akkermanf90da011999-10-31 21:15:38 +00002122#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002123#ifdef I386
2124 { uoff(i387), "offsetof(struct user, i387)" },
2125#else /* !I386 */
2126#ifdef M68K
2127 { uoff(m68kfp), "offsetof(struct user, m68kfp)" },
2128#endif /* M68K */
2129#endif /* !I386 */
2130 { uoff(u_tsize), "offsetof(struct user, u_tsize)" },
2131 { uoff(u_dsize), "offsetof(struct user, u_dsize)" },
2132 { uoff(u_ssize), "offsetof(struct user, u_ssize)" },
2133 { uoff(start_code), "offsetof(struct user, start_code)" },
2134 { uoff(start_stack), "offsetof(struct user, start_stack)" },
2135 { uoff(signal), "offsetof(struct user, signal)" },
Wichert Akkerman12f75d12000-02-14 16:23:40 +00002136#if !defined(S390) && !defined(MIPS)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002137 { uoff(reserved), "offsetof(struct user, reserved)" },
Wichert Akkermanf90da011999-10-31 21:15:38 +00002138#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002139 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00002140#if !defined(ARM) && !defined(MIPS) && !defined(S390)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002141 { uoff(u_fpstate), "offsetof(struct user, u_fpstate)" },
2142#endif
2143 { uoff(magic), "offsetof(struct user, magic)" },
2144 { uoff(u_comm), "offsetof(struct user, u_comm)" },
2145#ifdef I386
2146 { uoff(u_debugreg), "offsetof(struct user, u_debugreg)" },
2147#endif /* I386 */
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002148#endif /* !IA64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002149#endif /* !ALPHA */
2150#endif /* !POWERPC/!SPARC */
2151#endif /* LINUX */
2152#ifdef SUNOS4
2153 { uoff(u_pcb), "offsetof(struct user, u_pcb)" },
2154 { uoff(u_procp), "offsetof(struct user, u_procp)" },
2155 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
2156 { uoff(u_comm[0]), "offsetof(struct user, u_comm[0])" },
2157 { uoff(u_arg[0]), "offsetof(struct user, u_arg[0])" },
2158 { uoff(u_ap), "offsetof(struct user, u_ap)" },
2159 { uoff(u_qsave), "offsetof(struct user, u_qsave)" },
2160 { uoff(u_rval1), "offsetof(struct user, u_rval1)" },
2161 { uoff(u_rval2), "offsetof(struct user, u_rval2)" },
2162 { uoff(u_error), "offsetof(struct user, u_error)" },
2163 { uoff(u_eosys), "offsetof(struct user, u_eosys)" },
2164 { uoff(u_ssave), "offsetof(struct user, u_ssave)" },
2165 { uoff(u_signal[0]), "offsetof(struct user, u_signal)" },
2166 { uoff(u_sigmask[0]), "offsetof(struct user, u_sigmask)" },
2167 { uoff(u_sigonstack), "offsetof(struct user, u_sigonstack)" },
2168 { uoff(u_sigintr), "offsetof(struct user, u_sigintr)" },
2169 { uoff(u_sigreset), "offsetof(struct user, u_sigreset)" },
2170 { uoff(u_oldmask), "offsetof(struct user, u_oldmask)" },
2171 { uoff(u_code), "offsetof(struct user, u_code)" },
2172 { uoff(u_addr), "offsetof(struct user, u_addr)" },
2173 { uoff(u_sigstack), "offsetof(struct user, u_sigstack)" },
2174 { uoff(u_ofile), "offsetof(struct user, u_ofile)" },
2175 { uoff(u_pofile), "offsetof(struct user, u_pofile)" },
2176 { uoff(u_ofile_arr[0]), "offsetof(struct user, u_ofile_arr[0])" },
2177 { uoff(u_pofile_arr[0]),"offsetof(struct user, u_pofile_arr[0])"},
2178 { uoff(u_lastfile), "offsetof(struct user, u_lastfile)" },
2179 { uoff(u_cwd), "offsetof(struct user, u_cwd)" },
2180 { uoff(u_cdir), "offsetof(struct user, u_cdir)" },
2181 { uoff(u_rdir), "offsetof(struct user, u_rdir)" },
2182 { uoff(u_cmask), "offsetof(struct user, u_cmask)" },
2183 { uoff(u_ru), "offsetof(struct user, u_ru)" },
2184 { uoff(u_cru), "offsetof(struct user, u_cru)" },
2185 { uoff(u_timer[0]), "offsetof(struct user, u_timer[0])" },
2186 { uoff(u_XXX[0]), "offsetof(struct user, u_XXX[0])" },
2187 { uoff(u_ioch), "offsetof(struct user, u_ioch)" },
2188 { uoff(u_start), "offsetof(struct user, u_start)" },
2189 { uoff(u_acflag), "offsetof(struct user, u_acflag)" },
2190 { uoff(u_prof.pr_base), "offsetof(struct user, u_prof.pr_base)" },
2191 { uoff(u_prof.pr_size), "offsetof(struct user, u_prof.pr_size)" },
2192 { uoff(u_prof.pr_off), "offsetof(struct user, u_prof.pr_off)" },
2193 { uoff(u_prof.pr_scale),"offsetof(struct user, u_prof.pr_scale)"},
2194 { uoff(u_rlimit[0]), "offsetof(struct user, u_rlimit)" },
2195 { uoff(u_exdata.Ux_A), "offsetof(struct user, u_exdata.Ux_A)" },
2196 { uoff(u_exdata.ux_shell[0]),"offsetof(struct user, u_exdata.ux_shell[0])"},
2197 { uoff(u_lofault), "offsetof(struct user, u_lofault)" },
2198#endif /* SUNOS4 */
Wichert Akkermanc1652e22001-03-27 12:17:16 +00002199#ifndef HPPA
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002200 { sizeof(struct user), "sizeof(struct user)" },
Wichert Akkermanc1652e22001-03-27 12:17:16 +00002201#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002202 { 0, NULL },
2203};
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002204#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002205
2206int
2207sys_ptrace(tcp)
2208struct tcb *tcp;
2209{
2210 char *cmd;
2211 struct xlat *x;
2212 long addr;
2213
2214 cmd = xlookup(ptrace_cmds, tcp->u_arg[0]);
2215 if (!cmd)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002216#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002217 cmd = "PTRACE_???";
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002218#else
2219 cmd = "PT_???";
2220#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002221 if (entering(tcp)) {
2222 tprintf("%s, %lu, ", cmd, tcp->u_arg[1]);
2223 addr = tcp->u_arg[2];
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002224#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002225 if (tcp->u_arg[0] == PTRACE_PEEKUSER
2226 || tcp->u_arg[0] == PTRACE_POKEUSER) {
2227 for (x = struct_user_offsets; x->str; x++) {
2228 if (x->val >= addr)
2229 break;
2230 }
2231 if (!x->str)
2232 tprintf("%#lx, ", addr);
2233 else if (x->val > addr && x != struct_user_offsets) {
2234 x--;
2235 tprintf("%s + %ld, ", x->str, addr - x->val);
2236 }
2237 else
2238 tprintf("%s, ", x->str);
2239 }
2240 else
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002241#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002242 tprintf("%#lx, ", tcp->u_arg[2]);
2243#ifdef LINUX
2244 switch (tcp->u_arg[0]) {
2245 case PTRACE_PEEKDATA:
2246 case PTRACE_PEEKTEXT:
2247 case PTRACE_PEEKUSER:
2248 break;
2249 case PTRACE_CONT:
2250 case PTRACE_SINGLESTEP:
2251 case PTRACE_SYSCALL:
2252 case PTRACE_DETACH:
2253 printsignal(tcp->u_arg[3]);
2254 break;
2255 default:
2256 tprintf("%#lx", tcp->u_arg[3]);
2257 break;
2258 }
2259 } else {
2260 switch (tcp->u_arg[0]) {
2261 case PTRACE_PEEKDATA:
2262 case PTRACE_PEEKTEXT:
2263 case PTRACE_PEEKUSER:
2264 printnum(tcp, tcp->u_arg[3], "%#x");
2265 break;
2266 }
2267 }
2268#endif /* LINUX */
2269#ifdef SUNOS4
2270 if (tcp->u_arg[0] == PTRACE_WRITEDATA ||
2271 tcp->u_arg[0] == PTRACE_WRITETEXT) {
2272 tprintf("%lu, ", tcp->u_arg[3]);
2273 printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]);
2274 } else if (tcp->u_arg[0] != PTRACE_READDATA &&
2275 tcp->u_arg[0] != PTRACE_READTEXT) {
2276 tprintf("%#lx", tcp->u_arg[3]);
2277 }
2278 } else {
2279 if (tcp->u_arg[0] == PTRACE_READDATA ||
2280 tcp->u_arg[0] == PTRACE_READTEXT) {
2281 tprintf("%lu, ", tcp->u_arg[3]);
2282 printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]);
2283 }
2284 }
2285#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002286#ifdef FREEBSD
2287 tprintf("%lu", tcp->u_arg[3]);
2288 }
2289#endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002290 return 0;
2291}
2292
2293#endif /* !SVR4 */