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",
140 #if defined (PR_STEP)
141 PR_STEP
, "PR_STEP", "Process has single step pending",
144 PR_KLC
, "PR_KLC", "Kill-on-last-close is in effect",
146 #if defined (PR_ASYNC)
147 PR_ASYNC
, "PR_ASYNC", "Asynchronous stop is in effect",
149 #if defined (PR_PCOMPAT)
150 PR_PCOMPAT
, "PR_PCOMPAT", "Ptrace compatibility mode in effect",
155 /* Translate values in the pr_why field of the prstatus struct. */
157 static struct trans pr_why_table
[] =
159 #if defined (PR_REQUESTED)
160 PR_REQUESTED
, "PR_REQUESTED", "Directed to stop via PIOCSTOP/PIOCWSTOP",
162 #if defined (PR_SIGNALLED)
163 PR_SIGNALLED
, "PR_SIGNALLED", "Receipt of a traced signal",
165 #if defined (PR_FAULTED)
166 PR_FAULTED
, "PR_FAULTED", "Incurred a traced hardware fault",
168 #if defined (PR_SYSENTRY)
169 PR_SYSENTRY
, "PR_SYSENTRY", "Entry to a traced system call",
171 #if defined (PR_SYSEXIT)
172 PR_SYSEXIT
, "PR_SYSEXIT", "Exit from a traced system call",
174 #if defined (PR_JOBCONTROL)
175 PR_JOBCONTROL
, "PR_JOBCONTROL", "Default job control stop signal action",
177 #if defined (PR_SUSPENDED)
178 PR_SUSPENDED
, "PR_SUSPENDED", "Process suspended",
183 /* Hardware fault translation table. */
185 static struct trans faults_table
[] =
188 FLTILL
, "FLTILL", "Illegal instruction",
190 #if defined (FLTPRIV)
191 FLTPRIV
, "FLTPRIV", "Privileged instruction",
194 FLTBPT
, "FLTBPT", "Breakpoint trap",
196 #if defined (FLTTRACE)
197 FLTTRACE
, "FLTTRACE", "Trace trap",
199 #if defined (FLTACCESS)
200 FLTACCESS
, "FLTACCESS", "Memory access fault",
202 #if defined (FLTBOUNDS)
203 FLTBOUNDS
, "FLTBOUNDS", "Memory bounds violation",
205 #if defined (FLTIOVF)
206 FLTIOVF
, "FLTIOVF", "Integer overflow",
208 #if defined (FLTIZDIV)
209 FLTIZDIV
, "FLTIZDIV", "Integer zero divide",
212 FLTFPE
, "FLTFPE", "Floating-point exception",
214 #if defined (FLTSTACK)
215 FLTSTACK
, "FLTSTACK", "Unrecoverable stack fault",
217 #if defined (FLTPAGE)
218 FLTPAGE
, "FLTPAGE", "Recoverable page fault",
223 /* Translation table for signal generation information. See UNIX System
224 V Release 4 Programmer's Reference Manual, siginfo(5). */
226 static struct sigcode
{
231 } siginfo_table
[] = {
232 #if defined (SIGILL) && defined (ILL_ILLOPC)
233 SIGILL
, ILL_ILLOPC
, "ILL_ILLOPC", "Illegal opcode",
235 #if defined (SIGILL) && defined (ILL_ILLOPN)
236 SIGILL
, ILL_ILLOPN
, "ILL_ILLOPN", "Illegal operand",
238 #if defined (SIGILL) && defined (ILL_ILLADR)
239 SIGILL
, ILL_ILLADR
, "ILL_ILLADR", "Illegal addressing mode",
241 #if defined (SIGILL) && defined (ILL_ILLTRP)
242 SIGILL
, ILL_ILLTRP
, "ILL_ILLTRP", "Illegal trap",
244 #if defined (SIGILL) && defined (ILL_PRVOPC)
245 SIGILL
, ILL_PRVOPC
, "ILL_PRVOPC", "Privileged opcode",
247 #if defined (SIGILL) && defined (ILL_PRVREG)
248 SIGILL
, ILL_PRVREG
, "ILL_PRVREG", "Privileged register",
250 #if defined (SIGILL) && defined (ILL_COPROC)
251 SIGILL
, ILL_COPROC
, "ILL_COPROC", "Coprocessor error",
253 #if defined (SIGILL) && defined (ILL_BADSTK)
254 SIGILL
, ILL_BADSTK
, "ILL_BADSTK", "Internal stack error",
256 #if defined (SIGFPE) && defined (FPE_INTDIV)
257 SIGFPE
, FPE_INTDIV
, "FPE_INTDIV", "Integer divide by zero",
259 #if defined (SIGFPE) && defined (FPE_INTOVF)
260 SIGFPE
, FPE_INTOVF
, "FPE_INTOVF", "Integer overflow",
262 #if defined (SIGFPE) && defined (FPE_FLTDIV)
263 SIGFPE
, FPE_FLTDIV
, "FPE_FLTDIV", "Floating point divide by zero",
265 #if defined (SIGFPE) && defined (FPE_FLTOVF)
266 SIGFPE
, FPE_FLTOVF
, "FPE_FLTOVF", "Floating point overflow",
268 #if defined (SIGFPE) && defined (FPE_FLTUND)
269 SIGFPE
, FPE_FLTUND
, "FPE_FLTUND", "Floating point underflow",
271 #if defined (SIGFPE) && defined (FPE_FLTRES)
272 SIGFPE
, FPE_FLTRES
, "FPE_FLTRES", "Floating point inexact result",
274 #if defined (SIGFPE) && defined (FPE_FLTINV)
275 SIGFPE
, FPE_FLTINV
, "FPE_FLTINV", "Invalid floating point operation",
277 #if defined (SIGFPE) && defined (FPE_FLTSUB)
278 SIGFPE
, FPE_FLTSUB
, "FPE_FLTSUB", "Subscript out of range",
280 #if defined (SIGSEGV) && defined (SEGV_MAPERR)
281 SIGSEGV
, SEGV_MAPERR
, "SEGV_MAPERR", "Address not mapped to object",
283 #if defined (SIGSEGV) && defined (SEGV_ACCERR)
284 SIGSEGV
, SEGV_ACCERR
, "SEGV_ACCERR", "Invalid permissions for object",
286 #if defined (SIGBUS) && defined (BUS_ADRALN)
287 SIGBUS
, BUS_ADRALN
, "BUS_ADRALN", "Invalid address alignment",
289 #if defined (SIGBUS) && defined (BUS_ADRERR)
290 SIGBUS
, BUS_ADRERR
, "BUS_ADRERR", "Non-existent physical address",
292 #if defined (SIGBUS) && defined (BUS_OBJERR)
293 SIGBUS
, BUS_OBJERR
, "BUS_OBJERR", "Object specific hardware error",
295 #if defined (SIGTRAP) && defined (TRAP_BRKPT)
296 SIGTRAP
, TRAP_BRKPT
, "TRAP_BRKPT", "Process breakpoint",
298 #if defined (SIGTRAP) && defined (TRAP_TRACE)
299 SIGTRAP
, TRAP_TRACE
, "TRAP_TRACE", "Process trace trap",
301 #if defined (SIGCLD) && defined (CLD_EXITED)
302 SIGCLD
, CLD_EXITED
, "CLD_EXITED", "Child has exited",
304 #if defined (SIGCLD) && defined (CLD_KILLED)
305 SIGCLD
, CLD_KILLED
, "CLD_KILLED", "Child was killed",
307 #if defined (SIGCLD) && defined (CLD_DUMPED)
308 SIGCLD
, CLD_DUMPED
, "CLD_DUMPED", "Child has terminated abnormally",
310 #if defined (SIGCLD) && defined (CLD_TRAPPED)
311 SIGCLD
, CLD_TRAPPED
, "CLD_TRAPPED", "Traced child has trapped",
313 #if defined (SIGCLD) && defined (CLD_STOPPED)
314 SIGCLD
, CLD_STOPPED
, "CLD_STOPPED", "Child has stopped",
316 #if defined (SIGCLD) && defined (CLD_CONTINUED)
317 SIGCLD
, CLD_CONTINUED
, "CLD_CONTINUED", "Stopped child had continued",
319 #if defined (SIGPOLL) && defined (POLL_IN)
320 SIGPOLL
, POLL_IN
, "POLL_IN", "Input input available",
322 #if defined (SIGPOLL) && defined (POLL_OUT)
323 SIGPOLL
, POLL_OUT
, "POLL_OUT", "Output buffers available",
325 #if defined (SIGPOLL) && defined (POLL_MSG)
326 SIGPOLL
, POLL_MSG
, "POLL_MSG", "Input message available",
328 #if defined (SIGPOLL) && defined (POLL_ERR)
329 SIGPOLL
, POLL_ERR
, "POLL_ERR", "I/O error",
331 #if defined (SIGPOLL) && defined (POLL_PRI)
332 SIGPOLL
, POLL_PRI
, "POLL_PRI", "High priority input available",
334 #if defined (SIGPOLL) && defined (POLL_HUP)
335 SIGPOLL
, POLL_HUP
, "POLL_HUP", "Device disconnected",
340 /* Translation table for errno values. See intro(2) in most UNIX systems
341 Programmers Reference Manuals.
343 Note that some systems provide a function (strerror) that returns the
344 error message string, or a global variable that is the base address of the
345 array of character pointers. Perhaps we should try to make use of these
346 provided strings if they are present, but at least this is more portable.
349 static struct trans errno_table
[] =
352 EPERM
, "EPERM", "Not super-user",
355 ENOENT
, "ENOENT", "No such file or directory",
358 ESRCH
, "ESRCH", "No such process",
361 EINTR
, "EINTR", "Interrupted system call",
364 EIO
, "EIO", "I/O error",
367 ENXIO
, "ENXIO", "No such device or address",
370 E2BIG
, "E2BIG", "Arg list too long",
372 #if defined (ENOEXEC)
373 ENOEXEC
, "ENOEXEC", "Exec format error",
376 EBADF
, "EBADF", "Bad file number",
379 ECHILD
, "ECHILD", "No child process",
382 EAGAIN
, "EAGAIN", "No more processes",
385 ENOMEM
, "ENOMEM", "Not enough space",
388 EACCES
, "EACCES", "Permission denied",
391 EFAULT
, "EFAULT", "Bad address",
393 #if defined (ENOTBLK)
394 ENOTBLK
, "ENOTBLK", "Block device required",
397 EBUSY
, "EBUSY", "Device busy",
400 EEXIST
, "EEXIST", "File exists",
403 EXDEV
, "EXDEV", "Cross-device link",
406 ENODEV
, "ENODEV", "No such device",
408 #if defined (ENOTDIR)
409 ENOTDIR
, "ENOTDIR", "Not a directory",
412 EISDIR
, "EISDIR", "Is a directory",
415 EINVAL
, "EINVAL", "Invalid argument",
418 ENFILE
, "ENFILE", "File table overflow",
421 EMFILE
, "EMFILE", "Too many open files",
424 ENOTTY
, "ENOTTY", "Not a typewriter",
426 #if defined (ETXTBSY)
427 ETXTBSY
, "ETXTBSY", "Text file busy",
430 EFBIG
, "EFBIG", "File too large",
433 ENOSPC
, "ENOSPC", "No space left on device",
436 ESPIPE
, "ESPIPE", "Illegal seek",
439 EROFS
, "EROFS", "Read only file system",
442 EMLINK
, "EMLINK", "Too many links",
445 EPIPE
, "EPIPE", "Broken pipe",
448 EDOM
, "EDOM", "Math argument out of domain of func",
451 ERANGE
, "ERANGE", "Math result not representable",
454 ENOMSG
, "ENOMSG", "No message of desired type",
457 EIDRM
, "EIDRM", "Identifier removed",
460 ECHRNG
, "ECHRNG", "Channel number out of range",
462 #if defined (EL2NSYNC)
463 EL2NSYNC
, "EL2NSYNC", "Level 2 not synchronized",
466 EL3HLT
, "EL3HLT", "Level 3 halted",
469 EL3RST
, "EL3RST", "Level 3 reset",
472 ELNRNG
, "ELNRNG", "Link number out of range",
474 #if defined (EUNATCH)
475 EUNATCH
, "EUNATCH", "Protocol driver not attached",
478 ENOCSI
, "ENOCSI", "No CSI structure available",
481 EL2HLT
, "EL2HLT", "Level 2 halted",
483 #if defined (EDEADLK)
484 EDEADLK
, "EDEADLK", "Deadlock condition",
487 ENOLCK
, "ENOLCK", "No record locks available",
490 EBADE
, "EBADE", "Invalid exchange",
493 EBADR
, "EBADR", "Invalid request descriptor",
496 EXFULL
, "EXFULL", "Exchange full",
499 ENOANO
, "ENOANO", "No anode",
501 #if defined (EBADRQC)
502 EBADRQC
, "EBADRQC", "Invalid request code",
504 #if defined (EBADSLT)
505 EBADSLT
, "EBADSLT", "Invalid slot",
507 #if defined (EDEADLOCK)
508 EDEADLOCK
, "EDEADLOCK", "File locking deadlock error",
511 EBFONT
, "EBFONT", "Bad font file fmt",
514 ENOSTR
, "ENOSTR", "Device not a stream",
516 #if defined (ENODATA)
517 ENODATA
, "ENODATA", "No data available",
520 ETIME
, "ETIME", "Timer expired",
523 ENOSR
, "ENOSR", "Out of streams resources",
526 ENONET
, "ENONET", "Machine is not on the network",
529 ENOPKG
, "ENOPKG", "Package not installed",
531 #if defined (EREMOTE)
532 EREMOTE
, "EREMOTE", "Object is remote",
534 #if defined (ENOLINK)
535 ENOLINK
, "ENOLINK", "Link has been severed",
538 EADV
, "EADV", "Advertise error",
541 ESRMNT
, "ESRMNT", "Srmount error",
544 ECOMM
, "ECOMM", "Communication error on send",
547 EPROTO
, "EPROTO", "Protocol error",
549 #if defined (EMULTIHOP)
550 EMULTIHOP
, "EMULTIHOP", "Multihop attempted",
552 #if defined (EDOTDOT)
553 EDOTDOT
, "EDOTDOT", "RFS specific error",
555 #if defined (EBADMSG)
556 EBADMSG
, "EBADMSG", "Not a data message",
558 #if defined (ENAMETOOLONG)
559 ENAMETOOLONG
, "ENAMETOOLONG", "File name too long",
561 #if defined (EOVERFLOW)
562 EOVERFLOW
, "EOVERFLOW", "Value too large for defined data type",
564 #if defined (ENOTUNIQ)
565 ENOTUNIQ
, "ENOTUNIQ", "Name not unique on network",
568 EBADFD
, "EBADFD", "File descriptor in bad state",
570 #if defined (EREMCHG)
571 EREMCHG
, "EREMCHG", "Remote address changed",
573 #if defined (ELIBACC)
574 ELIBACC
, "ELIBACC", "Cannot access a needed shared library",
576 #if defined (ELIBBAD)
577 ELIBBAD
, "ELIBBAD", "Accessing a corrupted shared library",
579 #if defined (ELIBSCN)
580 ELIBSCN
, "ELIBSCN", ".lib section in a.out corrupted",
582 #if defined (ELIBMAX)
583 ELIBMAX
, "ELIBMAX", "Attempting to link in too many shared libraries",
585 #if defined (ELIBEXEC)
586 ELIBEXEC
, "ELIBEXEC", "Cannot exec a shared library directly",
589 EILSEQ
, "EILSEQ", "Illegal byte sequence",
592 ENOSYS
, "ENOSYS", "Operation not applicable",
595 ELOOP
, "ELOOP", "Too many symbolic links encountered",
597 #if defined (ERESTART)
598 ERESTART
, "ERESTART", "Interrupted system call should be restarted",
600 #if defined (ESTRPIPE)
601 ESTRPIPE
, "ESTRPIPE", "Streams pipe error",
603 #if defined (ENOTEMPTY)
604 ENOTEMPTY
, "ENOTEMPTY", "Directory not empty",
607 EUSERS
, "EUSERS", "Too many users",
609 #if defined (ENOTSOCK)
610 ENOTSOCK
, "ENOTSOCK", "Socket operation on non-socket",
612 #if defined (EDESTADDRREQ)
613 EDESTADDRREQ
, "EDESTADDRREQ", "Destination address required",
615 #if defined (EMSGSIZE)
616 EMSGSIZE
, "EMSGSIZE", "Message too long",
618 #if defined (EPROTOTYPE)
619 EPROTOTYPE
, "EPROTOTYPE", "Protocol wrong type for socket",
621 #if defined (ENOPROTOOPT)
622 ENOPROTOOPT
, "ENOPROTOOPT", "Protocol not available",
624 #if defined (EPROTONOSUPPORT)
625 EPROTONOSUPPORT
, "EPROTONOSUPPORT", "Protocol not supported",
627 #if defined (ESOCKTNOSUPPORT)
628 ESOCKTNOSUPPORT
, "ESOCKTNOSUPPORT", "Socket type not supported",
630 #if defined (EOPNOTSUPP)
631 EOPNOTSUPP
, "EOPNOTSUPP", "Operation not supported on transport endpoint ",
633 #if defined (EPFNOSUPPORT)
634 EPFNOSUPPORT
, "EPFNOSUPPORT", "Protocol family not supported",
636 #if defined (EAFNOSUPPORT)
637 EAFNOSUPPORT
, "EAFNOSUPPORT", "Address family not supported by protocol",
639 #if defined (EADDRINUSE)
640 EADDRINUSE
, "EADDRINUSE", "Address already in use",
642 #if defined (EADDRNOTAVAIL)
643 EADDRNOTAVAIL
, "EADDRNOTAVAIL","Cannot assign requested address",
645 #if defined (ENETDOWN)
646 ENETDOWN
, "ENETDOWN", "Network is down",
648 #if defined (ENETUNREACH)
649 ENETUNREACH
, "ENETUNREACH", "Network is unreachable",
651 #if defined (ENETRESET)
652 ENETRESET
, "ENETRESET", "Network dropped connection because of reset",
654 #if defined (ECONNABORTED)
655 ECONNABORTED
, "ECONNABORTED", "Software caused connection abort",
657 #if defined (ECONNRESET)
658 ECONNRESET
, "ECONNRESET", "Connection reset by peer",
660 #if defined (ENOBUFS)
661 ENOBUFS
, "ENOBUFS", "No buffer space available",
663 #if defined (EISCONN)
664 EISCONN
, "EISCONN", "Transport endpoint is already connected",
666 #if defined (ENOTCONN)
667 ENOTCONN
, "ENOTCONN", "Transport endpoint is not connected",
669 #if defined (ESHUTDOWN)
670 ESHUTDOWN
, "ESHUTDOWN", "Cannot send after transport endpoint shutdown",
672 #if defined (ETOOMANYREFS)
673 ETOOMANYREFS
, "ETOOMANYREFS", "Too many references: cannot splice",
675 #if defined (ETIMEDOUT)
676 ETIMEDOUT
, "ETIMEDOUT", "Connection timed out",
678 #if defined (ECONNREFUSED)
679 ECONNREFUSED
, "ECONNREFUSED", "Connection refused",
681 #if defined (EHOSTDOWN)
682 EHOSTDOWN
, "EHOSTDOWN", "Host is down",
684 #if defined (EHOSTUNREACH)
685 EHOSTUNREACH
, "EHOSTUNREACH", "No route to host",
687 #if defined (EWOULDBLOCK)
688 EWOULDBLOCK
, "EWOULDBLOCK", "Operation already in progress",
690 #if defined (EINPROGRESS)
691 EINPROGRESS
, "EINPROGRESS", "Operation now in progress",
694 ESTALE
, "ESTALE", "Stale NFS file handle",
696 #if defined (EUCLEAN)
697 EUCLEAN
, "EUCLEAN", "Structure needs cleaning",
699 #if defined (ENOTNAM)
700 ENOTNAM
, "ENOTNAM", "Not a XENIX named type file",
702 #if defined (ENAVAIL)
703 ENAVAIL
, "ENAVAIL", "No XENIX semaphores available",
706 EISNAM
, "EISNAM", "Is a named type file",
708 #if defined (EREMOTEIO)
709 EREMOTEIO
, "EREMOTEIO", "Remote I/O error",
714 static char *syscall_table
[MAX_SYSCALLS
];
716 /* Prototypes for local functions */
719 set_proc_siginfo
PARAMS ((struct procinfo
*, int));
722 init_syscall_table
PARAMS ((void));
725 syscallname
PARAMS ((int));
728 signalname
PARAMS ((int));
731 proc_address_to_fd
PARAMS ((CORE_ADDR
, int));
734 open_proc_file
PARAMS ((int, struct procinfo
*));
737 close_proc_file
PARAMS ((struct procinfo
*));
740 unconditionally_kill_inferior
PARAMS ((void));
743 proc_init_failed
PARAMS ((char *));
746 info_proc
PARAMS ((char *, int));
749 info_proc_flags
PARAMS ((struct procinfo
*, int));
752 info_proc_stop
PARAMS ((struct procinfo
*, int));
755 info_proc_siginfo
PARAMS ((struct procinfo
*, int));
758 info_proc_syscalls
PARAMS ((struct procinfo
*, int));
761 info_proc_mappings
PARAMS ((struct procinfo
*, int));
764 info_proc_signals
PARAMS ((struct procinfo
*, int));
767 info_proc_faults
PARAMS ((struct procinfo
*, int));
770 mappingflags
PARAMS ((long));
773 lookupname
PARAMS ((struct trans
*, unsigned int, char *));
776 lookupdesc
PARAMS ((struct trans
*, unsigned int));
778 /* External function prototypes that can't be easily included in any
779 header file because the args are typedefs in system include files. */
782 supply_gregset
PARAMS ((gregset_t
*));
785 fill_gregset
PARAMS ((gregset_t
*, int));
788 supply_fpregset
PARAMS ((fpregset_t
*));
791 fill_fpregset
PARAMS ((fpregset_t
*, int));
797 lookupdesc -- translate a value to a summary desc string
801 static char *lookupdesc (struct trans *transp, unsigned int val);
805 Given a pointer to a translation table and a value to be translated,
806 lookup the desc string and return it.
810 lookupdesc (transp
, val
)
811 struct trans
*transp
;
816 for (desc
= NULL
; transp
-> name
!= NULL
; transp
++)
818 if (transp
-> value
== val
)
820 desc
= transp
-> desc
;
825 /* Didn't find a translation for the specified value, set a default one. */
838 lookupname -- translate a value to symbolic name
842 static char *lookupname (struct trans *transp, unsigned int val,
847 Given a pointer to a translation table, a value to be translated,
848 and a default prefix to return if the value can't be translated,
849 match the value with one of the translation table entries and
850 return a pointer to the symbolic name.
852 If no match is found it just returns the value as a printable string,
853 with the given prefix. The previous such value, if any, is freed
858 lookupname (transp
, val
, prefix
)
859 struct trans
*transp
;
866 for (name
= NULL
; transp
-> name
!= NULL
; transp
++)
868 if (transp
-> value
== val
)
870 name
= transp
-> name
;
875 /* Didn't find a translation for the specified value, build a default
876 one using the specified prefix and return it. The lifetime of
877 the value is only until the next one is needed. */
885 locbuf
= xmalloc (strlen (prefix
) + 16);
886 (void) sprintf (locbuf
, "%s %u", prefix
, val
);
898 static char locbuf
[32];
900 for (scp
= siginfo_table
; scp
-> codename
!= NULL
; scp
++)
902 if ((scp
-> signo
== sip
-> si_signo
) &&
903 (scp
-> code
== sip
-> si_code
))
905 name
= scp
-> codename
;
911 (void) sprintf (locbuf
, "sigcode %u", sip
-> si_signo
);
917 static char *sigcodedesc (sip
)
923 for (scp
= siginfo_table
; scp
-> codename
!= NULL
; scp
++)
925 if ((scp
-> signo
== sip
-> si_signo
) &&
926 (scp
-> code
== sip
-> si_code
))
934 desc
= "Unrecognized signal or trap use";
943 syscallname - translate a system call number into a system call name
947 char *syscallname (int syscallnum)
951 Given a system call number, translate it into the printable name
952 of a system call, or into "syscall <num>" if it is an unknown
957 syscallname (syscallnum
)
960 static char locbuf
[32];
963 if (syscallnum
>= 0 && syscallnum
< MAX_SYSCALLS
)
965 rtnval
= syscall_table
[syscallnum
];
969 (void) sprintf (locbuf
, "syscall %u", syscallnum
);
979 init_syscall_table - initialize syscall translation table
983 void init_syscall_table (void)
987 Dynamically initialize the translation table to convert system
988 call numbers into printable system call names. Done once per
989 gdb run, on initialization.
993 This is awfully ugly, but preprocessor tricks to make it prettier
994 tend to be nonportable.
998 init_syscall_table ()
1002 #if defined (SYS_exit)
1003 syscall_table
[SYS_exit
] = "exit";
1005 #if defined (SYS_fork)
1006 syscall_table
[SYS_fork
] = "fork";
1008 #if defined (SYS_read)
1009 syscall_table
[SYS_read
] = "read";
1011 #if defined (SYS_write)
1012 syscall_table
[SYS_write
] = "write";
1014 #if defined (SYS_open)
1015 syscall_table
[SYS_open
] = "open";
1017 #if defined (SYS_close)
1018 syscall_table
[SYS_close
] = "close";
1020 #if defined (SYS_wait)
1021 syscall_table
[SYS_wait
] = "wait";
1023 #if defined (SYS_creat)
1024 syscall_table
[SYS_creat
] = "creat";
1026 #if defined (SYS_link)
1027 syscall_table
[SYS_link
] = "link";
1029 #if defined (SYS_unlink)
1030 syscall_table
[SYS_unlink
] = "unlink";
1032 #if defined (SYS_exec)
1033 syscall_table
[SYS_exec
] = "exec";
1035 #if defined (SYS_execv)
1036 syscall_table
[SYS_execv
] = "execv";
1038 #if defined (SYS_execve)
1039 syscall_table
[SYS_execve
] = "execve";
1041 #if defined (SYS_chdir)
1042 syscall_table
[SYS_chdir
] = "chdir";
1044 #if defined (SYS_time)
1045 syscall_table
[SYS_time
] = "time";
1047 #if defined (SYS_mknod)
1048 syscall_table
[SYS_mknod
] = "mknod";
1050 #if defined (SYS_chmod)
1051 syscall_table
[SYS_chmod
] = "chmod";
1053 #if defined (SYS_chown)
1054 syscall_table
[SYS_chown
] = "chown";
1056 #if defined (SYS_brk)
1057 syscall_table
[SYS_brk
] = "brk";
1059 #if defined (SYS_stat)
1060 syscall_table
[SYS_stat
] = "stat";
1062 #if defined (SYS_lseek)
1063 syscall_table
[SYS_lseek
] = "lseek";
1065 #if defined (SYS_getpid)
1066 syscall_table
[SYS_getpid
] = "getpid";
1068 #if defined (SYS_mount)
1069 syscall_table
[SYS_mount
] = "mount";
1071 #if defined (SYS_umount)
1072 syscall_table
[SYS_umount
] = "umount";
1074 #if defined (SYS_setuid)
1075 syscall_table
[SYS_setuid
] = "setuid";
1077 #if defined (SYS_getuid)
1078 syscall_table
[SYS_getuid
] = "getuid";
1080 #if defined (SYS_stime)
1081 syscall_table
[SYS_stime
] = "stime";
1083 #if defined (SYS_ptrace)
1084 syscall_table
[SYS_ptrace
] = "ptrace";
1086 #if defined (SYS_alarm)
1087 syscall_table
[SYS_alarm
] = "alarm";
1089 #if defined (SYS_fstat)
1090 syscall_table
[SYS_fstat
] = "fstat";
1092 #if defined (SYS_pause)
1093 syscall_table
[SYS_pause
] = "pause";
1095 #if defined (SYS_utime)
1096 syscall_table
[SYS_utime
] = "utime";
1098 #if defined (SYS_stty)
1099 syscall_table
[SYS_stty
] = "stty";
1101 #if defined (SYS_gtty)
1102 syscall_table
[SYS_gtty
] = "gtty";
1104 #if defined (SYS_access)
1105 syscall_table
[SYS_access
] = "access";
1107 #if defined (SYS_nice)
1108 syscall_table
[SYS_nice
] = "nice";
1110 #if defined (SYS_statfs)
1111 syscall_table
[SYS_statfs
] = "statfs";
1113 #if defined (SYS_sync)
1114 syscall_table
[SYS_sync
] = "sync";
1116 #if defined (SYS_kill)
1117 syscall_table
[SYS_kill
] = "kill";
1119 #if defined (SYS_fstatfs)
1120 syscall_table
[SYS_fstatfs
] = "fstatfs";
1122 #if defined (SYS_pgrpsys)
1123 syscall_table
[SYS_pgrpsys
] = "pgrpsys";
1125 #if defined (SYS_xenix)
1126 syscall_table
[SYS_xenix
] = "xenix";
1128 #if defined (SYS_dup)
1129 syscall_table
[SYS_dup
] = "dup";
1131 #if defined (SYS_pipe)
1132 syscall_table
[SYS_pipe
] = "pipe";
1134 #if defined (SYS_times)
1135 syscall_table
[SYS_times
] = "times";
1137 #if defined (SYS_profil)
1138 syscall_table
[SYS_profil
] = "profil";
1140 #if defined (SYS_plock)
1141 syscall_table
[SYS_plock
] = "plock";
1143 #if defined (SYS_setgid)
1144 syscall_table
[SYS_setgid
] = "setgid";
1146 #if defined (SYS_getgid)
1147 syscall_table
[SYS_getgid
] = "getgid";
1149 #if defined (SYS_signal)
1150 syscall_table
[SYS_signal
] = "signal";
1152 #if defined (SYS_msgsys)
1153 syscall_table
[SYS_msgsys
] = "msgsys";
1155 #if defined (SYS_sys3b)
1156 syscall_table
[SYS_sys3b
] = "sys3b";
1158 #if defined (SYS_acct)
1159 syscall_table
[SYS_acct
] = "acct";
1161 #if defined (SYS_shmsys)
1162 syscall_table
[SYS_shmsys
] = "shmsys";
1164 #if defined (SYS_semsys)
1165 syscall_table
[SYS_semsys
] = "semsys";
1167 #if defined (SYS_ioctl)
1168 syscall_table
[SYS_ioctl
] = "ioctl";
1170 #if defined (SYS_uadmin)
1171 syscall_table
[SYS_uadmin
] = "uadmin";
1173 #if defined (SYS_utssys)
1174 syscall_table
[SYS_utssys
] = "utssys";
1176 #if defined (SYS_fsync)
1177 syscall_table
[SYS_fsync
] = "fsync";
1179 #if defined (SYS_umask)
1180 syscall_table
[SYS_umask
] = "umask";
1182 #if defined (SYS_chroot)
1183 syscall_table
[SYS_chroot
] = "chroot";
1185 #if defined (SYS_fcntl)
1186 syscall_table
[SYS_fcntl
] = "fcntl";
1188 #if defined (SYS_ulimit)
1189 syscall_table
[SYS_ulimit
] = "ulimit";
1191 #if defined (SYS_rfsys)
1192 syscall_table
[SYS_rfsys
] = "rfsys";
1194 #if defined (SYS_rmdir)
1195 syscall_table
[SYS_rmdir
] = "rmdir";
1197 #if defined (SYS_mkdir)
1198 syscall_table
[SYS_mkdir
] = "mkdir";
1200 #if defined (SYS_getdents)
1201 syscall_table
[SYS_getdents
] = "getdents";
1203 #if defined (SYS_sysfs)
1204 syscall_table
[SYS_sysfs
] = "sysfs";
1206 #if defined (SYS_getmsg)
1207 syscall_table
[SYS_getmsg
] = "getmsg";
1209 #if defined (SYS_putmsg)
1210 syscall_table
[SYS_putmsg
] = "putmsg";
1212 #if defined (SYS_poll)
1213 syscall_table
[SYS_poll
] = "poll";
1215 #if defined (SYS_lstat)
1216 syscall_table
[SYS_lstat
] = "lstat";
1218 #if defined (SYS_symlink)
1219 syscall_table
[SYS_symlink
] = "symlink";
1221 #if defined (SYS_readlink)
1222 syscall_table
[SYS_readlink
] = "readlink";
1224 #if defined (SYS_setgroups)
1225 syscall_table
[SYS_setgroups
] = "setgroups";
1227 #if defined (SYS_getgroups)
1228 syscall_table
[SYS_getgroups
] = "getgroups";
1230 #if defined (SYS_fchmod)
1231 syscall_table
[SYS_fchmod
] = "fchmod";
1233 #if defined (SYS_fchown)
1234 syscall_table
[SYS_fchown
] = "fchown";
1236 #if defined (SYS_sigprocmask)
1237 syscall_table
[SYS_sigprocmask
] = "sigprocmask";
1239 #if defined (SYS_sigsuspend)
1240 syscall_table
[SYS_sigsuspend
] = "sigsuspend";
1242 #if defined (SYS_sigaltstack)
1243 syscall_table
[SYS_sigaltstack
] = "sigaltstack";
1245 #if defined (SYS_sigaction)
1246 syscall_table
[SYS_sigaction
] = "sigaction";
1248 #if defined (SYS_sigpending)
1249 syscall_table
[SYS_sigpending
] = "sigpending";
1251 #if defined (SYS_context)
1252 syscall_table
[SYS_context
] = "context";
1254 #if defined (SYS_evsys)
1255 syscall_table
[SYS_evsys
] = "evsys";
1257 #if defined (SYS_evtrapret)
1258 syscall_table
[SYS_evtrapret
] = "evtrapret";
1260 #if defined (SYS_statvfs)
1261 syscall_table
[SYS_statvfs
] = "statvfs";
1263 #if defined (SYS_fstatvfs)
1264 syscall_table
[SYS_fstatvfs
] = "fstatvfs";
1266 #if defined (SYS_nfssys)
1267 syscall_table
[SYS_nfssys
] = "nfssys";
1269 #if defined (SYS_waitsys)
1270 syscall_table
[SYS_waitsys
] = "waitsys";
1272 #if defined (SYS_sigsendsys)
1273 syscall_table
[SYS_sigsendsys
] = "sigsendsys";
1275 #if defined (SYS_hrtsys)
1276 syscall_table
[SYS_hrtsys
] = "hrtsys";
1278 #if defined (SYS_acancel)
1279 syscall_table
[SYS_acancel
] = "acancel";
1281 #if defined (SYS_async)
1282 syscall_table
[SYS_async
] = "async";
1284 #if defined (SYS_priocntlsys)
1285 syscall_table
[SYS_priocntlsys
] = "priocntlsys";
1287 #if defined (SYS_pathconf)
1288 syscall_table
[SYS_pathconf
] = "pathconf";
1290 #if defined (SYS_mincore)
1291 syscall_table
[SYS_mincore
] = "mincore";
1293 #if defined (SYS_mmap)
1294 syscall_table
[SYS_mmap
] = "mmap";
1296 #if defined (SYS_mprotect)
1297 syscall_table
[SYS_mprotect
] = "mprotect";
1299 #if defined (SYS_munmap)
1300 syscall_table
[SYS_munmap
] = "munmap";
1302 #if defined (SYS_fpathconf)
1303 syscall_table
[SYS_fpathconf
] = "fpathconf";
1305 #if defined (SYS_vfork)
1306 syscall_table
[SYS_vfork
] = "vfork";
1308 #if defined (SYS_fchdir)
1309 syscall_table
[SYS_fchdir
] = "fchdir";
1311 #if defined (SYS_readv)
1312 syscall_table
[SYS_readv
] = "readv";
1314 #if defined (SYS_writev)
1315 syscall_table
[SYS_writev
] = "writev";
1317 #if defined (SYS_xstat)
1318 syscall_table
[SYS_xstat
] = "xstat";
1320 #if defined (SYS_lxstat)
1321 syscall_table
[SYS_lxstat
] = "lxstat";
1323 #if defined (SYS_fxstat)
1324 syscall_table
[SYS_fxstat
] = "fxstat";
1326 #if defined (SYS_xmknod)
1327 syscall_table
[SYS_xmknod
] = "xmknod";
1329 #if defined (SYS_clocal)
1330 syscall_table
[SYS_clocal
] = "clocal";
1332 #if defined (SYS_setrlimit)
1333 syscall_table
[SYS_setrlimit
] = "setrlimit";
1335 #if defined (SYS_getrlimit)
1336 syscall_table
[SYS_getrlimit
] = "getrlimit";
1338 #if defined (SYS_lchown)
1339 syscall_table
[SYS_lchown
] = "lchown";
1341 #if defined (SYS_memcntl)
1342 syscall_table
[SYS_memcntl
] = "memcntl";
1344 #if defined (SYS_getpmsg)
1345 syscall_table
[SYS_getpmsg
] = "getpmsg";
1347 #if defined (SYS_putpmsg)
1348 syscall_table
[SYS_putpmsg
] = "putpmsg";
1350 #if defined (SYS_rename)
1351 syscall_table
[SYS_rename
] = "rename";
1353 #if defined (SYS_uname)
1354 syscall_table
[SYS_uname
] = "uname";
1356 #if defined (SYS_setegid)
1357 syscall_table
[SYS_setegid
] = "setegid";
1359 #if defined (SYS_sysconfig)
1360 syscall_table
[SYS_sysconfig
] = "sysconfig";
1362 #if defined (SYS_adjtime)
1363 syscall_table
[SYS_adjtime
] = "adjtime";
1365 #if defined (SYS_systeminfo)
1366 syscall_table
[SYS_systeminfo
] = "systeminfo";
1368 #if defined (SYS_seteuid)
1369 syscall_table
[SYS_seteuid
] = "seteuid";
1377 ptrace -- override library version to force errors for /proc version
1381 int ptrace (int request, int pid, int arg3, int arg4)
1385 When gdb is configured to use /proc, it should not be calling
1386 or otherwise attempting to use ptrace. In order to catch errors
1387 where use of /proc is configured, but some routine is still calling
1388 ptrace, we provide a local version of a function with that name
1389 that does nothing but issue an error message.
1393 ptrace (request
, pid
, arg3
, arg4
)
1399 error ("internal error - there is a call to ptrace() somewhere");
1407 kill_inferior_fast -- kill inferior while gdb is exiting
1411 void kill_inferior_fast (void)
1415 This is used when GDB is exiting. It gives less chance of error.
1419 Don't attempt to kill attached inferiors since we may be called
1420 when gdb is in the process of aborting, and killing the attached
1421 inferior may be very anti-social. This is particularly true if we
1422 were attached just so we could use the /proc facilities to get
1423 detailed information about it's status.
1428 kill_inferior_fast ()
1430 if (inferior_pid
!= 0 && !attach_flag
)
1432 unconditionally_kill_inferior ();
1440 kill_inferior - kill any currently inferior
1444 void kill_inferior (void)
1448 Kill any current inferior.
1452 Kills even attached inferiors. Presumably the user has already
1453 been prompted that the inferior is an attached one rather than
1454 one started by gdb. (FIXME?)
1461 if (inferior_pid
!= 0)
1463 unconditionally_kill_inferior ();
1464 target_mourn_inferior ();
1472 unconditionally_kill_inferior - terminate the inferior
1476 static void unconditionally_kill_inferior (void)
1480 Kill the current inferior. Should not be called until it
1481 is at least tested that there is an inferior.
1485 A possibly useful enhancement would be to first try sending
1486 the inferior a terminate signal, politely asking it to commit
1487 suicide, before we murder it.
1492 unconditionally_kill_inferior ()
1497 (void) ioctl (pi
.fd
, PIOCKILL
, &signo
);
1498 close_proc_file (&pi
);
1506 child_xfer_memory -- copy data to or from inferior memory space
1510 int child_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len,
1511 int dowrite, struct target_ops target)
1515 Copy LEN bytes to/from inferior's memory starting at MEMADDR
1516 from/to debugger memory starting at MYADDR. Copy from inferior
1517 if DOWRITE is zero or to inferior if DOWRITE is nonzero.
1519 Returns the length copied, which is either the LEN argument or
1520 zero. This xfer function does not do partial moves, since child_ops
1521 doesn't allow memory operations to cross below us in the target stack
1526 The /proc interface makes this an almost trivial task.
1531 child_xfer_memory (memaddr
, myaddr
, len
, dowrite
, target
)
1536 struct target_ops
*target
; /* ignored */
1540 if (lseek (pi
.fd
, (off_t
) memaddr
, 0) == (off_t
) memaddr
)
1544 nbytes
= write (pi
.fd
, myaddr
, len
);
1548 nbytes
= read (pi
.fd
, myaddr
, len
);
1562 store_inferior_registers -- copy register values back to inferior
1566 void store_inferior_registers (int regno)
1570 Store our current register values back into the inferior. If
1571 REGNO is -1 then store all the register, otherwise store just
1572 the value specified by REGNO.
1576 If we are storing only a single register, we first have to get all
1577 the current values from the process, overwrite the desired register
1578 in the gregset with the one we want from gdb's registers, and then
1579 send the whole set back to the process. For writing all the
1580 registers, all we have to do is generate the gregset and send it to
1583 Also note that the process has to be stopped on an event of interest
1584 for this to work, which basically means that it has to have been
1585 run under the control of one of the other /proc ioctl calls and not
1586 ptrace. Since we don't use ptrace anyway, we don't worry about this
1587 fine point, but it is worth noting for future reference.
1589 Gdb is confused about what this function is supposed to return.
1590 Some versions return a value, others return nothing. Some are
1591 declared to return a value and actually return nothing. Gdb ignores
1592 anything returned. (FIXME)
1597 store_inferior_registers (regno
)
1602 (void) ioctl (pi
.fd
, PIOCGREG
, &pi
.gregset
);
1604 fill_gregset (&pi
.gregset
, regno
);
1605 (void) ioctl (pi
.fd
, PIOCSREG
, &pi
.gregset
);
1607 #if defined (FP0_REGNUM)
1609 /* Now repeat everything using the floating point register set, if the
1610 target has floating point hardware. Since we ignore the returned value,
1611 we'll never know whether it worked or not anyway. */
1615 (void) ioctl (pi
.fd
, PIOCGFPREG
, &pi
.fpregset
);
1617 fill_fpregset (&pi
.fpregset
, regno
);
1618 (void) ioctl (pi
.fd
, PIOCSFPREG
, &pi
.fpregset
);
1620 #endif /* FP0_REGNUM */
1628 inferior_proc_init - initialize access to a /proc entry
1632 void inferior_proc_init (int pid)
1636 When gdb starts an inferior, this function is called in the parent
1637 process immediately after the fork. It waits for the child to stop
1638 on the return from the exec system call (the child itself takes care
1639 of ensuring that this is set up), then sets up the set of signals
1640 and faults that are to be traced.
1644 If proc_init_failed ever gets called, control returns to the command
1645 processing loop via the standard error handling code.
1650 inferior_proc_init (pid
)
1653 if (!open_proc_file (pid
, &pi
))
1655 proc_init_failed ("can't open process file");
1659 (void) memset ((char *) &pi
.prrun
, 0, sizeof (pi
.prrun
));
1660 prfillset (&pi
.prrun
.pr_trace
);
1661 proc_signal_handling_change ();
1662 prfillset (&pi
.prrun
.pr_fault
);
1663 prdelset (&pi
.prrun
.pr_fault
, FLTPAGE
);
1664 if (ioctl (pi
.fd
, PIOCWSTOP
, &pi
.prstatus
) < 0)
1666 proc_init_failed ("PIOCWSTOP failed");
1668 else if (ioctl (pi
.fd
, PIOCSFAULT
, &pi
.prrun
.pr_fault
) < 0)
1670 proc_init_failed ("PIOCSFAULT failed");
1679 proc_signal_handling_change
1683 void proc_signal_handling_change (void);
1687 When the user changes the state of gdb's signal handling via the
1688 "handle" command, this function gets called to see if any change
1689 in the /proc interface is required. It is also called internally
1690 by other /proc interface functions to initialize the state of
1691 the traced signal set.
1693 One thing it does is that signals for which the state is "nostop",
1694 "noprint", and "pass", have their trace bits reset in the pr_trace
1695 field, so that they are no longer traced. This allows them to be
1696 delivered directly to the inferior without the debugger ever being
1701 proc_signal_handling_change ()
1707 for (signo
= 0; signo
< NSIG
; signo
++)
1709 if (signal_stop_state (signo
) == 0 &&
1710 signal_print_state (signo
) == 0 &&
1711 signal_pass_state (signo
) == 1)
1713 prdelset (&pi
.prrun
.pr_trace
, signo
);
1717 praddset (&pi
.prrun
.pr_trace
, signo
);
1720 if (ioctl (pi
.fd
, PIOCSTRACE
, &pi
.prrun
.pr_trace
))
1722 print_sys_errmsg ("PIOCSTRACE failed", errno
);
1731 proc_set_exec_trap -- arrange for exec'd child to halt at startup
1735 void proc_set_exec_trap (void)
1739 This function is called in the child process when starting up
1740 an inferior, prior to doing the exec of the actual inferior.
1741 It sets the child process's exitset to make exit from the exec
1742 system call an event of interest to stop on, and then simply
1743 returns. The child does the exec, the system call returns, and
1744 the child stops at the first instruction, ready for the gdb
1745 parent process to take control of it.
1749 We need to use all local variables since the child may be sharing
1750 it's data space with the parent, if vfork was used rather than
1753 Also note that we want to turn off the inherit-on-fork flag in
1754 the child process so that any grand-children start with all
1755 tracing flags cleared.
1759 proc_set_exec_trap ()
1762 auto char procname
[32];
1765 (void) sprintf (procname
, PROC_NAME_FMT
, getpid ());
1766 if ((fd
= open (procname
, O_RDWR
)) < 0)
1772 premptyset (&exitset
);
1775 Not all systems with /proc have all the exec* syscalls with the same
1776 names. On the SGI, for example, there is no SYS_exec, but there
1777 *is* a SYS_execv. So, we try to account for that. */
1780 praddset (&exitset
, SYS_exec
);
1783 praddset (&exitset
, SYS_execve
);
1786 praddset(&exitset
, SYS_execv
);
1789 if (ioctl (fd
, PIOCSEXIT
, &exitset
) < 0)
1796 /* Turn off inherit-on-fork flag so that all grand-children of gdb
1797 start with tracing flags cleared. */
1799 #if defined (PIOCRESET) /* New method */
1803 (void) ioctl (fd
, PIOCRESET
, &pr_flags
);
1806 #if defined (PIOCRFORK) /* Original method */
1807 (void) ioctl (fd
, PIOCRFORK
, NULL
);
1816 proc_iterate_over_mappings -- call function for every mapped space
1820 int proc_iterate_over_mappings (int (*func)())
1824 Given a pointer to a function, call that function for every
1825 mapped address space, passing it an open file descriptor for
1826 the file corresponding to that mapped address space (if any)
1827 and the base address of the mapped space. Quit when we hit
1828 the end of the mappings or the function returns nonzero.
1832 proc_iterate_over_mappings (func
)
1833 int (*func
) PARAMS ((int, CORE_ADDR
));
1838 struct prmap
*prmaps
;
1839 struct prmap
*prmap
;
1840 CORE_ADDR baseaddr
= 0;
1842 if (pi
.valid
&& (ioctl (pi
.fd
, PIOCNMAP
, &nmap
) == 0))
1844 prmaps
= (struct prmap
*) alloca ((nmap
+ 1) * sizeof (*prmaps
));
1845 if (ioctl (pi
.fd
, PIOCMAP
, prmaps
) == 0)
1847 for (prmap
= prmaps
; prmap
-> pr_size
&& funcstat
== 0; ++prmap
)
1849 fd
= proc_address_to_fd ((CORE_ADDR
) prmap
-> pr_vaddr
, 0);
1850 funcstat
= (*func
) (fd
, (CORE_ADDR
) prmap
-> pr_vaddr
);
1862 proc_base_address -- find base address for segment containing address
1866 CORE_ADDR proc_base_address (CORE_ADDR addr)
1870 Given an address of a location in the inferior, find and return
1871 the base address of the mapped segment containing that address.
1873 This is used for example, by the shared library support code,
1874 where we have the pc value for some location in the shared library
1875 where we are stopped, and need to know the base address of the
1876 segment containing that address.
1880 #if 0 /* Currently unused */
1883 proc_base_address (addr
)
1887 struct prmap
*prmaps
;
1888 struct prmap
*prmap
;
1889 CORE_ADDR baseaddr
= 0;
1891 if (pi
.valid
&& (ioctl (pi
.fd
, PIOCNMAP
, &nmap
) == 0))
1893 prmaps
= (struct prmap
*) alloca ((nmap
+ 1) * sizeof (*prmaps
));
1894 if (ioctl (pi
.fd
, PIOCMAP
, prmaps
) == 0)
1896 for (prmap
= prmaps
; prmap
-> pr_size
; ++prmap
)
1898 if ((prmap
-> pr_vaddr
<= (caddr_t
) addr
) &&
1899 (prmap
-> pr_vaddr
+ prmap
-> pr_size
> (caddr_t
) addr
))
1901 baseaddr
= (CORE_ADDR
) prmap
-> pr_vaddr
;
1916 proc_address_to_fd -- return open fd for file mapped to address
1920 int proc_address_to_fd (CORE_ADDR addr, complain)
1924 Given an address in the current inferior's address space, use the
1925 /proc interface to find an open file descriptor for the file that
1926 this address was mapped in from. Return -1 if there is no current
1927 inferior. Print a warning message if there is an inferior but
1928 the address corresponds to no file (IE a bogus address).
1933 proc_address_to_fd (addr
, complain
)
1941 if ((fd
= ioctl (pi
.fd
, PIOCOPENM
, (caddr_t
*) &addr
)) < 0)
1945 print_sys_errmsg (pi
.pathname
, errno
);
1946 warning ("can't find mapped file for address 0x%x", addr
);
1954 #ifdef ATTACH_DETACH
1960 attach -- attach to an already existing process
1964 int attach (int pid)
1968 Attach to an already existing process with the specified process
1969 id. If the process is not already stopped, query whether to
1974 The option of stopping at attach time is specific to the /proc
1975 versions of gdb. Versions using ptrace force the attachee
1984 if (!open_proc_file (pid
, &pi
))
1986 perror_with_name (pi
.pathname
);
1990 /* Get current status of process and if it is not already stopped,
1991 then stop it. Remember whether or not it was stopped when we first
1994 if (ioctl (pi
.fd
, PIOCSTATUS
, &pi
.prstatus
) < 0)
1996 print_sys_errmsg (pi
.pathname
, errno
);
1997 close_proc_file (&pi
);
1998 error ("PIOCSTATUS failed");
2000 if (pi
.prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
))
2007 if (query ("Process is currently running, stop it? "))
2009 if (ioctl (pi
.fd
, PIOCSTOP
, &pi
.prstatus
) < 0)
2011 print_sys_errmsg (pi
.pathname
, errno
);
2012 close_proc_file (&pi
);
2013 error ("PIOCSTOP failed");
2018 /* Remember some things about the inferior that we will, or might, change
2019 so that we can restore them when we detach. */
2021 (void) ioctl (pi
.fd
, PIOCGTRACE
, &pi
.saved_trace
);
2022 (void) ioctl (pi
.fd
, PIOCGHOLD
, &pi
.saved_sighold
);
2023 (void) ioctl (pi
.fd
, PIOCGFAULT
, &pi
.saved_fltset
);
2024 (void) ioctl (pi
.fd
, PIOCGENTRY
, &pi
.saved_entryset
);
2025 (void) ioctl (pi
.fd
, PIOCGEXIT
, &pi
.saved_exitset
);
2027 /* Set up trace and fault sets, as gdb expects them. */
2029 (void) memset (&pi
.prrun
, 0, sizeof (pi
.prrun
));
2030 prfillset (&pi
.prrun
.pr_trace
);
2031 proc_signal_handling_change ();
2032 prfillset (&pi
.prrun
.pr_fault
);
2033 prdelset (&pi
.prrun
.pr_fault
, FLTPAGE
);
2034 if (ioctl (pi
.fd
, PIOCSFAULT
, &pi
.prrun
.pr_fault
))
2036 print_sys_errmsg ("PIOCSFAULT failed", errno
);
2038 if (ioctl (pi
.fd
, PIOCSTRACE
, &pi
.prrun
.pr_trace
))
2040 print_sys_errmsg ("PIOCSTRACE failed", errno
);
2050 detach -- detach from an attached-to process
2054 void detach (int signal)
2058 Detach from the current attachee.
2060 If signal is non-zero, the attachee is started running again and sent
2061 the specified signal.
2063 If signal is zero and the attachee was not already stopped when we
2064 attached to it, then we make it runnable again when we detach.
2066 Otherwise, we query whether or not to make the attachee runnable
2067 again, since we may simply want to leave it in the state it was in
2070 We report any problems, but do not consider them errors, since we
2071 MUST detach even if some things don't seem to go right. This may not
2072 be the ideal situation. (FIXME).
2081 set_proc_siginfo (&pi
, signal
);
2083 if (ioctl (pi
.fd
, PIOCSEXIT
, &pi
.saved_exitset
) < 0)
2085 print_sys_errmsg (pi
.pathname
, errno
);
2086 printf ("PIOCSEXIT failed.\n");
2088 if (ioctl (pi
.fd
, PIOCSENTRY
, &pi
.saved_entryset
) < 0)
2090 print_sys_errmsg (pi
.pathname
, errno
);
2091 printf ("PIOCSENTRY failed.\n");
2093 if (ioctl (pi
.fd
, PIOCSTRACE
, &pi
.saved_trace
) < 0)
2095 print_sys_errmsg (pi
.pathname
, errno
);
2096 printf ("PIOCSTRACE failed.\n");
2098 if (ioctl (pi
.fd
, PIOCSHOLD
, &pi
.saved_sighold
) < 0)
2100 print_sys_errmsg (pi
.pathname
, errno
);
2101 printf ("PIOSCHOLD failed.\n");
2103 if (ioctl (pi
.fd
, PIOCSFAULT
, &pi
.saved_fltset
) < 0)
2105 print_sys_errmsg (pi
.pathname
, errno
);
2106 printf ("PIOCSFAULT failed.\n");
2108 if (ioctl (pi
.fd
, PIOCSTATUS
, &pi
.prstatus
) < 0)
2110 print_sys_errmsg (pi
.pathname
, errno
);
2111 printf ("PIOCSTATUS failed.\n");
2115 if (signal
|| (pi
.prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
)))
2117 if (signal
|| !pi
.was_stopped
||
2118 query ("Was stopped when attached, make it runnable again? "))
2120 (void) memset (&pi
.prrun
, 0, sizeof (pi
.prrun
));
2121 pi
.prrun
.pr_flags
= PRCFAULT
;
2122 if (ioctl (pi
.fd
, PIOCRUN
, &pi
.prrun
))
2124 print_sys_errmsg (pi
.pathname
, errno
);
2125 printf ("PIOCRUN failed.\n");
2130 close_proc_file (&pi
);
2134 #endif /* ATTACH_DETACH */
2140 proc_wait -- emulate wait() as much as possible
2144 int proc_wait (int *statloc)
2148 Try to emulate wait() as much as possible. Not sure why we can't
2149 just use wait(), but it seems to have problems when applied to a
2150 process being controlled with the /proc interface.
2154 We have a race problem here with no obvious solution. We need to let
2155 the inferior run until it stops on an event of interest, which means
2156 that we need to use the PIOCWSTOP ioctl. However, we cannot use this
2157 ioctl if the process is already stopped on something that is not an
2158 event of interest, or the call will hang indefinitely. Thus we first
2159 use PIOCSTATUS to see if the process is not stopped. If not, then we
2160 use PIOCWSTOP. But during the window between the two, if the process
2161 stops for any reason that is not an event of interest (such as a job
2162 control signal) then gdb will hang. One possible workaround is to set
2163 an alarm to wake up every minute of so and check to see if the process
2164 is still running, and if so, then reissue the PIOCWSTOP. But this is
2165 a real kludge, so has not been implemented. FIXME: investigate
2168 FIXME: Investigate why wait() seems to have problems with programs
2169 being control by /proc routines.
2183 if (ioctl (pi
.fd
, PIOCSTATUS
, &pi
.prstatus
) < 0)
2187 else if (!(pi
.prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
)))
2189 if (ioctl (pi
.fd
, PIOCWSTOP
, &pi
.prstatus
) < 0)
2196 if (errno
== ENOENT
)
2198 rtnval
= wait (&statval
);
2199 if (rtnval
!= inferior_pid
)
2201 error ("PIOCWSTOP, wait failed, returned %d", rtnval
);
2207 print_sys_errmsg (pi
.pathname
, errno
);
2208 error ("PIOCSTATUS or PIOCWSTOP failed.");
2212 else if (pi
.prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
))
2214 rtnval
= pi
.prstatus
.pr_pid
;
2215 why
= pi
.prstatus
.pr_why
;
2216 what
= pi
.prstatus
.pr_what
;
2217 if (why
== PR_SIGNALLED
)
2219 statval
= (what
<< 8) | 0177;
2221 else if ((why
== PR_SYSEXIT
)
2230 || what
== SYS_execve
2233 || what
== SYS_execv
2237 statval
= (SIGTRAP
<< 8) | 0177;
2239 else if (why
== PR_REQUESTED
)
2241 statval
= (SIGSTOP
<< 8) | 0177;
2243 else if (why
== PR_JOBCONTROL
)
2245 statval
= (what
<< 8) | 0177;
2247 else if (why
== PR_FAULTED
)
2253 statval
= (SIGILL
<< 8) | 0177;
2257 statval
= (SIGTRAP
<< 8) | 0177;
2262 statval
= (SIGSEGV
<< 8) | 0177;
2267 statval
= (SIGFPE
<< 8) | 0177;
2269 case FLTPAGE
: /* Recoverable page fault */
2272 error ("PIOCWSTOP, unknown why %d, what %d", why
, what
);
2279 error ("PIOCWSTOP, unknown why %d, what %d", why
, what
);
2285 error ("PIOCWSTOP, stopped for unknown/unhandled reason, flags %#x",
2286 pi
.prstatus
.pr_flags
);
2300 set_proc_siginfo - set a process's current signal info
2304 void set_proc_siginfo (struct procinfo *pip, int signo);
2308 Given a pointer to a process info struct in PIP and a signal number
2309 in SIGNO, set the process's current signal and its associated signal
2310 information. The signal will be delivered to the process immediately
2311 after execution is resumed, even if it is being held. In addition,
2312 this particular delivery will not cause another PR_SIGNALLED stop
2313 even if the signal is being traced.
2315 If we are not delivering the same signal that the prstatus siginfo
2316 struct contains information about, then synthesize a siginfo struct
2317 to match the signal we are doing to deliver, make it of the type
2318 "generated by a user process", and send this synthesized copy. When
2319 used to set the inferior's signal state, this will be required if we
2320 are not currently stopped because of a traced signal, or if we decide
2321 to continue with a different signal.
2323 Note that when continuing the inferior from a stop due to receipt
2324 of a traced signal, we either have set PRCSIG to clear the existing
2325 signal, or we have to call this function to do a PIOCSSIG with either
2326 the existing siginfo struct from pr_info, or one we have synthesized
2327 appropriately for the signal we want to deliver. Otherwise if the
2328 signal is still being traced, the inferior will immediately stop
2331 See siginfo(5) for more details.
2335 set_proc_siginfo (pip
, signo
)
2336 struct procinfo
*pip
;
2339 struct siginfo newsiginfo
;
2340 struct siginfo
*sip
;
2344 if (signo
== pip
-> prstatus
.pr_info
.si_signo
)
2346 sip
= &pip
-> prstatus
.pr_info
;
2350 (void) memset ((char *) &newsiginfo
, 0, sizeof (newsiginfo
));
2352 sip
-> si_signo
= signo
;
2354 sip
-> si_errno
= 0;
2355 sip
-> si_pid
= getpid ();
2356 sip
-> si_uid
= getuid ();
2358 if (ioctl (pip
-> fd
, PIOCSSIG
, sip
) < 0)
2360 print_sys_errmsg (pip
-> pathname
, errno
);
2361 warning ("PIOCSSIG failed");
2370 child_resume -- resume execution of the inferior process
2374 void child_resume (int step, int signo)
2378 Resume execution of the inferior process. If STEP is nozero, then
2379 just single step it. If SIGNAL is nonzero, restart it with that
2384 It may not be absolutely necessary to specify the PC value for
2385 restarting, but to be safe we use the value that gdb considers
2386 to be current. One case where this might be necessary is if the
2387 user explicitly changes the PC value that gdb considers to be
2388 current. FIXME: Investigate if this is necessary or not.
2392 child_resume (step
, signo
)
2397 pi
.prrun
.pr_flags
= PRSVADDR
| PRSTRACE
| PRSFAULT
| PRCFAULT
;
2398 pi
.prrun
.pr_vaddr
= (caddr_t
) *(int *) ®isters
[REGISTER_BYTE (PC_REGNUM
)];
2401 set_proc_siginfo (&pi
, signo
);
2405 pi
.prrun
.pr_flags
|= PRCSIG
;
2409 pi
.prrun
.pr_flags
|= PRSTEP
;
2411 if (ioctl (pi
.fd
, PIOCRUN
, &pi
.prrun
) != 0)
2413 perror_with_name (pi
.pathname
);
2422 fetch_inferior_registers -- fetch current registers from inferior
2426 void fetch_inferior_registers (int regno)
2430 Read the current values of the inferior's registers, both the
2431 general register set and floating point registers (if supported)
2432 and update gdb's idea of their current values.
2437 fetch_inferior_registers (regno
)
2440 if (ioctl (pi
.fd
, PIOCGREG
, &pi
.gregset
) != -1)
2442 supply_gregset (&pi
.gregset
);
2444 #if defined (FP0_REGNUM)
2445 if (ioctl (pi
.fd
, PIOCGFPREG
, &pi
.fpregset
) != -1)
2447 supply_fpregset (&pi
.fpregset
);
2456 fetch_core_registers -- fetch current registers from core file data
2460 void fetch_core_registers (char *core_reg_sect, unsigned core_reg_size,
2461 int which, unsigned in reg_addr)
2465 Read the values of either the general register set (WHICH equals 0)
2466 or the floating point register set (WHICH equals 2) from the core
2467 file data (pointed to by CORE_REG_SECT), and update gdb's idea of
2468 their current values. The CORE_REG_SIZE parameter is ignored.
2472 Use the indicated sizes to validate the gregset and fpregset
2477 fetch_core_registers (core_reg_sect
, core_reg_size
, which
, reg_addr
)
2478 char *core_reg_sect
;
2479 unsigned core_reg_size
;
2481 unsigned int reg_addr
; /* Unused in this version */
2486 if (core_reg_size
!= sizeof (pi
.gregset
))
2488 warning ("wrong size gregset struct in core file");
2492 (void) memcpy ((char *) &pi
.gregset
, core_reg_sect
,
2493 sizeof (pi
.gregset
));
2494 supply_gregset (&pi
.gregset
);
2497 else if (which
== 2)
2499 if (core_reg_size
!= sizeof (pi
.fpregset
))
2501 warning ("wrong size fpregset struct in core file");
2505 (void) memcpy ((char *) &pi
.fpregset
, core_reg_sect
,
2506 sizeof (pi
.fpregset
));
2507 #if defined (FP0_REGNUM)
2508 supply_fpregset (&pi
.fpregset
);
2518 proc_init_failed - called whenever /proc access initialization fails
2522 static void proc_init_failed (char *why)
2526 This function is called whenever initialization of access to a /proc
2527 entry fails. It prints a suitable error message, does some cleanup,
2528 and then invokes the standard error processing routine which dumps
2529 us back into the command loop.
2533 proc_init_failed (why
)
2536 print_sys_errmsg (pi
.pathname
, errno
);
2537 (void) kill (pi
.pid
, SIGKILL
);
2538 close_proc_file (&pi
);
2547 close_proc_file - close any currently open /proc entry
2551 static void close_proc_file (struct procinfo *pip)
2555 Close any currently open /proc entry and mark the process information
2556 entry as invalid. In order to ensure that we don't try to reuse any
2557 stale information, the pid, fd, and pathnames are explicitly
2558 invalidated, which may be overkill.
2563 close_proc_file (pip
)
2564 struct procinfo
*pip
;
2569 (void) close (pip
-> fd
);
2572 if (pip
-> pathname
)
2574 free (pip
-> pathname
);
2575 pip
-> pathname
= NULL
;
2584 open_proc_file - open a /proc entry for a given process id
2588 static int open_proc_file (pid, struct procinfo *pip)
2592 Given a process id, close the existing open /proc entry (if any)
2593 and open one for the new process id. Once it is open, then
2594 mark the local process information structure as valid, which
2595 guarantees that the pid, fd, and pathname fields match an open
2596 /proc entry. Returns zero if the open fails, nonzero otherwise.
2598 Note that the pathname is left intact, even when the open fails,
2599 so that callers can use it to construct meaningful error messages
2600 rather than just "file open failed".
2604 open_proc_file (pid
, pip
)
2606 struct procinfo
*pip
;
2611 (void) close (pip
-> fd
);
2613 if (pip
-> pathname
== NULL
)
2615 pip
-> pathname
= xmalloc (32);
2617 sprintf (pip
-> pathname
, PROC_NAME_FMT
, pid
);
2618 if ((pip
-> fd
= open (pip
-> pathname
, O_RDWR
)) >= 0)
2623 return (pip
-> valid
);
2627 mappingflags (flags
)
2630 static char asciiflags
[8];
2632 strcpy (asciiflags
, "-------");
2633 #if defined (MA_PHYS)
2634 if (flags
& MA_PHYS
) asciiflags
[0] = 'd';
2636 if (flags
& MA_STACK
) asciiflags
[1] = 's';
2637 if (flags
& MA_BREAK
) asciiflags
[2] = 'b';
2638 if (flags
& MA_SHARED
) asciiflags
[3] = 's';
2639 if (flags
& MA_READ
) asciiflags
[4] = 'r';
2640 if (flags
& MA_WRITE
) asciiflags
[5] = 'w';
2641 if (flags
& MA_EXEC
) asciiflags
[6] = 'x';
2642 return (asciiflags
);
2646 info_proc_flags (pip
, summary
)
2647 struct procinfo
*pip
;
2650 struct trans
*transp
;
2652 printf_filtered ("%-32s", "Process status flags:");
2655 printf_filtered ("\n\n");
2657 for (transp
= pr_flag_table
; transp
-> name
!= NULL
; transp
++)
2659 if (pip
-> prstatus
.pr_flags
& transp
-> value
)
2663 printf_filtered ("%s ", transp
-> name
);
2667 printf_filtered ("\t%-16s %s.\n", transp
-> name
, transp
-> desc
);
2671 printf_filtered ("\n");
2675 info_proc_stop (pip
, summary
)
2676 struct procinfo
*pip
;
2679 struct trans
*transp
;
2683 why
= pip
-> prstatus
.pr_why
;
2684 what
= pip
-> prstatus
.pr_what
;
2686 if (pip
-> prstatus
.pr_flags
& PR_STOPPED
)
2688 printf_filtered ("%-32s", "Reason for stopping:");
2691 printf_filtered ("\n\n");
2693 for (transp
= pr_why_table
; transp
-> name
!= NULL
; transp
++)
2695 if (why
== transp
-> value
)
2699 printf_filtered ("%s ", transp
-> name
);
2703 printf_filtered ("\t%-16s %s.\n",
2704 transp
-> name
, transp
-> desc
);
2710 /* Use the pr_why field to determine what the pr_what field means, and
2711 print more information. */
2716 /* pr_what is unused for this case */
2722 printf_filtered ("%s ", signalname (what
));
2726 printf_filtered ("\t%-16s %s.\n", signalname (what
),
2733 printf_filtered ("%s ", syscallname (what
));
2737 printf_filtered ("\t%-16s %s.\n", syscallname (what
),
2738 "Entered this system call");
2744 printf_filtered ("%s ", syscallname (what
));
2748 printf_filtered ("\t%-16s %s.\n", syscallname (what
),
2749 "Returned from this system call");
2755 printf_filtered ("%s ",
2756 lookupname (faults_table
, what
, "fault"));
2760 printf_filtered ("\t%-16s %s.\n",
2761 lookupname (faults_table
, what
, "fault"),
2762 lookupdesc (faults_table
, what
));
2766 printf_filtered ("\n");
2771 info_proc_siginfo (pip
, summary
)
2772 struct procinfo
*pip
;
2775 struct siginfo
*sip
;
2777 if ((pip
-> prstatus
.pr_flags
& PR_STOPPED
) &&
2778 (pip
-> prstatus
.pr_why
== PR_SIGNALLED
||
2779 pip
-> prstatus
.pr_why
== PR_FAULTED
))
2781 printf_filtered ("%-32s", "Additional signal/fault info:");
2782 sip
= &pip
-> prstatus
.pr_info
;
2785 printf_filtered ("%s ", signalname (sip
-> si_signo
));
2786 if (sip
-> si_errno
> 0)
2788 printf_filtered ("%s ", lookupname (errno_table
,
2789 sip
-> si_errno
, "errno"));
2791 if (sip
-> si_code
<= 0)
2793 printf_filtered ("sent by pid %d, uid %d ", sip
-> si_pid
,
2798 printf_filtered ("%s ", sigcodename (sip
));
2799 if ((sip
-> si_signo
== SIGILL
) ||
2800 (sip
-> si_signo
== SIGFPE
) ||
2801 (sip
-> si_signo
== SIGSEGV
) ||
2802 (sip
-> si_signo
== SIGBUS
))
2804 printf_filtered ("addr=%#x ", sip
-> si_addr
);
2806 else if ((sip
-> si_signo
== SIGCHLD
))
2808 printf_filtered ("child pid %u, status %u ",
2812 else if ((sip
-> si_signo
== SIGPOLL
))
2814 printf_filtered ("band %u ", sip
-> si_band
);
2820 printf_filtered ("\n\n");
2821 printf_filtered ("\t%-16s %s.\n", signalname (sip
-> si_signo
),
2822 sys_siglist
[sip
-> si_signo
]);
2823 if (sip
-> si_errno
> 0)
2825 printf_filtered ("\t%-16s %s.\n",
2826 lookupname (errno_table
,
2827 sip
-> si_errno
, "errno"),
2828 lookupdesc (errno_table
, sip
-> si_errno
));
2830 if (sip
-> si_code
<= 0)
2832 printf_filtered ("\t%-16u %s\n", sip
-> si_pid
,
2833 "PID of process sending signal");
2834 printf_filtered ("\t%-16u %s\n", sip
-> si_uid
,
2835 "UID of process sending signal");
2839 printf_filtered ("\t%-16s %s.\n", sigcodename (sip
),
2841 if ((sip
-> si_signo
== SIGILL
) ||
2842 (sip
-> si_signo
== SIGFPE
))
2844 printf_filtered ("\t%-16#x %s.\n", sip
-> si_addr
,
2845 "Address of faulting instruction");
2847 else if ((sip
-> si_signo
== SIGSEGV
) ||
2848 (sip
-> si_signo
== SIGBUS
))
2850 printf_filtered ("\t%-16#x %s.\n", sip
-> si_addr
,
2851 "Address of faulting memory reference");
2853 else if ((sip
-> si_signo
== SIGCHLD
))
2855 printf_filtered ("\t%-16u %s.\n", sip
-> si_pid
,
2856 "Child process ID");
2857 printf_filtered ("\t%-16u %s.\n", sip
-> si_status
,
2858 "Child process exit value or signal");
2860 else if ((sip
-> si_signo
== SIGPOLL
))
2862 printf_filtered ("\t%-16u %s.\n", sip
-> si_band
,
2863 "Band event for POLL_{IN,OUT,MSG}");
2867 printf_filtered ("\n");
2872 info_proc_syscalls (pip
, summary
)
2873 struct procinfo
*pip
;
2881 #if 0 /* FIXME: Needs to use gdb-wide configured info about system calls. */
2882 if (pip
-> prstatus
.pr_flags
& PR_ASLEEP
)
2884 int syscallnum
= pip
-> prstatus
.pr_reg
[R_D0
];
2887 printf_filtered ("%-32s", "Sleeping in system call:");
2888 printf_filtered ("%s", syscallname (syscallnum
));
2892 printf_filtered ("Sleeping in system call '%s'.\n",
2893 syscallname (syscallnum
));
2898 if (ioctl (pip
-> fd
, PIOCGENTRY
, &pip
-> entryset
) < 0)
2900 print_sys_errmsg (pip
-> pathname
, errno
);
2901 error ("PIOCGENTRY failed");
2904 if (ioctl (pip
-> fd
, PIOCGEXIT
, &pip
-> exitset
) < 0)
2906 print_sys_errmsg (pip
-> pathname
, errno
);
2907 error ("PIOCGEXIT failed");
2910 printf_filtered ("System call tracing information:\n\n");
2912 printf_filtered ("\t%-12s %-8s %-8s\n",
2916 for (syscallnum
= 0; syscallnum
< MAX_SYSCALLS
; syscallnum
++)
2919 if (syscall_table
[syscallnum
] != NULL
)
2921 printf_filtered ("\t%-12s ", syscall_table
[syscallnum
]);
2922 printf_filtered ("%-8s ",
2923 prismember (&pip
-> entryset
, syscallnum
)
2925 printf_filtered ("%-8s ",
2926 prismember (&pip
-> exitset
, syscallnum
)
2928 printf_filtered ("\n");
2931 printf_filtered ("\n");
2940 static char locbuf
[32];
2942 abbrev
= sig_abbrev (signo
);
2945 sprintf (locbuf
, "signal %d", signo
);
2949 sprintf (locbuf
, "SIG%s (%d)", abbrev
, signo
);
2955 info_proc_signals (pip
, summary
)
2956 struct procinfo
*pip
;
2963 if (ioctl (pip
-> fd
, PIOCGTRACE
, &pip
-> trace
) < 0)
2965 print_sys_errmsg (pip
-> pathname
, errno
);
2966 error ("PIOCGTRACE failed");
2969 printf_filtered ("Disposition of signals:\n\n");
2970 printf_filtered ("\t%-15s %-8s %-8s %-8s %s\n\n",
2971 "Signal", "Trace", "Hold", "Pending", "Description");
2972 for (signo
= 0; signo
< NSIG
; signo
++)
2975 printf_filtered ("\t%-15s ", signalname (signo
));
2976 printf_filtered ("%-8s ",
2977 prismember (&pip
-> trace
, signo
)
2979 printf_filtered ("%-8s ",
2980 prismember (&pip
-> prstatus
.pr_sighold
, signo
)
2982 printf_filtered ("%-8s ",
2983 prismember (&pip
-> prstatus
.pr_sigpend
, signo
)
2985 printf_filtered (" %s\n", sys_siglist
[signo
]);
2987 printf_filtered ("\n");
2992 info_proc_faults (pip
, summary
)
2993 struct procinfo
*pip
;
2996 struct trans
*transp
;
3000 if (ioctl (pip
-> fd
, PIOCGFAULT
, &pip
-> fltset
) < 0)
3002 print_sys_errmsg (pip
-> pathname
, errno
);
3003 error ("PIOCGFAULT failed");
3006 printf_filtered ("Current traced hardware fault set:\n\n");
3007 printf_filtered ("\t%-12s %-8s\n", "Fault", "Trace");
3009 for (transp
= faults_table
; transp
-> name
!= NULL
; transp
++)
3012 printf_filtered ("\t%-12s ", transp
-> name
);
3013 printf_filtered ("%-8s", prismember (&pip
-> fltset
, transp
-> value
)
3015 printf_filtered ("\n");
3017 printf_filtered ("\n");
3022 info_proc_mappings (pip
, summary
)
3023 struct procinfo
*pip
;
3027 struct prmap
*prmaps
;
3028 struct prmap
*prmap
;
3032 printf_filtered ("Mapped address spaces:\n\n");
3033 printf_filtered ("\t%10s %10s %10s %10s %7s\n",
3039 if (ioctl (pip
-> fd
, PIOCNMAP
, &nmap
) == 0)
3041 prmaps
= (struct prmap
*) alloca ((nmap
+ 1) * sizeof (*prmaps
));
3042 if (ioctl (pip
-> fd
, PIOCMAP
, prmaps
) == 0)
3044 for (prmap
= prmaps
; prmap
-> pr_size
; ++prmap
)
3046 printf_filtered ("\t%#10x %#10x %#10x %#10x %7s\n",
3048 prmap
-> pr_vaddr
+ prmap
-> pr_size
- 1,
3051 mappingflags (prmap
-> pr_mflags
));
3055 printf_filtered ("\n");
3063 info_proc -- implement the "info proc" command
3067 void info_proc (char *args, int from_tty)
3071 Implement gdb's "info proc" command by using the /proc interface
3072 to print status information about any currently running process.
3074 Examples of the use of "info proc" are:
3076 info proc (prints summary info for current inferior)
3077 info proc 123 (prints summary info for process with pid 123)
3078 info proc mappings (prints address mappings)
3079 info proc times (prints process/children times)
3080 info proc id (prints pid, ppid, gid, sid, etc)
3081 info proc status (prints general process state info)
3082 info proc signals (prints info about signal handling)
3083 info proc all (prints all info)
3088 info_proc (args
, from_tty
)
3093 struct procinfo pii
;
3094 struct procinfo
*pip
;
3095 struct cleanup
*old_chain
;
3110 old_chain
= make_cleanup (null_cleanup
, 0);
3112 /* Default to using the current inferior if no pid specified */
3118 if ((argv
= buildargv (args
)) == NULL
)
3122 make_cleanup (freeargv
, (char *) argv
);
3124 while (*argv
!= NULL
)
3126 argsize
= strlen (*argv
);
3127 if (argsize
>= 1 && strncmp (*argv
, "all", argsize
) == 0)
3132 else if (argsize
>= 2 && strncmp (*argv
, "faults", argsize
) == 0)
3137 else if (argsize
>= 2 && strncmp (*argv
, "flags", argsize
) == 0)
3142 else if (argsize
>= 1 && strncmp (*argv
, "id", argsize
) == 0)
3147 else if (argsize
>= 1 && strncmp (*argv
, "mappings", argsize
) == 0)
3152 else if (argsize
>= 2 && strncmp (*argv
, "signals", argsize
) == 0)
3157 else if (argsize
>= 2 && strncmp (*argv
, "status", argsize
) == 0)
3162 else if (argsize
>= 2 && strncmp (*argv
, "syscalls", argsize
) == 0)
3167 else if (argsize
>= 1 && strncmp (*argv
, "times", argsize
) == 0)
3172 else if ((pii
.pid
= atoi (*argv
)) > 0)
3176 (void) memset (&pii
, 0, sizeof (pii
));
3177 if (!open_proc_file (pid
, pip
))
3179 perror_with_name (pip
-> pathname
);
3182 make_cleanup (close_proc_file
, pip
);
3184 else if (**argv
!= '\000')
3186 error ("Unrecognized or ambiguous keyword `%s'.", *argv
);
3192 /* If we don't have a valid open process at this point, then we have no
3193 inferior or didn't specify a specific pid. */
3197 error ("No process. Run an inferior or specify an explicit pid.");
3199 if (ioctl (pip
-> fd
, PIOCSTATUS
, &(pip
-> prstatus
)) < 0)
3201 print_sys_errmsg (pip
-> pathname
, errno
);
3202 error ("PIOCSTATUS failed");
3205 /* Print verbose information of the requested type(s), or just a summary
3206 of the information for all types. */
3208 printf_filtered ("\nInformation for %s:\n\n", pip
-> pathname
);
3209 if (summary
|| all
|| flags
)
3211 info_proc_flags (pip
, summary
);
3215 info_proc_stop (pip
, summary
);
3217 if (summary
|| all
|| signals
|| faults
)
3219 info_proc_siginfo (pip
, summary
);
3221 if (summary
|| all
|| syscalls
)
3223 info_proc_syscalls (pip
, summary
);
3225 if (summary
|| all
|| mappings
)
3227 info_proc_mappings (pip
, summary
);
3229 if (summary
|| all
|| signals
)
3231 info_proc_signals (pip
, summary
);
3233 if (summary
|| all
|| faults
)
3235 info_proc_faults (pip
, summary
);
3237 printf_filtered ("\n");
3239 /* All done, deal with closing any temporary process info structure,
3240 freeing temporary memory , etc. */
3242 do_cleanups (old_chain
);
3249 _initialize_proc_fs -- initialize the process file system stuff
3253 void _initialize_proc_fs (void)
3257 Do required initializations during gdb startup for using the
3258 /proc file system interface.
3262 static char *proc_desc
=
3263 "Show process status information using /proc entry.\n\
3264 Specify process id or use current inferior by default.\n\
3265 Specify keywords for detailed information; default is summary.\n\
3266 Keywords are: `all', `faults', `flags', `id', `mappings', `signals',\n\
3267 `status', `syscalls', and `times'.\n\
3268 Unambiguous abbreviations may be used.";
3271 _initialize_proc_fs ()
3273 add_info ("proc", info_proc
, proc_desc
);
3274 init_syscall_table ();
3277 #endif /* USE_PROC_FS */