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>
50 #define MAX_SYSCALLS 256 /* Maximum number of syscalls for table */
53 #define PROC_NAME_FMT "/proc/%05d"
56 extern struct target_ops procfs_ops
; /* Forward declaration */
58 #if 1 /* FIXME: Gross and ugly hack to resolve coredep.c global */
59 CORE_ADDR kernel_u_addr
;
62 #ifdef BROKEN_SIGINFO_H /* Workaround broken SGS <sys/siginfo.h> */
64 #define si_pid _data._proc.pid
66 #define si_uid _data._proc._pdata._kill.uid
67 #endif /* BROKEN_SIGINFO_H */
69 /* All access to the inferior, either one started by gdb or one that has
70 been attached to, is controlled by an instance of a procinfo structure,
71 defined below. Since gdb currently only handles one inferior at a time,
72 the procinfo structure for the inferior is statically allocated and
73 only one exists at any given time. There is a separate procinfo
74 structure for use by the "info proc" command, so that we can print
75 useful information about any random process without interfering with
76 the inferior's procinfo information. */
79 int valid
; /* Nonzero if pid, fd, & pathname are valid */
80 int pid
; /* Process ID of inferior */
81 int fd
; /* File descriptor for /proc entry */
82 char *pathname
; /* Pathname to /proc entry */
83 int was_stopped
; /* Nonzero if was stopped prior to attach */
84 int nopass_next_sigstop
; /* Don't pass a sigstop on next resume */
85 prrun_t prrun
; /* Control state when it is run */
86 prstatus_t prstatus
; /* Current process status info */
87 gregset_t gregset
; /* General register set */
88 fpregset_t fpregset
; /* Floating point register set */
89 fltset_t fltset
; /* Current traced hardware fault set */
90 sigset_t trace
; /* Current traced signal set */
91 sysset_t exitset
; /* Current traced system call exit set */
92 sysset_t entryset
; /* Current traced system call entry set */
93 fltset_t saved_fltset
; /* Saved traced hardware fault set */
94 sigset_t saved_trace
; /* Saved traced signal set */
95 sigset_t saved_sighold
; /* Saved held signal set */
96 sysset_t saved_exitset
; /* Saved traced system call exit set */
97 sysset_t saved_entryset
; /* Saved traced system call entry set */
100 static struct procinfo pi
; /* Inferior's process information */
102 /* Much of the information used in the /proc interface, particularly for
103 printing status information, is kept as tables of structures of the
104 following form. These tables can be used to map numeric values to
105 their symbolic names and to a string that describes their specific use. */
108 int value
; /* The numeric value */
109 char *name
; /* The equivalent symbolic value */
110 char *desc
; /* Short description of value */
113 /* Translate bits in the pr_flags member of the prstatus structure, into the
114 names and desc information. */
116 static struct trans pr_flag_table
[] =
118 #if defined (PR_STOPPED)
119 PR_STOPPED
, "PR_STOPPED", "Process is stopped",
121 #if defined (PR_ISTOP)
122 PR_ISTOP
, "PR_ISTOP", "Stopped on an event of interest",
124 #if defined (PR_DSTOP)
125 PR_DSTOP
, "PR_DSTOP", "A stop directive is in effect",
127 #if defined (PR_ASLEEP)
128 PR_ASLEEP
, "PR_ASLEEP", "Sleeping in an interruptible system call",
130 #if defined (PR_FORK)
131 PR_FORK
, "PR_FORK", "Inherit-on-fork is in effect",
134 PR_RLC
, "PR_RLC", "Run-on-last-close is in effect",
136 #if defined (PR_PTRACE)
137 PR_PTRACE
, "PR_PTRACE", "Process is being controlled by ptrace",
139 #if defined (PR_PCINVAL)
140 PR_PCINVAL
, "PR_PCINVAL", "PC refers to an invalid virtual address",
142 #if defined (PR_ISSYS)
143 PR_ISSYS
, "PR_ISSYS", "Is a system process",
145 #if defined (PR_STEP)
146 PR_STEP
, "PR_STEP", "Process has single step pending",
149 PR_KLC
, "PR_KLC", "Kill-on-last-close is in effect",
151 #if defined (PR_ASYNC)
152 PR_ASYNC
, "PR_ASYNC", "Asynchronous stop is in effect",
154 #if defined (PR_PCOMPAT)
155 PR_PCOMPAT
, "PR_PCOMPAT", "Ptrace compatibility mode in effect",
160 /* Translate values in the pr_why field of the prstatus struct. */
162 static struct trans pr_why_table
[] =
164 #if defined (PR_REQUESTED)
165 PR_REQUESTED
, "PR_REQUESTED", "Directed to stop via PIOCSTOP/PIOCWSTOP",
167 #if defined (PR_SIGNALLED)
168 PR_SIGNALLED
, "PR_SIGNALLED", "Receipt of a traced signal",
170 #if defined (PR_FAULTED)
171 PR_FAULTED
, "PR_FAULTED", "Incurred a traced hardware fault",
173 #if defined (PR_SYSENTRY)
174 PR_SYSENTRY
, "PR_SYSENTRY", "Entry to a traced system call",
176 #if defined (PR_SYSEXIT)
177 PR_SYSEXIT
, "PR_SYSEXIT", "Exit from a traced system call",
179 #if defined (PR_JOBCONTROL)
180 PR_JOBCONTROL
, "PR_JOBCONTROL", "Default job control stop signal action",
182 #if defined (PR_SUSPENDED)
183 PR_SUSPENDED
, "PR_SUSPENDED", "Process suspended",
188 /* Hardware fault translation table. */
190 static struct trans faults_table
[] =
193 FLTILL
, "FLTILL", "Illegal instruction",
195 #if defined (FLTPRIV)
196 FLTPRIV
, "FLTPRIV", "Privileged instruction",
199 FLTBPT
, "FLTBPT", "Breakpoint trap",
201 #if defined (FLTTRACE)
202 FLTTRACE
, "FLTTRACE", "Trace trap",
204 #if defined (FLTACCESS)
205 FLTACCESS
, "FLTACCESS", "Memory access fault",
207 #if defined (FLTBOUNDS)
208 FLTBOUNDS
, "FLTBOUNDS", "Memory bounds violation",
210 #if defined (FLTIOVF)
211 FLTIOVF
, "FLTIOVF", "Integer overflow",
213 #if defined (FLTIZDIV)
214 FLTIZDIV
, "FLTIZDIV", "Integer zero divide",
217 FLTFPE
, "FLTFPE", "Floating-point exception",
219 #if defined (FLTSTACK)
220 FLTSTACK
, "FLTSTACK", "Unrecoverable stack fault",
222 #if defined (FLTPAGE)
223 FLTPAGE
, "FLTPAGE", "Recoverable page fault",
228 /* Translation table for signal generation information. See UNIX System
229 V Release 4 Programmer's Reference Manual, siginfo(5). */
231 static struct sigcode
{
236 } siginfo_table
[] = {
237 #if defined (SIGILL) && defined (ILL_ILLOPC)
238 SIGILL
, ILL_ILLOPC
, "ILL_ILLOPC", "Illegal opcode",
240 #if defined (SIGILL) && defined (ILL_ILLOPN)
241 SIGILL
, ILL_ILLOPN
, "ILL_ILLOPN", "Illegal operand",
243 #if defined (SIGILL) && defined (ILL_ILLADR)
244 SIGILL
, ILL_ILLADR
, "ILL_ILLADR", "Illegal addressing mode",
246 #if defined (SIGILL) && defined (ILL_ILLTRP)
247 SIGILL
, ILL_ILLTRP
, "ILL_ILLTRP", "Illegal trap",
249 #if defined (SIGILL) && defined (ILL_PRVOPC)
250 SIGILL
, ILL_PRVOPC
, "ILL_PRVOPC", "Privileged opcode",
252 #if defined (SIGILL) && defined (ILL_PRVREG)
253 SIGILL
, ILL_PRVREG
, "ILL_PRVREG", "Privileged register",
255 #if defined (SIGILL) && defined (ILL_COPROC)
256 SIGILL
, ILL_COPROC
, "ILL_COPROC", "Coprocessor error",
258 #if defined (SIGILL) && defined (ILL_BADSTK)
259 SIGILL
, ILL_BADSTK
, "ILL_BADSTK", "Internal stack error",
261 #if defined (SIGFPE) && defined (FPE_INTDIV)
262 SIGFPE
, FPE_INTDIV
, "FPE_INTDIV", "Integer divide by zero",
264 #if defined (SIGFPE) && defined (FPE_INTOVF)
265 SIGFPE
, FPE_INTOVF
, "FPE_INTOVF", "Integer overflow",
267 #if defined (SIGFPE) && defined (FPE_FLTDIV)
268 SIGFPE
, FPE_FLTDIV
, "FPE_FLTDIV", "Floating point divide by zero",
270 #if defined (SIGFPE) && defined (FPE_FLTOVF)
271 SIGFPE
, FPE_FLTOVF
, "FPE_FLTOVF", "Floating point overflow",
273 #if defined (SIGFPE) && defined (FPE_FLTUND)
274 SIGFPE
, FPE_FLTUND
, "FPE_FLTUND", "Floating point underflow",
276 #if defined (SIGFPE) && defined (FPE_FLTRES)
277 SIGFPE
, FPE_FLTRES
, "FPE_FLTRES", "Floating point inexact result",
279 #if defined (SIGFPE) && defined (FPE_FLTINV)
280 SIGFPE
, FPE_FLTINV
, "FPE_FLTINV", "Invalid floating point operation",
282 #if defined (SIGFPE) && defined (FPE_FLTSUB)
283 SIGFPE
, FPE_FLTSUB
, "FPE_FLTSUB", "Subscript out of range",
285 #if defined (SIGSEGV) && defined (SEGV_MAPERR)
286 SIGSEGV
, SEGV_MAPERR
, "SEGV_MAPERR", "Address not mapped to object",
288 #if defined (SIGSEGV) && defined (SEGV_ACCERR)
289 SIGSEGV
, SEGV_ACCERR
, "SEGV_ACCERR", "Invalid permissions for object",
291 #if defined (SIGBUS) && defined (BUS_ADRALN)
292 SIGBUS
, BUS_ADRALN
, "BUS_ADRALN", "Invalid address alignment",
294 #if defined (SIGBUS) && defined (BUS_ADRERR)
295 SIGBUS
, BUS_ADRERR
, "BUS_ADRERR", "Non-existent physical address",
297 #if defined (SIGBUS) && defined (BUS_OBJERR)
298 SIGBUS
, BUS_OBJERR
, "BUS_OBJERR", "Object specific hardware error",
300 #if defined (SIGTRAP) && defined (TRAP_BRKPT)
301 SIGTRAP
, TRAP_BRKPT
, "TRAP_BRKPT", "Process breakpoint",
303 #if defined (SIGTRAP) && defined (TRAP_TRACE)
304 SIGTRAP
, TRAP_TRACE
, "TRAP_TRACE", "Process trace trap",
306 #if defined (SIGCLD) && defined (CLD_EXITED)
307 SIGCLD
, CLD_EXITED
, "CLD_EXITED", "Child has exited",
309 #if defined (SIGCLD) && defined (CLD_KILLED)
310 SIGCLD
, CLD_KILLED
, "CLD_KILLED", "Child was killed",
312 #if defined (SIGCLD) && defined (CLD_DUMPED)
313 SIGCLD
, CLD_DUMPED
, "CLD_DUMPED", "Child has terminated abnormally",
315 #if defined (SIGCLD) && defined (CLD_TRAPPED)
316 SIGCLD
, CLD_TRAPPED
, "CLD_TRAPPED", "Traced child has trapped",
318 #if defined (SIGCLD) && defined (CLD_STOPPED)
319 SIGCLD
, CLD_STOPPED
, "CLD_STOPPED", "Child has stopped",
321 #if defined (SIGCLD) && defined (CLD_CONTINUED)
322 SIGCLD
, CLD_CONTINUED
, "CLD_CONTINUED", "Stopped child had continued",
324 #if defined (SIGPOLL) && defined (POLL_IN)
325 SIGPOLL
, POLL_IN
, "POLL_IN", "Input input available",
327 #if defined (SIGPOLL) && defined (POLL_OUT)
328 SIGPOLL
, POLL_OUT
, "POLL_OUT", "Output buffers available",
330 #if defined (SIGPOLL) && defined (POLL_MSG)
331 SIGPOLL
, POLL_MSG
, "POLL_MSG", "Input message available",
333 #if defined (SIGPOLL) && defined (POLL_ERR)
334 SIGPOLL
, POLL_ERR
, "POLL_ERR", "I/O error",
336 #if defined (SIGPOLL) && defined (POLL_PRI)
337 SIGPOLL
, POLL_PRI
, "POLL_PRI", "High priority input available",
339 #if defined (SIGPOLL) && defined (POLL_HUP)
340 SIGPOLL
, POLL_HUP
, "POLL_HUP", "Device disconnected",
345 static char *syscall_table
[MAX_SYSCALLS
];
347 /* Prototypes for local functions */
350 set_proc_siginfo
PARAMS ((struct procinfo
*, int));
353 init_syscall_table
PARAMS ((void));
356 syscallname
PARAMS ((int));
359 signalname
PARAMS ((int));
362 errnoname
PARAMS ((int));
365 proc_address_to_fd
PARAMS ((CORE_ADDR
, int));
368 open_proc_file
PARAMS ((int, struct procinfo
*, int));
371 close_proc_file
PARAMS ((struct procinfo
*));
374 unconditionally_kill_inferior
PARAMS ((void));
377 proc_init_failed
PARAMS ((char *));
380 info_proc
PARAMS ((char *, int));
383 info_proc_flags
PARAMS ((struct procinfo
*, int));
386 info_proc_stop
PARAMS ((struct procinfo
*, int));
389 info_proc_siginfo
PARAMS ((struct procinfo
*, int));
392 info_proc_syscalls
PARAMS ((struct procinfo
*, int));
395 info_proc_mappings
PARAMS ((struct procinfo
*, int));
398 info_proc_signals
PARAMS ((struct procinfo
*, int));
401 info_proc_faults
PARAMS ((struct procinfo
*, int));
404 mappingflags
PARAMS ((long));
407 lookupname
PARAMS ((struct trans
*, unsigned int, char *));
410 lookupdesc
PARAMS ((struct trans
*, unsigned int));
413 do_attach
PARAMS ((int pid
));
416 do_detach
PARAMS ((int siggnal
));
419 procfs_create_inferior
PARAMS ((char *, char *, char **));
422 procfs_notice_signals
PARAMS ((void));
424 /* External function prototypes that can't be easily included in any
425 header file because the args are typedefs in system include files. */
428 supply_gregset
PARAMS ((gregset_t
*));
431 fill_gregset
PARAMS ((gregset_t
*, int));
434 supply_fpregset
PARAMS ((fpregset_t
*));
437 fill_fpregset
PARAMS ((fpregset_t
*, int));
443 lookupdesc -- translate a value to a summary desc string
447 static char *lookupdesc (struct trans *transp, unsigned int val);
451 Given a pointer to a translation table and a value to be translated,
452 lookup the desc string and return it.
456 lookupdesc (transp
, val
)
457 struct trans
*transp
;
462 for (desc
= NULL
; transp
-> name
!= NULL
; transp
++)
464 if (transp
-> value
== val
)
466 desc
= transp
-> desc
;
471 /* Didn't find a translation for the specified value, set a default one. */
484 lookupname -- translate a value to symbolic name
488 static char *lookupname (struct trans *transp, unsigned int val,
493 Given a pointer to a translation table, a value to be translated,
494 and a default prefix to return if the value can't be translated,
495 match the value with one of the translation table entries and
496 return a pointer to the symbolic name.
498 If no match is found it just returns the value as a printable string,
499 with the given prefix. The previous such value, if any, is freed
504 lookupname (transp
, val
, prefix
)
505 struct trans
*transp
;
512 for (name
= NULL
; transp
-> name
!= NULL
; transp
++)
514 if (transp
-> value
== val
)
516 name
= transp
-> name
;
521 /* Didn't find a translation for the specified value, build a default
522 one using the specified prefix and return it. The lifetime of
523 the value is only until the next one is needed. */
531 locbuf
= xmalloc (strlen (prefix
) + 16);
532 sprintf (locbuf
, "%s %u", prefix
, val
);
544 static char locbuf
[32];
546 for (scp
= siginfo_table
; scp
-> codename
!= NULL
; scp
++)
548 if ((scp
-> signo
== sip
-> si_signo
) &&
549 (scp
-> code
== sip
-> si_code
))
551 name
= scp
-> codename
;
557 sprintf (locbuf
, "sigcode %u", sip
-> si_signo
);
570 for (scp
= siginfo_table
; scp
-> codename
!= NULL
; scp
++)
572 if ((scp
-> signo
== sip
-> si_signo
) &&
573 (scp
-> code
== sip
-> si_code
))
581 desc
= "Unrecognized signal or trap use";
590 syscallname - translate a system call number into a system call name
594 char *syscallname (int syscallnum)
598 Given a system call number, translate it into the printable name
599 of a system call, or into "syscall <num>" if it is an unknown
604 syscallname (syscallnum
)
607 static char locbuf
[32];
610 if (syscallnum
>= 0 && syscallnum
< MAX_SYSCALLS
)
612 rtnval
= syscall_table
[syscallnum
];
616 sprintf (locbuf
, "syscall %u", syscallnum
);
626 init_syscall_table - initialize syscall translation table
630 void init_syscall_table (void)
634 Dynamically initialize the translation table to convert system
635 call numbers into printable system call names. Done once per
636 gdb run, on initialization.
640 This is awfully ugly, but preprocessor tricks to make it prettier
641 tend to be nonportable.
645 init_syscall_table ()
647 #if defined (SYS_exit)
648 syscall_table
[SYS_exit
] = "exit";
650 #if defined (SYS_fork)
651 syscall_table
[SYS_fork
] = "fork";
653 #if defined (SYS_read)
654 syscall_table
[SYS_read
] = "read";
656 #if defined (SYS_write)
657 syscall_table
[SYS_write
] = "write";
659 #if defined (SYS_open)
660 syscall_table
[SYS_open
] = "open";
662 #if defined (SYS_close)
663 syscall_table
[SYS_close
] = "close";
665 #if defined (SYS_wait)
666 syscall_table
[SYS_wait
] = "wait";
668 #if defined (SYS_creat)
669 syscall_table
[SYS_creat
] = "creat";
671 #if defined (SYS_link)
672 syscall_table
[SYS_link
] = "link";
674 #if defined (SYS_unlink)
675 syscall_table
[SYS_unlink
] = "unlink";
677 #if defined (SYS_exec)
678 syscall_table
[SYS_exec
] = "exec";
680 #if defined (SYS_execv)
681 syscall_table
[SYS_execv
] = "execv";
683 #if defined (SYS_execve)
684 syscall_table
[SYS_execve
] = "execve";
686 #if defined (SYS_chdir)
687 syscall_table
[SYS_chdir
] = "chdir";
689 #if defined (SYS_time)
690 syscall_table
[SYS_time
] = "time";
692 #if defined (SYS_mknod)
693 syscall_table
[SYS_mknod
] = "mknod";
695 #if defined (SYS_chmod)
696 syscall_table
[SYS_chmod
] = "chmod";
698 #if defined (SYS_chown)
699 syscall_table
[SYS_chown
] = "chown";
701 #if defined (SYS_brk)
702 syscall_table
[SYS_brk
] = "brk";
704 #if defined (SYS_stat)
705 syscall_table
[SYS_stat
] = "stat";
707 #if defined (SYS_lseek)
708 syscall_table
[SYS_lseek
] = "lseek";
710 #if defined (SYS_getpid)
711 syscall_table
[SYS_getpid
] = "getpid";
713 #if defined (SYS_mount)
714 syscall_table
[SYS_mount
] = "mount";
716 #if defined (SYS_umount)
717 syscall_table
[SYS_umount
] = "umount";
719 #if defined (SYS_setuid)
720 syscall_table
[SYS_setuid
] = "setuid";
722 #if defined (SYS_getuid)
723 syscall_table
[SYS_getuid
] = "getuid";
725 #if defined (SYS_stime)
726 syscall_table
[SYS_stime
] = "stime";
728 #if defined (SYS_ptrace)
729 syscall_table
[SYS_ptrace
] = "ptrace";
731 #if defined (SYS_alarm)
732 syscall_table
[SYS_alarm
] = "alarm";
734 #if defined (SYS_fstat)
735 syscall_table
[SYS_fstat
] = "fstat";
737 #if defined (SYS_pause)
738 syscall_table
[SYS_pause
] = "pause";
740 #if defined (SYS_utime)
741 syscall_table
[SYS_utime
] = "utime";
743 #if defined (SYS_stty)
744 syscall_table
[SYS_stty
] = "stty";
746 #if defined (SYS_gtty)
747 syscall_table
[SYS_gtty
] = "gtty";
749 #if defined (SYS_access)
750 syscall_table
[SYS_access
] = "access";
752 #if defined (SYS_nice)
753 syscall_table
[SYS_nice
] = "nice";
755 #if defined (SYS_statfs)
756 syscall_table
[SYS_statfs
] = "statfs";
758 #if defined (SYS_sync)
759 syscall_table
[SYS_sync
] = "sync";
761 #if defined (SYS_kill)
762 syscall_table
[SYS_kill
] = "kill";
764 #if defined (SYS_fstatfs)
765 syscall_table
[SYS_fstatfs
] = "fstatfs";
767 #if defined (SYS_pgrpsys)
768 syscall_table
[SYS_pgrpsys
] = "pgrpsys";
770 #if defined (SYS_xenix)
771 syscall_table
[SYS_xenix
] = "xenix";
773 #if defined (SYS_dup)
774 syscall_table
[SYS_dup
] = "dup";
776 #if defined (SYS_pipe)
777 syscall_table
[SYS_pipe
] = "pipe";
779 #if defined (SYS_times)
780 syscall_table
[SYS_times
] = "times";
782 #if defined (SYS_profil)
783 syscall_table
[SYS_profil
] = "profil";
785 #if defined (SYS_plock)
786 syscall_table
[SYS_plock
] = "plock";
788 #if defined (SYS_setgid)
789 syscall_table
[SYS_setgid
] = "setgid";
791 #if defined (SYS_getgid)
792 syscall_table
[SYS_getgid
] = "getgid";
794 #if defined (SYS_signal)
795 syscall_table
[SYS_signal
] = "signal";
797 #if defined (SYS_msgsys)
798 syscall_table
[SYS_msgsys
] = "msgsys";
800 #if defined (SYS_sys3b)
801 syscall_table
[SYS_sys3b
] = "sys3b";
803 #if defined (SYS_acct)
804 syscall_table
[SYS_acct
] = "acct";
806 #if defined (SYS_shmsys)
807 syscall_table
[SYS_shmsys
] = "shmsys";
809 #if defined (SYS_semsys)
810 syscall_table
[SYS_semsys
] = "semsys";
812 #if defined (SYS_ioctl)
813 syscall_table
[SYS_ioctl
] = "ioctl";
815 #if defined (SYS_uadmin)
816 syscall_table
[SYS_uadmin
] = "uadmin";
818 #if defined (SYS_utssys)
819 syscall_table
[SYS_utssys
] = "utssys";
821 #if defined (SYS_fsync)
822 syscall_table
[SYS_fsync
] = "fsync";
824 #if defined (SYS_umask)
825 syscall_table
[SYS_umask
] = "umask";
827 #if defined (SYS_chroot)
828 syscall_table
[SYS_chroot
] = "chroot";
830 #if defined (SYS_fcntl)
831 syscall_table
[SYS_fcntl
] = "fcntl";
833 #if defined (SYS_ulimit)
834 syscall_table
[SYS_ulimit
] = "ulimit";
836 #if defined (SYS_rfsys)
837 syscall_table
[SYS_rfsys
] = "rfsys";
839 #if defined (SYS_rmdir)
840 syscall_table
[SYS_rmdir
] = "rmdir";
842 #if defined (SYS_mkdir)
843 syscall_table
[SYS_mkdir
] = "mkdir";
845 #if defined (SYS_getdents)
846 syscall_table
[SYS_getdents
] = "getdents";
848 #if defined (SYS_sysfs)
849 syscall_table
[SYS_sysfs
] = "sysfs";
851 #if defined (SYS_getmsg)
852 syscall_table
[SYS_getmsg
] = "getmsg";
854 #if defined (SYS_putmsg)
855 syscall_table
[SYS_putmsg
] = "putmsg";
857 #if defined (SYS_poll)
858 syscall_table
[SYS_poll
] = "poll";
860 #if defined (SYS_lstat)
861 syscall_table
[SYS_lstat
] = "lstat";
863 #if defined (SYS_symlink)
864 syscall_table
[SYS_symlink
] = "symlink";
866 #if defined (SYS_readlink)
867 syscall_table
[SYS_readlink
] = "readlink";
869 #if defined (SYS_setgroups)
870 syscall_table
[SYS_setgroups
] = "setgroups";
872 #if defined (SYS_getgroups)
873 syscall_table
[SYS_getgroups
] = "getgroups";
875 #if defined (SYS_fchmod)
876 syscall_table
[SYS_fchmod
] = "fchmod";
878 #if defined (SYS_fchown)
879 syscall_table
[SYS_fchown
] = "fchown";
881 #if defined (SYS_sigprocmask)
882 syscall_table
[SYS_sigprocmask
] = "sigprocmask";
884 #if defined (SYS_sigsuspend)
885 syscall_table
[SYS_sigsuspend
] = "sigsuspend";
887 #if defined (SYS_sigaltstack)
888 syscall_table
[SYS_sigaltstack
] = "sigaltstack";
890 #if defined (SYS_sigaction)
891 syscall_table
[SYS_sigaction
] = "sigaction";
893 #if defined (SYS_sigpending)
894 syscall_table
[SYS_sigpending
] = "sigpending";
896 #if defined (SYS_context)
897 syscall_table
[SYS_context
] = "context";
899 #if defined (SYS_evsys)
900 syscall_table
[SYS_evsys
] = "evsys";
902 #if defined (SYS_evtrapret)
903 syscall_table
[SYS_evtrapret
] = "evtrapret";
905 #if defined (SYS_statvfs)
906 syscall_table
[SYS_statvfs
] = "statvfs";
908 #if defined (SYS_fstatvfs)
909 syscall_table
[SYS_fstatvfs
] = "fstatvfs";
911 #if defined (SYS_nfssys)
912 syscall_table
[SYS_nfssys
] = "nfssys";
914 #if defined (SYS_waitsys)
915 syscall_table
[SYS_waitsys
] = "waitsys";
917 #if defined (SYS_sigsendsys)
918 syscall_table
[SYS_sigsendsys
] = "sigsendsys";
920 #if defined (SYS_hrtsys)
921 syscall_table
[SYS_hrtsys
] = "hrtsys";
923 #if defined (SYS_acancel)
924 syscall_table
[SYS_acancel
] = "acancel";
926 #if defined (SYS_async)
927 syscall_table
[SYS_async
] = "async";
929 #if defined (SYS_priocntlsys)
930 syscall_table
[SYS_priocntlsys
] = "priocntlsys";
932 #if defined (SYS_pathconf)
933 syscall_table
[SYS_pathconf
] = "pathconf";
935 #if defined (SYS_mincore)
936 syscall_table
[SYS_mincore
] = "mincore";
938 #if defined (SYS_mmap)
939 syscall_table
[SYS_mmap
] = "mmap";
941 #if defined (SYS_mprotect)
942 syscall_table
[SYS_mprotect
] = "mprotect";
944 #if defined (SYS_munmap)
945 syscall_table
[SYS_munmap
] = "munmap";
947 #if defined (SYS_fpathconf)
948 syscall_table
[SYS_fpathconf
] = "fpathconf";
950 #if defined (SYS_vfork)
951 syscall_table
[SYS_vfork
] = "vfork";
953 #if defined (SYS_fchdir)
954 syscall_table
[SYS_fchdir
] = "fchdir";
956 #if defined (SYS_readv)
957 syscall_table
[SYS_readv
] = "readv";
959 #if defined (SYS_writev)
960 syscall_table
[SYS_writev
] = "writev";
962 #if defined (SYS_xstat)
963 syscall_table
[SYS_xstat
] = "xstat";
965 #if defined (SYS_lxstat)
966 syscall_table
[SYS_lxstat
] = "lxstat";
968 #if defined (SYS_fxstat)
969 syscall_table
[SYS_fxstat
] = "fxstat";
971 #if defined (SYS_xmknod)
972 syscall_table
[SYS_xmknod
] = "xmknod";
974 #if defined (SYS_clocal)
975 syscall_table
[SYS_clocal
] = "clocal";
977 #if defined (SYS_setrlimit)
978 syscall_table
[SYS_setrlimit
] = "setrlimit";
980 #if defined (SYS_getrlimit)
981 syscall_table
[SYS_getrlimit
] = "getrlimit";
983 #if defined (SYS_lchown)
984 syscall_table
[SYS_lchown
] = "lchown";
986 #if defined (SYS_memcntl)
987 syscall_table
[SYS_memcntl
] = "memcntl";
989 #if defined (SYS_getpmsg)
990 syscall_table
[SYS_getpmsg
] = "getpmsg";
992 #if defined (SYS_putpmsg)
993 syscall_table
[SYS_putpmsg
] = "putpmsg";
995 #if defined (SYS_rename)
996 syscall_table
[SYS_rename
] = "rename";
998 #if defined (SYS_uname)
999 syscall_table
[SYS_uname
] = "uname";
1001 #if defined (SYS_setegid)
1002 syscall_table
[SYS_setegid
] = "setegid";
1004 #if defined (SYS_sysconfig)
1005 syscall_table
[SYS_sysconfig
] = "sysconfig";
1007 #if defined (SYS_adjtime)
1008 syscall_table
[SYS_adjtime
] = "adjtime";
1010 #if defined (SYS_systeminfo)
1011 syscall_table
[SYS_systeminfo
] = "systeminfo";
1013 #if defined (SYS_seteuid)
1014 syscall_table
[SYS_seteuid
] = "seteuid";
1022 ptrace -- override library version to force errors for /proc version
1026 int ptrace (int request, int pid, PTRACE_ARG3_TYPE arg3, int arg4)
1030 When gdb is configured to use /proc, it should not be calling
1031 or otherwise attempting to use ptrace. In order to catch errors
1032 where use of /proc is configured, but some routine is still calling
1033 ptrace, we provide a local version of a function with that name
1034 that does nothing but issue an error message.
1038 ptrace (request
, pid
, arg3
, arg4
)
1041 PTRACE_ARG3_TYPE arg3
;
1044 error ("internal error - there is a call to ptrace() somewhere");
1052 procfs_kill_inferior - kill any currently inferior
1056 void procfs_kill_inferior (void)
1060 Kill any current inferior.
1064 Kills even attached inferiors. Presumably the user has already
1065 been prompted that the inferior is an attached one rather than
1066 one started by gdb. (FIXME?)
1071 procfs_kill_inferior ()
1073 if (inferior_pid
!= 0)
1075 unconditionally_kill_inferior ();
1076 target_mourn_inferior ();
1084 unconditionally_kill_inferior - terminate the inferior
1088 static void unconditionally_kill_inferior (void)
1092 Kill the current inferior. Should not be called until it
1093 is at least tested that there is an inferior.
1097 A possibly useful enhancement would be to first try sending
1098 the inferior a terminate signal, politely asking it to commit
1099 suicide, before we murder it.
1104 unconditionally_kill_inferior ()
1109 ioctl (pi
.fd
, PIOCKILL
, &signo
);
1110 close_proc_file (&pi
);
1118 procfs_xfer_memory -- copy data to or from inferior memory space
1122 int procfs_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len,
1123 int dowrite, struct target_ops target)
1127 Copy LEN bytes to/from inferior's memory starting at MEMADDR
1128 from/to debugger memory starting at MYADDR. Copy from inferior
1129 if DOWRITE is zero or to inferior if DOWRITE is nonzero.
1131 Returns the length copied, which is either the LEN argument or
1132 zero. This xfer function does not do partial moves, since procfs_ops
1133 doesn't allow memory operations to cross below us in the target stack
1138 The /proc interface makes this an almost trivial task.
1142 procfs_xfer_memory (memaddr
, myaddr
, len
, dowrite
, target
)
1147 struct target_ops
*target
; /* ignored */
1151 if (lseek (pi
.fd
, (off_t
) memaddr
, 0) == (off_t
) memaddr
)
1155 nbytes
= write (pi
.fd
, myaddr
, len
);
1159 nbytes
= read (pi
.fd
, myaddr
, len
);
1173 procfs_store_registers -- copy register values back to inferior
1177 void procfs_store_registers (int regno)
1181 Store our current register values back into the inferior. If
1182 REGNO is -1 then store all the register, otherwise store just
1183 the value specified by REGNO.
1187 If we are storing only a single register, we first have to get all
1188 the current values from the process, overwrite the desired register
1189 in the gregset with the one we want from gdb's registers, and then
1190 send the whole set back to the process. For writing all the
1191 registers, all we have to do is generate the gregset and send it to
1194 Also note that the process has to be stopped on an event of interest
1195 for this to work, which basically means that it has to have been
1196 run under the control of one of the other /proc ioctl calls and not
1197 ptrace. Since we don't use ptrace anyway, we don't worry about this
1198 fine point, but it is worth noting for future reference.
1200 Gdb is confused about what this function is supposed to return.
1201 Some versions return a value, others return nothing. Some are
1202 declared to return a value and actually return nothing. Gdb ignores
1203 anything returned. (FIXME)
1208 procfs_store_registers (regno
)
1213 ioctl (pi
.fd
, PIOCGREG
, &pi
.gregset
);
1215 fill_gregset (&pi
.gregset
, regno
);
1216 ioctl (pi
.fd
, PIOCSREG
, &pi
.gregset
);
1218 #if defined (FP0_REGNUM)
1220 /* Now repeat everything using the floating point register set, if the
1221 target has floating point hardware. Since we ignore the returned value,
1222 we'll never know whether it worked or not anyway. */
1226 ioctl (pi
.fd
, PIOCGFPREG
, &pi
.fpregset
);
1228 fill_fpregset (&pi
.fpregset
, regno
);
1229 ioctl (pi
.fd
, PIOCSFPREG
, &pi
.fpregset
);
1231 #endif /* FP0_REGNUM */
1239 procfs_init_inferior - initialize access to a /proc entry
1243 void procfs_init_inferior (int pid)
1247 When gdb starts an inferior, this function is called in the parent
1248 process immediately after the fork. It waits for the child to stop
1249 on the return from the exec system call (the child itself takes care
1250 of ensuring that this is set up), then sets up the set of signals
1251 and faults that are to be traced.
1255 If proc_init_failed ever gets called, control returns to the command
1256 processing loop via the standard error handling code.
1261 procfs_init_inferior (pid
)
1265 push_target (&procfs_ops
);
1267 if (!open_proc_file (pid
, &pi
, O_RDWR
))
1269 proc_init_failed ("can't open process file");
1273 memset ((char *) &pi
.prrun
, 0, sizeof (pi
.prrun
));
1274 prfillset (&pi
.prrun
.pr_trace
);
1275 procfs_notice_signals ();
1276 prfillset (&pi
.prrun
.pr_fault
);
1277 prdelset (&pi
.prrun
.pr_fault
, FLTPAGE
);
1278 if (ioctl (pi
.fd
, PIOCWSTOP
, &pi
.prstatus
) < 0)
1280 proc_init_failed ("PIOCWSTOP failed");
1282 else if (ioctl (pi
.fd
, PIOCSFAULT
, &pi
.prrun
.pr_fault
) < 0)
1284 proc_init_failed ("PIOCSFAULT failed");
1293 procfs_notice_signals
1297 static void procfs_notice_signals (void);
1301 When the user changes the state of gdb's signal handling via the
1302 "handle" command, this function gets called to see if any change
1303 in the /proc interface is required. It is also called internally
1304 by other /proc interface functions to initialize the state of
1305 the traced signal set.
1307 One thing it does is that signals for which the state is "nostop",
1308 "noprint", and "pass", have their trace bits reset in the pr_trace
1309 field, so that they are no longer traced. This allows them to be
1310 delivered directly to the inferior without the debugger ever being
1315 procfs_notice_signals ()
1321 for (signo
= 0; signo
< NSIG
; signo
++)
1323 if (signal_stop_state (signo
) == 0 &&
1324 signal_print_state (signo
) == 0 &&
1325 signal_pass_state (signo
) == 1)
1327 prdelset (&pi
.prrun
.pr_trace
, signo
);
1331 praddset (&pi
.prrun
.pr_trace
, signo
);
1334 if (ioctl (pi
.fd
, PIOCSTRACE
, &pi
.prrun
.pr_trace
))
1336 print_sys_errmsg ("PIOCSTRACE failed", errno
);
1345 proc_set_exec_trap -- arrange for exec'd child to halt at startup
1349 void proc_set_exec_trap (void)
1353 This function is called in the child process when starting up
1354 an inferior, prior to doing the exec of the actual inferior.
1355 It sets the child process's exitset to make exit from the exec
1356 system call an event of interest to stop on, and then simply
1357 returns. The child does the exec, the system call returns, and
1358 the child stops at the first instruction, ready for the gdb
1359 parent process to take control of it.
1363 We need to use all local variables since the child may be sharing
1364 it's data space with the parent, if vfork was used rather than
1367 Also note that we want to turn off the inherit-on-fork flag in
1368 the child process so that any grand-children start with all
1369 tracing flags cleared.
1373 proc_set_exec_trap ()
1376 auto char procname
[32];
1379 sprintf (procname
, PROC_NAME_FMT
, getpid ());
1380 if ((fd
= open (procname
, O_RDWR
)) < 0)
1386 premptyset (&exitset
);
1389 Not all systems with /proc have all the exec* syscalls with the same
1390 names. On the SGI, for example, there is no SYS_exec, but there
1391 *is* a SYS_execv. So, we try to account for that. */
1394 praddset (&exitset
, SYS_exec
);
1397 praddset (&exitset
, SYS_execve
);
1400 praddset(&exitset
, SYS_execv
);
1403 if (ioctl (fd
, PIOCSEXIT
, &exitset
) < 0)
1410 /* Turn off inherit-on-fork flag so that all grand-children of gdb
1411 start with tracing flags cleared. */
1413 #if defined (PIOCRESET) /* New method */
1417 ioctl (fd
, PIOCRESET
, &pr_flags
);
1420 #if defined (PIOCRFORK) /* Original method */
1421 ioctl (fd
, PIOCRFORK
, NULL
);
1425 /* Turn on run-on-last-close flag so that this process will not hang
1426 if GDB goes away for some reason. */
1428 #if defined (PIOCSET) /* New method */
1432 (void) ioctl (fd
, PIOCSET
, &pr_flags
);
1435 #if defined (PIOCSRLC) /* Original method */
1436 (void) ioctl (fd
, PIOCSRLC
, 0);
1445 proc_iterate_over_mappings -- call function for every mapped space
1449 int proc_iterate_over_mappings (int (*func)())
1453 Given a pointer to a function, call that function for every
1454 mapped address space, passing it an open file descriptor for
1455 the file corresponding to that mapped address space (if any)
1456 and the base address of the mapped space. Quit when we hit
1457 the end of the mappings or the function returns nonzero.
1461 proc_iterate_over_mappings (func
)
1462 int (*func
) PARAMS ((int, CORE_ADDR
));
1467 struct prmap
*prmaps
;
1468 struct prmap
*prmap
;
1470 if (pi
.valid
&& (ioctl (pi
.fd
, PIOCNMAP
, &nmap
) == 0))
1472 prmaps
= (struct prmap
*) alloca ((nmap
+ 1) * sizeof (*prmaps
));
1473 if (ioctl (pi
.fd
, PIOCMAP
, prmaps
) == 0)
1475 for (prmap
= prmaps
; prmap
-> pr_size
&& funcstat
== 0; ++prmap
)
1477 fd
= proc_address_to_fd ((CORE_ADDR
) prmap
-> pr_vaddr
, 0);
1478 funcstat
= (*func
) (fd
, (CORE_ADDR
) prmap
-> pr_vaddr
);
1486 #if 0 /* Currently unused */
1491 proc_base_address -- find base address for segment containing address
1495 CORE_ADDR proc_base_address (CORE_ADDR addr)
1499 Given an address of a location in the inferior, find and return
1500 the base address of the mapped segment containing that address.
1502 This is used for example, by the shared library support code,
1503 where we have the pc value for some location in the shared library
1504 where we are stopped, and need to know the base address of the
1505 segment containing that address.
1509 proc_base_address (addr
)
1513 struct prmap
*prmaps
;
1514 struct prmap
*prmap
;
1515 CORE_ADDR baseaddr
= 0;
1517 if (pi
.valid
&& (ioctl (pi
.fd
, PIOCNMAP
, &nmap
) == 0))
1519 prmaps
= (struct prmap
*) alloca ((nmap
+ 1) * sizeof (*prmaps
));
1520 if (ioctl (pi
.fd
, PIOCMAP
, prmaps
) == 0)
1522 for (prmap
= prmaps
; prmap
-> pr_size
; ++prmap
)
1524 if ((prmap
-> pr_vaddr
<= (caddr_t
) addr
) &&
1525 (prmap
-> pr_vaddr
+ prmap
-> pr_size
> (caddr_t
) addr
))
1527 baseaddr
= (CORE_ADDR
) prmap
-> pr_vaddr
;
1542 proc_address_to_fd -- return open fd for file mapped to address
1546 int proc_address_to_fd (CORE_ADDR addr, complain)
1550 Given an address in the current inferior's address space, use the
1551 /proc interface to find an open file descriptor for the file that
1552 this address was mapped in from. Return -1 if there is no current
1553 inferior. Print a warning message if there is an inferior but
1554 the address corresponds to no file (IE a bogus address).
1559 proc_address_to_fd (addr
, complain
)
1567 if ((fd
= ioctl (pi
.fd
, PIOCOPENM
, (caddr_t
*) &addr
)) < 0)
1571 print_sys_errmsg (pi
.pathname
, errno
);
1572 warning ("can't find mapped file for address 0x%x", addr
);
1580 /* Attach to process PID, then initialize for debugging it
1581 and wait for the trace-trap that results from attaching. */
1584 procfs_attach (args
, from_tty
)
1592 error_no_arg ("process-id to attach");
1596 if (pid
== getpid()) /* Trying to masturbate? */
1597 error ("I refuse to debug myself!");
1601 exec_file
= (char *) get_exec_file (0);
1604 printf ("Attaching program `%s', pid %d\n", exec_file
, pid
);
1606 printf ("Attaching pid %d\n", pid
);
1613 push_target (&procfs_ops
);
1617 /* Take a program previously attached to and detaches it.
1618 The program resumes execution and will no longer stop
1619 on signals, etc. We'd better not have left any breakpoints
1620 in the program or it'll die when it hits one. For this
1621 to work, it may be necessary for the process to have been
1622 previously attached. It *might* work if the program was
1623 started via the normal ptrace (PTRACE_TRACEME). */
1626 procfs_detach (args
, from_tty
)
1634 char *exec_file
= get_exec_file (0);
1637 printf ("Detaching program: %s pid %d\n",
1638 exec_file
, inferior_pid
);
1642 siggnal
= atoi (args
);
1644 do_detach (siggnal
);
1646 unpush_target (&procfs_ops
); /* Pop out of handling an inferior */
1649 /* Get ready to modify the registers array. On machines which store
1650 individual registers, this doesn't need to do anything. On machines
1651 which store all the registers in one fell swoop, this makes sure
1652 that registers contains all the registers from the program being
1656 procfs_prepare_to_store ()
1658 #ifdef CHILD_PREPARE_TO_STORE
1659 CHILD_PREPARE_TO_STORE ();
1663 /* Print status information about what we're accessing. */
1666 procfs_files_info (ignore
)
1667 struct target_ops
*ignore
;
1669 printf ("\tUsing the running image of %s process %d via /proc.\n",
1670 attach_flag
? "attached": "child", inferior_pid
);
1675 procfs_open (arg
, from_tty
)
1679 error ("Use the \"run\" command to start a Unix child process.");
1686 do_attach -- attach to an already existing process
1690 int do_attach (int pid)
1694 Attach to an already existing process with the specified process
1695 id. If the process is not already stopped, query whether to
1700 The option of stopping at attach time is specific to the /proc
1701 versions of gdb. Versions using ptrace force the attachee
1702 to stop. (I have changed this version to do so, too. All you
1703 have to do is "continue" to make it go on. -- gnu@cygnus.com)
1713 if (!open_proc_file (pid
, &pi
, O_RDWR
))
1715 perror_with_name (pi
.pathname
);
1719 /* Get current status of process and if it is not already stopped,
1720 then stop it. Remember whether or not it was stopped when we first
1723 if (ioctl (pi
.fd
, PIOCSTATUS
, &pi
.prstatus
) < 0)
1725 print_sys_errmsg (pi
.pathname
, errno
);
1726 close_proc_file (&pi
);
1727 error ("PIOCSTATUS failed");
1729 if (pi
.prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
))
1736 if (1 || query ("Process is currently running, stop it? "))
1738 /* Make it run again when we close it. */
1739 #if defined (PIOCSET) /* New method */
1743 result
= ioctl (pi
.fd
, PIOCSET
, &pr_flags
);
1746 #if defined (PIOCSRLC) /* Original method */
1747 result
= ioctl (pi
.fd
, PIOCSRLC
, 0);
1752 print_sys_errmsg (pi
.pathname
, errno
);
1753 close_proc_file (&pi
);
1754 error ("PIOCSRLC or PIOCSET failed");
1756 if (ioctl (pi
.fd
, PIOCSTOP
, &pi
.prstatus
) < 0)
1758 print_sys_errmsg (pi
.pathname
, errno
);
1759 close_proc_file (&pi
);
1760 error ("PIOCSTOP failed");
1762 pi
.nopass_next_sigstop
= 1;
1766 printf ("Ok, gdb will wait for process %u to stop.\n", pid
);
1770 /* Remember some things about the inferior that we will, or might, change
1771 so that we can restore them when we detach. */
1773 ioctl (pi
.fd
, PIOCGTRACE
, &pi
.saved_trace
);
1774 ioctl (pi
.fd
, PIOCGHOLD
, &pi
.saved_sighold
);
1775 ioctl (pi
.fd
, PIOCGFAULT
, &pi
.saved_fltset
);
1776 ioctl (pi
.fd
, PIOCGENTRY
, &pi
.saved_entryset
);
1777 ioctl (pi
.fd
, PIOCGEXIT
, &pi
.saved_exitset
);
1779 /* Set up trace and fault sets, as gdb expects them. */
1781 memset (&pi
.prrun
, 0, sizeof (pi
.prrun
));
1782 prfillset (&pi
.prrun
.pr_trace
);
1783 procfs_notice_signals ();
1784 prfillset (&pi
.prrun
.pr_fault
);
1785 prdelset (&pi
.prrun
.pr_fault
, FLTPAGE
);
1786 if (ioctl (pi
.fd
, PIOCSFAULT
, &pi
.prrun
.pr_fault
))
1788 print_sys_errmsg ("PIOCSFAULT failed", errno
);
1790 if (ioctl (pi
.fd
, PIOCSTRACE
, &pi
.prrun
.pr_trace
))
1792 print_sys_errmsg ("PIOCSTRACE failed", errno
);
1802 do_detach -- detach from an attached-to process
1806 void do_detach (int signal)
1810 Detach from the current attachee.
1812 If signal is non-zero, the attachee is started running again and sent
1813 the specified signal.
1815 If signal is zero and the attachee was not already stopped when we
1816 attached to it, then we make it runnable again when we detach.
1818 Otherwise, we query whether or not to make the attachee runnable
1819 again, since we may simply want to leave it in the state it was in
1822 We report any problems, but do not consider them errors, since we
1823 MUST detach even if some things don't seem to go right. This may not
1824 be the ideal situation. (FIXME).
1835 set_proc_siginfo (&pi
, signal
);
1837 if (ioctl (pi
.fd
, PIOCSEXIT
, &pi
.saved_exitset
) < 0)
1839 print_sys_errmsg (pi
.pathname
, errno
);
1840 printf ("PIOCSEXIT failed.\n");
1842 if (ioctl (pi
.fd
, PIOCSENTRY
, &pi
.saved_entryset
) < 0)
1844 print_sys_errmsg (pi
.pathname
, errno
);
1845 printf ("PIOCSENTRY failed.\n");
1847 if (ioctl (pi
.fd
, PIOCSTRACE
, &pi
.saved_trace
) < 0)
1849 print_sys_errmsg (pi
.pathname
, errno
);
1850 printf ("PIOCSTRACE failed.\n");
1852 if (ioctl (pi
.fd
, PIOCSHOLD
, &pi
.saved_sighold
) < 0)
1854 print_sys_errmsg (pi
.pathname
, errno
);
1855 printf ("PIOSCHOLD failed.\n");
1857 if (ioctl (pi
.fd
, PIOCSFAULT
, &pi
.saved_fltset
) < 0)
1859 print_sys_errmsg (pi
.pathname
, errno
);
1860 printf ("PIOCSFAULT failed.\n");
1862 if (ioctl (pi
.fd
, PIOCSTATUS
, &pi
.prstatus
) < 0)
1864 print_sys_errmsg (pi
.pathname
, errno
);
1865 printf ("PIOCSTATUS failed.\n");
1869 if (signal
|| (pi
.prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
)))
1871 if (signal
|| !pi
.was_stopped
||
1872 query ("Was stopped when attached, make it runnable again? "))
1874 /* Clear any fault that might have stopped it. */
1875 if (ioctl (pi
.fd
, PIOCCFAULT
, 0))
1877 print_sys_errmsg (pi
.pathname
, errno
);
1878 printf ("PIOCCFAULT failed.\n");
1881 /* Make it run again when we close it. */
1882 #if defined (PIOCSET) /* New method */
1886 result
= ioctl (pi
.fd
, PIOCSET
, &pr_flags
);
1889 #if defined (PIOCSRLC) /* Original method */
1890 result
= ioctl (pi
.fd
, PIOCSRLC
, 0);
1895 print_sys_errmsg (pi
.pathname
, errno
);
1896 printf ("PIOCSRLC or PIOCSET failed.\n");
1901 close_proc_file (&pi
);
1909 procfs_wait -- emulate wait() as much as possible
1910 Wait for child to do something. Return pid of child, or -1 in case
1911 of error; store status through argument pointer STATUS.
1916 int procfs_wait (int *statloc)
1920 Try to emulate wait() as much as possible. Not sure why we can't
1921 just use wait(), but it seems to have problems when applied to a
1922 process being controlled with the /proc interface.
1926 We have a race problem here with no obvious solution. We need to let
1927 the inferior run until it stops on an event of interest, which means
1928 that we need to use the PIOCWSTOP ioctl. However, we cannot use this
1929 ioctl if the process is already stopped on something that is not an
1930 event of interest, or the call will hang indefinitely. Thus we first
1931 use PIOCSTATUS to see if the process is not stopped. If not, then we
1932 use PIOCWSTOP. But during the window between the two, if the process
1933 stops for any reason that is not an event of interest (such as a job
1934 control signal) then gdb will hang. One possible workaround is to set
1935 an alarm to wake up every minute of so and check to see if the process
1936 is still running, and if so, then reissue the PIOCWSTOP. But this is
1937 a real kludge, so has not been implemented. FIXME: investigate
1940 FIXME: Investigate why wait() seems to have problems with programs
1941 being control by /proc routines.
1946 procfs_wait (statloc
)
1955 if (ioctl (pi
.fd
, PIOCSTATUS
, &pi
.prstatus
) < 0)
1959 else if (!(pi
.prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
)))
1961 if (ioctl (pi
.fd
, PIOCWSTOP
, &pi
.prstatus
) < 0)
1968 if (errno
== ENOENT
)
1970 rtnval
= wait (&statval
);
1971 if (rtnval
!= inferior_pid
)
1973 print_sys_errmsg (pi
.pathname
, errno
);
1974 error ("PIOCWSTOP, wait failed, returned %d", rtnval
);
1980 print_sys_errmsg (pi
.pathname
, errno
);
1981 error ("PIOCSTATUS or PIOCWSTOP failed.");
1985 else if (pi
.prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
))
1987 rtnval
= pi
.prstatus
.pr_pid
;
1988 why
= pi
.prstatus
.pr_why
;
1989 what
= pi
.prstatus
.pr_what
;
1990 if (why
== PR_SIGNALLED
)
1992 statval
= (what
<< 8) | 0177;
1994 else if ((why
== PR_SYSEXIT
)
2003 || what
== SYS_execve
2006 || what
== SYS_execv
2010 statval
= (SIGTRAP
<< 8) | 0177;
2012 else if (why
== PR_REQUESTED
)
2014 statval
= (SIGSTOP
<< 8) | 0177;
2016 else if (why
== PR_JOBCONTROL
)
2018 statval
= (what
<< 8) | 0177;
2020 else if (why
== PR_FAULTED
)
2026 statval
= (SIGILL
<< 8) | 0177;
2030 statval
= (SIGTRAP
<< 8) | 0177;
2035 statval
= (SIGSEGV
<< 8) | 0177;
2040 statval
= (SIGFPE
<< 8) | 0177;
2042 case FLTPAGE
: /* Recoverable page fault */
2045 error ("PIOCWSTOP, unknown why %d, what %d", why
, what
);
2052 error ("PIOCWSTOP, unknown why %d, what %d", why
, what
);
2058 error ("PIOCWSTOP, stopped for unknown/unhandled reason, flags %#x",
2059 pi
.prstatus
.pr_flags
);
2068 if (rtnval
== -1) /* No more children to wait for */
2070 fprintf (stderr
, "Child process unexpectedly missing.\n");
2071 *statloc
= 42; /* Claim it exited with signal 42 */
2082 set_proc_siginfo - set a process's current signal info
2086 void set_proc_siginfo (struct procinfo *pip, int signo);
2090 Given a pointer to a process info struct in PIP and a signal number
2091 in SIGNO, set the process's current signal and its associated signal
2092 information. The signal will be delivered to the process immediately
2093 after execution is resumed, even if it is being held. In addition,
2094 this particular delivery will not cause another PR_SIGNALLED stop
2095 even if the signal is being traced.
2097 If we are not delivering the same signal that the prstatus siginfo
2098 struct contains information about, then synthesize a siginfo struct
2099 to match the signal we are doing to deliver, make it of the type
2100 "generated by a user process", and send this synthesized copy. When
2101 used to set the inferior's signal state, this will be required if we
2102 are not currently stopped because of a traced signal, or if we decide
2103 to continue with a different signal.
2105 Note that when continuing the inferior from a stop due to receipt
2106 of a traced signal, we either have set PRCSIG to clear the existing
2107 signal, or we have to call this function to do a PIOCSSIG with either
2108 the existing siginfo struct from pr_info, or one we have synthesized
2109 appropriately for the signal we want to deliver. Otherwise if the
2110 signal is still being traced, the inferior will immediately stop
2113 See siginfo(5) for more details.
2117 set_proc_siginfo (pip
, signo
)
2118 struct procinfo
*pip
;
2121 struct siginfo newsiginfo
;
2122 struct siginfo
*sip
;
2126 if (signo
== pip
-> prstatus
.pr_info
.si_signo
)
2128 sip
= &pip
-> prstatus
.pr_info
;
2132 memset ((char *) &newsiginfo
, 0, sizeof (newsiginfo
));
2134 sip
-> si_signo
= signo
;
2136 sip
-> si_errno
= 0;
2137 sip
-> si_pid
= getpid ();
2138 sip
-> si_uid
= getuid ();
2140 if (ioctl (pip
-> fd
, PIOCSSIG
, sip
) < 0)
2142 print_sys_errmsg (pip
-> pathname
, errno
);
2143 warning ("PIOCSSIG failed");
2152 procfs_resume -- resume execution of the inferior process
2156 void procfs_resume (int step, int signo)
2160 Resume execution of the inferior process. If STEP is nozero, then
2161 just single step it. If SIGNAL is nonzero, restart it with that
2166 It may not be absolutely necessary to specify the PC value for
2167 restarting, but to be safe we use the value that gdb considers
2168 to be current. One case where this might be necessary is if the
2169 user explicitly changes the PC value that gdb considers to be
2170 current. FIXME: Investigate if this is necessary or not.
2172 When attaching to a child process, if we forced it to stop with
2173 a PIOCSTOP, then we will have set the nopass_next_sigstop flag.
2174 Upon resuming the first time after such a stop, we explicitly
2175 inhibit sending it another SIGSTOP, which would be the normal
2176 result of default signal handling. One potential drawback to
2177 this is that we will also ignore any attempt to by the user
2178 to explicitly continue after the attach with a SIGSTOP. Ultimately
2179 this problem should be dealt with by making the routines that
2180 deal with the inferior a little smarter, and possibly even allow
2181 an inferior to continue running at the same time as gdb. (FIXME?)
2185 procfs_resume (step
, signo
)
2190 pi
.prrun
.pr_flags
= PRSTRACE
| PRSFAULT
| PRCFAULT
;
2192 #ifdef PRSVADDR_BROKEN
2193 /* Can't do this under Solaris running on a Sparc, as there seems to be no
2194 place to put nPC. In fact, if you use this, nPC seems to be set to some
2195 random garbage. We have to rely on the fact that PC and nPC have been
2196 written previously via PIOCSREG during a register flush. */
2198 pi
.prrun
.pr_vaddr
= (caddr_t
) *(int *) ®isters
[REGISTER_BYTE (PC_REGNUM
)];
2199 pi
.prrun
.pr_flags
!= PRSVADDR
;
2202 if (signo
&& !(signo
== SIGSTOP
&& pi
.nopass_next_sigstop
))
2204 set_proc_siginfo (&pi
, signo
);
2208 pi
.prrun
.pr_flags
|= PRCSIG
;
2210 pi
.nopass_next_sigstop
= 0;
2213 pi
.prrun
.pr_flags
|= PRSTEP
;
2215 if (ioctl (pi
.fd
, PIOCRUN
, &pi
.prrun
) != 0)
2217 perror_with_name (pi
.pathname
);
2226 procfs_fetch_registers -- fetch current registers from inferior
2230 void procfs_fetch_registers (int regno)
2234 Read the current values of the inferior's registers, both the
2235 general register set and floating point registers (if supported)
2236 and update gdb's idea of their current values.
2241 procfs_fetch_registers (regno
)
2244 if (ioctl (pi
.fd
, PIOCGREG
, &pi
.gregset
) != -1)
2246 supply_gregset (&pi
.gregset
);
2248 #if defined (FP0_REGNUM)
2249 if (ioctl (pi
.fd
, PIOCGFPREG
, &pi
.fpregset
) != -1)
2251 supply_fpregset (&pi
.fpregset
);
2260 fetch_core_registers -- fetch current registers from core file data
2264 void fetch_core_registers (char *core_reg_sect, unsigned core_reg_size,
2265 int which, unsigned in reg_addr)
2269 Read the values of either the general register set (WHICH equals 0)
2270 or the floating point register set (WHICH equals 2) from the core
2271 file data (pointed to by CORE_REG_SECT), and update gdb's idea of
2272 their current values. The CORE_REG_SIZE parameter is ignored.
2276 Use the indicated sizes to validate the gregset and fpregset
2281 fetch_core_registers (core_reg_sect
, core_reg_size
, which
, reg_addr
)
2282 char *core_reg_sect
;
2283 unsigned core_reg_size
;
2285 unsigned int reg_addr
; /* Unused in this version */
2290 if (core_reg_size
!= sizeof (pi
.gregset
))
2292 warning ("wrong size gregset struct in core file");
2296 memcpy ((char *) &pi
.gregset
, core_reg_sect
, sizeof (pi
.gregset
));
2297 supply_gregset (&pi
.gregset
);
2300 else if (which
== 2)
2302 if (core_reg_size
!= sizeof (pi
.fpregset
))
2304 warning ("wrong size fpregset struct in core file");
2308 memcpy ((char *) &pi
.fpregset
, core_reg_sect
, sizeof (pi
.fpregset
));
2309 #if defined (FP0_REGNUM)
2310 supply_fpregset (&pi
.fpregset
);
2320 proc_init_failed - called whenever /proc access initialization fails
2324 static void proc_init_failed (char *why)
2328 This function is called whenever initialization of access to a /proc
2329 entry fails. It prints a suitable error message, does some cleanup,
2330 and then invokes the standard error processing routine which dumps
2331 us back into the command loop.
2335 proc_init_failed (why
)
2338 print_sys_errmsg (pi
.pathname
, errno
);
2339 kill (pi
.pid
, SIGKILL
);
2340 close_proc_file (&pi
);
2349 close_proc_file - close any currently open /proc entry
2353 static void close_proc_file (struct procinfo *pip)
2357 Close any currently open /proc entry and mark the process information
2358 entry as invalid. In order to ensure that we don't try to reuse any
2359 stale information, the pid, fd, and pathnames are explicitly
2360 invalidated, which may be overkill.
2365 close_proc_file (pip
)
2366 struct procinfo
*pip
;
2374 if (pip
-> pathname
)
2376 free (pip
-> pathname
);
2377 pip
-> pathname
= NULL
;
2386 open_proc_file - open a /proc entry for a given process id
2390 static int open_proc_file (int pid, struct procinfo *pip, int mode)
2394 Given a process id and a mode, close the existing open /proc
2395 entry (if any) and open one for the new process id, in the
2396 specified mode. Once it is open, then mark the local process
2397 information structure as valid, which guarantees that the pid,
2398 fd, and pathname fields match an open /proc entry. Returns
2399 zero if the open fails, nonzero otherwise.
2401 Note that the pathname is left intact, even when the open fails,
2402 so that callers can use it to construct meaningful error messages
2403 rather than just "file open failed".
2407 open_proc_file (pid
, pip
, mode
)
2409 struct procinfo
*pip
;
2412 pip
-> valid
= 0; /* FIXME, what is this? ?! */
2417 if (pip
-> pathname
== NULL
)
2419 pip
-> pathname
= xmalloc (32);
2421 sprintf (pip
-> pathname
, PROC_NAME_FMT
, pid
);
2422 if ((pip
-> fd
= open (pip
-> pathname
, mode
)) >= 0)
2427 return (pip
-> valid
);
2431 mappingflags (flags
)
2434 static char asciiflags
[8];
2436 strcpy (asciiflags
, "-------");
2437 #if defined (MA_PHYS)
2438 if (flags
& MA_PHYS
) asciiflags
[0] = 'd';
2440 if (flags
& MA_STACK
) asciiflags
[1] = 's';
2441 if (flags
& MA_BREAK
) asciiflags
[2] = 'b';
2442 if (flags
& MA_SHARED
) asciiflags
[3] = 's';
2443 if (flags
& MA_READ
) asciiflags
[4] = 'r';
2444 if (flags
& MA_WRITE
) asciiflags
[5] = 'w';
2445 if (flags
& MA_EXEC
) asciiflags
[6] = 'x';
2446 return (asciiflags
);
2450 info_proc_flags (pip
, summary
)
2451 struct procinfo
*pip
;
2454 struct trans
*transp
;
2456 printf_filtered ("%-32s", "Process status flags:");
2459 printf_filtered ("\n\n");
2461 for (transp
= pr_flag_table
; transp
-> name
!= NULL
; transp
++)
2463 if (pip
-> prstatus
.pr_flags
& transp
-> value
)
2467 printf_filtered ("%s ", transp
-> name
);
2471 printf_filtered ("\t%-16s %s.\n", transp
-> name
, transp
-> desc
);
2475 printf_filtered ("\n");
2479 info_proc_stop (pip
, summary
)
2480 struct procinfo
*pip
;
2483 struct trans
*transp
;
2487 why
= pip
-> prstatus
.pr_why
;
2488 what
= pip
-> prstatus
.pr_what
;
2490 if (pip
-> prstatus
.pr_flags
& PR_STOPPED
)
2492 printf_filtered ("%-32s", "Reason for stopping:");
2495 printf_filtered ("\n\n");
2497 for (transp
= pr_why_table
; transp
-> name
!= NULL
; transp
++)
2499 if (why
== transp
-> value
)
2503 printf_filtered ("%s ", transp
-> name
);
2507 printf_filtered ("\t%-16s %s.\n",
2508 transp
-> name
, transp
-> desc
);
2514 /* Use the pr_why field to determine what the pr_what field means, and
2515 print more information. */
2520 /* pr_what is unused for this case */
2526 printf_filtered ("%s ", signalname (what
));
2530 printf_filtered ("\t%-16s %s.\n", signalname (what
),
2531 safe_strsignal (what
));
2537 printf_filtered ("%s ", syscallname (what
));
2541 printf_filtered ("\t%-16s %s.\n", syscallname (what
),
2542 "Entered this system call");
2548 printf_filtered ("%s ", syscallname (what
));
2552 printf_filtered ("\t%-16s %s.\n", syscallname (what
),
2553 "Returned from this system call");
2559 printf_filtered ("%s ",
2560 lookupname (faults_table
, what
, "fault"));
2564 printf_filtered ("\t%-16s %s.\n",
2565 lookupname (faults_table
, what
, "fault"),
2566 lookupdesc (faults_table
, what
));
2570 printf_filtered ("\n");
2575 info_proc_siginfo (pip
, summary
)
2576 struct procinfo
*pip
;
2579 struct siginfo
*sip
;
2581 if ((pip
-> prstatus
.pr_flags
& PR_STOPPED
) &&
2582 (pip
-> prstatus
.pr_why
== PR_SIGNALLED
||
2583 pip
-> prstatus
.pr_why
== PR_FAULTED
))
2585 printf_filtered ("%-32s", "Additional signal/fault info:");
2586 sip
= &pip
-> prstatus
.pr_info
;
2589 printf_filtered ("%s ", signalname (sip
-> si_signo
));
2590 if (sip
-> si_errno
> 0)
2592 printf_filtered ("%s ", errnoname (sip
-> si_errno
));
2594 if (sip
-> si_code
<= 0)
2596 printf_filtered ("sent by pid %d, uid %d ", sip
-> si_pid
,
2601 printf_filtered ("%s ", sigcodename (sip
));
2602 if ((sip
-> si_signo
== SIGILL
) ||
2603 (sip
-> si_signo
== SIGFPE
) ||
2604 (sip
-> si_signo
== SIGSEGV
) ||
2605 (sip
-> si_signo
== SIGBUS
))
2607 printf_filtered ("addr=%#x ", sip
-> si_addr
);
2609 else if ((sip
-> si_signo
== SIGCHLD
))
2611 printf_filtered ("child pid %u, status %u ",
2615 else if ((sip
-> si_signo
== SIGPOLL
))
2617 printf_filtered ("band %u ", sip
-> si_band
);
2623 printf_filtered ("\n\n");
2624 printf_filtered ("\t%-16s %s.\n", signalname (sip
-> si_signo
),
2625 safe_strsignal (sip
-> si_signo
));
2626 if (sip
-> si_errno
> 0)
2628 printf_filtered ("\t%-16s %s.\n",
2629 errnoname (sip
-> si_errno
),
2630 safe_strerror (sip
-> si_errno
));
2632 if (sip
-> si_code
<= 0)
2634 printf_filtered ("\t%-16u %s\n", sip
-> si_pid
,
2635 "PID of process sending signal");
2636 printf_filtered ("\t%-16u %s\n", sip
-> si_uid
,
2637 "UID of process sending signal");
2641 printf_filtered ("\t%-16s %s.\n", sigcodename (sip
),
2643 if ((sip
-> si_signo
== SIGILL
) ||
2644 (sip
-> si_signo
== SIGFPE
))
2646 printf_filtered ("\t%-16#x %s.\n", sip
-> si_addr
,
2647 "Address of faulting instruction");
2649 else if ((sip
-> si_signo
== SIGSEGV
) ||
2650 (sip
-> si_signo
== SIGBUS
))
2652 printf_filtered ("\t%-16#x %s.\n", sip
-> si_addr
,
2653 "Address of faulting memory reference");
2655 else if ((sip
-> si_signo
== SIGCHLD
))
2657 printf_filtered ("\t%-16u %s.\n", sip
-> si_pid
,
2658 "Child process ID");
2659 printf_filtered ("\t%-16u %s.\n", sip
-> si_status
,
2660 "Child process exit value or signal");
2662 else if ((sip
-> si_signo
== SIGPOLL
))
2664 printf_filtered ("\t%-16u %s.\n", sip
-> si_band
,
2665 "Band event for POLL_{IN,OUT,MSG}");
2669 printf_filtered ("\n");
2674 info_proc_syscalls (pip
, summary
)
2675 struct procinfo
*pip
;
2683 #if 0 /* FIXME: Needs to use gdb-wide configured info about system calls. */
2684 if (pip
-> prstatus
.pr_flags
& PR_ASLEEP
)
2686 int syscallnum
= pip
-> prstatus
.pr_reg
[R_D0
];
2689 printf_filtered ("%-32s", "Sleeping in system call:");
2690 printf_filtered ("%s", syscallname (syscallnum
));
2694 printf_filtered ("Sleeping in system call '%s'.\n",
2695 syscallname (syscallnum
));
2700 if (ioctl (pip
-> fd
, PIOCGENTRY
, &pip
-> entryset
) < 0)
2702 print_sys_errmsg (pip
-> pathname
, errno
);
2703 error ("PIOCGENTRY failed");
2706 if (ioctl (pip
-> fd
, PIOCGEXIT
, &pip
-> exitset
) < 0)
2708 print_sys_errmsg (pip
-> pathname
, errno
);
2709 error ("PIOCGEXIT failed");
2712 printf_filtered ("System call tracing information:\n\n");
2714 printf_filtered ("\t%-12s %-8s %-8s\n",
2718 for (syscallnum
= 0; syscallnum
< MAX_SYSCALLS
; syscallnum
++)
2721 if (syscall_table
[syscallnum
] != NULL
)
2723 printf_filtered ("\t%-12s ", syscall_table
[syscallnum
]);
2724 printf_filtered ("%-8s ",
2725 prismember (&pip
-> entryset
, syscallnum
)
2727 printf_filtered ("%-8s ",
2728 prismember (&pip
-> exitset
, syscallnum
)
2730 printf_filtered ("\n");
2733 printf_filtered ("\n");
2742 static char locbuf
[32];
2744 name
= strsigno (signo
);
2747 sprintf (locbuf
, "Signal %d", signo
);
2751 sprintf (locbuf
, "%s (%d)", name
, signo
);
2761 static char locbuf
[32];
2763 name
= strerrno (errnum
);
2766 sprintf (locbuf
, "Errno %d", errnum
);
2770 sprintf (locbuf
, "%s (%d)", name
, errnum
);
2776 info_proc_signals (pip
, summary
)
2777 struct procinfo
*pip
;
2784 if (ioctl (pip
-> fd
, PIOCGTRACE
, &pip
-> trace
) < 0)
2786 print_sys_errmsg (pip
-> pathname
, errno
);
2787 error ("PIOCGTRACE failed");
2790 printf_filtered ("Disposition of signals:\n\n");
2791 printf_filtered ("\t%-15s %-8s %-8s %-8s %s\n\n",
2792 "Signal", "Trace", "Hold", "Pending", "Description");
2793 for (signo
= 0; signo
< NSIG
; signo
++)
2796 printf_filtered ("\t%-15s ", signalname (signo
));
2797 printf_filtered ("%-8s ",
2798 prismember (&pip
-> trace
, signo
)
2800 printf_filtered ("%-8s ",
2801 prismember (&pip
-> prstatus
.pr_sighold
, signo
)
2803 printf_filtered ("%-8s ",
2804 prismember (&pip
-> prstatus
.pr_sigpend
, signo
)
2806 printf_filtered (" %s\n", safe_strsignal (signo
));
2808 printf_filtered ("\n");
2813 info_proc_faults (pip
, summary
)
2814 struct procinfo
*pip
;
2817 struct trans
*transp
;
2821 if (ioctl (pip
-> fd
, PIOCGFAULT
, &pip
-> fltset
) < 0)
2823 print_sys_errmsg (pip
-> pathname
, errno
);
2824 error ("PIOCGFAULT failed");
2827 printf_filtered ("Current traced hardware fault set:\n\n");
2828 printf_filtered ("\t%-12s %-8s\n", "Fault", "Trace");
2830 for (transp
= faults_table
; transp
-> name
!= NULL
; transp
++)
2833 printf_filtered ("\t%-12s ", transp
-> name
);
2834 printf_filtered ("%-8s", prismember (&pip
-> fltset
, transp
-> value
)
2836 printf_filtered ("\n");
2838 printf_filtered ("\n");
2843 info_proc_mappings (pip
, summary
)
2844 struct procinfo
*pip
;
2848 struct prmap
*prmaps
;
2849 struct prmap
*prmap
;
2853 printf_filtered ("Mapped address spaces:\n\n");
2854 printf_filtered ("\t%10s %10s %10s %10s %7s\n",
2860 if (ioctl (pip
-> fd
, PIOCNMAP
, &nmap
) == 0)
2862 prmaps
= (struct prmap
*) alloca ((nmap
+ 1) * sizeof (*prmaps
));
2863 if (ioctl (pip
-> fd
, PIOCMAP
, prmaps
) == 0)
2865 for (prmap
= prmaps
; prmap
-> pr_size
; ++prmap
)
2867 printf_filtered ("\t%#10x %#10x %#10x %#10x %7s\n",
2869 prmap
-> pr_vaddr
+ prmap
-> pr_size
- 1,
2872 mappingflags (prmap
-> pr_mflags
));
2876 printf_filtered ("\n");
2884 info_proc -- implement the "info proc" command
2888 void info_proc (char *args, int from_tty)
2892 Implement gdb's "info proc" command by using the /proc interface
2893 to print status information about any currently running process.
2895 Examples of the use of "info proc" are:
2897 info proc (prints summary info for current inferior)
2898 info proc 123 (prints summary info for process with pid 123)
2899 info proc mappings (prints address mappings)
2900 info proc times (prints process/children times)
2901 info proc id (prints pid, ppid, gid, sid, etc)
2902 FIXME: i proc id not implemented.
2903 info proc status (prints general process state info)
2904 FIXME: i proc status not implemented.
2905 info proc signals (prints info about signal handling)
2906 info proc all (prints all info)
2911 info_proc (args
, from_tty
)
2916 struct procinfo pii
;
2917 struct procinfo
*pip
;
2918 struct cleanup
*old_chain
;
2932 old_chain
= make_cleanup (null_cleanup
, 0);
2934 /* Default to using the current inferior if no pid specified */
2940 if ((argv
= buildargv (args
)) == NULL
)
2944 make_cleanup (freeargv
, (char *) argv
);
2946 while (*argv
!= NULL
)
2948 argsize
= strlen (*argv
);
2949 if (argsize
>= 1 && strncmp (*argv
, "all", argsize
) == 0)
2954 else if (argsize
>= 2 && strncmp (*argv
, "faults", argsize
) == 0)
2959 else if (argsize
>= 2 && strncmp (*argv
, "flags", argsize
) == 0)
2964 else if (argsize
>= 1 && strncmp (*argv
, "id", argsize
) == 0)
2969 else if (argsize
>= 1 && strncmp (*argv
, "mappings", argsize
) == 0)
2974 else if (argsize
>= 2 && strncmp (*argv
, "signals", argsize
) == 0)
2979 else if (argsize
>= 2 && strncmp (*argv
, "status", argsize
) == 0)
2984 else if (argsize
>= 2 && strncmp (*argv
, "syscalls", argsize
) == 0)
2989 else if (argsize
>= 1 && strncmp (*argv
, "times", argsize
) == 0)
2994 else if ((pii
.pid
= atoi (*argv
)) > 0)
2998 memset (&pii
, 0, sizeof (pii
));
2999 if (!open_proc_file (pid
, pip
, O_RDONLY
))
3001 perror_with_name (pip
-> pathname
);
3004 make_cleanup (close_proc_file
, pip
);
3006 else if (**argv
!= '\000')
3008 error ("Unrecognized or ambiguous keyword `%s'.", *argv
);
3014 /* If we don't have a valid open process at this point, then we have no
3015 inferior or didn't specify a specific pid. */
3019 error ("No process. Run an inferior or specify an explicit pid.");
3021 if (ioctl (pip
-> fd
, PIOCSTATUS
, &(pip
-> prstatus
)) < 0)
3023 print_sys_errmsg (pip
-> pathname
, errno
);
3024 error ("PIOCSTATUS failed");
3027 /* Print verbose information of the requested type(s), or just a summary
3028 of the information for all types. */
3030 printf_filtered ("\nInformation for %s:\n\n", pip
-> pathname
);
3031 if (summary
|| all
|| flags
)
3033 info_proc_flags (pip
, summary
);
3037 info_proc_stop (pip
, summary
);
3039 if (summary
|| all
|| signals
|| faults
)
3041 info_proc_siginfo (pip
, summary
);
3043 if (summary
|| all
|| syscalls
)
3045 info_proc_syscalls (pip
, summary
);
3047 if (summary
|| all
|| mappings
)
3049 info_proc_mappings (pip
, summary
);
3051 if (summary
|| all
|| signals
)
3053 info_proc_signals (pip
, summary
);
3055 if (summary
|| all
|| faults
)
3057 info_proc_faults (pip
, summary
);
3059 printf_filtered ("\n");
3061 /* All done, deal with closing any temporary process info structure,
3062 freeing temporary memory , etc. */
3064 do_cleanups (old_chain
);
3067 /* Fork an inferior process, and start debugging it with /proc. */
3070 procfs_create_inferior (exec_file
, allargs
, env
)
3075 fork_inferior (exec_file
, allargs
, env
,
3076 proc_set_exec_trap
, procfs_init_inferior
);
3077 /* We are at the first instruction we care about. */
3078 /* Pedal to the metal... */
3079 proceed ((CORE_ADDR
) -1, 0, 0);
3082 /* Clean up after the inferior dies. */
3085 procfs_mourn_inferior ()
3087 unpush_target (&procfs_ops
);
3088 generic_mourn_inferior ();
3091 /* Mark our target-struct as eligible for stray "run" and "attach" commands. */
3098 struct target_ops procfs_ops
= {
3099 "procfs", /* to_shortname */
3100 "Unix /proc child process", /* to_longname */
3101 "Unix /proc child process (started by the \"run\" command).", /* to_doc */
3102 procfs_open
, /* to_open */
3104 procfs_attach
, /* to_attach */
3105 procfs_detach
, /* to_detach */
3106 procfs_resume
, /* to_resume */
3107 procfs_wait
, /* to_wait */
3108 procfs_fetch_registers
, /* to_fetch_registers */
3109 procfs_store_registers
, /* to_store_registers */
3110 procfs_prepare_to_store
, /* to_prepare_to_store */
3111 procfs_xfer_memory
, /* to_xfer_memory */
3112 procfs_files_info
, /* to_files_info */
3113 memory_insert_breakpoint
, /* to_insert_breakpoint */
3114 memory_remove_breakpoint
, /* to_remove_breakpoint */
3115 terminal_init_inferior
, /* to_terminal_init */
3116 terminal_inferior
, /* to_terminal_inferior */
3117 terminal_ours_for_output
, /* to_terminal_ours_for_output */
3118 terminal_ours
, /* to_terminal_ours */
3119 child_terminal_info
, /* to_terminal_info */
3120 procfs_kill_inferior
, /* to_kill */
3122 0, /* to_lookup_symbol */
3123 procfs_create_inferior
, /* to_create_inferior */
3124 procfs_mourn_inferior
, /* to_mourn_inferior */
3125 procfs_can_run
, /* to_can_run */
3126 procfs_notice_signals
, /* to_notice_signals */
3127 process_stratum
, /* to_stratum */
3129 1, /* to_has_all_memory */
3130 1, /* to_has_memory */
3131 1, /* to_has_stack */
3132 1, /* to_has_registers */
3133 1, /* to_has_execution */
3135 0, /* sections_end */
3136 OPS_MAGIC
/* to_magic */
3143 _initialize_procfs -- initialize the process file system stuff
3147 void _initialize_procfs (void)
3151 Do required initializations during gdb startup for using the
3152 /proc file system interface.
3157 _initialize_procfs ()
3159 add_target (&procfs_ops
);
3161 add_info ("proc", info_proc
,
3162 "Show process status information using /proc entry.\n\
3163 Specify process id or use current inferior by default.\n\
3164 Specify keywords for detailed information; default is summary.\n\
3165 Keywords are: `all', `faults', `flags', `id', `mappings', `signals',\n\
3166 `status', `syscalls', and `times'.\n\
3167 Unambiguous abbreviations may be used.");
3169 init_syscall_table ();