2 * Pretty-print trace of api calls to the /proc api
3 * (ioctl or read/write calls).
10 #if defined (NEW_PROC_API)
11 #define _STRUCTURED_PROC 1
15 #include <sys/types.h>
16 #include <sys/procfs.h>
17 #include <sys/proc.h> /* for struct proc */
18 #include <sys/user.h> /* for struct user */
19 #include <fcntl.h> /* for O_RDWR etc. */
21 /* Much of the information used in the /proc interface, particularly for
22 printing status information, is kept as tables of structures of the
23 following form. These tables can be used to map numeric values to
24 their symbolic names and to a string that describes their specific use. */
27 long value
; /* The numeric value */
28 char *name
; /* The equivalent symbolic value */
29 char *desc
; /* Short description of value */
32 static int procfs_trace
= 1;
33 /*static int info_verbose = 1;*/ /* kludge */
34 static FILE *procfs_file
= NULL
;
35 static char *procfs_filename
= "procfs_trace";
38 set_procfs_trace_cmd (args
, from_tty
, c
)
41 struct cmd_list_element
*c
;
43 #if 0 /* not sure what I might actually need to do here, if anything */
50 set_procfs_file_cmd (args
, from_tty
, c
)
53 struct cmd_list_element
*c
;
55 /* Just changed the filename for procfs tracing.
56 If a file was already open, close it. */
65 static struct trans ioctl_table
[] = {
66 #ifdef PIOCACINFO /* irix */
67 { PIOCACINFO
, "PIOCACINFO", "get process account info" },
69 { PIOCACTION
, "PIOCACTION", "get signal action structs" },
70 #ifdef PIOCARGUMENTS /* osf */
71 { PIOCARGUMENTS
, "PIOCARGUMENTS", "command line args" },
73 #ifdef PIOCAUXV /* solaris aux vectors */
74 { PIOCAUXV
, "PIOCAUXV", "get aux vector" },
75 { PIOCNAUXV
, "PIOCNAUXV", "get number of aux vector entries" },
77 { PIOCCFAULT
, "PIOCCFAULT", "clear current fault" },
78 { PIOCCRED
, "PIOCCRED", "get process credentials" },
79 #ifdef PIOCENEVCTRS /* irix event counters */
80 { PIOCENEVCTRS
, "PIOCENEVCTRS", "acquire and start event counters" },
81 { PIOCGETEVCTRL
, "PIOCGETEVCTRL", "get control info of event counters" },
82 { PIOCGETEVCTRS
, "PIOCGETEVCTRS", "dump event counters" },
83 { PIOCGETPREVCTRS
, "PIOCGETPREVCTRS", "dump event counters & prusage info" },
84 { PIOCRELEVCTRS
, "PIOCRELEVCTRS", "release/stop event counters" },
85 { PIOCSETEVCTRL
, "PIOCSETEVCTRL", "set control info of event counters" },
86 { PIOCGETPTIMER
, "PIOCGETPTIMER", "get process timers" },
87 #endif /* irix event counters */
88 { PIOCGENTRY
, "PIOCGENTRY", "get traced syscall entry set" },
89 { PIOCGETPR
, "PIOCGETPR", "read struct proc" },
90 { PIOCGETU
, "PIOCGETU", "read user area" },
91 #if defined (PIOCGETUTK) && (defined(KERNEL) || defined(SHOW_UTT)) /* osf */
92 { PIOCGETUTK
, "PIOCGETUTK", "get the utask struct" },
94 { PIOCGEXIT
, "PIOCGEXIT", "get traced syscall exit set" },
95 { PIOCGFAULT
, "PIOCGFAULT", "get traced fault set" },
96 #ifdef PIOCGFPCR /* osf */
97 { PIOCGFPCR
, "PIOCGFPCR", "get FP control register" },
98 { PIOCSFPCR
, "PIOCSFPCR", "set FP conrtol register" },
100 { PIOCGFPREG
, "PIOCGFPREG", "get floating point registers" },
101 { PIOCGHOLD
, "PIOCGHOLD", "get held signal set" },
102 { PIOCGREG
, "PIOCGREG", "get general registers" },
103 { PIOCGROUPS
, "PIOCGROUPS", "get supplementary groups" },
104 #ifdef PIOCGSPCACT /* osf */
105 { PIOCGSPCACT
, "PIOCGSPCACT", "get special action" },
106 { PIOCSSPCACT
, "PIOCSSPCACT", "set special action" },
108 { PIOCGTRACE
, "PIOCGTRACE", "get traced signal set" },
109 #ifdef PIOCGWATCH /* irix watchpoints */
110 { PIOCGWATCH
, "PIOCGWATCH", "get watchpoint" },
111 { PIOCSWATCH
, "PIOCSWATCH", "set watchpoint" },
112 { PIOCNWATCH
, "PIOCNWATCH", "get number of watchpoints" },
113 #endif /* irix watchpoints */
114 #ifdef PIOCGWIN /* solaris sparc */
115 { PIOCGWIN
, "PIOCGWIN", "get gwindows_t" },
117 #ifdef PIOCGXREG /* solaris sparc extra regs */
118 { PIOCGXREGSIZE
, "PIOCXREGSIZE", "get extra register state size" },
119 { PIOCGXREG
, "PIOCGXREG", "get extra register state" },
120 { PIOCSXREG
, "PIOCSXREG", "set extra register state" },
122 { PIOCKILL
, "PIOCKILL", "send signal" },
123 #ifdef PIOCLDT /* solaris i386 */
124 { PIOCLDT
, "PIOCLDT", "get LDT" },
125 { PIOCNLDT
, "PIOCNLDT", "get number of LDT entries" },
127 #ifdef PIOCLSTATUS /* solaris and unixware */
128 { PIOCLSTATUS
, "PIOCLSTATUS", "get status of all lwps" },
129 { PIOCLUSAGE
, "PIOCLUSAGE", "get resource usage of all lwps" },
130 { PIOCOPENLWP
, "PIOCOPENLWP", "get lwp file descriptor" },
131 { PIOCLWPIDS
, "PIOCLWPIDS", "get lwp identifiers" },
133 { PIOCMAP
, "PIOCMAP", "get memory map information" },
134 { PIOCMAXSIG
, "PIOCMAXSIG", "get max signal number" },
135 { PIOCNICE
, "PIOCNICE", "set nice priority" },
136 { PIOCNMAP
, "PIOCNMAP", "get number of memory mappings" },
137 { PIOCOPENM
, "PIOCOPENM", "open mapped object for reading" },
138 #ifdef PIOCOPENMOBS /* osf */
139 { PIOCOPENMOBS
, "PIOCOPENMOBS", "open mapped object" },
141 #ifdef PIOCOPENPD /* solaris */
142 { PIOCOPENPD
, "PIOCOPENPD", "get page data file descriptor" },
144 { PIOCPSINFO
, "PIOCPSINFO", "get ps(1) information" },
145 { PIOCRESET
, "PIOCRESET", "reset process flags" },
146 { PIOCRFORK
, "PIOCRFORK", "reset inherit-on-fork flag" },
147 { PIOCRRLC
, "PIOCRRLC", "reset run-on-last-close flag" },
148 { PIOCRUN
, "PIOCRUN", "make process runnable" },
149 #ifdef PIOCSAVECCNTRS /* irix */
150 { PIOCSAVECCNTRS
, "PIOCSAVECCNTRS", "parent gets child cntrs" },
152 { PIOCSENTRY
, "PIOCSENTRY", "set traced syscall entry set" },
153 { PIOCSET
, "PIOCSET", "set process flags" },
154 { PIOCSEXIT
, "PIOCSEXIT", "set traced syscall exit set" },
155 { PIOCSFAULT
, "PIOCSFAULT", "set traced fault set" },
156 { PIOCSFORK
, "PIOCSFORK", "set inherit-on-fork flag" },
157 { PIOCSFPREG
, "PIOCSFPREG", "set floating point registers" },
158 { PIOCSHOLD
, "PIOCSHOLD", "set held signal set" },
159 { PIOCSREG
, "PIOCSREG", "set general registers" },
160 { PIOCSRLC
, "PIOCSRLC", "set run-on-last-close flag" },
161 { PIOCSSIG
, "PIOCSSIG", "set current signal" },
162 { PIOCSTATUS
, "PIOCSTATUS", "get process status" },
163 { PIOCSTOP
, "PIOCSTOP", "post stop request" },
164 { PIOCSTRACE
, "PIOCSTRACE", "set traced signal set" },
165 { PIOCUNKILL
, "PIOCUNKILL", "delete a signal" },
166 #ifdef PIOCUSAGE /* solaris */
167 { PIOCUSAGE
, "PIOCUSAGE", "get resource usage" },
169 { PIOCWSTOP
, "PIOCWSTOP", "wait for process to stop" },
171 #ifdef PIOCNTHR /* osf threads */
172 { PIOCNTHR
, "PIOCNTHR", "get thread count" },
173 { PIOCRTINH
, "PIOCRTINH", "reset inherit-on-thread-creation" },
174 { PIOCSTINH
, "PIOCSTINH", "set inherit-on-thread-creation" },
175 { PIOCTLIST
, "PIOCTLIST", "get thread ids" },
176 { PIOCXPTH
, "PIOCXPTH", "translate port to thread handle" },
177 { PIOCTRUN
, "PIOCTRUN", "make thread runnable" },
178 { PIOCTSTATUS
, "PIOCTSTATUS", "get thread status" },
179 { PIOCTSTOP
, "PIOCTSTOP", "stop a thread" },
180 /* ... TGTRACE TSTRACE TSSIG TKILL TUNKILL TCFAULT TGFAULT TSFAULT
181 TGFPREG TSFPREG TGREG TSREG TACTION TTERM TABRUN TGENTRY TSENTRY
182 TGEXIT TSEXIT TSHOLD ... thread functions */
183 #endif /* osf threads */
188 ioctl_with_trace (fd
, opcode
, ptr
, file
, line
)
199 if (procfs_file
== NULL
&& procfs_filename
!= NULL
)
200 procfs_file
= fopen (procfs_filename
, "a");
202 for (i
= 0; ioctl_table
[i
].name
!= NULL
; i
++)
203 if (ioctl_table
[i
].value
== opcode
)
207 fprintf (procfs_file
? procfs_file
: stdout
,
208 "%s:%d -- ", file
, line
);
211 arg1
= ptr
? *(long *) ptr
: 0;
212 fprintf (procfs_file
? procfs_file
: stdout
,
213 "ioctl (PIOCSET, %s) %s\n",
214 arg1
== PR_FORK
? "PR_FORK" :
215 arg1
== PR_RLC
? "PR_RLC" :
217 arg1
== PR_ASYNC
? "PR_ASYNC" :
220 info_verbose
? ioctl_table
[i
].desc
: "");
223 arg1
= ptr
? *(long *) ptr
: 0;
224 fprintf (procfs_file
? procfs_file
: stdout
,
225 "ioctl (PIOCRESET, %s) %s\n",
226 arg1
== PR_FORK
? "PR_FORK" :
227 arg1
== PR_RLC
? "PR_RLC" :
229 arg1
== PR_ASYNC
? "PR_ASYNC" :
232 info_verbose
? ioctl_table
[i
].desc
: "");
235 fprintf (procfs_file
? procfs_file
: stdout
,
236 "ioctl (PIOCSTRACE) ");
237 proc_prettyfprint_signalset (procfs_file
? procfs_file
: stdout
,
238 (sigset_t
*) ptr
, 0);
241 fprintf (procfs_file
? procfs_file
: stdout
,
243 opcode
== PIOCSFAULT
? "PIOCSFAULT" : "PIOCGFAULT");
244 proc_prettyfprint_faultset (procfs_file
? procfs_file
: stdout
,
245 (fltset_t
*) ptr
, 0);
248 fprintf (procfs_file
? procfs_file
: stdout
,
250 opcode
== PIOCSENTRY
? "PIOCSENTRY" : "PIOCGENTRY");
251 proc_prettyfprint_syscalls (procfs_file
? procfs_file
: stdout
,
252 (sysset_t
*) ptr
, 0);
255 fprintf (procfs_file
? procfs_file
: stdout
,
257 opcode
== PIOCSEXIT
? "PIOCSEXIT" : "PIOCGEXIT");
258 proc_prettyfprint_syscalls (procfs_file
? procfs_file
: stdout
,
259 (sysset_t
*) ptr
, 0);
262 fprintf (procfs_file
? procfs_file
: stdout
,
264 opcode
== PIOCSHOLD
? "PIOCSHOLD" : "PIOCGHOLD");
265 proc_prettyfprint_signalset (procfs_file
? procfs_file
: stdout
,
266 (sigset_t
*) ptr
, 0);
269 fprintf (procfs_file
? procfs_file
: stdout
,
270 "ioctl (PIOCSSIG) ");
271 proc_prettyfprint_signal (procfs_file
? procfs_file
: stdout
,
272 ptr
? ((siginfo_t
*) ptr
)->si_signo
: 0,
274 fprintf (procfs_file
? procfs_file
: stdout
, "\n");
277 fprintf (procfs_file
? procfs_file
: stdout
,
280 arg1
= ptr
? *(long *) ptr
: 0;
282 fprintf (procfs_file
? procfs_file
: stdout
, "clearSig ");
284 fprintf (procfs_file
? procfs_file
: stdout
, "clearFlt ");
286 fprintf (procfs_file
? procfs_file
: stdout
, "setTrace ");
288 fprintf (procfs_file
? procfs_file
: stdout
, "setHold ");
290 fprintf (procfs_file
? procfs_file
: stdout
, "setFlt ");
292 fprintf (procfs_file
? procfs_file
: stdout
, "setVaddr ");
294 fprintf (procfs_file
? procfs_file
: stdout
, "step ");
296 fprintf (procfs_file
? procfs_file
: stdout
, "syscallAbort ");
298 fprintf (procfs_file
? procfs_file
: stdout
, "stopReq ");
300 fprintf (procfs_file
? procfs_file
: stdout
, "\n");
303 fprintf (procfs_file
? procfs_file
: stdout
,
304 "ioctl (PIOCKILL) ");
305 proc_prettyfprint_signal (procfs_file
? procfs_file
: stdout
,
306 ptr
? *(long *) ptr
: 0, 0);
307 fprintf (procfs_file
? procfs_file
: stdout
, "\n");
311 fprintf (procfs_file
? procfs_file
: stdout
,
312 "ioctl (PIOCSSPCACT) ");
313 arg1
= ptr
? *(long *) ptr
: 0;
314 if (arg1
& PRFS_STOPFORK
)
315 fprintf (procfs_file
? procfs_file
: stdout
, "stopFork ");
316 if (arg1
& PRFS_STOPEXEC
)
317 fprintf (procfs_file
? procfs_file
: stdout
, "stopExec ");
318 if (arg1
& PRFS_STOPTERM
)
319 fprintf (procfs_file
? procfs_file
: stdout
, "stopTerm ");
320 if (arg1
& PRFS_STOPTCR
)
321 fprintf (procfs_file
? procfs_file
: stdout
, "stopThreadCreate ");
322 if (arg1
& PRFS_STOPTTERM
)
323 fprintf (procfs_file
? procfs_file
: stdout
, "stopThreadTerm ");
324 if (arg1
& PRFS_KOLC
)
325 fprintf (procfs_file
? procfs_file
: stdout
, "killOnLastClose ");
326 fprintf (procfs_file
? procfs_file
: stdout
, "\n");
328 #endif /* PIOCSSPCACT */
330 if (ioctl_table
[i
].name
)
331 fprintf (procfs_file
? procfs_file
: stdout
,
334 info_verbose
? ioctl_table
[i
].desc
: "");
336 fprintf (procfs_file
? procfs_file
: stdout
,
337 "ioctl (<unknown %ld (0x%lx)) \n", opcode
, opcode
);
341 fflush (procfs_file
);
343 ret
= ioctl (fd
, opcode
, ptr
);
344 if (procfs_trace
&& ret
< 0)
346 fprintf (procfs_file
? procfs_file
: stdout
,
347 "[ioctl (%s) FAILED!]\n",
348 ioctl_table
[i
].name
!= NULL
?
349 ioctl_table
[i
].name
: "<unknown>");
351 fflush (procfs_file
);
357 #else /* NEW_PROC_API */
359 static struct trans rw_table
[] = {
360 #ifdef PCAGENT /* solaris */
361 { PCAGENT
, "PCAGENT", "create agent lwp with regs from argument" },
363 { PCCFAULT
, "PCCFAULT", "clear current fault" },
364 #ifdef PCCSIG /* solaris */
365 { PCCSIG
, "PCCSIG", "clear current signal" },
367 { PCDSTOP
, "PCDSTOP", "post stop request" },
368 { PCKILL
, "PCKILL", "post a signal" },
369 { PCNICE
, "PCNICE", "set nice priority" },
370 #ifdef PCREAD /* solaris */
371 { PCREAD
, "PCREAD", "read from the address space" },
372 { PCWRITE
, "PCWRITE", "write to the address space" },
374 #ifdef PCRESET /* unixware */
375 { PCRESET
, "PCRESET", "unset modes" },
377 { PCRUN
, "PCRUN", "make process/lwp runnable" },
378 #ifdef PCSASRS /* solaris 2.7 only */
379 { PCSASRS
, "PCSASRS", "set ancillary state registers" },
381 #ifdef PCSCRED /* solaris */
382 { PCSCRED
, "PCSCRED", "set process credentials" },
384 { PCSENTRY
, "PCSENTRY", "set traced syscall entry set" },
385 { PCSET
, "PCSET", "set modes" },
386 { PCSEXIT
, "PCSEXIT", "set traced syscall exit set" },
387 { PCSFAULT
, "PCSFAULT", "set traced fault set" },
388 { PCSFPREG
, "PCSFPREG", "set floating point registers" },
389 { PCSHOLD
, "PCSHOLD", "set signal mask" },
390 { PCSREG
, "PCSREG", "set general registers" },
391 { PCSSIG
, "PCSSIG", "set current signal" },
392 { PCSTOP
, "PCSTOP", "post stop request and wait" },
393 { PCSTRACE
, "PCSTRACE", "set traced signal set" },
394 #ifdef PCSVADDR /* solaris */
395 { PCSVADDR
, "PCSVADDR", "set pc virtual address" },
397 #ifdef PCSXREG /* solaris sparc only */
398 { PCSXREG
, "PCSXREG", "set extra registers" },
400 #ifdef PCTWSTOP /* solaris */
401 { PCTWSTOP
, "PCTWSTOP", "wait for stop, with timeout arg" },
403 { PCUNKILL
, "PCUNKILL", "delete a pending signal" },
404 #ifdef PCUNSET /* solaris */
405 { PCUNSET
, "PCUNSET", "unset modes" },
407 #ifdef PCWATCH /* solaris */
408 { PCWATCH
, "PCWATCH", "set/unset watched memory area" },
410 { PCWSTOP
, "PCWSTOP", "wait for process/lwp to stop, no timeout" },
414 static off_t lseek_offset
;
417 write_with_trace (fd
, arg
, len
, file
, line
)
425 long opcode
= arg
[0];
430 if (procfs_file
== NULL
&& procfs_filename
!= NULL
)
431 procfs_file
= fopen (procfs_filename
, "a");
433 for (i
= 0; rw_table
[i
].name
!= NULL
; i
++)
434 if (rw_table
[i
].value
== opcode
)
438 fprintf (procfs_file
? procfs_file
: stdout
,
439 "%s:%d -- ", file
, line
);
442 fprintf (procfs_file
? procfs_file
: stdout
,
443 "write (PCSET, %s) %s\n",
444 arg
[1] == PR_FORK
? "PR_FORK" :
445 arg
[1] == PR_RLC
? "PR_RLC" :
447 arg
[1] == PR_ASYNC
? "PR_ASYNC" :
450 info_verbose
? rw_table
[i
].desc
: "");
458 fprintf (procfs_file
? procfs_file
: stdout
,
459 "write (PCRESET, %s) %s\n",
460 arg
[1] == PR_FORK
? "PR_FORK" :
461 arg
[1] == PR_RLC
? "PR_RLC" :
463 arg
[1] == PR_ASYNC
? "PR_ASYNC" :
466 info_verbose
? rw_table
[i
].desc
: "");
469 fprintf (procfs_file
? procfs_file
: stdout
,
470 "write (PCSTRACE) ");
471 proc_prettyfprint_signalset (procfs_file
? procfs_file
: stdout
,
472 (sigset_t
*) &arg
[1], 0);
475 fprintf (procfs_file
? procfs_file
: stdout
,
476 "write (PCSFAULT) ");
477 proc_prettyfprint_faultset (procfs_file
? procfs_file
: stdout
,
478 (fltset_t
*) &arg
[1], 0);
481 fprintf (procfs_file
? procfs_file
: stdout
,
482 "write (PCSENTRY) ");
483 proc_prettyfprint_syscalls (procfs_file
? procfs_file
: stdout
,
484 (sysset_t
*) &arg
[1], 0);
487 fprintf (procfs_file
? procfs_file
: stdout
,
489 proc_prettyfprint_syscalls (procfs_file
? procfs_file
: stdout
,
490 (sysset_t
*) &arg
[1], 0);
493 fprintf (procfs_file
? procfs_file
: stdout
,
495 proc_prettyfprint_signalset (procfs_file
? procfs_file
: stdout
,
496 (sigset_t
*) &arg
[1], 0);
499 fprintf (procfs_file
? procfs_file
: stdout
,
501 proc_prettyfprint_signal (procfs_file
? procfs_file
: stdout
,
502 arg
[1] ? ((siginfo_t
*) &arg
[1])->si_signo
505 fprintf (procfs_file
? procfs_file
: stdout
, "\n");
508 fprintf (procfs_file
? procfs_file
: stdout
,
511 fprintf (procfs_file
? procfs_file
: stdout
, "clearSig ");
512 if (arg
[1] & PRCFAULT
)
513 fprintf (procfs_file
? procfs_file
: stdout
, "clearFlt ");
515 fprintf (procfs_file
? procfs_file
: stdout
, "step ");
516 if (arg
[1] & PRSABORT
)
517 fprintf (procfs_file
? procfs_file
: stdout
, "syscallAbort ");
519 fprintf (procfs_file
? procfs_file
: stdout
, "stopReq ");
521 fprintf (procfs_file
? procfs_file
: stdout
, "\n");
524 fprintf (procfs_file
? procfs_file
: stdout
,
526 proc_prettyfprint_signal (procfs_file
? procfs_file
: stdout
,
528 fprintf (procfs_file
? procfs_file
: stdout
, "\n");
532 static unsigned char break_insn
[] = BREAKPOINT
;
534 if (len
== sizeof (break_insn
) &&
535 memcmp (arg
, &break_insn
, len
) == 0)
536 fprintf (procfs_file
? procfs_file
: stdout
,
537 "write (<breakpoint at 0x%08x>) \n", lseek_offset
);
538 else if (rw_table
[i
].name
)
539 fprintf (procfs_file
? procfs_file
: stdout
,
542 info_verbose
? rw_table
[i
].desc
: "");
545 if (lseek_offset
!= -1)
546 fprintf (procfs_file
? procfs_file
: stdout
,
547 "write (<unknown>, %d bytes at 0x%08x) \n",
550 fprintf (procfs_file
? procfs_file
: stdout
,
551 "write (<unknown>, %d bytes) \n", len
);
557 fflush (procfs_file
);
559 ret
= write (fd
, arg
, len
);
560 if (procfs_trace
&& ret
!= len
)
562 fprintf (procfs_file
? procfs_file
: stdout
,
563 "[write (%s) FAILED!\n",
564 rw_table
[i
].name
!= NULL
?
565 rw_table
[i
].name
: "<unknown>");
567 fflush (procfs_file
);
575 lseek_with_trace (fd
, offset
, whence
, file
, line
)
584 #if 0 /* don't need output, just need address */
587 if (procfs_file
== NULL
&& procfs_filename
!= NULL
)
588 procfs_file
= fopen (procfs_filename
, "a");
591 fprintf (procfs_file
? procfs_file
: stdout
,
592 "%s:%d -- ", file
, line
);
593 fprintf (procfs_file
? procfs_file
: stdout
,
594 "lseek (0x%08x, %s) \n", offset
,
595 whence
== SEEK_SET
? "SEEK_SET" :
596 whence
== SEEK_CUR
? "SEEK_CUR" :
597 whence
== SEEK_END
? "SEEK_END" :
600 fflush (procfs_file
);
603 ret
= lseek (fd
, offset
, whence
);
605 if (procfs_trace
&& ret
== -1)
607 if (procfs_file
== NULL
&& procfs_filename
!= NULL
)
608 procfs_file
= fopen (procfs_filename
, "a");
610 fprintf (procfs_file
? procfs_file
: stdout
,
611 "[lseek (0x%08x) FAILED!\n", offset
);
613 fflush (procfs_file
);
619 #endif /* NEW_PROC_API */
622 open_with_trace (filename
, mode
, file
, line
)
628 int ret
= open (filename
, mode
);
632 if (procfs_file
== NULL
&& procfs_filename
!= NULL
)
633 procfs_file
= fopen (procfs_filename
, "a");
636 fprintf (procfs_file
? procfs_file
: stdout
,
637 "%s:%d -- ", file
, line
);
638 fprintf (procfs_file
? procfs_file
: stdout
,
639 "%d = open (%s, ", ret
, filename
);
640 if (mode
== O_RDONLY
)
641 fprintf (procfs_file
? procfs_file
: stdout
, "O_RDONLY) %d\n", line
);
642 else if (mode
== O_WRONLY
)
643 fprintf (procfs_file
? procfs_file
: stdout
, "O_WRONLY) %d\n", line
);
644 else if (mode
== O_RDWR
)
645 fprintf (procfs_file
? procfs_file
: stdout
, "O_RDWR) %d\n", line
);
647 fflush (procfs_file
);
654 close_with_trace (fd
, file
, line
)
659 int ret
= close (fd
);
663 if (procfs_file
== NULL
&& procfs_filename
!= NULL
)
664 procfs_file
= fopen (procfs_filename
, "a");
667 fprintf (procfs_file
? procfs_file
: stdout
,
668 "%s:%d -- ", file
, line
);
669 fprintf (procfs_file
? procfs_file
: stdout
,
670 "%d = close (%d)\n", ret
, fd
);
672 fflush (procfs_file
);
679 wait_with_trace (wstat
, file
, line
)
688 if (procfs_file
== NULL
&& procfs_filename
!= NULL
)
689 procfs_file
= fopen (procfs_filename
, "a");
692 fprintf (procfs_file
? procfs_file
: stdout
,
693 "%s:%d -- ", file
, line
);
694 fprintf (procfs_file
? procfs_file
: stdout
,
695 "wait (line %d) ", line
);
697 fflush (procfs_file
);
702 fprintf (procfs_file
? procfs_file
: stdout
,
703 "returned pid %d, status 0x%x\n", ret
, lstat
);
705 fflush (procfs_file
);
714 procfs_note (msg
, file
, line
)
721 if (procfs_file
== NULL
&& procfs_filename
!= NULL
)
722 procfs_file
= fopen (procfs_filename
, "a");
725 fprintf (procfs_file
? procfs_file
: stdout
,
726 "%s:%d -- ", file
, line
);
727 fprintf (procfs_file
? procfs_file
: stdout
, msg
);
729 fflush (procfs_file
);
734 proc_prettyfprint_status (flags
, why
, what
, thread
)
742 if (procfs_file
== NULL
&& procfs_filename
!= NULL
)
743 procfs_file
= fopen (procfs_filename
, "a");
746 fprintf (procfs_file
? procfs_file
: stdout
,
747 "Thread %d: ", thread
);
749 proc_prettyfprint_flags (procfs_file
? procfs_file
: stdout
,
752 if (flags
& (PR_STOPPED
| PR_ISTOP
))
753 proc_prettyfprint_why (procfs_file
? procfs_file
: stdout
,
756 fflush (procfs_file
);
762 _initialize_proc_api ()
764 struct cmd_list_element
*c
;
766 c
= add_set_cmd ("procfs-trace", no_class
,
767 var_boolean
, (char *) &procfs_trace
,
768 "Set tracing for /proc ioctl calls.\n", &setlist
);
770 add_show_from_set (c
, &showlist
);
771 c
->function
.sfunc
= set_procfs_trace_cmd
;
773 c
= add_set_cmd ("procfs-file", no_class
, var_filename
,
774 (char *) &procfs_filename
,
775 "Set filename for /proc tracefile.\n", &setlist
);
777 add_show_from_set (c
, &showlist
);
778 c
->function
.sfunc
= set_procfs_file_cmd
;
781 if (procfs_file
== NULL
&& procfs_filename
!= NULL
)
782 procfs_file
= fopen (procfs_filename
, "a");
This page took 0.046094 seconds and 4 git commands to generate.