blob: f985e215f9b0b11808dbf472274baabbbdba106f [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>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 * $Id$
30 */
31
32#include "defs.h"
33
34#include <fcntl.h>
35#include <sys/stat.h>
36#include <sys/time.h>
37#include <sys/wait.h>
38#include <sys/resource.h>
39#include <sys/utsname.h>
40#include <sys/user.h>
41#include <sys/syscall.h>
42#include <signal.h>
43#ifdef SUNOS4
44#include <machine/reg.h>
45#endif /* SUNOS4 */
46
Wichert Akkerman15dea971999-10-06 13:06:34 +000047#if HAVE_LINUX_PTRACE_H
48#undef PTRACE_SYSCALL
Wichert Akkerman36915a11999-07-13 15:45:02 +000049#include <linux/ptrace.h>
50#endif
51
52#ifdef HAVE_SYS_REG_H
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000053# include <sys/reg.h>
Wichert Akkerman15dea971999-10-06 13:06:34 +000054#ifndef PTRACE_PEEKUSR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000055# define PTRACE_PEEKUSR PTRACE_PEEKUSER
Wichert Akkerman15dea971999-10-06 13:06:34 +000056#endif
57#ifndef PTRACE_POKEUSR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000058# define PTRACE_POKEUSR PTRACE_POKEUSER
59#endif
Wichert Akkerman15dea971999-10-06 13:06:34 +000060#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000061
62#ifdef LINUX
Wichert Akkerman2e2553a1999-05-09 00:29:58 +000063#include <asm/posix_types.h>
64#undef GETGROUPS_T
65#define GETGROUPS_T __kernel_gid_t
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000066#endif /* LINUX */
67
68#ifdef HAVE_PRCTL
69#include <sys/prctl.h>
70#endif
71
72#ifndef WCOREDUMP
73#define WCOREDUMP(status) ((status) & 0200)
74#endif
75
Wichert Akkerman5daa0281999-03-15 19:49:42 +000076/* WTA: this has `&& !defined(LINUXSPARC)', this seems unneeded though? */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000077#if defined(HAVE_PRCTL)
78static struct xlat prctl_options[] = {
79#ifdef PR_MAXPROCS
80 { PR_MAXPROCS, "PR_MAXPROCS" },
81#endif
82#ifdef PR_ISBLOCKED
83 { PR_ISBLOCKED, "PR_ISBLOCKED" },
84#endif
85#ifdef PR_SETSTACKSIZE
86 { PR_SETSTACKSIZE, "PR_SETSTACKSIZE" },
87#endif
88#ifdef PR_GETSTACKSIZE
89 { PR_GETSTACKSIZE, "PR_GETSTACKSIZE" },
90#endif
91#ifdef PR_MAXPPROCS
92 { PR_MAXPPROCS, "PR_MAXPPROCS" },
93#endif
94#ifdef PR_UNBLKONEXEC
95 { PR_UNBLKONEXEC, "PR_UNBLKONEXEC" },
96#endif
97#ifdef PR_ATOMICSIM
98 { PR_ATOMICSIM, "PR_ATOMICSIM" },
99#endif
100#ifdef PR_SETEXITSIG
101 { PR_SETEXITSIG, "PR_SETEXITSIG" },
102#endif
103#ifdef PR_RESIDENT
104 { PR_RESIDENT, "PR_RESIDENT" },
105#endif
106#ifdef PR_ATTACHADDR
107 { PR_ATTACHADDR, "PR_ATTACHADDR" },
108#endif
109#ifdef PR_DETACHADDR
110 { PR_DETACHADDR, "PR_DETACHADDR" },
111#endif
112#ifdef PR_TERMCHILD
113 { PR_TERMCHILD, "PR_TERMCHILD" },
114#endif
115#ifdef PR_GETSHMASK
116 { PR_GETSHMASK, "PR_GETSHMASK" },
117#endif
118#ifdef PR_GETNSHARE
119 { PR_GETNSHARE, "PR_GETNSHARE" },
120#endif
121#if defined(PR_SET_PDEATHSIG)
122 { PR_SET_PDEATHSIG, "PR_SET_PDEATHSIG" },
123#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +0000124#ifdef PR_COREPID
125 { PR_COREPID, "PR_COREPID" },
126#endif
127#ifdef PR_ATTACHADDRPERM
128 { PR_ATTACHADDRPERM, "PR_ATTACHADDRPERM" },
129#endif
130#ifdef PR_PTHREADEXIT
131 { PR_PTHREADEXIT, "PR_PTHREADEXIT" },
132#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000133 { 0, NULL },
134};
135
136int
137sys_prctl(tcp)
138struct tcb *tcp;
139{
140 int i;
141
142 if (entering(tcp)) {
143 printxval(prctl_options, tcp->u_arg[0], "PR_???");
144 switch (tcp->u_arg[0]) {
145#ifdef PR_GETNSHARE
146 case PR_GETNSHARE:
147 break;
148#endif
149 default:
150 for (i = 1; i < tcp->u_nargs; i++)
151 tprintf(", %#lx", tcp->u_arg[i]);
152 break;
153 }
154 }
155 return 0;
156}
157
158#endif /* HAVE_PRCTL */
159
160int
161sys_gethostid(tcp)
162struct tcb *tcp;
163{
164 if (exiting(tcp))
165 return RVAL_HEX;
166 return 0;
167}
168
169int
170sys_sethostname(tcp)
171struct tcb *tcp;
172{
173 if (entering(tcp)) {
174 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
175 tprintf(", %lu", tcp->u_arg[1]);
176 }
177 return 0;
178}
179
180int
181sys_gethostname(tcp)
182struct tcb *tcp;
183{
184 if (exiting(tcp)) {
185 if (syserror(tcp))
186 tprintf("%#lx", tcp->u_arg[0]);
187 else
188 printpath(tcp, tcp->u_arg[0]);
189 tprintf(", %lu", tcp->u_arg[1]);
190 }
191 return 0;
192}
193
194int
195sys_setdomainname(tcp)
196struct tcb *tcp;
197{
198 if (entering(tcp)) {
199 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
200 tprintf(", %lu", tcp->u_arg[1]);
201 }
202 return 0;
203}
204
Wichert Akkerman5daa0281999-03-15 19:49:42 +0000205#if !defined(LINUX)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000206
207int
208sys_getdomainname(tcp)
209struct tcb *tcp;
210{
211 if (exiting(tcp)) {
212 if (syserror(tcp))
213 tprintf("%#lx", tcp->u_arg[0]);
214 else
215 printpath(tcp, tcp->u_arg[0]);
216 tprintf(", %lu", tcp->u_arg[1]);
217 }
218 return 0;
219}
220#endif /* !LINUX */
221
222int
223sys_exit(tcp)
224struct tcb *tcp;
225{
226 if (exiting(tcp)) {
227 fprintf(stderr, "_exit returned!\n");
228 return -1;
229 }
230 /* special case: we stop tracing this process, finish line now */
231 tprintf("%ld) ", tcp->u_arg[0]);
232 tabto(acolumn);
233 tprintf("= ?");
234 printtrailer(tcp);
235 return 0;
236}
237
238int
239internal_exit(tcp)
240struct tcb *tcp;
241{
242 if (entering(tcp))
243 tcp->flags |= TCB_EXITING;
244 return 0;
245}
246
247#ifdef SVR4
248
249int
250sys_fork(tcp)
251struct tcb *tcp;
252{
253 if (exiting(tcp)) {
254 if (getrval2(tcp)) {
255 tcp->auxstr = "child process";
256 return RVAL_UDECIMAL | RVAL_STR;
257 }
258 }
259 return 0;
260}
261
262int
263internal_fork(tcp)
264struct tcb *tcp;
265{
266 struct tcb *tcpchild;
267
268 if (exiting(tcp)) {
269 if (getrval2(tcp))
270 return 0;
271 if (!followfork)
272 return 0;
273 if (nprocs == MAX_PROCS) {
274 tcp->flags &= ~TCB_FOLLOWFORK;
275 fprintf(stderr, "sys_fork: tcb table full\n");
276 return 0;
277 }
278 else
279 tcp->flags |= TCB_FOLLOWFORK;
280 if (syserror(tcp))
281 return 0;
282 if ((tcpchild = alloctcb(tcp->u_rval)) == NULL) {
283 fprintf(stderr, "sys_fork: tcb table full\n");
284 return 0;
285 }
286 proc_open(tcpchild, 1);
287 }
288 return 0;
289}
290
291#else /* !SVR4 */
292
293int
294sys_fork(tcp)
295struct tcb *tcp;
296{
297 if (exiting(tcp))
298 return RVAL_UDECIMAL;
299 return 0;
300}
301
302int
303internal_fork(tcp)
304struct tcb *tcp;
305{
306 struct tcb *tcpchild;
307 int pid;
Nate Sammonsccd8f211999-03-29 22:57:54 +0000308 int dont_follow = 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000309
310#ifdef SYS_vfork
Nate Sammonsccd8f211999-03-29 22:57:54 +0000311 if (tcp->scno == SYS_vfork) {
312#if defined(I386) && defined(LINUX)
313 /* Attempt to make vfork into fork, which we can follow. */
314 if (!followvfork ||
315 ptrace(PTRACE_POKEUSR, tcp->pid,
316 (void *)(ORIG_EAX * 4), SYS_fork) < 0)
317 dont_follow = 1;
318
319#else
320 dont_follow = 1;
321#endif
322 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000323#endif
Nate Sammons38508fd1999-03-29 23:02:29 +0000324#ifdef SYS_clone
325 /* clone can do many things, not all of which we know how to handle.
326 Don't do it for now. */
327 if (tcp->scno == SYS_clone)
328 dont_follow = 1;
329#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000330 if (entering(tcp)) {
Nate Sammonsccd8f211999-03-29 22:57:54 +0000331 if (!followfork || dont_follow)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000332 return 0;
333 if (nprocs == MAX_PROCS) {
334 tcp->flags &= ~TCB_FOLLOWFORK;
335 fprintf(stderr, "sys_fork: tcb table full\n");
336 return 0;
337 }
338 tcp->flags |= TCB_FOLLOWFORK;
339 if (setbpt(tcp) < 0)
340 return 0;
341 }
342 else {
343 int bpt = tcp->flags & TCB_BPTSET;
344
345 if (!(tcp->flags & TCB_FOLLOWFORK))
346 return 0;
347 if (bpt)
348 clearbpt(tcp);
349
350 if (syserror(tcp))
351 return 0;
352
353 pid = tcp->u_rval;
354 if ((tcpchild = alloctcb(pid)) == NULL) {
355 fprintf(stderr, " [tcb table full]\n");
356 kill(pid, SIGKILL); /* XXX */
357 return 0;
358 }
359#ifdef LINUX
360 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) < 0) {
361 perror("PTRACE_ATTACH");
362 fprintf(stderr, "Too late?\n");
363 droptcb(tcpchild);
364 return 0;
365 }
366#endif /* LINUX */
367#ifdef SUNOS4
368#ifdef oldway
369 /* The child must have run before it can be attached. */
370 {
371 struct timeval tv;
372 tv.tv_sec = 0;
373 tv.tv_usec = 10000;
374 select(0, NULL, NULL, NULL, &tv);
375 }
376 if (ptrace(PTRACE_ATTACH, pid, (char *)1, 0) < 0) {
377 perror("PTRACE_ATTACH");
378 fprintf(stderr, "Too late?\n");
379 droptcb(tcpchild);
380 return 0;
381 }
382#else /* !oldway */
383 /* Try to catch the new process as soon as possible. */
384 {
385 int i;
386 for (i = 0; i < 1024; i++)
387 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) >= 0)
388 break;
389 if (i == 1024) {
390 perror("PTRACE_ATTACH");
391 fprintf(stderr, "Too late?\n");
392 droptcb(tcpchild);
393 return 0;
394 }
395 }
396#endif /* !oldway */
397#endif /* SUNOS4 */
398 tcpchild->flags |= TCB_ATTACHED;
399 /* Child has BPT too, must be removed on first occasion */
400 if (bpt) {
401 tcpchild->flags |= TCB_BPTSET;
402 tcpchild->baddr = tcp->baddr;
403 memcpy(tcpchild->inst, tcp->inst,
404 sizeof tcpchild->inst);
405 }
406 newoutf(tcpchild);
407 tcpchild->parent = tcp;
408 tcp->nchildren++;
409 if (!qflag)
410 fprintf(stderr, "Process %d attached\n", pid);
411 }
412 return 0;
413}
414
415#endif /* !SVR4 */
416
417#if defined(SUNOS4) || defined(LINUX)
418
419int
420sys_vfork(tcp)
421struct tcb *tcp;
422{
423 if (exiting(tcp))
424 return RVAL_UDECIMAL;
425 return 0;
426}
427
428#endif /* SUNOS4 || LINUX */
429
430#ifndef LINUX
431
432static char idstr[16];
433
434int
435sys_getpid(tcp)
436struct tcb *tcp;
437{
438 if (exiting(tcp)) {
439 sprintf(idstr, "ppid %lu", getrval2(tcp));
440 tcp->auxstr = idstr;
441 return RVAL_STR;
442 }
443 return 0;
444}
445
446int
447sys_getuid(tcp)
448struct tcb *tcp;
449{
450 if (exiting(tcp)) {
451 sprintf(idstr, "euid %lu", getrval2(tcp));
452 tcp->auxstr = idstr;
453 return RVAL_STR;
454 }
455 return 0;
456}
457
458int
459sys_getgid(tcp)
460struct tcb *tcp;
461{
462 if (exiting(tcp)) {
463 sprintf(idstr, "egid %lu", getrval2(tcp));
464 tcp->auxstr = idstr;
465 return RVAL_STR;
466 }
467 return 0;
468}
469
470#endif /* !LINUX */
471
472#ifdef LINUX
473
474int
475sys_setuid(tcp)
476struct tcb *tcp;
477{
478 if (entering(tcp)) {
479 tprintf("%u", (uid_t) tcp->u_arg[0]);
480 }
481 return 0;
482}
483
484int
485sys_setgid(tcp)
486struct tcb *tcp;
487{
488 if (entering(tcp)) {
489 tprintf("%u", (gid_t) tcp->u_arg[0]);
490 }
491 return 0;
492}
493
494int
495sys_getresuid(tcp)
496 struct tcb *tcp;
497{
498 if (exiting(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000499 __kernel_uid_t uid;
500 if (syserror(tcp))
501 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
502 tcp->u_arg[1], tcp->u_arg[2]);
503 else {
504 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
505 tprintf("%#lx, ", tcp->u_arg[0]);
506 else
507 tprintf("ruid %lu, ", (unsigned long) uid);
508 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
509 tprintf("%#lx, ", tcp->u_arg[0]);
510 else
511 tprintf("euid %lu, ", (unsigned long) uid);
512 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
513 tprintf("%#lx", tcp->u_arg[0]);
514 else
515 tprintf("suid %lu", (unsigned long) uid);
516 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000517 }
518 return 0;
519}
520
521int
522sys_getresgid(tcp)
523struct tcb *tcp;
524{
525 if (exiting(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000526 __kernel_gid_t gid;
527 if (syserror(tcp))
528 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
529 tcp->u_arg[1], tcp->u_arg[2]);
530 else {
531 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
532 tprintf("%#lx, ", tcp->u_arg[0]);
533 else
534 tprintf("rgid %lu, ", (unsigned long) gid);
535 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
536 tprintf("%#lx, ", tcp->u_arg[0]);
537 else
538 tprintf("egid %lu, ", (unsigned long) gid);
539 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
540 tprintf("%#lx", tcp->u_arg[0]);
541 else
542 tprintf("sgid %lu", (unsigned long) gid);
543 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000544 }
545 return 0;
546}
547
548#endif /* LINUX */
549
550int
551sys_setreuid(tcp)
552struct tcb *tcp;
553{
554 if (entering(tcp)) {
555 tprintf("%lu, %lu",
556 (unsigned long) (uid_t) tcp->u_arg[0],
557 (unsigned long) (uid_t) tcp->u_arg[1]);
558 }
559 return 0;
560}
561
562int
563sys_setregid(tcp)
564struct tcb *tcp;
565{
566 if (entering(tcp)) {
567 tprintf("%lu, %lu",
568 (unsigned long) (gid_t) tcp->u_arg[0],
569 (unsigned long) (gid_t) tcp->u_arg[1]);
570 }
571 return 0;
572}
573
574#ifdef LINUX
575int
576sys_setresuid(tcp)
577 struct tcb *tcp;
578{
579 if (entering(tcp)) {
580 tprintf("ruid %u, euid %u, suid %u",
581 (uid_t) tcp->u_arg[0],
582 (uid_t) tcp->u_arg[1],
583 (uid_t) tcp->u_arg[2]);
584 }
585 return 0;
586}
587int
588sys_setresgid(tcp)
589 struct tcb *tcp;
590{
591 if (entering(tcp)) {
592 tprintf("rgid %u, egid %u, sgid %u",
593 (uid_t) tcp->u_arg[0],
594 (uid_t) tcp->u_arg[1],
595 (uid_t) tcp->u_arg[2]);
596 }
597 return 0;
598}
599
600#endif /* LINUX */
601
602int
603sys_setgroups(tcp)
604struct tcb *tcp;
605{
606 int i, len;
607 GETGROUPS_T *gidset;
608
609 if (entering(tcp)) {
610 len = tcp->u_arg[0];
611 tprintf("%u, ", len);
612 if (len <= 0) {
613 tprintf("[]");
614 return 0;
615 }
616 gidset = (GETGROUPS_T *) malloc(len * sizeof(GETGROUPS_T));
617 if (gidset == NULL) {
618 fprintf(stderr, "sys_setgroups: out of memory\n");
619 return -1;
620 }
621 if (!verbose(tcp))
622 tprintf("%#lx", tcp->u_arg[1]);
623 else if (umoven(tcp, tcp->u_arg[1],
624 len * sizeof(GETGROUPS_T), (char *) gidset) < 0)
625 tprintf("[?]");
626 else {
627 tprintf("[");
628 for (i = 0; i < len; i++)
629 tprintf("%s%lu", i ? ", " : "",
630 (unsigned long) gidset[i]);
631 tprintf("]");
632 }
633 free((char *) gidset);
634 }
635 return 0;
636}
637
638int
639sys_getgroups(tcp)
640struct tcb *tcp;
641{
642 int i, len;
643 GETGROUPS_T *gidset;
644
645 if (entering(tcp)) {
646 len = tcp->u_arg[0];
647 tprintf("%u, ", len);
648 } else {
649 len = tcp->u_rval;
650 if (len <= 0) {
651 tprintf("[]");
652 return 0;
653 }
654 gidset = (GETGROUPS_T *) malloc(len * sizeof(GETGROUPS_T));
655 if (gidset == NULL) {
656 fprintf(stderr, "sys_getgroups: out of memory\n");
657 return -1;
658 }
659 if (!tcp->u_arg[1])
660 tprintf("NULL");
661 else if (!verbose(tcp) || tcp->u_arg[0] == 0)
662 tprintf("%#lx", tcp->u_arg[1]);
663 else if (umoven(tcp, tcp->u_arg[1],
664 len * sizeof(GETGROUPS_T), (char *) gidset) < 0)
665 tprintf("[?]");
666 else {
667 tprintf("[");
668 for (i = 0; i < len; i++)
669 tprintf("%s%lu", i ? ", " : "",
670 (unsigned long) gidset[i]);
671 tprintf("]");
672 }
673 free((char *)gidset);
674 }
675 return 0;
676}
677
678int
679sys_setpgrp(tcp)
680struct tcb *tcp;
681{
682 if (entering(tcp)) {
683#ifndef SVR4
684 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
685#endif /* !SVR4 */
686 }
687 return 0;
688}
689
690int
691sys_getpgrp(tcp)
692struct tcb *tcp;
693{
694 if (entering(tcp)) {
695#ifndef SVR4
696 tprintf("%lu", tcp->u_arg[0]);
697#endif /* !SVR4 */
698 }
699 return 0;
700}
701
702int
703sys_getsid(tcp)
704struct tcb *tcp;
705{
706 if (entering(tcp)) {
707 tprintf("%lu", tcp->u_arg[0]);
708 }
709 return 0;
710}
711
712int
713sys_setsid(tcp)
714struct tcb *tcp;
715{
716 return 0;
717}
718
719int
720sys_getpgid(tcp)
721struct tcb *tcp;
722{
723 if (entering(tcp)) {
724 tprintf("%lu", tcp->u_arg[0]);
725 }
726 return 0;
727}
728
729int
730sys_setpgid(tcp)
731struct tcb *tcp;
732{
733 if (entering(tcp)) {
734 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
735 }
736 return 0;
737}
738
739void
740fake_execve(tcp, program, argv, envp)
741struct tcb *tcp;
742char *program;
743char *argv[];
744char *envp[];
745{
746 int i;
747
748#ifdef ARM
749 if (!(qual_flags[SYS_execve - __NR_SYSCALL_BASE] & QUAL_TRACE))
750 return;
751#else
752 if (!(qual_flags[SYS_execve] & QUAL_TRACE))
753 return;
754#endif /* !ARM */
755 printleader(tcp);
756 tprintf("execve(");
757 string_quote(program);
758 tprintf(", [");
759 for (i = 0; argv[i] != NULL; i++) {
760 if (i != 0)
761 tprintf(", ");
762 string_quote(argv[i]);
763 }
764 for (i = 0; envp[i] != NULL; i++)
765 ;
766 tprintf("], [/* %d var%s */]) ", i, (i != 1) ? "s" : "");
767 tabto(acolumn);
768 tprintf("= 0");
769 printtrailer(tcp);
770}
771
772static void
773printargv(tcp, addr)
774struct tcb *tcp;
775long addr;
776{
777 char *cp;
778 char *sep;
779 int max = max_strlen / 2;
780
781 for (sep = ""; --max >= 0; sep = ", ") {
782 if (!abbrev(tcp))
783 max++;
784 if (umove(tcp, addr, &cp) < 0) {
785 tprintf("%#lx", addr);
786 return;
787 }
788 if (cp == 0)
789 break;
790 tprintf(sep);
791 printstr(tcp, (long) cp, -1);
792 addr += sizeof(char *);
793 }
794 if (cp)
795 tprintf(", ...");
796}
797
798static void
799printargc(fmt, tcp, addr)
800char *fmt;
801struct tcb *tcp;
802long addr;
803{
804 int count;
805 char *cp;
806
807 for (count = 0; umove(tcp, addr, &cp) >= 0 && cp != NULL; count++) {
808 addr += sizeof(char *);
809 }
810 tprintf(fmt, count, count == 1 ? "" : "s");
811}
812
813int
814sys_execv(tcp)
815struct tcb *tcp;
816{
817 if (entering(tcp)) {
818 printpath(tcp, tcp->u_arg[0]);
819 if (!verbose(tcp))
820 tprintf(", %#lx", tcp->u_arg[1]);
821#if 0
822 else if (abbrev(tcp))
823 printargc(", [/* %d arg%s */]", tcp, tcp->u_arg[1]);
824#endif
825 else {
826 tprintf(", [");
827 printargv(tcp, tcp->u_arg[1]);
828 tprintf("]");
829 }
830 }
831 return 0;
832}
833
834int
835sys_execve(tcp)
836struct tcb *tcp;
837{
838 if (entering(tcp)) {
839 printpath(tcp, tcp->u_arg[0]);
840 if (!verbose(tcp))
841 tprintf(", %#lx", tcp->u_arg[1]);
842#if 0
843 else if (abbrev(tcp))
844 printargc(", [/* %d arg%s */]", tcp, tcp->u_arg[1]);
845#endif
846 else {
847 tprintf(", [");
848 printargv(tcp, tcp->u_arg[1]);
849 tprintf("]");
850 }
851 if (!verbose(tcp))
852 tprintf(", %#lx", tcp->u_arg[2]);
853 else if (abbrev(tcp))
854 printargc(", [/* %d var%s */]", tcp, tcp->u_arg[2]);
855 else {
856 tprintf(", [");
857 printargv(tcp, tcp->u_arg[2]);
858 tprintf("]");
859 }
860 }
861#ifdef LINUX
862#if defined(ALPHA) || defined(SPARC) || defined(POWERPC)
863 tcp->flags |= TCB_WAITEXECVE;
864#endif /* ALPHA || SPARC || POWERPC */
865#endif /* LINUX */
866 return 0;
867}
868
869int
870internal_exec(tcp)
871struct tcb *tcp;
872{
873#ifdef SUNOS4
874 if (exiting(tcp) && !syserror(tcp) && followfork)
875 fixvfork(tcp);
876#endif /* SUNOS4 */
877 return 0;
878}
879
880#ifdef LINUX
881#ifndef __WCLONE
882#define __WCLONE 0x8000000
883#endif
884#endif /* LINUX */
885
886static struct xlat wait4_options[] = {
887 { WNOHANG, "WNOHANG" },
888#ifndef WSTOPPED
889 { WUNTRACED, "WUNTRACED" },
890#endif
891#ifdef WEXITED
892 { WEXITED, "WEXITED" },
893#endif
894#ifdef WTRAPPED
895 { WTRAPPED, "WTRAPPED" },
896#endif
897#ifdef WSTOPPED
898 { WSTOPPED, "WSTOPPED" },
899#endif
900#ifdef WCONTINUED
901 { WCONTINUED, "WCONTINUED" },
902#endif
903#ifdef WNOWAIT
904 { WNOWAIT, "WNOWAIT" },
905#endif
906#ifdef __WCLONE
907 { __WCLONE, "__WCLONE" },
908#endif
909 { 0, NULL },
910};
911
912static int
913printstatus(status)
914int status;
915{
916 int exited = 0;
917
918 /*
919 * Here is a tricky presentation problem. This solution
920 * is still not entirely satisfactory but since there
921 * are no wait status constructors it will have to do.
922 */
923 if (WIFSTOPPED(status))
924 tprintf("[WIFSTOPPED(s) && WSTOPSIG(s) == %s]",
Nate Sammonsce780fc1999-03-29 23:23:13 +0000925 signame(WSTOPSIG(status)));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000926 else if WIFSIGNALED(status)
927 tprintf("[WIFSIGNALED(s) && WTERMSIG(s) == %s%s]",
Nate Sammonsce780fc1999-03-29 23:23:13 +0000928 signame(WTERMSIG(status)),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000929 WCOREDUMP(status) ? " && WCOREDUMP(s)" : "");
930 else if WIFEXITED(status) {
931 tprintf("[WIFEXITED(s) && WEXITSTATUS(s) == %d]",
932 WEXITSTATUS(status));
933 exited = 1;
934 }
935 else
936 tprintf("[%#x]", status);
937 return exited;
938}
939
940static int
941printwaitn(tcp, n)
942struct tcb *tcp;
943int n;
944{
945 int status;
946 int exited = 0;
947
948 if (entering(tcp)) {
949 tprintf("%ld, ", tcp->u_arg[0]);
950 } else {
951 /* status */
952 if (!tcp->u_arg[1])
953 tprintf("NULL");
954 else if (syserror(tcp) || tcp->u_rval == 0)
955 tprintf("%#lx", tcp->u_arg[1]);
956 else if (umove(tcp, tcp->u_arg[1], &status) < 0)
957 tprintf("[?]");
958 else
959 exited = printstatus(status);
960 /* options */
961 tprintf(", ");
962 if (!printflags(wait4_options, tcp->u_arg[2]))
963 tprintf("0");
964 if (n == 4) {
965 tprintf(", ");
966 /* usage */
967 if (!tcp->u_arg[3])
968 tprintf("NULL");
969#ifdef LINUX
970 else if (tcp->u_rval > 0)
971 printrusage(tcp, tcp->u_arg[3]);
972#endif /* LINUX */
973#ifdef SUNOS4
974 else if (tcp->u_rval > 0 && exited)
975 printrusage(tcp, tcp->u_arg[3]);
976#endif /* SUNOS4 */
977 else
978 tprintf("%#lx", tcp->u_arg[3]);
979 }
980 }
981 return 0;
982}
983
984int
985internal_wait(tcp)
986struct tcb *tcp;
987{
988 if (entering(tcp)) {
Wichert Akkerman5daa0281999-03-15 19:49:42 +0000989 /* WTA: fix bug with hanging children */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000990 if (!(tcp->u_arg[2] & WNOHANG) && tcp->nchildren > 0) {
991 /* There are traced children */
992 tcp->flags |= TCB_SUSPENDED;
993 tcp->waitpid = tcp->u_arg[0];
994 }
995 }
996 return 0;
997}
998
999#ifdef SVR4
1000
1001int
1002sys_wait(tcp)
1003struct tcb *tcp;
1004{
1005 if (exiting(tcp)) {
1006 /* The library wrapper stuffs this into the user variable. */
1007 if (!syserror(tcp))
1008 printstatus(getrval2(tcp));
1009 }
1010 return 0;
1011}
1012
1013#endif /* SVR4 */
1014
1015int
1016sys_waitpid(tcp)
1017struct tcb *tcp;
1018{
1019 return printwaitn(tcp, 3);
1020}
1021
1022int
1023sys_wait4(tcp)
1024struct tcb *tcp;
1025{
1026 return printwaitn(tcp, 4);
1027}
1028
1029#ifdef SVR4
1030
1031static struct xlat waitid_types[] = {
1032 { P_PID, "P_PID" },
1033 { P_PPID, "P_PPID" },
1034 { P_PGID, "P_PGID" },
1035 { P_SID, "P_SID" },
1036 { P_CID, "P_CID" },
1037 { P_UID, "P_UID" },
1038 { P_GID, "P_GID" },
1039 { P_ALL, "P_ALL" },
1040#ifdef P_LWPID
1041 { P_LWPID, "P_LWPID" },
1042#endif
1043 { 0, NULL },
1044};
1045
1046static struct xlat siginfo_codes[] = {
1047#ifdef SI_NOINFO
1048 { SI_NOINFO, "SI_NOINFO" },
1049#endif
1050#ifdef SI_USER
1051 { SI_USER, "SI_USER" },
1052#endif
1053#ifdef SI_LWP
1054 { SI_LWP, "SI_LWP" },
1055#endif
1056#ifdef SI_QUEUE
1057 { SI_QUEUE, "SI_QUEUE" },
1058#endif
1059#ifdef SI_TIMER
1060 { SI_TIMER, "SI_TIMER" },
1061#endif
1062#ifdef SI_ASYNCIO
1063 { SI_ASYNCIO, "SI_ASYNCIO" },
1064#endif
1065#ifdef SI_MESGQ
1066 { SI_MESGQ, "SI_MESGQ" },
1067#endif
1068 { 0, NULL },
1069};
1070
1071static struct xlat sigtrap_codes[] = {
1072 { TRAP_BRKPT, "TRAP_BRKPT" },
1073 { TRAP_TRACE, "TRAP_TRACE" },
1074 { 0, NULL },
1075};
1076
1077static struct xlat sigcld_codes[] = {
1078 { CLD_EXITED, "CLD_EXITED" },
1079 { CLD_KILLED, "CLD_KILLED" },
1080 { CLD_DUMPED, "CLD_DUMPED" },
1081 { CLD_TRAPPED, "CLD_TRAPPED" },
1082 { CLD_STOPPED, "CLD_STOPPED" },
1083 { CLD_CONTINUED,"CLD_CONTINUED" },
1084 { 0, NULL },
1085};
1086
1087static struct xlat sigpoll_codes[] = {
1088 { POLL_IN, "POLL_IN" },
1089 { POLL_OUT, "POLL_OUT" },
1090 { POLL_MSG, "POLL_MSG" },
1091 { POLL_ERR, "POLL_ERR" },
1092 { POLL_PRI, "POLL_PRI" },
1093 { POLL_HUP, "POLL_HUP" },
1094 { 0, NULL },
1095};
1096
1097static struct xlat sigprof_codes[] = {
1098#ifdef PROF_SIG
1099 { PROF_SIG, "PROF_SIG" },
1100#endif
1101 { 0, NULL },
1102};
1103
1104static struct xlat sigill_codes[] = {
1105 { ILL_ILLOPC, "ILL_ILLOPC" },
1106 { ILL_ILLOPN, "ILL_ILLOPN" },
1107 { ILL_ILLADR, "ILL_ILLADR" },
1108 { ILL_ILLTRP, "ILL_ILLTRP" },
1109 { ILL_PRVOPC, "ILL_PRVOPC" },
1110 { ILL_PRVREG, "ILL_PRVREG" },
1111 { ILL_COPROC, "ILL_COPROC" },
1112 { ILL_BADSTK, "ILL_BADSTK" },
1113 { 0, NULL },
1114};
1115
1116static struct xlat sigemt_codes[] = {
1117#ifdef EMT_TAGOVF
1118 { EMT_TAGOVF, "EMT_TAGOVF" },
1119#endif
1120 { 0, NULL },
1121};
1122
1123static struct xlat sigfpe_codes[] = {
1124 { FPE_INTDIV, "FPE_INTDIV" },
1125 { FPE_INTOVF, "FPE_INTOVF" },
1126 { FPE_FLTDIV, "FPE_FLTDIV" },
1127 { FPE_FLTOVF, "FPE_FLTOVF" },
1128 { FPE_FLTUND, "FPE_FLTUND" },
1129 { FPE_FLTRES, "FPE_FLTRES" },
1130 { FPE_FLTINV, "FPE_FLTINV" },
1131 { FPE_FLTSUB, "FPE_FLTSUB" },
1132 { 0, NULL },
1133};
1134
1135static struct xlat sigsegv_codes[] = {
1136 { SEGV_MAPERR, "SEGV_MAPERR" },
1137 { SEGV_ACCERR, "SEGV_ACCERR" },
1138 { 0, NULL },
1139};
1140
1141static struct xlat sigbus_codes[] = {
1142 { BUS_ADRALN, "BUS_ADRALN" },
1143 { BUS_ADRERR, "BUS_ADRERR" },
1144 { BUS_OBJERR, "BUS_OBJERR" },
1145 { 0, NULL },
1146};
1147
1148void
1149printsiginfo(sip)
1150siginfo_t *sip;
1151{
1152 char *code;
1153
1154 tprintf("{si_signo=");
1155 printsignal(sip->si_signo);
1156 code = xlookup(siginfo_codes, sip->si_code);
1157 if (!code) {
1158 switch (sip->si_signo) {
1159 case SIGTRAP:
1160 code = xlookup(sigtrap_codes, sip->si_code);
1161 break;
1162 case SIGCHLD:
1163 code = xlookup(sigcld_codes, sip->si_code);
1164 break;
1165 case SIGPOLL:
1166 code = xlookup(sigpoll_codes, sip->si_code);
1167 break;
1168 case SIGPROF:
1169 code = xlookup(sigprof_codes, sip->si_code);
1170 break;
1171 case SIGILL:
1172 code = xlookup(sigill_codes, sip->si_code);
1173 break;
1174 case SIGEMT:
1175 code = xlookup(sigemt_codes, sip->si_code);
1176 break;
1177 case SIGFPE:
1178 code = xlookup(sigfpe_codes, sip->si_code);
1179 break;
1180 case SIGSEGV:
1181 code = xlookup(sigsegv_codes, sip->si_code);
1182 break;
1183 case SIGBUS:
1184 code = xlookup(sigbus_codes, sip->si_code);
1185 break;
1186 }
1187 }
1188 if (code)
1189 tprintf(", si_code=%s", code);
1190 else
1191 tprintf(", si_code=%#x", sip->si_code);
1192#ifdef SI_NOINFO
1193 if (sip->si_code != SI_NOINFO) {
1194#endif
1195 if (sip->si_errno) {
1196 if (sip->si_errno < 0 || sip->si_errno >= nerrnos)
1197 tprintf(", si_errno=%d", sip->si_errno);
1198 else
1199 tprintf(", si_errno=%s",
1200 errnoent[sip->si_errno]);
1201 }
1202 if (SI_FROMUSER(sip)) {
1203#ifdef SI_QUEUE
1204 tprintf(", si_pid=%ld, si_uid=%ld",
1205 sip->si_pid, sip->si_uid);
1206 switch (sip->si_code) {
1207 case SI_QUEUE:
1208#ifdef SI_TIMER
1209 case SI_TIMER:
1210#endif /* SI_QUEUE */
1211 case SI_ASYNCIO:
1212#ifdef SI_MESGQ
1213 case SI_MESGQ:
1214#endif /* SI_MESGQ */
1215 tprintf(", si_value=%d",
1216 sip->si_value.sival_int);
1217 break;
1218 }
1219#endif /* SI_QUEUE */
1220 }
1221 else {
1222 switch (sip->si_signo) {
1223 case SIGCHLD:
1224 tprintf(", si_pid=%ld, si_status=",
1225 sip->si_pid);
1226 if (sip->si_code == CLD_EXITED)
1227 tprintf("%d", sip->si_status);
1228 else
1229 printsignal(sip->si_status);
1230 break;
1231 case SIGILL: case SIGFPE:
1232 case SIGSEGV: case SIGBUS:
1233 tprintf(", si_addr=%#lx",
1234 (unsigned long) sip->si_addr);
1235 break;
1236 case SIGPOLL:
1237 switch (sip->si_code) {
1238 case POLL_IN: case POLL_OUT: case POLL_MSG:
1239 tprintf(", si_band=%ld",
1240 (long) sip->si_band);
1241 break;
1242 }
1243 break;
1244 }
1245 }
1246 tprintf(", ...");
1247#ifdef SI_NOINFO
1248 }
1249#endif
1250 tprintf("}");
1251}
1252
1253int
1254sys_waitid(tcp)
1255struct tcb *tcp;
1256{
1257 siginfo_t si;
1258 int exited;
1259
1260 if (entering(tcp)) {
1261 printxval(waitid_types, tcp->u_arg[0], "P_???");
1262 tprintf(", %ld, ", tcp->u_arg[1]);
1263 if (tcp->nchildren > 0) {
1264 /* There are traced children */
1265 tcp->flags |= TCB_SUSPENDED;
1266 tcp->waitpid = tcp->u_arg[0];
1267 }
1268 }
1269 else {
1270 /* siginfo */
1271 exited = 0;
1272 if (!tcp->u_arg[2])
1273 tprintf("NULL");
1274 else if (syserror(tcp))
1275 tprintf("%#lx", tcp->u_arg[2]);
1276 else if (umove(tcp, tcp->u_arg[2], &si) < 0)
1277 tprintf("{???}");
1278 else
1279 printsiginfo(&si);
1280 /* options */
1281 tprintf(", ");
1282 if (!printflags(wait4_options, tcp->u_arg[3]))
1283 tprintf("0");
1284 }
1285 return 0;
1286}
1287
1288#endif /* SVR4 */
1289
1290int
1291sys_alarm(tcp)
1292struct tcb *tcp;
1293{
1294 if (entering(tcp))
1295 tprintf("%lu", tcp->u_arg[0]);
1296 return 0;
1297}
1298
1299int
1300sys_uname(tcp)
1301struct tcb *tcp;
1302{
1303 struct utsname uname;
1304
1305 if (exiting(tcp)) {
1306 if (syserror(tcp) || !verbose(tcp))
1307 tprintf("%#lx", tcp->u_arg[0]);
1308 else if (umove(tcp, tcp->u_arg[0], &uname) < 0)
1309 tprintf("{...}");
1310 else if (!abbrev(tcp)) {
1311
1312 tprintf("{sysname=\"%s\", nodename=\"%s\", ",
1313 uname.sysname, uname.nodename);
1314 tprintf("release=\"%s\", version=\"%s\", ",
1315 uname.release, uname.version);
1316 tprintf("machine=\"%s\"", uname.machine);
1317#ifdef LINUX
1318#ifndef __GLIBC__
1319 tprintf(", domainname=\"%s\"", uname.domainname);
1320#endif /* __GLIBC__ */
1321#endif /* LINUX */
1322 tprintf("}");
1323 }
1324 else
1325 tprintf("{sys=\"%s\", node=\"%s\", ...}",
1326 uname.sysname, uname.nodename);
1327 }
1328 return 0;
1329}
1330
1331#ifndef SVR4
1332
1333static struct xlat ptrace_cmds[] = {
1334 { PTRACE_TRACEME, "PTRACE_TRACEME" },
1335 { PTRACE_PEEKTEXT, "PTRACE_PEEKTEXT", },
1336 { PTRACE_PEEKDATA, "PTRACE_PEEKDATA", },
1337 { PTRACE_PEEKUSER, "PTRACE_PEEKUSER", },
1338 { PTRACE_POKETEXT, "PTRACE_POKETEXT", },
1339 { PTRACE_POKEDATA, "PTRACE_POKEDATA", },
1340 { PTRACE_POKEUSER, "PTRACE_POKEUSER", },
1341 { PTRACE_CONT, "PTRACE_CONT" },
1342 { PTRACE_KILL, "PTRACE_KILL" },
1343 { PTRACE_SINGLESTEP, "PTRACE_SINGLESTEP" },
1344 { PTRACE_ATTACH, "PTRACE_ATTACH" },
1345 { PTRACE_DETACH, "PTRACE_DETACH" },
1346#ifdef SUNOS4
1347 { PTRACE_GETREGS, "PTRACE_GETREGS" },
1348 { PTRACE_SETREGS, "PTRACE_SETREGS" },
1349 { PTRACE_GETFPREGS, "PTRACE_GETFPREGS", },
1350 { PTRACE_SETFPREGS, "PTRACE_SETFPREGS", },
1351 { PTRACE_READDATA, "PTRACE_READDATA" },
1352 { PTRACE_WRITEDATA, "PTRACE_WRITEDATA" },
1353 { PTRACE_READTEXT, "PTRACE_READTEXT" },
1354 { PTRACE_WRITETEXT, "PTRACE_WRITETEXT" },
1355 { PTRACE_GETFPAREGS, "PTRACE_GETFPAREGS" },
1356 { PTRACE_SETFPAREGS, "PTRACE_SETFPAREGS" },
1357#ifdef SPARC
1358 { PTRACE_GETWINDOW, "PTRACE_GETWINDOW" },
1359 { PTRACE_SETWINDOW, "PTRACE_SETWINDOW" },
1360#else /* !SPARC */
1361 { PTRACE_22, "PTRACE_PTRACE_22" },
1362 { PTRACE_23, "PTRACE_PTRACE_23" },
1363#endif /* !SPARC */
1364#endif /* SUNOS4 */
1365 { PTRACE_SYSCALL, "PTRACE_SYSCALL" },
1366#ifdef SUNOS4
1367 { PTRACE_DUMPCORE, "PTRACE_DUMPCORE" },
1368#ifdef I386
1369 { PTRACE_SETWRBKPT, "PTRACE_SETWRBKPT" },
1370 { PTRACE_SETACBKPT, "PTRACE_SETACBKPT" },
1371 { PTRACE_CLRDR7, "PTRACE_CLRDR7" },
1372#else /* !I386 */
1373 { PTRACE_26, "PTRACE_26" },
1374 { PTRACE_27, "PTRACE_27" },
1375 { PTRACE_28, "PTRACE_28" },
1376#endif /* !I386 */
1377 { PTRACE_GETUCODE, "PTRACE_GETUCODE" },
1378#endif /* SUNOS4 */
1379 { 0, NULL },
1380};
1381
1382#ifndef SUNOS4_KERNEL_ARCH_KLUDGE
1383static
1384#endif /* !SUNOS4_KERNEL_ARCH_KLUDGE */
1385struct xlat struct_user_offsets[] = {
1386#ifdef LINUX
1387#ifdef SPARC
1388 /* XXX No support for these offsets yet. */
1389#elif defined(POWERPC)
1390 { 4*PT_R0, "4*PT_R0" },
1391 { 4*PT_R1, "4*PT_R1" },
1392 { 4*PT_R2, "4*PT_R2" },
1393 { 4*PT_R3, "4*PT_R3" },
1394 { 4*PT_R4, "4*PT_R4" },
1395 { 4*PT_R5, "4*PT_R5" },
1396 { 4*PT_R6, "4*PT_R6" },
1397 { 4*PT_R7, "4*PT_R7" },
1398 { 4*PT_R8, "4*PT_R8" },
1399 { 4*PT_R9, "4*PT_R9" },
1400 { 4*PT_R10, "4*PT_R10" },
1401 { 4*PT_R11, "4*PT_R11" },
1402 { 4*PT_R12, "4*PT_R12" },
1403 { 4*PT_R13, "4*PT_R13" },
1404 { 4*PT_R14, "4*PT_R14" },
1405 { 4*PT_R15, "4*PT_R15" },
1406 { 4*PT_R16, "4*PT_R16" },
1407 { 4*PT_R17, "4*PT_R17" },
1408 { 4*PT_R18, "4*PT_R18" },
1409 { 4*PT_R19, "4*PT_R19" },
1410 { 4*PT_R20, "4*PT_R20" },
1411 { 4*PT_R21, "4*PT_R21" },
1412 { 4*PT_R22, "4*PT_R22" },
1413 { 4*PT_R23, "4*PT_R23" },
1414 { 4*PT_R24, "4*PT_R24" },
1415 { 4*PT_R25, "4*PT_R25" },
1416 { 4*PT_R26, "4*PT_R26" },
1417 { 4*PT_R27, "4*PT_R27" },
1418 { 4*PT_R28, "4*PT_R28" },
1419 { 4*PT_R29, "4*PT_R29" },
1420 { 4*PT_R30, "4*PT_R30" },
1421 { 4*PT_R31, "4*PT_R31" },
1422 { 4*PT_NIP, "4*PT_NIP" },
1423 { 4*PT_MSR, "4*PT_MSR" },
1424 { 4*PT_ORIG_R3, "4*PT_ORIG_R3" },
1425 { 4*PT_CTR, "4*PT_CTR" },
1426 { 4*PT_LNK, "4*PT_LNK" },
1427 { 4*PT_XER, "4*PT_XER" },
1428 { 4*PT_CCR, "4*PT_CCR" },
1429 { 4*PT_FPR0, "4*PT_FPR0" },
1430#else
1431#ifdef ALPHA
1432 { 0, "r0" },
1433 { 1, "r1" },
1434 { 2, "r2" },
1435 { 3, "r3" },
1436 { 4, "r4" },
1437 { 5, "r5" },
1438 { 6, "r6" },
1439 { 7, "r7" },
1440 { 8, "r8" },
1441 { 9, "r9" },
1442 { 10, "r10" },
1443 { 11, "r11" },
1444 { 12, "r12" },
1445 { 13, "r13" },
1446 { 14, "r14" },
1447 { 15, "r15" },
1448 { 16, "r16" },
1449 { 17, "r17" },
1450 { 18, "r18" },
1451 { 19, "r19" },
1452 { 20, "r20" },
1453 { 21, "r21" },
1454 { 22, "r22" },
1455 { 23, "r23" },
1456 { 24, "r24" },
1457 { 25, "r25" },
1458 { 26, "r26" },
1459 { 27, "r27" },
1460 { 28, "r28" },
1461 { 29, "gp" },
1462 { 30, "fp" },
1463 { 31, "zero" },
1464 { 32, "fp0" },
1465 { 33, "fp" },
1466 { 34, "fp2" },
1467 { 35, "fp3" },
1468 { 36, "fp4" },
1469 { 37, "fp5" },
1470 { 38, "fp6" },
1471 { 39, "fp7" },
1472 { 40, "fp8" },
1473 { 41, "fp9" },
1474 { 42, "fp10" },
1475 { 43, "fp11" },
1476 { 44, "fp12" },
1477 { 45, "fp13" },
1478 { 46, "fp14" },
1479 { 47, "fp15" },
1480 { 48, "fp16" },
1481 { 49, "fp17" },
1482 { 50, "fp18" },
1483 { 51, "fp19" },
1484 { 52, "fp20" },
1485 { 53, "fp21" },
1486 { 54, "fp22" },
1487 { 55, "fp23" },
1488 { 56, "fp24" },
1489 { 57, "fp25" },
1490 { 58, "fp26" },
1491 { 59, "fp27" },
1492 { 60, "fp28" },
1493 { 61, "fp29" },
1494 { 62, "fp30" },
1495 { 63, "fp31" },
1496 { 64, "pc" },
1497#else /* !ALPHA */
1498#ifdef I386
1499 { 4*EBX, "4*EBX" },
1500 { 4*ECX, "4*ECX" },
1501 { 4*EDX, "4*EDX" },
1502 { 4*ESI, "4*ESI" },
1503 { 4*EDI, "4*EDI" },
1504 { 4*EBP, "4*EBP" },
1505 { 4*EAX, "4*EAX" },
1506 { 4*DS, "4*DS" },
1507 { 4*ES, "4*ES" },
1508 { 4*FS, "4*FS" },
1509 { 4*GS, "4*GS" },
1510 { 4*ORIG_EAX, "4*ORIG_EAX" },
1511 { 4*EIP, "4*EIP" },
1512 { 4*CS, "4*CS" },
1513 { 4*EFL, "4*EFL" },
1514 { 4*UESP, "4*UESP" },
1515 { 4*SS, "4*SS" },
1516#else /* !I386 */
1517#ifdef M68K
1518 { 4*PT_D1, "4*PT_D1" },
1519 { 4*PT_D2, "4*PT_D2" },
1520 { 4*PT_D3, "4*PT_D3" },
1521 { 4*PT_D4, "4*PT_D4" },
1522 { 4*PT_D5, "4*PT_D5" },
1523 { 4*PT_D6, "4*PT_D6" },
1524 { 4*PT_D7, "4*PT_D7" },
1525 { 4*PT_A0, "4*PT_A0" },
1526 { 4*PT_A1, "4*PT_A1" },
1527 { 4*PT_A2, "4*PT_A2" },
1528 { 4*PT_A3, "4*PT_A3" },
1529 { 4*PT_A4, "4*PT_A4" },
1530 { 4*PT_A5, "4*PT_A5" },
1531 { 4*PT_A6, "4*PT_A6" },
1532 { 4*PT_D0, "4*PT_D0" },
1533 { 4*PT_USP, "4*PT_USP" },
1534 { 4*PT_ORIG_D0, "4*PT_ORIG_D0" },
1535 { 4*PT_SR, "4*PT_SR" },
1536 { 4*PT_PC, "4*PT_PC" },
1537#endif /* M68K */
1538#endif /* !I386 */
Wichert Akkermanf90da011999-10-31 21:15:38 +00001539#ifndef MIPS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001540 { uoff(u_fpvalid), "offsetof(struct user, u_fpvalid)" },
Wichert Akkermanf90da011999-10-31 21:15:38 +00001541#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001542#ifdef I386
1543 { uoff(i387), "offsetof(struct user, i387)" },
1544#else /* !I386 */
1545#ifdef M68K
1546 { uoff(m68kfp), "offsetof(struct user, m68kfp)" },
1547#endif /* M68K */
1548#endif /* !I386 */
1549 { uoff(u_tsize), "offsetof(struct user, u_tsize)" },
1550 { uoff(u_dsize), "offsetof(struct user, u_dsize)" },
1551 { uoff(u_ssize), "offsetof(struct user, u_ssize)" },
1552 { uoff(start_code), "offsetof(struct user, start_code)" },
1553 { uoff(start_stack), "offsetof(struct user, start_stack)" },
1554 { uoff(signal), "offsetof(struct user, signal)" },
Wichert Akkermanf90da011999-10-31 21:15:38 +00001555#ifndef MIPS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001556 { uoff(reserved), "offsetof(struct user, reserved)" },
Wichert Akkermanf90da011999-10-31 21:15:38 +00001557#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001558 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
Wichert Akkermanf90da011999-10-31 21:15:38 +00001559#if !defined(ARM) && !defined(MIPS)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001560 { uoff(u_fpstate), "offsetof(struct user, u_fpstate)" },
1561#endif
1562 { uoff(magic), "offsetof(struct user, magic)" },
1563 { uoff(u_comm), "offsetof(struct user, u_comm)" },
1564#ifdef I386
1565 { uoff(u_debugreg), "offsetof(struct user, u_debugreg)" },
1566#endif /* I386 */
1567#endif /* !ALPHA */
1568#endif /* !POWERPC/!SPARC */
1569#endif /* LINUX */
1570#ifdef SUNOS4
1571 { uoff(u_pcb), "offsetof(struct user, u_pcb)" },
1572 { uoff(u_procp), "offsetof(struct user, u_procp)" },
1573 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
1574 { uoff(u_comm[0]), "offsetof(struct user, u_comm[0])" },
1575 { uoff(u_arg[0]), "offsetof(struct user, u_arg[0])" },
1576 { uoff(u_ap), "offsetof(struct user, u_ap)" },
1577 { uoff(u_qsave), "offsetof(struct user, u_qsave)" },
1578 { uoff(u_rval1), "offsetof(struct user, u_rval1)" },
1579 { uoff(u_rval2), "offsetof(struct user, u_rval2)" },
1580 { uoff(u_error), "offsetof(struct user, u_error)" },
1581 { uoff(u_eosys), "offsetof(struct user, u_eosys)" },
1582 { uoff(u_ssave), "offsetof(struct user, u_ssave)" },
1583 { uoff(u_signal[0]), "offsetof(struct user, u_signal)" },
1584 { uoff(u_sigmask[0]), "offsetof(struct user, u_sigmask)" },
1585 { uoff(u_sigonstack), "offsetof(struct user, u_sigonstack)" },
1586 { uoff(u_sigintr), "offsetof(struct user, u_sigintr)" },
1587 { uoff(u_sigreset), "offsetof(struct user, u_sigreset)" },
1588 { uoff(u_oldmask), "offsetof(struct user, u_oldmask)" },
1589 { uoff(u_code), "offsetof(struct user, u_code)" },
1590 { uoff(u_addr), "offsetof(struct user, u_addr)" },
1591 { uoff(u_sigstack), "offsetof(struct user, u_sigstack)" },
1592 { uoff(u_ofile), "offsetof(struct user, u_ofile)" },
1593 { uoff(u_pofile), "offsetof(struct user, u_pofile)" },
1594 { uoff(u_ofile_arr[0]), "offsetof(struct user, u_ofile_arr[0])" },
1595 { uoff(u_pofile_arr[0]),"offsetof(struct user, u_pofile_arr[0])"},
1596 { uoff(u_lastfile), "offsetof(struct user, u_lastfile)" },
1597 { uoff(u_cwd), "offsetof(struct user, u_cwd)" },
1598 { uoff(u_cdir), "offsetof(struct user, u_cdir)" },
1599 { uoff(u_rdir), "offsetof(struct user, u_rdir)" },
1600 { uoff(u_cmask), "offsetof(struct user, u_cmask)" },
1601 { uoff(u_ru), "offsetof(struct user, u_ru)" },
1602 { uoff(u_cru), "offsetof(struct user, u_cru)" },
1603 { uoff(u_timer[0]), "offsetof(struct user, u_timer[0])" },
1604 { uoff(u_XXX[0]), "offsetof(struct user, u_XXX[0])" },
1605 { uoff(u_ioch), "offsetof(struct user, u_ioch)" },
1606 { uoff(u_start), "offsetof(struct user, u_start)" },
1607 { uoff(u_acflag), "offsetof(struct user, u_acflag)" },
1608 { uoff(u_prof.pr_base), "offsetof(struct user, u_prof.pr_base)" },
1609 { uoff(u_prof.pr_size), "offsetof(struct user, u_prof.pr_size)" },
1610 { uoff(u_prof.pr_off), "offsetof(struct user, u_prof.pr_off)" },
1611 { uoff(u_prof.pr_scale),"offsetof(struct user, u_prof.pr_scale)"},
1612 { uoff(u_rlimit[0]), "offsetof(struct user, u_rlimit)" },
1613 { uoff(u_exdata.Ux_A), "offsetof(struct user, u_exdata.Ux_A)" },
1614 { uoff(u_exdata.ux_shell[0]),"offsetof(struct user, u_exdata.ux_shell[0])"},
1615 { uoff(u_lofault), "offsetof(struct user, u_lofault)" },
1616#endif /* SUNOS4 */
1617 { sizeof(struct user), "sizeof(struct user)" },
1618 { 0, NULL },
1619};
1620
1621int
1622sys_ptrace(tcp)
1623struct tcb *tcp;
1624{
1625 char *cmd;
1626 struct xlat *x;
1627 long addr;
1628
1629 cmd = xlookup(ptrace_cmds, tcp->u_arg[0]);
1630 if (!cmd)
1631 cmd = "PTRACE_???";
1632 if (entering(tcp)) {
1633 tprintf("%s, %lu, ", cmd, tcp->u_arg[1]);
1634 addr = tcp->u_arg[2];
1635 if (tcp->u_arg[0] == PTRACE_PEEKUSER
1636 || tcp->u_arg[0] == PTRACE_POKEUSER) {
1637 for (x = struct_user_offsets; x->str; x++) {
1638 if (x->val >= addr)
1639 break;
1640 }
1641 if (!x->str)
1642 tprintf("%#lx, ", addr);
1643 else if (x->val > addr && x != struct_user_offsets) {
1644 x--;
1645 tprintf("%s + %ld, ", x->str, addr - x->val);
1646 }
1647 else
1648 tprintf("%s, ", x->str);
1649 }
1650 else
1651 tprintf("%#lx, ", tcp->u_arg[2]);
1652#ifdef LINUX
1653 switch (tcp->u_arg[0]) {
1654 case PTRACE_PEEKDATA:
1655 case PTRACE_PEEKTEXT:
1656 case PTRACE_PEEKUSER:
1657 break;
1658 case PTRACE_CONT:
1659 case PTRACE_SINGLESTEP:
1660 case PTRACE_SYSCALL:
1661 case PTRACE_DETACH:
1662 printsignal(tcp->u_arg[3]);
1663 break;
1664 default:
1665 tprintf("%#lx", tcp->u_arg[3]);
1666 break;
1667 }
1668 } else {
1669 switch (tcp->u_arg[0]) {
1670 case PTRACE_PEEKDATA:
1671 case PTRACE_PEEKTEXT:
1672 case PTRACE_PEEKUSER:
1673 printnum(tcp, tcp->u_arg[3], "%#x");
1674 break;
1675 }
1676 }
1677#endif /* LINUX */
1678#ifdef SUNOS4
1679 if (tcp->u_arg[0] == PTRACE_WRITEDATA ||
1680 tcp->u_arg[0] == PTRACE_WRITETEXT) {
1681 tprintf("%lu, ", tcp->u_arg[3]);
1682 printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]);
1683 } else if (tcp->u_arg[0] != PTRACE_READDATA &&
1684 tcp->u_arg[0] != PTRACE_READTEXT) {
1685 tprintf("%#lx", tcp->u_arg[3]);
1686 }
1687 } else {
1688 if (tcp->u_arg[0] == PTRACE_READDATA ||
1689 tcp->u_arg[0] == PTRACE_READTEXT) {
1690 tprintf("%lu, ", tcp->u_arg[3]);
1691 printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]);
1692 }
1693 }
1694#endif /* SUNOS4 */
1695 return 0;
1696}
1697
1698#endif /* !SVR4 */