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>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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.
38 #include <sys/resource.h>
39 #include <sys/utsname.h>
41 #include <sys/syscall.h>
44 #include <machine/reg.h>
47 #if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 1 && (defined(I386) || defined(M68K))
49 # define PTRACE_PEEKUSR PTRACE_PEEKUSER
50 # define PTRACE_POKEUSR PTRACE_POKEUSER
54 #include <linux/ptrace.h>
58 #include <sys/prctl.h>
62 #define WCOREDUMP(status) ((status) & 0200)
65 /* WTA: this has `&& !defined(LINUXSPARC)', this seems unneeded though? */
66 #if defined(HAVE_PRCTL)
67 static struct xlat prctl_options[] = {
69 { PR_MAXPROCS, "PR_MAXPROCS" },
72 { PR_ISBLOCKED, "PR_ISBLOCKED" },
74 #ifdef PR_SETSTACKSIZE
75 { PR_SETSTACKSIZE, "PR_SETSTACKSIZE" },
77 #ifdef PR_GETSTACKSIZE
78 { PR_GETSTACKSIZE, "PR_GETSTACKSIZE" },
81 { PR_MAXPPROCS, "PR_MAXPPROCS" },
84 { PR_UNBLKONEXEC, "PR_UNBLKONEXEC" },
87 { PR_ATOMICSIM, "PR_ATOMICSIM" },
90 { PR_SETEXITSIG, "PR_SETEXITSIG" },
93 { PR_RESIDENT, "PR_RESIDENT" },
96 { PR_ATTACHADDR, "PR_ATTACHADDR" },
99 { PR_DETACHADDR, "PR_DETACHADDR" },
102 { PR_TERMCHILD, "PR_TERMCHILD" },
105 { PR_GETSHMASK, "PR_GETSHMASK" },
108 { PR_GETNSHARE, "PR_GETNSHARE" },
110 #if defined(PR_SET_PDEATHSIG)
111 { PR_SET_PDEATHSIG, "PR_SET_PDEATHSIG" },
123 printxval(prctl_options, tcp->u_arg[0], "PR_???");
124 switch (tcp->u_arg[0]) {
130 for (i = 1; i < tcp->u_nargs; i++)
131 tprintf(", %#lx", tcp->u_arg[i]);
138 #endif /* HAVE_PRCTL */
154 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
155 tprintf(", %lu", tcp->u_arg[1]);
166 tprintf("%#lx", tcp->u_arg[0]);
168 printpath(tcp, tcp->u_arg[0]);
169 tprintf(", %lu", tcp->u_arg[1]);
175 sys_setdomainname(tcp)
179 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
180 tprintf(", %lu", tcp->u_arg[1]);
188 sys_getdomainname(tcp)
193 tprintf("%#lx", tcp->u_arg[0]);
195 printpath(tcp, tcp->u_arg[0]);
196 tprintf(", %lu", tcp->u_arg[1]);
207 fprintf(stderr, "_exit returned!\n");
210 /* special case: we stop tracing this process, finish line now */
211 tprintf("%ld) ", tcp->u_arg[0]);
223 tcp->flags |= TCB_EXITING;
235 tcp->auxstr = "child process";
236 return RVAL_UDECIMAL | RVAL_STR;
246 struct tcb *tcpchild;
253 if (nprocs == MAX_PROCS) {
254 tcp->flags &= ~TCB_FOLLOWFORK;
255 fprintf(stderr, "sys_fork: tcb table full\n");
259 tcp->flags |= TCB_FOLLOWFORK;
262 if ((tcpchild = alloctcb(tcp->u_rval)) == NULL) {
263 fprintf(stderr, "sys_fork: tcb table full\n");
266 proc_open(tcpchild, 1);
278 return RVAL_UDECIMAL;
286 struct tcb *tcpchild;
291 if (tcp->scno == SYS_vfork) {
292 #if defined(I386) && defined(LINUX)
293 /* Attempt to make vfork into fork, which we can follow. */
295 ptrace(PTRACE_POKEUSR, tcp->pid,
296 (void *)(ORIG_EAX * 4), SYS_fork) < 0)
305 if (!followfork || dont_follow)
307 if (nprocs == MAX_PROCS) {
308 tcp->flags &= ~TCB_FOLLOWFORK;
309 fprintf(stderr, "sys_fork: tcb table full\n");
312 tcp->flags |= TCB_FOLLOWFORK;
317 int bpt = tcp->flags & TCB_BPTSET;
319 if (!(tcp->flags & TCB_FOLLOWFORK))
328 if ((tcpchild = alloctcb(pid)) == NULL) {
329 fprintf(stderr, " [tcb table full]\n");
330 kill(pid, SIGKILL); /* XXX */
334 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) < 0) {
335 perror("PTRACE_ATTACH");
336 fprintf(stderr, "Too late?\n");
343 /* The child must have run before it can be attached. */
348 select(0, NULL, NULL, NULL, &tv);
350 if (ptrace(PTRACE_ATTACH, pid, (char *)1, 0) < 0) {
351 perror("PTRACE_ATTACH");
352 fprintf(stderr, "Too late?\n");
357 /* Try to catch the new process as soon as possible. */
360 for (i = 0; i < 1024; i++)
361 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) >= 0)
364 perror("PTRACE_ATTACH");
365 fprintf(stderr, "Too late?\n");
372 tcpchild->flags |= TCB_ATTACHED;
373 /* Child has BPT too, must be removed on first occasion */
375 tcpchild->flags |= TCB_BPTSET;
376 tcpchild->baddr = tcp->baddr;
377 memcpy(tcpchild->inst, tcp->inst,
378 sizeof tcpchild->inst);
381 tcpchild->parent = tcp;
384 fprintf(stderr, "Process %d attached\n", pid);
391 #if defined(SUNOS4) || defined(LINUX)
398 return RVAL_UDECIMAL;
402 #endif /* SUNOS4 || LINUX */
406 static char idstr[16];
413 sprintf(idstr, "ppid %lu", getrval2(tcp));
425 sprintf(idstr, "euid %lu", getrval2(tcp));
437 sprintf(idstr, "egid %lu", getrval2(tcp));
453 tprintf("%u", (uid_t) tcp->u_arg[0]);
463 tprintf("%u", (gid_t) tcp->u_arg[0]);
474 if (umoven(tcp, tcp->u_arg[0], sizeof(pid_t),
475 (char *) &res[0]) < 0
476 || umoven(tcp, tcp->u_arg[2], sizeof(pid_t),
477 (char *) &res[1]) < 0
478 || umoven(tcp, tcp->u_arg[2], sizeof(pid_t),
479 (char *) &res[2]) < 0)
481 tprintf("ruid %lu, euid %lu, suid %lu",
482 (unsigned long) res[0],
483 (unsigned long) res[1],
484 (unsigned long) res[2]);
495 if (umoven(tcp, tcp->u_arg[0], sizeof(pid_t),
496 (char *) &res[0]) < 0
497 || umoven(tcp, tcp->u_arg[2], sizeof(pid_t),
498 (char *) &res[1]) < 0
499 || umoven(tcp, tcp->u_arg[2], sizeof(pid_t),
500 (char *) &res[2]) < 0)
502 tprintf("rgid %lu, egid %lu, sgid %lu",
503 (unsigned long) res[0],
504 (unsigned long) res[1],
505 (unsigned long) res[2]);
518 (unsigned long) (uid_t) tcp->u_arg[0],
519 (unsigned long) (uid_t) tcp->u_arg[1]);
530 (unsigned long) (gid_t) tcp->u_arg[0],
531 (unsigned long) (gid_t) tcp->u_arg[1]);
542 tprintf("ruid %u, euid %u, suid %u",
543 (uid_t) tcp->u_arg[0],
544 (uid_t) tcp->u_arg[1],
545 (uid_t) tcp->u_arg[2]);
554 tprintf("rgid %u, egid %u, sgid %u",
555 (uid_t) tcp->u_arg[0],
556 (uid_t) tcp->u_arg[1],
557 (uid_t) tcp->u_arg[2]);
573 tprintf("%u, ", len);
578 gidset = (GETGROUPS_T *) malloc(len * sizeof(GETGROUPS_T));
579 if (gidset == NULL) {
580 fprintf(stderr, "sys_setgroups: out of memory\n");
584 tprintf("%#lx", tcp->u_arg[1]);
585 else if (umoven(tcp, tcp->u_arg[1],
586 len * sizeof(GETGROUPS_T), (char *) gidset) < 0)
590 for (i = 0; i < len; i++)
591 tprintf("%s%lu", i ? ", " : "",
592 (unsigned long) gidset[i]);
595 free((char *) gidset);
609 tprintf("%u, ", len);
616 gidset = (GETGROUPS_T *) malloc(len * sizeof(GETGROUPS_T));
617 if (gidset == NULL) {
618 fprintf(stderr, "sys_getgroups: out of memory\n");
623 else if (!verbose(tcp) || tcp->u_arg[0] == 0)
624 tprintf("%#lx", tcp->u_arg[1]);
625 else if (umoven(tcp, tcp->u_arg[1],
626 len * sizeof(GETGROUPS_T), (char *) gidset) < 0)
630 for (i = 0; i < len; i++)
631 tprintf("%s%lu", i ? ", " : "",
632 (unsigned long) gidset[i]);
635 free((char *)gidset);
646 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
658 tprintf("%lu", tcp->u_arg[0]);
669 tprintf("%lu", tcp->u_arg[0]);
686 tprintf("%lu", tcp->u_arg[0]);
696 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
702 fake_execve(tcp, program, argv, envp)
711 if (!(qual_flags[SYS_execve - __NR_SYSCALL_BASE] & QUAL_TRACE))
714 if (!(qual_flags[SYS_execve] & QUAL_TRACE))
719 string_quote(program);
721 for (i = 0; argv[i] != NULL; i++) {
724 string_quote(argv[i]);
726 for (i = 0; envp[i] != NULL; i++)
728 tprintf("], [/* %d var%s */]) ", i, (i != 1) ? "s" : "");
741 int max = max_strlen / 2;
743 for (sep = ""; --max >= 0; sep = ", ") {
746 if (umove(tcp, addr, &cp) < 0) {
747 tprintf("%#lx", addr);
753 printstr(tcp, (long) cp, -1);
754 addr += sizeof(char *);
761 printargc(fmt, tcp, addr)
769 for (count = 0; umove(tcp, addr, &cp) >= 0 && cp != NULL; count++) {
770 addr += sizeof(char *);
772 tprintf(fmt, count, count == 1 ? "" : "s");
780 printpath(tcp, tcp->u_arg[0]);
782 tprintf(", %#lx", tcp->u_arg[1]);
784 else if (abbrev(tcp))
785 printargc(", [/* %d arg%s */]", tcp, tcp->u_arg[1]);
789 printargv(tcp, tcp->u_arg[1]);
801 printpath(tcp, tcp->u_arg[0]);
803 tprintf(", %#lx", tcp->u_arg[1]);
805 else if (abbrev(tcp))
806 printargc(", [/* %d arg%s */]", tcp, tcp->u_arg[1]);
810 printargv(tcp, tcp->u_arg[1]);
814 tprintf(", %#lx", tcp->u_arg[2]);
815 else if (abbrev(tcp))
816 printargc(", [/* %d var%s */]", tcp, tcp->u_arg[2]);
819 printargv(tcp, tcp->u_arg[2]);
824 #if defined(ALPHA) || defined(SPARC) || defined(POWERPC)
825 tcp->flags |= TCB_WAITEXECVE;
826 #endif /* ALPHA || SPARC || POWERPC */
836 if (exiting(tcp) && !syserror(tcp) && followfork)
844 #define __WCLONE 0x8000000
848 static struct xlat wait4_options[] = {
849 { WNOHANG, "WNOHANG" },
851 { WUNTRACED, "WUNTRACED" },
854 { WEXITED, "WEXITED" },
857 { WTRAPPED, "WTRAPPED" },
860 { WSTOPPED, "WSTOPPED" },
863 { WCONTINUED, "WCONTINUED" },
866 { WNOWAIT, "WNOWAIT" },
869 { __WCLONE, "__WCLONE" },
881 * Here is a tricky presentation problem. This solution
882 * is still not entirely satisfactory but since there
883 * are no wait status constructors it will have to do.
885 if (WIFSTOPPED(status))
886 tprintf("[WIFSTOPPED(s) && WSTOPSIG(s) == %s]",
887 signalent[WSTOPSIG(status)]);
888 else if WIFSIGNALED(status)
889 tprintf("[WIFSIGNALED(s) && WTERMSIG(s) == %s%s]",
890 signalent[WTERMSIG(status)],
891 WCOREDUMP(status) ? " && WCOREDUMP(s)" : "");
892 else if WIFEXITED(status) {
893 tprintf("[WIFEXITED(s) && WEXITSTATUS(s) == %d]",
894 WEXITSTATUS(status));
898 tprintf("[%#x]", status);
911 tprintf("%ld, ", tcp->u_arg[0]);
916 else if (syserror(tcp) || tcp->u_rval == 0)
917 tprintf("%#lx", tcp->u_arg[1]);
918 else if (umove(tcp, tcp->u_arg[1], &status) < 0)
921 exited = printstatus(status);
924 if (!printflags(wait4_options, tcp->u_arg[2]))
932 else if (tcp->u_rval > 0)
933 printrusage(tcp, tcp->u_arg[3]);
936 else if (tcp->u_rval > 0 && exited)
937 printrusage(tcp, tcp->u_arg[3]);
940 tprintf("%#lx", tcp->u_arg[3]);
951 /* WTA: fix bug with hanging children */
952 if (!(tcp->u_arg[2] & WNOHANG) && tcp->nchildren > 0) {
953 /* There are traced children */
954 tcp->flags |= TCB_SUSPENDED;
955 tcp->waitpid = tcp->u_arg[0];
968 /* The library wrapper stuffs this into the user variable. */
970 printstatus(getrval2(tcp));
981 return printwaitn(tcp, 3);
988 return printwaitn(tcp, 4);
993 static struct xlat waitid_types[] = {
995 { P_PPID, "P_PPID" },
996 { P_PGID, "P_PGID" },
1003 { P_LWPID, "P_LWPID" },
1008 static struct xlat siginfo_codes[] = {
1010 { SI_NOINFO, "SI_NOINFO" },
1013 { SI_USER, "SI_USER" },
1016 { SI_LWP, "SI_LWP" },
1019 { SI_QUEUE, "SI_QUEUE" },
1022 { SI_TIMER, "SI_TIMER" },
1025 { SI_ASYNCIO, "SI_ASYNCIO" },
1028 { SI_MESGQ, "SI_MESGQ" },
1033 static struct xlat sigtrap_codes[] = {
1034 { TRAP_BRKPT, "TRAP_BRKPT" },
1035 { TRAP_TRACE, "TRAP_TRACE" },
1039 static struct xlat sigcld_codes[] = {
1040 { CLD_EXITED, "CLD_EXITED" },
1041 { CLD_KILLED, "CLD_KILLED" },
1042 { CLD_DUMPED, "CLD_DUMPED" },
1043 { CLD_TRAPPED, "CLD_TRAPPED" },
1044 { CLD_STOPPED, "CLD_STOPPED" },
1045 { CLD_CONTINUED,"CLD_CONTINUED" },
1049 static struct xlat sigpoll_codes[] = {
1050 { POLL_IN, "POLL_IN" },
1051 { POLL_OUT, "POLL_OUT" },
1052 { POLL_MSG, "POLL_MSG" },
1053 { POLL_ERR, "POLL_ERR" },
1054 { POLL_PRI, "POLL_PRI" },
1055 { POLL_HUP, "POLL_HUP" },
1059 static struct xlat sigprof_codes[] = {
1061 { PROF_SIG, "PROF_SIG" },
1066 static struct xlat sigill_codes[] = {
1067 { ILL_ILLOPC, "ILL_ILLOPC" },
1068 { ILL_ILLOPN, "ILL_ILLOPN" },
1069 { ILL_ILLADR, "ILL_ILLADR" },
1070 { ILL_ILLTRP, "ILL_ILLTRP" },
1071 { ILL_PRVOPC, "ILL_PRVOPC" },
1072 { ILL_PRVREG, "ILL_PRVREG" },
1073 { ILL_COPROC, "ILL_COPROC" },
1074 { ILL_BADSTK, "ILL_BADSTK" },
1078 static struct xlat sigemt_codes[] = {
1080 { EMT_TAGOVF, "EMT_TAGOVF" },
1085 static struct xlat sigfpe_codes[] = {
1086 { FPE_INTDIV, "FPE_INTDIV" },
1087 { FPE_INTOVF, "FPE_INTOVF" },
1088 { FPE_FLTDIV, "FPE_FLTDIV" },
1089 { FPE_FLTOVF, "FPE_FLTOVF" },
1090 { FPE_FLTUND, "FPE_FLTUND" },
1091 { FPE_FLTRES, "FPE_FLTRES" },
1092 { FPE_FLTINV, "FPE_FLTINV" },
1093 { FPE_FLTSUB, "FPE_FLTSUB" },
1097 static struct xlat sigsegv_codes[] = {
1098 { SEGV_MAPERR, "SEGV_MAPERR" },
1099 { SEGV_ACCERR, "SEGV_ACCERR" },
1103 static struct xlat sigbus_codes[] = {
1104 { BUS_ADRALN, "BUS_ADRALN" },
1105 { BUS_ADRERR, "BUS_ADRERR" },
1106 { BUS_OBJERR, "BUS_OBJERR" },
1116 tprintf("{si_signo=");
1117 printsignal(sip->si_signo);
1118 code = xlookup(siginfo_codes, sip->si_code);
1120 switch (sip->si_signo) {
1122 code = xlookup(sigtrap_codes, sip->si_code);
1125 code = xlookup(sigcld_codes, sip->si_code);
1128 code = xlookup(sigpoll_codes, sip->si_code);
1131 code = xlookup(sigprof_codes, sip->si_code);
1134 code = xlookup(sigill_codes, sip->si_code);
1137 code = xlookup(sigemt_codes, sip->si_code);
1140 code = xlookup(sigfpe_codes, sip->si_code);
1143 code = xlookup(sigsegv_codes, sip->si_code);
1146 code = xlookup(sigbus_codes, sip->si_code);
1151 tprintf(", si_code=%s", code);
1153 tprintf(", si_code=%#x", sip->si_code);
1155 if (sip->si_code != SI_NOINFO) {
1157 if (sip->si_errno) {
1158 if (sip->si_errno < 0 || sip->si_errno >= nerrnos)
1159 tprintf(", si_errno=%d", sip->si_errno);
1161 tprintf(", si_errno=%s",
1162 errnoent[sip->si_errno]);
1164 if (SI_FROMUSER(sip)) {
1166 tprintf(", si_pid=%ld, si_uid=%ld",
1167 sip->si_pid, sip->si_uid);
1168 switch (sip->si_code) {
1172 #endif /* SI_QUEUE */
1176 #endif /* SI_MESGQ */
1177 tprintf(", si_value=%d",
1178 sip->si_value.sival_int);
1181 #endif /* SI_QUEUE */
1184 switch (sip->si_signo) {
1186 tprintf(", si_pid=%ld, si_status=",
1188 if (sip->si_code == CLD_EXITED)
1189 tprintf("%d", sip->si_status);
1191 printsignal(sip->si_status);
1193 case SIGILL: case SIGFPE:
1194 case SIGSEGV: case SIGBUS:
1195 tprintf(", si_addr=%#lx",
1196 (unsigned long) sip->si_addr);
1199 switch (sip->si_code) {
1200 case POLL_IN: case POLL_OUT: case POLL_MSG:
1201 tprintf(", si_band=%ld",
1202 (long) sip->si_band);
1222 if (entering(tcp)) {
1223 printxval(waitid_types, tcp->u_arg[0], "P_???");
1224 tprintf(", %ld, ", tcp->u_arg[1]);
1225 if (tcp->nchildren > 0) {
1226 /* There are traced children */
1227 tcp->flags |= TCB_SUSPENDED;
1228 tcp->waitpid = tcp->u_arg[0];
1236 else if (syserror(tcp))
1237 tprintf("%#lx", tcp->u_arg[2]);
1238 else if (umove(tcp, tcp->u_arg[2], &si) < 0)
1244 if (!printflags(wait4_options, tcp->u_arg[3]))
1257 tprintf("%lu", tcp->u_arg[0]);
1265 struct utsname uname;
1268 if (syserror(tcp) || !verbose(tcp))
1269 tprintf("%#lx", tcp->u_arg[0]);
1270 else if (umove(tcp, tcp->u_arg[0], &uname) < 0)
1272 else if (!abbrev(tcp)) {
1274 tprintf("{sysname=\"%s\", nodename=\"%s\", ",
1275 uname.sysname, uname.nodename);
1276 tprintf("release=\"%s\", version=\"%s\", ",
1277 uname.release, uname.version);
1278 tprintf("machine=\"%s\"", uname.machine);
1281 tprintf(", domainname=\"%s\"", uname.domainname);
1282 #endif /* __GLIBC__ */
1287 tprintf("{sys=\"%s\", node=\"%s\", ...}",
1288 uname.sysname, uname.nodename);
1295 static struct xlat ptrace_cmds[] = {
1296 { PTRACE_TRACEME, "PTRACE_TRACEME" },
1297 { PTRACE_PEEKTEXT, "PTRACE_PEEKTEXT", },
1298 { PTRACE_PEEKDATA, "PTRACE_PEEKDATA", },
1299 { PTRACE_PEEKUSER, "PTRACE_PEEKUSER", },
1300 { PTRACE_POKETEXT, "PTRACE_POKETEXT", },
1301 { PTRACE_POKEDATA, "PTRACE_POKEDATA", },
1302 { PTRACE_POKEUSER, "PTRACE_POKEUSER", },
1303 { PTRACE_CONT, "PTRACE_CONT" },
1304 { PTRACE_KILL, "PTRACE_KILL" },
1305 { PTRACE_SINGLESTEP, "PTRACE_SINGLESTEP" },
1306 { PTRACE_ATTACH, "PTRACE_ATTACH" },
1307 { PTRACE_DETACH, "PTRACE_DETACH" },
1309 { PTRACE_GETREGS, "PTRACE_GETREGS" },
1310 { PTRACE_SETREGS, "PTRACE_SETREGS" },
1311 { PTRACE_GETFPREGS, "PTRACE_GETFPREGS", },
1312 { PTRACE_SETFPREGS, "PTRACE_SETFPREGS", },
1313 { PTRACE_READDATA, "PTRACE_READDATA" },
1314 { PTRACE_WRITEDATA, "PTRACE_WRITEDATA" },
1315 { PTRACE_READTEXT, "PTRACE_READTEXT" },
1316 { PTRACE_WRITETEXT, "PTRACE_WRITETEXT" },
1317 { PTRACE_GETFPAREGS, "PTRACE_GETFPAREGS" },
1318 { PTRACE_SETFPAREGS, "PTRACE_SETFPAREGS" },
1320 { PTRACE_GETWINDOW, "PTRACE_GETWINDOW" },
1321 { PTRACE_SETWINDOW, "PTRACE_SETWINDOW" },
1323 { PTRACE_22, "PTRACE_PTRACE_22" },
1324 { PTRACE_23, "PTRACE_PTRACE_23" },
1327 { PTRACE_SYSCALL, "PTRACE_SYSCALL" },
1329 { PTRACE_DUMPCORE, "PTRACE_DUMPCORE" },
1331 { PTRACE_SETWRBKPT, "PTRACE_SETWRBKPT" },
1332 { PTRACE_SETACBKPT, "PTRACE_SETACBKPT" },
1333 { PTRACE_CLRDR7, "PTRACE_CLRDR7" },
1335 { PTRACE_26, "PTRACE_26" },
1336 { PTRACE_27, "PTRACE_27" },
1337 { PTRACE_28, "PTRACE_28" },
1339 { PTRACE_GETUCODE, "PTRACE_GETUCODE" },
1344 #ifndef SUNOS4_KERNEL_ARCH_KLUDGE
1346 #endif /* !SUNOS4_KERNEL_ARCH_KLUDGE */
1347 struct xlat struct_user_offsets[] = {
1350 /* XXX No support for these offsets yet. */
1351 #elif defined(POWERPC)
1352 { 4*PT_R0, "4*PT_R0" },
1353 { 4*PT_R1, "4*PT_R1" },
1354 { 4*PT_R2, "4*PT_R2" },
1355 { 4*PT_R3, "4*PT_R3" },
1356 { 4*PT_R4, "4*PT_R4" },
1357 { 4*PT_R5, "4*PT_R5" },
1358 { 4*PT_R6, "4*PT_R6" },
1359 { 4*PT_R7, "4*PT_R7" },
1360 { 4*PT_R8, "4*PT_R8" },
1361 { 4*PT_R9, "4*PT_R9" },
1362 { 4*PT_R10, "4*PT_R10" },
1363 { 4*PT_R11, "4*PT_R11" },
1364 { 4*PT_R12, "4*PT_R12" },
1365 { 4*PT_R13, "4*PT_R13" },
1366 { 4*PT_R14, "4*PT_R14" },
1367 { 4*PT_R15, "4*PT_R15" },
1368 { 4*PT_R16, "4*PT_R16" },
1369 { 4*PT_R17, "4*PT_R17" },
1370 { 4*PT_R18, "4*PT_R18" },
1371 { 4*PT_R19, "4*PT_R19" },
1372 { 4*PT_R20, "4*PT_R20" },
1373 { 4*PT_R21, "4*PT_R21" },
1374 { 4*PT_R22, "4*PT_R22" },
1375 { 4*PT_R23, "4*PT_R23" },
1376 { 4*PT_R24, "4*PT_R24" },
1377 { 4*PT_R25, "4*PT_R25" },
1378 { 4*PT_R26, "4*PT_R26" },
1379 { 4*PT_R27, "4*PT_R27" },
1380 { 4*PT_R28, "4*PT_R28" },
1381 { 4*PT_R29, "4*PT_R29" },
1382 { 4*PT_R30, "4*PT_R30" },
1383 { 4*PT_R31, "4*PT_R31" },
1384 { 4*PT_NIP, "4*PT_NIP" },
1385 { 4*PT_MSR, "4*PT_MSR" },
1386 { 4*PT_ORIG_R3, "4*PT_ORIG_R3" },
1387 { 4*PT_CTR, "4*PT_CTR" },
1388 { 4*PT_LNK, "4*PT_LNK" },
1389 { 4*PT_XER, "4*PT_XER" },
1390 { 4*PT_CCR, "4*PT_CCR" },
1391 { 4*PT_FPR0, "4*PT_FPR0" },
1472 { 4*ORIG_EAX, "4*ORIG_EAX" },
1476 { 4*UESP, "4*UESP" },
1480 { 4*PT_D1, "4*PT_D1" },
1481 { 4*PT_D2, "4*PT_D2" },
1482 { 4*PT_D3, "4*PT_D3" },
1483 { 4*PT_D4, "4*PT_D4" },
1484 { 4*PT_D5, "4*PT_D5" },
1485 { 4*PT_D6, "4*PT_D6" },
1486 { 4*PT_D7, "4*PT_D7" },
1487 { 4*PT_A0, "4*PT_A0" },
1488 { 4*PT_A1, "4*PT_A1" },
1489 { 4*PT_A2, "4*PT_A2" },
1490 { 4*PT_A3, "4*PT_A3" },
1491 { 4*PT_A4, "4*PT_A4" },
1492 { 4*PT_A5, "4*PT_A5" },
1493 { 4*PT_A6, "4*PT_A6" },
1494 { 4*PT_D0, "4*PT_D0" },
1495 { 4*PT_USP, "4*PT_USP" },
1496 { 4*PT_ORIG_D0, "4*PT_ORIG_D0" },
1497 { 4*PT_SR, "4*PT_SR" },
1498 { 4*PT_PC, "4*PT_PC" },
1501 { uoff(u_fpvalid), "offsetof(struct user, u_fpvalid)" },
1503 { uoff(i387), "offsetof(struct user, i387)" },
1506 { uoff(m68kfp), "offsetof(struct user, m68kfp)" },
1509 { uoff(u_tsize), "offsetof(struct user, u_tsize)" },
1510 { uoff(u_dsize), "offsetof(struct user, u_dsize)" },
1511 { uoff(u_ssize), "offsetof(struct user, u_ssize)" },
1512 { uoff(start_code), "offsetof(struct user, start_code)" },
1513 { uoff(start_stack), "offsetof(struct user, start_stack)" },
1514 { uoff(signal), "offsetof(struct user, signal)" },
1515 { uoff(reserved), "offsetof(struct user, reserved)" },
1516 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
1518 { uoff(u_fpstate), "offsetof(struct user, u_fpstate)" },
1520 { uoff(magic), "offsetof(struct user, magic)" },
1521 { uoff(u_comm), "offsetof(struct user, u_comm)" },
1523 { uoff(u_debugreg), "offsetof(struct user, u_debugreg)" },
1526 #endif /* !POWERPC/!SPARC */
1529 { uoff(u_pcb), "offsetof(struct user, u_pcb)" },
1530 { uoff(u_procp), "offsetof(struct user, u_procp)" },
1531 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
1532 { uoff(u_comm[0]), "offsetof(struct user, u_comm[0])" },
1533 { uoff(u_arg[0]), "offsetof(struct user, u_arg[0])" },
1534 { uoff(u_ap), "offsetof(struct user, u_ap)" },
1535 { uoff(u_qsave), "offsetof(struct user, u_qsave)" },
1536 { uoff(u_rval1), "offsetof(struct user, u_rval1)" },
1537 { uoff(u_rval2), "offsetof(struct user, u_rval2)" },
1538 { uoff(u_error), "offsetof(struct user, u_error)" },
1539 { uoff(u_eosys), "offsetof(struct user, u_eosys)" },
1540 { uoff(u_ssave), "offsetof(struct user, u_ssave)" },
1541 { uoff(u_signal[0]), "offsetof(struct user, u_signal)" },
1542 { uoff(u_sigmask[0]), "offsetof(struct user, u_sigmask)" },
1543 { uoff(u_sigonstack), "offsetof(struct user, u_sigonstack)" },
1544 { uoff(u_sigintr), "offsetof(struct user, u_sigintr)" },
1545 { uoff(u_sigreset), "offsetof(struct user, u_sigreset)" },
1546 { uoff(u_oldmask), "offsetof(struct user, u_oldmask)" },
1547 { uoff(u_code), "offsetof(struct user, u_code)" },
1548 { uoff(u_addr), "offsetof(struct user, u_addr)" },
1549 { uoff(u_sigstack), "offsetof(struct user, u_sigstack)" },
1550 { uoff(u_ofile), "offsetof(struct user, u_ofile)" },
1551 { uoff(u_pofile), "offsetof(struct user, u_pofile)" },
1552 { uoff(u_ofile_arr[0]), "offsetof(struct user, u_ofile_arr[0])" },
1553 { uoff(u_pofile_arr[0]),"offsetof(struct user, u_pofile_arr[0])"},
1554 { uoff(u_lastfile), "offsetof(struct user, u_lastfile)" },
1555 { uoff(u_cwd), "offsetof(struct user, u_cwd)" },
1556 { uoff(u_cdir), "offsetof(struct user, u_cdir)" },
1557 { uoff(u_rdir), "offsetof(struct user, u_rdir)" },
1558 { uoff(u_cmask), "offsetof(struct user, u_cmask)" },
1559 { uoff(u_ru), "offsetof(struct user, u_ru)" },
1560 { uoff(u_cru), "offsetof(struct user, u_cru)" },
1561 { uoff(u_timer[0]), "offsetof(struct user, u_timer[0])" },
1562 { uoff(u_XXX[0]), "offsetof(struct user, u_XXX[0])" },
1563 { uoff(u_ioch), "offsetof(struct user, u_ioch)" },
1564 { uoff(u_start), "offsetof(struct user, u_start)" },
1565 { uoff(u_acflag), "offsetof(struct user, u_acflag)" },
1566 { uoff(u_prof.pr_base), "offsetof(struct user, u_prof.pr_base)" },
1567 { uoff(u_prof.pr_size), "offsetof(struct user, u_prof.pr_size)" },
1568 { uoff(u_prof.pr_off), "offsetof(struct user, u_prof.pr_off)" },
1569 { uoff(u_prof.pr_scale),"offsetof(struct user, u_prof.pr_scale)"},
1570 { uoff(u_rlimit[0]), "offsetof(struct user, u_rlimit)" },
1571 { uoff(u_exdata.Ux_A), "offsetof(struct user, u_exdata.Ux_A)" },
1572 { uoff(u_exdata.ux_shell[0]),"offsetof(struct user, u_exdata.ux_shell[0])"},
1573 { uoff(u_lofault), "offsetof(struct user, u_lofault)" },
1575 { sizeof(struct user), "sizeof(struct user)" },
1587 cmd = xlookup(ptrace_cmds, tcp->u_arg[0]);
1590 if (entering(tcp)) {
1591 tprintf("%s, %lu, ", cmd, tcp->u_arg[1]);
1592 addr = tcp->u_arg[2];
1593 if (tcp->u_arg[0] == PTRACE_PEEKUSER
1594 || tcp->u_arg[0] == PTRACE_POKEUSER) {
1595 for (x = struct_user_offsets; x->str; x++) {
1600 tprintf("%#lx, ", addr);
1601 else if (x->val > addr && x != struct_user_offsets) {
1603 tprintf("%s + %ld, ", x->str, addr - x->val);
1606 tprintf("%s, ", x->str);
1609 tprintf("%#lx, ", tcp->u_arg[2]);
1611 switch (tcp->u_arg[0]) {
1612 case PTRACE_PEEKDATA:
1613 case PTRACE_PEEKTEXT:
1614 case PTRACE_PEEKUSER:
1617 case PTRACE_SINGLESTEP:
1618 case PTRACE_SYSCALL:
1620 printsignal(tcp->u_arg[3]);
1623 tprintf("%#lx", tcp->u_arg[3]);
1627 switch (tcp->u_arg[0]) {
1628 case PTRACE_PEEKDATA:
1629 case PTRACE_PEEKTEXT:
1630 case PTRACE_PEEKUSER:
1631 printnum(tcp, tcp->u_arg[3], "%#x");
1637 if (tcp->u_arg[0] == PTRACE_WRITEDATA ||
1638 tcp->u_arg[0] == PTRACE_WRITETEXT) {
1639 tprintf("%lu, ", tcp->u_arg[3]);
1640 printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]);
1641 } else if (tcp->u_arg[0] != PTRACE_READDATA &&
1642 tcp->u_arg[0] != PTRACE_READTEXT) {
1643 tprintf("%#lx", tcp->u_arg[3]);
1646 if (tcp->u_arg[0] == PTRACE_READDATA ||
1647 tcp->u_arg[0] == PTRACE_READTEXT) {
1648 tprintf("%lu, ", tcp->u_arg[3]);
1649 printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]);