Commit | Line | Data |
---|---|---|
35f5886e FF |
1 | /* Machine independent support for SVR4 /proc (process file system) for GDB. |
2 | Copyright (C) 1991 Free Software Foundation, Inc. | |
3 | Written by Fred Fish at Cygnus Support. | |
4 | ||
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program; if not, write to the Free Software | |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
20 | ||
21 | ||
22 | /* N O T E S | |
23 | ||
24 | For information on the details of using /proc consult section proc(4) | |
25 | in the UNIX System V Release 4 System Administrator's Reference Manual. | |
26 | ||
27 | The general register and floating point register sets are manipulated by | |
28 | separate ioctl's. This file makes the assumption that if FP0_REGNUM is | |
29 | defined, then support for the floating point register set is desired, | |
30 | regardless of whether or not the actual target has floating point hardware. | |
31 | ||
32 | */ | |
33 | ||
34 | ||
5129100c | 35 | #include "defs.h" |
35f5886e FF |
36 | |
37 | #ifdef USE_PROC_FS /* Entire file goes away if not using /proc */ | |
38 | ||
407a8389 | 39 | #include <time.h> |
35f5886e FF |
40 | #include <sys/procfs.h> |
41 | #include <fcntl.h> | |
42 | #include <errno.h> | |
43 | ||
35f5886e FF |
44 | #include "inferior.h" |
45 | #include "target.h" | |
cc221e76 FF |
46 | #include "signame.h" |
47 | ||
48 | #define MAX_SYSCALLS 256 /* Maximum number of syscalls for table */ | |
35f5886e FF |
49 | |
50 | #ifndef PROC_NAME_FMT | |
51 | #define PROC_NAME_FMT "/proc/%d" | |
52 | #endif | |
53 | ||
35f5886e FF |
54 | #if 1 /* FIXME: Gross and ugly hack to resolve coredep.c global */ |
55 | CORE_ADDR kernel_u_addr; | |
56 | #endif | |
57 | ||
cc221e76 FF |
58 | #ifdef BROKEN_SIGINFO_H /* Workaround broken SGS <sys/siginfo.h> */ |
59 | #undef si_pid | |
60 | #define si_pid _data._proc.pid | |
61 | #undef si_uid | |
62 | #define si_uid _data._proc._pdata._kill.uid | |
63 | #endif /* BROKEN_SIGINFO_H */ | |
64 | ||
35f5886e FF |
65 | /* All access to the inferior, either one started by gdb or one that has |
66 | been attached to, is controlled by an instance of a procinfo structure, | |
67 | defined below. Since gdb currently only handles one inferior at a time, | |
a39ad5ce FF |
68 | the procinfo structure for the inferior is statically allocated and |
69 | only one exists at any given time. There is a separate procinfo | |
70 | structure for use by the "info proc" command, so that we can print | |
71 | useful information about any random process without interfering with | |
72 | the inferior's procinfo information. */ | |
35f5886e FF |
73 | |
74 | struct procinfo { | |
75 | int valid; /* Nonzero if pid, fd, & pathname are valid */ | |
76 | int pid; /* Process ID of inferior */ | |
77 | int fd; /* File descriptor for /proc entry */ | |
78 | char *pathname; /* Pathname to /proc entry */ | |
79 | int was_stopped; /* Nonzero if was stopped prior to attach */ | |
80 | prrun_t prrun; /* Control state when it is run */ | |
81 | prstatus_t prstatus; /* Current process status info */ | |
82 | gregset_t gregset; /* General register set */ | |
83 | fpregset_t fpregset; /* Floating point register set */ | |
84 | fltset_t fltset; /* Current traced hardware fault set */ | |
85 | sigset_t trace; /* Current traced signal set */ | |
86 | sysset_t exitset; /* Current traced system call exit set */ | |
87 | sysset_t entryset; /* Current traced system call entry set */ | |
cc221e76 FF |
88 | fltset_t saved_fltset; /* Saved traced hardware fault set */ |
89 | sigset_t saved_trace; /* Saved traced signal set */ | |
90 | sigset_t saved_sighold; /* Saved held signal set */ | |
91 | sysset_t saved_exitset; /* Saved traced system call exit set */ | |
92 | sysset_t saved_entryset; /* Saved traced system call entry set */ | |
a39ad5ce FF |
93 | }; |
94 | ||
95 | static struct procinfo pi; /* Inferior's process information */ | |
35f5886e | 96 | |
cc221e76 FF |
97 | /* Much of the information used in the /proc interface, particularly for |
98 | printing status information, is kept as tables of structures of the | |
99 | following form. These tables can be used to map numeric values to | |
100 | their symbolic names and to a string that describes their specific use. */ | |
101 | ||
102 | struct trans { | |
103 | int value; /* The numeric value */ | |
104 | char *name; /* The equivalent symbolic value */ | |
105 | char *desc; /* Short description of value */ | |
106 | }; | |
107 | ||
108 | /* Translate bits in the pr_flags member of the prstatus structure, into the | |
109 | names and desc information. */ | |
110 | ||
111 | static struct trans pr_flag_table[] = | |
112 | { | |
113 | #if defined (PR_STOPPED) | |
114 | PR_STOPPED, "PR_STOPPED", "Process is stopped", | |
115 | #endif | |
116 | #if defined (PR_ISTOP) | |
117 | PR_ISTOP, "PR_ISTOP", "Stopped on an event of interest", | |
118 | #endif | |
119 | #if defined (PR_DSTOP) | |
120 | PR_DSTOP, "PR_DSTOP", "A stop directive is in effect", | |
121 | #endif | |
122 | #if defined (PR_ASLEEP) | |
123 | PR_ASLEEP, "PR_ASLEEP", "Sleeping in an interruptible system call", | |
124 | #endif | |
125 | #if defined (PR_FORK) | |
126 | PR_FORK, "PR_FORK", "Inherit-on-fork is in effect", | |
127 | #endif | |
128 | #if defined (PR_RLC) | |
129 | PR_RLC, "PR_RLC", "Run-on-last-close is in effect", | |
130 | #endif | |
131 | #if defined (PR_PTRACE) | |
132 | PR_PTRACE, "PR_PTRACE", "Process is being controlled by ptrace", | |
133 | #endif | |
134 | #if defined (PR_PCINVAL) | |
135 | PR_PCINVAL, "PR_PCINVAL", "PC refers to an invalid virtual address", | |
136 | #endif | |
137 | #if defined (PR_ISSYS) | |
138 | PR_ISSYS, "PR_ISSYS", "Is a system process", | |
139 | #endif | |
140 | 0, NULL, NULL | |
141 | }; | |
142 | ||
143 | /* Translate values in the pr_why field of the prstatus struct. */ | |
144 | ||
145 | static struct trans pr_why_table[] = | |
146 | { | |
147 | #if defined (PR_REQUESTED) | |
148 | PR_REQUESTED, "PR_REQUESTED", "Directed to stop via PIOCSTOP/PIOCWSTOP", | |
149 | #endif | |
150 | #if defined (PR_SIGNALLED) | |
151 | PR_SIGNALLED, "PR_SIGNALLED", "Receipt of a traced signal", | |
152 | #endif | |
153 | #if defined (PR_FAULTED) | |
154 | PR_FAULTED, "PR_FAULTED", "Incurred a traced hardware fault", | |
155 | #endif | |
156 | #if defined (PR_SYSENTRY) | |
157 | PR_SYSENTRY, "PR_SYSENTRY", "Entry to a traced system call", | |
158 | #endif | |
159 | #if defined (PR_SYSEXIT) | |
160 | PR_SYSEXIT, "PR_SYSEXIT", "Exit from a traced system call", | |
161 | #endif | |
162 | #if defined (PR_JOBCONTROL) | |
163 | PR_JOBCONTROL, "PR_JOBCONTROL", "Default job control stop signal action", | |
164 | #endif | |
165 | 0, NULL, NULL | |
166 | }; | |
167 | ||
168 | /* Hardware fault translation table. */ | |
169 | ||
170 | static struct trans faults_table[] = | |
171 | { | |
172 | #if defined (FLTILL) | |
173 | FLTILL, "FLTILL", "Illegal instruction", | |
174 | #endif | |
175 | #if defined (FLTPRIV) | |
176 | FLTPRIV, "FLTPRIV", "Privileged instruction", | |
177 | #endif | |
178 | #if defined (FLTBPT) | |
179 | FLTBPT, "FLTBPT", "Breakpoint trap", | |
180 | #endif | |
181 | #if defined (FLTTRACE) | |
182 | FLTTRACE, "FLTTRACE", "Trace trap", | |
183 | #endif | |
184 | #if defined (FLTACCESS) | |
185 | FLTACCESS, "FLTACCESS", "Memory access fault", | |
186 | #endif | |
187 | #if defined (FLTBOUNDS) | |
188 | FLTBOUNDS, "FLTBOUNDS", "Memory bounds violation", | |
189 | #endif | |
190 | #if defined (FLTIOVF) | |
191 | FLTIOVF, "FLTIOVF", "Integer overflow", | |
192 | #endif | |
193 | #if defined (FLTIZDIV) | |
194 | FLTIZDIV, "FLTIZDIV", "Integer zero divide", | |
195 | #endif | |
196 | #if defined (FLTFPE) | |
197 | FLTFPE, "FLTFPE", "Floating-point exception", | |
198 | #endif | |
199 | #if defined (FLTSTACK) | |
200 | FLTSTACK, "FLTSTACK", "Unrecoverable stack fault", | |
201 | #endif | |
202 | #if defined (FLTPAGE) | |
203 | FLTPAGE, "FLTPAGE", "Recoverable page fault", | |
204 | #endif | |
205 | 0, NULL, NULL | |
206 | }; | |
207 | ||
208 | /* Translation table for signal generation information. See UNIX System | |
209 | V Release 4 Programmer's Reference Manual, siginfo(5). */ | |
210 | ||
211 | static struct sigcode { | |
212 | int signo; | |
213 | int code; | |
214 | char *codename; | |
215 | char *desc; | |
216 | } siginfo_table[] = { | |
217 | #if defined (SIGILL) && defined (ILL_ILLOPC) | |
218 | SIGILL, ILL_ILLOPC, "ILL_ILLOPC", "Illegal opcode", | |
219 | #endif | |
220 | #if defined (SIGILL) && defined (ILL_ILLOPN) | |
221 | SIGILL, ILL_ILLOPN, "ILL_ILLOPN", "Illegal operand", | |
222 | #endif | |
223 | #if defined (SIGILL) && defined (ILL_ILLADR) | |
224 | SIGILL, ILL_ILLADR, "ILL_ILLADR", "Illegal addressing mode", | |
225 | #endif | |
226 | #if defined (SIGILL) && defined (ILL_ILLTRP) | |
227 | SIGILL, ILL_ILLTRP, "ILL_ILLTRP", "Illegal trap", | |
228 | #endif | |
229 | #if defined (SIGILL) && defined (ILL_PRVOPC) | |
230 | SIGILL, ILL_PRVOPC, "ILL_PRVOPC", "Privileged opcode", | |
231 | #endif | |
232 | #if defined (SIGILL) && defined (ILL_PRVREG) | |
233 | SIGILL, ILL_PRVREG, "ILL_PRVREG", "Privileged register", | |
234 | #endif | |
235 | #if defined (SIGILL) && defined (ILL_COPROC) | |
236 | SIGILL, ILL_COPROC, "ILL_COPROC", "Coprocessor error", | |
237 | #endif | |
238 | #if defined (SIGILL) && defined (ILL_BADSTK) | |
239 | SIGILL, ILL_BADSTK, "ILL_BADSTK", "Internal stack error", | |
240 | #endif | |
241 | #if defined (SIGFPE) && defined (FPE_INTDIV) | |
242 | SIGFPE, FPE_INTDIV, "FPE_INTDIV", "Integer divide by zero", | |
243 | #endif | |
244 | #if defined (SIGFPE) && defined (FPE_INTOVF) | |
245 | SIGFPE, FPE_INTOVF, "FPE_INTOVF", "Integer overflow", | |
246 | #endif | |
247 | #if defined (SIGFPE) && defined (FPE_FLTDIV) | |
248 | SIGFPE, FPE_FLTDIV, "FPE_FLTDIV", "Floating point divide by zero", | |
249 | #endif | |
250 | #if defined (SIGFPE) && defined (FPE_FLTOVF) | |
251 | SIGFPE, FPE_FLTOVF, "FPE_FLTOVF", "Floating point overflow", | |
252 | #endif | |
253 | #if defined (SIGFPE) && defined (FPE_FLTUND) | |
254 | SIGFPE, FPE_FLTUND, "FPE_FLTUND", "Floating point underflow", | |
255 | #endif | |
256 | #if defined (SIGFPE) && defined (FPE_FLTRES) | |
257 | SIGFPE, FPE_FLTRES, "FPE_FLTRES", "Floating point inexact result", | |
258 | #endif | |
259 | #if defined (SIGFPE) && defined (FPE_FLTINV) | |
260 | SIGFPE, FPE_FLTINV, "FPE_FLTINV", "Invalid floating point operation", | |
261 | #endif | |
262 | #if defined (SIGFPE) && defined (FPE_FLTSUB) | |
263 | SIGFPE, FPE_FLTSUB, "FPE_FLTSUB", "Subscript out of range", | |
264 | #endif | |
265 | #if defined (SIGSEGV) && defined (SEGV_MAPERR) | |
266 | SIGSEGV, SEGV_MAPERR, "SEGV_MAPERR", "Address not mapped to object", | |
267 | #endif | |
268 | #if defined (SIGSEGV) && defined (SEGV_ACCERR) | |
269 | SIGSEGV, SEGV_ACCERR, "SEGV_ACCERR", "Invalid permissions for object", | |
270 | #endif | |
271 | #if defined (SIGBUS) && defined (BUS_ADRALN) | |
272 | SIGBUS, BUS_ADRALN, "BUS_ADRALN", "Invalid address alignment", | |
273 | #endif | |
274 | #if defined (SIGBUS) && defined (BUS_ADRERR) | |
275 | SIGBUS, BUS_ADRERR, "BUS_ADRERR", "Non-existent physical address", | |
276 | #endif | |
277 | #if defined (SIGBUS) && defined (BUS_OBJERR) | |
278 | SIGBUS, BUS_OBJERR, "BUS_OBJERR", "Object specific hardware error", | |
279 | #endif | |
280 | #if defined (SIGTRAP) && defined (TRAP_BRKPT) | |
281 | SIGTRAP, TRAP_BRKPT, "TRAP_BRKPT", "Process breakpoint", | |
282 | #endif | |
283 | #if defined (SIGTRAP) && defined (TRAP_TRACE) | |
284 | SIGTRAP, TRAP_TRACE, "TRAP_TRACE", "Process trace trap", | |
285 | #endif | |
286 | #if defined (SIGCLD) && defined (CLD_EXITED) | |
287 | SIGCLD, CLD_EXITED, "CLD_EXITED", "Child has exited", | |
288 | #endif | |
289 | #if defined (SIGCLD) && defined (CLD_KILLED) | |
290 | SIGCLD, CLD_KILLED, "CLD_KILLED", "Child was killed", | |
291 | #endif | |
292 | #if defined (SIGCLD) && defined (CLD_DUMPED) | |
293 | SIGCLD, CLD_DUMPED, "CLD_DUMPED", "Child has terminated abnormally", | |
294 | #endif | |
295 | #if defined (SIGCLD) && defined (CLD_TRAPPED) | |
296 | SIGCLD, CLD_TRAPPED, "CLD_TRAPPED", "Traced child has trapped", | |
297 | #endif | |
298 | #if defined (SIGCLD) && defined (CLD_STOPPED) | |
299 | SIGCLD, CLD_STOPPED, "CLD_STOPPED", "Child has stopped", | |
300 | #endif | |
301 | #if defined (SIGCLD) && defined (CLD_CONTINUED) | |
302 | SIGCLD, CLD_CONTINUED, "CLD_CONTINUED", "Stopped child had continued", | |
303 | #endif | |
304 | #if defined (SIGPOLL) && defined (POLL_IN) | |
305 | SIGPOLL, POLL_IN, "POLL_IN", "Input input available", | |
306 | #endif | |
307 | #if defined (SIGPOLL) && defined (POLL_OUT) | |
308 | SIGPOLL, POLL_OUT, "POLL_OUT", "Output buffers available", | |
309 | #endif | |
310 | #if defined (SIGPOLL) && defined (POLL_MSG) | |
311 | SIGPOLL, POLL_MSG, "POLL_MSG", "Input message available", | |
312 | #endif | |
313 | #if defined (SIGPOLL) && defined (POLL_ERR) | |
314 | SIGPOLL, POLL_ERR, "POLL_ERR", "I/O error", | |
315 | #endif | |
316 | #if defined (SIGPOLL) && defined (POLL_PRI) | |
317 | SIGPOLL, POLL_PRI, "POLL_PRI", "High priority input available", | |
318 | #endif | |
319 | #if defined (SIGPOLL) && defined (POLL_HUP) | |
320 | SIGPOLL, POLL_HUP, "POLL_HUP", "Device disconnected", | |
321 | #endif | |
322 | 0, 0, NULL, NULL | |
323 | }; | |
324 | ||
325 | /* Translation table for errno values. See intro(2) in most UNIX systems | |
326 | Programmers Reference Manuals. | |
327 | ||
328 | Note that some systems provide a function (strerror) that returns the | |
329 | error message string, or a global variable that is the base address of the | |
330 | array of character pointers. Perhaps we should try to make use of these | |
331 | provided strings if they are present, but at least this is more portable. | |
332 | (FIXME?) */ | |
333 | ||
334 | static struct trans errno_table[] = | |
335 | { | |
336 | #if defined (EPERM) | |
337 | EPERM, "EPERM", "Not super-user", | |
338 | #endif | |
339 | #if defined (ENOENT) | |
340 | ENOENT, "ENOENT", "No such file or directory", | |
341 | #endif | |
342 | #if defined (ESRCH) | |
343 | ESRCH, "ESRCH", "No such process", | |
344 | #endif | |
345 | #if defined (EINTR) | |
346 | EINTR, "EINTR", "Interrupted system call", | |
347 | #endif | |
348 | #if defined (EIO) | |
349 | EIO, "EIO", "I/O error", | |
350 | #endif | |
351 | #if defined (ENXIO) | |
352 | ENXIO, "ENXIO", "No such device or address", | |
353 | #endif | |
354 | #if defined (E2BIG) | |
355 | E2BIG, "E2BIG", "Arg list too long", | |
356 | #endif | |
357 | #if defined (ENOEXEC) | |
358 | ENOEXEC, "ENOEXEC", "Exec format error", | |
359 | #endif | |
360 | #if defined (EBADF) | |
361 | EBADF, "EBADF", "Bad file number", | |
362 | #endif | |
363 | #if defined (ECHILD) | |
364 | ECHILD, "ECHILD", "No child process", | |
365 | #endif | |
366 | #if defined (EAGAIN) | |
367 | EAGAIN, "EAGAIN", "No more processes", | |
368 | #endif | |
369 | #if defined (ENOMEM) | |
370 | ENOMEM, "ENOMEM", "Not enough space", | |
371 | #endif | |
372 | #if defined (EACCES) | |
373 | EACCES, "EACCES", "Permission denied", | |
374 | #endif | |
375 | #if defined (EFAULT) | |
376 | EFAULT, "EFAULT", "Bad address", | |
377 | #endif | |
378 | #if defined (ENOTBLK) | |
379 | ENOTBLK, "ENOTBLK", "Block device required", | |
380 | #endif | |
381 | #if defined (EBUSY) | |
382 | EBUSY, "EBUSY", "Device busy", | |
383 | #endif | |
384 | #if defined (EEXIST) | |
385 | EEXIST, "EEXIST", "File exists", | |
386 | #endif | |
387 | #if defined (EXDEV) | |
388 | EXDEV, "EXDEV", "Cross-device link", | |
389 | #endif | |
390 | #if defined (ENODEV) | |
391 | ENODEV, "ENODEV", "No such device", | |
392 | #endif | |
393 | #if defined (ENOTDIR) | |
394 | ENOTDIR, "ENOTDIR", "Not a directory", | |
395 | #endif | |
396 | #if defined (EISDIR) | |
397 | EISDIR, "EISDIR", "Is a directory", | |
398 | #endif | |
399 | #if defined (EINVAL) | |
400 | EINVAL, "EINVAL", "Invalid argument", | |
401 | #endif | |
402 | #if defined (ENFILE) | |
403 | ENFILE, "ENFILE", "File table overflow", | |
404 | #endif | |
405 | #if defined (EMFILE) | |
406 | EMFILE, "EMFILE", "Too many open files", | |
407 | #endif | |
408 | #if defined (ENOTTY) | |
409 | ENOTTY, "ENOTTY", "Not a typewriter", | |
410 | #endif | |
411 | #if defined (ETXTBSY) | |
412 | ETXTBSY, "ETXTBSY", "Text file busy", | |
413 | #endif | |
414 | #if defined (EFBIG) | |
415 | EFBIG, "EFBIG", "File too large", | |
416 | #endif | |
417 | #if defined (ENOSPC) | |
418 | ENOSPC, "ENOSPC", "No space left on device", | |
419 | #endif | |
420 | #if defined (ESPIPE) | |
421 | ESPIPE, "ESPIPE", "Illegal seek", | |
422 | #endif | |
423 | #if defined (EROFS) | |
424 | EROFS, "EROFS", "Read only file system", | |
425 | #endif | |
426 | #if defined (EMLINK) | |
427 | EMLINK, "EMLINK", "Too many links", | |
428 | #endif | |
429 | #if defined (EPIPE) | |
430 | EPIPE, "EPIPE", "Broken pipe", | |
431 | #endif | |
432 | #if defined (EDOM) | |
433 | EDOM, "EDOM", "Math argument out of domain of func", | |
434 | #endif | |
435 | #if defined (ERANGE) | |
436 | ERANGE, "ERANGE", "Math result not representable", | |
437 | #endif | |
438 | #if defined (ENOMSG) | |
439 | ENOMSG, "ENOMSG", "No message of desired type", | |
440 | #endif | |
441 | #if defined (EIDRM) | |
442 | EIDRM, "EIDRM", "Identifier removed", | |
443 | #endif | |
444 | #if defined (ECHRNG) | |
445 | ECHRNG, "ECHRNG", "Channel number out of range", | |
446 | #endif | |
447 | #if defined (EL2NSYNC) | |
448 | EL2NSYNC, "EL2NSYNC", "Level 2 not synchronized", | |
449 | #endif | |
450 | #if defined (EL3HLT) | |
451 | EL3HLT, "EL3HLT", "Level 3 halted", | |
452 | #endif | |
453 | #if defined (EL3RST) | |
454 | EL3RST, "EL3RST", "Level 3 reset", | |
455 | #endif | |
456 | #if defined (ELNRNG) | |
457 | ELNRNG, "ELNRNG", "Link number out of range", | |
458 | #endif | |
459 | #if defined (EUNATCH) | |
460 | EUNATCH, "EUNATCH", "Protocol driver not attached", | |
461 | #endif | |
462 | #if defined (ENOCSI) | |
463 | ENOCSI, "ENOCSI", "No CSI structure available", | |
464 | #endif | |
465 | #if defined (EL2HLT) | |
466 | EL2HLT, "EL2HLT", "Level 2 halted", | |
467 | #endif | |
468 | #if defined (EDEADLK) | |
469 | EDEADLK, "EDEADLK", "Deadlock condition", | |
470 | #endif | |
471 | #if defined (ENOLCK) | |
472 | ENOLCK, "ENOLCK", "No record locks available", | |
473 | #endif | |
474 | #if defined (EBADE) | |
475 | EBADE, "EBADE", "Invalid exchange", | |
476 | #endif | |
477 | #if defined (EBADR) | |
478 | EBADR, "EBADR", "Invalid request descriptor", | |
479 | #endif | |
480 | #if defined (EXFULL) | |
481 | EXFULL, "EXFULL", "Exchange full", | |
482 | #endif | |
483 | #if defined (ENOANO) | |
484 | ENOANO, "ENOANO", "No anode", | |
485 | #endif | |
486 | #if defined (EBADRQC) | |
487 | EBADRQC, "EBADRQC", "Invalid request code", | |
488 | #endif | |
489 | #if defined (EBADSLT) | |
490 | EBADSLT, "EBADSLT", "Invalid slot", | |
491 | #endif | |
492 | #if defined (EDEADLOCK) | |
493 | EDEADLOCK, "EDEADLOCK", "File locking deadlock error", | |
494 | #endif | |
495 | #if defined (EBFONT) | |
496 | EBFONT, "EBFONT", "Bad font file fmt", | |
497 | #endif | |
498 | #if defined (ENOSTR) | |
499 | ENOSTR, "ENOSTR", "Device not a stream", | |
500 | #endif | |
501 | #if defined (ENODATA) | |
502 | ENODATA, "ENODATA", "No data available", | |
503 | #endif | |
504 | #if defined (ETIME) | |
505 | ETIME, "ETIME", "Timer expired", | |
506 | #endif | |
507 | #if defined (ENOSR) | |
508 | ENOSR, "ENOSR", "Out of streams resources", | |
509 | #endif | |
510 | #if defined (ENONET) | |
511 | ENONET, "ENONET", "Machine is not on the network", | |
512 | #endif | |
513 | #if defined (ENOPKG) | |
514 | ENOPKG, "ENOPKG", "Package not installed", | |
515 | #endif | |
516 | #if defined (EREMOTE) | |
517 | EREMOTE, "EREMOTE", "Object is remote", | |
518 | #endif | |
519 | #if defined (ENOLINK) | |
520 | ENOLINK, "ENOLINK", "Link has been severed", | |
521 | #endif | |
522 | #if defined (EADV) | |
523 | EADV, "EADV", "Advertise error", | |
524 | #endif | |
525 | #if defined (ESRMNT) | |
526 | ESRMNT, "ESRMNT", "Srmount error", | |
527 | #endif | |
528 | #if defined (ECOMM) | |
529 | ECOMM, "ECOMM", "Communication error on send", | |
530 | #endif | |
531 | #if defined (EPROTO) | |
532 | EPROTO, "EPROTO", "Protocol error", | |
533 | #endif | |
534 | #if defined (EMULTIHOP) | |
535 | EMULTIHOP, "EMULTIHOP", "Multihop attempted", | |
536 | #endif | |
537 | #if defined (EDOTDOT) | |
538 | EDOTDOT, "EDOTDOT", "RFS specific error", | |
539 | #endif | |
540 | #if defined (EBADMSG) | |
541 | EBADMSG, "EBADMSG", "Not a data message", | |
542 | #endif | |
543 | #if defined (ENAMETOOLONG) | |
544 | ENAMETOOLONG, "ENAMETOOLONG", "File name too long", | |
545 | #endif | |
546 | #if defined (EOVERFLOW) | |
547 | EOVERFLOW, "EOVERFLOW", "Value too large for defined data type", | |
548 | #endif | |
549 | #if defined (ENOTUNIQ) | |
550 | ENOTUNIQ, "ENOTUNIQ", "Name not unique on network", | |
551 | #endif | |
552 | #if defined (EBADFD) | |
553 | EBADFD, "EBADFD", "File descriptor in bad state", | |
554 | #endif | |
555 | #if defined (EREMCHG) | |
556 | EREMCHG, "EREMCHG", "Remote address changed", | |
557 | #endif | |
558 | #if defined (ELIBACC) | |
559 | ELIBACC, "ELIBACC", "Cannot access a needed shared library", | |
560 | #endif | |
561 | #if defined (ELIBBAD) | |
562 | ELIBBAD, "ELIBBAD", "Accessing a corrupted shared library", | |
563 | #endif | |
564 | #if defined (ELIBSCN) | |
565 | ELIBSCN, "ELIBSCN", ".lib section in a.out corrupted", | |
566 | #endif | |
567 | #if defined (ELIBMAX) | |
568 | ELIBMAX, "ELIBMAX", "Attempting to link in too many shared libraries", | |
569 | #endif | |
570 | #if defined (ELIBEXEC) | |
571 | ELIBEXEC, "ELIBEXEC", "Cannot exec a shared library directly", | |
572 | #endif | |
573 | #if defined (EILSEQ) | |
574 | EILSEQ, "EILSEQ", "Illegal byte sequence", | |
575 | #endif | |
576 | #if defined (ENOSYS) | |
577 | ENOSYS, "ENOSYS", "Operation not applicable", | |
578 | #endif | |
579 | #if defined (ELOOP) | |
580 | ELOOP, "ELOOP", "Too many symbolic links encountered", | |
581 | #endif | |
582 | #if defined (ERESTART) | |
583 | ERESTART, "ERESTART", "Interrupted system call should be restarted", | |
584 | #endif | |
585 | #if defined (ESTRPIPE) | |
586 | ESTRPIPE, "ESTRPIPE", "Streams pipe error", | |
587 | #endif | |
588 | #if defined (ENOTEMPTY) | |
589 | ENOTEMPTY, "ENOTEMPTY", "Directory not empty", | |
590 | #endif | |
591 | #if defined (EUSERS) | |
592 | EUSERS, "EUSERS", "Too many users", | |
593 | #endif | |
594 | #if defined (ENOTSOCK) | |
595 | ENOTSOCK, "ENOTSOCK", "Socket operation on non-socket", | |
596 | #endif | |
597 | #if defined (EDESTADDRREQ) | |
598 | EDESTADDRREQ, "EDESTADDRREQ", "Destination address required", | |
599 | #endif | |
600 | #if defined (EMSGSIZE) | |
601 | EMSGSIZE, "EMSGSIZE", "Message too long", | |
602 | #endif | |
603 | #if defined (EPROTOTYPE) | |
604 | EPROTOTYPE, "EPROTOTYPE", "Protocol wrong type for socket", | |
605 | #endif | |
606 | #if defined (ENOPROTOOPT) | |
607 | ENOPROTOOPT, "ENOPROTOOPT", "Protocol not available", | |
608 | #endif | |
609 | #if defined (EPROTONOSUPPORT) | |
610 | EPROTONOSUPPORT, "EPROTONOSUPPORT", "Protocol not supported", | |
611 | #endif | |
612 | #if defined (ESOCKTNOSUPPORT) | |
613 | ESOCKTNOSUPPORT, "ESOCKTNOSUPPORT", "Socket type not supported", | |
614 | #endif | |
615 | #if defined (EOPNOTSUPP) | |
616 | EOPNOTSUPP, "EOPNOTSUPP", "Operation not supported on transport endpoint ", | |
617 | #endif | |
618 | #if defined (EPFNOSUPPORT) | |
619 | EPFNOSUPPORT, "EPFNOSUPPORT", "Protocol family not supported", | |
620 | #endif | |
621 | #if defined (EAFNOSUPPORT) | |
622 | EAFNOSUPPORT, "EAFNOSUPPORT", "Address family not supported by protocol", | |
623 | #endif | |
624 | #if defined (EADDRINUSE) | |
625 | EADDRINUSE, "EADDRINUSE", "Address already in use", | |
626 | #endif | |
627 | #if defined (EADDRNOTAVAIL) | |
628 | EADDRNOTAVAIL, "EADDRNOTAVAIL","Cannot assign requested address", | |
629 | #endif | |
630 | #if defined (ENETDOWN) | |
631 | ENETDOWN, "ENETDOWN", "Network is down", | |
632 | #endif | |
633 | #if defined (ENETUNREACH) | |
634 | ENETUNREACH, "ENETUNREACH", "Network is unreachable", | |
635 | #endif | |
636 | #if defined (ENETRESET) | |
637 | ENETRESET, "ENETRESET", "Network dropped connection because of reset", | |
638 | #endif | |
639 | #if defined (ECONNABORTED) | |
640 | ECONNABORTED, "ECONNABORTED", "Software caused connection abort", | |
641 | #endif | |
642 | #if defined (ECONNRESET) | |
643 | ECONNRESET, "ECONNRESET", "Connection reset by peer", | |
644 | #endif | |
645 | #if defined (ENOBUFS) | |
646 | ENOBUFS, "ENOBUFS", "No buffer space available", | |
647 | #endif | |
648 | #if defined (EISCONN) | |
649 | EISCONN, "EISCONN", "Transport endpoint is already connected", | |
650 | #endif | |
651 | #if defined (ENOTCONN) | |
652 | ENOTCONN, "ENOTCONN", "Transport endpoint is not connected", | |
653 | #endif | |
654 | #if defined (ESHUTDOWN) | |
655 | ESHUTDOWN, "ESHUTDOWN", "Cannot send after transport endpoint shutdown", | |
656 | #endif | |
657 | #if defined (ETOOMANYREFS) | |
658 | ETOOMANYREFS, "ETOOMANYREFS", "Too many references: cannot splice", | |
659 | #endif | |
660 | #if defined (ETIMEDOUT) | |
661 | ETIMEDOUT, "ETIMEDOUT", "Connection timed out", | |
662 | #endif | |
663 | #if defined (ECONNREFUSED) | |
664 | ECONNREFUSED, "ECONNREFUSED", "Connection refused", | |
665 | #endif | |
666 | #if defined (EHOSTDOWN) | |
667 | EHOSTDOWN, "EHOSTDOWN", "Host is down", | |
668 | #endif | |
669 | #if defined (EHOSTUNREACH) | |
670 | EHOSTUNREACH, "EHOSTUNREACH", "No route to host", | |
671 | #endif | |
672 | #if defined (EWOULDBLOCK) | |
673 | EWOULDBLOCK, "EWOULDBLOCK", "Operation already in progress", | |
674 | #endif | |
675 | #if defined (EINPROGRESS) | |
676 | EINPROGRESS, "EINPROGRESS", "Operation now in progress", | |
677 | #endif | |
678 | #if defined (ESTALE) | |
679 | ESTALE, "ESTALE", "Stale NFS file handle", | |
680 | #endif | |
681 | #if defined (EUCLEAN) | |
682 | EUCLEAN, "EUCLEAN", "Structure needs cleaning", | |
683 | #endif | |
684 | #if defined (ENOTNAM) | |
685 | ENOTNAM, "ENOTNAM", "Not a XENIX named type file", | |
686 | #endif | |
687 | #if defined (ENAVAIL) | |
688 | ENAVAIL, "ENAVAIL", "No XENIX semaphores available", | |
689 | #endif | |
690 | #if defined (EISNAM) | |
691 | EISNAM, "EISNAM", "Is a named type file", | |
692 | #endif | |
693 | #if defined (EREMOTEIO) | |
694 | EREMOTEIO, "EREMOTEIO", "Remote I/O error", | |
695 | #endif | |
696 | 0, NULL, NULL | |
697 | }; | |
698 | ||
699 | static char *syscall_table[MAX_SYSCALLS]; | |
700 | ||
1ab3bf1b JG |
701 | /* Prototypes for local functions */ |
702 | ||
6b801388 FF |
703 | static void |
704 | set_proc_siginfo PARAMS ((struct procinfo *, int)); | |
705 | ||
cc221e76 FF |
706 | static void |
707 | init_syscall_table PARAMS ((void)); | |
708 | ||
709 | static char * | |
710 | syscallname PARAMS ((int)); | |
711 | ||
712 | static char * | |
713 | signalname PARAMS ((int)); | |
714 | ||
1ab3bf1b JG |
715 | static int |
716 | proc_address_to_fd PARAMS ((CORE_ADDR, int)); | |
717 | ||
718 | static int | |
719 | open_proc_file PARAMS ((int, struct procinfo *)); | |
720 | ||
721 | static void | |
722 | close_proc_file PARAMS ((struct procinfo *)); | |
723 | ||
724 | static void | |
725 | unconditionally_kill_inferior PARAMS ((void)); | |
726 | ||
727 | static void | |
728 | proc_init_failed PARAMS ((char *)); | |
729 | ||
730 | static void | |
cc221e76 FF |
731 | info_proc PARAMS ((char *, int)); |
732 | ||
733 | static void | |
734 | info_proc_flags PARAMS ((struct procinfo *, int)); | |
735 | ||
736 | static void | |
737 | info_proc_stop PARAMS ((struct procinfo *, int)); | |
1ab3bf1b JG |
738 | |
739 | static void | |
cc221e76 FF |
740 | info_proc_siginfo PARAMS ((struct procinfo *, int)); |
741 | ||
742 | static void | |
743 | info_proc_syscalls PARAMS ((struct procinfo *, int)); | |
744 | ||
745 | static void | |
746 | info_proc_mappings PARAMS ((struct procinfo *, int)); | |
747 | ||
748 | static void | |
749 | info_proc_signals PARAMS ((struct procinfo *, int)); | |
750 | ||
751 | static void | |
752 | info_proc_faults PARAMS ((struct procinfo *, int)); | |
1ab3bf1b JG |
753 | |
754 | static char * | |
755 | mappingflags PARAMS ((long)); | |
756 | ||
cc221e76 FF |
757 | static char * |
758 | lookupname PARAMS ((struct trans *, unsigned int, char *)); | |
759 | ||
760 | static char * | |
761 | lookupdesc PARAMS ((struct trans *, unsigned int)); | |
762 | ||
1ab3bf1b JG |
763 | /* External function prototypes that can't be easily included in any |
764 | header file because the args are typedefs in system include files. */ | |
765 | ||
766 | extern void | |
767 | supply_gregset PARAMS ((gregset_t *)); | |
768 | ||
769 | extern void | |
770 | fill_gregset PARAMS ((gregset_t *, int)); | |
771 | ||
772 | extern void | |
773 | supply_fpregset PARAMS ((fpregset_t *)); | |
774 | ||
775 | extern void | |
776 | fill_fpregset PARAMS ((fpregset_t *, int)); | |
35f5886e | 777 | |
cc221e76 FF |
778 | /* |
779 | ||
780 | LOCAL FUNCTION | |
781 | ||
782 | lookupdesc -- translate a value to a summary desc string | |
783 | ||
784 | SYNOPSIS | |
785 | ||
786 | static char *lookupdesc (struct trans *transp, unsigned int val); | |
787 | ||
788 | DESCRIPTION | |
789 | ||
790 | Given a pointer to a translation table and a value to be translated, | |
791 | lookup the desc string and return it. | |
792 | */ | |
793 | ||
794 | static char * | |
795 | lookupdesc (transp, val) | |
796 | struct trans *transp; | |
797 | unsigned int val; | |
798 | { | |
799 | char *desc; | |
800 | ||
801 | for (desc = NULL; transp -> name != NULL; transp++) | |
802 | { | |
803 | if (transp -> value == val) | |
804 | { | |
805 | desc = transp -> desc; | |
806 | break; | |
807 | } | |
808 | } | |
809 | ||
810 | /* Didn't find a translation for the specified value, set a default one. */ | |
811 | ||
812 | if (desc == NULL) | |
813 | { | |
814 | desc = "Unknown"; | |
815 | } | |
816 | return (desc); | |
817 | } | |
818 | ||
819 | /* | |
820 | ||
821 | LOCAL FUNCTION | |
822 | ||
823 | lookupname -- translate a value to symbolic name | |
824 | ||
825 | SYNOPSIS | |
826 | ||
827 | static char *lookupname (struct trans *transp, unsigned int val, | |
828 | char *prefix); | |
829 | ||
830 | DESCRIPTION | |
831 | ||
832 | Given a pointer to a translation table, a value to be translated, | |
833 | and a default prefix to return if the value can't be translated, | |
834 | match the value with one of the translation table entries and | |
835 | return a pointer to the symbolic name. | |
836 | ||
837 | If no match is found it just returns the value as a printable string, | |
838 | with the given prefix. The previous such value, if any, is freed | |
839 | at this time. | |
840 | */ | |
841 | ||
842 | static char * | |
843 | lookupname (transp, val, prefix) | |
844 | struct trans *transp; | |
845 | unsigned int val; | |
846 | char *prefix; | |
847 | { | |
848 | static char *locbuf; | |
849 | char *name; | |
850 | ||
851 | for (name = NULL; transp -> name != NULL; transp++) | |
852 | { | |
853 | if (transp -> value == val) | |
854 | { | |
855 | name = transp -> name; | |
856 | break; | |
857 | } | |
858 | } | |
859 | ||
860 | /* Didn't find a translation for the specified value, build a default | |
861 | one using the specified prefix and return it. The lifetime of | |
862 | the value is only until the next one is needed. */ | |
863 | ||
864 | if (name == NULL) | |
865 | { | |
866 | if (locbuf != NULL) | |
867 | { | |
868 | free (locbuf); | |
869 | } | |
870 | locbuf = xmalloc (strlen (prefix) + 16); | |
871 | (void) sprintf (locbuf, "%s %u", prefix, val); | |
872 | name = locbuf; | |
873 | } | |
874 | return (name); | |
875 | } | |
876 | ||
877 | static char * | |
878 | sigcodename (sip) | |
879 | siginfo_t *sip; | |
880 | { | |
881 | struct sigcode *scp; | |
882 | char *name = NULL; | |
883 | static char locbuf[32]; | |
884 | ||
885 | for (scp = siginfo_table; scp -> codename != NULL; scp++) | |
886 | { | |
887 | if ((scp -> signo == sip -> si_signo) && | |
888 | (scp -> code == sip -> si_code)) | |
889 | { | |
890 | name = scp -> codename; | |
891 | break; | |
892 | } | |
893 | } | |
894 | if (name == NULL) | |
895 | { | |
896 | (void) sprintf (locbuf, "sigcode %u", sip -> si_signo); | |
897 | name = locbuf; | |
898 | } | |
899 | return (name); | |
900 | } | |
901 | ||
902 | static char *sigcodedesc (sip) | |
903 | siginfo_t *sip; | |
904 | { | |
905 | struct sigcode *scp; | |
906 | char *desc = NULL; | |
907 | ||
908 | for (scp = siginfo_table; scp -> codename != NULL; scp++) | |
909 | { | |
910 | if ((scp -> signo == sip -> si_signo) && | |
911 | (scp -> code == sip -> si_code)) | |
912 | { | |
913 | desc = scp -> desc; | |
914 | break; | |
915 | } | |
916 | } | |
917 | if (desc == NULL) | |
918 | { | |
919 | desc = "Unrecognized signal or trap use"; | |
920 | } | |
921 | return (desc); | |
922 | } | |
923 | ||
924 | /* | |
925 | ||
926 | LOCAL FUNCTION | |
927 | ||
928 | syscallname - translate a system call number into a system call name | |
929 | ||
930 | SYNOPSIS | |
931 | ||
932 | char *syscallname (int syscallnum) | |
933 | ||
934 | DESCRIPTION | |
935 | ||
936 | Given a system call number, translate it into the printable name | |
937 | of a system call, or into "syscall <num>" if it is an unknown | |
938 | number. | |
939 | */ | |
940 | ||
941 | static char * | |
942 | syscallname (syscallnum) | |
943 | int syscallnum; | |
944 | { | |
945 | static char locbuf[32]; | |
946 | char *rtnval; | |
947 | ||
948 | if (syscallnum >= 0 && syscallnum < MAX_SYSCALLS) | |
949 | { | |
950 | rtnval = syscall_table[syscallnum]; | |
951 | } | |
952 | else | |
953 | { | |
954 | (void) sprintf (locbuf, "syscall %u", syscallnum); | |
955 | rtnval = locbuf; | |
956 | } | |
957 | return (rtnval); | |
958 | } | |
959 | ||
960 | /* | |
961 | ||
962 | LOCAL FUNCTION | |
963 | ||
964 | init_syscall_table - initialize syscall translation table | |
965 | ||
966 | SYNOPSIS | |
967 | ||
968 | void init_syscall_table (void) | |
969 | ||
970 | DESCRIPTION | |
971 | ||
972 | Dynamically initialize the translation table to convert system | |
973 | call numbers into printable system call names. Done once per | |
974 | gdb run, on initialization. | |
975 | ||
976 | NOTES | |
977 | ||
978 | This is awfully ugly, but preprocessor tricks to make it prettier | |
979 | tend to be nonportable. | |
980 | */ | |
981 | ||
982 | static void | |
983 | init_syscall_table () | |
984 | { | |
985 | int syscallnum; | |
986 | ||
987 | #if defined (SYS_exit) | |
988 | syscall_table[SYS_exit] = "exit"; | |
989 | #endif | |
990 | #if defined (SYS_fork) | |
991 | syscall_table[SYS_fork] = "fork"; | |
992 | #endif | |
993 | #if defined (SYS_read) | |
994 | syscall_table[SYS_read] = "read"; | |
995 | #endif | |
996 | #if defined (SYS_write) | |
997 | syscall_table[SYS_write] = "write"; | |
998 | #endif | |
999 | #if defined (SYS_open) | |
1000 | syscall_table[SYS_open] = "open"; | |
1001 | #endif | |
1002 | #if defined (SYS_close) | |
1003 | syscall_table[SYS_close] = "close"; | |
1004 | #endif | |
1005 | #if defined (SYS_wait) | |
1006 | syscall_table[SYS_wait] = "wait"; | |
1007 | #endif | |
1008 | #if defined (SYS_creat) | |
1009 | syscall_table[SYS_creat] = "creat"; | |
1010 | #endif | |
1011 | #if defined (SYS_link) | |
1012 | syscall_table[SYS_link] = "link"; | |
1013 | #endif | |
1014 | #if defined (SYS_unlink) | |
1015 | syscall_table[SYS_unlink] = "unlink"; | |
1016 | #endif | |
1017 | #if defined (SYS_exec) | |
1018 | syscall_table[SYS_exec] = "exec"; | |
1019 | #endif | |
1020 | #if defined (SYS_execv) | |
1021 | syscall_table[SYS_execv] = "execv"; | |
1022 | #endif | |
1023 | #if defined (SYS_execve) | |
1024 | syscall_table[SYS_execve] = "execve"; | |
1025 | #endif | |
1026 | #if defined (SYS_chdir) | |
1027 | syscall_table[SYS_chdir] = "chdir"; | |
1028 | #endif | |
1029 | #if defined (SYS_time) | |
1030 | syscall_table[SYS_time] = "time"; | |
1031 | #endif | |
1032 | #if defined (SYS_mknod) | |
1033 | syscall_table[SYS_mknod] = "mknod"; | |
1034 | #endif | |
1035 | #if defined (SYS_chmod) | |
1036 | syscall_table[SYS_chmod] = "chmod"; | |
1037 | #endif | |
1038 | #if defined (SYS_chown) | |
1039 | syscall_table[SYS_chown] = "chown"; | |
1040 | #endif | |
1041 | #if defined (SYS_brk) | |
1042 | syscall_table[SYS_brk] = "brk"; | |
1043 | #endif | |
1044 | #if defined (SYS_stat) | |
1045 | syscall_table[SYS_stat] = "stat"; | |
1046 | #endif | |
1047 | #if defined (SYS_lseek) | |
1048 | syscall_table[SYS_lseek] = "lseek"; | |
1049 | #endif | |
1050 | #if defined (SYS_getpid) | |
1051 | syscall_table[SYS_getpid] = "getpid"; | |
1052 | #endif | |
1053 | #if defined (SYS_mount) | |
1054 | syscall_table[SYS_mount] = "mount"; | |
1055 | #endif | |
1056 | #if defined (SYS_umount) | |
1057 | syscall_table[SYS_umount] = "umount"; | |
1058 | #endif | |
1059 | #if defined (SYS_setuid) | |
1060 | syscall_table[SYS_setuid] = "setuid"; | |
1061 | #endif | |
1062 | #if defined (SYS_getuid) | |
1063 | syscall_table[SYS_getuid] = "getuid"; | |
1064 | #endif | |
1065 | #if defined (SYS_stime) | |
1066 | syscall_table[SYS_stime] = "stime"; | |
1067 | #endif | |
1068 | #if defined (SYS_ptrace) | |
1069 | syscall_table[SYS_ptrace] = "ptrace"; | |
1070 | #endif | |
1071 | #if defined (SYS_alarm) | |
1072 | syscall_table[SYS_alarm] = "alarm"; | |
1073 | #endif | |
1074 | #if defined (SYS_fstat) | |
1075 | syscall_table[SYS_fstat] = "fstat"; | |
1076 | #endif | |
1077 | #if defined (SYS_pause) | |
1078 | syscall_table[SYS_pause] = "pause"; | |
1079 | #endif | |
1080 | #if defined (SYS_utime) | |
1081 | syscall_table[SYS_utime] = "utime"; | |
1082 | #endif | |
1083 | #if defined (SYS_stty) | |
1084 | syscall_table[SYS_stty] = "stty"; | |
1085 | #endif | |
1086 | #if defined (SYS_gtty) | |
1087 | syscall_table[SYS_gtty] = "gtty"; | |
1088 | #endif | |
1089 | #if defined (SYS_access) | |
1090 | syscall_table[SYS_access] = "access"; | |
1091 | #endif | |
1092 | #if defined (SYS_nice) | |
1093 | syscall_table[SYS_nice] = "nice"; | |
1094 | #endif | |
1095 | #if defined (SYS_statfs) | |
1096 | syscall_table[SYS_statfs] = "statfs"; | |
1097 | #endif | |
1098 | #if defined (SYS_sync) | |
1099 | syscall_table[SYS_sync] = "sync"; | |
1100 | #endif | |
1101 | #if defined (SYS_kill) | |
1102 | syscall_table[SYS_kill] = "kill"; | |
1103 | #endif | |
1104 | #if defined (SYS_fstatfs) | |
1105 | syscall_table[SYS_fstatfs] = "fstatfs"; | |
1106 | #endif | |
1107 | #if defined (SYS_pgrpsys) | |
1108 | syscall_table[SYS_pgrpsys] = "pgrpsys"; | |
1109 | #endif | |
1110 | #if defined (SYS_xenix) | |
1111 | syscall_table[SYS_xenix] = "xenix"; | |
1112 | #endif | |
1113 | #if defined (SYS_dup) | |
1114 | syscall_table[SYS_dup] = "dup"; | |
1115 | #endif | |
1116 | #if defined (SYS_pipe) | |
1117 | syscall_table[SYS_pipe] = "pipe"; | |
1118 | #endif | |
1119 | #if defined (SYS_times) | |
1120 | syscall_table[SYS_times] = "times"; | |
1121 | #endif | |
1122 | #if defined (SYS_profil) | |
1123 | syscall_table[SYS_profil] = "profil"; | |
1124 | #endif | |
1125 | #if defined (SYS_plock) | |
1126 | syscall_table[SYS_plock] = "plock"; | |
1127 | #endif | |
1128 | #if defined (SYS_setgid) | |
1129 | syscall_table[SYS_setgid] = "setgid"; | |
1130 | #endif | |
1131 | #if defined (SYS_getgid) | |
1132 | syscall_table[SYS_getgid] = "getgid"; | |
1133 | #endif | |
1134 | #if defined (SYS_signal) | |
1135 | syscall_table[SYS_signal] = "signal"; | |
1136 | #endif | |
1137 | #if defined (SYS_msgsys) | |
1138 | syscall_table[SYS_msgsys] = "msgsys"; | |
1139 | #endif | |
1140 | #if defined (SYS_sys3b) | |
1141 | syscall_table[SYS_sys3b] = "sys3b"; | |
1142 | #endif | |
1143 | #if defined (SYS_acct) | |
1144 | syscall_table[SYS_acct] = "acct"; | |
1145 | #endif | |
1146 | #if defined (SYS_shmsys) | |
1147 | syscall_table[SYS_shmsys] = "shmsys"; | |
1148 | #endif | |
1149 | #if defined (SYS_semsys) | |
1150 | syscall_table[SYS_semsys] = "semsys"; | |
1151 | #endif | |
1152 | #if defined (SYS_ioctl) | |
1153 | syscall_table[SYS_ioctl] = "ioctl"; | |
1154 | #endif | |
1155 | #if defined (SYS_uadmin) | |
1156 | syscall_table[SYS_uadmin] = "uadmin"; | |
1157 | #endif | |
1158 | #if defined (SYS_utssys) | |
1159 | syscall_table[SYS_utssys] = "utssys"; | |
1160 | #endif | |
1161 | #if defined (SYS_fsync) | |
1162 | syscall_table[SYS_fsync] = "fsync"; | |
1163 | #endif | |
1164 | #if defined (SYS_umask) | |
1165 | syscall_table[SYS_umask] = "umask"; | |
1166 | #endif | |
1167 | #if defined (SYS_chroot) | |
1168 | syscall_table[SYS_chroot] = "chroot"; | |
1169 | #endif | |
1170 | #if defined (SYS_fcntl) | |
1171 | syscall_table[SYS_fcntl] = "fcntl"; | |
1172 | #endif | |
1173 | #if defined (SYS_ulimit) | |
1174 | syscall_table[SYS_ulimit] = "ulimit"; | |
1175 | #endif | |
1176 | #if defined (SYS_rfsys) | |
1177 | syscall_table[SYS_rfsys] = "rfsys"; | |
1178 | #endif | |
1179 | #if defined (SYS_rmdir) | |
1180 | syscall_table[SYS_rmdir] = "rmdir"; | |
1181 | #endif | |
1182 | #if defined (SYS_mkdir) | |
1183 | syscall_table[SYS_mkdir] = "mkdir"; | |
1184 | #endif | |
1185 | #if defined (SYS_getdents) | |
1186 | syscall_table[SYS_getdents] = "getdents"; | |
1187 | #endif | |
1188 | #if defined (SYS_sysfs) | |
1189 | syscall_table[SYS_sysfs] = "sysfs"; | |
1190 | #endif | |
1191 | #if defined (SYS_getmsg) | |
1192 | syscall_table[SYS_getmsg] = "getmsg"; | |
1193 | #endif | |
1194 | #if defined (SYS_putmsg) | |
1195 | syscall_table[SYS_putmsg] = "putmsg"; | |
1196 | #endif | |
1197 | #if defined (SYS_poll) | |
1198 | syscall_table[SYS_poll] = "poll"; | |
1199 | #endif | |
1200 | #if defined (SYS_lstat) | |
1201 | syscall_table[SYS_lstat] = "lstat"; | |
1202 | #endif | |
1203 | #if defined (SYS_symlink) | |
1204 | syscall_table[SYS_symlink] = "symlink"; | |
1205 | #endif | |
1206 | #if defined (SYS_readlink) | |
1207 | syscall_table[SYS_readlink] = "readlink"; | |
1208 | #endif | |
1209 | #if defined (SYS_setgroups) | |
1210 | syscall_table[SYS_setgroups] = "setgroups"; | |
1211 | #endif | |
1212 | #if defined (SYS_getgroups) | |
1213 | syscall_table[SYS_getgroups] = "getgroups"; | |
1214 | #endif | |
1215 | #if defined (SYS_fchmod) | |
1216 | syscall_table[SYS_fchmod] = "fchmod"; | |
1217 | #endif | |
1218 | #if defined (SYS_fchown) | |
1219 | syscall_table[SYS_fchown] = "fchown"; | |
1220 | #endif | |
1221 | #if defined (SYS_sigprocmask) | |
1222 | syscall_table[SYS_sigprocmask] = "sigprocmask"; | |
1223 | #endif | |
1224 | #if defined (SYS_sigsuspend) | |
1225 | syscall_table[SYS_sigsuspend] = "sigsuspend"; | |
1226 | #endif | |
1227 | #if defined (SYS_sigaltstack) | |
1228 | syscall_table[SYS_sigaltstack] = "sigaltstack"; | |
1229 | #endif | |
1230 | #if defined (SYS_sigaction) | |
1231 | syscall_table[SYS_sigaction] = "sigaction"; | |
1232 | #endif | |
1233 | #if defined (SYS_sigpending) | |
1234 | syscall_table[SYS_sigpending] = "sigpending"; | |
1235 | #endif | |
1236 | #if defined (SYS_context) | |
1237 | syscall_table[SYS_context] = "context"; | |
1238 | #endif | |
1239 | #if defined (SYS_evsys) | |
1240 | syscall_table[SYS_evsys] = "evsys"; | |
1241 | #endif | |
1242 | #if defined (SYS_evtrapret) | |
1243 | syscall_table[SYS_evtrapret] = "evtrapret"; | |
1244 | #endif | |
1245 | #if defined (SYS_statvfs) | |
1246 | syscall_table[SYS_statvfs] = "statvfs"; | |
1247 | #endif | |
1248 | #if defined (SYS_fstatvfs) | |
1249 | syscall_table[SYS_fstatvfs] = "fstatvfs"; | |
1250 | #endif | |
1251 | #if defined (SYS_nfssys) | |
1252 | syscall_table[SYS_nfssys] = "nfssys"; | |
1253 | #endif | |
1254 | #if defined (SYS_waitsys) | |
1255 | syscall_table[SYS_waitsys] = "waitsys"; | |
1256 | #endif | |
1257 | #if defined (SYS_sigsendsys) | |
1258 | syscall_table[SYS_sigsendsys] = "sigsendsys"; | |
1259 | #endif | |
1260 | #if defined (SYS_hrtsys) | |
1261 | syscall_table[SYS_hrtsys] = "hrtsys"; | |
1262 | #endif | |
1263 | #if defined (SYS_acancel) | |
1264 | syscall_table[SYS_acancel] = "acancel"; | |
1265 | #endif | |
1266 | #if defined (SYS_async) | |
1267 | syscall_table[SYS_async] = "async"; | |
1268 | #endif | |
1269 | #if defined (SYS_priocntlsys) | |
1270 | syscall_table[SYS_priocntlsys] = "priocntlsys"; | |
1271 | #endif | |
1272 | #if defined (SYS_pathconf) | |
1273 | syscall_table[SYS_pathconf] = "pathconf"; | |
1274 | #endif | |
1275 | #if defined (SYS_mincore) | |
1276 | syscall_table[SYS_mincore] = "mincore"; | |
1277 | #endif | |
1278 | #if defined (SYS_mmap) | |
1279 | syscall_table[SYS_mmap] = "mmap"; | |
1280 | #endif | |
1281 | #if defined (SYS_mprotect) | |
1282 | syscall_table[SYS_mprotect] = "mprotect"; | |
1283 | #endif | |
1284 | #if defined (SYS_munmap) | |
1285 | syscall_table[SYS_munmap] = "munmap"; | |
1286 | #endif | |
1287 | #if defined (SYS_fpathconf) | |
1288 | syscall_table[SYS_fpathconf] = "fpathconf"; | |
1289 | #endif | |
1290 | #if defined (SYS_vfork) | |
1291 | syscall_table[SYS_vfork] = "vfork"; | |
1292 | #endif | |
1293 | #if defined (SYS_fchdir) | |
1294 | syscall_table[SYS_fchdir] = "fchdir"; | |
1295 | #endif | |
1296 | #if defined (SYS_readv) | |
1297 | syscall_table[SYS_readv] = "readv"; | |
1298 | #endif | |
1299 | #if defined (SYS_writev) | |
1300 | syscall_table[SYS_writev] = "writev"; | |
1301 | #endif | |
1302 | #if defined (SYS_xstat) | |
1303 | syscall_table[SYS_xstat] = "xstat"; | |
1304 | #endif | |
1305 | #if defined (SYS_lxstat) | |
1306 | syscall_table[SYS_lxstat] = "lxstat"; | |
1307 | #endif | |
1308 | #if defined (SYS_fxstat) | |
1309 | syscall_table[SYS_fxstat] = "fxstat"; | |
1310 | #endif | |
1311 | #if defined (SYS_xmknod) | |
1312 | syscall_table[SYS_xmknod] = "xmknod"; | |
1313 | #endif | |
1314 | #if defined (SYS_clocal) | |
1315 | syscall_table[SYS_clocal] = "clocal"; | |
1316 | #endif | |
1317 | #if defined (SYS_setrlimit) | |
1318 | syscall_table[SYS_setrlimit] = "setrlimit"; | |
1319 | #endif | |
1320 | #if defined (SYS_getrlimit) | |
1321 | syscall_table[SYS_getrlimit] = "getrlimit"; | |
1322 | #endif | |
1323 | #if defined (SYS_lchown) | |
1324 | syscall_table[SYS_lchown] = "lchown"; | |
1325 | #endif | |
1326 | #if defined (SYS_memcntl) | |
1327 | syscall_table[SYS_memcntl] = "memcntl"; | |
1328 | #endif | |
1329 | #if defined (SYS_getpmsg) | |
1330 | syscall_table[SYS_getpmsg] = "getpmsg"; | |
1331 | #endif | |
1332 | #if defined (SYS_putpmsg) | |
1333 | syscall_table[SYS_putpmsg] = "putpmsg"; | |
1334 | #endif | |
1335 | #if defined (SYS_rename) | |
1336 | syscall_table[SYS_rename] = "rename"; | |
1337 | #endif | |
1338 | #if defined (SYS_uname) | |
1339 | syscall_table[SYS_uname] = "uname"; | |
1340 | #endif | |
1341 | #if defined (SYS_setegid) | |
1342 | syscall_table[SYS_setegid] = "setegid"; | |
1343 | #endif | |
1344 | #if defined (SYS_sysconfig) | |
1345 | syscall_table[SYS_sysconfig] = "sysconfig"; | |
1346 | #endif | |
1347 | #if defined (SYS_adjtime) | |
1348 | syscall_table[SYS_adjtime] = "adjtime"; | |
1349 | #endif | |
1350 | #if defined (SYS_systeminfo) | |
1351 | syscall_table[SYS_systeminfo] = "systeminfo"; | |
1352 | #endif | |
1353 | #if defined (SYS_seteuid) | |
1354 | syscall_table[SYS_seteuid] = "seteuid"; | |
1355 | #endif | |
1356 | } | |
35f5886e FF |
1357 | |
1358 | /* | |
1359 | ||
1360 | GLOBAL FUNCTION | |
1361 | ||
1362 | ptrace -- override library version to force errors for /proc version | |
1363 | ||
1364 | SYNOPSIS | |
1365 | ||
1366 | int ptrace (int request, int pid, int arg3, int arg4) | |
1367 | ||
1368 | DESCRIPTION | |
1369 | ||
1370 | When gdb is configured to use /proc, it should not be calling | |
1371 | or otherwise attempting to use ptrace. In order to catch errors | |
1372 | where use of /proc is configured, but some routine is still calling | |
1373 | ptrace, we provide a local version of a function with that name | |
1374 | that does nothing but issue an error message. | |
1375 | */ | |
1376 | ||
1377 | int | |
1ab3bf1b JG |
1378 | ptrace (request, pid, arg3, arg4) |
1379 | int request; | |
1380 | int pid; | |
1381 | int arg3; | |
1382 | int arg4; | |
35f5886e FF |
1383 | { |
1384 | error ("internal error - there is a call to ptrace() somewhere"); | |
1385 | /*NOTREACHED*/ | |
1386 | } | |
1387 | ||
1388 | /* | |
1389 | ||
1390 | GLOBAL FUNCTION | |
1391 | ||
1392 | kill_inferior_fast -- kill inferior while gdb is exiting | |
1393 | ||
1394 | SYNOPSIS | |
1395 | ||
1396 | void kill_inferior_fast (void) | |
1397 | ||
1398 | DESCRIPTION | |
1399 | ||
1400 | This is used when GDB is exiting. It gives less chance of error. | |
1401 | ||
1402 | NOTES | |
1403 | ||
1404 | Don't attempt to kill attached inferiors since we may be called | |
1405 | when gdb is in the process of aborting, and killing the attached | |
1406 | inferior may be very anti-social. This is particularly true if we | |
1407 | were attached just so we could use the /proc facilities to get | |
1408 | detailed information about it's status. | |
1409 | ||
1410 | */ | |
1411 | ||
1412 | void | |
1ab3bf1b | 1413 | kill_inferior_fast () |
35f5886e FF |
1414 | { |
1415 | if (inferior_pid != 0 && !attach_flag) | |
1416 | { | |
1417 | unconditionally_kill_inferior (); | |
1418 | } | |
1419 | } | |
1420 | ||
1421 | /* | |
1422 | ||
1423 | GLOBAL FUNCTION | |
1424 | ||
1425 | kill_inferior - kill any currently inferior | |
1426 | ||
1427 | SYNOPSIS | |
1428 | ||
1429 | void kill_inferior (void) | |
1430 | ||
1431 | DESCRIPTION | |
1432 | ||
1433 | Kill any current inferior. | |
1434 | ||
1435 | NOTES | |
1436 | ||
1437 | Kills even attached inferiors. Presumably the user has already | |
1438 | been prompted that the inferior is an attached one rather than | |
1439 | one started by gdb. (FIXME?) | |
1440 | ||
1441 | */ | |
1442 | ||
1443 | void | |
1ab3bf1b | 1444 | kill_inferior () |
35f5886e FF |
1445 | { |
1446 | if (inferior_pid != 0) | |
1447 | { | |
1448 | unconditionally_kill_inferior (); | |
1449 | target_mourn_inferior (); | |
1450 | } | |
1451 | } | |
1452 | ||
1453 | /* | |
1454 | ||
1455 | LOCAL FUNCTION | |
1456 | ||
1457 | unconditionally_kill_inferior - terminate the inferior | |
1458 | ||
1459 | SYNOPSIS | |
1460 | ||
1461 | static void unconditionally_kill_inferior (void) | |
1462 | ||
1463 | DESCRIPTION | |
1464 | ||
1465 | Kill the current inferior. Should not be called until it | |
1466 | is at least tested that there is an inferior. | |
1467 | ||
1468 | NOTE | |
1469 | ||
1470 | A possibly useful enhancement would be to first try sending | |
1471 | the inferior a terminate signal, politely asking it to commit | |
1472 | suicide, before we murder it. | |
1473 | ||
1474 | */ | |
1475 | ||
1476 | static void | |
1ab3bf1b | 1477 | unconditionally_kill_inferior () |
35f5886e FF |
1478 | { |
1479 | int signo; | |
1480 | ||
1481 | signo = SIGKILL; | |
1482 | (void) ioctl (pi.fd, PIOCKILL, &signo); | |
a39ad5ce | 1483 | close_proc_file (&pi); |
35f5886e FF |
1484 | wait ((int *) 0); |
1485 | } | |
1486 | ||
1487 | /* | |
1488 | ||
1489 | GLOBAL FUNCTION | |
1490 | ||
1491 | child_xfer_memory -- copy data to or from inferior memory space | |
1492 | ||
1493 | SYNOPSIS | |
1494 | ||
1495 | int child_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, | |
1496 | int dowrite, struct target_ops target) | |
1497 | ||
1498 | DESCRIPTION | |
1499 | ||
1500 | Copy LEN bytes to/from inferior's memory starting at MEMADDR | |
1501 | from/to debugger memory starting at MYADDR. Copy from inferior | |
1502 | if DOWRITE is zero or to inferior if DOWRITE is nonzero. | |
1503 | ||
1504 | Returns the length copied, which is either the LEN argument or | |
1505 | zero. This xfer function does not do partial moves, since child_ops | |
1506 | doesn't allow memory operations to cross below us in the target stack | |
1507 | anyway. | |
1508 | ||
1509 | NOTES | |
1510 | ||
1511 | The /proc interface makes this an almost trivial task. | |
1512 | */ | |
1513 | ||
1514 | ||
1515 | int | |
1ab3bf1b JG |
1516 | child_xfer_memory (memaddr, myaddr, len, dowrite, target) |
1517 | CORE_ADDR memaddr; | |
1518 | char *myaddr; | |
1519 | int len; | |
1520 | int dowrite; | |
1521 | struct target_ops *target; /* ignored */ | |
35f5886e FF |
1522 | { |
1523 | int nbytes = 0; | |
1524 | ||
1525 | if (lseek (pi.fd, (off_t) memaddr, 0) == (off_t) memaddr) | |
1526 | { | |
1527 | if (dowrite) | |
1528 | { | |
1529 | nbytes = write (pi.fd, myaddr, len); | |
1530 | } | |
1531 | else | |
1532 | { | |
1533 | nbytes = read (pi.fd, myaddr, len); | |
1534 | } | |
1535 | if (nbytes < 0) | |
1536 | { | |
1537 | nbytes = 0; | |
1538 | } | |
1539 | } | |
1540 | return (nbytes); | |
1541 | } | |
1542 | ||
1543 | /* | |
1544 | ||
1545 | GLOBAL FUNCTION | |
1546 | ||
1547 | store_inferior_registers -- copy register values back to inferior | |
1548 | ||
1549 | SYNOPSIS | |
1550 | ||
1551 | void store_inferior_registers (int regno) | |
1552 | ||
1553 | DESCRIPTION | |
1554 | ||
1555 | Store our current register values back into the inferior. If | |
1556 | REGNO is -1 then store all the register, otherwise store just | |
1557 | the value specified by REGNO. | |
1558 | ||
1559 | NOTES | |
1560 | ||
1561 | If we are storing only a single register, we first have to get all | |
1562 | the current values from the process, overwrite the desired register | |
1563 | in the gregset with the one we want from gdb's registers, and then | |
1564 | send the whole set back to the process. For writing all the | |
1565 | registers, all we have to do is generate the gregset and send it to | |
1566 | the process. | |
1567 | ||
1568 | Also note that the process has to be stopped on an event of interest | |
1569 | for this to work, which basically means that it has to have been | |
1570 | run under the control of one of the other /proc ioctl calls and not | |
1571 | ptrace. Since we don't use ptrace anyway, we don't worry about this | |
1572 | fine point, but it is worth noting for future reference. | |
1573 | ||
1574 | Gdb is confused about what this function is supposed to return. | |
1575 | Some versions return a value, others return nothing. Some are | |
1576 | declared to return a value and actually return nothing. Gdb ignores | |
1577 | anything returned. (FIXME) | |
1578 | ||
1579 | */ | |
1580 | ||
1581 | void | |
1ab3bf1b JG |
1582 | store_inferior_registers (regno) |
1583 | int regno; | |
35f5886e FF |
1584 | { |
1585 | if (regno != -1) | |
1586 | { | |
1587 | (void) ioctl (pi.fd, PIOCGREG, &pi.gregset); | |
1588 | } | |
1589 | fill_gregset (&pi.gregset, regno); | |
1590 | (void) ioctl (pi.fd, PIOCSREG, &pi.gregset); | |
1591 | ||
1592 | #if defined (FP0_REGNUM) | |
1593 | ||
1594 | /* Now repeat everything using the floating point register set, if the | |
1595 | target has floating point hardware. Since we ignore the returned value, | |
1596 | we'll never know whether it worked or not anyway. */ | |
1597 | ||
1598 | if (regno != -1) | |
1599 | { | |
1600 | (void) ioctl (pi.fd, PIOCGFPREG, &pi.fpregset); | |
1601 | } | |
1602 | fill_fpregset (&pi.fpregset, regno); | |
1603 | (void) ioctl (pi.fd, PIOCSFPREG, &pi.fpregset); | |
1604 | ||
1605 | #endif /* FP0_REGNUM */ | |
1606 | ||
1607 | } | |
1608 | ||
1609 | /* | |
1610 | ||
1611 | GLOBAL FUNCTION | |
1612 | ||
1613 | inferior_proc_init - initialize access to a /proc entry | |
1614 | ||
1615 | SYNOPSIS | |
1616 | ||
1617 | void inferior_proc_init (int pid) | |
1618 | ||
1619 | DESCRIPTION | |
1620 | ||
1621 | When gdb starts an inferior, this function is called in the parent | |
1622 | process immediately after the fork. It waits for the child to stop | |
1623 | on the return from the exec system call (the child itself takes care | |
1624 | of ensuring that this is set up), then sets up the set of signals | |
1625 | and faults that are to be traced. | |
1626 | ||
1627 | NOTES | |
1628 | ||
1629 | If proc_init_failed ever gets called, control returns to the command | |
1630 | processing loop via the standard error handling code. | |
cc221e76 | 1631 | |
35f5886e FF |
1632 | */ |
1633 | ||
1634 | void | |
1ab3bf1b JG |
1635 | inferior_proc_init (pid) |
1636 | int pid; | |
35f5886e | 1637 | { |
a39ad5ce | 1638 | if (!open_proc_file (pid, &pi)) |
35f5886e FF |
1639 | { |
1640 | proc_init_failed ("can't open process file"); | |
1641 | } | |
1642 | else | |
1643 | { | |
cc221e76 | 1644 | (void) memset ((char *) &pi.prrun, 0, sizeof (pi.prrun)); |
35f5886e | 1645 | prfillset (&pi.prrun.pr_trace); |
cc221e76 | 1646 | proc_signal_handling_change (); |
35f5886e FF |
1647 | prfillset (&pi.prrun.pr_fault); |
1648 | prdelset (&pi.prrun.pr_fault, FLTPAGE); | |
1649 | if (ioctl (pi.fd, PIOCWSTOP, &pi.prstatus) < 0) | |
1650 | { | |
1651 | proc_init_failed ("PIOCWSTOP failed"); | |
1652 | } | |
35f5886e FF |
1653 | else if (ioctl (pi.fd, PIOCSFAULT, &pi.prrun.pr_fault) < 0) |
1654 | { | |
1655 | proc_init_failed ("PIOCSFAULT failed"); | |
1656 | } | |
1657 | } | |
1658 | } | |
1659 | ||
1660 | /* | |
1661 | ||
cc221e76 FF |
1662 | GLOBAL FUNCTION |
1663 | ||
1664 | proc_signal_handling_change | |
1665 | ||
1666 | SYNOPSIS | |
1667 | ||
1668 | void proc_signal_handling_change (void); | |
1669 | ||
1670 | DESCRIPTION | |
1671 | ||
1672 | When the user changes the state of gdb's signal handling via the | |
1673 | "handle" command, this function gets called to see if any change | |
1674 | in the /proc interface is required. It is also called internally | |
1675 | by other /proc interface functions to initialize the state of | |
1676 | the traced signal set. | |
1677 | ||
1678 | One thing it does is that signals for which the state is "nostop", | |
1679 | "noprint", and "pass", have their trace bits reset in the pr_trace | |
1680 | field, so that they are no longer traced. This allows them to be | |
1681 | delivered directly to the inferior without the debugger ever being | |
1682 | involved. | |
1683 | */ | |
1684 | ||
1685 | void | |
1686 | proc_signal_handling_change () | |
1687 | { | |
1688 | int signo; | |
1689 | ||
1690 | if (pi.valid) | |
1691 | { | |
1692 | for (signo = 0; signo < NSIG; signo++) | |
1693 | { | |
1694 | if (signal_stop_state (signo) == 0 && | |
1695 | signal_print_state (signo) == 0 && | |
1696 | signal_pass_state (signo) == 1) | |
1697 | { | |
1698 | prdelset (&pi.prrun.pr_trace, signo); | |
1699 | } | |
1700 | else | |
1701 | { | |
1702 | praddset (&pi.prrun.pr_trace, signo); | |
1703 | } | |
1704 | } | |
1705 | if (ioctl (pi.fd, PIOCSTRACE, &pi.prrun.pr_trace)) | |
1706 | { | |
1707 | print_sys_errmsg ("PIOCSTRACE failed", errno); | |
1708 | } | |
1709 | } | |
1710 | } | |
1711 | ||
1712 | /* | |
1713 | ||
35f5886e FF |
1714 | GLOBAL FUNCTION |
1715 | ||
1716 | proc_set_exec_trap -- arrange for exec'd child to halt at startup | |
1717 | ||
1718 | SYNOPSIS | |
1719 | ||
1720 | void proc_set_exec_trap (void) | |
1721 | ||
1722 | DESCRIPTION | |
1723 | ||
1724 | This function is called in the child process when starting up | |
1725 | an inferior, prior to doing the exec of the actual inferior. | |
1726 | It sets the child process's exitset to make exit from the exec | |
1727 | system call an event of interest to stop on, and then simply | |
1728 | returns. The child does the exec, the system call returns, and | |
1729 | the child stops at the first instruction, ready for the gdb | |
1730 | parent process to take control of it. | |
1731 | ||
1732 | NOTE | |
1733 | ||
1734 | We need to use all local variables since the child may be sharing | |
1735 | it's data space with the parent, if vfork was used rather than | |
1736 | fork. | |
cc221e76 FF |
1737 | |
1738 | Also note that we want to turn off the inherit-on-fork flag in | |
1739 | the child process so that any grand-children start with all | |
1740 | tracing flags cleared. | |
35f5886e FF |
1741 | */ |
1742 | ||
1743 | void | |
1ab3bf1b | 1744 | proc_set_exec_trap () |
35f5886e FF |
1745 | { |
1746 | sysset_t exitset; | |
1747 | auto char procname[32]; | |
1748 | int fd; | |
1749 | ||
1750 | (void) sprintf (procname, PROC_NAME_FMT, getpid ()); | |
1751 | if ((fd = open (procname, O_RDWR)) < 0) | |
1752 | { | |
1753 | perror (procname); | |
1754 | fflush (stderr); | |
1755 | _exit (127); | |
1756 | } | |
1757 | premptyset (&exitset); | |
407a8389 | 1758 | |
cc221e76 FF |
1759 | /* GW: Rationale... |
1760 | Not all systems with /proc have all the exec* syscalls with the same | |
1761 | names. On the SGI, for example, there is no SYS_exec, but there | |
1762 | *is* a SYS_execv. So, we try to account for that. */ | |
1763 | ||
407a8389 | 1764 | #ifdef SYS_exec |
35f5886e | 1765 | praddset (&exitset, SYS_exec); |
407a8389 SG |
1766 | #endif |
1767 | #ifdef SYS_execve | |
35f5886e | 1768 | praddset (&exitset, SYS_execve); |
407a8389 SG |
1769 | #endif |
1770 | #ifdef SYS_execv | |
1771 | praddset(&exitset, SYS_execv); | |
1772 | #endif | |
1773 | ||
35f5886e FF |
1774 | if (ioctl (fd, PIOCSEXIT, &exitset) < 0) |
1775 | { | |
1776 | perror (procname); | |
1777 | fflush (stderr); | |
1778 | _exit (127); | |
1779 | } | |
cc221e76 FF |
1780 | |
1781 | /* Turn off inherit-on-fork flag so that all grand-children of gdb | |
1782 | start with tracing flags cleared. */ | |
1783 | ||
1784 | #ifdef PIOCRFORK /* Standard SVR4 */ | |
1785 | (void) ioctl (fd, PIOCRFORK, NULL); | |
1786 | #else | |
1787 | #ifdef PIOCRESET /* iris (for example) */ | |
1788 | { | |
1789 | long pr_flags; | |
1790 | pr_flags = PR_FORK; | |
1791 | (void) ioctl (fd, PIOCRESET, &pr_flags); | |
1792 | } | |
1793 | #endif | |
1794 | #endif | |
35f5886e FF |
1795 | } |
1796 | ||
f8b76e70 FF |
1797 | /* |
1798 | ||
a39ad5ce FF |
1799 | GLOBAL FUNCTION |
1800 | ||
1801 | proc_iterate_over_mappings -- call function for every mapped space | |
1802 | ||
1803 | SYNOPSIS | |
1804 | ||
1805 | int proc_iterate_over_mappings (int (*func)()) | |
1806 | ||
1807 | DESCRIPTION | |
1808 | ||
1809 | Given a pointer to a function, call that function for every | |
1810 | mapped address space, passing it an open file descriptor for | |
1811 | the file corresponding to that mapped address space (if any) | |
1812 | and the base address of the mapped space. Quit when we hit | |
1813 | the end of the mappings or the function returns nonzero. | |
1814 | */ | |
1815 | ||
1816 | int | |
1ab3bf1b JG |
1817 | proc_iterate_over_mappings (func) |
1818 | int (*func) PARAMS ((int, CORE_ADDR)); | |
a39ad5ce FF |
1819 | { |
1820 | int nmap; | |
1821 | int fd; | |
1822 | int funcstat = 0; | |
1823 | struct prmap *prmaps; | |
1824 | struct prmap *prmap; | |
1825 | CORE_ADDR baseaddr = 0; | |
1826 | ||
1827 | if (pi.valid && (ioctl (pi.fd, PIOCNMAP, &nmap) == 0)) | |
1828 | { | |
1ab3bf1b | 1829 | prmaps = (struct prmap *) alloca ((nmap + 1) * sizeof (*prmaps)); |
a39ad5ce FF |
1830 | if (ioctl (pi.fd, PIOCMAP, prmaps) == 0) |
1831 | { | |
1832 | for (prmap = prmaps; prmap -> pr_size && funcstat == 0; ++prmap) | |
1833 | { | |
1ab3bf1b JG |
1834 | fd = proc_address_to_fd ((CORE_ADDR) prmap -> pr_vaddr, 0); |
1835 | funcstat = (*func) (fd, (CORE_ADDR) prmap -> pr_vaddr); | |
a39ad5ce FF |
1836 | close (fd); |
1837 | } | |
1838 | } | |
1839 | } | |
1840 | return (funcstat); | |
1841 | } | |
1842 | ||
1843 | /* | |
1844 | ||
f8b76e70 FF |
1845 | GLOBAL FUNCTION |
1846 | ||
1847 | proc_base_address -- find base address for segment containing address | |
1848 | ||
1849 | SYNOPSIS | |
1850 | ||
1851 | CORE_ADDR proc_base_address (CORE_ADDR addr) | |
1852 | ||
1853 | DESCRIPTION | |
1854 | ||
1855 | Given an address of a location in the inferior, find and return | |
1856 | the base address of the mapped segment containing that address. | |
1857 | ||
1858 | This is used for example, by the shared library support code, | |
1859 | where we have the pc value for some location in the shared library | |
1860 | where we are stopped, and need to know the base address of the | |
1861 | segment containing that address. | |
1862 | */ | |
1863 | ||
1864 | ||
1ab3bf1b JG |
1865 | #if 0 /* Currently unused */ |
1866 | ||
f8b76e70 | 1867 | CORE_ADDR |
1ab3bf1b | 1868 | proc_base_address (addr) |
cc221e76 | 1869 | CORE_ADDR addr; |
f8b76e70 FF |
1870 | { |
1871 | int nmap; | |
1872 | struct prmap *prmaps; | |
1873 | struct prmap *prmap; | |
1874 | CORE_ADDR baseaddr = 0; | |
1875 | ||
a39ad5ce | 1876 | if (pi.valid && (ioctl (pi.fd, PIOCNMAP, &nmap) == 0)) |
f8b76e70 | 1877 | { |
1ab3bf1b | 1878 | prmaps = (struct prmap *) alloca ((nmap + 1) * sizeof (*prmaps)); |
f8b76e70 FF |
1879 | if (ioctl (pi.fd, PIOCMAP, prmaps) == 0) |
1880 | { | |
1881 | for (prmap = prmaps; prmap -> pr_size; ++prmap) | |
1882 | { | |
1883 | if ((prmap -> pr_vaddr <= (caddr_t) addr) && | |
1884 | (prmap -> pr_vaddr + prmap -> pr_size > (caddr_t) addr)) | |
1885 | { | |
1886 | baseaddr = (CORE_ADDR) prmap -> pr_vaddr; | |
1887 | break; | |
1888 | } | |
1889 | } | |
1890 | } | |
1891 | } | |
1892 | return (baseaddr); | |
1893 | } | |
1894 | ||
1ab3bf1b JG |
1895 | #endif /* 0 */ |
1896 | ||
f8b76e70 FF |
1897 | /* |
1898 | ||
cc221e76 | 1899 | LOCAL FUNCTION |
f8b76e70 FF |
1900 | |
1901 | proc_address_to_fd -- return open fd for file mapped to address | |
1902 | ||
1903 | SYNOPSIS | |
1904 | ||
a39ad5ce | 1905 | int proc_address_to_fd (CORE_ADDR addr, complain) |
f8b76e70 FF |
1906 | |
1907 | DESCRIPTION | |
1908 | ||
1909 | Given an address in the current inferior's address space, use the | |
1910 | /proc interface to find an open file descriptor for the file that | |
1911 | this address was mapped in from. Return -1 if there is no current | |
1912 | inferior. Print a warning message if there is an inferior but | |
1913 | the address corresponds to no file (IE a bogus address). | |
1914 | ||
1915 | */ | |
1916 | ||
1ab3bf1b JG |
1917 | static int |
1918 | proc_address_to_fd (addr, complain) | |
1919 | CORE_ADDR addr; | |
1920 | int complain; | |
f8b76e70 FF |
1921 | { |
1922 | int fd = -1; | |
1923 | ||
1924 | if (pi.valid) | |
1925 | { | |
1926 | if ((fd = ioctl (pi.fd, PIOCOPENM, (caddr_t *) &addr)) < 0) | |
1927 | { | |
a39ad5ce FF |
1928 | if (complain) |
1929 | { | |
1930 | print_sys_errmsg (pi.pathname, errno); | |
1931 | warning ("can't find mapped file for address 0x%x", addr); | |
1932 | } | |
f8b76e70 FF |
1933 | } |
1934 | } | |
1935 | return (fd); | |
1936 | } | |
1937 | ||
35f5886e FF |
1938 | |
1939 | #ifdef ATTACH_DETACH | |
1940 | ||
1941 | /* | |
1942 | ||
1943 | GLOBAL FUNCTION | |
1944 | ||
1945 | attach -- attach to an already existing process | |
1946 | ||
1947 | SYNOPSIS | |
1948 | ||
1949 | int attach (int pid) | |
1950 | ||
1951 | DESCRIPTION | |
1952 | ||
1953 | Attach to an already existing process with the specified process | |
1954 | id. If the process is not already stopped, query whether to | |
1955 | stop it or not. | |
1956 | ||
1957 | NOTES | |
1958 | ||
1959 | The option of stopping at attach time is specific to the /proc | |
1960 | versions of gdb. Versions using ptrace force the attachee | |
1961 | to stop. | |
1962 | ||
1963 | */ | |
1964 | ||
1965 | int | |
1ab3bf1b JG |
1966 | attach (pid) |
1967 | int pid; | |
35f5886e | 1968 | { |
a39ad5ce | 1969 | if (!open_proc_file (pid, &pi)) |
35f5886e FF |
1970 | { |
1971 | perror_with_name (pi.pathname); | |
1972 | /* NOTREACHED */ | |
1973 | } | |
1974 | ||
1975 | /* Get current status of process and if it is not already stopped, | |
1976 | then stop it. Remember whether or not it was stopped when we first | |
1977 | examined it. */ | |
1978 | ||
1979 | if (ioctl (pi.fd, PIOCSTATUS, &pi.prstatus) < 0) | |
1980 | { | |
1981 | print_sys_errmsg (pi.pathname, errno); | |
a39ad5ce | 1982 | close_proc_file (&pi); |
35f5886e FF |
1983 | error ("PIOCSTATUS failed"); |
1984 | } | |
1985 | if (pi.prstatus.pr_flags & (PR_STOPPED | PR_ISTOP)) | |
1986 | { | |
1987 | pi.was_stopped = 1; | |
1988 | } | |
1989 | else | |
1990 | { | |
1991 | pi.was_stopped = 0; | |
1992 | if (query ("Process is currently running, stop it? ")) | |
1993 | { | |
1994 | if (ioctl (pi.fd, PIOCSTOP, &pi.prstatus) < 0) | |
1995 | { | |
1996 | print_sys_errmsg (pi.pathname, errno); | |
a39ad5ce | 1997 | close_proc_file (&pi); |
35f5886e FF |
1998 | error ("PIOCSTOP failed"); |
1999 | } | |
2000 | } | |
2001 | } | |
2002 | ||
2003 | /* Remember some things about the inferior that we will, or might, change | |
2004 | so that we can restore them when we detach. */ | |
2005 | ||
cc221e76 FF |
2006 | (void) ioctl (pi.fd, PIOCGTRACE, &pi.saved_trace); |
2007 | (void) ioctl (pi.fd, PIOCGHOLD, &pi.saved_sighold); | |
2008 | (void) ioctl (pi.fd, PIOCGFAULT, &pi.saved_fltset); | |
2009 | (void) ioctl (pi.fd, PIOCGENTRY, &pi.saved_entryset); | |
2010 | (void) ioctl (pi.fd, PIOCGEXIT, &pi.saved_exitset); | |
35f5886e FF |
2011 | |
2012 | /* Set up trace and fault sets, as gdb expects them. */ | |
2013 | ||
2014 | (void) memset (&pi.prrun, 0, sizeof (pi.prrun)); | |
2015 | prfillset (&pi.prrun.pr_trace); | |
cc221e76 | 2016 | proc_signal_handling_change (); |
35f5886e FF |
2017 | prfillset (&pi.prrun.pr_fault); |
2018 | prdelset (&pi.prrun.pr_fault, FLTPAGE); | |
2019 | if (ioctl (pi.fd, PIOCSFAULT, &pi.prrun.pr_fault)) | |
2020 | { | |
f66f459f | 2021 | print_sys_errmsg ("PIOCSFAULT failed", errno); |
35f5886e FF |
2022 | } |
2023 | if (ioctl (pi.fd, PIOCSTRACE, &pi.prrun.pr_trace)) | |
2024 | { | |
f66f459f | 2025 | print_sys_errmsg ("PIOCSTRACE failed", errno); |
35f5886e FF |
2026 | } |
2027 | attach_flag = 1; | |
2028 | return (pid); | |
2029 | } | |
2030 | ||
2031 | /* | |
2032 | ||
2033 | GLOBAL FUNCTION | |
2034 | ||
2035 | detach -- detach from an attached-to process | |
2036 | ||
2037 | SYNOPSIS | |
2038 | ||
2039 | void detach (int signal) | |
2040 | ||
2041 | DESCRIPTION | |
2042 | ||
2043 | Detach from the current attachee. | |
2044 | ||
2045 | If signal is non-zero, the attachee is started running again and sent | |
2046 | the specified signal. | |
2047 | ||
2048 | If signal is zero and the attachee was not already stopped when we | |
2049 | attached to it, then we make it runnable again when we detach. | |
2050 | ||
2051 | Otherwise, we query whether or not to make the attachee runnable | |
2052 | again, since we may simply want to leave it in the state it was in | |
2053 | when we attached. | |
2054 | ||
2055 | We report any problems, but do not consider them errors, since we | |
2056 | MUST detach even if some things don't seem to go right. This may not | |
2057 | be the ideal situation. (FIXME). | |
2058 | */ | |
2059 | ||
2060 | void | |
1ab3bf1b JG |
2061 | detach (signal) |
2062 | int signal; | |
35f5886e FF |
2063 | { |
2064 | if (signal) | |
2065 | { | |
6b801388 | 2066 | set_proc_siginfo (&pi, signal); |
35f5886e | 2067 | } |
cc221e76 | 2068 | if (ioctl (pi.fd, PIOCSEXIT, &pi.saved_exitset) < 0) |
35f5886e FF |
2069 | { |
2070 | print_sys_errmsg (pi.pathname, errno); | |
2071 | printf ("PIOCSEXIT failed.\n"); | |
2072 | } | |
cc221e76 | 2073 | if (ioctl (pi.fd, PIOCSENTRY, &pi.saved_entryset) < 0) |
35f5886e FF |
2074 | { |
2075 | print_sys_errmsg (pi.pathname, errno); | |
2076 | printf ("PIOCSENTRY failed.\n"); | |
2077 | } | |
cc221e76 | 2078 | if (ioctl (pi.fd, PIOCSTRACE, &pi.saved_trace) < 0) |
35f5886e FF |
2079 | { |
2080 | print_sys_errmsg (pi.pathname, errno); | |
2081 | printf ("PIOCSTRACE failed.\n"); | |
2082 | } | |
cc221e76 FF |
2083 | if (ioctl (pi.fd, PIOCSHOLD, &pi.saved_sighold) < 0) |
2084 | { | |
2085 | print_sys_errmsg (pi.pathname, errno); | |
2086 | printf ("PIOSCHOLD failed.\n"); | |
2087 | } | |
2088 | if (ioctl (pi.fd, PIOCSFAULT, &pi.saved_fltset) < 0) | |
35f5886e FF |
2089 | { |
2090 | print_sys_errmsg (pi.pathname, errno); | |
2091 | printf ("PIOCSFAULT failed.\n"); | |
2092 | } | |
2093 | if (ioctl (pi.fd, PIOCSTATUS, &pi.prstatus) < 0) | |
2094 | { | |
2095 | print_sys_errmsg (pi.pathname, errno); | |
2096 | printf ("PIOCSTATUS failed.\n"); | |
2097 | } | |
2098 | else | |
2099 | { | |
2100 | if (signal || (pi.prstatus.pr_flags & (PR_STOPPED | PR_ISTOP))) | |
2101 | { | |
2102 | if (signal || !pi.was_stopped || | |
2103 | query ("Was stopped when attached, make it runnable again? ")) | |
2104 | { | |
2105 | (void) memset (&pi.prrun, 0, sizeof (pi.prrun)); | |
2106 | pi.prrun.pr_flags = PRCFAULT; | |
2107 | if (ioctl (pi.fd, PIOCRUN, &pi.prrun)) | |
2108 | { | |
2109 | print_sys_errmsg (pi.pathname, errno); | |
2110 | printf ("PIOCRUN failed.\n"); | |
2111 | } | |
2112 | } | |
2113 | } | |
2114 | } | |
a39ad5ce | 2115 | close_proc_file (&pi); |
35f5886e FF |
2116 | attach_flag = 0; |
2117 | } | |
2118 | ||
fb182850 FF |
2119 | #endif /* ATTACH_DETACH */ |
2120 | ||
35f5886e FF |
2121 | /* |
2122 | ||
2123 | GLOBAL FUNCTION | |
2124 | ||
2125 | proc_wait -- emulate wait() as much as possible | |
2126 | ||
2127 | SYNOPSIS | |
2128 | ||
2129 | int proc_wait (int *statloc) | |
2130 | ||
2131 | DESCRIPTION | |
2132 | ||
2133 | Try to emulate wait() as much as possible. Not sure why we can't | |
2134 | just use wait(), but it seems to have problems when applied to a | |
2135 | process being controlled with the /proc interface. | |
2136 | ||
2137 | NOTES | |
2138 | ||
2139 | We have a race problem here with no obvious solution. We need to let | |
2140 | the inferior run until it stops on an event of interest, which means | |
2141 | that we need to use the PIOCWSTOP ioctl. However, we cannot use this | |
2142 | ioctl if the process is already stopped on something that is not an | |
2143 | event of interest, or the call will hang indefinitely. Thus we first | |
2144 | use PIOCSTATUS to see if the process is not stopped. If not, then we | |
2145 | use PIOCWSTOP. But during the window between the two, if the process | |
2146 | stops for any reason that is not an event of interest (such as a job | |
2147 | control signal) then gdb will hang. One possible workaround is to set | |
2148 | an alarm to wake up every minute of so and check to see if the process | |
2149 | is still running, and if so, then reissue the PIOCWSTOP. But this is | |
2150 | a real kludge, so has not been implemented. FIXME: investigate | |
2151 | alternatives. | |
2152 | ||
2153 | FIXME: Investigate why wait() seems to have problems with programs | |
2154 | being control by /proc routines. | |
2155 | ||
2156 | */ | |
2157 | ||
2158 | int | |
1ab3bf1b JG |
2159 | proc_wait (statloc) |
2160 | int *statloc; | |
35f5886e FF |
2161 | { |
2162 | short what; | |
2163 | short why; | |
2164 | int statval = 0; | |
2165 | int checkerr = 0; | |
2166 | int rtnval = -1; | |
2167 | ||
2168 | if (ioctl (pi.fd, PIOCSTATUS, &pi.prstatus) < 0) | |
2169 | { | |
2170 | checkerr++; | |
2171 | } | |
2172 | else if (!(pi.prstatus.pr_flags & (PR_STOPPED | PR_ISTOP))) | |
2173 | { | |
2174 | if (ioctl (pi.fd, PIOCWSTOP, &pi.prstatus) < 0) | |
2175 | { | |
2176 | checkerr++; | |
2177 | } | |
2178 | } | |
2179 | if (checkerr) | |
2180 | { | |
2181 | if (errno == ENOENT) | |
2182 | { | |
2183 | rtnval = wait (&statval); | |
2184 | if (rtnval != inferior_pid) | |
2185 | { | |
2186 | error ("PIOCWSTOP, wait failed, returned %d", rtnval); | |
2187 | /* NOTREACHED */ | |
2188 | } | |
2189 | } | |
2190 | else | |
2191 | { | |
2192 | print_sys_errmsg (pi.pathname, errno); | |
2193 | error ("PIOCSTATUS or PIOCWSTOP failed."); | |
2194 | /* NOTREACHED */ | |
2195 | } | |
2196 | } | |
2197 | else if (pi.prstatus.pr_flags & (PR_STOPPED | PR_ISTOP)) | |
2198 | { | |
2199 | rtnval = pi.prstatus.pr_pid; | |
2200 | why = pi.prstatus.pr_why; | |
2201 | what = pi.prstatus.pr_what; | |
2202 | if (why == PR_SIGNALLED) | |
2203 | { | |
2204 | statval = (what << 8) | 0177; | |
2205 | } | |
407a8389 SG |
2206 | else if ((why == PR_SYSEXIT) |
2207 | && | |
2208 | ( | |
2209 | #ifdef SYS_exec | |
2210 | what == SYS_exec | |
2211 | #else | |
2212 | 0 == 0 | |
2213 | #endif | |
2214 | #ifdef SYS_execve | |
2215 | || what == SYS_execve | |
2216 | #endif | |
2217 | #ifdef SYS_execv | |
2218 | || what == SYS_execv | |
2219 | #endif | |
2220 | )) | |
35f5886e FF |
2221 | { |
2222 | statval = (SIGTRAP << 8) | 0177; | |
2223 | } | |
2224 | else if (why == PR_REQUESTED) | |
2225 | { | |
2226 | statval = (SIGSTOP << 8) | 0177; | |
2227 | } | |
2228 | else if (why == PR_JOBCONTROL) | |
2229 | { | |
2230 | statval = (what << 8) | 0177; | |
2231 | } | |
2232 | else if (why == PR_FAULTED) | |
2233 | { | |
2234 | switch (what) | |
2235 | { | |
2236 | case FLTPRIV: | |
2237 | case FLTILL: | |
2238 | statval = (SIGILL << 8) | 0177; | |
2239 | break; | |
2240 | case FLTBPT: | |
2241 | case FLTTRACE: | |
2242 | statval = (SIGTRAP << 8) | 0177; | |
2243 | break; | |
2244 | case FLTSTACK: | |
2245 | case FLTACCESS: | |
2246 | case FLTBOUNDS: | |
2247 | statval = (SIGSEGV << 8) | 0177; | |
2248 | break; | |
2249 | case FLTIOVF: | |
2250 | case FLTIZDIV: | |
2251 | case FLTFPE: | |
2252 | statval = (SIGFPE << 8) | 0177; | |
2253 | break; | |
2254 | case FLTPAGE: /* Recoverable page fault */ | |
2255 | default: | |
2256 | rtnval = -1; | |
2257 | error ("PIOCWSTOP, unknown why %d, what %d", why, what); | |
2258 | /* NOTREACHED */ | |
2259 | } | |
2260 | } | |
2261 | else | |
2262 | { | |
2263 | rtnval = -1; | |
2264 | error ("PIOCWSTOP, unknown why %d, what %d", why, what); | |
2265 | /* NOTREACHED */ | |
2266 | } | |
2267 | } | |
2268 | else | |
2269 | { | |
2270 | error ("PIOCWSTOP, stopped for unknown/unhandled reason, flags %#x", | |
2271 | pi.prstatus.pr_flags); | |
2272 | /* NOTREACHED */ | |
2273 | } | |
2274 | if (statloc) | |
2275 | { | |
2276 | *statloc = statval; | |
2277 | } | |
2278 | return (rtnval); | |
2279 | } | |
2280 | ||
2281 | /* | |
2282 | ||
6b801388 FF |
2283 | LOCAL FUNCTION |
2284 | ||
2285 | set_proc_siginfo - set a process's current signal info | |
2286 | ||
2287 | SYNOPSIS | |
2288 | ||
2289 | void set_proc_siginfo (struct procinfo *pip, int signo); | |
2290 | ||
2291 | DESCRIPTION | |
2292 | ||
2293 | Given a pointer to a process info struct in PIP and a signal number | |
2294 | in SIGNO, set the process's current signal and its associated signal | |
2295 | information. The signal will be delivered to the process immediately | |
2296 | after execution is resumed, even if it is being held. In addition, | |
2297 | this particular delivery will not cause another PR_SIGNALLED stop | |
2298 | even if the signal is being traced. | |
2299 | ||
2300 | If we are not delivering the same signal that the prstatus siginfo | |
2301 | struct contains information about, then synthesize a siginfo struct | |
2302 | to match the signal we are doing to deliver, make it of the type | |
2303 | "generated by a user process", and send this synthesized copy. When | |
2304 | used to set the inferior's signal state, this will be required if we | |
2305 | are not currently stopped because of a traced signal, or if we decide | |
2306 | to continue with a different signal. | |
2307 | ||
2308 | Note that when continuing the inferior from a stop due to receipt | |
2309 | of a traced signal, we either have set PRCSIG to clear the existing | |
2310 | signal, or we have to call this function to do a PIOCSSIG with either | |
2311 | the existing siginfo struct from pr_info, or one we have synthesized | |
2312 | appropriately for the signal we want to deliver. Otherwise if the | |
2313 | signal is still being traced, the inferior will immediately stop | |
2314 | again. | |
2315 | ||
2316 | See siginfo(5) for more details. | |
2317 | */ | |
2318 | ||
2319 | static void | |
2320 | set_proc_siginfo (pip, signo) | |
cc221e76 FF |
2321 | struct procinfo *pip; |
2322 | int signo; | |
6b801388 FF |
2323 | { |
2324 | struct siginfo newsiginfo; | |
2325 | struct siginfo *sip; | |
2326 | ||
2327 | if (pip -> valid) | |
2328 | { | |
2329 | if (signo == pip -> prstatus.pr_info.si_signo) | |
2330 | { | |
2331 | sip = &pip -> prstatus.pr_info; | |
2332 | } | |
2333 | else | |
2334 | { | |
2335 | (void) memset ((char *) &newsiginfo, 0, sizeof (newsiginfo)); | |
2336 | sip = &newsiginfo; | |
2337 | sip -> si_signo = signo; | |
2338 | sip -> si_code = 0; | |
2339 | sip -> si_errno = 0; | |
2340 | sip -> si_pid = getpid (); | |
2341 | sip -> si_uid = getuid (); | |
2342 | } | |
2343 | if (ioctl (pip -> fd, PIOCSSIG, sip) < 0) | |
2344 | { | |
2345 | print_sys_errmsg (pip -> pathname, errno); | |
2346 | warning ("PIOCSSIG failed"); | |
2347 | } | |
2348 | } | |
2349 | } | |
2350 | ||
2351 | /* | |
2352 | ||
35f5886e FF |
2353 | GLOBAL FUNCTION |
2354 | ||
2355 | child_resume -- resume execution of the inferior process | |
2356 | ||
2357 | SYNOPSIS | |
2358 | ||
cc221e76 | 2359 | void child_resume (int step, int signo) |
35f5886e FF |
2360 | |
2361 | DESCRIPTION | |
2362 | ||
2363 | Resume execution of the inferior process. If STEP is nozero, then | |
2364 | just single step it. If SIGNAL is nonzero, restart it with that | |
2365 | signal activated. | |
2366 | ||
2367 | NOTE | |
2368 | ||
2369 | It may not be absolutely necessary to specify the PC value for | |
2370 | restarting, but to be safe we use the value that gdb considers | |
2371 | to be current. One case where this might be necessary is if the | |
2372 | user explicitly changes the PC value that gdb considers to be | |
2373 | current. FIXME: Investigate if this is necessary or not. | |
2374 | */ | |
2375 | ||
2376 | void | |
cc221e76 | 2377 | child_resume (step, signo) |
1ab3bf1b | 2378 | int step; |
cc221e76 | 2379 | int signo; |
35f5886e FF |
2380 | { |
2381 | errno = 0; | |
2382 | pi.prrun.pr_flags = PRSVADDR | PRSTRACE | PRSFAULT | PRCFAULT; | |
2383 | pi.prrun.pr_vaddr = (caddr_t) *(int *) ®isters[REGISTER_BYTE (PC_REGNUM)]; | |
cc221e76 | 2384 | if (signo) |
35f5886e | 2385 | { |
cc221e76 | 2386 | set_proc_siginfo (&pi, signo); |
35f5886e FF |
2387 | } |
2388 | else | |
2389 | { | |
2390 | pi.prrun.pr_flags |= PRCSIG; | |
2391 | } | |
2392 | if (step) | |
2393 | { | |
2394 | pi.prrun.pr_flags |= PRSTEP; | |
2395 | } | |
2396 | if (ioctl (pi.fd, PIOCRUN, &pi.prrun) != 0) | |
2397 | { | |
2398 | perror_with_name (pi.pathname); | |
2399 | /* NOTREACHED */ | |
2400 | } | |
2401 | } | |
2402 | ||
2403 | /* | |
2404 | ||
2405 | GLOBAL FUNCTION | |
2406 | ||
2407 | fetch_inferior_registers -- fetch current registers from inferior | |
2408 | ||
2409 | SYNOPSIS | |
2410 | ||
1ab3bf1b | 2411 | void fetch_inferior_registers (int regno) |
35f5886e FF |
2412 | |
2413 | DESCRIPTION | |
2414 | ||
2415 | Read the current values of the inferior's registers, both the | |
2416 | general register set and floating point registers (if supported) | |
2417 | and update gdb's idea of their current values. | |
2418 | ||
2419 | */ | |
2420 | ||
2421 | void | |
1ab3bf1b JG |
2422 | fetch_inferior_registers (regno) |
2423 | int regno; | |
35f5886e FF |
2424 | { |
2425 | if (ioctl (pi.fd, PIOCGREG, &pi.gregset) != -1) | |
2426 | { | |
2427 | supply_gregset (&pi.gregset); | |
2428 | } | |
2429 | #if defined (FP0_REGNUM) | |
2430 | if (ioctl (pi.fd, PIOCGFPREG, &pi.fpregset) != -1) | |
2431 | { | |
2432 | supply_fpregset (&pi.fpregset); | |
2433 | } | |
2434 | #endif | |
2435 | } | |
2436 | ||
fb182850 FF |
2437 | /* |
2438 | ||
2439 | GLOBAL FUNCTION | |
2440 | ||
2441 | fetch_core_registers -- fetch current registers from core file data | |
2442 | ||
2443 | SYNOPSIS | |
2444 | ||
2445 | void fetch_core_registers (char *core_reg_sect, unsigned core_reg_size, | |
1ab3bf1b | 2446 | int which, unsigned in reg_addr) |
fb182850 FF |
2447 | |
2448 | DESCRIPTION | |
2449 | ||
2450 | Read the values of either the general register set (WHICH equals 0) | |
2451 | or the floating point register set (WHICH equals 2) from the core | |
2452 | file data (pointed to by CORE_REG_SECT), and update gdb's idea of | |
2453 | their current values. The CORE_REG_SIZE parameter is ignored. | |
2454 | ||
2455 | NOTES | |
2456 | ||
2457 | Use the indicated sizes to validate the gregset and fpregset | |
2458 | structures. | |
2459 | */ | |
2460 | ||
2461 | void | |
1ab3bf1b | 2462 | fetch_core_registers (core_reg_sect, core_reg_size, which, reg_addr) |
cc221e76 FF |
2463 | char *core_reg_sect; |
2464 | unsigned core_reg_size; | |
2465 | int which; | |
2466 | unsigned int reg_addr; /* Unused in this version */ | |
fb182850 FF |
2467 | { |
2468 | ||
2469 | if (which == 0) | |
2470 | { | |
2471 | if (core_reg_size != sizeof (pi.gregset)) | |
2472 | { | |
2473 | warning ("wrong size gregset struct in core file"); | |
2474 | } | |
2475 | else | |
2476 | { | |
2477 | (void) memcpy ((char *) &pi.gregset, core_reg_sect, | |
2478 | sizeof (pi.gregset)); | |
2479 | supply_gregset (&pi.gregset); | |
2480 | } | |
2481 | } | |
2482 | else if (which == 2) | |
2483 | { | |
2484 | if (core_reg_size != sizeof (pi.fpregset)) | |
2485 | { | |
2486 | warning ("wrong size fpregset struct in core file"); | |
2487 | } | |
2488 | else | |
2489 | { | |
2490 | (void) memcpy ((char *) &pi.fpregset, core_reg_sect, | |
2491 | sizeof (pi.fpregset)); | |
2492 | #if defined (FP0_REGNUM) | |
2493 | supply_fpregset (&pi.fpregset); | |
2494 | #endif | |
2495 | } | |
2496 | } | |
2497 | } | |
35f5886e FF |
2498 | |
2499 | /* | |
2500 | ||
2501 | LOCAL FUNCTION | |
2502 | ||
2503 | proc_init_failed - called whenever /proc access initialization fails | |
2504 | ||
2505 | SYNOPSIS | |
2506 | ||
2507 | static void proc_init_failed (char *why) | |
2508 | ||
2509 | DESCRIPTION | |
2510 | ||
2511 | This function is called whenever initialization of access to a /proc | |
2512 | entry fails. It prints a suitable error message, does some cleanup, | |
2513 | and then invokes the standard error processing routine which dumps | |
2514 | us back into the command loop. | |
2515 | */ | |
2516 | ||
2517 | static void | |
1ab3bf1b JG |
2518 | proc_init_failed (why) |
2519 | char *why; | |
35f5886e FF |
2520 | { |
2521 | print_sys_errmsg (pi.pathname, errno); | |
2522 | (void) kill (pi.pid, SIGKILL); | |
a39ad5ce | 2523 | close_proc_file (&pi); |
35f5886e FF |
2524 | error (why); |
2525 | /* NOTREACHED */ | |
2526 | } | |
2527 | ||
2528 | /* | |
2529 | ||
2530 | LOCAL FUNCTION | |
2531 | ||
2532 | close_proc_file - close any currently open /proc entry | |
2533 | ||
2534 | SYNOPSIS | |
2535 | ||
a39ad5ce | 2536 | static void close_proc_file (struct procinfo *pip) |
35f5886e FF |
2537 | |
2538 | DESCRIPTION | |
2539 | ||
2540 | Close any currently open /proc entry and mark the process information | |
2541 | entry as invalid. In order to ensure that we don't try to reuse any | |
2542 | stale information, the pid, fd, and pathnames are explicitly | |
2543 | invalidated, which may be overkill. | |
2544 | ||
2545 | */ | |
2546 | ||
2547 | static void | |
1ab3bf1b JG |
2548 | close_proc_file (pip) |
2549 | struct procinfo *pip; | |
35f5886e | 2550 | { |
a39ad5ce FF |
2551 | pip -> pid = 0; |
2552 | if (pip -> valid) | |
35f5886e | 2553 | { |
a39ad5ce | 2554 | (void) close (pip -> fd); |
35f5886e | 2555 | } |
a39ad5ce FF |
2556 | pip -> fd = -1; |
2557 | if (pip -> pathname) | |
35f5886e | 2558 | { |
a39ad5ce FF |
2559 | free (pip -> pathname); |
2560 | pip -> pathname = NULL; | |
35f5886e | 2561 | } |
a39ad5ce | 2562 | pip -> valid = 0; |
35f5886e FF |
2563 | } |
2564 | ||
2565 | /* | |
2566 | ||
2567 | LOCAL FUNCTION | |
2568 | ||
2569 | open_proc_file - open a /proc entry for a given process id | |
2570 | ||
2571 | SYNOPSIS | |
2572 | ||
a39ad5ce | 2573 | static int open_proc_file (pid, struct procinfo *pip) |
35f5886e FF |
2574 | |
2575 | DESCRIPTION | |
2576 | ||
2577 | Given a process id, close the existing open /proc entry (if any) | |
2578 | and open one for the new process id. Once it is open, then | |
2579 | mark the local process information structure as valid, which | |
2580 | guarantees that the pid, fd, and pathname fields match an open | |
2581 | /proc entry. Returns zero if the open fails, nonzero otherwise. | |
2582 | ||
2583 | Note that the pathname is left intact, even when the open fails, | |
2584 | so that callers can use it to construct meaningful error messages | |
2585 | rather than just "file open failed". | |
2586 | */ | |
2587 | ||
2588 | static int | |
1ab3bf1b JG |
2589 | open_proc_file (pid, pip) |
2590 | int pid; | |
2591 | struct procinfo *pip; | |
35f5886e | 2592 | { |
a39ad5ce FF |
2593 | pip -> valid = 0; |
2594 | if (pip -> valid) | |
2595 | { | |
2596 | (void) close (pip -> fd); | |
2597 | } | |
2598 | if (pip -> pathname == NULL) | |
2599 | { | |
2600 | pip -> pathname = xmalloc (32); | |
2601 | } | |
2602 | sprintf (pip -> pathname, PROC_NAME_FMT, pid); | |
2603 | if ((pip -> fd = open (pip -> pathname, O_RDWR)) >= 0) | |
2604 | { | |
2605 | pip -> valid = 1; | |
2606 | pip -> pid = pid; | |
2607 | } | |
2608 | return (pip -> valid); | |
2609 | } | |
2610 | ||
f66f459f | 2611 | static char * |
1ab3bf1b JG |
2612 | mappingflags (flags) |
2613 | long flags; | |
a39ad5ce FF |
2614 | { |
2615 | static char asciiflags[7]; | |
2616 | ||
2617 | strcpy (asciiflags, "------"); | |
2618 | if (flags & MA_STACK) asciiflags[0] = 's'; | |
2619 | if (flags & MA_BREAK) asciiflags[1] = 'b'; | |
2620 | if (flags & MA_SHARED) asciiflags[2] = 's'; | |
2621 | if (flags & MA_READ) asciiflags[3] = 'r'; | |
2622 | if (flags & MA_WRITE) asciiflags[4] = 'w'; | |
2623 | if (flags & MA_EXEC) asciiflags[5] = 'x'; | |
2624 | return (asciiflags); | |
2625 | } | |
2626 | ||
2627 | static void | |
cc221e76 FF |
2628 | info_proc_flags (pip, summary) |
2629 | struct procinfo *pip; | |
2630 | int summary; | |
2631 | { | |
2632 | struct trans *transp; | |
2633 | ||
2634 | printf_filtered ("%-32s", "Process status flags:"); | |
2635 | if (!summary) | |
2636 | { | |
2637 | printf_filtered ("\n\n"); | |
2638 | } | |
2639 | for (transp = pr_flag_table; transp -> name != NULL; transp++) | |
2640 | { | |
2641 | if (pip -> prstatus.pr_flags & transp -> value) | |
2642 | { | |
2643 | if (summary) | |
2644 | { | |
2645 | printf_filtered ("%s ", transp -> name); | |
2646 | } | |
2647 | else | |
2648 | { | |
2649 | printf_filtered ("\t%-16s %s.\n", transp -> name, transp -> desc); | |
2650 | } | |
2651 | } | |
2652 | } | |
2653 | printf_filtered ("\n"); | |
2654 | } | |
2655 | ||
2656 | static void | |
2657 | info_proc_stop (pip, summary) | |
2658 | struct procinfo *pip; | |
2659 | int summary; | |
2660 | { | |
2661 | struct trans *transp; | |
2662 | int why; | |
2663 | int what; | |
2664 | ||
2665 | why = pip -> prstatus.pr_why; | |
2666 | what = pip -> prstatus.pr_what; | |
2667 | ||
2668 | if (pip -> prstatus.pr_flags & PR_STOPPED) | |
2669 | { | |
2670 | printf_filtered ("%-32s", "Reason for stopping:"); | |
2671 | if (!summary) | |
2672 | { | |
2673 | printf_filtered ("\n\n"); | |
2674 | } | |
2675 | for (transp = pr_why_table; transp -> name != NULL; transp++) | |
2676 | { | |
2677 | if (why == transp -> value) | |
2678 | { | |
2679 | if (summary) | |
2680 | { | |
2681 | printf_filtered ("%s ", transp -> name); | |
2682 | } | |
2683 | else | |
2684 | { | |
2685 | printf_filtered ("\t%-16s %s.\n", | |
2686 | transp -> name, transp -> desc); | |
2687 | } | |
2688 | break; | |
2689 | } | |
2690 | } | |
2691 | ||
2692 | /* Use the pr_why field to determine what the pr_what field means, and | |
2693 | print more information. */ | |
2694 | ||
2695 | switch (why) | |
2696 | { | |
2697 | case PR_REQUESTED: | |
2698 | /* pr_what is unused for this case */ | |
2699 | break; | |
2700 | case PR_JOBCONTROL: | |
2701 | case PR_SIGNALLED: | |
2702 | if (summary) | |
2703 | { | |
2704 | printf_filtered ("%s ", signalname (what)); | |
2705 | } | |
2706 | else | |
2707 | { | |
2708 | printf_filtered ("\t%-16s %s.\n", signalname (what), | |
2709 | sys_siglist[what]); | |
2710 | } | |
2711 | break; | |
2712 | case PR_SYSENTRY: | |
2713 | if (summary) | |
2714 | { | |
2715 | printf_filtered ("%s ", syscallname (what)); | |
2716 | } | |
2717 | else | |
2718 | { | |
2719 | printf_filtered ("\t%-16s %s.\n", syscallname (what), | |
2720 | "Entered this system call"); | |
2721 | } | |
2722 | break; | |
2723 | case PR_SYSEXIT: | |
2724 | if (summary) | |
2725 | { | |
2726 | printf_filtered ("%s ", syscallname (what)); | |
2727 | } | |
2728 | else | |
2729 | { | |
2730 | printf_filtered ("\t%-16s %s.\n", syscallname (what), | |
2731 | "Returned from this system call"); | |
2732 | } | |
2733 | break; | |
2734 | case PR_FAULTED: | |
2735 | if (summary) | |
2736 | { | |
2737 | printf_filtered ("%s ", | |
2738 | lookupname (faults_table, what, "fault")); | |
2739 | } | |
2740 | else | |
2741 | { | |
2742 | printf_filtered ("\t%-16s %s.\n", | |
2743 | lookupname (faults_table, what, "fault"), | |
2744 | lookupdesc (faults_table, what)); | |
2745 | } | |
2746 | break; | |
2747 | } | |
2748 | printf_filtered ("\n"); | |
2749 | } | |
2750 | } | |
2751 | ||
2752 | static void | |
2753 | info_proc_siginfo (pip, summary) | |
2754 | struct procinfo *pip; | |
2755 | int summary; | |
2756 | { | |
2757 | struct siginfo *sip; | |
2758 | ||
2759 | if ((pip -> prstatus.pr_flags & PR_STOPPED) && | |
2760 | (pip -> prstatus.pr_why == PR_SIGNALLED || | |
2761 | pip -> prstatus.pr_why == PR_FAULTED)) | |
2762 | { | |
2763 | printf_filtered ("%-32s", "Additional signal/fault info:"); | |
2764 | sip = &pip -> prstatus.pr_info; | |
2765 | if (summary) | |
2766 | { | |
2767 | printf_filtered ("%s ", signalname (sip -> si_signo)); | |
2768 | if (sip -> si_errno > 0) | |
2769 | { | |
2770 | printf_filtered ("%s ", lookupname (errno_table, | |
2771 | sip -> si_errno, "errno")); | |
2772 | } | |
2773 | if (sip -> si_code <= 0) | |
2774 | { | |
2775 | printf_filtered ("sent by pid %d, uid %d ", sip -> si_pid, | |
2776 | sip -> si_uid); | |
2777 | } | |
2778 | else | |
2779 | { | |
2780 | printf_filtered ("%s ", sigcodename (sip)); | |
2781 | if ((sip -> si_signo == SIGILL) || | |
2782 | (sip -> si_signo == SIGFPE) || | |
2783 | (sip -> si_signo == SIGSEGV) || | |
2784 | (sip -> si_signo == SIGBUS)) | |
2785 | { | |
2786 | printf_filtered ("addr=%#x ", sip -> si_addr); | |
2787 | } | |
2788 | else if ((sip -> si_signo == SIGCHLD)) | |
2789 | { | |
2790 | printf_filtered ("child pid %u, status %u ", | |
2791 | sip -> si_pid, | |
2792 | sip -> si_status); | |
2793 | } | |
2794 | else if ((sip -> si_signo == SIGPOLL)) | |
2795 | { | |
2796 | printf_filtered ("band %u ", sip -> si_band); | |
2797 | } | |
2798 | } | |
2799 | } | |
2800 | else | |
2801 | { | |
2802 | printf_filtered ("\n\n"); | |
2803 | printf_filtered ("\t%-16s %s.\n", signalname (sip -> si_signo), | |
2804 | sys_siglist[sip -> si_signo]); | |
2805 | if (sip -> si_errno > 0) | |
2806 | { | |
2807 | printf_filtered ("\t%-16s %s.\n", | |
2808 | lookupname (errno_table, | |
2809 | sip -> si_errno, "errno"), | |
2810 | lookupdesc (errno_table, sip -> si_errno)); | |
2811 | } | |
2812 | if (sip -> si_code <= 0) | |
2813 | { | |
2814 | printf_filtered ("\t%-16u %s\n", sip -> si_pid, | |
2815 | "PID of process sending signal"); | |
2816 | printf_filtered ("\t%-16u %s\n", sip -> si_uid, | |
2817 | "UID of process sending signal"); | |
2818 | } | |
2819 | else | |
2820 | { | |
2821 | printf_filtered ("\t%-16s %s.\n", sigcodename (sip), | |
2822 | sigcodedesc (sip)); | |
2823 | if ((sip -> si_signo == SIGILL) || | |
2824 | (sip -> si_signo == SIGFPE)) | |
2825 | { | |
2826 | printf_filtered ("\t%-16#x %s.\n", sip -> si_addr, | |
2827 | "Address of faulting instruction"); | |
2828 | } | |
2829 | else if ((sip -> si_signo == SIGSEGV) || | |
2830 | (sip -> si_signo == SIGBUS)) | |
2831 | { | |
2832 | printf_filtered ("\t%-16#x %s.\n", sip -> si_addr, | |
2833 | "Address of faulting memory reference"); | |
2834 | } | |
2835 | else if ((sip -> si_signo == SIGCHLD)) | |
2836 | { | |
2837 | printf_filtered ("\t%-16u %s.\n", sip -> si_pid, | |
2838 | "Child process ID"); | |
2839 | printf_filtered ("\t%-16u %s.\n", sip -> si_status, | |
2840 | "Child process exit value or signal"); | |
2841 | } | |
2842 | else if ((sip -> si_signo == SIGPOLL)) | |
2843 | { | |
2844 | printf_filtered ("\t%-16u %s.\n", sip -> si_band, | |
2845 | "Band event for POLL_{IN,OUT,MSG}"); | |
2846 | } | |
2847 | } | |
2848 | } | |
2849 | printf_filtered ("\n"); | |
2850 | } | |
2851 | } | |
2852 | ||
2853 | static void | |
2854 | info_proc_syscalls (pip, summary) | |
2855 | struct procinfo *pip; | |
2856 | int summary; | |
2857 | { | |
2858 | int syscallnum; | |
2859 | ||
2860 | if (!summary) | |
2861 | { | |
2862 | ||
2863 | #if 0 /* FIXME: Needs to use gdb-wide configured info about system calls. */ | |
2864 | if (pip -> prstatus.pr_flags & PR_ASLEEP) | |
2865 | { | |
2866 | int syscallnum = pip -> prstatus.pr_reg[R_D0]; | |
2867 | if (summary) | |
2868 | { | |
2869 | printf_filtered ("%-32s", "Sleeping in system call:"); | |
2870 | printf_filtered ("%s", syscallname (syscallnum)); | |
2871 | } | |
2872 | else | |
2873 | { | |
2874 | printf_filtered ("Sleeping in system call '%s'.\n", | |
2875 | syscallname (syscallnum)); | |
2876 | } | |
2877 | } | |
2878 | #endif | |
2879 | ||
2880 | if (ioctl (pip -> fd, PIOCGENTRY, &pip -> entryset) < 0) | |
2881 | { | |
2882 | print_sys_errmsg (pip -> pathname, errno); | |
2883 | error ("PIOCGENTRY failed"); | |
2884 | } | |
2885 | ||
2886 | if (ioctl (pip -> fd, PIOCGEXIT, &pip -> exitset) < 0) | |
2887 | { | |
2888 | print_sys_errmsg (pip -> pathname, errno); | |
2889 | error ("PIOCGEXIT failed"); | |
2890 | } | |
2891 | ||
2892 | printf_filtered ("System call tracing information:\n\n"); | |
2893 | ||
2894 | printf_filtered ("\t%-12s %-8s %-8s\n", | |
2895 | "System call", | |
2896 | "Entry", | |
2897 | "Exit"); | |
2898 | for (syscallnum = 0; syscallnum < MAX_SYSCALLS; syscallnum++) | |
2899 | { | |
2900 | QUIT; | |
2901 | if (syscall_table[syscallnum] != NULL) | |
2902 | { | |
2903 | printf_filtered ("\t%-12s ", syscall_table[syscallnum]); | |
2904 | printf_filtered ("%-8s ", | |
2905 | prismember (&pip -> entryset, syscallnum) | |
2906 | ? "on" : "off"); | |
2907 | printf_filtered ("%-8s ", | |
2908 | prismember (&pip -> exitset, syscallnum) | |
2909 | ? "on" : "off"); | |
2910 | printf_filtered ("\n"); | |
2911 | } | |
2912 | } | |
2913 | printf_filtered ("\n"); | |
2914 | } | |
2915 | } | |
2916 | ||
2917 | static char * | |
2918 | signalname (signo) | |
2919 | int signo; | |
2920 | { | |
2921 | char *abbrev; | |
2922 | static char locbuf[32]; | |
2923 | ||
2924 | abbrev = sig_abbrev (signo); | |
2925 | if (abbrev == NULL) | |
2926 | { | |
2927 | sprintf (locbuf, "signal %d", signo); | |
2928 | } | |
2929 | else | |
2930 | { | |
2931 | sprintf (locbuf, "SIG%s (%d)", abbrev, signo); | |
2932 | } | |
2933 | return (locbuf); | |
2934 | } | |
2935 | ||
2936 | static void | |
2937 | info_proc_signals (pip, summary) | |
2938 | struct procinfo *pip; | |
2939 | int summary; | |
2940 | { | |
2941 | int signo; | |
2942 | ||
2943 | if (!summary) | |
2944 | { | |
2945 | if (ioctl (pip -> fd, PIOCGTRACE, &pip -> trace) < 0) | |
2946 | { | |
2947 | print_sys_errmsg (pip -> pathname, errno); | |
2948 | error ("PIOCGTRACE failed"); | |
2949 | } | |
2950 | ||
2951 | printf_filtered ("Disposition of signals:\n\n"); | |
2952 | printf_filtered ("\t%-15s %-8s %-8s %-8s %s\n\n", | |
2953 | "Signal", "Trace", "Hold", "Pending", "Description"); | |
2954 | for (signo = 0; signo < NSIG; signo++) | |
2955 | { | |
2956 | QUIT; | |
2957 | printf_filtered ("\t%-15s ", signalname (signo)); | |
2958 | printf_filtered ("%-8s ", | |
2959 | prismember (&pip -> trace, signo) | |
2960 | ? "on" : "off"); | |
2961 | printf_filtered ("%-8s ", | |
2962 | prismember (&pip -> prstatus.pr_sighold, signo) | |
2963 | ? "on" : "off"); | |
2964 | printf_filtered ("%-8s ", | |
2965 | prismember (&pip -> prstatus.pr_sigpend, signo) | |
2966 | ? "yes" : "no"); | |
2967 | printf_filtered (" %s\n", sys_siglist[signo]); | |
2968 | } | |
2969 | printf_filtered ("\n"); | |
2970 | } | |
2971 | } | |
2972 | ||
2973 | static void | |
2974 | info_proc_faults (pip, summary) | |
2975 | struct procinfo *pip; | |
2976 | int summary; | |
2977 | { | |
2978 | struct trans *transp; | |
2979 | ||
2980 | if (!summary) | |
2981 | { | |
2982 | if (ioctl (pip -> fd, PIOCGFAULT, &pip -> fltset) < 0) | |
2983 | { | |
2984 | print_sys_errmsg (pip -> pathname, errno); | |
2985 | error ("PIOCGFAULT failed"); | |
2986 | } | |
2987 | ||
2988 | printf_filtered ("Current traced hardware fault set:\n\n"); | |
2989 | printf_filtered ("\t%-12s %-8s\n", "Fault", "Trace"); | |
2990 | ||
2991 | for (transp = faults_table; transp -> name != NULL; transp++) | |
2992 | { | |
2993 | QUIT; | |
2994 | printf_filtered ("\t%-12s ", transp -> name); | |
2995 | printf_filtered ("%-8s", prismember (&pip -> fltset, transp -> value) | |
2996 | ? "on" : "off"); | |
2997 | printf_filtered ("\n"); | |
2998 | } | |
2999 | printf_filtered ("\n"); | |
3000 | } | |
3001 | } | |
3002 | ||
3003 | static void | |
3004 | info_proc_mappings (pip, summary) | |
1ab3bf1b | 3005 | struct procinfo *pip; |
cc221e76 | 3006 | int summary; |
a39ad5ce FF |
3007 | { |
3008 | int nmap; | |
3009 | struct prmap *prmaps; | |
3010 | struct prmap *prmap; | |
3011 | ||
cc221e76 | 3012 | if (!summary) |
a39ad5ce | 3013 | { |
cc221e76 FF |
3014 | printf_filtered ("Mapped address spaces:\n\n"); |
3015 | printf_filtered ("\t%10s %10s %10s %10s %6s\n", | |
3016 | "Start Addr", | |
3017 | " End Addr", | |
3018 | " Size", | |
3019 | " Offset", | |
3020 | "Flags"); | |
3021 | if (ioctl (pip -> fd, PIOCNMAP, &nmap) == 0) | |
a39ad5ce | 3022 | { |
cc221e76 FF |
3023 | prmaps = (struct prmap *) alloca ((nmap + 1) * sizeof (*prmaps)); |
3024 | if (ioctl (pip -> fd, PIOCMAP, prmaps) == 0) | |
a39ad5ce | 3025 | { |
cc221e76 FF |
3026 | for (prmap = prmaps; prmap -> pr_size; ++prmap) |
3027 | { | |
3028 | printf_filtered ("\t%#10x %#10x %#10x %#10x %6s\n", | |
3029 | prmap -> pr_vaddr, | |
3030 | prmap -> pr_vaddr + prmap -> pr_size - 1, | |
3031 | prmap -> pr_size, | |
3032 | prmap -> pr_off, | |
3033 | mappingflags (prmap -> pr_mflags)); | |
3034 | } | |
a39ad5ce FF |
3035 | } |
3036 | } | |
cc221e76 | 3037 | printf_filtered ("\n"); |
a39ad5ce | 3038 | } |
a39ad5ce FF |
3039 | } |
3040 | ||
3041 | /* | |
3042 | ||
3043 | LOCAL FUNCTION | |
3044 | ||
cc221e76 | 3045 | info_proc -- implement the "info proc" command |
a39ad5ce FF |
3046 | |
3047 | SYNOPSIS | |
3048 | ||
cc221e76 | 3049 | void info_proc (char *args, int from_tty) |
a39ad5ce FF |
3050 | |
3051 | DESCRIPTION | |
3052 | ||
3053 | Implement gdb's "info proc" command by using the /proc interface | |
3054 | to print status information about any currently running process. | |
3055 | ||
3056 | Examples of the use of "info proc" are: | |
3057 | ||
cc221e76 FF |
3058 | info proc (prints summary info for current inferior) |
3059 | info proc 123 (prints summary info for process with pid 123) | |
3060 | info proc mappings (prints address mappings) | |
3061 | info proc times (prints process/children times) | |
3062 | info proc id (prints pid, ppid, gid, sid, etc) | |
3063 | info proc status (prints general process state info) | |
3064 | info proc signals (prints info about signal handling) | |
3065 | info proc all (prints all info) | |
a39ad5ce FF |
3066 | |
3067 | */ | |
3068 | ||
3069 | static void | |
cc221e76 | 3070 | info_proc (args, from_tty) |
1ab3bf1b JG |
3071 | char *args; |
3072 | int from_tty; | |
a39ad5ce | 3073 | { |
a39ad5ce FF |
3074 | int pid; |
3075 | struct procinfo pii; | |
3076 | struct procinfo *pip; | |
3077 | struct cleanup *old_chain; | |
3078 | char *nexttok; | |
cc221e76 FF |
3079 | char **argv; |
3080 | int argsize; | |
3081 | int summary = 1; | |
3082 | int flags = 0; | |
3083 | int syscalls = 0; | |
3084 | int signals = 0; | |
3085 | int faults = 0; | |
3086 | int mappings = 0; | |
3087 | int times = 0; | |
3088 | int id = 0; | |
3089 | int status = 0; | |
3090 | int all = 0; | |
a39ad5ce FF |
3091 | |
3092 | old_chain = make_cleanup (null_cleanup, 0); | |
3093 | ||
3094 | /* Default to using the current inferior if no pid specified */ | |
3095 | ||
3096 | pip = π | |
3097 | ||
a39ad5ce | 3098 | if (args != NULL) |
35f5886e | 3099 | { |
cc221e76 | 3100 | if ((argv = buildargv (args)) == NULL) |
a39ad5ce | 3101 | { |
cc221e76 FF |
3102 | nomem (0); |
3103 | } | |
3104 | make_cleanup (freeargv, (char *) argv); | |
3105 | ||
3106 | while (*argv != NULL) | |
3107 | { | |
3108 | argsize = strlen (*argv); | |
3109 | if (argsize >= 1 && strncmp (*argv, "all", argsize) == 0) | |
3110 | { | |
3111 | summary = 0; | |
3112 | all = 1; | |
3113 | } | |
3114 | else if (argsize >= 2 && strncmp (*argv, "faults", argsize) == 0) | |
3115 | { | |
3116 | summary = 0; | |
3117 | faults = 1; | |
3118 | } | |
3119 | else if (argsize >= 2 && strncmp (*argv, "flags", argsize) == 0) | |
3120 | { | |
3121 | summary = 0; | |
3122 | flags = 1; | |
3123 | } | |
3124 | else if (argsize >= 1 && strncmp (*argv, "id", argsize) == 0) | |
3125 | { | |
3126 | summary = 0; | |
3127 | id = 1; | |
3128 | } | |
3129 | else if (argsize >= 1 && strncmp (*argv, "mappings", argsize) == 0) | |
3130 | { | |
3131 | summary = 0; | |
3132 | mappings = 1; | |
3133 | } | |
3134 | else if (argsize >= 2 && strncmp (*argv, "signals", argsize) == 0) | |
3135 | { | |
3136 | summary = 0; | |
3137 | signals = 1; | |
3138 | } | |
3139 | else if (argsize >= 2 && strncmp (*argv, "status", argsize) == 0) | |
3140 | { | |
3141 | summary = 0; | |
3142 | status = 1; | |
3143 | } | |
3144 | else if (argsize >= 2 && strncmp (*argv, "syscalls", argsize) == 0) | |
3145 | { | |
3146 | summary = 0; | |
3147 | syscalls = 1; | |
3148 | } | |
3149 | else if (argsize >= 1 && strncmp (*argv, "times", argsize) == 0) | |
a39ad5ce | 3150 | { |
cc221e76 FF |
3151 | summary = 0; |
3152 | times = 1; | |
a39ad5ce | 3153 | } |
cc221e76 | 3154 | else if ((pii.pid = atoi (*argv)) > 0) |
a39ad5ce FF |
3155 | { |
3156 | pid = pii.pid; | |
3157 | pip = &pii; | |
3158 | (void) memset (&pii, 0, sizeof (pii)); | |
3159 | if (!open_proc_file (pid, pip)) | |
3160 | { | |
3161 | perror_with_name (pip -> pathname); | |
3162 | /* NOTREACHED */ | |
3163 | } | |
3164 | make_cleanup (close_proc_file, pip); | |
3165 | } | |
cc221e76 FF |
3166 | else if (**argv != '\000') |
3167 | { | |
3168 | error ("Unrecognized or ambiguous keyword `%s'.", *argv); | |
3169 | } | |
3170 | argv++; | |
a39ad5ce | 3171 | } |
35f5886e | 3172 | } |
a39ad5ce FF |
3173 | |
3174 | /* If we don't have a valid open process at this point, then we have no | |
3175 | inferior or didn't specify a specific pid. */ | |
3176 | ||
3177 | if (!pip -> valid) | |
35f5886e | 3178 | { |
a39ad5ce | 3179 | error ("No process. Run an inferior or specify an explicit pid."); |
35f5886e | 3180 | } |
a39ad5ce | 3181 | if (ioctl (pip -> fd, PIOCSTATUS, &(pip -> prstatus)) < 0) |
35f5886e | 3182 | { |
a39ad5ce FF |
3183 | print_sys_errmsg (pip -> pathname, errno); |
3184 | error ("PIOCSTATUS failed"); | |
35f5886e | 3185 | } |
a39ad5ce | 3186 | |
cc221e76 FF |
3187 | /* Print verbose information of the requested type(s), or just a summary |
3188 | of the information for all types. */ | |
3189 | ||
3190 | printf_filtered ("\nInformation for %s:\n\n", pip -> pathname); | |
3191 | if (summary || all || flags) | |
3192 | { | |
3193 | info_proc_flags (pip, summary); | |
3194 | } | |
3195 | if (summary || all) | |
3196 | { | |
3197 | info_proc_stop (pip, summary); | |
3198 | } | |
3199 | if (summary || all || signals || faults) | |
3200 | { | |
3201 | info_proc_siginfo (pip, summary); | |
3202 | } | |
3203 | if (summary || all || syscalls) | |
3204 | { | |
3205 | info_proc_syscalls (pip, summary); | |
3206 | } | |
3207 | if (summary || all || mappings) | |
3208 | { | |
3209 | info_proc_mappings (pip, summary); | |
3210 | } | |
3211 | if (summary || all || signals) | |
3212 | { | |
3213 | info_proc_signals (pip, summary); | |
3214 | } | |
3215 | if (summary || all || faults) | |
3216 | { | |
3217 | info_proc_faults (pip, summary); | |
3218 | } | |
3219 | printf_filtered ("\n"); | |
a39ad5ce FF |
3220 | |
3221 | /* All done, deal with closing any temporary process info structure, | |
3222 | freeing temporary memory , etc. */ | |
3223 | ||
3224 | do_cleanups (old_chain); | |
3225 | } | |
3226 | ||
3227 | /* | |
3228 | ||
3229 | GLOBAL FUNCTION | |
3230 | ||
3231 | _initialize_proc_fs -- initialize the process file system stuff | |
3232 | ||
3233 | SYNOPSIS | |
3234 | ||
3235 | void _initialize_proc_fs (void) | |
3236 | ||
3237 | DESCRIPTION | |
3238 | ||
3239 | Do required initializations during gdb startup for using the | |
3240 | /proc file system interface. | |
3241 | ||
3242 | */ | |
3243 | ||
3244 | static char *proc_desc = | |
cc221e76 FF |
3245 | "Show process status information using /proc entry.\n\ |
3246 | Specify process id or use current inferior by default.\n\ | |
3247 | Specify keywords for detailed information; default is summary.\n\ | |
3248 | Keywords are: `all', `faults', `flags', `id', `mappings', `signals',\n\ | |
3249 | `status', `syscalls', and `times'.\n\ | |
3250 | Unambiguous abbreviations may be used."; | |
a39ad5ce FF |
3251 | |
3252 | void | |
3253 | _initialize_proc_fs () | |
3254 | { | |
cc221e76 FF |
3255 | add_info ("proc", info_proc, proc_desc); |
3256 | init_syscall_table (); | |
35f5886e FF |
3257 | } |
3258 | ||
3259 | #endif /* USE_PROC_FS */ |