blob: ae7b8e4a06c9b93d02d69d4649e2916e5400558f [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 Akkerman15dea971999-10-06 13:06:34 +000052#if HAVE_LINUX_PTRACE_H
53#undef PTRACE_SYSCALL
Wichert Akkerman36915a11999-07-13 15:45:02 +000054#include <linux/ptrace.h>
55#endif
56
57#ifdef HAVE_SYS_REG_H
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000058# include <sys/reg.h>
Wichert Akkerman15dea971999-10-06 13:06:34 +000059#ifndef PTRACE_PEEKUSR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000060# define PTRACE_PEEKUSR PTRACE_PEEKUSER
Wichert Akkerman15dea971999-10-06 13:06:34 +000061#endif
62#ifndef PTRACE_POKEUSR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000063# define PTRACE_POKEUSR PTRACE_POKEUSER
64#endif
Wichert Akkerman15dea971999-10-06 13:06:34 +000065#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000066
67#ifdef LINUX
Wichert Akkerman2e2553a1999-05-09 00:29:58 +000068#include <asm/posix_types.h>
69#undef GETGROUPS_T
70#define GETGROUPS_T __kernel_gid_t
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000071#endif /* LINUX */
72
73#ifdef HAVE_PRCTL
74#include <sys/prctl.h>
75#endif
76
77#ifndef WCOREDUMP
78#define WCOREDUMP(status) ((status) & 0200)
79#endif
80
Wichert Akkerman7a0b6491999-12-23 15:08:17 +000081/* WTA: this was `&& !defined(LINUXSPARC)', this seems unneeded though? */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000082#if defined(HAVE_PRCTL)
83static struct xlat prctl_options[] = {
84#ifdef PR_MAXPROCS
85 { PR_MAXPROCS, "PR_MAXPROCS" },
86#endif
87#ifdef PR_ISBLOCKED
88 { PR_ISBLOCKED, "PR_ISBLOCKED" },
89#endif
90#ifdef PR_SETSTACKSIZE
91 { PR_SETSTACKSIZE, "PR_SETSTACKSIZE" },
92#endif
93#ifdef PR_GETSTACKSIZE
94 { PR_GETSTACKSIZE, "PR_GETSTACKSIZE" },
95#endif
96#ifdef PR_MAXPPROCS
97 { PR_MAXPPROCS, "PR_MAXPPROCS" },
98#endif
99#ifdef PR_UNBLKONEXEC
100 { PR_UNBLKONEXEC, "PR_UNBLKONEXEC" },
101#endif
102#ifdef PR_ATOMICSIM
103 { PR_ATOMICSIM, "PR_ATOMICSIM" },
104#endif
105#ifdef PR_SETEXITSIG
106 { PR_SETEXITSIG, "PR_SETEXITSIG" },
107#endif
108#ifdef PR_RESIDENT
109 { PR_RESIDENT, "PR_RESIDENT" },
110#endif
111#ifdef PR_ATTACHADDR
112 { PR_ATTACHADDR, "PR_ATTACHADDR" },
113#endif
114#ifdef PR_DETACHADDR
115 { PR_DETACHADDR, "PR_DETACHADDR" },
116#endif
117#ifdef PR_TERMCHILD
118 { PR_TERMCHILD, "PR_TERMCHILD" },
119#endif
120#ifdef PR_GETSHMASK
121 { PR_GETSHMASK, "PR_GETSHMASK" },
122#endif
123#ifdef PR_GETNSHARE
124 { PR_GETNSHARE, "PR_GETNSHARE" },
125#endif
126#if defined(PR_SET_PDEATHSIG)
127 { PR_SET_PDEATHSIG, "PR_SET_PDEATHSIG" },
128#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +0000129#ifdef PR_COREPID
130 { PR_COREPID, "PR_COREPID" },
131#endif
132#ifdef PR_ATTACHADDRPERM
133 { PR_ATTACHADDRPERM, "PR_ATTACHADDRPERM" },
134#endif
135#ifdef PR_PTHREADEXIT
136 { PR_PTHREADEXIT, "PR_PTHREADEXIT" },
137#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000138#ifdef PR_SET_PDEATHSIG
139 { PR_SET_PDEATHSIG, "PR_SET_PDEATHSIG" },
140#endif
141#ifdef PR_GET_PDEATHSIG
142 { PR_GET_PDEATHSIG, "PR_GET_PDEATHSIG" },
143#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000144 { 0, NULL },
145};
146
147int
148sys_prctl(tcp)
149struct tcb *tcp;
150{
151 int i;
152
153 if (entering(tcp)) {
154 printxval(prctl_options, tcp->u_arg[0], "PR_???");
155 switch (tcp->u_arg[0]) {
156#ifdef PR_GETNSHARE
157 case PR_GETNSHARE:
158 break;
159#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000160#ifdef PR_SET_DEATHSIG
161 case PR_GET_PDEATHSIG:
162 break;
163#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000164 default:
165 for (i = 1; i < tcp->u_nargs; i++)
166 tprintf(", %#lx", tcp->u_arg[i]);
167 break;
168 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000169 } else {
170 switch (tcp->u_arg[0]) {
171#ifdef PR_GET_PDEATHSIG
172 case PR_GET_PDEATHSIG:
173 for (i=1; i<tcp->u_nargs; i++)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000174 tprintf(", %#lx", tcp->u_arg[i]);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000175 break;
176#endif
177 default:
178 break;
179 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000180 }
181 return 0;
182}
183
184#endif /* HAVE_PRCTL */
185
186int
187sys_gethostid(tcp)
188struct tcb *tcp;
189{
190 if (exiting(tcp))
191 return RVAL_HEX;
192 return 0;
193}
194
195int
196sys_sethostname(tcp)
197struct tcb *tcp;
198{
199 if (entering(tcp)) {
200 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
201 tprintf(", %lu", tcp->u_arg[1]);
202 }
203 return 0;
204}
205
206int
207sys_gethostname(tcp)
208struct tcb *tcp;
209{
210 if (exiting(tcp)) {
211 if (syserror(tcp))
212 tprintf("%#lx", tcp->u_arg[0]);
213 else
214 printpath(tcp, tcp->u_arg[0]);
215 tprintf(", %lu", tcp->u_arg[1]);
216 }
217 return 0;
218}
219
220int
221sys_setdomainname(tcp)
222struct tcb *tcp;
223{
224 if (entering(tcp)) {
225 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
226 tprintf(", %lu", tcp->u_arg[1]);
227 }
228 return 0;
229}
230
Wichert Akkerman5daa0281999-03-15 19:49:42 +0000231#if !defined(LINUX)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000232
233int
234sys_getdomainname(tcp)
235struct tcb *tcp;
236{
237 if (exiting(tcp)) {
238 if (syserror(tcp))
239 tprintf("%#lx", tcp->u_arg[0]);
240 else
241 printpath(tcp, tcp->u_arg[0]);
242 tprintf(", %lu", tcp->u_arg[1]);
243 }
244 return 0;
245}
246#endif /* !LINUX */
247
248int
249sys_exit(tcp)
250struct tcb *tcp;
251{
252 if (exiting(tcp)) {
253 fprintf(stderr, "_exit returned!\n");
254 return -1;
255 }
256 /* special case: we stop tracing this process, finish line now */
257 tprintf("%ld) ", tcp->u_arg[0]);
258 tabto(acolumn);
259 tprintf("= ?");
260 printtrailer(tcp);
261 return 0;
262}
263
264int
265internal_exit(tcp)
266struct tcb *tcp;
267{
268 if (entering(tcp))
269 tcp->flags |= TCB_EXITING;
270 return 0;
271}
272
273#ifdef SVR4
274
275int
276sys_fork(tcp)
277struct tcb *tcp;
278{
279 if (exiting(tcp)) {
280 if (getrval2(tcp)) {
281 tcp->auxstr = "child process";
282 return RVAL_UDECIMAL | RVAL_STR;
283 }
284 }
285 return 0;
286}
287
288int
289internal_fork(tcp)
290struct tcb *tcp;
291{
292 struct tcb *tcpchild;
293
294 if (exiting(tcp)) {
295 if (getrval2(tcp))
296 return 0;
297 if (!followfork)
298 return 0;
299 if (nprocs == MAX_PROCS) {
300 tcp->flags &= ~TCB_FOLLOWFORK;
301 fprintf(stderr, "sys_fork: tcb table full\n");
302 return 0;
303 }
304 else
305 tcp->flags |= TCB_FOLLOWFORK;
306 if (syserror(tcp))
307 return 0;
308 if ((tcpchild = alloctcb(tcp->u_rval)) == NULL) {
309 fprintf(stderr, "sys_fork: tcb table full\n");
310 return 0;
311 }
312 proc_open(tcpchild, 1);
313 }
314 return 0;
315}
316
317#else /* !SVR4 */
318
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000319#ifdef LINUX
320
321/* defines copied from linux/sched.h since we can't include that
322 * ourselves (it conflicts with *lots* of libc includes)
323 */
324#define CSIGNAL 0x000000ff /* signal mask to be sent at exit */
325#define CLONE_VM 0x00000100 /* set if VM shared between processes */
326#define CLONE_FS 0x00000200 /* set if fs info shared between processes */
327#define CLONE_FILES 0x00000400 /* set if open files shared between processes */
328#define CLONE_SIGHAND 0x00000800 /* set if signal handlers shared */
329#define CLONE_PID 0x00001000 /* set if pid shared */
330#define CLONE_PTRACE 0x00002000 /* set if we want to let tracing continue on the child too */
331#define CLONE_VFORK 0x00004000 /* set if the parent wants the child to wake it up on mm_release */
332#define CLONE_PARENT 0x00008000 /* set if we want to have the same parent as the cloner */
333
334static struct xlat clone_flags[] = {
335 { CLONE_VM, "CLONE_VM" },
336 { CLONE_FS, "CLONE_FS" },
337 { CLONE_FILES, "CLONE_FILES" },
338 { CLONE_SIGHAND, "CLONE_SIGHAND" },
339 { CLONE_PID, "CLONE_PID" },
340 { CLONE_PTRACE, "CLONE_PTRACE" },
341 { CLONE_VFORK, "CLONE_VFORK" },
342 { CLONE_PARENT, "CLONE_PARENT" },
343 { 0, NULL },
344};
345
346#endif
347
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000348int
349sys_fork(tcp)
350struct tcb *tcp;
351{
352 if (exiting(tcp))
353 return RVAL_UDECIMAL;
354 return 0;
355}
356
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000357#ifdef SYS_clone
358int
359internal_clone(tcp)
360struct tcb *tcp;
361{
362 if (entering(tcp)) {
363 tprintf("fn=%#lx, child_stack=%#lx, flags=",
364 tcp->u_arg[0], tcp->u_arg[1]);
365 if (printflags(clone_flags, tcp->u_arg[2]) == 0)
366 tprintf("0");
367 tprintf(", args=%#lx", tcp->u_arg[3]);
368
369 /* For now we don't follow clone yet.. we're just preparing the code */
370 dont_follow = 1;
371
372 if (!followfork || dont_follow)
373 return 0;
374 if (nprocs == MAX_PROCS) {
375 tcp->flags &= ~TCB_FOLLOWFORK;
376 fprintf(stderr, "sys_fork: tcb table full\n");
377 return 0;
378 }
379 tcp->flags |= TCB_FOLLOWFORK;
380
381 /* XXX
382 /* We will take the simple approach and add CLONE_PTRACE to the clone
383 * options. This only works on Linux 2.2.x and later. This means that
384 * we break all programs using clone on older kernels..
385 * We should try to fallback to the bpt-trick if this fails, but right
386 * now we don't.
387 */
388
389 /* TODO: actually change the flags */
390 } else {
391 if (!(tcp->flags & TCB_FOLLOWFORK))
392 return 0;
393
394 if (syserror(tcp))
395 return 0;
396
397 pid = tcp->u_rval;
398 if ((tcpchild = alloctcb(pid)) == NULL) {
399 fprintf(stderr, " [tcb table full]\n");
400 kill(pid, SIGKILL); /* XXX */
401 return 0;
402 }
403
404 /* For fork we need to re-attach, but thanks to CLONE_PTRACE we're
405 * already attached.
406 */
407 tcphild->flags |= TCB_ATTACHED;
408 newoutf(tcpfhild);
409 tcp->nchildren++;
410 if (!qflag)
411 fprintf(stderr, "Process %d attached\n", pid);
412 }
413 return 0;
414}
415#endif
416
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000417int
418internal_fork(tcp)
419struct tcb *tcp;
420{
421 struct tcb *tcpchild;
422 int pid;
Nate Sammonsccd8f211999-03-29 22:57:54 +0000423 int dont_follow = 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000424
425#ifdef SYS_vfork
Nate Sammonsccd8f211999-03-29 22:57:54 +0000426 if (tcp->scno == SYS_vfork) {
427#if defined(I386) && defined(LINUX)
428 /* Attempt to make vfork into fork, which we can follow. */
429 if (!followvfork ||
430 ptrace(PTRACE_POKEUSR, tcp->pid,
431 (void *)(ORIG_EAX * 4), SYS_fork) < 0)
432 dont_follow = 1;
433
434#else
435 dont_follow = 1;
436#endif
437 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000438#endif
Nate Sammons38508fd1999-03-29 23:02:29 +0000439#ifdef SYS_clone
440 /* clone can do many things, not all of which we know how to handle.
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000441 Don't do much for now. */
442 if (tcp->scno == SYS_clone) {
443 if (entering(tcp)) {
444 tprintf("fn=%#lx, child_stack=%#lx, flags=",
445 tcp->u_arg[0], tcp->u_arg[1]);
446 if (printflags(clone_flags, tcp->u_arg[2]) == 0)
447 tprintf("0");
448 tprintf(", args=%#lx", tcp->u_arg[3]);
449 }
Nate Sammons38508fd1999-03-29 23:02:29 +0000450 dont_follow = 1;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000451 }
Nate Sammons38508fd1999-03-29 23:02:29 +0000452#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000453 if (entering(tcp)) {
Nate Sammonsccd8f211999-03-29 22:57:54 +0000454 if (!followfork || dont_follow)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000455 return 0;
456 if (nprocs == MAX_PROCS) {
457 tcp->flags &= ~TCB_FOLLOWFORK;
458 fprintf(stderr, "sys_fork: tcb table full\n");
459 return 0;
460 }
461 tcp->flags |= TCB_FOLLOWFORK;
462 if (setbpt(tcp) < 0)
463 return 0;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000464 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000465 else {
466 int bpt = tcp->flags & TCB_BPTSET;
467
468 if (!(tcp->flags & TCB_FOLLOWFORK))
469 return 0;
470 if (bpt)
471 clearbpt(tcp);
472
473 if (syserror(tcp))
474 return 0;
475
476 pid = tcp->u_rval;
477 if ((tcpchild = alloctcb(pid)) == NULL) {
478 fprintf(stderr, " [tcb table full]\n");
479 kill(pid, SIGKILL); /* XXX */
480 return 0;
481 }
482#ifdef LINUX
483 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) < 0) {
484 perror("PTRACE_ATTACH");
485 fprintf(stderr, "Too late?\n");
486 droptcb(tcpchild);
487 return 0;
488 }
489#endif /* LINUX */
490#ifdef SUNOS4
491#ifdef oldway
492 /* The child must have run before it can be attached. */
493 {
494 struct timeval tv;
495 tv.tv_sec = 0;
496 tv.tv_usec = 10000;
497 select(0, NULL, NULL, NULL, &tv);
498 }
499 if (ptrace(PTRACE_ATTACH, pid, (char *)1, 0) < 0) {
500 perror("PTRACE_ATTACH");
501 fprintf(stderr, "Too late?\n");
502 droptcb(tcpchild);
503 return 0;
504 }
505#else /* !oldway */
506 /* Try to catch the new process as soon as possible. */
507 {
508 int i;
509 for (i = 0; i < 1024; i++)
510 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) >= 0)
511 break;
512 if (i == 1024) {
513 perror("PTRACE_ATTACH");
514 fprintf(stderr, "Too late?\n");
515 droptcb(tcpchild);
516 return 0;
517 }
518 }
519#endif /* !oldway */
520#endif /* SUNOS4 */
521 tcpchild->flags |= TCB_ATTACHED;
522 /* Child has BPT too, must be removed on first occasion */
523 if (bpt) {
524 tcpchild->flags |= TCB_BPTSET;
525 tcpchild->baddr = tcp->baddr;
526 memcpy(tcpchild->inst, tcp->inst,
527 sizeof tcpchild->inst);
528 }
529 newoutf(tcpchild);
530 tcpchild->parent = tcp;
531 tcp->nchildren++;
532 if (!qflag)
533 fprintf(stderr, "Process %d attached\n", pid);
534 }
535 return 0;
536}
537
538#endif /* !SVR4 */
539
540#if defined(SUNOS4) || defined(LINUX)
541
542int
543sys_vfork(tcp)
544struct tcb *tcp;
545{
546 if (exiting(tcp))
547 return RVAL_UDECIMAL;
548 return 0;
549}
550
551#endif /* SUNOS4 || LINUX */
552
553#ifndef LINUX
554
555static char idstr[16];
556
557int
558sys_getpid(tcp)
559struct tcb *tcp;
560{
561 if (exiting(tcp)) {
562 sprintf(idstr, "ppid %lu", getrval2(tcp));
563 tcp->auxstr = idstr;
564 return RVAL_STR;
565 }
566 return 0;
567}
568
569int
570sys_getuid(tcp)
571struct tcb *tcp;
572{
573 if (exiting(tcp)) {
574 sprintf(idstr, "euid %lu", getrval2(tcp));
575 tcp->auxstr = idstr;
576 return RVAL_STR;
577 }
578 return 0;
579}
580
581int
582sys_getgid(tcp)
583struct tcb *tcp;
584{
585 if (exiting(tcp)) {
586 sprintf(idstr, "egid %lu", getrval2(tcp));
587 tcp->auxstr = idstr;
588 return RVAL_STR;
589 }
590 return 0;
591}
592
593#endif /* !LINUX */
594
595#ifdef LINUX
596
597int
598sys_setuid(tcp)
599struct tcb *tcp;
600{
601 if (entering(tcp)) {
602 tprintf("%u", (uid_t) tcp->u_arg[0]);
603 }
604 return 0;
605}
606
607int
608sys_setgid(tcp)
609struct tcb *tcp;
610{
611 if (entering(tcp)) {
612 tprintf("%u", (gid_t) tcp->u_arg[0]);
613 }
614 return 0;
615}
616
617int
618sys_getresuid(tcp)
619 struct tcb *tcp;
620{
621 if (exiting(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000622 __kernel_uid_t uid;
623 if (syserror(tcp))
624 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
625 tcp->u_arg[1], tcp->u_arg[2]);
626 else {
627 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
628 tprintf("%#lx, ", tcp->u_arg[0]);
629 else
630 tprintf("ruid %lu, ", (unsigned long) uid);
631 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
632 tprintf("%#lx, ", tcp->u_arg[0]);
633 else
634 tprintf("euid %lu, ", (unsigned long) uid);
635 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
636 tprintf("%#lx", tcp->u_arg[0]);
637 else
638 tprintf("suid %lu", (unsigned long) uid);
639 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000640 }
641 return 0;
642}
643
644int
645sys_getresgid(tcp)
646struct tcb *tcp;
647{
648 if (exiting(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000649 __kernel_gid_t gid;
650 if (syserror(tcp))
651 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
652 tcp->u_arg[1], tcp->u_arg[2]);
653 else {
654 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
655 tprintf("%#lx, ", tcp->u_arg[0]);
656 else
657 tprintf("rgid %lu, ", (unsigned long) gid);
658 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
659 tprintf("%#lx, ", tcp->u_arg[0]);
660 else
661 tprintf("egid %lu, ", (unsigned long) gid);
662 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
663 tprintf("%#lx", tcp->u_arg[0]);
664 else
665 tprintf("sgid %lu", (unsigned long) gid);
666 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000667 }
668 return 0;
669}
670
671#endif /* LINUX */
672
673int
674sys_setreuid(tcp)
675struct tcb *tcp;
676{
677 if (entering(tcp)) {
678 tprintf("%lu, %lu",
679 (unsigned long) (uid_t) tcp->u_arg[0],
680 (unsigned long) (uid_t) tcp->u_arg[1]);
681 }
682 return 0;
683}
684
685int
686sys_setregid(tcp)
687struct tcb *tcp;
688{
689 if (entering(tcp)) {
690 tprintf("%lu, %lu",
691 (unsigned long) (gid_t) tcp->u_arg[0],
692 (unsigned long) (gid_t) tcp->u_arg[1]);
693 }
694 return 0;
695}
696
697#ifdef LINUX
698int
699sys_setresuid(tcp)
700 struct tcb *tcp;
701{
702 if (entering(tcp)) {
703 tprintf("ruid %u, euid %u, suid %u",
704 (uid_t) tcp->u_arg[0],
705 (uid_t) tcp->u_arg[1],
706 (uid_t) tcp->u_arg[2]);
707 }
708 return 0;
709}
710int
711sys_setresgid(tcp)
712 struct tcb *tcp;
713{
714 if (entering(tcp)) {
715 tprintf("rgid %u, egid %u, sgid %u",
716 (uid_t) tcp->u_arg[0],
717 (uid_t) tcp->u_arg[1],
718 (uid_t) tcp->u_arg[2]);
719 }
720 return 0;
721}
722
723#endif /* LINUX */
724
725int
726sys_setgroups(tcp)
727struct tcb *tcp;
728{
729 int i, len;
730 GETGROUPS_T *gidset;
731
732 if (entering(tcp)) {
733 len = tcp->u_arg[0];
734 tprintf("%u, ", len);
735 if (len <= 0) {
736 tprintf("[]");
737 return 0;
738 }
739 gidset = (GETGROUPS_T *) malloc(len * sizeof(GETGROUPS_T));
740 if (gidset == NULL) {
741 fprintf(stderr, "sys_setgroups: out of memory\n");
742 return -1;
743 }
744 if (!verbose(tcp))
745 tprintf("%#lx", tcp->u_arg[1]);
746 else if (umoven(tcp, tcp->u_arg[1],
747 len * sizeof(GETGROUPS_T), (char *) gidset) < 0)
748 tprintf("[?]");
749 else {
750 tprintf("[");
751 for (i = 0; i < len; i++)
752 tprintf("%s%lu", i ? ", " : "",
753 (unsigned long) gidset[i]);
754 tprintf("]");
755 }
756 free((char *) gidset);
757 }
758 return 0;
759}
760
761int
762sys_getgroups(tcp)
763struct tcb *tcp;
764{
765 int i, len;
766 GETGROUPS_T *gidset;
767
768 if (entering(tcp)) {
769 len = tcp->u_arg[0];
770 tprintf("%u, ", len);
771 } else {
772 len = tcp->u_rval;
773 if (len <= 0) {
774 tprintf("[]");
775 return 0;
776 }
777 gidset = (GETGROUPS_T *) malloc(len * sizeof(GETGROUPS_T));
778 if (gidset == NULL) {
779 fprintf(stderr, "sys_getgroups: out of memory\n");
780 return -1;
781 }
782 if (!tcp->u_arg[1])
783 tprintf("NULL");
784 else if (!verbose(tcp) || tcp->u_arg[0] == 0)
785 tprintf("%#lx", tcp->u_arg[1]);
786 else if (umoven(tcp, tcp->u_arg[1],
787 len * sizeof(GETGROUPS_T), (char *) gidset) < 0)
788 tprintf("[?]");
789 else {
790 tprintf("[");
791 for (i = 0; i < len; i++)
792 tprintf("%s%lu", i ? ", " : "",
793 (unsigned long) gidset[i]);
794 tprintf("]");
795 }
796 free((char *)gidset);
797 }
798 return 0;
799}
800
801int
802sys_setpgrp(tcp)
803struct tcb *tcp;
804{
805 if (entering(tcp)) {
806#ifndef SVR4
807 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
808#endif /* !SVR4 */
809 }
810 return 0;
811}
812
813int
814sys_getpgrp(tcp)
815struct tcb *tcp;
816{
817 if (entering(tcp)) {
818#ifndef SVR4
819 tprintf("%lu", tcp->u_arg[0]);
820#endif /* !SVR4 */
821 }
822 return 0;
823}
824
825int
826sys_getsid(tcp)
827struct tcb *tcp;
828{
829 if (entering(tcp)) {
830 tprintf("%lu", tcp->u_arg[0]);
831 }
832 return 0;
833}
834
835int
836sys_setsid(tcp)
837struct tcb *tcp;
838{
839 return 0;
840}
841
842int
843sys_getpgid(tcp)
844struct tcb *tcp;
845{
846 if (entering(tcp)) {
847 tprintf("%lu", tcp->u_arg[0]);
848 }
849 return 0;
850}
851
852int
853sys_setpgid(tcp)
854struct tcb *tcp;
855{
856 if (entering(tcp)) {
857 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
858 }
859 return 0;
860}
861
862void
863fake_execve(tcp, program, argv, envp)
864struct tcb *tcp;
865char *program;
866char *argv[];
867char *envp[];
868{
869 int i;
870
871#ifdef ARM
872 if (!(qual_flags[SYS_execve - __NR_SYSCALL_BASE] & QUAL_TRACE))
873 return;
874#else
875 if (!(qual_flags[SYS_execve] & QUAL_TRACE))
876 return;
877#endif /* !ARM */
878 printleader(tcp);
879 tprintf("execve(");
880 string_quote(program);
881 tprintf(", [");
882 for (i = 0; argv[i] != NULL; i++) {
883 if (i != 0)
884 tprintf(", ");
885 string_quote(argv[i]);
886 }
887 for (i = 0; envp[i] != NULL; i++)
888 ;
889 tprintf("], [/* %d var%s */]) ", i, (i != 1) ? "s" : "");
890 tabto(acolumn);
891 tprintf("= 0");
892 printtrailer(tcp);
893}
894
895static void
896printargv(tcp, addr)
897struct tcb *tcp;
898long addr;
899{
900 char *cp;
901 char *sep;
902 int max = max_strlen / 2;
903
904 for (sep = ""; --max >= 0; sep = ", ") {
905 if (!abbrev(tcp))
906 max++;
907 if (umove(tcp, addr, &cp) < 0) {
908 tprintf("%#lx", addr);
909 return;
910 }
911 if (cp == 0)
912 break;
913 tprintf(sep);
914 printstr(tcp, (long) cp, -1);
915 addr += sizeof(char *);
916 }
917 if (cp)
918 tprintf(", ...");
919}
920
921static void
922printargc(fmt, tcp, addr)
923char *fmt;
924struct tcb *tcp;
925long addr;
926{
927 int count;
928 char *cp;
929
930 for (count = 0; umove(tcp, addr, &cp) >= 0 && cp != NULL; count++) {
931 addr += sizeof(char *);
932 }
933 tprintf(fmt, count, count == 1 ? "" : "s");
934}
935
936int
937sys_execv(tcp)
938struct tcb *tcp;
939{
940 if (entering(tcp)) {
941 printpath(tcp, tcp->u_arg[0]);
942 if (!verbose(tcp))
943 tprintf(", %#lx", tcp->u_arg[1]);
944#if 0
945 else if (abbrev(tcp))
946 printargc(", [/* %d arg%s */]", tcp, tcp->u_arg[1]);
947#endif
948 else {
949 tprintf(", [");
950 printargv(tcp, tcp->u_arg[1]);
951 tprintf("]");
952 }
953 }
954 return 0;
955}
956
957int
958sys_execve(tcp)
959struct tcb *tcp;
960{
961 if (entering(tcp)) {
962 printpath(tcp, tcp->u_arg[0]);
963 if (!verbose(tcp))
964 tprintf(", %#lx", tcp->u_arg[1]);
965#if 0
966 else if (abbrev(tcp))
967 printargc(", [/* %d arg%s */]", tcp, tcp->u_arg[1]);
968#endif
969 else {
970 tprintf(", [");
971 printargv(tcp, tcp->u_arg[1]);
972 tprintf("]");
973 }
974 if (!verbose(tcp))
975 tprintf(", %#lx", tcp->u_arg[2]);
976 else if (abbrev(tcp))
977 printargc(", [/* %d var%s */]", tcp, tcp->u_arg[2]);
978 else {
979 tprintf(", [");
980 printargv(tcp, tcp->u_arg[2]);
981 tprintf("]");
982 }
983 }
984#ifdef LINUX
985#if defined(ALPHA) || defined(SPARC) || defined(POWERPC)
986 tcp->flags |= TCB_WAITEXECVE;
987#endif /* ALPHA || SPARC || POWERPC */
988#endif /* LINUX */
989 return 0;
990}
991
992int
993internal_exec(tcp)
994struct tcb *tcp;
995{
996#ifdef SUNOS4
997 if (exiting(tcp) && !syserror(tcp) && followfork)
998 fixvfork(tcp);
999#endif /* SUNOS4 */
1000 return 0;
1001}
1002
1003#ifdef LINUX
1004#ifndef __WCLONE
1005#define __WCLONE 0x8000000
1006#endif
1007#endif /* LINUX */
1008
1009static struct xlat wait4_options[] = {
1010 { WNOHANG, "WNOHANG" },
1011#ifndef WSTOPPED
1012 { WUNTRACED, "WUNTRACED" },
1013#endif
1014#ifdef WEXITED
1015 { WEXITED, "WEXITED" },
1016#endif
1017#ifdef WTRAPPED
1018 { WTRAPPED, "WTRAPPED" },
1019#endif
1020#ifdef WSTOPPED
1021 { WSTOPPED, "WSTOPPED" },
1022#endif
1023#ifdef WCONTINUED
1024 { WCONTINUED, "WCONTINUED" },
1025#endif
1026#ifdef WNOWAIT
1027 { WNOWAIT, "WNOWAIT" },
1028#endif
1029#ifdef __WCLONE
1030 { __WCLONE, "__WCLONE" },
1031#endif
1032 { 0, NULL },
1033};
1034
1035static int
1036printstatus(status)
1037int status;
1038{
1039 int exited = 0;
1040
1041 /*
1042 * Here is a tricky presentation problem. This solution
1043 * is still not entirely satisfactory but since there
1044 * are no wait status constructors it will have to do.
1045 */
1046 if (WIFSTOPPED(status))
1047 tprintf("[WIFSTOPPED(s) && WSTOPSIG(s) == %s]",
Nate Sammonsce780fc1999-03-29 23:23:13 +00001048 signame(WSTOPSIG(status)));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001049 else if WIFSIGNALED(status)
1050 tprintf("[WIFSIGNALED(s) && WTERMSIG(s) == %s%s]",
Nate Sammonsce780fc1999-03-29 23:23:13 +00001051 signame(WTERMSIG(status)),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001052 WCOREDUMP(status) ? " && WCOREDUMP(s)" : "");
1053 else if WIFEXITED(status) {
1054 tprintf("[WIFEXITED(s) && WEXITSTATUS(s) == %d]",
1055 WEXITSTATUS(status));
1056 exited = 1;
1057 }
1058 else
1059 tprintf("[%#x]", status);
1060 return exited;
1061}
1062
1063static int
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001064printwaitn(tcp, n, bitness)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001065struct tcb *tcp;
1066int n;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001067int bitness;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001068{
1069 int status;
1070 int exited = 0;
1071
1072 if (entering(tcp)) {
1073 tprintf("%ld, ", tcp->u_arg[0]);
1074 } else {
1075 /* status */
1076 if (!tcp->u_arg[1])
1077 tprintf("NULL");
1078 else if (syserror(tcp) || tcp->u_rval == 0)
1079 tprintf("%#lx", tcp->u_arg[1]);
1080 else if (umove(tcp, tcp->u_arg[1], &status) < 0)
1081 tprintf("[?]");
1082 else
1083 exited = printstatus(status);
1084 /* options */
1085 tprintf(", ");
1086 if (!printflags(wait4_options, tcp->u_arg[2]))
1087 tprintf("0");
1088 if (n == 4) {
1089 tprintf(", ");
1090 /* usage */
1091 if (!tcp->u_arg[3])
1092 tprintf("NULL");
1093#ifdef LINUX
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001094 else if (tcp->u_rval > 0) {
1095#ifdef LINUX_64BIT
1096 if (bitness)
1097 printrusage32(tcp, tcp->u_arg[3]);
1098 else
1099#endif
1100 printrusage(tcp, tcp->u_arg[3]);
1101 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001102#endif /* LINUX */
1103#ifdef SUNOS4
1104 else if (tcp->u_rval > 0 && exited)
1105 printrusage(tcp, tcp->u_arg[3]);
1106#endif /* SUNOS4 */
1107 else
1108 tprintf("%#lx", tcp->u_arg[3]);
1109 }
1110 }
1111 return 0;
1112}
1113
1114int
1115internal_wait(tcp)
1116struct tcb *tcp;
1117{
1118 if (entering(tcp)) {
Wichert Akkerman5daa0281999-03-15 19:49:42 +00001119 /* WTA: fix bug with hanging children */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001120 if (!(tcp->u_arg[2] & WNOHANG) && tcp->nchildren > 0) {
1121 /* There are traced children */
1122 tcp->flags |= TCB_SUSPENDED;
1123 tcp->waitpid = tcp->u_arg[0];
1124 }
1125 }
1126 return 0;
1127}
1128
1129#ifdef SVR4
1130
1131int
1132sys_wait(tcp)
1133struct tcb *tcp;
1134{
1135 if (exiting(tcp)) {
1136 /* The library wrapper stuffs this into the user variable. */
1137 if (!syserror(tcp))
1138 printstatus(getrval2(tcp));
1139 }
1140 return 0;
1141}
1142
1143#endif /* SVR4 */
1144
1145int
1146sys_waitpid(tcp)
1147struct tcb *tcp;
1148{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001149 return printwaitn(tcp, 3, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001150}
1151
1152int
1153sys_wait4(tcp)
1154struct tcb *tcp;
1155{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001156 return printwaitn(tcp, 4, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001157}
1158
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001159#ifdef ALPHA
1160int
1161sys_osf_wait4(tcp)
1162struct tcb *tcp;
1163{
1164 return printwaitn(tcp, 4, 1);
1165}
1166#endif
1167
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001168#ifdef SVR4
1169
1170static struct xlat waitid_types[] = {
1171 { P_PID, "P_PID" },
1172 { P_PPID, "P_PPID" },
1173 { P_PGID, "P_PGID" },
1174 { P_SID, "P_SID" },
1175 { P_CID, "P_CID" },
1176 { P_UID, "P_UID" },
1177 { P_GID, "P_GID" },
1178 { P_ALL, "P_ALL" },
1179#ifdef P_LWPID
1180 { P_LWPID, "P_LWPID" },
1181#endif
1182 { 0, NULL },
1183};
1184
1185static struct xlat siginfo_codes[] = {
1186#ifdef SI_NOINFO
1187 { SI_NOINFO, "SI_NOINFO" },
1188#endif
1189#ifdef SI_USER
1190 { SI_USER, "SI_USER" },
1191#endif
1192#ifdef SI_LWP
1193 { SI_LWP, "SI_LWP" },
1194#endif
1195#ifdef SI_QUEUE
1196 { SI_QUEUE, "SI_QUEUE" },
1197#endif
1198#ifdef SI_TIMER
1199 { SI_TIMER, "SI_TIMER" },
1200#endif
1201#ifdef SI_ASYNCIO
1202 { SI_ASYNCIO, "SI_ASYNCIO" },
1203#endif
1204#ifdef SI_MESGQ
1205 { SI_MESGQ, "SI_MESGQ" },
1206#endif
1207 { 0, NULL },
1208};
1209
1210static struct xlat sigtrap_codes[] = {
1211 { TRAP_BRKPT, "TRAP_BRKPT" },
1212 { TRAP_TRACE, "TRAP_TRACE" },
1213 { 0, NULL },
1214};
1215
1216static struct xlat sigcld_codes[] = {
1217 { CLD_EXITED, "CLD_EXITED" },
1218 { CLD_KILLED, "CLD_KILLED" },
1219 { CLD_DUMPED, "CLD_DUMPED" },
1220 { CLD_TRAPPED, "CLD_TRAPPED" },
1221 { CLD_STOPPED, "CLD_STOPPED" },
1222 { CLD_CONTINUED,"CLD_CONTINUED" },
1223 { 0, NULL },
1224};
1225
1226static struct xlat sigpoll_codes[] = {
1227 { POLL_IN, "POLL_IN" },
1228 { POLL_OUT, "POLL_OUT" },
1229 { POLL_MSG, "POLL_MSG" },
1230 { POLL_ERR, "POLL_ERR" },
1231 { POLL_PRI, "POLL_PRI" },
1232 { POLL_HUP, "POLL_HUP" },
1233 { 0, NULL },
1234};
1235
1236static struct xlat sigprof_codes[] = {
1237#ifdef PROF_SIG
1238 { PROF_SIG, "PROF_SIG" },
1239#endif
1240 { 0, NULL },
1241};
1242
1243static struct xlat sigill_codes[] = {
1244 { ILL_ILLOPC, "ILL_ILLOPC" },
1245 { ILL_ILLOPN, "ILL_ILLOPN" },
1246 { ILL_ILLADR, "ILL_ILLADR" },
1247 { ILL_ILLTRP, "ILL_ILLTRP" },
1248 { ILL_PRVOPC, "ILL_PRVOPC" },
1249 { ILL_PRVREG, "ILL_PRVREG" },
1250 { ILL_COPROC, "ILL_COPROC" },
1251 { ILL_BADSTK, "ILL_BADSTK" },
1252 { 0, NULL },
1253};
1254
1255static struct xlat sigemt_codes[] = {
1256#ifdef EMT_TAGOVF
1257 { EMT_TAGOVF, "EMT_TAGOVF" },
1258#endif
1259 { 0, NULL },
1260};
1261
1262static struct xlat sigfpe_codes[] = {
1263 { FPE_INTDIV, "FPE_INTDIV" },
1264 { FPE_INTOVF, "FPE_INTOVF" },
1265 { FPE_FLTDIV, "FPE_FLTDIV" },
1266 { FPE_FLTOVF, "FPE_FLTOVF" },
1267 { FPE_FLTUND, "FPE_FLTUND" },
1268 { FPE_FLTRES, "FPE_FLTRES" },
1269 { FPE_FLTINV, "FPE_FLTINV" },
1270 { FPE_FLTSUB, "FPE_FLTSUB" },
1271 { 0, NULL },
1272};
1273
1274static struct xlat sigsegv_codes[] = {
1275 { SEGV_MAPERR, "SEGV_MAPERR" },
1276 { SEGV_ACCERR, "SEGV_ACCERR" },
1277 { 0, NULL },
1278};
1279
1280static struct xlat sigbus_codes[] = {
1281 { BUS_ADRALN, "BUS_ADRALN" },
1282 { BUS_ADRERR, "BUS_ADRERR" },
1283 { BUS_OBJERR, "BUS_OBJERR" },
1284 { 0, NULL },
1285};
1286
1287void
1288printsiginfo(sip)
1289siginfo_t *sip;
1290{
1291 char *code;
1292
1293 tprintf("{si_signo=");
1294 printsignal(sip->si_signo);
1295 code = xlookup(siginfo_codes, sip->si_code);
1296 if (!code) {
1297 switch (sip->si_signo) {
1298 case SIGTRAP:
1299 code = xlookup(sigtrap_codes, sip->si_code);
1300 break;
1301 case SIGCHLD:
1302 code = xlookup(sigcld_codes, sip->si_code);
1303 break;
1304 case SIGPOLL:
1305 code = xlookup(sigpoll_codes, sip->si_code);
1306 break;
1307 case SIGPROF:
1308 code = xlookup(sigprof_codes, sip->si_code);
1309 break;
1310 case SIGILL:
1311 code = xlookup(sigill_codes, sip->si_code);
1312 break;
1313 case SIGEMT:
1314 code = xlookup(sigemt_codes, sip->si_code);
1315 break;
1316 case SIGFPE:
1317 code = xlookup(sigfpe_codes, sip->si_code);
1318 break;
1319 case SIGSEGV:
1320 code = xlookup(sigsegv_codes, sip->si_code);
1321 break;
1322 case SIGBUS:
1323 code = xlookup(sigbus_codes, sip->si_code);
1324 break;
1325 }
1326 }
1327 if (code)
1328 tprintf(", si_code=%s", code);
1329 else
1330 tprintf(", si_code=%#x", sip->si_code);
1331#ifdef SI_NOINFO
1332 if (sip->si_code != SI_NOINFO) {
1333#endif
1334 if (sip->si_errno) {
1335 if (sip->si_errno < 0 || sip->si_errno >= nerrnos)
1336 tprintf(", si_errno=%d", sip->si_errno);
1337 else
1338 tprintf(", si_errno=%s",
1339 errnoent[sip->si_errno]);
1340 }
1341 if (SI_FROMUSER(sip)) {
1342#ifdef SI_QUEUE
1343 tprintf(", si_pid=%ld, si_uid=%ld",
1344 sip->si_pid, sip->si_uid);
1345 switch (sip->si_code) {
1346 case SI_QUEUE:
1347#ifdef SI_TIMER
1348 case SI_TIMER:
1349#endif /* SI_QUEUE */
1350 case SI_ASYNCIO:
1351#ifdef SI_MESGQ
1352 case SI_MESGQ:
1353#endif /* SI_MESGQ */
1354 tprintf(", si_value=%d",
1355 sip->si_value.sival_int);
1356 break;
1357 }
1358#endif /* SI_QUEUE */
1359 }
1360 else {
1361 switch (sip->si_signo) {
1362 case SIGCHLD:
1363 tprintf(", si_pid=%ld, si_status=",
1364 sip->si_pid);
1365 if (sip->si_code == CLD_EXITED)
1366 tprintf("%d", sip->si_status);
1367 else
1368 printsignal(sip->si_status);
1369 break;
1370 case SIGILL: case SIGFPE:
1371 case SIGSEGV: case SIGBUS:
1372 tprintf(", si_addr=%#lx",
1373 (unsigned long) sip->si_addr);
1374 break;
1375 case SIGPOLL:
1376 switch (sip->si_code) {
1377 case POLL_IN: case POLL_OUT: case POLL_MSG:
1378 tprintf(", si_band=%ld",
1379 (long) sip->si_band);
1380 break;
1381 }
1382 break;
1383 }
1384 }
1385 tprintf(", ...");
1386#ifdef SI_NOINFO
1387 }
1388#endif
1389 tprintf("}");
1390}
1391
1392int
1393sys_waitid(tcp)
1394struct tcb *tcp;
1395{
1396 siginfo_t si;
1397 int exited;
1398
1399 if (entering(tcp)) {
1400 printxval(waitid_types, tcp->u_arg[0], "P_???");
1401 tprintf(", %ld, ", tcp->u_arg[1]);
1402 if (tcp->nchildren > 0) {
1403 /* There are traced children */
1404 tcp->flags |= TCB_SUSPENDED;
1405 tcp->waitpid = tcp->u_arg[0];
1406 }
1407 }
1408 else {
1409 /* siginfo */
1410 exited = 0;
1411 if (!tcp->u_arg[2])
1412 tprintf("NULL");
1413 else if (syserror(tcp))
1414 tprintf("%#lx", tcp->u_arg[2]);
1415 else if (umove(tcp, tcp->u_arg[2], &si) < 0)
1416 tprintf("{???}");
1417 else
1418 printsiginfo(&si);
1419 /* options */
1420 tprintf(", ");
1421 if (!printflags(wait4_options, tcp->u_arg[3]))
1422 tprintf("0");
1423 }
1424 return 0;
1425}
1426
1427#endif /* SVR4 */
1428
1429int
1430sys_alarm(tcp)
1431struct tcb *tcp;
1432{
1433 if (entering(tcp))
1434 tprintf("%lu", tcp->u_arg[0]);
1435 return 0;
1436}
1437
1438int
1439sys_uname(tcp)
1440struct tcb *tcp;
1441{
1442 struct utsname uname;
1443
1444 if (exiting(tcp)) {
1445 if (syserror(tcp) || !verbose(tcp))
1446 tprintf("%#lx", tcp->u_arg[0]);
1447 else if (umove(tcp, tcp->u_arg[0], &uname) < 0)
1448 tprintf("{...}");
1449 else if (!abbrev(tcp)) {
1450
1451 tprintf("{sysname=\"%s\", nodename=\"%s\", ",
1452 uname.sysname, uname.nodename);
1453 tprintf("release=\"%s\", version=\"%s\", ",
1454 uname.release, uname.version);
1455 tprintf("machine=\"%s\"", uname.machine);
1456#ifdef LINUX
1457#ifndef __GLIBC__
1458 tprintf(", domainname=\"%s\"", uname.domainname);
1459#endif /* __GLIBC__ */
1460#endif /* LINUX */
1461 tprintf("}");
1462 }
1463 else
1464 tprintf("{sys=\"%s\", node=\"%s\", ...}",
1465 uname.sysname, uname.nodename);
1466 }
1467 return 0;
1468}
1469
1470#ifndef SVR4
1471
1472static struct xlat ptrace_cmds[] = {
1473 { PTRACE_TRACEME, "PTRACE_TRACEME" },
1474 { PTRACE_PEEKTEXT, "PTRACE_PEEKTEXT", },
1475 { PTRACE_PEEKDATA, "PTRACE_PEEKDATA", },
1476 { PTRACE_PEEKUSER, "PTRACE_PEEKUSER", },
1477 { PTRACE_POKETEXT, "PTRACE_POKETEXT", },
1478 { PTRACE_POKEDATA, "PTRACE_POKEDATA", },
1479 { PTRACE_POKEUSER, "PTRACE_POKEUSER", },
1480 { PTRACE_CONT, "PTRACE_CONT" },
1481 { PTRACE_KILL, "PTRACE_KILL" },
1482 { PTRACE_SINGLESTEP, "PTRACE_SINGLESTEP" },
1483 { PTRACE_ATTACH, "PTRACE_ATTACH" },
1484 { PTRACE_DETACH, "PTRACE_DETACH" },
1485#ifdef SUNOS4
1486 { PTRACE_GETREGS, "PTRACE_GETREGS" },
1487 { PTRACE_SETREGS, "PTRACE_SETREGS" },
1488 { PTRACE_GETFPREGS, "PTRACE_GETFPREGS", },
1489 { PTRACE_SETFPREGS, "PTRACE_SETFPREGS", },
1490 { PTRACE_READDATA, "PTRACE_READDATA" },
1491 { PTRACE_WRITEDATA, "PTRACE_WRITEDATA" },
1492 { PTRACE_READTEXT, "PTRACE_READTEXT" },
1493 { PTRACE_WRITETEXT, "PTRACE_WRITETEXT" },
1494 { PTRACE_GETFPAREGS, "PTRACE_GETFPAREGS" },
1495 { PTRACE_SETFPAREGS, "PTRACE_SETFPAREGS" },
1496#ifdef SPARC
1497 { PTRACE_GETWINDOW, "PTRACE_GETWINDOW" },
1498 { PTRACE_SETWINDOW, "PTRACE_SETWINDOW" },
1499#else /* !SPARC */
1500 { PTRACE_22, "PTRACE_PTRACE_22" },
1501 { PTRACE_23, "PTRACE_PTRACE_23" },
1502#endif /* !SPARC */
1503#endif /* SUNOS4 */
1504 { PTRACE_SYSCALL, "PTRACE_SYSCALL" },
1505#ifdef SUNOS4
1506 { PTRACE_DUMPCORE, "PTRACE_DUMPCORE" },
1507#ifdef I386
1508 { PTRACE_SETWRBKPT, "PTRACE_SETWRBKPT" },
1509 { PTRACE_SETACBKPT, "PTRACE_SETACBKPT" },
1510 { PTRACE_CLRDR7, "PTRACE_CLRDR7" },
1511#else /* !I386 */
1512 { PTRACE_26, "PTRACE_26" },
1513 { PTRACE_27, "PTRACE_27" },
1514 { PTRACE_28, "PTRACE_28" },
1515#endif /* !I386 */
1516 { PTRACE_GETUCODE, "PTRACE_GETUCODE" },
1517#endif /* SUNOS4 */
1518 { 0, NULL },
1519};
1520
1521#ifndef SUNOS4_KERNEL_ARCH_KLUDGE
1522static
1523#endif /* !SUNOS4_KERNEL_ARCH_KLUDGE */
1524struct xlat struct_user_offsets[] = {
1525#ifdef LINUX
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001526#ifdef S390
1527 { PT_PSWMASK, "psw_mask" },
1528 { PT_PSWADDR, "psw_addr" },
1529 { PT_GPR0, "gpr0" },
1530 { PT_GPR1, "gpr1" },
1531 { PT_GPR2, "gpr2" },
1532 { PT_GPR3, "gpr3" },
1533 { PT_GPR4, "gpr4" },
1534 { PT_GPR5, "gpr5" },
1535 { PT_GPR6, "gpr6" },
1536 { PT_GPR7, "gpr7" },
1537 { PT_GPR8, "gpr8" },
1538 { PT_GPR9, "gpr9" },
1539 { PT_GPR10, "gpr10" },
1540 { PT_GPR11, "gpr11" },
1541 { PT_GPR12, "gpr12" },
1542 { PT_GPR13, "gpr13" },
1543 { PT_GPR14, "gpr14" },
1544 { PT_GPR15, "gpr15" },
1545 { PT_ACR0, "acr0" },
1546 { PT_ACR1, "acr1" },
1547 { PT_ACR2, "acr2" },
1548 { PT_ACR3, "acr3" },
1549 { PT_ACR4, "acr4" },
1550 { PT_ACR5, "acr5" },
1551 { PT_ACR6, "acr6" },
1552 { PT_ACR7, "acr7" },
1553 { PT_ACR8, "acr8" },
1554 { PT_ACR9, "acr9" },
1555 { PT_ACR10, "acr10" },
1556 { PT_ACR11, "acr11" },
1557 { PT_ACR12, "acr12" },
1558 { PT_ACR13, "acr13" },
1559 { PT_ACR14, "acr14" },
1560 { PT_ACR15, "acr15" },
1561 { PT_ORIGGPR2, "orig_gpr2" },
1562 { PT_FPC, "fpc" },
1563 { PT_FPR0_HI, "fpr0.hi" },
1564 { PT_FPR0_LO, "fpr0.lo" },
1565 { PT_FPR1_HI, "fpr1.hi" },
1566 { PT_FPR1_LO, "fpr1.lo" },
1567 { PT_FPR2_HI, "fpr2.hi" },
1568 { PT_FPR2_LO, "fpr2.lo" },
1569 { PT_FPR3_HI, "fpr3.hi" },
1570 { PT_FPR3_LO, "fpr3.lo" },
1571 { PT_FPR4_HI, "fpr4.hi" },
1572 { PT_FPR4_LO, "fpr4.lo" },
1573 { PT_FPR5_HI, "fpr5.hi" },
1574 { PT_FPR5_LO, "fpr5.lo" },
1575 { PT_FPR6_HI, "fpr6.hi" },
1576 { PT_FPR6_LO, "fpr6.lo" },
1577 { PT_FPR7_HI, "fpr7.hi" },
1578 { PT_FPR7_LO, "fpr7.lo" },
1579 { PT_FPR8_HI, "fpr8.hi" },
1580 { PT_FPR8_LO, "fpr8.lo" },
1581 { PT_FPR9_HI, "fpr9.hi" },
1582 { PT_FPR9_LO, "fpr9.lo" },
1583 { PT_FPR10_HI, "fpr10.hi" },
1584 { PT_FPR10_LO, "fpr10.lo" },
1585 { PT_FPR11_HI, "fpr11.hi" },
1586 { PT_FPR11_LO, "fpr11.lo" },
1587 { PT_FPR12_HI, "fpr12.hi" },
1588 { PT_FPR12_LO, "fpr12.lo" },
1589 { PT_FPR13_HI, "fpr13.hi" },
1590 { PT_FPR13_LO, "fpr13.lo" },
1591 { PT_FPR14_HI, "fpr14.hi" },
1592 { PT_FPR14_LO, "fpr14.lo" },
1593 { PT_FPR15_HI, "fpr15.hi" },
1594 { PT_FPR15_LO, "fpr15.lo" },
1595 { PT_CR_9, "cr9" },
1596 { PT_CR_10, "cr10" },
1597 { PT_CR_11, "cr11" },
1598#endif
1599#if defined(SPARC)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001600 /* XXX No support for these offsets yet. */
1601#elif defined(POWERPC)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001602 { 4*PT_R0, "4*PT_R0" },
1603 { 4*PT_R1, "4*PT_R1" },
1604 { 4*PT_R2, "4*PT_R2" },
1605 { 4*PT_R3, "4*PT_R3" },
1606 { 4*PT_R4, "4*PT_R4" },
1607 { 4*PT_R5, "4*PT_R5" },
1608 { 4*PT_R6, "4*PT_R6" },
1609 { 4*PT_R7, "4*PT_R7" },
1610 { 4*PT_R8, "4*PT_R8" },
1611 { 4*PT_R9, "4*PT_R9" },
1612 { 4*PT_R10, "4*PT_R10" },
1613 { 4*PT_R11, "4*PT_R11" },
1614 { 4*PT_R12, "4*PT_R12" },
1615 { 4*PT_R13, "4*PT_R13" },
1616 { 4*PT_R14, "4*PT_R14" },
1617 { 4*PT_R15, "4*PT_R15" },
1618 { 4*PT_R16, "4*PT_R16" },
1619 { 4*PT_R17, "4*PT_R17" },
1620 { 4*PT_R18, "4*PT_R18" },
1621 { 4*PT_R19, "4*PT_R19" },
1622 { 4*PT_R20, "4*PT_R20" },
1623 { 4*PT_R21, "4*PT_R21" },
1624 { 4*PT_R22, "4*PT_R22" },
1625 { 4*PT_R23, "4*PT_R23" },
1626 { 4*PT_R24, "4*PT_R24" },
1627 { 4*PT_R25, "4*PT_R25" },
1628 { 4*PT_R26, "4*PT_R26" },
1629 { 4*PT_R27, "4*PT_R27" },
1630 { 4*PT_R28, "4*PT_R28" },
1631 { 4*PT_R29, "4*PT_R29" },
1632 { 4*PT_R30, "4*PT_R30" },
1633 { 4*PT_R31, "4*PT_R31" },
1634 { 4*PT_NIP, "4*PT_NIP" },
1635 { 4*PT_MSR, "4*PT_MSR" },
1636 { 4*PT_ORIG_R3, "4*PT_ORIG_R3" },
1637 { 4*PT_CTR, "4*PT_CTR" },
1638 { 4*PT_LNK, "4*PT_LNK" },
1639 { 4*PT_XER, "4*PT_XER" },
1640 { 4*PT_CCR, "4*PT_CCR" },
1641 { 4*PT_FPR0, "4*PT_FPR0" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001642#else
1643#ifdef ALPHA
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001644 { 0, "r0" },
1645 { 1, "r1" },
1646 { 2, "r2" },
1647 { 3, "r3" },
1648 { 4, "r4" },
1649 { 5, "r5" },
1650 { 6, "r6" },
1651 { 7, "r7" },
1652 { 8, "r8" },
1653 { 9, "r9" },
1654 { 10, "r10" },
1655 { 11, "r11" },
1656 { 12, "r12" },
1657 { 13, "r13" },
1658 { 14, "r14" },
1659 { 15, "r15" },
1660 { 16, "r16" },
1661 { 17, "r17" },
1662 { 18, "r18" },
1663 { 19, "r19" },
1664 { 20, "r20" },
1665 { 21, "r21" },
1666 { 22, "r22" },
1667 { 23, "r23" },
1668 { 24, "r24" },
1669 { 25, "r25" },
1670 { 26, "r26" },
1671 { 27, "r27" },
1672 { 28, "r28" },
1673 { 29, "gp" },
1674 { 30, "fp" },
1675 { 31, "zero" },
1676 { 32, "fp0" },
1677 { 33, "fp" },
1678 { 34, "fp2" },
1679 { 35, "fp3" },
1680 { 36, "fp4" },
1681 { 37, "fp5" },
1682 { 38, "fp6" },
1683 { 39, "fp7" },
1684 { 40, "fp8" },
1685 { 41, "fp9" },
1686 { 42, "fp10" },
1687 { 43, "fp11" },
1688 { 44, "fp12" },
1689 { 45, "fp13" },
1690 { 46, "fp14" },
1691 { 47, "fp15" },
1692 { 48, "fp16" },
1693 { 49, "fp17" },
1694 { 50, "fp18" },
1695 { 51, "fp19" },
1696 { 52, "fp20" },
1697 { 53, "fp21" },
1698 { 54, "fp22" },
1699 { 55, "fp23" },
1700 { 56, "fp24" },
1701 { 57, "fp25" },
1702 { 58, "fp26" },
1703 { 59, "fp27" },
1704 { 60, "fp28" },
1705 { 61, "fp29" },
1706 { 62, "fp30" },
1707 { 63, "fp31" },
1708 { 64, "pc" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001709#else /* !ALPHA */
1710#ifdef I386
1711 { 4*EBX, "4*EBX" },
1712 { 4*ECX, "4*ECX" },
1713 { 4*EDX, "4*EDX" },
1714 { 4*ESI, "4*ESI" },
1715 { 4*EDI, "4*EDI" },
1716 { 4*EBP, "4*EBP" },
1717 { 4*EAX, "4*EAX" },
1718 { 4*DS, "4*DS" },
1719 { 4*ES, "4*ES" },
1720 { 4*FS, "4*FS" },
1721 { 4*GS, "4*GS" },
1722 { 4*ORIG_EAX, "4*ORIG_EAX" },
1723 { 4*EIP, "4*EIP" },
1724 { 4*CS, "4*CS" },
1725 { 4*EFL, "4*EFL" },
1726 { 4*UESP, "4*UESP" },
1727 { 4*SS, "4*SS" },
1728#else /* !I386 */
1729#ifdef M68K
1730 { 4*PT_D1, "4*PT_D1" },
1731 { 4*PT_D2, "4*PT_D2" },
1732 { 4*PT_D3, "4*PT_D3" },
1733 { 4*PT_D4, "4*PT_D4" },
1734 { 4*PT_D5, "4*PT_D5" },
1735 { 4*PT_D6, "4*PT_D6" },
1736 { 4*PT_D7, "4*PT_D7" },
1737 { 4*PT_A0, "4*PT_A0" },
1738 { 4*PT_A1, "4*PT_A1" },
1739 { 4*PT_A2, "4*PT_A2" },
1740 { 4*PT_A3, "4*PT_A3" },
1741 { 4*PT_A4, "4*PT_A4" },
1742 { 4*PT_A5, "4*PT_A5" },
1743 { 4*PT_A6, "4*PT_A6" },
1744 { 4*PT_D0, "4*PT_D0" },
1745 { 4*PT_USP, "4*PT_USP" },
1746 { 4*PT_ORIG_D0, "4*PT_ORIG_D0" },
1747 { 4*PT_SR, "4*PT_SR" },
1748 { 4*PT_PC, "4*PT_PC" },
1749#endif /* M68K */
1750#endif /* !I386 */
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001751#ifdef S390
1752 { uoff(u_fpvalid), "offsetof(struct user, u_fpvalid)" },
1753#endif
Wichert Akkermanf90da011999-10-31 21:15:38 +00001754#ifndef MIPS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001755 { uoff(u_fpvalid), "offsetof(struct user, u_fpvalid)" },
Wichert Akkermanf90da011999-10-31 21:15:38 +00001756#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001757#ifdef I386
1758 { uoff(i387), "offsetof(struct user, i387)" },
1759#else /* !I386 */
1760#ifdef M68K
1761 { uoff(m68kfp), "offsetof(struct user, m68kfp)" },
1762#endif /* M68K */
1763#endif /* !I386 */
1764 { uoff(u_tsize), "offsetof(struct user, u_tsize)" },
1765 { uoff(u_dsize), "offsetof(struct user, u_dsize)" },
1766 { uoff(u_ssize), "offsetof(struct user, u_ssize)" },
1767 { uoff(start_code), "offsetof(struct user, start_code)" },
1768 { uoff(start_stack), "offsetof(struct user, start_stack)" },
1769 { uoff(signal), "offsetof(struct user, signal)" },
Wichert Akkermanf90da011999-10-31 21:15:38 +00001770#ifndef MIPS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001771 { uoff(reserved), "offsetof(struct user, reserved)" },
Wichert Akkermanf90da011999-10-31 21:15:38 +00001772#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001773 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001774#if !defined(ARM) && !defined(MIPS) && !defined(S390)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001775 { uoff(u_fpstate), "offsetof(struct user, u_fpstate)" },
1776#endif
1777 { uoff(magic), "offsetof(struct user, magic)" },
1778 { uoff(u_comm), "offsetof(struct user, u_comm)" },
1779#ifdef I386
1780 { uoff(u_debugreg), "offsetof(struct user, u_debugreg)" },
1781#endif /* I386 */
1782#endif /* !ALPHA */
1783#endif /* !POWERPC/!SPARC */
1784#endif /* LINUX */
1785#ifdef SUNOS4
1786 { uoff(u_pcb), "offsetof(struct user, u_pcb)" },
1787 { uoff(u_procp), "offsetof(struct user, u_procp)" },
1788 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
1789 { uoff(u_comm[0]), "offsetof(struct user, u_comm[0])" },
1790 { uoff(u_arg[0]), "offsetof(struct user, u_arg[0])" },
1791 { uoff(u_ap), "offsetof(struct user, u_ap)" },
1792 { uoff(u_qsave), "offsetof(struct user, u_qsave)" },
1793 { uoff(u_rval1), "offsetof(struct user, u_rval1)" },
1794 { uoff(u_rval2), "offsetof(struct user, u_rval2)" },
1795 { uoff(u_error), "offsetof(struct user, u_error)" },
1796 { uoff(u_eosys), "offsetof(struct user, u_eosys)" },
1797 { uoff(u_ssave), "offsetof(struct user, u_ssave)" },
1798 { uoff(u_signal[0]), "offsetof(struct user, u_signal)" },
1799 { uoff(u_sigmask[0]), "offsetof(struct user, u_sigmask)" },
1800 { uoff(u_sigonstack), "offsetof(struct user, u_sigonstack)" },
1801 { uoff(u_sigintr), "offsetof(struct user, u_sigintr)" },
1802 { uoff(u_sigreset), "offsetof(struct user, u_sigreset)" },
1803 { uoff(u_oldmask), "offsetof(struct user, u_oldmask)" },
1804 { uoff(u_code), "offsetof(struct user, u_code)" },
1805 { uoff(u_addr), "offsetof(struct user, u_addr)" },
1806 { uoff(u_sigstack), "offsetof(struct user, u_sigstack)" },
1807 { uoff(u_ofile), "offsetof(struct user, u_ofile)" },
1808 { uoff(u_pofile), "offsetof(struct user, u_pofile)" },
1809 { uoff(u_ofile_arr[0]), "offsetof(struct user, u_ofile_arr[0])" },
1810 { uoff(u_pofile_arr[0]),"offsetof(struct user, u_pofile_arr[0])"},
1811 { uoff(u_lastfile), "offsetof(struct user, u_lastfile)" },
1812 { uoff(u_cwd), "offsetof(struct user, u_cwd)" },
1813 { uoff(u_cdir), "offsetof(struct user, u_cdir)" },
1814 { uoff(u_rdir), "offsetof(struct user, u_rdir)" },
1815 { uoff(u_cmask), "offsetof(struct user, u_cmask)" },
1816 { uoff(u_ru), "offsetof(struct user, u_ru)" },
1817 { uoff(u_cru), "offsetof(struct user, u_cru)" },
1818 { uoff(u_timer[0]), "offsetof(struct user, u_timer[0])" },
1819 { uoff(u_XXX[0]), "offsetof(struct user, u_XXX[0])" },
1820 { uoff(u_ioch), "offsetof(struct user, u_ioch)" },
1821 { uoff(u_start), "offsetof(struct user, u_start)" },
1822 { uoff(u_acflag), "offsetof(struct user, u_acflag)" },
1823 { uoff(u_prof.pr_base), "offsetof(struct user, u_prof.pr_base)" },
1824 { uoff(u_prof.pr_size), "offsetof(struct user, u_prof.pr_size)" },
1825 { uoff(u_prof.pr_off), "offsetof(struct user, u_prof.pr_off)" },
1826 { uoff(u_prof.pr_scale),"offsetof(struct user, u_prof.pr_scale)"},
1827 { uoff(u_rlimit[0]), "offsetof(struct user, u_rlimit)" },
1828 { uoff(u_exdata.Ux_A), "offsetof(struct user, u_exdata.Ux_A)" },
1829 { uoff(u_exdata.ux_shell[0]),"offsetof(struct user, u_exdata.ux_shell[0])"},
1830 { uoff(u_lofault), "offsetof(struct user, u_lofault)" },
1831#endif /* SUNOS4 */
1832 { sizeof(struct user), "sizeof(struct user)" },
1833 { 0, NULL },
1834};
1835
1836int
1837sys_ptrace(tcp)
1838struct tcb *tcp;
1839{
1840 char *cmd;
1841 struct xlat *x;
1842 long addr;
1843
1844 cmd = xlookup(ptrace_cmds, tcp->u_arg[0]);
1845 if (!cmd)
1846 cmd = "PTRACE_???";
1847 if (entering(tcp)) {
1848 tprintf("%s, %lu, ", cmd, tcp->u_arg[1]);
1849 addr = tcp->u_arg[2];
1850 if (tcp->u_arg[0] == PTRACE_PEEKUSER
1851 || tcp->u_arg[0] == PTRACE_POKEUSER) {
1852 for (x = struct_user_offsets; x->str; x++) {
1853 if (x->val >= addr)
1854 break;
1855 }
1856 if (!x->str)
1857 tprintf("%#lx, ", addr);
1858 else if (x->val > addr && x != struct_user_offsets) {
1859 x--;
1860 tprintf("%s + %ld, ", x->str, addr - x->val);
1861 }
1862 else
1863 tprintf("%s, ", x->str);
1864 }
1865 else
1866 tprintf("%#lx, ", tcp->u_arg[2]);
1867#ifdef LINUX
1868 switch (tcp->u_arg[0]) {
1869 case PTRACE_PEEKDATA:
1870 case PTRACE_PEEKTEXT:
1871 case PTRACE_PEEKUSER:
1872 break;
1873 case PTRACE_CONT:
1874 case PTRACE_SINGLESTEP:
1875 case PTRACE_SYSCALL:
1876 case PTRACE_DETACH:
1877 printsignal(tcp->u_arg[3]);
1878 break;
1879 default:
1880 tprintf("%#lx", tcp->u_arg[3]);
1881 break;
1882 }
1883 } else {
1884 switch (tcp->u_arg[0]) {
1885 case PTRACE_PEEKDATA:
1886 case PTRACE_PEEKTEXT:
1887 case PTRACE_PEEKUSER:
1888 printnum(tcp, tcp->u_arg[3], "%#x");
1889 break;
1890 }
1891 }
1892#endif /* LINUX */
1893#ifdef SUNOS4
1894 if (tcp->u_arg[0] == PTRACE_WRITEDATA ||
1895 tcp->u_arg[0] == PTRACE_WRITETEXT) {
1896 tprintf("%lu, ", tcp->u_arg[3]);
1897 printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]);
1898 } else if (tcp->u_arg[0] != PTRACE_READDATA &&
1899 tcp->u_arg[0] != PTRACE_READTEXT) {
1900 tprintf("%#lx", tcp->u_arg[3]);
1901 }
1902 } else {
1903 if (tcp->u_arg[0] == PTRACE_READDATA ||
1904 tcp->u_arg[0] == PTRACE_READTEXT) {
1905 tprintf("%lu, ", tcp->u_arg[3]);
1906 printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]);
1907 }
1908 }
1909#endif /* SUNOS4 */
1910 return 0;
1911}
1912
1913#endif /* !SVR4 */