* stabsread.c (get_substring): Declare second arg as int.
[deliverable/binutils-gdb.git] / gdb / procfs.c
CommitLineData
35f5886e 1/* Machine independent support for SVR4 /proc (process file system) for GDB.
255181a9 2 Copyright 1991, 1992, 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
35f5886e
FF
3 Written by Fred Fish at Cygnus Support.
4
5This file is part of GDB.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
6c9638b4 19Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
35f5886e
FF
20
21
22/* N O T E S
23
24For information on the details of using /proc consult section proc(4)
25in the UNIX System V Release 4 System Administrator's Reference Manual.
26
27The general register and floating point register sets are manipulated by
28separate ioctl's. This file makes the assumption that if FP0_REGNUM is
29defined, then support for the floating point register set is desired,
30regardless of whether or not the actual target has floating point hardware.
31
32 */
33
34
5129100c 35#include "defs.h"
35f5886e 36
08f74b92 37#include <sys/types.h>
407a8389 38#include <time.h>
2592eef8
PS
39#include <sys/fault.h>
40#include <sys/syscall.h>
35f5886e
FF
41#include <sys/procfs.h>
42#include <fcntl.h>
43#include <errno.h>
2b576293 44#include "gdb_string.h"
de43d7d0
SG
45#include <stropts.h>
46#include <poll.h>
08f74b92 47#include <unistd.h>
2b576293 48#include "gdb_stat.h"
35f5886e 49
35f5886e
FF
50#include "inferior.h"
51#include "target.h"
51b57ded 52#include "command.h"
3fbdd536 53#include "gdbcore.h"
fdfa3315 54#include "gdbthread.h"
cc221e76
FF
55
56#define MAX_SYSCALLS 256 /* Maximum number of syscalls for table */
35f5886e
FF
57
58#ifndef PROC_NAME_FMT
6c316cfd 59#define PROC_NAME_FMT "/proc/%05d"
35f5886e
FF
60#endif
61
3fbdd536
JG
62extern struct target_ops procfs_ops; /* Forward declaration */
63
8fc2b417
SG
64int 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
67 thread support. */
68
35f5886e
FF
69#if 1 /* FIXME: Gross and ugly hack to resolve coredep.c global */
70CORE_ADDR kernel_u_addr;
71#endif
72
cc221e76
FF
73#ifdef BROKEN_SIGINFO_H /* Workaround broken SGS <sys/siginfo.h> */
74#undef si_pid
75#define si_pid _data._proc.pid
76#undef si_uid
77#define si_uid _data._proc._pdata._kill.uid
78#endif /* BROKEN_SIGINFO_H */
79
35f5886e
FF
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,
a39ad5ce
FF
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. */
35f5886e
FF
88
89struct procinfo {
de43d7d0 90 struct procinfo *next;
35f5886e
FF
91 int pid; /* Process ID of inferior */
92 int fd; /* File descriptor for /proc entry */
93 char *pathname; /* Pathname to /proc entry */
de43d7d0 94 int had_event; /* poll/select says something happened */
35f5886e 95 int was_stopped; /* Nonzero if was stopped prior to attach */
d65eee73 96 int nopass_next_sigstop; /* Don't pass a sigstop on next resume */
35f5886e
FF
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 */
cc221e76
FF
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 */
8fc2b417
SG
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 */
a39ad5ce
FF
113};
114
de43d7d0
SG
115/* List of inferior process information */
116static struct procinfo *procinfo_list = NULL;
117
118static struct pollfd *poll_list; /* pollfds used for waiting on /proc */
119
120static int num_poll_list = 0; /* Number of entries in poll_list */
121
cc221e76
FF
122/* Much of the information used in the /proc interface, particularly for
123 printing status information, is kept as tables of structures of the
124 following form. These tables can be used to map numeric values to
125 their symbolic names and to a string that describes their specific use. */
126
127struct trans {
128 int value; /* The numeric value */
129 char *name; /* The equivalent symbolic value */
130 char *desc; /* Short description of value */
131};
132
133/* Translate bits in the pr_flags member of the prstatus structure, into the
134 names and desc information. */
135
136static struct trans pr_flag_table[] =
137{
138#if defined (PR_STOPPED)
e3be225e 139 { PR_STOPPED, "PR_STOPPED", "Process is stopped" },
cc221e76
FF
140#endif
141#if defined (PR_ISTOP)
e3be225e 142 { PR_ISTOP, "PR_ISTOP", "Stopped on an event of interest" },
cc221e76
FF
143#endif
144#if defined (PR_DSTOP)
e3be225e 145 { PR_DSTOP, "PR_DSTOP", "A stop directive is in effect" },
cc221e76
FF
146#endif
147#if defined (PR_ASLEEP)
e3be225e 148 { PR_ASLEEP, "PR_ASLEEP", "Sleeping in an interruptible system call" },
cc221e76
FF
149#endif
150#if defined (PR_FORK)
e3be225e 151 { PR_FORK, "PR_FORK", "Inherit-on-fork is in effect" },
cc221e76
FF
152#endif
153#if defined (PR_RLC)
e3be225e 154 { PR_RLC, "PR_RLC", "Run-on-last-close is in effect" },
cc221e76
FF
155#endif
156#if defined (PR_PTRACE)
e3be225e 157 { PR_PTRACE, "PR_PTRACE", "Process is being controlled by ptrace" },
cc221e76
FF
158#endif
159#if defined (PR_PCINVAL)
e3be225e 160 { PR_PCINVAL, "PR_PCINVAL", "PC refers to an invalid virtual address" },
cc221e76
FF
161#endif
162#if defined (PR_ISSYS)
e3be225e 163 { PR_ISSYS, "PR_ISSYS", "Is a system process" },
5c1c5e67
FF
164#endif
165#if defined (PR_STEP)
e3be225e 166 { PR_STEP, "PR_STEP", "Process has single step pending" },
5c1c5e67
FF
167#endif
168#if defined (PR_KLC)
e3be225e 169 { PR_KLC, "PR_KLC", "Kill-on-last-close is in effect" },
5c1c5e67
FF
170#endif
171#if defined (PR_ASYNC)
e3be225e 172 { PR_ASYNC, "PR_ASYNC", "Asynchronous stop is in effect" },
5c1c5e67
FF
173#endif
174#if defined (PR_PCOMPAT)
e3be225e 175 { PR_PCOMPAT, "PR_PCOMPAT", "Ptrace compatibility mode in effect" },
cc221e76 176#endif
e3be225e 177 { 0, NULL, NULL }
cc221e76
FF
178};
179
180/* Translate values in the pr_why field of the prstatus struct. */
181
182static struct trans pr_why_table[] =
183{
184#if defined (PR_REQUESTED)
e3be225e 185 { PR_REQUESTED, "PR_REQUESTED", "Directed to stop via PIOCSTOP/PIOCWSTOP" },
cc221e76
FF
186#endif
187#if defined (PR_SIGNALLED)
e3be225e 188 { PR_SIGNALLED, "PR_SIGNALLED", "Receipt of a traced signal" },
cc221e76
FF
189#endif
190#if defined (PR_FAULTED)
e3be225e 191 { PR_FAULTED, "PR_FAULTED", "Incurred a traced hardware fault" },
cc221e76
FF
192#endif
193#if defined (PR_SYSENTRY)
e3be225e 194 { PR_SYSENTRY, "PR_SYSENTRY", "Entry to a traced system call" },
cc221e76
FF
195#endif
196#if defined (PR_SYSEXIT)
e3be225e 197 { PR_SYSEXIT, "PR_SYSEXIT", "Exit from a traced system call" },
cc221e76
FF
198#endif
199#if defined (PR_JOBCONTROL)
e3be225e 200 { PR_JOBCONTROL, "PR_JOBCONTROL", "Default job control stop signal action" },
5c1c5e67
FF
201#endif
202#if defined (PR_SUSPENDED)
e3be225e 203 { PR_SUSPENDED, "PR_SUSPENDED", "Process suspended" },
cc221e76 204#endif
e3be225e 205 { 0, NULL, NULL }
cc221e76
FF
206};
207
208/* Hardware fault translation table. */
209
210static struct trans faults_table[] =
211{
212#if defined (FLTILL)
e3be225e 213 { FLTILL, "FLTILL", "Illegal instruction" },
cc221e76
FF
214#endif
215#if defined (FLTPRIV)
e3be225e 216 { FLTPRIV, "FLTPRIV", "Privileged instruction" },
cc221e76
FF
217#endif
218#if defined (FLTBPT)
e3be225e 219 { FLTBPT, "FLTBPT", "Breakpoint trap" },
cc221e76
FF
220#endif
221#if defined (FLTTRACE)
e3be225e 222 { FLTTRACE, "FLTTRACE", "Trace trap" },
cc221e76
FF
223#endif
224#if defined (FLTACCESS)
e3be225e 225 { FLTACCESS, "FLTACCESS", "Memory access fault" },
cc221e76
FF
226#endif
227#if defined (FLTBOUNDS)
e3be225e 228 { FLTBOUNDS, "FLTBOUNDS", "Memory bounds violation" },
cc221e76
FF
229#endif
230#if defined (FLTIOVF)
e3be225e 231 { FLTIOVF, "FLTIOVF", "Integer overflow" },
cc221e76
FF
232#endif
233#if defined (FLTIZDIV)
e3be225e 234 { FLTIZDIV, "FLTIZDIV", "Integer zero divide" },
cc221e76
FF
235#endif
236#if defined (FLTFPE)
e3be225e 237 { FLTFPE, "FLTFPE", "Floating-point exception" },
cc221e76
FF
238#endif
239#if defined (FLTSTACK)
e3be225e 240 { FLTSTACK, "FLTSTACK", "Unrecoverable stack fault" },
cc221e76
FF
241#endif
242#if defined (FLTPAGE)
e3be225e 243 { FLTPAGE, "FLTPAGE", "Recoverable page fault" },
cc221e76 244#endif
e3be225e 245 { 0, NULL, NULL }
cc221e76
FF
246};
247
248/* Translation table for signal generation information. See UNIX System
249 V Release 4 Programmer's Reference Manual, siginfo(5). */
250
251static struct sigcode {
252 int signo;
253 int code;
254 char *codename;
255 char *desc;
256} siginfo_table[] = {
257#if defined (SIGILL) && defined (ILL_ILLOPC)
e3be225e 258 { SIGILL, ILL_ILLOPC, "ILL_ILLOPC", "Illegal opcode" },
cc221e76
FF
259#endif
260#if defined (SIGILL) && defined (ILL_ILLOPN)
e3be225e 261 { SIGILL, ILL_ILLOPN, "ILL_ILLOPN", "Illegal operand", },
cc221e76
FF
262#endif
263#if defined (SIGILL) && defined (ILL_ILLADR)
e3be225e 264 { SIGILL, ILL_ILLADR, "ILL_ILLADR", "Illegal addressing mode" },
cc221e76
FF
265#endif
266#if defined (SIGILL) && defined (ILL_ILLTRP)
e3be225e 267 { SIGILL, ILL_ILLTRP, "ILL_ILLTRP", "Illegal trap" },
cc221e76
FF
268#endif
269#if defined (SIGILL) && defined (ILL_PRVOPC)
e3be225e 270 { SIGILL, ILL_PRVOPC, "ILL_PRVOPC", "Privileged opcode" },
cc221e76
FF
271#endif
272#if defined (SIGILL) && defined (ILL_PRVREG)
e3be225e 273 { SIGILL, ILL_PRVREG, "ILL_PRVREG", "Privileged register" },
cc221e76
FF
274#endif
275#if defined (SIGILL) && defined (ILL_COPROC)
e3be225e 276 { SIGILL, ILL_COPROC, "ILL_COPROC", "Coprocessor error" },
cc221e76
FF
277#endif
278#if defined (SIGILL) && defined (ILL_BADSTK)
e3be225e 279 { SIGILL, ILL_BADSTK, "ILL_BADSTK", "Internal stack error" },
cc221e76
FF
280#endif
281#if defined (SIGFPE) && defined (FPE_INTDIV)
e3be225e 282 { SIGFPE, FPE_INTDIV, "FPE_INTDIV", "Integer divide by zero" },
cc221e76
FF
283#endif
284#if defined (SIGFPE) && defined (FPE_INTOVF)
e3be225e 285 { SIGFPE, FPE_INTOVF, "FPE_INTOVF", "Integer overflow" },
cc221e76
FF
286#endif
287#if defined (SIGFPE) && defined (FPE_FLTDIV)
e3be225e 288 { SIGFPE, FPE_FLTDIV, "FPE_FLTDIV", "Floating point divide by zero" },
cc221e76
FF
289#endif
290#if defined (SIGFPE) && defined (FPE_FLTOVF)
e3be225e 291 { SIGFPE, FPE_FLTOVF, "FPE_FLTOVF", "Floating point overflow" },
cc221e76
FF
292#endif
293#if defined (SIGFPE) && defined (FPE_FLTUND)
e3be225e 294 { SIGFPE, FPE_FLTUND, "FPE_FLTUND", "Floating point underflow" },
cc221e76
FF
295#endif
296#if defined (SIGFPE) && defined (FPE_FLTRES)
e3be225e 297 { SIGFPE, FPE_FLTRES, "FPE_FLTRES", "Floating point inexact result" },
cc221e76
FF
298#endif
299#if defined (SIGFPE) && defined (FPE_FLTINV)
e3be225e 300 { SIGFPE, FPE_FLTINV, "FPE_FLTINV", "Invalid floating point operation" },
cc221e76
FF
301#endif
302#if defined (SIGFPE) && defined (FPE_FLTSUB)
e3be225e 303 { SIGFPE, FPE_FLTSUB, "FPE_FLTSUB", "Subscript out of range" },
cc221e76
FF
304#endif
305#if defined (SIGSEGV) && defined (SEGV_MAPERR)
e3be225e 306 { SIGSEGV, SEGV_MAPERR, "SEGV_MAPERR", "Address not mapped to object" },
cc221e76
FF
307#endif
308#if defined (SIGSEGV) && defined (SEGV_ACCERR)
e3be225e 309 { SIGSEGV, SEGV_ACCERR, "SEGV_ACCERR", "Invalid permissions for object" },
cc221e76
FF
310#endif
311#if defined (SIGBUS) && defined (BUS_ADRALN)
e3be225e 312 { SIGBUS, BUS_ADRALN, "BUS_ADRALN", "Invalid address alignment" },
cc221e76
FF
313#endif
314#if defined (SIGBUS) && defined (BUS_ADRERR)
e3be225e 315 { SIGBUS, BUS_ADRERR, "BUS_ADRERR", "Non-existent physical address" },
cc221e76
FF
316#endif
317#if defined (SIGBUS) && defined (BUS_OBJERR)
e3be225e 318 { SIGBUS, BUS_OBJERR, "BUS_OBJERR", "Object specific hardware error" },
cc221e76
FF
319#endif
320#if defined (SIGTRAP) && defined (TRAP_BRKPT)
e3be225e 321 { SIGTRAP, TRAP_BRKPT, "TRAP_BRKPT", "Process breakpoint" },
cc221e76
FF
322#endif
323#if defined (SIGTRAP) && defined (TRAP_TRACE)
e3be225e 324 { SIGTRAP, TRAP_TRACE, "TRAP_TRACE", "Process trace trap" },
cc221e76
FF
325#endif
326#if defined (SIGCLD) && defined (CLD_EXITED)
e3be225e 327 { SIGCLD, CLD_EXITED, "CLD_EXITED", "Child has exited" },
cc221e76
FF
328#endif
329#if defined (SIGCLD) && defined (CLD_KILLED)
e3be225e 330 { SIGCLD, CLD_KILLED, "CLD_KILLED", "Child was killed" },
cc221e76
FF
331#endif
332#if defined (SIGCLD) && defined (CLD_DUMPED)
e3be225e 333 { SIGCLD, CLD_DUMPED, "CLD_DUMPED", "Child has terminated abnormally" },
cc221e76
FF
334#endif
335#if defined (SIGCLD) && defined (CLD_TRAPPED)
e3be225e 336 { SIGCLD, CLD_TRAPPED, "CLD_TRAPPED", "Traced child has trapped" },
cc221e76
FF
337#endif
338#if defined (SIGCLD) && defined (CLD_STOPPED)
e3be225e 339 { SIGCLD, CLD_STOPPED, "CLD_STOPPED", "Child has stopped" },
cc221e76
FF
340#endif
341#if defined (SIGCLD) && defined (CLD_CONTINUED)
e3be225e 342 { SIGCLD, CLD_CONTINUED, "CLD_CONTINUED", "Stopped child had continued" },
cc221e76
FF
343#endif
344#if defined (SIGPOLL) && defined (POLL_IN)
e3be225e 345 { SIGPOLL, POLL_IN, "POLL_IN", "Input input available" },
cc221e76
FF
346#endif
347#if defined (SIGPOLL) && defined (POLL_OUT)
e3be225e 348 { SIGPOLL, POLL_OUT, "POLL_OUT", "Output buffers available" },
cc221e76
FF
349#endif
350#if defined (SIGPOLL) && defined (POLL_MSG)
e3be225e 351 { SIGPOLL, POLL_MSG, "POLL_MSG", "Input message available" },
cc221e76
FF
352#endif
353#if defined (SIGPOLL) && defined (POLL_ERR)
e3be225e 354 { SIGPOLL, POLL_ERR, "POLL_ERR", "I/O error" },
cc221e76
FF
355#endif
356#if defined (SIGPOLL) && defined (POLL_PRI)
e3be225e 357 { SIGPOLL, POLL_PRI, "POLL_PRI", "High priority input available" },
cc221e76
FF
358#endif
359#if defined (SIGPOLL) && defined (POLL_HUP)
e3be225e 360 { SIGPOLL, POLL_HUP, "POLL_HUP", "Device disconnected" },
cc221e76 361#endif
e3be225e 362 { 0, 0, NULL, NULL }
cc221e76
FF
363};
364
cc221e76
FF
365static char *syscall_table[MAX_SYSCALLS];
366
1ab3bf1b
JG
367/* Prototypes for local functions */
368
b607efe7
FF
369static void procfs_stop PARAMS ((void));
370
371static int procfs_thread_alive PARAMS ((int));
372
373static int procfs_can_run PARAMS ((void));
374
375static void procfs_mourn_inferior PARAMS ((void));
376
377static void procfs_fetch_registers PARAMS ((int));
378
379static int procfs_wait PARAMS ((int, struct target_waitstatus *));
380
381static void procfs_open PARAMS ((char *, int));
382
383static void procfs_files_info PARAMS ((struct target_ops *));
384
385static void procfs_prepare_to_store PARAMS ((void));
386
387static void procfs_detach PARAMS ((char *, int));
388
389static void procfs_attach PARAMS ((char *, int));
390
391static void proc_set_exec_trap PARAMS ((void));
392
393static int procfs_init_inferior PARAMS ((int));
394
395static struct procinfo *create_procinfo PARAMS ((int));
396
397static void procfs_store_registers PARAMS ((int));
398
399static int procfs_xfer_memory PARAMS ((CORE_ADDR, char *, int, int, struct target_ops *));
400
401static void procfs_kill_inferior PARAMS ((void));
402
403static char *sigcodedesc PARAMS ((siginfo_t *));
404
405static char *sigcodename PARAMS ((siginfo_t *));
406
407static struct procinfo *wait_fd PARAMS ((void));
408
409static void remove_fd PARAMS ((struct procinfo *));
410
411static void add_fd PARAMS ((struct procinfo *));
412
e3be225e 413static void set_proc_siginfo PARAMS ((struct procinfo *, int));
6b801388 414
e3be225e 415static void init_syscall_table PARAMS ((void));
cc221e76 416
e3be225e 417static char *syscallname PARAMS ((int));
cc221e76 418
e3be225e 419static char *signalname PARAMS ((int));
cc221e76 420
e3be225e 421static char *errnoname PARAMS ((int));
4ace50a5 422
e3be225e 423static int proc_address_to_fd PARAMS ((struct procinfo *, CORE_ADDR, int));
1ab3bf1b 424
e3be225e 425static int open_proc_file PARAMS ((int, struct procinfo *, int));
1ab3bf1b 426
e3be225e 427static void close_proc_file PARAMS ((struct procinfo *));
1ab3bf1b 428
e3be225e 429static void unconditionally_kill_inferior PARAMS ((struct procinfo *));
1ab3bf1b 430
e3be225e 431static NORETURN void proc_init_failed PARAMS ((struct procinfo *, char *)) ATTR_NORETURN;
1ab3bf1b 432
e3be225e 433static void info_proc PARAMS ((char *, int));
cc221e76 434
e3be225e 435static void info_proc_flags PARAMS ((struct procinfo *, int));
cc221e76 436
e3be225e 437static void info_proc_stop PARAMS ((struct procinfo *, int));
1ab3bf1b 438
e3be225e 439static void info_proc_siginfo PARAMS ((struct procinfo *, int));
cc221e76 440
e3be225e 441static void info_proc_syscalls PARAMS ((struct procinfo *, int));
cc221e76 442
e3be225e 443static void info_proc_mappings PARAMS ((struct procinfo *, int));
cc221e76 444
e3be225e 445static void info_proc_signals PARAMS ((struct procinfo *, int));
cc221e76 446
e3be225e 447static void info_proc_faults PARAMS ((struct procinfo *, int));
1ab3bf1b 448
e3be225e 449static char *mappingflags PARAMS ((long));
1ab3bf1b 450
e3be225e 451static char *lookupname PARAMS ((struct trans *, unsigned int, char *));
cc221e76 452
e3be225e 453static char *lookupdesc PARAMS ((struct trans *, unsigned int));
cc221e76 454
e3be225e 455static int do_attach PARAMS ((int pid));
3fbdd536 456
e3be225e 457static void do_detach PARAMS ((int siggnal));
3fbdd536 458
e3be225e 459static void procfs_create_inferior PARAMS ((char *, char *, char **));
3fbdd536 460
e3be225e 461static void procfs_notice_signals PARAMS ((int pid));
de43d7d0 462
e3be225e 463static struct procinfo *find_procinfo PARAMS ((pid_t pid, int okfail));
3950a34e 464
8fc2b417
SG
465typedef int syscall_func_t PARAMS ((struct procinfo *pi, int syscall_num,
466 int why, int *rtnval, int *statval));
467
468static void procfs_set_syscall_trap PARAMS ((struct procinfo *pi,
469 int syscall_num, int flags,
470 syscall_func_t *func));
471
472static void procfs_clear_syscall_trap PARAMS ((struct procinfo *pi,
473 int syscall_num, int errok));
474
475#define PROCFS_SYSCALL_ENTRY 0x1 /* Trap on entry to sys call */
476#define PROCFS_SYSCALL_EXIT 0x2 /* Trap on exit from sys call */
477
478static syscall_func_t procfs_exit_handler;
479
480static syscall_func_t procfs_exec_handler;
481
482#ifdef SYS_sproc
483static syscall_func_t procfs_sproc_handler;
484static syscall_func_t procfs_fork_handler;
485#endif
486
487#ifdef SYS_lwp_create
488static syscall_func_t procfs_lwp_creation_handler;
489#endif
490
491static void modify_inherit_on_fork_flag PARAMS ((int fd, int flag));
492static void modify_run_on_last_close_flag PARAMS ((int fd, int flag));
493
494/* */
495
496struct procfs_syscall_handler
497{
498 int syscall_num; /* The number of the system call being handled */
499 /* The function to be called */
500 syscall_func_t *func;
501};
502
503static void procfs_resume PARAMS ((int pid, int step,
504 enum target_signal signo));
505
1ab3bf1b
JG
506/* External function prototypes that can't be easily included in any
507 header file because the args are typedefs in system include files. */
508
e3be225e 509extern void supply_gregset PARAMS ((gregset_t *));
1ab3bf1b 510
e3be225e 511extern void fill_gregset PARAMS ((gregset_t *, int));
1ab3bf1b 512
e3be225e 513extern void supply_fpregset PARAMS ((fpregset_t *));
1ab3bf1b 514
e3be225e 515extern void fill_fpregset PARAMS ((fpregset_t *, int));
35f5886e 516
cc221e76
FF
517/*
518
de43d7d0
SG
519LOCAL FUNCTION
520
521 find_procinfo -- convert a process id to a struct procinfo
522
523SYNOPSIS
524
525 static struct procinfo * find_procinfo (pid_t pid, int okfail);
526
527DESCRIPTION
528
529 Given a process id, look it up in the procinfo chain. Returns
530 a struct procinfo *. If can't find pid, then call error(),
531 unless okfail is set, in which case, return NULL;
532 */
533
534static struct procinfo *
535find_procinfo (pid, okfail)
536 pid_t pid;
537 int okfail;
538{
539 struct procinfo *procinfo;
540
541 for (procinfo = procinfo_list; procinfo; procinfo = procinfo->next)
542 if (procinfo->pid == pid)
543 return procinfo;
544
545 if (okfail)
546 return NULL;
547
548 error ("procfs (find_procinfo): Couldn't locate pid %d", pid);
549}
550
551/*
552
7c5d526e
SG
553LOCAL MACRO
554
555 current_procinfo -- convert inferior_pid to a struct procinfo
556
557SYNOPSIS
558
559 static struct procinfo * current_procinfo;
560
561DESCRIPTION
562
563 Looks up inferior_pid in the procinfo chain. Always returns a
564 struct procinfo *. If process can't be found, we error() out.
565 */
566
567#define current_procinfo find_procinfo (inferior_pid, 0)
568
569/*
570
de43d7d0
SG
571LOCAL FUNCTION
572
573 add_fd -- Add the fd to the poll/select list
574
575SYNOPSIS
576
577 static void add_fd (struct procinfo *);
578
579DESCRIPTION
580
581 Add the fd of the supplied procinfo to the list of fds used for
582 poll/select operations.
583 */
584
585static void
586add_fd (pi)
587 struct procinfo *pi;
588{
589 if (num_poll_list <= 0)
590 poll_list = (struct pollfd *) xmalloc (sizeof (struct pollfd));
591 else
592 poll_list = (struct pollfd *) xrealloc (poll_list,
593 (num_poll_list + 1)
594 * sizeof (struct pollfd));
595 poll_list[num_poll_list].fd = pi->fd;
596 poll_list[num_poll_list].events = POLLPRI;
597
598 num_poll_list++;
599}
600
601static void
602remove_fd (pi)
603 struct procinfo *pi;
604{
605 int i;
606
607 for (i = 0; i < num_poll_list; i++)
608 {
609 if (poll_list[i].fd == pi->fd)
610 {
611 if (i != num_poll_list - 1)
8fc2b417 612 memcpy (poll_list + i, poll_list + i + 1,
de43d7d0
SG
613 (num_poll_list - i - 1) * sizeof (struct pollfd));
614
615 num_poll_list--;
616
617 if (num_poll_list == 0)
618 free (poll_list);
619 else
620 poll_list = (struct pollfd *) xrealloc (poll_list,
621 num_poll_list
622 * sizeof (struct pollfd));
623 return;
624 }
625 }
626}
627
7c5d526e
SG
628static struct procinfo *
629wait_fd ()
630{
631 struct procinfo *pi;
b607efe7 632#ifndef LOSING_POLL
7c5d526e
SG
633 int num_fds;
634 int i;
b607efe7 635#endif
de43d7d0 636
1e75b5f5 637 set_sigint_trap (); /* Causes SIGINT to be passed on to the
7c5d526e 638 attached process. */
429f1c9f 639 set_sigio_trap ();
de43d7d0 640
7c5d526e
SG
641#ifndef LOSING_POLL
642 num_fds = poll (poll_list, num_poll_list, -1);
643#else
644 pi = current_procinfo;
de43d7d0 645
8afd05c0 646 while (ioctl (pi->fd, PIOCWSTOP, &pi->prstatus) < 0)
7c5d526e 647 {
cef0333e
PS
648 if (errno == ENOENT)
649 {
650 /* Process exited. */
651 pi->prstatus.pr_flags = 0;
652 break;
653 }
654 else if (errno != EINTR)
8afd05c0
JK
655 {
656 print_sys_errmsg (pi->pathname, errno);
657 error ("PIOCWSTOP failed");
658 }
7c5d526e 659 }
fb63d460 660 pi->had_event = 1;
7c5d526e
SG
661#endif
662
1e75b5f5 663 clear_sigint_trap ();
429f1c9f 664 clear_sigio_trap ();
de43d7d0 665
7c5d526e 666#ifndef LOSING_POLL
de43d7d0 667
7c5d526e
SG
668 if (num_fds <= 0)
669 {
670 print_sys_errmsg ("poll failed\n", errno);
671 error ("Poll failed, returned %d", num_fds);
672 }
673
674 for (i = 0; i < num_poll_list && num_fds > 0; i++)
675 {
676 if ((poll_list[i].revents & (POLLPRI|POLLERR|POLLHUP|POLLNVAL)) == 0)
677 continue;
678 for (pi = procinfo_list; pi; pi = pi->next)
679 {
680 if (poll_list[i].fd == pi->fd)
681 {
682 if (ioctl (pi->fd, PIOCSTATUS, &pi->prstatus) < 0)
683 {
684 print_sys_errmsg (pi->pathname, errno);
685 error ("PIOCSTATUS failed");
686 }
687 num_fds--;
688 pi->had_event = 1;
689 break;
690 }
691 }
692 if (!pi)
8fc2b417 693 error ("wait_fd: Couldn't find procinfo for fd %d\n",
7c5d526e
SG
694 poll_list[i].fd);
695 }
696#endif /* LOSING_POLL */
697
698 return pi;
699}
de43d7d0
SG
700
701/*
702
cc221e76
FF
703LOCAL FUNCTION
704
705 lookupdesc -- translate a value to a summary desc string
706
707SYNOPSIS
708
709 static char *lookupdesc (struct trans *transp, unsigned int val);
710
711DESCRIPTION
712
713 Given a pointer to a translation table and a value to be translated,
714 lookup the desc string and return it.
715 */
716
717static char *
718lookupdesc (transp, val)
719 struct trans *transp;
720 unsigned int val;
721{
722 char *desc;
723
724 for (desc = NULL; transp -> name != NULL; transp++)
725 {
726 if (transp -> value == val)
727 {
728 desc = transp -> desc;
729 break;
730 }
731 }
732
733 /* Didn't find a translation for the specified value, set a default one. */
734
735 if (desc == NULL)
736 {
737 desc = "Unknown";
738 }
739 return (desc);
740}
741
742/*
743
744LOCAL FUNCTION
745
746 lookupname -- translate a value to symbolic name
747
748SYNOPSIS
749
750 static char *lookupname (struct trans *transp, unsigned int val,
751 char *prefix);
752
753DESCRIPTION
754
755 Given a pointer to a translation table, a value to be translated,
756 and a default prefix to return if the value can't be translated,
757 match the value with one of the translation table entries and
758 return a pointer to the symbolic name.
759
760 If no match is found it just returns the value as a printable string,
761 with the given prefix. The previous such value, if any, is freed
762 at this time.
763 */
764
765static char *
766lookupname (transp, val, prefix)
767 struct trans *transp;
768 unsigned int val;
769 char *prefix;
770{
771 static char *locbuf;
772 char *name;
773
774 for (name = NULL; transp -> name != NULL; transp++)
775 {
776 if (transp -> value == val)
777 {
778 name = transp -> name;
779 break;
780 }
781 }
782
783 /* Didn't find a translation for the specified value, build a default
784 one using the specified prefix and return it. The lifetime of
785 the value is only until the next one is needed. */
786
787 if (name == NULL)
788 {
789 if (locbuf != NULL)
790 {
791 free (locbuf);
792 }
793 locbuf = xmalloc (strlen (prefix) + 16);
4ed3a9ea 794 sprintf (locbuf, "%s %u", prefix, val);
cc221e76
FF
795 name = locbuf;
796 }
797 return (name);
798}
799
800static char *
801sigcodename (sip)
802 siginfo_t *sip;
803{
804 struct sigcode *scp;
805 char *name = NULL;
806 static char locbuf[32];
807
808 for (scp = siginfo_table; scp -> codename != NULL; scp++)
809 {
810 if ((scp -> signo == sip -> si_signo) &&
811 (scp -> code == sip -> si_code))
812 {
813 name = scp -> codename;
814 break;
815 }
816 }
817 if (name == NULL)
818 {
4ed3a9ea 819 sprintf (locbuf, "sigcode %u", sip -> si_signo);
cc221e76
FF
820 name = locbuf;
821 }
822 return (name);
823}
824
3fbdd536
JG
825static char *
826sigcodedesc (sip)
cc221e76
FF
827 siginfo_t *sip;
828{
829 struct sigcode *scp;
830 char *desc = NULL;
831
832 for (scp = siginfo_table; scp -> codename != NULL; scp++)
833 {
834 if ((scp -> signo == sip -> si_signo) &&
835 (scp -> code == sip -> si_code))
836 {
837 desc = scp -> desc;
838 break;
839 }
840 }
841 if (desc == NULL)
842 {
843 desc = "Unrecognized signal or trap use";
844 }
845 return (desc);
846}
847
848/*
849
850LOCAL FUNCTION
851
852 syscallname - translate a system call number into a system call name
853
854SYNOPSIS
855
856 char *syscallname (int syscallnum)
857
858DESCRIPTION
859
860 Given a system call number, translate it into the printable name
861 of a system call, or into "syscall <num>" if it is an unknown
862 number.
863 */
864
865static char *
866syscallname (syscallnum)
867 int syscallnum;
868{
869 static char locbuf[32];
cc221e76 870
8fc2b417
SG
871 if (syscallnum >= 0 && syscallnum < MAX_SYSCALLS
872 && syscall_table[syscallnum] != NULL)
873 return syscall_table[syscallnum];
cc221e76
FF
874 else
875 {
4ed3a9ea 876 sprintf (locbuf, "syscall %u", syscallnum);
8fc2b417 877 return locbuf;
cc221e76 878 }
cc221e76
FF
879}
880
881/*
882
883LOCAL FUNCTION
884
885 init_syscall_table - initialize syscall translation table
886
887SYNOPSIS
888
889 void init_syscall_table (void)
890
891DESCRIPTION
892
893 Dynamically initialize the translation table to convert system
894 call numbers into printable system call names. Done once per
895 gdb run, on initialization.
896
897NOTES
898
899 This is awfully ugly, but preprocessor tricks to make it prettier
900 tend to be nonportable.
901 */
902
903static void
904init_syscall_table ()
905{
cc221e76
FF
906#if defined (SYS_exit)
907 syscall_table[SYS_exit] = "exit";
908#endif
909#if defined (SYS_fork)
910 syscall_table[SYS_fork] = "fork";
911#endif
912#if defined (SYS_read)
913 syscall_table[SYS_read] = "read";
914#endif
915#if defined (SYS_write)
916 syscall_table[SYS_write] = "write";
917#endif
918#if defined (SYS_open)
919 syscall_table[SYS_open] = "open";
920#endif
921#if defined (SYS_close)
922 syscall_table[SYS_close] = "close";
923#endif
924#if defined (SYS_wait)
925 syscall_table[SYS_wait] = "wait";
926#endif
927#if defined (SYS_creat)
928 syscall_table[SYS_creat] = "creat";
929#endif
930#if defined (SYS_link)
931 syscall_table[SYS_link] = "link";
932#endif
933#if defined (SYS_unlink)
934 syscall_table[SYS_unlink] = "unlink";
935#endif
936#if defined (SYS_exec)
937 syscall_table[SYS_exec] = "exec";
938#endif
939#if defined (SYS_execv)
940 syscall_table[SYS_execv] = "execv";
941#endif
942#if defined (SYS_execve)
943 syscall_table[SYS_execve] = "execve";
944#endif
945#if defined (SYS_chdir)
946 syscall_table[SYS_chdir] = "chdir";
947#endif
948#if defined (SYS_time)
949 syscall_table[SYS_time] = "time";
950#endif
951#if defined (SYS_mknod)
952 syscall_table[SYS_mknod] = "mknod";
953#endif
954#if defined (SYS_chmod)
955 syscall_table[SYS_chmod] = "chmod";
956#endif
957#if defined (SYS_chown)
958 syscall_table[SYS_chown] = "chown";
959#endif
960#if defined (SYS_brk)
961 syscall_table[SYS_brk] = "brk";
962#endif
963#if defined (SYS_stat)
964 syscall_table[SYS_stat] = "stat";
965#endif
966#if defined (SYS_lseek)
967 syscall_table[SYS_lseek] = "lseek";
968#endif
969#if defined (SYS_getpid)
970 syscall_table[SYS_getpid] = "getpid";
971#endif
972#if defined (SYS_mount)
973 syscall_table[SYS_mount] = "mount";
974#endif
975#if defined (SYS_umount)
976 syscall_table[SYS_umount] = "umount";
977#endif
978#if defined (SYS_setuid)
979 syscall_table[SYS_setuid] = "setuid";
980#endif
981#if defined (SYS_getuid)
982 syscall_table[SYS_getuid] = "getuid";
983#endif
984#if defined (SYS_stime)
985 syscall_table[SYS_stime] = "stime";
986#endif
987#if defined (SYS_ptrace)
988 syscall_table[SYS_ptrace] = "ptrace";
989#endif
990#if defined (SYS_alarm)
991 syscall_table[SYS_alarm] = "alarm";
992#endif
993#if defined (SYS_fstat)
994 syscall_table[SYS_fstat] = "fstat";
995#endif
996#if defined (SYS_pause)
997 syscall_table[SYS_pause] = "pause";
998#endif
999#if defined (SYS_utime)
1000 syscall_table[SYS_utime] = "utime";
1001#endif
1002#if defined (SYS_stty)
1003 syscall_table[SYS_stty] = "stty";
1004#endif
1005#if defined (SYS_gtty)
1006 syscall_table[SYS_gtty] = "gtty";
1007#endif
1008#if defined (SYS_access)
1009 syscall_table[SYS_access] = "access";
1010#endif
1011#if defined (SYS_nice)
1012 syscall_table[SYS_nice] = "nice";
1013#endif
1014#if defined (SYS_statfs)
1015 syscall_table[SYS_statfs] = "statfs";
1016#endif
1017#if defined (SYS_sync)
1018 syscall_table[SYS_sync] = "sync";
1019#endif
1020#if defined (SYS_kill)
1021 syscall_table[SYS_kill] = "kill";
1022#endif
1023#if defined (SYS_fstatfs)
1024 syscall_table[SYS_fstatfs] = "fstatfs";
1025#endif
1026#if defined (SYS_pgrpsys)
1027 syscall_table[SYS_pgrpsys] = "pgrpsys";
1028#endif
1029#if defined (SYS_xenix)
1030 syscall_table[SYS_xenix] = "xenix";
1031#endif
1032#if defined (SYS_dup)
1033 syscall_table[SYS_dup] = "dup";
1034#endif
1035#if defined (SYS_pipe)
1036 syscall_table[SYS_pipe] = "pipe";
1037#endif
1038#if defined (SYS_times)
1039 syscall_table[SYS_times] = "times";
1040#endif
1041#if defined (SYS_profil)
1042 syscall_table[SYS_profil] = "profil";
1043#endif
1044#if defined (SYS_plock)
1045 syscall_table[SYS_plock] = "plock";
1046#endif
1047#if defined (SYS_setgid)
1048 syscall_table[SYS_setgid] = "setgid";
1049#endif
1050#if defined (SYS_getgid)
1051 syscall_table[SYS_getgid] = "getgid";
1052#endif
1053#if defined (SYS_signal)
1054 syscall_table[SYS_signal] = "signal";
1055#endif
1056#if defined (SYS_msgsys)
1057 syscall_table[SYS_msgsys] = "msgsys";
1058#endif
1059#if defined (SYS_sys3b)
1060 syscall_table[SYS_sys3b] = "sys3b";
1061#endif
1062#if defined (SYS_acct)
1063 syscall_table[SYS_acct] = "acct";
1064#endif
1065#if defined (SYS_shmsys)
1066 syscall_table[SYS_shmsys] = "shmsys";
1067#endif
1068#if defined (SYS_semsys)
1069 syscall_table[SYS_semsys] = "semsys";
1070#endif
1071#if defined (SYS_ioctl)
1072 syscall_table[SYS_ioctl] = "ioctl";
1073#endif
1074#if defined (SYS_uadmin)
1075 syscall_table[SYS_uadmin] = "uadmin";
1076#endif
1077#if defined (SYS_utssys)
1078 syscall_table[SYS_utssys] = "utssys";
1079#endif
1080#if defined (SYS_fsync)
1081 syscall_table[SYS_fsync] = "fsync";
1082#endif
1083#if defined (SYS_umask)
1084 syscall_table[SYS_umask] = "umask";
1085#endif
1086#if defined (SYS_chroot)
1087 syscall_table[SYS_chroot] = "chroot";
1088#endif
1089#if defined (SYS_fcntl)
1090 syscall_table[SYS_fcntl] = "fcntl";
1091#endif
1092#if defined (SYS_ulimit)
1093 syscall_table[SYS_ulimit] = "ulimit";
1094#endif
1095#if defined (SYS_rfsys)
1096 syscall_table[SYS_rfsys] = "rfsys";
1097#endif
1098#if defined (SYS_rmdir)
1099 syscall_table[SYS_rmdir] = "rmdir";
1100#endif
1101#if defined (SYS_mkdir)
1102 syscall_table[SYS_mkdir] = "mkdir";
1103#endif
1104#if defined (SYS_getdents)
1105 syscall_table[SYS_getdents] = "getdents";
1106#endif
1107#if defined (SYS_sysfs)
1108 syscall_table[SYS_sysfs] = "sysfs";
1109#endif
1110#if defined (SYS_getmsg)
1111 syscall_table[SYS_getmsg] = "getmsg";
1112#endif
1113#if defined (SYS_putmsg)
1114 syscall_table[SYS_putmsg] = "putmsg";
1115#endif
1116#if defined (SYS_poll)
1117 syscall_table[SYS_poll] = "poll";
1118#endif
1119#if defined (SYS_lstat)
1120 syscall_table[SYS_lstat] = "lstat";
1121#endif
1122#if defined (SYS_symlink)
1123 syscall_table[SYS_symlink] = "symlink";
1124#endif
1125#if defined (SYS_readlink)
1126 syscall_table[SYS_readlink] = "readlink";
1127#endif
1128#if defined (SYS_setgroups)
1129 syscall_table[SYS_setgroups] = "setgroups";
1130#endif
1131#if defined (SYS_getgroups)
1132 syscall_table[SYS_getgroups] = "getgroups";
1133#endif
1134#if defined (SYS_fchmod)
1135 syscall_table[SYS_fchmod] = "fchmod";
1136#endif
1137#if defined (SYS_fchown)
1138 syscall_table[SYS_fchown] = "fchown";
1139#endif
1140#if defined (SYS_sigprocmask)
1141 syscall_table[SYS_sigprocmask] = "sigprocmask";
1142#endif
1143#if defined (SYS_sigsuspend)
1144 syscall_table[SYS_sigsuspend] = "sigsuspend";
1145#endif
1146#if defined (SYS_sigaltstack)
1147 syscall_table[SYS_sigaltstack] = "sigaltstack";
1148#endif
1149#if defined (SYS_sigaction)
1150 syscall_table[SYS_sigaction] = "sigaction";
1151#endif
1152#if defined (SYS_sigpending)
1153 syscall_table[SYS_sigpending] = "sigpending";
1154#endif
1155#if defined (SYS_context)
1156 syscall_table[SYS_context] = "context";
1157#endif
1158#if defined (SYS_evsys)
1159 syscall_table[SYS_evsys] = "evsys";
1160#endif
1161#if defined (SYS_evtrapret)
1162 syscall_table[SYS_evtrapret] = "evtrapret";
1163#endif
1164#if defined (SYS_statvfs)
1165 syscall_table[SYS_statvfs] = "statvfs";
1166#endif
1167#if defined (SYS_fstatvfs)
1168 syscall_table[SYS_fstatvfs] = "fstatvfs";
1169#endif
1170#if defined (SYS_nfssys)
1171 syscall_table[SYS_nfssys] = "nfssys";
1172#endif
1173#if defined (SYS_waitsys)
1174 syscall_table[SYS_waitsys] = "waitsys";
1175#endif
1176#if defined (SYS_sigsendsys)
1177 syscall_table[SYS_sigsendsys] = "sigsendsys";
1178#endif
1179#if defined (SYS_hrtsys)
1180 syscall_table[SYS_hrtsys] = "hrtsys";
1181#endif
1182#if defined (SYS_acancel)
1183 syscall_table[SYS_acancel] = "acancel";
1184#endif
1185#if defined (SYS_async)
1186 syscall_table[SYS_async] = "async";
1187#endif
1188#if defined (SYS_priocntlsys)
1189 syscall_table[SYS_priocntlsys] = "priocntlsys";
1190#endif
1191#if defined (SYS_pathconf)
1192 syscall_table[SYS_pathconf] = "pathconf";
1193#endif
1194#if defined (SYS_mincore)
1195 syscall_table[SYS_mincore] = "mincore";
1196#endif
1197#if defined (SYS_mmap)
1198 syscall_table[SYS_mmap] = "mmap";
1199#endif
1200#if defined (SYS_mprotect)
1201 syscall_table[SYS_mprotect] = "mprotect";
1202#endif
1203#if defined (SYS_munmap)
1204 syscall_table[SYS_munmap] = "munmap";
1205#endif
1206#if defined (SYS_fpathconf)
1207 syscall_table[SYS_fpathconf] = "fpathconf";
1208#endif
1209#if defined (SYS_vfork)
1210 syscall_table[SYS_vfork] = "vfork";
1211#endif
1212#if defined (SYS_fchdir)
1213 syscall_table[SYS_fchdir] = "fchdir";
1214#endif
1215#if defined (SYS_readv)
1216 syscall_table[SYS_readv] = "readv";
1217#endif
1218#if defined (SYS_writev)
1219 syscall_table[SYS_writev] = "writev";
1220#endif
1221#if defined (SYS_xstat)
1222 syscall_table[SYS_xstat] = "xstat";
1223#endif
1224#if defined (SYS_lxstat)
1225 syscall_table[SYS_lxstat] = "lxstat";
1226#endif
1227#if defined (SYS_fxstat)
1228 syscall_table[SYS_fxstat] = "fxstat";
1229#endif
1230#if defined (SYS_xmknod)
1231 syscall_table[SYS_xmknod] = "xmknod";
1232#endif
1233#if defined (SYS_clocal)
1234 syscall_table[SYS_clocal] = "clocal";
1235#endif
1236#if defined (SYS_setrlimit)
1237 syscall_table[SYS_setrlimit] = "setrlimit";
1238#endif
1239#if defined (SYS_getrlimit)
1240 syscall_table[SYS_getrlimit] = "getrlimit";
1241#endif
1242#if defined (SYS_lchown)
1243 syscall_table[SYS_lchown] = "lchown";
1244#endif
1245#if defined (SYS_memcntl)
1246 syscall_table[SYS_memcntl] = "memcntl";
1247#endif
1248#if defined (SYS_getpmsg)
1249 syscall_table[SYS_getpmsg] = "getpmsg";
1250#endif
1251#if defined (SYS_putpmsg)
1252 syscall_table[SYS_putpmsg] = "putpmsg";
1253#endif
1254#if defined (SYS_rename)
1255 syscall_table[SYS_rename] = "rename";
1256#endif
1257#if defined (SYS_uname)
1258 syscall_table[SYS_uname] = "uname";
1259#endif
1260#if defined (SYS_setegid)
1261 syscall_table[SYS_setegid] = "setegid";
1262#endif
1263#if defined (SYS_sysconfig)
1264 syscall_table[SYS_sysconfig] = "sysconfig";
1265#endif
1266#if defined (SYS_adjtime)
1267 syscall_table[SYS_adjtime] = "adjtime";
1268#endif
1269#if defined (SYS_systeminfo)
1270 syscall_table[SYS_systeminfo] = "systeminfo";
1271#endif
1272#if defined (SYS_seteuid)
1273 syscall_table[SYS_seteuid] = "seteuid";
1274#endif
de43d7d0
SG
1275#if defined (SYS_sproc)
1276 syscall_table[SYS_sproc] = "sproc";
1277#endif
cc221e76 1278}
35f5886e
FF
1279
1280/*
1281
3fbdd536 1282LOCAL FUNCTION
35f5886e 1283
3fbdd536 1284 procfs_kill_inferior - kill any currently inferior
35f5886e
FF
1285
1286SYNOPSIS
1287
3fbdd536 1288 void procfs_kill_inferior (void)
35f5886e
FF
1289
1290DESCRIPTION
1291
1292 Kill any current inferior.
1293
1294NOTES
1295
1296 Kills even attached inferiors. Presumably the user has already
1297 been prompted that the inferior is an attached one rather than
1298 one started by gdb. (FIXME?)
1299
1300*/
1301
3fbdd536
JG
1302static void
1303procfs_kill_inferior ()
35f5886e 1304{
de43d7d0 1305 target_mourn_inferior ();
35f5886e
FF
1306}
1307
1308/*
1309
1310LOCAL FUNCTION
1311
1312 unconditionally_kill_inferior - terminate the inferior
1313
1314SYNOPSIS
1315
de43d7d0 1316 static void unconditionally_kill_inferior (struct procinfo *)
35f5886e
FF
1317
1318DESCRIPTION
1319
de43d7d0 1320 Kill the specified inferior.
35f5886e
FF
1321
1322NOTE
1323
1324 A possibly useful enhancement would be to first try sending
1325 the inferior a terminate signal, politely asking it to commit
de43d7d0
SG
1326 suicide, before we murder it (we could call that
1327 politely_kill_inferior()).
35f5886e
FF
1328
1329*/
1330
1331static void
de43d7d0
SG
1332unconditionally_kill_inferior (pi)
1333 struct procinfo *pi;
35f5886e
FF
1334{
1335 int signo;
de43d7d0 1336 int ppid;
35f5886e 1337
de43d7d0
SG
1338 ppid = pi->prstatus.pr_ppid;
1339
35f5886e 1340 signo = SIGKILL;
2592eef8 1341
b6753b3f
PS
1342#ifdef PROCFS_NEED_CLEAR_CURSIG_FOR_KILL
1343 /* Alpha OSF/1-3.x procfs needs a clear of the current signal
1344 before the PIOCKILL, otherwise it might generate a corrupted core
1345 file for the inferior. */
1346 ioctl (pi->fd, PIOCSSIG, NULL);
1347#endif
2592eef8 1348#ifdef PROCFS_NEED_PIOCSSIG_FOR_KILL
b6753b3f 1349 /* Alpha OSF/1-2.x procfs needs a PIOCSSIG call with a SIGKILL signal
f5de4904
PS
1350 to kill the inferior, otherwise it might remain stopped with a
1351 pending SIGKILL.
2592eef8
PS
1352 We do not check the result of the PIOCSSIG, the inferior might have
1353 died already. */
1354 {
1355 struct siginfo newsiginfo;
1356
1357 memset ((char *) &newsiginfo, 0, sizeof (newsiginfo));
1358 newsiginfo.si_signo = signo;
1359 newsiginfo.si_code = 0;
1360 newsiginfo.si_errno = 0;
1361 newsiginfo.si_pid = getpid ();
1362 newsiginfo.si_uid = getuid ();
1363 ioctl (pi->fd, PIOCSSIG, &newsiginfo);
1364 }
f5de4904
PS
1365#else
1366 ioctl (pi->fd, PIOCKILL, &signo);
2592eef8
PS
1367#endif
1368
de43d7d0
SG
1369 close_proc_file (pi);
1370
1371/* Only wait() for our direct children. Our grandchildren zombies are killed
1372 by the death of their parents. */
1373
1374 if (ppid == getpid())
1375 wait ((int *) 0);
35f5886e
FF
1376}
1377
1378/*
1379
3fbdd536 1380LOCAL FUNCTION
35f5886e 1381
3fbdd536 1382 procfs_xfer_memory -- copy data to or from inferior memory space
35f5886e
FF
1383
1384SYNOPSIS
1385
3fbdd536 1386 int procfs_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len,
35f5886e
FF
1387 int dowrite, struct target_ops target)
1388
1389DESCRIPTION
1390
1391 Copy LEN bytes to/from inferior's memory starting at MEMADDR
1392 from/to debugger memory starting at MYADDR. Copy from inferior
1393 if DOWRITE is zero or to inferior if DOWRITE is nonzero.
1394
1395 Returns the length copied, which is either the LEN argument or
3fbdd536 1396 zero. This xfer function does not do partial moves, since procfs_ops
35f5886e
FF
1397 doesn't allow memory operations to cross below us in the target stack
1398 anyway.
1399
1400NOTES
1401
1402 The /proc interface makes this an almost trivial task.
1403 */
1404
3fbdd536
JG
1405static int
1406procfs_xfer_memory (memaddr, myaddr, len, dowrite, target)
1ab3bf1b
JG
1407 CORE_ADDR memaddr;
1408 char *myaddr;
1409 int len;
1410 int dowrite;
1411 struct target_ops *target; /* ignored */
35f5886e
FF
1412{
1413 int nbytes = 0;
de43d7d0 1414 struct procinfo *pi;
35f5886e 1415
de43d7d0
SG
1416 pi = current_procinfo;
1417
1418 if (lseek(pi->fd, (off_t) memaddr, 0) == (off_t) memaddr)
35f5886e
FF
1419 {
1420 if (dowrite)
1421 {
de43d7d0 1422 nbytes = write (pi->fd, myaddr, len);
35f5886e
FF
1423 }
1424 else
1425 {
de43d7d0 1426 nbytes = read (pi->fd, myaddr, len);
35f5886e
FF
1427 }
1428 if (nbytes < 0)
1429 {
1430 nbytes = 0;
1431 }
1432 }
1433 return (nbytes);
1434}
1435
1436/*
1437
3fbdd536 1438LOCAL FUNCTION
35f5886e 1439
3fbdd536 1440 procfs_store_registers -- copy register values back to inferior
35f5886e
FF
1441
1442SYNOPSIS
1443
3fbdd536 1444 void procfs_store_registers (int regno)
35f5886e
FF
1445
1446DESCRIPTION
1447
1448 Store our current register values back into the inferior. If
1449 REGNO is -1 then store all the register, otherwise store just
1450 the value specified by REGNO.
1451
1452NOTES
1453
1454 If we are storing only a single register, we first have to get all
1455 the current values from the process, overwrite the desired register
1456 in the gregset with the one we want from gdb's registers, and then
1457 send the whole set back to the process. For writing all the
1458 registers, all we have to do is generate the gregset and send it to
1459 the process.
1460
1461 Also note that the process has to be stopped on an event of interest
1462 for this to work, which basically means that it has to have been
1463 run under the control of one of the other /proc ioctl calls and not
1464 ptrace. Since we don't use ptrace anyway, we don't worry about this
1465 fine point, but it is worth noting for future reference.
1466
1467 Gdb is confused about what this function is supposed to return.
1468 Some versions return a value, others return nothing. Some are
1469 declared to return a value and actually return nothing. Gdb ignores
1470 anything returned. (FIXME)
1471
1472 */
1473
3fbdd536
JG
1474static void
1475procfs_store_registers (regno)
1ab3bf1b 1476 int regno;
35f5886e 1477{
de43d7d0
SG
1478 struct procinfo *pi;
1479
1480 pi = current_procinfo;
1481
35f5886e
FF
1482 if (regno != -1)
1483 {
de43d7d0 1484 ioctl (pi->fd, PIOCGREG, &pi->gregset);
35f5886e 1485 }
de43d7d0
SG
1486 fill_gregset (&pi->gregset, regno);
1487 ioctl (pi->fd, PIOCSREG, &pi->gregset);
35f5886e
FF
1488
1489#if defined (FP0_REGNUM)
1490
1491 /* Now repeat everything using the floating point register set, if the
1492 target has floating point hardware. Since we ignore the returned value,
1493 we'll never know whether it worked or not anyway. */
1494
1495 if (regno != -1)
1496 {
de43d7d0 1497 ioctl (pi->fd, PIOCGFPREG, &pi->fpregset);
35f5886e 1498 }
de43d7d0
SG
1499 fill_fpregset (&pi->fpregset, regno);
1500 ioctl (pi->fd, PIOCSFPREG, &pi->fpregset);
35f5886e
FF
1501
1502#endif /* FP0_REGNUM */
1503
1504}
1505
1506/*
1507
3fbdd536 1508LOCAL FUNCTION
35f5886e 1509
de43d7d0
SG
1510 create_procinfo - initialize access to a /proc entry
1511
1512SYNOPSIS
1513
eca4a350 1514 struct procinfo * create_procinfo (int pid)
de43d7d0
SG
1515
1516DESCRIPTION
1517
eca4a350
SG
1518 Allocate a procinfo structure, open the /proc file and then set up the
1519 set of signals and faults that are to be traced. Returns a pointer to
1520 the new procinfo structure.
de43d7d0
SG
1521
1522NOTES
1523
1524 If proc_init_failed ever gets called, control returns to the command
1525 processing loop via the standard error handling code.
1526
1527 */
1528
eca4a350 1529static struct procinfo *
de43d7d0
SG
1530create_procinfo (pid)
1531 int pid;
1532{
1533 struct procinfo *pi;
1534
2592eef8
PS
1535 pi = find_procinfo (pid, 1);
1536 if (pi != NULL)
1537 return pi; /* All done! It already exists */
de43d7d0
SG
1538
1539 pi = (struct procinfo *) xmalloc (sizeof (struct procinfo));
1540
1541 if (!open_proc_file (pid, pi, O_RDWR))
1542 proc_init_failed (pi, "can't open process file");
1543
8fc2b417
SG
1544 /* open_proc_file may modify pid. */
1545
1546 pid = pi -> pid;
1547
de43d7d0
SG
1548 /* Add new process to process info list */
1549
1550 pi->next = procinfo_list;
1551 procinfo_list = pi;
1552
1553 add_fd (pi); /* Add to list for poll/select */
1554
8fc2b417
SG
1555 pi->num_syscall_handlers = 0;
1556 pi->syscall_handlers = NULL;
de43d7d0
SG
1557 memset ((char *) &pi->prrun, 0, sizeof (pi->prrun));
1558 prfillset (&pi->prrun.pr_trace);
1559 procfs_notice_signals (pid);
1560 prfillset (&pi->prrun.pr_fault);
1561 prdelset (&pi->prrun.pr_fault, FLTPAGE);
1562
b9e58503
PS
1563#ifdef PROCFS_DONT_TRACE_FAULTS
1564 premptyset (&pi->prrun.pr_fault);
2592eef8
PS
1565#endif
1566
8fc2b417
SG
1567 if (ioctl (pi->fd, PIOCSTATUS, &pi->prstatus) < 0)
1568 proc_init_failed (pi, "PIOCSTATUS failed");
1569
1570/* A bug in Solaris (2.5 at least) causes PIOCWSTOP to hang on LWPs that are
1571 already stopped, even if they all have PR_ASYNC set. */
1572
1573 if (!(pi->prstatus.pr_flags & PR_STOPPED))
1574 if (ioctl (pi->fd, PIOCWSTOP, &pi->prstatus) < 0)
1575 proc_init_failed (pi, "PIOCWSTOP failed");
de43d7d0
SG
1576
1577 if (ioctl (pi->fd, PIOCSFAULT, &pi->prrun.pr_fault) < 0)
1578 proc_init_failed (pi, "PIOCSFAULT failed");
eca4a350
SG
1579
1580 return pi;
de43d7d0
SG
1581}
1582
1583/*
1584
8fc2b417
SG
1585LOCAL FUNCTION
1586
1587 procfs_exit_handler - handle entry into the _exit syscall
1588
1589SYNOPSIS
1590
1591 int procfs_exit_handler (pi, syscall_num, why, rtnvalp, statvalp)
1592
1593DESCRIPTION
1594
1595 This routine is called when an inferior process enters the _exit()
1596 system call. It continues the process, and then collects the exit
1597 status and pid which are returned in *statvalp and *rtnvalp. After
1598 that it returns non-zero to indicate that procfs_wait should wake up.
1599
1600NOTES
1601 There is probably a better way to do this.
1602
1603 */
1604
1605static int
1606procfs_exit_handler (pi, syscall_num, why, rtnvalp, statvalp)
1607 struct procinfo *pi;
1608 int syscall_num;
1609 int why;
1610 int *rtnvalp;
1611 int *statvalp;
1612{
1613 pi->prrun.pr_flags = PRCFAULT;
1614
1615 if (ioctl (pi->fd, PIOCRUN, &pi->prrun) != 0)
1616 perror_with_name (pi->pathname);
1617
1618 *rtnvalp = wait (statvalp);
1619 if (*rtnvalp >= 0)
1620 *rtnvalp = pi->pid;
1621
1622 return 1;
1623}
1624
1625/*
1626
1627LOCAL FUNCTION
1628
1629 procfs_exec_handler - handle exit from the exec family of syscalls
1630
1631SYNOPSIS
1632
1633 int procfs_exec_handler (pi, syscall_num, why, rtnvalp, statvalp)
1634
1635DESCRIPTION
1636
1637 This routine is called when an inferior process is about to finish any
1638 of the exec() family of system calls. It pretends that we got a
1639 SIGTRAP (for compatibility with ptrace behavior), and returns non-zero
1640 to tell procfs_wait to wake up.
1641
1642NOTES
1643 This need for compatibility with ptrace is questionable. In the
1644 future, it shouldn't be necessary.
1645
1646 */
1647
1648static int
1649procfs_exec_handler (pi, syscall_num, why, rtnvalp, statvalp)
1650 struct procinfo *pi;
1651 int syscall_num;
1652 int why;
1653 int *rtnvalp;
1654 int *statvalp;
1655{
1656 *statvalp = (SIGTRAP << 8) | 0177;
1657
1658 return 1;
1659}
1660
1661#ifdef SYS_sproc /* IRIX lwp creation system call */
1662
1663/*
1664
1665LOCAL FUNCTION
1666
1667 procfs_sproc_handler - handle exit from the sproc syscall
1668
1669SYNOPSIS
1670
1671 int procfs_sproc_handler (pi, syscall_num, why, rtnvalp, statvalp)
1672
1673DESCRIPTION
1674
1675 This routine is called when an inferior process is about to finish an
1676 sproc() system call. This is the system call that IRIX uses to create
1677 a lightweight process. When the target process gets this event, we can
1678 look at rval1 to find the new child processes ID, and create a new
1679 procinfo struct from that.
1680
1681 After that, it pretends that we got a SIGTRAP, and returns non-zero
1682 to tell procfs_wait to wake up. Subsequently, wait_for_inferior gets
1683 woken up, sees the new process and continues it.
1684
1685NOTES
1686 We actually never see the child exiting from sproc because we will
1687 shortly stop the child with PIOCSTOP, which is then registered as the
1688 event of interest.
1689 */
1690
1691static int
1692procfs_sproc_handler (pi, syscall_num, why, rtnvalp, statvalp)
1693 struct procinfo *pi;
1694 int syscall_num;
1695 int why;
1696 int *rtnvalp;
1697 int *statvalp;
1698{
1699/* We've just detected the completion of an sproc system call. Now we need to
1700 setup a procinfo struct for this thread, and notify the thread system of the
1701 new arrival. */
1702
1703/* If sproc failed, then nothing interesting happened. Continue the process
1704 and go back to sleep. */
1705
1706 if (pi->prstatus.pr_errno != 0)
1707 {
1708 pi->prrun.pr_flags &= PRSTEP;
1709 pi->prrun.pr_flags |= PRCFAULT;
1710
1711 if (ioctl (pi->fd, PIOCRUN, &pi->prrun) != 0)
1712 perror_with_name (pi->pathname);
1713
1714 return 0;
1715 }
1716
1717 /* At this point, the new thread is stopped at it's first instruction, and
1718 the parent is stopped at the exit from sproc. */
1719
1720 /* Notify the caller of the arrival of a new thread. */
1721 create_procinfo (pi->prstatus.pr_rval1);
1722
1723 *rtnvalp = pi->prstatus.pr_rval1;
1724 *statvalp = (SIGTRAP << 8) | 0177;
1725
1726 return 1;
1727}
1728
1729/*
1730
1731LOCAL FUNCTION
1732
1733 procfs_fork_handler - handle exit from the fork syscall
1734
1735SYNOPSIS
1736
1737 int procfs_fork_handler (pi, syscall_num, why, rtnvalp, statvalp)
1738
1739DESCRIPTION
1740
1741 This routine is called when an inferior process is about to finish a
1742 fork() system call. We will open up the new process, and then close
1743 it, which releases it from the clutches of the debugger.
1744
1745 After that, we continue the target process as though nothing had
1746 happened.
1747
1748NOTES
1749 This is necessary for IRIX because we have to set PR_FORK in order
1750 to catch the creation of lwps (via sproc()). When an actual fork
1751 occurs, it becomes necessary to reset the forks debugger flags and
1752 continue it because we can't hack multiple processes yet.
1753 */
1754
1755static int
1756procfs_fork_handler (pi, syscall_num, why, rtnvalp, statvalp)
1757 struct procinfo *pi;
1758 int syscall_num;
1759 int why;
1760 int *rtnvalp;
1761 int *statvalp;
1762{
1763 struct procinfo *pitemp;
1764
1765/* At this point, we've detected the completion of a fork (or vfork) call in
1766 our child. The grandchild is also stopped because we set inherit-on-fork
1767 earlier. (Note that nobody has the grandchilds' /proc file open at this
1768 point.) We will release the grandchild from the debugger by opening it's
1769 /proc file and then closing it. Since run-on-last-close is set, the
1770 grandchild continues on its' merry way. */
1771
1772
1773 pitemp = create_procinfo (pi->prstatus.pr_rval1);
1774 if (pitemp)
1775 close_proc_file (pitemp);
1776
1777 if (ioctl (pi->fd, PIOCRUN, &pi->prrun) != 0)
1778 perror_with_name (pi->pathname);
1779
1780 return 0;
1781}
1782#endif /* SYS_sproc */
1783
1784/*
1785
de43d7d0
SG
1786LOCAL FUNCTION
1787
1788 procfs_init_inferior - initialize target vector and access to a
1789 /proc entry
35f5886e
FF
1790
1791SYNOPSIS
1792
8fc2b417 1793 int procfs_init_inferior (int pid)
35f5886e
FF
1794
1795DESCRIPTION
1796
1797 When gdb starts an inferior, this function is called in the parent
1798 process immediately after the fork. It waits for the child to stop
1799 on the return from the exec system call (the child itself takes care
1800 of ensuring that this is set up), then sets up the set of signals
8fc2b417
SG
1801 and faults that are to be traced. Returns the pid, which may have had
1802 the thread-id added to it.
35f5886e
FF
1803
1804NOTES
1805
1806 If proc_init_failed ever gets called, control returns to the command
1807 processing loop via the standard error handling code.
cc221e76 1808
35f5886e
FF
1809 */
1810
8fc2b417 1811static int
3fbdd536 1812procfs_init_inferior (pid)
1ab3bf1b 1813 int pid;
35f5886e 1814{
8fc2b417
SG
1815 struct procinfo *pip;
1816
3fbdd536
JG
1817 push_target (&procfs_ops);
1818
8fc2b417
SG
1819 pip = create_procinfo (pid);
1820
1821 procfs_set_syscall_trap (pip, SYS_exit, PROCFS_SYSCALL_ENTRY,
1822 procfs_exit_handler);
1823
1824#ifndef PRFS_STOPEXEC
1825#ifdef SYS_exec
1826 procfs_set_syscall_trap (pip, SYS_exec, PROCFS_SYSCALL_EXIT,
1827 procfs_exec_handler);
1828#endif
1829#ifdef SYS_execv
1830 procfs_set_syscall_trap (pip, SYS_execv, PROCFS_SYSCALL_EXIT,
1831 procfs_exec_handler);
1832#endif
1833#ifdef SYS_execve
1834 procfs_set_syscall_trap (pip, SYS_execve, PROCFS_SYSCALL_EXIT,
1835 procfs_exec_handler);
1836#endif
1837#endif /* PRFS_STOPEXEC */
1838
1839 /* Setup traps on exit from sproc() */
1840
1841#ifdef SYS_sproc
1842 procfs_set_syscall_trap (pip, SYS_sproc, PROCFS_SYSCALL_EXIT,
1843 procfs_sproc_handler);
1844 procfs_set_syscall_trap (pip, SYS_fork, PROCFS_SYSCALL_EXIT,
1845 procfs_fork_handler);
1846#ifdef SYS_vfork
1847 procfs_set_syscall_trap (pip, SYS_vfork, PROCFS_SYSCALL_EXIT,
1848 procfs_fork_handler);
1849#endif
1850/* Turn on inherit-on-fork flag so that all children of the target process
1851 start with tracing flags set. This allows us to trap lwp creation. Note
1852 that we also have to trap on fork and vfork in order to disable all tracing
1853 in the targets child processes. */
1854
1855 modify_inherit_on_fork_flag (pip->fd, 1);
1856#endif
1857
1858#ifdef SYS_lwp_create
1859 procfs_set_syscall_trap (pip, SYS_lwp_create, PROCFS_SYSCALL_EXIT,
1860 procfs_lwp_creation_handler);
1861#endif
1862
1863 /* create_procinfo may change the pid, so we have to update inferior_pid
1864 here before calling other gdb routines that need the right pid. */
1865
1866 pid = pip -> pid;
1867 inferior_pid = pid;
1868
1869 add_thread (pip -> pid); /* Setup initial thread */
bc28a06c 1870
2592eef8
PS
1871#ifdef START_INFERIOR_TRAPS_EXPECTED
1872 startup_inferior (START_INFERIOR_TRAPS_EXPECTED);
1873#else
bc28a06c
JK
1874 /* One trap to exec the shell, one to exec the program being debugged. */
1875 startup_inferior (2);
2592eef8 1876#endif
8fc2b417
SG
1877
1878 return pid;
35f5886e
FF
1879}
1880
1881/*
1882
cc221e76
FF
1883GLOBAL FUNCTION
1884
3950a34e 1885 procfs_notice_signals
cc221e76
FF
1886
1887SYNOPSIS
1888
952a820e 1889 static void procfs_notice_signals (int pid);
cc221e76
FF
1890
1891DESCRIPTION
1892
1893 When the user changes the state of gdb's signal handling via the
1894 "handle" command, this function gets called to see if any change
1895 in the /proc interface is required. It is also called internally
1896 by other /proc interface functions to initialize the state of
1897 the traced signal set.
1898
1899 One thing it does is that signals for which the state is "nostop",
1900 "noprint", and "pass", have their trace bits reset in the pr_trace
1901 field, so that they are no longer traced. This allows them to be
1902 delivered directly to the inferior without the debugger ever being
1903 involved.
1904 */
1905
3950a34e 1906static void
de43d7d0 1907procfs_notice_signals (pid)
952a820e 1908 int pid;
cc221e76
FF
1909{
1910 int signo;
de43d7d0 1911 struct procinfo *pi;
cc221e76 1912
de43d7d0
SG
1913 pi = find_procinfo (pid, 0);
1914
1915 for (signo = 0; signo < NSIG; signo++)
cc221e76 1916 {
67ac9759
JK
1917 if (signal_stop_state (target_signal_from_host (signo)) == 0 &&
1918 signal_print_state (target_signal_from_host (signo)) == 0 &&
1919 signal_pass_state (target_signal_from_host (signo)) == 1)
cc221e76 1920 {
de43d7d0 1921 prdelset (&pi->prrun.pr_trace, signo);
cc221e76 1922 }
de43d7d0 1923 else
cc221e76 1924 {
de43d7d0 1925 praddset (&pi->prrun.pr_trace, signo);
cc221e76
FF
1926 }
1927 }
de43d7d0
SG
1928 if (ioctl (pi->fd, PIOCSTRACE, &pi->prrun.pr_trace))
1929 {
1930 print_sys_errmsg ("PIOCSTRACE failed", errno);
1931 }
cc221e76
FF
1932}
1933
1934/*
1935
3fbdd536 1936LOCAL FUNCTION
35f5886e
FF
1937
1938 proc_set_exec_trap -- arrange for exec'd child to halt at startup
1939
1940SYNOPSIS
1941
1942 void proc_set_exec_trap (void)
1943
1944DESCRIPTION
1945
1946 This function is called in the child process when starting up
1947 an inferior, prior to doing the exec of the actual inferior.
1948 It sets the child process's exitset to make exit from the exec
1949 system call an event of interest to stop on, and then simply
1950 returns. The child does the exec, the system call returns, and
1951 the child stops at the first instruction, ready for the gdb
1952 parent process to take control of it.
1953
1954NOTE
1955
1956 We need to use all local variables since the child may be sharing
1957 it's data space with the parent, if vfork was used rather than
1958 fork.
cc221e76
FF
1959
1960 Also note that we want to turn off the inherit-on-fork flag in
1961 the child process so that any grand-children start with all
1962 tracing flags cleared.
35f5886e
FF
1963 */
1964
3fbdd536 1965static void
1ab3bf1b 1966proc_set_exec_trap ()
35f5886e
FF
1967{
1968 sysset_t exitset;
fb63d460 1969 sysset_t entryset;
35f5886e
FF
1970 auto char procname[32];
1971 int fd;
1972
4ed3a9ea 1973 sprintf (procname, PROC_NAME_FMT, getpid ());
35f5886e
FF
1974 if ((fd = open (procname, O_RDWR)) < 0)
1975 {
1976 perror (procname);
199b2450 1977 gdb_flush (gdb_stderr);
35f5886e
FF
1978 _exit (127);
1979 }
1980 premptyset (&exitset);
fb63d460 1981 premptyset (&entryset);
407a8389 1982
2592eef8
PS
1983#ifdef PIOCSSPCACT
1984 /* Under Alpha OSF/1 we have to use a PIOCSSPCACT ioctl to trace
1985 exits from exec system calls because of the user level loader. */
1986 {
1987 int prfs_flags;
1988
1989 if (ioctl (fd, PIOCGSPCACT, &prfs_flags) < 0)
1990 {
1991 perror (procname);
1992 gdb_flush (gdb_stderr);
1993 _exit (127);
1994 }
1995 prfs_flags |= PRFS_STOPEXEC;
1996 if (ioctl (fd, PIOCSSPCACT, &prfs_flags) < 0)
1997 {
1998 perror (procname);
1999 gdb_flush (gdb_stderr);
2000 _exit (127);
2001 }
2002 }
2003#else
cc221e76
FF
2004 /* GW: Rationale...
2005 Not all systems with /proc have all the exec* syscalls with the same
2006 names. On the SGI, for example, there is no SYS_exec, but there
2007 *is* a SYS_execv. So, we try to account for that. */
2008
407a8389 2009#ifdef SYS_exec
35f5886e 2010 praddset (&exitset, SYS_exec);
407a8389
SG
2011#endif
2012#ifdef SYS_execve
35f5886e 2013 praddset (&exitset, SYS_execve);
407a8389
SG
2014#endif
2015#ifdef SYS_execv
fb63d460 2016 praddset (&exitset, SYS_execv);
407a8389
SG
2017#endif
2018
35f5886e
FF
2019 if (ioctl (fd, PIOCSEXIT, &exitset) < 0)
2020 {
2021 perror (procname);
199b2450 2022 gdb_flush (gdb_stderr);
35f5886e
FF
2023 _exit (127);
2024 }
2592eef8 2025#endif
cc221e76 2026
fb63d460
SG
2027 praddset (&entryset, SYS_exit);
2028
2029 if (ioctl (fd, PIOCSENTRY, &entryset) < 0)
2030 {
2031 perror (procname);
199b2450 2032 gdb_flush (gdb_stderr);
fb63d460
SG
2033 _exit (126);
2034 }
2035
cc221e76
FF
2036 /* Turn off inherit-on-fork flag so that all grand-children of gdb
2037 start with tracing flags cleared. */
2038
8fc2b417 2039 modify_inherit_on_fork_flag (fd, 0);
ec8ceca3
JG
2040
2041 /* Turn on run-on-last-close flag so that this process will not hang
2042 if GDB goes away for some reason. */
2043
8fc2b417
SG
2044 modify_run_on_last_close_flag (fd, 1);
2045
2046#ifdef PR_ASYNC
ec8ceca3 2047 {
8fc2b417
SG
2048 long pr_flags;
2049
2050/* Solaris needs this to make procfs treat all threads seperately. Without
2051 this, all threads halt whenever something happens to any thread. Since
2052 GDB wants to control all this itself, it needs to set PR_ASYNC. */
2053
2054 pr_flags = PR_ASYNC;
2055
2056 ioctl (fd, PIOCSET, &pr_flags);
ec8ceca3 2057 }
8fc2b417 2058#endif /* PR_ASYNC */
35f5886e
FF
2059}
2060
f8b76e70
FF
2061/*
2062
a39ad5ce
FF
2063GLOBAL FUNCTION
2064
2065 proc_iterate_over_mappings -- call function for every mapped space
2066
2067SYNOPSIS
2068
2069 int proc_iterate_over_mappings (int (*func)())
2070
2071DESCRIPTION
2072
2073 Given a pointer to a function, call that function for every
2074 mapped address space, passing it an open file descriptor for
2075 the file corresponding to that mapped address space (if any)
2076 and the base address of the mapped space. Quit when we hit
2077 the end of the mappings or the function returns nonzero.
2078 */
2079
2080int
1ab3bf1b
JG
2081proc_iterate_over_mappings (func)
2082 int (*func) PARAMS ((int, CORE_ADDR));
a39ad5ce
FF
2083{
2084 int nmap;
2085 int fd;
2086 int funcstat = 0;
2087 struct prmap *prmaps;
2088 struct prmap *prmap;
de43d7d0
SG
2089 struct procinfo *pi;
2090
2091 pi = current_procinfo;
a39ad5ce 2092
de43d7d0 2093 if (ioctl (pi->fd, PIOCNMAP, &nmap) == 0)
a39ad5ce 2094 {
1ab3bf1b 2095 prmaps = (struct prmap *) alloca ((nmap + 1) * sizeof (*prmaps));
de43d7d0 2096 if (ioctl (pi->fd, PIOCMAP, prmaps) == 0)
a39ad5ce
FF
2097 {
2098 for (prmap = prmaps; prmap -> pr_size && funcstat == 0; ++prmap)
2099 {
de43d7d0 2100 fd = proc_address_to_fd (pi, (CORE_ADDR) prmap -> pr_vaddr, 0);
1ab3bf1b 2101 funcstat = (*func) (fd, (CORE_ADDR) prmap -> pr_vaddr);
a39ad5ce
FF
2102 close (fd);
2103 }
2104 }
2105 }
2106 return (funcstat);
2107}
2108
3fbdd536 2109#if 0 /* Currently unused */
a39ad5ce
FF
2110/*
2111
f8b76e70
FF
2112GLOBAL FUNCTION
2113
2114 proc_base_address -- find base address for segment containing address
2115
2116SYNOPSIS
2117
2118 CORE_ADDR proc_base_address (CORE_ADDR addr)
2119
2120DESCRIPTION
2121
2122 Given an address of a location in the inferior, find and return
2123 the base address of the mapped segment containing that address.
2124
2125 This is used for example, by the shared library support code,
2126 where we have the pc value for some location in the shared library
2127 where we are stopped, and need to know the base address of the
2128 segment containing that address.
2129*/
2130
f8b76e70 2131CORE_ADDR
1ab3bf1b 2132proc_base_address (addr)
cc221e76 2133 CORE_ADDR addr;
f8b76e70
FF
2134{
2135 int nmap;
2136 struct prmap *prmaps;
2137 struct prmap *prmap;
2138 CORE_ADDR baseaddr = 0;
de43d7d0 2139 struct procinfo *pi;
f8b76e70 2140
de43d7d0
SG
2141 pi = current_procinfo;
2142
2143 if (ioctl (pi->fd, PIOCNMAP, &nmap) == 0)
f8b76e70 2144 {
1ab3bf1b 2145 prmaps = (struct prmap *) alloca ((nmap + 1) * sizeof (*prmaps));
de43d7d0 2146 if (ioctl (pi->fd, PIOCMAP, prmaps) == 0)
f8b76e70
FF
2147 {
2148 for (prmap = prmaps; prmap -> pr_size; ++prmap)
2149 {
2150 if ((prmap -> pr_vaddr <= (caddr_t) addr) &&
2151 (prmap -> pr_vaddr + prmap -> pr_size > (caddr_t) addr))
2152 {
2153 baseaddr = (CORE_ADDR) prmap -> pr_vaddr;
2154 break;
2155 }
2156 }
2157 }
2158 }
2159 return (baseaddr);
2160}
2161
1ab3bf1b
JG
2162#endif /* 0 */
2163
f8b76e70
FF
2164/*
2165
cc221e76 2166LOCAL FUNCTION
f8b76e70
FF
2167
2168 proc_address_to_fd -- return open fd for file mapped to address
2169
2170SYNOPSIS
2171
de43d7d0 2172 int proc_address_to_fd (struct procinfo *pi, CORE_ADDR addr, complain)
f8b76e70
FF
2173
2174DESCRIPTION
2175
2176 Given an address in the current inferior's address space, use the
2177 /proc interface to find an open file descriptor for the file that
2178 this address was mapped in from. Return -1 if there is no current
2179 inferior. Print a warning message if there is an inferior but
2180 the address corresponds to no file (IE a bogus address).
2181
2182*/
2183
1ab3bf1b 2184static int
de43d7d0
SG
2185proc_address_to_fd (pi, addr, complain)
2186 struct procinfo *pi;
1ab3bf1b
JG
2187 CORE_ADDR addr;
2188 int complain;
f8b76e70
FF
2189{
2190 int fd = -1;
2191
de43d7d0 2192 if ((fd = ioctl (pi->fd, PIOCOPENM, (caddr_t *) &addr)) < 0)
f8b76e70 2193 {
de43d7d0 2194 if (complain)
f8b76e70 2195 {
de43d7d0
SG
2196 print_sys_errmsg (pi->pathname, errno);
2197 warning ("can't find mapped file for address 0x%x", addr);
f8b76e70
FF
2198 }
2199 }
2200 return (fd);
2201}
2202
35f5886e 2203
3fbdd536
JG
2204/* Attach to process PID, then initialize for debugging it
2205 and wait for the trace-trap that results from attaching. */
2206
2207static void
2208procfs_attach (args, from_tty)
2209 char *args;
2210 int from_tty;
2211{
2212 char *exec_file;
2213 int pid;
2214
2215 if (!args)
2216 error_no_arg ("process-id to attach");
2217
2218 pid = atoi (args);
2219
2220 if (pid == getpid()) /* Trying to masturbate? */
2221 error ("I refuse to debug myself!");
2222
2223 if (from_tty)
2224 {
2225 exec_file = (char *) get_exec_file (0);
2226
2227 if (exec_file)
199b2450 2228 printf_unfiltered ("Attaching to program `%s', %s\n", exec_file, target_pid_to_str (pid));
3fbdd536 2229 else
199b2450 2230 printf_unfiltered ("Attaching to %s\n", target_pid_to_str (pid));
3fbdd536 2231
199b2450 2232 gdb_flush (gdb_stdout);
3fbdd536
JG
2233 }
2234
8fc2b417 2235 inferior_pid = pid = do_attach (pid);
3fbdd536
JG
2236 push_target (&procfs_ops);
2237}
2238
2239
2240/* Take a program previously attached to and detaches it.
2241 The program resumes execution and will no longer stop
2242 on signals, etc. We'd better not have left any breakpoints
2243 in the program or it'll die when it hits one. For this
2244 to work, it may be necessary for the process to have been
2245 previously attached. It *might* work if the program was
2246 started via the normal ptrace (PTRACE_TRACEME). */
2247
2248static void
2249procfs_detach (args, from_tty)
2250 char *args;
2251 int from_tty;
2252{
2253 int siggnal = 0;
2254
2255 if (from_tty)
2256 {
2257 char *exec_file = get_exec_file (0);
2258 if (exec_file == 0)
2259 exec_file = "";
199b2450 2260 printf_unfiltered ("Detaching from program: %s %s\n",
25286543 2261 exec_file, target_pid_to_str (inferior_pid));
199b2450 2262 gdb_flush (gdb_stdout);
3fbdd536
JG
2263 }
2264 if (args)
2265 siggnal = atoi (args);
2266
2267 do_detach (siggnal);
2268 inferior_pid = 0;
2269 unpush_target (&procfs_ops); /* Pop out of handling an inferior */
2270}
2271
2272/* Get ready to modify the registers array. On machines which store
2273 individual registers, this doesn't need to do anything. On machines
2274 which store all the registers in one fell swoop, this makes sure
2275 that registers contains all the registers from the program being
2276 debugged. */
2277
2278static void
2279procfs_prepare_to_store ()
2280{
2281#ifdef CHILD_PREPARE_TO_STORE
2282 CHILD_PREPARE_TO_STORE ();
2283#endif
2284}
2285
2286/* Print status information about what we're accessing. */
2287
2288static void
2289procfs_files_info (ignore)
2290 struct target_ops *ignore;
2291{
199b2450 2292 printf_unfiltered ("\tUsing the running image of %s %s via /proc.\n",
25286543 2293 attach_flag? "attached": "child", target_pid_to_str (inferior_pid));
3fbdd536
JG
2294}
2295
2296/* ARGSUSED */
2297static void
2298procfs_open (arg, from_tty)
2299 char *arg;
2300 int from_tty;
2301{
2302 error ("Use the \"run\" command to start a Unix child process.");
2303}
35f5886e
FF
2304
2305/*
2306
3fbdd536 2307LOCAL FUNCTION
35f5886e 2308
3fbdd536 2309 do_attach -- attach to an already existing process
35f5886e
FF
2310
2311SYNOPSIS
2312
3fbdd536 2313 int do_attach (int pid)
35f5886e
FF
2314
2315DESCRIPTION
2316
2317 Attach to an already existing process with the specified process
2318 id. If the process is not already stopped, query whether to
2319 stop it or not.
2320
2321NOTES
2322
2323 The option of stopping at attach time is specific to the /proc
2324 versions of gdb. Versions using ptrace force the attachee
ec8ceca3
JG
2325 to stop. (I have changed this version to do so, too. All you
2326 have to do is "continue" to make it go on. -- gnu@cygnus.com)
35f5886e
FF
2327
2328*/
2329
3fbdd536
JG
2330static int
2331do_attach (pid)
1ab3bf1b 2332 int pid;
35f5886e 2333{
de43d7d0
SG
2334 struct procinfo *pi;
2335
2336 pi = (struct procinfo *) xmalloc (sizeof (struct procinfo));
ec8ceca3 2337
de43d7d0 2338 if (!open_proc_file (pid, pi, O_RDWR))
35f5886e 2339 {
de43d7d0
SG
2340 free (pi);
2341 perror_with_name (pi->pathname);
35f5886e
FF
2342 /* NOTREACHED */
2343 }
2344
8fc2b417
SG
2345 pid = pi -> pid;
2346
de43d7d0
SG
2347 /* Add new process to process info list */
2348
2349 pi->next = procinfo_list;
2350 procinfo_list = pi;
2351
2352 add_fd (pi); /* Add to list for poll/select */
2353
35f5886e
FF
2354 /* Get current status of process and if it is not already stopped,
2355 then stop it. Remember whether or not it was stopped when we first
2356 examined it. */
2357
de43d7d0 2358 if (ioctl (pi->fd, PIOCSTATUS, &pi->prstatus) < 0)
35f5886e 2359 {
de43d7d0
SG
2360 print_sys_errmsg (pi->pathname, errno);
2361 close_proc_file (pi);
35f5886e
FF
2362 error ("PIOCSTATUS failed");
2363 }
de43d7d0 2364 if (pi->prstatus.pr_flags & (PR_STOPPED | PR_ISTOP))
35f5886e 2365 {
de43d7d0 2366 pi->was_stopped = 1;
35f5886e
FF
2367 }
2368 else
2369 {
de43d7d0 2370 pi->was_stopped = 0;
ec8ceca3 2371 if (1 || query ("Process is currently running, stop it? "))
35f5886e 2372 {
ec8ceca3 2373 /* Make it run again when we close it. */
8fc2b417
SG
2374
2375 modify_run_on_last_close_flag (pi->fd, 1);
2376
de43d7d0 2377 if (ioctl (pi->fd, PIOCSTOP, &pi->prstatus) < 0)
35f5886e 2378 {
de43d7d0
SG
2379 print_sys_errmsg (pi->pathname, errno);
2380 close_proc_file (pi);
35f5886e
FF
2381 error ("PIOCSTOP failed");
2382 }
de43d7d0 2383 pi->nopass_next_sigstop = 1;
d65eee73
FF
2384 }
2385 else
2386 {
199b2450 2387 printf_unfiltered ("Ok, gdb will wait for %s to stop.\n", target_pid_to_str (pid));
35f5886e
FF
2388 }
2389 }
ec8ceca3 2390
35f5886e
FF
2391 /* Remember some things about the inferior that we will, or might, change
2392 so that we can restore them when we detach. */
2393
de43d7d0
SG
2394 ioctl (pi->fd, PIOCGTRACE, &pi->saved_trace);
2395 ioctl (pi->fd, PIOCGHOLD, &pi->saved_sighold);
2396 ioctl (pi->fd, PIOCGFAULT, &pi->saved_fltset);
2397 ioctl (pi->fd, PIOCGENTRY, &pi->saved_entryset);
2398 ioctl (pi->fd, PIOCGEXIT, &pi->saved_exitset);
35f5886e
FF
2399
2400 /* Set up trace and fault sets, as gdb expects them. */
2401
de43d7d0
SG
2402 memset (&pi->prrun, 0, sizeof (pi->prrun));
2403 prfillset (&pi->prrun.pr_trace);
2404 procfs_notice_signals (pid);
2405 prfillset (&pi->prrun.pr_fault);
2406 prdelset (&pi->prrun.pr_fault, FLTPAGE);
2592eef8 2407
b9e58503
PS
2408#ifdef PROCFS_DONT_TRACE_FAULTS
2409 premptyset (&pi->prrun.pr_fault);
2592eef8
PS
2410#endif
2411
de43d7d0 2412 if (ioctl (pi->fd, PIOCSFAULT, &pi->prrun.pr_fault))
35f5886e 2413 {
f66f459f 2414 print_sys_errmsg ("PIOCSFAULT failed", errno);
35f5886e 2415 }
de43d7d0 2416 if (ioctl (pi->fd, PIOCSTRACE, &pi->prrun.pr_trace))
35f5886e 2417 {
f66f459f 2418 print_sys_errmsg ("PIOCSTRACE failed", errno);
35f5886e
FF
2419 }
2420 attach_flag = 1;
2421 return (pid);
2422}
2423
2424/*
2425
3fbdd536 2426LOCAL FUNCTION
35f5886e 2427
3fbdd536 2428 do_detach -- detach from an attached-to process
35f5886e
FF
2429
2430SYNOPSIS
2431
3fbdd536 2432 void do_detach (int signal)
35f5886e
FF
2433
2434DESCRIPTION
2435
2436 Detach from the current attachee.
2437
2438 If signal is non-zero, the attachee is started running again and sent
2439 the specified signal.
2440
2441 If signal is zero and the attachee was not already stopped when we
2442 attached to it, then we make it runnable again when we detach.
2443
2444 Otherwise, we query whether or not to make the attachee runnable
2445 again, since we may simply want to leave it in the state it was in
2446 when we attached.
2447
2448 We report any problems, but do not consider them errors, since we
2449 MUST detach even if some things don't seem to go right. This may not
2450 be the ideal situation. (FIXME).
2451 */
2452
3fbdd536
JG
2453static void
2454do_detach (signal)
1ab3bf1b 2455 int signal;
35f5886e 2456{
de43d7d0
SG
2457 struct procinfo *pi;
2458
2459 pi = current_procinfo;
ec8ceca3 2460
35f5886e
FF
2461 if (signal)
2462 {
de43d7d0 2463 set_proc_siginfo (pi, signal);
35f5886e 2464 }
de43d7d0 2465 if (ioctl (pi->fd, PIOCSEXIT, &pi->saved_exitset) < 0)
35f5886e 2466 {
de43d7d0 2467 print_sys_errmsg (pi->pathname, errno);
199b2450 2468 printf_unfiltered ("PIOCSEXIT failed.\n");
35f5886e 2469 }
de43d7d0 2470 if (ioctl (pi->fd, PIOCSENTRY, &pi->saved_entryset) < 0)
35f5886e 2471 {
de43d7d0 2472 print_sys_errmsg (pi->pathname, errno);
199b2450 2473 printf_unfiltered ("PIOCSENTRY failed.\n");
35f5886e 2474 }
de43d7d0 2475 if (ioctl (pi->fd, PIOCSTRACE, &pi->saved_trace) < 0)
35f5886e 2476 {
de43d7d0 2477 print_sys_errmsg (pi->pathname, errno);
199b2450 2478 printf_unfiltered ("PIOCSTRACE failed.\n");
35f5886e 2479 }
de43d7d0 2480 if (ioctl (pi->fd, PIOCSHOLD, &pi->saved_sighold) < 0)
cc221e76 2481 {
de43d7d0 2482 print_sys_errmsg (pi->pathname, errno);
199b2450 2483 printf_unfiltered ("PIOSCHOLD failed.\n");
cc221e76 2484 }
de43d7d0 2485 if (ioctl (pi->fd, PIOCSFAULT, &pi->saved_fltset) < 0)
35f5886e 2486 {
de43d7d0 2487 print_sys_errmsg (pi->pathname, errno);
199b2450 2488 printf_unfiltered ("PIOCSFAULT failed.\n");
35f5886e 2489 }
de43d7d0 2490 if (ioctl (pi->fd, PIOCSTATUS, &pi->prstatus) < 0)
35f5886e 2491 {
de43d7d0 2492 print_sys_errmsg (pi->pathname, errno);
199b2450 2493 printf_unfiltered ("PIOCSTATUS failed.\n");
35f5886e
FF
2494 }
2495 else
2496 {
de43d7d0 2497 if (signal || (pi->prstatus.pr_flags & (PR_STOPPED | PR_ISTOP)))
35f5886e 2498 {
de43d7d0 2499 if (signal || !pi->was_stopped ||
35f5886e
FF
2500 query ("Was stopped when attached, make it runnable again? "))
2501 {
2592eef8
PS
2502 /* Clear any pending signal if we want to detach without
2503 a signal. */
2504 if (signal == 0)
2505 set_proc_siginfo (pi, signal);
2506
ec8ceca3 2507 /* Clear any fault that might have stopped it. */
de43d7d0 2508 if (ioctl (pi->fd, PIOCCFAULT, 0))
eca4a350
SG
2509 {
2510 print_sys_errmsg (pi->pathname, errno);
199b2450 2511 printf_unfiltered ("PIOCCFAULT failed.\n");
eca4a350 2512 }
ec8ceca3
JG
2513
2514 /* Make it run again when we close it. */
8fc2b417
SG
2515
2516 modify_run_on_last_close_flag (pi->fd, 1);
35f5886e
FF
2517 }
2518 }
2519 }
de43d7d0 2520 close_proc_file (pi);
35f5886e
FF
2521 attach_flag = 0;
2522}
2523
45dc9be3
JK
2524/* emulate wait() as much as possible.
2525 Wait for child to do something. Return pid of child, or -1 in case
2526 of error; store status in *OURSTATUS.
2527
2528 Not sure why we can't
2529 just use wait(), but it seems to have problems when applied to a
2530 process being controlled with the /proc interface.
2531
2532 We have a race problem here with no obvious solution. We need to let
2533 the inferior run until it stops on an event of interest, which means
2534 that we need to use the PIOCWSTOP ioctl. However, we cannot use this
2535 ioctl if the process is already stopped on something that is not an
2536 event of interest, or the call will hang indefinitely. Thus we first
2537 use PIOCSTATUS to see if the process is not stopped. If not, then we
2538 use PIOCWSTOP. But during the window between the two, if the process
2539 stops for any reason that is not an event of interest (such as a job
2540 control signal) then gdb will hang. One possible workaround is to set
2541 an alarm to wake up every minute of so and check to see if the process
2542 is still running, and if so, then reissue the PIOCWSTOP. But this is
2543 a real kludge, so has not been implemented. FIXME: investigate
2544 alternatives.
2545
2546 FIXME: Investigate why wait() seems to have problems with programs
2547 being control by /proc routines. */
35f5886e 2548
3fbdd536 2549static int
45dc9be3 2550procfs_wait (pid, ourstatus)
de43d7d0 2551 int pid;
67ac9759 2552 struct target_waitstatus *ourstatus;
35f5886e
FF
2553{
2554 short what;
2555 short why;
2556 int statval = 0;
2557 int checkerr = 0;
2558 int rtnval = -1;
de43d7d0
SG
2559 struct procinfo *pi;
2560
2561 if (pid != -1) /* Non-specific process? */
2562 pi = NULL;
2563 else
2564 for (pi = procinfo_list; pi; pi = pi->next)
2565 if (pi->had_event)
2566 break;
2567
de43d7d0 2568 if (!pi)
eca4a350
SG
2569 {
2570 wait_again:
2571
8fc2b417
SG
2572 if (pi)
2573 pi->had_event = 0;
2574
eca4a350
SG
2575 pi = wait_fd ();
2576 }
de43d7d0
SG
2577
2578 if (pid != -1)
2579 for (pi = procinfo_list; pi; pi = pi->next)
2580 if (pi->pid == pid && pi->had_event)
2581 break;
2582
2583 if (!pi && !checkerr)
2584 goto wait_again;
2585
2586 if (!checkerr && !(pi->prstatus.pr_flags & (PR_STOPPED | PR_ISTOP)))
2587 {
2588 if (ioctl (pi->fd, PIOCWSTOP, &pi->prstatus) < 0)
2589 {
2590 checkerr++;
2591 }
35f5886e
FF
2592 }
2593 if (checkerr)
2594 {
2595 if (errno == ENOENT)
2596 {
2597 rtnval = wait (&statval);
2598 if (rtnval != inferior_pid)
2599 {
de43d7d0 2600 print_sys_errmsg (pi->pathname, errno);
35f5886e
FF
2601 error ("PIOCWSTOP, wait failed, returned %d", rtnval);
2602 /* NOTREACHED */
2603 }
2604 }
2605 else
2606 {
de43d7d0 2607 print_sys_errmsg (pi->pathname, errno);
35f5886e
FF
2608 error ("PIOCSTATUS or PIOCWSTOP failed.");
2609 /* NOTREACHED */
2610 }
2611 }
de43d7d0 2612 else if (pi->prstatus.pr_flags & (PR_STOPPED | PR_ISTOP))
35f5886e 2613 {
8fc2b417 2614 rtnval = pi->pid;
de43d7d0
SG
2615 why = pi->prstatus.pr_why;
2616 what = pi->prstatus.pr_what;
2617
2618 switch (why)
35f5886e 2619 {
de43d7d0 2620 case PR_SIGNALLED:
35f5886e 2621 statval = (what << 8) | 0177;
fb63d460
SG
2622 break;
2623 case PR_SYSENTRY:
de43d7d0 2624 case PR_SYSEXIT:
8fc2b417
SG
2625 {
2626 int i;
2627 int found_handler = 0;
de43d7d0 2628
8fc2b417
SG
2629 for (i = 0; i < pi->num_syscall_handlers; i++)
2630 if (pi->syscall_handlers[i].syscall_num == what)
de43d7d0 2631 {
8fc2b417
SG
2632 found_handler = 1;
2633 if (!pi->syscall_handlers[i].func (pi, what, why,
2634 &rtnval, &statval))
2635 goto wait_again;
de43d7d0 2636
8fc2b417 2637 break;
de43d7d0
SG
2638 }
2639
8fc2b417
SG
2640 if (!found_handler)
2641 if (why == PR_SYSENTRY)
2642 error ("PR_SYSENTRY, unhandled system call %d", what);
2643 else
2644 error ("PR_SYSEXIT, unhandled system call %d", what);
2645 }
de43d7d0
SG
2646 break;
2647 case PR_REQUESTED:
35f5886e 2648 statval = (SIGSTOP << 8) | 0177;
de43d7d0
SG
2649 break;
2650 case PR_JOBCONTROL:
35f5886e 2651 statval = (what << 8) | 0177;
de43d7d0
SG
2652 break;
2653 case PR_FAULTED:
35f5886e
FF
2654 switch (what)
2655 {
e6b8a171 2656#ifdef FLTWATCH
999dd04b 2657 case FLTWATCH:
e6b8a171
JL
2658 statval = (SIGTRAP << 8) | 0177;
2659 break;
2660#endif
2661#ifdef FLTKWATCH
999dd04b 2662 case FLTKWATCH:
35f5886e
FF
2663 statval = (SIGTRAP << 8) | 0177;
2664 break;
e6b8a171 2665#endif
3f5e2fb5
JK
2666#ifndef FAULTED_USE_SIGINFO
2667 /* Irix, contrary to the documentation, fills in 0 for si_signo.
2668 Solaris fills in si_signo. I'm not sure about others. */
2669 case FLTPRIV:
2670 case FLTILL:
2671 statval = (SIGILL << 8) | 0177;
2672 break;
2673 case FLTBPT:
2674 case FLTTRACE:
2675 statval = (SIGTRAP << 8) | 0177;
2676 break;
2677 case FLTSTACK:
2678 case FLTACCESS:
2679 case FLTBOUNDS:
2680 statval = (SIGSEGV << 8) | 0177;
2681 break;
2682 case FLTIOVF:
2683 case FLTIZDIV:
2684 case FLTFPE:
2685 statval = (SIGFPE << 8) | 0177;
2686 break;
2687 case FLTPAGE: /* Recoverable page fault */
2688#endif /* not FAULTED_USE_SIGINFO */
35f5886e 2689 default:
890634ed
JK
2690 /* Use the signal which the kernel assigns. This is better than
2691 trying to second-guess it from the fault. In fact, I suspect
2692 that FLTACCESS can be either SIGSEGV or SIGBUS. */
2693 statval = ((pi->prstatus.pr_info.si_signo) << 8) | 0177;
2694 break;
35f5886e 2695 }
de43d7d0
SG
2696 break;
2697 default:
35f5886e 2698 error ("PIOCWSTOP, unknown why %d, what %d", why, what);
35f5886e 2699 }
de43d7d0
SG
2700/* Stop all the other threads when any of them stops. */
2701
2702 {
2703 struct procinfo *procinfo;
2704
2705 for (procinfo = procinfo_list; procinfo; procinfo = procinfo->next)
2706 {
2707 if (!procinfo->had_event)
8fc2b417
SG
2708 {
2709 /* A bug in Solaris (2.5) causes us to hang when trying to
2710 stop a stopped process. So, we have to check first in
2711 order to avoid the hang. */
2712 if (ioctl (procinfo->fd, PIOCSTATUS, &procinfo->prstatus) < 0)
2713 {
2714 print_sys_errmsg (procinfo->pathname, errno);
2715 error ("PIOCSTATUS failed");
2716 }
2717 if (!(procinfo->prstatus.pr_flags & PR_STOPPED))
2718 if (ioctl (procinfo->fd, PIOCSTOP, &procinfo->prstatus) < 0)
2719 {
2720 print_sys_errmsg (procinfo->pathname, errno);
2721 error ("PIOCSTOP failed");
2722 }
2723 }
de43d7d0
SG
2724 }
2725 }
35f5886e
FF
2726 }
2727 else
2728 {
2729 error ("PIOCWSTOP, stopped for unknown/unhandled reason, flags %#x",
de43d7d0 2730 pi->prstatus.pr_flags);
35f5886e 2731 }
3fbdd536 2732
67ac9759 2733 store_waitstatus (ourstatus, statval);
3fbdd536
JG
2734
2735 if (rtnval == -1) /* No more children to wait for */
2736 {
199b2450 2737 fprintf_unfiltered (gdb_stderr, "Child process unexpectedly missing.\n");
67ac9759
JK
2738 /* Claim it exited with unknown signal. */
2739 ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
2740 ourstatus->value.sig = TARGET_SIGNAL_UNKNOWN;
3fbdd536
JG
2741 return rtnval;
2742 }
2743
de43d7d0 2744 pi->had_event = 0; /* Indicate that we've seen this one */
35f5886e
FF
2745 return (rtnval);
2746}
2747
2748/*
2749
6b801388
FF
2750LOCAL FUNCTION
2751
2752 set_proc_siginfo - set a process's current signal info
2753
2754SYNOPSIS
2755
2756 void set_proc_siginfo (struct procinfo *pip, int signo);
2757
2758DESCRIPTION
2759
2760 Given a pointer to a process info struct in PIP and a signal number
2761 in SIGNO, set the process's current signal and its associated signal
2762 information. The signal will be delivered to the process immediately
2763 after execution is resumed, even if it is being held. In addition,
2764 this particular delivery will not cause another PR_SIGNALLED stop
2765 even if the signal is being traced.
2766
2767 If we are not delivering the same signal that the prstatus siginfo
2768 struct contains information about, then synthesize a siginfo struct
2769 to match the signal we are doing to deliver, make it of the type
2770 "generated by a user process", and send this synthesized copy. When
2771 used to set the inferior's signal state, this will be required if we
2772 are not currently stopped because of a traced signal, or if we decide
2773 to continue with a different signal.
2774
2775 Note that when continuing the inferior from a stop due to receipt
2776 of a traced signal, we either have set PRCSIG to clear the existing
2777 signal, or we have to call this function to do a PIOCSSIG with either
2778 the existing siginfo struct from pr_info, or one we have synthesized
2779 appropriately for the signal we want to deliver. Otherwise if the
2780 signal is still being traced, the inferior will immediately stop
2781 again.
2782
2783 See siginfo(5) for more details.
2784*/
2785
2786static void
2787set_proc_siginfo (pip, signo)
cc221e76
FF
2788 struct procinfo *pip;
2789 int signo;
6b801388
FF
2790{
2791 struct siginfo newsiginfo;
2792 struct siginfo *sip;
2793
2592eef8
PS
2794#ifdef PROCFS_DONT_PIOCSSIG_CURSIG
2795 /* With Alpha OSF/1 procfs, the kernel gets really confused if it
a1a0d974 2796 receives a PIOCSSIG with a signal identical to the current signal,
2592eef8
PS
2797 it messes up the current signal. Work around the kernel bug. */
2798 if (signo == pip -> prstatus.pr_cursig)
2799 return;
2800#endif
2801
de43d7d0 2802 if (signo == pip -> prstatus.pr_info.si_signo)
6b801388 2803 {
de43d7d0
SG
2804 sip = &pip -> prstatus.pr_info;
2805 }
2806 else
2807 {
2808 memset ((char *) &newsiginfo, 0, sizeof (newsiginfo));
2809 sip = &newsiginfo;
2810 sip -> si_signo = signo;
2811 sip -> si_code = 0;
2812 sip -> si_errno = 0;
2813 sip -> si_pid = getpid ();
2814 sip -> si_uid = getuid ();
2815 }
2816 if (ioctl (pip -> fd, PIOCSSIG, sip) < 0)
2817 {
2818 print_sys_errmsg (pip -> pathname, errno);
2819 warning ("PIOCSSIG failed");
6b801388
FF
2820 }
2821}
2822
25286543 2823/* Resume execution of process PID. If STEP is nozero, then
59ba57da
JK
2824 just single step it. If SIGNAL is nonzero, restart it with that
2825 signal activated. */
35f5886e 2826
3fbdd536 2827static void
25286543
SG
2828procfs_resume (pid, step, signo)
2829 int pid;
1ab3bf1b 2830 int step;
67ac9759 2831 enum target_signal signo;
35f5886e 2832{
59ba57da 2833 int signal_to_pass;
de43d7d0
SG
2834 struct procinfo *pi, *procinfo;
2835
2836 pi = find_procinfo (pid == -1 ? inferior_pid : pid, 0);
59ba57da 2837
35f5886e 2838 errno = 0;
de43d7d0 2839 pi->prrun.pr_flags = PRSTRACE | PRSFAULT | PRCFAULT;
99fd9e3e 2840
59ba57da
JK
2841#if 0
2842 /* It should not be necessary. If the user explicitly changes the value,
2843 value_assign calls write_register_bytes, which writes it. */
2844/* It may not be absolutely necessary to specify the PC value for
2845 restarting, but to be safe we use the value that gdb considers
2846 to be current. One case where this might be necessary is if the
2847 user explicitly changes the PC value that gdb considers to be
2848 current. FIXME: Investigate if this is necessary or not. */
2849
c3192172 2850#ifdef PRSVADDR_BROKEN
99fd9e3e
SG
2851/* Can't do this under Solaris running on a Sparc, as there seems to be no
2852 place to put nPC. In fact, if you use this, nPC seems to be set to some
2853 random garbage. We have to rely on the fact that PC and nPC have been
2854 written previously via PIOCSREG during a register flush. */
2855
de43d7d0
SG
2856 pi->prrun.pr_vaddr = (caddr_t) *(int *) &registers[REGISTER_BYTE (PC_REGNUM)];
2857 pi->prrun.pr_flags != PRSVADDR;
99fd9e3e 2858#endif
59ba57da
JK
2859#endif
2860
67ac9759 2861 if (signo == TARGET_SIGNAL_STOP && pi->nopass_next_sigstop)
59ba57da
JK
2862 /* When attaching to a child process, if we forced it to stop with
2863 a PIOCSTOP, then we will have set the nopass_next_sigstop flag.
2864 Upon resuming the first time after such a stop, we explicitly
2865 inhibit sending it another SIGSTOP, which would be the normal
2866 result of default signal handling. One potential drawback to
2867 this is that we will also ignore any attempt to by the user
2868 to explicitly continue after the attach with a SIGSTOP. Ultimately
2869 this problem should be dealt with by making the routines that
2870 deal with the inferior a little smarter, and possibly even allow
2871 an inferior to continue running at the same time as gdb. (FIXME?) */
2872 signal_to_pass = 0;
67ac9759 2873 else if (signo == TARGET_SIGNAL_TSTP
de43d7d0
SG
2874 && pi->prstatus.pr_cursig == SIGTSTP
2875 && pi->prstatus.pr_action.sa_handler == SIG_DFL)
59ba57da
JK
2876
2877 /* We are about to pass the inferior a SIGTSTP whose action is
2878 SIG_DFL. The SIG_DFL action for a SIGTSTP is to stop
2879 (notifying the parent via wait()), and then keep going from the
2880 same place when the parent is ready for you to keep going. So
2881 under the debugger, it should do nothing (as if the program had
2882 been stopped and then later resumed. Under ptrace, this
2883 happens for us, but under /proc, the system obligingly stops
2884 the process, and wait_for_inferior would have no way of
2885 distinguishing that type of stop (which indicates that we
2886 should just start it again), with a stop due to the pr_trace
2887 field of the prrun_t struct.
2888
2889 Note that if the SIGTSTP is being caught, we *do* need to pass it,
2890 because the handler needs to get executed. */
2891 signal_to_pass = 0;
2892 else
67ac9759 2893 signal_to_pass = target_signal_to_host (signo);
99fd9e3e 2894
59ba57da 2895 if (signal_to_pass)
35f5886e 2896 {
de43d7d0 2897 set_proc_siginfo (pi, signal_to_pass);
35f5886e
FF
2898 }
2899 else
2900 {
de43d7d0 2901 pi->prrun.pr_flags |= PRCSIG;
35f5886e 2902 }
de43d7d0 2903 pi->nopass_next_sigstop = 0;
35f5886e
FF
2904 if (step)
2905 {
de43d7d0 2906 pi->prrun.pr_flags |= PRSTEP;
35f5886e 2907 }
8fc2b417
SG
2908
2909 /* Don't try to start a process unless it's stopped on an
2910 `event of interest'. Doing so will cause errors. */
2911
2912 if ((pi->prstatus.pr_flags & PR_ISTOP)
2913 && ioctl (pi->fd, PIOCRUN, &pi->prrun) != 0)
35f5886e 2914 {
de43d7d0 2915 perror_with_name (pi->pathname);
35f5886e
FF
2916 /* NOTREACHED */
2917 }
de43d7d0
SG
2918
2919 pi->had_event = 0;
2920
2921 /* Continue all the other threads that haven't had an event of
2922 interest. */
2923
2924 if (pid == -1)
2925 for (procinfo = procinfo_list; procinfo; procinfo = procinfo->next)
2926 {
2927 if (pi != procinfo && !procinfo->had_event)
2928 {
2929 procinfo->prrun.pr_flags &= PRSTEP;
2930 procinfo->prrun.pr_flags |= PRCFAULT | PRCSIG;
2931 ioctl (procinfo->fd, PIOCSTATUS, &procinfo->prstatus);
8fc2b417
SG
2932
2933 /* Don't try to start a process unless it's stopped on an
2934 `event of interest'. Doing so will cause errors. */
2935
2936 if ((procinfo->prstatus.pr_flags & PR_ISTOP)
2937 && ioctl (procinfo->fd, PIOCRUN, &procinfo->prrun) < 0)
de43d7d0
SG
2938 {
2939 if (ioctl (procinfo->fd, PIOCSTATUS, &procinfo->prstatus) < 0)
2940 {
199b2450 2941 fprintf_unfiltered(gdb_stderr, "PIOCSTATUS failed, errno=%d\n", errno);
de43d7d0
SG
2942 }
2943 print_sys_errmsg (procinfo->pathname, errno);
2944 error ("PIOCRUN failed");
2945 }
2946 ioctl (procinfo->fd, PIOCSTATUS, &procinfo->prstatus);
2947 }
2948 }
35f5886e
FF
2949}
2950
2951/*
2952
3fbdd536 2953LOCAL FUNCTION
35f5886e 2954
3fbdd536 2955 procfs_fetch_registers -- fetch current registers from inferior
35f5886e
FF
2956
2957SYNOPSIS
2958
3fbdd536 2959 void procfs_fetch_registers (int regno)
35f5886e
FF
2960
2961DESCRIPTION
2962
2963 Read the current values of the inferior's registers, both the
2964 general register set and floating point registers (if supported)
2965 and update gdb's idea of their current values.
2966
2967*/
2968
3fbdd536
JG
2969static void
2970procfs_fetch_registers (regno)
1ab3bf1b 2971 int regno;
35f5886e 2972{
de43d7d0
SG
2973 struct procinfo *pi;
2974
2975 pi = current_procinfo;
2976
2977 if (ioctl (pi->fd, PIOCGREG, &pi->gregset) != -1)
35f5886e 2978 {
de43d7d0 2979 supply_gregset (&pi->gregset);
35f5886e
FF
2980 }
2981#if defined (FP0_REGNUM)
de43d7d0 2982 if (ioctl (pi->fd, PIOCGFPREG, &pi->fpregset) != -1)
35f5886e 2983 {
de43d7d0 2984 supply_fpregset (&pi->fpregset);
35f5886e
FF
2985 }
2986#endif
2987}
2988
fb182850
FF
2989/*
2990
35f5886e
FF
2991LOCAL FUNCTION
2992
de43d7d0
SG
2993 proc_init_failed - called whenever /proc access initialization
2994fails
35f5886e
FF
2995
2996SYNOPSIS
2997
de43d7d0 2998 static void proc_init_failed (struct procinfo *pi, char *why)
35f5886e
FF
2999
3000DESCRIPTION
3001
3002 This function is called whenever initialization of access to a /proc
3003 entry fails. It prints a suitable error message, does some cleanup,
3004 and then invokes the standard error processing routine which dumps
3005 us back into the command loop.
3006 */
3007
3008static void
de43d7d0
SG
3009proc_init_failed (pi, why)
3010 struct procinfo *pi;
1ab3bf1b 3011 char *why;
35f5886e 3012{
de43d7d0
SG
3013 print_sys_errmsg (pi->pathname, errno);
3014 kill (pi->pid, SIGKILL);
3015 close_proc_file (pi);
35f5886e
FF
3016 error (why);
3017 /* NOTREACHED */
3018}
3019
3020/*
3021
3022LOCAL FUNCTION
3023
3024 close_proc_file - close any currently open /proc entry
3025
3026SYNOPSIS
3027
a39ad5ce 3028 static void close_proc_file (struct procinfo *pip)
35f5886e
FF
3029
3030DESCRIPTION
3031
3032 Close any currently open /proc entry and mark the process information
3033 entry as invalid. In order to ensure that we don't try to reuse any
3034 stale information, the pid, fd, and pathnames are explicitly
3035 invalidated, which may be overkill.
3036
3037 */
3038
3039static void
1ab3bf1b
JG
3040close_proc_file (pip)
3041 struct procinfo *pip;
35f5886e 3042{
de43d7d0
SG
3043 struct procinfo *procinfo;
3044
3045 remove_fd (pip); /* Remove fd from poll/select list */
3046
3047 close (pip -> fd);
3048
3049 free (pip -> pathname);
3050
3051 /* Unlink pip from the procinfo chain. Note pip might not be on the list. */
3052
3053 if (procinfo_list == pip)
3054 procinfo_list = pip->next;
3055 else
3056 for (procinfo = procinfo_list; procinfo; procinfo = procinfo->next)
3057 if (procinfo->next == pip)
3058 procinfo->next = pip->next;
3059
3060 free (pip);
35f5886e
FF
3061}
3062
3063/*
3064
3065LOCAL FUNCTION
3066
3067 open_proc_file - open a /proc entry for a given process id
3068
3069SYNOPSIS
3070
ec8ceca3 3071 static int open_proc_file (int pid, struct procinfo *pip, int mode)
35f5886e
FF
3072
3073DESCRIPTION
3074
ec8ceca3
JG
3075 Given a process id and a mode, close the existing open /proc
3076 entry (if any) and open one for the new process id, in the
3077 specified mode. Once it is open, then mark the local process
3078 information structure as valid, which guarantees that the pid,
3079 fd, and pathname fields match an open /proc entry. Returns
3080 zero if the open fails, nonzero otherwise.
35f5886e
FF
3081
3082 Note that the pathname is left intact, even when the open fails,
3083 so that callers can use it to construct meaningful error messages
3084 rather than just "file open failed".
8fc2b417
SG
3085
3086 Note that for Solaris, the process-id also includes an LWP-id, so we
3087 actually attempt to open that. If we are handed a pid with a 0 LWP-id,
3088 then we will ask the kernel what it is and add it to the pid. Hence,
3089 the pid can be changed by us.
35f5886e
FF
3090 */
3091
3092static int
ec8ceca3 3093open_proc_file (pid, pip, mode)
1ab3bf1b
JG
3094 int pid;
3095 struct procinfo *pip;
ec8ceca3 3096 int mode;
35f5886e 3097{
8fc2b417
SG
3098 int tmp, tmpfd;
3099
de43d7d0
SG
3100 pip -> next = NULL;
3101 pip -> had_event = 0;
3102 pip -> pathname = xmalloc (32);
3103 pip -> pid = pid;
3104
8fc2b417
SG
3105#ifndef PIOCOPENLWP
3106 tmp = pid;
3107#else
3108 tmp = pid & 0xffff;
3109#endif
3110
3111 sprintf (pip -> pathname, PROC_NAME_FMT, tmp);
3112 if ((tmpfd = open (pip -> pathname, mode)) < 0)
de43d7d0
SG
3113 return 0;
3114
8fc2b417
SG
3115#ifndef PIOCOPENLWP
3116 pip -> fd = tmpfd;
3117#else
3118 tmp = (pid >> 16) & 0xffff; /* Extract thread id */
3119
3120 if (tmp == 0)
3121 { /* Don't know thread id yet */
3122 if (ioctl (tmpfd, PIOCSTATUS, &pip -> prstatus) < 0)
3123 {
3124 print_sys_errmsg (pip -> pathname, errno);
3125 close (tmpfd);
3126 error ("open_proc_file: PIOCSTATUS failed");
3127 }
3128
3129 tmp = pip -> prstatus.pr_who; /* Get thread id from prstatus_t */
3130 pip -> pid = (tmp << 16) | pid; /* Update pip */
3131 }
3132
3133 if ((pip -> fd = ioctl (tmpfd, PIOCOPENLWP, &tmp)) < 0)
3134 {
3135 close (tmpfd);
3136 return 0;
3137 }
3138
3139#ifdef PIOCSET /* New method */
3140 {
3141 long pr_flags;
3142 pr_flags = PR_ASYNC;
3143 ioctl (pip -> fd, PIOCSET, &pr_flags);
3144 }
3145#endif
3146
3147 close (tmpfd); /* All done with main pid */
3148#endif /* PIOCOPENLWP */
3149
de43d7d0 3150 return 1;
a39ad5ce
FF
3151}
3152
f66f459f 3153static char *
1ab3bf1b
JG
3154mappingflags (flags)
3155 long flags;
a39ad5ce 3156{
5c1c5e67 3157 static char asciiflags[8];
a39ad5ce 3158
5c1c5e67
FF
3159 strcpy (asciiflags, "-------");
3160#if defined (MA_PHYS)
3161 if (flags & MA_PHYS) asciiflags[0] = 'd';
3162#endif
3163 if (flags & MA_STACK) asciiflags[1] = 's';
3164 if (flags & MA_BREAK) asciiflags[2] = 'b';
3165 if (flags & MA_SHARED) asciiflags[3] = 's';
3166 if (flags & MA_READ) asciiflags[4] = 'r';
3167 if (flags & MA_WRITE) asciiflags[5] = 'w';
3168 if (flags & MA_EXEC) asciiflags[6] = 'x';
a39ad5ce
FF
3169 return (asciiflags);
3170}
3171
3172static void
cc221e76
FF
3173info_proc_flags (pip, summary)
3174 struct procinfo *pip;
3175 int summary;
3176{
3177 struct trans *transp;
3178
3179 printf_filtered ("%-32s", "Process status flags:");
3180 if (!summary)
3181 {
3182 printf_filtered ("\n\n");
3183 }
3184 for (transp = pr_flag_table; transp -> name != NULL; transp++)
3185 {
3186 if (pip -> prstatus.pr_flags & transp -> value)
3187 {
3188 if (summary)
3189 {
3190 printf_filtered ("%s ", transp -> name);
3191 }
3192 else
3193 {
3194 printf_filtered ("\t%-16s %s.\n", transp -> name, transp -> desc);
3195 }
3196 }
3197 }
3198 printf_filtered ("\n");
3199}
3200
3201static void
3202info_proc_stop (pip, summary)
3203 struct procinfo *pip;
3204 int summary;
3205{
3206 struct trans *transp;
3207 int why;
3208 int what;
3209
3210 why = pip -> prstatus.pr_why;
3211 what = pip -> prstatus.pr_what;
3212
3213 if (pip -> prstatus.pr_flags & PR_STOPPED)
3214 {
3215 printf_filtered ("%-32s", "Reason for stopping:");
3216 if (!summary)
3217 {
3218 printf_filtered ("\n\n");
3219 }
3220 for (transp = pr_why_table; transp -> name != NULL; transp++)
3221 {
3222 if (why == transp -> value)
3223 {
3224 if (summary)
3225 {
3226 printf_filtered ("%s ", transp -> name);
3227 }
3228 else
3229 {
3230 printf_filtered ("\t%-16s %s.\n",
3231 transp -> name, transp -> desc);
3232 }
3233 break;
3234 }
3235 }
3236
3237 /* Use the pr_why field to determine what the pr_what field means, and
3238 print more information. */
3239
3240 switch (why)
3241 {
3242 case PR_REQUESTED:
3243 /* pr_what is unused for this case */
3244 break;
3245 case PR_JOBCONTROL:
3246 case PR_SIGNALLED:
3247 if (summary)
3248 {
3249 printf_filtered ("%s ", signalname (what));
3250 }
3251 else
3252 {
3253 printf_filtered ("\t%-16s %s.\n", signalname (what),
4ace50a5 3254 safe_strsignal (what));
cc221e76
FF
3255 }
3256 break;
3257 case PR_SYSENTRY:
3258 if (summary)
3259 {
3260 printf_filtered ("%s ", syscallname (what));
3261 }
3262 else
3263 {
3264 printf_filtered ("\t%-16s %s.\n", syscallname (what),
3265 "Entered this system call");
3266 }
3267 break;
3268 case PR_SYSEXIT:
3269 if (summary)
3270 {
3271 printf_filtered ("%s ", syscallname (what));
3272 }
3273 else
3274 {
3275 printf_filtered ("\t%-16s %s.\n", syscallname (what),
3276 "Returned from this system call");
3277 }
3278 break;
3279 case PR_FAULTED:
3280 if (summary)
3281 {
3282 printf_filtered ("%s ",
3283 lookupname (faults_table, what, "fault"));
3284 }
3285 else
3286 {
3287 printf_filtered ("\t%-16s %s.\n",
3288 lookupname (faults_table, what, "fault"),
3289 lookupdesc (faults_table, what));
3290 }
3291 break;
3292 }
3293 printf_filtered ("\n");
3294 }
3295}
3296
3297static void
3298info_proc_siginfo (pip, summary)
3299 struct procinfo *pip;
3300 int summary;
3301{
3302 struct siginfo *sip;
3303
3304 if ((pip -> prstatus.pr_flags & PR_STOPPED) &&
3305 (pip -> prstatus.pr_why == PR_SIGNALLED ||
3306 pip -> prstatus.pr_why == PR_FAULTED))
3307 {
3308 printf_filtered ("%-32s", "Additional signal/fault info:");
3309 sip = &pip -> prstatus.pr_info;
3310 if (summary)
3311 {
3312 printf_filtered ("%s ", signalname (sip -> si_signo));
3313 if (sip -> si_errno > 0)
3314 {
4ace50a5 3315 printf_filtered ("%s ", errnoname (sip -> si_errno));
cc221e76
FF
3316 }
3317 if (sip -> si_code <= 0)
3318 {
25286543
SG
3319 printf_filtered ("sent by %s, uid %d ",
3320 target_pid_to_str (sip -> si_pid),
cc221e76
FF
3321 sip -> si_uid);
3322 }
3323 else
3324 {
3325 printf_filtered ("%s ", sigcodename (sip));
3326 if ((sip -> si_signo == SIGILL) ||
3327 (sip -> si_signo == SIGFPE) ||
3328 (sip -> si_signo == SIGSEGV) ||
3329 (sip -> si_signo == SIGBUS))
3330 {
b9e58503
PS
3331 printf_filtered ("addr=%#lx ",
3332 (unsigned long) sip -> si_addr);
cc221e76
FF
3333 }
3334 else if ((sip -> si_signo == SIGCHLD))
3335 {
25286543
SG
3336 printf_filtered ("child %s, status %u ",
3337 target_pid_to_str (sip -> si_pid),
cc221e76
FF
3338 sip -> si_status);
3339 }
3340 else if ((sip -> si_signo == SIGPOLL))
3341 {
3342 printf_filtered ("band %u ", sip -> si_band);
3343 }
3344 }
3345 }
3346 else
3347 {
3348 printf_filtered ("\n\n");
3349 printf_filtered ("\t%-16s %s.\n", signalname (sip -> si_signo),
4ace50a5 3350 safe_strsignal (sip -> si_signo));
cc221e76
FF
3351 if (sip -> si_errno > 0)
3352 {
3353 printf_filtered ("\t%-16s %s.\n",
4ace50a5
FF
3354 errnoname (sip -> si_errno),
3355 safe_strerror (sip -> si_errno));
cc221e76
FF
3356 }
3357 if (sip -> si_code <= 0)
3358 {
25286543 3359 printf_filtered ("\t%-16u %s\n", sip -> si_pid, /* XXX need target_pid_to_str() */
cc221e76
FF
3360 "PID of process sending signal");
3361 printf_filtered ("\t%-16u %s\n", sip -> si_uid,
3362 "UID of process sending signal");
3363 }
3364 else
3365 {
3366 printf_filtered ("\t%-16s %s.\n", sigcodename (sip),
3367 sigcodedesc (sip));
3368 if ((sip -> si_signo == SIGILL) ||
3369 (sip -> si_signo == SIGFPE))
3370 {
b9e58503
PS
3371 printf_filtered ("\t%#-16lx %s.\n",
3372 (unsigned long) sip -> si_addr,
cc221e76
FF
3373 "Address of faulting instruction");
3374 }
3375 else if ((sip -> si_signo == SIGSEGV) ||
3376 (sip -> si_signo == SIGBUS))
3377 {
b9e58503
PS
3378 printf_filtered ("\t%#-16lx %s.\n",
3379 (unsigned long) sip -> si_addr,
cc221e76
FF
3380 "Address of faulting memory reference");
3381 }
3382 else if ((sip -> si_signo == SIGCHLD))
3383 {
25286543 3384 printf_filtered ("\t%-16u %s.\n", sip -> si_pid, /* XXX need target_pid_to_str() */
cc221e76
FF
3385 "Child process ID");
3386 printf_filtered ("\t%-16u %s.\n", sip -> si_status,
3387 "Child process exit value or signal");
3388 }
3389 else if ((sip -> si_signo == SIGPOLL))
3390 {
3391 printf_filtered ("\t%-16u %s.\n", sip -> si_band,
3392 "Band event for POLL_{IN,OUT,MSG}");
3393 }
3394 }
3395 }
3396 printf_filtered ("\n");
3397 }
3398}
3399
3400static void
3401info_proc_syscalls (pip, summary)
3402 struct procinfo *pip;
3403 int summary;
3404{
3405 int syscallnum;
3406
3407 if (!summary)
3408 {
3409
3410#if 0 /* FIXME: Needs to use gdb-wide configured info about system calls. */
3411 if (pip -> prstatus.pr_flags & PR_ASLEEP)
3412 {
3413 int syscallnum = pip -> prstatus.pr_reg[R_D0];
3414 if (summary)
3415 {
3416 printf_filtered ("%-32s", "Sleeping in system call:");
3417 printf_filtered ("%s", syscallname (syscallnum));
3418 }
3419 else
3420 {
3421 printf_filtered ("Sleeping in system call '%s'.\n",
3422 syscallname (syscallnum));
3423 }
3424 }
3425#endif
3426
3427 if (ioctl (pip -> fd, PIOCGENTRY, &pip -> entryset) < 0)
3428 {
3429 print_sys_errmsg (pip -> pathname, errno);
3430 error ("PIOCGENTRY failed");
3431 }
3432
3433 if (ioctl (pip -> fd, PIOCGEXIT, &pip -> exitset) < 0)
3434 {
3435 print_sys_errmsg (pip -> pathname, errno);
3436 error ("PIOCGEXIT failed");
3437 }
3438
3439 printf_filtered ("System call tracing information:\n\n");
3440
3441 printf_filtered ("\t%-12s %-8s %-8s\n",
3442 "System call",
3443 "Entry",
3444 "Exit");
3445 for (syscallnum = 0; syscallnum < MAX_SYSCALLS; syscallnum++)
3446 {
3447 QUIT;
3448 if (syscall_table[syscallnum] != NULL)
8fc2b417
SG
3449 printf_filtered ("\t%-12s ", syscall_table[syscallnum]);
3450 else
3451 printf_filtered ("\t%-12d ", syscallnum);
3452
3453 printf_filtered ("%-8s ",
3454 prismember (&pip -> entryset, syscallnum)
3455 ? "on" : "off");
3456 printf_filtered ("%-8s ",
3457 prismember (&pip -> exitset, syscallnum)
3458 ? "on" : "off");
3459 printf_filtered ("\n");
3460 }
cc221e76
FF
3461 printf_filtered ("\n");
3462 }
3463}
3464
3465static char *
3466signalname (signo)
3467 int signo;
3468{
26a859ec 3469 const char *name;
4ace50a5
FF
3470 static char locbuf[32];
3471
3472 name = strsigno (signo);
3473 if (name == NULL)
3474 {
3475 sprintf (locbuf, "Signal %d", signo);
3476 }
3477 else
3478 {
3479 sprintf (locbuf, "%s (%d)", name, signo);
3480 }
3481 return (locbuf);
3482}
3483
3484static char *
3485errnoname (errnum)
3486 int errnum;
3487{
26a859ec 3488 const char *name;
cc221e76
FF
3489 static char locbuf[32];
3490
4ace50a5
FF
3491 name = strerrno (errnum);
3492 if (name == NULL)
cc221e76 3493 {
4ace50a5 3494 sprintf (locbuf, "Errno %d", errnum);
cc221e76
FF
3495 }
3496 else
3497 {
4ace50a5 3498 sprintf (locbuf, "%s (%d)", name, errnum);
cc221e76
FF
3499 }
3500 return (locbuf);
3501}
3502
3503static void
3504info_proc_signals (pip, summary)
3505 struct procinfo *pip;
3506 int summary;
3507{
3508 int signo;
3509
3510 if (!summary)
3511 {
3512 if (ioctl (pip -> fd, PIOCGTRACE, &pip -> trace) < 0)
3513 {
3514 print_sys_errmsg (pip -> pathname, errno);
3515 error ("PIOCGTRACE failed");
3516 }
3517
3518 printf_filtered ("Disposition of signals:\n\n");
3519 printf_filtered ("\t%-15s %-8s %-8s %-8s %s\n\n",
3520 "Signal", "Trace", "Hold", "Pending", "Description");
3521 for (signo = 0; signo < NSIG; signo++)
3522 {
3523 QUIT;
3524 printf_filtered ("\t%-15s ", signalname (signo));
3525 printf_filtered ("%-8s ",
3526 prismember (&pip -> trace, signo)
3527 ? "on" : "off");
3528 printf_filtered ("%-8s ",
3529 prismember (&pip -> prstatus.pr_sighold, signo)
3530 ? "on" : "off");
2592eef8
PS
3531
3532#ifdef PROCFS_SIGPEND_OFFSET
3533 /* Alpha OSF/1 numbers the pending signals from 1. */
3534 printf_filtered ("%-8s ",
3535 (signo ? prismember (&pip -> prstatus.pr_sigpend,
3536 signo - 1)
3537 : 0)
3538 ? "yes" : "no");
3539#else
cc221e76
FF
3540 printf_filtered ("%-8s ",
3541 prismember (&pip -> prstatus.pr_sigpend, signo)
3542 ? "yes" : "no");
2592eef8 3543#endif
4ace50a5 3544 printf_filtered (" %s\n", safe_strsignal (signo));
cc221e76
FF
3545 }
3546 printf_filtered ("\n");
3547 }
3548}
3549
3550static void
3551info_proc_faults (pip, summary)
3552 struct procinfo *pip;
3553 int summary;
3554{
3555 struct trans *transp;
3556
3557 if (!summary)
3558 {
3559 if (ioctl (pip -> fd, PIOCGFAULT, &pip -> fltset) < 0)
3560 {
3561 print_sys_errmsg (pip -> pathname, errno);
3562 error ("PIOCGFAULT failed");
3563 }
3564
3565 printf_filtered ("Current traced hardware fault set:\n\n");
3566 printf_filtered ("\t%-12s %-8s\n", "Fault", "Trace");
3567
3568 for (transp = faults_table; transp -> name != NULL; transp++)
3569 {
3570 QUIT;
3571 printf_filtered ("\t%-12s ", transp -> name);
3572 printf_filtered ("%-8s", prismember (&pip -> fltset, transp -> value)
3573 ? "on" : "off");
3574 printf_filtered ("\n");
3575 }
3576 printf_filtered ("\n");
3577 }
3578}
3579
3580static void
3581info_proc_mappings (pip, summary)
1ab3bf1b 3582 struct procinfo *pip;
cc221e76 3583 int summary;
a39ad5ce
FF
3584{
3585 int nmap;
3586 struct prmap *prmaps;
3587 struct prmap *prmap;
3588
cc221e76 3589 if (!summary)
a39ad5ce 3590 {
cc221e76 3591 printf_filtered ("Mapped address spaces:\n\n");
2592eef8
PS
3592#ifdef BFD_HOST_64_BIT
3593 printf_filtered (" %18s %18s %10s %10s %7s\n",
3594#else
5c1c5e67 3595 printf_filtered ("\t%10s %10s %10s %10s %7s\n",
2592eef8 3596#endif
cc221e76
FF
3597 "Start Addr",
3598 " End Addr",
3599 " Size",
3600 " Offset",
3601 "Flags");
3602 if (ioctl (pip -> fd, PIOCNMAP, &nmap) == 0)
a39ad5ce 3603 {
cc221e76
FF
3604 prmaps = (struct prmap *) alloca ((nmap + 1) * sizeof (*prmaps));
3605 if (ioctl (pip -> fd, PIOCMAP, prmaps) == 0)
a39ad5ce 3606 {
cc221e76
FF
3607 for (prmap = prmaps; prmap -> pr_size; ++prmap)
3608 {
2592eef8
PS
3609#ifdef BFD_HOST_64_BIT
3610 printf_filtered (" %#18lx %#18lx %#10x %#10x %7s\n",
3611#else
3612 printf_filtered ("\t%#10lx %#10lx %#10x %#10x %7s\n",
3613#endif
3614 (unsigned long)prmap -> pr_vaddr,
3615 (unsigned long)prmap -> pr_vaddr
3616 + prmap -> pr_size - 1,
cc221e76
FF
3617 prmap -> pr_size,
3618 prmap -> pr_off,
3619 mappingflags (prmap -> pr_mflags));
3620 }
a39ad5ce
FF
3621 }
3622 }
cc221e76 3623 printf_filtered ("\n");
a39ad5ce 3624 }
a39ad5ce
FF
3625}
3626
3627/*
3628
3629LOCAL FUNCTION
3630
cc221e76 3631 info_proc -- implement the "info proc" command
a39ad5ce
FF
3632
3633SYNOPSIS
3634
cc221e76 3635 void info_proc (char *args, int from_tty)
a39ad5ce
FF
3636
3637DESCRIPTION
3638
3639 Implement gdb's "info proc" command by using the /proc interface
3640 to print status information about any currently running process.
3641
3642 Examples of the use of "info proc" are:
3643
cc221e76
FF
3644 info proc (prints summary info for current inferior)
3645 info proc 123 (prints summary info for process with pid 123)
3646 info proc mappings (prints address mappings)
3647 info proc times (prints process/children times)
3648 info proc id (prints pid, ppid, gid, sid, etc)
3fbdd536 3649 FIXME: i proc id not implemented.
cc221e76 3650 info proc status (prints general process state info)
3fbdd536 3651 FIXME: i proc status not implemented.
cc221e76
FF
3652 info proc signals (prints info about signal handling)
3653 info proc all (prints all info)
a39ad5ce
FF
3654
3655 */
3656
3657static void
cc221e76 3658info_proc (args, from_tty)
1ab3bf1b
JG
3659 char *args;
3660 int from_tty;
a39ad5ce 3661{
8fc2b417 3662 int pid = inferior_pid;
a39ad5ce
FF
3663 struct procinfo *pip;
3664 struct cleanup *old_chain;
cc221e76
FF
3665 char **argv;
3666 int argsize;
3667 int summary = 1;
3668 int flags = 0;
3669 int syscalls = 0;
3670 int signals = 0;
3671 int faults = 0;
3672 int mappings = 0;
3673 int times = 0;
3674 int id = 0;
3675 int status = 0;
3676 int all = 0;
8fc2b417 3677 int nlwp;
47ef0da5 3678 int *lwps;
a39ad5ce
FF
3679
3680 old_chain = make_cleanup (null_cleanup, 0);
3681
de43d7d0
SG
3682 /* Default to using the current inferior if no pid specified. Note
3683 that inferior_pid may be 0, hence we set okerr. */
a39ad5ce 3684
de43d7d0 3685 pip = find_procinfo (inferior_pid, 1);
a39ad5ce 3686
a39ad5ce 3687 if (args != NULL)
35f5886e 3688 {
cc221e76 3689 if ((argv = buildargv (args)) == NULL)
a39ad5ce 3690 {
cc221e76
FF
3691 nomem (0);
3692 }
3693 make_cleanup (freeargv, (char *) argv);
3694
3695 while (*argv != NULL)
3696 {
3697 argsize = strlen (*argv);
3698 if (argsize >= 1 && strncmp (*argv, "all", argsize) == 0)
3699 {
3700 summary = 0;
3701 all = 1;
3702 }
3703 else if (argsize >= 2 && strncmp (*argv, "faults", argsize) == 0)
3704 {
3705 summary = 0;
3706 faults = 1;
3707 }
3708 else if (argsize >= 2 && strncmp (*argv, "flags", argsize) == 0)
3709 {
3710 summary = 0;
3711 flags = 1;
3712 }
3713 else if (argsize >= 1 && strncmp (*argv, "id", argsize) == 0)
3714 {
3715 summary = 0;
3716 id = 1;
3717 }
3718 else if (argsize >= 1 && strncmp (*argv, "mappings", argsize) == 0)
3719 {
3720 summary = 0;
3721 mappings = 1;
3722 }
3723 else if (argsize >= 2 && strncmp (*argv, "signals", argsize) == 0)
3724 {
3725 summary = 0;
3726 signals = 1;
3727 }
3728 else if (argsize >= 2 && strncmp (*argv, "status", argsize) == 0)
3729 {
3730 summary = 0;
3731 status = 1;
3732 }
3733 else if (argsize >= 2 && strncmp (*argv, "syscalls", argsize) == 0)
3734 {
3735 summary = 0;
3736 syscalls = 1;
3737 }
3738 else if (argsize >= 1 && strncmp (*argv, "times", argsize) == 0)
a39ad5ce 3739 {
cc221e76
FF
3740 summary = 0;
3741 times = 1;
a39ad5ce 3742 }
de43d7d0 3743 else if ((pid = atoi (*argv)) > 0)
a39ad5ce 3744 {
de43d7d0
SG
3745 pip = (struct procinfo *) xmalloc (sizeof (struct procinfo));
3746 memset (pip, 0, sizeof (*pip));
3747
3748 pip->pid = pid;
ec8ceca3 3749 if (!open_proc_file (pid, pip, O_RDONLY))
a39ad5ce
FF
3750 {
3751 perror_with_name (pip -> pathname);
3752 /* NOTREACHED */
3753 }
8fc2b417 3754 pid = pip->pid;
a39ad5ce
FF
3755 make_cleanup (close_proc_file, pip);
3756 }
cc221e76
FF
3757 else if (**argv != '\000')
3758 {
3759 error ("Unrecognized or ambiguous keyword `%s'.", *argv);
3760 }
3761 argv++;
a39ad5ce 3762 }
35f5886e 3763 }
a39ad5ce
FF
3764
3765 /* If we don't have a valid open process at this point, then we have no
3766 inferior or didn't specify a specific pid. */
3767
de43d7d0 3768 if (!pip)
35f5886e 3769 {
6fe90fc8
JK
3770 error ("\
3771No process. Start debugging a program or specify an explicit process ID.");
35f5886e 3772 }
a39ad5ce 3773 if (ioctl (pip -> fd, PIOCSTATUS, &(pip -> prstatus)) < 0)
35f5886e 3774 {
a39ad5ce
FF
3775 print_sys_errmsg (pip -> pathname, errno);
3776 error ("PIOCSTATUS failed");
35f5886e 3777 }
a39ad5ce 3778
8fc2b417
SG
3779#ifdef PIOCLWPIDS
3780 nlwp = pip->prstatus.pr_nlwp;
3781 lwps = alloca ((2 * nlwp + 2) * sizeof (id_t));
cc221e76 3782
8fc2b417 3783 if (ioctl (pip->fd, PIOCLWPIDS, lwps))
cc221e76 3784 {
8fc2b417
SG
3785 print_sys_errmsg (pip -> pathname, errno);
3786 error ("PIOCSTATUS failed");
cc221e76 3787 }
8fc2b417
SG
3788#else /* PIOCLWPIDS */
3789 nlwp = 1;
47ef0da5 3790 lwps = alloca ((2 * nlwp + 2) * sizeof *lwps);
8fc2b417
SG
3791 lwps[0] = 0;
3792#endif /* PIOCLWPIDS */
3793
3794 for (; nlwp > 0; nlwp--, lwps++)
cc221e76 3795 {
8fc2b417
SG
3796 pip = find_procinfo ((*lwps << 16) | pid, 1);
3797
3798 if (!pip)
3799 {
3800 pip = (struct procinfo *) xmalloc (sizeof (struct procinfo));
3801 memset (pip, 0, sizeof (*pip));
3802 if (!open_proc_file ((*lwps << 16) | pid, pip, O_RDONLY))
3803 continue;
3804
3805 make_cleanup (close_proc_file, pip);
3806
3807 if (ioctl (pip -> fd, PIOCSTATUS, &(pip -> prstatus)) < 0)
3808 {
3809 print_sys_errmsg (pip -> pathname, errno);
3810 error ("PIOCSTATUS failed");
3811 }
3812 }
3813
3814 /* Print verbose information of the requested type(s), or just a summary
3815 of the information for all types. */
3816
3817 printf_filtered ("\nInformation for %s.%d:\n\n", pip -> pathname, *lwps);
3818 if (summary || all || flags)
3819 {
3820 info_proc_flags (pip, summary);
3821 }
3822 if (summary || all)
3823 {
3824 info_proc_stop (pip, summary);
3825 }
3826 if (summary || all || signals || faults)
3827 {
3828 info_proc_siginfo (pip, summary);
3829 }
3830 if (summary || all || syscalls)
3831 {
3832 info_proc_syscalls (pip, summary);
3833 }
3834 if (summary || all || mappings)
3835 {
3836 info_proc_mappings (pip, summary);
3837 }
3838 if (summary || all || signals)
3839 {
3840 info_proc_signals (pip, summary);
3841 }
3842 if (summary || all || faults)
3843 {
3844 info_proc_faults (pip, summary);
3845 }
3846 printf_filtered ("\n");
3847
3848 /* All done, deal with closing any temporary process info structure,
3849 freeing temporary memory , etc. */
3850
3851 do_cleanups (old_chain);
cc221e76 3852 }
8fc2b417
SG
3853}
3854
3855/*
3856
3857LOCAL FUNCTION
3858
3859 modify_inherit_on_fork_flag - Change the inherit-on-fork flag
3860
3861SYNOPSIS
3862
3863 void modify_inherit_on_fork_flag (fd, flag)
3864
3865DESCRIPTION
3866
3867 Call this routine to modify the inherit-on-fork flag. This routine is
3868 just a nice wrapper to hide the #ifdefs needed by various systems to
3869 control this flag.
3870
3871 */
3872
3873static void
3874modify_inherit_on_fork_flag (fd, flag)
3875 int fd;
3876 int flag;
3877{
b607efe7 3878#ifdef PIOCSET
8fc2b417 3879 long pr_flags;
b607efe7 3880#endif
8fc2b417
SG
3881 int retval;
3882
3883#ifdef PIOCSET /* New method */
3884 pr_flags = PR_FORK;
3885 if (flag)
3886 retval = ioctl (fd, PIOCSET, &pr_flags);
3887 else
3888 retval = ioctl (fd, PIOCRESET, &pr_flags);
3889
3890#else
3891#ifdef PIOCSFORK /* Original method */
3892 if (flag)
3893 retval = ioctl (fd, PIOCSFORK, NULL);
3894 else
3895 retval = ioctl (fd, PIOCRFORK, NULL);
3896#else
3897 Neither PR_FORK nor PIOCSFORK exist!!!
3898#endif
3899#endif
3900
3901 if (!retval)
3902 return;
3903
3904 print_sys_errmsg ("modify_inherit_on_fork_flag", errno);
3905 error ("PIOCSFORK or PR_FORK modification failed");
3906}
3907
3908/*
3909
3910LOCAL FUNCTION
3911
3912 modify_run_on_last_close_flag - Change the run-on-last-close flag
3913
3914SYNOPSIS
3915
3916 void modify_run_on_last_close_flag (fd, flag)
3917
3918DESCRIPTION
3919
3920 Call this routine to modify the run-on-last-close flag. This routine
3921 is just a nice wrapper to hide the #ifdefs needed by various systems to
3922 control this flag.
3923
3924 */
3925
3926static void
3927modify_run_on_last_close_flag (fd, flag)
3928 int fd;
3929 int flag;
3930{
b607efe7 3931#ifdef PIOCSET
8fc2b417 3932 long pr_flags;
b607efe7 3933#endif
8fc2b417
SG
3934 int retval;
3935
3936#ifdef PIOCSET /* New method */
3937 pr_flags = PR_RLC;
3938 if (flag)
3939 retval = ioctl (fd, PIOCSET, &pr_flags);
3940 else
3941 retval = ioctl (fd, PIOCRESET, &pr_flags);
3942
3943#else
3944#ifdef PIOCSRLC /* Original method */
3945 if (flag)
3946 retval = ioctl (fd, PIOCSRLC, NULL);
3947 else
3948 retval = ioctl (fd, PIOCRRLC, NULL);
3949#else
3950 Neither PR_RLC nor PIOCSRLC exist!!!
3951#endif
3952#endif
3953
3954 if (!retval)
3955 return;
3956
3957 print_sys_errmsg ("modify_run_on_last_close_flag", errno);
3958 error ("PIOCSRLC or PR_RLC modification failed");
3959}
3960
3961/*
3962
3963LOCAL FUNCTION
3964
3965 procfs_clear_syscall_trap -- Deletes the trap for the specified system call.
3966
3967SYNOPSIS
3968
3969 void procfs_clear_syscall_trap (struct procinfo *, int syscall_num, int errok)
3970
3971DESCRIPTION
3972
3973 This function function disables traps for the specified system call.
3974 errok is non-zero if errors should be ignored.
3975 */
3976
3977static void
3978procfs_clear_syscall_trap (pi, syscall_num, errok)
3979 struct procinfo *pi;
3980 int syscall_num;
3981 int errok;
3982{
3983 sysset_t sysset;
3984 int goterr, i;
3985
3986 goterr = ioctl (pi->fd, PIOCGENTRY, &sysset) < 0;
3987
3988 if (goterr && !errok)
cc221e76 3989 {
8fc2b417
SG
3990 print_sys_errmsg (pi->pathname, errno);
3991 error ("PIOCGENTRY failed");
cc221e76 3992 }
8fc2b417
SG
3993
3994 if (!goterr)
cc221e76 3995 {
8fc2b417
SG
3996 prdelset (&sysset, syscall_num);
3997
3998 if ((ioctl (pi->fd, PIOCSENTRY, &sysset) < 0) && !errok)
3999 {
4000 print_sys_errmsg (pi->pathname, errno);
4001 error ("PIOCSENTRY failed");
4002 }
cc221e76 4003 }
8fc2b417
SG
4004
4005 goterr = ioctl (pi->fd, PIOCGEXIT, &sysset) < 0;
4006
4007 if (goterr && !errok)
cc221e76 4008 {
8fc2b417
SG
4009 procfs_clear_syscall_trap (pi, syscall_num, 1);
4010 print_sys_errmsg (pi->pathname, errno);
4011 error ("PIOCGEXIT failed");
cc221e76 4012 }
8fc2b417
SG
4013
4014 if (!goterr)
cc221e76 4015 {
8fc2b417
SG
4016 praddset (&sysset, syscall_num);
4017
4018 if ((ioctl (pi->fd, PIOCSEXIT, &sysset) < 0) && !errok)
4019 {
4020 procfs_clear_syscall_trap (pi, syscall_num, 1);
4021 print_sys_errmsg (pi->pathname, errno);
4022 error ("PIOCSEXIT failed");
4023 }
cc221e76 4024 }
8fc2b417
SG
4025
4026 if (!pi->syscall_handlers)
cc221e76 4027 {
8fc2b417
SG
4028 if (!errok)
4029 error ("procfs_clear_syscall_trap: syscall_handlers is empty");
4030 return;
cc221e76 4031 }
a39ad5ce 4032
8fc2b417 4033 /* Remove handler func from the handler list */
a39ad5ce 4034
8fc2b417
SG
4035 for (i = 0; i < pi->num_syscall_handlers; i++)
4036 if (pi->syscall_handlers[i].syscall_num == syscall_num)
4037 {
4038 if (i + 1 != pi->num_syscall_handlers)
4039 { /* Not the last entry.
4040 Move subsequent entries fwd. */
4041 memcpy (&pi->syscall_handlers[i], &pi->syscall_handlers[i + 1],
4042 (pi->num_syscall_handlers - i - 1)
4043 * sizeof (struct procfs_syscall_handler));
4044 }
4045
4046 pi->syscall_handlers = xrealloc (pi->syscall_handlers,
4047 (pi->num_syscall_handlers - 1)
4048 * sizeof (struct procfs_syscall_handler));
4049 pi->num_syscall_handlers--;
4050 return;
4051 }
4052
4053 if (!errok)
4054 error ("procfs_clear_syscall_trap: Couldn't find handler for sys call %d",
4055 syscall_num);
a39ad5ce
FF
4056}
4057
de43d7d0
SG
4058/*
4059
4060LOCAL FUNCTION
4061
8fc2b417
SG
4062 procfs_set_syscall_trap -- arrange for a function to be called when the
4063 child executes the specified system call.
de43d7d0
SG
4064
4065SYNOPSIS
4066
8fc2b417
SG
4067 void procfs_set_syscall_trap (struct procinfo *, int syscall_num, int flags,
4068 syscall_func_t *function)
de43d7d0
SG
4069
4070DESCRIPTION
4071
8fc2b417
SG
4072 This function sets up an entry and/or exit trap for the specified system
4073 call. When the child executes the specified system call, your function
4074 will be called with the call #, a flag that indicates entry or exit, and
4075 pointers to rtnval and statval (which are used by procfs_wait). The
4076 function should return non-zero if something interesting happened, zero
4077 otherwise.
de43d7d0
SG
4078 */
4079
4080static void
8fc2b417 4081procfs_set_syscall_trap (pi, syscall_num, flags, func)
de43d7d0 4082 struct procinfo *pi;
8fc2b417
SG
4083 int syscall_num;
4084 int flags;
4085 syscall_func_t *func;
de43d7d0 4086{
8fc2b417 4087 sysset_t sysset;
de43d7d0 4088
8fc2b417 4089 if (flags & PROCFS_SYSCALL_ENTRY)
de43d7d0 4090 {
8fc2b417
SG
4091 if (ioctl (pi->fd, PIOCGENTRY, &sysset) < 0)
4092 {
4093 print_sys_errmsg (pi->pathname, errno);
4094 error ("PIOCGENTRY failed");
4095 }
4096
4097 praddset (&sysset, syscall_num);
4098
4099 if (ioctl (pi->fd, PIOCSENTRY, &sysset) < 0)
4100 {
4101 print_sys_errmsg (pi->pathname, errno);
4102 error ("PIOCSENTRY failed");
4103 }
de43d7d0
SG
4104 }
4105
8fc2b417
SG
4106 if (flags & PROCFS_SYSCALL_EXIT)
4107 {
4108 if (ioctl (pi->fd, PIOCGEXIT, &sysset) < 0)
4109 {
4110 procfs_clear_syscall_trap (pi, syscall_num, 1);
4111 print_sys_errmsg (pi->pathname, errno);
4112 error ("PIOCGEXIT failed");
4113 }
de43d7d0 4114
8fc2b417 4115 praddset (&sysset, syscall_num);
eca4a350 4116
8fc2b417
SG
4117 if (ioctl (pi->fd, PIOCSEXIT, &sysset) < 0)
4118 {
4119 procfs_clear_syscall_trap (pi, syscall_num, 1);
4120 print_sys_errmsg (pi->pathname, errno);
4121 error ("PIOCSEXIT failed");
4122 }
4123 }
eca4a350 4124
8fc2b417 4125 if (!pi->syscall_handlers)
de43d7d0 4126 {
8fc2b417
SG
4127 pi->syscall_handlers = xmalloc (sizeof (struct procfs_syscall_handler));
4128 pi->syscall_handlers[0].syscall_num = syscall_num;
4129 pi->syscall_handlers[0].func = func;
4130 pi->num_syscall_handlers = 1;
de43d7d0 4131 }
8fc2b417
SG
4132 else
4133 {
4134 int i;
de43d7d0 4135
8fc2b417
SG
4136 for (i = 0; i < pi->num_syscall_handlers; i++)
4137 if (pi->syscall_handlers[i].syscall_num == syscall_num)
4138 {
4139 pi->syscall_handlers[i].func = func;
4140 return;
4141 }
de43d7d0 4142
8fc2b417
SG
4143 pi->syscall_handlers = xrealloc (pi->syscall_handlers, (i + 1)
4144 * sizeof (struct procfs_syscall_handler));
4145 pi->syscall_handlers[i].syscall_num = syscall_num;
4146 pi->syscall_handlers[i].func = func;
4147 pi->num_syscall_handlers++;
4148 }
de43d7d0 4149}
8fc2b417
SG
4150
4151#ifdef SYS_lwp_create
4152
4153/*
4154
4155LOCAL FUNCTION
4156
4157 procfs_lwp_creation_handler - handle exit from the _lwp_create syscall
4158
4159SYNOPSIS
4160
4161 int procfs_lwp_creation_handler (pi, syscall_num, why, rtnvalp, statvalp)
4162
4163DESCRIPTION
4164
4165 This routine is called both when an inferior process and it's new lwp
4166 are about to finish a _lwp_create() system call. This is the system
4167 call that Solaris uses to create a lightweight process. When the
4168 target process gets this event, we can look at sysarg[2] to find the
4169 new childs lwp ID, and create a procinfo struct from that. After that,
4170 we pretend that we got a SIGTRAP, and return non-zero to tell
4171 procfs_wait to wake up. Subsequently, wait_for_inferior gets woken up,
4172 sees the new process and continues it.
4173
4174 When we see the child exiting from lwp_create, we just contine it,
4175 since everything was handled when the parent trapped.
4176
4177NOTES
4178 In effect, we are only paying attention to the parent's completion of
4179 the lwp_create syscall. If we only paid attention to the child
4180 instead, then we wouldn't detect the creation of a suspended thread.
4181 */
4182
4183static int
4184procfs_lwp_creation_handler (pi, syscall_num, why, rtnvalp, statvalp)
4185 struct procinfo *pi;
4186 int syscall_num;
4187 int why;
4188 int *rtnvalp;
4189 int *statvalp;
4190{
4191 int lwp_id;
4192 struct procinfo *childpi;
4193
4194 /* We've just detected the completion of an lwp_create system call. Now we
4195 need to setup a procinfo struct for this thread, and notify the thread
4196 system of the new arrival. */
4197
4198 /* If lwp_create failed, then nothing interesting happened. Continue the
4199 process and go back to sleep. */
4200
4201 if (pi->prstatus.pr_reg[R_PSR] & PS_FLAG_CARRY)
4202 { /* _lwp_create failed */
4203 pi->prrun.pr_flags &= PRSTEP;
4204 pi->prrun.pr_flags |= PRCFAULT;
4205
4206 if (ioctl (pi->fd, PIOCRUN, &pi->prrun) != 0)
4207 perror_with_name (pi->pathname);
4208
4209 return 0;
4210 }
4211
4212 /* At this point, the new thread is stopped at it's first instruction, and
4213 the parent is stopped at the exit from lwp_create. */
4214
4215 if (pi->new_child) /* Child? */
4216 { /* Yes, just continue it */
4217 pi->prrun.pr_flags &= PRSTEP;
4218 pi->prrun.pr_flags |= PRCFAULT;
4219
4220 if ((pi->prstatus.pr_flags & PR_ISTOP)
4221 && ioctl (pi->fd, PIOCRUN, &pi->prrun) != 0)
4222 perror_with_name (pi->pathname);
4223
4224 pi->new_child = 0; /* No longer new */
4225
4226 return 0;
4227 }
4228
4229 /* We're the proud parent of a new thread. Setup an exit trap for lwp_create
4230 in the child and continue the parent. */
4231
4232 /* Third arg is pointer to new thread id. */
4233 lwp_id = read_memory_integer (pi->prstatus.pr_sysarg[2], sizeof (int));
4234
4235 lwp_id = (lwp_id << 16) | PIDGET (pi->pid);
4236
4237 childpi = create_procinfo (lwp_id);
4238
4239 /* The new process has actually inherited the lwp_create syscall trap from
4240 it's parent, but we still have to call this to register a handler for
4241 that child. */
4242
4243 procfs_set_syscall_trap (childpi, SYS_lwp_create, PROCFS_SYSCALL_EXIT,
4244 procfs_lwp_creation_handler);
4245
4246 childpi->new_child = 1; /* Flag this as an unseen child process */
4247
4248 *rtnvalp = lwp_id; /* the new arrival. */
4249 *statvalp = (SIGTRAP << 8) | 0177;
4250
4251 return 1;
4252}
4253#endif /* SYS_lwp_create */
de43d7d0 4254
3fbdd536
JG
4255/* Fork an inferior process, and start debugging it with /proc. */
4256
4257static void
4258procfs_create_inferior (exec_file, allargs, env)
4259 char *exec_file;
4260 char *allargs;
4261 char **env;
4262{
08f74b92
JK
4263 char *shell_file = getenv ("SHELL");
4264 char *tryname;
4265 if (shell_file != NULL && strchr (shell_file, '/') == NULL)
4266 {
4267
4268 /* We will be looking down the PATH to find shell_file. If we
4269 just do this the normal way (via execlp, which operates by
4270 attempting an exec for each element of the PATH until it
4271 finds one which succeeds), then there will be an exec for
4272 each failed attempt, each of which will cause a PR_SYSEXIT
4273 stop, and we won't know how to distinguish the PR_SYSEXIT's
4274 for these failed execs with the ones for successful execs
4275 (whether the exec has succeeded is stored at that time in the
4276 carry bit or some such architecture-specific and
4277 non-ABI-specified place).
4278
4279 So I can't think of anything better than to search the PATH
4280 now. This has several disadvantages: (1) There is a race
4281 condition; if we find a file now and it is deleted before we
4282 exec it, we lose, even if the deletion leaves a valid file
4283 further down in the PATH, (2) there is no way to know exactly
4284 what an executable (in the sense of "capable of being
4285 exec'd") file is. Using access() loses because it may lose
4286 if the caller is the superuser; failing to use it loses if
4287 there are ACLs or some such. */
4288
4289 char *p;
4290 char *p1;
f93b941b
JK
4291 /* FIXME-maybe: might want "set path" command so user can change what
4292 path is used from within GDB. */
08f74b92
JK
4293 char *path = getenv ("PATH");
4294 int len;
4295 struct stat statbuf;
4296
4297 if (path == NULL)
4298 path = "/bin:/usr/bin";
4299
4300 tryname = alloca (strlen (path) + strlen (shell_file) + 2);
4301 for (p = path; p != NULL; p = p1 ? p1 + 1: NULL)
4302 {
4303 p1 = strchr (p, ':');
4304 if (p1 != NULL)
4305 len = p1 - p;
4306 else
4307 len = strlen (p);
4308 strncpy (tryname, p, len);
4309 tryname[len] = '\0';
4310 strcat (tryname, "/");
4311 strcat (tryname, shell_file);
4312 if (access (tryname, X_OK) < 0)
4313 continue;
4314 if (stat (tryname, &statbuf) < 0)
4315 continue;
4316 if (!S_ISREG (statbuf.st_mode))
4317 /* We certainly need to reject directories. I'm not quite
4318 as sure about FIFOs, sockets, etc., but I kind of doubt
4319 that people want to exec() these things. */
4320 continue;
4321 break;
4322 }
4323 if (p == NULL)
4324 /* Not found. This must be an error rather than merely passing
4325 the file to execlp(), because execlp() would try all the
4326 exec()s, causing GDB to get confused. */
4327 error ("Can't find shell %s in PATH", shell_file);
4328
4329 shell_file = tryname;
4330 }
4331
3fbdd536 4332 fork_inferior (exec_file, allargs, env,
08f74b92
JK
4333 proc_set_exec_trap, procfs_init_inferior, shell_file);
4334
3fbdd536
JG
4335 /* We are at the first instruction we care about. */
4336 /* Pedal to the metal... */
de43d7d0 4337
67ac9759 4338 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_0, 0);
3fbdd536
JG
4339}
4340
4341/* Clean up after the inferior dies. */
4342
4343static void
4344procfs_mourn_inferior ()
4345{
fb63d460 4346 struct procinfo *pi;
cd4104e0 4347 struct procinfo *next_pi;
fb63d460 4348
cd4104e0
TL
4349 for (pi = procinfo_list; pi; pi = next_pi)
4350 {
4351 next_pi = pi->next;
4352 unconditionally_kill_inferior (pi);
4353 }
fb63d460 4354
3fbdd536
JG
4355 unpush_target (&procfs_ops);
4356 generic_mourn_inferior ();
4357}
4358
cd4104e0 4359
3fbdd536
JG
4360/* Mark our target-struct as eligible for stray "run" and "attach" commands. */
4361static int
4362procfs_can_run ()
4363{
8fc2b417
SG
4364 /* This variable is controlled by modules that sit atop procfs that may layer
4365 their own process structure atop that provided here. sol-thread.c does
4366 this because of the Solaris two-level thread model. */
4367
4368 return !procfs_suppress_run;
3fbdd536 4369}
f5a8f1a6 4370#ifdef TARGET_HAS_HARDWARE_WATCHPOINTS
999dd04b
JL
4371\f
4372/* Insert a watchpoint */
4373int
4374procfs_set_watchpoint(pid, addr, len, rw)
4375 int pid;
4376 CORE_ADDR addr;
4377 int len;
4378 int rw;
4379{
4380 struct procinfo *pi;
4381 prwatch_t wpt;
4382
4383 pi = find_procinfo (pid == -1 ? inferior_pid : pid, 0);
4384 wpt.pr_vaddr = (caddr_t)addr;
4385 wpt.pr_size = len;
4386 wpt.pr_wflags = ((rw & 1) ? MA_READ : 0) | ((rw & 2) ? MA_WRITE : 0);
4387 if (ioctl (pi->fd, PIOCSWATCH, &wpt) < 0)
4388 {
4389 if (errno == E2BIG)
4390 return -1;
4391 /* Currently it sometimes happens that the same watchpoint gets
4392 deleted twice - don't die in this case (FIXME please) */
4393 if (errno == ESRCH && len == 0)
4394 return 0;
4395 print_sys_errmsg (pi->pathname, errno);
4396 error ("PIOCSWATCH failed");
4397 }
4398 return 0;
4399}
4400
4401int
4402procfs_stopped_by_watchpoint(pid)
4403 int pid;
4404{
4405 struct procinfo *pi;
4406 short what;
4407 short why;
4408
4409 pi = find_procinfo (pid == -1 ? inferior_pid : pid, 0);
4410 if (pi->prstatus.pr_flags & (PR_STOPPED | PR_ISTOP))
4411 {
4412 why = pi->prstatus.pr_why;
4413 what = pi->prstatus.pr_what;
4414 if (why == PR_FAULTED
6bc194d2 4415#if defined (FLTWATCH) && defined (FLTKWATCH)
255181a9 4416 && (what == FLTWATCH || what == FLTKWATCH)
6bc194d2
JL
4417#else
4418#ifdef FLTWATCH
4419 && (what == FLTWATCH)
4420#endif
4421#ifdef FLTKWATCH
4422 && (what == FLTKWATCH)
4423#endif
72b8ca51 4424#endif
6bc194d2 4425 )
999dd04b
JL
4426 return what;
4427 }
4428 return 0;
4429}
6bc194d2 4430#endif
999dd04b 4431
8fc2b417
SG
4432/* Why is this necessary? Shouldn't dead threads just be removed from the
4433 thread database? */
4434
9b33e492 4435static int
8fc2b417
SG
4436procfs_thread_alive (pid)
4437 int pid;
4438{
4439 return 1;
4440}
4441
78b459a7
SG
4442/* Send a SIGINT to the process group. This acts just like the user typed a
4443 ^C on the controlling terminal.
4444
4445 XXX - This may not be correct for all systems. Some may want to use
4446 killpg() instead of kill (-pgrp). */
4447
9b33e492 4448static void
2592eef8 4449procfs_stop ()
78b459a7
SG
4450{
4451 extern pid_t inferior_process_group;
4452
4453 kill (-inferior_process_group, SIGINT);
4454}
9b33e492
SG
4455\f
4456/* Convert a pid to printable form. */
78b459a7 4457
9b33e492
SG
4458#ifdef TIDGET
4459char *
4460procfs_pid_to_str (pid)
4461 int pid;
4462{
4463 static char buf[100];
4464
4465 sprintf (buf, "Kernel thread %d", TIDGET (pid));
4466
4467 return buf;
4468}
4469#endif /* TIDGET */
3fbdd536
JG
4470\f
4471struct target_ops procfs_ops = {
4472 "procfs", /* to_shortname */
4473 "Unix /proc child process", /* to_longname */
4474 "Unix /proc child process (started by the \"run\" command).", /* to_doc */
4475 procfs_open, /* to_open */
4476 0, /* to_close */
4477 procfs_attach, /* to_attach */
4478 procfs_detach, /* to_detach */
4479 procfs_resume, /* to_resume */
4480 procfs_wait, /* to_wait */
4481 procfs_fetch_registers, /* to_fetch_registers */
4482 procfs_store_registers, /* to_store_registers */
4483 procfs_prepare_to_store, /* to_prepare_to_store */
4484 procfs_xfer_memory, /* to_xfer_memory */
4485 procfs_files_info, /* to_files_info */
4486 memory_insert_breakpoint, /* to_insert_breakpoint */
4487 memory_remove_breakpoint, /* to_remove_breakpoint */
4488 terminal_init_inferior, /* to_terminal_init */
4489 terminal_inferior, /* to_terminal_inferior */
4490 terminal_ours_for_output, /* to_terminal_ours_for_output */
4491 terminal_ours, /* to_terminal_ours */
4492 child_terminal_info, /* to_terminal_info */
4493 procfs_kill_inferior, /* to_kill */
4494 0, /* to_load */
4495 0, /* to_lookup_symbol */
4496 procfs_create_inferior, /* to_create_inferior */
4497 procfs_mourn_inferior, /* to_mourn_inferior */
4498 procfs_can_run, /* to_can_run */
3950a34e 4499 procfs_notice_signals, /* to_notice_signals */
8fc2b417 4500 procfs_thread_alive, /* to_thread_alive */
2592eef8 4501 procfs_stop, /* to_stop */
3fbdd536
JG
4502 process_stratum, /* to_stratum */
4503 0, /* to_next */
4504 1, /* to_has_all_memory */
4505 1, /* to_has_memory */
4506 1, /* to_has_stack */
4507 1, /* to_has_registers */
4508 1, /* to_has_execution */
4509 0, /* sections */
4510 0, /* sections_end */
4511 OPS_MAGIC /* to_magic */
4512};
4513
3fbdd536
JG
4514void
4515_initialize_procfs ()
4516{
2592eef8
PS
4517#ifdef HAVE_OPTIONAL_PROC_FS
4518 char procname[32];
4519 int fd;
4520
4521 /* If we have an optional /proc filesystem (e.g. under OSF/1),
4522 don't add procfs support if we cannot access the running
4523 GDB via /proc. */
4524 sprintf (procname, PROC_NAME_FMT, getpid ());
4525 if ((fd = open (procname, O_RDONLY)) < 0)
4526 return;
4527 close (fd);
4528#endif
4529
3fbdd536
JG
4530 add_target (&procfs_ops);
4531
4532 add_info ("proc", info_proc,
cc221e76
FF
4533"Show process status information using /proc entry.\n\
4534Specify process id or use current inferior by default.\n\
4535Specify keywords for detailed information; default is summary.\n\
4536Keywords are: `all', `faults', `flags', `id', `mappings', `signals',\n\
4537`status', `syscalls', and `times'.\n\
3fbdd536 4538Unambiguous abbreviations may be used.");
a39ad5ce 4539
cc221e76 4540 init_syscall_table ();
35f5886e 4541}
This page took 0.473016 seconds and 4 git commands to generate.