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 defined(linux) && !defined(__GLIBC__)
48 #include <linux/ptrace.h>
53 # define PTRACE_PEEKUSR PTRACE_PEEKUSER
54 # define PTRACE_POKEUSR PTRACE_POKEUSER
58 #include <asm/posix_types.h>
60 #define GETGROUPS_T __kernel_gid_t
64 #include <sys/prctl.h>
68 #define WCOREDUMP(status) ((status) & 0200)
71 /* WTA: this has `&& !defined(LINUXSPARC)', this seems unneeded though? */
72 #if defined(HAVE_PRCTL)
73 static struct xlat prctl_options[] = {
75 { PR_MAXPROCS, "PR_MAXPROCS" },
78 { PR_ISBLOCKED, "PR_ISBLOCKED" },
80 #ifdef PR_SETSTACKSIZE
81 { PR_SETSTACKSIZE, "PR_SETSTACKSIZE" },
83 #ifdef PR_GETSTACKSIZE
84 { PR_GETSTACKSIZE, "PR_GETSTACKSIZE" },
87 { PR_MAXPPROCS, "PR_MAXPPROCS" },
90 { PR_UNBLKONEXEC, "PR_UNBLKONEXEC" },
93 { PR_ATOMICSIM, "PR_ATOMICSIM" },
96 { PR_SETEXITSIG, "PR_SETEXITSIG" },
99 { PR_RESIDENT, "PR_RESIDENT" },
102 { PR_ATTACHADDR, "PR_ATTACHADDR" },
105 { PR_DETACHADDR, "PR_DETACHADDR" },
108 { PR_TERMCHILD, "PR_TERMCHILD" },
111 { PR_GETSHMASK, "PR_GETSHMASK" },
114 { PR_GETNSHARE, "PR_GETNSHARE" },
116 #if defined(PR_SET_PDEATHSIG)
117 { PR_SET_PDEATHSIG, "PR_SET_PDEATHSIG" },
120 { PR_COREPID, "PR_COREPID" },
122 #ifdef PR_ATTACHADDRPERM
123 { PR_ATTACHADDRPERM, "PR_ATTACHADDRPERM" },
125 #ifdef PR_PTHREADEXIT
126 { PR_PTHREADEXIT, "PR_PTHREADEXIT" },
138 printxval(prctl_options, tcp->u_arg[0], "PR_???");
139 switch (tcp->u_arg[0]) {
145 for (i = 1; i < tcp->u_nargs; i++)
146 tprintf(", %#lx", tcp->u_arg[i]);
153 #endif /* HAVE_PRCTL */
169 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
170 tprintf(", %lu", tcp->u_arg[1]);
181 tprintf("%#lx", tcp->u_arg[0]);
183 printpath(tcp, tcp->u_arg[0]);
184 tprintf(", %lu", tcp->u_arg[1]);
190 sys_setdomainname(tcp)
194 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
195 tprintf(", %lu", tcp->u_arg[1]);
203 sys_getdomainname(tcp)
208 tprintf("%#lx", tcp->u_arg[0]);
210 printpath(tcp, tcp->u_arg[0]);
211 tprintf(", %lu", tcp->u_arg[1]);
222 fprintf(stderr, "_exit returned!\n");
225 /* special case: we stop tracing this process, finish line now */
226 tprintf("%ld) ", tcp->u_arg[0]);
238 tcp->flags |= TCB_EXITING;
250 tcp->auxstr = "child process";
251 return RVAL_UDECIMAL | RVAL_STR;
261 struct tcb *tcpchild;
268 if (nprocs == MAX_PROCS) {
269 tcp->flags &= ~TCB_FOLLOWFORK;
270 fprintf(stderr, "sys_fork: tcb table full\n");
274 tcp->flags |= TCB_FOLLOWFORK;
277 if ((tcpchild = alloctcb(tcp->u_rval)) == NULL) {
278 fprintf(stderr, "sys_fork: tcb table full\n");
281 proc_open(tcpchild, 1);
293 return RVAL_UDECIMAL;
301 struct tcb *tcpchild;
306 if (tcp->scno == SYS_vfork) {
307 #if defined(I386) && defined(LINUX)
308 /* Attempt to make vfork into fork, which we can follow. */
310 ptrace(PTRACE_POKEUSR, tcp->pid,
311 (void *)(ORIG_EAX * 4), SYS_fork) < 0)
320 /* clone can do many things, not all of which we know how to handle.
321 Don't do it for now. */
322 if (tcp->scno == SYS_clone)
326 if (!followfork || dont_follow)
328 if (nprocs == MAX_PROCS) {
329 tcp->flags &= ~TCB_FOLLOWFORK;
330 fprintf(stderr, "sys_fork: tcb table full\n");
333 tcp->flags |= TCB_FOLLOWFORK;
338 int bpt = tcp->flags & TCB_BPTSET;
340 if (!(tcp->flags & TCB_FOLLOWFORK))
349 if ((tcpchild = alloctcb(pid)) == NULL) {
350 fprintf(stderr, " [tcb table full]\n");
351 kill(pid, SIGKILL); /* XXX */
355 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) < 0) {
356 perror("PTRACE_ATTACH");
357 fprintf(stderr, "Too late?\n");
364 /* The child must have run before it can be attached. */
369 select(0, NULL, NULL, NULL, &tv);
371 if (ptrace(PTRACE_ATTACH, pid, (char *)1, 0) < 0) {
372 perror("PTRACE_ATTACH");
373 fprintf(stderr, "Too late?\n");
378 /* Try to catch the new process as soon as possible. */
381 for (i = 0; i < 1024; i++)
382 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) >= 0)
385 perror("PTRACE_ATTACH");
386 fprintf(stderr, "Too late?\n");
393 tcpchild->flags |= TCB_ATTACHED;
394 /* Child has BPT too, must be removed on first occasion */
396 tcpchild->flags |= TCB_BPTSET;
397 tcpchild->baddr = tcp->baddr;
398 memcpy(tcpchild->inst, tcp->inst,
399 sizeof tcpchild->inst);
402 tcpchild->parent = tcp;
405 fprintf(stderr, "Process %d attached\n", pid);
412 #if defined(SUNOS4) || defined(LINUX)
419 return RVAL_UDECIMAL;
423 #endif /* SUNOS4 || LINUX */
427 static char idstr[16];
434 sprintf(idstr, "ppid %lu", getrval2(tcp));
446 sprintf(idstr, "euid %lu", getrval2(tcp));
458 sprintf(idstr, "egid %lu", getrval2(tcp));
474 tprintf("%u", (uid_t) tcp->u_arg[0]);
484 tprintf("%u", (gid_t) tcp->u_arg[0]);
496 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
497 tcp->u_arg[1], tcp->u_arg[2]);
499 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
500 tprintf("%#lx, ", tcp->u_arg[0]);
502 tprintf("ruid %lu, ", (unsigned long) uid);
503 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
504 tprintf("%#lx, ", tcp->u_arg[0]);
506 tprintf("euid %lu, ", (unsigned long) uid);
507 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
508 tprintf("%#lx", tcp->u_arg[0]);
510 tprintf("suid %lu", (unsigned long) uid);
523 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
524 tcp->u_arg[1], tcp->u_arg[2]);
526 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
527 tprintf("%#lx, ", tcp->u_arg[0]);
529 tprintf("rgid %lu, ", (unsigned long) gid);
530 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
531 tprintf("%#lx, ", tcp->u_arg[0]);
533 tprintf("egid %lu, ", (unsigned long) gid);
534 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
535 tprintf("%#lx", tcp->u_arg[0]);
537 tprintf("sgid %lu", (unsigned long) gid);
551 (unsigned long) (uid_t) tcp->u_arg[0],
552 (unsigned long) (uid_t) tcp->u_arg[1]);
563 (unsigned long) (gid_t) tcp->u_arg[0],
564 (unsigned long) (gid_t) tcp->u_arg[1]);
575 tprintf("ruid %u, euid %u, suid %u",
576 (uid_t) tcp->u_arg[0],
577 (uid_t) tcp->u_arg[1],
578 (uid_t) tcp->u_arg[2]);
587 tprintf("rgid %u, egid %u, sgid %u",
588 (uid_t) tcp->u_arg[0],
589 (uid_t) tcp->u_arg[1],
590 (uid_t) tcp->u_arg[2]);
606 tprintf("%u, ", len);
611 gidset = (GETGROUPS_T *) malloc(len * sizeof(GETGROUPS_T));
612 if (gidset == NULL) {
613 fprintf(stderr, "sys_setgroups: out of memory\n");
617 tprintf("%#lx", tcp->u_arg[1]);
618 else if (umoven(tcp, tcp->u_arg[1],
619 len * sizeof(GETGROUPS_T), (char *) gidset) < 0)
623 for (i = 0; i < len; i++)
624 tprintf("%s%lu", i ? ", " : "",
625 (unsigned long) gidset[i]);
628 free((char *) gidset);
642 tprintf("%u, ", len);
649 gidset = (GETGROUPS_T *) malloc(len * sizeof(GETGROUPS_T));
650 if (gidset == NULL) {
651 fprintf(stderr, "sys_getgroups: out of memory\n");
656 else if (!verbose(tcp) || tcp->u_arg[0] == 0)
657 tprintf("%#lx", tcp->u_arg[1]);
658 else if (umoven(tcp, tcp->u_arg[1],
659 len * sizeof(GETGROUPS_T), (char *) gidset) < 0)
663 for (i = 0; i < len; i++)
664 tprintf("%s%lu", i ? ", " : "",
665 (unsigned long) gidset[i]);
668 free((char *)gidset);
679 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
691 tprintf("%lu", tcp->u_arg[0]);
702 tprintf("%lu", tcp->u_arg[0]);
719 tprintf("%lu", tcp->u_arg[0]);
729 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
735 fake_execve(tcp, program, argv, envp)
744 if (!(qual_flags[SYS_execve - __NR_SYSCALL_BASE] & QUAL_TRACE))
747 if (!(qual_flags[SYS_execve] & QUAL_TRACE))
752 string_quote(program);
754 for (i = 0; argv[i] != NULL; i++) {
757 string_quote(argv[i]);
759 for (i = 0; envp[i] != NULL; i++)
761 tprintf("], [/* %d var%s */]) ", i, (i != 1) ? "s" : "");
774 int max = max_strlen / 2;
776 for (sep = ""; --max >= 0; sep = ", ") {
779 if (umove(tcp, addr, &cp) < 0) {
780 tprintf("%#lx", addr);
786 printstr(tcp, (long) cp, -1);
787 addr += sizeof(char *);
794 printargc(fmt, tcp, addr)
802 for (count = 0; umove(tcp, addr, &cp) >= 0 && cp != NULL; count++) {
803 addr += sizeof(char *);
805 tprintf(fmt, count, count == 1 ? "" : "s");
813 printpath(tcp, tcp->u_arg[0]);
815 tprintf(", %#lx", tcp->u_arg[1]);
817 else if (abbrev(tcp))
818 printargc(", [/* %d arg%s */]", tcp, tcp->u_arg[1]);
822 printargv(tcp, tcp->u_arg[1]);
834 printpath(tcp, tcp->u_arg[0]);
836 tprintf(", %#lx", tcp->u_arg[1]);
838 else if (abbrev(tcp))
839 printargc(", [/* %d arg%s */]", tcp, tcp->u_arg[1]);
843 printargv(tcp, tcp->u_arg[1]);
847 tprintf(", %#lx", tcp->u_arg[2]);
848 else if (abbrev(tcp))
849 printargc(", [/* %d var%s */]", tcp, tcp->u_arg[2]);
852 printargv(tcp, tcp->u_arg[2]);
857 #if defined(ALPHA) || defined(SPARC) || defined(POWERPC)
858 tcp->flags |= TCB_WAITEXECVE;
859 #endif /* ALPHA || SPARC || POWERPC */
869 if (exiting(tcp) && !syserror(tcp) && followfork)
877 #define __WCLONE 0x8000000
881 static struct xlat wait4_options[] = {
882 { WNOHANG, "WNOHANG" },
884 { WUNTRACED, "WUNTRACED" },
887 { WEXITED, "WEXITED" },
890 { WTRAPPED, "WTRAPPED" },
893 { WSTOPPED, "WSTOPPED" },
896 { WCONTINUED, "WCONTINUED" },
899 { WNOWAIT, "WNOWAIT" },
902 { __WCLONE, "__WCLONE" },
914 * Here is a tricky presentation problem. This solution
915 * is still not entirely satisfactory but since there
916 * are no wait status constructors it will have to do.
918 if (WIFSTOPPED(status))
919 tprintf("[WIFSTOPPED(s) && WSTOPSIG(s) == %s]",
920 signame(WSTOPSIG(status)));
921 else if WIFSIGNALED(status)
922 tprintf("[WIFSIGNALED(s) && WTERMSIG(s) == %s%s]",
923 signame(WTERMSIG(status)),
924 WCOREDUMP(status) ? " && WCOREDUMP(s)" : "");
925 else if WIFEXITED(status) {
926 tprintf("[WIFEXITED(s) && WEXITSTATUS(s) == %d]",
927 WEXITSTATUS(status));
931 tprintf("[%#x]", status);
944 tprintf("%ld, ", tcp->u_arg[0]);
949 else if (syserror(tcp) || tcp->u_rval == 0)
950 tprintf("%#lx", tcp->u_arg[1]);
951 else if (umove(tcp, tcp->u_arg[1], &status) < 0)
954 exited = printstatus(status);
957 if (!printflags(wait4_options, tcp->u_arg[2]))
965 else if (tcp->u_rval > 0)
966 printrusage(tcp, tcp->u_arg[3]);
969 else if (tcp->u_rval > 0 && exited)
970 printrusage(tcp, tcp->u_arg[3]);
973 tprintf("%#lx", tcp->u_arg[3]);
984 /* WTA: fix bug with hanging children */
985 if (!(tcp->u_arg[2] & WNOHANG) && tcp->nchildren > 0) {
986 /* There are traced children */
987 tcp->flags |= TCB_SUSPENDED;
988 tcp->waitpid = tcp->u_arg[0];
1001 /* The library wrapper stuffs this into the user variable. */
1003 printstatus(getrval2(tcp));
1014 return printwaitn(tcp, 3);
1021 return printwaitn(tcp, 4);
1026 static struct xlat waitid_types[] = {
1028 { P_PPID, "P_PPID" },
1029 { P_PGID, "P_PGID" },
1036 { P_LWPID, "P_LWPID" },
1041 static struct xlat siginfo_codes[] = {
1043 { SI_NOINFO, "SI_NOINFO" },
1046 { SI_USER, "SI_USER" },
1049 { SI_LWP, "SI_LWP" },
1052 { SI_QUEUE, "SI_QUEUE" },
1055 { SI_TIMER, "SI_TIMER" },
1058 { SI_ASYNCIO, "SI_ASYNCIO" },
1061 { SI_MESGQ, "SI_MESGQ" },
1066 static struct xlat sigtrap_codes[] = {
1067 { TRAP_BRKPT, "TRAP_BRKPT" },
1068 { TRAP_TRACE, "TRAP_TRACE" },
1072 static struct xlat sigcld_codes[] = {
1073 { CLD_EXITED, "CLD_EXITED" },
1074 { CLD_KILLED, "CLD_KILLED" },
1075 { CLD_DUMPED, "CLD_DUMPED" },
1076 { CLD_TRAPPED, "CLD_TRAPPED" },
1077 { CLD_STOPPED, "CLD_STOPPED" },
1078 { CLD_CONTINUED,"CLD_CONTINUED" },
1082 static struct xlat sigpoll_codes[] = {
1083 { POLL_IN, "POLL_IN" },
1084 { POLL_OUT, "POLL_OUT" },
1085 { POLL_MSG, "POLL_MSG" },
1086 { POLL_ERR, "POLL_ERR" },
1087 { POLL_PRI, "POLL_PRI" },
1088 { POLL_HUP, "POLL_HUP" },
1092 static struct xlat sigprof_codes[] = {
1094 { PROF_SIG, "PROF_SIG" },
1099 static struct xlat sigill_codes[] = {
1100 { ILL_ILLOPC, "ILL_ILLOPC" },
1101 { ILL_ILLOPN, "ILL_ILLOPN" },
1102 { ILL_ILLADR, "ILL_ILLADR" },
1103 { ILL_ILLTRP, "ILL_ILLTRP" },
1104 { ILL_PRVOPC, "ILL_PRVOPC" },
1105 { ILL_PRVREG, "ILL_PRVREG" },
1106 { ILL_COPROC, "ILL_COPROC" },
1107 { ILL_BADSTK, "ILL_BADSTK" },
1111 static struct xlat sigemt_codes[] = {
1113 { EMT_TAGOVF, "EMT_TAGOVF" },
1118 static struct xlat sigfpe_codes[] = {
1119 { FPE_INTDIV, "FPE_INTDIV" },
1120 { FPE_INTOVF, "FPE_INTOVF" },
1121 { FPE_FLTDIV, "FPE_FLTDIV" },
1122 { FPE_FLTOVF, "FPE_FLTOVF" },
1123 { FPE_FLTUND, "FPE_FLTUND" },
1124 { FPE_FLTRES, "FPE_FLTRES" },
1125 { FPE_FLTINV, "FPE_FLTINV" },
1126 { FPE_FLTSUB, "FPE_FLTSUB" },
1130 static struct xlat sigsegv_codes[] = {
1131 { SEGV_MAPERR, "SEGV_MAPERR" },
1132 { SEGV_ACCERR, "SEGV_ACCERR" },
1136 static struct xlat sigbus_codes[] = {
1137 { BUS_ADRALN, "BUS_ADRALN" },
1138 { BUS_ADRERR, "BUS_ADRERR" },
1139 { BUS_OBJERR, "BUS_OBJERR" },
1149 tprintf("{si_signo=");
1150 printsignal(sip->si_signo);
1151 code = xlookup(siginfo_codes, sip->si_code);
1153 switch (sip->si_signo) {
1155 code = xlookup(sigtrap_codes, sip->si_code);
1158 code = xlookup(sigcld_codes, sip->si_code);
1161 code = xlookup(sigpoll_codes, sip->si_code);
1164 code = xlookup(sigprof_codes, sip->si_code);
1167 code = xlookup(sigill_codes, sip->si_code);
1170 code = xlookup(sigemt_codes, sip->si_code);
1173 code = xlookup(sigfpe_codes, sip->si_code);
1176 code = xlookup(sigsegv_codes, sip->si_code);
1179 code = xlookup(sigbus_codes, sip->si_code);
1184 tprintf(", si_code=%s", code);
1186 tprintf(", si_code=%#x", sip->si_code);
1188 if (sip->si_code != SI_NOINFO) {
1190 if (sip->si_errno) {
1191 if (sip->si_errno < 0 || sip->si_errno >= nerrnos)
1192 tprintf(", si_errno=%d", sip->si_errno);
1194 tprintf(", si_errno=%s",
1195 errnoent[sip->si_errno]);
1197 if (SI_FROMUSER(sip)) {
1199 tprintf(", si_pid=%ld, si_uid=%ld",
1200 sip->si_pid, sip->si_uid);
1201 switch (sip->si_code) {
1205 #endif /* SI_QUEUE */
1209 #endif /* SI_MESGQ */
1210 tprintf(", si_value=%d",
1211 sip->si_value.sival_int);
1214 #endif /* SI_QUEUE */
1217 switch (sip->si_signo) {
1219 tprintf(", si_pid=%ld, si_status=",
1221 if (sip->si_code == CLD_EXITED)
1222 tprintf("%d", sip->si_status);
1224 printsignal(sip->si_status);
1226 case SIGILL: case SIGFPE:
1227 case SIGSEGV: case SIGBUS:
1228 tprintf(", si_addr=%#lx",
1229 (unsigned long) sip->si_addr);
1232 switch (sip->si_code) {
1233 case POLL_IN: case POLL_OUT: case POLL_MSG:
1234 tprintf(", si_band=%ld",
1235 (long) sip->si_band);
1255 if (entering(tcp)) {
1256 printxval(waitid_types, tcp->u_arg[0], "P_???");
1257 tprintf(", %ld, ", tcp->u_arg[1]);
1258 if (tcp->nchildren > 0) {
1259 /* There are traced children */
1260 tcp->flags |= TCB_SUSPENDED;
1261 tcp->waitpid = tcp->u_arg[0];
1269 else if (syserror(tcp))
1270 tprintf("%#lx", tcp->u_arg[2]);
1271 else if (umove(tcp, tcp->u_arg[2], &si) < 0)
1277 if (!printflags(wait4_options, tcp->u_arg[3]))
1290 tprintf("%lu", tcp->u_arg[0]);
1298 struct utsname uname;
1301 if (syserror(tcp) || !verbose(tcp))
1302 tprintf("%#lx", tcp->u_arg[0]);
1303 else if (umove(tcp, tcp->u_arg[0], &uname) < 0)
1305 else if (!abbrev(tcp)) {
1307 tprintf("{sysname=\"%s\", nodename=\"%s\", ",
1308 uname.sysname, uname.nodename);
1309 tprintf("release=\"%s\", version=\"%s\", ",
1310 uname.release, uname.version);
1311 tprintf("machine=\"%s\"", uname.machine);
1314 tprintf(", domainname=\"%s\"", uname.domainname);
1315 #endif /* __GLIBC__ */
1320 tprintf("{sys=\"%s\", node=\"%s\", ...}",
1321 uname.sysname, uname.nodename);
1328 static struct xlat ptrace_cmds[] = {
1329 { PTRACE_TRACEME, "PTRACE_TRACEME" },
1330 { PTRACE_PEEKTEXT, "PTRACE_PEEKTEXT", },
1331 { PTRACE_PEEKDATA, "PTRACE_PEEKDATA", },
1332 { PTRACE_PEEKUSER, "PTRACE_PEEKUSER", },
1333 { PTRACE_POKETEXT, "PTRACE_POKETEXT", },
1334 { PTRACE_POKEDATA, "PTRACE_POKEDATA", },
1335 { PTRACE_POKEUSER, "PTRACE_POKEUSER", },
1336 { PTRACE_CONT, "PTRACE_CONT" },
1337 { PTRACE_KILL, "PTRACE_KILL" },
1338 { PTRACE_SINGLESTEP, "PTRACE_SINGLESTEP" },
1339 { PTRACE_ATTACH, "PTRACE_ATTACH" },
1340 { PTRACE_DETACH, "PTRACE_DETACH" },
1342 { PTRACE_GETREGS, "PTRACE_GETREGS" },
1343 { PTRACE_SETREGS, "PTRACE_SETREGS" },
1344 { PTRACE_GETFPREGS, "PTRACE_GETFPREGS", },
1345 { PTRACE_SETFPREGS, "PTRACE_SETFPREGS", },
1346 { PTRACE_READDATA, "PTRACE_READDATA" },
1347 { PTRACE_WRITEDATA, "PTRACE_WRITEDATA" },
1348 { PTRACE_READTEXT, "PTRACE_READTEXT" },
1349 { PTRACE_WRITETEXT, "PTRACE_WRITETEXT" },
1350 { PTRACE_GETFPAREGS, "PTRACE_GETFPAREGS" },
1351 { PTRACE_SETFPAREGS, "PTRACE_SETFPAREGS" },
1353 { PTRACE_GETWINDOW, "PTRACE_GETWINDOW" },
1354 { PTRACE_SETWINDOW, "PTRACE_SETWINDOW" },
1356 { PTRACE_22, "PTRACE_PTRACE_22" },
1357 { PTRACE_23, "PTRACE_PTRACE_23" },
1360 { PTRACE_SYSCALL, "PTRACE_SYSCALL" },
1362 { PTRACE_DUMPCORE, "PTRACE_DUMPCORE" },
1364 { PTRACE_SETWRBKPT, "PTRACE_SETWRBKPT" },
1365 { PTRACE_SETACBKPT, "PTRACE_SETACBKPT" },
1366 { PTRACE_CLRDR7, "PTRACE_CLRDR7" },
1368 { PTRACE_26, "PTRACE_26" },
1369 { PTRACE_27, "PTRACE_27" },
1370 { PTRACE_28, "PTRACE_28" },
1372 { PTRACE_GETUCODE, "PTRACE_GETUCODE" },
1377 #ifndef SUNOS4_KERNEL_ARCH_KLUDGE
1379 #endif /* !SUNOS4_KERNEL_ARCH_KLUDGE */
1380 struct xlat struct_user_offsets[] = {
1383 /* XXX No support for these offsets yet. */
1384 #elif defined(POWERPC)
1385 { 4*PT_R0, "4*PT_R0" },
1386 { 4*PT_R1, "4*PT_R1" },
1387 { 4*PT_R2, "4*PT_R2" },
1388 { 4*PT_R3, "4*PT_R3" },
1389 { 4*PT_R4, "4*PT_R4" },
1390 { 4*PT_R5, "4*PT_R5" },
1391 { 4*PT_R6, "4*PT_R6" },
1392 { 4*PT_R7, "4*PT_R7" },
1393 { 4*PT_R8, "4*PT_R8" },
1394 { 4*PT_R9, "4*PT_R9" },
1395 { 4*PT_R10, "4*PT_R10" },
1396 { 4*PT_R11, "4*PT_R11" },
1397 { 4*PT_R12, "4*PT_R12" },
1398 { 4*PT_R13, "4*PT_R13" },
1399 { 4*PT_R14, "4*PT_R14" },
1400 { 4*PT_R15, "4*PT_R15" },
1401 { 4*PT_R16, "4*PT_R16" },
1402 { 4*PT_R17, "4*PT_R17" },
1403 { 4*PT_R18, "4*PT_R18" },
1404 { 4*PT_R19, "4*PT_R19" },
1405 { 4*PT_R20, "4*PT_R20" },
1406 { 4*PT_R21, "4*PT_R21" },
1407 { 4*PT_R22, "4*PT_R22" },
1408 { 4*PT_R23, "4*PT_R23" },
1409 { 4*PT_R24, "4*PT_R24" },
1410 { 4*PT_R25, "4*PT_R25" },
1411 { 4*PT_R26, "4*PT_R26" },
1412 { 4*PT_R27, "4*PT_R27" },
1413 { 4*PT_R28, "4*PT_R28" },
1414 { 4*PT_R29, "4*PT_R29" },
1415 { 4*PT_R30, "4*PT_R30" },
1416 { 4*PT_R31, "4*PT_R31" },
1417 { 4*PT_NIP, "4*PT_NIP" },
1418 { 4*PT_MSR, "4*PT_MSR" },
1419 { 4*PT_ORIG_R3, "4*PT_ORIG_R3" },
1420 { 4*PT_CTR, "4*PT_CTR" },
1421 { 4*PT_LNK, "4*PT_LNK" },
1422 { 4*PT_XER, "4*PT_XER" },
1423 { 4*PT_CCR, "4*PT_CCR" },
1424 { 4*PT_FPR0, "4*PT_FPR0" },
1505 { 4*ORIG_EAX, "4*ORIG_EAX" },
1509 { 4*UESP, "4*UESP" },
1513 { 4*PT_D1, "4*PT_D1" },
1514 { 4*PT_D2, "4*PT_D2" },
1515 { 4*PT_D3, "4*PT_D3" },
1516 { 4*PT_D4, "4*PT_D4" },
1517 { 4*PT_D5, "4*PT_D5" },
1518 { 4*PT_D6, "4*PT_D6" },
1519 { 4*PT_D7, "4*PT_D7" },
1520 { 4*PT_A0, "4*PT_A0" },
1521 { 4*PT_A1, "4*PT_A1" },
1522 { 4*PT_A2, "4*PT_A2" },
1523 { 4*PT_A3, "4*PT_A3" },
1524 { 4*PT_A4, "4*PT_A4" },
1525 { 4*PT_A5, "4*PT_A5" },
1526 { 4*PT_A6, "4*PT_A6" },
1527 { 4*PT_D0, "4*PT_D0" },
1528 { 4*PT_USP, "4*PT_USP" },
1529 { 4*PT_ORIG_D0, "4*PT_ORIG_D0" },
1530 { 4*PT_SR, "4*PT_SR" },
1531 { 4*PT_PC, "4*PT_PC" },
1534 { uoff(u_fpvalid), "offsetof(struct user, u_fpvalid)" },
1536 { uoff(i387), "offsetof(struct user, i387)" },
1539 { uoff(m68kfp), "offsetof(struct user, m68kfp)" },
1542 { uoff(u_tsize), "offsetof(struct user, u_tsize)" },
1543 { uoff(u_dsize), "offsetof(struct user, u_dsize)" },
1544 { uoff(u_ssize), "offsetof(struct user, u_ssize)" },
1545 { uoff(start_code), "offsetof(struct user, start_code)" },
1546 { uoff(start_stack), "offsetof(struct user, start_stack)" },
1547 { uoff(signal), "offsetof(struct user, signal)" },
1548 { uoff(reserved), "offsetof(struct user, reserved)" },
1549 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
1551 { uoff(u_fpstate), "offsetof(struct user, u_fpstate)" },
1553 { uoff(magic), "offsetof(struct user, magic)" },
1554 { uoff(u_comm), "offsetof(struct user, u_comm)" },
1556 { uoff(u_debugreg), "offsetof(struct user, u_debugreg)" },
1559 #endif /* !POWERPC/!SPARC */
1562 { uoff(u_pcb), "offsetof(struct user, u_pcb)" },
1563 { uoff(u_procp), "offsetof(struct user, u_procp)" },
1564 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
1565 { uoff(u_comm[0]), "offsetof(struct user, u_comm[0])" },
1566 { uoff(u_arg[0]), "offsetof(struct user, u_arg[0])" },
1567 { uoff(u_ap), "offsetof(struct user, u_ap)" },
1568 { uoff(u_qsave), "offsetof(struct user, u_qsave)" },
1569 { uoff(u_rval1), "offsetof(struct user, u_rval1)" },
1570 { uoff(u_rval2), "offsetof(struct user, u_rval2)" },
1571 { uoff(u_error), "offsetof(struct user, u_error)" },
1572 { uoff(u_eosys), "offsetof(struct user, u_eosys)" },
1573 { uoff(u_ssave), "offsetof(struct user, u_ssave)" },
1574 { uoff(u_signal[0]), "offsetof(struct user, u_signal)" },
1575 { uoff(u_sigmask[0]), "offsetof(struct user, u_sigmask)" },
1576 { uoff(u_sigonstack), "offsetof(struct user, u_sigonstack)" },
1577 { uoff(u_sigintr), "offsetof(struct user, u_sigintr)" },
1578 { uoff(u_sigreset), "offsetof(struct user, u_sigreset)" },
1579 { uoff(u_oldmask), "offsetof(struct user, u_oldmask)" },
1580 { uoff(u_code), "offsetof(struct user, u_code)" },
1581 { uoff(u_addr), "offsetof(struct user, u_addr)" },
1582 { uoff(u_sigstack), "offsetof(struct user, u_sigstack)" },
1583 { uoff(u_ofile), "offsetof(struct user, u_ofile)" },
1584 { uoff(u_pofile), "offsetof(struct user, u_pofile)" },
1585 { uoff(u_ofile_arr[0]), "offsetof(struct user, u_ofile_arr[0])" },
1586 { uoff(u_pofile_arr[0]),"offsetof(struct user, u_pofile_arr[0])"},
1587 { uoff(u_lastfile), "offsetof(struct user, u_lastfile)" },
1588 { uoff(u_cwd), "offsetof(struct user, u_cwd)" },
1589 { uoff(u_cdir), "offsetof(struct user, u_cdir)" },
1590 { uoff(u_rdir), "offsetof(struct user, u_rdir)" },
1591 { uoff(u_cmask), "offsetof(struct user, u_cmask)" },
1592 { uoff(u_ru), "offsetof(struct user, u_ru)" },
1593 { uoff(u_cru), "offsetof(struct user, u_cru)" },
1594 { uoff(u_timer[0]), "offsetof(struct user, u_timer[0])" },
1595 { uoff(u_XXX[0]), "offsetof(struct user, u_XXX[0])" },
1596 { uoff(u_ioch), "offsetof(struct user, u_ioch)" },
1597 { uoff(u_start), "offsetof(struct user, u_start)" },
1598 { uoff(u_acflag), "offsetof(struct user, u_acflag)" },
1599 { uoff(u_prof.pr_base), "offsetof(struct user, u_prof.pr_base)" },
1600 { uoff(u_prof.pr_size), "offsetof(struct user, u_prof.pr_size)" },
1601 { uoff(u_prof.pr_off), "offsetof(struct user, u_prof.pr_off)" },
1602 { uoff(u_prof.pr_scale),"offsetof(struct user, u_prof.pr_scale)"},
1603 { uoff(u_rlimit[0]), "offsetof(struct user, u_rlimit)" },
1604 { uoff(u_exdata.Ux_A), "offsetof(struct user, u_exdata.Ux_A)" },
1605 { uoff(u_exdata.ux_shell[0]),"offsetof(struct user, u_exdata.ux_shell[0])"},
1606 { uoff(u_lofault), "offsetof(struct user, u_lofault)" },
1608 { sizeof(struct user), "sizeof(struct user)" },
1620 cmd = xlookup(ptrace_cmds, tcp->u_arg[0]);
1623 if (entering(tcp)) {
1624 tprintf("%s, %lu, ", cmd, tcp->u_arg[1]);
1625 addr = tcp->u_arg[2];
1626 if (tcp->u_arg[0] == PTRACE_PEEKUSER
1627 || tcp->u_arg[0] == PTRACE_POKEUSER) {
1628 for (x = struct_user_offsets; x->str; x++) {
1633 tprintf("%#lx, ", addr);
1634 else if (x->val > addr && x != struct_user_offsets) {
1636 tprintf("%s + %ld, ", x->str, addr - x->val);
1639 tprintf("%s, ", x->str);
1642 tprintf("%#lx, ", tcp->u_arg[2]);
1644 switch (tcp->u_arg[0]) {
1645 case PTRACE_PEEKDATA:
1646 case PTRACE_PEEKTEXT:
1647 case PTRACE_PEEKUSER:
1650 case PTRACE_SINGLESTEP:
1651 case PTRACE_SYSCALL:
1653 printsignal(tcp->u_arg[3]);
1656 tprintf("%#lx", tcp->u_arg[3]);
1660 switch (tcp->u_arg[0]) {
1661 case PTRACE_PEEKDATA:
1662 case PTRACE_PEEKTEXT:
1663 case PTRACE_PEEKUSER:
1664 printnum(tcp, tcp->u_arg[3], "%#x");
1670 if (tcp->u_arg[0] == PTRACE_WRITEDATA ||
1671 tcp->u_arg[0] == PTRACE_WRITETEXT) {
1672 tprintf("%lu, ", tcp->u_arg[3]);
1673 printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]);
1674 } else if (tcp->u_arg[0] != PTRACE_READDATA &&
1675 tcp->u_arg[0] != PTRACE_READTEXT) {
1676 tprintf("%#lx", tcp->u_arg[3]);
1679 if (tcp->u_arg[0] == PTRACE_READDATA ||
1680 tcp->u_arg[0] == PTRACE_READTEXT) {
1681 tprintf("%lu, ", tcp->u_arg[3]);
1682 printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]);