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 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
6 * Copyright (c) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation
7 * Linux for s390 port by D.J. Barrow
8 * <barrow_dj@mail.yahoo.com,djbarrow@de.ibm.com>
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 #include <sys/syscall.h>
43 #include <sys/param.h>
47 #ifndef PTRACE_PEEKUSR
48 # define PTRACE_PEEKUSR PTRACE_PEEKUSER
50 #elif defined(HAVE_LINUX_PTRACE_H)
52 # ifdef HAVE_STRUCT_IA64_FPREG
53 # define ia64_fpreg XXX_ia64_fpreg
55 # ifdef HAVE_STRUCT_PT_ALL_USER_REGS
56 # define pt_all_user_regs XXX_pt_all_user_regs
58 #include <linux/ptrace.h>
60 # undef pt_all_user_regs
63 #if defined (LINUX) && defined (SPARC64)
64 # undef PTRACE_GETREGS
65 # define PTRACE_GETREGS PTRACE_GETREGS64
66 # undef PTRACE_SETREGS
67 # define PTRACE_SETREGS PTRACE_SETREGS64
68 #endif /* LINUX && SPARC64 */
70 #if defined(LINUX) && defined(IA64)
71 # include <asm/ptrace_offsets.h>
75 #define NR_SYSCALL_BASE 0
78 #define ERESTARTSYS 512
80 #ifndef ERESTARTNOINTR
81 #define ERESTARTNOINTR 513
83 #ifndef ERESTARTNOHAND
84 #define ERESTARTNOHAND 514 /* restart if no handler.. */
87 #define ENOIOCTLCMD 515 /* No ioctl command */
89 #ifndef ERESTART_RESTARTBLOCK
90 #define ERESTART_RESTARTBLOCK 516 /* restart by calling sys_restart_syscall */
93 #warning: NSIG is not defined, using 32
97 /* Ugh. Is this really correct? ARM has no RT signals?! */
100 #undef NR_SYSCALL_BASE
101 #define NR_SYSCALL_BASE __NR_SYSCALL_BASE
107 /* Define these shorthand notations to simplify the syscallent files. */
108 #define TD TRACE_DESC
109 #define TF TRACE_FILE
111 #define TN TRACE_NETWORK
112 #define TP TRACE_PROCESS
113 #define TS TRACE_SIGNAL
114 #define NF SYSCALL_NEVER_FAILS
117 static const struct sysent sysent0[] = {
118 #include "syscallent.h"
121 #if SUPPORTED_PERSONALITIES >= 2
122 static const struct sysent sysent1[] = {
123 #include "syscallent1.h"
127 #if SUPPORTED_PERSONALITIES >= 3
128 static const struct sysent sysent2[] = {
129 #include "syscallent2.h"
133 /* Now undef them since short defines cause wicked namespace pollution. */
145 * `ioctlent.h' may be generated from `ioctlent.raw' by the auxiliary
146 * program `ioctlsort', such that the list is sorted by the `code' field.
147 * This has the side-effect of resolving the _IO.. macros into
148 * plain integers, eliminating the need to include here everything
153 static const char *const errnoent0[] = {
154 #include "errnoent.h"
156 static const char *const signalent0[] = {
157 #include "signalent.h"
159 static const struct ioctlent ioctlent0[] = {
160 #include "ioctlent.h"
162 enum { nsyscalls0 = ARRAY_SIZE(sysent0) };
163 enum { nerrnos0 = ARRAY_SIZE(errnoent0) };
164 enum { nsignals0 = ARRAY_SIZE(signalent0) };
165 enum { nioctlents0 = ARRAY_SIZE(ioctlent0) };
166 int qual_flags0[MAX_QUALS];
168 #if SUPPORTED_PERSONALITIES >= 2
169 static const char *const errnoent1[] = {
170 #include "errnoent1.h"
172 static const char *const signalent1[] = {
173 #include "signalent1.h"
175 static const struct ioctlent ioctlent1[] = {
176 #include "ioctlent1.h"
178 enum { nsyscalls1 = ARRAY_SIZE(sysent1) };
179 enum { nerrnos1 = ARRAY_SIZE(errnoent1) };
180 enum { nsignals1 = ARRAY_SIZE(signalent1) };
181 enum { nioctlents1 = ARRAY_SIZE(ioctlent1) };
182 int qual_flags1[MAX_QUALS];
185 #if SUPPORTED_PERSONALITIES >= 3
186 static const char *const errnoent2[] = {
187 #include "errnoent2.h"
189 static const char *const signalent2[] = {
190 #include "signalent2.h"
192 static const struct ioctlent ioctlent2[] = {
193 #include "ioctlent2.h"
195 enum { nsyscalls2 = ARRAY_SIZE(sysent2) };
196 enum { nerrnos2 = ARRAY_SIZE(errnoent2) };
197 enum { nsignals2 = ARRAY_SIZE(signalent2) };
198 enum { nioctlents2 = ARRAY_SIZE(ioctlent2) };
199 int qual_flags2[MAX_QUALS];
203 const struct sysent *sysent;
204 const char *const *errnoent;
205 const char *const *signalent;
206 const struct ioctlent *ioctlent;
213 int current_personality;
215 #ifndef PERSONALITY0_WORDSIZE
216 # define PERSONALITY0_WORDSIZE sizeof(long)
218 const int personality_wordsize[SUPPORTED_PERSONALITIES] = {
219 PERSONALITY0_WORDSIZE,
220 #if SUPPORTED_PERSONALITIES > 1
221 PERSONALITY1_WORDSIZE,
223 #if SUPPORTED_PERSONALITIES > 2
224 PERSONALITY2_WORDSIZE,
229 set_personality(int personality)
231 switch (personality) {
233 errnoent = errnoent0;
236 nsyscalls = nsyscalls0;
237 ioctlent = ioctlent0;
238 nioctlents = nioctlents0;
239 signalent = signalent0;
240 nsignals = nsignals0;
241 qual_flags = qual_flags0;
244 #if SUPPORTED_PERSONALITIES >= 2
246 errnoent = errnoent1;
249 nsyscalls = nsyscalls1;
250 ioctlent = ioctlent1;
251 nioctlents = nioctlents1;
252 signalent = signalent1;
253 nsignals = nsignals1;
254 qual_flags = qual_flags1;
258 #if SUPPORTED_PERSONALITIES >= 3
260 errnoent = errnoent2;
263 nsyscalls = nsyscalls2;
264 ioctlent = ioctlent2;
265 nioctlents = nioctlents2;
266 signalent = signalent2;
267 nsignals = nsignals2;
268 qual_flags = qual_flags2;
273 current_personality = personality;
277 static int qual_syscall(), qual_signal(), qual_fault(), qual_desc();
279 static const struct qual_options {
281 const char *option_name;
282 int (*qualify)(const char *, int, int);
283 const char *argument_name;
285 { QUAL_TRACE, "trace", qual_syscall, "system call" },
286 { QUAL_TRACE, "t", qual_syscall, "system call" },
287 { QUAL_ABBREV, "abbrev", qual_syscall, "system call" },
288 { QUAL_ABBREV, "a", qual_syscall, "system call" },
289 { QUAL_VERBOSE, "verbose", qual_syscall, "system call" },
290 { QUAL_VERBOSE, "v", qual_syscall, "system call" },
291 { QUAL_RAW, "raw", qual_syscall, "system call" },
292 { QUAL_RAW, "x", qual_syscall, "system call" },
293 { QUAL_SIGNAL, "signal", qual_signal, "signal" },
294 { QUAL_SIGNAL, "signals", qual_signal, "signal" },
295 { QUAL_SIGNAL, "s", qual_signal, "signal" },
296 { QUAL_FAULT, "fault", qual_fault, "fault" },
297 { QUAL_FAULT, "faults", qual_fault, "fault" },
298 { QUAL_FAULT, "m", qual_fault, "fault" },
299 { QUAL_READ, "read", qual_desc, "descriptor" },
300 { QUAL_READ, "reads", qual_desc, "descriptor" },
301 { QUAL_READ, "r", qual_desc, "descriptor" },
302 { QUAL_WRITE, "write", qual_desc, "descriptor" },
303 { QUAL_WRITE, "writes", qual_desc, "descriptor" },
304 { QUAL_WRITE, "w", qual_desc, "descriptor" },
305 { 0, NULL, NULL, NULL },
309 qualify_one(int n, int bitflag, int not, int pers)
311 if (pers == 0 || pers < 0) {
313 qual_flags0[n] &= ~bitflag;
315 qual_flags0[n] |= bitflag;
318 #if SUPPORTED_PERSONALITIES >= 2
319 if (pers == 1 || pers < 0) {
321 qual_flags1[n] &= ~bitflag;
323 qual_flags1[n] |= bitflag;
325 #endif /* SUPPORTED_PERSONALITIES >= 2 */
327 #if SUPPORTED_PERSONALITIES >= 3
328 if (pers == 2 || pers < 0) {
330 qual_flags2[n] &= ~bitflag;
332 qual_flags2[n] |= bitflag;
334 #endif /* SUPPORTED_PERSONALITIES >= 3 */
338 qual_syscall(const char *s, int bitflag, int not)
343 if (isdigit((unsigned char)*s)) {
345 if (i < 0 || i >= MAX_QUALS)
347 qualify_one(i, bitflag, not, -1);
350 for (i = 0; i < nsyscalls0; i++)
351 if (strcmp(s, sysent0[i].sys_name) == 0) {
352 qualify_one(i, bitflag, not, 0);
356 #if SUPPORTED_PERSONALITIES >= 2
357 for (i = 0; i < nsyscalls1; i++)
358 if (strcmp(s, sysent1[i].sys_name) == 0) {
359 qualify_one(i, bitflag, not, 1);
362 #endif /* SUPPORTED_PERSONALITIES >= 2 */
364 #if SUPPORTED_PERSONALITIES >= 3
365 for (i = 0; i < nsyscalls2; i++)
366 if (strcmp(s, sysent2[i].sys_name) == 0) {
367 qualify_one(i, bitflag, not, 2);
370 #endif /* SUPPORTED_PERSONALITIES >= 3 */
376 qual_signal(const char *s, int bitflag, int not)
381 if (isdigit((unsigned char)*s)) {
383 if (signo < 0 || signo >= MAX_QUALS)
385 qualify_one(signo, bitflag, not, -1);
388 if (strlen(s) >= sizeof buf)
392 if (strncasecmp(s, "SIG", 3) == 0)
394 for (i = 0; i <= NSIG; i++)
395 if (strcasecmp(s, signame(i) + 3) == 0) {
396 qualify_one(i, bitflag, not, -1);
403 qual_fault(const char *s, int bitflag, int not)
409 qual_desc(const char *s, int bitflag, int not)
411 if (isdigit((unsigned char)*s)) {
413 if (desc < 0 || desc >= MAX_QUALS)
415 qualify_one(desc, bitflag, not, -1);
422 lookup_class(const char *s)
424 if (strcmp(s, "file") == 0)
426 if (strcmp(s, "ipc") == 0)
428 if (strcmp(s, "network") == 0)
429 return TRACE_NETWORK;
430 if (strcmp(s, "process") == 0)
431 return TRACE_PROCESS;
432 if (strcmp(s, "signal") == 0)
434 if (strcmp(s, "desc") == 0)
440 qualify(const char *s)
442 const struct qual_options *opt;
448 opt = &qual_options[0];
449 for (i = 0; (p = qual_options[i].option_name); i++) {
451 if (strncmp(s, p, n) == 0 && s[n] == '=') {
452 opt = &qual_options[i];
462 if (strcmp(s, "none") == 0) {
466 if (strcmp(s, "all") == 0) {
467 for (i = 0; i < MAX_QUALS; i++) {
468 qualify_one(i, opt->bitflag, not, -1);
472 for (i = 0; i < MAX_QUALS; i++) {
473 qualify_one(i, opt->bitflag, !not, -1);
477 fprintf(stderr, "out of memory\n");
480 for (p = strtok(copy, ","); p; p = strtok(NULL, ",")) {
481 if (opt->bitflag == QUAL_TRACE && (n = lookup_class(p)) > 0) {
482 for (i = 0; i < nsyscalls0; i++)
483 if (sysent0[i].sys_flags & n)
484 qualify_one(i, opt->bitflag, not, 0);
486 #if SUPPORTED_PERSONALITIES >= 2
487 for (i = 0; i < nsyscalls1; i++)
488 if (sysent1[i].sys_flags & n)
489 qualify_one(i, opt->bitflag, not, 1);
490 #endif /* SUPPORTED_PERSONALITIES >= 2 */
492 #if SUPPORTED_PERSONALITIES >= 3
493 for (i = 0; i < nsyscalls2; i++)
494 if (sysent2[i].sys_flags & n)
495 qualify_one(i, opt->bitflag, not, 2);
496 #endif /* SUPPORTED_PERSONALITIES >= 3 */
500 if (opt->qualify(p, opt->bitflag, not)) {
501 fprintf(stderr, "strace: invalid %s `%s'\n",
502 opt->argument_name, p);
511 dumpio(struct tcb *tcp)
515 if (tcp->u_arg[0] < 0 || tcp->u_arg[0] >= MAX_QUALS)
517 if (tcp->scno < 0 || tcp->scno >= nsyscalls)
519 if (sysent[tcp->scno].sys_func == printargs)
521 if (qual_flags[tcp->u_arg[0]] & QUAL_READ) {
522 if (sysent[tcp->scno].sys_func == sys_read ||
523 sysent[tcp->scno].sys_func == sys_pread ||
524 sysent[tcp->scno].sys_func == sys_pread64 ||
525 sysent[tcp->scno].sys_func == sys_recv ||
526 sysent[tcp->scno].sys_func == sys_recvfrom)
527 dumpstr(tcp, tcp->u_arg[1], tcp->u_rval);
528 else if (sysent[tcp->scno].sys_func == sys_readv)
529 dumpiov(tcp, tcp->u_arg[2], tcp->u_arg[1]);
532 if (qual_flags[tcp->u_arg[0]] & QUAL_WRITE) {
533 if (sysent[tcp->scno].sys_func == sys_write ||
534 sysent[tcp->scno].sys_func == sys_pwrite ||
535 sysent[tcp->scno].sys_func == sys_pwrite64 ||
536 sysent[tcp->scno].sys_func == sys_send ||
537 sysent[tcp->scno].sys_func == sys_sendto)
538 dumpstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
539 else if (sysent[tcp->scno].sys_func == sys_writev)
540 dumpiov(tcp, tcp->u_arg[2], tcp->u_arg[1]);
546 enum subcall_style { shift_style, deref_style, mask_style, door_style };
548 enum subcall_style { shift_style, deref_style, mask_style, door_style, table_style };
556 static const struct subcall subcalls_table[] = {
557 { SYS_shmsys, 5, { SYS_shmat, SYS_shmctl, SYS_shmdt, SYS_shmget, SYS_shmctl } },
559 { SYS_semsys, 4, { SYS___semctl, SYS_semget, SYS_semop, SYS_semconfig } },
561 { SYS_semsys, 3, { SYS___semctl, SYS_semget, SYS_semop } },
563 { SYS_msgsys, 4, { SYS_msgctl, SYS_msgget, SYS_msgsnd, SYS_msgrcv } },
567 #if !(defined(LINUX) && ( defined(ALPHA) || defined(MIPS) || defined(__ARM_EABI__) ))
570 decode_subcall(struct tcb *tcp, int subcall, int nsubcalls, enum subcall_style style)
572 unsigned long addr, mask;
574 int size = personality_wordsize[current_personality];
578 if (tcp->u_arg[0] < 0 || tcp->u_arg[0] >= nsubcalls)
580 tcp->scno = subcall + tcp->u_arg[0];
581 tcp->u_nargs = n = sysent[tcp->scno].nargs;
582 for (i = 0; i < n; i++)
583 tcp->u_arg[i] = tcp->u_arg[i + 1];
586 if (tcp->u_arg[0] < 0 || tcp->u_arg[0] >= nsubcalls)
588 tcp->scno = subcall + tcp->u_arg[0];
589 addr = tcp->u_arg[1];
590 tcp->u_nargs = n = sysent[tcp->scno].nargs;
591 for (i = 0; i < n; i++) {
592 if (size == sizeof(int)) {
594 if (umove(tcp, addr, &arg) < 0)
598 else if (size == sizeof(long)) {
600 if (umove(tcp, addr, &arg) < 0)
610 mask = (tcp->u_arg[0] >> 8) & 0xff;
611 for (i = 0; mask; i++)
615 tcp->u_arg[0] &= 0xff;
616 tcp->scno = subcall + i;
617 tcp->u_nargs = sysent[tcp->scno].nargs;
621 * Oh, yuck. The call code is the *sixth* argument.
622 * (don't you mean the *last* argument? - JH)
624 if (tcp->u_arg[5] < 0 || tcp->u_arg[5] >= nsubcalls)
626 tcp->scno = subcall + tcp->u_arg[5];
627 tcp->u_nargs = sysent[tcp->scno].nargs;
631 for (i = 0; i < ARRAY_SIZE(subcalls_table); i++)
632 if (subcalls_table[i].call == tcp->scno) break;
633 if (i < ARRAY_SIZE(subcalls_table) &&
634 tcp->u_arg[0] >= 0 && tcp->u_arg[0] < subcalls_table[i].nsubcalls) {
635 tcp->scno = subcalls_table[i].subcalls[tcp->u_arg[0]];
636 for (i = 0; i < tcp->u_nargs; i++)
637 tcp->u_arg[i] = tcp->u_arg[i + 1];
645 struct tcb *tcp_last = NULL;
648 internal_syscall(struct tcb *tcp)
651 * We must always trace a few critical system calls in order to
652 * correctly support following forks in the presence of tracing
657 if (tcp->scno < 0 || tcp->scno >= nsyscalls)
660 func = sysent[tcp->scno].sys_func;
662 if ( sys_fork == func
663 #if defined(FREEBSD) || defined(LINUX) || defined(SUNOS4)
673 return internal_fork(tcp);
675 #if defined SUNOS4 || (defined LINUX && defined TCB_WAITEXECVE)
676 if ( sys_execve == func
677 # if defined(SPARC) || defined(SPARC64) || defined(SUNOS4)
681 || sys_rexecve == func
684 return internal_exec(tcp);
694 # elif defined (IA64)
695 long r8, r10, psr; /* TODO: make static? */
696 long ia32 = 0; /* not static */
697 # elif defined (POWERPC)
698 static long result, flags;
699 # elif defined (M68K)
704 static struct pt_regs regs;
705 # elif defined (ALPHA)
708 # elif defined(AVR32)
709 static struct pt_regs regs;
710 # elif defined (SPARC) || defined (SPARC64)
711 static struct pt_regs regs;
712 static unsigned long trap;
713 # elif defined(LINUX_MIPSN32)
719 # elif defined(S390) || defined(S390X)
722 static long syscall_mode;
729 # elif defined(X86_64)
731 # elif defined(CRISV10) || defined(CRISV32)
733 # elif defined(MICROBLAZE)
738 struct reg regs; /* TODO: make static? */
742 * 0: "ignore this ptrace stop", bail out of trace_syscall() silently.
743 * 1: ok, continue in trace_syscall().
744 * other: error, trace_syscall() should print error indicator
745 * ("????" etc) and bail out.
748 get_scno(struct tcb *tcp)
753 # if defined(S390) || defined(S390X)
754 if (tcp->flags & TCB_WAITEXECVE) {
756 * When the execve system call completes successfully, the
757 * new process still has -ENOSYS (old style) or __NR_execve
758 * (new style) in gpr2. We cannot recover the scno again
759 * by disassembly, because the image that executed the
760 * syscall is gone now. Fortunately, we don't want it. We
761 * leave the flag set so that syscall_fixup can fake the
767 * This is the post-execve SIGTRAP. We cannot try to read
768 * the system call here either.
770 tcp->flags &= ~TCB_WAITEXECVE;
774 if (upeek(tcp, PT_GPR2, &syscall_mode) < 0)
777 if (syscall_mode != -ENOSYS) {
779 * Since kernel version 2.5.44 the scno gets passed in gpr2.
784 * Old style of "passing" the scno via the SVC instruction.
787 long opcode, offset_reg, tmp;
789 static const int gpr_offset[16] = {
790 PT_GPR0, PT_GPR1, PT_ORIGGPR2, PT_GPR3,
791 PT_GPR4, PT_GPR5, PT_GPR6, PT_GPR7,
792 PT_GPR8, PT_GPR9, PT_GPR10, PT_GPR11,
793 PT_GPR12, PT_GPR13, PT_GPR14, PT_GPR15
796 if (upeek(tcp, PT_PSWADDR, &pc) < 0)
799 opcode = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)(pc-sizeof(long)), 0);
801 perror("peektext(pc-oneword)");
806 * We have to check if the SVC got executed directly or via an
807 * EXECUTE instruction. In case of EXECUTE it is necessary to do
808 * instruction decoding to derive the system call number.
809 * Unfortunately the opcode sizes of EXECUTE and SVC are differently,
810 * so that this doesn't work if a SVC opcode is part of an EXECUTE
811 * opcode. Since there is no way to find out the opcode size this
812 * is the best we can do...
815 if ((opcode & 0xff00) == 0x0a00) {
817 scno = opcode & 0xff;
820 /* SVC got executed by EXECUTE instruction */
823 * Do instruction decoding of EXECUTE. If you really want to
824 * understand this, read the Principles of Operations.
826 svc_addr = (void *) (opcode & 0xfff);
829 offset_reg = (opcode & 0x000f0000) >> 16;
830 if (offset_reg && (upeek(tcp, gpr_offset[offset_reg], &tmp) < 0))
835 offset_reg = (opcode & 0x0000f000) >> 12;
836 if (offset_reg && (upeek(tcp, gpr_offset[offset_reg], &tmp) < 0))
840 scno = ptrace(PTRACE_PEEKTEXT, tcp->pid, svc_addr, 0);
849 offset_reg = (opcode & 0x00f00000) >> 20;
850 if (offset_reg && (upeek(tcp, gpr_offset[offset_reg], &tmp) < 0))
853 scno = (scno | tmp) & 0xff;
856 # elif defined (POWERPC)
857 if (upeek(tcp, sizeof(unsigned long)*PT_R0, &scno) < 0)
860 /* Check if this is the post-execve SIGTRAP. */
861 if (scno == 0 && (tcp->flags & TCB_WAITEXECVE)) {
862 tcp->flags &= ~TCB_WAITEXECVE;
869 /* TODO: speed up strace by not doing this at every syscall.
870 * We only need to do it after execve.
876 /* Check for 64/32 bit mode. */
877 if (upeek(tcp, sizeof(unsigned long)*PT_MSR, &val) < 0)
879 /* SF is bit 0 of MSR */
884 if (currpers != current_personality) {
885 static const char *const names[] = {"64 bit", "32 bit"};
886 set_personality(currpers);
887 fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n",
888 pid, names[current_personality]);
892 # elif defined(AVR32)
894 * Read complete register set in one go.
896 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, ®s) < 0)
900 * We only need to grab the syscall number on syscall entry.
905 /* Check if this is the post-execve SIGTRAP. */
906 if (tcp->flags & TCB_WAITEXECVE) {
907 tcp->flags &= ~TCB_WAITEXECVE;
912 if (upeek(tcp, PT_ORIG_P0, &scno))
914 # elif defined (I386)
915 if (upeek(tcp, 4*ORIG_EAX, &scno) < 0)
917 # elif defined (X86_64)
918 if (upeek(tcp, 8*ORIG_RAX, &scno) < 0)
922 /* TODO: speed up strace by not doing this at every syscall.
923 * We only need to do it after execve.
929 /* Check CS register value. On x86-64 linux it is:
930 * 0x33 for long mode (64 bit)
931 * 0x23 for compatibility mode (32 bit)
932 * It takes only one ptrace and thus doesn't need
935 if (upeek(tcp, 8*CS, &val) < 0)
938 case 0x23: currpers = 1; break;
939 case 0x33: currpers = 0; break;
941 fprintf(stderr, "Unknown value CS=0x%02X while "
942 "detecting personality of process "
943 "PID=%d\n", (int)val, pid);
944 currpers = current_personality;
948 /* This version analyzes the opcode of a syscall instruction.
949 * (int 0x80 on i386 vs. syscall on x86-64)
950 * It works, but is too complicated.
952 unsigned long val, rip, i;
954 if (upeek(tcp, 8*RIP, &rip) < 0)
955 perror("upeek(RIP)");
957 /* sizeof(syscall) == sizeof(int 0x80) == 2 */
961 call = ptrace(PTRACE_PEEKTEXT, pid, (char *)rip, (char *)0);
963 fprintf(stderr, "ptrace_peektext failed: %s\n",
965 switch (call & 0xffff) {
966 /* x86-64: syscall = 0x0f 0x05 */
967 case 0x050f: currpers = 0; break;
968 /* i386: int 0x80 = 0xcd 0x80 */
969 case 0x80cd: currpers = 1; break;
971 currpers = current_personality;
973 "Unknown syscall opcode (0x%04X) while "
974 "detecting personality of process "
975 "PID=%d\n", (int)call, pid);
979 if (currpers != current_personality) {
980 static const char *const names[] = {"64 bit", "32 bit"};
981 set_personality(currpers);
982 fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n",
983 pid, names[current_personality]);
987 # define IA64_PSR_IS ((long)1 << 34)
988 if (upeek(tcp, PT_CR_IPSR, &psr) >= 0)
989 ia32 = (psr & IA64_PSR_IS) != 0;
992 if (upeek(tcp, PT_R1, &scno) < 0) /* orig eax */
995 if (upeek(tcp, PT_R15, &scno) < 0)
998 /* Check if this is the post-execve SIGTRAP. */
999 if (tcp->flags & TCB_WAITEXECVE) {
1000 tcp->flags &= ~TCB_WAITEXECVE;
1005 if (upeek(tcp, PT_R8, &r8) < 0)
1007 if (upeek(tcp, PT_R10, &r10) < 0)
1010 # elif defined (ARM)
1012 * Read complete register set in one go.
1014 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (void *)®s) == -1)
1018 * We only need to grab the syscall number on syscall entry.
1020 if (regs.ARM_ip == 0) {
1021 if (entering(tcp)) {
1022 /* Check if this is the post-execve SIGTRAP. */
1023 if (tcp->flags & TCB_WAITEXECVE) {
1024 tcp->flags &= ~TCB_WAITEXECVE;
1030 * Note: we only deal with only 32-bit CPUs here.
1032 if (regs.ARM_cpsr & 0x20) {
1034 * Get the Thumb-mode system call number
1039 * Get the ARM-mode system call number
1042 scno = ptrace(PTRACE_PEEKTEXT, tcp->pid, (void *)(regs.ARM_pc - 4), NULL);
1046 /* FIXME: bogus check? it is already done on entering before,
1047 * so we never can see it here?
1049 if (scno == 0 && (tcp->flags & TCB_WAITEXECVE)) {
1050 tcp->flags &= ~TCB_WAITEXECVE;
1054 /* Handle the EABI syscall convention. We do not
1055 bother converting structures between the two
1056 ABIs, but basic functionality should work even
1057 if strace and the traced program have different
1059 if (scno == 0xef000000) {
1062 if ((scno & 0x0ff00000) != 0x0f900000) {
1063 fprintf(stderr, "syscall: unknown syscall trap 0x%08lx\n",
1069 * Fixup the syscall number
1074 if (scno & 0x0f0000) {
1076 * Handle ARM specific syscall
1084 fprintf(stderr, "pid %d stray syscall exit\n", tcp->pid);
1085 tcp->flags &= ~TCB_INSYSCALL;
1088 if (entering(tcp)) {
1089 fprintf(stderr, "pid %d stray syscall entry\n", tcp->pid);
1090 tcp->flags |= TCB_INSYSCALL;
1093 # elif defined (M68K)
1094 if (upeek(tcp, 4*PT_ORIG_D0, &scno) < 0)
1096 # elif defined (LINUX_MIPSN32)
1097 unsigned long long regs[38];
1099 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long) ®s) < 0)
1104 if (entering(tcp)) {
1107 /* Check if this is the post-execve SIGTRAP. */
1108 if (scno == 0 && tcp->flags & TCB_WAITEXECVE) {
1109 tcp->flags &= ~TCB_WAITEXECVE;
1113 if (scno < 0 || scno > nsyscalls) {
1114 if (a3 == 0 || a3 == -1) {
1116 fprintf(stderr, "stray syscall exit: v0 = %ld\n", scno);
1121 # elif defined (MIPS)
1122 if (upeek(tcp, REG_A3, &a3) < 0)
1124 if (entering(tcp)) {
1125 if (upeek(tcp, REG_V0, &scno) < 0)
1128 /* Check if this is the post-execve SIGTRAP. */
1129 if (scno == 0 && tcp->flags & TCB_WAITEXECVE) {
1130 tcp->flags &= ~TCB_WAITEXECVE;
1134 if (scno < 0 || scno > nsyscalls) {
1135 if (a3 == 0 || a3 == -1) {
1137 fprintf(stderr, "stray syscall exit: v0 = %ld\n", scno);
1142 if (upeek(tcp, REG_V0, &r2) < 0)
1145 # elif defined (ALPHA)
1146 if (upeek(tcp, REG_A3, &a3) < 0)
1149 if (entering(tcp)) {
1150 if (upeek(tcp, REG_R0, &scno) < 0)
1153 /* Check if this is the post-execve SIGTRAP. */
1154 if (scno == 0 && tcp->flags & TCB_WAITEXECVE) {
1155 tcp->flags &= ~TCB_WAITEXECVE;
1160 * Do some sanity checks to figure out if it's
1161 * really a syscall entry
1163 if (scno < 0 || scno > nsyscalls) {
1164 if (a3 == 0 || a3 == -1) {
1166 fprintf(stderr, "stray syscall exit: r0 = %ld\n", scno);
1172 if (upeek(tcp, REG_R0, &r0) < 0)
1175 # elif defined (SPARC) || defined (SPARC64)
1176 /* Everything we need is in the current register set. */
1177 if (ptrace(PTRACE_GETREGS, tcp->pid, (char *)®s, 0) < 0)
1180 /* If we are entering, then disassemble the syscall trap. */
1181 if (entering(tcp)) {
1182 /* Retrieve the syscall trap instruction. */
1184 # if defined(SPARC64)
1185 trap = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)regs.tpc, 0);
1188 trap = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)regs.pc, 0);
1193 /* Disassemble the trap to see what personality to use. */
1196 /* Linux/SPARC syscall trap. */
1200 /* Linux/SPARC64 syscall trap. */
1204 /* SunOS syscall trap. (pers 1) */
1205 fprintf(stderr, "syscall: SunOS no support\n");
1208 /* Solaris 2.x syscall trap. (per 2) */
1212 /* NetBSD/FreeBSD syscall trap. */
1213 fprintf(stderr, "syscall: NetBSD/FreeBSD not supported\n");
1216 /* Solaris 2.x gettimeofday */
1220 /* Check if this is the post-execve SIGTRAP. */
1221 if (tcp->flags & TCB_WAITEXECVE) {
1222 tcp->flags &= ~TCB_WAITEXECVE;
1225 # if defined (SPARC64)
1226 fprintf(stderr, "syscall: unknown syscall trap %08lx %016lx\n", trap, regs.tpc);
1228 fprintf(stderr, "syscall: unknown syscall trap %08lx %08lx\n", trap, regs.pc);
1233 /* Extract the system call number from the registers. */
1234 if (trap == 0x91d02027)
1237 scno = regs.u_regs[U_REG_G1];
1239 scno = regs.u_regs[U_REG_O0];
1240 memmove(®s.u_regs[U_REG_O0], ®s.u_regs[U_REG_O1], 7*sizeof(regs.u_regs[0]));
1243 # elif defined(HPPA)
1244 if (upeek(tcp, PT_GR20, &scno) < 0)
1246 if (entering(tcp)) {
1247 /* Check if this is the post-execve SIGTRAP. */
1248 if (tcp->flags & TCB_WAITEXECVE) {
1249 tcp->flags &= ~TCB_WAITEXECVE;
1255 * In the new syscall ABI, the system call number is in R3.
1257 if (upeek(tcp, 4*(REG_REG0+3), &scno) < 0)
1261 /* Odd as it may seem, a glibc bug has been known to cause
1262 glibc to issue bogus negative syscall numbers. So for
1263 our purposes, make strace print what it *should* have been */
1264 long correct_scno = (scno & 0xff);
1267 "Detected glibc bug: bogus system call"
1268 " number = %ld, correcting to %ld\n",
1271 scno = correct_scno;
1274 if (entering(tcp)) {
1275 /* Check if this is the post-execve SIGTRAP. */
1276 if (scno == 0 && tcp->flags & TCB_WAITEXECVE) {
1277 tcp->flags &= ~TCB_WAITEXECVE;
1281 # elif defined(SH64)
1282 if (upeek(tcp, REG_SYSCALL, &scno) < 0)
1286 if (entering(tcp)) {
1287 /* Check if this is the post-execve SIGTRAP. */
1288 if (tcp->flags & TCB_WAITEXECVE) {
1289 tcp->flags &= ~TCB_WAITEXECVE;
1293 # elif defined(CRISV10) || defined(CRISV32)
1294 if (upeek(tcp, 4*PT_R9, &scno) < 0)
1296 # elif defined(TILE)
1297 if (upeek(tcp, PTREGS_OFFSET_REG(10), &scno) < 0)
1300 if (entering(tcp)) {
1301 /* Check if this is the post-execve SIGTRAP. */
1302 if (tcp->flags & TCB_WAITEXECVE) {
1303 tcp->flags &= ~TCB_WAITEXECVE;
1307 # elif defined(MICROBLAZE)
1308 if (upeek(tcp, 0, &scno) < 0)
1314 if (upeek(tcp, uoff(u_arg[7]), &scno) < 0)
1317 /* new syscall ABI returns result in R0 */
1318 if (upeek(tcp, 4*REG_REG0, (long *)&r0) < 0)
1321 /* ABI defines result returned in r9 */
1322 if (upeek(tcp, REG_GENERAL(9), (long *)&r9) < 0)
1327 # ifdef HAVE_PR_SYSCALL
1328 scno = tcp->status.PR_SYSCALL;
1331 scno = tcp->status.PR_WHAT;
1333 if (pread(tcp->pfd_reg, ®s, sizeof(regs), 0) < 0) {
1337 switch (regs.r_eax) {
1340 pread(tcp->pfd, &scno, sizeof(scno), regs.r_esp + sizeof(int));
1346 # endif /* FREEBSD */
1347 # endif /* !HAVE_PR_SYSCALL */
1348 #endif /* USE_PROCFS */
1357 known_scno(struct tcb *tcp)
1359 long scno = tcp->scno;
1360 #if SUPPORTED_PERSONALITIES > 1
1361 if (scno >= 0 && scno < nsyscalls && sysent[scno].native_scno != 0)
1362 scno = sysent[scno].native_scno;
1365 scno += NR_SYSCALL_BASE;
1369 /* Called in trace_syscall() at each syscall entry and exit.
1371 * 0: "ignore this ptrace stop", bail out of trace_syscall() silently.
1372 * 1: ok, continue in trace_syscall().
1373 * other: error, trace_syscall() should print error indicator
1374 * ("????" etc) and bail out.
1377 syscall_fixup(struct tcb *tcp)
1380 int scno = known_scno(tcp);
1382 if (entering(tcp)) {
1383 if (tcp->status.PR_WHY != PR_SYSENTRY) {
1387 || scno == SYS_vfork
1388 #endif /* SYS_vfork */
1390 || scno == SYS_fork1
1391 #endif /* SYS_fork1 */
1393 || scno == SYS_forkall
1394 #endif /* SYS_forkall */
1396 || scno == SYS_rfork1
1397 #endif /* SYS_fork1 */
1399 || scno == SYS_rforkall
1400 #endif /* SYS_rforkall */
1402 /* We are returning in the child, fake it. */
1403 tcp->status.PR_WHY = PR_SYSENTRY;
1405 tcp->status.PR_WHY = PR_SYSEXIT;
1408 fprintf(stderr, "syscall: missing entry\n");
1409 tcp->flags |= TCB_INSYSCALL;
1414 if (tcp->status.PR_WHY != PR_SYSEXIT) {
1415 fprintf(stderr, "syscall: missing exit\n");
1416 tcp->flags &= ~TCB_INSYSCALL;
1419 #endif /* USE_PROCFS */
1422 if (entering(tcp)) {
1424 fprintf(stderr, "syscall: missing entry\n");
1425 tcp->flags |= TCB_INSYSCALL;
1432 * This happens when a signal handler
1433 * for a signal which interrupted a
1434 * a system call makes another system call.
1436 fprintf(stderr, "syscall: missing exit\n");
1438 tcp->flags &= ~TCB_INSYSCALL;
1444 /* A common case of "not a syscall entry" is post-execve SIGTRAP */
1446 if (upeek(tcp, 4*EAX, &eax) < 0)
1448 if (eax != -ENOSYS && entering(tcp)) {
1450 fprintf(stderr, "not a syscall entry (eax = %ld)\n", eax);
1453 #elif defined (X86_64)
1454 if (upeek(tcp, 8*RAX, &rax) < 0)
1456 if (current_personality == 1)
1457 rax = (long int)(int)rax; /* sign extend from 32 bits */
1458 if (rax != -ENOSYS && entering(tcp)) {
1460 fprintf(stderr, "not a syscall entry (rax = %ld)\n", rax);
1463 #elif defined (S390) || defined (S390X)
1464 if (upeek(tcp, PT_GPR2, &gpr2) < 0)
1466 if (syscall_mode != -ENOSYS)
1467 syscall_mode = tcp->scno;
1468 if (gpr2 != syscall_mode && entering(tcp)) {
1470 fprintf(stderr, "not a syscall entry (gpr2 = %ld)\n", gpr2);
1473 else if (((tcp->flags & (TCB_INSYSCALL|TCB_WAITEXECVE))
1474 == (TCB_INSYSCALL|TCB_WAITEXECVE))
1475 && (gpr2 == -ENOSYS || gpr2 == tcp->scno)) {
1477 * Fake a return value of zero. We leave the TCB_WAITEXECVE
1478 * flag set for the post-execve SIGTRAP to see and reset.
1482 #elif defined (POWERPC)
1483 # define SO_MASK 0x10000000
1484 if (upeek(tcp, sizeof(unsigned long)*PT_CCR, &flags) < 0)
1486 if (upeek(tcp, sizeof(unsigned long)*PT_R3, &result) < 0)
1488 if (flags & SO_MASK)
1490 #elif defined (M68K)
1491 if (upeek(tcp, 4*PT_D0, &d0) < 0)
1493 if (d0 != -ENOSYS && entering(tcp)) {
1495 fprintf(stderr, "not a syscall entry (d0 = %ld)\n", d0);
1503 if (upeek(tcp, PT_R0, &r0) < 0)
1505 #elif defined (HPPA)
1506 if (upeek(tcp, PT_GR28, &r28) < 0)
1509 if (upeek(tcp, PT_R10, &r10) < 0)
1511 if (upeek(tcp, PT_R8, &r8) < 0)
1513 if (ia32 && r8 != -ENOSYS && entering(tcp)) {
1515 fprintf(stderr, "not a syscall entry (r8 = %ld)\n", r8);
1518 #elif defined(CRISV10) || defined(CRISV32)
1519 if (upeek(tcp, 4*PT_R10, &r10) < 0)
1521 if (r10 != -ENOSYS && entering(tcp)) {
1523 fprintf(stderr, "not a syscall entry (r10 = %ld)\n", r10);
1526 #elif defined(MICROBLAZE)
1527 if (upeek(tcp, 3 * 4, &r3) < 0)
1529 if (r3 != -ENOSYS && entering(tcp)) {
1531 fprintf(stderr, "not a syscall entry (r3 = %ld)\n", r3);
1541 * Check the syscall return value register value for whether it is
1542 * a negated errno code indicating an error, or a success return value.
1545 is_negated_errno(unsigned long int val)
1547 unsigned long int max = -(long int) nerrnos;
1548 # if SUPPORTED_PERSONALITIES > 1
1549 if (personality_wordsize[current_personality] < sizeof(val)) {
1550 val = (unsigned int) val;
1551 max = (unsigned int) max;
1559 get_error(struct tcb *tcp)
1563 int check_errno = 1;
1564 if (tcp->scno >= 0 && tcp->scno < nsyscalls &&
1565 sysent[tcp->scno].sys_flags & SYSCALL_NEVER_FAILS) {
1568 # if defined(S390) || defined(S390X)
1569 if (check_errno && is_negated_errno(gpr2)) {
1577 # elif defined(I386)
1578 if (check_errno && is_negated_errno(eax)) {
1586 # elif defined(X86_64)
1587 if (check_errno && is_negated_errno(rax)) {
1595 # elif defined(IA64)
1600 if (check_errno && is_negated_errno(err)) {
1609 if (check_errno && r10) {
1617 # elif defined(MIPS)
1618 if (check_errno && a3) {
1625 # elif defined(POWERPC)
1626 if (check_errno && is_negated_errno(result)) {
1631 tcp->u_rval = result;
1634 # elif defined(M68K)
1635 if (check_errno && is_negated_errno(d0)) {
1644 if (check_errno && is_negated_errno(regs.ARM_r0)) {
1646 u_error = -regs.ARM_r0;
1649 tcp->u_rval = regs.ARM_r0;
1652 # elif defined(AVR32)
1653 if (check_errno && regs.r12 && (unsigned) -regs.r12 < nerrnos) {
1655 u_error = -regs.r12;
1658 tcp->u_rval = regs.r12;
1661 # elif defined(BFIN)
1662 if (check_errno && is_negated_errno(r0)) {
1669 # elif defined(ALPHA)
1670 if (check_errno && a3) {
1678 # elif defined(SPARC)
1679 if (check_errno && regs.psr & PSR_C) {
1681 u_error = regs.u_regs[U_REG_O0];
1684 tcp->u_rval = regs.u_regs[U_REG_O0];
1687 # elif defined(SPARC64)
1688 if (check_errno && regs.tstate & 0x1100000000UL) {
1690 u_error = regs.u_regs[U_REG_O0];
1693 tcp->u_rval = regs.u_regs[U_REG_O0];
1696 # elif defined(HPPA)
1697 if (check_errno && is_negated_errno(r28)) {
1706 /* interpret R0 as return value or error number */
1707 if (check_errno && is_negated_errno(r0)) {
1715 # elif defined(SH64)
1716 /* interpret result as return value or error number */
1717 if (check_errno && is_negated_errno(r9)) {
1725 # elif defined(CRISV10) || defined(CRISV32)
1726 if (check_errno && r10 && (unsigned) -r10 < nerrnos) {
1734 # elif defined(TILE)
1736 /* interpret result as return value or error number */
1737 if (upeek(tcp, PTREGS_OFFSET_REG(0), &rval) < 0)
1739 if (check_errno && rval < 0 && rval > -nerrnos) {
1747 # elif defined(MICROBLAZE)
1748 /* interpret result as return value or error number */
1749 if (check_errno && is_negated_errno(r3)) {
1760 /* get error code from user struct */
1761 if (upeek(tcp, uoff(u_error), &u_error) < 0)
1763 u_error >>= 24; /* u_error is a char */
1765 /* get system call return value */
1766 if (upeek(tcp, uoff(u_rval1), &tcp->u_rval) < 0)
1771 /* Judicious guessing goes a long way. */
1772 if (tcp->status.pr_reg[R_PSR] & 0x100000) {
1774 u_error = tcp->status.pr_reg[R_O0];
1777 tcp->u_rval = tcp->status.pr_reg[R_O0];
1782 /* Wanna know how to kill an hour single-stepping? */
1783 if (tcp->status.PR_REG[EFL] & 0x1) {
1785 u_error = tcp->status.PR_REG[EAX];
1788 tcp->u_rval = tcp->status.PR_REG[EAX];
1789 # ifdef HAVE_LONG_LONG
1791 ((unsigned long long) tcp->status.PR_REG[EDX] << 32) +
1792 tcp->status.PR_REG[EAX];
1798 /* Wanna know how to kill an hour single-stepping? */
1799 if (tcp->status.PR_REG[EFLAGS] & 0x1) {
1801 u_error = tcp->status.PR_REG[RAX];
1804 tcp->u_rval = tcp->status.PR_REG[RAX];
1807 # endif /* X86_64 */
1809 if (tcp->status.pr_reg[CTX_A3]) {
1811 u_error = tcp->status.pr_reg[CTX_V0];
1814 tcp->u_rval = tcp->status.pr_reg[CTX_V0];
1820 if (regs.r_eflags & PSL_C) {
1822 u_error = regs.r_eax;
1824 tcp->u_rval = regs.r_eax;
1826 ((unsigned long long) regs.r_edx << 32) + regs.r_eax;
1829 #endif /* FREEBSD */
1830 tcp->u_error = u_error;
1835 force_result(struct tcb *tcp, int error, long rval)
1838 # if defined(S390) || defined(S390X)
1839 gpr2 = error ? -error : rval;
1840 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)PT_GPR2, gpr2) < 0)
1842 # elif defined(I386)
1843 eax = error ? -error : rval;
1844 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(EAX * 4), eax) < 0)
1846 # elif defined(X86_64)
1847 rax = error ? -error : rval;
1848 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(RAX * 8), rax) < 0)
1850 # elif defined(IA64)
1852 r8 = error ? -error : rval;
1853 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_R8), r8) < 0)
1865 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_R8), r8) < 0 ||
1866 ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_R10), r10) < 0)
1869 # elif defined(BFIN)
1870 r0 = error ? -error : rval;
1871 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)PT_R0, r0) < 0)
1873 # elif defined(MIPS)
1882 /* PTRACE_POKEUSER is OK even for n32 since rval is only a long. */
1883 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_A3), a3) < 0 ||
1884 ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_V0), r2) < 0)
1886 # elif defined(POWERPC)
1887 if (upeek(tcp, sizeof(unsigned long)*PT_CCR, &flags) < 0)
1897 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(sizeof(unsigned long)*PT_CCR), flags) < 0 ||
1898 ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(sizeof(unsigned long)*PT_R3), result) < 0)
1900 # elif defined(M68K)
1901 d0 = error ? -error : rval;
1902 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*PT_D0), d0) < 0)
1905 regs.ARM_r0 = error ? -error : rval;
1906 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*0), regs.ARM_r0) < 0)
1908 # elif defined(AVR32)
1909 regs.r12 = error ? -error : rval;
1910 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)REG_R12, regs.r12) < 0)
1912 # elif defined(ALPHA)
1921 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_A3), a3) < 0 ||
1922 ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_R0), r0) < 0)
1924 # elif defined(SPARC)
1925 if (ptrace(PTRACE_GETREGS, tcp->pid, (char *)®s, 0) < 0)
1929 regs.u_regs[U_REG_O0] = error;
1933 regs.u_regs[U_REG_O0] = rval;
1935 if (ptrace(PTRACE_SETREGS, tcp->pid, (char *)®s, 0) < 0)
1937 # elif defined(SPARC64)
1938 if (ptrace(PTRACE_GETREGS, tcp->pid, (char *)®s, 0) < 0)
1941 regs.tstate |= 0x1100000000UL;
1942 regs.u_regs[U_REG_O0] = error;
1945 regs.tstate &= ~0x1100000000UL;
1946 regs.u_regs[U_REG_O0] = rval;
1948 if (ptrace(PTRACE_SETREGS, tcp->pid, (char *)®s, 0) < 0)
1950 # elif defined(HPPA)
1951 r28 = error ? -error : rval;
1952 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_GR28), r28) < 0)
1955 r0 = error ? -error : rval;
1956 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*REG_REG0), r0) < 0)
1958 # elif defined(SH64)
1959 r9 = error ? -error : rval;
1960 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)REG_GENERAL(9), r9) < 0)
1966 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)uoff(u_error),
1968 ptrace(PTRACE_POKEUSER, tcp->pid, (char*)uoff(u_rval1), rval) < 0)
1978 if (pread(tcp->pfd_reg, ®s, sizeof(regs), 0) < 0) {
1983 regs.r_eflags |= PSL_C;
1987 regs.r_eflags &= ~PSL_C;
1990 if (pwrite(tcp->pfd_reg, ®s, sizeof(regs), 0) < 0) {
1994 #endif /* FREEBSD */
1996 /* All branches reach here on success (only). */
1997 tcp->u_error = error;
2003 syscall_enter(struct tcb *tcp)
2006 # if defined(S390) || defined(S390X)
2008 if (tcp->scno >= 0 && tcp->scno < nsyscalls)
2009 tcp->u_nargs = sysent[tcp->scno].nargs;
2011 tcp->u_nargs = MAX_ARGS;
2012 for (i = 0; i < tcp->u_nargs; i++) {
2013 if (upeek(tcp, i==0 ? PT_ORIGGPR2 : PT_GPR2 + i*sizeof(long), &tcp->u_arg[i]) < 0)
2016 # elif defined(ALPHA)
2018 if (tcp->scno >= 0 && tcp->scno < nsyscalls)
2019 tcp->u_nargs = sysent[tcp->scno].nargs;
2021 tcp->u_nargs = MAX_ARGS;
2022 for (i = 0; i < tcp->u_nargs; i++) {
2023 /* WTA: if scno is out-of-bounds this will bomb. Add range-check
2024 * for scno somewhere above here!
2026 if (upeek(tcp, REG_A0+i, &tcp->u_arg[i]) < 0)
2029 # elif defined(IA64)
2031 unsigned long *out0, cfm, sof, sol, i;
2033 /* be backwards compatible with kernel < 2.4.4... */
2035 # define PT_RBS_END PT_AR_BSP
2038 if (upeek(tcp, PT_RBS_END, &rbs_end) < 0)
2040 if (upeek(tcp, PT_CFM, (long *) &cfm) < 0)
2043 sof = (cfm >> 0) & 0x7f;
2044 sol = (cfm >> 7) & 0x7f;
2045 out0 = ia64_rse_skip_regs((unsigned long *) rbs_end, -sof + sol);
2047 if (tcp->scno >= 0 && tcp->scno < nsyscalls)
2048 tcp->u_nargs = sysent[tcp->scno].nargs;
2050 tcp->u_nargs = MAX_ARGS;
2051 for (i = 0; i < tcp->u_nargs; ++i) {
2052 if (umoven(tcp, (unsigned long) ia64_rse_skip_regs(out0, i),
2053 sizeof(long), (char *) &tcp->u_arg[i]) < 0)
2059 if (/* EBX = out0 */
2060 upeek(tcp, PT_R11, (long *) &tcp->u_arg[0]) < 0
2062 || upeek(tcp, PT_R9, (long *) &tcp->u_arg[1]) < 0
2064 || upeek(tcp, PT_R10, (long *) &tcp->u_arg[2]) < 0
2066 || upeek(tcp, PT_R14, (long *) &tcp->u_arg[3]) < 0
2068 || upeek(tcp, PT_R15, (long *) &tcp->u_arg[4]) < 0
2070 || upeek(tcp, PT_R13, (long *) &tcp->u_arg[5]) < 0)
2073 for (i = 0; i < 6; ++i)
2074 /* truncate away IVE sign-extension */
2075 tcp->u_arg[i] &= 0xffffffff;
2077 if (tcp->scno >= 0 && tcp->scno < nsyscalls)
2078 tcp->u_nargs = sysent[tcp->scno].nargs;
2082 # elif defined(LINUX_MIPSN32) || defined(LINUX_MIPSN64)
2083 /* N32 and N64 both use up to six registers. */
2084 unsigned long long regs[38];
2086 if (tcp->scno >= 0 && tcp->scno < nsyscalls)
2087 nargs = tcp->u_nargs = sysent[tcp->scno].nargs;
2089 nargs = tcp->u_nargs = MAX_ARGS;
2091 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long) ®s) < 0)
2094 for (i = 0; i < nargs; i++) {
2095 tcp->u_arg[i] = regs[REG_A0 + i];
2096 # if defined(LINUX_MIPSN32)
2097 tcp->ext_arg[i] = regs[REG_A0 + i];
2100 # elif defined(MIPS)
2104 if (tcp->scno >= 0 && tcp->scno < nsyscalls)
2105 nargs = tcp->u_nargs = sysent[tcp->scno].nargs;
2107 nargs = tcp->u_nargs = MAX_ARGS;
2109 if (upeek(tcp, REG_SP, &sp) < 0)
2111 for (i = 0; i < 4; i++) {
2112 if (upeek(tcp, REG_A0 + i, &tcp->u_arg[i]) < 0)
2115 umoven(tcp, sp+16, (nargs-4) * sizeof(tcp->u_arg[0]),
2116 (char *)(tcp->u_arg + 4));
2118 for (i = 0; i < nargs; i++) {
2119 if (upeek(tcp, REG_A0 + i, &tcp->u_arg[i]) < 0)
2123 # elif defined(POWERPC)
2125 # define PT_ORIG_R3 34
2128 if (tcp->scno >= 0 && tcp->scno < nsyscalls)
2129 nargs = tcp->u_nargs = sysent[tcp->scno].nargs;
2131 nargs = tcp->u_nargs = MAX_ARGS;
2132 for (i = 0; i < nargs; i++) {
2133 if (upeek(tcp, (i==0) ?
2134 (sizeof(unsigned long) * PT_ORIG_R3) :
2135 ((i+PT_R3) * sizeof(unsigned long)),
2136 &tcp->u_arg[i]) < 0)
2139 # elif defined(SPARC) || defined(SPARC64)
2141 if (tcp->scno >= 0 && tcp->scno < nsyscalls)
2142 tcp->u_nargs = sysent[tcp->scno].nargs;
2144 tcp->u_nargs = MAX_ARGS;
2145 for (i = 0; i < tcp->u_nargs; i++)
2146 tcp->u_arg[i] = regs.u_regs[U_REG_O0 + i];
2147 # elif defined(HPPA)
2149 if (tcp->scno >= 0 && tcp->scno < nsyscalls)
2150 nargs = tcp->u_nargs = sysent[tcp->scno].nargs;
2152 nargs = tcp->u_nargs = MAX_ARGS;
2153 for (i = 0; i < nargs; i++) {
2154 if (upeek(tcp, PT_GR26-4*i, &tcp->u_arg[i]) < 0)
2159 if (tcp->scno >= 0 && tcp->scno < nsyscalls)
2160 tcp->u_nargs = sysent[tcp->scno].nargs;
2162 tcp->u_nargs = MAX_ARGS;
2163 for (i = 0; i < tcp->u_nargs; i++)
2164 tcp->u_arg[i] = regs.uregs[i];
2165 # elif defined(AVR32)
2166 tcp->u_nargs = sysent[tcp->scno].nargs;
2167 tcp->u_arg[0] = regs.r12;
2168 tcp->u_arg[1] = regs.r11;
2169 tcp->u_arg[2] = regs.r10;
2170 tcp->u_arg[3] = regs.r9;
2171 tcp->u_arg[4] = regs.r5;
2172 tcp->u_arg[5] = regs.r3;
2173 # elif defined(BFIN)
2175 static const int argreg[] = { PT_R0, PT_R1, PT_R2, PT_R3, PT_R4, PT_R5 };
2177 if (tcp->scno >= 0 && tcp->scno < nsyscalls)
2178 nargs = tcp->u_nargs = sysent[tcp->scno].nargs;
2180 nargs = tcp->u_nargs = ARRAY_SIZE(argreg);
2182 for (i = 0; i < nargs; ++i)
2183 if (upeek(tcp, argreg[i], &tcp->u_arg[i]) < 0)
2187 static const int syscall_regs[] = {
2188 4 * (REG_REG0+4), 4 * (REG_REG0+5), 4 * (REG_REG0+6), 4 * (REG_REG0+7),
2189 4 * (REG_REG0 ), 4 * (REG_REG0+1), 4 * (REG_REG0+2)
2192 nargs = tcp->u_nargs = sysent[tcp->scno].nargs;
2193 for (i = 0; i < nargs; i++) {
2194 if (upeek(tcp, syscall_regs[i], &tcp->u_arg[i]) < 0)
2197 # elif defined(SH64)
2199 /* Registers used by SH5 Linux system calls for parameters */
2200 static const int syscall_regs[] = { 2, 3, 4, 5, 6, 7 };
2203 * TODO: should also check that the number of arguments encoded
2204 * in the trap number matches the number strace expects.
2207 assert(sysent[tcp->scno].nargs < ARRAY_SIZE(syscall_regs));
2210 nargs = tcp->u_nargs = sysent[tcp->scno].nargs;
2211 for (i = 0; i < nargs; i++) {
2212 if (upeek(tcp, REG_GENERAL(syscall_regs[i]), &tcp->u_arg[i]) < 0)
2215 # elif defined(X86_64)
2217 static const int argreg[SUPPORTED_PERSONALITIES][MAX_ARGS] = {
2218 { 8 * RDI, 8 * RSI, 8 * RDX, 8 * R10, 8 * R8 , 8 * R9 }, /* x86-64 ABI */
2219 { 8 * RBX, 8 * RCX, 8 * RDX, 8 * RSI, 8 * RDI, 8 * RBP } /* i386 ABI */
2222 if (tcp->scno >= 0 && tcp->scno < nsyscalls)
2223 nargs = tcp->u_nargs = sysent[tcp->scno].nargs;
2225 nargs = tcp->u_nargs = MAX_ARGS;
2226 for (i = 0; i < nargs; i++) {
2227 if (upeek(tcp, argreg[current_personality][i], &tcp->u_arg[i]) < 0)
2230 # elif defined(MICROBLAZE)
2232 if (tcp->scno >= 0 && tcp->scno < nsyscalls)
2233 nargs = tcp->u_nargs = sysent[tcp->scno].nargs;
2235 nargs = tcp->u_nargs = 0;
2236 for (i = 0; i < nargs; i++) {
2237 if (upeek(tcp, (5 + i) * 4, &tcp->u_arg[i]) < 0)
2240 # elif defined(CRISV10) || defined(CRISV32)
2242 static const int crisregs[] = {
2243 4*PT_ORIG_R10, 4*PT_R11, 4*PT_R12,
2244 4*PT_R13 , 4*PT_MOF, 4*PT_SRP
2247 if (tcp->scno >= 0 && tcp->scno < nsyscalls)
2248 nargs = tcp->u_nargs = sysent[tcp->scno].nargs;
2250 nargs = tcp->u_nargs = 0;
2251 for (i = 0; i < nargs; i++) {
2252 if (upeek(tcp, crisregs[i], &tcp->u_arg[i]) < 0)
2255 # elif defined(TILE)
2257 if (tcp->scno >= 0 && tcp->scno < nsyscalls)
2258 nargs = tcp->u_nargs = sysent[tcp->scno].nargs;
2260 nargs = tcp->u_nargs = MAX_ARGS;
2261 for (i = 0; i < nargs; ++i) {
2262 if (upeek(tcp, PTREGS_OFFSET_REG(i), &tcp->u_arg[i]) < 0)
2265 # elif defined(M68K)
2267 if (tcp->scno >= 0 && tcp->scno < nsyscalls)
2268 nargs = tcp->u_nargs = sysent[tcp->scno].nargs;
2270 nargs = tcp->u_nargs = MAX_ARGS;
2271 for (i = 0; i < nargs; i++) {
2272 if (upeek(tcp, (i < 5 ? i : i + 2)*4, &tcp->u_arg[i]) < 0)
2275 # else /* Other architecture (like i386) (32bits specific) */
2277 if (tcp->scno >= 0 && tcp->scno < nsyscalls)
2278 nargs = tcp->u_nargs = sysent[tcp->scno].nargs;
2280 nargs = tcp->u_nargs = MAX_ARGS;
2281 for (i = 0; i < nargs; i++) {
2282 if (upeek(tcp, i*4, &tcp->u_arg[i]) < 0)
2289 if (tcp->scno >= 0 && tcp->scno < nsyscalls)
2290 nargs = tcp->u_nargs = sysent[tcp->scno].nargs;
2292 nargs = tcp->u_nargs = MAX_ARGS;
2293 for (i = 0; i < nargs; i++) {
2296 if (upeek(tcp, uoff(u_arg[0]) +
2297 (i * sizeof(u->u_arg[0])), &tcp->u_arg[i]) < 0)
2304 * SGI is broken: even though it has pr_sysarg, it doesn't
2305 * set them on system call entry. Get a clue.
2307 if (tcp->scno >= 0 && tcp->scno < nsyscalls)
2308 tcp->u_nargs = sysent[tcp->scno].nargs;
2310 tcp->u_nargs = tcp->status.pr_nsysarg;
2311 if (tcp->u_nargs > 4) {
2312 memcpy(tcp->u_arg, &tcp->status.pr_reg[CTX_A0],
2313 4 * sizeof(tcp->u_arg[0]));
2314 umoven(tcp, tcp->status.pr_reg[CTX_SP] + 16,
2315 (tcp->u_nargs - 4) * sizeof(tcp->u_arg[0]), (char *) (tcp->u_arg + 4));
2318 memcpy(tcp->u_arg, &tcp->status.pr_reg[CTX_A0],
2319 tcp->u_nargs * sizeof(tcp->u_arg[0]));
2321 # elif UNIXWARE >= 2
2323 * Like SGI, UnixWare doesn't set pr_sysarg until system call exit
2325 if (tcp->scno >= 0 && tcp->scno < nsyscalls)
2326 tcp->u_nargs = sysent[tcp->scno].nargs;
2328 tcp->u_nargs = tcp->status.pr_lwp.pr_nsysarg;
2329 umoven(tcp, tcp->status.PR_REG[UESP] + 4,
2330 tcp->u_nargs * sizeof(tcp->u_arg[0]), (char *) tcp->u_arg);
2331 # elif defined(HAVE_PR_SYSCALL)
2333 if (tcp->scno >= 0 && tcp->scno < nsyscalls)
2334 tcp->u_nargs = sysent[tcp->scno].nargs;
2336 tcp->u_nargs = tcp->status.pr_nsysarg;
2337 for (i = 0; i < tcp->u_nargs; i++)
2338 tcp->u_arg[i] = tcp->status.pr_sysarg[i];
2339 # elif defined(I386)
2340 if (tcp->scno >= 0 && tcp->scno < nsyscalls)
2341 tcp->u_nargs = sysent[tcp->scno].nargs;
2344 if (tcp->u_nargs > 0)
2345 umoven(tcp, tcp->status.PR_REG[UESP] + 4,
2346 tcp->u_nargs * sizeof(tcp->u_arg[0]), (char *) tcp->u_arg);
2348 I DONT KNOW WHAT TO DO
2352 if (tcp->scno >= 0 && tcp->scno < nsyscalls &&
2353 sysent[tcp->scno].nargs > tcp->status.val)
2354 tcp->u_nargs = sysent[tcp->scno].nargs;
2356 tcp->u_nargs = tcp->status.val;
2357 if (tcp->u_nargs < 0)
2359 if (tcp->u_nargs > MAX_ARGS)
2360 tcp->u_nargs = MAX_ARGS;
2361 switch (regs.r_eax) {
2363 pread(tcp->pfd, &tcp->u_arg, tcp->u_nargs * sizeof(unsigned long),
2364 regs.r_esp + sizeof(int) + sizeof(quad_t));
2367 pread(tcp->pfd, &tcp->u_arg, tcp->u_nargs * sizeof(unsigned long),
2368 regs.r_esp + 2 * sizeof(int));
2371 pread(tcp->pfd, &tcp->u_arg, tcp->u_nargs * sizeof(unsigned long),
2372 regs.r_esp + sizeof(int));
2375 #endif /* FREEBSD */
2380 trace_syscall_entering(struct tcb *tcp)
2384 scno_good = res = get_scno(tcp);
2388 res = syscall_fixup(tcp);
2392 res = syscall_enter(tcp);
2398 tcp->flags &= ~TCB_REPRINT;
2401 tprintf("????" /* anti-trigraph gap */ "(");
2402 else if (tcp->scno >= nsyscalls || tcp->scno < 0)
2403 tprintf("syscall_%lu(", tcp->scno);
2405 tprintf("%s(", sysent[tcp->scno].sys_name);
2407 * " <unavailable>" will be added later by the code which
2408 * detects ptrace errors.
2413 switch (known_scno(tcp)) {
2414 #ifdef SYS_socket_subcall
2415 case SYS_socketcall:
2416 decode_subcall(tcp, SYS_socket_subcall,
2417 SYS_socket_nsubcalls, deref_style);
2420 #ifdef SYS_ipc_subcall
2422 decode_subcall(tcp, SYS_ipc_subcall,
2423 SYS_ipc_nsubcalls, shift_style);
2427 #ifdef SYS_pgrpsys_subcall
2429 decode_subcall(tcp, SYS_pgrpsys_subcall,
2430 SYS_pgrpsys_nsubcalls, shift_style);
2432 #endif /* SYS_pgrpsys_subcall */
2433 #ifdef SYS_sigcall_subcall
2435 decode_subcall(tcp, SYS_sigcall_subcall,
2436 SYS_sigcall_nsubcalls, mask_style);
2438 #endif /* SYS_sigcall_subcall */
2440 decode_subcall(tcp, SYS_msgsys_subcall,
2441 SYS_msgsys_nsubcalls, shift_style);
2444 decode_subcall(tcp, SYS_shmsys_subcall,
2445 SYS_shmsys_nsubcalls, shift_style);
2448 decode_subcall(tcp, SYS_semsys_subcall,
2449 SYS_semsys_nsubcalls, shift_style);
2452 decode_subcall(tcp, SYS_sysfs_subcall,
2453 SYS_sysfs_nsubcalls, shift_style);
2456 decode_subcall(tcp, SYS_spcall_subcall,
2457 SYS_spcall_nsubcalls, shift_style);
2459 #ifdef SYS_context_subcall
2461 decode_subcall(tcp, SYS_context_subcall,
2462 SYS_context_nsubcalls, shift_style);
2464 #endif /* SYS_context_subcall */
2465 #ifdef SYS_door_subcall
2467 decode_subcall(tcp, SYS_door_subcall,
2468 SYS_door_nsubcalls, door_style);
2470 #endif /* SYS_door_subcall */
2471 #ifdef SYS_kaio_subcall
2473 decode_subcall(tcp, SYS_kaio_subcall,
2474 SYS_kaio_nsubcalls, shift_style);
2482 decode_subcall(tcp, 0, 0, table_style);
2487 decode_subcall(tcp, SYS_semsys_subcall,
2488 SYS_semsys_nsubcalls, shift_style);
2491 decode_subcall(tcp, SYS_msgsys_subcall,
2492 SYS_msgsys_nsubcalls, shift_style);
2495 decode_subcall(tcp, SYS_shmsys_subcall,
2496 SYS_shmsys_nsubcalls, shift_style);
2501 internal_syscall(tcp);
2503 if ((tcp->scno >= 0 && tcp->scno < nsyscalls &&
2504 !(qual_flags[tcp->scno] & QUAL_TRACE)) ||
2505 (tracing_paths && !pathtrace_match(tcp))) {
2506 tcp->flags |= TCB_INSYSCALL | TCB_FILTERED;
2510 tcp->flags &= ~TCB_FILTERED;
2512 if (cflag == CFLAG_ONLY_STATS) {
2518 tcp->flags &= ~TCB_REPRINT;
2520 if (tcp->scno >= nsyscalls || tcp->scno < 0)
2521 tprintf("syscall_%lu(", tcp->scno);
2523 tprintf("%s(", sysent[tcp->scno].sys_name);
2524 if (tcp->scno >= nsyscalls || tcp->scno < 0 ||
2525 ((qual_flags[tcp->scno] & QUAL_RAW) &&
2526 sysent[tcp->scno].sys_func != sys_exit))
2527 res = printargs(tcp);
2529 res = (*sysent[tcp->scno].sys_func)(tcp);
2531 if (fflush(tcp->outf) == EOF)
2534 tcp->flags |= TCB_INSYSCALL;
2535 /* Measure the entrance time as late as possible to avoid errors. */
2537 gettimeofday(&tcp->etime, NULL);
2542 trace_syscall_exiting(struct tcb *tcp)
2549 /* Measure the exit time as early as possible to avoid errors. */
2551 gettimeofday(&tv, NULL);
2553 /* BTW, why we don't just memorize syscall no. on entry
2554 * in tcp->something?
2556 scno_good = res = get_scno(tcp);
2560 res = syscall_fixup(tcp);
2564 res = get_error(tcp);
2568 internal_syscall(tcp);
2570 if (res == 1 && filtered(tcp)) {
2574 if (tcp->flags & TCB_REPRINT) {
2579 else if (tcp->scno >= nsyscalls || tcp->scno < 0)
2580 tprintf("syscall_%lu", tcp->scno);
2582 tprintf("%s", sysent[tcp->scno].sys_name);
2583 tprintf(" resumed> ");
2587 struct timeval t = tv;
2588 count_syscall(tcp, &t);
2589 if (cflag == CFLAG_ONLY_STATS) {
2597 tprintf("= ? <unavailable>");
2599 tcp->flags &= ~TCB_INSYSCALL;
2603 if (tcp->scno >= nsyscalls || tcp->scno < 0
2604 || (qual_flags[tcp->scno] & QUAL_RAW))
2605 sys_res = printargs(tcp);
2607 /* FIXME: not_failing_only (IOW, option -z) is broken:
2608 * failure of syscall is known only after syscall return.
2609 * Thus we end up with something like this on, say, ENOENT:
2610 * open("doesnt_exist", O_RDONLY <unfinished ...>
2611 * {next syscall decode}
2612 * whereas the intended result is that open(...) line
2613 * is not shown at all.
2615 if (not_failing_only && tcp->u_error)
2616 goto ret; /* ignore failed syscalls */
2617 sys_res = (*sysent[tcp->scno].sys_func)(tcp);
2622 u_error = tcp->u_error;
2623 if (tcp->scno >= nsyscalls || tcp->scno < 0 ||
2624 qual_flags[tcp->scno] & QUAL_RAW) {
2626 tprintf("= -1 (errno %ld)", u_error);
2628 tprintf("= %#lx", tcp->u_rval);
2630 else if (!(sys_res & RVAL_NONE) && u_error) {
2634 tprintf("= ? ERESTARTSYS (To be restarted)");
2636 case ERESTARTNOINTR:
2637 tprintf("= ? ERESTARTNOINTR (To be restarted)");
2639 case ERESTARTNOHAND:
2640 tprintf("= ? ERESTARTNOHAND (To be restarted)");
2642 case ERESTART_RESTARTBLOCK:
2643 tprintf("= ? ERESTART_RESTARTBLOCK (To be restarted)");
2648 tprintf("= -1 E??? (errno %ld)", u_error);
2649 else if (u_error < nerrnos)
2650 tprintf("= -1 %s (%s)", errnoent[u_error],
2653 tprintf("= -1 ERRNO_%ld (%s)", u_error,
2657 if ((sys_res & RVAL_STR) && tcp->auxstr)
2658 tprintf(" (%s)", tcp->auxstr);
2661 if (sys_res & RVAL_NONE)
2664 switch (sys_res & RVAL_MASK) {
2666 tprintf("= %#lx", tcp->u_rval);
2669 tprintf("= %#lo", tcp->u_rval);
2672 tprintf("= %lu", tcp->u_rval);
2675 tprintf("= %ld", tcp->u_rval);
2677 #ifdef HAVE_LONG_LONG
2679 tprintf("= %#llx", tcp->u_lrval);
2682 tprintf("= %#llo", tcp->u_lrval);
2684 case RVAL_LUDECIMAL:
2685 tprintf("= %llu", tcp->u_lrval);
2688 tprintf("= %lld", tcp->u_lrval);
2693 "invalid rval format\n");
2697 if ((sys_res & RVAL_STR) && tcp->auxstr)
2698 tprintf(" (%s)", tcp->auxstr);
2701 tv_sub(&tv, &tv, &tcp->etime);
2702 tprintf(" <%ld.%06ld>",
2703 (long) tv.tv_sec, (long) tv.tv_usec);
2708 if (fflush(tcp->outf) == EOF)
2711 tcp->flags &= ~TCB_INSYSCALL;
2716 trace_syscall(struct tcb *tcp)
2718 return exiting(tcp) ?
2719 trace_syscall_exiting(tcp) : trace_syscall_entering(tcp);
2723 printargs(struct tcb *tcp)
2725 if (entering(tcp)) {
2728 for (i = 0; i < tcp->u_nargs; i++)
2729 tprintf("%s%#lx", i ? ", " : "", tcp->u_arg[i]);
2735 getrval2(struct tcb *tcp)
2740 #if defined (SPARC) || defined (SPARC64)
2741 struct pt_regs regs;
2742 if (ptrace(PTRACE_GETREGS, tcp->pid, (char *)®s, 0) < 0)
2744 val = regs.u_regs[U_REG_O1];
2746 if (upeek(tcp, 4*(REG_REG0+1), &val) < 0)
2749 if (upeek(tcp, PT_R9, &val) < 0)
2755 if (upeek(tcp, uoff(u_rval2), &val) < 0)
2761 val = tcp->status.PR_REG[R_O1];
2764 val = tcp->status.PR_REG[EDX];
2767 val = tcp->status.PR_REG[RDX];
2770 val = tcp->status.PR_REG[CTX_V1];
2776 pread(tcp->pfd_reg, ®s, sizeof(regs), 0);
2784 * Apparently, indirect system calls have already be converted by ptrace(2),
2785 * so if you see "indir" this program has gone astray.
2788 sys_indir(struct tcb *tcp)
2792 if (entering(tcp)) {
2793 scno = tcp->u_arg[0];
2794 if (scno > nsyscalls) {
2795 fprintf(stderr, "Bogus syscall: %u\n", scno);
2798 nargs = sysent[scno].nargs;
2799 tprintf("%s", sysent[scno].sys_name);
2800 for (i = 0; i < nargs; i++)
2801 tprintf(", %#lx", tcp->u_arg[i+1]);
2808 is_restart_error(struct tcb *tcp)
2813 switch (tcp->u_error) {
2815 case ERESTARTNOINTR:
2816 case ERESTARTNOHAND:
2817 case ERESTART_RESTARTBLOCK: