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
42 #ifdef HAVE_SYS_USER_H
69 if (procfs_file == NULL)
70 if (procfs_filename != NULL)
71 procfs_file = fopen (procfs_filename,
"a");
96 static struct trans ioctl_table[] = {
98 { PIOCACINFO,
"PIOCACINFO",
"get process account info" },
100 { PIOCACTION,
"PIOCACTION",
"get signal action structs" },
102 { PIOCARGUMENTS,
"PIOCARGUMENTS",
"command line args" },
105 { PIOCAUXV,
"PIOCAUXV",
"get aux vector" },
106 { PIOCNAUXV,
"PIOCNAUXV",
"get number of aux vector entries" },
108 { PIOCCFAULT,
"PIOCCFAULT",
"clear current fault" },
109 { PIOCCRED,
"PIOCCRED",
"get process credentials" },
111 { PIOCENEVCTRS,
"PIOCENEVCTRS",
"acquire and start event counters" },
112 { PIOCGETEVCTRL,
"PIOCGETEVCTRL",
"get control info of event counters" },
113 { PIOCGETEVCTRS,
"PIOCGETEVCTRS",
"dump event counters" },
114 { PIOCGETPREVCTRS,
"PIOCGETPREVCTRS",
"dump event counters & prusage info" },
115 { PIOCRELEVCTRS,
"PIOCRELEVCTRS",
"release/stop event counters" },
116 { PIOCSETEVCTRL,
"PIOCSETEVCTRL",
"set control info of event counters" },
117 { PIOCGETPTIMER,
"PIOCGETPTIMER",
"get process timers" },
119 { PIOCGENTRY,
"PIOCGENTRY",
"get traced syscall entry set" },
120 #if defined (PIOCGETPR)
121 { PIOCGETPR,
"PIOCGETPR",
"read struct proc" },
123 #if defined (PIOCGETU)
124 { PIOCGETU,
"PIOCGETU",
"read user area" },
126 #if defined (PIOCGETUTK) && (defined(KERNEL) || defined(SHOW_UTT))
127 { PIOCGETUTK,
"PIOCGETUTK",
"get the utask struct" },
129 { PIOCGEXIT,
"PIOCGEXIT",
"get traced syscall exit set" },
130 { PIOCGFAULT,
"PIOCGFAULT",
"get traced fault set" },
132 { PIOCGFPCR,
"PIOCGFPCR",
"get FP control register" },
133 { PIOCSFPCR,
"PIOCSFPCR",
"set FP conrtol register" },
135 { PIOCGFPREG,
"PIOCGFPREG",
"get floating point registers" },
136 { PIOCGHOLD,
"PIOCGHOLD",
"get held signal set" },
137 { PIOCGREG,
"PIOCGREG",
"get general registers" },
138 { PIOCGROUPS,
"PIOCGROUPS",
"get supplementary groups" },
140 { PIOCGSPCACT,
"PIOCGSPCACT",
"get special action" },
141 { PIOCSSPCACT,
"PIOCSSPCACT",
"set special action" },
143 { PIOCGTRACE,
"PIOCGTRACE",
"get traced signal set" },
145 { PIOCGWATCH,
"PIOCGWATCH",
"get watchpoint" },
146 { PIOCSWATCH,
"PIOCSWATCH",
"set watchpoint" },
147 { PIOCNWATCH,
"PIOCNWATCH",
"get number of watchpoints" },
150 { PIOCGWIN,
"PIOCGWIN",
"get gwindows_t" },
153 { PIOCGXREGSIZE,
"PIOCXREGSIZE",
"get extra register state size" },
154 { PIOCGXREG,
"PIOCGXREG",
"get extra register state" },
155 { PIOCSXREG,
"PIOCSXREG",
"set extra register state" },
157 { PIOCKILL,
"PIOCKILL",
"send signal" },
159 { PIOCLDT,
"PIOCLDT",
"get LDT" },
160 { PIOCNLDT,
"PIOCNLDT",
"get number of LDT entries" },
163 { PIOCLSTATUS,
"PIOCLSTATUS",
"get status of all lwps" },
164 { PIOCLUSAGE,
"PIOCLUSAGE",
"get resource usage of all lwps" },
165 { PIOCOPENLWP,
"PIOCOPENLWP",
"get lwp file descriptor" },
166 { PIOCLWPIDS,
"PIOCLWPIDS",
"get lwp identifiers" },
168 { PIOCMAP,
"PIOCMAP",
"get memory map information" },
169 { PIOCMAXSIG,
"PIOCMAXSIG",
"get max signal number" },
170 { PIOCNICE,
"PIOCNICE",
"set nice priority" },
171 { PIOCNMAP,
"PIOCNMAP",
"get number of memory mappings" },
172 { PIOCOPENM,
"PIOCOPENM",
"open mapped object for reading" },
174 { PIOCOPENMOBS,
"PIOCOPENMOBS",
"open mapped object" },
177 { PIOCOPENPD,
"PIOCOPENPD",
"get page data file descriptor" },
179 { PIOCPSINFO,
"PIOCPSINFO",
"get ps(1) information" },
180 { PIOCRESET,
"PIOCRESET",
"reset process flags" },
181 { PIOCRFORK,
"PIOCRFORK",
"reset inherit-on-fork flag" },
182 { PIOCRRLC,
"PIOCRRLC",
"reset run-on-last-close flag" },
183 { PIOCRUN,
"PIOCRUN",
"make process runnable" },
184 #ifdef PIOCSAVECCNTRS
185 { PIOCSAVECCNTRS,
"PIOCSAVECCNTRS",
"parent gets child cntrs" },
187 { PIOCSENTRY,
"PIOCSENTRY",
"set traced syscall entry set" },
188 { PIOCSET,
"PIOCSET",
"set process flags" },
189 { PIOCSEXIT,
"PIOCSEXIT",
"set traced syscall exit set" },
190 { PIOCSFAULT,
"PIOCSFAULT",
"set traced fault set" },
191 { PIOCSFORK,
"PIOCSFORK",
"set inherit-on-fork flag" },
192 { PIOCSFPREG,
"PIOCSFPREG",
"set floating point registers" },
193 { PIOCSHOLD,
"PIOCSHOLD",
"set held signal set" },
194 { PIOCSREG,
"PIOCSREG",
"set general registers" },
195 { PIOCSRLC,
"PIOCSRLC",
"set run-on-last-close flag" },
196 { PIOCSSIG,
"PIOCSSIG",
"set current signal" },
197 { PIOCSTATUS,
"PIOCSTATUS",
"get process status" },
198 { PIOCSTOP,
"PIOCSTOP",
"post stop request" },
199 { PIOCSTRACE,
"PIOCSTRACE",
"set traced signal set" },
200 { PIOCUNKILL,
"PIOCUNKILL",
"delete a signal" },
202 { PIOCUSAGE,
"PIOCUSAGE",
"get resource usage" },
204 { PIOCWSTOP,
"PIOCWSTOP",
"wait for process to stop" },
207 { PIOCNTHR,
"PIOCNTHR",
"get thread count" },
208 { PIOCRTINH,
"PIOCRTINH",
"reset inherit-on-thread-creation" },
209 { PIOCSTINH,
"PIOCSTINH",
"set inherit-on-thread-creation" },
210 { PIOCTLIST,
"PIOCTLIST",
"get thread ids" },
211 { PIOCXPTH,
"PIOCXPTH",
"translate port to thread handle" },
212 { PIOCTRUN,
"PIOCTRUN",
"make thread runnable" },
213 { PIOCTSTATUS,
"PIOCTSTATUS",
"get thread status" },
214 { PIOCTSTOP,
"PIOCTSTOP",
"stop a thread" },
233 for (i = 0; ioctl_table[i].
name != NULL; i++)
234 if (ioctl_table[i].
value == opcode)
238 fprintf (procfs_file ? procfs_file : stdout,
239 "%s:%d -- ", file, line);
242 arg1 = ptr ? *(
long *) ptr : 0;
243 fprintf (procfs_file ? procfs_file : stdout,
244 "ioctl (PIOCSET, %s) %s\n",
245 arg1 == PR_FORK ?
"PR_FORK" :
246 arg1 == PR_RLC ?
"PR_RLC" :
248 arg1 == PR_ASYNC ?
"PR_ASYNC" :
254 arg1 = ptr ? *(
long *) ptr : 0;
255 fprintf (procfs_file ? procfs_file : stdout,
256 "ioctl (PIOCRESET, %s) %s\n",
257 arg1 == PR_FORK ?
"PR_FORK" :
258 arg1 == PR_RLC ?
"PR_RLC" :
260 arg1 == PR_ASYNC ?
"PR_ASYNC" :
266 fprintf (procfs_file ? procfs_file : stdout,
267 "ioctl (PIOCSTRACE) ");
269 (sigset_t *) ptr, 0);
272 fprintf (procfs_file ? procfs_file : stdout,
274 opcode == PIOCSFAULT ?
"PIOCSFAULT" :
"PIOCGFAULT");
276 (fltset_t *) ptr, 0);
279 fprintf (procfs_file ? procfs_file : stdout,
281 opcode == PIOCSENTRY ?
"PIOCSENTRY" :
"PIOCGENTRY");
283 (sysset_t *) ptr, 0);
286 fprintf (procfs_file ? procfs_file : stdout,
288 opcode == PIOCSEXIT ?
"PIOCSEXIT" :
"PIOCGEXIT");
290 (sysset_t *) ptr, 0);
293 fprintf (procfs_file ? procfs_file : stdout,
295 opcode == PIOCSHOLD ?
"PIOCSHOLD" :
"PIOCGHOLD");
297 (sigset_t *) ptr, 0);
300 fprintf (procfs_file ? procfs_file : stdout,
301 "ioctl (PIOCSSIG) ");
303 ptr ? ((siginfo_t *) ptr)->si_signo : 0,
305 fprintf (procfs_file ? procfs_file : stdout,
"\n");
308 fprintf (procfs_file ? procfs_file : stdout,
311 arg1 = ptr ? *(
long *) ptr : 0;
313 fprintf (procfs_file ? procfs_file : stdout,
"clearSig ");
315 fprintf (procfs_file ? procfs_file : stdout,
"clearFlt ");
317 fprintf (procfs_file ? procfs_file : stdout,
"setTrace ");
319 fprintf (procfs_file ? procfs_file : stdout,
"setHold ");
321 fprintf (procfs_file ? procfs_file : stdout,
"setFlt ");
323 fprintf (procfs_file ? procfs_file : stdout,
"setVaddr ");
325 fprintf (procfs_file ? procfs_file : stdout,
"step ");
327 fprintf (procfs_file ? procfs_file : stdout,
"syscallAbort ");
329 fprintf (procfs_file ? procfs_file : stdout,
"stopReq ");
331 fprintf (procfs_file ? procfs_file : stdout,
"\n");
334 fprintf (procfs_file ? procfs_file : stdout,
335 "ioctl (PIOCKILL) ");
337 ptr ? *(
long *) ptr : 0, 0);
338 fprintf (procfs_file ? procfs_file : stdout,
"\n");
342 fprintf (procfs_file ? procfs_file : stdout,
343 "ioctl (PIOCSSPCACT) ");
344 arg1 = ptr ? *(
long *) ptr : 0;
345 if (arg1 & PRFS_STOPFORK)
346 fprintf (procfs_file ? procfs_file : stdout,
"stopFork ");
347 if (arg1 & PRFS_STOPEXEC)
348 fprintf (procfs_file ? procfs_file : stdout,
"stopExec ");
349 if (arg1 & PRFS_STOPTERM)
350 fprintf (procfs_file ? procfs_file : stdout,
"stopTerm ");
351 if (arg1 & PRFS_STOPTCR)
352 fprintf (procfs_file ? procfs_file : stdout,
"stopThreadCreate ");
353 if (arg1 & PRFS_STOPTTERM)
354 fprintf (procfs_file ? procfs_file : stdout,
"stopThreadTerm ");
355 if (arg1 & PRFS_KOLC)
356 fprintf (procfs_file ? procfs_file : stdout,
"killOnLastClose ");
357 fprintf (procfs_file ? procfs_file : stdout,
"\n");
361 if (ioctl_table[i].name)
362 fprintf (procfs_file ? procfs_file : stdout,
367 fprintf (procfs_file ? procfs_file : stdout,
368 "ioctl (<unknown %ld (0x%lx)) \n", opcode, opcode);
372 fflush (procfs_file);
375 ret = ioctl (fd, opcode, ptr);
376 if (procfs_trace && ret < 0)
378 fprintf (procfs_file ? procfs_file : stdout,
379 "[ioctl (%s) FAILED! (%s)]\n",
380 ioctl_table[i].name != NULL ?
381 ioctl_table[i].name :
"<unknown>",
384 fflush (procfs_file);
392 static struct trans rw_table[] = {
394 { PCAGENT,
"PCAGENT",
"create agent lwp with regs from argument" },
396 { PCCFAULT,
"PCCFAULT",
"clear current fault" },
398 { PCCSIG,
"PCCSIG",
"clear current signal" },
401 { PCDSTOP,
"PCDSTOP",
"post stop request" },
403 { PCKILL,
"PCKILL",
"post a signal" },
405 { PCNICE,
"PCNICE",
"set nice priority" },
408 { PCREAD,
"PCREAD",
"read from the address space" },
409 { PCWRITE,
"PCWRITE",
"write to the address space" },
411 { PCRUN,
"PCRUN",
"make process/lwp runnable" },
413 { PCSASRS,
"PCSASRS",
"set ancillary state registers" },
416 { PCSCRED,
"PCSCRED",
"set process credentials" },
418 { PCSENTRY,
"PCSENTRY",
"set traced syscall entry set" },
419 { PCSET,
"PCSET",
"set modes" },
420 { PCSEXIT,
"PCSEXIT",
"set traced syscall exit set" },
421 { PCSFAULT,
"PCSFAULT",
"set traced fault set" },
422 { PCSFPREG,
"PCSFPREG",
"set floating point registers" },
424 { PCSHOLD,
"PCSHOLD",
"set signal mask" },
426 { PCSREG,
"PCSREG",
"set general registers" },
427 { PCSSIG,
"PCSSIG",
"set current signal" },
428 { PCSTOP,
"PCSTOP",
"post stop request and wait" },
429 { PCSTRACE,
"PCSTRACE",
"set traced signal set" },
431 { PCSVADDR,
"PCSVADDR",
"set pc virtual address" },
434 { PCSXREG,
"PCSXREG",
"set extra registers" },
437 { PCTWSTOP,
"PCTWSTOP",
"wait for stop, with timeout arg" },
440 { PCUNKILL,
"PCUNKILL",
"delete a pending signal" },
443 { PCUNSET,
"PCUNSET",
"unset modes" },
446 { PCWATCH,
"PCWATCH",
"set/unset watched memory area" },
448 { PCWSTOP,
"PCWSTOP",
"wait for process/lwp to stop, no timeout" },
452 static off_t lseek_offset;
457 int i = ARRAY_SIZE (rw_table) - 1;
465 for (i = 0; rw_table[i].
name != NULL; i++)
466 if (rw_table[i].
value == opcode)
470 fprintf (procfs_file ? procfs_file : stdout,
471 "%s:%d -- ", file, line);
474 fprintf (procfs_file ? procfs_file : stdout,
475 "write (PCSET, %s) %s\n",
476 arg[1] == PR_FORK ?
"PR_FORK" :
477 arg[1] == PR_RLC ?
"PR_RLC" :
479 arg[1] == PR_ASYNC ?
"PR_ASYNC" :
488 #if PCRESET != PCUNSET
492 fprintf (procfs_file ? procfs_file : stdout,
493 "write (PCRESET, %s) %s\n",
494 arg[1] == PR_FORK ?
"PR_FORK" :
495 arg[1] == PR_RLC ?
"PR_RLC" :
497 arg[1] == PR_ASYNC ?
"PR_ASYNC" :
503 fprintf (procfs_file ? procfs_file : stdout,
504 "write (PCSTRACE) ");
506 (sigset_t *) &arg[1], 0);
509 fprintf (procfs_file ? procfs_file : stdout,
510 "write (PCSFAULT) ");
512 (fltset_t *) &arg[1], 0);
515 fprintf (procfs_file ? procfs_file : stdout,
516 "write (PCSENTRY) ");
518 (sysset_t *) &arg[1], 0);
521 fprintf (procfs_file ? procfs_file : stdout,
524 (sysset_t *) &arg[1], 0);
528 fprintf (procfs_file ? procfs_file : stdout,
531 (sigset_t *) &arg[1], 0);
535 fprintf (procfs_file ? procfs_file : stdout,
538 arg[1] ? ((siginfo_t *) &arg[1])->si_signo
541 fprintf (procfs_file ? procfs_file : stdout,
"\n");
544 fprintf (procfs_file ? procfs_file : stdout,
547 fprintf (procfs_file ? procfs_file : stdout,
"clearSig ");
548 if (arg[1] & PRCFAULT)
549 fprintf (procfs_file ? procfs_file : stdout,
"clearFlt ");
551 fprintf (procfs_file ? procfs_file : stdout,
"step ");
553 if (arg[1] & PRSABORT)
554 fprintf (procfs_file ? procfs_file : stdout,
"syscallAbort ");
558 fprintf (procfs_file ? procfs_file : stdout,
"stopReq ");
561 fprintf (procfs_file ? procfs_file : stdout,
"\n");
564 fprintf (procfs_file ? procfs_file : stdout,
568 fprintf (procfs_file ? procfs_file : stdout,
"\n");
572 if (rw_table[i].name)
573 fprintf (procfs_file ? procfs_file : stdout,
579 if (lseek_offset != -1)
580 fprintf (procfs_file ? procfs_file : stdout,
581 "write (<unknown>, %lud bytes at 0x%08lx) \n",
582 (
unsigned long) len, (
unsigned long) lseek_offset);
584 fprintf (procfs_file ? procfs_file : stdout,
585 "write (<unknown>, %lud bytes) \n",
586 (
unsigned long) len);
592 fflush (procfs_file);
595 ret = write (fd, (
void *) arg, len);
596 if (procfs_trace && ret != len)
598 fprintf (procfs_file ? procfs_file : stdout,
599 "[write (%s) FAILED! (%s)]\n",
600 rw_table[i].name != NULL ?
601 rw_table[i].name :
"<unknown>",
604 fflush (procfs_file);
618 ret = lseek (fd, offset, whence);
620 if (procfs_trace && (ret == -1 || errno != 0))
622 fprintf (procfs_file ? procfs_file : stdout,
623 "[lseek (0x%08lx) FAILED! (%s)]\n",
626 fflush (procfs_file);
641 ret = open (filename, mode);
645 fprintf (procfs_file ? procfs_file : stdout,
646 "%s:%d -- ", file, line);
650 fprintf (procfs_file ? procfs_file : stdout,
651 "[open FAILED! (%s) line %d]\\n",
656 fprintf (procfs_file ? procfs_file : stdout,
657 "%d = open (%s, ", ret, filename);
658 if (mode == O_RDONLY)
659 fprintf (procfs_file ? procfs_file : stdout,
"O_RDONLY) %d\n",
661 else if (mode == O_WRONLY)
662 fprintf (procfs_file ? procfs_file : stdout,
"O_WRONLY) %d\n",
664 else if (mode == O_RDWR)
665 fprintf (procfs_file ? procfs_file : stdout,
"O_RDWR) %d\n",
669 fflush (procfs_file);
686 fprintf (procfs_file ? procfs_file : stdout,
687 "%s:%d -- ", file, line);
689 fprintf (procfs_file ? procfs_file : stdout,
692 fprintf (procfs_file ? procfs_file : stdout,
693 "%d = close (%d)\n", ret, fd);
695 fflush (procfs_file);
710 fprintf (procfs_file ? procfs_file : stdout,
711 "%s:%d -- ", file, line);
712 fprintf (procfs_file ? procfs_file : stdout,
713 "wait (line %d) ", line);
715 fflush (procfs_file);
722 fprintf (procfs_file ? procfs_file : stdout,
725 fprintf (procfs_file ? procfs_file : stdout,
726 "returned pid %d, status 0x%x\n", ret, lstat);
728 fflush (procfs_file);
743 fprintf (procfs_file ? procfs_file : stdout,
744 "%s:%d -- ", file, line);
745 fprintf (procfs_file ? procfs_file : stdout,
"%s", msg);
747 fflush (procfs_file);
758 fprintf (procfs_file ? procfs_file : stdout,
759 "Thread %d: ", thread);
764 if (flags & (PR_STOPPED | PR_ISTOP))
768 fflush (procfs_file);
782 Set tracing for /proc api calls."),
_(
"\
783 Show tracing for /proc api calls."), NULL,
789 Set filename for /proc tracefile."),
_(
"\
790 Show filename for /proc tracefile."), NULL,
int ioctl_with_trace(int fd, long opcode, void *ptr, char *file, int line)
int close_with_trace(int fd, char *file, int line)
static void prepare_to_trace(void)
void procfs_note(char *msg, char *file, int line)
static void set_procfs_trace_cmd(char *args, int from_tty, struct cmd_list_element *c)
mach_port_t kern_return_t mach_port_t msgports mach_port_t kern_return_t pid_t pid mach_port_t kern_return_t mach_port_t task mach_port_t kern_return_t int flags
off_t lseek_with_trace(int, off_t, int, char *, int)
struct cmd_list_element * setlist
static char * procfs_filename
struct cmd_list_element * showlist
void proc_prettyfprint_faultset(FILE *file, fltset_t *fltset, int verbose)
int write_with_trace(int, void *, size_t, char *, int)
pid_t wait_with_trace(int *wstat, char *file, int line)
static FILE * procfs_file
void _initialize_proc_api(void)
void proc_prettyfprint_why(FILE *file, unsigned long why, unsigned long what, int verbose)
void proc_prettyfprint_syscalls(FILE *file, sysset_t *sysset, int verbose)
char * safe_strerror(int)
void proc_prettyfprint_signal(FILE *file, int signo, int verbose)
void add_setshow_filename_cmd(const char *name, enum command_class theclass, char **var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
int open_with_trace(char *filename, int mode, char *file, int line)
void proc_prettyfprint_signalset(FILE *file, sigset_t *sigset, int verbose)
static void set_procfs_file_cmd(char *args, int from_tty, struct cmd_list_element *c)
void proc_prettyfprint_status(long flags, int why, int what, int thread)
void add_setshow_boolean_cmd(const char *name, enum command_class theclass, int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
void proc_prettyfprint_flags(FILE *file, unsigned long flags, int verbose)