ab160b1d021443c7ed144a5e903c8720c5853f87
1 /* Machine independent support for Solaris /proc (process file system) for GDB.
3 Copyright (C) 1999-2018 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
29 #include "completer.h"
31 #define _STRUCTURED_PROC 1
33 #include <sys/types.h>
34 #include <sys/procfs.h>
35 #include <sys/proc.h> /* for struct proc */
36 #include <sys/user.h> /* for struct user */
37 #include <fcntl.h> /* for O_RDWR etc. */
40 #include "proc-utils.h"
42 /* Much of the information used in the /proc interface, particularly for
43 printing status information, is kept as tables of structures of the
44 following form. These tables can be used to map numeric values to
45 their symbolic names and to a string that describes their specific use. */
48 long value
; /* The numeric value */
49 const char *name
; /* The equivalent symbolic value */
50 const char *desc
; /* Short description of value */
53 static int procfs_trace
= 0;
54 static FILE *procfs_file
= NULL
;
55 static char *procfs_filename
;
58 prepare_to_trace (void)
60 if (procfs_trace
) /* if procfs tracing turned on */
61 if (procfs_file
== NULL
) /* if output file not yet open */
62 procfs_file
= fopen (procfs_filename
, "a"); /* open output file */
66 set_procfs_trace_cmd (const char *args
,
67 int from_tty
, struct cmd_list_element
*c
)
69 #if 0 /* not sure what I might actually need to do here, if anything */
76 set_procfs_file_cmd (const char *args
,
77 int from_tty
, struct cmd_list_element
*c
)
79 /* Just changed the filename for procfs tracing.
80 If a file was already open, close it. */
86 static struct trans rw_table
[] = {
87 { PCAGENT
, "PCAGENT", "create agent lwp with regs from argument" },
88 { PCCFAULT
, "PCCFAULT", "clear current fault" },
89 { PCCSIG
, "PCCSIG", "clear current signal" },
90 { PCDSTOP
, "PCDSTOP", "post stop request" },
91 { PCKILL
, "PCKILL", "post a signal" },
92 { PCNICE
, "PCNICE", "set nice priority" },
93 { PCREAD
, "PCREAD", "read from the address space" },
94 { PCWRITE
, "PCWRITE", "write to the address space" },
95 { PCRUN
, "PCRUN", "make process/lwp runnable" },
96 { PCSASRS
, "PCSASRS", "set ancillary state registers" },
97 { PCSCRED
, "PCSCRED", "set process credentials" },
98 { PCSENTRY
, "PCSENTRY", "set traced syscall entry set" },
99 { PCSET
, "PCSET", "set modes" },
100 { PCSEXIT
, "PCSEXIT", "set traced syscall exit set" },
101 { PCSFAULT
, "PCSFAULT", "set traced fault set" },
102 { PCSFPREG
, "PCSFPREG", "set floating point registers" },
103 { PCSHOLD
, "PCSHOLD", "set signal mask" },
104 { PCSREG
, "PCSREG", "set general registers" },
105 { PCSSIG
, "PCSSIG", "set current signal" },
106 { PCSTOP
, "PCSTOP", "post stop request and wait" },
107 { PCSTRACE
, "PCSTRACE", "set traced signal set" },
108 { PCSVADDR
, "PCSVADDR", "set pc virtual address" },
109 { PCSXREG
, "PCSXREG", "set extra registers" },
110 { PCTWSTOP
, "PCTWSTOP", "wait for stop, with timeout arg" },
111 { PCUNKILL
, "PCUNKILL", "delete a pending signal" },
112 { PCUNSET
, "PCUNSET", "unset modes" },
113 { PCWATCH
, "PCWATCH", "set/unset watched memory area" },
114 { PCWSTOP
, "PCWSTOP", "wait for process/lwp to stop, no timeout" },
118 static off_t lseek_offset
;
121 write_with_trace (int fd
, void *varg
, size_t len
, char *file
, int line
)
123 int i
= ARRAY_SIZE (rw_table
) - 1;
125 procfs_ctl_t
*arg
= (procfs_ctl_t
*) varg
;
130 procfs_ctl_t opcode
= arg
[0];
131 for (i
= 0; rw_table
[i
].name
!= NULL
; i
++)
132 if (rw_table
[i
].value
== opcode
)
136 fprintf (procfs_file
? procfs_file
: stdout
,
137 "%s:%d -- ", file
, line
);
140 fprintf (procfs_file
? procfs_file
: stdout
,
141 "write (PCSET, %s) %s\n",
142 arg
[1] == PR_FORK
? "PR_FORK" :
143 arg
[1] == PR_RLC
? "PR_RLC" :
144 arg
[1] == PR_ASYNC
? "PR_ASYNC" :
146 info_verbose
? rw_table
[i
].desc
: "");
149 fprintf (procfs_file
? procfs_file
: stdout
,
150 "write (PCRESET, %s) %s\n",
151 arg
[1] == PR_FORK
? "PR_FORK" :
152 arg
[1] == PR_RLC
? "PR_RLC" :
153 arg
[1] == PR_ASYNC
? "PR_ASYNC" :
155 info_verbose
? rw_table
[i
].desc
: "");
158 fprintf (procfs_file
? procfs_file
: stdout
,
159 "write (PCSTRACE) ");
160 proc_prettyfprint_signalset (procfs_file
? procfs_file
: stdout
,
161 (sigset_t
*) &arg
[1], 0);
164 fprintf (procfs_file
? procfs_file
: stdout
,
165 "write (PCSFAULT) ");
166 proc_prettyfprint_faultset (procfs_file
? procfs_file
: stdout
,
167 (fltset_t
*) &arg
[1], 0);
170 fprintf (procfs_file
? procfs_file
: stdout
,
171 "write (PCSENTRY) ");
172 proc_prettyfprint_syscalls (procfs_file
? procfs_file
: stdout
,
173 (sysset_t
*) &arg
[1], 0);
176 fprintf (procfs_file
? procfs_file
: stdout
,
178 proc_prettyfprint_syscalls (procfs_file
? procfs_file
: stdout
,
179 (sysset_t
*) &arg
[1], 0);
182 fprintf (procfs_file
? procfs_file
: stdout
,
184 proc_prettyfprint_signalset (procfs_file
? procfs_file
: stdout
,
185 (sigset_t
*) &arg
[1], 0);
188 fprintf (procfs_file
? procfs_file
: stdout
,
190 proc_prettyfprint_signal (procfs_file
? procfs_file
: stdout
,
191 arg
[1] ? ((siginfo_t
*) &arg
[1])->si_signo
194 fprintf (procfs_file
? procfs_file
: stdout
, "\n");
197 fprintf (procfs_file
? procfs_file
: stdout
,
200 fprintf (procfs_file
? procfs_file
: stdout
, "clearSig ");
201 if (arg
[1] & PRCFAULT
)
202 fprintf (procfs_file
? procfs_file
: stdout
, "clearFlt ");
204 fprintf (procfs_file
? procfs_file
: stdout
, "step ");
205 if (arg
[1] & PRSABORT
)
206 fprintf (procfs_file
? procfs_file
: stdout
, "syscallAbort ");
208 fprintf (procfs_file
? procfs_file
: stdout
, "stopReq ");
210 fprintf (procfs_file
? procfs_file
: stdout
, "\n");
213 fprintf (procfs_file
? procfs_file
: stdout
,
215 proc_prettyfprint_signal (procfs_file
? procfs_file
: stdout
,
217 fprintf (procfs_file
? procfs_file
: stdout
, "\n");
221 if (rw_table
[i
].name
)
222 fprintf (procfs_file
? procfs_file
: stdout
,
225 info_verbose
? rw_table
[i
].desc
: "");
228 if (lseek_offset
!= -1)
229 fprintf (procfs_file
? procfs_file
: stdout
,
230 "write (<unknown>, %lud bytes at 0x%08lx) \n",
231 (unsigned long) len
, (unsigned long) lseek_offset
);
233 fprintf (procfs_file
? procfs_file
: stdout
,
234 "write (<unknown>, %lud bytes) \n",
235 (unsigned long) len
);
241 fflush (procfs_file
);
244 ret
= write (fd
, (void *) arg
, len
);
245 if (procfs_trace
&& ret
!= len
)
247 fprintf (procfs_file
? procfs_file
: stdout
,
248 "[write (%s) FAILED! (%s)]\n",
249 rw_table
[i
].name
!= NULL
?
250 rw_table
[i
].name
: "<unknown>",
251 safe_strerror (errno
));
253 fflush (procfs_file
);
261 lseek_with_trace (int fd
, off_t offset
, int whence
, char *file
, int line
)
267 ret
= lseek (fd
, offset
, whence
);
269 if (procfs_trace
&& (ret
== -1 || errno
!= 0))
271 fprintf (procfs_file
? procfs_file
: stdout
,
272 "[lseek (0x%08lx) FAILED! (%s)]\n",
273 (unsigned long) offset
, safe_strerror (errno
));
275 fflush (procfs_file
);
282 open_with_trace (char *filename
, int mode
, char *file
, int line
)
288 ret
= open (filename
, mode
);
292 fprintf (procfs_file
? procfs_file
: stdout
,
293 "%s:%d -- ", file
, line
);
297 fprintf (procfs_file
? procfs_file
: stdout
,
298 "[open FAILED! (%s) line %d]\\n",
299 safe_strerror (errno
), line
);
303 fprintf (procfs_file
? procfs_file
: stdout
,
304 "%d = open (%s, ", ret
, filename
);
305 if (mode
== O_RDONLY
)
306 fprintf (procfs_file
? procfs_file
: stdout
, "O_RDONLY) %d\n",
308 else if (mode
== O_WRONLY
)
309 fprintf (procfs_file
? procfs_file
: stdout
, "O_WRONLY) %d\n",
311 else if (mode
== O_RDWR
)
312 fprintf (procfs_file
? procfs_file
: stdout
, "O_RDWR) %d\n",
316 fflush (procfs_file
);
323 close_with_trace (int fd
, char *file
, int line
)
333 fprintf (procfs_file
? procfs_file
: stdout
,
334 "%s:%d -- ", file
, line
);
336 fprintf (procfs_file
? procfs_file
: stdout
,
337 "[close FAILED! (%s)]\n", safe_strerror (errno
));
339 fprintf (procfs_file
? procfs_file
: stdout
,
340 "%d = close (%d)\n", ret
, fd
);
342 fflush (procfs_file
);
349 wait_with_trace (int *wstat
, char *file
, int line
)
357 fprintf (procfs_file
? procfs_file
: stdout
,
358 "%s:%d -- ", file
, line
);
359 fprintf (procfs_file
? procfs_file
: stdout
,
360 "wait (line %d) ", line
);
362 fflush (procfs_file
);
369 fprintf (procfs_file
? procfs_file
: stdout
,
370 "[wait FAILED! (%s)]\n", safe_strerror (errno
));
372 fprintf (procfs_file
? procfs_file
: stdout
,
373 "returned pid %d, status 0x%x\n", ret
, lstat
);
375 fflush (procfs_file
);
384 procfs_note (const char *msg
, const char *file
, int line
)
390 fprintf (procfs_file
? procfs_file
: stdout
,
391 "%s:%d -- ", file
, line
);
392 fprintf (procfs_file
? procfs_file
: stdout
, "%s", msg
);
394 fflush (procfs_file
);
399 proc_prettyfprint_status (long flags
, int why
, int what
, int thread
)
405 fprintf (procfs_file
? procfs_file
: stdout
,
406 "Thread %d: ", thread
);
408 proc_prettyfprint_flags (procfs_file
? procfs_file
: stdout
,
411 if (flags
& (PR_STOPPED
| PR_ISTOP
))
412 proc_prettyfprint_why (procfs_file
? procfs_file
: stdout
,
415 fflush (procfs_file
);
420 _initialize_proc_api (void)
422 add_setshow_boolean_cmd ("procfs-trace", no_class
, &procfs_trace
, _("\
423 Set tracing for /proc api calls."), _("\
424 Show tracing for /proc api calls."), NULL
,
425 set_procfs_trace_cmd
,
426 NULL
, /* FIXME: i18n: */
427 &setlist
, &showlist
);
429 procfs_filename
= xstrdup ("procfs_trace");
430 add_setshow_filename_cmd ("procfs-file", no_class
, &procfs_filename
, _("\
431 Set filename for /proc tracefile."), _("\
432 Show filename for /proc tracefile."), NULL
,
434 NULL
, /* FIXME: i18n: */
435 &setlist
, &showlist
);
This page took 0.037922 seconds and 4 git commands to generate.