1 /* Machine independent support for SVR4 /proc (process file system) for GDB.
2 Copyright 1999, 2000, 2001 Free Software Foundation, Inc.
3 Written by Michael Snyder at Cygnus Solutions.
4 Based on work by Fred Fish, Stu Grossman, Geoff Noer, and others.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software Foundation,
20 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 * Pretty-print trace of api calls to the /proc api
24 * (ioctl or read/write calls).
30 #include "completer.h"
32 #if defined (NEW_PROC_API)
33 #define _STRUCTURED_PROC 1
37 #include <sys/types.h>
38 #include <sys/procfs.h>
39 #include <sys/proc.h> /* for struct proc */
40 #ifdef HAVE_SYS_USER_H
41 #include <sys/user.h> /* for struct user */
43 #include <fcntl.h> /* for O_RDWR etc. */
46 #include "proc-utils.h"
48 /* Much of the information used in the /proc interface, particularly for
49 printing status information, is kept as tables of structures of the
50 following form. These tables can be used to map numeric values to
51 their symbolic names and to a string that describes their specific use. */
54 long value; /* The numeric value */
55 char *name; /* The equivalent symbolic value */
56 char *desc; /* Short description of value */
59 static int procfs_trace = 0;
60 static FILE *procfs_file = NULL;
61 static char *procfs_filename = "procfs_trace";
64 prepare_to_trace (void)
66 if (procfs_trace) /* if procfs tracing turned on */
67 if (procfs_file == NULL) /* if output file not yet open */
68 if (procfs_filename != NULL) /* if output filename known */
69 procfs_file = fopen (procfs_filename, "a"); /* open output file */
73 set_procfs_trace_cmd (char *args, int from_tty, struct cmd_list_element *c)
75 #if 0 /* not sure what I might actually need to do here, if anything */
82 set_procfs_file_cmd (char *args, int from_tty, struct cmd_list_element *c)
84 /* Just changed the filename for procfs tracing.
85 If a file was already open, close it. */
94 static struct trans ioctl_table[] = {
95 #ifdef PIOCACINFO /* irix */
96 { PIOCACINFO, "PIOCACINFO", "get process account info" },
98 { PIOCACTION, "PIOCACTION", "get signal action structs" },
99 #ifdef PIOCARGUMENTS /* osf */
100 { PIOCARGUMENTS, "PIOCARGUMENTS", "command line args" },
102 #ifdef PIOCAUXV /* solaris aux vectors */
103 { PIOCAUXV, "PIOCAUXV", "get aux vector" },
104 { PIOCNAUXV, "PIOCNAUXV", "get number of aux vector entries" },
106 { PIOCCFAULT, "PIOCCFAULT", "clear current fault" },
107 { PIOCCRED, "PIOCCRED", "get process credentials" },
108 #ifdef PIOCENEVCTRS /* irix event counters */
109 { PIOCENEVCTRS, "PIOCENEVCTRS", "acquire and start event counters" },
110 { PIOCGETEVCTRL, "PIOCGETEVCTRL", "get control info of event counters" },
111 { PIOCGETEVCTRS, "PIOCGETEVCTRS", "dump event counters" },
112 { PIOCGETPREVCTRS, "PIOCGETPREVCTRS", "dump event counters & prusage info" },
113 { PIOCRELEVCTRS, "PIOCRELEVCTRS", "release/stop event counters" },
114 { PIOCSETEVCTRL, "PIOCSETEVCTRL", "set control info of event counters" },
115 { PIOCGETPTIMER, "PIOCGETPTIMER", "get process timers" },
116 #endif /* irix event counters */
117 { PIOCGENTRY, "PIOCGENTRY", "get traced syscall entry set" },
118 #if defined (PIOCGETPR)
119 { PIOCGETPR, "PIOCGETPR", "read struct proc" },
121 #if defined (PIOCGETU)
122 { PIOCGETU, "PIOCGETU", "read user area" },
124 #if defined (PIOCGETUTK) && (defined(KERNEL) || defined(SHOW_UTT)) /* osf */
125 { PIOCGETUTK, "PIOCGETUTK", "get the utask struct" },
127 { PIOCGEXIT, "PIOCGEXIT", "get traced syscall exit set" },
128 { PIOCGFAULT, "PIOCGFAULT", "get traced fault set" },
129 #ifdef PIOCGFPCR /* osf */
130 { PIOCGFPCR, "PIOCGFPCR", "get FP control register" },
131 { PIOCSFPCR, "PIOCSFPCR", "set FP conrtol register" },
133 { PIOCGFPREG, "PIOCGFPREG", "get floating point registers" },
134 { PIOCGHOLD, "PIOCGHOLD", "get held signal set" },
135 { PIOCGREG, "PIOCGREG", "get general registers" },
136 { PIOCGROUPS, "PIOCGROUPS", "get supplementary groups" },
137 #ifdef PIOCGSPCACT /* osf */
138 { PIOCGSPCACT, "PIOCGSPCACT", "get special action" },
139 { PIOCSSPCACT, "PIOCSSPCACT", "set special action" },
141 { PIOCGTRACE, "PIOCGTRACE", "get traced signal set" },
142 #ifdef PIOCGWATCH /* irix watchpoints */
143 { PIOCGWATCH, "PIOCGWATCH", "get watchpoint" },
144 { PIOCSWATCH, "PIOCSWATCH", "set watchpoint" },
145 { PIOCNWATCH, "PIOCNWATCH", "get number of watchpoints" },
146 #endif /* irix watchpoints */
147 #ifdef PIOCGWIN /* solaris sparc */
148 { PIOCGWIN, "PIOCGWIN", "get gwindows_t" },
150 #ifdef PIOCGXREG /* solaris sparc extra regs */
151 { PIOCGXREGSIZE, "PIOCXREGSIZE", "get extra register state size" },
152 { PIOCGXREG, "PIOCGXREG", "get extra register state" },
153 { PIOCSXREG, "PIOCSXREG", "set extra register state" },
155 { PIOCKILL, "PIOCKILL", "send signal" },
156 #ifdef PIOCLDT /* solaris i386 */
157 { PIOCLDT, "PIOCLDT", "get LDT" },
158 { PIOCNLDT, "PIOCNLDT", "get number of LDT entries" },
160 #ifdef PIOCLSTATUS /* solaris and unixware */
161 { PIOCLSTATUS, "PIOCLSTATUS", "get status of all lwps" },
162 { PIOCLUSAGE, "PIOCLUSAGE", "get resource usage of all lwps" },
163 { PIOCOPENLWP, "PIOCOPENLWP", "get lwp file descriptor" },
164 { PIOCLWPIDS, "PIOCLWPIDS", "get lwp identifiers" },
166 { PIOCMAP, "PIOCMAP", "get memory map information" },
167 { PIOCMAXSIG, "PIOCMAXSIG", "get max signal number" },
168 { PIOCNICE, "PIOCNICE", "set nice priority" },
169 { PIOCNMAP, "PIOCNMAP", "get number of memory mappings" },
170 { PIOCOPENM, "PIOCOPENM", "open mapped object for reading" },
171 #ifdef PIOCOPENMOBS /* osf */
172 { PIOCOPENMOBS, "PIOCOPENMOBS", "open mapped object" },
174 #ifdef PIOCOPENPD /* solaris */
175 { PIOCOPENPD, "PIOCOPENPD", "get page data file descriptor" },
177 { PIOCPSINFO, "PIOCPSINFO", "get ps(1) information" },
178 { PIOCRESET, "PIOCRESET", "reset process flags" },
179 { PIOCRFORK, "PIOCRFORK", "reset inherit-on-fork flag" },
180 { PIOCRRLC, "PIOCRRLC", "reset run-on-last-close flag" },
181 { PIOCRUN, "PIOCRUN", "make process runnable" },
182 #ifdef PIOCSAVECCNTRS /* irix */
183 { PIOCSAVECCNTRS, "PIOCSAVECCNTRS", "parent gets child cntrs" },
185 { PIOCSENTRY, "PIOCSENTRY", "set traced syscall entry set" },
186 { PIOCSET, "PIOCSET", "set process flags" },
187 { PIOCSEXIT, "PIOCSEXIT", "set traced syscall exit set" },
188 { PIOCSFAULT, "PIOCSFAULT", "set traced fault set" },
189 { PIOCSFORK, "PIOCSFORK", "set inherit-on-fork flag" },
190 { PIOCSFPREG, "PIOCSFPREG", "set floating point registers" },
191 { PIOCSHOLD, "PIOCSHOLD", "set held signal set" },
192 { PIOCSREG, "PIOCSREG", "set general registers" },
193 { PIOCSRLC, "PIOCSRLC", "set run-on-last-close flag" },
194 { PIOCSSIG, "PIOCSSIG", "set current signal" },
195 { PIOCSTATUS, "PIOCSTATUS", "get process status" },
196 { PIOCSTOP, "PIOCSTOP", "post stop request" },
197 { PIOCSTRACE, "PIOCSTRACE", "set traced signal set" },
198 { PIOCUNKILL, "PIOCUNKILL", "delete a signal" },
199 #ifdef PIOCUSAGE /* solaris */
200 { PIOCUSAGE, "PIOCUSAGE", "get resource usage" },
202 { PIOCWSTOP, "PIOCWSTOP", "wait for process to stop" },
204 #ifdef PIOCNTHR /* osf threads */
205 { PIOCNTHR, "PIOCNTHR", "get thread count" },
206 { PIOCRTINH, "PIOCRTINH", "reset inherit-on-thread-creation" },
207 { PIOCSTINH, "PIOCSTINH", "set inherit-on-thread-creation" },
208 { PIOCTLIST, "PIOCTLIST", "get thread ids" },
209 { PIOCXPTH, "PIOCXPTH", "translate port to thread handle" },
210 { PIOCTRUN, "PIOCTRUN", "make thread runnable" },
211 { PIOCTSTATUS, "PIOCTSTATUS", "get thread status" },
212 { PIOCTSTOP, "PIOCTSTOP", "stop a thread" },
213 /* ... TGTRACE TSTRACE TSSIG TKILL TUNKILL TCFAULT TGFAULT TSFAULT
214 TGFPREG TSFPREG TGREG TSREG TACTION TTERM TABRUN TGENTRY TSENTRY
215 TGEXIT TSEXIT TSHOLD ... thread functions */
216 #endif /* osf threads */
221 ioctl_with_trace (int fd, long opcode, void *ptr, char *file, int line)
231 for (i = 0; ioctl_table[i].name != NULL; i++)
232 if (ioctl_table[i].value == opcode)
236 fprintf (procfs_file ? procfs_file : stdout,
237 "%s:%d -- ", file, line);
240 arg1 = ptr ? *(long *) ptr : 0;
241 fprintf (procfs_file ? procfs_file : stdout,
242 "ioctl (PIOCSET, %s) %s\n",
243 arg1 == PR_FORK ? "PR_FORK" :
244 arg1 == PR_RLC ? "PR_RLC" :
246 arg1 == PR_ASYNC ? "PR_ASYNC" :
249 info_verbose ? ioctl_table[i].desc : "");
252 arg1 = ptr ? *(long *) ptr : 0;
253 fprintf (procfs_file ? procfs_file : stdout,
254 "ioctl (PIOCRESET, %s) %s\n",
255 arg1 == PR_FORK ? "PR_FORK" :
256 arg1 == PR_RLC ? "PR_RLC" :
258 arg1 == PR_ASYNC ? "PR_ASYNC" :
261 info_verbose ? ioctl_table[i].desc : "");
264 fprintf (procfs_file ? procfs_file : stdout,
265 "ioctl (PIOCSTRACE) ");
266 proc_prettyfprint_signalset (procfs_file ? procfs_file : stdout,
267 (sigset_t *) ptr, 0);
270 fprintf (procfs_file ? procfs_file : stdout,
272 opcode == PIOCSFAULT ? "PIOCSFAULT" : "PIOCGFAULT");
273 proc_prettyfprint_faultset (procfs_file ? procfs_file : stdout,
274 (fltset_t *) ptr, 0);
277 fprintf (procfs_file ? procfs_file : stdout,
279 opcode == PIOCSENTRY ? "PIOCSENTRY" : "PIOCGENTRY");
280 proc_prettyfprint_syscalls (procfs_file ? procfs_file : stdout,
281 (sysset_t *) ptr, 0);
284 fprintf (procfs_file ? procfs_file : stdout,
286 opcode == PIOCSEXIT ? "PIOCSEXIT" : "PIOCGEXIT");
287 proc_prettyfprint_syscalls (procfs_file ? procfs_file : stdout,
288 (sysset_t *) ptr, 0);
291 fprintf (procfs_file ? procfs_file : stdout,
293 opcode == PIOCSHOLD ? "PIOCSHOLD" : "PIOCGHOLD");
294 proc_prettyfprint_signalset (procfs_file ? procfs_file : stdout,
295 (sigset_t *) ptr, 0);
298 fprintf (procfs_file ? procfs_file : stdout,
299 "ioctl (PIOCSSIG) ");
300 proc_prettyfprint_signal (procfs_file ? procfs_file : stdout,
301 ptr ? ((siginfo_t *) ptr)->si_signo : 0,
303 fprintf (procfs_file ? procfs_file : stdout, "\n");
306 fprintf (procfs_file ? procfs_file : stdout,
309 arg1 = ptr ? *(long *) ptr : 0;
311 fprintf (procfs_file ? procfs_file : stdout, "clearSig ");
313 fprintf (procfs_file ? procfs_file : stdout, "clearFlt ");
315 fprintf (procfs_file ? procfs_file : stdout, "setTrace ");
317 fprintf (procfs_file ? procfs_file : stdout, "setHold ");
319 fprintf (procfs_file ? procfs_file : stdout, "setFlt ");
321 fprintf (procfs_file ? procfs_file : stdout, "setVaddr ");
323 fprintf (procfs_file ? procfs_file : stdout, "step ");
325 fprintf (procfs_file ? procfs_file : stdout, "syscallAbort ");
327 fprintf (procfs_file ? procfs_file : stdout, "stopReq ");
329 fprintf (procfs_file ? procfs_file : stdout, "\n");
332 fprintf (procfs_file ? procfs_file : stdout,
333 "ioctl (PIOCKILL) ");
334 proc_prettyfprint_signal (procfs_file ? procfs_file : stdout,
335 ptr ? *(long *) ptr : 0, 0);
336 fprintf (procfs_file ? procfs_file : stdout, "\n");
340 fprintf (procfs_file ? procfs_file : stdout,
341 "ioctl (PIOCSSPCACT) ");
342 arg1 = ptr ? *(long *) ptr : 0;
343 if (arg1 & PRFS_STOPFORK)
344 fprintf (procfs_file ? procfs_file : stdout, "stopFork ");
345 if (arg1 & PRFS_STOPEXEC)
346 fprintf (procfs_file ? procfs_file : stdout, "stopExec ");
347 if (arg1 & PRFS_STOPTERM)
348 fprintf (procfs_file ? procfs_file : stdout, "stopTerm ");
349 if (arg1 & PRFS_STOPTCR)
350 fprintf (procfs_file ? procfs_file : stdout, "stopThreadCreate ");
351 if (arg1 & PRFS_STOPTTERM)
352 fprintf (procfs_file ? procfs_file : stdout, "stopThreadTerm ");
353 if (arg1 & PRFS_KOLC)
354 fprintf (procfs_file ? procfs_file : stdout, "killOnLastClose ");
355 fprintf (procfs_file ? procfs_file : stdout, "\n");
357 #endif /* PIOCSSPCACT */
359 if (ioctl_table[i].name)
360 fprintf (procfs_file ? procfs_file : stdout,
363 info_verbose ? ioctl_table[i].desc : "");
365 fprintf (procfs_file ? procfs_file : stdout,
366 "ioctl (<unknown %ld (0x%lx)) \n", opcode, opcode);
370 fflush (procfs_file);
373 ret = ioctl (fd, opcode, ptr);
374 if (procfs_trace && ret < 0)
376 fprintf (procfs_file ? procfs_file : stdout,
377 "[ioctl (%s) FAILED! (%s)]\n",
378 ioctl_table[i].name != NULL ?
379 ioctl_table[i].name : "<unknown>",
380 safe_strerror (errno));
382 fflush (procfs_file);
388 #else /* NEW_PROC_API */
390 static struct trans rw_table[] = {
391 #ifdef PCAGENT /* solaris */
392 { PCAGENT, "PCAGENT", "create agent lwp with regs from argument" },
394 { PCCFAULT, "PCCFAULT", "clear current fault" },
395 #ifdef PCCSIG /* solaris */
396 { PCCSIG, "PCCSIG", "clear current signal" },
398 { PCDSTOP, "PCDSTOP", "post stop request" },
399 { PCKILL, "PCKILL", "post a signal" },
400 { PCNICE, "PCNICE", "set nice priority" },
401 #ifdef PCREAD /* solaris */
402 { PCREAD, "PCREAD", "read from the address space" },
403 { PCWRITE, "PCWRITE", "write to the address space" },
405 #ifdef PCRESET /* unixware */
406 { PCRESET, "PCRESET", "unset modes" },
408 { PCRUN, "PCRUN", "make process/lwp runnable" },
409 #ifdef PCSASRS /* solaris 2.7 only */
410 { PCSASRS, "PCSASRS", "set ancillary state registers" },
412 #ifdef PCSCRED /* solaris */
413 { PCSCRED, "PCSCRED", "set process credentials" },
415 { PCSENTRY, "PCSENTRY", "set traced syscall entry set" },
416 { PCSET, "PCSET", "set modes" },
417 { PCSEXIT, "PCSEXIT", "set traced syscall exit set" },
418 { PCSFAULT, "PCSFAULT", "set traced fault set" },
419 { PCSFPREG, "PCSFPREG", "set floating point registers" },
420 { PCSHOLD, "PCSHOLD", "set signal mask" },
421 { PCSREG, "PCSREG", "set general registers" },
422 { PCSSIG, "PCSSIG", "set current signal" },
423 { PCSTOP, "PCSTOP", "post stop request and wait" },
424 { PCSTRACE, "PCSTRACE", "set traced signal set" },
425 #ifdef PCSVADDR /* solaris */
426 { PCSVADDR, "PCSVADDR", "set pc virtual address" },
428 #ifdef PCSXREG /* solaris sparc only */
429 { PCSXREG, "PCSXREG", "set extra registers" },
431 #ifdef PCTWSTOP /* solaris */
432 { PCTWSTOP, "PCTWSTOP", "wait for stop, with timeout arg" },
434 { PCUNKILL, "PCUNKILL", "delete a pending signal" },
435 #ifdef PCUNSET /* solaris */
436 { PCUNSET, "PCUNSET", "unset modes" },
438 #ifdef PCWATCH /* solaris */
439 { PCWATCH, "PCWATCH", "set/unset watched memory area" },
441 { PCWSTOP, "PCWSTOP", "wait for process/lwp to stop, no timeout" },
445 static off_t lseek_offset;
448 write_with_trace (int fd, void *varg, size_t len, char *file, int line)
452 procfs_ctl_t *arg = (procfs_ctl_t *) varg;
457 procfs_ctl_t opcode = arg[0];
458 for (i = 0; rw_table[i].name != NULL; i++)
459 if (rw_table[i].value == opcode)
463 fprintf (procfs_file ? procfs_file : stdout,
464 "%s:%d -- ", file, line);
467 fprintf (procfs_file ? procfs_file : stdout,
468 "write (PCSET, %s) %s\n",
469 arg[1] == PR_FORK ? "PR_FORK" :
470 arg[1] == PR_RLC ? "PR_RLC" :
472 arg[1] == PR_ASYNC ? "PR_ASYNC" :
475 info_verbose ? rw_table[i].desc : "");
481 #if PCRESET != PCUNSET
485 fprintf (procfs_file ? procfs_file : stdout,
486 "write (PCRESET, %s) %s\n",
487 arg[1] == PR_FORK ? "PR_FORK" :
488 arg[1] == PR_RLC ? "PR_RLC" :
490 arg[1] == PR_ASYNC ? "PR_ASYNC" :
493 info_verbose ? rw_table[i].desc : "");
496 fprintf (procfs_file ? procfs_file : stdout,
497 "write (PCSTRACE) ");
498 proc_prettyfprint_signalset (procfs_file ? procfs_file : stdout,
499 (sigset_t *) &arg[1], 0);
502 fprintf (procfs_file ? procfs_file : stdout,
503 "write (PCSFAULT) ");
504 proc_prettyfprint_faultset (procfs_file ? procfs_file : stdout,
505 (fltset_t *) &arg[1], 0);
508 fprintf (procfs_file ? procfs_file : stdout,
509 "write (PCSENTRY) ");
510 proc_prettyfprint_syscalls (procfs_file ? procfs_file : stdout,
511 (sysset_t *) &arg[1], 0);
514 fprintf (procfs_file ? procfs_file : stdout,
516 proc_prettyfprint_syscalls (procfs_file ? procfs_file : stdout,
517 (sysset_t *) &arg[1], 0);
520 fprintf (procfs_file ? procfs_file : stdout,
522 proc_prettyfprint_signalset (procfs_file ? procfs_file : stdout,
523 (sigset_t *) &arg[1], 0);
526 fprintf (procfs_file ? procfs_file : stdout,
528 proc_prettyfprint_signal (procfs_file ? procfs_file : stdout,
529 arg[1] ? ((siginfo_t *) &arg[1])->si_signo
532 fprintf (procfs_file ? procfs_file : stdout, "\n");
535 fprintf (procfs_file ? procfs_file : stdout,
538 fprintf (procfs_file ? procfs_file : stdout, "clearSig ");
539 if (arg[1] & PRCFAULT)
540 fprintf (procfs_file ? procfs_file : stdout, "clearFlt ");
542 fprintf (procfs_file ? procfs_file : stdout, "step ");
543 if (arg[1] & PRSABORT)
544 fprintf (procfs_file ? procfs_file : stdout, "syscallAbort ");
546 fprintf (procfs_file ? procfs_file : stdout, "stopReq ");
548 fprintf (procfs_file ? procfs_file : stdout, "\n");
551 fprintf (procfs_file ? procfs_file : stdout,
553 proc_prettyfprint_signal (procfs_file ? procfs_file : stdout,
555 fprintf (procfs_file ? procfs_file : stdout, "\n");
560 static unsigned char break_insn[] = BREAKPOINT;
562 if (len == sizeof (break_insn) &&
563 memcmp (arg, &break_insn, len) == 0)
564 fprintf (procfs_file ? procfs_file : stdout,
565 "write (<breakpoint at 0x%08lx>) \n",
566 (unsigned long) lseek_offset);
569 if (rw_table[i].name)
570 fprintf (procfs_file ? procfs_file : stdout,
573 info_verbose ? rw_table[i].desc : "");
576 if (lseek_offset != -1)
577 fprintf (procfs_file ? procfs_file : stdout,
578 "write (<unknown>, %lud bytes at 0x%08lx) \n",
579 (unsigned long) len, (unsigned long) lseek_offset);
581 fprintf (procfs_file ? procfs_file : stdout,
582 "write (<unknown>, %lud bytes) \n",
583 (unsigned long) len);
589 fflush (procfs_file);
592 ret = write (fd, (void *) arg, len);
593 if (procfs_trace && ret != len)
595 fprintf (procfs_file ? procfs_file : stdout,
596 "[write (%s) FAILED! (%s)]\n",
597 rw_table[i].name != NULL ?
598 rw_table[i].name : "<unknown>",
599 safe_strerror (errno));
601 fflush (procfs_file);
609 lseek_with_trace (int fd, off_t offset, int whence, char *file, int line)
615 ret = lseek (fd, offset, whence);
617 if (procfs_trace && (ret == -1 || errno != 0))
619 fprintf (procfs_file ? procfs_file : stdout,
620 "[lseek (0x%08lx) FAILED! (%s)]\n",
621 (unsigned long) offset, safe_strerror (errno));
623 fflush (procfs_file);
629 #endif /* NEW_PROC_API */
632 open_with_trace (char *filename, int mode, char *file, int line)
638 ret = open (filename, mode);
642 fprintf (procfs_file ? procfs_file : stdout,
643 "%s:%d -- ", file, line);
647 fprintf (procfs_file ? procfs_file : stdout,
648 "[open FAILED! (%s) line %d]\\n",
649 safe_strerror (errno), line);
653 fprintf (procfs_file ? procfs_file : stdout,
654 "%d = open (%s, ", ret, filename);
655 if (mode == O_RDONLY)
656 fprintf (procfs_file ? procfs_file : stdout, "O_RDONLY) %d\n",
658 else if (mode == O_WRONLY)
659 fprintf (procfs_file ? procfs_file : stdout, "O_WRONLY) %d\n",
661 else if (mode == O_RDWR)
662 fprintf (procfs_file ? procfs_file : stdout, "O_RDWR) %d\n",
666 fflush (procfs_file);
673 close_with_trace (int fd, char *file, int line)
683 fprintf (procfs_file ? procfs_file : stdout,
684 "%s:%d -- ", file, line);
686 fprintf (procfs_file ? procfs_file : stdout,
687 "[close FAILED! (%s)]\n", safe_strerror (errno));
689 fprintf (procfs_file ? procfs_file : stdout,
690 "%d = close (%d)\n", ret, fd);
692 fflush (procfs_file);
699 wait_with_trace (int *wstat, char *file, int line)
707 fprintf (procfs_file ? procfs_file : stdout,
708 "%s:%d -- ", file, line);
709 fprintf (procfs_file ? procfs_file : stdout,
710 "wait (line %d) ", line);
712 fflush (procfs_file);
719 fprintf (procfs_file ? procfs_file : stdout,
720 "[wait FAILED! (%s)]\n", safe_strerror (errno));
722 fprintf (procfs_file ? procfs_file : stdout,
723 "returned pid %d, status 0x%x\n", ret, lstat);
725 fflush (procfs_file);
734 procfs_note (char *msg, char *file, int line)
740 fprintf (procfs_file ? procfs_file : stdout,
741 "%s:%d -- ", file, line);
742 fprintf (procfs_file ? procfs_file : stdout, msg);
744 fflush (procfs_file);
749 proc_prettyfprint_status (long flags, int why, int what, int thread)
755 fprintf (procfs_file ? procfs_file : stdout,
756 "Thread %d: ", thread);
758 proc_prettyfprint_flags (procfs_file ? procfs_file : stdout,
761 if (flags & (PR_STOPPED | PR_ISTOP))
762 proc_prettyfprint_why (procfs_file ? procfs_file : stdout,
765 fflush (procfs_file);
771 _initialize_proc_api (void)
773 struct cmd_list_element *c;
775 c = add_set_cmd ("procfs-trace", no_class,
776 var_boolean, (char *) &procfs_trace,
777 "Set tracing for /proc api calls.\n", &setlist);
779 add_show_from_set (c, &showlist);
780 set_cmd_sfunc (c, set_procfs_trace_cmd);
781 set_cmd_completer (c, filename_completer);
783 c = add_set_cmd ("procfs-file", no_class, var_filename,
784 (char *) &procfs_filename,
785 "Set filename for /proc tracefile.\n", &setlist);
787 add_show_from_set (c, &showlist);
788 set_cmd_sfunc (c, set_procfs_file_cmd);