1 /* Machine independent support for SVR4 /proc (process file system) for GDB.
2 Copyright 1991, 1992, 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
3 Written by Fred Fish at Cygnus Support.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
24 For information on the details of using /proc consult section proc(4)
25 in the UNIX System V Release 4 System Administrator's Reference Manual.
27 The general register and floating point register sets are manipulated by
28 separate ioctl's. This file makes the assumption that if FP0_REGNUM is
29 defined, then support for the floating point register set is desired,
30 regardless of whether or not the actual target has floating point hardware.
37 #include <sys/types.h>
39 #include <sys/fault.h>
40 #include <sys/syscall.h>
41 #include <sys/procfs.h>
44 #include "gdb_string.h"
54 #include "gdbthread.h"
56 #define MAX_SYSCALLS 256 /* Maximum number of syscalls for table */
59 #define PROC_NAME_FMT "/proc/%05d"
62 extern struct target_ops procfs_ops
; /* Forward declaration */
64 int procfs_suppress_run
= 0; /* Non-zero if procfs should pretend not to
65 be a runnable target. Used by targets
66 that can sit atop procfs, such as solaris
69 #if 1 /* FIXME: Gross and ugly hack to resolve coredep.c global */
70 CORE_ADDR kernel_u_addr
;
73 #ifdef BROKEN_SIGINFO_H /* Workaround broken SGS <sys/siginfo.h> */
75 #define si_pid _data._proc.pid
77 #define si_uid _data._proc._pdata._kill.uid
78 #endif /* BROKEN_SIGINFO_H */
80 /* All access to the inferior, either one started by gdb or one that has
81 been attached to, is controlled by an instance of a procinfo structure,
82 defined below. Since gdb currently only handles one inferior at a time,
83 the procinfo structure for the inferior is statically allocated and
84 only one exists at any given time. There is a separate procinfo
85 structure for use by the "info proc" command, so that we can print
86 useful information about any random process without interfering with
87 the inferior's procinfo information. */
90 struct procinfo
*next
;
91 int pid
; /* Process ID of inferior */
92 int fd
; /* File descriptor for /proc entry */
93 char *pathname
; /* Pathname to /proc entry */
94 int had_event
; /* poll/select says something happened */
95 int was_stopped
; /* Nonzero if was stopped prior to attach */
96 int nopass_next_sigstop
; /* Don't pass a sigstop on next resume */
97 prrun_t prrun
; /* Control state when it is run */
98 prstatus_t prstatus
; /* Current process status info */
99 gregset_t gregset
; /* General register set */
100 fpregset_t fpregset
; /* Floating point register set */
101 fltset_t fltset
; /* Current traced hardware fault set */
102 sigset_t trace
; /* Current traced signal set */
103 sysset_t exitset
; /* Current traced system call exit set */
104 sysset_t entryset
; /* Current traced system call entry set */
105 fltset_t saved_fltset
; /* Saved traced hardware fault set */
106 sigset_t saved_trace
; /* Saved traced signal set */
107 sigset_t saved_sighold
; /* Saved held signal set */
108 sysset_t saved_exitset
; /* Saved traced system call exit set */
109 sysset_t saved_entryset
; /* Saved traced system call entry set */
110 int num_syscall_handlers
; /* Number of syscall handlers currently installed */
111 struct procfs_syscall_handler
*syscall_handlers
; /* Pointer to list of syscall trap handlers */
112 int new_child
; /* Non-zero if it's a new thread */
115 /* List of inferior process information */
116 static struct procinfo
*procinfo_list
= NULL
;
118 static struct pollfd
*poll_list
; /* pollfds used for waiting on /proc */
120 static int num_poll_list
= 0; /* Number of entries in poll_list */
122 static int last_resume_pid
= -1; /* Last pid used with procfs_resume */
124 /* Much of the information used in the /proc interface, particularly for
125 printing status information, is kept as tables of structures of the
126 following form. These tables can be used to map numeric values to
127 their symbolic names and to a string that describes their specific use. */
130 int value
; /* The numeric value */
131 char *name
; /* The equivalent symbolic value */
132 char *desc
; /* Short description of value */
135 /* Translate bits in the pr_flags member of the prstatus structure, into the
136 names and desc information. */
138 static struct trans pr_flag_table
[] =
140 #if defined (PR_STOPPED)
141 { PR_STOPPED
, "PR_STOPPED", "Process is stopped" },
143 #if defined (PR_ISTOP)
144 { PR_ISTOP
, "PR_ISTOP", "Stopped on an event of interest" },
146 #if defined (PR_DSTOP)
147 { PR_DSTOP
, "PR_DSTOP", "A stop directive is in effect" },
149 #if defined (PR_ASLEEP)
150 { PR_ASLEEP
, "PR_ASLEEP", "Sleeping in an interruptible system call" },
152 #if defined (PR_FORK)
153 { PR_FORK
, "PR_FORK", "Inherit-on-fork is in effect" },
156 { PR_RLC
, "PR_RLC", "Run-on-last-close is in effect" },
158 #if defined (PR_PTRACE)
159 { PR_PTRACE
, "PR_PTRACE", "Process is being controlled by ptrace" },
161 #if defined (PR_PCINVAL)
162 { PR_PCINVAL
, "PR_PCINVAL", "PC refers to an invalid virtual address" },
164 #if defined (PR_ISSYS)
165 { PR_ISSYS
, "PR_ISSYS", "Is a system process" },
167 #if defined (PR_STEP)
168 { PR_STEP
, "PR_STEP", "Process has single step pending" },
171 { PR_KLC
, "PR_KLC", "Kill-on-last-close is in effect" },
173 #if defined (PR_ASYNC)
174 { PR_ASYNC
, "PR_ASYNC", "Asynchronous stop is in effect" },
176 #if defined (PR_PCOMPAT)
177 { PR_PCOMPAT
, "PR_PCOMPAT", "Ptrace compatibility mode in effect" },
182 /* Translate values in the pr_why field of the prstatus struct. */
184 static struct trans pr_why_table
[] =
186 #if defined (PR_REQUESTED)
187 { PR_REQUESTED
, "PR_REQUESTED", "Directed to stop via PIOCSTOP/PIOCWSTOP" },
189 #if defined (PR_SIGNALLED)
190 { PR_SIGNALLED
, "PR_SIGNALLED", "Receipt of a traced signal" },
192 #if defined (PR_FAULTED)
193 { PR_FAULTED
, "PR_FAULTED", "Incurred a traced hardware fault" },
195 #if defined (PR_SYSENTRY)
196 { PR_SYSENTRY
, "PR_SYSENTRY", "Entry to a traced system call" },
198 #if defined (PR_SYSEXIT)
199 { PR_SYSEXIT
, "PR_SYSEXIT", "Exit from a traced system call" },
201 #if defined (PR_JOBCONTROL)
202 { PR_JOBCONTROL
, "PR_JOBCONTROL", "Default job control stop signal action" },
204 #if defined (PR_SUSPENDED)
205 { PR_SUSPENDED
, "PR_SUSPENDED", "Process suspended" },
210 /* Hardware fault translation table. */
212 static struct trans faults_table
[] =
215 { FLTILL
, "FLTILL", "Illegal instruction" },
217 #if defined (FLTPRIV)
218 { FLTPRIV
, "FLTPRIV", "Privileged instruction" },
221 { FLTBPT
, "FLTBPT", "Breakpoint trap" },
223 #if defined (FLTTRACE)
224 { FLTTRACE
, "FLTTRACE", "Trace trap" },
226 #if defined (FLTACCESS)
227 { FLTACCESS
, "FLTACCESS", "Memory access fault" },
229 #if defined (FLTBOUNDS)
230 { FLTBOUNDS
, "FLTBOUNDS", "Memory bounds violation" },
232 #if defined (FLTIOVF)
233 { FLTIOVF
, "FLTIOVF", "Integer overflow" },
235 #if defined (FLTIZDIV)
236 { FLTIZDIV
, "FLTIZDIV", "Integer zero divide" },
239 { FLTFPE
, "FLTFPE", "Floating-point exception" },
241 #if defined (FLTSTACK)
242 { FLTSTACK
, "FLTSTACK", "Unrecoverable stack fault" },
244 #if defined (FLTPAGE)
245 { FLTPAGE
, "FLTPAGE", "Recoverable page fault" },
250 /* Translation table for signal generation information. See UNIX System
251 V Release 4 Programmer's Reference Manual, siginfo(5). */
253 static struct sigcode
{
258 } siginfo_table
[] = {
259 #if defined (SIGILL) && defined (ILL_ILLOPC)
260 { SIGILL
, ILL_ILLOPC
, "ILL_ILLOPC", "Illegal opcode" },
262 #if defined (SIGILL) && defined (ILL_ILLOPN)
263 { SIGILL
, ILL_ILLOPN
, "ILL_ILLOPN", "Illegal operand", },
265 #if defined (SIGILL) && defined (ILL_ILLADR)
266 { SIGILL
, ILL_ILLADR
, "ILL_ILLADR", "Illegal addressing mode" },
268 #if defined (SIGILL) && defined (ILL_ILLTRP)
269 { SIGILL
, ILL_ILLTRP
, "ILL_ILLTRP", "Illegal trap" },
271 #if defined (SIGILL) && defined (ILL_PRVOPC)
272 { SIGILL
, ILL_PRVOPC
, "ILL_PRVOPC", "Privileged opcode" },
274 #if defined (SIGILL) && defined (ILL_PRVREG)
275 { SIGILL
, ILL_PRVREG
, "ILL_PRVREG", "Privileged register" },
277 #if defined (SIGILL) && defined (ILL_COPROC)
278 { SIGILL
, ILL_COPROC
, "ILL_COPROC", "Coprocessor error" },
280 #if defined (SIGILL) && defined (ILL_BADSTK)
281 { SIGILL
, ILL_BADSTK
, "ILL_BADSTK", "Internal stack error" },
283 #if defined (SIGFPE) && defined (FPE_INTDIV)
284 { SIGFPE
, FPE_INTDIV
, "FPE_INTDIV", "Integer divide by zero" },
286 #if defined (SIGFPE) && defined (FPE_INTOVF)
287 { SIGFPE
, FPE_INTOVF
, "FPE_INTOVF", "Integer overflow" },
289 #if defined (SIGFPE) && defined (FPE_FLTDIV)
290 { SIGFPE
, FPE_FLTDIV
, "FPE_FLTDIV", "Floating point divide by zero" },
292 #if defined (SIGFPE) && defined (FPE_FLTOVF)
293 { SIGFPE
, FPE_FLTOVF
, "FPE_FLTOVF", "Floating point overflow" },
295 #if defined (SIGFPE) && defined (FPE_FLTUND)
296 { SIGFPE
, FPE_FLTUND
, "FPE_FLTUND", "Floating point underflow" },
298 #if defined (SIGFPE) && defined (FPE_FLTRES)
299 { SIGFPE
, FPE_FLTRES
, "FPE_FLTRES", "Floating point inexact result" },
301 #if defined (SIGFPE) && defined (FPE_FLTINV)
302 { SIGFPE
, FPE_FLTINV
, "FPE_FLTINV", "Invalid floating point operation" },
304 #if defined (SIGFPE) && defined (FPE_FLTSUB)
305 { SIGFPE
, FPE_FLTSUB
, "FPE_FLTSUB", "Subscript out of range" },
307 #if defined (SIGSEGV) && defined (SEGV_MAPERR)
308 { SIGSEGV
, SEGV_MAPERR
, "SEGV_MAPERR", "Address not mapped to object" },
310 #if defined (SIGSEGV) && defined (SEGV_ACCERR)
311 { SIGSEGV
, SEGV_ACCERR
, "SEGV_ACCERR", "Invalid permissions for object" },
313 #if defined (SIGBUS) && defined (BUS_ADRALN)
314 { SIGBUS
, BUS_ADRALN
, "BUS_ADRALN", "Invalid address alignment" },
316 #if defined (SIGBUS) && defined (BUS_ADRERR)
317 { SIGBUS
, BUS_ADRERR
, "BUS_ADRERR", "Non-existent physical address" },
319 #if defined (SIGBUS) && defined (BUS_OBJERR)
320 { SIGBUS
, BUS_OBJERR
, "BUS_OBJERR", "Object specific hardware error" },
322 #if defined (SIGTRAP) && defined (TRAP_BRKPT)
323 { SIGTRAP
, TRAP_BRKPT
, "TRAP_BRKPT", "Process breakpoint" },
325 #if defined (SIGTRAP) && defined (TRAP_TRACE)
326 { SIGTRAP
, TRAP_TRACE
, "TRAP_TRACE", "Process trace trap" },
328 #if defined (SIGCLD) && defined (CLD_EXITED)
329 { SIGCLD
, CLD_EXITED
, "CLD_EXITED", "Child has exited" },
331 #if defined (SIGCLD) && defined (CLD_KILLED)
332 { SIGCLD
, CLD_KILLED
, "CLD_KILLED", "Child was killed" },
334 #if defined (SIGCLD) && defined (CLD_DUMPED)
335 { SIGCLD
, CLD_DUMPED
, "CLD_DUMPED", "Child has terminated abnormally" },
337 #if defined (SIGCLD) && defined (CLD_TRAPPED)
338 { SIGCLD
, CLD_TRAPPED
, "CLD_TRAPPED", "Traced child has trapped" },
340 #if defined (SIGCLD) && defined (CLD_STOPPED)
341 { SIGCLD
, CLD_STOPPED
, "CLD_STOPPED", "Child has stopped" },
343 #if defined (SIGCLD) && defined (CLD_CONTINUED)
344 { SIGCLD
, CLD_CONTINUED
, "CLD_CONTINUED", "Stopped child had continued" },
346 #if defined (SIGPOLL) && defined (POLL_IN)
347 { SIGPOLL
, POLL_IN
, "POLL_IN", "Input input available" },
349 #if defined (SIGPOLL) && defined (POLL_OUT)
350 { SIGPOLL
, POLL_OUT
, "POLL_OUT", "Output buffers available" },
352 #if defined (SIGPOLL) && defined (POLL_MSG)
353 { SIGPOLL
, POLL_MSG
, "POLL_MSG", "Input message available" },
355 #if defined (SIGPOLL) && defined (POLL_ERR)
356 { SIGPOLL
, POLL_ERR
, "POLL_ERR", "I/O error" },
358 #if defined (SIGPOLL) && defined (POLL_PRI)
359 { SIGPOLL
, POLL_PRI
, "POLL_PRI", "High priority input available" },
361 #if defined (SIGPOLL) && defined (POLL_HUP)
362 { SIGPOLL
, POLL_HUP
, "POLL_HUP", "Device disconnected" },
367 static char *syscall_table
[MAX_SYSCALLS
];
369 /* Prototypes for local functions */
371 static void set_proc_siginfo
PARAMS ((struct procinfo
*, int));
373 static void init_syscall_table
PARAMS ((void));
375 static char *syscallname
PARAMS ((int));
377 static char *signalname
PARAMS ((int));
379 static char *errnoname
PARAMS ((int));
381 static int proc_address_to_fd
PARAMS ((struct procinfo
*, CORE_ADDR
, int));
383 static int open_proc_file
PARAMS ((int, struct procinfo
*, int));
385 static void close_proc_file
PARAMS ((struct procinfo
*));
387 static void unconditionally_kill_inferior
PARAMS ((struct procinfo
*));
389 static NORETURN
void proc_init_failed
PARAMS ((struct procinfo
*, char *)) ATTR_NORETURN
;
391 static void info_proc
PARAMS ((char *, int));
393 static void info_proc_flags
PARAMS ((struct procinfo
*, int));
395 static void info_proc_stop
PARAMS ((struct procinfo
*, int));
397 static void info_proc_siginfo
PARAMS ((struct procinfo
*, int));
399 static void info_proc_syscalls
PARAMS ((struct procinfo
*, int));
401 static void info_proc_mappings
PARAMS ((struct procinfo
*, int));
403 static void info_proc_signals
PARAMS ((struct procinfo
*, int));
405 static void info_proc_faults
PARAMS ((struct procinfo
*, int));
407 static char *mappingflags
PARAMS ((long));
409 static char *lookupname
PARAMS ((struct trans
*, unsigned int, char *));
411 static char *lookupdesc
PARAMS ((struct trans
*, unsigned int));
413 static int do_attach
PARAMS ((int pid
));
415 static void do_detach
PARAMS ((int siggnal
));
417 static void procfs_create_inferior
PARAMS ((char *, char *, char **));
419 static void procfs_notice_signals
PARAMS ((int pid
));
421 static struct procinfo
*find_procinfo
PARAMS ((pid_t pid
, int okfail
));
423 typedef int syscall_func_t
PARAMS ((struct procinfo
*pi
, int syscall_num
,
424 int why
, int *rtnval
, int *statval
));
426 static void procfs_set_syscall_trap
PARAMS ((struct procinfo
*pi
,
427 int syscall_num
, int flags
,
428 syscall_func_t
*func
));
430 static void procfs_clear_syscall_trap
PARAMS ((struct procinfo
*pi
,
431 int syscall_num
, int errok
));
433 #define PROCFS_SYSCALL_ENTRY 0x1 /* Trap on entry to sys call */
434 #define PROCFS_SYSCALL_EXIT 0x2 /* Trap on exit from sys call */
436 static syscall_func_t procfs_exit_handler
;
438 static syscall_func_t procfs_exec_handler
;
441 static syscall_func_t procfs_sproc_handler
;
442 static syscall_func_t procfs_fork_handler
;
445 #ifdef SYS_lwp_create
446 static syscall_func_t procfs_lwp_creation_handler
;
449 static void modify_inherit_on_fork_flag
PARAMS ((int fd
, int flag
));
450 static void modify_run_on_last_close_flag
PARAMS ((int fd
, int flag
));
454 struct procfs_syscall_handler
456 int syscall_num
; /* The number of the system call being handled */
457 /* The function to be called */
458 syscall_func_t
*func
;
461 static void procfs_resume
PARAMS ((int pid
, int step
,
462 enum target_signal signo
));
464 /* External function prototypes that can't be easily included in any
465 header file because the args are typedefs in system include files. */
467 extern void supply_gregset
PARAMS ((gregset_t
*));
469 extern void fill_gregset
PARAMS ((gregset_t
*, int));
471 extern void supply_fpregset
PARAMS ((fpregset_t
*));
473 extern void fill_fpregset
PARAMS ((fpregset_t
*, int));
479 find_procinfo -- convert a process id to a struct procinfo
483 static struct procinfo * find_procinfo (pid_t pid, int okfail);
487 Given a process id, look it up in the procinfo chain. Returns
488 a struct procinfo *. If can't find pid, then call error(),
489 unless okfail is set, in which case, return NULL;
492 static struct procinfo
*
493 find_procinfo (pid
, okfail
)
497 struct procinfo
*procinfo
;
499 for (procinfo
= procinfo_list
; procinfo
; procinfo
= procinfo
->next
)
500 if (procinfo
->pid
== pid
)
506 error ("procfs (find_procinfo): Couldn't locate pid %d", pid
);
513 current_procinfo -- convert inferior_pid to a struct procinfo
517 static struct procinfo * current_procinfo;
521 Looks up inferior_pid in the procinfo chain. Always returns a
522 struct procinfo *. If process can't be found, we error() out.
525 #define current_procinfo find_procinfo (inferior_pid, 0)
531 add_fd -- Add the fd to the poll/select list
535 static void add_fd (struct procinfo *);
539 Add the fd of the supplied procinfo to the list of fds used for
540 poll/select operations.
547 if (num_poll_list
<= 0)
548 poll_list
= (struct pollfd
*) xmalloc (sizeof (struct pollfd
));
550 poll_list
= (struct pollfd
*) xrealloc (poll_list
,
552 * sizeof (struct pollfd
));
553 poll_list
[num_poll_list
].fd
= pi
->fd
;
554 poll_list
[num_poll_list
].events
= POLLPRI
;
565 for (i
= 0; i
< num_poll_list
; i
++)
567 if (poll_list
[i
].fd
== pi
->fd
)
569 if (i
!= num_poll_list
- 1)
570 memcpy (poll_list
+ i
, poll_list
+ i
+ 1,
571 (num_poll_list
- i
- 1) * sizeof (struct pollfd
));
575 if (num_poll_list
== 0)
578 poll_list
= (struct pollfd
*) xrealloc (poll_list
,
580 * sizeof (struct pollfd
));
586 static struct procinfo
*
593 set_sigint_trap (); /* Causes SIGINT to be passed on to the
598 num_fds
= poll (poll_list
, num_poll_list
, -1);
600 pi
= current_procinfo
;
602 while (ioctl (pi
->fd
, PIOCWSTOP
, &pi
->prstatus
) < 0)
606 /* Process exited. */
607 pi
->prstatus
.pr_flags
= 0;
610 else if (errno
!= EINTR
)
612 print_sys_errmsg (pi
->pathname
, errno
);
613 error ("PIOCWSTOP failed");
619 clear_sigint_trap ();
626 print_sys_errmsg ("poll failed\n", errno
);
627 error ("Poll failed, returned %d", num_fds
);
630 for (i
= 0; i
< num_poll_list
&& num_fds
> 0; i
++)
632 if ((poll_list
[i
].revents
& (POLLPRI
|POLLERR
|POLLHUP
|POLLNVAL
)) == 0)
634 for (pi
= procinfo_list
; pi
; pi
= pi
->next
)
636 if (poll_list
[i
].fd
== pi
->fd
)
638 if (ioctl (pi
->fd
, PIOCSTATUS
, &pi
->prstatus
) < 0)
640 print_sys_errmsg (pi
->pathname
, errno
);
641 error ("PIOCSTATUS failed");
649 error ("wait_fd: Couldn't find procinfo for fd %d\n",
652 #endif /* LOSING_POLL */
661 lookupdesc -- translate a value to a summary desc string
665 static char *lookupdesc (struct trans *transp, unsigned int val);
669 Given a pointer to a translation table and a value to be translated,
670 lookup the desc string and return it.
674 lookupdesc (transp
, val
)
675 struct trans
*transp
;
680 for (desc
= NULL
; transp
-> name
!= NULL
; transp
++)
682 if (transp
-> value
== val
)
684 desc
= transp
-> desc
;
689 /* Didn't find a translation for the specified value, set a default one. */
702 lookupname -- translate a value to symbolic name
706 static char *lookupname (struct trans *transp, unsigned int val,
711 Given a pointer to a translation table, a value to be translated,
712 and a default prefix to return if the value can't be translated,
713 match the value with one of the translation table entries and
714 return a pointer to the symbolic name.
716 If no match is found it just returns the value as a printable string,
717 with the given prefix. The previous such value, if any, is freed
722 lookupname (transp
, val
, prefix
)
723 struct trans
*transp
;
730 for (name
= NULL
; transp
-> name
!= NULL
; transp
++)
732 if (transp
-> value
== val
)
734 name
= transp
-> name
;
739 /* Didn't find a translation for the specified value, build a default
740 one using the specified prefix and return it. The lifetime of
741 the value is only until the next one is needed. */
749 locbuf
= xmalloc (strlen (prefix
) + 16);
750 sprintf (locbuf
, "%s %u", prefix
, val
);
762 static char locbuf
[32];
764 for (scp
= siginfo_table
; scp
-> codename
!= NULL
; scp
++)
766 if ((scp
-> signo
== sip
-> si_signo
) &&
767 (scp
-> code
== sip
-> si_code
))
769 name
= scp
-> codename
;
775 sprintf (locbuf
, "sigcode %u", sip
-> si_signo
);
788 for (scp
= siginfo_table
; scp
-> codename
!= NULL
; scp
++)
790 if ((scp
-> signo
== sip
-> si_signo
) &&
791 (scp
-> code
== sip
-> si_code
))
799 desc
= "Unrecognized signal or trap use";
808 syscallname - translate a system call number into a system call name
812 char *syscallname (int syscallnum)
816 Given a system call number, translate it into the printable name
817 of a system call, or into "syscall <num>" if it is an unknown
822 syscallname (syscallnum
)
825 static char locbuf
[32];
827 if (syscallnum
>= 0 && syscallnum
< MAX_SYSCALLS
828 && syscall_table
[syscallnum
] != NULL
)
829 return syscall_table
[syscallnum
];
832 sprintf (locbuf
, "syscall %u", syscallnum
);
841 init_syscall_table - initialize syscall translation table
845 void init_syscall_table (void)
849 Dynamically initialize the translation table to convert system
850 call numbers into printable system call names. Done once per
851 gdb run, on initialization.
855 This is awfully ugly, but preprocessor tricks to make it prettier
856 tend to be nonportable.
860 init_syscall_table ()
862 #if defined (SYS_exit)
863 syscall_table
[SYS_exit
] = "exit";
865 #if defined (SYS_fork)
866 syscall_table
[SYS_fork
] = "fork";
868 #if defined (SYS_read)
869 syscall_table
[SYS_read
] = "read";
871 #if defined (SYS_write)
872 syscall_table
[SYS_write
] = "write";
874 #if defined (SYS_open)
875 syscall_table
[SYS_open
] = "open";
877 #if defined (SYS_close)
878 syscall_table
[SYS_close
] = "close";
880 #if defined (SYS_wait)
881 syscall_table
[SYS_wait
] = "wait";
883 #if defined (SYS_creat)
884 syscall_table
[SYS_creat
] = "creat";
886 #if defined (SYS_link)
887 syscall_table
[SYS_link
] = "link";
889 #if defined (SYS_unlink)
890 syscall_table
[SYS_unlink
] = "unlink";
892 #if defined (SYS_exec)
893 syscall_table
[SYS_exec
] = "exec";
895 #if defined (SYS_execv)
896 syscall_table
[SYS_execv
] = "execv";
898 #if defined (SYS_execve)
899 syscall_table
[SYS_execve
] = "execve";
901 #if defined (SYS_chdir)
902 syscall_table
[SYS_chdir
] = "chdir";
904 #if defined (SYS_time)
905 syscall_table
[SYS_time
] = "time";
907 #if defined (SYS_mknod)
908 syscall_table
[SYS_mknod
] = "mknod";
910 #if defined (SYS_chmod)
911 syscall_table
[SYS_chmod
] = "chmod";
913 #if defined (SYS_chown)
914 syscall_table
[SYS_chown
] = "chown";
916 #if defined (SYS_brk)
917 syscall_table
[SYS_brk
] = "brk";
919 #if defined (SYS_stat)
920 syscall_table
[SYS_stat
] = "stat";
922 #if defined (SYS_lseek)
923 syscall_table
[SYS_lseek
] = "lseek";
925 #if defined (SYS_getpid)
926 syscall_table
[SYS_getpid
] = "getpid";
928 #if defined (SYS_mount)
929 syscall_table
[SYS_mount
] = "mount";
931 #if defined (SYS_umount)
932 syscall_table
[SYS_umount
] = "umount";
934 #if defined (SYS_setuid)
935 syscall_table
[SYS_setuid
] = "setuid";
937 #if defined (SYS_getuid)
938 syscall_table
[SYS_getuid
] = "getuid";
940 #if defined (SYS_stime)
941 syscall_table
[SYS_stime
] = "stime";
943 #if defined (SYS_ptrace)
944 syscall_table
[SYS_ptrace
] = "ptrace";
946 #if defined (SYS_alarm)
947 syscall_table
[SYS_alarm
] = "alarm";
949 #if defined (SYS_fstat)
950 syscall_table
[SYS_fstat
] = "fstat";
952 #if defined (SYS_pause)
953 syscall_table
[SYS_pause
] = "pause";
955 #if defined (SYS_utime)
956 syscall_table
[SYS_utime
] = "utime";
958 #if defined (SYS_stty)
959 syscall_table
[SYS_stty
] = "stty";
961 #if defined (SYS_gtty)
962 syscall_table
[SYS_gtty
] = "gtty";
964 #if defined (SYS_access)
965 syscall_table
[SYS_access
] = "access";
967 #if defined (SYS_nice)
968 syscall_table
[SYS_nice
] = "nice";
970 #if defined (SYS_statfs)
971 syscall_table
[SYS_statfs
] = "statfs";
973 #if defined (SYS_sync)
974 syscall_table
[SYS_sync
] = "sync";
976 #if defined (SYS_kill)
977 syscall_table
[SYS_kill
] = "kill";
979 #if defined (SYS_fstatfs)
980 syscall_table
[SYS_fstatfs
] = "fstatfs";
982 #if defined (SYS_pgrpsys)
983 syscall_table
[SYS_pgrpsys
] = "pgrpsys";
985 #if defined (SYS_xenix)
986 syscall_table
[SYS_xenix
] = "xenix";
988 #if defined (SYS_dup)
989 syscall_table
[SYS_dup
] = "dup";
991 #if defined (SYS_pipe)
992 syscall_table
[SYS_pipe
] = "pipe";
994 #if defined (SYS_times)
995 syscall_table
[SYS_times
] = "times";
997 #if defined (SYS_profil)
998 syscall_table
[SYS_profil
] = "profil";
1000 #if defined (SYS_plock)
1001 syscall_table
[SYS_plock
] = "plock";
1003 #if defined (SYS_setgid)
1004 syscall_table
[SYS_setgid
] = "setgid";
1006 #if defined (SYS_getgid)
1007 syscall_table
[SYS_getgid
] = "getgid";
1009 #if defined (SYS_signal)
1010 syscall_table
[SYS_signal
] = "signal";
1012 #if defined (SYS_msgsys)
1013 syscall_table
[SYS_msgsys
] = "msgsys";
1015 #if defined (SYS_sys3b)
1016 syscall_table
[SYS_sys3b
] = "sys3b";
1018 #if defined (SYS_acct)
1019 syscall_table
[SYS_acct
] = "acct";
1021 #if defined (SYS_shmsys)
1022 syscall_table
[SYS_shmsys
] = "shmsys";
1024 #if defined (SYS_semsys)
1025 syscall_table
[SYS_semsys
] = "semsys";
1027 #if defined (SYS_ioctl)
1028 syscall_table
[SYS_ioctl
] = "ioctl";
1030 #if defined (SYS_uadmin)
1031 syscall_table
[SYS_uadmin
] = "uadmin";
1033 #if defined (SYS_utssys)
1034 syscall_table
[SYS_utssys
] = "utssys";
1036 #if defined (SYS_fsync)
1037 syscall_table
[SYS_fsync
] = "fsync";
1039 #if defined (SYS_umask)
1040 syscall_table
[SYS_umask
] = "umask";
1042 #if defined (SYS_chroot)
1043 syscall_table
[SYS_chroot
] = "chroot";
1045 #if defined (SYS_fcntl)
1046 syscall_table
[SYS_fcntl
] = "fcntl";
1048 #if defined (SYS_ulimit)
1049 syscall_table
[SYS_ulimit
] = "ulimit";
1051 #if defined (SYS_rfsys)
1052 syscall_table
[SYS_rfsys
] = "rfsys";
1054 #if defined (SYS_rmdir)
1055 syscall_table
[SYS_rmdir
] = "rmdir";
1057 #if defined (SYS_mkdir)
1058 syscall_table
[SYS_mkdir
] = "mkdir";
1060 #if defined (SYS_getdents)
1061 syscall_table
[SYS_getdents
] = "getdents";
1063 #if defined (SYS_sysfs)
1064 syscall_table
[SYS_sysfs
] = "sysfs";
1066 #if defined (SYS_getmsg)
1067 syscall_table
[SYS_getmsg
] = "getmsg";
1069 #if defined (SYS_putmsg)
1070 syscall_table
[SYS_putmsg
] = "putmsg";
1072 #if defined (SYS_poll)
1073 syscall_table
[SYS_poll
] = "poll";
1075 #if defined (SYS_lstat)
1076 syscall_table
[SYS_lstat
] = "lstat";
1078 #if defined (SYS_symlink)
1079 syscall_table
[SYS_symlink
] = "symlink";
1081 #if defined (SYS_readlink)
1082 syscall_table
[SYS_readlink
] = "readlink";
1084 #if defined (SYS_setgroups)
1085 syscall_table
[SYS_setgroups
] = "setgroups";
1087 #if defined (SYS_getgroups)
1088 syscall_table
[SYS_getgroups
] = "getgroups";
1090 #if defined (SYS_fchmod)
1091 syscall_table
[SYS_fchmod
] = "fchmod";
1093 #if defined (SYS_fchown)
1094 syscall_table
[SYS_fchown
] = "fchown";
1096 #if defined (SYS_sigprocmask)
1097 syscall_table
[SYS_sigprocmask
] = "sigprocmask";
1099 #if defined (SYS_sigsuspend)
1100 syscall_table
[SYS_sigsuspend
] = "sigsuspend";
1102 #if defined (SYS_sigaltstack)
1103 syscall_table
[SYS_sigaltstack
] = "sigaltstack";
1105 #if defined (SYS_sigaction)
1106 syscall_table
[SYS_sigaction
] = "sigaction";
1108 #if defined (SYS_sigpending)
1109 syscall_table
[SYS_sigpending
] = "sigpending";
1111 #if defined (SYS_context)
1112 syscall_table
[SYS_context
] = "context";
1114 #if defined (SYS_evsys)
1115 syscall_table
[SYS_evsys
] = "evsys";
1117 #if defined (SYS_evtrapret)
1118 syscall_table
[SYS_evtrapret
] = "evtrapret";
1120 #if defined (SYS_statvfs)
1121 syscall_table
[SYS_statvfs
] = "statvfs";
1123 #if defined (SYS_fstatvfs)
1124 syscall_table
[SYS_fstatvfs
] = "fstatvfs";
1126 #if defined (SYS_nfssys)
1127 syscall_table
[SYS_nfssys
] = "nfssys";
1129 #if defined (SYS_waitsys)
1130 syscall_table
[SYS_waitsys
] = "waitsys";
1132 #if defined (SYS_sigsendsys)
1133 syscall_table
[SYS_sigsendsys
] = "sigsendsys";
1135 #if defined (SYS_hrtsys)
1136 syscall_table
[SYS_hrtsys
] = "hrtsys";
1138 #if defined (SYS_acancel)
1139 syscall_table
[SYS_acancel
] = "acancel";
1141 #if defined (SYS_async)
1142 syscall_table
[SYS_async
] = "async";
1144 #if defined (SYS_priocntlsys)
1145 syscall_table
[SYS_priocntlsys
] = "priocntlsys";
1147 #if defined (SYS_pathconf)
1148 syscall_table
[SYS_pathconf
] = "pathconf";
1150 #if defined (SYS_mincore)
1151 syscall_table
[SYS_mincore
] = "mincore";
1153 #if defined (SYS_mmap)
1154 syscall_table
[SYS_mmap
] = "mmap";
1156 #if defined (SYS_mprotect)
1157 syscall_table
[SYS_mprotect
] = "mprotect";
1159 #if defined (SYS_munmap)
1160 syscall_table
[SYS_munmap
] = "munmap";
1162 #if defined (SYS_fpathconf)
1163 syscall_table
[SYS_fpathconf
] = "fpathconf";
1165 #if defined (SYS_vfork)
1166 syscall_table
[SYS_vfork
] = "vfork";
1168 #if defined (SYS_fchdir)
1169 syscall_table
[SYS_fchdir
] = "fchdir";
1171 #if defined (SYS_readv)
1172 syscall_table
[SYS_readv
] = "readv";
1174 #if defined (SYS_writev)
1175 syscall_table
[SYS_writev
] = "writev";
1177 #if defined (SYS_xstat)
1178 syscall_table
[SYS_xstat
] = "xstat";
1180 #if defined (SYS_lxstat)
1181 syscall_table
[SYS_lxstat
] = "lxstat";
1183 #if defined (SYS_fxstat)
1184 syscall_table
[SYS_fxstat
] = "fxstat";
1186 #if defined (SYS_xmknod)
1187 syscall_table
[SYS_xmknod
] = "xmknod";
1189 #if defined (SYS_clocal)
1190 syscall_table
[SYS_clocal
] = "clocal";
1192 #if defined (SYS_setrlimit)
1193 syscall_table
[SYS_setrlimit
] = "setrlimit";
1195 #if defined (SYS_getrlimit)
1196 syscall_table
[SYS_getrlimit
] = "getrlimit";
1198 #if defined (SYS_lchown)
1199 syscall_table
[SYS_lchown
] = "lchown";
1201 #if defined (SYS_memcntl)
1202 syscall_table
[SYS_memcntl
] = "memcntl";
1204 #if defined (SYS_getpmsg)
1205 syscall_table
[SYS_getpmsg
] = "getpmsg";
1207 #if defined (SYS_putpmsg)
1208 syscall_table
[SYS_putpmsg
] = "putpmsg";
1210 #if defined (SYS_rename)
1211 syscall_table
[SYS_rename
] = "rename";
1213 #if defined (SYS_uname)
1214 syscall_table
[SYS_uname
] = "uname";
1216 #if defined (SYS_setegid)
1217 syscall_table
[SYS_setegid
] = "setegid";
1219 #if defined (SYS_sysconfig)
1220 syscall_table
[SYS_sysconfig
] = "sysconfig";
1222 #if defined (SYS_adjtime)
1223 syscall_table
[SYS_adjtime
] = "adjtime";
1225 #if defined (SYS_systeminfo)
1226 syscall_table
[SYS_systeminfo
] = "systeminfo";
1228 #if defined (SYS_seteuid)
1229 syscall_table
[SYS_seteuid
] = "seteuid";
1231 #if defined (SYS_sproc)
1232 syscall_table
[SYS_sproc
] = "sproc";
1240 procfs_kill_inferior - kill any currently inferior
1244 void procfs_kill_inferior (void)
1248 Kill any current inferior.
1252 Kills even attached inferiors. Presumably the user has already
1253 been prompted that the inferior is an attached one rather than
1254 one started by gdb. (FIXME?)
1259 procfs_kill_inferior ()
1261 target_mourn_inferior ();
1268 unconditionally_kill_inferior - terminate the inferior
1272 static void unconditionally_kill_inferior (struct procinfo *)
1276 Kill the specified inferior.
1280 A possibly useful enhancement would be to first try sending
1281 the inferior a terminate signal, politely asking it to commit
1282 suicide, before we murder it (we could call that
1283 politely_kill_inferior()).
1288 unconditionally_kill_inferior (pi
)
1289 struct procinfo
*pi
;
1294 ppid
= pi
->prstatus
.pr_ppid
;
1298 #ifdef PROCFS_NEED_CLEAR_CURSIG_FOR_KILL
1299 /* Alpha OSF/1-3.x procfs needs a clear of the current signal
1300 before the PIOCKILL, otherwise it might generate a corrupted core
1301 file for the inferior. */
1302 ioctl (pi
->fd
, PIOCSSIG
, NULL
);
1304 #ifdef PROCFS_NEED_PIOCSSIG_FOR_KILL
1305 /* Alpha OSF/1-2.x procfs needs a PIOCSSIG call with a SIGKILL signal
1306 to kill the inferior, otherwise it might remain stopped with a
1308 We do not check the result of the PIOCSSIG, the inferior might have
1311 struct siginfo newsiginfo
;
1313 memset ((char *) &newsiginfo
, 0, sizeof (newsiginfo
));
1314 newsiginfo
.si_signo
= signo
;
1315 newsiginfo
.si_code
= 0;
1316 newsiginfo
.si_errno
= 0;
1317 newsiginfo
.si_pid
= getpid ();
1318 newsiginfo
.si_uid
= getuid ();
1319 ioctl (pi
->fd
, PIOCSSIG
, &newsiginfo
);
1322 ioctl (pi
->fd
, PIOCKILL
, &signo
);
1325 close_proc_file (pi
);
1327 /* Only wait() for our direct children. Our grandchildren zombies are killed
1328 by the death of their parents. */
1330 if (ppid
== getpid())
1338 procfs_xfer_memory -- copy data to or from inferior memory space
1342 int procfs_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len,
1343 int dowrite, struct target_ops target)
1347 Copy LEN bytes to/from inferior's memory starting at MEMADDR
1348 from/to debugger memory starting at MYADDR. Copy from inferior
1349 if DOWRITE is zero or to inferior if DOWRITE is nonzero.
1351 Returns the length copied, which is either the LEN argument or
1352 zero. This xfer function does not do partial moves, since procfs_ops
1353 doesn't allow memory operations to cross below us in the target stack
1358 The /proc interface makes this an almost trivial task.
1362 procfs_xfer_memory (memaddr
, myaddr
, len
, dowrite
, target
)
1367 struct target_ops
*target
; /* ignored */
1370 struct procinfo
*pi
;
1372 pi
= current_procinfo
;
1374 if (lseek(pi
->fd
, (off_t
) memaddr
, 0) == (off_t
) memaddr
)
1378 nbytes
= write (pi
->fd
, myaddr
, len
);
1382 nbytes
= read (pi
->fd
, myaddr
, len
);
1396 procfs_store_registers -- copy register values back to inferior
1400 void procfs_store_registers (int regno)
1404 Store our current register values back into the inferior. If
1405 REGNO is -1 then store all the register, otherwise store just
1406 the value specified by REGNO.
1410 If we are storing only a single register, we first have to get all
1411 the current values from the process, overwrite the desired register
1412 in the gregset with the one we want from gdb's registers, and then
1413 send the whole set back to the process. For writing all the
1414 registers, all we have to do is generate the gregset and send it to
1417 Also note that the process has to be stopped on an event of interest
1418 for this to work, which basically means that it has to have been
1419 run under the control of one of the other /proc ioctl calls and not
1420 ptrace. Since we don't use ptrace anyway, we don't worry about this
1421 fine point, but it is worth noting for future reference.
1423 Gdb is confused about what this function is supposed to return.
1424 Some versions return a value, others return nothing. Some are
1425 declared to return a value and actually return nothing. Gdb ignores
1426 anything returned. (FIXME)
1431 procfs_store_registers (regno
)
1434 struct procinfo
*pi
;
1436 pi
= current_procinfo
;
1440 ioctl (pi
->fd
, PIOCGREG
, &pi
->gregset
);
1442 fill_gregset (&pi
->gregset
, regno
);
1443 ioctl (pi
->fd
, PIOCSREG
, &pi
->gregset
);
1445 #if defined (FP0_REGNUM)
1447 /* Now repeat everything using the floating point register set, if the
1448 target has floating point hardware. Since we ignore the returned value,
1449 we'll never know whether it worked or not anyway. */
1453 ioctl (pi
->fd
, PIOCGFPREG
, &pi
->fpregset
);
1455 fill_fpregset (&pi
->fpregset
, regno
);
1456 ioctl (pi
->fd
, PIOCSFPREG
, &pi
->fpregset
);
1458 #endif /* FP0_REGNUM */
1466 create_procinfo - initialize access to a /proc entry
1470 struct procinfo * create_procinfo (int pid)
1474 Allocate a procinfo structure, open the /proc file and then set up the
1475 set of signals and faults that are to be traced. Returns a pointer to
1476 the new procinfo structure.
1480 If proc_init_failed ever gets called, control returns to the command
1481 processing loop via the standard error handling code.
1485 static struct procinfo
*
1486 create_procinfo (pid
)
1489 struct procinfo
*pi
;
1491 pi
= find_procinfo (pid
, 1);
1493 return pi
; /* All done! It already exists */
1495 pi
= (struct procinfo
*) xmalloc (sizeof (struct procinfo
));
1497 if (!open_proc_file (pid
, pi
, O_RDWR
))
1498 proc_init_failed (pi
, "can't open process file");
1500 /* open_proc_file may modify pid. */
1504 /* Add new process to process info list */
1506 pi
->next
= procinfo_list
;
1509 add_fd (pi
); /* Add to list for poll/select */
1511 pi
->num_syscall_handlers
= 0;
1512 pi
->syscall_handlers
= NULL
;
1513 memset ((char *) &pi
->prrun
, 0, sizeof (pi
->prrun
));
1514 prfillset (&pi
->prrun
.pr_trace
);
1515 procfs_notice_signals (pid
);
1516 prfillset (&pi
->prrun
.pr_fault
);
1517 prdelset (&pi
->prrun
.pr_fault
, FLTPAGE
);
1519 #ifdef PROCFS_DONT_TRACE_FAULTS
1520 premptyset (&pi
->prrun
.pr_fault
);
1523 if (ioctl (pi
->fd
, PIOCSTATUS
, &pi
->prstatus
) < 0)
1524 proc_init_failed (pi
, "PIOCSTATUS failed");
1526 /* A bug in Solaris (2.5 at least) causes PIOCWSTOP to hang on LWPs that are
1527 already stopped, even if they all have PR_ASYNC set. */
1529 if (!(pi
->prstatus
.pr_flags
& PR_STOPPED
))
1530 if (ioctl (pi
->fd
, PIOCWSTOP
, &pi
->prstatus
) < 0)
1531 proc_init_failed (pi
, "PIOCWSTOP failed");
1533 if (ioctl (pi
->fd
, PIOCSFAULT
, &pi
->prrun
.pr_fault
) < 0)
1534 proc_init_failed (pi
, "PIOCSFAULT failed");
1543 procfs_exit_handler - handle entry into the _exit syscall
1547 int procfs_exit_handler (pi, syscall_num, why, rtnvalp, statvalp)
1551 This routine is called when an inferior process enters the _exit()
1552 system call. It continues the process, and then collects the exit
1553 status and pid which are returned in *statvalp and *rtnvalp. After
1554 that it returns non-zero to indicate that procfs_wait should wake up.
1557 There is probably a better way to do this.
1562 procfs_exit_handler (pi
, syscall_num
, why
, rtnvalp
, statvalp
)
1563 struct procinfo
*pi
;
1569 pi
->prrun
.pr_flags
= PRCFAULT
;
1571 if (ioctl (pi
->fd
, PIOCRUN
, &pi
->prrun
) != 0)
1572 perror_with_name (pi
->pathname
);
1574 *rtnvalp
= wait (statvalp
);
1585 procfs_exec_handler - handle exit from the exec family of syscalls
1589 int procfs_exec_handler (pi, syscall_num, why, rtnvalp, statvalp)
1593 This routine is called when an inferior process is about to finish any
1594 of the exec() family of system calls. It pretends that we got a
1595 SIGTRAP (for compatibility with ptrace behavior), and returns non-zero
1596 to tell procfs_wait to wake up.
1599 This need for compatibility with ptrace is questionable. In the
1600 future, it shouldn't be necessary.
1605 procfs_exec_handler (pi
, syscall_num
, why
, rtnvalp
, statvalp
)
1606 struct procinfo
*pi
;
1612 *statvalp
= (SIGTRAP
<< 8) | 0177;
1617 #ifdef SYS_sproc /* IRIX lwp creation system call */
1623 procfs_sproc_handler - handle exit from the sproc syscall
1627 int procfs_sproc_handler (pi, syscall_num, why, rtnvalp, statvalp)
1631 This routine is called when an inferior process is about to finish an
1632 sproc() system call. This is the system call that IRIX uses to create
1633 a lightweight process. When the target process gets this event, we can
1634 look at rval1 to find the new child processes ID, and create a new
1635 procinfo struct from that.
1637 After that, it pretends that we got a SIGTRAP, and returns non-zero
1638 to tell procfs_wait to wake up. Subsequently, wait_for_inferior gets
1639 woken up, sees the new process and continues it.
1642 We actually never see the child exiting from sproc because we will
1643 shortly stop the child with PIOCSTOP, which is then registered as the
1648 procfs_sproc_handler (pi
, syscall_num
, why
, rtnvalp
, statvalp
)
1649 struct procinfo
*pi
;
1655 /* We've just detected the completion of an sproc system call. Now we need to
1656 setup a procinfo struct for this thread, and notify the thread system of the
1659 /* If sproc failed, then nothing interesting happened. Continue the process
1660 and go back to sleep. */
1662 if (pi
->prstatus
.pr_errno
!= 0)
1664 pi
->prrun
.pr_flags
&= PRSTEP
;
1665 pi
->prrun
.pr_flags
|= PRCFAULT
;
1667 if (ioctl (pi
->fd
, PIOCRUN
, &pi
->prrun
) != 0)
1668 perror_with_name (pi
->pathname
);
1673 /* At this point, the new thread is stopped at it's first instruction, and
1674 the parent is stopped at the exit from sproc. */
1676 /* Notify the caller of the arrival of a new thread. */
1677 create_procinfo (pi
->prstatus
.pr_rval1
);
1679 *rtnvalp
= pi
->prstatus
.pr_rval1
;
1680 *statvalp
= (SIGTRAP
<< 8) | 0177;
1689 procfs_fork_handler - handle exit from the fork syscall
1693 int procfs_fork_handler (pi, syscall_num, why, rtnvalp, statvalp)
1697 This routine is called when an inferior process is about to finish a
1698 fork() system call. We will open up the new process, and then close
1699 it, which releases it from the clutches of the debugger.
1701 After that, we continue the target process as though nothing had
1705 This is necessary for IRIX because we have to set PR_FORK in order
1706 to catch the creation of lwps (via sproc()). When an actual fork
1707 occurs, it becomes necessary to reset the forks debugger flags and
1708 continue it because we can't hack multiple processes yet.
1712 procfs_fork_handler (pi
, syscall_num
, why
, rtnvalp
, statvalp
)
1713 struct procinfo
*pi
;
1719 struct procinfo
*pitemp
;
1721 /* At this point, we've detected the completion of a fork (or vfork) call in
1722 our child. The grandchild is also stopped because we set inherit-on-fork
1723 earlier. (Note that nobody has the grandchilds' /proc file open at this
1724 point.) We will release the grandchild from the debugger by opening it's
1725 /proc file and then closing it. Since run-on-last-close is set, the
1726 grandchild continues on its' merry way. */
1729 pitemp
= create_procinfo (pi
->prstatus
.pr_rval1
);
1731 close_proc_file (pitemp
);
1733 if (ioctl (pi
->fd
, PIOCRUN
, &pi
->prrun
) != 0)
1734 perror_with_name (pi
->pathname
);
1738 #endif /* SYS_sproc */
1744 procfs_init_inferior - initialize target vector and access to a
1749 int procfs_init_inferior (int pid)
1753 When gdb starts an inferior, this function is called in the parent
1754 process immediately after the fork. It waits for the child to stop
1755 on the return from the exec system call (the child itself takes care
1756 of ensuring that this is set up), then sets up the set of signals
1757 and faults that are to be traced. Returns the pid, which may have had
1758 the thread-id added to it.
1762 If proc_init_failed ever gets called, control returns to the command
1763 processing loop via the standard error handling code.
1768 procfs_init_inferior (pid
)
1771 struct procinfo
*pip
;
1773 push_target (&procfs_ops
);
1775 pip
= create_procinfo (pid
);
1777 procfs_set_syscall_trap (pip
, SYS_exit
, PROCFS_SYSCALL_ENTRY
,
1778 procfs_exit_handler
);
1780 #ifndef PRFS_STOPEXEC
1782 procfs_set_syscall_trap (pip
, SYS_exec
, PROCFS_SYSCALL_EXIT
,
1783 procfs_exec_handler
);
1786 procfs_set_syscall_trap (pip
, SYS_execv
, PROCFS_SYSCALL_EXIT
,
1787 procfs_exec_handler
);
1790 procfs_set_syscall_trap (pip
, SYS_execve
, PROCFS_SYSCALL_EXIT
,
1791 procfs_exec_handler
);
1793 #endif /* PRFS_STOPEXEC */
1795 /* Setup traps on exit from sproc() */
1798 procfs_set_syscall_trap (pip
, SYS_sproc
, PROCFS_SYSCALL_EXIT
,
1799 procfs_sproc_handler
);
1800 procfs_set_syscall_trap (pip
, SYS_fork
, PROCFS_SYSCALL_EXIT
,
1801 procfs_fork_handler
);
1803 procfs_set_syscall_trap (pip
, SYS_vfork
, PROCFS_SYSCALL_EXIT
,
1804 procfs_fork_handler
);
1806 /* Turn on inherit-on-fork flag so that all children of the target process
1807 start with tracing flags set. This allows us to trap lwp creation. Note
1808 that we also have to trap on fork and vfork in order to disable all tracing
1809 in the targets child processes. */
1811 modify_inherit_on_fork_flag (pip
->fd
, 1);
1814 #ifdef SYS_lwp_create
1815 procfs_set_syscall_trap (pip
, SYS_lwp_create
, PROCFS_SYSCALL_EXIT
,
1816 procfs_lwp_creation_handler
);
1819 /* create_procinfo may change the pid, so we have to update inferior_pid
1820 here before calling other gdb routines that need the right pid. */
1825 add_thread (pip
-> pid
); /* Setup initial thread */
1827 #ifdef START_INFERIOR_TRAPS_EXPECTED
1828 startup_inferior (START_INFERIOR_TRAPS_EXPECTED
);
1830 /* One trap to exec the shell, one to exec the program being debugged. */
1831 startup_inferior (2);
1841 procfs_notice_signals
1845 static void procfs_notice_signals (int pid);
1849 When the user changes the state of gdb's signal handling via the
1850 "handle" command, this function gets called to see if any change
1851 in the /proc interface is required. It is also called internally
1852 by other /proc interface functions to initialize the state of
1853 the traced signal set.
1855 One thing it does is that signals for which the state is "nostop",
1856 "noprint", and "pass", have their trace bits reset in the pr_trace
1857 field, so that they are no longer traced. This allows them to be
1858 delivered directly to the inferior without the debugger ever being
1863 procfs_notice_signals (pid
)
1867 struct procinfo
*pi
;
1869 pi
= find_procinfo (pid
, 0);
1871 for (signo
= 0; signo
< NSIG
; signo
++)
1873 if (signal_stop_state (target_signal_from_host (signo
)) == 0 &&
1874 signal_print_state (target_signal_from_host (signo
)) == 0 &&
1875 signal_pass_state (target_signal_from_host (signo
)) == 1)
1877 prdelset (&pi
->prrun
.pr_trace
, signo
);
1881 praddset (&pi
->prrun
.pr_trace
, signo
);
1884 if (ioctl (pi
->fd
, PIOCSTRACE
, &pi
->prrun
.pr_trace
))
1886 print_sys_errmsg ("PIOCSTRACE failed", errno
);
1894 proc_set_exec_trap -- arrange for exec'd child to halt at startup
1898 void proc_set_exec_trap (void)
1902 This function is called in the child process when starting up
1903 an inferior, prior to doing the exec of the actual inferior.
1904 It sets the child process's exitset to make exit from the exec
1905 system call an event of interest to stop on, and then simply
1906 returns. The child does the exec, the system call returns, and
1907 the child stops at the first instruction, ready for the gdb
1908 parent process to take control of it.
1912 We need to use all local variables since the child may be sharing
1913 it's data space with the parent, if vfork was used rather than
1916 Also note that we want to turn off the inherit-on-fork flag in
1917 the child process so that any grand-children start with all
1918 tracing flags cleared.
1922 proc_set_exec_trap ()
1926 auto char procname
[32];
1929 sprintf (procname
, PROC_NAME_FMT
, getpid ());
1930 if ((fd
= open (procname
, O_RDWR
)) < 0)
1933 gdb_flush (gdb_stderr
);
1936 premptyset (&exitset
);
1937 premptyset (&entryset
);
1940 /* Under Alpha OSF/1 we have to use a PIOCSSPCACT ioctl to trace
1941 exits from exec system calls because of the user level loader. */
1945 if (ioctl (fd
, PIOCGSPCACT
, &prfs_flags
) < 0)
1948 gdb_flush (gdb_stderr
);
1951 prfs_flags
|= PRFS_STOPEXEC
;
1952 if (ioctl (fd
, PIOCSSPCACT
, &prfs_flags
) < 0)
1955 gdb_flush (gdb_stderr
);
1961 Not all systems with /proc have all the exec* syscalls with the same
1962 names. On the SGI, for example, there is no SYS_exec, but there
1963 *is* a SYS_execv. So, we try to account for that. */
1966 praddset (&exitset
, SYS_exec
);
1969 praddset (&exitset
, SYS_execve
);
1972 praddset (&exitset
, SYS_execv
);
1975 if (ioctl (fd
, PIOCSEXIT
, &exitset
) < 0)
1978 gdb_flush (gdb_stderr
);
1983 praddset (&entryset
, SYS_exit
);
1985 if (ioctl (fd
, PIOCSENTRY
, &entryset
) < 0)
1988 gdb_flush (gdb_stderr
);
1992 /* Turn off inherit-on-fork flag so that all grand-children of gdb
1993 start with tracing flags cleared. */
1995 modify_inherit_on_fork_flag (fd
, 0);
1997 /* Turn on run-on-last-close flag so that this process will not hang
1998 if GDB goes away for some reason. */
2000 modify_run_on_last_close_flag (fd
, 1);
2006 /* Solaris needs this to make procfs treat all threads seperately. Without
2007 this, all threads halt whenever something happens to any thread. Since
2008 GDB wants to control all this itself, it needs to set PR_ASYNC. */
2010 pr_flags
= PR_ASYNC
;
2012 ioctl (fd
, PIOCSET
, &pr_flags
);
2014 #endif /* PR_ASYNC */
2021 proc_iterate_over_mappings -- call function for every mapped space
2025 int proc_iterate_over_mappings (int (*func)())
2029 Given a pointer to a function, call that function for every
2030 mapped address space, passing it an open file descriptor for
2031 the file corresponding to that mapped address space (if any)
2032 and the base address of the mapped space. Quit when we hit
2033 the end of the mappings or the function returns nonzero.
2037 proc_iterate_over_mappings (func
)
2038 int (*func
) PARAMS ((int, CORE_ADDR
));
2043 struct prmap
*prmaps
;
2044 struct prmap
*prmap
;
2045 struct procinfo
*pi
;
2047 pi
= current_procinfo
;
2049 if (ioctl (pi
->fd
, PIOCNMAP
, &nmap
) == 0)
2051 prmaps
= (struct prmap
*) alloca ((nmap
+ 1) * sizeof (*prmaps
));
2052 if (ioctl (pi
->fd
, PIOCMAP
, prmaps
) == 0)
2054 for (prmap
= prmaps
; prmap
-> pr_size
&& funcstat
== 0; ++prmap
)
2056 fd
= proc_address_to_fd (pi
, (CORE_ADDR
) prmap
-> pr_vaddr
, 0);
2057 funcstat
= (*func
) (fd
, (CORE_ADDR
) prmap
-> pr_vaddr
);
2065 #if 0 /* Currently unused */
2070 proc_base_address -- find base address for segment containing address
2074 CORE_ADDR proc_base_address (CORE_ADDR addr)
2078 Given an address of a location in the inferior, find and return
2079 the base address of the mapped segment containing that address.
2081 This is used for example, by the shared library support code,
2082 where we have the pc value for some location in the shared library
2083 where we are stopped, and need to know the base address of the
2084 segment containing that address.
2088 proc_base_address (addr
)
2092 struct prmap
*prmaps
;
2093 struct prmap
*prmap
;
2094 CORE_ADDR baseaddr
= 0;
2095 struct procinfo
*pi
;
2097 pi
= current_procinfo
;
2099 if (ioctl (pi
->fd
, PIOCNMAP
, &nmap
) == 0)
2101 prmaps
= (struct prmap
*) alloca ((nmap
+ 1) * sizeof (*prmaps
));
2102 if (ioctl (pi
->fd
, PIOCMAP
, prmaps
) == 0)
2104 for (prmap
= prmaps
; prmap
-> pr_size
; ++prmap
)
2106 if ((prmap
-> pr_vaddr
<= (caddr_t
) addr
) &&
2107 (prmap
-> pr_vaddr
+ prmap
-> pr_size
> (caddr_t
) addr
))
2109 baseaddr
= (CORE_ADDR
) prmap
-> pr_vaddr
;
2124 proc_address_to_fd -- return open fd for file mapped to address
2128 int proc_address_to_fd (struct procinfo *pi, CORE_ADDR addr, complain)
2132 Given an address in the current inferior's address space, use the
2133 /proc interface to find an open file descriptor for the file that
2134 this address was mapped in from. Return -1 if there is no current
2135 inferior. Print a warning message if there is an inferior but
2136 the address corresponds to no file (IE a bogus address).
2141 proc_address_to_fd (pi
, addr
, complain
)
2142 struct procinfo
*pi
;
2148 if ((fd
= ioctl (pi
->fd
, PIOCOPENM
, (caddr_t
*) &addr
)) < 0)
2152 print_sys_errmsg (pi
->pathname
, errno
);
2153 warning ("can't find mapped file for address 0x%x", addr
);
2160 /* Attach to process PID, then initialize for debugging it
2161 and wait for the trace-trap that results from attaching. */
2164 procfs_attach (args
, from_tty
)
2172 error_no_arg ("process-id to attach");
2176 if (pid
== getpid()) /* Trying to masturbate? */
2177 error ("I refuse to debug myself!");
2181 exec_file
= (char *) get_exec_file (0);
2184 printf_unfiltered ("Attaching to program `%s', %s\n", exec_file
, target_pid_to_str (pid
));
2186 printf_unfiltered ("Attaching to %s\n", target_pid_to_str (pid
));
2188 gdb_flush (gdb_stdout
);
2191 inferior_pid
= pid
= do_attach (pid
);
2192 push_target (&procfs_ops
);
2196 /* Take a program previously attached to and detaches it.
2197 The program resumes execution and will no longer stop
2198 on signals, etc. We'd better not have left any breakpoints
2199 in the program or it'll die when it hits one. For this
2200 to work, it may be necessary for the process to have been
2201 previously attached. It *might* work if the program was
2202 started via the normal ptrace (PTRACE_TRACEME). */
2205 procfs_detach (args
, from_tty
)
2213 char *exec_file
= get_exec_file (0);
2216 printf_unfiltered ("Detaching from program: %s %s\n",
2217 exec_file
, target_pid_to_str (inferior_pid
));
2218 gdb_flush (gdb_stdout
);
2221 siggnal
= atoi (args
);
2223 do_detach (siggnal
);
2225 unpush_target (&procfs_ops
); /* Pop out of handling an inferior */
2228 /* Get ready to modify the registers array. On machines which store
2229 individual registers, this doesn't need to do anything. On machines
2230 which store all the registers in one fell swoop, this makes sure
2231 that registers contains all the registers from the program being
2235 procfs_prepare_to_store ()
2237 #ifdef CHILD_PREPARE_TO_STORE
2238 CHILD_PREPARE_TO_STORE ();
2242 /* Print status information about what we're accessing. */
2245 procfs_files_info (ignore
)
2246 struct target_ops
*ignore
;
2248 printf_unfiltered ("\tUsing the running image of %s %s via /proc.\n",
2249 attach_flag
? "attached": "child", target_pid_to_str (inferior_pid
));
2254 procfs_open (arg
, from_tty
)
2258 error ("Use the \"run\" command to start a Unix child process.");
2265 do_attach -- attach to an already existing process
2269 int do_attach (int pid)
2273 Attach to an already existing process with the specified process
2274 id. If the process is not already stopped, query whether to
2279 The option of stopping at attach time is specific to the /proc
2280 versions of gdb. Versions using ptrace force the attachee
2281 to stop. (I have changed this version to do so, too. All you
2282 have to do is "continue" to make it go on. -- gnu@cygnus.com)
2291 struct procinfo
*pi
;
2293 pi
= (struct procinfo
*) xmalloc (sizeof (struct procinfo
));
2295 if (!open_proc_file (pid
, pi
, O_RDWR
))
2298 perror_with_name (pi
->pathname
);
2304 /* Add new process to process info list */
2306 pi
->next
= procinfo_list
;
2309 add_fd (pi
); /* Add to list for poll/select */
2311 /* Get current status of process and if it is not already stopped,
2312 then stop it. Remember whether or not it was stopped when we first
2315 if (ioctl (pi
->fd
, PIOCSTATUS
, &pi
->prstatus
) < 0)
2317 print_sys_errmsg (pi
->pathname
, errno
);
2318 close_proc_file (pi
);
2319 error ("PIOCSTATUS failed");
2321 if (pi
->prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
))
2323 pi
->was_stopped
= 1;
2327 pi
->was_stopped
= 0;
2328 if (1 || query ("Process is currently running, stop it? "))
2330 /* Make it run again when we close it. */
2332 modify_run_on_last_close_flag (pi
->fd
, 1);
2334 if (ioctl (pi
->fd
, PIOCSTOP
, &pi
->prstatus
) < 0)
2336 print_sys_errmsg (pi
->pathname
, errno
);
2337 close_proc_file (pi
);
2338 error ("PIOCSTOP failed");
2340 pi
->nopass_next_sigstop
= 1;
2344 printf_unfiltered ("Ok, gdb will wait for %s to stop.\n", target_pid_to_str (pid
));
2348 /* Remember some things about the inferior that we will, or might, change
2349 so that we can restore them when we detach. */
2351 ioctl (pi
->fd
, PIOCGTRACE
, &pi
->saved_trace
);
2352 ioctl (pi
->fd
, PIOCGHOLD
, &pi
->saved_sighold
);
2353 ioctl (pi
->fd
, PIOCGFAULT
, &pi
->saved_fltset
);
2354 ioctl (pi
->fd
, PIOCGENTRY
, &pi
->saved_entryset
);
2355 ioctl (pi
->fd
, PIOCGEXIT
, &pi
->saved_exitset
);
2357 /* Set up trace and fault sets, as gdb expects them. */
2359 memset (&pi
->prrun
, 0, sizeof (pi
->prrun
));
2360 prfillset (&pi
->prrun
.pr_trace
);
2361 procfs_notice_signals (pid
);
2362 prfillset (&pi
->prrun
.pr_fault
);
2363 prdelset (&pi
->prrun
.pr_fault
, FLTPAGE
);
2365 #ifdef PROCFS_DONT_TRACE_FAULTS
2366 premptyset (&pi
->prrun
.pr_fault
);
2369 if (ioctl (pi
->fd
, PIOCSFAULT
, &pi
->prrun
.pr_fault
))
2371 print_sys_errmsg ("PIOCSFAULT failed", errno
);
2373 if (ioctl (pi
->fd
, PIOCSTRACE
, &pi
->prrun
.pr_trace
))
2375 print_sys_errmsg ("PIOCSTRACE failed", errno
);
2385 do_detach -- detach from an attached-to process
2389 void do_detach (int signal)
2393 Detach from the current attachee.
2395 If signal is non-zero, the attachee is started running again and sent
2396 the specified signal.
2398 If signal is zero and the attachee was not already stopped when we
2399 attached to it, then we make it runnable again when we detach.
2401 Otherwise, we query whether or not to make the attachee runnable
2402 again, since we may simply want to leave it in the state it was in
2405 We report any problems, but do not consider them errors, since we
2406 MUST detach even if some things don't seem to go right. This may not
2407 be the ideal situation. (FIXME).
2415 struct procinfo
*pi
;
2417 pi
= current_procinfo
;
2421 set_proc_siginfo (pi
, signal
);
2423 if (ioctl (pi
->fd
, PIOCSEXIT
, &pi
->saved_exitset
) < 0)
2425 print_sys_errmsg (pi
->pathname
, errno
);
2426 printf_unfiltered ("PIOCSEXIT failed.\n");
2428 if (ioctl (pi
->fd
, PIOCSENTRY
, &pi
->saved_entryset
) < 0)
2430 print_sys_errmsg (pi
->pathname
, errno
);
2431 printf_unfiltered ("PIOCSENTRY failed.\n");
2433 if (ioctl (pi
->fd
, PIOCSTRACE
, &pi
->saved_trace
) < 0)
2435 print_sys_errmsg (pi
->pathname
, errno
);
2436 printf_unfiltered ("PIOCSTRACE failed.\n");
2438 if (ioctl (pi
->fd
, PIOCSHOLD
, &pi
->saved_sighold
) < 0)
2440 print_sys_errmsg (pi
->pathname
, errno
);
2441 printf_unfiltered ("PIOSCHOLD failed.\n");
2443 if (ioctl (pi
->fd
, PIOCSFAULT
, &pi
->saved_fltset
) < 0)
2445 print_sys_errmsg (pi
->pathname
, errno
);
2446 printf_unfiltered ("PIOCSFAULT failed.\n");
2448 if (ioctl (pi
->fd
, PIOCSTATUS
, &pi
->prstatus
) < 0)
2450 print_sys_errmsg (pi
->pathname
, errno
);
2451 printf_unfiltered ("PIOCSTATUS failed.\n");
2455 if (signal
|| (pi
->prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
)))
2457 if (signal
|| !pi
->was_stopped
||
2458 query ("Was stopped when attached, make it runnable again? "))
2460 /* Clear any pending signal if we want to detach without
2463 set_proc_siginfo (pi
, signal
);
2465 /* Clear any fault that might have stopped it. */
2466 if (ioctl (pi
->fd
, PIOCCFAULT
, 0))
2468 print_sys_errmsg (pi
->pathname
, errno
);
2469 printf_unfiltered ("PIOCCFAULT failed.\n");
2472 /* Make it run again when we close it. */
2474 modify_run_on_last_close_flag (pi
->fd
, 1);
2478 close_proc_file (pi
);
2482 /* emulate wait() as much as possible.
2483 Wait for child to do something. Return pid of child, or -1 in case
2484 of error; store status in *OURSTATUS.
2486 Not sure why we can't
2487 just use wait(), but it seems to have problems when applied to a
2488 process being controlled with the /proc interface.
2490 We have a race problem here with no obvious solution. We need to let
2491 the inferior run until it stops on an event of interest, which means
2492 that we need to use the PIOCWSTOP ioctl. However, we cannot use this
2493 ioctl if the process is already stopped on something that is not an
2494 event of interest, or the call will hang indefinitely. Thus we first
2495 use PIOCSTATUS to see if the process is not stopped. If not, then we
2496 use PIOCWSTOP. But during the window between the two, if the process
2497 stops for any reason that is not an event of interest (such as a job
2498 control signal) then gdb will hang. One possible workaround is to set
2499 an alarm to wake up every minute of so and check to see if the process
2500 is still running, and if so, then reissue the PIOCWSTOP. But this is
2501 a real kludge, so has not been implemented. FIXME: investigate
2504 FIXME: Investigate why wait() seems to have problems with programs
2505 being control by /proc routines. */
2508 procfs_wait (pid
, ourstatus
)
2510 struct target_waitstatus
*ourstatus
;
2517 struct procinfo
*pi
;
2519 if (pid
!= -1) /* Non-specific process? */
2522 for (pi
= procinfo_list
; pi
; pi
= pi
->next
)
2537 for (pi
= procinfo_list
; pi
; pi
= pi
->next
)
2538 if (pi
->pid
== pid
&& pi
->had_event
)
2541 if (!pi
&& !checkerr
)
2544 if (!checkerr
&& !(pi
->prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
)))
2546 if (ioctl (pi
->fd
, PIOCWSTOP
, &pi
->prstatus
) < 0)
2553 if (errno
== ENOENT
)
2555 rtnval
= wait (&statval
);
2556 if (rtnval
!= inferior_pid
)
2558 print_sys_errmsg (pi
->pathname
, errno
);
2559 error ("PIOCWSTOP, wait failed, returned %d", rtnval
);
2565 print_sys_errmsg (pi
->pathname
, errno
);
2566 error ("PIOCSTATUS or PIOCWSTOP failed.");
2570 else if (pi
->prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
))
2573 why
= pi
->prstatus
.pr_why
;
2574 what
= pi
->prstatus
.pr_what
;
2579 statval
= (what
<< 8) | 0177;
2585 int found_handler
= 0;
2587 for (i
= 0; i
< pi
->num_syscall_handlers
; i
++)
2588 if (pi
->syscall_handlers
[i
].syscall_num
== what
)
2591 if (!pi
->syscall_handlers
[i
].func (pi
, what
, why
,
2599 if (why
== PR_SYSENTRY
)
2600 error ("PR_SYSENTRY, unhandled system call %d", what
);
2602 error ("PR_SYSEXIT, unhandled system call %d", what
);
2606 statval
= (SIGSTOP
<< 8) | 0177;
2609 statval
= (what
<< 8) | 0177;
2616 statval
= (SIGTRAP
<< 8) | 0177;
2621 statval
= (SIGTRAP
<< 8) | 0177;
2624 #ifndef FAULTED_USE_SIGINFO
2625 /* Irix, contrary to the documentation, fills in 0 for si_signo.
2626 Solaris fills in si_signo. I'm not sure about others. */
2629 statval
= (SIGILL
<< 8) | 0177;
2633 statval
= (SIGTRAP
<< 8) | 0177;
2638 statval
= (SIGSEGV
<< 8) | 0177;
2643 statval
= (SIGFPE
<< 8) | 0177;
2645 case FLTPAGE
: /* Recoverable page fault */
2646 #endif /* not FAULTED_USE_SIGINFO */
2648 /* Use the signal which the kernel assigns. This is better than
2649 trying to second-guess it from the fault. In fact, I suspect
2650 that FLTACCESS can be either SIGSEGV or SIGBUS. */
2651 statval
= ((pi
->prstatus
.pr_info
.si_signo
) << 8) | 0177;
2656 error ("PIOCWSTOP, unknown why %d, what %d", why
, what
);
2658 /* Stop all the other threads when any of them stops. */
2661 struct procinfo
*procinfo
;
2663 for (procinfo
= procinfo_list
; procinfo
; procinfo
= procinfo
->next
)
2665 if (!procinfo
->had_event
)
2667 /* A bug in Solaris (2.5) causes us to hang when trying to
2668 stop a stopped process. So, we have to check first in
2669 order to avoid the hang. */
2670 if (ioctl (procinfo
->fd
, PIOCSTATUS
, &procinfo
->prstatus
) < 0)
2672 print_sys_errmsg (procinfo
->pathname
, errno
);
2673 error ("PIOCSTATUS failed");
2675 if (!(procinfo
->prstatus
.pr_flags
& PR_STOPPED
))
2676 if (ioctl (procinfo
->fd
, PIOCSTOP
, &procinfo
->prstatus
) < 0)
2678 print_sys_errmsg (procinfo
->pathname
, errno
);
2679 error ("PIOCSTOP failed");
2687 error ("PIOCWSTOP, stopped for unknown/unhandled reason, flags %#x",
2688 pi
->prstatus
.pr_flags
);
2691 store_waitstatus (ourstatus
, statval
);
2693 if (rtnval
== -1) /* No more children to wait for */
2695 fprintf_unfiltered (gdb_stderr
, "Child process unexpectedly missing.\n");
2696 /* Claim it exited with unknown signal. */
2697 ourstatus
->kind
= TARGET_WAITKIND_SIGNALLED
;
2698 ourstatus
->value
.sig
= TARGET_SIGNAL_UNKNOWN
;
2702 pi
->had_event
= 0; /* Indicate that we've seen this one */
2710 set_proc_siginfo - set a process's current signal info
2714 void set_proc_siginfo (struct procinfo *pip, int signo);
2718 Given a pointer to a process info struct in PIP and a signal number
2719 in SIGNO, set the process's current signal and its associated signal
2720 information. The signal will be delivered to the process immediately
2721 after execution is resumed, even if it is being held. In addition,
2722 this particular delivery will not cause another PR_SIGNALLED stop
2723 even if the signal is being traced.
2725 If we are not delivering the same signal that the prstatus siginfo
2726 struct contains information about, then synthesize a siginfo struct
2727 to match the signal we are doing to deliver, make it of the type
2728 "generated by a user process", and send this synthesized copy. When
2729 used to set the inferior's signal state, this will be required if we
2730 are not currently stopped because of a traced signal, or if we decide
2731 to continue with a different signal.
2733 Note that when continuing the inferior from a stop due to receipt
2734 of a traced signal, we either have set PRCSIG to clear the existing
2735 signal, or we have to call this function to do a PIOCSSIG with either
2736 the existing siginfo struct from pr_info, or one we have synthesized
2737 appropriately for the signal we want to deliver. Otherwise if the
2738 signal is still being traced, the inferior will immediately stop
2741 See siginfo(5) for more details.
2745 set_proc_siginfo (pip
, signo
)
2746 struct procinfo
*pip
;
2749 struct siginfo newsiginfo
;
2750 struct siginfo
*sip
;
2752 #ifdef PROCFS_DONT_PIOCSSIG_CURSIG
2753 /* With Alpha OSF/1 procfs, the kernel gets really confused if it
2754 receives a PIOCSSIG with a signal identical to the current signal,
2755 it messes up the current signal. Work around the kernel bug. */
2756 if (signo
== pip
-> prstatus
.pr_cursig
)
2760 if (signo
== pip
-> prstatus
.pr_info
.si_signo
)
2762 sip
= &pip
-> prstatus
.pr_info
;
2766 memset ((char *) &newsiginfo
, 0, sizeof (newsiginfo
));
2768 sip
-> si_signo
= signo
;
2770 sip
-> si_errno
= 0;
2771 sip
-> si_pid
= getpid ();
2772 sip
-> si_uid
= getuid ();
2774 if (ioctl (pip
-> fd
, PIOCSSIG
, sip
) < 0)
2776 print_sys_errmsg (pip
-> pathname
, errno
);
2777 warning ("PIOCSSIG failed");
2781 /* Resume execution of process PID. If STEP is nozero, then
2782 just single step it. If SIGNAL is nonzero, restart it with that
2783 signal activated. */
2786 procfs_resume (pid
, step
, signo
)
2789 enum target_signal signo
;
2792 struct procinfo
*pi
, *procinfo
;
2794 pi
= find_procinfo (pid
== -1 ? inferior_pid
: pid
, 0);
2797 pi
->prrun
.pr_flags
= PRSTRACE
| PRSFAULT
| PRCFAULT
;
2800 /* It should not be necessary. If the user explicitly changes the value,
2801 value_assign calls write_register_bytes, which writes it. */
2802 /* It may not be absolutely necessary to specify the PC value for
2803 restarting, but to be safe we use the value that gdb considers
2804 to be current. One case where this might be necessary is if the
2805 user explicitly changes the PC value that gdb considers to be
2806 current. FIXME: Investigate if this is necessary or not. */
2808 #ifdef PRSVADDR_BROKEN
2809 /* Can't do this under Solaris running on a Sparc, as there seems to be no
2810 place to put nPC. In fact, if you use this, nPC seems to be set to some
2811 random garbage. We have to rely on the fact that PC and nPC have been
2812 written previously via PIOCSREG during a register flush. */
2814 pi
->prrun
.pr_vaddr
= (caddr_t
) *(int *) ®isters
[REGISTER_BYTE (PC_REGNUM
)];
2815 pi
->prrun
.pr_flags
!= PRSVADDR
;
2819 if (signo
== TARGET_SIGNAL_STOP
&& pi
->nopass_next_sigstop
)
2820 /* When attaching to a child process, if we forced it to stop with
2821 a PIOCSTOP, then we will have set the nopass_next_sigstop flag.
2822 Upon resuming the first time after such a stop, we explicitly
2823 inhibit sending it another SIGSTOP, which would be the normal
2824 result of default signal handling. One potential drawback to
2825 this is that we will also ignore any attempt to by the user
2826 to explicitly continue after the attach with a SIGSTOP. Ultimately
2827 this problem should be dealt with by making the routines that
2828 deal with the inferior a little smarter, and possibly even allow
2829 an inferior to continue running at the same time as gdb. (FIXME?) */
2831 else if (signo
== TARGET_SIGNAL_TSTP
2832 && pi
->prstatus
.pr_cursig
== SIGTSTP
2833 && pi
->prstatus
.pr_action
.sa_handler
== SIG_DFL
)
2835 /* We are about to pass the inferior a SIGTSTP whose action is
2836 SIG_DFL. The SIG_DFL action for a SIGTSTP is to stop
2837 (notifying the parent via wait()), and then keep going from the
2838 same place when the parent is ready for you to keep going. So
2839 under the debugger, it should do nothing (as if the program had
2840 been stopped and then later resumed. Under ptrace, this
2841 happens for us, but under /proc, the system obligingly stops
2842 the process, and wait_for_inferior would have no way of
2843 distinguishing that type of stop (which indicates that we
2844 should just start it again), with a stop due to the pr_trace
2845 field of the prrun_t struct.
2847 Note that if the SIGTSTP is being caught, we *do* need to pass it,
2848 because the handler needs to get executed. */
2851 signal_to_pass
= target_signal_to_host (signo
);
2855 set_proc_siginfo (pi
, signal_to_pass
);
2859 pi
->prrun
.pr_flags
|= PRCSIG
;
2861 pi
->nopass_next_sigstop
= 0;
2864 pi
->prrun
.pr_flags
|= PRSTEP
;
2867 /* Don't try to start a process unless it's stopped on an
2868 `event of interest'. Doing so will cause errors. */
2870 if ((pi
->prstatus
.pr_flags
& PR_ISTOP
)
2871 && ioctl (pi
->fd
, PIOCRUN
, &pi
->prrun
) != 0)
2873 perror_with_name (pi
->pathname
);
2879 /* Continue all the other threads that haven't had an event of
2883 for (procinfo
= procinfo_list
; procinfo
; procinfo
= procinfo
->next
)
2885 if (pi
!= procinfo
&& !procinfo
->had_event
)
2887 procinfo
->prrun
.pr_flags
&= PRSTEP
;
2888 procinfo
->prrun
.pr_flags
|= PRCFAULT
| PRCSIG
;
2889 ioctl (procinfo
->fd
, PIOCSTATUS
, &procinfo
->prstatus
);
2891 /* Don't try to start a process unless it's stopped on an
2892 `event of interest'. Doing so will cause errors. */
2894 if ((procinfo
->prstatus
.pr_flags
& PR_ISTOP
)
2895 && ioctl (procinfo
->fd
, PIOCRUN
, &procinfo
->prrun
) < 0)
2897 if (ioctl (procinfo
->fd
, PIOCSTATUS
, &procinfo
->prstatus
) < 0)
2899 fprintf_unfiltered(gdb_stderr
, "PIOCSTATUS failed, errno=%d\n", errno
);
2901 print_sys_errmsg (procinfo
->pathname
, errno
);
2902 error ("PIOCRUN failed");
2904 ioctl (procinfo
->fd
, PIOCSTATUS
, &procinfo
->prstatus
);
2913 procfs_fetch_registers -- fetch current registers from inferior
2917 void procfs_fetch_registers (int regno)
2921 Read the current values of the inferior's registers, both the
2922 general register set and floating point registers (if supported)
2923 and update gdb's idea of their current values.
2928 procfs_fetch_registers (regno
)
2931 struct procinfo
*pi
;
2933 pi
= current_procinfo
;
2935 if (ioctl (pi
->fd
, PIOCGREG
, &pi
->gregset
) != -1)
2937 supply_gregset (&pi
->gregset
);
2939 #if defined (FP0_REGNUM)
2940 if (ioctl (pi
->fd
, PIOCGFPREG
, &pi
->fpregset
) != -1)
2942 supply_fpregset (&pi
->fpregset
);
2951 proc_init_failed - called whenever /proc access initialization
2956 static void proc_init_failed (struct procinfo *pi, char *why)
2960 This function is called whenever initialization of access to a /proc
2961 entry fails. It prints a suitable error message, does some cleanup,
2962 and then invokes the standard error processing routine which dumps
2963 us back into the command loop.
2967 proc_init_failed (pi
, why
)
2968 struct procinfo
*pi
;
2971 print_sys_errmsg (pi
->pathname
, errno
);
2972 kill (pi
->pid
, SIGKILL
);
2973 close_proc_file (pi
);
2982 close_proc_file - close any currently open /proc entry
2986 static void close_proc_file (struct procinfo *pip)
2990 Close any currently open /proc entry and mark the process information
2991 entry as invalid. In order to ensure that we don't try to reuse any
2992 stale information, the pid, fd, and pathnames are explicitly
2993 invalidated, which may be overkill.
2998 close_proc_file (pip
)
2999 struct procinfo
*pip
;
3001 struct procinfo
*procinfo
;
3003 remove_fd (pip
); /* Remove fd from poll/select list */
3007 free (pip
-> pathname
);
3009 /* Unlink pip from the procinfo chain. Note pip might not be on the list. */
3011 if (procinfo_list
== pip
)
3012 procinfo_list
= pip
->next
;
3014 for (procinfo
= procinfo_list
; procinfo
; procinfo
= procinfo
->next
)
3015 if (procinfo
->next
== pip
)
3016 procinfo
->next
= pip
->next
;
3025 open_proc_file - open a /proc entry for a given process id
3029 static int open_proc_file (int pid, struct procinfo *pip, int mode)
3033 Given a process id and a mode, close the existing open /proc
3034 entry (if any) and open one for the new process id, in the
3035 specified mode. Once it is open, then mark the local process
3036 information structure as valid, which guarantees that the pid,
3037 fd, and pathname fields match an open /proc entry. Returns
3038 zero if the open fails, nonzero otherwise.
3040 Note that the pathname is left intact, even when the open fails,
3041 so that callers can use it to construct meaningful error messages
3042 rather than just "file open failed".
3044 Note that for Solaris, the process-id also includes an LWP-id, so we
3045 actually attempt to open that. If we are handed a pid with a 0 LWP-id,
3046 then we will ask the kernel what it is and add it to the pid. Hence,
3047 the pid can be changed by us.
3051 open_proc_file (pid
, pip
, mode
)
3053 struct procinfo
*pip
;
3059 pip
-> had_event
= 0;
3060 pip
-> pathname
= xmalloc (32);
3069 sprintf (pip
-> pathname
, PROC_NAME_FMT
, tmp
);
3070 if ((tmpfd
= open (pip
-> pathname
, mode
)) < 0)
3076 tmp
= (pid
>> 16) & 0xffff; /* Extract thread id */
3079 { /* Don't know thread id yet */
3080 if (ioctl (tmpfd
, PIOCSTATUS
, &pip
-> prstatus
) < 0)
3082 print_sys_errmsg (pip
-> pathname
, errno
);
3084 error ("open_proc_file: PIOCSTATUS failed");
3087 tmp
= pip
-> prstatus
.pr_who
; /* Get thread id from prstatus_t */
3088 pip
-> pid
= (tmp
<< 16) | pid
; /* Update pip */
3091 if ((pip
-> fd
= ioctl (tmpfd
, PIOCOPENLWP
, &tmp
)) < 0)
3097 #ifdef PIOCSET /* New method */
3100 pr_flags
= PR_ASYNC
;
3101 ioctl (pip
-> fd
, PIOCSET
, &pr_flags
);
3105 close (tmpfd
); /* All done with main pid */
3106 #endif /* PIOCOPENLWP */
3112 mappingflags (flags
)
3115 static char asciiflags
[8];
3117 strcpy (asciiflags
, "-------");
3118 #if defined (MA_PHYS)
3119 if (flags
& MA_PHYS
) asciiflags
[0] = 'd';
3121 if (flags
& MA_STACK
) asciiflags
[1] = 's';
3122 if (flags
& MA_BREAK
) asciiflags
[2] = 'b';
3123 if (flags
& MA_SHARED
) asciiflags
[3] = 's';
3124 if (flags
& MA_READ
) asciiflags
[4] = 'r';
3125 if (flags
& MA_WRITE
) asciiflags
[5] = 'w';
3126 if (flags
& MA_EXEC
) asciiflags
[6] = 'x';
3127 return (asciiflags
);
3131 info_proc_flags (pip
, summary
)
3132 struct procinfo
*pip
;
3135 struct trans
*transp
;
3137 printf_filtered ("%-32s", "Process status flags:");
3140 printf_filtered ("\n\n");
3142 for (transp
= pr_flag_table
; transp
-> name
!= NULL
; transp
++)
3144 if (pip
-> prstatus
.pr_flags
& transp
-> value
)
3148 printf_filtered ("%s ", transp
-> name
);
3152 printf_filtered ("\t%-16s %s.\n", transp
-> name
, transp
-> desc
);
3156 printf_filtered ("\n");
3160 info_proc_stop (pip
, summary
)
3161 struct procinfo
*pip
;
3164 struct trans
*transp
;
3168 why
= pip
-> prstatus
.pr_why
;
3169 what
= pip
-> prstatus
.pr_what
;
3171 if (pip
-> prstatus
.pr_flags
& PR_STOPPED
)
3173 printf_filtered ("%-32s", "Reason for stopping:");
3176 printf_filtered ("\n\n");
3178 for (transp
= pr_why_table
; transp
-> name
!= NULL
; transp
++)
3180 if (why
== transp
-> value
)
3184 printf_filtered ("%s ", transp
-> name
);
3188 printf_filtered ("\t%-16s %s.\n",
3189 transp
-> name
, transp
-> desc
);
3195 /* Use the pr_why field to determine what the pr_what field means, and
3196 print more information. */
3201 /* pr_what is unused for this case */
3207 printf_filtered ("%s ", signalname (what
));
3211 printf_filtered ("\t%-16s %s.\n", signalname (what
),
3212 safe_strsignal (what
));
3218 printf_filtered ("%s ", syscallname (what
));
3222 printf_filtered ("\t%-16s %s.\n", syscallname (what
),
3223 "Entered this system call");
3229 printf_filtered ("%s ", syscallname (what
));
3233 printf_filtered ("\t%-16s %s.\n", syscallname (what
),
3234 "Returned from this system call");
3240 printf_filtered ("%s ",
3241 lookupname (faults_table
, what
, "fault"));
3245 printf_filtered ("\t%-16s %s.\n",
3246 lookupname (faults_table
, what
, "fault"),
3247 lookupdesc (faults_table
, what
));
3251 printf_filtered ("\n");
3256 info_proc_siginfo (pip
, summary
)
3257 struct procinfo
*pip
;
3260 struct siginfo
*sip
;
3262 if ((pip
-> prstatus
.pr_flags
& PR_STOPPED
) &&
3263 (pip
-> prstatus
.pr_why
== PR_SIGNALLED
||
3264 pip
-> prstatus
.pr_why
== PR_FAULTED
))
3266 printf_filtered ("%-32s", "Additional signal/fault info:");
3267 sip
= &pip
-> prstatus
.pr_info
;
3270 printf_filtered ("%s ", signalname (sip
-> si_signo
));
3271 if (sip
-> si_errno
> 0)
3273 printf_filtered ("%s ", errnoname (sip
-> si_errno
));
3275 if (sip
-> si_code
<= 0)
3277 printf_filtered ("sent by %s, uid %d ",
3278 target_pid_to_str (sip
-> si_pid
),
3283 printf_filtered ("%s ", sigcodename (sip
));
3284 if ((sip
-> si_signo
== SIGILL
) ||
3285 (sip
-> si_signo
== SIGFPE
) ||
3286 (sip
-> si_signo
== SIGSEGV
) ||
3287 (sip
-> si_signo
== SIGBUS
))
3289 printf_filtered ("addr=%#lx ",
3290 (unsigned long) sip
-> si_addr
);
3292 else if ((sip
-> si_signo
== SIGCHLD
))
3294 printf_filtered ("child %s, status %u ",
3295 target_pid_to_str (sip
-> si_pid
),
3298 else if ((sip
-> si_signo
== SIGPOLL
))
3300 printf_filtered ("band %u ", sip
-> si_band
);
3306 printf_filtered ("\n\n");
3307 printf_filtered ("\t%-16s %s.\n", signalname (sip
-> si_signo
),
3308 safe_strsignal (sip
-> si_signo
));
3309 if (sip
-> si_errno
> 0)
3311 printf_filtered ("\t%-16s %s.\n",
3312 errnoname (sip
-> si_errno
),
3313 safe_strerror (sip
-> si_errno
));
3315 if (sip
-> si_code
<= 0)
3317 printf_filtered ("\t%-16u %s\n", sip
-> si_pid
, /* XXX need target_pid_to_str() */
3318 "PID of process sending signal");
3319 printf_filtered ("\t%-16u %s\n", sip
-> si_uid
,
3320 "UID of process sending signal");
3324 printf_filtered ("\t%-16s %s.\n", sigcodename (sip
),
3326 if ((sip
-> si_signo
== SIGILL
) ||
3327 (sip
-> si_signo
== SIGFPE
))
3329 printf_filtered ("\t%#-16lx %s.\n",
3330 (unsigned long) sip
-> si_addr
,
3331 "Address of faulting instruction");
3333 else if ((sip
-> si_signo
== SIGSEGV
) ||
3334 (sip
-> si_signo
== SIGBUS
))
3336 printf_filtered ("\t%#-16lx %s.\n",
3337 (unsigned long) sip
-> si_addr
,
3338 "Address of faulting memory reference");
3340 else if ((sip
-> si_signo
== SIGCHLD
))
3342 printf_filtered ("\t%-16u %s.\n", sip
-> si_pid
, /* XXX need target_pid_to_str() */
3343 "Child process ID");
3344 printf_filtered ("\t%-16u %s.\n", sip
-> si_status
,
3345 "Child process exit value or signal");
3347 else if ((sip
-> si_signo
== SIGPOLL
))
3349 printf_filtered ("\t%-16u %s.\n", sip
-> si_band
,
3350 "Band event for POLL_{IN,OUT,MSG}");
3354 printf_filtered ("\n");
3359 info_proc_syscalls (pip
, summary
)
3360 struct procinfo
*pip
;
3368 #if 0 /* FIXME: Needs to use gdb-wide configured info about system calls. */
3369 if (pip
-> prstatus
.pr_flags
& PR_ASLEEP
)
3371 int syscallnum
= pip
-> prstatus
.pr_reg
[R_D0
];
3374 printf_filtered ("%-32s", "Sleeping in system call:");
3375 printf_filtered ("%s", syscallname (syscallnum
));
3379 printf_filtered ("Sleeping in system call '%s'.\n",
3380 syscallname (syscallnum
));
3385 if (ioctl (pip
-> fd
, PIOCGENTRY
, &pip
-> entryset
) < 0)
3387 print_sys_errmsg (pip
-> pathname
, errno
);
3388 error ("PIOCGENTRY failed");
3391 if (ioctl (pip
-> fd
, PIOCGEXIT
, &pip
-> exitset
) < 0)
3393 print_sys_errmsg (pip
-> pathname
, errno
);
3394 error ("PIOCGEXIT failed");
3397 printf_filtered ("System call tracing information:\n\n");
3399 printf_filtered ("\t%-12s %-8s %-8s\n",
3403 for (syscallnum
= 0; syscallnum
< MAX_SYSCALLS
; syscallnum
++)
3406 if (syscall_table
[syscallnum
] != NULL
)
3407 printf_filtered ("\t%-12s ", syscall_table
[syscallnum
]);
3409 printf_filtered ("\t%-12d ", syscallnum
);
3411 printf_filtered ("%-8s ",
3412 prismember (&pip
-> entryset
, syscallnum
)
3414 printf_filtered ("%-8s ",
3415 prismember (&pip
-> exitset
, syscallnum
)
3417 printf_filtered ("\n");
3419 printf_filtered ("\n");
3428 static char locbuf
[32];
3430 name
= strsigno (signo
);
3433 sprintf (locbuf
, "Signal %d", signo
);
3437 sprintf (locbuf
, "%s (%d)", name
, signo
);
3447 static char locbuf
[32];
3449 name
= strerrno (errnum
);
3452 sprintf (locbuf
, "Errno %d", errnum
);
3456 sprintf (locbuf
, "%s (%d)", name
, errnum
);
3462 info_proc_signals (pip
, summary
)
3463 struct procinfo
*pip
;
3470 if (ioctl (pip
-> fd
, PIOCGTRACE
, &pip
-> trace
) < 0)
3472 print_sys_errmsg (pip
-> pathname
, errno
);
3473 error ("PIOCGTRACE failed");
3476 printf_filtered ("Disposition of signals:\n\n");
3477 printf_filtered ("\t%-15s %-8s %-8s %-8s %s\n\n",
3478 "Signal", "Trace", "Hold", "Pending", "Description");
3479 for (signo
= 0; signo
< NSIG
; signo
++)
3482 printf_filtered ("\t%-15s ", signalname (signo
));
3483 printf_filtered ("%-8s ",
3484 prismember (&pip
-> trace
, signo
)
3486 printf_filtered ("%-8s ",
3487 prismember (&pip
-> prstatus
.pr_sighold
, signo
)
3490 #ifdef PROCFS_SIGPEND_OFFSET
3491 /* Alpha OSF/1 numbers the pending signals from 1. */
3492 printf_filtered ("%-8s ",
3493 (signo
? prismember (&pip
-> prstatus
.pr_sigpend
,
3498 printf_filtered ("%-8s ",
3499 prismember (&pip
-> prstatus
.pr_sigpend
, signo
)
3502 printf_filtered (" %s\n", safe_strsignal (signo
));
3504 printf_filtered ("\n");
3509 info_proc_faults (pip
, summary
)
3510 struct procinfo
*pip
;
3513 struct trans
*transp
;
3517 if (ioctl (pip
-> fd
, PIOCGFAULT
, &pip
-> fltset
) < 0)
3519 print_sys_errmsg (pip
-> pathname
, errno
);
3520 error ("PIOCGFAULT failed");
3523 printf_filtered ("Current traced hardware fault set:\n\n");
3524 printf_filtered ("\t%-12s %-8s\n", "Fault", "Trace");
3526 for (transp
= faults_table
; transp
-> name
!= NULL
; transp
++)
3529 printf_filtered ("\t%-12s ", transp
-> name
);
3530 printf_filtered ("%-8s", prismember (&pip
-> fltset
, transp
-> value
)
3532 printf_filtered ("\n");
3534 printf_filtered ("\n");
3539 info_proc_mappings (pip
, summary
)
3540 struct procinfo
*pip
;
3544 struct prmap
*prmaps
;
3545 struct prmap
*prmap
;
3549 printf_filtered ("Mapped address spaces:\n\n");
3550 #ifdef BFD_HOST_64_BIT
3551 printf_filtered (" %18s %18s %10s %10s %7s\n",
3553 printf_filtered ("\t%10s %10s %10s %10s %7s\n",
3560 if (ioctl (pip
-> fd
, PIOCNMAP
, &nmap
) == 0)
3562 prmaps
= (struct prmap
*) alloca ((nmap
+ 1) * sizeof (*prmaps
));
3563 if (ioctl (pip
-> fd
, PIOCMAP
, prmaps
) == 0)
3565 for (prmap
= prmaps
; prmap
-> pr_size
; ++prmap
)
3567 #ifdef BFD_HOST_64_BIT
3568 printf_filtered (" %#18lx %#18lx %#10x %#10x %7s\n",
3570 printf_filtered ("\t%#10lx %#10lx %#10x %#10x %7s\n",
3572 (unsigned long)prmap
-> pr_vaddr
,
3573 (unsigned long)prmap
-> pr_vaddr
3574 + prmap
-> pr_size
- 1,
3577 mappingflags (prmap
-> pr_mflags
));
3581 printf_filtered ("\n");
3589 info_proc -- implement the "info proc" command
3593 void info_proc (char *args, int from_tty)
3597 Implement gdb's "info proc" command by using the /proc interface
3598 to print status information about any currently running process.
3600 Examples of the use of "info proc" are:
3602 info proc (prints summary info for current inferior)
3603 info proc 123 (prints summary info for process with pid 123)
3604 info proc mappings (prints address mappings)
3605 info proc times (prints process/children times)
3606 info proc id (prints pid, ppid, gid, sid, etc)
3607 FIXME: i proc id not implemented.
3608 info proc status (prints general process state info)
3609 FIXME: i proc status not implemented.
3610 info proc signals (prints info about signal handling)
3611 info proc all (prints all info)
3616 info_proc (args
, from_tty
)
3620 int pid
= inferior_pid
;
3621 struct procinfo
*pip
;
3622 struct cleanup
*old_chain
;
3638 old_chain
= make_cleanup (null_cleanup
, 0);
3640 /* Default to using the current inferior if no pid specified. Note
3641 that inferior_pid may be 0, hence we set okerr. */
3643 pip
= find_procinfo (inferior_pid
, 1);
3647 if ((argv
= buildargv (args
)) == NULL
)
3651 make_cleanup (freeargv
, (char *) argv
);
3653 while (*argv
!= NULL
)
3655 argsize
= strlen (*argv
);
3656 if (argsize
>= 1 && strncmp (*argv
, "all", argsize
) == 0)
3661 else if (argsize
>= 2 && strncmp (*argv
, "faults", argsize
) == 0)
3666 else if (argsize
>= 2 && strncmp (*argv
, "flags", argsize
) == 0)
3671 else if (argsize
>= 1 && strncmp (*argv
, "id", argsize
) == 0)
3676 else if (argsize
>= 1 && strncmp (*argv
, "mappings", argsize
) == 0)
3681 else if (argsize
>= 2 && strncmp (*argv
, "signals", argsize
) == 0)
3686 else if (argsize
>= 2 && strncmp (*argv
, "status", argsize
) == 0)
3691 else if (argsize
>= 2 && strncmp (*argv
, "syscalls", argsize
) == 0)
3696 else if (argsize
>= 1 && strncmp (*argv
, "times", argsize
) == 0)
3701 else if ((pid
= atoi (*argv
)) > 0)
3703 pip
= (struct procinfo
*) xmalloc (sizeof (struct procinfo
));
3704 memset (pip
, 0, sizeof (*pip
));
3707 if (!open_proc_file (pid
, pip
, O_RDONLY
))
3709 perror_with_name (pip
-> pathname
);
3713 make_cleanup (close_proc_file
, pip
);
3715 else if (**argv
!= '\000')
3717 error ("Unrecognized or ambiguous keyword `%s'.", *argv
);
3723 /* If we don't have a valid open process at this point, then we have no
3724 inferior or didn't specify a specific pid. */
3729 No process. Start debugging a program or specify an explicit process ID.");
3731 if (ioctl (pip
-> fd
, PIOCSTATUS
, &(pip
-> prstatus
)) < 0)
3733 print_sys_errmsg (pip
-> pathname
, errno
);
3734 error ("PIOCSTATUS failed");
3738 nlwp
= pip
->prstatus
.pr_nlwp
;
3739 lwps
= alloca ((2 * nlwp
+ 2) * sizeof (id_t
));
3741 if (ioctl (pip
->fd
, PIOCLWPIDS
, lwps
))
3743 print_sys_errmsg (pip
-> pathname
, errno
);
3744 error ("PIOCSTATUS failed");
3746 #else /* PIOCLWPIDS */
3748 lwps
= alloca ((2 * nlwp
+ 2) * sizeof *lwps
);
3750 #endif /* PIOCLWPIDS */
3752 for (; nlwp
> 0; nlwp
--, lwps
++)
3754 pip
= find_procinfo ((*lwps
<< 16) | pid
, 1);
3758 pip
= (struct procinfo
*) xmalloc (sizeof (struct procinfo
));
3759 memset (pip
, 0, sizeof (*pip
));
3760 if (!open_proc_file ((*lwps
<< 16) | pid
, pip
, O_RDONLY
))
3763 make_cleanup (close_proc_file
, pip
);
3765 if (ioctl (pip
-> fd
, PIOCSTATUS
, &(pip
-> prstatus
)) < 0)
3767 print_sys_errmsg (pip
-> pathname
, errno
);
3768 error ("PIOCSTATUS failed");
3772 /* Print verbose information of the requested type(s), or just a summary
3773 of the information for all types. */
3775 printf_filtered ("\nInformation for %s.%d:\n\n", pip
-> pathname
, *lwps
);
3776 if (summary
|| all
|| flags
)
3778 info_proc_flags (pip
, summary
);
3782 info_proc_stop (pip
, summary
);
3784 if (summary
|| all
|| signals
|| faults
)
3786 info_proc_siginfo (pip
, summary
);
3788 if (summary
|| all
|| syscalls
)
3790 info_proc_syscalls (pip
, summary
);
3792 if (summary
|| all
|| mappings
)
3794 info_proc_mappings (pip
, summary
);
3796 if (summary
|| all
|| signals
)
3798 info_proc_signals (pip
, summary
);
3800 if (summary
|| all
|| faults
)
3802 info_proc_faults (pip
, summary
);
3804 printf_filtered ("\n");
3806 /* All done, deal with closing any temporary process info structure,
3807 freeing temporary memory , etc. */
3809 do_cleanups (old_chain
);
3817 modify_inherit_on_fork_flag - Change the inherit-on-fork flag
3821 void modify_inherit_on_fork_flag (fd, flag)
3825 Call this routine to modify the inherit-on-fork flag. This routine is
3826 just a nice wrapper to hide the #ifdefs needed by various systems to
3832 modify_inherit_on_fork_flag (fd
, flag
)
3839 #ifdef PIOCSET /* New method */
3842 retval
= ioctl (fd
, PIOCSET
, &pr_flags
);
3844 retval
= ioctl (fd
, PIOCRESET
, &pr_flags
);
3847 #ifdef PIOCSFORK /* Original method */
3849 retval
= ioctl (fd
, PIOCSFORK
, NULL
);
3851 retval
= ioctl (fd
, PIOCRFORK
, NULL
);
3853 Neither PR_FORK nor PIOCSFORK exist
!!!
3860 print_sys_errmsg ("modify_inherit_on_fork_flag", errno
);
3861 error ("PIOCSFORK or PR_FORK modification failed");
3868 modify_run_on_last_close_flag - Change the run-on-last-close flag
3872 void modify_run_on_last_close_flag (fd, flag)
3876 Call this routine to modify the run-on-last-close flag. This routine
3877 is just a nice wrapper to hide the #ifdefs needed by various systems to
3883 modify_run_on_last_close_flag (fd
, flag
)
3890 #ifdef PIOCSET /* New method */
3893 retval
= ioctl (fd
, PIOCSET
, &pr_flags
);
3895 retval
= ioctl (fd
, PIOCRESET
, &pr_flags
);
3898 #ifdef PIOCSRLC /* Original method */
3900 retval
= ioctl (fd
, PIOCSRLC
, NULL
);
3902 retval
= ioctl (fd
, PIOCRRLC
, NULL
);
3904 Neither PR_RLC nor PIOCSRLC exist
!!!
3911 print_sys_errmsg ("modify_run_on_last_close_flag", errno
);
3912 error ("PIOCSRLC or PR_RLC modification failed");
3919 procfs_clear_syscall_trap -- Deletes the trap for the specified system call.
3923 void procfs_clear_syscall_trap (struct procinfo *, int syscall_num, int errok)
3927 This function function disables traps for the specified system call.
3928 errok is non-zero if errors should be ignored.
3932 procfs_clear_syscall_trap (pi
, syscall_num
, errok
)
3933 struct procinfo
*pi
;
3940 goterr
= ioctl (pi
->fd
, PIOCGENTRY
, &sysset
) < 0;
3942 if (goterr
&& !errok
)
3944 print_sys_errmsg (pi
->pathname
, errno
);
3945 error ("PIOCGENTRY failed");
3950 prdelset (&sysset
, syscall_num
);
3952 if ((ioctl (pi
->fd
, PIOCSENTRY
, &sysset
) < 0) && !errok
)
3954 print_sys_errmsg (pi
->pathname
, errno
);
3955 error ("PIOCSENTRY failed");
3959 goterr
= ioctl (pi
->fd
, PIOCGEXIT
, &sysset
) < 0;
3961 if (goterr
&& !errok
)
3963 procfs_clear_syscall_trap (pi
, syscall_num
, 1);
3964 print_sys_errmsg (pi
->pathname
, errno
);
3965 error ("PIOCGEXIT failed");
3970 praddset (&sysset
, syscall_num
);
3972 if ((ioctl (pi
->fd
, PIOCSEXIT
, &sysset
) < 0) && !errok
)
3974 procfs_clear_syscall_trap (pi
, syscall_num
, 1);
3975 print_sys_errmsg (pi
->pathname
, errno
);
3976 error ("PIOCSEXIT failed");
3980 if (!pi
->syscall_handlers
)
3983 error ("procfs_clear_syscall_trap: syscall_handlers is empty");
3987 /* Remove handler func from the handler list */
3989 for (i
= 0; i
< pi
->num_syscall_handlers
; i
++)
3990 if (pi
->syscall_handlers
[i
].syscall_num
== syscall_num
)
3992 if (i
+ 1 != pi
->num_syscall_handlers
)
3993 { /* Not the last entry.
3994 Move subsequent entries fwd. */
3995 memcpy (&pi
->syscall_handlers
[i
], &pi
->syscall_handlers
[i
+ 1],
3996 (pi
->num_syscall_handlers
- i
- 1)
3997 * sizeof (struct procfs_syscall_handler
));
4000 pi
->syscall_handlers
= xrealloc (pi
->syscall_handlers
,
4001 (pi
->num_syscall_handlers
- 1)
4002 * sizeof (struct procfs_syscall_handler
));
4003 pi
->num_syscall_handlers
--;
4008 error ("procfs_clear_syscall_trap: Couldn't find handler for sys call %d",
4016 procfs_set_syscall_trap -- arrange for a function to be called when the
4017 child executes the specified system call.
4021 void procfs_set_syscall_trap (struct procinfo *, int syscall_num, int flags,
4022 syscall_func_t *function)
4026 This function sets up an entry and/or exit trap for the specified system
4027 call. When the child executes the specified system call, your function
4028 will be called with the call #, a flag that indicates entry or exit, and
4029 pointers to rtnval and statval (which are used by procfs_wait). The
4030 function should return non-zero if something interesting happened, zero
4035 procfs_set_syscall_trap (pi
, syscall_num
, flags
, func
)
4036 struct procinfo
*pi
;
4039 syscall_func_t
*func
;
4043 if (flags
& PROCFS_SYSCALL_ENTRY
)
4045 if (ioctl (pi
->fd
, PIOCGENTRY
, &sysset
) < 0)
4047 print_sys_errmsg (pi
->pathname
, errno
);
4048 error ("PIOCGENTRY failed");
4051 praddset (&sysset
, syscall_num
);
4053 if (ioctl (pi
->fd
, PIOCSENTRY
, &sysset
) < 0)
4055 print_sys_errmsg (pi
->pathname
, errno
);
4056 error ("PIOCSENTRY failed");
4060 if (flags
& PROCFS_SYSCALL_EXIT
)
4062 if (ioctl (pi
->fd
, PIOCGEXIT
, &sysset
) < 0)
4064 procfs_clear_syscall_trap (pi
, syscall_num
, 1);
4065 print_sys_errmsg (pi
->pathname
, errno
);
4066 error ("PIOCGEXIT failed");
4069 praddset (&sysset
, syscall_num
);
4071 if (ioctl (pi
->fd
, PIOCSEXIT
, &sysset
) < 0)
4073 procfs_clear_syscall_trap (pi
, syscall_num
, 1);
4074 print_sys_errmsg (pi
->pathname
, errno
);
4075 error ("PIOCSEXIT failed");
4079 if (!pi
->syscall_handlers
)
4081 pi
->syscall_handlers
= xmalloc (sizeof (struct procfs_syscall_handler
));
4082 pi
->syscall_handlers
[0].syscall_num
= syscall_num
;
4083 pi
->syscall_handlers
[0].func
= func
;
4084 pi
->num_syscall_handlers
= 1;
4090 for (i
= 0; i
< pi
->num_syscall_handlers
; i
++)
4091 if (pi
->syscall_handlers
[i
].syscall_num
== syscall_num
)
4093 pi
->syscall_handlers
[i
].func
= func
;
4097 pi
->syscall_handlers
= xrealloc (pi
->syscall_handlers
, (i
+ 1)
4098 * sizeof (struct procfs_syscall_handler
));
4099 pi
->syscall_handlers
[i
].syscall_num
= syscall_num
;
4100 pi
->syscall_handlers
[i
].func
= func
;
4101 pi
->num_syscall_handlers
++;
4105 #ifdef SYS_lwp_create
4111 procfs_lwp_creation_handler - handle exit from the _lwp_create syscall
4115 int procfs_lwp_creation_handler (pi, syscall_num, why, rtnvalp, statvalp)
4119 This routine is called both when an inferior process and it's new lwp
4120 are about to finish a _lwp_create() system call. This is the system
4121 call that Solaris uses to create a lightweight process. When the
4122 target process gets this event, we can look at sysarg[2] to find the
4123 new childs lwp ID, and create a procinfo struct from that. After that,
4124 we pretend that we got a SIGTRAP, and return non-zero to tell
4125 procfs_wait to wake up. Subsequently, wait_for_inferior gets woken up,
4126 sees the new process and continues it.
4128 When we see the child exiting from lwp_create, we just contine it,
4129 since everything was handled when the parent trapped.
4132 In effect, we are only paying attention to the parent's completion of
4133 the lwp_create syscall. If we only paid attention to the child
4134 instead, then we wouldn't detect the creation of a suspended thread.
4138 procfs_lwp_creation_handler (pi
, syscall_num
, why
, rtnvalp
, statvalp
)
4139 struct procinfo
*pi
;
4146 struct procinfo
*childpi
;
4148 /* We've just detected the completion of an lwp_create system call. Now we
4149 need to setup a procinfo struct for this thread, and notify the thread
4150 system of the new arrival. */
4152 /* If lwp_create failed, then nothing interesting happened. Continue the
4153 process and go back to sleep. */
4155 if (pi
->prstatus
.pr_reg
[R_PSR
] & PS_FLAG_CARRY
)
4156 { /* _lwp_create failed */
4157 pi
->prrun
.pr_flags
&= PRSTEP
;
4158 pi
->prrun
.pr_flags
|= PRCFAULT
;
4160 if (ioctl (pi
->fd
, PIOCRUN
, &pi
->prrun
) != 0)
4161 perror_with_name (pi
->pathname
);
4166 /* At this point, the new thread is stopped at it's first instruction, and
4167 the parent is stopped at the exit from lwp_create. */
4169 if (pi
->new_child
) /* Child? */
4170 { /* Yes, just continue it */
4171 pi
->prrun
.pr_flags
&= PRSTEP
;
4172 pi
->prrun
.pr_flags
|= PRCFAULT
;
4174 if ((pi
->prstatus
.pr_flags
& PR_ISTOP
)
4175 && ioctl (pi
->fd
, PIOCRUN
, &pi
->prrun
) != 0)
4176 perror_with_name (pi
->pathname
);
4178 pi
->new_child
= 0; /* No longer new */
4183 /* We're the proud parent of a new thread. Setup an exit trap for lwp_create
4184 in the child and continue the parent. */
4186 /* Third arg is pointer to new thread id. */
4187 lwp_id
= read_memory_integer (pi
->prstatus
.pr_sysarg
[2], sizeof (int));
4189 lwp_id
= (lwp_id
<< 16) | PIDGET (pi
->pid
);
4191 childpi
= create_procinfo (lwp_id
);
4193 /* The new process has actually inherited the lwp_create syscall trap from
4194 it's parent, but we still have to call this to register a handler for
4197 procfs_set_syscall_trap (childpi
, SYS_lwp_create
, PROCFS_SYSCALL_EXIT
,
4198 procfs_lwp_creation_handler
);
4200 childpi
->new_child
= 1; /* Flag this as an unseen child process */
4202 *rtnvalp
= lwp_id
; /* the new arrival. */
4203 *statvalp
= (SIGTRAP
<< 8) | 0177;
4207 #endif /* SYS_lwp_create */
4209 /* Fork an inferior process, and start debugging it with /proc. */
4212 procfs_create_inferior (exec_file
, allargs
, env
)
4217 char *shell_file
= getenv ("SHELL");
4219 if (shell_file
!= NULL
&& strchr (shell_file
, '/') == NULL
)
4222 /* We will be looking down the PATH to find shell_file. If we
4223 just do this the normal way (via execlp, which operates by
4224 attempting an exec for each element of the PATH until it
4225 finds one which succeeds), then there will be an exec for
4226 each failed attempt, each of which will cause a PR_SYSEXIT
4227 stop, and we won't know how to distinguish the PR_SYSEXIT's
4228 for these failed execs with the ones for successful execs
4229 (whether the exec has succeeded is stored at that time in the
4230 carry bit or some such architecture-specific and
4231 non-ABI-specified place).
4233 So I can't think of anything better than to search the PATH
4234 now. This has several disadvantages: (1) There is a race
4235 condition; if we find a file now and it is deleted before we
4236 exec it, we lose, even if the deletion leaves a valid file
4237 further down in the PATH, (2) there is no way to know exactly
4238 what an executable (in the sense of "capable of being
4239 exec'd") file is. Using access() loses because it may lose
4240 if the caller is the superuser; failing to use it loses if
4241 there are ACLs or some such. */
4245 /* FIXME-maybe: might want "set path" command so user can change what
4246 path is used from within GDB. */
4247 char *path
= getenv ("PATH");
4249 struct stat statbuf
;
4252 path
= "/bin:/usr/bin";
4254 tryname
= alloca (strlen (path
) + strlen (shell_file
) + 2);
4255 for (p
= path
; p
!= NULL
; p
= p1
? p1
+ 1: NULL
)
4257 p1
= strchr (p
, ':');
4262 strncpy (tryname
, p
, len
);
4263 tryname
[len
] = '\0';
4264 strcat (tryname
, "/");
4265 strcat (tryname
, shell_file
);
4266 if (access (tryname
, X_OK
) < 0)
4268 if (stat (tryname
, &statbuf
) < 0)
4270 if (!S_ISREG (statbuf
.st_mode
))
4271 /* We certainly need to reject directories. I'm not quite
4272 as sure about FIFOs, sockets, etc., but I kind of doubt
4273 that people want to exec() these things. */
4278 /* Not found. This must be an error rather than merely passing
4279 the file to execlp(), because execlp() would try all the
4280 exec()s, causing GDB to get confused. */
4281 error ("Can't find shell %s in PATH", shell_file
);
4283 shell_file
= tryname
;
4286 fork_inferior (exec_file
, allargs
, env
,
4287 proc_set_exec_trap
, procfs_init_inferior
, shell_file
);
4289 /* We are at the first instruction we care about. */
4290 /* Pedal to the metal... */
4292 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_0
, 0);
4295 /* Clean up after the inferior dies. */
4298 procfs_mourn_inferior ()
4300 struct procinfo
*pi
;
4301 struct procinfo
*next_pi
;
4303 for (pi
= procinfo_list
; pi
; pi
= next_pi
)
4306 unconditionally_kill_inferior (pi
);
4309 unpush_target (&procfs_ops
);
4310 generic_mourn_inferior ();
4314 /* Mark our target-struct as eligible for stray "run" and "attach" commands. */
4318 /* This variable is controlled by modules that sit atop procfs that may layer
4319 their own process structure atop that provided here. sol-thread.c does
4320 this because of the Solaris two-level thread model. */
4322 return !procfs_suppress_run
;
4324 #ifdef TARGET_HAS_HARDWARE_WATCHPOINTS
4326 /* Insert a watchpoint */
4328 procfs_set_watchpoint(pid
, addr
, len
, rw
)
4334 struct procinfo
*pi
;
4337 pi
= find_procinfo (pid
== -1 ? inferior_pid
: pid
, 0);
4338 wpt
.pr_vaddr
= (caddr_t
)addr
;
4340 wpt
.pr_wflags
= ((rw
& 1) ? MA_READ
: 0) | ((rw
& 2) ? MA_WRITE
: 0);
4341 if (ioctl (pi
->fd
, PIOCSWATCH
, &wpt
) < 0)
4345 /* Currently it sometimes happens that the same watchpoint gets
4346 deleted twice - don't die in this case (FIXME please) */
4347 if (errno
== ESRCH
&& len
== 0)
4349 print_sys_errmsg (pi
->pathname
, errno
);
4350 error ("PIOCSWATCH failed");
4356 procfs_stopped_by_watchpoint(pid
)
4359 struct procinfo
*pi
;
4363 pi
= find_procinfo (pid
== -1 ? inferior_pid
: pid
, 0);
4364 if (pi
->prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
))
4366 why
= pi
->prstatus
.pr_why
;
4367 what
= pi
->prstatus
.pr_what
;
4368 if (why
== PR_FAULTED
4369 #if defined (FLTWATCH) && defined (FLTKWATCH)
4370 && (what
== FLTWATCH
|| what
== FLTKWATCH
)
4373 && (what
== FLTWATCH
)
4376 && (what
== FLTKWATCH
)
4386 /* Why is this necessary? Shouldn't dead threads just be removed from the
4390 procfs_thread_alive (pid
)
4396 /* Send a SIGINT to the process group. This acts just like the user typed a
4397 ^C on the controlling terminal.
4399 XXX - This may not be correct for all systems. Some may want to use
4400 killpg() instead of kill (-pgrp). */
4405 extern pid_t inferior_process_group
;
4407 kill (-inferior_process_group
, SIGINT
);
4410 /* Convert a pid to printable form. */
4414 procfs_pid_to_str (pid
)
4417 static char buf
[100];
4419 sprintf (buf
, "Kernel thread %d", TIDGET (pid
));
4425 struct target_ops procfs_ops
= {
4426 "procfs", /* to_shortname */
4427 "Unix /proc child process", /* to_longname */
4428 "Unix /proc child process (started by the \"run\" command).", /* to_doc */
4429 procfs_open
, /* to_open */
4431 procfs_attach
, /* to_attach */
4432 procfs_detach
, /* to_detach */
4433 procfs_resume
, /* to_resume */
4434 procfs_wait
, /* to_wait */
4435 procfs_fetch_registers
, /* to_fetch_registers */
4436 procfs_store_registers
, /* to_store_registers */
4437 procfs_prepare_to_store
, /* to_prepare_to_store */
4438 procfs_xfer_memory
, /* to_xfer_memory */
4439 procfs_files_info
, /* to_files_info */
4440 memory_insert_breakpoint
, /* to_insert_breakpoint */
4441 memory_remove_breakpoint
, /* to_remove_breakpoint */
4442 terminal_init_inferior
, /* to_terminal_init */
4443 terminal_inferior
, /* to_terminal_inferior */
4444 terminal_ours_for_output
, /* to_terminal_ours_for_output */
4445 terminal_ours
, /* to_terminal_ours */
4446 child_terminal_info
, /* to_terminal_info */
4447 procfs_kill_inferior
, /* to_kill */
4449 0, /* to_lookup_symbol */
4450 procfs_create_inferior
, /* to_create_inferior */
4451 procfs_mourn_inferior
, /* to_mourn_inferior */
4452 procfs_can_run
, /* to_can_run */
4453 procfs_notice_signals
, /* to_notice_signals */
4454 procfs_thread_alive
, /* to_thread_alive */
4455 procfs_stop
, /* to_stop */
4456 process_stratum
, /* to_stratum */
4458 1, /* to_has_all_memory */
4459 1, /* to_has_memory */
4460 1, /* to_has_stack */
4461 1, /* to_has_registers */
4462 1, /* to_has_execution */
4464 0, /* sections_end */
4465 OPS_MAGIC
/* to_magic */
4469 _initialize_procfs ()
4471 #ifdef HAVE_OPTIONAL_PROC_FS
4475 /* If we have an optional /proc filesystem (e.g. under OSF/1),
4476 don't add procfs support if we cannot access the running
4478 sprintf (procname
, PROC_NAME_FMT
, getpid ());
4479 if ((fd
= open (procname
, O_RDONLY
)) < 0)
4484 add_target (&procfs_ops
);
4486 add_info ("proc", info_proc
,
4487 "Show process status information using /proc entry.\n\
4488 Specify process id or use current inferior by default.\n\
4489 Specify keywords for detailed information; default is summary.\n\
4490 Keywords are: `all', `faults', `flags', `id', `mappings', `signals',\n\
4491 `status', `syscalls', and `times'.\n\
4492 Unambiguous abbreviations may be used.");
4494 init_syscall_table ();