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