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