1 /* Machine independent support for SVR4 /proc (process file system) for GDB.
2 Copyright 1991, 1992 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.
38 #include <sys/procfs.h>
48 #define MAX_SYSCALLS 256 /* Maximum number of syscalls for table */
51 #define PROC_NAME_FMT "/proc/%05d"
54 extern struct target_ops procfs_ops
; /* Forward declaration */
56 #if 1 /* FIXME: Gross and ugly hack to resolve coredep.c global */
57 CORE_ADDR kernel_u_addr
;
60 #ifdef BROKEN_SIGINFO_H /* Workaround broken SGS <sys/siginfo.h> */
62 #define si_pid _data._proc.pid
64 #define si_uid _data._proc._pdata._kill.uid
65 #endif /* BROKEN_SIGINFO_H */
67 /* All access to the inferior, either one started by gdb or one that has
68 been attached to, is controlled by an instance of a procinfo structure,
69 defined below. Since gdb currently only handles one inferior at a time,
70 the procinfo structure for the inferior is statically allocated and
71 only one exists at any given time. There is a separate procinfo
72 structure for use by the "info proc" command, so that we can print
73 useful information about any random process without interfering with
74 the inferior's procinfo information. */
77 int valid
; /* Nonzero if pid, fd, & pathname are valid */
78 int pid
; /* Process ID of inferior */
79 int fd
; /* File descriptor for /proc entry */
80 char *pathname
; /* Pathname to /proc entry */
81 int was_stopped
; /* Nonzero if was stopped prior to attach */
82 int nopass_next_sigstop
; /* Don't pass a sigstop on next resume */
83 prrun_t prrun
; /* Control state when it is run */
84 prstatus_t prstatus
; /* Current process status info */
85 gregset_t gregset
; /* General register set */
86 fpregset_t fpregset
; /* Floating point register set */
87 fltset_t fltset
; /* Current traced hardware fault set */
88 sigset_t trace
; /* Current traced signal set */
89 sysset_t exitset
; /* Current traced system call exit set */
90 sysset_t entryset
; /* Current traced system call entry set */
91 fltset_t saved_fltset
; /* Saved traced hardware fault set */
92 sigset_t saved_trace
; /* Saved traced signal set */
93 sigset_t saved_sighold
; /* Saved held signal set */
94 sysset_t saved_exitset
; /* Saved traced system call exit set */
95 sysset_t saved_entryset
; /* Saved traced system call entry set */
98 static struct procinfo pi
; /* Inferior's process information */
100 /* Much of the information used in the /proc interface, particularly for
101 printing status information, is kept as tables of structures of the
102 following form. These tables can be used to map numeric values to
103 their symbolic names and to a string that describes their specific use. */
106 int value
; /* The numeric value */
107 char *name
; /* The equivalent symbolic value */
108 char *desc
; /* Short description of value */
111 /* Translate bits in the pr_flags member of the prstatus structure, into the
112 names and desc information. */
114 static struct trans pr_flag_table
[] =
116 #if defined (PR_STOPPED)
117 PR_STOPPED
, "PR_STOPPED", "Process is stopped",
119 #if defined (PR_ISTOP)
120 PR_ISTOP
, "PR_ISTOP", "Stopped on an event of interest",
122 #if defined (PR_DSTOP)
123 PR_DSTOP
, "PR_DSTOP", "A stop directive is in effect",
125 #if defined (PR_ASLEEP)
126 PR_ASLEEP
, "PR_ASLEEP", "Sleeping in an interruptible system call",
128 #if defined (PR_FORK)
129 PR_FORK
, "PR_FORK", "Inherit-on-fork is in effect",
132 PR_RLC
, "PR_RLC", "Run-on-last-close is in effect",
134 #if defined (PR_PTRACE)
135 PR_PTRACE
, "PR_PTRACE", "Process is being controlled by ptrace",
137 #if defined (PR_PCINVAL)
138 PR_PCINVAL
, "PR_PCINVAL", "PC refers to an invalid virtual address",
140 #if defined (PR_ISSYS)
141 PR_ISSYS
, "PR_ISSYS", "Is a system process",
143 #if defined (PR_STEP)
144 PR_STEP
, "PR_STEP", "Process has single step pending",
147 PR_KLC
, "PR_KLC", "Kill-on-last-close is in effect",
149 #if defined (PR_ASYNC)
150 PR_ASYNC
, "PR_ASYNC", "Asynchronous stop is in effect",
152 #if defined (PR_PCOMPAT)
153 PR_PCOMPAT
, "PR_PCOMPAT", "Ptrace compatibility mode in effect",
158 /* Translate values in the pr_why field of the prstatus struct. */
160 static struct trans pr_why_table
[] =
162 #if defined (PR_REQUESTED)
163 PR_REQUESTED
, "PR_REQUESTED", "Directed to stop via PIOCSTOP/PIOCWSTOP",
165 #if defined (PR_SIGNALLED)
166 PR_SIGNALLED
, "PR_SIGNALLED", "Receipt of a traced signal",
168 #if defined (PR_FAULTED)
169 PR_FAULTED
, "PR_FAULTED", "Incurred a traced hardware fault",
171 #if defined (PR_SYSENTRY)
172 PR_SYSENTRY
, "PR_SYSENTRY", "Entry to a traced system call",
174 #if defined (PR_SYSEXIT)
175 PR_SYSEXIT
, "PR_SYSEXIT", "Exit from a traced system call",
177 #if defined (PR_JOBCONTROL)
178 PR_JOBCONTROL
, "PR_JOBCONTROL", "Default job control stop signal action",
180 #if defined (PR_SUSPENDED)
181 PR_SUSPENDED
, "PR_SUSPENDED", "Process suspended",
186 /* Hardware fault translation table. */
188 static struct trans faults_table
[] =
191 FLTILL
, "FLTILL", "Illegal instruction",
193 #if defined (FLTPRIV)
194 FLTPRIV
, "FLTPRIV", "Privileged instruction",
197 FLTBPT
, "FLTBPT", "Breakpoint trap",
199 #if defined (FLTTRACE)
200 FLTTRACE
, "FLTTRACE", "Trace trap",
202 #if defined (FLTACCESS)
203 FLTACCESS
, "FLTACCESS", "Memory access fault",
205 #if defined (FLTBOUNDS)
206 FLTBOUNDS
, "FLTBOUNDS", "Memory bounds violation",
208 #if defined (FLTIOVF)
209 FLTIOVF
, "FLTIOVF", "Integer overflow",
211 #if defined (FLTIZDIV)
212 FLTIZDIV
, "FLTIZDIV", "Integer zero divide",
215 FLTFPE
, "FLTFPE", "Floating-point exception",
217 #if defined (FLTSTACK)
218 FLTSTACK
, "FLTSTACK", "Unrecoverable stack fault",
220 #if defined (FLTPAGE)
221 FLTPAGE
, "FLTPAGE", "Recoverable page fault",
226 /* Translation table for signal generation information. See UNIX System
227 V Release 4 Programmer's Reference Manual, siginfo(5). */
229 static struct sigcode
{
234 } siginfo_table
[] = {
235 #if defined (SIGILL) && defined (ILL_ILLOPC)
236 SIGILL
, ILL_ILLOPC
, "ILL_ILLOPC", "Illegal opcode",
238 #if defined (SIGILL) && defined (ILL_ILLOPN)
239 SIGILL
, ILL_ILLOPN
, "ILL_ILLOPN", "Illegal operand",
241 #if defined (SIGILL) && defined (ILL_ILLADR)
242 SIGILL
, ILL_ILLADR
, "ILL_ILLADR", "Illegal addressing mode",
244 #if defined (SIGILL) && defined (ILL_ILLTRP)
245 SIGILL
, ILL_ILLTRP
, "ILL_ILLTRP", "Illegal trap",
247 #if defined (SIGILL) && defined (ILL_PRVOPC)
248 SIGILL
, ILL_PRVOPC
, "ILL_PRVOPC", "Privileged opcode",
250 #if defined (SIGILL) && defined (ILL_PRVREG)
251 SIGILL
, ILL_PRVREG
, "ILL_PRVREG", "Privileged register",
253 #if defined (SIGILL) && defined (ILL_COPROC)
254 SIGILL
, ILL_COPROC
, "ILL_COPROC", "Coprocessor error",
256 #if defined (SIGILL) && defined (ILL_BADSTK)
257 SIGILL
, ILL_BADSTK
, "ILL_BADSTK", "Internal stack error",
259 #if defined (SIGFPE) && defined (FPE_INTDIV)
260 SIGFPE
, FPE_INTDIV
, "FPE_INTDIV", "Integer divide by zero",
262 #if defined (SIGFPE) && defined (FPE_INTOVF)
263 SIGFPE
, FPE_INTOVF
, "FPE_INTOVF", "Integer overflow",
265 #if defined (SIGFPE) && defined (FPE_FLTDIV)
266 SIGFPE
, FPE_FLTDIV
, "FPE_FLTDIV", "Floating point divide by zero",
268 #if defined (SIGFPE) && defined (FPE_FLTOVF)
269 SIGFPE
, FPE_FLTOVF
, "FPE_FLTOVF", "Floating point overflow",
271 #if defined (SIGFPE) && defined (FPE_FLTUND)
272 SIGFPE
, FPE_FLTUND
, "FPE_FLTUND", "Floating point underflow",
274 #if defined (SIGFPE) && defined (FPE_FLTRES)
275 SIGFPE
, FPE_FLTRES
, "FPE_FLTRES", "Floating point inexact result",
277 #if defined (SIGFPE) && defined (FPE_FLTINV)
278 SIGFPE
, FPE_FLTINV
, "FPE_FLTINV", "Invalid floating point operation",
280 #if defined (SIGFPE) && defined (FPE_FLTSUB)
281 SIGFPE
, FPE_FLTSUB
, "FPE_FLTSUB", "Subscript out of range",
283 #if defined (SIGSEGV) && defined (SEGV_MAPERR)
284 SIGSEGV
, SEGV_MAPERR
, "SEGV_MAPERR", "Address not mapped to object",
286 #if defined (SIGSEGV) && defined (SEGV_ACCERR)
287 SIGSEGV
, SEGV_ACCERR
, "SEGV_ACCERR", "Invalid permissions for object",
289 #if defined (SIGBUS) && defined (BUS_ADRALN)
290 SIGBUS
, BUS_ADRALN
, "BUS_ADRALN", "Invalid address alignment",
292 #if defined (SIGBUS) && defined (BUS_ADRERR)
293 SIGBUS
, BUS_ADRERR
, "BUS_ADRERR", "Non-existent physical address",
295 #if defined (SIGBUS) && defined (BUS_OBJERR)
296 SIGBUS
, BUS_OBJERR
, "BUS_OBJERR", "Object specific hardware error",
298 #if defined (SIGTRAP) && defined (TRAP_BRKPT)
299 SIGTRAP
, TRAP_BRKPT
, "TRAP_BRKPT", "Process breakpoint",
301 #if defined (SIGTRAP) && defined (TRAP_TRACE)
302 SIGTRAP
, TRAP_TRACE
, "TRAP_TRACE", "Process trace trap",
304 #if defined (SIGCLD) && defined (CLD_EXITED)
305 SIGCLD
, CLD_EXITED
, "CLD_EXITED", "Child has exited",
307 #if defined (SIGCLD) && defined (CLD_KILLED)
308 SIGCLD
, CLD_KILLED
, "CLD_KILLED", "Child was killed",
310 #if defined (SIGCLD) && defined (CLD_DUMPED)
311 SIGCLD
, CLD_DUMPED
, "CLD_DUMPED", "Child has terminated abnormally",
313 #if defined (SIGCLD) && defined (CLD_TRAPPED)
314 SIGCLD
, CLD_TRAPPED
, "CLD_TRAPPED", "Traced child has trapped",
316 #if defined (SIGCLD) && defined (CLD_STOPPED)
317 SIGCLD
, CLD_STOPPED
, "CLD_STOPPED", "Child has stopped",
319 #if defined (SIGCLD) && defined (CLD_CONTINUED)
320 SIGCLD
, CLD_CONTINUED
, "CLD_CONTINUED", "Stopped child had continued",
322 #if defined (SIGPOLL) && defined (POLL_IN)
323 SIGPOLL
, POLL_IN
, "POLL_IN", "Input input available",
325 #if defined (SIGPOLL) && defined (POLL_OUT)
326 SIGPOLL
, POLL_OUT
, "POLL_OUT", "Output buffers available",
328 #if defined (SIGPOLL) && defined (POLL_MSG)
329 SIGPOLL
, POLL_MSG
, "POLL_MSG", "Input message available",
331 #if defined (SIGPOLL) && defined (POLL_ERR)
332 SIGPOLL
, POLL_ERR
, "POLL_ERR", "I/O error",
334 #if defined (SIGPOLL) && defined (POLL_PRI)
335 SIGPOLL
, POLL_PRI
, "POLL_PRI", "High priority input available",
337 #if defined (SIGPOLL) && defined (POLL_HUP)
338 SIGPOLL
, POLL_HUP
, "POLL_HUP", "Device disconnected",
343 static char *syscall_table
[MAX_SYSCALLS
];
345 /* Prototypes for local functions */
348 set_proc_siginfo
PARAMS ((struct procinfo
*, int));
351 init_syscall_table
PARAMS ((void));
354 syscallname
PARAMS ((int));
357 signalname
PARAMS ((int));
360 errnoname
PARAMS ((int));
363 proc_address_to_fd
PARAMS ((CORE_ADDR
, int));
366 open_proc_file
PARAMS ((int, struct procinfo
*, int));
369 close_proc_file
PARAMS ((struct procinfo
*));
372 unconditionally_kill_inferior
PARAMS ((void));
375 proc_init_failed
PARAMS ((char *));
378 info_proc
PARAMS ((char *, int));
381 info_proc_flags
PARAMS ((struct procinfo
*, int));
384 info_proc_stop
PARAMS ((struct procinfo
*, int));
387 info_proc_siginfo
PARAMS ((struct procinfo
*, int));
390 info_proc_syscalls
PARAMS ((struct procinfo
*, int));
393 info_proc_mappings
PARAMS ((struct procinfo
*, int));
396 info_proc_signals
PARAMS ((struct procinfo
*, int));
399 info_proc_faults
PARAMS ((struct procinfo
*, int));
402 mappingflags
PARAMS ((long));
405 lookupname
PARAMS ((struct trans
*, unsigned int, char *));
408 lookupdesc
PARAMS ((struct trans
*, unsigned int));
411 do_attach
PARAMS ((int pid
));
414 do_detach
PARAMS ((int siggnal
));
417 procfs_create_inferior
PARAMS ((char *, char *, char **));
419 /* External function prototypes that can't be easily included in any
420 header file because the args are typedefs in system include files. */
423 supply_gregset
PARAMS ((gregset_t
*));
426 fill_gregset
PARAMS ((gregset_t
*, int));
429 supply_fpregset
PARAMS ((fpregset_t
*));
432 fill_fpregset
PARAMS ((fpregset_t
*, int));
438 lookupdesc -- translate a value to a summary desc string
442 static char *lookupdesc (struct trans *transp, unsigned int val);
446 Given a pointer to a translation table and a value to be translated,
447 lookup the desc string and return it.
451 lookupdesc (transp
, val
)
452 struct trans
*transp
;
457 for (desc
= NULL
; transp
-> name
!= NULL
; transp
++)
459 if (transp
-> value
== val
)
461 desc
= transp
-> desc
;
466 /* Didn't find a translation for the specified value, set a default one. */
479 lookupname -- translate a value to symbolic name
483 static char *lookupname (struct trans *transp, unsigned int val,
488 Given a pointer to a translation table, a value to be translated,
489 and a default prefix to return if the value can't be translated,
490 match the value with one of the translation table entries and
491 return a pointer to the symbolic name.
493 If no match is found it just returns the value as a printable string,
494 with the given prefix. The previous such value, if any, is freed
499 lookupname (transp
, val
, prefix
)
500 struct trans
*transp
;
507 for (name
= NULL
; transp
-> name
!= NULL
; transp
++)
509 if (transp
-> value
== val
)
511 name
= transp
-> name
;
516 /* Didn't find a translation for the specified value, build a default
517 one using the specified prefix and return it. The lifetime of
518 the value is only until the next one is needed. */
526 locbuf
= xmalloc (strlen (prefix
) + 16);
527 sprintf (locbuf
, "%s %u", prefix
, val
);
539 static char locbuf
[32];
541 for (scp
= siginfo_table
; scp
-> codename
!= NULL
; scp
++)
543 if ((scp
-> signo
== sip
-> si_signo
) &&
544 (scp
-> code
== sip
-> si_code
))
546 name
= scp
-> codename
;
552 sprintf (locbuf
, "sigcode %u", sip
-> si_signo
);
565 for (scp
= siginfo_table
; scp
-> codename
!= NULL
; scp
++)
567 if ((scp
-> signo
== sip
-> si_signo
) &&
568 (scp
-> code
== sip
-> si_code
))
576 desc
= "Unrecognized signal or trap use";
585 syscallname - translate a system call number into a system call name
589 char *syscallname (int syscallnum)
593 Given a system call number, translate it into the printable name
594 of a system call, or into "syscall <num>" if it is an unknown
599 syscallname (syscallnum
)
602 static char locbuf
[32];
605 if (syscallnum
>= 0 && syscallnum
< MAX_SYSCALLS
)
607 rtnval
= syscall_table
[syscallnum
];
611 sprintf (locbuf
, "syscall %u", syscallnum
);
621 init_syscall_table - initialize syscall translation table
625 void init_syscall_table (void)
629 Dynamically initialize the translation table to convert system
630 call numbers into printable system call names. Done once per
631 gdb run, on initialization.
635 This is awfully ugly, but preprocessor tricks to make it prettier
636 tend to be nonportable.
640 init_syscall_table ()
642 #if defined (SYS_exit)
643 syscall_table
[SYS_exit
] = "exit";
645 #if defined (SYS_fork)
646 syscall_table
[SYS_fork
] = "fork";
648 #if defined (SYS_read)
649 syscall_table
[SYS_read
] = "read";
651 #if defined (SYS_write)
652 syscall_table
[SYS_write
] = "write";
654 #if defined (SYS_open)
655 syscall_table
[SYS_open
] = "open";
657 #if defined (SYS_close)
658 syscall_table
[SYS_close
] = "close";
660 #if defined (SYS_wait)
661 syscall_table
[SYS_wait
] = "wait";
663 #if defined (SYS_creat)
664 syscall_table
[SYS_creat
] = "creat";
666 #if defined (SYS_link)
667 syscall_table
[SYS_link
] = "link";
669 #if defined (SYS_unlink)
670 syscall_table
[SYS_unlink
] = "unlink";
672 #if defined (SYS_exec)
673 syscall_table
[SYS_exec
] = "exec";
675 #if defined (SYS_execv)
676 syscall_table
[SYS_execv
] = "execv";
678 #if defined (SYS_execve)
679 syscall_table
[SYS_execve
] = "execve";
681 #if defined (SYS_chdir)
682 syscall_table
[SYS_chdir
] = "chdir";
684 #if defined (SYS_time)
685 syscall_table
[SYS_time
] = "time";
687 #if defined (SYS_mknod)
688 syscall_table
[SYS_mknod
] = "mknod";
690 #if defined (SYS_chmod)
691 syscall_table
[SYS_chmod
] = "chmod";
693 #if defined (SYS_chown)
694 syscall_table
[SYS_chown
] = "chown";
696 #if defined (SYS_brk)
697 syscall_table
[SYS_brk
] = "brk";
699 #if defined (SYS_stat)
700 syscall_table
[SYS_stat
] = "stat";
702 #if defined (SYS_lseek)
703 syscall_table
[SYS_lseek
] = "lseek";
705 #if defined (SYS_getpid)
706 syscall_table
[SYS_getpid
] = "getpid";
708 #if defined (SYS_mount)
709 syscall_table
[SYS_mount
] = "mount";
711 #if defined (SYS_umount)
712 syscall_table
[SYS_umount
] = "umount";
714 #if defined (SYS_setuid)
715 syscall_table
[SYS_setuid
] = "setuid";
717 #if defined (SYS_getuid)
718 syscall_table
[SYS_getuid
] = "getuid";
720 #if defined (SYS_stime)
721 syscall_table
[SYS_stime
] = "stime";
723 #if defined (SYS_ptrace)
724 syscall_table
[SYS_ptrace
] = "ptrace";
726 #if defined (SYS_alarm)
727 syscall_table
[SYS_alarm
] = "alarm";
729 #if defined (SYS_fstat)
730 syscall_table
[SYS_fstat
] = "fstat";
732 #if defined (SYS_pause)
733 syscall_table
[SYS_pause
] = "pause";
735 #if defined (SYS_utime)
736 syscall_table
[SYS_utime
] = "utime";
738 #if defined (SYS_stty)
739 syscall_table
[SYS_stty
] = "stty";
741 #if defined (SYS_gtty)
742 syscall_table
[SYS_gtty
] = "gtty";
744 #if defined (SYS_access)
745 syscall_table
[SYS_access
] = "access";
747 #if defined (SYS_nice)
748 syscall_table
[SYS_nice
] = "nice";
750 #if defined (SYS_statfs)
751 syscall_table
[SYS_statfs
] = "statfs";
753 #if defined (SYS_sync)
754 syscall_table
[SYS_sync
] = "sync";
756 #if defined (SYS_kill)
757 syscall_table
[SYS_kill
] = "kill";
759 #if defined (SYS_fstatfs)
760 syscall_table
[SYS_fstatfs
] = "fstatfs";
762 #if defined (SYS_pgrpsys)
763 syscall_table
[SYS_pgrpsys
] = "pgrpsys";
765 #if defined (SYS_xenix)
766 syscall_table
[SYS_xenix
] = "xenix";
768 #if defined (SYS_dup)
769 syscall_table
[SYS_dup
] = "dup";
771 #if defined (SYS_pipe)
772 syscall_table
[SYS_pipe
] = "pipe";
774 #if defined (SYS_times)
775 syscall_table
[SYS_times
] = "times";
777 #if defined (SYS_profil)
778 syscall_table
[SYS_profil
] = "profil";
780 #if defined (SYS_plock)
781 syscall_table
[SYS_plock
] = "plock";
783 #if defined (SYS_setgid)
784 syscall_table
[SYS_setgid
] = "setgid";
786 #if defined (SYS_getgid)
787 syscall_table
[SYS_getgid
] = "getgid";
789 #if defined (SYS_signal)
790 syscall_table
[SYS_signal
] = "signal";
792 #if defined (SYS_msgsys)
793 syscall_table
[SYS_msgsys
] = "msgsys";
795 #if defined (SYS_sys3b)
796 syscall_table
[SYS_sys3b
] = "sys3b";
798 #if defined (SYS_acct)
799 syscall_table
[SYS_acct
] = "acct";
801 #if defined (SYS_shmsys)
802 syscall_table
[SYS_shmsys
] = "shmsys";
804 #if defined (SYS_semsys)
805 syscall_table
[SYS_semsys
] = "semsys";
807 #if defined (SYS_ioctl)
808 syscall_table
[SYS_ioctl
] = "ioctl";
810 #if defined (SYS_uadmin)
811 syscall_table
[SYS_uadmin
] = "uadmin";
813 #if defined (SYS_utssys)
814 syscall_table
[SYS_utssys
] = "utssys";
816 #if defined (SYS_fsync)
817 syscall_table
[SYS_fsync
] = "fsync";
819 #if defined (SYS_umask)
820 syscall_table
[SYS_umask
] = "umask";
822 #if defined (SYS_chroot)
823 syscall_table
[SYS_chroot
] = "chroot";
825 #if defined (SYS_fcntl)
826 syscall_table
[SYS_fcntl
] = "fcntl";
828 #if defined (SYS_ulimit)
829 syscall_table
[SYS_ulimit
] = "ulimit";
831 #if defined (SYS_rfsys)
832 syscall_table
[SYS_rfsys
] = "rfsys";
834 #if defined (SYS_rmdir)
835 syscall_table
[SYS_rmdir
] = "rmdir";
837 #if defined (SYS_mkdir)
838 syscall_table
[SYS_mkdir
] = "mkdir";
840 #if defined (SYS_getdents)
841 syscall_table
[SYS_getdents
] = "getdents";
843 #if defined (SYS_sysfs)
844 syscall_table
[SYS_sysfs
] = "sysfs";
846 #if defined (SYS_getmsg)
847 syscall_table
[SYS_getmsg
] = "getmsg";
849 #if defined (SYS_putmsg)
850 syscall_table
[SYS_putmsg
] = "putmsg";
852 #if defined (SYS_poll)
853 syscall_table
[SYS_poll
] = "poll";
855 #if defined (SYS_lstat)
856 syscall_table
[SYS_lstat
] = "lstat";
858 #if defined (SYS_symlink)
859 syscall_table
[SYS_symlink
] = "symlink";
861 #if defined (SYS_readlink)
862 syscall_table
[SYS_readlink
] = "readlink";
864 #if defined (SYS_setgroups)
865 syscall_table
[SYS_setgroups
] = "setgroups";
867 #if defined (SYS_getgroups)
868 syscall_table
[SYS_getgroups
] = "getgroups";
870 #if defined (SYS_fchmod)
871 syscall_table
[SYS_fchmod
] = "fchmod";
873 #if defined (SYS_fchown)
874 syscall_table
[SYS_fchown
] = "fchown";
876 #if defined (SYS_sigprocmask)
877 syscall_table
[SYS_sigprocmask
] = "sigprocmask";
879 #if defined (SYS_sigsuspend)
880 syscall_table
[SYS_sigsuspend
] = "sigsuspend";
882 #if defined (SYS_sigaltstack)
883 syscall_table
[SYS_sigaltstack
] = "sigaltstack";
885 #if defined (SYS_sigaction)
886 syscall_table
[SYS_sigaction
] = "sigaction";
888 #if defined (SYS_sigpending)
889 syscall_table
[SYS_sigpending
] = "sigpending";
891 #if defined (SYS_context)
892 syscall_table
[SYS_context
] = "context";
894 #if defined (SYS_evsys)
895 syscall_table
[SYS_evsys
] = "evsys";
897 #if defined (SYS_evtrapret)
898 syscall_table
[SYS_evtrapret
] = "evtrapret";
900 #if defined (SYS_statvfs)
901 syscall_table
[SYS_statvfs
] = "statvfs";
903 #if defined (SYS_fstatvfs)
904 syscall_table
[SYS_fstatvfs
] = "fstatvfs";
906 #if defined (SYS_nfssys)
907 syscall_table
[SYS_nfssys
] = "nfssys";
909 #if defined (SYS_waitsys)
910 syscall_table
[SYS_waitsys
] = "waitsys";
912 #if defined (SYS_sigsendsys)
913 syscall_table
[SYS_sigsendsys
] = "sigsendsys";
915 #if defined (SYS_hrtsys)
916 syscall_table
[SYS_hrtsys
] = "hrtsys";
918 #if defined (SYS_acancel)
919 syscall_table
[SYS_acancel
] = "acancel";
921 #if defined (SYS_async)
922 syscall_table
[SYS_async
] = "async";
924 #if defined (SYS_priocntlsys)
925 syscall_table
[SYS_priocntlsys
] = "priocntlsys";
927 #if defined (SYS_pathconf)
928 syscall_table
[SYS_pathconf
] = "pathconf";
930 #if defined (SYS_mincore)
931 syscall_table
[SYS_mincore
] = "mincore";
933 #if defined (SYS_mmap)
934 syscall_table
[SYS_mmap
] = "mmap";
936 #if defined (SYS_mprotect)
937 syscall_table
[SYS_mprotect
] = "mprotect";
939 #if defined (SYS_munmap)
940 syscall_table
[SYS_munmap
] = "munmap";
942 #if defined (SYS_fpathconf)
943 syscall_table
[SYS_fpathconf
] = "fpathconf";
945 #if defined (SYS_vfork)
946 syscall_table
[SYS_vfork
] = "vfork";
948 #if defined (SYS_fchdir)
949 syscall_table
[SYS_fchdir
] = "fchdir";
951 #if defined (SYS_readv)
952 syscall_table
[SYS_readv
] = "readv";
954 #if defined (SYS_writev)
955 syscall_table
[SYS_writev
] = "writev";
957 #if defined (SYS_xstat)
958 syscall_table
[SYS_xstat
] = "xstat";
960 #if defined (SYS_lxstat)
961 syscall_table
[SYS_lxstat
] = "lxstat";
963 #if defined (SYS_fxstat)
964 syscall_table
[SYS_fxstat
] = "fxstat";
966 #if defined (SYS_xmknod)
967 syscall_table
[SYS_xmknod
] = "xmknod";
969 #if defined (SYS_clocal)
970 syscall_table
[SYS_clocal
] = "clocal";
972 #if defined (SYS_setrlimit)
973 syscall_table
[SYS_setrlimit
] = "setrlimit";
975 #if defined (SYS_getrlimit)
976 syscall_table
[SYS_getrlimit
] = "getrlimit";
978 #if defined (SYS_lchown)
979 syscall_table
[SYS_lchown
] = "lchown";
981 #if defined (SYS_memcntl)
982 syscall_table
[SYS_memcntl
] = "memcntl";
984 #if defined (SYS_getpmsg)
985 syscall_table
[SYS_getpmsg
] = "getpmsg";
987 #if defined (SYS_putpmsg)
988 syscall_table
[SYS_putpmsg
] = "putpmsg";
990 #if defined (SYS_rename)
991 syscall_table
[SYS_rename
] = "rename";
993 #if defined (SYS_uname)
994 syscall_table
[SYS_uname
] = "uname";
996 #if defined (SYS_setegid)
997 syscall_table
[SYS_setegid
] = "setegid";
999 #if defined (SYS_sysconfig)
1000 syscall_table
[SYS_sysconfig
] = "sysconfig";
1002 #if defined (SYS_adjtime)
1003 syscall_table
[SYS_adjtime
] = "adjtime";
1005 #if defined (SYS_systeminfo)
1006 syscall_table
[SYS_systeminfo
] = "systeminfo";
1008 #if defined (SYS_seteuid)
1009 syscall_table
[SYS_seteuid
] = "seteuid";
1017 ptrace -- override library version to force errors for /proc version
1021 int ptrace (int request, int pid, PTRACE_ARG3_TYPE arg3, int arg4)
1025 When gdb is configured to use /proc, it should not be calling
1026 or otherwise attempting to use ptrace. In order to catch errors
1027 where use of /proc is configured, but some routine is still calling
1028 ptrace, we provide a local version of a function with that name
1029 that does nothing but issue an error message.
1033 ptrace (request
, pid
, arg3
, arg4
)
1036 PTRACE_ARG3_TYPE arg3
;
1039 error ("internal error - there is a call to ptrace() somewhere");
1047 procfs_kill_inferior - kill any currently inferior
1051 void procfs_kill_inferior (void)
1055 Kill any current inferior.
1059 Kills even attached inferiors. Presumably the user has already
1060 been prompted that the inferior is an attached one rather than
1061 one started by gdb. (FIXME?)
1066 procfs_kill_inferior ()
1068 if (inferior_pid
!= 0)
1070 unconditionally_kill_inferior ();
1071 target_mourn_inferior ();
1079 unconditionally_kill_inferior - terminate the inferior
1083 static void unconditionally_kill_inferior (void)
1087 Kill the current inferior. Should not be called until it
1088 is at least tested that there is an inferior.
1092 A possibly useful enhancement would be to first try sending
1093 the inferior a terminate signal, politely asking it to commit
1094 suicide, before we murder it.
1099 unconditionally_kill_inferior ()
1104 ioctl (pi
.fd
, PIOCKILL
, &signo
);
1105 close_proc_file (&pi
);
1113 procfs_xfer_memory -- copy data to or from inferior memory space
1117 int procfs_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len,
1118 int dowrite, struct target_ops target)
1122 Copy LEN bytes to/from inferior's memory starting at MEMADDR
1123 from/to debugger memory starting at MYADDR. Copy from inferior
1124 if DOWRITE is zero or to inferior if DOWRITE is nonzero.
1126 Returns the length copied, which is either the LEN argument or
1127 zero. This xfer function does not do partial moves, since procfs_ops
1128 doesn't allow memory operations to cross below us in the target stack
1133 The /proc interface makes this an almost trivial task.
1137 procfs_xfer_memory (memaddr
, myaddr
, len
, dowrite
, target
)
1142 struct target_ops
*target
; /* ignored */
1146 if (lseek (pi
.fd
, (off_t
) memaddr
, 0) == (off_t
) memaddr
)
1150 nbytes
= write (pi
.fd
, myaddr
, len
);
1154 nbytes
= read (pi
.fd
, myaddr
, len
);
1168 procfs_store_registers -- copy register values back to inferior
1172 void procfs_store_registers (int regno)
1176 Store our current register values back into the inferior. If
1177 REGNO is -1 then store all the register, otherwise store just
1178 the value specified by REGNO.
1182 If we are storing only a single register, we first have to get all
1183 the current values from the process, overwrite the desired register
1184 in the gregset with the one we want from gdb's registers, and then
1185 send the whole set back to the process. For writing all the
1186 registers, all we have to do is generate the gregset and send it to
1189 Also note that the process has to be stopped on an event of interest
1190 for this to work, which basically means that it has to have been
1191 run under the control of one of the other /proc ioctl calls and not
1192 ptrace. Since we don't use ptrace anyway, we don't worry about this
1193 fine point, but it is worth noting for future reference.
1195 Gdb is confused about what this function is supposed to return.
1196 Some versions return a value, others return nothing. Some are
1197 declared to return a value and actually return nothing. Gdb ignores
1198 anything returned. (FIXME)
1203 procfs_store_registers (regno
)
1208 ioctl (pi
.fd
, PIOCGREG
, &pi
.gregset
);
1210 fill_gregset (&pi
.gregset
, regno
);
1211 ioctl (pi
.fd
, PIOCSREG
, &pi
.gregset
);
1213 #if defined (FP0_REGNUM)
1215 /* Now repeat everything using the floating point register set, if the
1216 target has floating point hardware. Since we ignore the returned value,
1217 we'll never know whether it worked or not anyway. */
1221 ioctl (pi
.fd
, PIOCGFPREG
, &pi
.fpregset
);
1223 fill_fpregset (&pi
.fpregset
, regno
);
1224 ioctl (pi
.fd
, PIOCSFPREG
, &pi
.fpregset
);
1226 #endif /* FP0_REGNUM */
1234 procfs_init_inferior - initialize access to a /proc entry
1238 void procfs_init_inferior (int pid)
1242 When gdb starts an inferior, this function is called in the parent
1243 process immediately after the fork. It waits for the child to stop
1244 on the return from the exec system call (the child itself takes care
1245 of ensuring that this is set up), then sets up the set of signals
1246 and faults that are to be traced.
1250 If proc_init_failed ever gets called, control returns to the command
1251 processing loop via the standard error handling code.
1256 procfs_init_inferior (pid
)
1260 push_target (&procfs_ops
);
1262 if (!open_proc_file (pid
, &pi
, O_RDWR
))
1264 proc_init_failed ("can't open process file");
1268 memset ((char *) &pi
.prrun
, 0, sizeof (pi
.prrun
));
1269 prfillset (&pi
.prrun
.pr_trace
);
1270 proc_signal_handling_change ();
1271 prfillset (&pi
.prrun
.pr_fault
);
1272 prdelset (&pi
.prrun
.pr_fault
, FLTPAGE
);
1273 if (ioctl (pi
.fd
, PIOCWSTOP
, &pi
.prstatus
) < 0)
1275 proc_init_failed ("PIOCWSTOP failed");
1277 else if (ioctl (pi
.fd
, PIOCSFAULT
, &pi
.prrun
.pr_fault
) < 0)
1279 proc_init_failed ("PIOCSFAULT failed");
1288 proc_signal_handling_change
1292 void proc_signal_handling_change (void);
1296 When the user changes the state of gdb's signal handling via the
1297 "handle" command, this function gets called to see if any change
1298 in the /proc interface is required. It is also called internally
1299 by other /proc interface functions to initialize the state of
1300 the traced signal set.
1302 One thing it does is that signals for which the state is "nostop",
1303 "noprint", and "pass", have their trace bits reset in the pr_trace
1304 field, so that they are no longer traced. This allows them to be
1305 delivered directly to the inferior without the debugger ever being
1310 proc_signal_handling_change ()
1316 for (signo
= 0; signo
< NSIG
; signo
++)
1318 if (signal_stop_state (signo
) == 0 &&
1319 signal_print_state (signo
) == 0 &&
1320 signal_pass_state (signo
) == 1)
1322 prdelset (&pi
.prrun
.pr_trace
, signo
);
1326 praddset (&pi
.prrun
.pr_trace
, signo
);
1329 if (ioctl (pi
.fd
, PIOCSTRACE
, &pi
.prrun
.pr_trace
))
1331 print_sys_errmsg ("PIOCSTRACE failed", errno
);
1340 proc_set_exec_trap -- arrange for exec'd child to halt at startup
1344 void proc_set_exec_trap (void)
1348 This function is called in the child process when starting up
1349 an inferior, prior to doing the exec of the actual inferior.
1350 It sets the child process's exitset to make exit from the exec
1351 system call an event of interest to stop on, and then simply
1352 returns. The child does the exec, the system call returns, and
1353 the child stops at the first instruction, ready for the gdb
1354 parent process to take control of it.
1358 We need to use all local variables since the child may be sharing
1359 it's data space with the parent, if vfork was used rather than
1362 Also note that we want to turn off the inherit-on-fork flag in
1363 the child process so that any grand-children start with all
1364 tracing flags cleared.
1368 proc_set_exec_trap ()
1371 auto char procname
[32];
1374 sprintf (procname
, PROC_NAME_FMT
, getpid ());
1375 if ((fd
= open (procname
, O_RDWR
)) < 0)
1381 premptyset (&exitset
);
1384 Not all systems with /proc have all the exec* syscalls with the same
1385 names. On the SGI, for example, there is no SYS_exec, but there
1386 *is* a SYS_execv. So, we try to account for that. */
1389 praddset (&exitset
, SYS_exec
);
1392 praddset (&exitset
, SYS_execve
);
1395 praddset(&exitset
, SYS_execv
);
1398 if (ioctl (fd
, PIOCSEXIT
, &exitset
) < 0)
1405 /* Turn off inherit-on-fork flag so that all grand-children of gdb
1406 start with tracing flags cleared. */
1408 #if defined (PIOCRESET) /* New method */
1412 ioctl (fd
, PIOCRESET
, &pr_flags
);
1415 #if defined (PIOCRFORK) /* Original method */
1416 ioctl (fd
, PIOCRFORK
, NULL
);
1420 /* Turn on run-on-last-close flag so that this process will not hang
1421 if GDB goes away for some reason. */
1423 #if defined (PIOCSET) /* New method */
1427 (void) ioctl (fd
, PIOCSET
, &pr_flags
);
1430 #if defined (PIOCSRLC) /* Original method */
1431 (void) ioctl (fd
, PIOCSRLC
, 0);
1440 proc_iterate_over_mappings -- call function for every mapped space
1444 int proc_iterate_over_mappings (int (*func)())
1448 Given a pointer to a function, call that function for every
1449 mapped address space, passing it an open file descriptor for
1450 the file corresponding to that mapped address space (if any)
1451 and the base address of the mapped space. Quit when we hit
1452 the end of the mappings or the function returns nonzero.
1456 proc_iterate_over_mappings (func
)
1457 int (*func
) PARAMS ((int, CORE_ADDR
));
1462 struct prmap
*prmaps
;
1463 struct prmap
*prmap
;
1465 if (pi
.valid
&& (ioctl (pi
.fd
, PIOCNMAP
, &nmap
) == 0))
1467 prmaps
= (struct prmap
*) alloca ((nmap
+ 1) * sizeof (*prmaps
));
1468 if (ioctl (pi
.fd
, PIOCMAP
, prmaps
) == 0)
1470 for (prmap
= prmaps
; prmap
-> pr_size
&& funcstat
== 0; ++prmap
)
1472 fd
= proc_address_to_fd ((CORE_ADDR
) prmap
-> pr_vaddr
, 0);
1473 funcstat
= (*func
) (fd
, (CORE_ADDR
) prmap
-> pr_vaddr
);
1481 #if 0 /* Currently unused */
1486 proc_base_address -- find base address for segment containing address
1490 CORE_ADDR proc_base_address (CORE_ADDR addr)
1494 Given an address of a location in the inferior, find and return
1495 the base address of the mapped segment containing that address.
1497 This is used for example, by the shared library support code,
1498 where we have the pc value for some location in the shared library
1499 where we are stopped, and need to know the base address of the
1500 segment containing that address.
1504 proc_base_address (addr
)
1508 struct prmap
*prmaps
;
1509 struct prmap
*prmap
;
1510 CORE_ADDR baseaddr
= 0;
1512 if (pi
.valid
&& (ioctl (pi
.fd
, PIOCNMAP
, &nmap
) == 0))
1514 prmaps
= (struct prmap
*) alloca ((nmap
+ 1) * sizeof (*prmaps
));
1515 if (ioctl (pi
.fd
, PIOCMAP
, prmaps
) == 0)
1517 for (prmap
= prmaps
; prmap
-> pr_size
; ++prmap
)
1519 if ((prmap
-> pr_vaddr
<= (caddr_t
) addr
) &&
1520 (prmap
-> pr_vaddr
+ prmap
-> pr_size
> (caddr_t
) addr
))
1522 baseaddr
= (CORE_ADDR
) prmap
-> pr_vaddr
;
1537 proc_address_to_fd -- return open fd for file mapped to address
1541 int proc_address_to_fd (CORE_ADDR addr, complain)
1545 Given an address in the current inferior's address space, use the
1546 /proc interface to find an open file descriptor for the file that
1547 this address was mapped in from. Return -1 if there is no current
1548 inferior. Print a warning message if there is an inferior but
1549 the address corresponds to no file (IE a bogus address).
1554 proc_address_to_fd (addr
, complain
)
1562 if ((fd
= ioctl (pi
.fd
, PIOCOPENM
, (caddr_t
*) &addr
)) < 0)
1566 print_sys_errmsg (pi
.pathname
, errno
);
1567 warning ("can't find mapped file for address 0x%x", addr
);
1575 /* Attach to process PID, then initialize for debugging it
1576 and wait for the trace-trap that results from attaching. */
1579 procfs_attach (args
, from_tty
)
1587 error_no_arg ("process-id to attach");
1591 if (pid
== getpid()) /* Trying to masturbate? */
1592 error ("I refuse to debug myself!");
1596 exec_file
= (char *) get_exec_file (0);
1599 printf ("Attaching program `%s', pid %d\n", exec_file
, pid
);
1601 printf ("Attaching pid %d\n", pid
);
1608 push_target (&procfs_ops
);
1612 /* Take a program previously attached to and detaches it.
1613 The program resumes execution and will no longer stop
1614 on signals, etc. We'd better not have left any breakpoints
1615 in the program or it'll die when it hits one. For this
1616 to work, it may be necessary for the process to have been
1617 previously attached. It *might* work if the program was
1618 started via the normal ptrace (PTRACE_TRACEME). */
1621 procfs_detach (args
, from_tty
)
1629 char *exec_file
= get_exec_file (0);
1632 printf ("Detaching program: %s pid %d\n",
1633 exec_file
, inferior_pid
);
1637 siggnal
= atoi (args
);
1639 do_detach (siggnal
);
1641 unpush_target (&procfs_ops
); /* Pop out of handling an inferior */
1644 /* Get ready to modify the registers array. On machines which store
1645 individual registers, this doesn't need to do anything. On machines
1646 which store all the registers in one fell swoop, this makes sure
1647 that registers contains all the registers from the program being
1651 procfs_prepare_to_store ()
1653 #ifdef CHILD_PREPARE_TO_STORE
1654 CHILD_PREPARE_TO_STORE ();
1658 /* Print status information about what we're accessing. */
1661 procfs_files_info (ignore
)
1662 struct target_ops
*ignore
;
1664 printf ("\tUsing the running image of %s process %d via /proc.\n",
1665 attach_flag
? "attached": "child", inferior_pid
);
1670 procfs_open (arg
, from_tty
)
1674 error ("Use the \"run\" command to start a Unix child process.");
1681 do_attach -- attach to an already existing process
1685 int do_attach (int pid)
1689 Attach to an already existing process with the specified process
1690 id. If the process is not already stopped, query whether to
1695 The option of stopping at attach time is specific to the /proc
1696 versions of gdb. Versions using ptrace force the attachee
1697 to stop. (I have changed this version to do so, too. All you
1698 have to do is "continue" to make it go on. -- gnu@cygnus.com)
1708 if (!open_proc_file (pid
, &pi
, O_RDWR
))
1710 perror_with_name (pi
.pathname
);
1714 /* Get current status of process and if it is not already stopped,
1715 then stop it. Remember whether or not it was stopped when we first
1718 if (ioctl (pi
.fd
, PIOCSTATUS
, &pi
.prstatus
) < 0)
1720 print_sys_errmsg (pi
.pathname
, errno
);
1721 close_proc_file (&pi
);
1722 error ("PIOCSTATUS failed");
1724 if (pi
.prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
))
1731 if (1 || query ("Process is currently running, stop it? "))
1733 /* Make it run again when we close it. */
1734 #if defined (PIOCSET) /* New method */
1738 result
= ioctl (pi
.fd
, PIOCSET
, &pr_flags
);
1741 #if defined (PIOCSRLC) /* Original method */
1742 result
= ioctl (pi
.fd
, PIOCSRLC
, 0);
1747 print_sys_errmsg (pi
.pathname
, errno
);
1748 close_proc_file (&pi
);
1749 error ("PIOCSRLC or PIOCSET failed");
1751 if (ioctl (pi
.fd
, PIOCSTOP
, &pi
.prstatus
) < 0)
1753 print_sys_errmsg (pi
.pathname
, errno
);
1754 close_proc_file (&pi
);
1755 error ("PIOCSTOP failed");
1757 pi
.nopass_next_sigstop
= 1;
1761 printf ("Ok, gdb will wait for process %u to stop.\n", pid
);
1765 /* Remember some things about the inferior that we will, or might, change
1766 so that we can restore them when we detach. */
1768 ioctl (pi
.fd
, PIOCGTRACE
, &pi
.saved_trace
);
1769 ioctl (pi
.fd
, PIOCGHOLD
, &pi
.saved_sighold
);
1770 ioctl (pi
.fd
, PIOCGFAULT
, &pi
.saved_fltset
);
1771 ioctl (pi
.fd
, PIOCGENTRY
, &pi
.saved_entryset
);
1772 ioctl (pi
.fd
, PIOCGEXIT
, &pi
.saved_exitset
);
1774 /* Set up trace and fault sets, as gdb expects them. */
1776 memset (&pi
.prrun
, 0, sizeof (pi
.prrun
));
1777 prfillset (&pi
.prrun
.pr_trace
);
1778 proc_signal_handling_change ();
1779 prfillset (&pi
.prrun
.pr_fault
);
1780 prdelset (&pi
.prrun
.pr_fault
, FLTPAGE
);
1781 if (ioctl (pi
.fd
, PIOCSFAULT
, &pi
.prrun
.pr_fault
))
1783 print_sys_errmsg ("PIOCSFAULT failed", errno
);
1785 if (ioctl (pi
.fd
, PIOCSTRACE
, &pi
.prrun
.pr_trace
))
1787 print_sys_errmsg ("PIOCSTRACE failed", errno
);
1797 do_detach -- detach from an attached-to process
1801 void do_detach (int signal)
1805 Detach from the current attachee.
1807 If signal is non-zero, the attachee is started running again and sent
1808 the specified signal.
1810 If signal is zero and the attachee was not already stopped when we
1811 attached to it, then we make it runnable again when we detach.
1813 Otherwise, we query whether or not to make the attachee runnable
1814 again, since we may simply want to leave it in the state it was in
1817 We report any problems, but do not consider them errors, since we
1818 MUST detach even if some things don't seem to go right. This may not
1819 be the ideal situation. (FIXME).
1830 set_proc_siginfo (&pi
, signal
);
1832 if (ioctl (pi
.fd
, PIOCSEXIT
, &pi
.saved_exitset
) < 0)
1834 print_sys_errmsg (pi
.pathname
, errno
);
1835 printf ("PIOCSEXIT failed.\n");
1837 if (ioctl (pi
.fd
, PIOCSENTRY
, &pi
.saved_entryset
) < 0)
1839 print_sys_errmsg (pi
.pathname
, errno
);
1840 printf ("PIOCSENTRY failed.\n");
1842 if (ioctl (pi
.fd
, PIOCSTRACE
, &pi
.saved_trace
) < 0)
1844 print_sys_errmsg (pi
.pathname
, errno
);
1845 printf ("PIOCSTRACE failed.\n");
1847 if (ioctl (pi
.fd
, PIOCSHOLD
, &pi
.saved_sighold
) < 0)
1849 print_sys_errmsg (pi
.pathname
, errno
);
1850 printf ("PIOSCHOLD failed.\n");
1852 if (ioctl (pi
.fd
, PIOCSFAULT
, &pi
.saved_fltset
) < 0)
1854 print_sys_errmsg (pi
.pathname
, errno
);
1855 printf ("PIOCSFAULT failed.\n");
1857 if (ioctl (pi
.fd
, PIOCSTATUS
, &pi
.prstatus
) < 0)
1859 print_sys_errmsg (pi
.pathname
, errno
);
1860 printf ("PIOCSTATUS failed.\n");
1864 if (signal
|| (pi
.prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
)))
1866 if (signal
|| !pi
.was_stopped
||
1867 query ("Was stopped when attached, make it runnable again? "))
1869 /* Clear any fault that might have stopped it. */
1870 if (ioctl (pi
.fd
, PIOCCFAULT
, 0))
1872 print_sys_errmsg (pi
.pathname
, errno
);
1873 printf ("PIOCCFAULT failed.\n");
1876 /* Make it run again when we close it. */
1877 #if defined (PIOCSET) /* New method */
1881 result
= ioctl (pi
.fd
, PIOCSET
, &pr_flags
);
1884 #if defined (PIOCSRLC) /* Original method */
1885 result
= ioctl (pi
.fd
, PIOCSRLC
, 0);
1890 print_sys_errmsg (pi
.pathname
, errno
);
1891 printf ("PIOCSRLC or PIOCSET failed.\n");
1896 close_proc_file (&pi
);
1904 procfs_wait -- emulate wait() as much as possible
1905 Wait for child to do something. Return pid of child, or -1 in case
1906 of error; store status through argument pointer STATUS.
1911 int procfs_wait (int *statloc)
1915 Try to emulate wait() as much as possible. Not sure why we can't
1916 just use wait(), but it seems to have problems when applied to a
1917 process being controlled with the /proc interface.
1921 We have a race problem here with no obvious solution. We need to let
1922 the inferior run until it stops on an event of interest, which means
1923 that we need to use the PIOCWSTOP ioctl. However, we cannot use this
1924 ioctl if the process is already stopped on something that is not an
1925 event of interest, or the call will hang indefinitely. Thus we first
1926 use PIOCSTATUS to see if the process is not stopped. If not, then we
1927 use PIOCWSTOP. But during the window between the two, if the process
1928 stops for any reason that is not an event of interest (such as a job
1929 control signal) then gdb will hang. One possible workaround is to set
1930 an alarm to wake up every minute of so and check to see if the process
1931 is still running, and if so, then reissue the PIOCWSTOP. But this is
1932 a real kludge, so has not been implemented. FIXME: investigate
1935 FIXME: Investigate why wait() seems to have problems with programs
1936 being control by /proc routines.
1941 procfs_wait (statloc
)
1950 if (ioctl (pi
.fd
, PIOCSTATUS
, &pi
.prstatus
) < 0)
1954 else if (!(pi
.prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
)))
1956 if (ioctl (pi
.fd
, PIOCWSTOP
, &pi
.prstatus
) < 0)
1963 if (errno
== ENOENT
)
1965 rtnval
= wait (&statval
);
1966 if (rtnval
!= inferior_pid
)
1968 print_sys_errmsg (pi
.pathname
, errno
);
1969 error ("PIOCWSTOP, wait failed, returned %d", rtnval
);
1975 print_sys_errmsg (pi
.pathname
, errno
);
1976 error ("PIOCSTATUS or PIOCWSTOP failed.");
1980 else if (pi
.prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
))
1982 rtnval
= pi
.prstatus
.pr_pid
;
1983 why
= pi
.prstatus
.pr_why
;
1984 what
= pi
.prstatus
.pr_what
;
1985 if (why
== PR_SIGNALLED
)
1987 statval
= (what
<< 8) | 0177;
1989 else if ((why
== PR_SYSEXIT
)
1998 || what
== SYS_execve
2001 || what
== SYS_execv
2005 statval
= (SIGTRAP
<< 8) | 0177;
2007 else if (why
== PR_REQUESTED
)
2009 statval
= (SIGSTOP
<< 8) | 0177;
2011 else if (why
== PR_JOBCONTROL
)
2013 statval
= (what
<< 8) | 0177;
2015 else if (why
== PR_FAULTED
)
2021 statval
= (SIGILL
<< 8) | 0177;
2025 statval
= (SIGTRAP
<< 8) | 0177;
2030 statval
= (SIGSEGV
<< 8) | 0177;
2035 statval
= (SIGFPE
<< 8) | 0177;
2037 case FLTPAGE
: /* Recoverable page fault */
2040 error ("PIOCWSTOP, unknown why %d, what %d", why
, what
);
2047 error ("PIOCWSTOP, unknown why %d, what %d", why
, what
);
2053 error ("PIOCWSTOP, stopped for unknown/unhandled reason, flags %#x",
2054 pi
.prstatus
.pr_flags
);
2063 if (rtnval
== -1) /* No more children to wait for */
2065 fprintf (stderr
, "Child process unexpectedly missing.\n");
2066 *statloc
= 42; /* Claim it exited with signal 42 */
2077 set_proc_siginfo - set a process's current signal info
2081 void set_proc_siginfo (struct procinfo *pip, int signo);
2085 Given a pointer to a process info struct in PIP and a signal number
2086 in SIGNO, set the process's current signal and its associated signal
2087 information. The signal will be delivered to the process immediately
2088 after execution is resumed, even if it is being held. In addition,
2089 this particular delivery will not cause another PR_SIGNALLED stop
2090 even if the signal is being traced.
2092 If we are not delivering the same signal that the prstatus siginfo
2093 struct contains information about, then synthesize a siginfo struct
2094 to match the signal we are doing to deliver, make it of the type
2095 "generated by a user process", and send this synthesized copy. When
2096 used to set the inferior's signal state, this will be required if we
2097 are not currently stopped because of a traced signal, or if we decide
2098 to continue with a different signal.
2100 Note that when continuing the inferior from a stop due to receipt
2101 of a traced signal, we either have set PRCSIG to clear the existing
2102 signal, or we have to call this function to do a PIOCSSIG with either
2103 the existing siginfo struct from pr_info, or one we have synthesized
2104 appropriately for the signal we want to deliver. Otherwise if the
2105 signal is still being traced, the inferior will immediately stop
2108 See siginfo(5) for more details.
2112 set_proc_siginfo (pip
, signo
)
2113 struct procinfo
*pip
;
2116 struct siginfo newsiginfo
;
2117 struct siginfo
*sip
;
2121 if (signo
== pip
-> prstatus
.pr_info
.si_signo
)
2123 sip
= &pip
-> prstatus
.pr_info
;
2127 memset ((char *) &newsiginfo
, 0, sizeof (newsiginfo
));
2129 sip
-> si_signo
= signo
;
2131 sip
-> si_errno
= 0;
2132 sip
-> si_pid
= getpid ();
2133 sip
-> si_uid
= getuid ();
2135 if (ioctl (pip
-> fd
, PIOCSSIG
, sip
) < 0)
2137 print_sys_errmsg (pip
-> pathname
, errno
);
2138 warning ("PIOCSSIG failed");
2147 procfs_resume -- resume execution of the inferior process
2151 void procfs_resume (int step, int signo)
2155 Resume execution of the inferior process. If STEP is nozero, then
2156 just single step it. If SIGNAL is nonzero, restart it with that
2161 It may not be absolutely necessary to specify the PC value for
2162 restarting, but to be safe we use the value that gdb considers
2163 to be current. One case where this might be necessary is if the
2164 user explicitly changes the PC value that gdb considers to be
2165 current. FIXME: Investigate if this is necessary or not.
2167 When attaching to a child process, if we forced it to stop with
2168 a PIOCSTOP, then we will have set the nopass_next_sigstop flag.
2169 Upon resuming the first time after such a stop, we explicitly
2170 inhibit sending it another SIGSTOP, which would be the normal
2171 result of default signal handling. One potential drawback to
2172 this is that we will also ignore any attempt to by the user
2173 to explicitly continue after the attach with a SIGSTOP. Ultimately
2174 this problem should be dealt with by making the routines that
2175 deal with the inferior a little smarter, and possibly even allow
2176 an inferior to continue running at the same time as gdb. (FIXME?)
2180 procfs_resume (step
, signo
)
2185 pi
.prrun
.pr_flags
= PRSTRACE
| PRSFAULT
| PRCFAULT
;
2187 #ifdef PRSVADDR_BROKEN
2188 /* Can't do this under Solaris running on a Sparc, as there seems to be no
2189 place to put nPC. In fact, if you use this, nPC seems to be set to some
2190 random garbage. We have to rely on the fact that PC and nPC have been
2191 written previously via PIOCSREG during a register flush. */
2193 pi
.prrun
.pr_vaddr
= (caddr_t
) *(int *) ®isters
[REGISTER_BYTE (PC_REGNUM
)];
2194 pi
.prrun
.pr_flags
!= PRSVADDR
;
2197 if (signo
&& !(signo
== SIGSTOP
&& pi
.nopass_next_sigstop
))
2199 set_proc_siginfo (&pi
, signo
);
2203 pi
.prrun
.pr_flags
|= PRCSIG
;
2205 pi
.nopass_next_sigstop
= 0;
2208 pi
.prrun
.pr_flags
|= PRSTEP
;
2210 if (ioctl (pi
.fd
, PIOCRUN
, &pi
.prrun
) != 0)
2212 perror_with_name (pi
.pathname
);
2221 procfs_fetch_registers -- fetch current registers from inferior
2225 void procfs_fetch_registers (int regno)
2229 Read the current values of the inferior's registers, both the
2230 general register set and floating point registers (if supported)
2231 and update gdb's idea of their current values.
2236 procfs_fetch_registers (regno
)
2239 if (ioctl (pi
.fd
, PIOCGREG
, &pi
.gregset
) != -1)
2241 supply_gregset (&pi
.gregset
);
2243 #if defined (FP0_REGNUM)
2244 if (ioctl (pi
.fd
, PIOCGFPREG
, &pi
.fpregset
) != -1)
2246 supply_fpregset (&pi
.fpregset
);
2255 fetch_core_registers -- fetch current registers from core file data
2259 void fetch_core_registers (char *core_reg_sect, unsigned core_reg_size,
2260 int which, unsigned in reg_addr)
2264 Read the values of either the general register set (WHICH equals 0)
2265 or the floating point register set (WHICH equals 2) from the core
2266 file data (pointed to by CORE_REG_SECT), and update gdb's idea of
2267 their current values. The CORE_REG_SIZE parameter is ignored.
2271 Use the indicated sizes to validate the gregset and fpregset
2276 fetch_core_registers (core_reg_sect
, core_reg_size
, which
, reg_addr
)
2277 char *core_reg_sect
;
2278 unsigned core_reg_size
;
2280 unsigned int reg_addr
; /* Unused in this version */
2285 if (core_reg_size
!= sizeof (pi
.gregset
))
2287 warning ("wrong size gregset struct in core file");
2291 memcpy ((char *) &pi
.gregset
, core_reg_sect
, sizeof (pi
.gregset
));
2292 supply_gregset (&pi
.gregset
);
2295 else if (which
== 2)
2297 if (core_reg_size
!= sizeof (pi
.fpregset
))
2299 warning ("wrong size fpregset struct in core file");
2303 memcpy ((char *) &pi
.fpregset
, core_reg_sect
, sizeof (pi
.fpregset
));
2304 #if defined (FP0_REGNUM)
2305 supply_fpregset (&pi
.fpregset
);
2315 proc_init_failed - called whenever /proc access initialization fails
2319 static void proc_init_failed (char *why)
2323 This function is called whenever initialization of access to a /proc
2324 entry fails. It prints a suitable error message, does some cleanup,
2325 and then invokes the standard error processing routine which dumps
2326 us back into the command loop.
2330 proc_init_failed (why
)
2333 print_sys_errmsg (pi
.pathname
, errno
);
2334 kill (pi
.pid
, SIGKILL
);
2335 close_proc_file (&pi
);
2344 close_proc_file - close any currently open /proc entry
2348 static void close_proc_file (struct procinfo *pip)
2352 Close any currently open /proc entry and mark the process information
2353 entry as invalid. In order to ensure that we don't try to reuse any
2354 stale information, the pid, fd, and pathnames are explicitly
2355 invalidated, which may be overkill.
2360 close_proc_file (pip
)
2361 struct procinfo
*pip
;
2369 if (pip
-> pathname
)
2371 free (pip
-> pathname
);
2372 pip
-> pathname
= NULL
;
2381 open_proc_file - open a /proc entry for a given process id
2385 static int open_proc_file (int pid, struct procinfo *pip, int mode)
2389 Given a process id and a mode, close the existing open /proc
2390 entry (if any) and open one for the new process id, in the
2391 specified mode. Once it is open, then mark the local process
2392 information structure as valid, which guarantees that the pid,
2393 fd, and pathname fields match an open /proc entry. Returns
2394 zero if the open fails, nonzero otherwise.
2396 Note that the pathname is left intact, even when the open fails,
2397 so that callers can use it to construct meaningful error messages
2398 rather than just "file open failed".
2402 open_proc_file (pid
, pip
, mode
)
2404 struct procinfo
*pip
;
2407 pip
-> valid
= 0; /* FIXME, what is this? ?! */
2412 if (pip
-> pathname
== NULL
)
2414 pip
-> pathname
= xmalloc (32);
2416 sprintf (pip
-> pathname
, PROC_NAME_FMT
, pid
);
2417 if ((pip
-> fd
= open (pip
-> pathname
, mode
)) >= 0)
2422 return (pip
-> valid
);
2426 mappingflags (flags
)
2429 static char asciiflags
[8];
2431 strcpy (asciiflags
, "-------");
2432 #if defined (MA_PHYS)
2433 if (flags
& MA_PHYS
) asciiflags
[0] = 'd';
2435 if (flags
& MA_STACK
) asciiflags
[1] = 's';
2436 if (flags
& MA_BREAK
) asciiflags
[2] = 'b';
2437 if (flags
& MA_SHARED
) asciiflags
[3] = 's';
2438 if (flags
& MA_READ
) asciiflags
[4] = 'r';
2439 if (flags
& MA_WRITE
) asciiflags
[5] = 'w';
2440 if (flags
& MA_EXEC
) asciiflags
[6] = 'x';
2441 return (asciiflags
);
2445 info_proc_flags (pip
, summary
)
2446 struct procinfo
*pip
;
2449 struct trans
*transp
;
2451 printf_filtered ("%-32s", "Process status flags:");
2454 printf_filtered ("\n\n");
2456 for (transp
= pr_flag_table
; transp
-> name
!= NULL
; transp
++)
2458 if (pip
-> prstatus
.pr_flags
& transp
-> value
)
2462 printf_filtered ("%s ", transp
-> name
);
2466 printf_filtered ("\t%-16s %s.\n", transp
-> name
, transp
-> desc
);
2470 printf_filtered ("\n");
2474 info_proc_stop (pip
, summary
)
2475 struct procinfo
*pip
;
2478 struct trans
*transp
;
2482 why
= pip
-> prstatus
.pr_why
;
2483 what
= pip
-> prstatus
.pr_what
;
2485 if (pip
-> prstatus
.pr_flags
& PR_STOPPED
)
2487 printf_filtered ("%-32s", "Reason for stopping:");
2490 printf_filtered ("\n\n");
2492 for (transp
= pr_why_table
; transp
-> name
!= NULL
; transp
++)
2494 if (why
== transp
-> value
)
2498 printf_filtered ("%s ", transp
-> name
);
2502 printf_filtered ("\t%-16s %s.\n",
2503 transp
-> name
, transp
-> desc
);
2509 /* Use the pr_why field to determine what the pr_what field means, and
2510 print more information. */
2515 /* pr_what is unused for this case */
2521 printf_filtered ("%s ", signalname (what
));
2525 printf_filtered ("\t%-16s %s.\n", signalname (what
),
2526 safe_strsignal (what
));
2532 printf_filtered ("%s ", syscallname (what
));
2536 printf_filtered ("\t%-16s %s.\n", syscallname (what
),
2537 "Entered this system call");
2543 printf_filtered ("%s ", syscallname (what
));
2547 printf_filtered ("\t%-16s %s.\n", syscallname (what
),
2548 "Returned from this system call");
2554 printf_filtered ("%s ",
2555 lookupname (faults_table
, what
, "fault"));
2559 printf_filtered ("\t%-16s %s.\n",
2560 lookupname (faults_table
, what
, "fault"),
2561 lookupdesc (faults_table
, what
));
2565 printf_filtered ("\n");
2570 info_proc_siginfo (pip
, summary
)
2571 struct procinfo
*pip
;
2574 struct siginfo
*sip
;
2576 if ((pip
-> prstatus
.pr_flags
& PR_STOPPED
) &&
2577 (pip
-> prstatus
.pr_why
== PR_SIGNALLED
||
2578 pip
-> prstatus
.pr_why
== PR_FAULTED
))
2580 printf_filtered ("%-32s", "Additional signal/fault info:");
2581 sip
= &pip
-> prstatus
.pr_info
;
2584 printf_filtered ("%s ", signalname (sip
-> si_signo
));
2585 if (sip
-> si_errno
> 0)
2587 printf_filtered ("%s ", errnoname (sip
-> si_errno
));
2589 if (sip
-> si_code
<= 0)
2591 printf_filtered ("sent by pid %d, uid %d ", sip
-> si_pid
,
2596 printf_filtered ("%s ", sigcodename (sip
));
2597 if ((sip
-> si_signo
== SIGILL
) ||
2598 (sip
-> si_signo
== SIGFPE
) ||
2599 (sip
-> si_signo
== SIGSEGV
) ||
2600 (sip
-> si_signo
== SIGBUS
))
2602 printf_filtered ("addr=%#x ", sip
-> si_addr
);
2604 else if ((sip
-> si_signo
== SIGCHLD
))
2606 printf_filtered ("child pid %u, status %u ",
2610 else if ((sip
-> si_signo
== SIGPOLL
))
2612 printf_filtered ("band %u ", sip
-> si_band
);
2618 printf_filtered ("\n\n");
2619 printf_filtered ("\t%-16s %s.\n", signalname (sip
-> si_signo
),
2620 safe_strsignal (sip
-> si_signo
));
2621 if (sip
-> si_errno
> 0)
2623 printf_filtered ("\t%-16s %s.\n",
2624 errnoname (sip
-> si_errno
),
2625 safe_strerror (sip
-> si_errno
));
2627 if (sip
-> si_code
<= 0)
2629 printf_filtered ("\t%-16u %s\n", sip
-> si_pid
,
2630 "PID of process sending signal");
2631 printf_filtered ("\t%-16u %s\n", sip
-> si_uid
,
2632 "UID of process sending signal");
2636 printf_filtered ("\t%-16s %s.\n", sigcodename (sip
),
2638 if ((sip
-> si_signo
== SIGILL
) ||
2639 (sip
-> si_signo
== SIGFPE
))
2641 printf_filtered ("\t%-16#x %s.\n", sip
-> si_addr
,
2642 "Address of faulting instruction");
2644 else if ((sip
-> si_signo
== SIGSEGV
) ||
2645 (sip
-> si_signo
== SIGBUS
))
2647 printf_filtered ("\t%-16#x %s.\n", sip
-> si_addr
,
2648 "Address of faulting memory reference");
2650 else if ((sip
-> si_signo
== SIGCHLD
))
2652 printf_filtered ("\t%-16u %s.\n", sip
-> si_pid
,
2653 "Child process ID");
2654 printf_filtered ("\t%-16u %s.\n", sip
-> si_status
,
2655 "Child process exit value or signal");
2657 else if ((sip
-> si_signo
== SIGPOLL
))
2659 printf_filtered ("\t%-16u %s.\n", sip
-> si_band
,
2660 "Band event for POLL_{IN,OUT,MSG}");
2664 printf_filtered ("\n");
2669 info_proc_syscalls (pip
, summary
)
2670 struct procinfo
*pip
;
2678 #if 0 /* FIXME: Needs to use gdb-wide configured info about system calls. */
2679 if (pip
-> prstatus
.pr_flags
& PR_ASLEEP
)
2681 int syscallnum
= pip
-> prstatus
.pr_reg
[R_D0
];
2684 printf_filtered ("%-32s", "Sleeping in system call:");
2685 printf_filtered ("%s", syscallname (syscallnum
));
2689 printf_filtered ("Sleeping in system call '%s'.\n",
2690 syscallname (syscallnum
));
2695 if (ioctl (pip
-> fd
, PIOCGENTRY
, &pip
-> entryset
) < 0)
2697 print_sys_errmsg (pip
-> pathname
, errno
);
2698 error ("PIOCGENTRY failed");
2701 if (ioctl (pip
-> fd
, PIOCGEXIT
, &pip
-> exitset
) < 0)
2703 print_sys_errmsg (pip
-> pathname
, errno
);
2704 error ("PIOCGEXIT failed");
2707 printf_filtered ("System call tracing information:\n\n");
2709 printf_filtered ("\t%-12s %-8s %-8s\n",
2713 for (syscallnum
= 0; syscallnum
< MAX_SYSCALLS
; syscallnum
++)
2716 if (syscall_table
[syscallnum
] != NULL
)
2718 printf_filtered ("\t%-12s ", syscall_table
[syscallnum
]);
2719 printf_filtered ("%-8s ",
2720 prismember (&pip
-> entryset
, syscallnum
)
2722 printf_filtered ("%-8s ",
2723 prismember (&pip
-> exitset
, syscallnum
)
2725 printf_filtered ("\n");
2728 printf_filtered ("\n");
2737 static char locbuf
[32];
2739 name
= strsigno (signo
);
2742 sprintf (locbuf
, "Signal %d", signo
);
2746 sprintf (locbuf
, "%s (%d)", name
, signo
);
2756 static char locbuf
[32];
2758 name
= strerrno (errnum
);
2761 sprintf (locbuf
, "Errno %d", errnum
);
2765 sprintf (locbuf
, "%s (%d)", name
, errnum
);
2771 info_proc_signals (pip
, summary
)
2772 struct procinfo
*pip
;
2779 if (ioctl (pip
-> fd
, PIOCGTRACE
, &pip
-> trace
) < 0)
2781 print_sys_errmsg (pip
-> pathname
, errno
);
2782 error ("PIOCGTRACE failed");
2785 printf_filtered ("Disposition of signals:\n\n");
2786 printf_filtered ("\t%-15s %-8s %-8s %-8s %s\n\n",
2787 "Signal", "Trace", "Hold", "Pending", "Description");
2788 for (signo
= 0; signo
< NSIG
; signo
++)
2791 printf_filtered ("\t%-15s ", signalname (signo
));
2792 printf_filtered ("%-8s ",
2793 prismember (&pip
-> trace
, signo
)
2795 printf_filtered ("%-8s ",
2796 prismember (&pip
-> prstatus
.pr_sighold
, signo
)
2798 printf_filtered ("%-8s ",
2799 prismember (&pip
-> prstatus
.pr_sigpend
, signo
)
2801 printf_filtered (" %s\n", safe_strsignal (signo
));
2803 printf_filtered ("\n");
2808 info_proc_faults (pip
, summary
)
2809 struct procinfo
*pip
;
2812 struct trans
*transp
;
2816 if (ioctl (pip
-> fd
, PIOCGFAULT
, &pip
-> fltset
) < 0)
2818 print_sys_errmsg (pip
-> pathname
, errno
);
2819 error ("PIOCGFAULT failed");
2822 printf_filtered ("Current traced hardware fault set:\n\n");
2823 printf_filtered ("\t%-12s %-8s\n", "Fault", "Trace");
2825 for (transp
= faults_table
; transp
-> name
!= NULL
; transp
++)
2828 printf_filtered ("\t%-12s ", transp
-> name
);
2829 printf_filtered ("%-8s", prismember (&pip
-> fltset
, transp
-> value
)
2831 printf_filtered ("\n");
2833 printf_filtered ("\n");
2838 info_proc_mappings (pip
, summary
)
2839 struct procinfo
*pip
;
2843 struct prmap
*prmaps
;
2844 struct prmap
*prmap
;
2848 printf_filtered ("Mapped address spaces:\n\n");
2849 printf_filtered ("\t%10s %10s %10s %10s %7s\n",
2855 if (ioctl (pip
-> fd
, PIOCNMAP
, &nmap
) == 0)
2857 prmaps
= (struct prmap
*) alloca ((nmap
+ 1) * sizeof (*prmaps
));
2858 if (ioctl (pip
-> fd
, PIOCMAP
, prmaps
) == 0)
2860 for (prmap
= prmaps
; prmap
-> pr_size
; ++prmap
)
2862 printf_filtered ("\t%#10x %#10x %#10x %#10x %7s\n",
2864 prmap
-> pr_vaddr
+ prmap
-> pr_size
- 1,
2867 mappingflags (prmap
-> pr_mflags
));
2871 printf_filtered ("\n");
2879 info_proc -- implement the "info proc" command
2883 void info_proc (char *args, int from_tty)
2887 Implement gdb's "info proc" command by using the /proc interface
2888 to print status information about any currently running process.
2890 Examples of the use of "info proc" are:
2892 info proc (prints summary info for current inferior)
2893 info proc 123 (prints summary info for process with pid 123)
2894 info proc mappings (prints address mappings)
2895 info proc times (prints process/children times)
2896 info proc id (prints pid, ppid, gid, sid, etc)
2897 FIXME: i proc id not implemented.
2898 info proc status (prints general process state info)
2899 FIXME: i proc status not implemented.
2900 info proc signals (prints info about signal handling)
2901 info proc all (prints all info)
2906 info_proc (args
, from_tty
)
2911 struct procinfo pii
;
2912 struct procinfo
*pip
;
2913 struct cleanup
*old_chain
;
2927 old_chain
= make_cleanup (null_cleanup
, 0);
2929 /* Default to using the current inferior if no pid specified */
2935 if ((argv
= buildargv (args
)) == NULL
)
2939 make_cleanup (freeargv
, (char *) argv
);
2941 while (*argv
!= NULL
)
2943 argsize
= strlen (*argv
);
2944 if (argsize
>= 1 && strncmp (*argv
, "all", argsize
) == 0)
2949 else if (argsize
>= 2 && strncmp (*argv
, "faults", argsize
) == 0)
2954 else if (argsize
>= 2 && strncmp (*argv
, "flags", argsize
) == 0)
2959 else if (argsize
>= 1 && strncmp (*argv
, "id", argsize
) == 0)
2964 else if (argsize
>= 1 && strncmp (*argv
, "mappings", argsize
) == 0)
2969 else if (argsize
>= 2 && strncmp (*argv
, "signals", argsize
) == 0)
2974 else if (argsize
>= 2 && strncmp (*argv
, "status", argsize
) == 0)
2979 else if (argsize
>= 2 && strncmp (*argv
, "syscalls", argsize
) == 0)
2984 else if (argsize
>= 1 && strncmp (*argv
, "times", argsize
) == 0)
2989 else if ((pii
.pid
= atoi (*argv
)) > 0)
2993 memset (&pii
, 0, sizeof (pii
));
2994 if (!open_proc_file (pid
, pip
, O_RDONLY
))
2996 perror_with_name (pip
-> pathname
);
2999 make_cleanup (close_proc_file
, pip
);
3001 else if (**argv
!= '\000')
3003 error ("Unrecognized or ambiguous keyword `%s'.", *argv
);
3009 /* If we don't have a valid open process at this point, then we have no
3010 inferior or didn't specify a specific pid. */
3014 error ("No process. Run an inferior or specify an explicit pid.");
3016 if (ioctl (pip
-> fd
, PIOCSTATUS
, &(pip
-> prstatus
)) < 0)
3018 print_sys_errmsg (pip
-> pathname
, errno
);
3019 error ("PIOCSTATUS failed");
3022 /* Print verbose information of the requested type(s), or just a summary
3023 of the information for all types. */
3025 printf_filtered ("\nInformation for %s:\n\n", pip
-> pathname
);
3026 if (summary
|| all
|| flags
)
3028 info_proc_flags (pip
, summary
);
3032 info_proc_stop (pip
, summary
);
3034 if (summary
|| all
|| signals
|| faults
)
3036 info_proc_siginfo (pip
, summary
);
3038 if (summary
|| all
|| syscalls
)
3040 info_proc_syscalls (pip
, summary
);
3042 if (summary
|| all
|| mappings
)
3044 info_proc_mappings (pip
, summary
);
3046 if (summary
|| all
|| signals
)
3048 info_proc_signals (pip
, summary
);
3050 if (summary
|| all
|| faults
)
3052 info_proc_faults (pip
, summary
);
3054 printf_filtered ("\n");
3056 /* All done, deal with closing any temporary process info structure,
3057 freeing temporary memory , etc. */
3059 do_cleanups (old_chain
);
3062 /* Fork an inferior process, and start debugging it with /proc. */
3065 procfs_create_inferior (exec_file
, allargs
, env
)
3070 fork_inferior (exec_file
, allargs
, env
,
3071 proc_set_exec_trap
, procfs_init_inferior
);
3072 /* We are at the first instruction we care about. */
3073 /* Pedal to the metal... */
3074 proceed ((CORE_ADDR
) -1, 0, 0);
3077 /* Clean up after the inferior dies. */
3080 procfs_mourn_inferior ()
3082 unpush_target (&procfs_ops
);
3083 generic_mourn_inferior ();
3086 /* Mark our target-struct as eligible for stray "run" and "attach" commands. */
3093 struct target_ops procfs_ops
= {
3094 "procfs", /* to_shortname */
3095 "Unix /proc child process", /* to_longname */
3096 "Unix /proc child process (started by the \"run\" command).", /* to_doc */
3097 procfs_open
, /* to_open */
3099 procfs_attach
, /* to_attach */
3100 procfs_detach
, /* to_detach */
3101 procfs_resume
, /* to_resume */
3102 procfs_wait
, /* to_wait */
3103 procfs_fetch_registers
, /* to_fetch_registers */
3104 procfs_store_registers
, /* to_store_registers */
3105 procfs_prepare_to_store
, /* to_prepare_to_store */
3106 procfs_xfer_memory
, /* to_xfer_memory */
3107 procfs_files_info
, /* to_files_info */
3108 memory_insert_breakpoint
, /* to_insert_breakpoint */
3109 memory_remove_breakpoint
, /* to_remove_breakpoint */
3110 terminal_init_inferior
, /* to_terminal_init */
3111 terminal_inferior
, /* to_terminal_inferior */
3112 terminal_ours_for_output
, /* to_terminal_ours_for_output */
3113 terminal_ours
, /* to_terminal_ours */
3114 child_terminal_info
, /* to_terminal_info */
3115 procfs_kill_inferior
, /* to_kill */
3117 0, /* to_lookup_symbol */
3118 procfs_create_inferior
, /* to_create_inferior */
3119 procfs_mourn_inferior
, /* to_mourn_inferior */
3120 procfs_can_run
, /* to_can_run */
3121 process_stratum
, /* to_stratum */
3123 1, /* to_has_all_memory */
3124 1, /* to_has_memory */
3125 1, /* to_has_stack */
3126 1, /* to_has_registers */
3127 1, /* to_has_execution */
3129 0, /* sections_end */
3130 OPS_MAGIC
/* to_magic */
3137 _initialize_procfs -- initialize the process file system stuff
3141 void _initialize_procfs (void)
3145 Do required initializations during gdb startup for using the
3146 /proc file system interface.
3151 _initialize_procfs ()
3153 add_target (&procfs_ops
);
3155 add_info ("proc", info_proc
,
3156 "Show process status information using /proc entry.\n\
3157 Specify process id or use current inferior by default.\n\
3158 Specify keywords for detailed information; default is summary.\n\
3159 Keywords are: `all', `faults', `flags', `id', `mappings', `signals',\n\
3160 `status', `syscalls', and `times'.\n\
3161 Unambiguous abbreviations may be used.");
3163 init_syscall_table ();