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