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