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