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 # define fpq kernel_fpq
49 # define fpu kernel_fpu
61 #ifndef PTRACE_PEEKUSR
62 # define PTRACE_PEEKUSR PTRACE_PEEKUSER
64 #elif defined(HAVE_LINUX_PTRACE_H)
66 #include <linux/ptrace.h>
69 #if defined(LINUX) && defined(IA64)
70 # include <asm/ptrace_offsets.h>
74 #ifndef SYS_ERRLIST_DECLARED
76 extern char *sys_errlist[];
77 #endif /* SYS_ERRLIST_DECLARED */
79 #define NR_SYSCALL_BASE 0
82 #define ERESTARTSYS 512
84 #ifndef ERESTARTNOINTR
85 #define ERESTARTNOINTR 513
87 #ifndef ERESTARTNOHAND
88 #define ERESTARTNOHAND 514 /* restart if no handler.. */
91 #define ENOIOCTLCMD 515 /* No ioctl command */
99 #undef NR_SYSCALL_BASE
100 #define NR_SYSCALL_BASE __NR_SYSCALL_BASE
106 /* Define these shorthand notations to simplify the syscallent files. */
107 #define TF TRACE_FILE
109 #define TN TRACE_NETWORK
110 #define TP TRACE_PROCESS
111 #define TS TRACE_SIGNAL
113 struct sysent sysent0[] = {
114 #include "syscallent.h"
116 int nsyscalls0 = sizeof sysent0 / sizeof sysent0[0];
118 #if SUPPORTED_PERSONALITIES >= 2
119 struct sysent sysent1[] = {
120 #include "syscallent1.h"
122 int nsyscalls1 = sizeof sysent1 / sizeof sysent1[0];
123 #endif /* SUPPORTED_PERSONALITIES >= 2 */
125 #if SUPPORTED_PERSONALITIES >= 3
126 struct sysent sysent2[] = {
127 #include "syscallent2.h"
129 int nsyscalls2 = sizeof sysent2 / sizeof sysent2[0];
130 #endif /* SUPPORTED_PERSONALITIES >= 3 */
132 struct sysent *sysent;
135 /* Now undef them since short defines cause wicked namespace pollution. */
142 char *errnoent0[] = {
143 #include "errnoent.h"
145 int nerrnos0 = sizeof errnoent0 / sizeof errnoent0[0];
147 #if SUPPORTED_PERSONALITIES >= 2
148 char *errnoent1[] = {
149 #include "errnoent1.h"
151 int nerrnos1 = sizeof errnoent1 / sizeof errnoent1[0];
152 #endif /* SUPPORTED_PERSONALITIES >= 2 */
154 #if SUPPORTED_PERSONALITIES >= 3
155 char *errnoent2[] = {
156 #include "errnoent2.h"
158 int nerrnos2 = sizeof errnoent2 / sizeof errnoent2[0];
159 #endif /* SUPPORTED_PERSONALITIES >= 3 */
164 int current_personality;
167 set_personality(personality)
170 switch (personality) {
172 errnoent = errnoent0;
175 nsyscalls = nsyscalls0;
176 ioctlent = ioctlent0;
177 nioctlents = nioctlents0;
178 signalent = signalent0;
179 nsignals = nsignals0;
182 #if SUPPORTED_PERSONALITIES >= 2
184 errnoent = errnoent1;
187 nsyscalls = nsyscalls1;
188 ioctlent = ioctlent1;
189 nioctlents = nioctlents1;
190 signalent = signalent1;
191 nsignals = nsignals1;
193 #endif /* SUPPORTED_PERSONALITIES >= 2 */
195 #if SUPPORTED_PERSONALITIES >= 3
197 errnoent = errnoent2;
200 nsyscalls = nsyscalls2;
201 ioctlent = ioctlent2;
202 nioctlents = nioctlents2;
203 signalent = signalent2;
204 nsignals = nsignals2;
206 #endif /* SUPPORTED_PERSONALITIES >= 3 */
212 current_personality = personality;
216 int qual_flags[MAX_QUALS];
218 static int call_count[MAX_QUALS];
219 static int error_count[MAX_QUALS];
220 static struct timeval tv_count[MAX_QUALS];
221 static int sorted_count[MAX_QUALS];
223 static struct timeval shortest = { 1000000, 0 };
225 static int lookup_syscall(), lookup_signal(), lookup_fault(), lookup_desc();
227 static struct qual_options {
233 { QUAL_TRACE, "trace", lookup_syscall, "system call" },
234 { QUAL_TRACE, "t", lookup_syscall, "system call" },
235 { QUAL_ABBREV, "abbrev", lookup_syscall, "system call" },
236 { QUAL_ABBREV, "a", lookup_syscall, "system call" },
237 { QUAL_VERBOSE, "verbose", lookup_syscall, "system call" },
238 { QUAL_VERBOSE, "v", lookup_syscall, "system call" },
239 { QUAL_RAW, "raw", lookup_syscall, "system call" },
240 { QUAL_RAW, "x", lookup_syscall, "system call" },
241 { QUAL_SIGNAL, "signal", lookup_signal, "signal" },
242 { QUAL_SIGNAL, "signals", lookup_signal, "signal" },
243 { QUAL_SIGNAL, "s", lookup_signal, "signal" },
244 { QUAL_FAULT, "fault", lookup_fault, "fault" },
245 { QUAL_FAULT, "faults", lookup_fault, "fault" },
246 { QUAL_FAULT, "m", lookup_fault, "fault" },
247 { QUAL_READ, "read", lookup_desc, "descriptor" },
248 { QUAL_READ, "reads", lookup_desc, "descriptor" },
249 { QUAL_READ, "r", lookup_desc, "descriptor" },
250 { QUAL_WRITE, "write", lookup_desc, "descriptor" },
251 { QUAL_WRITE, "writes", lookup_desc, "descriptor" },
252 { QUAL_WRITE, "w", lookup_desc, "descriptor" },
253 { 0, NULL, NULL, NULL },
262 for (i = 0; i < nsyscalls; i++) {
263 if (strcmp(s, sysent[i].sys_name) == 0)
276 if (s && *s && isdigit((unsigned char)*s))
280 for (i = 0; s[i]; i++)
281 s[i] = toupper((unsigned char)(s[i]));
282 if (strncmp(s, "SIG", 3) == 0)
284 for (i = 0; i <= NSIG; i++) {
285 if (strcmp(s, signame(i) + 3) == 0)
302 if (s && *s && isdigit((unsigned char)*s))
311 if (strcmp(s, "file") == 0)
313 if (strcmp(s, "ipc") == 0)
315 if (strcmp(s, "network") == 0)
316 return TRACE_NETWORK;
317 if (strcmp(s, "process") == 0)
318 return TRACE_PROCESS;
319 if (strcmp(s, "signal") == 0)
328 struct qual_options *opt;
333 opt = &qual_options[0];
334 for (i = 0; (p = qual_options[i].option_name); i++) {
336 if (strncmp(s, p, n) == 0 && s[n] == '=') {
337 opt = &qual_options[i];
347 if (strcmp(s, "none") == 0) {
351 if (strcmp(s, "all") == 0) {
352 for (i = 0; i < MAX_QUALS; i++) {
354 qual_flags[i] &= ~opt->bitflag;
356 qual_flags[i] |= opt->bitflag;
360 for (i = 0; i < MAX_QUALS; i++) {
362 qual_flags[i] |= opt->bitflag;
364 qual_flags[i] &= ~opt->bitflag;
366 for (p = strtok(s, ","); p; p = strtok(NULL, ",")) {
367 if (opt->bitflag == QUAL_TRACE && (n = lookup_class(p)) > 0) {
368 for (i = 0; i < MAX_QUALS; i++) {
369 if (sysent[i].sys_flags & n) {
371 qual_flags[i] &= ~opt->bitflag;
373 qual_flags[i] |= opt->bitflag;
378 if ((n = (*opt->lookup)(p)) < 0) {
379 fprintf(stderr, "strace: invalid %s `%s'\n",
380 opt->argument_name, p);
384 qual_flags[n] &= ~opt->bitflag;
386 qual_flags[n] |= opt->bitflag;
397 if (tcp->u_arg[0] < 0 || tcp->u_arg[0] >= MAX_QUALS)
399 switch (tcp->scno + NR_SYSCALL_BASE) {
407 if (qual_flags[tcp->u_arg[0]] & QUAL_READ)
408 dumpstr(tcp, tcp->u_arg[1], tcp->u_rval);
417 if (qual_flags[tcp->u_arg[0]] & QUAL_WRITE)
418 dumpstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
422 if (qual_flags[tcp->u_arg[0]] & QUAL_READ)
423 dumpiov(tcp, tcp->u_arg[2], tcp->u_arg[1]);
429 if (qual_flags[tcp->u_arg[0]] & QUAL_WRITE)
430 dumpiov(tcp, tcp->u_arg[2], tcp->u_arg[1]);
437 enum subcall_style { shift_style, deref_style, mask_style, door_style };
439 enum subcall_style { shift_style, deref_style, mask_style, door_style, table_style };
447 const struct subcall subcalls_table[] = {
448 { SYS_shmsys, 5, { SYS_shmat, SYS_shmctl, SYS_shmdt, SYS_shmget, SYS_shmctl } },
450 { SYS_semsys, 4, { SYS___semctl, SYS_semget, SYS_semop, SYS_semconfig } },
452 { SYS_semsys, 3, { SYS___semctl, SYS_semget, SYS_semop } },
454 { SYS_msgsys, 4, { SYS_msgctl, SYS_msgget, SYS_msgsnd, SYS_msgrcv } },
458 #if !(defined(LINUX) && ( defined(ALPHA) || defined(MIPS) ))
460 const int socket_map [] = {
463 /* SYS_CONNECT */ 98,
464 /* SYS_LISTEN */ 106,
466 /* SYS_GETSOCKNAME */ 150,
467 /* SYS_GETPEERNAME */ 141,
468 /* SYS_SOCKETPAIR */ 135,
471 /* SYS_SENDTO */ 133,
472 /* SYS_RECVFROM */ 125,
473 /* SYS_SHUTDOWN */ 134,
474 /* SYS_SETSOCKOPT */ 105,
475 /* SYS_GETSOCKOPT */ 118,
476 /* SYS_SENDMSG */ 114,
477 /* SYS_RECVMSG */ 113
481 sparc_socket_decode (tcp)
487 if (tcp->u_arg [0] < 1 || tcp->u_arg [0] > sizeof(socket_map)/sizeof(int)+1){
490 tcp->scno = socket_map [tcp->u_arg [0]-1];
491 n = tcp->u_nargs = sysent [tcp->scno].nargs;
492 addr = tcp->u_arg [1];
493 for (i = 0; i < n; i++){
495 if (umoven (tcp, addr, sizeof (arg), (void *) &arg) < 0)
497 tcp->u_arg [i] = arg;
498 addr += sizeof (arg);
503 decode_subcall(tcp, subcall, nsubcalls, style)
507 enum subcall_style style;
509 int i, addr, mask, arg;
513 if (tcp->u_arg[0] < 0 || tcp->u_arg[0] >= nsubcalls)
515 tcp->scno = subcall + tcp->u_arg[0];
516 if (sysent[tcp->scno].nargs != -1)
517 tcp->u_nargs = sysent[tcp->scno].nargs;
520 for (i = 0; i < tcp->u_nargs; i++)
521 tcp->u_arg[i] = tcp->u_arg[i + 1];
524 if (tcp->u_arg[0] < 0 || tcp->u_arg[0] >= nsubcalls)
526 tcp->scno = subcall + tcp->u_arg[0];
527 addr = tcp->u_arg[1];
528 for (i = 0; i < sysent[tcp->scno].nargs; i++) {
529 if (umove(tcp, addr, &arg) < 0)
534 tcp->u_nargs = sysent[tcp->scno].nargs;
537 mask = (tcp->u_arg[0] >> 8) & 0xff;
538 for (i = 0; mask; i++)
542 tcp->u_arg[0] &= 0xff;
543 tcp->scno = subcall + i;
544 if (sysent[tcp->scno].nargs != -1)
545 tcp->u_nargs = sysent[tcp->scno].nargs;
549 * Oh, yuck. The call code is the *sixth* argument.
550 * (don't you mean the *last* argument? - JH)
552 if (tcp->u_arg[5] < 0 || tcp->u_arg[5] >= nsubcalls)
554 tcp->scno = subcall + tcp->u_arg[5];
555 if (sysent[tcp->scno].nargs != -1)
556 tcp->u_nargs = sysent[tcp->scno].nargs;
562 for (i = 0; i < sizeof(subcalls_table) / sizeof(struct subcall); i++)
563 if (subcalls_table[i].call == tcp->scno) break;
564 if (i < sizeof(subcalls_table) / sizeof(struct subcall) &&
565 tcp->u_arg[0] >= 0 && tcp->u_arg[0] < subcalls_table[i].nsubcalls) {
566 tcp->scno = subcalls_table[i].subcalls[tcp->u_arg[0]];
567 for (i = 0; i < tcp->u_nargs; i++)
568 tcp->u_arg[i] = tcp->u_arg[i + 1];
576 struct tcb *tcp_last = NULL;
579 internal_syscall(tcp)
583 * We must always trace a few critical system calls in order to
584 * correctly support following forks in the presence of tracing
587 switch (tcp->scno + NR_SYSCALL_BASE) {
667 #elif defined (POWERPC)
668 static long result,flags;
673 #elif defined (ALPHA)
676 #elif defined (SPARC)
677 static struct regs regs;
678 static unsigned long trap;
707 if (upeek(tcp->pid,PT_PSWADDR,&pc) < 0)
709 scno = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)(pc-4),0);
713 #elif defined (POWERPC)
714 if (upeek(pid, 4*PT_R0, &scno) < 0)
716 if (!(tcp->flags & TCB_INSYSCALL)) {
717 /* Check if we return from execve. */
718 if (scno == 0 && (tcp->flags & TCB_WAITEXECVE)) {
719 tcp->flags &= ~TCB_WAITEXECVE;
724 if (upeek(pid, 4*ORIG_EAX, &scno) < 0)
727 # define IA64_PSR_IS ((long)1 << 34)
728 if (upeek (pid, PT_CR_IPSR, &psr) >= 0)
729 ia32 = (psr & IA64_PSR_IS) != 0;
730 if (!(tcp->flags & TCB_INSYSCALL)) {
732 if (upeek(pid, PT_R1, &scno) < 0) /* orig eax */
734 /* Check if we return from execve. */
736 if (upeek (pid, PT_R15, &scno) < 0)
740 /* syscall in progress */
741 if (upeek (pid, PT_R8, &r8) < 0)
743 if (upeek (pid, PT_R10, &r10) < 0)
746 if (tcp->flags & TCB_WAITEXECVE) {
747 tcp->flags &= ~TCB_WAITEXECVE;
754 upeek(pid, 4*15, &pc);
755 umoven(tcp, pc-4, 4, (char *)&scno);
759 if (upeek(pid, 4*PT_ORIG_D0, &scno) < 0)
762 if (upeek(pid, REG_A3, &a3) < 0)
765 if(!(tcp->flags & TCB_INSYSCALL)) {
766 if (upeek(pid, REG_V0, &scno) < 0)
769 if (scno < 0 || scno > nsyscalls) {
770 if(a3 == 0 || a3 == -1) {
772 fprintf (stderr, "stray syscall exit: v0 = %ld\n", scno);
777 if (upeek(pid, REG_V0, &r2) < 0)
780 #elif defined (ALPHA)
781 if (upeek(pid, REG_A3, &a3) < 0)
784 if (!(tcp->flags & TCB_INSYSCALL)) {
785 if (upeek(pid, REG_R0, &scno) < 0)
788 /* Check if we return from execve. */
789 if (scno == 0 && tcp->flags & TCB_WAITEXECVE) {
790 tcp->flags &= ~TCB_WAITEXECVE;
795 * Do some sanity checks to figure out if it's
796 * really a syscall entry
798 if (scno < 0 || scno > nsyscalls) {
799 if (a3 == 0 || a3 == -1) {
801 fprintf (stderr, "stray syscall exit: r0 = %ld\n", scno);
807 if (upeek(pid, REG_R0, &r0) < 0)
810 #elif defined (SPARC)
811 /* Everything we need is in the current register set. */
812 if (ptrace(PTRACE_GETREGS,pid,(char *)®s,0) < 0)
815 /* If we are entering, then disassemble the syscall trap. */
816 if (!(tcp->flags & TCB_INSYSCALL)) {
817 /* Retrieve the syscall trap instruction. */
819 trap = ptrace(PTRACE_PEEKTEXT,pid,(char *)regs.r_pc,0);
823 /* Disassemble the trap to see what personality to use. */
826 /* Linux/SPARC syscall trap. */
830 /* Linux/SPARC64 syscall trap. */
831 fprintf(stderr,"syscall: Linux/SPARC64 not supported yet\n");
834 /* SunOS syscall trap. (pers 1) */
835 fprintf(stderr,"syscall: SunOS no support\n");
838 /* Solaris 2.x syscall trap. (per 2) */
842 /* NetBSD/FreeBSD syscall trap. */
843 fprintf(stderr,"syscall: NetBSD/FreeBSD not supported\n");
846 /* Solaris 2.x gettimeofday */
850 /* Unknown syscall trap. */
851 if(tcp->flags & TCB_WAITEXECVE) {
852 tcp->flags &= ~TCB_WAITEXECVE;
855 fprintf(stderr,"syscall: unknown syscall trap %08x %08x\n", trap, regs.r_pc);
859 /* Extract the system call number from the registers. */
860 if (trap == 0x91d02027)
866 memmove (®s.r_o0, ®s.r_o1, 7*sizeof(regs.r_o0));
870 if (upeek(pid, PT_GR20, &scno) < 0)
872 if (!(tcp->flags & TCB_INSYSCALL)) {
873 /* Check if we return from execve. */
874 if ((tcp->flags & TCB_WAITEXECVE)) {
875 tcp->flags &= ~TCB_WAITEXECVE;
881 * In the new syscall ABI, the system call number is in R3.
883 if (upeek(pid, 4*(REG_REG0+3), &scno) < 0)
887 /* Odd as it may seem, a glibc bug has been known to cause
888 glibc to issue bogus negative syscall numbers. So for
889 our purposes, make strace print what it *should* have been */
890 long correct_scno = (scno & 0xff);
893 "Detected glibc bug: bogus system call number = %ld,
894 correcting to %ld\n",
901 if (!(tcp->flags & TCB_INSYSCALL)) {
902 /* Check if we return from execve. */
903 if (scno == 0 && tcp->flags & TCB_WAITEXECVE) {
904 tcp->flags &= ~TCB_WAITEXECVE;
911 if (upeek(pid, uoff(u_arg[7]), &scno) < 0)
914 /* new syscall ABI returns result in R0 */
915 if (upeek(pid, 4*REG_REG0, (long *)&r0) < 0)
919 #ifdef HAVE_PR_SYSCALL
920 scno = tcp->status.PR_SYSCALL;
921 #else /* !HAVE_PR_SYSCALL */
923 scno = tcp->status.PR_WHAT;
925 if (pread(tcp->pfd_reg, ®s, sizeof(regs), 0) < 0) {
929 switch (regs.r_eax) {
932 pread(tcp->pfd, &scno, sizeof(scno), regs.r_esp + sizeof(int));
939 #endif /* !HAVE_PR_SYSCALL */
940 #endif /* USE_PROCFS */
941 if (!(tcp->flags & TCB_INSYSCALL))
953 #else /* USE_PROCFS */
954 int scno = tcp->scno;
956 if (!(tcp->flags & TCB_INSYSCALL)) {
957 if (tcp->status.PR_WHY != PR_SYSENTRY) {
962 #endif /* SYS_vfork */
965 #endif /* SYS_fork1 */
967 || scno == SYS_forkall
968 #endif /* SYS_forkall */
970 || scno == SYS_rfork1
971 #endif /* SYS_fork1 */
973 || scno == SYS_rforkall
974 #endif /* SYS_rforkall */
976 /* We are returning in the child, fake it. */
977 tcp->status.PR_WHY = PR_SYSENTRY;
979 tcp->status.PR_WHY = PR_SYSEXIT;
982 fprintf(stderr, "syscall: missing entry\n");
983 tcp->flags |= TCB_INSYSCALL;
988 if (tcp->status.PR_WHY != PR_SYSEXIT) {
989 fprintf(stderr, "syscall: missing exit\n");
990 tcp->flags &= ~TCB_INSYSCALL;
993 #endif /* USE_PROCFS */
995 if (!(tcp->flags & TCB_INSYSCALL)) {
997 fprintf(stderr, "syscall: missing entry\n");
998 tcp->flags |= TCB_INSYSCALL;
1005 * This happens when a signal handler
1006 * for a signal which interrupted a
1007 * a system call makes another system call.
1009 fprintf(stderr, "syscall: missing exit\n");
1011 tcp->flags &= ~TCB_INSYSCALL;
1017 if (upeek(pid, 4*EAX, &eax) < 0)
1019 if (eax != -ENOSYS && !(tcp->flags & TCB_INSYSCALL)) {
1021 fprintf(stderr, "stray syscall exit: eax = %ld\n", eax);
1024 #elif defined (S390)
1025 if (upeek(pid, PT_GPR2, &gpr2) < 0)
1027 if (gpr2 != -ENOSYS && !(tcp->flags & TCB_INSYSCALL)) {
1029 fprintf(stderr, "stray syscall exit: gpr2 = %ld\n", gpr2);
1032 #elif defined (POWERPC)
1033 # define SO_MASK 0x10000000
1034 if (upeek(pid, 4*PT_CCR, &flags) < 0)
1036 if (upeek(pid, 4*PT_R3, &result) < 0)
1038 if (flags & SO_MASK)
1040 #elif defined (M68K)
1041 if (upeek(pid, 4*PT_D0, &d0) < 0)
1043 if (d0 != -ENOSYS && !(tcp->flags & TCB_INSYSCALL)) {
1045 fprintf(stderr, "stray syscall exit: d0 = %ld\n", d0);
1049 if (upeek(pid, 4*0, (long *)&r0) < 0)
1051 if ( 0 && r0 != -ENOSYS && !(tcp->flags & TCB_INSYSCALL)) {
1053 fprintf(stderr, "stray syscall exit: d0 = %ld\n", r0);
1056 #elif defined (HPPA)
1057 if (upeek(pid, PT_GR28, &r28) < 0)
1060 if (upeek(pid, PT_R10, &r10) < 0)
1062 if (upeek(pid, PT_R8, &r8) < 0)
1064 if (ia32 && r8 != -ENOSYS && !(tcp->flags & TCB_INSYSCALL)) {
1066 fprintf(stderr, "stray syscall exit: r8 = %ld\n", r8);
1081 if (gpr2 && (unsigned) -gpr2 < nerrnos) {
1091 if (eax < 0 && -eax < nerrnos) {
1105 if (err < 0 && -err < nerrnos) {
1133 if (result && (unsigned) -result < nerrnos) {
1138 tcp->u_rval = result;
1141 #else /* !POWERPC */
1143 if (d0 && (unsigned) -d0 < nerrnos) {
1153 if (r0 && (unsigned) -r0 < nerrnos) {
1173 if (regs.r_psr & PSR_C) {
1175 u_error = regs.r_o0;
1178 tcp->u_rval = regs.r_o0;
1183 if (r28 && (unsigned) -r28 < nerrnos) {
1193 /* interpret R0 as return value or error number */
1194 if (r0 && (unsigned) -r0 < nerrnos) {
1208 #endif /* POWERPC */
1215 /* get error code from user struct */
1216 if (upeek(pid, uoff(u_error), &u_error) < 0)
1218 u_error >>= 24; /* u_error is a char */
1220 /* get system call return value */
1221 if (upeek(pid, uoff(u_rval1), &tcp->u_rval) < 0)
1226 /* Judicious guessing goes a long way. */
1227 if (tcp->status.pr_reg[R_PSR] & 0x100000) {
1229 u_error = tcp->status.pr_reg[R_O0];
1232 tcp->u_rval = tcp->status.pr_reg[R_O0];
1237 /* Wanna know how to kill an hour single-stepping? */
1238 if (tcp->status.PR_REG[EFL] & 0x1) {
1240 u_error = tcp->status.PR_REG[EAX];
1243 tcp->u_rval = tcp->status.PR_REG[EAX];
1244 #ifdef HAVE_LONG_LONG
1246 ((unsigned long long) tcp->status.PR_REG[EDX] << 32) +
1247 tcp->status.PR_REG[EAX];
1253 if (tcp->status.pr_reg[CTX_A3]) {
1255 u_error = tcp->status.pr_reg[CTX_V0];
1258 tcp->u_rval = tcp->status.pr_reg[CTX_V0];
1264 if (regs.r_eflags & PSL_C) {
1266 u_error = regs.r_eax;
1268 tcp->u_rval = regs.r_eax;
1270 ((unsigned long long) regs.r_edx << 32) + regs.r_eax;
1273 #endif /* FREEBSD */
1274 tcp->u_error = u_error;
1278 int syscall_enter(tcp)
1283 #endif /* !USE_PROCFS */
1288 if (tcp->scno >= 0 && tcp->scno < nsyscalls && sysent[tcp->scno].nargs != -1)
1289 tcp->u_nargs = sysent[tcp->scno].nargs;
1291 tcp->u_nargs = MAX_ARGS;
1292 for (i = 0; i < tcp->u_nargs; i++) {
1293 if (upeek(pid,i==0 ? PT_ORIGGPR2:PT_GPR2+(i<<2), &tcp->u_arg[i]) < 0)
1297 #elif defined (ALPHA)
1300 if (tcp->scno >= 0 && tcp->scno < nsyscalls && sysent[tcp->scno].nargs != -1)
1301 tcp->u_nargs = sysent[tcp->scno].nargs;
1303 tcp->u_nargs = MAX_ARGS;
1304 for (i = 0; i < tcp->u_nargs; i++) {
1305 /* WTA: if scno is out-of-bounds this will bomb. Add range-check
1306 * for scno somewhere above here!
1308 if (upeek(pid, REG_A0+i, &tcp->u_arg[i]) < 0)
1312 #elif defined (IA64)
1315 unsigned long *out0, *rbs_end, cfm, sof, sol, i;
1316 /* be backwards compatible with kernel < 2.4.4... */
1318 # define PT_RBS_END PT_AR_BSP
1321 if (upeek(pid, PT_RBS_END, (long *) &rbs_end) < 0)
1323 if (upeek(pid, PT_CFM, (long *) &cfm) < 0)
1326 sof = (cfm >> 0) & 0x7f;
1327 sol = (cfm >> 7) & 0x7f;
1328 out0 = ia64_rse_skip_regs(rbs_end, -sof + sol);
1330 if (tcp->scno >= 0 && tcp->scno < nsyscalls
1331 && sysent[tcp->scno].nargs != -1)
1332 tcp->u_nargs = sysent[tcp->scno].nargs;
1334 tcp->u_nargs = MAX_ARGS;
1335 for (i = 0; i < tcp->u_nargs; ++i) {
1336 if (umoven(tcp, (unsigned long) ia64_rse_skip_regs(out0, i),
1337 sizeof(long), (char *) &tcp->u_arg[i]) < 0)
1343 if (/* EBX = out0 */
1344 upeek(pid, PT_R11, (long *) &tcp->u_arg[0]) < 0
1346 || upeek(pid, PT_R9, (long *) &tcp->u_arg[1]) < 0
1348 || upeek(pid, PT_R10, (long *) &tcp->u_arg[2]) < 0
1350 || upeek(pid, PT_R14, (long *) &tcp->u_arg[3]) < 0
1352 || upeek(pid, PT_R15, (long *) &tcp->u_arg[4]) < 0
1354 || upeek(pid, PT_R13, (long *) &tcp->u_arg[5]) < 0)
1357 for (i = 0; i < 6; ++i)
1358 /* truncate away IVE sign-extension */
1359 tcp->u_arg[i] &= 0xffffffff;
1361 if (tcp->scno >= 0 && tcp->scno < nsyscalls
1362 && sysent[tcp->scno].nargs != -1)
1363 tcp->u_nargs = sysent[tcp->scno].nargs;
1368 #elif defined (MIPS)
1373 if (tcp->scno >= 0 && tcp->scno < nsyscalls && sysent[tcp->scno].nargs != -1)
1374 nargs = tcp->u_nargs = sysent[tcp->scno].nargs;
1376 nargs = tcp->u_nargs = MAX_ARGS;
1378 if(upeek(pid, REG_SP, &sp) < 0)
1380 for(i = 0; i < 4; i++) {
1381 if (upeek(pid, REG_A0 + i, &tcp->u_arg[i])<0)
1384 umoven(tcp, sp+16, (nargs-4) * sizeof(tcp->u_arg[0]),
1385 (char *)(tcp->u_arg + 4));
1387 for(i = 0; i < nargs; i++) {
1388 if (upeek(pid, REG_A0 + i, &tcp->u_arg[i]) < 0)
1393 #elif defined (POWERPC)
1396 if (tcp->scno >= 0 && tcp->scno < nsyscalls && sysent[tcp->scno].nargs != -1)
1397 tcp->u_nargs = sysent[tcp->scno].nargs;
1399 tcp->u_nargs = MAX_ARGS;
1400 for (i = 0; i < tcp->u_nargs; i++) {
1401 if (upeek(pid, (i==0) ? (4*PT_ORIG_R3) : ((i+PT_R3)*4), &tcp->u_arg[i]) < 0)
1405 #elif defined (SPARC)
1409 if (tcp->scno >= 0 && tcp->scno < nsyscalls && sysent[tcp->scno].nargs != -1)
1410 tcp->u_nargs = sysent[tcp->scno].nargs;
1412 tcp->u_nargs = MAX_ARGS;
1413 for (i = 0; i < tcp->u_nargs; i++)
1414 tcp->u_arg[i] = *((®s.r_o0) + i);
1416 #elif defined (HPPA)
1420 if (tcp->scno >= 0 && tcp->scno < nsyscalls && sysent[tcp->scno].nargs != -1)
1421 tcp->u_nargs = sysent[tcp->scno].nargs;
1423 tcp->u_nargs = MAX_ARGS;
1424 for (i = 0; i < tcp->u_nargs; i++) {
1425 if (upeek(pid, PT_GR26-4*i, &tcp->u_arg[i]) < 0)
1432 static int syscall_regs[] = {
1433 REG_REG0+4, REG_REG0+5, REG_REG0+6, REG_REG0+7,
1434 REG_REG0, REG_REG0+1, REG_REG0+2
1437 tcp->u_nargs = sysent[tcp->scno].nargs;
1438 for (i = 0; i < tcp->u_nargs; i++) {
1439 if (upeek(pid, 4*syscall_regs[i], &tcp->u_arg[i]) < 0)
1443 #else /* Other architecture (like i386) (32bits specific) */
1446 if (tcp->scno >= 0 && tcp->scno < nsyscalls && sysent[tcp->scno].nargs != -1)
1447 tcp->u_nargs = sysent[tcp->scno].nargs;
1449 tcp->u_nargs = MAX_ARGS;
1450 for (i = 0; i < tcp->u_nargs; i++) {
1451 if (upeek(pid, i*4, &tcp->u_arg[i]) < 0)
1460 if (tcp->scno >= 0 && tcp->scno < nsyscalls && sysent[tcp->scno].nargs != -1)
1461 tcp->u_nargs = sysent[tcp->scno].nargs;
1463 tcp->u_nargs = MAX_ARGS;
1464 for (i = 0; i < tcp->u_nargs; i++) {
1467 if (upeek(pid, uoff(u_arg[0]) +
1468 (i*sizeof(u->u_arg[0])), &tcp->u_arg[i]) < 0)
1476 * SGI is broken: even though it has pr_sysarg, it doesn't
1477 * set them on system call entry. Get a clue.
1479 if (tcp->scno >= 0 && tcp->scno < nsyscalls && sysent[tcp->scno].nargs != -1)
1480 tcp->u_nargs = sysent[tcp->scno].nargs;
1482 tcp->u_nargs = tcp->status.pr_nsysarg;
1483 if (tcp->u_nargs > 4) {
1484 memcpy(tcp->u_arg, &tcp->status.pr_reg[CTX_A0],
1485 4*sizeof(tcp->u_arg[0]));
1486 umoven(tcp, tcp->status.pr_reg[CTX_SP] + 16,
1487 (tcp->u_nargs - 4)*sizeof(tcp->u_arg[0]), (char *) (tcp->u_arg + 4));
1490 memcpy(tcp->u_arg, &tcp->status.pr_reg[CTX_A0],
1491 tcp->u_nargs*sizeof(tcp->u_arg[0]));
1495 * Like SGI, UnixWare doesn't set pr_sysarg until system call exit
1497 if (tcp->scno >= 0 && tcp->scno < nsyscalls && sysent[tcp->scno].nargs != -1)
1498 tcp->u_nargs = sysent[tcp->scno].nargs;
1500 tcp->u_nargs = tcp->status.pr_lwp.pr_nsysarg;
1501 umoven(tcp, tcp->status.PR_REG[UESP] + 4,
1502 tcp->u_nargs*sizeof(tcp->u_arg[0]), (char *) tcp->u_arg);
1503 #elif defined (HAVE_PR_SYSCALL)
1504 if (tcp->scno >= 0 && tcp->scno < nsyscalls && sysent[tcp->scno].nargs != -1)
1505 tcp->u_nargs = sysent[tcp->scno].nargs;
1507 tcp->u_nargs = tcp->status.pr_nsysarg;
1510 for (i = 0; i < tcp->u_nargs; i++)
1511 tcp->u_arg[i] = tcp->status.pr_sysarg[i];
1513 #elif defined (I386)
1514 if (tcp->scno >= 0 && tcp->scno < nsyscalls && sysent[tcp->scno].nargs != -1)
1515 tcp->u_nargs = sysent[tcp->scno].nargs;
1518 umoven(tcp, tcp->status.PR_REG[UESP] + 4,
1519 tcp->u_nargs*sizeof(tcp->u_arg[0]), (char *) tcp->u_arg);
1521 I DONT KNOW WHAT TO DO
1522 #endif /* !HAVE_PR_SYSCALL */
1525 if (tcp->scno >= 0 && tcp->scno < nsyscalls &&
1526 sysent[tcp->scno].nargs > tcp->status.val)
1527 tcp->u_nargs = sysent[tcp->scno].nargs;
1529 tcp->u_nargs = tcp->status.val;
1530 if (tcp->u_nargs < 0)
1532 if (tcp->u_nargs > MAX_ARGS)
1533 tcp->u_nargs = MAX_ARGS;
1534 switch(regs.r_eax) {
1536 pread(tcp->pfd, &tcp->u_arg, tcp->u_nargs * sizeof(unsigned long),
1537 regs.r_esp + sizeof(int) + sizeof(quad_t));
1540 pread(tcp->pfd, &tcp->u_arg, tcp->u_nargs * sizeof(unsigned long),
1541 regs.r_esp + 2 * sizeof(int));
1544 pread(tcp->pfd, &tcp->u_arg, tcp->u_nargs * sizeof(unsigned long),
1545 regs.r_esp + sizeof(int));
1548 #endif /* FREEBSD */
1560 /* Measure the exit time as early as possible to avoid errors. */
1561 if (dtime && (tcp->flags & TCB_INSYSCALL))
1562 gettimeofday(&tv, NULL);
1564 res = get_scno(tcp);
1568 res = syscall_fixup(tcp);
1572 if (tcp->flags & TCB_INSYSCALL) {
1574 res = get_error(tcp);
1577 u_error = tcp->u_error;
1580 internal_syscall(tcp);
1581 if (tcp->scno >= 0 && tcp->scno < nsyscalls &&
1582 !(qual_flags[tcp->scno] & QUAL_TRACE)) {
1583 tcp->flags &= ~TCB_INSYSCALL;
1587 if (tcp->flags & TCB_REPRINT) {
1590 if (tcp->scno >= nsyscalls || tcp->scno < 0)
1591 tprintf("syscall_%lu", tcp->scno);
1593 tprintf("%s", sysent[tcp->scno].sys_name);
1594 tprintf(" resumed> ");
1597 if (cflag && tcp->scno < nsyscalls && tcp->scno >= 0) {
1598 call_count[tcp->scno]++;
1600 error_count[tcp->scno]++;
1601 tv_sub(&tv, &tv, &tcp->etime);
1603 if (tv_cmp(&tv, &tcp->dtime) > 0) {
1604 static struct timeval one_tick =
1605 { 0, 1000000 / HZ };
1607 if (tv_nz(&tcp->dtime))
1609 else if (tv_cmp(&tv, &one_tick) > 0) {
1610 if (tv_cmp(&shortest, &one_tick) < 0)
1617 if (tv_cmp(&tv, &shortest) < 0)
1619 tv_add(&tv_count[tcp->scno],
1620 &tv_count[tcp->scno], &tv);
1621 tcp->flags &= ~TCB_INSYSCALL;
1625 if (tcp->scno >= nsyscalls || tcp->scno < 0
1626 || (qual_flags[tcp->scno] & QUAL_RAW))
1627 sys_res = printargs(tcp);
1629 sys_res = (*sysent[tcp->scno].sys_func)(tcp);
1630 u_error = tcp->u_error;
1633 if (tcp->scno >= nsyscalls || tcp->scno < 0 ||
1634 qual_flags[tcp->scno] & QUAL_RAW) {
1636 tprintf("= -1 (errno %ld)", u_error);
1638 tprintf("= %#lx", tcp->u_rval);
1640 else if (!(sys_res & RVAL_NONE) && u_error) {
1644 tprintf("= ? ERESTARTSYS (To be restarted)");
1646 case ERESTARTNOINTR:
1647 tprintf("= ? ERESTARTNOINTR (To be restarted)");
1649 case ERESTARTNOHAND:
1650 tprintf("= ? ERESTARTNOHAND (To be restarted)");
1656 tprintf("E??? (errno %ld)", u_error);
1657 else if (u_error < nerrnos && u_error < sys_nerr)
1658 tprintf("%s (%s)", errnoent[u_error],
1659 sys_errlist[u_error]);
1660 else if (u_error < nerrnos)
1661 tprintf("%s (errno %ld)",
1662 errnoent[u_error], u_error);
1663 else if (u_error < sys_nerr)
1664 tprintf("ERRNO_%ld (%s)", u_error,
1665 sys_errlist[u_error]);
1667 tprintf("E??? (errno %ld)", u_error);
1672 if (sys_res & RVAL_NONE)
1675 switch (sys_res & RVAL_MASK) {
1677 tprintf("= %#lx", tcp->u_rval);
1680 tprintf("= %#lo", tcp->u_rval);
1683 tprintf("= %lu", tcp->u_rval);
1686 tprintf("= %ld", tcp->u_rval);
1688 #ifdef HAVE_LONG_LONG
1690 tprintf("= %#llx", tcp->u_lrval);
1693 tprintf("= %#llo", tcp->u_lrval);
1695 case RVAL_LUDECIMAL:
1696 tprintf("= %llu", tcp->u_lrval);
1699 tprintf("= %lld", tcp->u_lrval);
1704 "invalid rval format\n");
1708 if ((sys_res & RVAL_STR) && tcp->auxstr)
1709 tprintf(" (%s)", tcp->auxstr);
1712 tv_sub(&tv, &tv, &tcp->etime);
1713 tprintf(" <%ld.%06ld>",
1714 (long) tv.tv_sec, (long) tv.tv_usec);
1719 if (fflush(tcp->outf) == EOF)
1721 tcp->flags &= ~TCB_INSYSCALL;
1725 /* Entering system call */
1726 res = syscall_enter(tcp);
1730 switch (tcp->scno + NR_SYSCALL_BASE) {
1732 #if !defined (ALPHA) && !defined(SPARC) && !defined(MIPS) && !defined(HPPA)
1733 case SYS_socketcall:
1734 decode_subcall(tcp, SYS_socket_subcall,
1735 SYS_socket_nsubcalls, deref_style);
1738 decode_subcall(tcp, SYS_ipc_subcall,
1739 SYS_ipc_nsubcalls, shift_style);
1741 #endif /* !ALPHA && !MIPS && !SPARC */
1743 case SYS_socketcall:
1744 sparc_socket_decode (tcp);
1749 #ifdef SYS_pgrpsys_subcall
1751 decode_subcall(tcp, SYS_pgrpsys_subcall,
1752 SYS_pgrpsys_nsubcalls, shift_style);
1754 #endif /* SYS_pgrpsys_subcall */
1755 #ifdef SYS_sigcall_subcall
1757 decode_subcall(tcp, SYS_sigcall_subcall,
1758 SYS_sigcall_nsubcalls, mask_style);
1760 #endif /* SYS_sigcall_subcall */
1762 decode_subcall(tcp, SYS_msgsys_subcall,
1763 SYS_msgsys_nsubcalls, shift_style);
1766 decode_subcall(tcp, SYS_shmsys_subcall,
1767 SYS_shmsys_nsubcalls, shift_style);
1770 decode_subcall(tcp, SYS_semsys_subcall,
1771 SYS_semsys_nsubcalls, shift_style);
1775 decode_subcall(tcp, SYS_utssys_subcall,
1776 SYS_utssys_nsubcalls, shift_style);
1780 decode_subcall(tcp, SYS_sysfs_subcall,
1781 SYS_sysfs_nsubcalls, shift_style);
1784 decode_subcall(tcp, SYS_spcall_subcall,
1785 SYS_spcall_nsubcalls, shift_style);
1787 #ifdef SYS_context_subcall
1789 decode_subcall(tcp, SYS_context_subcall,
1790 SYS_context_nsubcalls, shift_style);
1792 #endif /* SYS_context_subcall */
1793 #ifdef SYS_door_subcall
1795 decode_subcall(tcp, SYS_door_subcall,
1796 SYS_door_nsubcalls, door_style);
1798 #endif /* SYS_door_subcall */
1799 #ifdef SYS_kaio_subcall
1801 decode_subcall(tcp, SYS_kaio_subcall,
1802 SYS_kaio_nsubcalls, shift_style);
1810 decode_subcall(tcp, 0, 0, table_style);
1815 decode_subcall(tcp, SYS_semsys_subcall,
1816 SYS_semsys_nsubcalls, shift_style);
1819 decode_subcall(tcp, SYS_msgsys_subcall,
1820 SYS_msgsys_nsubcalls, shift_style);
1823 decode_subcall(tcp, SYS_shmsys_subcall,
1824 SYS_shmsys_nsubcalls, shift_style);
1829 internal_syscall(tcp);
1830 if (tcp->scno >=0 && tcp->scno < nsyscalls && !(qual_flags[tcp->scno] & QUAL_TRACE)) {
1831 tcp->flags |= TCB_INSYSCALL;
1836 gettimeofday(&tcp->etime, NULL);
1837 tcp->flags |= TCB_INSYSCALL;
1842 tcp->flags &= ~TCB_REPRINT;
1844 if (tcp->scno >= nsyscalls || tcp->scno < 0)
1845 tprintf("syscall_%lu(", tcp->scno);
1847 tprintf("%s(", sysent[tcp->scno].sys_name);
1848 if (tcp->scno >= nsyscalls || tcp->scno < 0 ||
1849 ((qual_flags[tcp->scno] & QUAL_RAW) && tcp->scno != SYS_exit))
1850 sys_res = printargs(tcp);
1852 sys_res = (*sysent[tcp->scno].sys_func)(tcp);
1853 if (fflush(tcp->outf) == EOF)
1855 tcp->flags |= TCB_INSYSCALL;
1856 /* Measure the entrance time as late as possible to avoid errors. */
1858 gettimeofday(&tcp->etime, NULL);
1866 if (entering(tcp)) {
1869 for (i = 0; i < tcp->u_nargs; i++)
1870 tprintf("%s%#lx", i ? ", " : "", tcp->u_arg[i]);
1884 if (ptrace(PTRACE_GETREGS,tcp->pid,(char *)®s,0) < 0)
1891 if (upeek(tcp->pid, uoff(u_rval2), &val) < 0)
1897 val = tcp->status.PR_REG[R_O1];
1900 val = tcp->status.PR_REG[EDX];
1903 val = tcp->status.PR_REG[CTX_V1];
1908 pread(tcp->pfd_reg, ®s, sizeof(regs), 0);
1915 * Apparently, indirect system calls have already be converted by ptrace(2),
1916 * so if you see "indir" this program has gone astray.
1924 if (entering(tcp)) {
1925 if ((scno = tcp->u_arg[0]) > nsyscalls) {
1926 fprintf(stderr, "Bogus syscall: %u\n", scno);
1929 nargs = sysent[scno].nargs;
1930 tprintf("%s", sysent[scno].sys_name);
1931 for (i = 0; i < nargs; i++)
1932 tprintf(", %#lx", tcp->u_arg[i+1]);
1942 return -tv_cmp(&tv_count[*((int *) a)], &tv_count[*((int *) b)]);
1950 return strcmp(sysent[*((int *) a)].sys_name,
1951 sysent[*((int *) b)].sys_name);
1959 int m = call_count[*((int *) a)], n = call_count[*((int *) b)];
1961 return (m < n) ? 1 : (m > n) ? -1 : 0;
1964 static int (*sortfun)();
1965 static struct timeval overhead = { -1, -1 };
1971 if (strcmp(sortby, "time") == 0)
1973 else if (strcmp(sortby, "calls") == 0)
1974 sortfun = count_cmp;
1975 else if (strcmp(sortby, "name") == 0)
1976 sortfun = syscall_cmp;
1977 else if (strcmp(sortby, "nothing") == 0)
1980 fprintf(stderr, "invalid sortby: `%s'\n", sortby);
1985 void set_overhead(n)
1988 overhead.tv_sec = n / 1000000;
1989 overhead.tv_usec = n % 1000000;
1997 int call_cum, error_cum;
1998 struct timeval tv_cum, dtv;
2000 char *dashes = "-------------------------";
2003 call_cum = error_cum = tv_cum.tv_sec = tv_cum.tv_usec = 0;
2004 if (overhead.tv_sec == -1) {
2005 tv_mul(&overhead, &shortest, 8);
2006 tv_div(&overhead, &overhead, 10);
2008 for (i = 0; i < nsyscalls; i++) {
2009 sorted_count[i] = i;
2010 if (call_count[i] == 0)
2012 tv_mul(&dtv, &overhead, call_count[i]);
2013 tv_sub(&tv_count[i], &tv_count[i], &dtv);
2014 call_cum += call_count[i];
2015 error_cum += error_count[i];
2016 tv_add(&tv_cum, &tv_cum, &tv_count[i]);
2019 qsort((void *) sorted_count, nsyscalls, sizeof(int), sortfun);
2020 fprintf(outf, "%6.6s %11.11s %11.11s %9.9s %9.9s %s\n",
2021 "% time", "seconds", "usecs/call",
2022 "calls", "errors", "syscall");
2023 fprintf(outf, "%6.6s %11.11s %11.11s %9.9s %9.9s %-16.16s\n",
2024 dashes, dashes, dashes, dashes, dashes, dashes);
2025 for (i = 0; i < nsyscalls; i++) {
2026 j = sorted_count[i];
2027 if (call_count[j] == 0)
2029 tv_div(&dtv, &tv_count[j], call_count[j]);
2031 sprintf(error_str, "%d", error_count[j]);
2033 error_str[0] = '\0';
2034 percent = 100.0*tv_float(&tv_count[j])/tv_float(&tv_cum);
2035 fprintf(outf, "%6.2f %4ld.%06ld %11ld %9d %9.9s %s\n",
2036 percent, (long) tv_count[j].tv_sec,
2037 (long) tv_count[j].tv_usec,
2038 (long) 1000000 * dtv.tv_sec + dtv.tv_usec,
2039 call_count[j], error_str, sysent[j].sys_name);
2041 fprintf(outf, "%6.6s %11.11s %11.11s %9.9s %9.9s %-16.16s\n",
2042 dashes, dashes, dashes, dashes, dashes, dashes);
2044 sprintf(error_str, "%d", error_cum);
2046 error_str[0] = '\0';
2047 fprintf(outf, "%6.6s %4ld.%06ld %11.11s %9d %9.9s %s\n",
2048 "100.00", (long) tv_cum.tv_sec, (long) tv_cum.tv_usec, "",
2049 call_cum, error_str, "total");