1 /* Machine independent support for SVR4 /proc (process file system) for GDB.
3 Copyright (C) 1999-2017 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 3 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, see <http://www.gnu.org/licenses/>. */
24 * Pretty-print trace of api calls to the /proc api
25 * (ioctl or read/write calls).
31 #include "completer.h"
33 #if defined (NEW_PROC_API)
34 #define _STRUCTURED_PROC 1
37 #include <sys/types.h>
38 #include <sys/procfs.h>
39 #ifdef HAVE_SYS_PROC_H
40 #include <sys/proc.h> /* for struct proc */
42 #ifdef HAVE_SYS_USER_H
43 #include <sys/user.h> /* for struct user */
45 #include <fcntl.h> /* for O_RDWR etc. */
48 #include "proc-utils.h"
50 /* Much of the information used in the /proc interface, particularly for
51 printing status information, is kept as tables of structures of the
52 following form. These tables can be used to map numeric values to
53 their symbolic names and to a string that describes their specific use. */
56 long value
; /* The numeric value */
57 const char *name
; /* The equivalent symbolic value */
58 const char *desc
; /* Short description of value */
61 static int procfs_trace
= 0;
62 static FILE *procfs_file
= NULL
;
63 static char *procfs_filename
;
66 prepare_to_trace (void)
68 if (procfs_trace
) /* if procfs tracing turned on */
69 if (procfs_file
== NULL
) /* if output file not yet open */
70 procfs_file
= fopen (procfs_filename
, "a"); /* open output file */
74 set_procfs_trace_cmd (char *args
, int from_tty
, struct cmd_list_element
*c
)
76 #if 0 /* not sure what I might actually need to do here, if anything */
83 set_procfs_file_cmd (char *args
, int from_tty
, struct cmd_list_element
*c
)
85 /* Just changed the filename for procfs tracing.
86 If a file was already open, close it. */
95 static struct trans ioctl_table
[] = {
96 #ifdef PIOCACINFO /* irix */
97 { PIOCACINFO
, "PIOCACINFO", "get process account info" },
99 { PIOCACTION
, "PIOCACTION", "get signal action structs" },
100 #ifdef PIOCARGUMENTS /* osf */
101 { PIOCARGUMENTS
, "PIOCARGUMENTS", "command line args" },
103 #ifdef PIOCAUXV /* solaris aux vectors */
104 { PIOCAUXV
, "PIOCAUXV", "get aux vector" },
105 { PIOCNAUXV
, "PIOCNAUXV", "get number of aux vector entries" },
107 { PIOCCFAULT
, "PIOCCFAULT", "clear current fault" },
108 { PIOCCRED
, "PIOCCRED", "get process credentials" },
109 #ifdef PIOCENEVCTRS /* irix event counters */
110 { PIOCENEVCTRS
, "PIOCENEVCTRS", "acquire and start event counters" },
111 { PIOCGETEVCTRL
, "PIOCGETEVCTRL", "get control info of event counters" },
112 { PIOCGETEVCTRS
, "PIOCGETEVCTRS", "dump event counters" },
113 { PIOCGETPREVCTRS
, "PIOCGETPREVCTRS", "dump event counters & prusage info" },
114 { PIOCRELEVCTRS
, "PIOCRELEVCTRS", "release/stop event counters" },
115 { PIOCSETEVCTRL
, "PIOCSETEVCTRL", "set control info of event counters" },
116 { PIOCGETPTIMER
, "PIOCGETPTIMER", "get process timers" },
117 #endif /* irix event counters */
118 { PIOCGENTRY
, "PIOCGENTRY", "get traced syscall entry set" },
119 #if defined (PIOCGETPR)
120 { PIOCGETPR
, "PIOCGETPR", "read struct proc" },
122 #if defined (PIOCGETU)
123 { PIOCGETU
, "PIOCGETU", "read user area" },
125 #if defined (PIOCGETUTK) && (defined(KERNEL) || defined(SHOW_UTT)) /* osf */
126 { PIOCGETUTK
, "PIOCGETUTK", "get the utask struct" },
128 { PIOCGEXIT
, "PIOCGEXIT", "get traced syscall exit set" },
129 { PIOCGFAULT
, "PIOCGFAULT", "get traced fault set" },
130 #ifdef PIOCGFPCR /* osf */
131 { PIOCGFPCR
, "PIOCGFPCR", "get FP control register" },
132 { PIOCSFPCR
, "PIOCSFPCR", "set FP conrtol register" },
134 { PIOCGFPREG
, "PIOCGFPREG", "get floating point registers" },
135 { PIOCGHOLD
, "PIOCGHOLD", "get held signal set" },
136 { PIOCGREG
, "PIOCGREG", "get general registers" },
137 { PIOCGROUPS
, "PIOCGROUPS", "get supplementary groups" },
138 #ifdef PIOCGSPCACT /* osf */
139 { PIOCGSPCACT
, "PIOCGSPCACT", "get special action" },
140 { PIOCSSPCACT
, "PIOCSSPCACT", "set special action" },
142 { PIOCGTRACE
, "PIOCGTRACE", "get traced signal set" },
143 #ifdef PIOCGWATCH /* irix watchpoints */
144 { PIOCGWATCH
, "PIOCGWATCH", "get watchpoint" },
145 { PIOCSWATCH
, "PIOCSWATCH", "set watchpoint" },
146 { PIOCNWATCH
, "PIOCNWATCH", "get number of watchpoints" },
147 #endif /* irix watchpoints */
148 #ifdef PIOCGWIN /* solaris sparc */
149 { PIOCGWIN
, "PIOCGWIN", "get gwindows_t" },
151 #ifdef PIOCGXREG /* solaris sparc extra regs */
152 { PIOCGXREGSIZE
, "PIOCXREGSIZE", "get extra register state size" },
153 { PIOCGXREG
, "PIOCGXREG", "get extra register state" },
154 { PIOCSXREG
, "PIOCSXREG", "set extra register state" },
156 { PIOCKILL
, "PIOCKILL", "send signal" },
157 #ifdef PIOCLDT /* solaris i386 */
158 { PIOCLDT
, "PIOCLDT", "get LDT" },
159 { PIOCNLDT
, "PIOCNLDT", "get number of LDT entries" },
161 #ifdef PIOCLSTATUS /* solaris */
162 { PIOCLSTATUS
, "PIOCLSTATUS", "get status of all lwps" },
163 { PIOCLUSAGE
, "PIOCLUSAGE", "get resource usage of all lwps" },
164 { PIOCOPENLWP
, "PIOCOPENLWP", "get lwp file descriptor" },
165 { PIOCLWPIDS
, "PIOCLWPIDS", "get lwp identifiers" },
167 { PIOCMAP
, "PIOCMAP", "get memory map information" },
168 { PIOCMAXSIG
, "PIOCMAXSIG", "get max signal number" },
169 { PIOCNICE
, "PIOCNICE", "set nice priority" },
170 { PIOCNMAP
, "PIOCNMAP", "get number of memory mappings" },
171 { PIOCOPENM
, "PIOCOPENM", "open mapped object for reading" },
172 #ifdef PIOCOPENMOBS /* osf */
173 { PIOCOPENMOBS
, "PIOCOPENMOBS", "open mapped object" },
175 #ifdef PIOCOPENPD /* solaris */
176 { PIOCOPENPD
, "PIOCOPENPD", "get page data file descriptor" },
178 { PIOCPSINFO
, "PIOCPSINFO", "get ps(1) information" },
179 { PIOCRESET
, "PIOCRESET", "reset process flags" },
180 { PIOCRFORK
, "PIOCRFORK", "reset inherit-on-fork flag" },
181 { PIOCRRLC
, "PIOCRRLC", "reset run-on-last-close flag" },
182 { PIOCRUN
, "PIOCRUN", "make process runnable" },
183 #ifdef PIOCSAVECCNTRS /* irix */
184 { PIOCSAVECCNTRS
, "PIOCSAVECCNTRS", "parent gets child cntrs" },
186 { PIOCSENTRY
, "PIOCSENTRY", "set traced syscall entry set" },
187 { PIOCSET
, "PIOCSET", "set process flags" },
188 { PIOCSEXIT
, "PIOCSEXIT", "set traced syscall exit set" },
189 { PIOCSFAULT
, "PIOCSFAULT", "set traced fault set" },
190 { PIOCSFORK
, "PIOCSFORK", "set inherit-on-fork flag" },
191 { PIOCSFPREG
, "PIOCSFPREG", "set floating point registers" },
192 { PIOCSHOLD
, "PIOCSHOLD", "set held signal set" },
193 { PIOCSREG
, "PIOCSREG", "set general registers" },
194 { PIOCSRLC
, "PIOCSRLC", "set run-on-last-close flag" },
195 { PIOCSSIG
, "PIOCSSIG", "set current signal" },
196 { PIOCSTATUS
, "PIOCSTATUS", "get process status" },
197 { PIOCSTOP
, "PIOCSTOP", "post stop request" },
198 { PIOCSTRACE
, "PIOCSTRACE", "set traced signal set" },
199 { PIOCUNKILL
, "PIOCUNKILL", "delete a signal" },
200 #ifdef PIOCUSAGE /* solaris */
201 { PIOCUSAGE
, "PIOCUSAGE", "get resource usage" },
203 { PIOCWSTOP
, "PIOCWSTOP", "wait for process to stop" },
205 #ifdef PIOCNTHR /* osf threads */
206 { PIOCNTHR
, "PIOCNTHR", "get thread count" },
207 { PIOCRTINH
, "PIOCRTINH", "reset inherit-on-thread-creation" },
208 { PIOCSTINH
, "PIOCSTINH", "set inherit-on-thread-creation" },
209 { PIOCTLIST
, "PIOCTLIST", "get thread ids" },
210 { PIOCXPTH
, "PIOCXPTH", "translate port to thread handle" },
211 { PIOCTRUN
, "PIOCTRUN", "make thread runnable" },
212 { PIOCTSTATUS
, "PIOCTSTATUS", "get thread status" },
213 { PIOCTSTOP
, "PIOCTSTOP", "stop a thread" },
214 /* ... TGTRACE TSTRACE TSSIG TKILL TUNKILL TCFAULT TGFAULT TSFAULT
215 TGFPREG TSFPREG TGREG TSREG TACTION TTERM TABRUN TGENTRY TSENTRY
216 TGEXIT TSEXIT TSHOLD ... thread functions */
217 #endif /* osf threads */
222 ioctl_with_trace (int fd
, long opcode
, void *ptr
, char *file
, int line
)
232 for (i
= 0; ioctl_table
[i
].name
!= NULL
; i
++)
233 if (ioctl_table
[i
].value
== opcode
)
237 fprintf (procfs_file
? procfs_file
: stdout
,
238 "%s:%d -- ", file
, line
);
241 arg1
= ptr
? *(long *) ptr
: 0;
242 fprintf (procfs_file
? procfs_file
: stdout
,
243 "ioctl (PIOCSET, %s) %s\n",
244 arg1
== PR_FORK
? "PR_FORK" :
245 arg1
== PR_RLC
? "PR_RLC" :
247 arg1
== PR_ASYNC
? "PR_ASYNC" :
250 info_verbose
? ioctl_table
[i
].desc
: "");
253 arg1
= ptr
? *(long *) ptr
: 0;
254 fprintf (procfs_file
? procfs_file
: stdout
,
255 "ioctl (PIOCRESET, %s) %s\n",
256 arg1
== PR_FORK
? "PR_FORK" :
257 arg1
== PR_RLC
? "PR_RLC" :
259 arg1
== PR_ASYNC
? "PR_ASYNC" :
262 info_verbose
? ioctl_table
[i
].desc
: "");
265 fprintf (procfs_file
? procfs_file
: stdout
,
266 "ioctl (PIOCSTRACE) ");
267 proc_prettyfprint_signalset (procfs_file
? procfs_file
: stdout
,
268 (sigset_t
*) ptr
, 0);
271 fprintf (procfs_file
? procfs_file
: stdout
,
273 opcode
== PIOCSFAULT
? "PIOCSFAULT" : "PIOCGFAULT");
274 proc_prettyfprint_faultset (procfs_file
? procfs_file
: stdout
,
275 (fltset_t
*) ptr
, 0);
278 fprintf (procfs_file
? procfs_file
: stdout
,
280 opcode
== PIOCSENTRY
? "PIOCSENTRY" : "PIOCGENTRY");
281 proc_prettyfprint_syscalls (procfs_file
? procfs_file
: stdout
,
282 (sysset_t
*) ptr
, 0);
285 fprintf (procfs_file
? procfs_file
: stdout
,
287 opcode
== PIOCSEXIT
? "PIOCSEXIT" : "PIOCGEXIT");
288 proc_prettyfprint_syscalls (procfs_file
? procfs_file
: stdout
,
289 (sysset_t
*) ptr
, 0);
292 fprintf (procfs_file
? procfs_file
: stdout
,
294 opcode
== PIOCSHOLD
? "PIOCSHOLD" : "PIOCGHOLD");
295 proc_prettyfprint_signalset (procfs_file
? procfs_file
: stdout
,
296 (sigset_t
*) ptr
, 0);
299 fprintf (procfs_file
? procfs_file
: stdout
,
300 "ioctl (PIOCSSIG) ");
301 proc_prettyfprint_signal (procfs_file
? procfs_file
: stdout
,
302 ptr
? ((siginfo_t
*) ptr
)->si_signo
: 0,
304 fprintf (procfs_file
? procfs_file
: stdout
, "\n");
307 fprintf (procfs_file
? procfs_file
: stdout
,
310 arg1
= ptr
? *(long *) ptr
: 0;
312 fprintf (procfs_file
? procfs_file
: stdout
, "clearSig ");
314 fprintf (procfs_file
? procfs_file
: stdout
, "clearFlt ");
316 fprintf (procfs_file
? procfs_file
: stdout
, "setTrace ");
318 fprintf (procfs_file
? procfs_file
: stdout
, "setHold ");
320 fprintf (procfs_file
? procfs_file
: stdout
, "setFlt ");
322 fprintf (procfs_file
? procfs_file
: stdout
, "setVaddr ");
324 fprintf (procfs_file
? procfs_file
: stdout
, "step ");
326 fprintf (procfs_file
? procfs_file
: stdout
, "syscallAbort ");
328 fprintf (procfs_file
? procfs_file
: stdout
, "stopReq ");
330 fprintf (procfs_file
? procfs_file
: stdout
, "\n");
333 fprintf (procfs_file
? procfs_file
: stdout
,
334 "ioctl (PIOCKILL) ");
335 proc_prettyfprint_signal (procfs_file
? procfs_file
: stdout
,
336 ptr
? *(long *) ptr
: 0, 0);
337 fprintf (procfs_file
? procfs_file
: stdout
, "\n");
341 fprintf (procfs_file
? procfs_file
: stdout
,
342 "ioctl (PIOCSSPCACT) ");
343 arg1
= ptr
? *(long *) ptr
: 0;
344 if (arg1
& PRFS_STOPFORK
)
345 fprintf (procfs_file
? procfs_file
: stdout
, "stopFork ");
346 if (arg1
& PRFS_STOPEXEC
)
347 fprintf (procfs_file
? procfs_file
: stdout
, "stopExec ");
348 if (arg1
& PRFS_STOPTERM
)
349 fprintf (procfs_file
? procfs_file
: stdout
, "stopTerm ");
350 if (arg1
& PRFS_STOPTCR
)
351 fprintf (procfs_file
? procfs_file
: stdout
, "stopThreadCreate ");
352 if (arg1
& PRFS_STOPTTERM
)
353 fprintf (procfs_file
? procfs_file
: stdout
, "stopThreadTerm ");
354 if (arg1
& PRFS_KOLC
)
355 fprintf (procfs_file
? procfs_file
: stdout
, "killOnLastClose ");
356 fprintf (procfs_file
? procfs_file
: stdout
, "\n");
358 #endif /* PIOCSSPCACT */
360 if (ioctl_table
[i
].name
)
361 fprintf (procfs_file
? procfs_file
: stdout
,
364 info_verbose
? ioctl_table
[i
].desc
: "");
366 fprintf (procfs_file
? procfs_file
: stdout
,
367 "ioctl (<unknown %ld (0x%lx)) \n", opcode
, opcode
);
371 fflush (procfs_file
);
374 ret
= ioctl (fd
, opcode
, ptr
);
375 if (procfs_trace
&& ret
< 0)
377 fprintf (procfs_file
? procfs_file
: stdout
,
378 "[ioctl (%s) FAILED! (%s)]\n",
379 ioctl_table
[i
].name
!= NULL
?
380 ioctl_table
[i
].name
: "<unknown>",
381 safe_strerror (errno
));
383 fflush (procfs_file
);
389 #else /* NEW_PROC_API */
391 static struct trans rw_table
[] = {
392 #ifdef PCAGENT /* solaris */
393 { PCAGENT
, "PCAGENT", "create agent lwp with regs from argument" },
395 { PCCFAULT
, "PCCFAULT", "clear current fault" },
396 #ifdef PCCSIG /* solaris */
397 { PCCSIG
, "PCCSIG", "clear current signal" },
399 #ifdef PCDSTOP /* solaris */
400 { PCDSTOP
, "PCDSTOP", "post stop request" },
402 { PCKILL
, "PCKILL", "post a signal" },
403 #ifdef PCNICE /* solaris */
404 { PCNICE
, "PCNICE", "set nice priority" },
406 #ifdef PCREAD /* solaris */
407 { PCREAD
, "PCREAD", "read from the address space" },
408 { PCWRITE
, "PCWRITE", "write to the address space" },
410 { PCRUN
, "PCRUN", "make process/lwp runnable" },
411 #ifdef PCSASRS /* solaris 2.7 only */
412 { PCSASRS
, "PCSASRS", "set ancillary state registers" },
414 #ifdef PCSCRED /* solaris */
415 { PCSCRED
, "PCSCRED", "set process credentials" },
417 { PCSENTRY
, "PCSENTRY", "set traced syscall entry set" },
418 { PCSET
, "PCSET", "set modes" },
419 { PCSEXIT
, "PCSEXIT", "set traced syscall exit set" },
420 { PCSFAULT
, "PCSFAULT", "set traced fault set" },
421 { PCSFPREG
, "PCSFPREG", "set floating point registers" },
422 #ifdef PCSHOLD /* solaris */
423 { PCSHOLD
, "PCSHOLD", "set signal mask" },
425 { PCSREG
, "PCSREG", "set general registers" },
426 { PCSSIG
, "PCSSIG", "set current signal" },
427 { PCSTOP
, "PCSTOP", "post stop request and wait" },
428 { PCSTRACE
, "PCSTRACE", "set traced signal set" },
429 #ifdef PCSVADDR /* solaris */
430 { PCSVADDR
, "PCSVADDR", "set pc virtual address" },
432 #ifdef PCSXREG /* solaris sparc only */
433 { PCSXREG
, "PCSXREG", "set extra registers" },
435 #ifdef PCTWSTOP /* solaris */
436 { PCTWSTOP
, "PCTWSTOP", "wait for stop, with timeout arg" },
438 #ifdef PCUNKILL /* solaris */
439 { PCUNKILL
, "PCUNKILL", "delete a pending signal" },
441 #ifdef PCUNSET /* solaris */
442 { PCUNSET
, "PCUNSET", "unset modes" },
444 #ifdef PCWATCH /* solaris */
445 { PCWATCH
, "PCWATCH", "set/unset watched memory area" },
447 { PCWSTOP
, "PCWSTOP", "wait for process/lwp to stop, no timeout" },
451 static off_t lseek_offset
;
454 write_with_trace (int fd
, void *varg
, size_t len
, char *file
, int line
)
456 int i
= ARRAY_SIZE (rw_table
) - 1;
458 procfs_ctl_t
*arg
= (procfs_ctl_t
*) varg
;
463 procfs_ctl_t opcode
= arg
[0];
464 for (i
= 0; rw_table
[i
].name
!= NULL
; i
++)
465 if (rw_table
[i
].value
== opcode
)
469 fprintf (procfs_file
? procfs_file
: stdout
,
470 "%s:%d -- ", file
, line
);
473 fprintf (procfs_file
? procfs_file
: stdout
,
474 "write (PCSET, %s) %s\n",
475 arg
[1] == PR_FORK
? "PR_FORK" :
476 arg
[1] == PR_RLC
? "PR_RLC" :
478 arg
[1] == PR_ASYNC
? "PR_ASYNC" :
481 info_verbose
? rw_table
[i
].desc
: "");
487 #if PCRESET != PCUNSET
491 fprintf (procfs_file
? procfs_file
: stdout
,
492 "write (PCRESET, %s) %s\n",
493 arg
[1] == PR_FORK
? "PR_FORK" :
494 arg
[1] == PR_RLC
? "PR_RLC" :
496 arg
[1] == PR_ASYNC
? "PR_ASYNC" :
499 info_verbose
? rw_table
[i
].desc
: "");
502 fprintf (procfs_file
? procfs_file
: stdout
,
503 "write (PCSTRACE) ");
504 proc_prettyfprint_signalset (procfs_file
? procfs_file
: stdout
,
505 (sigset_t
*) &arg
[1], 0);
508 fprintf (procfs_file
? procfs_file
: stdout
,
509 "write (PCSFAULT) ");
510 proc_prettyfprint_faultset (procfs_file
? procfs_file
: stdout
,
511 (fltset_t
*) &arg
[1], 0);
514 fprintf (procfs_file
? procfs_file
: stdout
,
515 "write (PCSENTRY) ");
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_syscalls (procfs_file
? procfs_file
: stdout
,
523 (sysset_t
*) &arg
[1], 0);
527 fprintf (procfs_file
? procfs_file
: stdout
,
529 proc_prettyfprint_signalset (procfs_file
? procfs_file
: stdout
,
530 (sigset_t
*) &arg
[1], 0);
534 fprintf (procfs_file
? procfs_file
: stdout
,
536 proc_prettyfprint_signal (procfs_file
? procfs_file
: stdout
,
537 arg
[1] ? ((siginfo_t
*) &arg
[1])->si_signo
540 fprintf (procfs_file
? procfs_file
: stdout
, "\n");
543 fprintf (procfs_file
? procfs_file
: stdout
,
546 fprintf (procfs_file
? procfs_file
: stdout
, "clearSig ");
547 if (arg
[1] & PRCFAULT
)
548 fprintf (procfs_file
? procfs_file
: stdout
, "clearFlt ");
550 fprintf (procfs_file
? procfs_file
: stdout
, "step ");
552 if (arg
[1] & PRSABORT
)
553 fprintf (procfs_file
? procfs_file
: stdout
, "syscallAbort ");
557 fprintf (procfs_file
? procfs_file
: stdout
, "stopReq ");
560 fprintf (procfs_file
? procfs_file
: stdout
, "\n");
563 fprintf (procfs_file
? procfs_file
: stdout
,
565 proc_prettyfprint_signal (procfs_file
? procfs_file
: stdout
,
567 fprintf (procfs_file
? procfs_file
: stdout
, "\n");
571 if (rw_table
[i
].name
)
572 fprintf (procfs_file
? procfs_file
: stdout
,
575 info_verbose
? rw_table
[i
].desc
: "");
578 if (lseek_offset
!= -1)
579 fprintf (procfs_file
? procfs_file
: stdout
,
580 "write (<unknown>, %lud bytes at 0x%08lx) \n",
581 (unsigned long) len
, (unsigned long) lseek_offset
);
583 fprintf (procfs_file
? procfs_file
: stdout
,
584 "write (<unknown>, %lud bytes) \n",
585 (unsigned long) len
);
591 fflush (procfs_file
);
594 ret
= write (fd
, (void *) arg
, len
);
595 if (procfs_trace
&& ret
!= len
)
597 fprintf (procfs_file
? procfs_file
: stdout
,
598 "[write (%s) FAILED! (%s)]\n",
599 rw_table
[i
].name
!= NULL
?
600 rw_table
[i
].name
: "<unknown>",
601 safe_strerror (errno
));
603 fflush (procfs_file
);
611 lseek_with_trace (int fd
, off_t offset
, int whence
, char *file
, int line
)
617 ret
= lseek (fd
, offset
, whence
);
619 if (procfs_trace
&& (ret
== -1 || errno
!= 0))
621 fprintf (procfs_file
? procfs_file
: stdout
,
622 "[lseek (0x%08lx) FAILED! (%s)]\n",
623 (unsigned long) offset
, safe_strerror (errno
));
625 fflush (procfs_file
);
631 #endif /* NEW_PROC_API */
634 open_with_trace (char *filename
, int mode
, char *file
, int line
)
640 ret
= open (filename
, mode
);
644 fprintf (procfs_file
? procfs_file
: stdout
,
645 "%s:%d -- ", file
, line
);
649 fprintf (procfs_file
? procfs_file
: stdout
,
650 "[open FAILED! (%s) line %d]\\n",
651 safe_strerror (errno
), line
);
655 fprintf (procfs_file
? procfs_file
: stdout
,
656 "%d = open (%s, ", ret
, filename
);
657 if (mode
== O_RDONLY
)
658 fprintf (procfs_file
? procfs_file
: stdout
, "O_RDONLY) %d\n",
660 else if (mode
== O_WRONLY
)
661 fprintf (procfs_file
? procfs_file
: stdout
, "O_WRONLY) %d\n",
663 else if (mode
== O_RDWR
)
664 fprintf (procfs_file
? procfs_file
: stdout
, "O_RDWR) %d\n",
668 fflush (procfs_file
);
675 close_with_trace (int fd
, char *file
, int line
)
685 fprintf (procfs_file
? procfs_file
: stdout
,
686 "%s:%d -- ", file
, line
);
688 fprintf (procfs_file
? procfs_file
: stdout
,
689 "[close FAILED! (%s)]\n", safe_strerror (errno
));
691 fprintf (procfs_file
? procfs_file
: stdout
,
692 "%d = close (%d)\n", ret
, fd
);
694 fflush (procfs_file
);
701 wait_with_trace (int *wstat
, char *file
, int line
)
709 fprintf (procfs_file
? procfs_file
: stdout
,
710 "%s:%d -- ", file
, line
);
711 fprintf (procfs_file
? procfs_file
: stdout
,
712 "wait (line %d) ", line
);
714 fflush (procfs_file
);
721 fprintf (procfs_file
? procfs_file
: stdout
,
722 "[wait FAILED! (%s)]\n", safe_strerror (errno
));
724 fprintf (procfs_file
? procfs_file
: stdout
,
725 "returned pid %d, status 0x%x\n", ret
, lstat
);
727 fflush (procfs_file
);
736 procfs_note (const char *msg
, const char *file
, int line
)
742 fprintf (procfs_file
? procfs_file
: stdout
,
743 "%s:%d -- ", file
, line
);
744 fprintf (procfs_file
? procfs_file
: stdout
, "%s", msg
);
746 fflush (procfs_file
);
751 proc_prettyfprint_status (long flags
, int why
, int what
, int thread
)
757 fprintf (procfs_file
? procfs_file
: stdout
,
758 "Thread %d: ", thread
);
760 proc_prettyfprint_flags (procfs_file
? procfs_file
: stdout
,
763 if (flags
& (PR_STOPPED
| PR_ISTOP
))
764 proc_prettyfprint_why (procfs_file
? procfs_file
: stdout
,
767 fflush (procfs_file
);
772 _initialize_proc_api (void)
774 struct cmd_list_element
*c
;
776 add_setshow_boolean_cmd ("procfs-trace", no_class
, &procfs_trace
, _("\
777 Set tracing for /proc api calls."), _("\
778 Show tracing for /proc api calls."), NULL
,
779 set_procfs_trace_cmd
,
780 NULL
, /* FIXME: i18n: */
781 &setlist
, &showlist
);
783 procfs_filename
= xstrdup ("procfs_trace");
784 add_setshow_filename_cmd ("procfs-file", no_class
, &procfs_filename
, _("\
785 Set filename for /proc tracefile."), _("\
786 Show filename for /proc tracefile."), NULL
,
788 NULL
, /* FIXME: i18n: */
789 &setlist
, &showlist
);
This page took 0.04509 seconds and 4 git commands to generate.