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 prrun_t prrun
; /* Control state when it is run */
81 prstatus_t prstatus
; /* Current process status info */
82 gregset_t gregset
; /* General register set */
83 fpregset_t fpregset
; /* Floating point register set */
84 fltset_t fltset
; /* Current traced hardware fault set */
85 sigset_t trace
; /* Current traced signal set */
86 sysset_t exitset
; /* Current traced system call exit set */
87 sysset_t entryset
; /* Current traced system call entry set */
88 fltset_t saved_fltset
; /* Saved traced hardware fault set */
89 sigset_t saved_trace
; /* Saved traced signal set */
90 sigset_t saved_sighold
; /* Saved held signal set */
91 sysset_t saved_exitset
; /* Saved traced system call exit set */
92 sysset_t saved_entryset
; /* Saved traced system call entry set */
95 static struct procinfo pi
; /* Inferior's process information */
97 /* Much of the information used in the /proc interface, particularly for
98 printing status information, is kept as tables of structures of the
99 following form. These tables can be used to map numeric values to
100 their symbolic names and to a string that describes their specific use. */
103 int value
; /* The numeric value */
104 char *name
; /* The equivalent symbolic value */
105 char *desc
; /* Short description of value */
108 /* Translate bits in the pr_flags member of the prstatus structure, into the
109 names and desc information. */
111 static struct trans pr_flag_table
[] =
113 #if defined (PR_STOPPED)
114 PR_STOPPED
, "PR_STOPPED", "Process is stopped",
116 #if defined (PR_ISTOP)
117 PR_ISTOP
, "PR_ISTOP", "Stopped on an event of interest",
119 #if defined (PR_DSTOP)
120 PR_DSTOP
, "PR_DSTOP", "A stop directive is in effect",
122 #if defined (PR_ASLEEP)
123 PR_ASLEEP
, "PR_ASLEEP", "Sleeping in an interruptible system call",
125 #if defined (PR_FORK)
126 PR_FORK
, "PR_FORK", "Inherit-on-fork is in effect",
129 PR_RLC
, "PR_RLC", "Run-on-last-close is in effect",
131 #if defined (PR_PTRACE)
132 PR_PTRACE
, "PR_PTRACE", "Process is being controlled by ptrace",
134 #if defined (PR_PCINVAL)
135 PR_PCINVAL
, "PR_PCINVAL", "PC refers to an invalid virtual address",
137 #if defined (PR_ISSYS)
138 PR_ISSYS
, "PR_ISSYS", "Is a system process",
143 /* Translate values in the pr_why field of the prstatus struct. */
145 static struct trans pr_why_table
[] =
147 #if defined (PR_REQUESTED)
148 PR_REQUESTED
, "PR_REQUESTED", "Directed to stop via PIOCSTOP/PIOCWSTOP",
150 #if defined (PR_SIGNALLED)
151 PR_SIGNALLED
, "PR_SIGNALLED", "Receipt of a traced signal",
153 #if defined (PR_FAULTED)
154 PR_FAULTED
, "PR_FAULTED", "Incurred a traced hardware fault",
156 #if defined (PR_SYSENTRY)
157 PR_SYSENTRY
, "PR_SYSENTRY", "Entry to a traced system call",
159 #if defined (PR_SYSEXIT)
160 PR_SYSEXIT
, "PR_SYSEXIT", "Exit from a traced system call",
162 #if defined (PR_JOBCONTROL)
163 PR_JOBCONTROL
, "PR_JOBCONTROL", "Default job control stop signal action",
168 /* Hardware fault translation table. */
170 static struct trans faults_table
[] =
173 FLTILL
, "FLTILL", "Illegal instruction",
175 #if defined (FLTPRIV)
176 FLTPRIV
, "FLTPRIV", "Privileged instruction",
179 FLTBPT
, "FLTBPT", "Breakpoint trap",
181 #if defined (FLTTRACE)
182 FLTTRACE
, "FLTTRACE", "Trace trap",
184 #if defined (FLTACCESS)
185 FLTACCESS
, "FLTACCESS", "Memory access fault",
187 #if defined (FLTBOUNDS)
188 FLTBOUNDS
, "FLTBOUNDS", "Memory bounds violation",
190 #if defined (FLTIOVF)
191 FLTIOVF
, "FLTIOVF", "Integer overflow",
193 #if defined (FLTIZDIV)
194 FLTIZDIV
, "FLTIZDIV", "Integer zero divide",
197 FLTFPE
, "FLTFPE", "Floating-point exception",
199 #if defined (FLTSTACK)
200 FLTSTACK
, "FLTSTACK", "Unrecoverable stack fault",
202 #if defined (FLTPAGE)
203 FLTPAGE
, "FLTPAGE", "Recoverable page fault",
208 /* Translation table for signal generation information. See UNIX System
209 V Release 4 Programmer's Reference Manual, siginfo(5). */
211 static struct sigcode
{
216 } siginfo_table
[] = {
217 #if defined (SIGILL) && defined (ILL_ILLOPC)
218 SIGILL
, ILL_ILLOPC
, "ILL_ILLOPC", "Illegal opcode",
220 #if defined (SIGILL) && defined (ILL_ILLOPN)
221 SIGILL
, ILL_ILLOPN
, "ILL_ILLOPN", "Illegal operand",
223 #if defined (SIGILL) && defined (ILL_ILLADR)
224 SIGILL
, ILL_ILLADR
, "ILL_ILLADR", "Illegal addressing mode",
226 #if defined (SIGILL) && defined (ILL_ILLTRP)
227 SIGILL
, ILL_ILLTRP
, "ILL_ILLTRP", "Illegal trap",
229 #if defined (SIGILL) && defined (ILL_PRVOPC)
230 SIGILL
, ILL_PRVOPC
, "ILL_PRVOPC", "Privileged opcode",
232 #if defined (SIGILL) && defined (ILL_PRVREG)
233 SIGILL
, ILL_PRVREG
, "ILL_PRVREG", "Privileged register",
235 #if defined (SIGILL) && defined (ILL_COPROC)
236 SIGILL
, ILL_COPROC
, "ILL_COPROC", "Coprocessor error",
238 #if defined (SIGILL) && defined (ILL_BADSTK)
239 SIGILL
, ILL_BADSTK
, "ILL_BADSTK", "Internal stack error",
241 #if defined (SIGFPE) && defined (FPE_INTDIV)
242 SIGFPE
, FPE_INTDIV
, "FPE_INTDIV", "Integer divide by zero",
244 #if defined (SIGFPE) && defined (FPE_INTOVF)
245 SIGFPE
, FPE_INTOVF
, "FPE_INTOVF", "Integer overflow",
247 #if defined (SIGFPE) && defined (FPE_FLTDIV)
248 SIGFPE
, FPE_FLTDIV
, "FPE_FLTDIV", "Floating point divide by zero",
250 #if defined (SIGFPE) && defined (FPE_FLTOVF)
251 SIGFPE
, FPE_FLTOVF
, "FPE_FLTOVF", "Floating point overflow",
253 #if defined (SIGFPE) && defined (FPE_FLTUND)
254 SIGFPE
, FPE_FLTUND
, "FPE_FLTUND", "Floating point underflow",
256 #if defined (SIGFPE) && defined (FPE_FLTRES)
257 SIGFPE
, FPE_FLTRES
, "FPE_FLTRES", "Floating point inexact result",
259 #if defined (SIGFPE) && defined (FPE_FLTINV)
260 SIGFPE
, FPE_FLTINV
, "FPE_FLTINV", "Invalid floating point operation",
262 #if defined (SIGFPE) && defined (FPE_FLTSUB)
263 SIGFPE
, FPE_FLTSUB
, "FPE_FLTSUB", "Subscript out of range",
265 #if defined (SIGSEGV) && defined (SEGV_MAPERR)
266 SIGSEGV
, SEGV_MAPERR
, "SEGV_MAPERR", "Address not mapped to object",
268 #if defined (SIGSEGV) && defined (SEGV_ACCERR)
269 SIGSEGV
, SEGV_ACCERR
, "SEGV_ACCERR", "Invalid permissions for object",
271 #if defined (SIGBUS) && defined (BUS_ADRALN)
272 SIGBUS
, BUS_ADRALN
, "BUS_ADRALN", "Invalid address alignment",
274 #if defined (SIGBUS) && defined (BUS_ADRERR)
275 SIGBUS
, BUS_ADRERR
, "BUS_ADRERR", "Non-existent physical address",
277 #if defined (SIGBUS) && defined (BUS_OBJERR)
278 SIGBUS
, BUS_OBJERR
, "BUS_OBJERR", "Object specific hardware error",
280 #if defined (SIGTRAP) && defined (TRAP_BRKPT)
281 SIGTRAP
, TRAP_BRKPT
, "TRAP_BRKPT", "Process breakpoint",
283 #if defined (SIGTRAP) && defined (TRAP_TRACE)
284 SIGTRAP
, TRAP_TRACE
, "TRAP_TRACE", "Process trace trap",
286 #if defined (SIGCLD) && defined (CLD_EXITED)
287 SIGCLD
, CLD_EXITED
, "CLD_EXITED", "Child has exited",
289 #if defined (SIGCLD) && defined (CLD_KILLED)
290 SIGCLD
, CLD_KILLED
, "CLD_KILLED", "Child was killed",
292 #if defined (SIGCLD) && defined (CLD_DUMPED)
293 SIGCLD
, CLD_DUMPED
, "CLD_DUMPED", "Child has terminated abnormally",
295 #if defined (SIGCLD) && defined (CLD_TRAPPED)
296 SIGCLD
, CLD_TRAPPED
, "CLD_TRAPPED", "Traced child has trapped",
298 #if defined (SIGCLD) && defined (CLD_STOPPED)
299 SIGCLD
, CLD_STOPPED
, "CLD_STOPPED", "Child has stopped",
301 #if defined (SIGCLD) && defined (CLD_CONTINUED)
302 SIGCLD
, CLD_CONTINUED
, "CLD_CONTINUED", "Stopped child had continued",
304 #if defined (SIGPOLL) && defined (POLL_IN)
305 SIGPOLL
, POLL_IN
, "POLL_IN", "Input input available",
307 #if defined (SIGPOLL) && defined (POLL_OUT)
308 SIGPOLL
, POLL_OUT
, "POLL_OUT", "Output buffers available",
310 #if defined (SIGPOLL) && defined (POLL_MSG)
311 SIGPOLL
, POLL_MSG
, "POLL_MSG", "Input message available",
313 #if defined (SIGPOLL) && defined (POLL_ERR)
314 SIGPOLL
, POLL_ERR
, "POLL_ERR", "I/O error",
316 #if defined (SIGPOLL) && defined (POLL_PRI)
317 SIGPOLL
, POLL_PRI
, "POLL_PRI", "High priority input available",
319 #if defined (SIGPOLL) && defined (POLL_HUP)
320 SIGPOLL
, POLL_HUP
, "POLL_HUP", "Device disconnected",
325 /* Translation table for errno values. See intro(2) in most UNIX systems
326 Programmers Reference Manuals.
328 Note that some systems provide a function (strerror) that returns the
329 error message string, or a global variable that is the base address of the
330 array of character pointers. Perhaps we should try to make use of these
331 provided strings if they are present, but at least this is more portable.
334 static struct trans errno_table
[] =
337 EPERM
, "EPERM", "Not super-user",
340 ENOENT
, "ENOENT", "No such file or directory",
343 ESRCH
, "ESRCH", "No such process",
346 EINTR
, "EINTR", "Interrupted system call",
349 EIO
, "EIO", "I/O error",
352 ENXIO
, "ENXIO", "No such device or address",
355 E2BIG
, "E2BIG", "Arg list too long",
357 #if defined (ENOEXEC)
358 ENOEXEC
, "ENOEXEC", "Exec format error",
361 EBADF
, "EBADF", "Bad file number",
364 ECHILD
, "ECHILD", "No child process",
367 EAGAIN
, "EAGAIN", "No more processes",
370 ENOMEM
, "ENOMEM", "Not enough space",
373 EACCES
, "EACCES", "Permission denied",
376 EFAULT
, "EFAULT", "Bad address",
378 #if defined (ENOTBLK)
379 ENOTBLK
, "ENOTBLK", "Block device required",
382 EBUSY
, "EBUSY", "Device busy",
385 EEXIST
, "EEXIST", "File exists",
388 EXDEV
, "EXDEV", "Cross-device link",
391 ENODEV
, "ENODEV", "No such device",
393 #if defined (ENOTDIR)
394 ENOTDIR
, "ENOTDIR", "Not a directory",
397 EISDIR
, "EISDIR", "Is a directory",
400 EINVAL
, "EINVAL", "Invalid argument",
403 ENFILE
, "ENFILE", "File table overflow",
406 EMFILE
, "EMFILE", "Too many open files",
409 ENOTTY
, "ENOTTY", "Not a typewriter",
411 #if defined (ETXTBSY)
412 ETXTBSY
, "ETXTBSY", "Text file busy",
415 EFBIG
, "EFBIG", "File too large",
418 ENOSPC
, "ENOSPC", "No space left on device",
421 ESPIPE
, "ESPIPE", "Illegal seek",
424 EROFS
, "EROFS", "Read only file system",
427 EMLINK
, "EMLINK", "Too many links",
430 EPIPE
, "EPIPE", "Broken pipe",
433 EDOM
, "EDOM", "Math argument out of domain of func",
436 ERANGE
, "ERANGE", "Math result not representable",
439 ENOMSG
, "ENOMSG", "No message of desired type",
442 EIDRM
, "EIDRM", "Identifier removed",
445 ECHRNG
, "ECHRNG", "Channel number out of range",
447 #if defined (EL2NSYNC)
448 EL2NSYNC
, "EL2NSYNC", "Level 2 not synchronized",
451 EL3HLT
, "EL3HLT", "Level 3 halted",
454 EL3RST
, "EL3RST", "Level 3 reset",
457 ELNRNG
, "ELNRNG", "Link number out of range",
459 #if defined (EUNATCH)
460 EUNATCH
, "EUNATCH", "Protocol driver not attached",
463 ENOCSI
, "ENOCSI", "No CSI structure available",
466 EL2HLT
, "EL2HLT", "Level 2 halted",
468 #if defined (EDEADLK)
469 EDEADLK
, "EDEADLK", "Deadlock condition",
472 ENOLCK
, "ENOLCK", "No record locks available",
475 EBADE
, "EBADE", "Invalid exchange",
478 EBADR
, "EBADR", "Invalid request descriptor",
481 EXFULL
, "EXFULL", "Exchange full",
484 ENOANO
, "ENOANO", "No anode",
486 #if defined (EBADRQC)
487 EBADRQC
, "EBADRQC", "Invalid request code",
489 #if defined (EBADSLT)
490 EBADSLT
, "EBADSLT", "Invalid slot",
492 #if defined (EDEADLOCK)
493 EDEADLOCK
, "EDEADLOCK", "File locking deadlock error",
496 EBFONT
, "EBFONT", "Bad font file fmt",
499 ENOSTR
, "ENOSTR", "Device not a stream",
501 #if defined (ENODATA)
502 ENODATA
, "ENODATA", "No data available",
505 ETIME
, "ETIME", "Timer expired",
508 ENOSR
, "ENOSR", "Out of streams resources",
511 ENONET
, "ENONET", "Machine is not on the network",
514 ENOPKG
, "ENOPKG", "Package not installed",
516 #if defined (EREMOTE)
517 EREMOTE
, "EREMOTE", "Object is remote",
519 #if defined (ENOLINK)
520 ENOLINK
, "ENOLINK", "Link has been severed",
523 EADV
, "EADV", "Advertise error",
526 ESRMNT
, "ESRMNT", "Srmount error",
529 ECOMM
, "ECOMM", "Communication error on send",
532 EPROTO
, "EPROTO", "Protocol error",
534 #if defined (EMULTIHOP)
535 EMULTIHOP
, "EMULTIHOP", "Multihop attempted",
537 #if defined (EDOTDOT)
538 EDOTDOT
, "EDOTDOT", "RFS specific error",
540 #if defined (EBADMSG)
541 EBADMSG
, "EBADMSG", "Not a data message",
543 #if defined (ENAMETOOLONG)
544 ENAMETOOLONG
, "ENAMETOOLONG", "File name too long",
546 #if defined (EOVERFLOW)
547 EOVERFLOW
, "EOVERFLOW", "Value too large for defined data type",
549 #if defined (ENOTUNIQ)
550 ENOTUNIQ
, "ENOTUNIQ", "Name not unique on network",
553 EBADFD
, "EBADFD", "File descriptor in bad state",
555 #if defined (EREMCHG)
556 EREMCHG
, "EREMCHG", "Remote address changed",
558 #if defined (ELIBACC)
559 ELIBACC
, "ELIBACC", "Cannot access a needed shared library",
561 #if defined (ELIBBAD)
562 ELIBBAD
, "ELIBBAD", "Accessing a corrupted shared library",
564 #if defined (ELIBSCN)
565 ELIBSCN
, "ELIBSCN", ".lib section in a.out corrupted",
567 #if defined (ELIBMAX)
568 ELIBMAX
, "ELIBMAX", "Attempting to link in too many shared libraries",
570 #if defined (ELIBEXEC)
571 ELIBEXEC
, "ELIBEXEC", "Cannot exec a shared library directly",
574 EILSEQ
, "EILSEQ", "Illegal byte sequence",
577 ENOSYS
, "ENOSYS", "Operation not applicable",
580 ELOOP
, "ELOOP", "Too many symbolic links encountered",
582 #if defined (ERESTART)
583 ERESTART
, "ERESTART", "Interrupted system call should be restarted",
585 #if defined (ESTRPIPE)
586 ESTRPIPE
, "ESTRPIPE", "Streams pipe error",
588 #if defined (ENOTEMPTY)
589 ENOTEMPTY
, "ENOTEMPTY", "Directory not empty",
592 EUSERS
, "EUSERS", "Too many users",
594 #if defined (ENOTSOCK)
595 ENOTSOCK
, "ENOTSOCK", "Socket operation on non-socket",
597 #if defined (EDESTADDRREQ)
598 EDESTADDRREQ
, "EDESTADDRREQ", "Destination address required",
600 #if defined (EMSGSIZE)
601 EMSGSIZE
, "EMSGSIZE", "Message too long",
603 #if defined (EPROTOTYPE)
604 EPROTOTYPE
, "EPROTOTYPE", "Protocol wrong type for socket",
606 #if defined (ENOPROTOOPT)
607 ENOPROTOOPT
, "ENOPROTOOPT", "Protocol not available",
609 #if defined (EPROTONOSUPPORT)
610 EPROTONOSUPPORT
, "EPROTONOSUPPORT", "Protocol not supported",
612 #if defined (ESOCKTNOSUPPORT)
613 ESOCKTNOSUPPORT
, "ESOCKTNOSUPPORT", "Socket type not supported",
615 #if defined (EOPNOTSUPP)
616 EOPNOTSUPP
, "EOPNOTSUPP", "Operation not supported on transport endpoint ",
618 #if defined (EPFNOSUPPORT)
619 EPFNOSUPPORT
, "EPFNOSUPPORT", "Protocol family not supported",
621 #if defined (EAFNOSUPPORT)
622 EAFNOSUPPORT
, "EAFNOSUPPORT", "Address family not supported by protocol",
624 #if defined (EADDRINUSE)
625 EADDRINUSE
, "EADDRINUSE", "Address already in use",
627 #if defined (EADDRNOTAVAIL)
628 EADDRNOTAVAIL
, "EADDRNOTAVAIL","Cannot assign requested address",
630 #if defined (ENETDOWN)
631 ENETDOWN
, "ENETDOWN", "Network is down",
633 #if defined (ENETUNREACH)
634 ENETUNREACH
, "ENETUNREACH", "Network is unreachable",
636 #if defined (ENETRESET)
637 ENETRESET
, "ENETRESET", "Network dropped connection because of reset",
639 #if defined (ECONNABORTED)
640 ECONNABORTED
, "ECONNABORTED", "Software caused connection abort",
642 #if defined (ECONNRESET)
643 ECONNRESET
, "ECONNRESET", "Connection reset by peer",
645 #if defined (ENOBUFS)
646 ENOBUFS
, "ENOBUFS", "No buffer space available",
648 #if defined (EISCONN)
649 EISCONN
, "EISCONN", "Transport endpoint is already connected",
651 #if defined (ENOTCONN)
652 ENOTCONN
, "ENOTCONN", "Transport endpoint is not connected",
654 #if defined (ESHUTDOWN)
655 ESHUTDOWN
, "ESHUTDOWN", "Cannot send after transport endpoint shutdown",
657 #if defined (ETOOMANYREFS)
658 ETOOMANYREFS
, "ETOOMANYREFS", "Too many references: cannot splice",
660 #if defined (ETIMEDOUT)
661 ETIMEDOUT
, "ETIMEDOUT", "Connection timed out",
663 #if defined (ECONNREFUSED)
664 ECONNREFUSED
, "ECONNREFUSED", "Connection refused",
666 #if defined (EHOSTDOWN)
667 EHOSTDOWN
, "EHOSTDOWN", "Host is down",
669 #if defined (EHOSTUNREACH)
670 EHOSTUNREACH
, "EHOSTUNREACH", "No route to host",
672 #if defined (EWOULDBLOCK)
673 EWOULDBLOCK
, "EWOULDBLOCK", "Operation already in progress",
675 #if defined (EINPROGRESS)
676 EINPROGRESS
, "EINPROGRESS", "Operation now in progress",
679 ESTALE
, "ESTALE", "Stale NFS file handle",
681 #if defined (EUCLEAN)
682 EUCLEAN
, "EUCLEAN", "Structure needs cleaning",
684 #if defined (ENOTNAM)
685 ENOTNAM
, "ENOTNAM", "Not a XENIX named type file",
687 #if defined (ENAVAIL)
688 ENAVAIL
, "ENAVAIL", "No XENIX semaphores available",
691 EISNAM
, "EISNAM", "Is a named type file",
693 #if defined (EREMOTEIO)
694 EREMOTEIO
, "EREMOTEIO", "Remote I/O error",
699 static char *syscall_table
[MAX_SYSCALLS
];
701 /* Prototypes for local functions */
704 set_proc_siginfo
PARAMS ((struct procinfo
*, int));
707 init_syscall_table
PARAMS ((void));
710 syscallname
PARAMS ((int));
713 signalname
PARAMS ((int));
716 proc_address_to_fd
PARAMS ((CORE_ADDR
, int));
719 open_proc_file
PARAMS ((int, struct procinfo
*));
722 close_proc_file
PARAMS ((struct procinfo
*));
725 unconditionally_kill_inferior
PARAMS ((void));
728 proc_init_failed
PARAMS ((char *));
731 info_proc
PARAMS ((char *, int));
734 info_proc_flags
PARAMS ((struct procinfo
*, int));
737 info_proc_stop
PARAMS ((struct procinfo
*, int));
740 info_proc_siginfo
PARAMS ((struct procinfo
*, int));
743 info_proc_syscalls
PARAMS ((struct procinfo
*, int));
746 info_proc_mappings
PARAMS ((struct procinfo
*, int));
749 info_proc_signals
PARAMS ((struct procinfo
*, int));
752 info_proc_faults
PARAMS ((struct procinfo
*, int));
755 mappingflags
PARAMS ((long));
758 lookupname
PARAMS ((struct trans
*, unsigned int, char *));
761 lookupdesc
PARAMS ((struct trans
*, unsigned int));
763 /* External function prototypes that can't be easily included in any
764 header file because the args are typedefs in system include files. */
767 supply_gregset
PARAMS ((gregset_t
*));
770 fill_gregset
PARAMS ((gregset_t
*, int));
773 supply_fpregset
PARAMS ((fpregset_t
*));
776 fill_fpregset
PARAMS ((fpregset_t
*, int));
782 lookupdesc -- translate a value to a summary desc string
786 static char *lookupdesc (struct trans *transp, unsigned int val);
790 Given a pointer to a translation table and a value to be translated,
791 lookup the desc string and return it.
795 lookupdesc (transp
, val
)
796 struct trans
*transp
;
801 for (desc
= NULL
; transp
-> name
!= NULL
; transp
++)
803 if (transp
-> value
== val
)
805 desc
= transp
-> desc
;
810 /* Didn't find a translation for the specified value, set a default one. */
823 lookupname -- translate a value to symbolic name
827 static char *lookupname (struct trans *transp, unsigned int val,
832 Given a pointer to a translation table, a value to be translated,
833 and a default prefix to return if the value can't be translated,
834 match the value with one of the translation table entries and
835 return a pointer to the symbolic name.
837 If no match is found it just returns the value as a printable string,
838 with the given prefix. The previous such value, if any, is freed
843 lookupname (transp
, val
, prefix
)
844 struct trans
*transp
;
851 for (name
= NULL
; transp
-> name
!= NULL
; transp
++)
853 if (transp
-> value
== val
)
855 name
= transp
-> name
;
860 /* Didn't find a translation for the specified value, build a default
861 one using the specified prefix and return it. The lifetime of
862 the value is only until the next one is needed. */
870 locbuf
= xmalloc (strlen (prefix
) + 16);
871 (void) sprintf (locbuf
, "%s %u", prefix
, val
);
883 static char locbuf
[32];
885 for (scp
= siginfo_table
; scp
-> codename
!= NULL
; scp
++)
887 if ((scp
-> signo
== sip
-> si_signo
) &&
888 (scp
-> code
== sip
-> si_code
))
890 name
= scp
-> codename
;
896 (void) sprintf (locbuf
, "sigcode %u", sip
-> si_signo
);
902 static char *sigcodedesc (sip
)
908 for (scp
= siginfo_table
; scp
-> codename
!= NULL
; scp
++)
910 if ((scp
-> signo
== sip
-> si_signo
) &&
911 (scp
-> code
== sip
-> si_code
))
919 desc
= "Unrecognized signal or trap use";
928 syscallname - translate a system call number into a system call name
932 char *syscallname (int syscallnum)
936 Given a system call number, translate it into the printable name
937 of a system call, or into "syscall <num>" if it is an unknown
942 syscallname (syscallnum
)
945 static char locbuf
[32];
948 if (syscallnum
>= 0 && syscallnum
< MAX_SYSCALLS
)
950 rtnval
= syscall_table
[syscallnum
];
954 (void) sprintf (locbuf
, "syscall %u", syscallnum
);
964 init_syscall_table - initialize syscall translation table
968 void init_syscall_table (void)
972 Dynamically initialize the translation table to convert system
973 call numbers into printable system call names. Done once per
974 gdb run, on initialization.
978 This is awfully ugly, but preprocessor tricks to make it prettier
979 tend to be nonportable.
983 init_syscall_table ()
987 #if defined (SYS_exit)
988 syscall_table
[SYS_exit
] = "exit";
990 #if defined (SYS_fork)
991 syscall_table
[SYS_fork
] = "fork";
993 #if defined (SYS_read)
994 syscall_table
[SYS_read
] = "read";
996 #if defined (SYS_write)
997 syscall_table
[SYS_write
] = "write";
999 #if defined (SYS_open)
1000 syscall_table
[SYS_open
] = "open";
1002 #if defined (SYS_close)
1003 syscall_table
[SYS_close
] = "close";
1005 #if defined (SYS_wait)
1006 syscall_table
[SYS_wait
] = "wait";
1008 #if defined (SYS_creat)
1009 syscall_table
[SYS_creat
] = "creat";
1011 #if defined (SYS_link)
1012 syscall_table
[SYS_link
] = "link";
1014 #if defined (SYS_unlink)
1015 syscall_table
[SYS_unlink
] = "unlink";
1017 #if defined (SYS_exec)
1018 syscall_table
[SYS_exec
] = "exec";
1020 #if defined (SYS_execv)
1021 syscall_table
[SYS_execv
] = "execv";
1023 #if defined (SYS_execve)
1024 syscall_table
[SYS_execve
] = "execve";
1026 #if defined (SYS_chdir)
1027 syscall_table
[SYS_chdir
] = "chdir";
1029 #if defined (SYS_time)
1030 syscall_table
[SYS_time
] = "time";
1032 #if defined (SYS_mknod)
1033 syscall_table
[SYS_mknod
] = "mknod";
1035 #if defined (SYS_chmod)
1036 syscall_table
[SYS_chmod
] = "chmod";
1038 #if defined (SYS_chown)
1039 syscall_table
[SYS_chown
] = "chown";
1041 #if defined (SYS_brk)
1042 syscall_table
[SYS_brk
] = "brk";
1044 #if defined (SYS_stat)
1045 syscall_table
[SYS_stat
] = "stat";
1047 #if defined (SYS_lseek)
1048 syscall_table
[SYS_lseek
] = "lseek";
1050 #if defined (SYS_getpid)
1051 syscall_table
[SYS_getpid
] = "getpid";
1053 #if defined (SYS_mount)
1054 syscall_table
[SYS_mount
] = "mount";
1056 #if defined (SYS_umount)
1057 syscall_table
[SYS_umount
] = "umount";
1059 #if defined (SYS_setuid)
1060 syscall_table
[SYS_setuid
] = "setuid";
1062 #if defined (SYS_getuid)
1063 syscall_table
[SYS_getuid
] = "getuid";
1065 #if defined (SYS_stime)
1066 syscall_table
[SYS_stime
] = "stime";
1068 #if defined (SYS_ptrace)
1069 syscall_table
[SYS_ptrace
] = "ptrace";
1071 #if defined (SYS_alarm)
1072 syscall_table
[SYS_alarm
] = "alarm";
1074 #if defined (SYS_fstat)
1075 syscall_table
[SYS_fstat
] = "fstat";
1077 #if defined (SYS_pause)
1078 syscall_table
[SYS_pause
] = "pause";
1080 #if defined (SYS_utime)
1081 syscall_table
[SYS_utime
] = "utime";
1083 #if defined (SYS_stty)
1084 syscall_table
[SYS_stty
] = "stty";
1086 #if defined (SYS_gtty)
1087 syscall_table
[SYS_gtty
] = "gtty";
1089 #if defined (SYS_access)
1090 syscall_table
[SYS_access
] = "access";
1092 #if defined (SYS_nice)
1093 syscall_table
[SYS_nice
] = "nice";
1095 #if defined (SYS_statfs)
1096 syscall_table
[SYS_statfs
] = "statfs";
1098 #if defined (SYS_sync)
1099 syscall_table
[SYS_sync
] = "sync";
1101 #if defined (SYS_kill)
1102 syscall_table
[SYS_kill
] = "kill";
1104 #if defined (SYS_fstatfs)
1105 syscall_table
[SYS_fstatfs
] = "fstatfs";
1107 #if defined (SYS_pgrpsys)
1108 syscall_table
[SYS_pgrpsys
] = "pgrpsys";
1110 #if defined (SYS_xenix)
1111 syscall_table
[SYS_xenix
] = "xenix";
1113 #if defined (SYS_dup)
1114 syscall_table
[SYS_dup
] = "dup";
1116 #if defined (SYS_pipe)
1117 syscall_table
[SYS_pipe
] = "pipe";
1119 #if defined (SYS_times)
1120 syscall_table
[SYS_times
] = "times";
1122 #if defined (SYS_profil)
1123 syscall_table
[SYS_profil
] = "profil";
1125 #if defined (SYS_plock)
1126 syscall_table
[SYS_plock
] = "plock";
1128 #if defined (SYS_setgid)
1129 syscall_table
[SYS_setgid
] = "setgid";
1131 #if defined (SYS_getgid)
1132 syscall_table
[SYS_getgid
] = "getgid";
1134 #if defined (SYS_signal)
1135 syscall_table
[SYS_signal
] = "signal";
1137 #if defined (SYS_msgsys)
1138 syscall_table
[SYS_msgsys
] = "msgsys";
1140 #if defined (SYS_sys3b)
1141 syscall_table
[SYS_sys3b
] = "sys3b";
1143 #if defined (SYS_acct)
1144 syscall_table
[SYS_acct
] = "acct";
1146 #if defined (SYS_shmsys)
1147 syscall_table
[SYS_shmsys
] = "shmsys";
1149 #if defined (SYS_semsys)
1150 syscall_table
[SYS_semsys
] = "semsys";
1152 #if defined (SYS_ioctl)
1153 syscall_table
[SYS_ioctl
] = "ioctl";
1155 #if defined (SYS_uadmin)
1156 syscall_table
[SYS_uadmin
] = "uadmin";
1158 #if defined (SYS_utssys)
1159 syscall_table
[SYS_utssys
] = "utssys";
1161 #if defined (SYS_fsync)
1162 syscall_table
[SYS_fsync
] = "fsync";
1164 #if defined (SYS_umask)
1165 syscall_table
[SYS_umask
] = "umask";
1167 #if defined (SYS_chroot)
1168 syscall_table
[SYS_chroot
] = "chroot";
1170 #if defined (SYS_fcntl)
1171 syscall_table
[SYS_fcntl
] = "fcntl";
1173 #if defined (SYS_ulimit)
1174 syscall_table
[SYS_ulimit
] = "ulimit";
1176 #if defined (SYS_rfsys)
1177 syscall_table
[SYS_rfsys
] = "rfsys";
1179 #if defined (SYS_rmdir)
1180 syscall_table
[SYS_rmdir
] = "rmdir";
1182 #if defined (SYS_mkdir)
1183 syscall_table
[SYS_mkdir
] = "mkdir";
1185 #if defined (SYS_getdents)
1186 syscall_table
[SYS_getdents
] = "getdents";
1188 #if defined (SYS_sysfs)
1189 syscall_table
[SYS_sysfs
] = "sysfs";
1191 #if defined (SYS_getmsg)
1192 syscall_table
[SYS_getmsg
] = "getmsg";
1194 #if defined (SYS_putmsg)
1195 syscall_table
[SYS_putmsg
] = "putmsg";
1197 #if defined (SYS_poll)
1198 syscall_table
[SYS_poll
] = "poll";
1200 #if defined (SYS_lstat)
1201 syscall_table
[SYS_lstat
] = "lstat";
1203 #if defined (SYS_symlink)
1204 syscall_table
[SYS_symlink
] = "symlink";
1206 #if defined (SYS_readlink)
1207 syscall_table
[SYS_readlink
] = "readlink";
1209 #if defined (SYS_setgroups)
1210 syscall_table
[SYS_setgroups
] = "setgroups";
1212 #if defined (SYS_getgroups)
1213 syscall_table
[SYS_getgroups
] = "getgroups";
1215 #if defined (SYS_fchmod)
1216 syscall_table
[SYS_fchmod
] = "fchmod";
1218 #if defined (SYS_fchown)
1219 syscall_table
[SYS_fchown
] = "fchown";
1221 #if defined (SYS_sigprocmask)
1222 syscall_table
[SYS_sigprocmask
] = "sigprocmask";
1224 #if defined (SYS_sigsuspend)
1225 syscall_table
[SYS_sigsuspend
] = "sigsuspend";
1227 #if defined (SYS_sigaltstack)
1228 syscall_table
[SYS_sigaltstack
] = "sigaltstack";
1230 #if defined (SYS_sigaction)
1231 syscall_table
[SYS_sigaction
] = "sigaction";
1233 #if defined (SYS_sigpending)
1234 syscall_table
[SYS_sigpending
] = "sigpending";
1236 #if defined (SYS_context)
1237 syscall_table
[SYS_context
] = "context";
1239 #if defined (SYS_evsys)
1240 syscall_table
[SYS_evsys
] = "evsys";
1242 #if defined (SYS_evtrapret)
1243 syscall_table
[SYS_evtrapret
] = "evtrapret";
1245 #if defined (SYS_statvfs)
1246 syscall_table
[SYS_statvfs
] = "statvfs";
1248 #if defined (SYS_fstatvfs)
1249 syscall_table
[SYS_fstatvfs
] = "fstatvfs";
1251 #if defined (SYS_nfssys)
1252 syscall_table
[SYS_nfssys
] = "nfssys";
1254 #if defined (SYS_waitsys)
1255 syscall_table
[SYS_waitsys
] = "waitsys";
1257 #if defined (SYS_sigsendsys)
1258 syscall_table
[SYS_sigsendsys
] = "sigsendsys";
1260 #if defined (SYS_hrtsys)
1261 syscall_table
[SYS_hrtsys
] = "hrtsys";
1263 #if defined (SYS_acancel)
1264 syscall_table
[SYS_acancel
] = "acancel";
1266 #if defined (SYS_async)
1267 syscall_table
[SYS_async
] = "async";
1269 #if defined (SYS_priocntlsys)
1270 syscall_table
[SYS_priocntlsys
] = "priocntlsys";
1272 #if defined (SYS_pathconf)
1273 syscall_table
[SYS_pathconf
] = "pathconf";
1275 #if defined (SYS_mincore)
1276 syscall_table
[SYS_mincore
] = "mincore";
1278 #if defined (SYS_mmap)
1279 syscall_table
[SYS_mmap
] = "mmap";
1281 #if defined (SYS_mprotect)
1282 syscall_table
[SYS_mprotect
] = "mprotect";
1284 #if defined (SYS_munmap)
1285 syscall_table
[SYS_munmap
] = "munmap";
1287 #if defined (SYS_fpathconf)
1288 syscall_table
[SYS_fpathconf
] = "fpathconf";
1290 #if defined (SYS_vfork)
1291 syscall_table
[SYS_vfork
] = "vfork";
1293 #if defined (SYS_fchdir)
1294 syscall_table
[SYS_fchdir
] = "fchdir";
1296 #if defined (SYS_readv)
1297 syscall_table
[SYS_readv
] = "readv";
1299 #if defined (SYS_writev)
1300 syscall_table
[SYS_writev
] = "writev";
1302 #if defined (SYS_xstat)
1303 syscall_table
[SYS_xstat
] = "xstat";
1305 #if defined (SYS_lxstat)
1306 syscall_table
[SYS_lxstat
] = "lxstat";
1308 #if defined (SYS_fxstat)
1309 syscall_table
[SYS_fxstat
] = "fxstat";
1311 #if defined (SYS_xmknod)
1312 syscall_table
[SYS_xmknod
] = "xmknod";
1314 #if defined (SYS_clocal)
1315 syscall_table
[SYS_clocal
] = "clocal";
1317 #if defined (SYS_setrlimit)
1318 syscall_table
[SYS_setrlimit
] = "setrlimit";
1320 #if defined (SYS_getrlimit)
1321 syscall_table
[SYS_getrlimit
] = "getrlimit";
1323 #if defined (SYS_lchown)
1324 syscall_table
[SYS_lchown
] = "lchown";
1326 #if defined (SYS_memcntl)
1327 syscall_table
[SYS_memcntl
] = "memcntl";
1329 #if defined (SYS_getpmsg)
1330 syscall_table
[SYS_getpmsg
] = "getpmsg";
1332 #if defined (SYS_putpmsg)
1333 syscall_table
[SYS_putpmsg
] = "putpmsg";
1335 #if defined (SYS_rename)
1336 syscall_table
[SYS_rename
] = "rename";
1338 #if defined (SYS_uname)
1339 syscall_table
[SYS_uname
] = "uname";
1341 #if defined (SYS_setegid)
1342 syscall_table
[SYS_setegid
] = "setegid";
1344 #if defined (SYS_sysconfig)
1345 syscall_table
[SYS_sysconfig
] = "sysconfig";
1347 #if defined (SYS_adjtime)
1348 syscall_table
[SYS_adjtime
] = "adjtime";
1350 #if defined (SYS_systeminfo)
1351 syscall_table
[SYS_systeminfo
] = "systeminfo";
1353 #if defined (SYS_seteuid)
1354 syscall_table
[SYS_seteuid
] = "seteuid";
1362 ptrace -- override library version to force errors for /proc version
1366 int ptrace (int request, int pid, int arg3, int arg4)
1370 When gdb is configured to use /proc, it should not be calling
1371 or otherwise attempting to use ptrace. In order to catch errors
1372 where use of /proc is configured, but some routine is still calling
1373 ptrace, we provide a local version of a function with that name
1374 that does nothing but issue an error message.
1378 ptrace (request
, pid
, arg3
, arg4
)
1384 error ("internal error - there is a call to ptrace() somewhere");
1392 kill_inferior_fast -- kill inferior while gdb is exiting
1396 void kill_inferior_fast (void)
1400 This is used when GDB is exiting. It gives less chance of error.
1404 Don't attempt to kill attached inferiors since we may be called
1405 when gdb is in the process of aborting, and killing the attached
1406 inferior may be very anti-social. This is particularly true if we
1407 were attached just so we could use the /proc facilities to get
1408 detailed information about it's status.
1413 kill_inferior_fast ()
1415 if (inferior_pid
!= 0 && !attach_flag
)
1417 unconditionally_kill_inferior ();
1425 kill_inferior - kill any currently inferior
1429 void kill_inferior (void)
1433 Kill any current inferior.
1437 Kills even attached inferiors. Presumably the user has already
1438 been prompted that the inferior is an attached one rather than
1439 one started by gdb. (FIXME?)
1446 if (inferior_pid
!= 0)
1448 unconditionally_kill_inferior ();
1449 target_mourn_inferior ();
1457 unconditionally_kill_inferior - terminate the inferior
1461 static void unconditionally_kill_inferior (void)
1465 Kill the current inferior. Should not be called until it
1466 is at least tested that there is an inferior.
1470 A possibly useful enhancement would be to first try sending
1471 the inferior a terminate signal, politely asking it to commit
1472 suicide, before we murder it.
1477 unconditionally_kill_inferior ()
1482 (void) ioctl (pi
.fd
, PIOCKILL
, &signo
);
1483 close_proc_file (&pi
);
1491 child_xfer_memory -- copy data to or from inferior memory space
1495 int child_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len,
1496 int dowrite, struct target_ops target)
1500 Copy LEN bytes to/from inferior's memory starting at MEMADDR
1501 from/to debugger memory starting at MYADDR. Copy from inferior
1502 if DOWRITE is zero or to inferior if DOWRITE is nonzero.
1504 Returns the length copied, which is either the LEN argument or
1505 zero. This xfer function does not do partial moves, since child_ops
1506 doesn't allow memory operations to cross below us in the target stack
1511 The /proc interface makes this an almost trivial task.
1516 child_xfer_memory (memaddr
, myaddr
, len
, dowrite
, target
)
1521 struct target_ops
*target
; /* ignored */
1525 if (lseek (pi
.fd
, (off_t
) memaddr
, 0) == (off_t
) memaddr
)
1529 nbytes
= write (pi
.fd
, myaddr
, len
);
1533 nbytes
= read (pi
.fd
, myaddr
, len
);
1547 store_inferior_registers -- copy register values back to inferior
1551 void store_inferior_registers (int regno)
1555 Store our current register values back into the inferior. If
1556 REGNO is -1 then store all the register, otherwise store just
1557 the value specified by REGNO.
1561 If we are storing only a single register, we first have to get all
1562 the current values from the process, overwrite the desired register
1563 in the gregset with the one we want from gdb's registers, and then
1564 send the whole set back to the process. For writing all the
1565 registers, all we have to do is generate the gregset and send it to
1568 Also note that the process has to be stopped on an event of interest
1569 for this to work, which basically means that it has to have been
1570 run under the control of one of the other /proc ioctl calls and not
1571 ptrace. Since we don't use ptrace anyway, we don't worry about this
1572 fine point, but it is worth noting for future reference.
1574 Gdb is confused about what this function is supposed to return.
1575 Some versions return a value, others return nothing. Some are
1576 declared to return a value and actually return nothing. Gdb ignores
1577 anything returned. (FIXME)
1582 store_inferior_registers (regno
)
1587 (void) ioctl (pi
.fd
, PIOCGREG
, &pi
.gregset
);
1589 fill_gregset (&pi
.gregset
, regno
);
1590 (void) ioctl (pi
.fd
, PIOCSREG
, &pi
.gregset
);
1592 #if defined (FP0_REGNUM)
1594 /* Now repeat everything using the floating point register set, if the
1595 target has floating point hardware. Since we ignore the returned value,
1596 we'll never know whether it worked or not anyway. */
1600 (void) ioctl (pi
.fd
, PIOCGFPREG
, &pi
.fpregset
);
1602 fill_fpregset (&pi
.fpregset
, regno
);
1603 (void) ioctl (pi
.fd
, PIOCSFPREG
, &pi
.fpregset
);
1605 #endif /* FP0_REGNUM */
1613 inferior_proc_init - initialize access to a /proc entry
1617 void inferior_proc_init (int pid)
1621 When gdb starts an inferior, this function is called in the parent
1622 process immediately after the fork. It waits for the child to stop
1623 on the return from the exec system call (the child itself takes care
1624 of ensuring that this is set up), then sets up the set of signals
1625 and faults that are to be traced.
1629 If proc_init_failed ever gets called, control returns to the command
1630 processing loop via the standard error handling code.
1635 inferior_proc_init (pid
)
1638 if (!open_proc_file (pid
, &pi
))
1640 proc_init_failed ("can't open process file");
1644 (void) memset ((char *) &pi
.prrun
, 0, sizeof (pi
.prrun
));
1645 prfillset (&pi
.prrun
.pr_trace
);
1646 proc_signal_handling_change ();
1647 prfillset (&pi
.prrun
.pr_fault
);
1648 prdelset (&pi
.prrun
.pr_fault
, FLTPAGE
);
1649 if (ioctl (pi
.fd
, PIOCWSTOP
, &pi
.prstatus
) < 0)
1651 proc_init_failed ("PIOCWSTOP failed");
1653 else if (ioctl (pi
.fd
, PIOCSFAULT
, &pi
.prrun
.pr_fault
) < 0)
1655 proc_init_failed ("PIOCSFAULT failed");
1664 proc_signal_handling_change
1668 void proc_signal_handling_change (void);
1672 When the user changes the state of gdb's signal handling via the
1673 "handle" command, this function gets called to see if any change
1674 in the /proc interface is required. It is also called internally
1675 by other /proc interface functions to initialize the state of
1676 the traced signal set.
1678 One thing it does is that signals for which the state is "nostop",
1679 "noprint", and "pass", have their trace bits reset in the pr_trace
1680 field, so that they are no longer traced. This allows them to be
1681 delivered directly to the inferior without the debugger ever being
1686 proc_signal_handling_change ()
1692 for (signo
= 0; signo
< NSIG
; signo
++)
1694 if (signal_stop_state (signo
) == 0 &&
1695 signal_print_state (signo
) == 0 &&
1696 signal_pass_state (signo
) == 1)
1698 prdelset (&pi
.prrun
.pr_trace
, signo
);
1702 praddset (&pi
.prrun
.pr_trace
, signo
);
1705 if (ioctl (pi
.fd
, PIOCSTRACE
, &pi
.prrun
.pr_trace
))
1707 print_sys_errmsg ("PIOCSTRACE failed", errno
);
1716 proc_set_exec_trap -- arrange for exec'd child to halt at startup
1720 void proc_set_exec_trap (void)
1724 This function is called in the child process when starting up
1725 an inferior, prior to doing the exec of the actual inferior.
1726 It sets the child process's exitset to make exit from the exec
1727 system call an event of interest to stop on, and then simply
1728 returns. The child does the exec, the system call returns, and
1729 the child stops at the first instruction, ready for the gdb
1730 parent process to take control of it.
1734 We need to use all local variables since the child may be sharing
1735 it's data space with the parent, if vfork was used rather than
1738 Also note that we want to turn off the inherit-on-fork flag in
1739 the child process so that any grand-children start with all
1740 tracing flags cleared.
1744 proc_set_exec_trap ()
1747 auto char procname
[32];
1750 (void) sprintf (procname
, PROC_NAME_FMT
, getpid ());
1751 if ((fd
= open (procname
, O_RDWR
)) < 0)
1757 premptyset (&exitset
);
1760 Not all systems with /proc have all the exec* syscalls with the same
1761 names. On the SGI, for example, there is no SYS_exec, but there
1762 *is* a SYS_execv. So, we try to account for that. */
1765 praddset (&exitset
, SYS_exec
);
1768 praddset (&exitset
, SYS_execve
);
1771 praddset(&exitset
, SYS_execv
);
1774 if (ioctl (fd
, PIOCSEXIT
, &exitset
) < 0)
1781 /* Turn off inherit-on-fork flag so that all grand-children of gdb
1782 start with tracing flags cleared. */
1784 #ifdef PIOCRFORK /* Standard SVR4 */
1785 (void) ioctl (fd
, PIOCRFORK
, NULL
);
1787 #ifdef PIOCRESET /* iris (for example) */
1791 (void) ioctl (fd
, PIOCRESET
, &pr_flags
);
1801 proc_iterate_over_mappings -- call function for every mapped space
1805 int proc_iterate_over_mappings (int (*func)())
1809 Given a pointer to a function, call that function for every
1810 mapped address space, passing it an open file descriptor for
1811 the file corresponding to that mapped address space (if any)
1812 and the base address of the mapped space. Quit when we hit
1813 the end of the mappings or the function returns nonzero.
1817 proc_iterate_over_mappings (func
)
1818 int (*func
) PARAMS ((int, CORE_ADDR
));
1823 struct prmap
*prmaps
;
1824 struct prmap
*prmap
;
1825 CORE_ADDR baseaddr
= 0;
1827 if (pi
.valid
&& (ioctl (pi
.fd
, PIOCNMAP
, &nmap
) == 0))
1829 prmaps
= (struct prmap
*) alloca ((nmap
+ 1) * sizeof (*prmaps
));
1830 if (ioctl (pi
.fd
, PIOCMAP
, prmaps
) == 0)
1832 for (prmap
= prmaps
; prmap
-> pr_size
&& funcstat
== 0; ++prmap
)
1834 fd
= proc_address_to_fd ((CORE_ADDR
) prmap
-> pr_vaddr
, 0);
1835 funcstat
= (*func
) (fd
, (CORE_ADDR
) prmap
-> pr_vaddr
);
1847 proc_base_address -- find base address for segment containing address
1851 CORE_ADDR proc_base_address (CORE_ADDR addr)
1855 Given an address of a location in the inferior, find and return
1856 the base address of the mapped segment containing that address.
1858 This is used for example, by the shared library support code,
1859 where we have the pc value for some location in the shared library
1860 where we are stopped, and need to know the base address of the
1861 segment containing that address.
1865 #if 0 /* Currently unused */
1868 proc_base_address (addr
)
1872 struct prmap
*prmaps
;
1873 struct prmap
*prmap
;
1874 CORE_ADDR baseaddr
= 0;
1876 if (pi
.valid
&& (ioctl (pi
.fd
, PIOCNMAP
, &nmap
) == 0))
1878 prmaps
= (struct prmap
*) alloca ((nmap
+ 1) * sizeof (*prmaps
));
1879 if (ioctl (pi
.fd
, PIOCMAP
, prmaps
) == 0)
1881 for (prmap
= prmaps
; prmap
-> pr_size
; ++prmap
)
1883 if ((prmap
-> pr_vaddr
<= (caddr_t
) addr
) &&
1884 (prmap
-> pr_vaddr
+ prmap
-> pr_size
> (caddr_t
) addr
))
1886 baseaddr
= (CORE_ADDR
) prmap
-> pr_vaddr
;
1901 proc_address_to_fd -- return open fd for file mapped to address
1905 int proc_address_to_fd (CORE_ADDR addr, complain)
1909 Given an address in the current inferior's address space, use the
1910 /proc interface to find an open file descriptor for the file that
1911 this address was mapped in from. Return -1 if there is no current
1912 inferior. Print a warning message if there is an inferior but
1913 the address corresponds to no file (IE a bogus address).
1918 proc_address_to_fd (addr
, complain
)
1926 if ((fd
= ioctl (pi
.fd
, PIOCOPENM
, (caddr_t
*) &addr
)) < 0)
1930 print_sys_errmsg (pi
.pathname
, errno
);
1931 warning ("can't find mapped file for address 0x%x", addr
);
1939 #ifdef ATTACH_DETACH
1945 attach -- attach to an already existing process
1949 int attach (int pid)
1953 Attach to an already existing process with the specified process
1954 id. If the process is not already stopped, query whether to
1959 The option of stopping at attach time is specific to the /proc
1960 versions of gdb. Versions using ptrace force the attachee
1969 if (!open_proc_file (pid
, &pi
))
1971 perror_with_name (pi
.pathname
);
1975 /* Get current status of process and if it is not already stopped,
1976 then stop it. Remember whether or not it was stopped when we first
1979 if (ioctl (pi
.fd
, PIOCSTATUS
, &pi
.prstatus
) < 0)
1981 print_sys_errmsg (pi
.pathname
, errno
);
1982 close_proc_file (&pi
);
1983 error ("PIOCSTATUS failed");
1985 if (pi
.prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
))
1992 if (query ("Process is currently running, stop it? "))
1994 if (ioctl (pi
.fd
, PIOCSTOP
, &pi
.prstatus
) < 0)
1996 print_sys_errmsg (pi
.pathname
, errno
);
1997 close_proc_file (&pi
);
1998 error ("PIOCSTOP failed");
2003 /* Remember some things about the inferior that we will, or might, change
2004 so that we can restore them when we detach. */
2006 (void) ioctl (pi
.fd
, PIOCGTRACE
, &pi
.saved_trace
);
2007 (void) ioctl (pi
.fd
, PIOCGHOLD
, &pi
.saved_sighold
);
2008 (void) ioctl (pi
.fd
, PIOCGFAULT
, &pi
.saved_fltset
);
2009 (void) ioctl (pi
.fd
, PIOCGENTRY
, &pi
.saved_entryset
);
2010 (void) ioctl (pi
.fd
, PIOCGEXIT
, &pi
.saved_exitset
);
2012 /* Set up trace and fault sets, as gdb expects them. */
2014 (void) memset (&pi
.prrun
, 0, sizeof (pi
.prrun
));
2015 prfillset (&pi
.prrun
.pr_trace
);
2016 proc_signal_handling_change ();
2017 prfillset (&pi
.prrun
.pr_fault
);
2018 prdelset (&pi
.prrun
.pr_fault
, FLTPAGE
);
2019 if (ioctl (pi
.fd
, PIOCSFAULT
, &pi
.prrun
.pr_fault
))
2021 print_sys_errmsg ("PIOCSFAULT failed", errno
);
2023 if (ioctl (pi
.fd
, PIOCSTRACE
, &pi
.prrun
.pr_trace
))
2025 print_sys_errmsg ("PIOCSTRACE failed", errno
);
2035 detach -- detach from an attached-to process
2039 void detach (int signal)
2043 Detach from the current attachee.
2045 If signal is non-zero, the attachee is started running again and sent
2046 the specified signal.
2048 If signal is zero and the attachee was not already stopped when we
2049 attached to it, then we make it runnable again when we detach.
2051 Otherwise, we query whether or not to make the attachee runnable
2052 again, since we may simply want to leave it in the state it was in
2055 We report any problems, but do not consider them errors, since we
2056 MUST detach even if some things don't seem to go right. This may not
2057 be the ideal situation. (FIXME).
2066 set_proc_siginfo (&pi
, signal
);
2068 if (ioctl (pi
.fd
, PIOCSEXIT
, &pi
.saved_exitset
) < 0)
2070 print_sys_errmsg (pi
.pathname
, errno
);
2071 printf ("PIOCSEXIT failed.\n");
2073 if (ioctl (pi
.fd
, PIOCSENTRY
, &pi
.saved_entryset
) < 0)
2075 print_sys_errmsg (pi
.pathname
, errno
);
2076 printf ("PIOCSENTRY failed.\n");
2078 if (ioctl (pi
.fd
, PIOCSTRACE
, &pi
.saved_trace
) < 0)
2080 print_sys_errmsg (pi
.pathname
, errno
);
2081 printf ("PIOCSTRACE failed.\n");
2083 if (ioctl (pi
.fd
, PIOCSHOLD
, &pi
.saved_sighold
) < 0)
2085 print_sys_errmsg (pi
.pathname
, errno
);
2086 printf ("PIOSCHOLD failed.\n");
2088 if (ioctl (pi
.fd
, PIOCSFAULT
, &pi
.saved_fltset
) < 0)
2090 print_sys_errmsg (pi
.pathname
, errno
);
2091 printf ("PIOCSFAULT failed.\n");
2093 if (ioctl (pi
.fd
, PIOCSTATUS
, &pi
.prstatus
) < 0)
2095 print_sys_errmsg (pi
.pathname
, errno
);
2096 printf ("PIOCSTATUS failed.\n");
2100 if (signal
|| (pi
.prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
)))
2102 if (signal
|| !pi
.was_stopped
||
2103 query ("Was stopped when attached, make it runnable again? "))
2105 (void) memset (&pi
.prrun
, 0, sizeof (pi
.prrun
));
2106 pi
.prrun
.pr_flags
= PRCFAULT
;
2107 if (ioctl (pi
.fd
, PIOCRUN
, &pi
.prrun
))
2109 print_sys_errmsg (pi
.pathname
, errno
);
2110 printf ("PIOCRUN failed.\n");
2115 close_proc_file (&pi
);
2119 #endif /* ATTACH_DETACH */
2125 proc_wait -- emulate wait() as much as possible
2129 int proc_wait (int *statloc)
2133 Try to emulate wait() as much as possible. Not sure why we can't
2134 just use wait(), but it seems to have problems when applied to a
2135 process being controlled with the /proc interface.
2139 We have a race problem here with no obvious solution. We need to let
2140 the inferior run until it stops on an event of interest, which means
2141 that we need to use the PIOCWSTOP ioctl. However, we cannot use this
2142 ioctl if the process is already stopped on something that is not an
2143 event of interest, or the call will hang indefinitely. Thus we first
2144 use PIOCSTATUS to see if the process is not stopped. If not, then we
2145 use PIOCWSTOP. But during the window between the two, if the process
2146 stops for any reason that is not an event of interest (such as a job
2147 control signal) then gdb will hang. One possible workaround is to set
2148 an alarm to wake up every minute of so and check to see if the process
2149 is still running, and if so, then reissue the PIOCWSTOP. But this is
2150 a real kludge, so has not been implemented. FIXME: investigate
2153 FIXME: Investigate why wait() seems to have problems with programs
2154 being control by /proc routines.
2168 if (ioctl (pi
.fd
, PIOCSTATUS
, &pi
.prstatus
) < 0)
2172 else if (!(pi
.prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
)))
2174 if (ioctl (pi
.fd
, PIOCWSTOP
, &pi
.prstatus
) < 0)
2181 if (errno
== ENOENT
)
2183 rtnval
= wait (&statval
);
2184 if (rtnval
!= inferior_pid
)
2186 error ("PIOCWSTOP, wait failed, returned %d", rtnval
);
2192 print_sys_errmsg (pi
.pathname
, errno
);
2193 error ("PIOCSTATUS or PIOCWSTOP failed.");
2197 else if (pi
.prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
))
2199 rtnval
= pi
.prstatus
.pr_pid
;
2200 why
= pi
.prstatus
.pr_why
;
2201 what
= pi
.prstatus
.pr_what
;
2202 if (why
== PR_SIGNALLED
)
2204 statval
= (what
<< 8) | 0177;
2206 else if ((why
== PR_SYSEXIT
)
2215 || what
== SYS_execve
2218 || what
== SYS_execv
2222 statval
= (SIGTRAP
<< 8) | 0177;
2224 else if (why
== PR_REQUESTED
)
2226 statval
= (SIGSTOP
<< 8) | 0177;
2228 else if (why
== PR_JOBCONTROL
)
2230 statval
= (what
<< 8) | 0177;
2232 else if (why
== PR_FAULTED
)
2238 statval
= (SIGILL
<< 8) | 0177;
2242 statval
= (SIGTRAP
<< 8) | 0177;
2247 statval
= (SIGSEGV
<< 8) | 0177;
2252 statval
= (SIGFPE
<< 8) | 0177;
2254 case FLTPAGE
: /* Recoverable page fault */
2257 error ("PIOCWSTOP, unknown why %d, what %d", why
, what
);
2264 error ("PIOCWSTOP, unknown why %d, what %d", why
, what
);
2270 error ("PIOCWSTOP, stopped for unknown/unhandled reason, flags %#x",
2271 pi
.prstatus
.pr_flags
);
2285 set_proc_siginfo - set a process's current signal info
2289 void set_proc_siginfo (struct procinfo *pip, int signo);
2293 Given a pointer to a process info struct in PIP and a signal number
2294 in SIGNO, set the process's current signal and its associated signal
2295 information. The signal will be delivered to the process immediately
2296 after execution is resumed, even if it is being held. In addition,
2297 this particular delivery will not cause another PR_SIGNALLED stop
2298 even if the signal is being traced.
2300 If we are not delivering the same signal that the prstatus siginfo
2301 struct contains information about, then synthesize a siginfo struct
2302 to match the signal we are doing to deliver, make it of the type
2303 "generated by a user process", and send this synthesized copy. When
2304 used to set the inferior's signal state, this will be required if we
2305 are not currently stopped because of a traced signal, or if we decide
2306 to continue with a different signal.
2308 Note that when continuing the inferior from a stop due to receipt
2309 of a traced signal, we either have set PRCSIG to clear the existing
2310 signal, or we have to call this function to do a PIOCSSIG with either
2311 the existing siginfo struct from pr_info, or one we have synthesized
2312 appropriately for the signal we want to deliver. Otherwise if the
2313 signal is still being traced, the inferior will immediately stop
2316 See siginfo(5) for more details.
2320 set_proc_siginfo (pip
, signo
)
2321 struct procinfo
*pip
;
2324 struct siginfo newsiginfo
;
2325 struct siginfo
*sip
;
2329 if (signo
== pip
-> prstatus
.pr_info
.si_signo
)
2331 sip
= &pip
-> prstatus
.pr_info
;
2335 (void) memset ((char *) &newsiginfo
, 0, sizeof (newsiginfo
));
2337 sip
-> si_signo
= signo
;
2339 sip
-> si_errno
= 0;
2340 sip
-> si_pid
= getpid ();
2341 sip
-> si_uid
= getuid ();
2343 if (ioctl (pip
-> fd
, PIOCSSIG
, sip
) < 0)
2345 print_sys_errmsg (pip
-> pathname
, errno
);
2346 warning ("PIOCSSIG failed");
2355 child_resume -- resume execution of the inferior process
2359 void child_resume (int step, int signo)
2363 Resume execution of the inferior process. If STEP is nozero, then
2364 just single step it. If SIGNAL is nonzero, restart it with that
2369 It may not be absolutely necessary to specify the PC value for
2370 restarting, but to be safe we use the value that gdb considers
2371 to be current. One case where this might be necessary is if the
2372 user explicitly changes the PC value that gdb considers to be
2373 current. FIXME: Investigate if this is necessary or not.
2377 child_resume (step
, signo
)
2382 pi
.prrun
.pr_flags
= PRSVADDR
| PRSTRACE
| PRSFAULT
| PRCFAULT
;
2383 pi
.prrun
.pr_vaddr
= (caddr_t
) *(int *) ®isters
[REGISTER_BYTE (PC_REGNUM
)];
2386 set_proc_siginfo (&pi
, signo
);
2390 pi
.prrun
.pr_flags
|= PRCSIG
;
2394 pi
.prrun
.pr_flags
|= PRSTEP
;
2396 if (ioctl (pi
.fd
, PIOCRUN
, &pi
.prrun
) != 0)
2398 perror_with_name (pi
.pathname
);
2407 fetch_inferior_registers -- fetch current registers from inferior
2411 void fetch_inferior_registers (int regno)
2415 Read the current values of the inferior's registers, both the
2416 general register set and floating point registers (if supported)
2417 and update gdb's idea of their current values.
2422 fetch_inferior_registers (regno
)
2425 if (ioctl (pi
.fd
, PIOCGREG
, &pi
.gregset
) != -1)
2427 supply_gregset (&pi
.gregset
);
2429 #if defined (FP0_REGNUM)
2430 if (ioctl (pi
.fd
, PIOCGFPREG
, &pi
.fpregset
) != -1)
2432 supply_fpregset (&pi
.fpregset
);
2441 fetch_core_registers -- fetch current registers from core file data
2445 void fetch_core_registers (char *core_reg_sect, unsigned core_reg_size,
2446 int which, unsigned in reg_addr)
2450 Read the values of either the general register set (WHICH equals 0)
2451 or the floating point register set (WHICH equals 2) from the core
2452 file data (pointed to by CORE_REG_SECT), and update gdb's idea of
2453 their current values. The CORE_REG_SIZE parameter is ignored.
2457 Use the indicated sizes to validate the gregset and fpregset
2462 fetch_core_registers (core_reg_sect
, core_reg_size
, which
, reg_addr
)
2463 char *core_reg_sect
;
2464 unsigned core_reg_size
;
2466 unsigned int reg_addr
; /* Unused in this version */
2471 if (core_reg_size
!= sizeof (pi
.gregset
))
2473 warning ("wrong size gregset struct in core file");
2477 (void) memcpy ((char *) &pi
.gregset
, core_reg_sect
,
2478 sizeof (pi
.gregset
));
2479 supply_gregset (&pi
.gregset
);
2482 else if (which
== 2)
2484 if (core_reg_size
!= sizeof (pi
.fpregset
))
2486 warning ("wrong size fpregset struct in core file");
2490 (void) memcpy ((char *) &pi
.fpregset
, core_reg_sect
,
2491 sizeof (pi
.fpregset
));
2492 #if defined (FP0_REGNUM)
2493 supply_fpregset (&pi
.fpregset
);
2503 proc_init_failed - called whenever /proc access initialization fails
2507 static void proc_init_failed (char *why)
2511 This function is called whenever initialization of access to a /proc
2512 entry fails. It prints a suitable error message, does some cleanup,
2513 and then invokes the standard error processing routine which dumps
2514 us back into the command loop.
2518 proc_init_failed (why
)
2521 print_sys_errmsg (pi
.pathname
, errno
);
2522 (void) kill (pi
.pid
, SIGKILL
);
2523 close_proc_file (&pi
);
2532 close_proc_file - close any currently open /proc entry
2536 static void close_proc_file (struct procinfo *pip)
2540 Close any currently open /proc entry and mark the process information
2541 entry as invalid. In order to ensure that we don't try to reuse any
2542 stale information, the pid, fd, and pathnames are explicitly
2543 invalidated, which may be overkill.
2548 close_proc_file (pip
)
2549 struct procinfo
*pip
;
2554 (void) close (pip
-> fd
);
2557 if (pip
-> pathname
)
2559 free (pip
-> pathname
);
2560 pip
-> pathname
= NULL
;
2569 open_proc_file - open a /proc entry for a given process id
2573 static int open_proc_file (pid, struct procinfo *pip)
2577 Given a process id, close the existing open /proc entry (if any)
2578 and open one for the new process id. Once it is open, then
2579 mark the local process information structure as valid, which
2580 guarantees that the pid, fd, and pathname fields match an open
2581 /proc entry. Returns zero if the open fails, nonzero otherwise.
2583 Note that the pathname is left intact, even when the open fails,
2584 so that callers can use it to construct meaningful error messages
2585 rather than just "file open failed".
2589 open_proc_file (pid
, pip
)
2591 struct procinfo
*pip
;
2596 (void) close (pip
-> fd
);
2598 if (pip
-> pathname
== NULL
)
2600 pip
-> pathname
= xmalloc (32);
2602 sprintf (pip
-> pathname
, PROC_NAME_FMT
, pid
);
2603 if ((pip
-> fd
= open (pip
-> pathname
, O_RDWR
)) >= 0)
2608 return (pip
-> valid
);
2612 mappingflags (flags
)
2615 static char asciiflags
[7];
2617 strcpy (asciiflags
, "------");
2618 if (flags
& MA_STACK
) asciiflags
[0] = 's';
2619 if (flags
& MA_BREAK
) asciiflags
[1] = 'b';
2620 if (flags
& MA_SHARED
) asciiflags
[2] = 's';
2621 if (flags
& MA_READ
) asciiflags
[3] = 'r';
2622 if (flags
& MA_WRITE
) asciiflags
[4] = 'w';
2623 if (flags
& MA_EXEC
) asciiflags
[5] = 'x';
2624 return (asciiflags
);
2628 info_proc_flags (pip
, summary
)
2629 struct procinfo
*pip
;
2632 struct trans
*transp
;
2634 printf_filtered ("%-32s", "Process status flags:");
2637 printf_filtered ("\n\n");
2639 for (transp
= pr_flag_table
; transp
-> name
!= NULL
; transp
++)
2641 if (pip
-> prstatus
.pr_flags
& transp
-> value
)
2645 printf_filtered ("%s ", transp
-> name
);
2649 printf_filtered ("\t%-16s %s.\n", transp
-> name
, transp
-> desc
);
2653 printf_filtered ("\n");
2657 info_proc_stop (pip
, summary
)
2658 struct procinfo
*pip
;
2661 struct trans
*transp
;
2665 why
= pip
-> prstatus
.pr_why
;
2666 what
= pip
-> prstatus
.pr_what
;
2668 if (pip
-> prstatus
.pr_flags
& PR_STOPPED
)
2670 printf_filtered ("%-32s", "Reason for stopping:");
2673 printf_filtered ("\n\n");
2675 for (transp
= pr_why_table
; transp
-> name
!= NULL
; transp
++)
2677 if (why
== transp
-> value
)
2681 printf_filtered ("%s ", transp
-> name
);
2685 printf_filtered ("\t%-16s %s.\n",
2686 transp
-> name
, transp
-> desc
);
2692 /* Use the pr_why field to determine what the pr_what field means, and
2693 print more information. */
2698 /* pr_what is unused for this case */
2704 printf_filtered ("%s ", signalname (what
));
2708 printf_filtered ("\t%-16s %s.\n", signalname (what
),
2715 printf_filtered ("%s ", syscallname (what
));
2719 printf_filtered ("\t%-16s %s.\n", syscallname (what
),
2720 "Entered this system call");
2726 printf_filtered ("%s ", syscallname (what
));
2730 printf_filtered ("\t%-16s %s.\n", syscallname (what
),
2731 "Returned from this system call");
2737 printf_filtered ("%s ",
2738 lookupname (faults_table
, what
, "fault"));
2742 printf_filtered ("\t%-16s %s.\n",
2743 lookupname (faults_table
, what
, "fault"),
2744 lookupdesc (faults_table
, what
));
2748 printf_filtered ("\n");
2753 info_proc_siginfo (pip
, summary
)
2754 struct procinfo
*pip
;
2757 struct siginfo
*sip
;
2759 if ((pip
-> prstatus
.pr_flags
& PR_STOPPED
) &&
2760 (pip
-> prstatus
.pr_why
== PR_SIGNALLED
||
2761 pip
-> prstatus
.pr_why
== PR_FAULTED
))
2763 printf_filtered ("%-32s", "Additional signal/fault info:");
2764 sip
= &pip
-> prstatus
.pr_info
;
2767 printf_filtered ("%s ", signalname (sip
-> si_signo
));
2768 if (sip
-> si_errno
> 0)
2770 printf_filtered ("%s ", lookupname (errno_table
,
2771 sip
-> si_errno
, "errno"));
2773 if (sip
-> si_code
<= 0)
2775 printf_filtered ("sent by pid %d, uid %d ", sip
-> si_pid
,
2780 printf_filtered ("%s ", sigcodename (sip
));
2781 if ((sip
-> si_signo
== SIGILL
) ||
2782 (sip
-> si_signo
== SIGFPE
) ||
2783 (sip
-> si_signo
== SIGSEGV
) ||
2784 (sip
-> si_signo
== SIGBUS
))
2786 printf_filtered ("addr=%#x ", sip
-> si_addr
);
2788 else if ((sip
-> si_signo
== SIGCHLD
))
2790 printf_filtered ("child pid %u, status %u ",
2794 else if ((sip
-> si_signo
== SIGPOLL
))
2796 printf_filtered ("band %u ", sip
-> si_band
);
2802 printf_filtered ("\n\n");
2803 printf_filtered ("\t%-16s %s.\n", signalname (sip
-> si_signo
),
2804 sys_siglist
[sip
-> si_signo
]);
2805 if (sip
-> si_errno
> 0)
2807 printf_filtered ("\t%-16s %s.\n",
2808 lookupname (errno_table
,
2809 sip
-> si_errno
, "errno"),
2810 lookupdesc (errno_table
, sip
-> si_errno
));
2812 if (sip
-> si_code
<= 0)
2814 printf_filtered ("\t%-16u %s\n", sip
-> si_pid
,
2815 "PID of process sending signal");
2816 printf_filtered ("\t%-16u %s\n", sip
-> si_uid
,
2817 "UID of process sending signal");
2821 printf_filtered ("\t%-16s %s.\n", sigcodename (sip
),
2823 if ((sip
-> si_signo
== SIGILL
) ||
2824 (sip
-> si_signo
== SIGFPE
))
2826 printf_filtered ("\t%-16#x %s.\n", sip
-> si_addr
,
2827 "Address of faulting instruction");
2829 else if ((sip
-> si_signo
== SIGSEGV
) ||
2830 (sip
-> si_signo
== SIGBUS
))
2832 printf_filtered ("\t%-16#x %s.\n", sip
-> si_addr
,
2833 "Address of faulting memory reference");
2835 else if ((sip
-> si_signo
== SIGCHLD
))
2837 printf_filtered ("\t%-16u %s.\n", sip
-> si_pid
,
2838 "Child process ID");
2839 printf_filtered ("\t%-16u %s.\n", sip
-> si_status
,
2840 "Child process exit value or signal");
2842 else if ((sip
-> si_signo
== SIGPOLL
))
2844 printf_filtered ("\t%-16u %s.\n", sip
-> si_band
,
2845 "Band event for POLL_{IN,OUT,MSG}");
2849 printf_filtered ("\n");
2854 info_proc_syscalls (pip
, summary
)
2855 struct procinfo
*pip
;
2863 #if 0 /* FIXME: Needs to use gdb-wide configured info about system calls. */
2864 if (pip
-> prstatus
.pr_flags
& PR_ASLEEP
)
2866 int syscallnum
= pip
-> prstatus
.pr_reg
[R_D0
];
2869 printf_filtered ("%-32s", "Sleeping in system call:");
2870 printf_filtered ("%s", syscallname (syscallnum
));
2874 printf_filtered ("Sleeping in system call '%s'.\n",
2875 syscallname (syscallnum
));
2880 if (ioctl (pip
-> fd
, PIOCGENTRY
, &pip
-> entryset
) < 0)
2882 print_sys_errmsg (pip
-> pathname
, errno
);
2883 error ("PIOCGENTRY failed");
2886 if (ioctl (pip
-> fd
, PIOCGEXIT
, &pip
-> exitset
) < 0)
2888 print_sys_errmsg (pip
-> pathname
, errno
);
2889 error ("PIOCGEXIT failed");
2892 printf_filtered ("System call tracing information:\n\n");
2894 printf_filtered ("\t%-12s %-8s %-8s\n",
2898 for (syscallnum
= 0; syscallnum
< MAX_SYSCALLS
; syscallnum
++)
2901 if (syscall_table
[syscallnum
] != NULL
)
2903 printf_filtered ("\t%-12s ", syscall_table
[syscallnum
]);
2904 printf_filtered ("%-8s ",
2905 prismember (&pip
-> entryset
, syscallnum
)
2907 printf_filtered ("%-8s ",
2908 prismember (&pip
-> exitset
, syscallnum
)
2910 printf_filtered ("\n");
2913 printf_filtered ("\n");
2922 static char locbuf
[32];
2924 abbrev
= sig_abbrev (signo
);
2927 sprintf (locbuf
, "signal %d", signo
);
2931 sprintf (locbuf
, "SIG%s (%d)", abbrev
, signo
);
2937 info_proc_signals (pip
, summary
)
2938 struct procinfo
*pip
;
2945 if (ioctl (pip
-> fd
, PIOCGTRACE
, &pip
-> trace
) < 0)
2947 print_sys_errmsg (pip
-> pathname
, errno
);
2948 error ("PIOCGTRACE failed");
2951 printf_filtered ("Disposition of signals:\n\n");
2952 printf_filtered ("\t%-15s %-8s %-8s %-8s %s\n\n",
2953 "Signal", "Trace", "Hold", "Pending", "Description");
2954 for (signo
= 0; signo
< NSIG
; signo
++)
2957 printf_filtered ("\t%-15s ", signalname (signo
));
2958 printf_filtered ("%-8s ",
2959 prismember (&pip
-> trace
, signo
)
2961 printf_filtered ("%-8s ",
2962 prismember (&pip
-> prstatus
.pr_sighold
, signo
)
2964 printf_filtered ("%-8s ",
2965 prismember (&pip
-> prstatus
.pr_sigpend
, signo
)
2967 printf_filtered (" %s\n", sys_siglist
[signo
]);
2969 printf_filtered ("\n");
2974 info_proc_faults (pip
, summary
)
2975 struct procinfo
*pip
;
2978 struct trans
*transp
;
2982 if (ioctl (pip
-> fd
, PIOCGFAULT
, &pip
-> fltset
) < 0)
2984 print_sys_errmsg (pip
-> pathname
, errno
);
2985 error ("PIOCGFAULT failed");
2988 printf_filtered ("Current traced hardware fault set:\n\n");
2989 printf_filtered ("\t%-12s %-8s\n", "Fault", "Trace");
2991 for (transp
= faults_table
; transp
-> name
!= NULL
; transp
++)
2994 printf_filtered ("\t%-12s ", transp
-> name
);
2995 printf_filtered ("%-8s", prismember (&pip
-> fltset
, transp
-> value
)
2997 printf_filtered ("\n");
2999 printf_filtered ("\n");
3004 info_proc_mappings (pip
, summary
)
3005 struct procinfo
*pip
;
3009 struct prmap
*prmaps
;
3010 struct prmap
*prmap
;
3014 printf_filtered ("Mapped address spaces:\n\n");
3015 printf_filtered ("\t%10s %10s %10s %10s %6s\n",
3021 if (ioctl (pip
-> fd
, PIOCNMAP
, &nmap
) == 0)
3023 prmaps
= (struct prmap
*) alloca ((nmap
+ 1) * sizeof (*prmaps
));
3024 if (ioctl (pip
-> fd
, PIOCMAP
, prmaps
) == 0)
3026 for (prmap
= prmaps
; prmap
-> pr_size
; ++prmap
)
3028 printf_filtered ("\t%#10x %#10x %#10x %#10x %6s\n",
3030 prmap
-> pr_vaddr
+ prmap
-> pr_size
- 1,
3033 mappingflags (prmap
-> pr_mflags
));
3037 printf_filtered ("\n");
3045 info_proc -- implement the "info proc" command
3049 void info_proc (char *args, int from_tty)
3053 Implement gdb's "info proc" command by using the /proc interface
3054 to print status information about any currently running process.
3056 Examples of the use of "info proc" are:
3058 info proc (prints summary info for current inferior)
3059 info proc 123 (prints summary info for process with pid 123)
3060 info proc mappings (prints address mappings)
3061 info proc times (prints process/children times)
3062 info proc id (prints pid, ppid, gid, sid, etc)
3063 info proc status (prints general process state info)
3064 info proc signals (prints info about signal handling)
3065 info proc all (prints all info)
3070 info_proc (args
, from_tty
)
3075 struct procinfo pii
;
3076 struct procinfo
*pip
;
3077 struct cleanup
*old_chain
;
3092 old_chain
= make_cleanup (null_cleanup
, 0);
3094 /* Default to using the current inferior if no pid specified */
3100 if ((argv
= buildargv (args
)) == NULL
)
3104 make_cleanup (freeargv
, (char *) argv
);
3106 while (*argv
!= NULL
)
3108 argsize
= strlen (*argv
);
3109 if (argsize
>= 1 && strncmp (*argv
, "all", argsize
) == 0)
3114 else if (argsize
>= 2 && strncmp (*argv
, "faults", argsize
) == 0)
3119 else if (argsize
>= 2 && strncmp (*argv
, "flags", argsize
) == 0)
3124 else if (argsize
>= 1 && strncmp (*argv
, "id", argsize
) == 0)
3129 else if (argsize
>= 1 && strncmp (*argv
, "mappings", argsize
) == 0)
3134 else if (argsize
>= 2 && strncmp (*argv
, "signals", argsize
) == 0)
3139 else if (argsize
>= 2 && strncmp (*argv
, "status", argsize
) == 0)
3144 else if (argsize
>= 2 && strncmp (*argv
, "syscalls", argsize
) == 0)
3149 else if (argsize
>= 1 && strncmp (*argv
, "times", argsize
) == 0)
3154 else if ((pii
.pid
= atoi (*argv
)) > 0)
3158 (void) memset (&pii
, 0, sizeof (pii
));
3159 if (!open_proc_file (pid
, pip
))
3161 perror_with_name (pip
-> pathname
);
3164 make_cleanup (close_proc_file
, pip
);
3166 else if (**argv
!= '\000')
3168 error ("Unrecognized or ambiguous keyword `%s'.", *argv
);
3174 /* If we don't have a valid open process at this point, then we have no
3175 inferior or didn't specify a specific pid. */
3179 error ("No process. Run an inferior or specify an explicit pid.");
3181 if (ioctl (pip
-> fd
, PIOCSTATUS
, &(pip
-> prstatus
)) < 0)
3183 print_sys_errmsg (pip
-> pathname
, errno
);
3184 error ("PIOCSTATUS failed");
3187 /* Print verbose information of the requested type(s), or just a summary
3188 of the information for all types. */
3190 printf_filtered ("\nInformation for %s:\n\n", pip
-> pathname
);
3191 if (summary
|| all
|| flags
)
3193 info_proc_flags (pip
, summary
);
3197 info_proc_stop (pip
, summary
);
3199 if (summary
|| all
|| signals
|| faults
)
3201 info_proc_siginfo (pip
, summary
);
3203 if (summary
|| all
|| syscalls
)
3205 info_proc_syscalls (pip
, summary
);
3207 if (summary
|| all
|| mappings
)
3209 info_proc_mappings (pip
, summary
);
3211 if (summary
|| all
|| signals
)
3213 info_proc_signals (pip
, summary
);
3215 if (summary
|| all
|| faults
)
3217 info_proc_faults (pip
, summary
);
3219 printf_filtered ("\n");
3221 /* All done, deal with closing any temporary process info structure,
3222 freeing temporary memory , etc. */
3224 do_cleanups (old_chain
);
3231 _initialize_proc_fs -- initialize the process file system stuff
3235 void _initialize_proc_fs (void)
3239 Do required initializations during gdb startup for using the
3240 /proc file system interface.
3244 static char *proc_desc
=
3245 "Show process status information using /proc entry.\n\
3246 Specify process id or use current inferior by default.\n\
3247 Specify keywords for detailed information; default is summary.\n\
3248 Keywords are: `all', `faults', `flags', `id', `mappings', `signals',\n\
3249 `status', `syscalls', and `times'.\n\
3250 Unambiguous abbreviations may be used.";
3253 _initialize_proc_fs ()
3255 add_info ("proc", info_proc
, proc_desc
);
3256 init_syscall_table ();
3259 #endif /* USE_PROC_FS */