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