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