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 **));
420 procfs_notice_signals
PARAMS ((void));
422 /* External function prototypes that can't be easily included in any
423 header file because the args are typedefs in system include files. */
426 supply_gregset
PARAMS ((gregset_t
*));
429 fill_gregset
PARAMS ((gregset_t
*, int));
432 supply_fpregset
PARAMS ((fpregset_t
*));
435 fill_fpregset
PARAMS ((fpregset_t
*, int));
441 lookupdesc -- translate a value to a summary desc string
445 static char *lookupdesc (struct trans *transp, unsigned int val);
449 Given a pointer to a translation table and a value to be translated,
450 lookup the desc string and return it.
454 lookupdesc (transp
, val
)
455 struct trans
*transp
;
460 for (desc
= NULL
; transp
-> name
!= NULL
; transp
++)
462 if (transp
-> value
== val
)
464 desc
= transp
-> desc
;
469 /* Didn't find a translation for the specified value, set a default one. */
482 lookupname -- translate a value to symbolic name
486 static char *lookupname (struct trans *transp, unsigned int val,
491 Given a pointer to a translation table, a value to be translated,
492 and a default prefix to return if the value can't be translated,
493 match the value with one of the translation table entries and
494 return a pointer to the symbolic name.
496 If no match is found it just returns the value as a printable string,
497 with the given prefix. The previous such value, if any, is freed
502 lookupname (transp
, val
, prefix
)
503 struct trans
*transp
;
510 for (name
= NULL
; transp
-> name
!= NULL
; transp
++)
512 if (transp
-> value
== val
)
514 name
= transp
-> name
;
519 /* Didn't find a translation for the specified value, build a default
520 one using the specified prefix and return it. The lifetime of
521 the value is only until the next one is needed. */
529 locbuf
= xmalloc (strlen (prefix
) + 16);
530 sprintf (locbuf
, "%s %u", prefix
, val
);
542 static char locbuf
[32];
544 for (scp
= siginfo_table
; scp
-> codename
!= NULL
; scp
++)
546 if ((scp
-> signo
== sip
-> si_signo
) &&
547 (scp
-> code
== sip
-> si_code
))
549 name
= scp
-> codename
;
555 sprintf (locbuf
, "sigcode %u", sip
-> si_signo
);
568 for (scp
= siginfo_table
; scp
-> codename
!= NULL
; scp
++)
570 if ((scp
-> signo
== sip
-> si_signo
) &&
571 (scp
-> code
== sip
-> si_code
))
579 desc
= "Unrecognized signal or trap use";
588 syscallname - translate a system call number into a system call name
592 char *syscallname (int syscallnum)
596 Given a system call number, translate it into the printable name
597 of a system call, or into "syscall <num>" if it is an unknown
602 syscallname (syscallnum
)
605 static char locbuf
[32];
608 if (syscallnum
>= 0 && syscallnum
< MAX_SYSCALLS
)
610 rtnval
= syscall_table
[syscallnum
];
614 sprintf (locbuf
, "syscall %u", syscallnum
);
624 init_syscall_table - initialize syscall translation table
628 void init_syscall_table (void)
632 Dynamically initialize the translation table to convert system
633 call numbers into printable system call names. Done once per
634 gdb run, on initialization.
638 This is awfully ugly, but preprocessor tricks to make it prettier
639 tend to be nonportable.
643 init_syscall_table ()
645 #if defined (SYS_exit)
646 syscall_table
[SYS_exit
] = "exit";
648 #if defined (SYS_fork)
649 syscall_table
[SYS_fork
] = "fork";
651 #if defined (SYS_read)
652 syscall_table
[SYS_read
] = "read";
654 #if defined (SYS_write)
655 syscall_table
[SYS_write
] = "write";
657 #if defined (SYS_open)
658 syscall_table
[SYS_open
] = "open";
660 #if defined (SYS_close)
661 syscall_table
[SYS_close
] = "close";
663 #if defined (SYS_wait)
664 syscall_table
[SYS_wait
] = "wait";
666 #if defined (SYS_creat)
667 syscall_table
[SYS_creat
] = "creat";
669 #if defined (SYS_link)
670 syscall_table
[SYS_link
] = "link";
672 #if defined (SYS_unlink)
673 syscall_table
[SYS_unlink
] = "unlink";
675 #if defined (SYS_exec)
676 syscall_table
[SYS_exec
] = "exec";
678 #if defined (SYS_execv)
679 syscall_table
[SYS_execv
] = "execv";
681 #if defined (SYS_execve)
682 syscall_table
[SYS_execve
] = "execve";
684 #if defined (SYS_chdir)
685 syscall_table
[SYS_chdir
] = "chdir";
687 #if defined (SYS_time)
688 syscall_table
[SYS_time
] = "time";
690 #if defined (SYS_mknod)
691 syscall_table
[SYS_mknod
] = "mknod";
693 #if defined (SYS_chmod)
694 syscall_table
[SYS_chmod
] = "chmod";
696 #if defined (SYS_chown)
697 syscall_table
[SYS_chown
] = "chown";
699 #if defined (SYS_brk)
700 syscall_table
[SYS_brk
] = "brk";
702 #if defined (SYS_stat)
703 syscall_table
[SYS_stat
] = "stat";
705 #if defined (SYS_lseek)
706 syscall_table
[SYS_lseek
] = "lseek";
708 #if defined (SYS_getpid)
709 syscall_table
[SYS_getpid
] = "getpid";
711 #if defined (SYS_mount)
712 syscall_table
[SYS_mount
] = "mount";
714 #if defined (SYS_umount)
715 syscall_table
[SYS_umount
] = "umount";
717 #if defined (SYS_setuid)
718 syscall_table
[SYS_setuid
] = "setuid";
720 #if defined (SYS_getuid)
721 syscall_table
[SYS_getuid
] = "getuid";
723 #if defined (SYS_stime)
724 syscall_table
[SYS_stime
] = "stime";
726 #if defined (SYS_ptrace)
727 syscall_table
[SYS_ptrace
] = "ptrace";
729 #if defined (SYS_alarm)
730 syscall_table
[SYS_alarm
] = "alarm";
732 #if defined (SYS_fstat)
733 syscall_table
[SYS_fstat
] = "fstat";
735 #if defined (SYS_pause)
736 syscall_table
[SYS_pause
] = "pause";
738 #if defined (SYS_utime)
739 syscall_table
[SYS_utime
] = "utime";
741 #if defined (SYS_stty)
742 syscall_table
[SYS_stty
] = "stty";
744 #if defined (SYS_gtty)
745 syscall_table
[SYS_gtty
] = "gtty";
747 #if defined (SYS_access)
748 syscall_table
[SYS_access
] = "access";
750 #if defined (SYS_nice)
751 syscall_table
[SYS_nice
] = "nice";
753 #if defined (SYS_statfs)
754 syscall_table
[SYS_statfs
] = "statfs";
756 #if defined (SYS_sync)
757 syscall_table
[SYS_sync
] = "sync";
759 #if defined (SYS_kill)
760 syscall_table
[SYS_kill
] = "kill";
762 #if defined (SYS_fstatfs)
763 syscall_table
[SYS_fstatfs
] = "fstatfs";
765 #if defined (SYS_pgrpsys)
766 syscall_table
[SYS_pgrpsys
] = "pgrpsys";
768 #if defined (SYS_xenix)
769 syscall_table
[SYS_xenix
] = "xenix";
771 #if defined (SYS_dup)
772 syscall_table
[SYS_dup
] = "dup";
774 #if defined (SYS_pipe)
775 syscall_table
[SYS_pipe
] = "pipe";
777 #if defined (SYS_times)
778 syscall_table
[SYS_times
] = "times";
780 #if defined (SYS_profil)
781 syscall_table
[SYS_profil
] = "profil";
783 #if defined (SYS_plock)
784 syscall_table
[SYS_plock
] = "plock";
786 #if defined (SYS_setgid)
787 syscall_table
[SYS_setgid
] = "setgid";
789 #if defined (SYS_getgid)
790 syscall_table
[SYS_getgid
] = "getgid";
792 #if defined (SYS_signal)
793 syscall_table
[SYS_signal
] = "signal";
795 #if defined (SYS_msgsys)
796 syscall_table
[SYS_msgsys
] = "msgsys";
798 #if defined (SYS_sys3b)
799 syscall_table
[SYS_sys3b
] = "sys3b";
801 #if defined (SYS_acct)
802 syscall_table
[SYS_acct
] = "acct";
804 #if defined (SYS_shmsys)
805 syscall_table
[SYS_shmsys
] = "shmsys";
807 #if defined (SYS_semsys)
808 syscall_table
[SYS_semsys
] = "semsys";
810 #if defined (SYS_ioctl)
811 syscall_table
[SYS_ioctl
] = "ioctl";
813 #if defined (SYS_uadmin)
814 syscall_table
[SYS_uadmin
] = "uadmin";
816 #if defined (SYS_utssys)
817 syscall_table
[SYS_utssys
] = "utssys";
819 #if defined (SYS_fsync)
820 syscall_table
[SYS_fsync
] = "fsync";
822 #if defined (SYS_umask)
823 syscall_table
[SYS_umask
] = "umask";
825 #if defined (SYS_chroot)
826 syscall_table
[SYS_chroot
] = "chroot";
828 #if defined (SYS_fcntl)
829 syscall_table
[SYS_fcntl
] = "fcntl";
831 #if defined (SYS_ulimit)
832 syscall_table
[SYS_ulimit
] = "ulimit";
834 #if defined (SYS_rfsys)
835 syscall_table
[SYS_rfsys
] = "rfsys";
837 #if defined (SYS_rmdir)
838 syscall_table
[SYS_rmdir
] = "rmdir";
840 #if defined (SYS_mkdir)
841 syscall_table
[SYS_mkdir
] = "mkdir";
843 #if defined (SYS_getdents)
844 syscall_table
[SYS_getdents
] = "getdents";
846 #if defined (SYS_sysfs)
847 syscall_table
[SYS_sysfs
] = "sysfs";
849 #if defined (SYS_getmsg)
850 syscall_table
[SYS_getmsg
] = "getmsg";
852 #if defined (SYS_putmsg)
853 syscall_table
[SYS_putmsg
] = "putmsg";
855 #if defined (SYS_poll)
856 syscall_table
[SYS_poll
] = "poll";
858 #if defined (SYS_lstat)
859 syscall_table
[SYS_lstat
] = "lstat";
861 #if defined (SYS_symlink)
862 syscall_table
[SYS_symlink
] = "symlink";
864 #if defined (SYS_readlink)
865 syscall_table
[SYS_readlink
] = "readlink";
867 #if defined (SYS_setgroups)
868 syscall_table
[SYS_setgroups
] = "setgroups";
870 #if defined (SYS_getgroups)
871 syscall_table
[SYS_getgroups
] = "getgroups";
873 #if defined (SYS_fchmod)
874 syscall_table
[SYS_fchmod
] = "fchmod";
876 #if defined (SYS_fchown)
877 syscall_table
[SYS_fchown
] = "fchown";
879 #if defined (SYS_sigprocmask)
880 syscall_table
[SYS_sigprocmask
] = "sigprocmask";
882 #if defined (SYS_sigsuspend)
883 syscall_table
[SYS_sigsuspend
] = "sigsuspend";
885 #if defined (SYS_sigaltstack)
886 syscall_table
[SYS_sigaltstack
] = "sigaltstack";
888 #if defined (SYS_sigaction)
889 syscall_table
[SYS_sigaction
] = "sigaction";
891 #if defined (SYS_sigpending)
892 syscall_table
[SYS_sigpending
] = "sigpending";
894 #if defined (SYS_context)
895 syscall_table
[SYS_context
] = "context";
897 #if defined (SYS_evsys)
898 syscall_table
[SYS_evsys
] = "evsys";
900 #if defined (SYS_evtrapret)
901 syscall_table
[SYS_evtrapret
] = "evtrapret";
903 #if defined (SYS_statvfs)
904 syscall_table
[SYS_statvfs
] = "statvfs";
906 #if defined (SYS_fstatvfs)
907 syscall_table
[SYS_fstatvfs
] = "fstatvfs";
909 #if defined (SYS_nfssys)
910 syscall_table
[SYS_nfssys
] = "nfssys";
912 #if defined (SYS_waitsys)
913 syscall_table
[SYS_waitsys
] = "waitsys";
915 #if defined (SYS_sigsendsys)
916 syscall_table
[SYS_sigsendsys
] = "sigsendsys";
918 #if defined (SYS_hrtsys)
919 syscall_table
[SYS_hrtsys
] = "hrtsys";
921 #if defined (SYS_acancel)
922 syscall_table
[SYS_acancel
] = "acancel";
924 #if defined (SYS_async)
925 syscall_table
[SYS_async
] = "async";
927 #if defined (SYS_priocntlsys)
928 syscall_table
[SYS_priocntlsys
] = "priocntlsys";
930 #if defined (SYS_pathconf)
931 syscall_table
[SYS_pathconf
] = "pathconf";
933 #if defined (SYS_mincore)
934 syscall_table
[SYS_mincore
] = "mincore";
936 #if defined (SYS_mmap)
937 syscall_table
[SYS_mmap
] = "mmap";
939 #if defined (SYS_mprotect)
940 syscall_table
[SYS_mprotect
] = "mprotect";
942 #if defined (SYS_munmap)
943 syscall_table
[SYS_munmap
] = "munmap";
945 #if defined (SYS_fpathconf)
946 syscall_table
[SYS_fpathconf
] = "fpathconf";
948 #if defined (SYS_vfork)
949 syscall_table
[SYS_vfork
] = "vfork";
951 #if defined (SYS_fchdir)
952 syscall_table
[SYS_fchdir
] = "fchdir";
954 #if defined (SYS_readv)
955 syscall_table
[SYS_readv
] = "readv";
957 #if defined (SYS_writev)
958 syscall_table
[SYS_writev
] = "writev";
960 #if defined (SYS_xstat)
961 syscall_table
[SYS_xstat
] = "xstat";
963 #if defined (SYS_lxstat)
964 syscall_table
[SYS_lxstat
] = "lxstat";
966 #if defined (SYS_fxstat)
967 syscall_table
[SYS_fxstat
] = "fxstat";
969 #if defined (SYS_xmknod)
970 syscall_table
[SYS_xmknod
] = "xmknod";
972 #if defined (SYS_clocal)
973 syscall_table
[SYS_clocal
] = "clocal";
975 #if defined (SYS_setrlimit)
976 syscall_table
[SYS_setrlimit
] = "setrlimit";
978 #if defined (SYS_getrlimit)
979 syscall_table
[SYS_getrlimit
] = "getrlimit";
981 #if defined (SYS_lchown)
982 syscall_table
[SYS_lchown
] = "lchown";
984 #if defined (SYS_memcntl)
985 syscall_table
[SYS_memcntl
] = "memcntl";
987 #if defined (SYS_getpmsg)
988 syscall_table
[SYS_getpmsg
] = "getpmsg";
990 #if defined (SYS_putpmsg)
991 syscall_table
[SYS_putpmsg
] = "putpmsg";
993 #if defined (SYS_rename)
994 syscall_table
[SYS_rename
] = "rename";
996 #if defined (SYS_uname)
997 syscall_table
[SYS_uname
] = "uname";
999 #if defined (SYS_setegid)
1000 syscall_table
[SYS_setegid
] = "setegid";
1002 #if defined (SYS_sysconfig)
1003 syscall_table
[SYS_sysconfig
] = "sysconfig";
1005 #if defined (SYS_adjtime)
1006 syscall_table
[SYS_adjtime
] = "adjtime";
1008 #if defined (SYS_systeminfo)
1009 syscall_table
[SYS_systeminfo
] = "systeminfo";
1011 #if defined (SYS_seteuid)
1012 syscall_table
[SYS_seteuid
] = "seteuid";
1020 ptrace -- override library version to force errors for /proc version
1024 int ptrace (int request, int pid, PTRACE_ARG3_TYPE arg3, int arg4)
1028 When gdb is configured to use /proc, it should not be calling
1029 or otherwise attempting to use ptrace. In order to catch errors
1030 where use of /proc is configured, but some routine is still calling
1031 ptrace, we provide a local version of a function with that name
1032 that does nothing but issue an error message.
1036 ptrace (request
, pid
, arg3
, arg4
)
1039 PTRACE_ARG3_TYPE arg3
;
1042 error ("internal error - there is a call to ptrace() somewhere");
1050 procfs_kill_inferior - kill any currently inferior
1054 void procfs_kill_inferior (void)
1058 Kill any current inferior.
1062 Kills even attached inferiors. Presumably the user has already
1063 been prompted that the inferior is an attached one rather than
1064 one started by gdb. (FIXME?)
1069 procfs_kill_inferior ()
1071 if (inferior_pid
!= 0)
1073 unconditionally_kill_inferior ();
1074 target_mourn_inferior ();
1082 unconditionally_kill_inferior - terminate the inferior
1086 static void unconditionally_kill_inferior (void)
1090 Kill the current inferior. Should not be called until it
1091 is at least tested that there is an inferior.
1095 A possibly useful enhancement would be to first try sending
1096 the inferior a terminate signal, politely asking it to commit
1097 suicide, before we murder it.
1102 unconditionally_kill_inferior ()
1107 ioctl (pi
.fd
, PIOCKILL
, &signo
);
1108 close_proc_file (&pi
);
1116 procfs_xfer_memory -- copy data to or from inferior memory space
1120 int procfs_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len,
1121 int dowrite, struct target_ops target)
1125 Copy LEN bytes to/from inferior's memory starting at MEMADDR
1126 from/to debugger memory starting at MYADDR. Copy from inferior
1127 if DOWRITE is zero or to inferior if DOWRITE is nonzero.
1129 Returns the length copied, which is either the LEN argument or
1130 zero. This xfer function does not do partial moves, since procfs_ops
1131 doesn't allow memory operations to cross below us in the target stack
1136 The /proc interface makes this an almost trivial task.
1140 procfs_xfer_memory (memaddr
, myaddr
, len
, dowrite
, target
)
1145 struct target_ops
*target
; /* ignored */
1149 if (lseek (pi
.fd
, (off_t
) memaddr
, 0) == (off_t
) memaddr
)
1153 nbytes
= write (pi
.fd
, myaddr
, len
);
1157 nbytes
= read (pi
.fd
, myaddr
, len
);
1171 procfs_store_registers -- copy register values back to inferior
1175 void procfs_store_registers (int regno)
1179 Store our current register values back into the inferior. If
1180 REGNO is -1 then store all the register, otherwise store just
1181 the value specified by REGNO.
1185 If we are storing only a single register, we first have to get all
1186 the current values from the process, overwrite the desired register
1187 in the gregset with the one we want from gdb's registers, and then
1188 send the whole set back to the process. For writing all the
1189 registers, all we have to do is generate the gregset and send it to
1192 Also note that the process has to be stopped on an event of interest
1193 for this to work, which basically means that it has to have been
1194 run under the control of one of the other /proc ioctl calls and not
1195 ptrace. Since we don't use ptrace anyway, we don't worry about this
1196 fine point, but it is worth noting for future reference.
1198 Gdb is confused about what this function is supposed to return.
1199 Some versions return a value, others return nothing. Some are
1200 declared to return a value and actually return nothing. Gdb ignores
1201 anything returned. (FIXME)
1206 procfs_store_registers (regno
)
1211 ioctl (pi
.fd
, PIOCGREG
, &pi
.gregset
);
1213 fill_gregset (&pi
.gregset
, regno
);
1214 ioctl (pi
.fd
, PIOCSREG
, &pi
.gregset
);
1216 #if defined (FP0_REGNUM)
1218 /* Now repeat everything using the floating point register set, if the
1219 target has floating point hardware. Since we ignore the returned value,
1220 we'll never know whether it worked or not anyway. */
1224 ioctl (pi
.fd
, PIOCGFPREG
, &pi
.fpregset
);
1226 fill_fpregset (&pi
.fpregset
, regno
);
1227 ioctl (pi
.fd
, PIOCSFPREG
, &pi
.fpregset
);
1229 #endif /* FP0_REGNUM */
1237 procfs_init_inferior - initialize access to a /proc entry
1241 void procfs_init_inferior (int pid)
1245 When gdb starts an inferior, this function is called in the parent
1246 process immediately after the fork. It waits for the child to stop
1247 on the return from the exec system call (the child itself takes care
1248 of ensuring that this is set up), then sets up the set of signals
1249 and faults that are to be traced.
1253 If proc_init_failed ever gets called, control returns to the command
1254 processing loop via the standard error handling code.
1259 procfs_init_inferior (pid
)
1263 push_target (&procfs_ops
);
1265 if (!open_proc_file (pid
, &pi
, O_RDWR
))
1267 proc_init_failed ("can't open process file");
1271 memset ((char *) &pi
.prrun
, 0, sizeof (pi
.prrun
));
1272 prfillset (&pi
.prrun
.pr_trace
);
1273 procfs_notice_signals ();
1274 prfillset (&pi
.prrun
.pr_fault
);
1275 prdelset (&pi
.prrun
.pr_fault
, FLTPAGE
);
1276 if (ioctl (pi
.fd
, PIOCWSTOP
, &pi
.prstatus
) < 0)
1278 proc_init_failed ("PIOCWSTOP failed");
1280 else if (ioctl (pi
.fd
, PIOCSFAULT
, &pi
.prrun
.pr_fault
) < 0)
1282 proc_init_failed ("PIOCSFAULT failed");
1291 procfs_notice_signals
1295 static void procfs_notice_signals (void);
1299 When the user changes the state of gdb's signal handling via the
1300 "handle" command, this function gets called to see if any change
1301 in the /proc interface is required. It is also called internally
1302 by other /proc interface functions to initialize the state of
1303 the traced signal set.
1305 One thing it does is that signals for which the state is "nostop",
1306 "noprint", and "pass", have their trace bits reset in the pr_trace
1307 field, so that they are no longer traced. This allows them to be
1308 delivered directly to the inferior without the debugger ever being
1313 procfs_notice_signals ()
1319 for (signo
= 0; signo
< NSIG
; signo
++)
1321 if (signal_stop_state (signo
) == 0 &&
1322 signal_print_state (signo
) == 0 &&
1323 signal_pass_state (signo
) == 1)
1325 prdelset (&pi
.prrun
.pr_trace
, signo
);
1329 praddset (&pi
.prrun
.pr_trace
, signo
);
1332 if (ioctl (pi
.fd
, PIOCSTRACE
, &pi
.prrun
.pr_trace
))
1334 print_sys_errmsg ("PIOCSTRACE failed", errno
);
1343 proc_set_exec_trap -- arrange for exec'd child to halt at startup
1347 void proc_set_exec_trap (void)
1351 This function is called in the child process when starting up
1352 an inferior, prior to doing the exec of the actual inferior.
1353 It sets the child process's exitset to make exit from the exec
1354 system call an event of interest to stop on, and then simply
1355 returns. The child does the exec, the system call returns, and
1356 the child stops at the first instruction, ready for the gdb
1357 parent process to take control of it.
1361 We need to use all local variables since the child may be sharing
1362 it's data space with the parent, if vfork was used rather than
1365 Also note that we want to turn off the inherit-on-fork flag in
1366 the child process so that any grand-children start with all
1367 tracing flags cleared.
1371 proc_set_exec_trap ()
1374 auto char procname
[32];
1377 sprintf (procname
, PROC_NAME_FMT
, getpid ());
1378 if ((fd
= open (procname
, O_RDWR
)) < 0)
1384 premptyset (&exitset
);
1387 Not all systems with /proc have all the exec* syscalls with the same
1388 names. On the SGI, for example, there is no SYS_exec, but there
1389 *is* a SYS_execv. So, we try to account for that. */
1392 praddset (&exitset
, SYS_exec
);
1395 praddset (&exitset
, SYS_execve
);
1398 praddset(&exitset
, SYS_execv
);
1401 if (ioctl (fd
, PIOCSEXIT
, &exitset
) < 0)
1408 /* Turn off inherit-on-fork flag so that all grand-children of gdb
1409 start with tracing flags cleared. */
1411 #if defined (PIOCRESET) /* New method */
1415 ioctl (fd
, PIOCRESET
, &pr_flags
);
1418 #if defined (PIOCRFORK) /* Original method */
1419 ioctl (fd
, PIOCRFORK
, NULL
);
1423 /* Turn on run-on-last-close flag so that this process will not hang
1424 if GDB goes away for some reason. */
1426 #if defined (PIOCSET) /* New method */
1430 (void) ioctl (fd
, PIOCSET
, &pr_flags
);
1433 #if defined (PIOCSRLC) /* Original method */
1434 (void) ioctl (fd
, PIOCSRLC
, 0);
1443 proc_iterate_over_mappings -- call function for every mapped space
1447 int proc_iterate_over_mappings (int (*func)())
1451 Given a pointer to a function, call that function for every
1452 mapped address space, passing it an open file descriptor for
1453 the file corresponding to that mapped address space (if any)
1454 and the base address of the mapped space. Quit when we hit
1455 the end of the mappings or the function returns nonzero.
1459 proc_iterate_over_mappings (func
)
1460 int (*func
) PARAMS ((int, CORE_ADDR
));
1465 struct prmap
*prmaps
;
1466 struct prmap
*prmap
;
1468 if (pi
.valid
&& (ioctl (pi
.fd
, PIOCNMAP
, &nmap
) == 0))
1470 prmaps
= (struct prmap
*) alloca ((nmap
+ 1) * sizeof (*prmaps
));
1471 if (ioctl (pi
.fd
, PIOCMAP
, prmaps
) == 0)
1473 for (prmap
= prmaps
; prmap
-> pr_size
&& funcstat
== 0; ++prmap
)
1475 fd
= proc_address_to_fd ((CORE_ADDR
) prmap
-> pr_vaddr
, 0);
1476 funcstat
= (*func
) (fd
, (CORE_ADDR
) prmap
-> pr_vaddr
);
1484 #if 0 /* Currently unused */
1489 proc_base_address -- find base address for segment containing address
1493 CORE_ADDR proc_base_address (CORE_ADDR addr)
1497 Given an address of a location in the inferior, find and return
1498 the base address of the mapped segment containing that address.
1500 This is used for example, by the shared library support code,
1501 where we have the pc value for some location in the shared library
1502 where we are stopped, and need to know the base address of the
1503 segment containing that address.
1507 proc_base_address (addr
)
1511 struct prmap
*prmaps
;
1512 struct prmap
*prmap
;
1513 CORE_ADDR baseaddr
= 0;
1515 if (pi
.valid
&& (ioctl (pi
.fd
, PIOCNMAP
, &nmap
) == 0))
1517 prmaps
= (struct prmap
*) alloca ((nmap
+ 1) * sizeof (*prmaps
));
1518 if (ioctl (pi
.fd
, PIOCMAP
, prmaps
) == 0)
1520 for (prmap
= prmaps
; prmap
-> pr_size
; ++prmap
)
1522 if ((prmap
-> pr_vaddr
<= (caddr_t
) addr
) &&
1523 (prmap
-> pr_vaddr
+ prmap
-> pr_size
> (caddr_t
) addr
))
1525 baseaddr
= (CORE_ADDR
) prmap
-> pr_vaddr
;
1540 proc_address_to_fd -- return open fd for file mapped to address
1544 int proc_address_to_fd (CORE_ADDR addr, complain)
1548 Given an address in the current inferior's address space, use the
1549 /proc interface to find an open file descriptor for the file that
1550 this address was mapped in from. Return -1 if there is no current
1551 inferior. Print a warning message if there is an inferior but
1552 the address corresponds to no file (IE a bogus address).
1557 proc_address_to_fd (addr
, complain
)
1565 if ((fd
= ioctl (pi
.fd
, PIOCOPENM
, (caddr_t
*) &addr
)) < 0)
1569 print_sys_errmsg (pi
.pathname
, errno
);
1570 warning ("can't find mapped file for address 0x%x", addr
);
1578 /* Attach to process PID, then initialize for debugging it
1579 and wait for the trace-trap that results from attaching. */
1582 procfs_attach (args
, from_tty
)
1590 error_no_arg ("process-id to attach");
1594 if (pid
== getpid()) /* Trying to masturbate? */
1595 error ("I refuse to debug myself!");
1599 exec_file
= (char *) get_exec_file (0);
1602 printf ("Attaching program `%s', pid %d\n", exec_file
, pid
);
1604 printf ("Attaching pid %d\n", pid
);
1611 push_target (&procfs_ops
);
1615 /* Take a program previously attached to and detaches it.
1616 The program resumes execution and will no longer stop
1617 on signals, etc. We'd better not have left any breakpoints
1618 in the program or it'll die when it hits one. For this
1619 to work, it may be necessary for the process to have been
1620 previously attached. It *might* work if the program was
1621 started via the normal ptrace (PTRACE_TRACEME). */
1624 procfs_detach (args
, from_tty
)
1632 char *exec_file
= get_exec_file (0);
1635 printf ("Detaching program: %s pid %d\n",
1636 exec_file
, inferior_pid
);
1640 siggnal
= atoi (args
);
1642 do_detach (siggnal
);
1644 unpush_target (&procfs_ops
); /* Pop out of handling an inferior */
1647 /* Get ready to modify the registers array. On machines which store
1648 individual registers, this doesn't need to do anything. On machines
1649 which store all the registers in one fell swoop, this makes sure
1650 that registers contains all the registers from the program being
1654 procfs_prepare_to_store ()
1656 #ifdef CHILD_PREPARE_TO_STORE
1657 CHILD_PREPARE_TO_STORE ();
1661 /* Print status information about what we're accessing. */
1664 procfs_files_info (ignore
)
1665 struct target_ops
*ignore
;
1667 printf ("\tUsing the running image of %s process %d via /proc.\n",
1668 attach_flag
? "attached": "child", inferior_pid
);
1673 procfs_open (arg
, from_tty
)
1677 error ("Use the \"run\" command to start a Unix child process.");
1684 do_attach -- attach to an already existing process
1688 int do_attach (int pid)
1692 Attach to an already existing process with the specified process
1693 id. If the process is not already stopped, query whether to
1698 The option of stopping at attach time is specific to the /proc
1699 versions of gdb. Versions using ptrace force the attachee
1700 to stop. (I have changed this version to do so, too. All you
1701 have to do is "continue" to make it go on. -- gnu@cygnus.com)
1711 if (!open_proc_file (pid
, &pi
, O_RDWR
))
1713 perror_with_name (pi
.pathname
);
1717 /* Get current status of process and if it is not already stopped,
1718 then stop it. Remember whether or not it was stopped when we first
1721 if (ioctl (pi
.fd
, PIOCSTATUS
, &pi
.prstatus
) < 0)
1723 print_sys_errmsg (pi
.pathname
, errno
);
1724 close_proc_file (&pi
);
1725 error ("PIOCSTATUS failed");
1727 if (pi
.prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
))
1734 if (1 || query ("Process is currently running, stop it? "))
1736 /* Make it run again when we close it. */
1737 #if defined (PIOCSET) /* New method */
1741 result
= ioctl (pi
.fd
, PIOCSET
, &pr_flags
);
1744 #if defined (PIOCSRLC) /* Original method */
1745 result
= ioctl (pi
.fd
, PIOCSRLC
, 0);
1750 print_sys_errmsg (pi
.pathname
, errno
);
1751 close_proc_file (&pi
);
1752 error ("PIOCSRLC or PIOCSET failed");
1754 if (ioctl (pi
.fd
, PIOCSTOP
, &pi
.prstatus
) < 0)
1756 print_sys_errmsg (pi
.pathname
, errno
);
1757 close_proc_file (&pi
);
1758 error ("PIOCSTOP failed");
1760 pi
.nopass_next_sigstop
= 1;
1764 printf ("Ok, gdb will wait for process %u to stop.\n", pid
);
1768 /* Remember some things about the inferior that we will, or might, change
1769 so that we can restore them when we detach. */
1771 ioctl (pi
.fd
, PIOCGTRACE
, &pi
.saved_trace
);
1772 ioctl (pi
.fd
, PIOCGHOLD
, &pi
.saved_sighold
);
1773 ioctl (pi
.fd
, PIOCGFAULT
, &pi
.saved_fltset
);
1774 ioctl (pi
.fd
, PIOCGENTRY
, &pi
.saved_entryset
);
1775 ioctl (pi
.fd
, PIOCGEXIT
, &pi
.saved_exitset
);
1777 /* Set up trace and fault sets, as gdb expects them. */
1779 memset (&pi
.prrun
, 0, sizeof (pi
.prrun
));
1780 prfillset (&pi
.prrun
.pr_trace
);
1781 procfs_notice_signals ();
1782 prfillset (&pi
.prrun
.pr_fault
);
1783 prdelset (&pi
.prrun
.pr_fault
, FLTPAGE
);
1784 if (ioctl (pi
.fd
, PIOCSFAULT
, &pi
.prrun
.pr_fault
))
1786 print_sys_errmsg ("PIOCSFAULT failed", errno
);
1788 if (ioctl (pi
.fd
, PIOCSTRACE
, &pi
.prrun
.pr_trace
))
1790 print_sys_errmsg ("PIOCSTRACE failed", errno
);
1800 do_detach -- detach from an attached-to process
1804 void do_detach (int signal)
1808 Detach from the current attachee.
1810 If signal is non-zero, the attachee is started running again and sent
1811 the specified signal.
1813 If signal is zero and the attachee was not already stopped when we
1814 attached to it, then we make it runnable again when we detach.
1816 Otherwise, we query whether or not to make the attachee runnable
1817 again, since we may simply want to leave it in the state it was in
1820 We report any problems, but do not consider them errors, since we
1821 MUST detach even if some things don't seem to go right. This may not
1822 be the ideal situation. (FIXME).
1833 set_proc_siginfo (&pi
, signal
);
1835 if (ioctl (pi
.fd
, PIOCSEXIT
, &pi
.saved_exitset
) < 0)
1837 print_sys_errmsg (pi
.pathname
, errno
);
1838 printf ("PIOCSEXIT failed.\n");
1840 if (ioctl (pi
.fd
, PIOCSENTRY
, &pi
.saved_entryset
) < 0)
1842 print_sys_errmsg (pi
.pathname
, errno
);
1843 printf ("PIOCSENTRY failed.\n");
1845 if (ioctl (pi
.fd
, PIOCSTRACE
, &pi
.saved_trace
) < 0)
1847 print_sys_errmsg (pi
.pathname
, errno
);
1848 printf ("PIOCSTRACE failed.\n");
1850 if (ioctl (pi
.fd
, PIOCSHOLD
, &pi
.saved_sighold
) < 0)
1852 print_sys_errmsg (pi
.pathname
, errno
);
1853 printf ("PIOSCHOLD failed.\n");
1855 if (ioctl (pi
.fd
, PIOCSFAULT
, &pi
.saved_fltset
) < 0)
1857 print_sys_errmsg (pi
.pathname
, errno
);
1858 printf ("PIOCSFAULT failed.\n");
1860 if (ioctl (pi
.fd
, PIOCSTATUS
, &pi
.prstatus
) < 0)
1862 print_sys_errmsg (pi
.pathname
, errno
);
1863 printf ("PIOCSTATUS failed.\n");
1867 if (signal
|| (pi
.prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
)))
1869 if (signal
|| !pi
.was_stopped
||
1870 query ("Was stopped when attached, make it runnable again? "))
1872 /* Clear any fault that might have stopped it. */
1873 if (ioctl (pi
.fd
, PIOCCFAULT
, 0))
1875 print_sys_errmsg (pi
.pathname
, errno
);
1876 printf ("PIOCCFAULT failed.\n");
1879 /* Make it run again when we close it. */
1880 #if defined (PIOCSET) /* New method */
1884 result
= ioctl (pi
.fd
, PIOCSET
, &pr_flags
);
1887 #if defined (PIOCSRLC) /* Original method */
1888 result
= ioctl (pi
.fd
, PIOCSRLC
, 0);
1893 print_sys_errmsg (pi
.pathname
, errno
);
1894 printf ("PIOCSRLC or PIOCSET failed.\n");
1899 close_proc_file (&pi
);
1907 procfs_wait -- emulate wait() as much as possible
1908 Wait for child to do something. Return pid of child, or -1 in case
1909 of error; store status through argument pointer STATUS.
1914 int procfs_wait (int *statloc)
1918 Try to emulate wait() as much as possible. Not sure why we can't
1919 just use wait(), but it seems to have problems when applied to a
1920 process being controlled with the /proc interface.
1924 We have a race problem here with no obvious solution. We need to let
1925 the inferior run until it stops on an event of interest, which means
1926 that we need to use the PIOCWSTOP ioctl. However, we cannot use this
1927 ioctl if the process is already stopped on something that is not an
1928 event of interest, or the call will hang indefinitely. Thus we first
1929 use PIOCSTATUS to see if the process is not stopped. If not, then we
1930 use PIOCWSTOP. But during the window between the two, if the process
1931 stops for any reason that is not an event of interest (such as a job
1932 control signal) then gdb will hang. One possible workaround is to set
1933 an alarm to wake up every minute of so and check to see if the process
1934 is still running, and if so, then reissue the PIOCWSTOP. But this is
1935 a real kludge, so has not been implemented. FIXME: investigate
1938 FIXME: Investigate why wait() seems to have problems with programs
1939 being control by /proc routines.
1944 procfs_wait (statloc
)
1953 if (ioctl (pi
.fd
, PIOCSTATUS
, &pi
.prstatus
) < 0)
1957 else if (!(pi
.prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
)))
1959 if (ioctl (pi
.fd
, PIOCWSTOP
, &pi
.prstatus
) < 0)
1966 if (errno
== ENOENT
)
1968 rtnval
= wait (&statval
);
1969 if (rtnval
!= inferior_pid
)
1971 print_sys_errmsg (pi
.pathname
, errno
);
1972 error ("PIOCWSTOP, wait failed, returned %d", rtnval
);
1978 print_sys_errmsg (pi
.pathname
, errno
);
1979 error ("PIOCSTATUS or PIOCWSTOP failed.");
1983 else if (pi
.prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
))
1985 rtnval
= pi
.prstatus
.pr_pid
;
1986 why
= pi
.prstatus
.pr_why
;
1987 what
= pi
.prstatus
.pr_what
;
1988 if (why
== PR_SIGNALLED
)
1990 statval
= (what
<< 8) | 0177;
1992 else if ((why
== PR_SYSEXIT
)
2001 || what
== SYS_execve
2004 || what
== SYS_execv
2008 statval
= (SIGTRAP
<< 8) | 0177;
2010 else if (why
== PR_REQUESTED
)
2012 statval
= (SIGSTOP
<< 8) | 0177;
2014 else if (why
== PR_JOBCONTROL
)
2016 statval
= (what
<< 8) | 0177;
2018 else if (why
== PR_FAULTED
)
2024 statval
= (SIGILL
<< 8) | 0177;
2028 statval
= (SIGTRAP
<< 8) | 0177;
2033 statval
= (SIGSEGV
<< 8) | 0177;
2038 statval
= (SIGFPE
<< 8) | 0177;
2040 case FLTPAGE
: /* Recoverable page fault */
2043 error ("PIOCWSTOP, unknown why %d, what %d", why
, what
);
2050 error ("PIOCWSTOP, unknown why %d, what %d", why
, what
);
2056 error ("PIOCWSTOP, stopped for unknown/unhandled reason, flags %#x",
2057 pi
.prstatus
.pr_flags
);
2066 if (rtnval
== -1) /* No more children to wait for */
2068 fprintf (stderr
, "Child process unexpectedly missing.\n");
2069 *statloc
= 42; /* Claim it exited with signal 42 */
2080 set_proc_siginfo - set a process's current signal info
2084 void set_proc_siginfo (struct procinfo *pip, int signo);
2088 Given a pointer to a process info struct in PIP and a signal number
2089 in SIGNO, set the process's current signal and its associated signal
2090 information. The signal will be delivered to the process immediately
2091 after execution is resumed, even if it is being held. In addition,
2092 this particular delivery will not cause another PR_SIGNALLED stop
2093 even if the signal is being traced.
2095 If we are not delivering the same signal that the prstatus siginfo
2096 struct contains information about, then synthesize a siginfo struct
2097 to match the signal we are doing to deliver, make it of the type
2098 "generated by a user process", and send this synthesized copy. When
2099 used to set the inferior's signal state, this will be required if we
2100 are not currently stopped because of a traced signal, or if we decide
2101 to continue with a different signal.
2103 Note that when continuing the inferior from a stop due to receipt
2104 of a traced signal, we either have set PRCSIG to clear the existing
2105 signal, or we have to call this function to do a PIOCSSIG with either
2106 the existing siginfo struct from pr_info, or one we have synthesized
2107 appropriately for the signal we want to deliver. Otherwise if the
2108 signal is still being traced, the inferior will immediately stop
2111 See siginfo(5) for more details.
2115 set_proc_siginfo (pip
, signo
)
2116 struct procinfo
*pip
;
2119 struct siginfo newsiginfo
;
2120 struct siginfo
*sip
;
2124 if (signo
== pip
-> prstatus
.pr_info
.si_signo
)
2126 sip
= &pip
-> prstatus
.pr_info
;
2130 memset ((char *) &newsiginfo
, 0, sizeof (newsiginfo
));
2132 sip
-> si_signo
= signo
;
2134 sip
-> si_errno
= 0;
2135 sip
-> si_pid
= getpid ();
2136 sip
-> si_uid
= getuid ();
2138 if (ioctl (pip
-> fd
, PIOCSSIG
, sip
) < 0)
2140 print_sys_errmsg (pip
-> pathname
, errno
);
2141 warning ("PIOCSSIG failed");
2150 procfs_resume -- resume execution of the inferior process
2154 void procfs_resume (int step, int signo)
2158 Resume execution of the inferior process. If STEP is nozero, then
2159 just single step it. If SIGNAL is nonzero, restart it with that
2164 It may not be absolutely necessary to specify the PC value for
2165 restarting, but to be safe we use the value that gdb considers
2166 to be current. One case where this might be necessary is if the
2167 user explicitly changes the PC value that gdb considers to be
2168 current. FIXME: Investigate if this is necessary or not.
2170 When attaching to a child process, if we forced it to stop with
2171 a PIOCSTOP, then we will have set the nopass_next_sigstop flag.
2172 Upon resuming the first time after such a stop, we explicitly
2173 inhibit sending it another SIGSTOP, which would be the normal
2174 result of default signal handling. One potential drawback to
2175 this is that we will also ignore any attempt to by the user
2176 to explicitly continue after the attach with a SIGSTOP. Ultimately
2177 this problem should be dealt with by making the routines that
2178 deal with the inferior a little smarter, and possibly even allow
2179 an inferior to continue running at the same time as gdb. (FIXME?)
2183 procfs_resume (step
, signo
)
2188 pi
.prrun
.pr_flags
= PRSTRACE
| PRSFAULT
| PRCFAULT
;
2190 #ifdef PRSVADDR_BROKEN
2191 /* Can't do this under Solaris running on a Sparc, as there seems to be no
2192 place to put nPC. In fact, if you use this, nPC seems to be set to some
2193 random garbage. We have to rely on the fact that PC and nPC have been
2194 written previously via PIOCSREG during a register flush. */
2196 pi
.prrun
.pr_vaddr
= (caddr_t
) *(int *) ®isters
[REGISTER_BYTE (PC_REGNUM
)];
2197 pi
.prrun
.pr_flags
!= PRSVADDR
;
2200 if (signo
&& !(signo
== SIGSTOP
&& pi
.nopass_next_sigstop
))
2202 set_proc_siginfo (&pi
, signo
);
2206 pi
.prrun
.pr_flags
|= PRCSIG
;
2208 pi
.nopass_next_sigstop
= 0;
2211 pi
.prrun
.pr_flags
|= PRSTEP
;
2213 if (ioctl (pi
.fd
, PIOCRUN
, &pi
.prrun
) != 0)
2215 perror_with_name (pi
.pathname
);
2224 procfs_fetch_registers -- fetch current registers from inferior
2228 void procfs_fetch_registers (int regno)
2232 Read the current values of the inferior's registers, both the
2233 general register set and floating point registers (if supported)
2234 and update gdb's idea of their current values.
2239 procfs_fetch_registers (regno
)
2242 if (ioctl (pi
.fd
, PIOCGREG
, &pi
.gregset
) != -1)
2244 supply_gregset (&pi
.gregset
);
2246 #if defined (FP0_REGNUM)
2247 if (ioctl (pi
.fd
, PIOCGFPREG
, &pi
.fpregset
) != -1)
2249 supply_fpregset (&pi
.fpregset
);
2258 fetch_core_registers -- fetch current registers from core file data
2262 void fetch_core_registers (char *core_reg_sect, unsigned core_reg_size,
2263 int which, unsigned in reg_addr)
2267 Read the values of either the general register set (WHICH equals 0)
2268 or the floating point register set (WHICH equals 2) from the core
2269 file data (pointed to by CORE_REG_SECT), and update gdb's idea of
2270 their current values. The CORE_REG_SIZE parameter is ignored.
2274 Use the indicated sizes to validate the gregset and fpregset
2279 fetch_core_registers (core_reg_sect
, core_reg_size
, which
, reg_addr
)
2280 char *core_reg_sect
;
2281 unsigned core_reg_size
;
2283 unsigned int reg_addr
; /* Unused in this version */
2288 if (core_reg_size
!= sizeof (pi
.gregset
))
2290 warning ("wrong size gregset struct in core file");
2294 memcpy ((char *) &pi
.gregset
, core_reg_sect
, sizeof (pi
.gregset
));
2295 supply_gregset (&pi
.gregset
);
2298 else if (which
== 2)
2300 if (core_reg_size
!= sizeof (pi
.fpregset
))
2302 warning ("wrong size fpregset struct in core file");
2306 memcpy ((char *) &pi
.fpregset
, core_reg_sect
, sizeof (pi
.fpregset
));
2307 #if defined (FP0_REGNUM)
2308 supply_fpregset (&pi
.fpregset
);
2318 proc_init_failed - called whenever /proc access initialization fails
2322 static void proc_init_failed (char *why)
2326 This function is called whenever initialization of access to a /proc
2327 entry fails. It prints a suitable error message, does some cleanup,
2328 and then invokes the standard error processing routine which dumps
2329 us back into the command loop.
2333 proc_init_failed (why
)
2336 print_sys_errmsg (pi
.pathname
, errno
);
2337 kill (pi
.pid
, SIGKILL
);
2338 close_proc_file (&pi
);
2347 close_proc_file - close any currently open /proc entry
2351 static void close_proc_file (struct procinfo *pip)
2355 Close any currently open /proc entry and mark the process information
2356 entry as invalid. In order to ensure that we don't try to reuse any
2357 stale information, the pid, fd, and pathnames are explicitly
2358 invalidated, which may be overkill.
2363 close_proc_file (pip
)
2364 struct procinfo
*pip
;
2372 if (pip
-> pathname
)
2374 free (pip
-> pathname
);
2375 pip
-> pathname
= NULL
;
2384 open_proc_file - open a /proc entry for a given process id
2388 static int open_proc_file (int pid, struct procinfo *pip, int mode)
2392 Given a process id and a mode, close the existing open /proc
2393 entry (if any) and open one for the new process id, in the
2394 specified mode. Once it is open, then mark the local process
2395 information structure as valid, which guarantees that the pid,
2396 fd, and pathname fields match an open /proc entry. Returns
2397 zero if the open fails, nonzero otherwise.
2399 Note that the pathname is left intact, even when the open fails,
2400 so that callers can use it to construct meaningful error messages
2401 rather than just "file open failed".
2405 open_proc_file (pid
, pip
, mode
)
2407 struct procinfo
*pip
;
2410 pip
-> valid
= 0; /* FIXME, what is this? ?! */
2415 if (pip
-> pathname
== NULL
)
2417 pip
-> pathname
= xmalloc (32);
2419 sprintf (pip
-> pathname
, PROC_NAME_FMT
, pid
);
2420 if ((pip
-> fd
= open (pip
-> pathname
, mode
)) >= 0)
2425 return (pip
-> valid
);
2429 mappingflags (flags
)
2432 static char asciiflags
[8];
2434 strcpy (asciiflags
, "-------");
2435 #if defined (MA_PHYS)
2436 if (flags
& MA_PHYS
) asciiflags
[0] = 'd';
2438 if (flags
& MA_STACK
) asciiflags
[1] = 's';
2439 if (flags
& MA_BREAK
) asciiflags
[2] = 'b';
2440 if (flags
& MA_SHARED
) asciiflags
[3] = 's';
2441 if (flags
& MA_READ
) asciiflags
[4] = 'r';
2442 if (flags
& MA_WRITE
) asciiflags
[5] = 'w';
2443 if (flags
& MA_EXEC
) asciiflags
[6] = 'x';
2444 return (asciiflags
);
2448 info_proc_flags (pip
, summary
)
2449 struct procinfo
*pip
;
2452 struct trans
*transp
;
2454 printf_filtered ("%-32s", "Process status flags:");
2457 printf_filtered ("\n\n");
2459 for (transp
= pr_flag_table
; transp
-> name
!= NULL
; transp
++)
2461 if (pip
-> prstatus
.pr_flags
& transp
-> value
)
2465 printf_filtered ("%s ", transp
-> name
);
2469 printf_filtered ("\t%-16s %s.\n", transp
-> name
, transp
-> desc
);
2473 printf_filtered ("\n");
2477 info_proc_stop (pip
, summary
)
2478 struct procinfo
*pip
;
2481 struct trans
*transp
;
2485 why
= pip
-> prstatus
.pr_why
;
2486 what
= pip
-> prstatus
.pr_what
;
2488 if (pip
-> prstatus
.pr_flags
& PR_STOPPED
)
2490 printf_filtered ("%-32s", "Reason for stopping:");
2493 printf_filtered ("\n\n");
2495 for (transp
= pr_why_table
; transp
-> name
!= NULL
; transp
++)
2497 if (why
== transp
-> value
)
2501 printf_filtered ("%s ", transp
-> name
);
2505 printf_filtered ("\t%-16s %s.\n",
2506 transp
-> name
, transp
-> desc
);
2512 /* Use the pr_why field to determine what the pr_what field means, and
2513 print more information. */
2518 /* pr_what is unused for this case */
2524 printf_filtered ("%s ", signalname (what
));
2528 printf_filtered ("\t%-16s %s.\n", signalname (what
),
2529 safe_strsignal (what
));
2535 printf_filtered ("%s ", syscallname (what
));
2539 printf_filtered ("\t%-16s %s.\n", syscallname (what
),
2540 "Entered this system call");
2546 printf_filtered ("%s ", syscallname (what
));
2550 printf_filtered ("\t%-16s %s.\n", syscallname (what
),
2551 "Returned from this system call");
2557 printf_filtered ("%s ",
2558 lookupname (faults_table
, what
, "fault"));
2562 printf_filtered ("\t%-16s %s.\n",
2563 lookupname (faults_table
, what
, "fault"),
2564 lookupdesc (faults_table
, what
));
2568 printf_filtered ("\n");
2573 info_proc_siginfo (pip
, summary
)
2574 struct procinfo
*pip
;
2577 struct siginfo
*sip
;
2579 if ((pip
-> prstatus
.pr_flags
& PR_STOPPED
) &&
2580 (pip
-> prstatus
.pr_why
== PR_SIGNALLED
||
2581 pip
-> prstatus
.pr_why
== PR_FAULTED
))
2583 printf_filtered ("%-32s", "Additional signal/fault info:");
2584 sip
= &pip
-> prstatus
.pr_info
;
2587 printf_filtered ("%s ", signalname (sip
-> si_signo
));
2588 if (sip
-> si_errno
> 0)
2590 printf_filtered ("%s ", errnoname (sip
-> si_errno
));
2592 if (sip
-> si_code
<= 0)
2594 printf_filtered ("sent by pid %d, uid %d ", sip
-> si_pid
,
2599 printf_filtered ("%s ", sigcodename (sip
));
2600 if ((sip
-> si_signo
== SIGILL
) ||
2601 (sip
-> si_signo
== SIGFPE
) ||
2602 (sip
-> si_signo
== SIGSEGV
) ||
2603 (sip
-> si_signo
== SIGBUS
))
2605 printf_filtered ("addr=%#x ", sip
-> si_addr
);
2607 else if ((sip
-> si_signo
== SIGCHLD
))
2609 printf_filtered ("child pid %u, status %u ",
2613 else if ((sip
-> si_signo
== SIGPOLL
))
2615 printf_filtered ("band %u ", sip
-> si_band
);
2621 printf_filtered ("\n\n");
2622 printf_filtered ("\t%-16s %s.\n", signalname (sip
-> si_signo
),
2623 safe_strsignal (sip
-> si_signo
));
2624 if (sip
-> si_errno
> 0)
2626 printf_filtered ("\t%-16s %s.\n",
2627 errnoname (sip
-> si_errno
),
2628 safe_strerror (sip
-> si_errno
));
2630 if (sip
-> si_code
<= 0)
2632 printf_filtered ("\t%-16u %s\n", sip
-> si_pid
,
2633 "PID of process sending signal");
2634 printf_filtered ("\t%-16u %s\n", sip
-> si_uid
,
2635 "UID of process sending signal");
2639 printf_filtered ("\t%-16s %s.\n", sigcodename (sip
),
2641 if ((sip
-> si_signo
== SIGILL
) ||
2642 (sip
-> si_signo
== SIGFPE
))
2644 printf_filtered ("\t%-16#x %s.\n", sip
-> si_addr
,
2645 "Address of faulting instruction");
2647 else if ((sip
-> si_signo
== SIGSEGV
) ||
2648 (sip
-> si_signo
== SIGBUS
))
2650 printf_filtered ("\t%-16#x %s.\n", sip
-> si_addr
,
2651 "Address of faulting memory reference");
2653 else if ((sip
-> si_signo
== SIGCHLD
))
2655 printf_filtered ("\t%-16u %s.\n", sip
-> si_pid
,
2656 "Child process ID");
2657 printf_filtered ("\t%-16u %s.\n", sip
-> si_status
,
2658 "Child process exit value or signal");
2660 else if ((sip
-> si_signo
== SIGPOLL
))
2662 printf_filtered ("\t%-16u %s.\n", sip
-> si_band
,
2663 "Band event for POLL_{IN,OUT,MSG}");
2667 printf_filtered ("\n");
2672 info_proc_syscalls (pip
, summary
)
2673 struct procinfo
*pip
;
2681 #if 0 /* FIXME: Needs to use gdb-wide configured info about system calls. */
2682 if (pip
-> prstatus
.pr_flags
& PR_ASLEEP
)
2684 int syscallnum
= pip
-> prstatus
.pr_reg
[R_D0
];
2687 printf_filtered ("%-32s", "Sleeping in system call:");
2688 printf_filtered ("%s", syscallname (syscallnum
));
2692 printf_filtered ("Sleeping in system call '%s'.\n",
2693 syscallname (syscallnum
));
2698 if (ioctl (pip
-> fd
, PIOCGENTRY
, &pip
-> entryset
) < 0)
2700 print_sys_errmsg (pip
-> pathname
, errno
);
2701 error ("PIOCGENTRY failed");
2704 if (ioctl (pip
-> fd
, PIOCGEXIT
, &pip
-> exitset
) < 0)
2706 print_sys_errmsg (pip
-> pathname
, errno
);
2707 error ("PIOCGEXIT failed");
2710 printf_filtered ("System call tracing information:\n\n");
2712 printf_filtered ("\t%-12s %-8s %-8s\n",
2716 for (syscallnum
= 0; syscallnum
< MAX_SYSCALLS
; syscallnum
++)
2719 if (syscall_table
[syscallnum
] != NULL
)
2721 printf_filtered ("\t%-12s ", syscall_table
[syscallnum
]);
2722 printf_filtered ("%-8s ",
2723 prismember (&pip
-> entryset
, syscallnum
)
2725 printf_filtered ("%-8s ",
2726 prismember (&pip
-> exitset
, syscallnum
)
2728 printf_filtered ("\n");
2731 printf_filtered ("\n");
2740 static char locbuf
[32];
2742 name
= strsigno (signo
);
2745 sprintf (locbuf
, "Signal %d", signo
);
2749 sprintf (locbuf
, "%s (%d)", name
, signo
);
2759 static char locbuf
[32];
2761 name
= strerrno (errnum
);
2764 sprintf (locbuf
, "Errno %d", errnum
);
2768 sprintf (locbuf
, "%s (%d)", name
, errnum
);
2774 info_proc_signals (pip
, summary
)
2775 struct procinfo
*pip
;
2782 if (ioctl (pip
-> fd
, PIOCGTRACE
, &pip
-> trace
) < 0)
2784 print_sys_errmsg (pip
-> pathname
, errno
);
2785 error ("PIOCGTRACE failed");
2788 printf_filtered ("Disposition of signals:\n\n");
2789 printf_filtered ("\t%-15s %-8s %-8s %-8s %s\n\n",
2790 "Signal", "Trace", "Hold", "Pending", "Description");
2791 for (signo
= 0; signo
< NSIG
; signo
++)
2794 printf_filtered ("\t%-15s ", signalname (signo
));
2795 printf_filtered ("%-8s ",
2796 prismember (&pip
-> trace
, signo
)
2798 printf_filtered ("%-8s ",
2799 prismember (&pip
-> prstatus
.pr_sighold
, signo
)
2801 printf_filtered ("%-8s ",
2802 prismember (&pip
-> prstatus
.pr_sigpend
, signo
)
2804 printf_filtered (" %s\n", safe_strsignal (signo
));
2806 printf_filtered ("\n");
2811 info_proc_faults (pip
, summary
)
2812 struct procinfo
*pip
;
2815 struct trans
*transp
;
2819 if (ioctl (pip
-> fd
, PIOCGFAULT
, &pip
-> fltset
) < 0)
2821 print_sys_errmsg (pip
-> pathname
, errno
);
2822 error ("PIOCGFAULT failed");
2825 printf_filtered ("Current traced hardware fault set:\n\n");
2826 printf_filtered ("\t%-12s %-8s\n", "Fault", "Trace");
2828 for (transp
= faults_table
; transp
-> name
!= NULL
; transp
++)
2831 printf_filtered ("\t%-12s ", transp
-> name
);
2832 printf_filtered ("%-8s", prismember (&pip
-> fltset
, transp
-> value
)
2834 printf_filtered ("\n");
2836 printf_filtered ("\n");
2841 info_proc_mappings (pip
, summary
)
2842 struct procinfo
*pip
;
2846 struct prmap
*prmaps
;
2847 struct prmap
*prmap
;
2851 printf_filtered ("Mapped address spaces:\n\n");
2852 printf_filtered ("\t%10s %10s %10s %10s %7s\n",
2858 if (ioctl (pip
-> fd
, PIOCNMAP
, &nmap
) == 0)
2860 prmaps
= (struct prmap
*) alloca ((nmap
+ 1) * sizeof (*prmaps
));
2861 if (ioctl (pip
-> fd
, PIOCMAP
, prmaps
) == 0)
2863 for (prmap
= prmaps
; prmap
-> pr_size
; ++prmap
)
2865 printf_filtered ("\t%#10x %#10x %#10x %#10x %7s\n",
2867 prmap
-> pr_vaddr
+ prmap
-> pr_size
- 1,
2870 mappingflags (prmap
-> pr_mflags
));
2874 printf_filtered ("\n");
2882 info_proc -- implement the "info proc" command
2886 void info_proc (char *args, int from_tty)
2890 Implement gdb's "info proc" command by using the /proc interface
2891 to print status information about any currently running process.
2893 Examples of the use of "info proc" are:
2895 info proc (prints summary info for current inferior)
2896 info proc 123 (prints summary info for process with pid 123)
2897 info proc mappings (prints address mappings)
2898 info proc times (prints process/children times)
2899 info proc id (prints pid, ppid, gid, sid, etc)
2900 FIXME: i proc id not implemented.
2901 info proc status (prints general process state info)
2902 FIXME: i proc status not implemented.
2903 info proc signals (prints info about signal handling)
2904 info proc all (prints all info)
2909 info_proc (args
, from_tty
)
2914 struct procinfo pii
;
2915 struct procinfo
*pip
;
2916 struct cleanup
*old_chain
;
2930 old_chain
= make_cleanup (null_cleanup
, 0);
2932 /* Default to using the current inferior if no pid specified */
2938 if ((argv
= buildargv (args
)) == NULL
)
2942 make_cleanup (freeargv
, (char *) argv
);
2944 while (*argv
!= NULL
)
2946 argsize
= strlen (*argv
);
2947 if (argsize
>= 1 && strncmp (*argv
, "all", argsize
) == 0)
2952 else if (argsize
>= 2 && strncmp (*argv
, "faults", argsize
) == 0)
2957 else if (argsize
>= 2 && strncmp (*argv
, "flags", argsize
) == 0)
2962 else if (argsize
>= 1 && strncmp (*argv
, "id", argsize
) == 0)
2967 else if (argsize
>= 1 && strncmp (*argv
, "mappings", argsize
) == 0)
2972 else if (argsize
>= 2 && strncmp (*argv
, "signals", argsize
) == 0)
2977 else if (argsize
>= 2 && strncmp (*argv
, "status", argsize
) == 0)
2982 else if (argsize
>= 2 && strncmp (*argv
, "syscalls", argsize
) == 0)
2987 else if (argsize
>= 1 && strncmp (*argv
, "times", argsize
) == 0)
2992 else if ((pii
.pid
= atoi (*argv
)) > 0)
2996 memset (&pii
, 0, sizeof (pii
));
2997 if (!open_proc_file (pid
, pip
, O_RDONLY
))
2999 perror_with_name (pip
-> pathname
);
3002 make_cleanup (close_proc_file
, pip
);
3004 else if (**argv
!= '\000')
3006 error ("Unrecognized or ambiguous keyword `%s'.", *argv
);
3012 /* If we don't have a valid open process at this point, then we have no
3013 inferior or didn't specify a specific pid. */
3017 error ("No process. Run an inferior or specify an explicit pid.");
3019 if (ioctl (pip
-> fd
, PIOCSTATUS
, &(pip
-> prstatus
)) < 0)
3021 print_sys_errmsg (pip
-> pathname
, errno
);
3022 error ("PIOCSTATUS failed");
3025 /* Print verbose information of the requested type(s), or just a summary
3026 of the information for all types. */
3028 printf_filtered ("\nInformation for %s:\n\n", pip
-> pathname
);
3029 if (summary
|| all
|| flags
)
3031 info_proc_flags (pip
, summary
);
3035 info_proc_stop (pip
, summary
);
3037 if (summary
|| all
|| signals
|| faults
)
3039 info_proc_siginfo (pip
, summary
);
3041 if (summary
|| all
|| syscalls
)
3043 info_proc_syscalls (pip
, summary
);
3045 if (summary
|| all
|| mappings
)
3047 info_proc_mappings (pip
, summary
);
3049 if (summary
|| all
|| signals
)
3051 info_proc_signals (pip
, summary
);
3053 if (summary
|| all
|| faults
)
3055 info_proc_faults (pip
, summary
);
3057 printf_filtered ("\n");
3059 /* All done, deal with closing any temporary process info structure,
3060 freeing temporary memory , etc. */
3062 do_cleanups (old_chain
);
3065 /* Fork an inferior process, and start debugging it with /proc. */
3068 procfs_create_inferior (exec_file
, allargs
, env
)
3073 fork_inferior (exec_file
, allargs
, env
,
3074 proc_set_exec_trap
, procfs_init_inferior
);
3075 /* We are at the first instruction we care about. */
3076 /* Pedal to the metal... */
3077 proceed ((CORE_ADDR
) -1, 0, 0);
3080 /* Clean up after the inferior dies. */
3083 procfs_mourn_inferior ()
3085 unpush_target (&procfs_ops
);
3086 generic_mourn_inferior ();
3089 /* Mark our target-struct as eligible for stray "run" and "attach" commands. */
3096 struct target_ops procfs_ops
= {
3097 "procfs", /* to_shortname */
3098 "Unix /proc child process", /* to_longname */
3099 "Unix /proc child process (started by the \"run\" command).", /* to_doc */
3100 procfs_open
, /* to_open */
3102 procfs_attach
, /* to_attach */
3103 procfs_detach
, /* to_detach */
3104 procfs_resume
, /* to_resume */
3105 procfs_wait
, /* to_wait */
3106 procfs_fetch_registers
, /* to_fetch_registers */
3107 procfs_store_registers
, /* to_store_registers */
3108 procfs_prepare_to_store
, /* to_prepare_to_store */
3109 procfs_xfer_memory
, /* to_xfer_memory */
3110 procfs_files_info
, /* to_files_info */
3111 memory_insert_breakpoint
, /* to_insert_breakpoint */
3112 memory_remove_breakpoint
, /* to_remove_breakpoint */
3113 terminal_init_inferior
, /* to_terminal_init */
3114 terminal_inferior
, /* to_terminal_inferior */
3115 terminal_ours_for_output
, /* to_terminal_ours_for_output */
3116 terminal_ours
, /* to_terminal_ours */
3117 child_terminal_info
, /* to_terminal_info */
3118 procfs_kill_inferior
, /* to_kill */
3120 0, /* to_lookup_symbol */
3121 procfs_create_inferior
, /* to_create_inferior */
3122 procfs_mourn_inferior
, /* to_mourn_inferior */
3123 procfs_can_run
, /* to_can_run */
3124 procfs_notice_signals
, /* to_notice_signals */
3125 process_stratum
, /* to_stratum */
3127 1, /* to_has_all_memory */
3128 1, /* to_has_memory */
3129 1, /* to_has_stack */
3130 1, /* to_has_registers */
3131 1, /* to_has_execution */
3133 0, /* sections_end */
3134 OPS_MAGIC
/* to_magic */
3141 _initialize_procfs -- initialize the process file system stuff
3145 void _initialize_procfs (void)
3149 Do required initializations during gdb startup for using the
3150 /proc file system interface.
3155 _initialize_procfs ()
3157 add_target (&procfs_ops
);
3159 add_info ("proc", info_proc
,
3160 "Show process status information using /proc entry.\n\
3161 Specify process id or use current inferior by default.\n\
3162 Specify keywords for detailed information; default is summary.\n\
3163 Keywords are: `all', `faults', `flags', `id', `mappings', `signals',\n\
3164 `status', `syscalls', and `times'.\n\
3165 Unambiguous abbreviations may be used.");
3167 init_syscall_table ();