* gas/mn10300/other.s: Put parens around register
[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
1cb1b16c 1821#ifndef PIOCSSPCACT
8fc2b417
SG
1822 procfs_set_syscall_trap (pip, SYS_exit, PROCFS_SYSCALL_ENTRY,
1823 procfs_exit_handler);
1824
8fc2b417
SG
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
1cb1b16c 1837#endif /* PIOCSSPCACT */
8fc2b417
SG
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
1cb1b16c
PS
1985 exits from exec system calls because of the user level loader.
1986 Starting with OSF/1-4.0, tracing the entry to the exit system
1987 call no longer works. So we have to use PRFS_STOPTERM to trace
1988 termination of the inferior. */
2592eef8
PS
1989 {
1990 int prfs_flags;
1991
1992 if (ioctl (fd, PIOCGSPCACT, &prfs_flags) < 0)
1993 {
1994 perror (procname);
1995 gdb_flush (gdb_stderr);
1996 _exit (127);
1997 }
1cb1b16c 1998 prfs_flags |= PRFS_STOPEXEC | PRFS_STOPTERM;
2592eef8
PS
1999 if (ioctl (fd, PIOCSSPCACT, &prfs_flags) < 0)
2000 {
2001 perror (procname);
2002 gdb_flush (gdb_stderr);
2003 _exit (127);
2004 }
2005 }
1cb1b16c 2006#else /* PIOCSSPCACT */
cc221e76
FF
2007 /* GW: Rationale...
2008 Not all systems with /proc have all the exec* syscalls with the same
2009 names. On the SGI, for example, there is no SYS_exec, but there
2010 *is* a SYS_execv. So, we try to account for that. */
2011
407a8389 2012#ifdef SYS_exec
35f5886e 2013 praddset (&exitset, SYS_exec);
407a8389
SG
2014#endif
2015#ifdef SYS_execve
35f5886e 2016 praddset (&exitset, SYS_execve);
407a8389
SG
2017#endif
2018#ifdef SYS_execv
fb63d460 2019 praddset (&exitset, SYS_execv);
407a8389
SG
2020#endif
2021
35f5886e
FF
2022 if (ioctl (fd, PIOCSEXIT, &exitset) < 0)
2023 {
2024 perror (procname);
199b2450 2025 gdb_flush (gdb_stderr);
35f5886e
FF
2026 _exit (127);
2027 }
cc221e76 2028
fb63d460
SG
2029 praddset (&entryset, SYS_exit);
2030
2031 if (ioctl (fd, PIOCSENTRY, &entryset) < 0)
2032 {
2033 perror (procname);
199b2450 2034 gdb_flush (gdb_stderr);
fb63d460
SG
2035 _exit (126);
2036 }
1cb1b16c 2037#endif /* PIOCSSPCACT */
fb63d460 2038
cc221e76
FF
2039 /* Turn off inherit-on-fork flag so that all grand-children of gdb
2040 start with tracing flags cleared. */
2041
8fc2b417 2042 modify_inherit_on_fork_flag (fd, 0);
ec8ceca3
JG
2043
2044 /* Turn on run-on-last-close flag so that this process will not hang
2045 if GDB goes away for some reason. */
2046
8fc2b417
SG
2047 modify_run_on_last_close_flag (fd, 1);
2048
2049#ifdef PR_ASYNC
ec8ceca3 2050 {
8fc2b417
SG
2051 long pr_flags;
2052
2053/* Solaris needs this to make procfs treat all threads seperately. Without
2054 this, all threads halt whenever something happens to any thread. Since
2055 GDB wants to control all this itself, it needs to set PR_ASYNC. */
2056
2057 pr_flags = PR_ASYNC;
2058
2059 ioctl (fd, PIOCSET, &pr_flags);
ec8ceca3 2060 }
8fc2b417 2061#endif /* PR_ASYNC */
35f5886e
FF
2062}
2063
f8b76e70
FF
2064/*
2065
a39ad5ce
FF
2066GLOBAL FUNCTION
2067
2068 proc_iterate_over_mappings -- call function for every mapped space
2069
2070SYNOPSIS
2071
2072 int proc_iterate_over_mappings (int (*func)())
2073
2074DESCRIPTION
2075
2076 Given a pointer to a function, call that function for every
2077 mapped address space, passing it an open file descriptor for
2078 the file corresponding to that mapped address space (if any)
2079 and the base address of the mapped space. Quit when we hit
2080 the end of the mappings or the function returns nonzero.
2081 */
2082
2083int
1ab3bf1b
JG
2084proc_iterate_over_mappings (func)
2085 int (*func) PARAMS ((int, CORE_ADDR));
a39ad5ce
FF
2086{
2087 int nmap;
2088 int fd;
2089 int funcstat = 0;
2090 struct prmap *prmaps;
2091 struct prmap *prmap;
de43d7d0
SG
2092 struct procinfo *pi;
2093
2094 pi = current_procinfo;
a39ad5ce 2095
de43d7d0 2096 if (ioctl (pi->fd, PIOCNMAP, &nmap) == 0)
a39ad5ce 2097 {
1ab3bf1b 2098 prmaps = (struct prmap *) alloca ((nmap + 1) * sizeof (*prmaps));
de43d7d0 2099 if (ioctl (pi->fd, PIOCMAP, prmaps) == 0)
a39ad5ce
FF
2100 {
2101 for (prmap = prmaps; prmap -> pr_size && funcstat == 0; ++prmap)
2102 {
de43d7d0 2103 fd = proc_address_to_fd (pi, (CORE_ADDR) prmap -> pr_vaddr, 0);
1ab3bf1b 2104 funcstat = (*func) (fd, (CORE_ADDR) prmap -> pr_vaddr);
a39ad5ce
FF
2105 close (fd);
2106 }
2107 }
2108 }
2109 return (funcstat);
2110}
2111
3fbdd536 2112#if 0 /* Currently unused */
a39ad5ce
FF
2113/*
2114
f8b76e70
FF
2115GLOBAL FUNCTION
2116
2117 proc_base_address -- find base address for segment containing address
2118
2119SYNOPSIS
2120
2121 CORE_ADDR proc_base_address (CORE_ADDR addr)
2122
2123DESCRIPTION
2124
2125 Given an address of a location in the inferior, find and return
2126 the base address of the mapped segment containing that address.
2127
2128 This is used for example, by the shared library support code,
2129 where we have the pc value for some location in the shared library
2130 where we are stopped, and need to know the base address of the
2131 segment containing that address.
2132*/
2133
f8b76e70 2134CORE_ADDR
1ab3bf1b 2135proc_base_address (addr)
cc221e76 2136 CORE_ADDR addr;
f8b76e70
FF
2137{
2138 int nmap;
2139 struct prmap *prmaps;
2140 struct prmap *prmap;
2141 CORE_ADDR baseaddr = 0;
de43d7d0 2142 struct procinfo *pi;
f8b76e70 2143
de43d7d0
SG
2144 pi = current_procinfo;
2145
2146 if (ioctl (pi->fd, PIOCNMAP, &nmap) == 0)
f8b76e70 2147 {
1ab3bf1b 2148 prmaps = (struct prmap *) alloca ((nmap + 1) * sizeof (*prmaps));
de43d7d0 2149 if (ioctl (pi->fd, PIOCMAP, prmaps) == 0)
f8b76e70
FF
2150 {
2151 for (prmap = prmaps; prmap -> pr_size; ++prmap)
2152 {
2153 if ((prmap -> pr_vaddr <= (caddr_t) addr) &&
2154 (prmap -> pr_vaddr + prmap -> pr_size > (caddr_t) addr))
2155 {
2156 baseaddr = (CORE_ADDR) prmap -> pr_vaddr;
2157 break;
2158 }
2159 }
2160 }
2161 }
2162 return (baseaddr);
2163}
2164
1ab3bf1b
JG
2165#endif /* 0 */
2166
f8b76e70
FF
2167/*
2168
cc221e76 2169LOCAL FUNCTION
f8b76e70
FF
2170
2171 proc_address_to_fd -- return open fd for file mapped to address
2172
2173SYNOPSIS
2174
de43d7d0 2175 int proc_address_to_fd (struct procinfo *pi, CORE_ADDR addr, complain)
f8b76e70
FF
2176
2177DESCRIPTION
2178
2179 Given an address in the current inferior's address space, use the
2180 /proc interface to find an open file descriptor for the file that
2181 this address was mapped in from. Return -1 if there is no current
2182 inferior. Print a warning message if there is an inferior but
2183 the address corresponds to no file (IE a bogus address).
2184
2185*/
2186
1ab3bf1b 2187static int
de43d7d0
SG
2188proc_address_to_fd (pi, addr, complain)
2189 struct procinfo *pi;
1ab3bf1b
JG
2190 CORE_ADDR addr;
2191 int complain;
f8b76e70
FF
2192{
2193 int fd = -1;
2194
de43d7d0 2195 if ((fd = ioctl (pi->fd, PIOCOPENM, (caddr_t *) &addr)) < 0)
f8b76e70 2196 {
de43d7d0 2197 if (complain)
f8b76e70 2198 {
de43d7d0
SG
2199 print_sys_errmsg (pi->pathname, errno);
2200 warning ("can't find mapped file for address 0x%x", addr);
f8b76e70
FF
2201 }
2202 }
2203 return (fd);
2204}
2205
35f5886e 2206
3fbdd536
JG
2207/* Attach to process PID, then initialize for debugging it
2208 and wait for the trace-trap that results from attaching. */
2209
2210static void
2211procfs_attach (args, from_tty)
2212 char *args;
2213 int from_tty;
2214{
2215 char *exec_file;
2216 int pid;
2217
2218 if (!args)
2219 error_no_arg ("process-id to attach");
2220
2221 pid = atoi (args);
2222
2223 if (pid == getpid()) /* Trying to masturbate? */
2224 error ("I refuse to debug myself!");
2225
2226 if (from_tty)
2227 {
2228 exec_file = (char *) get_exec_file (0);
2229
2230 if (exec_file)
199b2450 2231 printf_unfiltered ("Attaching to program `%s', %s\n", exec_file, target_pid_to_str (pid));
3fbdd536 2232 else
199b2450 2233 printf_unfiltered ("Attaching to %s\n", target_pid_to_str (pid));
3fbdd536 2234
199b2450 2235 gdb_flush (gdb_stdout);
3fbdd536
JG
2236 }
2237
8fc2b417 2238 inferior_pid = pid = do_attach (pid);
3fbdd536
JG
2239 push_target (&procfs_ops);
2240}
2241
2242
2243/* Take a program previously attached to and detaches it.
2244 The program resumes execution and will no longer stop
2245 on signals, etc. We'd better not have left any breakpoints
2246 in the program or it'll die when it hits one. For this
2247 to work, it may be necessary for the process to have been
2248 previously attached. It *might* work if the program was
2249 started via the normal ptrace (PTRACE_TRACEME). */
2250
2251static void
2252procfs_detach (args, from_tty)
2253 char *args;
2254 int from_tty;
2255{
2256 int siggnal = 0;
2257
2258 if (from_tty)
2259 {
2260 char *exec_file = get_exec_file (0);
2261 if (exec_file == 0)
2262 exec_file = "";
199b2450 2263 printf_unfiltered ("Detaching from program: %s %s\n",
25286543 2264 exec_file, target_pid_to_str (inferior_pid));
199b2450 2265 gdb_flush (gdb_stdout);
3fbdd536
JG
2266 }
2267 if (args)
2268 siggnal = atoi (args);
2269
2270 do_detach (siggnal);
2271 inferior_pid = 0;
2272 unpush_target (&procfs_ops); /* Pop out of handling an inferior */
2273}
2274
2275/* Get ready to modify the registers array. On machines which store
2276 individual registers, this doesn't need to do anything. On machines
2277 which store all the registers in one fell swoop, this makes sure
2278 that registers contains all the registers from the program being
2279 debugged. */
2280
2281static void
2282procfs_prepare_to_store ()
2283{
2284#ifdef CHILD_PREPARE_TO_STORE
2285 CHILD_PREPARE_TO_STORE ();
2286#endif
2287}
2288
2289/* Print status information about what we're accessing. */
2290
2291static void
2292procfs_files_info (ignore)
2293 struct target_ops *ignore;
2294{
199b2450 2295 printf_unfiltered ("\tUsing the running image of %s %s via /proc.\n",
25286543 2296 attach_flag? "attached": "child", target_pid_to_str (inferior_pid));
3fbdd536
JG
2297}
2298
2299/* ARGSUSED */
2300static void
2301procfs_open (arg, from_tty)
2302 char *arg;
2303 int from_tty;
2304{
2305 error ("Use the \"run\" command to start a Unix child process.");
2306}
35f5886e
FF
2307
2308/*
2309
3fbdd536 2310LOCAL FUNCTION
35f5886e 2311
3fbdd536 2312 do_attach -- attach to an already existing process
35f5886e
FF
2313
2314SYNOPSIS
2315
3fbdd536 2316 int do_attach (int pid)
35f5886e
FF
2317
2318DESCRIPTION
2319
2320 Attach to an already existing process with the specified process
2321 id. If the process is not already stopped, query whether to
2322 stop it or not.
2323
2324NOTES
2325
2326 The option of stopping at attach time is specific to the /proc
2327 versions of gdb. Versions using ptrace force the attachee
ec8ceca3
JG
2328 to stop. (I have changed this version to do so, too. All you
2329 have to do is "continue" to make it go on. -- gnu@cygnus.com)
35f5886e
FF
2330
2331*/
2332
3fbdd536
JG
2333static int
2334do_attach (pid)
1ab3bf1b 2335 int pid;
35f5886e 2336{
de43d7d0
SG
2337 struct procinfo *pi;
2338
2339 pi = (struct procinfo *) xmalloc (sizeof (struct procinfo));
ec8ceca3 2340
de43d7d0 2341 if (!open_proc_file (pid, pi, O_RDWR))
35f5886e 2342 {
de43d7d0
SG
2343 free (pi);
2344 perror_with_name (pi->pathname);
35f5886e
FF
2345 /* NOTREACHED */
2346 }
2347
8fc2b417
SG
2348 pid = pi -> pid;
2349
de43d7d0
SG
2350 /* Add new process to process info list */
2351
2352 pi->next = procinfo_list;
2353 procinfo_list = pi;
2354
2355 add_fd (pi); /* Add to list for poll/select */
2356
35f5886e
FF
2357 /* Get current status of process and if it is not already stopped,
2358 then stop it. Remember whether or not it was stopped when we first
2359 examined it. */
2360
de43d7d0 2361 if (ioctl (pi->fd, PIOCSTATUS, &pi->prstatus) < 0)
35f5886e 2362 {
de43d7d0
SG
2363 print_sys_errmsg (pi->pathname, errno);
2364 close_proc_file (pi);
35f5886e
FF
2365 error ("PIOCSTATUS failed");
2366 }
de43d7d0 2367 if (pi->prstatus.pr_flags & (PR_STOPPED | PR_ISTOP))
35f5886e 2368 {
de43d7d0 2369 pi->was_stopped = 1;
35f5886e
FF
2370 }
2371 else
2372 {
de43d7d0 2373 pi->was_stopped = 0;
ec8ceca3 2374 if (1 || query ("Process is currently running, stop it? "))
35f5886e 2375 {
ec8ceca3 2376 /* Make it run again when we close it. */
8fc2b417
SG
2377
2378 modify_run_on_last_close_flag (pi->fd, 1);
2379
de43d7d0 2380 if (ioctl (pi->fd, PIOCSTOP, &pi->prstatus) < 0)
35f5886e 2381 {
de43d7d0
SG
2382 print_sys_errmsg (pi->pathname, errno);
2383 close_proc_file (pi);
35f5886e
FF
2384 error ("PIOCSTOP failed");
2385 }
de43d7d0 2386 pi->nopass_next_sigstop = 1;
d65eee73
FF
2387 }
2388 else
2389 {
199b2450 2390 printf_unfiltered ("Ok, gdb will wait for %s to stop.\n", target_pid_to_str (pid));
35f5886e
FF
2391 }
2392 }
ec8ceca3 2393
35f5886e
FF
2394 /* Remember some things about the inferior that we will, or might, change
2395 so that we can restore them when we detach. */
2396
de43d7d0
SG
2397 ioctl (pi->fd, PIOCGTRACE, &pi->saved_trace);
2398 ioctl (pi->fd, PIOCGHOLD, &pi->saved_sighold);
2399 ioctl (pi->fd, PIOCGFAULT, &pi->saved_fltset);
2400 ioctl (pi->fd, PIOCGENTRY, &pi->saved_entryset);
2401 ioctl (pi->fd, PIOCGEXIT, &pi->saved_exitset);
35f5886e
FF
2402
2403 /* Set up trace and fault sets, as gdb expects them. */
2404
de43d7d0
SG
2405 memset (&pi->prrun, 0, sizeof (pi->prrun));
2406 prfillset (&pi->prrun.pr_trace);
2407 procfs_notice_signals (pid);
2408 prfillset (&pi->prrun.pr_fault);
2409 prdelset (&pi->prrun.pr_fault, FLTPAGE);
2592eef8 2410
b9e58503
PS
2411#ifdef PROCFS_DONT_TRACE_FAULTS
2412 premptyset (&pi->prrun.pr_fault);
2592eef8
PS
2413#endif
2414
de43d7d0 2415 if (ioctl (pi->fd, PIOCSFAULT, &pi->prrun.pr_fault))
35f5886e 2416 {
f66f459f 2417 print_sys_errmsg ("PIOCSFAULT failed", errno);
35f5886e 2418 }
de43d7d0 2419 if (ioctl (pi->fd, PIOCSTRACE, &pi->prrun.pr_trace))
35f5886e 2420 {
f66f459f 2421 print_sys_errmsg ("PIOCSTRACE failed", errno);
35f5886e
FF
2422 }
2423 attach_flag = 1;
2424 return (pid);
2425}
2426
2427/*
2428
3fbdd536 2429LOCAL FUNCTION
35f5886e 2430
3fbdd536 2431 do_detach -- detach from an attached-to process
35f5886e
FF
2432
2433SYNOPSIS
2434
3fbdd536 2435 void do_detach (int signal)
35f5886e
FF
2436
2437DESCRIPTION
2438
2439 Detach from the current attachee.
2440
2441 If signal is non-zero, the attachee is started running again and sent
2442 the specified signal.
2443
2444 If signal is zero and the attachee was not already stopped when we
2445 attached to it, then we make it runnable again when we detach.
2446
2447 Otherwise, we query whether or not to make the attachee runnable
2448 again, since we may simply want to leave it in the state it was in
2449 when we attached.
2450
2451 We report any problems, but do not consider them errors, since we
2452 MUST detach even if some things don't seem to go right. This may not
2453 be the ideal situation. (FIXME).
2454 */
2455
3fbdd536
JG
2456static void
2457do_detach (signal)
1ab3bf1b 2458 int signal;
35f5886e 2459{
de43d7d0
SG
2460 struct procinfo *pi;
2461
2462 pi = current_procinfo;
ec8ceca3 2463
35f5886e
FF
2464 if (signal)
2465 {
de43d7d0 2466 set_proc_siginfo (pi, signal);
35f5886e 2467 }
de43d7d0 2468 if (ioctl (pi->fd, PIOCSEXIT, &pi->saved_exitset) < 0)
35f5886e 2469 {
de43d7d0 2470 print_sys_errmsg (pi->pathname, errno);
199b2450 2471 printf_unfiltered ("PIOCSEXIT failed.\n");
35f5886e 2472 }
de43d7d0 2473 if (ioctl (pi->fd, PIOCSENTRY, &pi->saved_entryset) < 0)
35f5886e 2474 {
de43d7d0 2475 print_sys_errmsg (pi->pathname, errno);
199b2450 2476 printf_unfiltered ("PIOCSENTRY failed.\n");
35f5886e 2477 }
de43d7d0 2478 if (ioctl (pi->fd, PIOCSTRACE, &pi->saved_trace) < 0)
35f5886e 2479 {
de43d7d0 2480 print_sys_errmsg (pi->pathname, errno);
199b2450 2481 printf_unfiltered ("PIOCSTRACE failed.\n");
35f5886e 2482 }
de43d7d0 2483 if (ioctl (pi->fd, PIOCSHOLD, &pi->saved_sighold) < 0)
cc221e76 2484 {
de43d7d0 2485 print_sys_errmsg (pi->pathname, errno);
199b2450 2486 printf_unfiltered ("PIOSCHOLD failed.\n");
cc221e76 2487 }
de43d7d0 2488 if (ioctl (pi->fd, PIOCSFAULT, &pi->saved_fltset) < 0)
35f5886e 2489 {
de43d7d0 2490 print_sys_errmsg (pi->pathname, errno);
199b2450 2491 printf_unfiltered ("PIOCSFAULT failed.\n");
35f5886e 2492 }
de43d7d0 2493 if (ioctl (pi->fd, PIOCSTATUS, &pi->prstatus) < 0)
35f5886e 2494 {
de43d7d0 2495 print_sys_errmsg (pi->pathname, errno);
199b2450 2496 printf_unfiltered ("PIOCSTATUS failed.\n");
35f5886e
FF
2497 }
2498 else
2499 {
de43d7d0 2500 if (signal || (pi->prstatus.pr_flags & (PR_STOPPED | PR_ISTOP)))
35f5886e 2501 {
de43d7d0 2502 if (signal || !pi->was_stopped ||
35f5886e
FF
2503 query ("Was stopped when attached, make it runnable again? "))
2504 {
2592eef8
PS
2505 /* Clear any pending signal if we want to detach without
2506 a signal. */
2507 if (signal == 0)
2508 set_proc_siginfo (pi, signal);
2509
ec8ceca3 2510 /* Clear any fault that might have stopped it. */
de43d7d0 2511 if (ioctl (pi->fd, PIOCCFAULT, 0))
eca4a350
SG
2512 {
2513 print_sys_errmsg (pi->pathname, errno);
199b2450 2514 printf_unfiltered ("PIOCCFAULT failed.\n");
eca4a350 2515 }
ec8ceca3
JG
2516
2517 /* Make it run again when we close it. */
8fc2b417
SG
2518
2519 modify_run_on_last_close_flag (pi->fd, 1);
35f5886e
FF
2520 }
2521 }
2522 }
de43d7d0 2523 close_proc_file (pi);
35f5886e
FF
2524 attach_flag = 0;
2525}
2526
45dc9be3
JK
2527/* emulate wait() as much as possible.
2528 Wait for child to do something. Return pid of child, or -1 in case
2529 of error; store status in *OURSTATUS.
2530
2531 Not sure why we can't
2532 just use wait(), but it seems to have problems when applied to a
2533 process being controlled with the /proc interface.
2534
2535 We have a race problem here with no obvious solution. We need to let
2536 the inferior run until it stops on an event of interest, which means
2537 that we need to use the PIOCWSTOP ioctl. However, we cannot use this
2538 ioctl if the process is already stopped on something that is not an
2539 event of interest, or the call will hang indefinitely. Thus we first
2540 use PIOCSTATUS to see if the process is not stopped. If not, then we
2541 use PIOCWSTOP. But during the window between the two, if the process
2542 stops for any reason that is not an event of interest (such as a job
2543 control signal) then gdb will hang. One possible workaround is to set
2544 an alarm to wake up every minute of so and check to see if the process
2545 is still running, and if so, then reissue the PIOCWSTOP. But this is
2546 a real kludge, so has not been implemented. FIXME: investigate
2547 alternatives.
2548
2549 FIXME: Investigate why wait() seems to have problems with programs
2550 being control by /proc routines. */
35f5886e 2551
3fbdd536 2552static int
45dc9be3 2553procfs_wait (pid, ourstatus)
de43d7d0 2554 int pid;
67ac9759 2555 struct target_waitstatus *ourstatus;
35f5886e
FF
2556{
2557 short what;
2558 short why;
2559 int statval = 0;
2560 int checkerr = 0;
2561 int rtnval = -1;
de43d7d0
SG
2562 struct procinfo *pi;
2563
2564 if (pid != -1) /* Non-specific process? */
2565 pi = NULL;
2566 else
2567 for (pi = procinfo_list; pi; pi = pi->next)
2568 if (pi->had_event)
2569 break;
2570
de43d7d0 2571 if (!pi)
eca4a350
SG
2572 {
2573 wait_again:
2574
8fc2b417
SG
2575 if (pi)
2576 pi->had_event = 0;
2577
eca4a350
SG
2578 pi = wait_fd ();
2579 }
de43d7d0
SG
2580
2581 if (pid != -1)
2582 for (pi = procinfo_list; pi; pi = pi->next)
2583 if (pi->pid == pid && pi->had_event)
2584 break;
2585
2586 if (!pi && !checkerr)
2587 goto wait_again;
2588
2589 if (!checkerr && !(pi->prstatus.pr_flags & (PR_STOPPED | PR_ISTOP)))
2590 {
2591 if (ioctl (pi->fd, PIOCWSTOP, &pi->prstatus) < 0)
2592 {
2593 checkerr++;
2594 }
35f5886e
FF
2595 }
2596 if (checkerr)
2597 {
2598 if (errno == ENOENT)
2599 {
2600 rtnval = wait (&statval);
2601 if (rtnval != inferior_pid)
2602 {
de43d7d0 2603 print_sys_errmsg (pi->pathname, errno);
35f5886e
FF
2604 error ("PIOCWSTOP, wait failed, returned %d", rtnval);
2605 /* NOTREACHED */
2606 }
2607 }
2608 else
2609 {
de43d7d0 2610 print_sys_errmsg (pi->pathname, errno);
35f5886e
FF
2611 error ("PIOCSTATUS or PIOCWSTOP failed.");
2612 /* NOTREACHED */
2613 }
2614 }
de43d7d0 2615 else if (pi->prstatus.pr_flags & (PR_STOPPED | PR_ISTOP))
35f5886e 2616 {
8fc2b417 2617 rtnval = pi->pid;
de43d7d0
SG
2618 why = pi->prstatus.pr_why;
2619 what = pi->prstatus.pr_what;
2620
2621 switch (why)
35f5886e 2622 {
de43d7d0 2623 case PR_SIGNALLED:
35f5886e 2624 statval = (what << 8) | 0177;
fb63d460
SG
2625 break;
2626 case PR_SYSENTRY:
de43d7d0 2627 case PR_SYSEXIT:
8fc2b417
SG
2628 {
2629 int i;
2630 int found_handler = 0;
de43d7d0 2631
8fc2b417
SG
2632 for (i = 0; i < pi->num_syscall_handlers; i++)
2633 if (pi->syscall_handlers[i].syscall_num == what)
de43d7d0 2634 {
8fc2b417
SG
2635 found_handler = 1;
2636 if (!pi->syscall_handlers[i].func (pi, what, why,
2637 &rtnval, &statval))
2638 goto wait_again;
de43d7d0 2639
8fc2b417 2640 break;
de43d7d0
SG
2641 }
2642
8fc2b417
SG
2643 if (!found_handler)
2644 if (why == PR_SYSENTRY)
2645 error ("PR_SYSENTRY, unhandled system call %d", what);
2646 else
2647 error ("PR_SYSEXIT, unhandled system call %d", what);
2648 }
de43d7d0 2649 break;
1cb1b16c
PS
2650#ifdef PR_DEAD
2651 case (short)PR_DEAD:
2652 {
2653 int dummy;
2654
2655 /* The inferior process is about to terminate.
2656 pr_what has the process's exit or return value.
2657 A PIOCRUN ioctl must be used to restart the process so it
2658 can finish exiting. */
2659
2660 pi->prrun.pr_flags = PRCFAULT;
2661
2662 if (ioctl (pi->fd, PIOCRUN, &pi->prrun) != 0)
2663 perror_with_name (pi->pathname);
2664
2665 if (wait (&dummy) < 0)
2666 rtnval = -1;
2667 statval = pi->prstatus.pr_what;
2668 }
2669 break;
2670#endif
de43d7d0 2671 case PR_REQUESTED:
35f5886e 2672 statval = (SIGSTOP << 8) | 0177;
de43d7d0
SG
2673 break;
2674 case PR_JOBCONTROL:
35f5886e 2675 statval = (what << 8) | 0177;
de43d7d0
SG
2676 break;
2677 case PR_FAULTED:
35f5886e
FF
2678 switch (what)
2679 {
e6b8a171 2680#ifdef FLTWATCH
999dd04b 2681 case FLTWATCH:
e6b8a171
JL
2682 statval = (SIGTRAP << 8) | 0177;
2683 break;
2684#endif
2685#ifdef FLTKWATCH
999dd04b 2686 case FLTKWATCH:
35f5886e
FF
2687 statval = (SIGTRAP << 8) | 0177;
2688 break;
e6b8a171 2689#endif
3f5e2fb5
JK
2690#ifndef FAULTED_USE_SIGINFO
2691 /* Irix, contrary to the documentation, fills in 0 for si_signo.
2692 Solaris fills in si_signo. I'm not sure about others. */
2693 case FLTPRIV:
2694 case FLTILL:
2695 statval = (SIGILL << 8) | 0177;
2696 break;
2697 case FLTBPT:
2698 case FLTTRACE:
2699 statval = (SIGTRAP << 8) | 0177;
2700 break;
2701 case FLTSTACK:
2702 case FLTACCESS:
2703 case FLTBOUNDS:
2704 statval = (SIGSEGV << 8) | 0177;
2705 break;
2706 case FLTIOVF:
2707 case FLTIZDIV:
2708 case FLTFPE:
2709 statval = (SIGFPE << 8) | 0177;
2710 break;
2711 case FLTPAGE: /* Recoverable page fault */
2712#endif /* not FAULTED_USE_SIGINFO */
35f5886e 2713 default:
890634ed
JK
2714 /* Use the signal which the kernel assigns. This is better than
2715 trying to second-guess it from the fault. In fact, I suspect
2716 that FLTACCESS can be either SIGSEGV or SIGBUS. */
2717 statval = ((pi->prstatus.pr_info.si_signo) << 8) | 0177;
2718 break;
35f5886e 2719 }
de43d7d0
SG
2720 break;
2721 default:
35f5886e 2722 error ("PIOCWSTOP, unknown why %d, what %d", why, what);
35f5886e 2723 }
de43d7d0
SG
2724/* Stop all the other threads when any of them stops. */
2725
2726 {
2727 struct procinfo *procinfo;
2728
2729 for (procinfo = procinfo_list; procinfo; procinfo = procinfo->next)
2730 {
2731 if (!procinfo->had_event)
8fc2b417
SG
2732 {
2733 /* A bug in Solaris (2.5) causes us to hang when trying to
2734 stop a stopped process. So, we have to check first in
2735 order to avoid the hang. */
2736 if (ioctl (procinfo->fd, PIOCSTATUS, &procinfo->prstatus) < 0)
2737 {
2738 print_sys_errmsg (procinfo->pathname, errno);
2739 error ("PIOCSTATUS failed");
2740 }
2741 if (!(procinfo->prstatus.pr_flags & PR_STOPPED))
2742 if (ioctl (procinfo->fd, PIOCSTOP, &procinfo->prstatus) < 0)
2743 {
2744 print_sys_errmsg (procinfo->pathname, errno);
2745 error ("PIOCSTOP failed");
2746 }
2747 }
de43d7d0
SG
2748 }
2749 }
35f5886e
FF
2750 }
2751 else
2752 {
2753 error ("PIOCWSTOP, stopped for unknown/unhandled reason, flags %#x",
de43d7d0 2754 pi->prstatus.pr_flags);
35f5886e 2755 }
3fbdd536 2756
67ac9759 2757 store_waitstatus (ourstatus, statval);
3fbdd536
JG
2758
2759 if (rtnval == -1) /* No more children to wait for */
2760 {
199b2450 2761 fprintf_unfiltered (gdb_stderr, "Child process unexpectedly missing.\n");
67ac9759
JK
2762 /* Claim it exited with unknown signal. */
2763 ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
2764 ourstatus->value.sig = TARGET_SIGNAL_UNKNOWN;
3fbdd536
JG
2765 return rtnval;
2766 }
2767
de43d7d0 2768 pi->had_event = 0; /* Indicate that we've seen this one */
35f5886e
FF
2769 return (rtnval);
2770}
2771
2772/*
2773
6b801388
FF
2774LOCAL FUNCTION
2775
2776 set_proc_siginfo - set a process's current signal info
2777
2778SYNOPSIS
2779
2780 void set_proc_siginfo (struct procinfo *pip, int signo);
2781
2782DESCRIPTION
2783
2784 Given a pointer to a process info struct in PIP and a signal number
2785 in SIGNO, set the process's current signal and its associated signal
2786 information. The signal will be delivered to the process immediately
2787 after execution is resumed, even if it is being held. In addition,
2788 this particular delivery will not cause another PR_SIGNALLED stop
2789 even if the signal is being traced.
2790
2791 If we are not delivering the same signal that the prstatus siginfo
2792 struct contains information about, then synthesize a siginfo struct
2793 to match the signal we are doing to deliver, make it of the type
2794 "generated by a user process", and send this synthesized copy. When
2795 used to set the inferior's signal state, this will be required if we
2796 are not currently stopped because of a traced signal, or if we decide
2797 to continue with a different signal.
2798
2799 Note that when continuing the inferior from a stop due to receipt
2800 of a traced signal, we either have set PRCSIG to clear the existing
2801 signal, or we have to call this function to do a PIOCSSIG with either
2802 the existing siginfo struct from pr_info, or one we have synthesized
2803 appropriately for the signal we want to deliver. Otherwise if the
2804 signal is still being traced, the inferior will immediately stop
2805 again.
2806
2807 See siginfo(5) for more details.
2808*/
2809
2810static void
2811set_proc_siginfo (pip, signo)
cc221e76
FF
2812 struct procinfo *pip;
2813 int signo;
6b801388
FF
2814{
2815 struct siginfo newsiginfo;
2816 struct siginfo *sip;
2817
2592eef8
PS
2818#ifdef PROCFS_DONT_PIOCSSIG_CURSIG
2819 /* With Alpha OSF/1 procfs, the kernel gets really confused if it
a1a0d974 2820 receives a PIOCSSIG with a signal identical to the current signal,
2592eef8
PS
2821 it messes up the current signal. Work around the kernel bug. */
2822 if (signo == pip -> prstatus.pr_cursig)
2823 return;
2824#endif
2825
de43d7d0 2826 if (signo == pip -> prstatus.pr_info.si_signo)
6b801388 2827 {
de43d7d0
SG
2828 sip = &pip -> prstatus.pr_info;
2829 }
2830 else
2831 {
2832 memset ((char *) &newsiginfo, 0, sizeof (newsiginfo));
2833 sip = &newsiginfo;
2834 sip -> si_signo = signo;
2835 sip -> si_code = 0;
2836 sip -> si_errno = 0;
2837 sip -> si_pid = getpid ();
2838 sip -> si_uid = getuid ();
2839 }
2840 if (ioctl (pip -> fd, PIOCSSIG, sip) < 0)
2841 {
2842 print_sys_errmsg (pip -> pathname, errno);
2843 warning ("PIOCSSIG failed");
6b801388
FF
2844 }
2845}
2846
25286543 2847/* Resume execution of process PID. If STEP is nozero, then
59ba57da
JK
2848 just single step it. If SIGNAL is nonzero, restart it with that
2849 signal activated. */
35f5886e 2850
3fbdd536 2851static void
25286543
SG
2852procfs_resume (pid, step, signo)
2853 int pid;
1ab3bf1b 2854 int step;
67ac9759 2855 enum target_signal signo;
35f5886e 2856{
59ba57da 2857 int signal_to_pass;
de43d7d0
SG
2858 struct procinfo *pi, *procinfo;
2859
2860 pi = find_procinfo (pid == -1 ? inferior_pid : pid, 0);
59ba57da 2861
35f5886e 2862 errno = 0;
de43d7d0 2863 pi->prrun.pr_flags = PRSTRACE | PRSFAULT | PRCFAULT;
99fd9e3e 2864
59ba57da
JK
2865#if 0
2866 /* It should not be necessary. If the user explicitly changes the value,
2867 value_assign calls write_register_bytes, which writes it. */
2868/* It may not be absolutely necessary to specify the PC value for
2869 restarting, but to be safe we use the value that gdb considers
2870 to be current. One case where this might be necessary is if the
2871 user explicitly changes the PC value that gdb considers to be
2872 current. FIXME: Investigate if this is necessary or not. */
2873
c3192172 2874#ifdef PRSVADDR_BROKEN
99fd9e3e
SG
2875/* Can't do this under Solaris running on a Sparc, as there seems to be no
2876 place to put nPC. In fact, if you use this, nPC seems to be set to some
2877 random garbage. We have to rely on the fact that PC and nPC have been
2878 written previously via PIOCSREG during a register flush. */
2879
de43d7d0
SG
2880 pi->prrun.pr_vaddr = (caddr_t) *(int *) &registers[REGISTER_BYTE (PC_REGNUM)];
2881 pi->prrun.pr_flags != PRSVADDR;
99fd9e3e 2882#endif
59ba57da
JK
2883#endif
2884
67ac9759 2885 if (signo == TARGET_SIGNAL_STOP && pi->nopass_next_sigstop)
59ba57da
JK
2886 /* When attaching to a child process, if we forced it to stop with
2887 a PIOCSTOP, then we will have set the nopass_next_sigstop flag.
2888 Upon resuming the first time after such a stop, we explicitly
2889 inhibit sending it another SIGSTOP, which would be the normal
2890 result of default signal handling. One potential drawback to
2891 this is that we will also ignore any attempt to by the user
2892 to explicitly continue after the attach with a SIGSTOP. Ultimately
2893 this problem should be dealt with by making the routines that
2894 deal with the inferior a little smarter, and possibly even allow
2895 an inferior to continue running at the same time as gdb. (FIXME?) */
2896 signal_to_pass = 0;
67ac9759 2897 else if (signo == TARGET_SIGNAL_TSTP
de43d7d0
SG
2898 && pi->prstatus.pr_cursig == SIGTSTP
2899 && pi->prstatus.pr_action.sa_handler == SIG_DFL)
59ba57da
JK
2900
2901 /* We are about to pass the inferior a SIGTSTP whose action is
2902 SIG_DFL. The SIG_DFL action for a SIGTSTP is to stop
2903 (notifying the parent via wait()), and then keep going from the
2904 same place when the parent is ready for you to keep going. So
2905 under the debugger, it should do nothing (as if the program had
2906 been stopped and then later resumed. Under ptrace, this
2907 happens for us, but under /proc, the system obligingly stops
2908 the process, and wait_for_inferior would have no way of
2909 distinguishing that type of stop (which indicates that we
2910 should just start it again), with a stop due to the pr_trace
2911 field of the prrun_t struct.
2912
2913 Note that if the SIGTSTP is being caught, we *do* need to pass it,
2914 because the handler needs to get executed. */
2915 signal_to_pass = 0;
2916 else
67ac9759 2917 signal_to_pass = target_signal_to_host (signo);
99fd9e3e 2918
59ba57da 2919 if (signal_to_pass)
35f5886e 2920 {
de43d7d0 2921 set_proc_siginfo (pi, signal_to_pass);
35f5886e
FF
2922 }
2923 else
2924 {
de43d7d0 2925 pi->prrun.pr_flags |= PRCSIG;
35f5886e 2926 }
de43d7d0 2927 pi->nopass_next_sigstop = 0;
35f5886e
FF
2928 if (step)
2929 {
de43d7d0 2930 pi->prrun.pr_flags |= PRSTEP;
35f5886e 2931 }
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 ((pi->prstatus.pr_flags & PR_ISTOP)
2937 && ioctl (pi->fd, PIOCRUN, &pi->prrun) != 0)
35f5886e 2938 {
de43d7d0 2939 perror_with_name (pi->pathname);
35f5886e
FF
2940 /* NOTREACHED */
2941 }
de43d7d0
SG
2942
2943 pi->had_event = 0;
2944
2945 /* Continue all the other threads that haven't had an event of
2946 interest. */
2947
2948 if (pid == -1)
2949 for (procinfo = procinfo_list; procinfo; procinfo = procinfo->next)
2950 {
2951 if (pi != procinfo && !procinfo->had_event)
2952 {
2953 procinfo->prrun.pr_flags &= PRSTEP;
2954 procinfo->prrun.pr_flags |= PRCFAULT | PRCSIG;
2955 ioctl (procinfo->fd, PIOCSTATUS, &procinfo->prstatus);
8fc2b417
SG
2956
2957 /* Don't try to start a process unless it's stopped on an
2958 `event of interest'. Doing so will cause errors. */
2959
2960 if ((procinfo->prstatus.pr_flags & PR_ISTOP)
2961 && ioctl (procinfo->fd, PIOCRUN, &procinfo->prrun) < 0)
de43d7d0
SG
2962 {
2963 if (ioctl (procinfo->fd, PIOCSTATUS, &procinfo->prstatus) < 0)
2964 {
199b2450 2965 fprintf_unfiltered(gdb_stderr, "PIOCSTATUS failed, errno=%d\n", errno);
de43d7d0
SG
2966 }
2967 print_sys_errmsg (procinfo->pathname, errno);
2968 error ("PIOCRUN failed");
2969 }
2970 ioctl (procinfo->fd, PIOCSTATUS, &procinfo->prstatus);
2971 }
2972 }
35f5886e
FF
2973}
2974
2975/*
2976
3fbdd536 2977LOCAL FUNCTION
35f5886e 2978
3fbdd536 2979 procfs_fetch_registers -- fetch current registers from inferior
35f5886e
FF
2980
2981SYNOPSIS
2982
3fbdd536 2983 void procfs_fetch_registers (int regno)
35f5886e
FF
2984
2985DESCRIPTION
2986
2987 Read the current values of the inferior's registers, both the
2988 general register set and floating point registers (if supported)
2989 and update gdb's idea of their current values.
2990
2991*/
2992
3fbdd536
JG
2993static void
2994procfs_fetch_registers (regno)
1ab3bf1b 2995 int regno;
35f5886e 2996{
de43d7d0
SG
2997 struct procinfo *pi;
2998
2999 pi = current_procinfo;
3000
3001 if (ioctl (pi->fd, PIOCGREG, &pi->gregset) != -1)
35f5886e 3002 {
de43d7d0 3003 supply_gregset (&pi->gregset);
35f5886e
FF
3004 }
3005#if defined (FP0_REGNUM)
de43d7d0 3006 if (ioctl (pi->fd, PIOCGFPREG, &pi->fpregset) != -1)
35f5886e 3007 {
de43d7d0 3008 supply_fpregset (&pi->fpregset);
35f5886e
FF
3009 }
3010#endif
3011}
3012
fb182850
FF
3013/*
3014
35f5886e
FF
3015LOCAL FUNCTION
3016
de43d7d0
SG
3017 proc_init_failed - called whenever /proc access initialization
3018fails
35f5886e
FF
3019
3020SYNOPSIS
3021
de43d7d0 3022 static void proc_init_failed (struct procinfo *pi, char *why)
35f5886e
FF
3023
3024DESCRIPTION
3025
3026 This function is called whenever initialization of access to a /proc
3027 entry fails. It prints a suitable error message, does some cleanup,
3028 and then invokes the standard error processing routine which dumps
3029 us back into the command loop.
3030 */
3031
3032static void
de43d7d0
SG
3033proc_init_failed (pi, why)
3034 struct procinfo *pi;
1ab3bf1b 3035 char *why;
35f5886e 3036{
de43d7d0
SG
3037 print_sys_errmsg (pi->pathname, errno);
3038 kill (pi->pid, SIGKILL);
3039 close_proc_file (pi);
35f5886e
FF
3040 error (why);
3041 /* NOTREACHED */
3042}
3043
3044/*
3045
3046LOCAL FUNCTION
3047
3048 close_proc_file - close any currently open /proc entry
3049
3050SYNOPSIS
3051
a39ad5ce 3052 static void close_proc_file (struct procinfo *pip)
35f5886e
FF
3053
3054DESCRIPTION
3055
3056 Close any currently open /proc entry and mark the process information
3057 entry as invalid. In order to ensure that we don't try to reuse any
3058 stale information, the pid, fd, and pathnames are explicitly
3059 invalidated, which may be overkill.
3060
3061 */
3062
3063static void
1ab3bf1b
JG
3064close_proc_file (pip)
3065 struct procinfo *pip;
35f5886e 3066{
de43d7d0
SG
3067 struct procinfo *procinfo;
3068
3069 remove_fd (pip); /* Remove fd from poll/select list */
3070
3071 close (pip -> fd);
3072
3073 free (pip -> pathname);
3074
3075 /* Unlink pip from the procinfo chain. Note pip might not be on the list. */
3076
3077 if (procinfo_list == pip)
3078 procinfo_list = pip->next;
3079 else
3080 for (procinfo = procinfo_list; procinfo; procinfo = procinfo->next)
3081 if (procinfo->next == pip)
3082 procinfo->next = pip->next;
3083
3084 free (pip);
35f5886e
FF
3085}
3086
3087/*
3088
3089LOCAL FUNCTION
3090
3091 open_proc_file - open a /proc entry for a given process id
3092
3093SYNOPSIS
3094
ec8ceca3 3095 static int open_proc_file (int pid, struct procinfo *pip, int mode)
35f5886e
FF
3096
3097DESCRIPTION
3098
ec8ceca3
JG
3099 Given a process id and a mode, close the existing open /proc
3100 entry (if any) and open one for the new process id, in the
3101 specified mode. Once it is open, then mark the local process
3102 information structure as valid, which guarantees that the pid,
3103 fd, and pathname fields match an open /proc entry. Returns
3104 zero if the open fails, nonzero otherwise.
35f5886e
FF
3105
3106 Note that the pathname is left intact, even when the open fails,
3107 so that callers can use it to construct meaningful error messages
3108 rather than just "file open failed".
8fc2b417
SG
3109
3110 Note that for Solaris, the process-id also includes an LWP-id, so we
3111 actually attempt to open that. If we are handed a pid with a 0 LWP-id,
3112 then we will ask the kernel what it is and add it to the pid. Hence,
3113 the pid can be changed by us.
35f5886e
FF
3114 */
3115
3116static int
ec8ceca3 3117open_proc_file (pid, pip, mode)
1ab3bf1b
JG
3118 int pid;
3119 struct procinfo *pip;
ec8ceca3 3120 int mode;
35f5886e 3121{
8fc2b417
SG
3122 int tmp, tmpfd;
3123
de43d7d0
SG
3124 pip -> next = NULL;
3125 pip -> had_event = 0;
3126 pip -> pathname = xmalloc (32);
3127 pip -> pid = pid;
3128
8fc2b417
SG
3129#ifndef PIOCOPENLWP
3130 tmp = pid;
3131#else
3132 tmp = pid & 0xffff;
3133#endif
3134
3135 sprintf (pip -> pathname, PROC_NAME_FMT, tmp);
3136 if ((tmpfd = open (pip -> pathname, mode)) < 0)
de43d7d0
SG
3137 return 0;
3138
8fc2b417
SG
3139#ifndef PIOCOPENLWP
3140 pip -> fd = tmpfd;
3141#else
3142 tmp = (pid >> 16) & 0xffff; /* Extract thread id */
3143
3144 if (tmp == 0)
3145 { /* Don't know thread id yet */
3146 if (ioctl (tmpfd, PIOCSTATUS, &pip -> prstatus) < 0)
3147 {
3148 print_sys_errmsg (pip -> pathname, errno);
3149 close (tmpfd);
3150 error ("open_proc_file: PIOCSTATUS failed");
3151 }
3152
3153 tmp = pip -> prstatus.pr_who; /* Get thread id from prstatus_t */
3154 pip -> pid = (tmp << 16) | pid; /* Update pip */
3155 }
3156
3157 if ((pip -> fd = ioctl (tmpfd, PIOCOPENLWP, &tmp)) < 0)
3158 {
3159 close (tmpfd);
3160 return 0;
3161 }
3162
3163#ifdef PIOCSET /* New method */
3164 {
3165 long pr_flags;
3166 pr_flags = PR_ASYNC;
3167 ioctl (pip -> fd, PIOCSET, &pr_flags);
3168 }
3169#endif
3170
3171 close (tmpfd); /* All done with main pid */
3172#endif /* PIOCOPENLWP */
3173
de43d7d0 3174 return 1;
a39ad5ce
FF
3175}
3176
f66f459f 3177static char *
1ab3bf1b
JG
3178mappingflags (flags)
3179 long flags;
a39ad5ce 3180{
5c1c5e67 3181 static char asciiflags[8];
a39ad5ce 3182
5c1c5e67
FF
3183 strcpy (asciiflags, "-------");
3184#if defined (MA_PHYS)
3185 if (flags & MA_PHYS) asciiflags[0] = 'd';
3186#endif
3187 if (flags & MA_STACK) asciiflags[1] = 's';
3188 if (flags & MA_BREAK) asciiflags[2] = 'b';
3189 if (flags & MA_SHARED) asciiflags[3] = 's';
3190 if (flags & MA_READ) asciiflags[4] = 'r';
3191 if (flags & MA_WRITE) asciiflags[5] = 'w';
3192 if (flags & MA_EXEC) asciiflags[6] = 'x';
a39ad5ce
FF
3193 return (asciiflags);
3194}
3195
3196static void
cc221e76
FF
3197info_proc_flags (pip, summary)
3198 struct procinfo *pip;
3199 int summary;
3200{
3201 struct trans *transp;
3202
3203 printf_filtered ("%-32s", "Process status flags:");
3204 if (!summary)
3205 {
3206 printf_filtered ("\n\n");
3207 }
3208 for (transp = pr_flag_table; transp -> name != NULL; transp++)
3209 {
3210 if (pip -> prstatus.pr_flags & transp -> value)
3211 {
3212 if (summary)
3213 {
3214 printf_filtered ("%s ", transp -> name);
3215 }
3216 else
3217 {
3218 printf_filtered ("\t%-16s %s.\n", transp -> name, transp -> desc);
3219 }
3220 }
3221 }
3222 printf_filtered ("\n");
3223}
3224
3225static void
3226info_proc_stop (pip, summary)
3227 struct procinfo *pip;
3228 int summary;
3229{
3230 struct trans *transp;
3231 int why;
3232 int what;
3233
3234 why = pip -> prstatus.pr_why;
3235 what = pip -> prstatus.pr_what;
3236
3237 if (pip -> prstatus.pr_flags & PR_STOPPED)
3238 {
3239 printf_filtered ("%-32s", "Reason for stopping:");
3240 if (!summary)
3241 {
3242 printf_filtered ("\n\n");
3243 }
3244 for (transp = pr_why_table; transp -> name != NULL; transp++)
3245 {
3246 if (why == transp -> value)
3247 {
3248 if (summary)
3249 {
3250 printf_filtered ("%s ", transp -> name);
3251 }
3252 else
3253 {
3254 printf_filtered ("\t%-16s %s.\n",
3255 transp -> name, transp -> desc);
3256 }
3257 break;
3258 }
3259 }
3260
3261 /* Use the pr_why field to determine what the pr_what field means, and
3262 print more information. */
3263
3264 switch (why)
3265 {
3266 case PR_REQUESTED:
3267 /* pr_what is unused for this case */
3268 break;
3269 case PR_JOBCONTROL:
3270 case PR_SIGNALLED:
3271 if (summary)
3272 {
3273 printf_filtered ("%s ", signalname (what));
3274 }
3275 else
3276 {
3277 printf_filtered ("\t%-16s %s.\n", signalname (what),
4ace50a5 3278 safe_strsignal (what));
cc221e76
FF
3279 }
3280 break;
3281 case PR_SYSENTRY:
3282 if (summary)
3283 {
3284 printf_filtered ("%s ", syscallname (what));
3285 }
3286 else
3287 {
3288 printf_filtered ("\t%-16s %s.\n", syscallname (what),
3289 "Entered this system call");
3290 }
3291 break;
3292 case PR_SYSEXIT:
3293 if (summary)
3294 {
3295 printf_filtered ("%s ", syscallname (what));
3296 }
3297 else
3298 {
3299 printf_filtered ("\t%-16s %s.\n", syscallname (what),
3300 "Returned from this system call");
3301 }
3302 break;
3303 case PR_FAULTED:
3304 if (summary)
3305 {
3306 printf_filtered ("%s ",
3307 lookupname (faults_table, what, "fault"));
3308 }
3309 else
3310 {
3311 printf_filtered ("\t%-16s %s.\n",
3312 lookupname (faults_table, what, "fault"),
3313 lookupdesc (faults_table, what));
3314 }
3315 break;
3316 }
3317 printf_filtered ("\n");
3318 }
3319}
3320
3321static void
3322info_proc_siginfo (pip, summary)
3323 struct procinfo *pip;
3324 int summary;
3325{
3326 struct siginfo *sip;
3327
3328 if ((pip -> prstatus.pr_flags & PR_STOPPED) &&
3329 (pip -> prstatus.pr_why == PR_SIGNALLED ||
3330 pip -> prstatus.pr_why == PR_FAULTED))
3331 {
3332 printf_filtered ("%-32s", "Additional signal/fault info:");
3333 sip = &pip -> prstatus.pr_info;
3334 if (summary)
3335 {
3336 printf_filtered ("%s ", signalname (sip -> si_signo));
3337 if (sip -> si_errno > 0)
3338 {
4ace50a5 3339 printf_filtered ("%s ", errnoname (sip -> si_errno));
cc221e76
FF
3340 }
3341 if (sip -> si_code <= 0)
3342 {
25286543
SG
3343 printf_filtered ("sent by %s, uid %d ",
3344 target_pid_to_str (sip -> si_pid),
cc221e76
FF
3345 sip -> si_uid);
3346 }
3347 else
3348 {
3349 printf_filtered ("%s ", sigcodename (sip));
3350 if ((sip -> si_signo == SIGILL) ||
3351 (sip -> si_signo == SIGFPE) ||
3352 (sip -> si_signo == SIGSEGV) ||
3353 (sip -> si_signo == SIGBUS))
3354 {
b9e58503
PS
3355 printf_filtered ("addr=%#lx ",
3356 (unsigned long) sip -> si_addr);
cc221e76
FF
3357 }
3358 else if ((sip -> si_signo == SIGCHLD))
3359 {
25286543
SG
3360 printf_filtered ("child %s, status %u ",
3361 target_pid_to_str (sip -> si_pid),
cc221e76
FF
3362 sip -> si_status);
3363 }
3364 else if ((sip -> si_signo == SIGPOLL))
3365 {
3366 printf_filtered ("band %u ", sip -> si_band);
3367 }
3368 }
3369 }
3370 else
3371 {
3372 printf_filtered ("\n\n");
3373 printf_filtered ("\t%-16s %s.\n", signalname (sip -> si_signo),
4ace50a5 3374 safe_strsignal (sip -> si_signo));
cc221e76
FF
3375 if (sip -> si_errno > 0)
3376 {
3377 printf_filtered ("\t%-16s %s.\n",
4ace50a5
FF
3378 errnoname (sip -> si_errno),
3379 safe_strerror (sip -> si_errno));
cc221e76
FF
3380 }
3381 if (sip -> si_code <= 0)
3382 {
25286543 3383 printf_filtered ("\t%-16u %s\n", sip -> si_pid, /* XXX need target_pid_to_str() */
cc221e76
FF
3384 "PID of process sending signal");
3385 printf_filtered ("\t%-16u %s\n", sip -> si_uid,
3386 "UID of process sending signal");
3387 }
3388 else
3389 {
3390 printf_filtered ("\t%-16s %s.\n", sigcodename (sip),
3391 sigcodedesc (sip));
3392 if ((sip -> si_signo == SIGILL) ||
3393 (sip -> si_signo == SIGFPE))
3394 {
b9e58503
PS
3395 printf_filtered ("\t%#-16lx %s.\n",
3396 (unsigned long) sip -> si_addr,
cc221e76
FF
3397 "Address of faulting instruction");
3398 }
3399 else if ((sip -> si_signo == SIGSEGV) ||
3400 (sip -> si_signo == SIGBUS))
3401 {
b9e58503
PS
3402 printf_filtered ("\t%#-16lx %s.\n",
3403 (unsigned long) sip -> si_addr,
cc221e76
FF
3404 "Address of faulting memory reference");
3405 }
3406 else if ((sip -> si_signo == SIGCHLD))
3407 {
25286543 3408 printf_filtered ("\t%-16u %s.\n", sip -> si_pid, /* XXX need target_pid_to_str() */
cc221e76
FF
3409 "Child process ID");
3410 printf_filtered ("\t%-16u %s.\n", sip -> si_status,
3411 "Child process exit value or signal");
3412 }
3413 else if ((sip -> si_signo == SIGPOLL))
3414 {
3415 printf_filtered ("\t%-16u %s.\n", sip -> si_band,
3416 "Band event for POLL_{IN,OUT,MSG}");
3417 }
3418 }
3419 }
3420 printf_filtered ("\n");
3421 }
3422}
3423
3424static void
3425info_proc_syscalls (pip, summary)
3426 struct procinfo *pip;
3427 int summary;
3428{
3429 int syscallnum;
3430
3431 if (!summary)
3432 {
3433
3434#if 0 /* FIXME: Needs to use gdb-wide configured info about system calls. */
3435 if (pip -> prstatus.pr_flags & PR_ASLEEP)
3436 {
3437 int syscallnum = pip -> prstatus.pr_reg[R_D0];
3438 if (summary)
3439 {
3440 printf_filtered ("%-32s", "Sleeping in system call:");
3441 printf_filtered ("%s", syscallname (syscallnum));
3442 }
3443 else
3444 {
3445 printf_filtered ("Sleeping in system call '%s'.\n",
3446 syscallname (syscallnum));
3447 }
3448 }
3449#endif
3450
3451 if (ioctl (pip -> fd, PIOCGENTRY, &pip -> entryset) < 0)
3452 {
3453 print_sys_errmsg (pip -> pathname, errno);
3454 error ("PIOCGENTRY failed");
3455 }
3456
3457 if (ioctl (pip -> fd, PIOCGEXIT, &pip -> exitset) < 0)
3458 {
3459 print_sys_errmsg (pip -> pathname, errno);
3460 error ("PIOCGEXIT failed");
3461 }
3462
3463 printf_filtered ("System call tracing information:\n\n");
3464
3465 printf_filtered ("\t%-12s %-8s %-8s\n",
3466 "System call",
3467 "Entry",
3468 "Exit");
3469 for (syscallnum = 0; syscallnum < MAX_SYSCALLS; syscallnum++)
3470 {
3471 QUIT;
3472 if (syscall_table[syscallnum] != NULL)
8fc2b417
SG
3473 printf_filtered ("\t%-12s ", syscall_table[syscallnum]);
3474 else
3475 printf_filtered ("\t%-12d ", syscallnum);
3476
3477 printf_filtered ("%-8s ",
3478 prismember (&pip -> entryset, syscallnum)
3479 ? "on" : "off");
3480 printf_filtered ("%-8s ",
3481 prismember (&pip -> exitset, syscallnum)
3482 ? "on" : "off");
3483 printf_filtered ("\n");
3484 }
cc221e76
FF
3485 printf_filtered ("\n");
3486 }
3487}
3488
3489static char *
3490signalname (signo)
3491 int signo;
3492{
26a859ec 3493 const char *name;
4ace50a5
FF
3494 static char locbuf[32];
3495
3496 name = strsigno (signo);
3497 if (name == NULL)
3498 {
3499 sprintf (locbuf, "Signal %d", signo);
3500 }
3501 else
3502 {
3503 sprintf (locbuf, "%s (%d)", name, signo);
3504 }
3505 return (locbuf);
3506}
3507
3508static char *
3509errnoname (errnum)
3510 int errnum;
3511{
26a859ec 3512 const char *name;
cc221e76
FF
3513 static char locbuf[32];
3514
4ace50a5
FF
3515 name = strerrno (errnum);
3516 if (name == NULL)
cc221e76 3517 {
4ace50a5 3518 sprintf (locbuf, "Errno %d", errnum);
cc221e76
FF
3519 }
3520 else
3521 {
4ace50a5 3522 sprintf (locbuf, "%s (%d)", name, errnum);
cc221e76
FF
3523 }
3524 return (locbuf);
3525}
3526
3527static void
3528info_proc_signals (pip, summary)
3529 struct procinfo *pip;
3530 int summary;
3531{
3532 int signo;
3533
3534 if (!summary)
3535 {
3536 if (ioctl (pip -> fd, PIOCGTRACE, &pip -> trace) < 0)
3537 {
3538 print_sys_errmsg (pip -> pathname, errno);
3539 error ("PIOCGTRACE failed");
3540 }
3541
3542 printf_filtered ("Disposition of signals:\n\n");
3543 printf_filtered ("\t%-15s %-8s %-8s %-8s %s\n\n",
3544 "Signal", "Trace", "Hold", "Pending", "Description");
3545 for (signo = 0; signo < NSIG; signo++)
3546 {
3547 QUIT;
3548 printf_filtered ("\t%-15s ", signalname (signo));
3549 printf_filtered ("%-8s ",
3550 prismember (&pip -> trace, signo)
3551 ? "on" : "off");
3552 printf_filtered ("%-8s ",
3553 prismember (&pip -> prstatus.pr_sighold, signo)
3554 ? "on" : "off");
2592eef8
PS
3555
3556#ifdef PROCFS_SIGPEND_OFFSET
3557 /* Alpha OSF/1 numbers the pending signals from 1. */
3558 printf_filtered ("%-8s ",
3559 (signo ? prismember (&pip -> prstatus.pr_sigpend,
3560 signo - 1)
3561 : 0)
3562 ? "yes" : "no");
3563#else
cc221e76
FF
3564 printf_filtered ("%-8s ",
3565 prismember (&pip -> prstatus.pr_sigpend, signo)
3566 ? "yes" : "no");
2592eef8 3567#endif
4ace50a5 3568 printf_filtered (" %s\n", safe_strsignal (signo));
cc221e76
FF
3569 }
3570 printf_filtered ("\n");
3571 }
3572}
3573
3574static void
3575info_proc_faults (pip, summary)
3576 struct procinfo *pip;
3577 int summary;
3578{
3579 struct trans *transp;
3580
3581 if (!summary)
3582 {
3583 if (ioctl (pip -> fd, PIOCGFAULT, &pip -> fltset) < 0)
3584 {
3585 print_sys_errmsg (pip -> pathname, errno);
3586 error ("PIOCGFAULT failed");
3587 }
3588
3589 printf_filtered ("Current traced hardware fault set:\n\n");
3590 printf_filtered ("\t%-12s %-8s\n", "Fault", "Trace");
3591
3592 for (transp = faults_table; transp -> name != NULL; transp++)
3593 {
3594 QUIT;
3595 printf_filtered ("\t%-12s ", transp -> name);
3596 printf_filtered ("%-8s", prismember (&pip -> fltset, transp -> value)
3597 ? "on" : "off");
3598 printf_filtered ("\n");
3599 }
3600 printf_filtered ("\n");
3601 }
3602}
3603
3604static void
3605info_proc_mappings (pip, summary)
1ab3bf1b 3606 struct procinfo *pip;
cc221e76 3607 int summary;
a39ad5ce
FF
3608{
3609 int nmap;
3610 struct prmap *prmaps;
3611 struct prmap *prmap;
3612
cc221e76 3613 if (!summary)
a39ad5ce 3614 {
cc221e76 3615 printf_filtered ("Mapped address spaces:\n\n");
2592eef8
PS
3616#ifdef BFD_HOST_64_BIT
3617 printf_filtered (" %18s %18s %10s %10s %7s\n",
3618#else
5c1c5e67 3619 printf_filtered ("\t%10s %10s %10s %10s %7s\n",
2592eef8 3620#endif
cc221e76
FF
3621 "Start Addr",
3622 " End Addr",
3623 " Size",
3624 " Offset",
3625 "Flags");
3626 if (ioctl (pip -> fd, PIOCNMAP, &nmap) == 0)
a39ad5ce 3627 {
cc221e76
FF
3628 prmaps = (struct prmap *) alloca ((nmap + 1) * sizeof (*prmaps));
3629 if (ioctl (pip -> fd, PIOCMAP, prmaps) == 0)
a39ad5ce 3630 {
cc221e76
FF
3631 for (prmap = prmaps; prmap -> pr_size; ++prmap)
3632 {
2592eef8
PS
3633#ifdef BFD_HOST_64_BIT
3634 printf_filtered (" %#18lx %#18lx %#10x %#10x %7s\n",
3635#else
3636 printf_filtered ("\t%#10lx %#10lx %#10x %#10x %7s\n",
3637#endif
3638 (unsigned long)prmap -> pr_vaddr,
3639 (unsigned long)prmap -> pr_vaddr
3640 + prmap -> pr_size - 1,
cc221e76
FF
3641 prmap -> pr_size,
3642 prmap -> pr_off,
3643 mappingflags (prmap -> pr_mflags));
3644 }
a39ad5ce
FF
3645 }
3646 }
cc221e76 3647 printf_filtered ("\n");
a39ad5ce 3648 }
a39ad5ce
FF
3649}
3650
3651/*
3652
3653LOCAL FUNCTION
3654
cc221e76 3655 info_proc -- implement the "info proc" command
a39ad5ce
FF
3656
3657SYNOPSIS
3658
cc221e76 3659 void info_proc (char *args, int from_tty)
a39ad5ce
FF
3660
3661DESCRIPTION
3662
3663 Implement gdb's "info proc" command by using the /proc interface
3664 to print status information about any currently running process.
3665
3666 Examples of the use of "info proc" are:
3667
cc221e76
FF
3668 info proc (prints summary info for current inferior)
3669 info proc 123 (prints summary info for process with pid 123)
3670 info proc mappings (prints address mappings)
3671 info proc times (prints process/children times)
3672 info proc id (prints pid, ppid, gid, sid, etc)
3fbdd536 3673 FIXME: i proc id not implemented.
cc221e76 3674 info proc status (prints general process state info)
3fbdd536 3675 FIXME: i proc status not implemented.
cc221e76
FF
3676 info proc signals (prints info about signal handling)
3677 info proc all (prints all info)
a39ad5ce
FF
3678
3679 */
3680
3681static void
cc221e76 3682info_proc (args, from_tty)
1ab3bf1b
JG
3683 char *args;
3684 int from_tty;
a39ad5ce 3685{
8fc2b417 3686 int pid = inferior_pid;
a39ad5ce
FF
3687 struct procinfo *pip;
3688 struct cleanup *old_chain;
cc221e76
FF
3689 char **argv;
3690 int argsize;
3691 int summary = 1;
3692 int flags = 0;
3693 int syscalls = 0;
3694 int signals = 0;
3695 int faults = 0;
3696 int mappings = 0;
3697 int times = 0;
3698 int id = 0;
3699 int status = 0;
3700 int all = 0;
8fc2b417 3701 int nlwp;
47ef0da5 3702 int *lwps;
a39ad5ce
FF
3703
3704 old_chain = make_cleanup (null_cleanup, 0);
3705
de43d7d0
SG
3706 /* Default to using the current inferior if no pid specified. Note
3707 that inferior_pid may be 0, hence we set okerr. */
a39ad5ce 3708
de43d7d0 3709 pip = find_procinfo (inferior_pid, 1);
a39ad5ce 3710
a39ad5ce 3711 if (args != NULL)
35f5886e 3712 {
cc221e76 3713 if ((argv = buildargv (args)) == NULL)
a39ad5ce 3714 {
cc221e76
FF
3715 nomem (0);
3716 }
3717 make_cleanup (freeargv, (char *) argv);
3718
3719 while (*argv != NULL)
3720 {
3721 argsize = strlen (*argv);
3722 if (argsize >= 1 && strncmp (*argv, "all", argsize) == 0)
3723 {
3724 summary = 0;
3725 all = 1;
3726 }
3727 else if (argsize >= 2 && strncmp (*argv, "faults", argsize) == 0)
3728 {
3729 summary = 0;
3730 faults = 1;
3731 }
3732 else if (argsize >= 2 && strncmp (*argv, "flags", argsize) == 0)
3733 {
3734 summary = 0;
3735 flags = 1;
3736 }
3737 else if (argsize >= 1 && strncmp (*argv, "id", argsize) == 0)
3738 {
3739 summary = 0;
3740 id = 1;
3741 }
3742 else if (argsize >= 1 && strncmp (*argv, "mappings", argsize) == 0)
3743 {
3744 summary = 0;
3745 mappings = 1;
3746 }
3747 else if (argsize >= 2 && strncmp (*argv, "signals", argsize) == 0)
3748 {
3749 summary = 0;
3750 signals = 1;
3751 }
3752 else if (argsize >= 2 && strncmp (*argv, "status", argsize) == 0)
3753 {
3754 summary = 0;
3755 status = 1;
3756 }
3757 else if (argsize >= 2 && strncmp (*argv, "syscalls", argsize) == 0)
3758 {
3759 summary = 0;
3760 syscalls = 1;
3761 }
3762 else if (argsize >= 1 && strncmp (*argv, "times", argsize) == 0)
a39ad5ce 3763 {
cc221e76
FF
3764 summary = 0;
3765 times = 1;
a39ad5ce 3766 }
de43d7d0 3767 else if ((pid = atoi (*argv)) > 0)
a39ad5ce 3768 {
de43d7d0
SG
3769 pip = (struct procinfo *) xmalloc (sizeof (struct procinfo));
3770 memset (pip, 0, sizeof (*pip));
3771
3772 pip->pid = pid;
ec8ceca3 3773 if (!open_proc_file (pid, pip, O_RDONLY))
a39ad5ce
FF
3774 {
3775 perror_with_name (pip -> pathname);
3776 /* NOTREACHED */
3777 }
8fc2b417 3778 pid = pip->pid;
a39ad5ce
FF
3779 make_cleanup (close_proc_file, pip);
3780 }
cc221e76
FF
3781 else if (**argv != '\000')
3782 {
3783 error ("Unrecognized or ambiguous keyword `%s'.", *argv);
3784 }
3785 argv++;
a39ad5ce 3786 }
35f5886e 3787 }
a39ad5ce
FF
3788
3789 /* If we don't have a valid open process at this point, then we have no
3790 inferior or didn't specify a specific pid. */
3791
de43d7d0 3792 if (!pip)
35f5886e 3793 {
6fe90fc8
JK
3794 error ("\
3795No process. Start debugging a program or specify an explicit process ID.");
35f5886e 3796 }
a39ad5ce 3797 if (ioctl (pip -> fd, PIOCSTATUS, &(pip -> prstatus)) < 0)
35f5886e 3798 {
a39ad5ce
FF
3799 print_sys_errmsg (pip -> pathname, errno);
3800 error ("PIOCSTATUS failed");
35f5886e 3801 }
a39ad5ce 3802
8fc2b417
SG
3803#ifdef PIOCLWPIDS
3804 nlwp = pip->prstatus.pr_nlwp;
3805 lwps = alloca ((2 * nlwp + 2) * sizeof (id_t));
cc221e76 3806
8fc2b417 3807 if (ioctl (pip->fd, PIOCLWPIDS, lwps))
cc221e76 3808 {
8fc2b417
SG
3809 print_sys_errmsg (pip -> pathname, errno);
3810 error ("PIOCSTATUS failed");
cc221e76 3811 }
8fc2b417
SG
3812#else /* PIOCLWPIDS */
3813 nlwp = 1;
47ef0da5 3814 lwps = alloca ((2 * nlwp + 2) * sizeof *lwps);
8fc2b417
SG
3815 lwps[0] = 0;
3816#endif /* PIOCLWPIDS */
3817
3818 for (; nlwp > 0; nlwp--, lwps++)
cc221e76 3819 {
8fc2b417
SG
3820 pip = find_procinfo ((*lwps << 16) | pid, 1);
3821
3822 if (!pip)
3823 {
3824 pip = (struct procinfo *) xmalloc (sizeof (struct procinfo));
3825 memset (pip, 0, sizeof (*pip));
3826 if (!open_proc_file ((*lwps << 16) | pid, pip, O_RDONLY))
3827 continue;
3828
3829 make_cleanup (close_proc_file, pip);
3830
3831 if (ioctl (pip -> fd, PIOCSTATUS, &(pip -> prstatus)) < 0)
3832 {
3833 print_sys_errmsg (pip -> pathname, errno);
3834 error ("PIOCSTATUS failed");
3835 }
3836 }
3837
3838 /* Print verbose information of the requested type(s), or just a summary
3839 of the information for all types. */
3840
3841 printf_filtered ("\nInformation for %s.%d:\n\n", pip -> pathname, *lwps);
3842 if (summary || all || flags)
3843 {
3844 info_proc_flags (pip, summary);
3845 }
3846 if (summary || all)
3847 {
3848 info_proc_stop (pip, summary);
3849 }
3850 if (summary || all || signals || faults)
3851 {
3852 info_proc_siginfo (pip, summary);
3853 }
3854 if (summary || all || syscalls)
3855 {
3856 info_proc_syscalls (pip, summary);
3857 }
3858 if (summary || all || mappings)
3859 {
3860 info_proc_mappings (pip, summary);
3861 }
3862 if (summary || all || signals)
3863 {
3864 info_proc_signals (pip, summary);
3865 }
3866 if (summary || all || faults)
3867 {
3868 info_proc_faults (pip, summary);
3869 }
3870 printf_filtered ("\n");
3871
3872 /* All done, deal with closing any temporary process info structure,
3873 freeing temporary memory , etc. */
3874
3875 do_cleanups (old_chain);
cc221e76 3876 }
8fc2b417
SG
3877}
3878
3879/*
3880
3881LOCAL FUNCTION
3882
3883 modify_inherit_on_fork_flag - Change the inherit-on-fork flag
3884
3885SYNOPSIS
3886
3887 void modify_inherit_on_fork_flag (fd, flag)
3888
3889DESCRIPTION
3890
3891 Call this routine to modify the inherit-on-fork flag. This routine is
3892 just a nice wrapper to hide the #ifdefs needed by various systems to
3893 control this flag.
3894
3895 */
3896
3897static void
3898modify_inherit_on_fork_flag (fd, flag)
3899 int fd;
3900 int flag;
3901{
b607efe7 3902#ifdef PIOCSET
8fc2b417 3903 long pr_flags;
b607efe7 3904#endif
8fc2b417
SG
3905 int retval;
3906
3907#ifdef PIOCSET /* New method */
3908 pr_flags = PR_FORK;
3909 if (flag)
3910 retval = ioctl (fd, PIOCSET, &pr_flags);
3911 else
3912 retval = ioctl (fd, PIOCRESET, &pr_flags);
3913
3914#else
3915#ifdef PIOCSFORK /* Original method */
3916 if (flag)
3917 retval = ioctl (fd, PIOCSFORK, NULL);
3918 else
3919 retval = ioctl (fd, PIOCRFORK, NULL);
3920#else
3921 Neither PR_FORK nor PIOCSFORK exist!!!
3922#endif
3923#endif
3924
3925 if (!retval)
3926 return;
3927
3928 print_sys_errmsg ("modify_inherit_on_fork_flag", errno);
3929 error ("PIOCSFORK or PR_FORK modification failed");
3930}
3931
3932/*
3933
3934LOCAL FUNCTION
3935
3936 modify_run_on_last_close_flag - Change the run-on-last-close flag
3937
3938SYNOPSIS
3939
3940 void modify_run_on_last_close_flag (fd, flag)
3941
3942DESCRIPTION
3943
3944 Call this routine to modify the run-on-last-close flag. This routine
3945 is just a nice wrapper to hide the #ifdefs needed by various systems to
3946 control this flag.
3947
3948 */
3949
3950static void
3951modify_run_on_last_close_flag (fd, flag)
3952 int fd;
3953 int flag;
3954{
b607efe7 3955#ifdef PIOCSET
8fc2b417 3956 long pr_flags;
b607efe7 3957#endif
8fc2b417
SG
3958 int retval;
3959
3960#ifdef PIOCSET /* New method */
3961 pr_flags = PR_RLC;
3962 if (flag)
3963 retval = ioctl (fd, PIOCSET, &pr_flags);
3964 else
3965 retval = ioctl (fd, PIOCRESET, &pr_flags);
3966
3967#else
3968#ifdef PIOCSRLC /* Original method */
3969 if (flag)
3970 retval = ioctl (fd, PIOCSRLC, NULL);
3971 else
3972 retval = ioctl (fd, PIOCRRLC, NULL);
3973#else
3974 Neither PR_RLC nor PIOCSRLC exist!!!
3975#endif
3976#endif
3977
3978 if (!retval)
3979 return;
3980
3981 print_sys_errmsg ("modify_run_on_last_close_flag", errno);
3982 error ("PIOCSRLC or PR_RLC modification failed");
3983}
3984
3985/*
3986
3987LOCAL FUNCTION
3988
3989 procfs_clear_syscall_trap -- Deletes the trap for the specified system call.
3990
3991SYNOPSIS
3992
3993 void procfs_clear_syscall_trap (struct procinfo *, int syscall_num, int errok)
3994
3995DESCRIPTION
3996
3997 This function function disables traps for the specified system call.
3998 errok is non-zero if errors should be ignored.
3999 */
4000
4001static void
4002procfs_clear_syscall_trap (pi, syscall_num, errok)
4003 struct procinfo *pi;
4004 int syscall_num;
4005 int errok;
4006{
4007 sysset_t sysset;
4008 int goterr, i;
4009
4010 goterr = ioctl (pi->fd, PIOCGENTRY, &sysset) < 0;
4011
4012 if (goterr && !errok)
cc221e76 4013 {
8fc2b417
SG
4014 print_sys_errmsg (pi->pathname, errno);
4015 error ("PIOCGENTRY failed");
cc221e76 4016 }
8fc2b417
SG
4017
4018 if (!goterr)
cc221e76 4019 {
8fc2b417
SG
4020 prdelset (&sysset, syscall_num);
4021
4022 if ((ioctl (pi->fd, PIOCSENTRY, &sysset) < 0) && !errok)
4023 {
4024 print_sys_errmsg (pi->pathname, errno);
4025 error ("PIOCSENTRY failed");
4026 }
cc221e76 4027 }
8fc2b417
SG
4028
4029 goterr = ioctl (pi->fd, PIOCGEXIT, &sysset) < 0;
4030
4031 if (goterr && !errok)
cc221e76 4032 {
8fc2b417
SG
4033 procfs_clear_syscall_trap (pi, syscall_num, 1);
4034 print_sys_errmsg (pi->pathname, errno);
4035 error ("PIOCGEXIT failed");
cc221e76 4036 }
8fc2b417
SG
4037
4038 if (!goterr)
cc221e76 4039 {
8fc2b417
SG
4040 praddset (&sysset, syscall_num);
4041
4042 if ((ioctl (pi->fd, PIOCSEXIT, &sysset) < 0) && !errok)
4043 {
4044 procfs_clear_syscall_trap (pi, syscall_num, 1);
4045 print_sys_errmsg (pi->pathname, errno);
4046 error ("PIOCSEXIT failed");
4047 }
cc221e76 4048 }
8fc2b417
SG
4049
4050 if (!pi->syscall_handlers)
cc221e76 4051 {
8fc2b417
SG
4052 if (!errok)
4053 error ("procfs_clear_syscall_trap: syscall_handlers is empty");
4054 return;
cc221e76 4055 }
a39ad5ce 4056
8fc2b417 4057 /* Remove handler func from the handler list */
a39ad5ce 4058
8fc2b417
SG
4059 for (i = 0; i < pi->num_syscall_handlers; i++)
4060 if (pi->syscall_handlers[i].syscall_num == syscall_num)
4061 {
4062 if (i + 1 != pi->num_syscall_handlers)
4063 { /* Not the last entry.
4064 Move subsequent entries fwd. */
4065 memcpy (&pi->syscall_handlers[i], &pi->syscall_handlers[i + 1],
4066 (pi->num_syscall_handlers - i - 1)
4067 * sizeof (struct procfs_syscall_handler));
4068 }
4069
4070 pi->syscall_handlers = xrealloc (pi->syscall_handlers,
4071 (pi->num_syscall_handlers - 1)
4072 * sizeof (struct procfs_syscall_handler));
4073 pi->num_syscall_handlers--;
4074 return;
4075 }
4076
4077 if (!errok)
4078 error ("procfs_clear_syscall_trap: Couldn't find handler for sys call %d",
4079 syscall_num);
a39ad5ce
FF
4080}
4081
de43d7d0
SG
4082/*
4083
4084LOCAL FUNCTION
4085
8fc2b417
SG
4086 procfs_set_syscall_trap -- arrange for a function to be called when the
4087 child executes the specified system call.
de43d7d0
SG
4088
4089SYNOPSIS
4090
8fc2b417
SG
4091 void procfs_set_syscall_trap (struct procinfo *, int syscall_num, int flags,
4092 syscall_func_t *function)
de43d7d0
SG
4093
4094DESCRIPTION
4095
8fc2b417
SG
4096 This function sets up an entry and/or exit trap for the specified system
4097 call. When the child executes the specified system call, your function
4098 will be called with the call #, a flag that indicates entry or exit, and
4099 pointers to rtnval and statval (which are used by procfs_wait). The
4100 function should return non-zero if something interesting happened, zero
4101 otherwise.
de43d7d0
SG
4102 */
4103
4104static void
8fc2b417 4105procfs_set_syscall_trap (pi, syscall_num, flags, func)
de43d7d0 4106 struct procinfo *pi;
8fc2b417
SG
4107 int syscall_num;
4108 int flags;
4109 syscall_func_t *func;
de43d7d0 4110{
8fc2b417 4111 sysset_t sysset;
de43d7d0 4112
8fc2b417 4113 if (flags & PROCFS_SYSCALL_ENTRY)
de43d7d0 4114 {
8fc2b417
SG
4115 if (ioctl (pi->fd, PIOCGENTRY, &sysset) < 0)
4116 {
4117 print_sys_errmsg (pi->pathname, errno);
4118 error ("PIOCGENTRY failed");
4119 }
4120
4121 praddset (&sysset, syscall_num);
4122
4123 if (ioctl (pi->fd, PIOCSENTRY, &sysset) < 0)
4124 {
4125 print_sys_errmsg (pi->pathname, errno);
4126 error ("PIOCSENTRY failed");
4127 }
de43d7d0
SG
4128 }
4129
8fc2b417
SG
4130 if (flags & PROCFS_SYSCALL_EXIT)
4131 {
4132 if (ioctl (pi->fd, PIOCGEXIT, &sysset) < 0)
4133 {
4134 procfs_clear_syscall_trap (pi, syscall_num, 1);
4135 print_sys_errmsg (pi->pathname, errno);
4136 error ("PIOCGEXIT failed");
4137 }
de43d7d0 4138
8fc2b417 4139 praddset (&sysset, syscall_num);
eca4a350 4140
8fc2b417
SG
4141 if (ioctl (pi->fd, PIOCSEXIT, &sysset) < 0)
4142 {
4143 procfs_clear_syscall_trap (pi, syscall_num, 1);
4144 print_sys_errmsg (pi->pathname, errno);
4145 error ("PIOCSEXIT failed");
4146 }
4147 }
eca4a350 4148
8fc2b417 4149 if (!pi->syscall_handlers)
de43d7d0 4150 {
8fc2b417
SG
4151 pi->syscall_handlers = xmalloc (sizeof (struct procfs_syscall_handler));
4152 pi->syscall_handlers[0].syscall_num = syscall_num;
4153 pi->syscall_handlers[0].func = func;
4154 pi->num_syscall_handlers = 1;
de43d7d0 4155 }
8fc2b417
SG
4156 else
4157 {
4158 int i;
de43d7d0 4159
8fc2b417
SG
4160 for (i = 0; i < pi->num_syscall_handlers; i++)
4161 if (pi->syscall_handlers[i].syscall_num == syscall_num)
4162 {
4163 pi->syscall_handlers[i].func = func;
4164 return;
4165 }
de43d7d0 4166
8fc2b417
SG
4167 pi->syscall_handlers = xrealloc (pi->syscall_handlers, (i + 1)
4168 * sizeof (struct procfs_syscall_handler));
4169 pi->syscall_handlers[i].syscall_num = syscall_num;
4170 pi->syscall_handlers[i].func = func;
4171 pi->num_syscall_handlers++;
4172 }
de43d7d0 4173}
8fc2b417
SG
4174
4175#ifdef SYS_lwp_create
4176
4177/*
4178
4179LOCAL FUNCTION
4180
4181 procfs_lwp_creation_handler - handle exit from the _lwp_create syscall
4182
4183SYNOPSIS
4184
4185 int procfs_lwp_creation_handler (pi, syscall_num, why, rtnvalp, statvalp)
4186
4187DESCRIPTION
4188
4189 This routine is called both when an inferior process and it's new lwp
4190 are about to finish a _lwp_create() system call. This is the system
4191 call that Solaris uses to create a lightweight process. When the
4192 target process gets this event, we can look at sysarg[2] to find the
4193 new childs lwp ID, and create a procinfo struct from that. After that,
4194 we pretend that we got a SIGTRAP, and return non-zero to tell
4195 procfs_wait to wake up. Subsequently, wait_for_inferior gets woken up,
4196 sees the new process and continues it.
4197
4198 When we see the child exiting from lwp_create, we just contine it,
4199 since everything was handled when the parent trapped.
4200
4201NOTES
4202 In effect, we are only paying attention to the parent's completion of
4203 the lwp_create syscall. If we only paid attention to the child
4204 instead, then we wouldn't detect the creation of a suspended thread.
4205 */
4206
4207static int
4208procfs_lwp_creation_handler (pi, syscall_num, why, rtnvalp, statvalp)
4209 struct procinfo *pi;
4210 int syscall_num;
4211 int why;
4212 int *rtnvalp;
4213 int *statvalp;
4214{
4215 int lwp_id;
4216 struct procinfo *childpi;
4217
4218 /* We've just detected the completion of an lwp_create system call. Now we
4219 need to setup a procinfo struct for this thread, and notify the thread
4220 system of the new arrival. */
4221
4222 /* If lwp_create failed, then nothing interesting happened. Continue the
4223 process and go back to sleep. */
4224
4225 if (pi->prstatus.pr_reg[R_PSR] & PS_FLAG_CARRY)
4226 { /* _lwp_create failed */
4227 pi->prrun.pr_flags &= PRSTEP;
4228 pi->prrun.pr_flags |= PRCFAULT;
4229
4230 if (ioctl (pi->fd, PIOCRUN, &pi->prrun) != 0)
4231 perror_with_name (pi->pathname);
4232
4233 return 0;
4234 }
4235
4236 /* At this point, the new thread is stopped at it's first instruction, and
4237 the parent is stopped at the exit from lwp_create. */
4238
4239 if (pi->new_child) /* Child? */
4240 { /* Yes, just continue it */
4241 pi->prrun.pr_flags &= PRSTEP;
4242 pi->prrun.pr_flags |= PRCFAULT;
4243
4244 if ((pi->prstatus.pr_flags & PR_ISTOP)
4245 && ioctl (pi->fd, PIOCRUN, &pi->prrun) != 0)
4246 perror_with_name (pi->pathname);
4247
4248 pi->new_child = 0; /* No longer new */
4249
4250 return 0;
4251 }
4252
4253 /* We're the proud parent of a new thread. Setup an exit trap for lwp_create
4254 in the child and continue the parent. */
4255
4256 /* Third arg is pointer to new thread id. */
4257 lwp_id = read_memory_integer (pi->prstatus.pr_sysarg[2], sizeof (int));
4258
4259 lwp_id = (lwp_id << 16) | PIDGET (pi->pid);
4260
4261 childpi = create_procinfo (lwp_id);
4262
4263 /* The new process has actually inherited the lwp_create syscall trap from
4264 it's parent, but we still have to call this to register a handler for
4265 that child. */
4266
4267 procfs_set_syscall_trap (childpi, SYS_lwp_create, PROCFS_SYSCALL_EXIT,
4268 procfs_lwp_creation_handler);
4269
4270 childpi->new_child = 1; /* Flag this as an unseen child process */
4271
4272 *rtnvalp = lwp_id; /* the new arrival. */
4273 *statvalp = (SIGTRAP << 8) | 0177;
4274
4275 return 1;
4276}
4277#endif /* SYS_lwp_create */
de43d7d0 4278
3fbdd536
JG
4279/* Fork an inferior process, and start debugging it with /proc. */
4280
4281static void
4282procfs_create_inferior (exec_file, allargs, env)
4283 char *exec_file;
4284 char *allargs;
4285 char **env;
4286{
08f74b92
JK
4287 char *shell_file = getenv ("SHELL");
4288 char *tryname;
4289 if (shell_file != NULL && strchr (shell_file, '/') == NULL)
4290 {
4291
4292 /* We will be looking down the PATH to find shell_file. If we
4293 just do this the normal way (via execlp, which operates by
4294 attempting an exec for each element of the PATH until it
4295 finds one which succeeds), then there will be an exec for
4296 each failed attempt, each of which will cause a PR_SYSEXIT
4297 stop, and we won't know how to distinguish the PR_SYSEXIT's
4298 for these failed execs with the ones for successful execs
4299 (whether the exec has succeeded is stored at that time in the
4300 carry bit or some such architecture-specific and
4301 non-ABI-specified place).
4302
4303 So I can't think of anything better than to search the PATH
4304 now. This has several disadvantages: (1) There is a race
4305 condition; if we find a file now and it is deleted before we
4306 exec it, we lose, even if the deletion leaves a valid file
4307 further down in the PATH, (2) there is no way to know exactly
4308 what an executable (in the sense of "capable of being
4309 exec'd") file is. Using access() loses because it may lose
4310 if the caller is the superuser; failing to use it loses if
4311 there are ACLs or some such. */
4312
4313 char *p;
4314 char *p1;
f93b941b
JK
4315 /* FIXME-maybe: might want "set path" command so user can change what
4316 path is used from within GDB. */
08f74b92
JK
4317 char *path = getenv ("PATH");
4318 int len;
4319 struct stat statbuf;
4320
4321 if (path == NULL)
4322 path = "/bin:/usr/bin";
4323
4324 tryname = alloca (strlen (path) + strlen (shell_file) + 2);
4325 for (p = path; p != NULL; p = p1 ? p1 + 1: NULL)
4326 {
4327 p1 = strchr (p, ':');
4328 if (p1 != NULL)
4329 len = p1 - p;
4330 else
4331 len = strlen (p);
4332 strncpy (tryname, p, len);
4333 tryname[len] = '\0';
4334 strcat (tryname, "/");
4335 strcat (tryname, shell_file);
4336 if (access (tryname, X_OK) < 0)
4337 continue;
4338 if (stat (tryname, &statbuf) < 0)
4339 continue;
4340 if (!S_ISREG (statbuf.st_mode))
4341 /* We certainly need to reject directories. I'm not quite
4342 as sure about FIFOs, sockets, etc., but I kind of doubt
4343 that people want to exec() these things. */
4344 continue;
4345 break;
4346 }
4347 if (p == NULL)
4348 /* Not found. This must be an error rather than merely passing
4349 the file to execlp(), because execlp() would try all the
4350 exec()s, causing GDB to get confused. */
4351 error ("Can't find shell %s in PATH", shell_file);
4352
4353 shell_file = tryname;
4354 }
4355
3fbdd536 4356 fork_inferior (exec_file, allargs, env,
08f74b92
JK
4357 proc_set_exec_trap, procfs_init_inferior, shell_file);
4358
3fbdd536
JG
4359 /* We are at the first instruction we care about. */
4360 /* Pedal to the metal... */
de43d7d0 4361
67ac9759 4362 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_0, 0);
3fbdd536
JG
4363}
4364
4365/* Clean up after the inferior dies. */
4366
4367static void
4368procfs_mourn_inferior ()
4369{
fb63d460 4370 struct procinfo *pi;
cd4104e0 4371 struct procinfo *next_pi;
fb63d460 4372
cd4104e0
TL
4373 for (pi = procinfo_list; pi; pi = next_pi)
4374 {
4375 next_pi = pi->next;
4376 unconditionally_kill_inferior (pi);
4377 }
fb63d460 4378
3fbdd536
JG
4379 unpush_target (&procfs_ops);
4380 generic_mourn_inferior ();
4381}
4382
cd4104e0 4383
3fbdd536
JG
4384/* Mark our target-struct as eligible for stray "run" and "attach" commands. */
4385static int
4386procfs_can_run ()
4387{
8fc2b417
SG
4388 /* This variable is controlled by modules that sit atop procfs that may layer
4389 their own process structure atop that provided here. sol-thread.c does
4390 this because of the Solaris two-level thread model. */
4391
4392 return !procfs_suppress_run;
3fbdd536 4393}
f5a8f1a6 4394#ifdef TARGET_HAS_HARDWARE_WATCHPOINTS
999dd04b
JL
4395\f
4396/* Insert a watchpoint */
4397int
4398procfs_set_watchpoint(pid, addr, len, rw)
4399 int pid;
4400 CORE_ADDR addr;
4401 int len;
4402 int rw;
4403{
4404 struct procinfo *pi;
4405 prwatch_t wpt;
4406
4407 pi = find_procinfo (pid == -1 ? inferior_pid : pid, 0);
4408 wpt.pr_vaddr = (caddr_t)addr;
4409 wpt.pr_size = len;
4410 wpt.pr_wflags = ((rw & 1) ? MA_READ : 0) | ((rw & 2) ? MA_WRITE : 0);
4411 if (ioctl (pi->fd, PIOCSWATCH, &wpt) < 0)
4412 {
4413 if (errno == E2BIG)
4414 return -1;
4415 /* Currently it sometimes happens that the same watchpoint gets
4416 deleted twice - don't die in this case (FIXME please) */
4417 if (errno == ESRCH && len == 0)
4418 return 0;
4419 print_sys_errmsg (pi->pathname, errno);
4420 error ("PIOCSWATCH failed");
4421 }
4422 return 0;
4423}
4424
4425int
4426procfs_stopped_by_watchpoint(pid)
4427 int pid;
4428{
4429 struct procinfo *pi;
4430 short what;
4431 short why;
4432
4433 pi = find_procinfo (pid == -1 ? inferior_pid : pid, 0);
4434 if (pi->prstatus.pr_flags & (PR_STOPPED | PR_ISTOP))
4435 {
4436 why = pi->prstatus.pr_why;
4437 what = pi->prstatus.pr_what;
4438 if (why == PR_FAULTED
6bc194d2 4439#if defined (FLTWATCH) && defined (FLTKWATCH)
255181a9 4440 && (what == FLTWATCH || what == FLTKWATCH)
6bc194d2
JL
4441#else
4442#ifdef FLTWATCH
4443 && (what == FLTWATCH)
4444#endif
4445#ifdef FLTKWATCH
4446 && (what == FLTKWATCH)
4447#endif
72b8ca51 4448#endif
6bc194d2 4449 )
999dd04b
JL
4450 return what;
4451 }
4452 return 0;
4453}
6bc194d2 4454#endif
999dd04b 4455
8fc2b417
SG
4456/* Why is this necessary? Shouldn't dead threads just be removed from the
4457 thread database? */
4458
9b33e492 4459static int
8fc2b417
SG
4460procfs_thread_alive (pid)
4461 int pid;
4462{
4463 return 1;
4464}
4465
78b459a7
SG
4466/* Send a SIGINT to the process group. This acts just like the user typed a
4467 ^C on the controlling terminal.
4468
4469 XXX - This may not be correct for all systems. Some may want to use
4470 killpg() instead of kill (-pgrp). */
4471
9b33e492 4472static void
2592eef8 4473procfs_stop ()
78b459a7
SG
4474{
4475 extern pid_t inferior_process_group;
4476
4477 kill (-inferior_process_group, SIGINT);
4478}
9b33e492
SG
4479\f
4480/* Convert a pid to printable form. */
78b459a7 4481
9b33e492
SG
4482#ifdef TIDGET
4483char *
4484procfs_pid_to_str (pid)
4485 int pid;
4486{
4487 static char buf[100];
4488
4489 sprintf (buf, "Kernel thread %d", TIDGET (pid));
4490
4491 return buf;
4492}
4493#endif /* TIDGET */
3fbdd536
JG
4494\f
4495struct target_ops procfs_ops = {
4496 "procfs", /* to_shortname */
4497 "Unix /proc child process", /* to_longname */
4498 "Unix /proc child process (started by the \"run\" command).", /* to_doc */
4499 procfs_open, /* to_open */
4500 0, /* to_close */
4501 procfs_attach, /* to_attach */
4502 procfs_detach, /* to_detach */
4503 procfs_resume, /* to_resume */
4504 procfs_wait, /* to_wait */
4505 procfs_fetch_registers, /* to_fetch_registers */
4506 procfs_store_registers, /* to_store_registers */
4507 procfs_prepare_to_store, /* to_prepare_to_store */
4508 procfs_xfer_memory, /* to_xfer_memory */
4509 procfs_files_info, /* to_files_info */
4510 memory_insert_breakpoint, /* to_insert_breakpoint */
4511 memory_remove_breakpoint, /* to_remove_breakpoint */
4512 terminal_init_inferior, /* to_terminal_init */
4513 terminal_inferior, /* to_terminal_inferior */
4514 terminal_ours_for_output, /* to_terminal_ours_for_output */
4515 terminal_ours, /* to_terminal_ours */
4516 child_terminal_info, /* to_terminal_info */
4517 procfs_kill_inferior, /* to_kill */
4518 0, /* to_load */
4519 0, /* to_lookup_symbol */
4520 procfs_create_inferior, /* to_create_inferior */
4521 procfs_mourn_inferior, /* to_mourn_inferior */
4522 procfs_can_run, /* to_can_run */
3950a34e 4523 procfs_notice_signals, /* to_notice_signals */
8fc2b417 4524 procfs_thread_alive, /* to_thread_alive */
2592eef8 4525 procfs_stop, /* to_stop */
3fbdd536
JG
4526 process_stratum, /* to_stratum */
4527 0, /* to_next */
4528 1, /* to_has_all_memory */
4529 1, /* to_has_memory */
4530 1, /* to_has_stack */
4531 1, /* to_has_registers */
4532 1, /* to_has_execution */
4533 0, /* sections */
4534 0, /* sections_end */
4535 OPS_MAGIC /* to_magic */
4536};
4537
3fbdd536
JG
4538void
4539_initialize_procfs ()
4540{
2592eef8
PS
4541#ifdef HAVE_OPTIONAL_PROC_FS
4542 char procname[32];
4543 int fd;
4544
4545 /* If we have an optional /proc filesystem (e.g. under OSF/1),
4546 don't add procfs support if we cannot access the running
4547 GDB via /proc. */
4548 sprintf (procname, PROC_NAME_FMT, getpid ());
4549 if ((fd = open (procname, O_RDONLY)) < 0)
4550 return;
4551 close (fd);
4552#endif
4553
3fbdd536
JG
4554 add_target (&procfs_ops);
4555
4556 add_info ("proc", info_proc,
cc221e76
FF
4557"Show process status information using /proc entry.\n\
4558Specify process id or use current inferior by default.\n\
4559Specify keywords for detailed information; default is summary.\n\
4560Keywords are: `all', `faults', `flags', `id', `mappings', `signals',\n\
4561`status', `syscalls', and `times'.\n\
3fbdd536 4562Unambiguous abbreviations may be used.");
a39ad5ce 4563
cc221e76 4564 init_syscall_table ();
35f5886e 4565}
This page took 0.480024 seconds and 4 git commands to generate.