1 /* Machine independent support for SVR4 /proc (process file system) for GDB.
3 Copyright (C) 1999, 2000, 2001, 2003, 2005 Free Software Foundation, Inc.
5 Written by Michael Snyder at Cygnus Solutions.
6 Based on work by Fred Fish, Stu Grossman, Geoff Noer, and others.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software Foundation,
22 Inc., 51 Franklin Street, Fifth Floor,
23 Boston, MA 02110-1301, USA. */
26 * Pretty-print trace of api calls to the /proc api
27 * (ioctl or read/write calls).
33 #include "completer.h"
35 #if defined (NEW_PROC_API)
36 #define _STRUCTURED_PROC 1
40 #include <sys/types.h>
41 #include <sys/procfs.h>
42 #ifdef HAVE_SYS_PROC_H
43 #include <sys/proc.h> /* for struct proc */
45 #ifdef HAVE_SYS_USER_H
46 #include <sys/user.h> /* for struct user */
48 #include <fcntl.h> /* for O_RDWR etc. */
51 #include "proc-utils.h"
53 /* Much of the information used in the /proc interface, particularly for
54 printing status information, is kept as tables of structures of the
55 following form. These tables can be used to map numeric values to
56 their symbolic names and to a string that describes their specific use. */
59 long value
; /* The numeric value */
60 char *name
; /* The equivalent symbolic value */
61 char *desc
; /* Short description of value */
64 static int procfs_trace
= 0;
65 static FILE *procfs_file
= NULL
;
66 static char *procfs_filename
= "procfs_trace";
69 prepare_to_trace (void)
71 if (procfs_trace
) /* if procfs tracing turned on */
72 if (procfs_file
== NULL
) /* if output file not yet open */
73 if (procfs_filename
!= NULL
) /* if output filename known */
74 procfs_file
= fopen (procfs_filename
, "a"); /* open output file */
78 set_procfs_trace_cmd (char *args
, int from_tty
, struct cmd_list_element
*c
)
80 #if 0 /* not sure what I might actually need to do here, if anything */
87 set_procfs_file_cmd (char *args
, int from_tty
, struct cmd_list_element
*c
)
89 /* Just changed the filename for procfs tracing.
90 If a file was already open, close it. */
99 static struct trans ioctl_table
[] = {
100 #ifdef PIOCACINFO /* irix */
101 { PIOCACINFO
, "PIOCACINFO", "get process account info" },
103 { PIOCACTION
, "PIOCACTION", "get signal action structs" },
104 #ifdef PIOCARGUMENTS /* osf */
105 { PIOCARGUMENTS
, "PIOCARGUMENTS", "command line args" },
107 #ifdef PIOCAUXV /* solaris aux vectors */
108 { PIOCAUXV
, "PIOCAUXV", "get aux vector" },
109 { PIOCNAUXV
, "PIOCNAUXV", "get number of aux vector entries" },
111 { PIOCCFAULT
, "PIOCCFAULT", "clear current fault" },
112 { PIOCCRED
, "PIOCCRED", "get process credentials" },
113 #ifdef PIOCENEVCTRS /* irix event counters */
114 { PIOCENEVCTRS
, "PIOCENEVCTRS", "acquire and start event counters" },
115 { PIOCGETEVCTRL
, "PIOCGETEVCTRL", "get control info of event counters" },
116 { PIOCGETEVCTRS
, "PIOCGETEVCTRS", "dump event counters" },
117 { PIOCGETPREVCTRS
, "PIOCGETPREVCTRS", "dump event counters & prusage info" },
118 { PIOCRELEVCTRS
, "PIOCRELEVCTRS", "release/stop event counters" },
119 { PIOCSETEVCTRL
, "PIOCSETEVCTRL", "set control info of event counters" },
120 { PIOCGETPTIMER
, "PIOCGETPTIMER", "get process timers" },
121 #endif /* irix event counters */
122 { PIOCGENTRY
, "PIOCGENTRY", "get traced syscall entry set" },
123 #if defined (PIOCGETPR)
124 { PIOCGETPR
, "PIOCGETPR", "read struct proc" },
126 #if defined (PIOCGETU)
127 { PIOCGETU
, "PIOCGETU", "read user area" },
129 #if defined (PIOCGETUTK) && (defined(KERNEL) || defined(SHOW_UTT)) /* osf */
130 { PIOCGETUTK
, "PIOCGETUTK", "get the utask struct" },
132 { PIOCGEXIT
, "PIOCGEXIT", "get traced syscall exit set" },
133 { PIOCGFAULT
, "PIOCGFAULT", "get traced fault set" },
134 #ifdef PIOCGFPCR /* osf */
135 { PIOCGFPCR
, "PIOCGFPCR", "get FP control register" },
136 { PIOCSFPCR
, "PIOCSFPCR", "set FP conrtol register" },
138 { PIOCGFPREG
, "PIOCGFPREG", "get floating point registers" },
139 { PIOCGHOLD
, "PIOCGHOLD", "get held signal set" },
140 { PIOCGREG
, "PIOCGREG", "get general registers" },
141 { PIOCGROUPS
, "PIOCGROUPS", "get supplementary groups" },
142 #ifdef PIOCGSPCACT /* osf */
143 { PIOCGSPCACT
, "PIOCGSPCACT", "get special action" },
144 { PIOCSSPCACT
, "PIOCSSPCACT", "set special action" },
146 { PIOCGTRACE
, "PIOCGTRACE", "get traced signal set" },
147 #ifdef PIOCGWATCH /* irix watchpoints */
148 { PIOCGWATCH
, "PIOCGWATCH", "get watchpoint" },
149 { PIOCSWATCH
, "PIOCSWATCH", "set watchpoint" },
150 { PIOCNWATCH
, "PIOCNWATCH", "get number of watchpoints" },
151 #endif /* irix watchpoints */
152 #ifdef PIOCGWIN /* solaris sparc */
153 { PIOCGWIN
, "PIOCGWIN", "get gwindows_t" },
155 #ifdef PIOCGXREG /* solaris sparc extra regs */
156 { PIOCGXREGSIZE
, "PIOCXREGSIZE", "get extra register state size" },
157 { PIOCGXREG
, "PIOCGXREG", "get extra register state" },
158 { PIOCSXREG
, "PIOCSXREG", "set extra register state" },
160 { PIOCKILL
, "PIOCKILL", "send signal" },
161 #ifdef PIOCLDT /* solaris i386 */
162 { PIOCLDT
, "PIOCLDT", "get LDT" },
163 { PIOCNLDT
, "PIOCNLDT", "get number of LDT entries" },
165 #ifdef PIOCLSTATUS /* solaris and unixware */
166 { PIOCLSTATUS
, "PIOCLSTATUS", "get status of all lwps" },
167 { PIOCLUSAGE
, "PIOCLUSAGE", "get resource usage of all lwps" },
168 { PIOCOPENLWP
, "PIOCOPENLWP", "get lwp file descriptor" },
169 { PIOCLWPIDS
, "PIOCLWPIDS", "get lwp identifiers" },
171 { PIOCMAP
, "PIOCMAP", "get memory map information" },
172 { PIOCMAXSIG
, "PIOCMAXSIG", "get max signal number" },
173 { PIOCNICE
, "PIOCNICE", "set nice priority" },
174 { PIOCNMAP
, "PIOCNMAP", "get number of memory mappings" },
175 { PIOCOPENM
, "PIOCOPENM", "open mapped object for reading" },
176 #ifdef PIOCOPENMOBS /* osf */
177 { PIOCOPENMOBS
, "PIOCOPENMOBS", "open mapped object" },
179 #ifdef PIOCOPENPD /* solaris */
180 { PIOCOPENPD
, "PIOCOPENPD", "get page data file descriptor" },
182 { PIOCPSINFO
, "PIOCPSINFO", "get ps(1) information" },
183 { PIOCRESET
, "PIOCRESET", "reset process flags" },
184 { PIOCRFORK
, "PIOCRFORK", "reset inherit-on-fork flag" },
185 { PIOCRRLC
, "PIOCRRLC", "reset run-on-last-close flag" },
186 { PIOCRUN
, "PIOCRUN", "make process runnable" },
187 #ifdef PIOCSAVECCNTRS /* irix */
188 { PIOCSAVECCNTRS
, "PIOCSAVECCNTRS", "parent gets child cntrs" },
190 { PIOCSENTRY
, "PIOCSENTRY", "set traced syscall entry set" },
191 { PIOCSET
, "PIOCSET", "set process flags" },
192 { PIOCSEXIT
, "PIOCSEXIT", "set traced syscall exit set" },
193 { PIOCSFAULT
, "PIOCSFAULT", "set traced fault set" },
194 { PIOCSFORK
, "PIOCSFORK", "set inherit-on-fork flag" },
195 { PIOCSFPREG
, "PIOCSFPREG", "set floating point registers" },
196 { PIOCSHOLD
, "PIOCSHOLD", "set held signal set" },
197 { PIOCSREG
, "PIOCSREG", "set general registers" },
198 { PIOCSRLC
, "PIOCSRLC", "set run-on-last-close flag" },
199 { PIOCSSIG
, "PIOCSSIG", "set current signal" },
200 { PIOCSTATUS
, "PIOCSTATUS", "get process status" },
201 { PIOCSTOP
, "PIOCSTOP", "post stop request" },
202 { PIOCSTRACE
, "PIOCSTRACE", "set traced signal set" },
203 { PIOCUNKILL
, "PIOCUNKILL", "delete a signal" },
204 #ifdef PIOCUSAGE /* solaris */
205 { PIOCUSAGE
, "PIOCUSAGE", "get resource usage" },
207 { PIOCWSTOP
, "PIOCWSTOP", "wait for process to stop" },
209 #ifdef PIOCNTHR /* osf threads */
210 { PIOCNTHR
, "PIOCNTHR", "get thread count" },
211 { PIOCRTINH
, "PIOCRTINH", "reset inherit-on-thread-creation" },
212 { PIOCSTINH
, "PIOCSTINH", "set inherit-on-thread-creation" },
213 { PIOCTLIST
, "PIOCTLIST", "get thread ids" },
214 { PIOCXPTH
, "PIOCXPTH", "translate port to thread handle" },
215 { PIOCTRUN
, "PIOCTRUN", "make thread runnable" },
216 { PIOCTSTATUS
, "PIOCTSTATUS", "get thread status" },
217 { PIOCTSTOP
, "PIOCTSTOP", "stop a thread" },
218 /* ... TGTRACE TSTRACE TSSIG TKILL TUNKILL TCFAULT TGFAULT TSFAULT
219 TGFPREG TSFPREG TGREG TSREG TACTION TTERM TABRUN TGENTRY TSENTRY
220 TGEXIT TSEXIT TSHOLD ... thread functions */
221 #endif /* osf threads */
226 ioctl_with_trace (int fd
, long opcode
, void *ptr
, char *file
, int line
)
236 for (i
= 0; ioctl_table
[i
].name
!= NULL
; i
++)
237 if (ioctl_table
[i
].value
== opcode
)
241 fprintf (procfs_file
? procfs_file
: stdout
,
242 "%s:%d -- ", file
, line
);
245 arg1
= ptr
? *(long *) ptr
: 0;
246 fprintf (procfs_file
? procfs_file
: stdout
,
247 "ioctl (PIOCSET, %s) %s\n",
248 arg1
== PR_FORK
? "PR_FORK" :
249 arg1
== PR_RLC
? "PR_RLC" :
251 arg1
== PR_ASYNC
? "PR_ASYNC" :
254 info_verbose
? ioctl_table
[i
].desc
: "");
257 arg1
= ptr
? *(long *) ptr
: 0;
258 fprintf (procfs_file
? procfs_file
: stdout
,
259 "ioctl (PIOCRESET, %s) %s\n",
260 arg1
== PR_FORK
? "PR_FORK" :
261 arg1
== PR_RLC
? "PR_RLC" :
263 arg1
== PR_ASYNC
? "PR_ASYNC" :
266 info_verbose
? ioctl_table
[i
].desc
: "");
269 fprintf (procfs_file
? procfs_file
: stdout
,
270 "ioctl (PIOCSTRACE) ");
271 proc_prettyfprint_signalset (procfs_file
? procfs_file
: stdout
,
272 (sigset_t
*) ptr
, 0);
275 fprintf (procfs_file
? procfs_file
: stdout
,
277 opcode
== PIOCSFAULT
? "PIOCSFAULT" : "PIOCGFAULT");
278 proc_prettyfprint_faultset (procfs_file
? procfs_file
: stdout
,
279 (fltset_t
*) ptr
, 0);
282 fprintf (procfs_file
? procfs_file
: stdout
,
284 opcode
== PIOCSENTRY
? "PIOCSENTRY" : "PIOCGENTRY");
285 proc_prettyfprint_syscalls (procfs_file
? procfs_file
: stdout
,
286 (sysset_t
*) ptr
, 0);
289 fprintf (procfs_file
? procfs_file
: stdout
,
291 opcode
== PIOCSEXIT
? "PIOCSEXIT" : "PIOCGEXIT");
292 proc_prettyfprint_syscalls (procfs_file
? procfs_file
: stdout
,
293 (sysset_t
*) ptr
, 0);
296 fprintf (procfs_file
? procfs_file
: stdout
,
298 opcode
== PIOCSHOLD
? "PIOCSHOLD" : "PIOCGHOLD");
299 proc_prettyfprint_signalset (procfs_file
? procfs_file
: stdout
,
300 (sigset_t
*) ptr
, 0);
303 fprintf (procfs_file
? procfs_file
: stdout
,
304 "ioctl (PIOCSSIG) ");
305 proc_prettyfprint_signal (procfs_file
? procfs_file
: stdout
,
306 ptr
? ((siginfo_t
*) ptr
)->si_signo
: 0,
308 fprintf (procfs_file
? procfs_file
: stdout
, "\n");
311 fprintf (procfs_file
? procfs_file
: stdout
,
314 arg1
= ptr
? *(long *) ptr
: 0;
316 fprintf (procfs_file
? procfs_file
: stdout
, "clearSig ");
318 fprintf (procfs_file
? procfs_file
: stdout
, "clearFlt ");
320 fprintf (procfs_file
? procfs_file
: stdout
, "setTrace ");
322 fprintf (procfs_file
? procfs_file
: stdout
, "setHold ");
324 fprintf (procfs_file
? procfs_file
: stdout
, "setFlt ");
326 fprintf (procfs_file
? procfs_file
: stdout
, "setVaddr ");
328 fprintf (procfs_file
? procfs_file
: stdout
, "step ");
330 fprintf (procfs_file
? procfs_file
: stdout
, "syscallAbort ");
332 fprintf (procfs_file
? procfs_file
: stdout
, "stopReq ");
334 fprintf (procfs_file
? procfs_file
: stdout
, "\n");
337 fprintf (procfs_file
? procfs_file
: stdout
,
338 "ioctl (PIOCKILL) ");
339 proc_prettyfprint_signal (procfs_file
? procfs_file
: stdout
,
340 ptr
? *(long *) ptr
: 0, 0);
341 fprintf (procfs_file
? procfs_file
: stdout
, "\n");
345 fprintf (procfs_file
? procfs_file
: stdout
,
346 "ioctl (PIOCSSPCACT) ");
347 arg1
= ptr
? *(long *) ptr
: 0;
348 if (arg1
& PRFS_STOPFORK
)
349 fprintf (procfs_file
? procfs_file
: stdout
, "stopFork ");
350 if (arg1
& PRFS_STOPEXEC
)
351 fprintf (procfs_file
? procfs_file
: stdout
, "stopExec ");
352 if (arg1
& PRFS_STOPTERM
)
353 fprintf (procfs_file
? procfs_file
: stdout
, "stopTerm ");
354 if (arg1
& PRFS_STOPTCR
)
355 fprintf (procfs_file
? procfs_file
: stdout
, "stopThreadCreate ");
356 if (arg1
& PRFS_STOPTTERM
)
357 fprintf (procfs_file
? procfs_file
: stdout
, "stopThreadTerm ");
358 if (arg1
& PRFS_KOLC
)
359 fprintf (procfs_file
? procfs_file
: stdout
, "killOnLastClose ");
360 fprintf (procfs_file
? procfs_file
: stdout
, "\n");
362 #endif /* PIOCSSPCACT */
364 if (ioctl_table
[i
].name
)
365 fprintf (procfs_file
? procfs_file
: stdout
,
368 info_verbose
? ioctl_table
[i
].desc
: "");
370 fprintf (procfs_file
? procfs_file
: stdout
,
371 "ioctl (<unknown %ld (0x%lx)) \n", opcode
, opcode
);
375 fflush (procfs_file
);
378 ret
= ioctl (fd
, opcode
, ptr
);
379 if (procfs_trace
&& ret
< 0)
381 fprintf (procfs_file
? procfs_file
: stdout
,
382 "[ioctl (%s) FAILED! (%s)]\n",
383 ioctl_table
[i
].name
!= NULL
?
384 ioctl_table
[i
].name
: "<unknown>",
385 safe_strerror (errno
));
387 fflush (procfs_file
);
393 #else /* NEW_PROC_API */
395 static struct trans rw_table
[] = {
396 #ifdef PCAGENT /* solaris */
397 { PCAGENT
, "PCAGENT", "create agent lwp with regs from argument" },
399 { PCCFAULT
, "PCCFAULT", "clear current fault" },
400 #ifdef PCCSIG /* solaris */
401 { PCCSIG
, "PCCSIG", "clear current signal" },
403 #ifdef PCDSTOP /* solaris */
404 { PCDSTOP
, "PCDSTOP", "post stop request" },
406 { PCKILL
, "PCKILL", "post a signal" },
407 #ifdef PCNICE /* solaris */
408 { PCNICE
, "PCNICE", "set nice priority" },
410 #ifdef PCREAD /* solaris */
411 { PCREAD
, "PCREAD", "read from the address space" },
412 { PCWRITE
, "PCWRITE", "write to the address space" },
414 #ifdef PCRESET /* unixware */
415 { PCRESET
, "PCRESET", "unset modes" },
417 { PCRUN
, "PCRUN", "make process/lwp runnable" },
418 #ifdef PCSASRS /* solaris 2.7 only */
419 { PCSASRS
, "PCSASRS", "set ancillary state registers" },
421 #ifdef PCSCRED /* solaris */
422 { PCSCRED
, "PCSCRED", "set process credentials" },
424 { PCSENTRY
, "PCSENTRY", "set traced syscall entry set" },
425 { PCSET
, "PCSET", "set modes" },
426 { PCSEXIT
, "PCSEXIT", "set traced syscall exit set" },
427 { PCSFAULT
, "PCSFAULT", "set traced fault set" },
428 { PCSFPREG
, "PCSFPREG", "set floating point registers" },
429 #ifdef PCSHOLD /* solaris */
430 { PCSHOLD
, "PCSHOLD", "set signal mask" },
432 { PCSREG
, "PCSREG", "set general registers" },
433 { PCSSIG
, "PCSSIG", "set current signal" },
434 { PCSTOP
, "PCSTOP", "post stop request and wait" },
435 { PCSTRACE
, "PCSTRACE", "set traced signal set" },
436 #ifdef PCSVADDR /* solaris */
437 { PCSVADDR
, "PCSVADDR", "set pc virtual address" },
439 #ifdef PCSXREG /* solaris sparc only */
440 { PCSXREG
, "PCSXREG", "set extra registers" },
442 #ifdef PCTWSTOP /* solaris */
443 { PCTWSTOP
, "PCTWSTOP", "wait for stop, with timeout arg" },
445 #ifdef PCUNKILL /* solaris */
446 { PCUNKILL
, "PCUNKILL", "delete a pending signal" },
448 #ifdef PCUNSET /* solaris */
449 { PCUNSET
, "PCUNSET", "unset modes" },
451 #ifdef PCWATCH /* solaris */
452 { PCWATCH
, "PCWATCH", "set/unset watched memory area" },
454 { PCWSTOP
, "PCWSTOP", "wait for process/lwp to stop, no timeout" },
458 static off_t lseek_offset
;
461 write_with_trace (int fd
, void *varg
, size_t len
, char *file
, int line
)
463 int i
= ARRAY_SIZE (rw_table
) - 1;
465 procfs_ctl_t
*arg
= (procfs_ctl_t
*) varg
;
470 procfs_ctl_t opcode
= arg
[0];
471 for (i
= 0; rw_table
[i
].name
!= NULL
; i
++)
472 if (rw_table
[i
].value
== opcode
)
476 fprintf (procfs_file
? procfs_file
: stdout
,
477 "%s:%d -- ", file
, line
);
480 fprintf (procfs_file
? procfs_file
: stdout
,
481 "write (PCSET, %s) %s\n",
482 arg
[1] == PR_FORK
? "PR_FORK" :
483 arg
[1] == PR_RLC
? "PR_RLC" :
485 arg
[1] == PR_ASYNC
? "PR_ASYNC" :
488 info_verbose
? rw_table
[i
].desc
: "");
494 #if PCRESET != PCUNSET
498 fprintf (procfs_file
? procfs_file
: stdout
,
499 "write (PCRESET, %s) %s\n",
500 arg
[1] == PR_FORK
? "PR_FORK" :
501 arg
[1] == PR_RLC
? "PR_RLC" :
503 arg
[1] == PR_ASYNC
? "PR_ASYNC" :
506 info_verbose
? rw_table
[i
].desc
: "");
509 fprintf (procfs_file
? procfs_file
: stdout
,
510 "write (PCSTRACE) ");
511 proc_prettyfprint_signalset (procfs_file
? procfs_file
: stdout
,
512 (sigset_t
*) &arg
[1], 0);
515 fprintf (procfs_file
? procfs_file
: stdout
,
516 "write (PCSFAULT) ");
517 proc_prettyfprint_faultset (procfs_file
? procfs_file
: stdout
,
518 (fltset_t
*) &arg
[1], 0);
521 fprintf (procfs_file
? procfs_file
: stdout
,
522 "write (PCSENTRY) ");
523 proc_prettyfprint_syscalls (procfs_file
? procfs_file
: stdout
,
524 (sysset_t
*) &arg
[1], 0);
527 fprintf (procfs_file
? procfs_file
: stdout
,
529 proc_prettyfprint_syscalls (procfs_file
? procfs_file
: stdout
,
530 (sysset_t
*) &arg
[1], 0);
534 fprintf (procfs_file
? procfs_file
: stdout
,
536 proc_prettyfprint_signalset (procfs_file
? procfs_file
: stdout
,
537 (sigset_t
*) &arg
[1], 0);
541 fprintf (procfs_file
? procfs_file
: stdout
,
543 proc_prettyfprint_signal (procfs_file
? procfs_file
: stdout
,
544 arg
[1] ? ((siginfo_t
*) &arg
[1])->si_signo
547 fprintf (procfs_file
? procfs_file
: stdout
, "\n");
550 fprintf (procfs_file
? procfs_file
: stdout
,
553 fprintf (procfs_file
? procfs_file
: stdout
, "clearSig ");
554 if (arg
[1] & PRCFAULT
)
555 fprintf (procfs_file
? procfs_file
: stdout
, "clearFlt ");
557 fprintf (procfs_file
? procfs_file
: stdout
, "step ");
559 if (arg
[1] & PRSABORT
)
560 fprintf (procfs_file
? procfs_file
: stdout
, "syscallAbort ");
564 fprintf (procfs_file
? procfs_file
: stdout
, "stopReq ");
567 fprintf (procfs_file
? procfs_file
: stdout
, "\n");
570 fprintf (procfs_file
? procfs_file
: stdout
,
572 proc_prettyfprint_signal (procfs_file
? procfs_file
: stdout
,
574 fprintf (procfs_file
? procfs_file
: stdout
, "\n");
578 if (rw_table
[i
].name
)
579 fprintf (procfs_file
? procfs_file
: stdout
,
582 info_verbose
? rw_table
[i
].desc
: "");
585 if (lseek_offset
!= -1)
586 fprintf (procfs_file
? procfs_file
: stdout
,
587 "write (<unknown>, %lud bytes at 0x%08lx) \n",
588 (unsigned long) len
, (unsigned long) lseek_offset
);
590 fprintf (procfs_file
? procfs_file
: stdout
,
591 "write (<unknown>, %lud bytes) \n",
592 (unsigned long) len
);
598 fflush (procfs_file
);
601 ret
= write (fd
, (void *) arg
, len
);
602 if (procfs_trace
&& ret
!= len
)
604 fprintf (procfs_file
? procfs_file
: stdout
,
605 "[write (%s) FAILED! (%s)]\n",
606 rw_table
[i
].name
!= NULL
?
607 rw_table
[i
].name
: "<unknown>",
608 safe_strerror (errno
));
610 fflush (procfs_file
);
618 lseek_with_trace (int fd
, off_t offset
, int whence
, char *file
, int line
)
624 ret
= lseek (fd
, offset
, whence
);
626 if (procfs_trace
&& (ret
== -1 || errno
!= 0))
628 fprintf (procfs_file
? procfs_file
: stdout
,
629 "[lseek (0x%08lx) FAILED! (%s)]\n",
630 (unsigned long) offset
, safe_strerror (errno
));
632 fflush (procfs_file
);
638 #endif /* NEW_PROC_API */
641 open_with_trace (char *filename
, int mode
, char *file
, int line
)
647 ret
= open (filename
, mode
);
651 fprintf (procfs_file
? procfs_file
: stdout
,
652 "%s:%d -- ", file
, line
);
656 fprintf (procfs_file
? procfs_file
: stdout
,
657 "[open FAILED! (%s) line %d]\\n",
658 safe_strerror (errno
), line
);
662 fprintf (procfs_file
? procfs_file
: stdout
,
663 "%d = open (%s, ", ret
, filename
);
664 if (mode
== O_RDONLY
)
665 fprintf (procfs_file
? procfs_file
: stdout
, "O_RDONLY) %d\n",
667 else if (mode
== O_WRONLY
)
668 fprintf (procfs_file
? procfs_file
: stdout
, "O_WRONLY) %d\n",
670 else if (mode
== O_RDWR
)
671 fprintf (procfs_file
? procfs_file
: stdout
, "O_RDWR) %d\n",
675 fflush (procfs_file
);
682 close_with_trace (int fd
, char *file
, int line
)
692 fprintf (procfs_file
? procfs_file
: stdout
,
693 "%s:%d -- ", file
, line
);
695 fprintf (procfs_file
? procfs_file
: stdout
,
696 "[close FAILED! (%s)]\n", safe_strerror (errno
));
698 fprintf (procfs_file
? procfs_file
: stdout
,
699 "%d = close (%d)\n", ret
, fd
);
701 fflush (procfs_file
);
708 wait_with_trace (int *wstat
, char *file
, int line
)
716 fprintf (procfs_file
? procfs_file
: stdout
,
717 "%s:%d -- ", file
, line
);
718 fprintf (procfs_file
? procfs_file
: stdout
,
719 "wait (line %d) ", line
);
721 fflush (procfs_file
);
728 fprintf (procfs_file
? procfs_file
: stdout
,
729 "[wait FAILED! (%s)]\n", safe_strerror (errno
));
731 fprintf (procfs_file
? procfs_file
: stdout
,
732 "returned pid %d, status 0x%x\n", ret
, lstat
);
734 fflush (procfs_file
);
743 procfs_note (char *msg
, char *file
, int line
)
749 fprintf (procfs_file
? procfs_file
: stdout
,
750 "%s:%d -- ", file
, line
);
751 fprintf (procfs_file
? procfs_file
: stdout
, "%s", msg
);
753 fflush (procfs_file
);
758 proc_prettyfprint_status (long flags
, int why
, int what
, int thread
)
764 fprintf (procfs_file
? procfs_file
: stdout
,
765 "Thread %d: ", thread
);
767 proc_prettyfprint_flags (procfs_file
? procfs_file
: stdout
,
770 if (flags
& (PR_STOPPED
| PR_ISTOP
))
771 proc_prettyfprint_why (procfs_file
? procfs_file
: stdout
,
774 fflush (procfs_file
);
780 _initialize_proc_api (void)
782 struct cmd_list_element
*c
;
784 add_setshow_boolean_cmd ("procfs-trace", no_class
, &procfs_trace
, _("\
785 Set tracing for /proc api calls."), _("\
786 Show tracing for /proc api calls."), NULL
,
787 set_procfs_trace_cmd
,
788 NULL
, /* FIXME: i18n: */
789 &setlist
, &showlist
);
791 add_setshow_filename_cmd ("procfs-file", no_class
, &procfs_filename
, _("\
792 Set filename for /proc tracefile."), _("\
793 Show filename for /proc tracefile."), NULL
,
795 NULL
, /* FIXME: i18n: */
796 &setlist
, &showlist
);
This page took 0.046124 seconds and 4 git commands to generate.