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.
5 This file is part of GDB.
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.
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.
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. */
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.
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.
37 #ifdef USE_PROC_FS /* Entire file goes away if not using /proc */
40 #include <sys/procfs.h>
48 #define MAX_SYSCALLS 256 /* Maximum number of syscalls for table */
51 #define PROC_NAME_FMT "/proc/%d"
54 #if 1 /* FIXME: Gross and ugly hack to resolve coredep.c global */
55 CORE_ADDR kernel_u_addr
;
58 #ifdef BROKEN_SIGINFO_H /* Workaround broken SGS <sys/siginfo.h> */
60 #define si_pid _data._proc.pid
62 #define si_uid _data._proc._pdata._kill.uid
63 #endif /* BROKEN_SIGINFO_H */
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. */
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 int nopass_next_sigstop
; /* Don't pass a sigstop on next resume */
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 */
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 */
96 static struct procinfo pi
; /* Inferior's process information */
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. */
104 int value
; /* The numeric value */
105 char *name
; /* The equivalent symbolic value */
106 char *desc
; /* Short description of value */
109 /* Translate bits in the pr_flags member of the prstatus structure, into the
110 names and desc information. */
112 static struct trans pr_flag_table
[] =
114 #if defined (PR_STOPPED)
115 PR_STOPPED
, "PR_STOPPED", "Process is stopped",
117 #if defined (PR_ISTOP)
118 PR_ISTOP
, "PR_ISTOP", "Stopped on an event of interest",
120 #if defined (PR_DSTOP)
121 PR_DSTOP
, "PR_DSTOP", "A stop directive is in effect",
123 #if defined (PR_ASLEEP)
124 PR_ASLEEP
, "PR_ASLEEP", "Sleeping in an interruptible system call",
126 #if defined (PR_FORK)
127 PR_FORK
, "PR_FORK", "Inherit-on-fork is in effect",
130 PR_RLC
, "PR_RLC", "Run-on-last-close is in effect",
132 #if defined (PR_PTRACE)
133 PR_PTRACE
, "PR_PTRACE", "Process is being controlled by ptrace",
135 #if defined (PR_PCINVAL)
136 PR_PCINVAL
, "PR_PCINVAL", "PC refers to an invalid virtual address",
138 #if defined (PR_ISSYS)
139 PR_ISSYS
, "PR_ISSYS", "Is a system process",
141 #if defined (PR_STEP)
142 PR_STEP
, "PR_STEP", "Process has single step pending",
145 PR_KLC
, "PR_KLC", "Kill-on-last-close is in effect",
147 #if defined (PR_ASYNC)
148 PR_ASYNC
, "PR_ASYNC", "Asynchronous stop is in effect",
150 #if defined (PR_PCOMPAT)
151 PR_PCOMPAT
, "PR_PCOMPAT", "Ptrace compatibility mode in effect",
156 /* Translate values in the pr_why field of the prstatus struct. */
158 static struct trans pr_why_table
[] =
160 #if defined (PR_REQUESTED)
161 PR_REQUESTED
, "PR_REQUESTED", "Directed to stop via PIOCSTOP/PIOCWSTOP",
163 #if defined (PR_SIGNALLED)
164 PR_SIGNALLED
, "PR_SIGNALLED", "Receipt of a traced signal",
166 #if defined (PR_FAULTED)
167 PR_FAULTED
, "PR_FAULTED", "Incurred a traced hardware fault",
169 #if defined (PR_SYSENTRY)
170 PR_SYSENTRY
, "PR_SYSENTRY", "Entry to a traced system call",
172 #if defined (PR_SYSEXIT)
173 PR_SYSEXIT
, "PR_SYSEXIT", "Exit from a traced system call",
175 #if defined (PR_JOBCONTROL)
176 PR_JOBCONTROL
, "PR_JOBCONTROL", "Default job control stop signal action",
178 #if defined (PR_SUSPENDED)
179 PR_SUSPENDED
, "PR_SUSPENDED", "Process suspended",
184 /* Hardware fault translation table. */
186 static struct trans faults_table
[] =
189 FLTILL
, "FLTILL", "Illegal instruction",
191 #if defined (FLTPRIV)
192 FLTPRIV
, "FLTPRIV", "Privileged instruction",
195 FLTBPT
, "FLTBPT", "Breakpoint trap",
197 #if defined (FLTTRACE)
198 FLTTRACE
, "FLTTRACE", "Trace trap",
200 #if defined (FLTACCESS)
201 FLTACCESS
, "FLTACCESS", "Memory access fault",
203 #if defined (FLTBOUNDS)
204 FLTBOUNDS
, "FLTBOUNDS", "Memory bounds violation",
206 #if defined (FLTIOVF)
207 FLTIOVF
, "FLTIOVF", "Integer overflow",
209 #if defined (FLTIZDIV)
210 FLTIZDIV
, "FLTIZDIV", "Integer zero divide",
213 FLTFPE
, "FLTFPE", "Floating-point exception",
215 #if defined (FLTSTACK)
216 FLTSTACK
, "FLTSTACK", "Unrecoverable stack fault",
218 #if defined (FLTPAGE)
219 FLTPAGE
, "FLTPAGE", "Recoverable page fault",
224 /* Translation table for signal generation information. See UNIX System
225 V Release 4 Programmer's Reference Manual, siginfo(5). */
227 static struct sigcode
{
232 } siginfo_table
[] = {
233 #if defined (SIGILL) && defined (ILL_ILLOPC)
234 SIGILL
, ILL_ILLOPC
, "ILL_ILLOPC", "Illegal opcode",
236 #if defined (SIGILL) && defined (ILL_ILLOPN)
237 SIGILL
, ILL_ILLOPN
, "ILL_ILLOPN", "Illegal operand",
239 #if defined (SIGILL) && defined (ILL_ILLADR)
240 SIGILL
, ILL_ILLADR
, "ILL_ILLADR", "Illegal addressing mode",
242 #if defined (SIGILL) && defined (ILL_ILLTRP)
243 SIGILL
, ILL_ILLTRP
, "ILL_ILLTRP", "Illegal trap",
245 #if defined (SIGILL) && defined (ILL_PRVOPC)
246 SIGILL
, ILL_PRVOPC
, "ILL_PRVOPC", "Privileged opcode",
248 #if defined (SIGILL) && defined (ILL_PRVREG)
249 SIGILL
, ILL_PRVREG
, "ILL_PRVREG", "Privileged register",
251 #if defined (SIGILL) && defined (ILL_COPROC)
252 SIGILL
, ILL_COPROC
, "ILL_COPROC", "Coprocessor error",
254 #if defined (SIGILL) && defined (ILL_BADSTK)
255 SIGILL
, ILL_BADSTK
, "ILL_BADSTK", "Internal stack error",
257 #if defined (SIGFPE) && defined (FPE_INTDIV)
258 SIGFPE
, FPE_INTDIV
, "FPE_INTDIV", "Integer divide by zero",
260 #if defined (SIGFPE) && defined (FPE_INTOVF)
261 SIGFPE
, FPE_INTOVF
, "FPE_INTOVF", "Integer overflow",
263 #if defined (SIGFPE) && defined (FPE_FLTDIV)
264 SIGFPE
, FPE_FLTDIV
, "FPE_FLTDIV", "Floating point divide by zero",
266 #if defined (SIGFPE) && defined (FPE_FLTOVF)
267 SIGFPE
, FPE_FLTOVF
, "FPE_FLTOVF", "Floating point overflow",
269 #if defined (SIGFPE) && defined (FPE_FLTUND)
270 SIGFPE
, FPE_FLTUND
, "FPE_FLTUND", "Floating point underflow",
272 #if defined (SIGFPE) && defined (FPE_FLTRES)
273 SIGFPE
, FPE_FLTRES
, "FPE_FLTRES", "Floating point inexact result",
275 #if defined (SIGFPE) && defined (FPE_FLTINV)
276 SIGFPE
, FPE_FLTINV
, "FPE_FLTINV", "Invalid floating point operation",
278 #if defined (SIGFPE) && defined (FPE_FLTSUB)
279 SIGFPE
, FPE_FLTSUB
, "FPE_FLTSUB", "Subscript out of range",
281 #if defined (SIGSEGV) && defined (SEGV_MAPERR)
282 SIGSEGV
, SEGV_MAPERR
, "SEGV_MAPERR", "Address not mapped to object",
284 #if defined (SIGSEGV) && defined (SEGV_ACCERR)
285 SIGSEGV
, SEGV_ACCERR
, "SEGV_ACCERR", "Invalid permissions for object",
287 #if defined (SIGBUS) && defined (BUS_ADRALN)
288 SIGBUS
, BUS_ADRALN
, "BUS_ADRALN", "Invalid address alignment",
290 #if defined (SIGBUS) && defined (BUS_ADRERR)
291 SIGBUS
, BUS_ADRERR
, "BUS_ADRERR", "Non-existent physical address",
293 #if defined (SIGBUS) && defined (BUS_OBJERR)
294 SIGBUS
, BUS_OBJERR
, "BUS_OBJERR", "Object specific hardware error",
296 #if defined (SIGTRAP) && defined (TRAP_BRKPT)
297 SIGTRAP
, TRAP_BRKPT
, "TRAP_BRKPT", "Process breakpoint",
299 #if defined (SIGTRAP) && defined (TRAP_TRACE)
300 SIGTRAP
, TRAP_TRACE
, "TRAP_TRACE", "Process trace trap",
302 #if defined (SIGCLD) && defined (CLD_EXITED)
303 SIGCLD
, CLD_EXITED
, "CLD_EXITED", "Child has exited",
305 #if defined (SIGCLD) && defined (CLD_KILLED)
306 SIGCLD
, CLD_KILLED
, "CLD_KILLED", "Child was killed",
308 #if defined (SIGCLD) && defined (CLD_DUMPED)
309 SIGCLD
, CLD_DUMPED
, "CLD_DUMPED", "Child has terminated abnormally",
311 #if defined (SIGCLD) && defined (CLD_TRAPPED)
312 SIGCLD
, CLD_TRAPPED
, "CLD_TRAPPED", "Traced child has trapped",
314 #if defined (SIGCLD) && defined (CLD_STOPPED)
315 SIGCLD
, CLD_STOPPED
, "CLD_STOPPED", "Child has stopped",
317 #if defined (SIGCLD) && defined (CLD_CONTINUED)
318 SIGCLD
, CLD_CONTINUED
, "CLD_CONTINUED", "Stopped child had continued",
320 #if defined (SIGPOLL) && defined (POLL_IN)
321 SIGPOLL
, POLL_IN
, "POLL_IN", "Input input available",
323 #if defined (SIGPOLL) && defined (POLL_OUT)
324 SIGPOLL
, POLL_OUT
, "POLL_OUT", "Output buffers available",
326 #if defined (SIGPOLL) && defined (POLL_MSG)
327 SIGPOLL
, POLL_MSG
, "POLL_MSG", "Input message available",
329 #if defined (SIGPOLL) && defined (POLL_ERR)
330 SIGPOLL
, POLL_ERR
, "POLL_ERR", "I/O error",
332 #if defined (SIGPOLL) && defined (POLL_PRI)
333 SIGPOLL
, POLL_PRI
, "POLL_PRI", "High priority input available",
335 #if defined (SIGPOLL) && defined (POLL_HUP)
336 SIGPOLL
, POLL_HUP
, "POLL_HUP", "Device disconnected",
341 /* Translation table for errno values. See intro(2) in most UNIX systems
342 Programmers Reference Manuals.
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.
350 static struct trans errno_table
[] =
353 EPERM
, "EPERM", "Not super-user",
356 ENOENT
, "ENOENT", "No such file or directory",
359 ESRCH
, "ESRCH", "No such process",
362 EINTR
, "EINTR", "Interrupted system call",
365 EIO
, "EIO", "I/O error",
368 ENXIO
, "ENXIO", "No such device or address",
371 E2BIG
, "E2BIG", "Arg list too long",
373 #if defined (ENOEXEC)
374 ENOEXEC
, "ENOEXEC", "Exec format error",
377 EBADF
, "EBADF", "Bad file number",
380 ECHILD
, "ECHILD", "No child process",
383 EAGAIN
, "EAGAIN", "No more processes",
386 ENOMEM
, "ENOMEM", "Not enough space",
389 EACCES
, "EACCES", "Permission denied",
392 EFAULT
, "EFAULT", "Bad address",
394 #if defined (ENOTBLK)
395 ENOTBLK
, "ENOTBLK", "Block device required",
398 EBUSY
, "EBUSY", "Device busy",
401 EEXIST
, "EEXIST", "File exists",
404 EXDEV
, "EXDEV", "Cross-device link",
407 ENODEV
, "ENODEV", "No such device",
409 #if defined (ENOTDIR)
410 ENOTDIR
, "ENOTDIR", "Not a directory",
413 EISDIR
, "EISDIR", "Is a directory",
416 EINVAL
, "EINVAL", "Invalid argument",
419 ENFILE
, "ENFILE", "File table overflow",
422 EMFILE
, "EMFILE", "Too many open files",
425 ENOTTY
, "ENOTTY", "Not a typewriter",
427 #if defined (ETXTBSY)
428 ETXTBSY
, "ETXTBSY", "Text file busy",
431 EFBIG
, "EFBIG", "File too large",
434 ENOSPC
, "ENOSPC", "No space left on device",
437 ESPIPE
, "ESPIPE", "Illegal seek",
440 EROFS
, "EROFS", "Read only file system",
443 EMLINK
, "EMLINK", "Too many links",
446 EPIPE
, "EPIPE", "Broken pipe",
449 EDOM
, "EDOM", "Math argument out of domain of func",
452 ERANGE
, "ERANGE", "Math result not representable",
455 ENOMSG
, "ENOMSG", "No message of desired type",
458 EIDRM
, "EIDRM", "Identifier removed",
461 ECHRNG
, "ECHRNG", "Channel number out of range",
463 #if defined (EL2NSYNC)
464 EL2NSYNC
, "EL2NSYNC", "Level 2 not synchronized",
467 EL3HLT
, "EL3HLT", "Level 3 halted",
470 EL3RST
, "EL3RST", "Level 3 reset",
473 ELNRNG
, "ELNRNG", "Link number out of range",
475 #if defined (EUNATCH)
476 EUNATCH
, "EUNATCH", "Protocol driver not attached",
479 ENOCSI
, "ENOCSI", "No CSI structure available",
482 EL2HLT
, "EL2HLT", "Level 2 halted",
484 #if defined (EDEADLK)
485 EDEADLK
, "EDEADLK", "Deadlock condition",
488 ENOLCK
, "ENOLCK", "No record locks available",
491 EBADE
, "EBADE", "Invalid exchange",
494 EBADR
, "EBADR", "Invalid request descriptor",
497 EXFULL
, "EXFULL", "Exchange full",
500 ENOANO
, "ENOANO", "No anode",
502 #if defined (EBADRQC)
503 EBADRQC
, "EBADRQC", "Invalid request code",
505 #if defined (EBADSLT)
506 EBADSLT
, "EBADSLT", "Invalid slot",
508 #if defined (EDEADLOCK)
509 EDEADLOCK
, "EDEADLOCK", "File locking deadlock error",
512 EBFONT
, "EBFONT", "Bad font file fmt",
515 ENOSTR
, "ENOSTR", "Device not a stream",
517 #if defined (ENODATA)
518 ENODATA
, "ENODATA", "No data available",
521 ETIME
, "ETIME", "Timer expired",
524 ENOSR
, "ENOSR", "Out of streams resources",
527 ENONET
, "ENONET", "Machine is not on the network",
530 ENOPKG
, "ENOPKG", "Package not installed",
532 #if defined (EREMOTE)
533 EREMOTE
, "EREMOTE", "Object is remote",
535 #if defined (ENOLINK)
536 ENOLINK
, "ENOLINK", "Link has been severed",
539 EADV
, "EADV", "Advertise error",
542 ESRMNT
, "ESRMNT", "Srmount error",
545 ECOMM
, "ECOMM", "Communication error on send",
548 EPROTO
, "EPROTO", "Protocol error",
550 #if defined (EMULTIHOP)
551 EMULTIHOP
, "EMULTIHOP", "Multihop attempted",
553 #if defined (EDOTDOT)
554 EDOTDOT
, "EDOTDOT", "RFS specific error",
556 #if defined (EBADMSG)
557 EBADMSG
, "EBADMSG", "Not a data message",
559 #if defined (ENAMETOOLONG)
560 ENAMETOOLONG
, "ENAMETOOLONG", "File name too long",
562 #if defined (EOVERFLOW)
563 EOVERFLOW
, "EOVERFLOW", "Value too large for defined data type",
565 #if defined (ENOTUNIQ)
566 ENOTUNIQ
, "ENOTUNIQ", "Name not unique on network",
569 EBADFD
, "EBADFD", "File descriptor in bad state",
571 #if defined (EREMCHG)
572 EREMCHG
, "EREMCHG", "Remote address changed",
574 #if defined (ELIBACC)
575 ELIBACC
, "ELIBACC", "Cannot access a needed shared library",
577 #if defined (ELIBBAD)
578 ELIBBAD
, "ELIBBAD", "Accessing a corrupted shared library",
580 #if defined (ELIBSCN)
581 ELIBSCN
, "ELIBSCN", ".lib section in a.out corrupted",
583 #if defined (ELIBMAX)
584 ELIBMAX
, "ELIBMAX", "Attempting to link in too many shared libraries",
586 #if defined (ELIBEXEC)
587 ELIBEXEC
, "ELIBEXEC", "Cannot exec a shared library directly",
590 EILSEQ
, "EILSEQ", "Illegal byte sequence",
593 ENOSYS
, "ENOSYS", "Operation not applicable",
596 ELOOP
, "ELOOP", "Too many symbolic links encountered",
598 #if defined (ERESTART)
599 ERESTART
, "ERESTART", "Interrupted system call should be restarted",
601 #if defined (ESTRPIPE)
602 ESTRPIPE
, "ESTRPIPE", "Streams pipe error",
604 #if defined (ENOTEMPTY)
605 ENOTEMPTY
, "ENOTEMPTY", "Directory not empty",
608 EUSERS
, "EUSERS", "Too many users",
610 #if defined (ENOTSOCK)
611 ENOTSOCK
, "ENOTSOCK", "Socket operation on non-socket",
613 #if defined (EDESTADDRREQ)
614 EDESTADDRREQ
, "EDESTADDRREQ", "Destination address required",
616 #if defined (EMSGSIZE)
617 EMSGSIZE
, "EMSGSIZE", "Message too long",
619 #if defined (EPROTOTYPE)
620 EPROTOTYPE
, "EPROTOTYPE", "Protocol wrong type for socket",
622 #if defined (ENOPROTOOPT)
623 ENOPROTOOPT
, "ENOPROTOOPT", "Protocol not available",
625 #if defined (EPROTONOSUPPORT)
626 EPROTONOSUPPORT
, "EPROTONOSUPPORT", "Protocol not supported",
628 #if defined (ESOCKTNOSUPPORT)
629 ESOCKTNOSUPPORT
, "ESOCKTNOSUPPORT", "Socket type not supported",
631 #if defined (EOPNOTSUPP)
632 EOPNOTSUPP
, "EOPNOTSUPP", "Operation not supported on transport endpoint ",
634 #if defined (EPFNOSUPPORT)
635 EPFNOSUPPORT
, "EPFNOSUPPORT", "Protocol family not supported",
637 #if defined (EAFNOSUPPORT)
638 EAFNOSUPPORT
, "EAFNOSUPPORT", "Address family not supported by protocol",
640 #if defined (EADDRINUSE)
641 EADDRINUSE
, "EADDRINUSE", "Address already in use",
643 #if defined (EADDRNOTAVAIL)
644 EADDRNOTAVAIL
, "EADDRNOTAVAIL","Cannot assign requested address",
646 #if defined (ENETDOWN)
647 ENETDOWN
, "ENETDOWN", "Network is down",
649 #if defined (ENETUNREACH)
650 ENETUNREACH
, "ENETUNREACH", "Network is unreachable",
652 #if defined (ENETRESET)
653 ENETRESET
, "ENETRESET", "Network dropped connection because of reset",
655 #if defined (ECONNABORTED)
656 ECONNABORTED
, "ECONNABORTED", "Software caused connection abort",
658 #if defined (ECONNRESET)
659 ECONNRESET
, "ECONNRESET", "Connection reset by peer",
661 #if defined (ENOBUFS)
662 ENOBUFS
, "ENOBUFS", "No buffer space available",
664 #if defined (EISCONN)
665 EISCONN
, "EISCONN", "Transport endpoint is already connected",
667 #if defined (ENOTCONN)
668 ENOTCONN
, "ENOTCONN", "Transport endpoint is not connected",
670 #if defined (ESHUTDOWN)
671 ESHUTDOWN
, "ESHUTDOWN", "Cannot send after transport endpoint shutdown",
673 #if defined (ETOOMANYREFS)
674 ETOOMANYREFS
, "ETOOMANYREFS", "Too many references: cannot splice",
676 #if defined (ETIMEDOUT)
677 ETIMEDOUT
, "ETIMEDOUT", "Connection timed out",
679 #if defined (ECONNREFUSED)
680 ECONNREFUSED
, "ECONNREFUSED", "Connection refused",
682 #if defined (EHOSTDOWN)
683 EHOSTDOWN
, "EHOSTDOWN", "Host is down",
685 #if defined (EHOSTUNREACH)
686 EHOSTUNREACH
, "EHOSTUNREACH", "No route to host",
688 #if defined (EWOULDBLOCK)
689 EWOULDBLOCK
, "EWOULDBLOCK", "Operation already in progress",
691 #if defined (EINPROGRESS)
692 EINPROGRESS
, "EINPROGRESS", "Operation now in progress",
695 ESTALE
, "ESTALE", "Stale NFS file handle",
697 #if defined (EUCLEAN)
698 EUCLEAN
, "EUCLEAN", "Structure needs cleaning",
700 #if defined (ENOTNAM)
701 ENOTNAM
, "ENOTNAM", "Not a XENIX named type file",
703 #if defined (ENAVAIL)
704 ENAVAIL
, "ENAVAIL", "No XENIX semaphores available",
707 EISNAM
, "EISNAM", "Is a named type file",
709 #if defined (EREMOTEIO)
710 EREMOTEIO
, "EREMOTEIO", "Remote I/O error",
715 static char *syscall_table
[MAX_SYSCALLS
];
717 /* Prototypes for local functions */
720 set_proc_siginfo
PARAMS ((struct procinfo
*, int));
723 init_syscall_table
PARAMS ((void));
726 syscallname
PARAMS ((int));
729 signalname
PARAMS ((int));
732 proc_address_to_fd
PARAMS ((CORE_ADDR
, int));
735 open_proc_file
PARAMS ((int, struct procinfo
*));
738 close_proc_file
PARAMS ((struct procinfo
*));
741 unconditionally_kill_inferior
PARAMS ((void));
744 proc_init_failed
PARAMS ((char *));
747 info_proc
PARAMS ((char *, int));
750 info_proc_flags
PARAMS ((struct procinfo
*, int));
753 info_proc_stop
PARAMS ((struct procinfo
*, int));
756 info_proc_siginfo
PARAMS ((struct procinfo
*, int));
759 info_proc_syscalls
PARAMS ((struct procinfo
*, int));
762 info_proc_mappings
PARAMS ((struct procinfo
*, int));
765 info_proc_signals
PARAMS ((struct procinfo
*, int));
768 info_proc_faults
PARAMS ((struct procinfo
*, int));
771 mappingflags
PARAMS ((long));
774 lookupname
PARAMS ((struct trans
*, unsigned int, char *));
777 lookupdesc
PARAMS ((struct trans
*, unsigned int));
779 /* External function prototypes that can't be easily included in any
780 header file because the args are typedefs in system include files. */
783 supply_gregset
PARAMS ((gregset_t
*));
786 fill_gregset
PARAMS ((gregset_t
*, int));
789 supply_fpregset
PARAMS ((fpregset_t
*));
792 fill_fpregset
PARAMS ((fpregset_t
*, int));
798 lookupdesc -- translate a value to a summary desc string
802 static char *lookupdesc (struct trans *transp, unsigned int val);
806 Given a pointer to a translation table and a value to be translated,
807 lookup the desc string and return it.
811 lookupdesc (transp
, val
)
812 struct trans
*transp
;
817 for (desc
= NULL
; transp
-> name
!= NULL
; transp
++)
819 if (transp
-> value
== val
)
821 desc
= transp
-> desc
;
826 /* Didn't find a translation for the specified value, set a default one. */
839 lookupname -- translate a value to symbolic name
843 static char *lookupname (struct trans *transp, unsigned int val,
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.
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
859 lookupname (transp
, val
, prefix
)
860 struct trans
*transp
;
867 for (name
= NULL
; transp
-> name
!= NULL
; transp
++)
869 if (transp
-> value
== val
)
871 name
= transp
-> name
;
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. */
886 locbuf
= xmalloc (strlen (prefix
) + 16);
887 (void) sprintf (locbuf
, "%s %u", prefix
, val
);
899 static char locbuf
[32];
901 for (scp
= siginfo_table
; scp
-> codename
!= NULL
; scp
++)
903 if ((scp
-> signo
== sip
-> si_signo
) &&
904 (scp
-> code
== sip
-> si_code
))
906 name
= scp
-> codename
;
912 (void) sprintf (locbuf
, "sigcode %u", sip
-> si_signo
);
918 static char *sigcodedesc (sip
)
924 for (scp
= siginfo_table
; scp
-> codename
!= NULL
; scp
++)
926 if ((scp
-> signo
== sip
-> si_signo
) &&
927 (scp
-> code
== sip
-> si_code
))
935 desc
= "Unrecognized signal or trap use";
944 syscallname - translate a system call number into a system call name
948 char *syscallname (int syscallnum)
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
958 syscallname (syscallnum
)
961 static char locbuf
[32];
964 if (syscallnum
>= 0 && syscallnum
< MAX_SYSCALLS
)
966 rtnval
= syscall_table
[syscallnum
];
970 (void) sprintf (locbuf
, "syscall %u", syscallnum
);
980 init_syscall_table - initialize syscall translation table
984 void init_syscall_table (void)
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.
994 This is awfully ugly, but preprocessor tricks to make it prettier
995 tend to be nonportable.
999 init_syscall_table ()
1003 #if defined (SYS_exit)
1004 syscall_table
[SYS_exit
] = "exit";
1006 #if defined (SYS_fork)
1007 syscall_table
[SYS_fork
] = "fork";
1009 #if defined (SYS_read)
1010 syscall_table
[SYS_read
] = "read";
1012 #if defined (SYS_write)
1013 syscall_table
[SYS_write
] = "write";
1015 #if defined (SYS_open)
1016 syscall_table
[SYS_open
] = "open";
1018 #if defined (SYS_close)
1019 syscall_table
[SYS_close
] = "close";
1021 #if defined (SYS_wait)
1022 syscall_table
[SYS_wait
] = "wait";
1024 #if defined (SYS_creat)
1025 syscall_table
[SYS_creat
] = "creat";
1027 #if defined (SYS_link)
1028 syscall_table
[SYS_link
] = "link";
1030 #if defined (SYS_unlink)
1031 syscall_table
[SYS_unlink
] = "unlink";
1033 #if defined (SYS_exec)
1034 syscall_table
[SYS_exec
] = "exec";
1036 #if defined (SYS_execv)
1037 syscall_table
[SYS_execv
] = "execv";
1039 #if defined (SYS_execve)
1040 syscall_table
[SYS_execve
] = "execve";
1042 #if defined (SYS_chdir)
1043 syscall_table
[SYS_chdir
] = "chdir";
1045 #if defined (SYS_time)
1046 syscall_table
[SYS_time
] = "time";
1048 #if defined (SYS_mknod)
1049 syscall_table
[SYS_mknod
] = "mknod";
1051 #if defined (SYS_chmod)
1052 syscall_table
[SYS_chmod
] = "chmod";
1054 #if defined (SYS_chown)
1055 syscall_table
[SYS_chown
] = "chown";
1057 #if defined (SYS_brk)
1058 syscall_table
[SYS_brk
] = "brk";
1060 #if defined (SYS_stat)
1061 syscall_table
[SYS_stat
] = "stat";
1063 #if defined (SYS_lseek)
1064 syscall_table
[SYS_lseek
] = "lseek";
1066 #if defined (SYS_getpid)
1067 syscall_table
[SYS_getpid
] = "getpid";
1069 #if defined (SYS_mount)
1070 syscall_table
[SYS_mount
] = "mount";
1072 #if defined (SYS_umount)
1073 syscall_table
[SYS_umount
] = "umount";
1075 #if defined (SYS_setuid)
1076 syscall_table
[SYS_setuid
] = "setuid";
1078 #if defined (SYS_getuid)
1079 syscall_table
[SYS_getuid
] = "getuid";
1081 #if defined (SYS_stime)
1082 syscall_table
[SYS_stime
] = "stime";
1084 #if defined (SYS_ptrace)
1085 syscall_table
[SYS_ptrace
] = "ptrace";
1087 #if defined (SYS_alarm)
1088 syscall_table
[SYS_alarm
] = "alarm";
1090 #if defined (SYS_fstat)
1091 syscall_table
[SYS_fstat
] = "fstat";
1093 #if defined (SYS_pause)
1094 syscall_table
[SYS_pause
] = "pause";
1096 #if defined (SYS_utime)
1097 syscall_table
[SYS_utime
] = "utime";
1099 #if defined (SYS_stty)
1100 syscall_table
[SYS_stty
] = "stty";
1102 #if defined (SYS_gtty)
1103 syscall_table
[SYS_gtty
] = "gtty";
1105 #if defined (SYS_access)
1106 syscall_table
[SYS_access
] = "access";
1108 #if defined (SYS_nice)
1109 syscall_table
[SYS_nice
] = "nice";
1111 #if defined (SYS_statfs)
1112 syscall_table
[SYS_statfs
] = "statfs";
1114 #if defined (SYS_sync)
1115 syscall_table
[SYS_sync
] = "sync";
1117 #if defined (SYS_kill)
1118 syscall_table
[SYS_kill
] = "kill";
1120 #if defined (SYS_fstatfs)
1121 syscall_table
[SYS_fstatfs
] = "fstatfs";
1123 #if defined (SYS_pgrpsys)
1124 syscall_table
[SYS_pgrpsys
] = "pgrpsys";
1126 #if defined (SYS_xenix)
1127 syscall_table
[SYS_xenix
] = "xenix";
1129 #if defined (SYS_dup)
1130 syscall_table
[SYS_dup
] = "dup";
1132 #if defined (SYS_pipe)
1133 syscall_table
[SYS_pipe
] = "pipe";
1135 #if defined (SYS_times)
1136 syscall_table
[SYS_times
] = "times";
1138 #if defined (SYS_profil)
1139 syscall_table
[SYS_profil
] = "profil";
1141 #if defined (SYS_plock)
1142 syscall_table
[SYS_plock
] = "plock";
1144 #if defined (SYS_setgid)
1145 syscall_table
[SYS_setgid
] = "setgid";
1147 #if defined (SYS_getgid)
1148 syscall_table
[SYS_getgid
] = "getgid";
1150 #if defined (SYS_signal)
1151 syscall_table
[SYS_signal
] = "signal";
1153 #if defined (SYS_msgsys)
1154 syscall_table
[SYS_msgsys
] = "msgsys";
1156 #if defined (SYS_sys3b)
1157 syscall_table
[SYS_sys3b
] = "sys3b";
1159 #if defined (SYS_acct)
1160 syscall_table
[SYS_acct
] = "acct";
1162 #if defined (SYS_shmsys)
1163 syscall_table
[SYS_shmsys
] = "shmsys";
1165 #if defined (SYS_semsys)
1166 syscall_table
[SYS_semsys
] = "semsys";
1168 #if defined (SYS_ioctl)
1169 syscall_table
[SYS_ioctl
] = "ioctl";
1171 #if defined (SYS_uadmin)
1172 syscall_table
[SYS_uadmin
] = "uadmin";
1174 #if defined (SYS_utssys)
1175 syscall_table
[SYS_utssys
] = "utssys";
1177 #if defined (SYS_fsync)
1178 syscall_table
[SYS_fsync
] = "fsync";
1180 #if defined (SYS_umask)
1181 syscall_table
[SYS_umask
] = "umask";
1183 #if defined (SYS_chroot)
1184 syscall_table
[SYS_chroot
] = "chroot";
1186 #if defined (SYS_fcntl)
1187 syscall_table
[SYS_fcntl
] = "fcntl";
1189 #if defined (SYS_ulimit)
1190 syscall_table
[SYS_ulimit
] = "ulimit";
1192 #if defined (SYS_rfsys)
1193 syscall_table
[SYS_rfsys
] = "rfsys";
1195 #if defined (SYS_rmdir)
1196 syscall_table
[SYS_rmdir
] = "rmdir";
1198 #if defined (SYS_mkdir)
1199 syscall_table
[SYS_mkdir
] = "mkdir";
1201 #if defined (SYS_getdents)
1202 syscall_table
[SYS_getdents
] = "getdents";
1204 #if defined (SYS_sysfs)
1205 syscall_table
[SYS_sysfs
] = "sysfs";
1207 #if defined (SYS_getmsg)
1208 syscall_table
[SYS_getmsg
] = "getmsg";
1210 #if defined (SYS_putmsg)
1211 syscall_table
[SYS_putmsg
] = "putmsg";
1213 #if defined (SYS_poll)
1214 syscall_table
[SYS_poll
] = "poll";
1216 #if defined (SYS_lstat)
1217 syscall_table
[SYS_lstat
] = "lstat";
1219 #if defined (SYS_symlink)
1220 syscall_table
[SYS_symlink
] = "symlink";
1222 #if defined (SYS_readlink)
1223 syscall_table
[SYS_readlink
] = "readlink";
1225 #if defined (SYS_setgroups)
1226 syscall_table
[SYS_setgroups
] = "setgroups";
1228 #if defined (SYS_getgroups)
1229 syscall_table
[SYS_getgroups
] = "getgroups";
1231 #if defined (SYS_fchmod)
1232 syscall_table
[SYS_fchmod
] = "fchmod";
1234 #if defined (SYS_fchown)
1235 syscall_table
[SYS_fchown
] = "fchown";
1237 #if defined (SYS_sigprocmask)
1238 syscall_table
[SYS_sigprocmask
] = "sigprocmask";
1240 #if defined (SYS_sigsuspend)
1241 syscall_table
[SYS_sigsuspend
] = "sigsuspend";
1243 #if defined (SYS_sigaltstack)
1244 syscall_table
[SYS_sigaltstack
] = "sigaltstack";
1246 #if defined (SYS_sigaction)
1247 syscall_table
[SYS_sigaction
] = "sigaction";
1249 #if defined (SYS_sigpending)
1250 syscall_table
[SYS_sigpending
] = "sigpending";
1252 #if defined (SYS_context)
1253 syscall_table
[SYS_context
] = "context";
1255 #if defined (SYS_evsys)
1256 syscall_table
[SYS_evsys
] = "evsys";
1258 #if defined (SYS_evtrapret)
1259 syscall_table
[SYS_evtrapret
] = "evtrapret";
1261 #if defined (SYS_statvfs)
1262 syscall_table
[SYS_statvfs
] = "statvfs";
1264 #if defined (SYS_fstatvfs)
1265 syscall_table
[SYS_fstatvfs
] = "fstatvfs";
1267 #if defined (SYS_nfssys)
1268 syscall_table
[SYS_nfssys
] = "nfssys";
1270 #if defined (SYS_waitsys)
1271 syscall_table
[SYS_waitsys
] = "waitsys";
1273 #if defined (SYS_sigsendsys)
1274 syscall_table
[SYS_sigsendsys
] = "sigsendsys";
1276 #if defined (SYS_hrtsys)
1277 syscall_table
[SYS_hrtsys
] = "hrtsys";
1279 #if defined (SYS_acancel)
1280 syscall_table
[SYS_acancel
] = "acancel";
1282 #if defined (SYS_async)
1283 syscall_table
[SYS_async
] = "async";
1285 #if defined (SYS_priocntlsys)
1286 syscall_table
[SYS_priocntlsys
] = "priocntlsys";
1288 #if defined (SYS_pathconf)
1289 syscall_table
[SYS_pathconf
] = "pathconf";
1291 #if defined (SYS_mincore)
1292 syscall_table
[SYS_mincore
] = "mincore";
1294 #if defined (SYS_mmap)
1295 syscall_table
[SYS_mmap
] = "mmap";
1297 #if defined (SYS_mprotect)
1298 syscall_table
[SYS_mprotect
] = "mprotect";
1300 #if defined (SYS_munmap)
1301 syscall_table
[SYS_munmap
] = "munmap";
1303 #if defined (SYS_fpathconf)
1304 syscall_table
[SYS_fpathconf
] = "fpathconf";
1306 #if defined (SYS_vfork)
1307 syscall_table
[SYS_vfork
] = "vfork";
1309 #if defined (SYS_fchdir)
1310 syscall_table
[SYS_fchdir
] = "fchdir";
1312 #if defined (SYS_readv)
1313 syscall_table
[SYS_readv
] = "readv";
1315 #if defined (SYS_writev)
1316 syscall_table
[SYS_writev
] = "writev";
1318 #if defined (SYS_xstat)
1319 syscall_table
[SYS_xstat
] = "xstat";
1321 #if defined (SYS_lxstat)
1322 syscall_table
[SYS_lxstat
] = "lxstat";
1324 #if defined (SYS_fxstat)
1325 syscall_table
[SYS_fxstat
] = "fxstat";
1327 #if defined (SYS_xmknod)
1328 syscall_table
[SYS_xmknod
] = "xmknod";
1330 #if defined (SYS_clocal)
1331 syscall_table
[SYS_clocal
] = "clocal";
1333 #if defined (SYS_setrlimit)
1334 syscall_table
[SYS_setrlimit
] = "setrlimit";
1336 #if defined (SYS_getrlimit)
1337 syscall_table
[SYS_getrlimit
] = "getrlimit";
1339 #if defined (SYS_lchown)
1340 syscall_table
[SYS_lchown
] = "lchown";
1342 #if defined (SYS_memcntl)
1343 syscall_table
[SYS_memcntl
] = "memcntl";
1345 #if defined (SYS_getpmsg)
1346 syscall_table
[SYS_getpmsg
] = "getpmsg";
1348 #if defined (SYS_putpmsg)
1349 syscall_table
[SYS_putpmsg
] = "putpmsg";
1351 #if defined (SYS_rename)
1352 syscall_table
[SYS_rename
] = "rename";
1354 #if defined (SYS_uname)
1355 syscall_table
[SYS_uname
] = "uname";
1357 #if defined (SYS_setegid)
1358 syscall_table
[SYS_setegid
] = "setegid";
1360 #if defined (SYS_sysconfig)
1361 syscall_table
[SYS_sysconfig
] = "sysconfig";
1363 #if defined (SYS_adjtime)
1364 syscall_table
[SYS_adjtime
] = "adjtime";
1366 #if defined (SYS_systeminfo)
1367 syscall_table
[SYS_systeminfo
] = "systeminfo";
1369 #if defined (SYS_seteuid)
1370 syscall_table
[SYS_seteuid
] = "seteuid";
1378 ptrace -- override library version to force errors for /proc version
1382 int ptrace (int request, int pid, int arg3, int arg4)
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.
1394 ptrace (request
, pid
, arg3
, arg4
)
1400 error ("internal error - there is a call to ptrace() somewhere");
1408 kill_inferior_fast -- kill inferior while gdb is exiting
1412 void kill_inferior_fast (void)
1416 This is used when GDB is exiting. It gives less chance of error.
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.
1429 kill_inferior_fast ()
1431 if (inferior_pid
!= 0 && !attach_flag
)
1433 unconditionally_kill_inferior ();
1441 kill_inferior - kill any currently inferior
1445 void kill_inferior (void)
1449 Kill any current inferior.
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?)
1462 if (inferior_pid
!= 0)
1464 unconditionally_kill_inferior ();
1465 target_mourn_inferior ();
1473 unconditionally_kill_inferior - terminate the inferior
1477 static void unconditionally_kill_inferior (void)
1481 Kill the current inferior. Should not be called until it
1482 is at least tested that there is an inferior.
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.
1493 unconditionally_kill_inferior ()
1498 (void) ioctl (pi
.fd
, PIOCKILL
, &signo
);
1499 close_proc_file (&pi
);
1507 child_xfer_memory -- copy data to or from inferior memory space
1511 int child_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len,
1512 int dowrite, struct target_ops target)
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.
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
1527 The /proc interface makes this an almost trivial task.
1532 child_xfer_memory (memaddr
, myaddr
, len
, dowrite
, target
)
1537 struct target_ops
*target
; /* ignored */
1541 if (lseek (pi
.fd
, (off_t
) memaddr
, 0) == (off_t
) memaddr
)
1545 nbytes
= write (pi
.fd
, myaddr
, len
);
1549 nbytes
= read (pi
.fd
, myaddr
, len
);
1563 store_inferior_registers -- copy register values back to inferior
1567 void store_inferior_registers (int regno)
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.
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
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.
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)
1598 store_inferior_registers (regno
)
1603 (void) ioctl (pi
.fd
, PIOCGREG
, &pi
.gregset
);
1605 fill_gregset (&pi
.gregset
, regno
);
1606 (void) ioctl (pi
.fd
, PIOCSREG
, &pi
.gregset
);
1608 #if defined (FP0_REGNUM)
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. */
1616 (void) ioctl (pi
.fd
, PIOCGFPREG
, &pi
.fpregset
);
1618 fill_fpregset (&pi
.fpregset
, regno
);
1619 (void) ioctl (pi
.fd
, PIOCSFPREG
, &pi
.fpregset
);
1621 #endif /* FP0_REGNUM */
1629 inferior_proc_init - initialize access to a /proc entry
1633 void inferior_proc_init (int pid)
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.
1645 If proc_init_failed ever gets called, control returns to the command
1646 processing loop via the standard error handling code.
1651 inferior_proc_init (pid
)
1654 if (!open_proc_file (pid
, &pi
))
1656 proc_init_failed ("can't open process file");
1660 (void) memset ((char *) &pi
.prrun
, 0, sizeof (pi
.prrun
));
1661 prfillset (&pi
.prrun
.pr_trace
);
1662 proc_signal_handling_change ();
1663 prfillset (&pi
.prrun
.pr_fault
);
1664 prdelset (&pi
.prrun
.pr_fault
, FLTPAGE
);
1665 if (ioctl (pi
.fd
, PIOCWSTOP
, &pi
.prstatus
) < 0)
1667 proc_init_failed ("PIOCWSTOP failed");
1669 else if (ioctl (pi
.fd
, PIOCSFAULT
, &pi
.prrun
.pr_fault
) < 0)
1671 proc_init_failed ("PIOCSFAULT failed");
1680 proc_signal_handling_change
1684 void proc_signal_handling_change (void);
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.
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
1702 proc_signal_handling_change ()
1708 for (signo
= 0; signo
< NSIG
; signo
++)
1710 if (signal_stop_state (signo
) == 0 &&
1711 signal_print_state (signo
) == 0 &&
1712 signal_pass_state (signo
) == 1)
1714 prdelset (&pi
.prrun
.pr_trace
, signo
);
1718 praddset (&pi
.prrun
.pr_trace
, signo
);
1721 if (ioctl (pi
.fd
, PIOCSTRACE
, &pi
.prrun
.pr_trace
))
1723 print_sys_errmsg ("PIOCSTRACE failed", errno
);
1732 proc_set_exec_trap -- arrange for exec'd child to halt at startup
1736 void proc_set_exec_trap (void)
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.
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
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.
1760 proc_set_exec_trap ()
1763 auto char procname
[32];
1766 (void) sprintf (procname
, PROC_NAME_FMT
, getpid ());
1767 if ((fd
= open (procname
, O_RDWR
)) < 0)
1773 premptyset (&exitset
);
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. */
1781 praddset (&exitset
, SYS_exec
);
1784 praddset (&exitset
, SYS_execve
);
1787 praddset(&exitset
, SYS_execv
);
1790 if (ioctl (fd
, PIOCSEXIT
, &exitset
) < 0)
1797 /* Turn off inherit-on-fork flag so that all grand-children of gdb
1798 start with tracing flags cleared. */
1800 #if defined (PIOCRESET) /* New method */
1804 (void) ioctl (fd
, PIOCRESET
, &pr_flags
);
1807 #if defined (PIOCRFORK) /* Original method */
1808 (void) ioctl (fd
, PIOCRFORK
, NULL
);
1817 proc_iterate_over_mappings -- call function for every mapped space
1821 int proc_iterate_over_mappings (int (*func)())
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.
1833 proc_iterate_over_mappings (func
)
1834 int (*func
) PARAMS ((int, CORE_ADDR
));
1839 struct prmap
*prmaps
;
1840 struct prmap
*prmap
;
1841 CORE_ADDR baseaddr
= 0;
1843 if (pi
.valid
&& (ioctl (pi
.fd
, PIOCNMAP
, &nmap
) == 0))
1845 prmaps
= (struct prmap
*) alloca ((nmap
+ 1) * sizeof (*prmaps
));
1846 if (ioctl (pi
.fd
, PIOCMAP
, prmaps
) == 0)
1848 for (prmap
= prmaps
; prmap
-> pr_size
&& funcstat
== 0; ++prmap
)
1850 fd
= proc_address_to_fd ((CORE_ADDR
) prmap
-> pr_vaddr
, 0);
1851 funcstat
= (*func
) (fd
, (CORE_ADDR
) prmap
-> pr_vaddr
);
1863 proc_base_address -- find base address for segment containing address
1867 CORE_ADDR proc_base_address (CORE_ADDR addr)
1871 Given an address of a location in the inferior, find and return
1872 the base address of the mapped segment containing that address.
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.
1881 #if 0 /* Currently unused */
1884 proc_base_address (addr
)
1888 struct prmap
*prmaps
;
1889 struct prmap
*prmap
;
1890 CORE_ADDR baseaddr
= 0;
1892 if (pi
.valid
&& (ioctl (pi
.fd
, PIOCNMAP
, &nmap
) == 0))
1894 prmaps
= (struct prmap
*) alloca ((nmap
+ 1) * sizeof (*prmaps
));
1895 if (ioctl (pi
.fd
, PIOCMAP
, prmaps
) == 0)
1897 for (prmap
= prmaps
; prmap
-> pr_size
; ++prmap
)
1899 if ((prmap
-> pr_vaddr
<= (caddr_t
) addr
) &&
1900 (prmap
-> pr_vaddr
+ prmap
-> pr_size
> (caddr_t
) addr
))
1902 baseaddr
= (CORE_ADDR
) prmap
-> pr_vaddr
;
1917 proc_address_to_fd -- return open fd for file mapped to address
1921 int proc_address_to_fd (CORE_ADDR addr, complain)
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).
1934 proc_address_to_fd (addr
, complain
)
1942 if ((fd
= ioctl (pi
.fd
, PIOCOPENM
, (caddr_t
*) &addr
)) < 0)
1946 print_sys_errmsg (pi
.pathname
, errno
);
1947 warning ("can't find mapped file for address 0x%x", addr
);
1955 #ifdef ATTACH_DETACH
1961 attach -- attach to an already existing process
1965 int attach (int pid)
1969 Attach to an already existing process with the specified process
1970 id. If the process is not already stopped, query whether to
1975 The option of stopping at attach time is specific to the /proc
1976 versions of gdb. Versions using ptrace force the attachee
1985 if (!open_proc_file (pid
, &pi
))
1987 perror_with_name (pi
.pathname
);
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
1995 if (ioctl (pi
.fd
, PIOCSTATUS
, &pi
.prstatus
) < 0)
1997 print_sys_errmsg (pi
.pathname
, errno
);
1998 close_proc_file (&pi
);
1999 error ("PIOCSTATUS failed");
2001 if (pi
.prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
))
2008 if (query ("Process is currently running, stop it? "))
2010 if (ioctl (pi
.fd
, PIOCSTOP
, &pi
.prstatus
) < 0)
2012 print_sys_errmsg (pi
.pathname
, errno
);
2013 close_proc_file (&pi
);
2014 error ("PIOCSTOP failed");
2016 pi
.nopass_next_sigstop
= 1;
2020 printf ("Ok, gdb will wait for process %u to stop.\n", pid
);
2024 /* Remember some things about the inferior that we will, or might, change
2025 so that we can restore them when we detach. */
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
);
2033 /* Set up trace and fault sets, as gdb expects them. */
2035 (void) memset (&pi
.prrun
, 0, sizeof (pi
.prrun
));
2036 prfillset (&pi
.prrun
.pr_trace
);
2037 proc_signal_handling_change ();
2038 prfillset (&pi
.prrun
.pr_fault
);
2039 prdelset (&pi
.prrun
.pr_fault
, FLTPAGE
);
2040 if (ioctl (pi
.fd
, PIOCSFAULT
, &pi
.prrun
.pr_fault
))
2042 print_sys_errmsg ("PIOCSFAULT failed", errno
);
2044 if (ioctl (pi
.fd
, PIOCSTRACE
, &pi
.prrun
.pr_trace
))
2046 print_sys_errmsg ("PIOCSTRACE failed", errno
);
2056 detach -- detach from an attached-to process
2060 void detach (int signal)
2064 Detach from the current attachee.
2066 If signal is non-zero, the attachee is started running again and sent
2067 the specified signal.
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.
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
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).
2087 set_proc_siginfo (&pi
, signal
);
2089 if (ioctl (pi
.fd
, PIOCSEXIT
, &pi
.saved_exitset
) < 0)
2091 print_sys_errmsg (pi
.pathname
, errno
);
2092 printf ("PIOCSEXIT failed.\n");
2094 if (ioctl (pi
.fd
, PIOCSENTRY
, &pi
.saved_entryset
) < 0)
2096 print_sys_errmsg (pi
.pathname
, errno
);
2097 printf ("PIOCSENTRY failed.\n");
2099 if (ioctl (pi
.fd
, PIOCSTRACE
, &pi
.saved_trace
) < 0)
2101 print_sys_errmsg (pi
.pathname
, errno
);
2102 printf ("PIOCSTRACE failed.\n");
2104 if (ioctl (pi
.fd
, PIOCSHOLD
, &pi
.saved_sighold
) < 0)
2106 print_sys_errmsg (pi
.pathname
, errno
);
2107 printf ("PIOSCHOLD failed.\n");
2109 if (ioctl (pi
.fd
, PIOCSFAULT
, &pi
.saved_fltset
) < 0)
2111 print_sys_errmsg (pi
.pathname
, errno
);
2112 printf ("PIOCSFAULT failed.\n");
2114 if (ioctl (pi
.fd
, PIOCSTATUS
, &pi
.prstatus
) < 0)
2116 print_sys_errmsg (pi
.pathname
, errno
);
2117 printf ("PIOCSTATUS failed.\n");
2121 if (signal
|| (pi
.prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
)))
2123 if (signal
|| !pi
.was_stopped
||
2124 query ("Was stopped when attached, make it runnable again? "))
2126 (void) memset (&pi
.prrun
, 0, sizeof (pi
.prrun
));
2127 pi
.prrun
.pr_flags
= PRCFAULT
;
2128 if (ioctl (pi
.fd
, PIOCRUN
, &pi
.prrun
))
2130 print_sys_errmsg (pi
.pathname
, errno
);
2131 printf ("PIOCRUN failed.\n");
2136 close_proc_file (&pi
);
2140 #endif /* ATTACH_DETACH */
2146 proc_wait -- emulate wait() as much as possible
2150 int proc_wait (int *statloc)
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.
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
2174 FIXME: Investigate why wait() seems to have problems with programs
2175 being control by /proc routines.
2189 if (ioctl (pi
.fd
, PIOCSTATUS
, &pi
.prstatus
) < 0)
2193 else if (!(pi
.prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
)))
2195 if (ioctl (pi
.fd
, PIOCWSTOP
, &pi
.prstatus
) < 0)
2202 if (errno
== ENOENT
)
2204 rtnval
= wait (&statval
);
2205 if (rtnval
!= inferior_pid
)
2207 error ("PIOCWSTOP, wait failed, returned %d", rtnval
);
2213 print_sys_errmsg (pi
.pathname
, errno
);
2214 error ("PIOCSTATUS or PIOCWSTOP failed.");
2218 else if (pi
.prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
))
2220 rtnval
= pi
.prstatus
.pr_pid
;
2221 why
= pi
.prstatus
.pr_why
;
2222 what
= pi
.prstatus
.pr_what
;
2223 if (why
== PR_SIGNALLED
)
2225 statval
= (what
<< 8) | 0177;
2227 else if ((why
== PR_SYSEXIT
)
2236 || what
== SYS_execve
2239 || what
== SYS_execv
2243 statval
= (SIGTRAP
<< 8) | 0177;
2245 else if (why
== PR_REQUESTED
)
2247 statval
= (SIGSTOP
<< 8) | 0177;
2249 else if (why
== PR_JOBCONTROL
)
2251 statval
= (what
<< 8) | 0177;
2253 else if (why
== PR_FAULTED
)
2259 statval
= (SIGILL
<< 8) | 0177;
2263 statval
= (SIGTRAP
<< 8) | 0177;
2268 statval
= (SIGSEGV
<< 8) | 0177;
2273 statval
= (SIGFPE
<< 8) | 0177;
2275 case FLTPAGE
: /* Recoverable page fault */
2278 error ("PIOCWSTOP, unknown why %d, what %d", why
, what
);
2285 error ("PIOCWSTOP, unknown why %d, what %d", why
, what
);
2291 error ("PIOCWSTOP, stopped for unknown/unhandled reason, flags %#x",
2292 pi
.prstatus
.pr_flags
);
2306 set_proc_siginfo - set a process's current signal info
2310 void set_proc_siginfo (struct procinfo *pip, int signo);
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.
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.
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
2337 See siginfo(5) for more details.
2341 set_proc_siginfo (pip
, signo
)
2342 struct procinfo
*pip
;
2345 struct siginfo newsiginfo
;
2346 struct siginfo
*sip
;
2350 if (signo
== pip
-> prstatus
.pr_info
.si_signo
)
2352 sip
= &pip
-> prstatus
.pr_info
;
2356 (void) memset ((char *) &newsiginfo
, 0, sizeof (newsiginfo
));
2358 sip
-> si_signo
= signo
;
2360 sip
-> si_errno
= 0;
2361 sip
-> si_pid
= getpid ();
2362 sip
-> si_uid
= getuid ();
2364 if (ioctl (pip
-> fd
, PIOCSSIG
, sip
) < 0)
2366 print_sys_errmsg (pip
-> pathname
, errno
);
2367 warning ("PIOCSSIG failed");
2376 child_resume -- resume execution of the inferior process
2380 void child_resume (int step, int signo)
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
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.
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?)
2409 child_resume (step
, signo
)
2414 pi
.prrun
.pr_flags
= PRSVADDR
| PRSTRACE
| PRSFAULT
| PRCFAULT
;
2415 pi
.prrun
.pr_vaddr
= (caddr_t
) *(int *) ®isters
[REGISTER_BYTE (PC_REGNUM
)];
2416 if (signo
&& !(signo
== SIGSTOP
&& pi
.nopass_next_sigstop
))
2418 set_proc_siginfo (&pi
, signo
);
2422 pi
.prrun
.pr_flags
|= PRCSIG
;
2424 pi
.nopass_next_sigstop
= 0;
2427 pi
.prrun
.pr_flags
|= PRSTEP
;
2429 if (ioctl (pi
.fd
, PIOCRUN
, &pi
.prrun
) != 0)
2431 perror_with_name (pi
.pathname
);
2440 fetch_inferior_registers -- fetch current registers from inferior
2444 void fetch_inferior_registers (int regno)
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.
2455 fetch_inferior_registers (regno
)
2458 if (ioctl (pi
.fd
, PIOCGREG
, &pi
.gregset
) != -1)
2460 supply_gregset (&pi
.gregset
);
2462 #if defined (FP0_REGNUM)
2463 if (ioctl (pi
.fd
, PIOCGFPREG
, &pi
.fpregset
) != -1)
2465 supply_fpregset (&pi
.fpregset
);
2474 fetch_core_registers -- fetch current registers from core file data
2478 void fetch_core_registers (char *core_reg_sect, unsigned core_reg_size,
2479 int which, unsigned in reg_addr)
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.
2490 Use the indicated sizes to validate the gregset and fpregset
2495 fetch_core_registers (core_reg_sect
, core_reg_size
, which
, reg_addr
)
2496 char *core_reg_sect
;
2497 unsigned core_reg_size
;
2499 unsigned int reg_addr
; /* Unused in this version */
2504 if (core_reg_size
!= sizeof (pi
.gregset
))
2506 warning ("wrong size gregset struct in core file");
2510 (void) memcpy ((char *) &pi
.gregset
, core_reg_sect
,
2511 sizeof (pi
.gregset
));
2512 supply_gregset (&pi
.gregset
);
2515 else if (which
== 2)
2517 if (core_reg_size
!= sizeof (pi
.fpregset
))
2519 warning ("wrong size fpregset struct in core file");
2523 (void) memcpy ((char *) &pi
.fpregset
, core_reg_sect
,
2524 sizeof (pi
.fpregset
));
2525 #if defined (FP0_REGNUM)
2526 supply_fpregset (&pi
.fpregset
);
2536 proc_init_failed - called whenever /proc access initialization fails
2540 static void proc_init_failed (char *why)
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.
2551 proc_init_failed (why
)
2554 print_sys_errmsg (pi
.pathname
, errno
);
2555 (void) kill (pi
.pid
, SIGKILL
);
2556 close_proc_file (&pi
);
2565 close_proc_file - close any currently open /proc entry
2569 static void close_proc_file (struct procinfo *pip)
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.
2581 close_proc_file (pip
)
2582 struct procinfo
*pip
;
2587 (void) close (pip
-> fd
);
2590 if (pip
-> pathname
)
2592 free (pip
-> pathname
);
2593 pip
-> pathname
= NULL
;
2602 open_proc_file - open a /proc entry for a given process id
2606 static int open_proc_file (pid, struct procinfo *pip)
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.
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".
2622 open_proc_file (pid
, pip
)
2624 struct procinfo
*pip
;
2629 (void) close (pip
-> fd
);
2631 if (pip
-> pathname
== NULL
)
2633 pip
-> pathname
= xmalloc (32);
2635 sprintf (pip
-> pathname
, PROC_NAME_FMT
, pid
);
2636 if ((pip
-> fd
= open (pip
-> pathname
, O_RDWR
)) >= 0)
2641 return (pip
-> valid
);
2645 mappingflags (flags
)
2648 static char asciiflags
[8];
2650 strcpy (asciiflags
, "-------");
2651 #if defined (MA_PHYS)
2652 if (flags
& MA_PHYS
) asciiflags
[0] = 'd';
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';
2660 return (asciiflags
);
2664 info_proc_flags (pip
, summary
)
2665 struct procinfo
*pip
;
2668 struct trans
*transp
;
2670 printf_filtered ("%-32s", "Process status flags:");
2673 printf_filtered ("\n\n");
2675 for (transp
= pr_flag_table
; transp
-> name
!= NULL
; transp
++)
2677 if (pip
-> prstatus
.pr_flags
& transp
-> value
)
2681 printf_filtered ("%s ", transp
-> name
);
2685 printf_filtered ("\t%-16s %s.\n", transp
-> name
, transp
-> desc
);
2689 printf_filtered ("\n");
2693 info_proc_stop (pip
, summary
)
2694 struct procinfo
*pip
;
2697 struct trans
*transp
;
2701 why
= pip
-> prstatus
.pr_why
;
2702 what
= pip
-> prstatus
.pr_what
;
2704 if (pip
-> prstatus
.pr_flags
& PR_STOPPED
)
2706 printf_filtered ("%-32s", "Reason for stopping:");
2709 printf_filtered ("\n\n");
2711 for (transp
= pr_why_table
; transp
-> name
!= NULL
; transp
++)
2713 if (why
== transp
-> value
)
2717 printf_filtered ("%s ", transp
-> name
);
2721 printf_filtered ("\t%-16s %s.\n",
2722 transp
-> name
, transp
-> desc
);
2728 /* Use the pr_why field to determine what the pr_what field means, and
2729 print more information. */
2734 /* pr_what is unused for this case */
2740 printf_filtered ("%s ", signalname (what
));
2744 printf_filtered ("\t%-16s %s.\n", signalname (what
),
2751 printf_filtered ("%s ", syscallname (what
));
2755 printf_filtered ("\t%-16s %s.\n", syscallname (what
),
2756 "Entered this system call");
2762 printf_filtered ("%s ", syscallname (what
));
2766 printf_filtered ("\t%-16s %s.\n", syscallname (what
),
2767 "Returned from this system call");
2773 printf_filtered ("%s ",
2774 lookupname (faults_table
, what
, "fault"));
2778 printf_filtered ("\t%-16s %s.\n",
2779 lookupname (faults_table
, what
, "fault"),
2780 lookupdesc (faults_table
, what
));
2784 printf_filtered ("\n");
2789 info_proc_siginfo (pip
, summary
)
2790 struct procinfo
*pip
;
2793 struct siginfo
*sip
;
2795 if ((pip
-> prstatus
.pr_flags
& PR_STOPPED
) &&
2796 (pip
-> prstatus
.pr_why
== PR_SIGNALLED
||
2797 pip
-> prstatus
.pr_why
== PR_FAULTED
))
2799 printf_filtered ("%-32s", "Additional signal/fault info:");
2800 sip
= &pip
-> prstatus
.pr_info
;
2803 printf_filtered ("%s ", signalname (sip
-> si_signo
));
2804 if (sip
-> si_errno
> 0)
2806 printf_filtered ("%s ", lookupname (errno_table
,
2807 sip
-> si_errno
, "errno"));
2809 if (sip
-> si_code
<= 0)
2811 printf_filtered ("sent by pid %d, uid %d ", sip
-> si_pid
,
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
))
2822 printf_filtered ("addr=%#x ", sip
-> si_addr
);
2824 else if ((sip
-> si_signo
== SIGCHLD
))
2826 printf_filtered ("child pid %u, status %u ",
2830 else if ((sip
-> si_signo
== SIGPOLL
))
2832 printf_filtered ("band %u ", sip
-> si_band
);
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)
2843 printf_filtered ("\t%-16s %s.\n",
2844 lookupname (errno_table
,
2845 sip
-> si_errno
, "errno"),
2846 lookupdesc (errno_table
, sip
-> si_errno
));
2848 if (sip
-> si_code
<= 0)
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");
2857 printf_filtered ("\t%-16s %s.\n", sigcodename (sip
),
2859 if ((sip
-> si_signo
== SIGILL
) ||
2860 (sip
-> si_signo
== SIGFPE
))
2862 printf_filtered ("\t%-16#x %s.\n", sip
-> si_addr
,
2863 "Address of faulting instruction");
2865 else if ((sip
-> si_signo
== SIGSEGV
) ||
2866 (sip
-> si_signo
== SIGBUS
))
2868 printf_filtered ("\t%-16#x %s.\n", sip
-> si_addr
,
2869 "Address of faulting memory reference");
2871 else if ((sip
-> si_signo
== SIGCHLD
))
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");
2878 else if ((sip
-> si_signo
== SIGPOLL
))
2880 printf_filtered ("\t%-16u %s.\n", sip
-> si_band
,
2881 "Band event for POLL_{IN,OUT,MSG}");
2885 printf_filtered ("\n");
2890 info_proc_syscalls (pip
, summary
)
2891 struct procinfo
*pip
;
2899 #if 0 /* FIXME: Needs to use gdb-wide configured info about system calls. */
2900 if (pip
-> prstatus
.pr_flags
& PR_ASLEEP
)
2902 int syscallnum
= pip
-> prstatus
.pr_reg
[R_D0
];
2905 printf_filtered ("%-32s", "Sleeping in system call:");
2906 printf_filtered ("%s", syscallname (syscallnum
));
2910 printf_filtered ("Sleeping in system call '%s'.\n",
2911 syscallname (syscallnum
));
2916 if (ioctl (pip
-> fd
, PIOCGENTRY
, &pip
-> entryset
) < 0)
2918 print_sys_errmsg (pip
-> pathname
, errno
);
2919 error ("PIOCGENTRY failed");
2922 if (ioctl (pip
-> fd
, PIOCGEXIT
, &pip
-> exitset
) < 0)
2924 print_sys_errmsg (pip
-> pathname
, errno
);
2925 error ("PIOCGEXIT failed");
2928 printf_filtered ("System call tracing information:\n\n");
2930 printf_filtered ("\t%-12s %-8s %-8s\n",
2934 for (syscallnum
= 0; syscallnum
< MAX_SYSCALLS
; syscallnum
++)
2937 if (syscall_table
[syscallnum
] != NULL
)
2939 printf_filtered ("\t%-12s ", syscall_table
[syscallnum
]);
2940 printf_filtered ("%-8s ",
2941 prismember (&pip
-> entryset
, syscallnum
)
2943 printf_filtered ("%-8s ",
2944 prismember (&pip
-> exitset
, syscallnum
)
2946 printf_filtered ("\n");
2949 printf_filtered ("\n");
2958 static char locbuf
[32];
2960 abbrev
= sig_abbrev (signo
);
2963 sprintf (locbuf
, "signal %d", signo
);
2967 sprintf (locbuf
, "SIG%s (%d)", abbrev
, signo
);
2973 info_proc_signals (pip
, summary
)
2974 struct procinfo
*pip
;
2981 if (ioctl (pip
-> fd
, PIOCGTRACE
, &pip
-> trace
) < 0)
2983 print_sys_errmsg (pip
-> pathname
, errno
);
2984 error ("PIOCGTRACE failed");
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
++)
2993 printf_filtered ("\t%-15s ", signalname (signo
));
2994 printf_filtered ("%-8s ",
2995 prismember (&pip
-> trace
, signo
)
2997 printf_filtered ("%-8s ",
2998 prismember (&pip
-> prstatus
.pr_sighold
, signo
)
3000 printf_filtered ("%-8s ",
3001 prismember (&pip
-> prstatus
.pr_sigpend
, signo
)
3003 printf_filtered (" %s\n", sys_siglist
[signo
]);
3005 printf_filtered ("\n");
3010 info_proc_faults (pip
, summary
)
3011 struct procinfo
*pip
;
3014 struct trans
*transp
;
3018 if (ioctl (pip
-> fd
, PIOCGFAULT
, &pip
-> fltset
) < 0)
3020 print_sys_errmsg (pip
-> pathname
, errno
);
3021 error ("PIOCGFAULT failed");
3024 printf_filtered ("Current traced hardware fault set:\n\n");
3025 printf_filtered ("\t%-12s %-8s\n", "Fault", "Trace");
3027 for (transp
= faults_table
; transp
-> name
!= NULL
; transp
++)
3030 printf_filtered ("\t%-12s ", transp
-> name
);
3031 printf_filtered ("%-8s", prismember (&pip
-> fltset
, transp
-> value
)
3033 printf_filtered ("\n");
3035 printf_filtered ("\n");
3040 info_proc_mappings (pip
, summary
)
3041 struct procinfo
*pip
;
3045 struct prmap
*prmaps
;
3046 struct prmap
*prmap
;
3050 printf_filtered ("Mapped address spaces:\n\n");
3051 printf_filtered ("\t%10s %10s %10s %10s %7s\n",
3057 if (ioctl (pip
-> fd
, PIOCNMAP
, &nmap
) == 0)
3059 prmaps
= (struct prmap
*) alloca ((nmap
+ 1) * sizeof (*prmaps
));
3060 if (ioctl (pip
-> fd
, PIOCMAP
, prmaps
) == 0)
3062 for (prmap
= prmaps
; prmap
-> pr_size
; ++prmap
)
3064 printf_filtered ("\t%#10x %#10x %#10x %#10x %7s\n",
3066 prmap
-> pr_vaddr
+ prmap
-> pr_size
- 1,
3069 mappingflags (prmap
-> pr_mflags
));
3073 printf_filtered ("\n");
3081 info_proc -- implement the "info proc" command
3085 void info_proc (char *args, int from_tty)
3089 Implement gdb's "info proc" command by using the /proc interface
3090 to print status information about any currently running process.
3092 Examples of the use of "info proc" are:
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)
3106 info_proc (args
, from_tty
)
3111 struct procinfo pii
;
3112 struct procinfo
*pip
;
3113 struct cleanup
*old_chain
;
3128 old_chain
= make_cleanup (null_cleanup
, 0);
3130 /* Default to using the current inferior if no pid specified */
3136 if ((argv
= buildargv (args
)) == NULL
)
3140 make_cleanup (freeargv
, (char *) argv
);
3142 while (*argv
!= NULL
)
3144 argsize
= strlen (*argv
);
3145 if (argsize
>= 1 && strncmp (*argv
, "all", argsize
) == 0)
3150 else if (argsize
>= 2 && strncmp (*argv
, "faults", argsize
) == 0)
3155 else if (argsize
>= 2 && strncmp (*argv
, "flags", argsize
) == 0)
3160 else if (argsize
>= 1 && strncmp (*argv
, "id", argsize
) == 0)
3165 else if (argsize
>= 1 && strncmp (*argv
, "mappings", argsize
) == 0)
3170 else if (argsize
>= 2 && strncmp (*argv
, "signals", argsize
) == 0)
3175 else if (argsize
>= 2 && strncmp (*argv
, "status", argsize
) == 0)
3180 else if (argsize
>= 2 && strncmp (*argv
, "syscalls", argsize
) == 0)
3185 else if (argsize
>= 1 && strncmp (*argv
, "times", argsize
) == 0)
3190 else if ((pii
.pid
= atoi (*argv
)) > 0)
3194 (void) memset (&pii
, 0, sizeof (pii
));
3195 if (!open_proc_file (pid
, pip
))
3197 perror_with_name (pip
-> pathname
);
3200 make_cleanup (close_proc_file
, pip
);
3202 else if (**argv
!= '\000')
3204 error ("Unrecognized or ambiguous keyword `%s'.", *argv
);
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. */
3215 error ("No process. Run an inferior or specify an explicit pid.");
3217 if (ioctl (pip
-> fd
, PIOCSTATUS
, &(pip
-> prstatus
)) < 0)
3219 print_sys_errmsg (pip
-> pathname
, errno
);
3220 error ("PIOCSTATUS failed");
3223 /* Print verbose information of the requested type(s), or just a summary
3224 of the information for all types. */
3226 printf_filtered ("\nInformation for %s:\n\n", pip
-> pathname
);
3227 if (summary
|| all
|| flags
)
3229 info_proc_flags (pip
, summary
);
3233 info_proc_stop (pip
, summary
);
3235 if (summary
|| all
|| signals
|| faults
)
3237 info_proc_siginfo (pip
, summary
);
3239 if (summary
|| all
|| syscalls
)
3241 info_proc_syscalls (pip
, summary
);
3243 if (summary
|| all
|| mappings
)
3245 info_proc_mappings (pip
, summary
);
3247 if (summary
|| all
|| signals
)
3249 info_proc_signals (pip
, summary
);
3251 if (summary
|| all
|| faults
)
3253 info_proc_faults (pip
, summary
);
3255 printf_filtered ("\n");
3257 /* All done, deal with closing any temporary process info structure,
3258 freeing temporary memory , etc. */
3260 do_cleanups (old_chain
);
3267 _initialize_proc_fs -- initialize the process file system stuff
3271 void _initialize_proc_fs (void)
3275 Do required initializations during gdb startup for using the
3276 /proc file system interface.
3280 static char *proc_desc
=
3281 "Show process status information using /proc entry.\n\
3282 Specify process id or use current inferior by default.\n\
3283 Specify keywords for detailed information; default is summary.\n\
3284 Keywords are: `all', `faults', `flags', `id', `mappings', `signals',\n\
3285 `status', `syscalls', and `times'.\n\
3286 Unambiguous abbreviations may be used.";
3289 _initialize_proc_fs ()
3291 add_info ("proc", info_proc
, proc_desc
);
3292 init_syscall_table ();
3295 #endif /* USE_PROC_FS */