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