1 /* Machine independent support for SVR4 /proc (process file system) for GDB.
2 Copyright 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
3 Written by Fred Fish at Cygnus Support.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
24 For information on the details of using /proc consult section proc(4)
25 in the UNIX System V Release 4 System Administrator's Reference Manual.
27 The general register and floating point register sets are manipulated by
28 separate ioctl's. This file makes the assumption that if FP0_REGNUM is
29 defined, then support for the floating point register set is desired,
30 regardless of whether or not the actual target has floating point hardware.
37 #include <sys/types.h>
39 #include <sys/procfs.h>
53 #define MAX_SYSCALLS 256 /* Maximum number of syscalls for table */
56 #define PROC_NAME_FMT "/proc/%05d"
59 extern struct target_ops procfs_ops
; /* Forward declaration */
61 #if 1 /* FIXME: Gross and ugly hack to resolve coredep.c global */
62 CORE_ADDR kernel_u_addr
;
65 #ifdef BROKEN_SIGINFO_H /* Workaround broken SGS <sys/siginfo.h> */
67 #define si_pid _data._proc.pid
69 #define si_uid _data._proc._pdata._kill.uid
70 #endif /* BROKEN_SIGINFO_H */
72 /* All access to the inferior, either one started by gdb or one that has
73 been attached to, is controlled by an instance of a procinfo structure,
74 defined below. Since gdb currently only handles one inferior at a time,
75 the procinfo structure for the inferior is statically allocated and
76 only one exists at any given time. There is a separate procinfo
77 structure for use by the "info proc" command, so that we can print
78 useful information about any random process without interfering with
79 the inferior's procinfo information. */
82 struct procinfo
*next
;
83 int pid
; /* Process ID of inferior */
84 int fd
; /* File descriptor for /proc entry */
85 char *pathname
; /* Pathname to /proc entry */
86 int had_event
; /* poll/select says something happened */
87 int was_stopped
; /* Nonzero if was stopped prior to attach */
88 int nopass_next_sigstop
; /* Don't pass a sigstop on next resume */
89 prrun_t prrun
; /* Control state when it is run */
90 prstatus_t prstatus
; /* Current process status info */
91 gregset_t gregset
; /* General register set */
92 fpregset_t fpregset
; /* Floating point register set */
93 fltset_t fltset
; /* Current traced hardware fault set */
94 sigset_t trace
; /* Current traced signal set */
95 sysset_t exitset
; /* Current traced system call exit set */
96 sysset_t entryset
; /* Current traced system call entry set */
97 fltset_t saved_fltset
; /* Saved traced hardware fault set */
98 sigset_t saved_trace
; /* Saved traced signal set */
99 sigset_t saved_sighold
; /* Saved held signal set */
100 sysset_t saved_exitset
; /* Saved traced system call exit set */
101 sysset_t saved_entryset
; /* Saved traced system call entry set */
104 /* List of inferior process information */
105 static struct procinfo
*procinfo_list
= NULL
;
107 static struct pollfd
*poll_list
; /* pollfds used for waiting on /proc */
109 static int num_poll_list
= 0; /* Number of entries in poll_list */
111 static int last_resume_pid
= -1; /* Last pid used with procfs_resume */
113 /* Much of the information used in the /proc interface, particularly for
114 printing status information, is kept as tables of structures of the
115 following form. These tables can be used to map numeric values to
116 their symbolic names and to a string that describes their specific use. */
119 int value
; /* The numeric value */
120 char *name
; /* The equivalent symbolic value */
121 char *desc
; /* Short description of value */
124 /* Translate bits in the pr_flags member of the prstatus structure, into the
125 names and desc information. */
127 static struct trans pr_flag_table
[] =
129 #if defined (PR_STOPPED)
130 PR_STOPPED
, "PR_STOPPED", "Process is stopped",
132 #if defined (PR_ISTOP)
133 PR_ISTOP
, "PR_ISTOP", "Stopped on an event of interest",
135 #if defined (PR_DSTOP)
136 PR_DSTOP
, "PR_DSTOP", "A stop directive is in effect",
138 #if defined (PR_ASLEEP)
139 PR_ASLEEP
, "PR_ASLEEP", "Sleeping in an interruptible system call",
141 #if defined (PR_FORK)
142 PR_FORK
, "PR_FORK", "Inherit-on-fork is in effect",
145 PR_RLC
, "PR_RLC", "Run-on-last-close is in effect",
147 #if defined (PR_PTRACE)
148 PR_PTRACE
, "PR_PTRACE", "Process is being controlled by ptrace",
150 #if defined (PR_PCINVAL)
151 PR_PCINVAL
, "PR_PCINVAL", "PC refers to an invalid virtual address",
153 #if defined (PR_ISSYS)
154 PR_ISSYS
, "PR_ISSYS", "Is a system process",
156 #if defined (PR_STEP)
157 PR_STEP
, "PR_STEP", "Process has single step pending",
160 PR_KLC
, "PR_KLC", "Kill-on-last-close is in effect",
162 #if defined (PR_ASYNC)
163 PR_ASYNC
, "PR_ASYNC", "Asynchronous stop is in effect",
165 #if defined (PR_PCOMPAT)
166 PR_PCOMPAT
, "PR_PCOMPAT", "Ptrace compatibility mode in effect",
171 /* Translate values in the pr_why field of the prstatus struct. */
173 static struct trans pr_why_table
[] =
175 #if defined (PR_REQUESTED)
176 PR_REQUESTED
, "PR_REQUESTED", "Directed to stop via PIOCSTOP/PIOCWSTOP",
178 #if defined (PR_SIGNALLED)
179 PR_SIGNALLED
, "PR_SIGNALLED", "Receipt of a traced signal",
181 #if defined (PR_FAULTED)
182 PR_FAULTED
, "PR_FAULTED", "Incurred a traced hardware fault",
184 #if defined (PR_SYSENTRY)
185 PR_SYSENTRY
, "PR_SYSENTRY", "Entry to a traced system call",
187 #if defined (PR_SYSEXIT)
188 PR_SYSEXIT
, "PR_SYSEXIT", "Exit from a traced system call",
190 #if defined (PR_JOBCONTROL)
191 PR_JOBCONTROL
, "PR_JOBCONTROL", "Default job control stop signal action",
193 #if defined (PR_SUSPENDED)
194 PR_SUSPENDED
, "PR_SUSPENDED", "Process suspended",
199 /* Hardware fault translation table. */
201 static struct trans faults_table
[] =
204 FLTILL
, "FLTILL", "Illegal instruction",
206 #if defined (FLTPRIV)
207 FLTPRIV
, "FLTPRIV", "Privileged instruction",
210 FLTBPT
, "FLTBPT", "Breakpoint trap",
212 #if defined (FLTTRACE)
213 FLTTRACE
, "FLTTRACE", "Trace trap",
215 #if defined (FLTACCESS)
216 FLTACCESS
, "FLTACCESS", "Memory access fault",
218 #if defined (FLTBOUNDS)
219 FLTBOUNDS
, "FLTBOUNDS", "Memory bounds violation",
221 #if defined (FLTIOVF)
222 FLTIOVF
, "FLTIOVF", "Integer overflow",
224 #if defined (FLTIZDIV)
225 FLTIZDIV
, "FLTIZDIV", "Integer zero divide",
228 FLTFPE
, "FLTFPE", "Floating-point exception",
230 #if defined (FLTSTACK)
231 FLTSTACK
, "FLTSTACK", "Unrecoverable stack fault",
233 #if defined (FLTPAGE)
234 FLTPAGE
, "FLTPAGE", "Recoverable page fault",
239 /* Translation table for signal generation information. See UNIX System
240 V Release 4 Programmer's Reference Manual, siginfo(5). */
242 static struct sigcode
{
247 } siginfo_table
[] = {
248 #if defined (SIGILL) && defined (ILL_ILLOPC)
249 SIGILL
, ILL_ILLOPC
, "ILL_ILLOPC", "Illegal opcode",
251 #if defined (SIGILL) && defined (ILL_ILLOPN)
252 SIGILL
, ILL_ILLOPN
, "ILL_ILLOPN", "Illegal operand",
254 #if defined (SIGILL) && defined (ILL_ILLADR)
255 SIGILL
, ILL_ILLADR
, "ILL_ILLADR", "Illegal addressing mode",
257 #if defined (SIGILL) && defined (ILL_ILLTRP)
258 SIGILL
, ILL_ILLTRP
, "ILL_ILLTRP", "Illegal trap",
260 #if defined (SIGILL) && defined (ILL_PRVOPC)
261 SIGILL
, ILL_PRVOPC
, "ILL_PRVOPC", "Privileged opcode",
263 #if defined (SIGILL) && defined (ILL_PRVREG)
264 SIGILL
, ILL_PRVREG
, "ILL_PRVREG", "Privileged register",
266 #if defined (SIGILL) && defined (ILL_COPROC)
267 SIGILL
, ILL_COPROC
, "ILL_COPROC", "Coprocessor error",
269 #if defined (SIGILL) && defined (ILL_BADSTK)
270 SIGILL
, ILL_BADSTK
, "ILL_BADSTK", "Internal stack error",
272 #if defined (SIGFPE) && defined (FPE_INTDIV)
273 SIGFPE
, FPE_INTDIV
, "FPE_INTDIV", "Integer divide by zero",
275 #if defined (SIGFPE) && defined (FPE_INTOVF)
276 SIGFPE
, FPE_INTOVF
, "FPE_INTOVF", "Integer overflow",
278 #if defined (SIGFPE) && defined (FPE_FLTDIV)
279 SIGFPE
, FPE_FLTDIV
, "FPE_FLTDIV", "Floating point divide by zero",
281 #if defined (SIGFPE) && defined (FPE_FLTOVF)
282 SIGFPE
, FPE_FLTOVF
, "FPE_FLTOVF", "Floating point overflow",
284 #if defined (SIGFPE) && defined (FPE_FLTUND)
285 SIGFPE
, FPE_FLTUND
, "FPE_FLTUND", "Floating point underflow",
287 #if defined (SIGFPE) && defined (FPE_FLTRES)
288 SIGFPE
, FPE_FLTRES
, "FPE_FLTRES", "Floating point inexact result",
290 #if defined (SIGFPE) && defined (FPE_FLTINV)
291 SIGFPE
, FPE_FLTINV
, "FPE_FLTINV", "Invalid floating point operation",
293 #if defined (SIGFPE) && defined (FPE_FLTSUB)
294 SIGFPE
, FPE_FLTSUB
, "FPE_FLTSUB", "Subscript out of range",
296 #if defined (SIGSEGV) && defined (SEGV_MAPERR)
297 SIGSEGV
, SEGV_MAPERR
, "SEGV_MAPERR", "Address not mapped to object",
299 #if defined (SIGSEGV) && defined (SEGV_ACCERR)
300 SIGSEGV
, SEGV_ACCERR
, "SEGV_ACCERR", "Invalid permissions for object",
302 #if defined (SIGBUS) && defined (BUS_ADRALN)
303 SIGBUS
, BUS_ADRALN
, "BUS_ADRALN", "Invalid address alignment",
305 #if defined (SIGBUS) && defined (BUS_ADRERR)
306 SIGBUS
, BUS_ADRERR
, "BUS_ADRERR", "Non-existent physical address",
308 #if defined (SIGBUS) && defined (BUS_OBJERR)
309 SIGBUS
, BUS_OBJERR
, "BUS_OBJERR", "Object specific hardware error",
311 #if defined (SIGTRAP) && defined (TRAP_BRKPT)
312 SIGTRAP
, TRAP_BRKPT
, "TRAP_BRKPT", "Process breakpoint",
314 #if defined (SIGTRAP) && defined (TRAP_TRACE)
315 SIGTRAP
, TRAP_TRACE
, "TRAP_TRACE", "Process trace trap",
317 #if defined (SIGCLD) && defined (CLD_EXITED)
318 SIGCLD
, CLD_EXITED
, "CLD_EXITED", "Child has exited",
320 #if defined (SIGCLD) && defined (CLD_KILLED)
321 SIGCLD
, CLD_KILLED
, "CLD_KILLED", "Child was killed",
323 #if defined (SIGCLD) && defined (CLD_DUMPED)
324 SIGCLD
, CLD_DUMPED
, "CLD_DUMPED", "Child has terminated abnormally",
326 #if defined (SIGCLD) && defined (CLD_TRAPPED)
327 SIGCLD
, CLD_TRAPPED
, "CLD_TRAPPED", "Traced child has trapped",
329 #if defined (SIGCLD) && defined (CLD_STOPPED)
330 SIGCLD
, CLD_STOPPED
, "CLD_STOPPED", "Child has stopped",
332 #if defined (SIGCLD) && defined (CLD_CONTINUED)
333 SIGCLD
, CLD_CONTINUED
, "CLD_CONTINUED", "Stopped child had continued",
335 #if defined (SIGPOLL) && defined (POLL_IN)
336 SIGPOLL
, POLL_IN
, "POLL_IN", "Input input available",
338 #if defined (SIGPOLL) && defined (POLL_OUT)
339 SIGPOLL
, POLL_OUT
, "POLL_OUT", "Output buffers available",
341 #if defined (SIGPOLL) && defined (POLL_MSG)
342 SIGPOLL
, POLL_MSG
, "POLL_MSG", "Input message available",
344 #if defined (SIGPOLL) && defined (POLL_ERR)
345 SIGPOLL
, POLL_ERR
, "POLL_ERR", "I/O error",
347 #if defined (SIGPOLL) && defined (POLL_PRI)
348 SIGPOLL
, POLL_PRI
, "POLL_PRI", "High priority input available",
350 #if defined (SIGPOLL) && defined (POLL_HUP)
351 SIGPOLL
, POLL_HUP
, "POLL_HUP", "Device disconnected",
356 static char *syscall_table
[MAX_SYSCALLS
];
358 /* Prototypes for local functions */
361 set_proc_siginfo
PARAMS ((struct procinfo
*, int));
364 init_syscall_table
PARAMS ((void));
367 syscallname
PARAMS ((int));
370 signalname
PARAMS ((int));
373 errnoname
PARAMS ((int));
376 proc_address_to_fd
PARAMS ((struct procinfo
*, CORE_ADDR
, int));
379 open_proc_file
PARAMS ((int, struct procinfo
*, int));
382 close_proc_file
PARAMS ((struct procinfo
*));
385 unconditionally_kill_inferior
PARAMS ((struct procinfo
*));
388 proc_init_failed
PARAMS ((struct procinfo
*, char *)) ATTR_NORETURN
;
391 info_proc
PARAMS ((char *, int));
394 info_proc_flags
PARAMS ((struct procinfo
*, int));
397 info_proc_stop
PARAMS ((struct procinfo
*, int));
400 info_proc_siginfo
PARAMS ((struct procinfo
*, int));
403 info_proc_syscalls
PARAMS ((struct procinfo
*, int));
406 info_proc_mappings
PARAMS ((struct procinfo
*, int));
409 info_proc_signals
PARAMS ((struct procinfo
*, int));
412 info_proc_faults
PARAMS ((struct procinfo
*, int));
415 mappingflags
PARAMS ((long));
418 lookupname
PARAMS ((struct trans
*, unsigned int, char *));
421 lookupdesc
PARAMS ((struct trans
*, unsigned int));
424 do_attach
PARAMS ((int pid
));
427 do_detach
PARAMS ((int siggnal
));
430 procfs_create_inferior
PARAMS ((char *, char *, char **));
433 procfs_notice_signals
PARAMS ((int pid
));
435 static struct procinfo
*
436 find_procinfo
PARAMS ((pid_t pid
, int okfail
));
438 /* External function prototypes that can't be easily included in any
439 header file because the args are typedefs in system include files. */
442 supply_gregset
PARAMS ((gregset_t
*));
445 fill_gregset
PARAMS ((gregset_t
*, int));
448 supply_fpregset
PARAMS ((fpregset_t
*));
451 fill_fpregset
PARAMS ((fpregset_t
*, int));
457 find_procinfo -- convert a process id to a struct procinfo
461 static struct procinfo * find_procinfo (pid_t pid, int okfail);
465 Given a process id, look it up in the procinfo chain. Returns
466 a struct procinfo *. If can't find pid, then call error(),
467 unless okfail is set, in which case, return NULL;
470 static struct procinfo
*
471 find_procinfo (pid
, okfail
)
475 struct procinfo
*procinfo
;
477 for (procinfo
= procinfo_list
; procinfo
; procinfo
= procinfo
->next
)
478 if (procinfo
->pid
== pid
)
484 error ("procfs (find_procinfo): Couldn't locate pid %d", pid
);
491 current_procinfo -- convert inferior_pid to a struct procinfo
495 static struct procinfo * current_procinfo;
499 Looks up inferior_pid in the procinfo chain. Always returns a
500 struct procinfo *. If process can't be found, we error() out.
503 #define current_procinfo find_procinfo (inferior_pid, 0)
509 add_fd -- Add the fd to the poll/select list
513 static void add_fd (struct procinfo *);
517 Add the fd of the supplied procinfo to the list of fds used for
518 poll/select operations.
525 if (num_poll_list
<= 0)
526 poll_list
= (struct pollfd
*) xmalloc (sizeof (struct pollfd
));
528 poll_list
= (struct pollfd
*) xrealloc (poll_list
,
530 * sizeof (struct pollfd
));
531 poll_list
[num_poll_list
].fd
= pi
->fd
;
532 poll_list
[num_poll_list
].events
= POLLPRI
;
543 for (i
= 0; i
< num_poll_list
; i
++)
545 if (poll_list
[i
].fd
== pi
->fd
)
547 if (i
!= num_poll_list
- 1)
548 memcpy (poll_list
, poll_list
+ i
+ 1,
549 (num_poll_list
- i
- 1) * sizeof (struct pollfd
));
553 if (num_poll_list
== 0)
556 poll_list
= (struct pollfd
*) xrealloc (poll_list
,
558 * sizeof (struct pollfd
));
564 #define LOSING_POLL unixware_sux
566 static struct procinfo
*
573 set_sigint_trap (); /* Causes SIGINT to be passed on to the
578 num_fds
= poll (poll_list
, num_poll_list
, -1);
580 pi
= current_procinfo
;
582 while (ioctl (pi
->fd
, PIOCWSTOP
, &pi
->prstatus
) < 0)
586 /* Process exited. */
587 pi
->prstatus
.pr_flags
= 0;
590 else if (errno
!= EINTR
)
592 print_sys_errmsg (pi
->pathname
, errno
);
593 error ("PIOCWSTOP failed");
599 clear_sigint_trap ();
606 print_sys_errmsg ("poll failed\n", errno
);
607 error ("Poll failed, returned %d", num_fds
);
610 for (i
= 0; i
< num_poll_list
&& num_fds
> 0; i
++)
612 if ((poll_list
[i
].revents
& (POLLPRI
|POLLERR
|POLLHUP
|POLLNVAL
)) == 0)
614 for (pi
= procinfo_list
; pi
; pi
= pi
->next
)
616 if (poll_list
[i
].fd
== pi
->fd
)
618 if (ioctl (pi
->fd
, PIOCSTATUS
, &pi
->prstatus
) < 0)
620 print_sys_errmsg (pi
->pathname
, errno
);
621 error ("PIOCSTATUS failed");
629 error ("procfs_wait: Couldn't find procinfo for fd %d\n",
632 #endif /* LOSING_POLL */
641 lookupdesc -- translate a value to a summary desc string
645 static char *lookupdesc (struct trans *transp, unsigned int val);
649 Given a pointer to a translation table and a value to be translated,
650 lookup the desc string and return it.
654 lookupdesc (transp
, val
)
655 struct trans
*transp
;
660 for (desc
= NULL
; transp
-> name
!= NULL
; transp
++)
662 if (transp
-> value
== val
)
664 desc
= transp
-> desc
;
669 /* Didn't find a translation for the specified value, set a default one. */
682 lookupname -- translate a value to symbolic name
686 static char *lookupname (struct trans *transp, unsigned int val,
691 Given a pointer to a translation table, a value to be translated,
692 and a default prefix to return if the value can't be translated,
693 match the value with one of the translation table entries and
694 return a pointer to the symbolic name.
696 If no match is found it just returns the value as a printable string,
697 with the given prefix. The previous such value, if any, is freed
702 lookupname (transp
, val
, prefix
)
703 struct trans
*transp
;
710 for (name
= NULL
; transp
-> name
!= NULL
; transp
++)
712 if (transp
-> value
== val
)
714 name
= transp
-> name
;
719 /* Didn't find a translation for the specified value, build a default
720 one using the specified prefix and return it. The lifetime of
721 the value is only until the next one is needed. */
729 locbuf
= xmalloc (strlen (prefix
) + 16);
730 sprintf (locbuf
, "%s %u", prefix
, val
);
742 static char locbuf
[32];
744 for (scp
= siginfo_table
; scp
-> codename
!= NULL
; scp
++)
746 if ((scp
-> signo
== sip
-> si_signo
) &&
747 (scp
-> code
== sip
-> si_code
))
749 name
= scp
-> codename
;
755 sprintf (locbuf
, "sigcode %u", sip
-> si_signo
);
768 for (scp
= siginfo_table
; scp
-> codename
!= NULL
; scp
++)
770 if ((scp
-> signo
== sip
-> si_signo
) &&
771 (scp
-> code
== sip
-> si_code
))
779 desc
= "Unrecognized signal or trap use";
788 syscallname - translate a system call number into a system call name
792 char *syscallname (int syscallnum)
796 Given a system call number, translate it into the printable name
797 of a system call, or into "syscall <num>" if it is an unknown
802 syscallname (syscallnum
)
805 static char locbuf
[32];
808 if (syscallnum
>= 0 && syscallnum
< MAX_SYSCALLS
)
810 rtnval
= syscall_table
[syscallnum
];
814 sprintf (locbuf
, "syscall %u", syscallnum
);
824 init_syscall_table - initialize syscall translation table
828 void init_syscall_table (void)
832 Dynamically initialize the translation table to convert system
833 call numbers into printable system call names. Done once per
834 gdb run, on initialization.
838 This is awfully ugly, but preprocessor tricks to make it prettier
839 tend to be nonportable.
843 init_syscall_table ()
845 #if defined (SYS_exit)
846 syscall_table
[SYS_exit
] = "exit";
848 #if defined (SYS_fork)
849 syscall_table
[SYS_fork
] = "fork";
851 #if defined (SYS_read)
852 syscall_table
[SYS_read
] = "read";
854 #if defined (SYS_write)
855 syscall_table
[SYS_write
] = "write";
857 #if defined (SYS_open)
858 syscall_table
[SYS_open
] = "open";
860 #if defined (SYS_close)
861 syscall_table
[SYS_close
] = "close";
863 #if defined (SYS_wait)
864 syscall_table
[SYS_wait
] = "wait";
866 #if defined (SYS_creat)
867 syscall_table
[SYS_creat
] = "creat";
869 #if defined (SYS_link)
870 syscall_table
[SYS_link
] = "link";
872 #if defined (SYS_unlink)
873 syscall_table
[SYS_unlink
] = "unlink";
875 #if defined (SYS_exec)
876 syscall_table
[SYS_exec
] = "exec";
878 #if defined (SYS_execv)
879 syscall_table
[SYS_execv
] = "execv";
881 #if defined (SYS_execve)
882 syscall_table
[SYS_execve
] = "execve";
884 #if defined (SYS_chdir)
885 syscall_table
[SYS_chdir
] = "chdir";
887 #if defined (SYS_time)
888 syscall_table
[SYS_time
] = "time";
890 #if defined (SYS_mknod)
891 syscall_table
[SYS_mknod
] = "mknod";
893 #if defined (SYS_chmod)
894 syscall_table
[SYS_chmod
] = "chmod";
896 #if defined (SYS_chown)
897 syscall_table
[SYS_chown
] = "chown";
899 #if defined (SYS_brk)
900 syscall_table
[SYS_brk
] = "brk";
902 #if defined (SYS_stat)
903 syscall_table
[SYS_stat
] = "stat";
905 #if defined (SYS_lseek)
906 syscall_table
[SYS_lseek
] = "lseek";
908 #if defined (SYS_getpid)
909 syscall_table
[SYS_getpid
] = "getpid";
911 #if defined (SYS_mount)
912 syscall_table
[SYS_mount
] = "mount";
914 #if defined (SYS_umount)
915 syscall_table
[SYS_umount
] = "umount";
917 #if defined (SYS_setuid)
918 syscall_table
[SYS_setuid
] = "setuid";
920 #if defined (SYS_getuid)
921 syscall_table
[SYS_getuid
] = "getuid";
923 #if defined (SYS_stime)
924 syscall_table
[SYS_stime
] = "stime";
926 #if defined (SYS_ptrace)
927 syscall_table
[SYS_ptrace
] = "ptrace";
929 #if defined (SYS_alarm)
930 syscall_table
[SYS_alarm
] = "alarm";
932 #if defined (SYS_fstat)
933 syscall_table
[SYS_fstat
] = "fstat";
935 #if defined (SYS_pause)
936 syscall_table
[SYS_pause
] = "pause";
938 #if defined (SYS_utime)
939 syscall_table
[SYS_utime
] = "utime";
941 #if defined (SYS_stty)
942 syscall_table
[SYS_stty
] = "stty";
944 #if defined (SYS_gtty)
945 syscall_table
[SYS_gtty
] = "gtty";
947 #if defined (SYS_access)
948 syscall_table
[SYS_access
] = "access";
950 #if defined (SYS_nice)
951 syscall_table
[SYS_nice
] = "nice";
953 #if defined (SYS_statfs)
954 syscall_table
[SYS_statfs
] = "statfs";
956 #if defined (SYS_sync)
957 syscall_table
[SYS_sync
] = "sync";
959 #if defined (SYS_kill)
960 syscall_table
[SYS_kill
] = "kill";
962 #if defined (SYS_fstatfs)
963 syscall_table
[SYS_fstatfs
] = "fstatfs";
965 #if defined (SYS_pgrpsys)
966 syscall_table
[SYS_pgrpsys
] = "pgrpsys";
968 #if defined (SYS_xenix)
969 syscall_table
[SYS_xenix
] = "xenix";
971 #if defined (SYS_dup)
972 syscall_table
[SYS_dup
] = "dup";
974 #if defined (SYS_pipe)
975 syscall_table
[SYS_pipe
] = "pipe";
977 #if defined (SYS_times)
978 syscall_table
[SYS_times
] = "times";
980 #if defined (SYS_profil)
981 syscall_table
[SYS_profil
] = "profil";
983 #if defined (SYS_plock)
984 syscall_table
[SYS_plock
] = "plock";
986 #if defined (SYS_setgid)
987 syscall_table
[SYS_setgid
] = "setgid";
989 #if defined (SYS_getgid)
990 syscall_table
[SYS_getgid
] = "getgid";
992 #if defined (SYS_signal)
993 syscall_table
[SYS_signal
] = "signal";
995 #if defined (SYS_msgsys)
996 syscall_table
[SYS_msgsys
] = "msgsys";
998 #if defined (SYS_sys3b)
999 syscall_table
[SYS_sys3b
] = "sys3b";
1001 #if defined (SYS_acct)
1002 syscall_table
[SYS_acct
] = "acct";
1004 #if defined (SYS_shmsys)
1005 syscall_table
[SYS_shmsys
] = "shmsys";
1007 #if defined (SYS_semsys)
1008 syscall_table
[SYS_semsys
] = "semsys";
1010 #if defined (SYS_ioctl)
1011 syscall_table
[SYS_ioctl
] = "ioctl";
1013 #if defined (SYS_uadmin)
1014 syscall_table
[SYS_uadmin
] = "uadmin";
1016 #if defined (SYS_utssys)
1017 syscall_table
[SYS_utssys
] = "utssys";
1019 #if defined (SYS_fsync)
1020 syscall_table
[SYS_fsync
] = "fsync";
1022 #if defined (SYS_umask)
1023 syscall_table
[SYS_umask
] = "umask";
1025 #if defined (SYS_chroot)
1026 syscall_table
[SYS_chroot
] = "chroot";
1028 #if defined (SYS_fcntl)
1029 syscall_table
[SYS_fcntl
] = "fcntl";
1031 #if defined (SYS_ulimit)
1032 syscall_table
[SYS_ulimit
] = "ulimit";
1034 #if defined (SYS_rfsys)
1035 syscall_table
[SYS_rfsys
] = "rfsys";
1037 #if defined (SYS_rmdir)
1038 syscall_table
[SYS_rmdir
] = "rmdir";
1040 #if defined (SYS_mkdir)
1041 syscall_table
[SYS_mkdir
] = "mkdir";
1043 #if defined (SYS_getdents)
1044 syscall_table
[SYS_getdents
] = "getdents";
1046 #if defined (SYS_sysfs)
1047 syscall_table
[SYS_sysfs
] = "sysfs";
1049 #if defined (SYS_getmsg)
1050 syscall_table
[SYS_getmsg
] = "getmsg";
1052 #if defined (SYS_putmsg)
1053 syscall_table
[SYS_putmsg
] = "putmsg";
1055 #if defined (SYS_poll)
1056 syscall_table
[SYS_poll
] = "poll";
1058 #if defined (SYS_lstat)
1059 syscall_table
[SYS_lstat
] = "lstat";
1061 #if defined (SYS_symlink)
1062 syscall_table
[SYS_symlink
] = "symlink";
1064 #if defined (SYS_readlink)
1065 syscall_table
[SYS_readlink
] = "readlink";
1067 #if defined (SYS_setgroups)
1068 syscall_table
[SYS_setgroups
] = "setgroups";
1070 #if defined (SYS_getgroups)
1071 syscall_table
[SYS_getgroups
] = "getgroups";
1073 #if defined (SYS_fchmod)
1074 syscall_table
[SYS_fchmod
] = "fchmod";
1076 #if defined (SYS_fchown)
1077 syscall_table
[SYS_fchown
] = "fchown";
1079 #if defined (SYS_sigprocmask)
1080 syscall_table
[SYS_sigprocmask
] = "sigprocmask";
1082 #if defined (SYS_sigsuspend)
1083 syscall_table
[SYS_sigsuspend
] = "sigsuspend";
1085 #if defined (SYS_sigaltstack)
1086 syscall_table
[SYS_sigaltstack
] = "sigaltstack";
1088 #if defined (SYS_sigaction)
1089 syscall_table
[SYS_sigaction
] = "sigaction";
1091 #if defined (SYS_sigpending)
1092 syscall_table
[SYS_sigpending
] = "sigpending";
1094 #if defined (SYS_context)
1095 syscall_table
[SYS_context
] = "context";
1097 #if defined (SYS_evsys)
1098 syscall_table
[SYS_evsys
] = "evsys";
1100 #if defined (SYS_evtrapret)
1101 syscall_table
[SYS_evtrapret
] = "evtrapret";
1103 #if defined (SYS_statvfs)
1104 syscall_table
[SYS_statvfs
] = "statvfs";
1106 #if defined (SYS_fstatvfs)
1107 syscall_table
[SYS_fstatvfs
] = "fstatvfs";
1109 #if defined (SYS_nfssys)
1110 syscall_table
[SYS_nfssys
] = "nfssys";
1112 #if defined (SYS_waitsys)
1113 syscall_table
[SYS_waitsys
] = "waitsys";
1115 #if defined (SYS_sigsendsys)
1116 syscall_table
[SYS_sigsendsys
] = "sigsendsys";
1118 #if defined (SYS_hrtsys)
1119 syscall_table
[SYS_hrtsys
] = "hrtsys";
1121 #if defined (SYS_acancel)
1122 syscall_table
[SYS_acancel
] = "acancel";
1124 #if defined (SYS_async)
1125 syscall_table
[SYS_async
] = "async";
1127 #if defined (SYS_priocntlsys)
1128 syscall_table
[SYS_priocntlsys
] = "priocntlsys";
1130 #if defined (SYS_pathconf)
1131 syscall_table
[SYS_pathconf
] = "pathconf";
1133 #if defined (SYS_mincore)
1134 syscall_table
[SYS_mincore
] = "mincore";
1136 #if defined (SYS_mmap)
1137 syscall_table
[SYS_mmap
] = "mmap";
1139 #if defined (SYS_mprotect)
1140 syscall_table
[SYS_mprotect
] = "mprotect";
1142 #if defined (SYS_munmap)
1143 syscall_table
[SYS_munmap
] = "munmap";
1145 #if defined (SYS_fpathconf)
1146 syscall_table
[SYS_fpathconf
] = "fpathconf";
1148 #if defined (SYS_vfork)
1149 syscall_table
[SYS_vfork
] = "vfork";
1151 #if defined (SYS_fchdir)
1152 syscall_table
[SYS_fchdir
] = "fchdir";
1154 #if defined (SYS_readv)
1155 syscall_table
[SYS_readv
] = "readv";
1157 #if defined (SYS_writev)
1158 syscall_table
[SYS_writev
] = "writev";
1160 #if defined (SYS_xstat)
1161 syscall_table
[SYS_xstat
] = "xstat";
1163 #if defined (SYS_lxstat)
1164 syscall_table
[SYS_lxstat
] = "lxstat";
1166 #if defined (SYS_fxstat)
1167 syscall_table
[SYS_fxstat
] = "fxstat";
1169 #if defined (SYS_xmknod)
1170 syscall_table
[SYS_xmknod
] = "xmknod";
1172 #if defined (SYS_clocal)
1173 syscall_table
[SYS_clocal
] = "clocal";
1175 #if defined (SYS_setrlimit)
1176 syscall_table
[SYS_setrlimit
] = "setrlimit";
1178 #if defined (SYS_getrlimit)
1179 syscall_table
[SYS_getrlimit
] = "getrlimit";
1181 #if defined (SYS_lchown)
1182 syscall_table
[SYS_lchown
] = "lchown";
1184 #if defined (SYS_memcntl)
1185 syscall_table
[SYS_memcntl
] = "memcntl";
1187 #if defined (SYS_getpmsg)
1188 syscall_table
[SYS_getpmsg
] = "getpmsg";
1190 #if defined (SYS_putpmsg)
1191 syscall_table
[SYS_putpmsg
] = "putpmsg";
1193 #if defined (SYS_rename)
1194 syscall_table
[SYS_rename
] = "rename";
1196 #if defined (SYS_uname)
1197 syscall_table
[SYS_uname
] = "uname";
1199 #if defined (SYS_setegid)
1200 syscall_table
[SYS_setegid
] = "setegid";
1202 #if defined (SYS_sysconfig)
1203 syscall_table
[SYS_sysconfig
] = "sysconfig";
1205 #if defined (SYS_adjtime)
1206 syscall_table
[SYS_adjtime
] = "adjtime";
1208 #if defined (SYS_systeminfo)
1209 syscall_table
[SYS_systeminfo
] = "systeminfo";
1211 #if defined (SYS_seteuid)
1212 syscall_table
[SYS_seteuid
] = "seteuid";
1214 #if defined (SYS_sproc)
1215 syscall_table
[SYS_sproc
] = "sproc";
1223 procfs_kill_inferior - kill any currently inferior
1227 void procfs_kill_inferior (void)
1231 Kill any current inferior.
1235 Kills even attached inferiors. Presumably the user has already
1236 been prompted that the inferior is an attached one rather than
1237 one started by gdb. (FIXME?)
1242 procfs_kill_inferior ()
1244 target_mourn_inferior ();
1251 unconditionally_kill_inferior - terminate the inferior
1255 static void unconditionally_kill_inferior (struct procinfo *)
1259 Kill the specified inferior.
1263 A possibly useful enhancement would be to first try sending
1264 the inferior a terminate signal, politely asking it to commit
1265 suicide, before we murder it (we could call that
1266 politely_kill_inferior()).
1271 unconditionally_kill_inferior (pi
)
1272 struct procinfo
*pi
;
1277 ppid
= pi
->prstatus
.pr_ppid
;
1280 ioctl (pi
->fd
, PIOCKILL
, &signo
);
1281 close_proc_file (pi
);
1283 /* Only wait() for our direct children. Our grandchildren zombies are killed
1284 by the death of their parents. */
1286 if (ppid
== getpid())
1294 procfs_xfer_memory -- copy data to or from inferior memory space
1298 int procfs_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len,
1299 int dowrite, struct target_ops target)
1303 Copy LEN bytes to/from inferior's memory starting at MEMADDR
1304 from/to debugger memory starting at MYADDR. Copy from inferior
1305 if DOWRITE is zero or to inferior if DOWRITE is nonzero.
1307 Returns the length copied, which is either the LEN argument or
1308 zero. This xfer function does not do partial moves, since procfs_ops
1309 doesn't allow memory operations to cross below us in the target stack
1314 The /proc interface makes this an almost trivial task.
1318 procfs_xfer_memory (memaddr
, myaddr
, len
, dowrite
, target
)
1323 struct target_ops
*target
; /* ignored */
1326 struct procinfo
*pi
;
1328 pi
= current_procinfo
;
1330 if (lseek(pi
->fd
, (off_t
) memaddr
, 0) == (off_t
) memaddr
)
1334 nbytes
= write (pi
->fd
, myaddr
, len
);
1338 nbytes
= read (pi
->fd
, myaddr
, len
);
1352 procfs_store_registers -- copy register values back to inferior
1356 void procfs_store_registers (int regno)
1360 Store our current register values back into the inferior. If
1361 REGNO is -1 then store all the register, otherwise store just
1362 the value specified by REGNO.
1366 If we are storing only a single register, we first have to get all
1367 the current values from the process, overwrite the desired register
1368 in the gregset with the one we want from gdb's registers, and then
1369 send the whole set back to the process. For writing all the
1370 registers, all we have to do is generate the gregset and send it to
1373 Also note that the process has to be stopped on an event of interest
1374 for this to work, which basically means that it has to have been
1375 run under the control of one of the other /proc ioctl calls and not
1376 ptrace. Since we don't use ptrace anyway, we don't worry about this
1377 fine point, but it is worth noting for future reference.
1379 Gdb is confused about what this function is supposed to return.
1380 Some versions return a value, others return nothing. Some are
1381 declared to return a value and actually return nothing. Gdb ignores
1382 anything returned. (FIXME)
1387 procfs_store_registers (regno
)
1390 struct procinfo
*pi
;
1392 pi
= current_procinfo
;
1396 ioctl (pi
->fd
, PIOCGREG
, &pi
->gregset
);
1398 fill_gregset (&pi
->gregset
, regno
);
1399 ioctl (pi
->fd
, PIOCSREG
, &pi
->gregset
);
1401 #if defined (FP0_REGNUM)
1403 /* Now repeat everything using the floating point register set, if the
1404 target has floating point hardware. Since we ignore the returned value,
1405 we'll never know whether it worked or not anyway. */
1409 ioctl (pi
->fd
, PIOCGFPREG
, &pi
->fpregset
);
1411 fill_fpregset (&pi
->fpregset
, regno
);
1412 ioctl (pi
->fd
, PIOCSFPREG
, &pi
->fpregset
);
1414 #endif /* FP0_REGNUM */
1422 create_procinfo - initialize access to a /proc entry
1426 struct procinfo * create_procinfo (int pid)
1430 Allocate a procinfo structure, open the /proc file and then set up the
1431 set of signals and faults that are to be traced. Returns a pointer to
1432 the new procinfo structure.
1436 If proc_init_failed ever gets called, control returns to the command
1437 processing loop via the standard error handling code.
1441 static struct procinfo
*
1442 create_procinfo (pid
)
1445 struct procinfo
*pi
;
1447 if (find_procinfo (pid
, 1))
1448 return; /* All done! It already exists */
1450 pi
= (struct procinfo
*) xmalloc (sizeof (struct procinfo
));
1452 if (!open_proc_file (pid
, pi
, O_RDWR
))
1453 proc_init_failed (pi
, "can't open process file");
1455 /* Add new process to process info list */
1457 pi
->next
= procinfo_list
;
1460 add_fd (pi
); /* Add to list for poll/select */
1462 memset ((char *) &pi
->prrun
, 0, sizeof (pi
->prrun
));
1463 prfillset (&pi
->prrun
.pr_trace
);
1464 procfs_notice_signals (pid
);
1465 prfillset (&pi
->prrun
.pr_fault
);
1466 prdelset (&pi
->prrun
.pr_fault
, FLTPAGE
);
1468 if (ioctl (pi
->fd
, PIOCWSTOP
, &pi
->prstatus
) < 0)
1469 proc_init_failed (pi
, "PIOCWSTOP failed");
1471 if (ioctl (pi
->fd
, PIOCSFAULT
, &pi
->prrun
.pr_fault
) < 0)
1472 proc_init_failed (pi
, "PIOCSFAULT failed");
1481 procfs_init_inferior - initialize target vector and access to a
1486 void procfs_init_inferior (int pid)
1490 When gdb starts an inferior, this function is called in the parent
1491 process immediately after the fork. It waits for the child to stop
1492 on the return from the exec system call (the child itself takes care
1493 of ensuring that this is set up), then sets up the set of signals
1494 and faults that are to be traced.
1498 If proc_init_failed ever gets called, control returns to the command
1499 processing loop via the standard error handling code.
1504 procfs_init_inferior (pid
)
1507 push_target (&procfs_ops
);
1509 create_procinfo (pid
);
1510 add_thread (pid
); /* Setup initial thread */
1512 /* One trap to exec the shell, one to exec the program being debugged. */
1513 startup_inferior (2);
1520 procfs_notice_signals
1524 static void procfs_notice_signals (int pid);
1528 When the user changes the state of gdb's signal handling via the
1529 "handle" command, this function gets called to see if any change
1530 in the /proc interface is required. It is also called internally
1531 by other /proc interface functions to initialize the state of
1532 the traced signal set.
1534 One thing it does is that signals for which the state is "nostop",
1535 "noprint", and "pass", have their trace bits reset in the pr_trace
1536 field, so that they are no longer traced. This allows them to be
1537 delivered directly to the inferior without the debugger ever being
1542 procfs_notice_signals (pid
)
1546 struct procinfo
*pi
;
1548 pi
= find_procinfo (pid
, 0);
1550 for (signo
= 0; signo
< NSIG
; signo
++)
1552 if (signal_stop_state (target_signal_from_host (signo
)) == 0 &&
1553 signal_print_state (target_signal_from_host (signo
)) == 0 &&
1554 signal_pass_state (target_signal_from_host (signo
)) == 1)
1556 prdelset (&pi
->prrun
.pr_trace
, signo
);
1560 praddset (&pi
->prrun
.pr_trace
, signo
);
1563 if (ioctl (pi
->fd
, PIOCSTRACE
, &pi
->prrun
.pr_trace
))
1565 print_sys_errmsg ("PIOCSTRACE failed", errno
);
1573 proc_set_exec_trap -- arrange for exec'd child to halt at startup
1577 void proc_set_exec_trap (void)
1581 This function is called in the child process when starting up
1582 an inferior, prior to doing the exec of the actual inferior.
1583 It sets the child process's exitset to make exit from the exec
1584 system call an event of interest to stop on, and then simply
1585 returns. The child does the exec, the system call returns, and
1586 the child stops at the first instruction, ready for the gdb
1587 parent process to take control of it.
1591 We need to use all local variables since the child may be sharing
1592 it's data space with the parent, if vfork was used rather than
1595 Also note that we want to turn off the inherit-on-fork flag in
1596 the child process so that any grand-children start with all
1597 tracing flags cleared.
1601 proc_set_exec_trap ()
1605 auto char procname
[32];
1608 sprintf (procname
, PROC_NAME_FMT
, getpid ());
1609 if ((fd
= open (procname
, O_RDWR
)) < 0)
1612 gdb_flush (gdb_stderr
);
1615 premptyset (&exitset
);
1616 premptyset (&entryset
);
1619 Not all systems with /proc have all the exec* syscalls with the same
1620 names. On the SGI, for example, there is no SYS_exec, but there
1621 *is* a SYS_execv. So, we try to account for that. */
1624 praddset (&exitset
, SYS_exec
);
1627 praddset (&exitset
, SYS_execve
);
1630 praddset (&exitset
, SYS_execv
);
1633 if (ioctl (fd
, PIOCSEXIT
, &exitset
) < 0)
1636 gdb_flush (gdb_stderr
);
1640 praddset (&entryset
, SYS_exit
);
1642 if (ioctl (fd
, PIOCSENTRY
, &entryset
) < 0)
1645 gdb_flush (gdb_stderr
);
1649 /* Turn off inherit-on-fork flag so that all grand-children of gdb
1650 start with tracing flags cleared. */
1652 #if defined (PIOCRESET) /* New method */
1656 ioctl (fd
, PIOCRESET
, &pr_flags
);
1659 #if defined (PIOCRFORK) /* Original method */
1660 ioctl (fd
, PIOCRFORK
, NULL
);
1664 /* Turn on run-on-last-close flag so that this process will not hang
1665 if GDB goes away for some reason. */
1667 #if defined (PIOCSET) /* New method */
1671 (void) ioctl (fd
, PIOCSET
, &pr_flags
);
1674 #if defined (PIOCSRLC) /* Original method */
1675 (void) ioctl (fd
, PIOCSRLC
, 0);
1684 proc_iterate_over_mappings -- call function for every mapped space
1688 int proc_iterate_over_mappings (int (*func)())
1692 Given a pointer to a function, call that function for every
1693 mapped address space, passing it an open file descriptor for
1694 the file corresponding to that mapped address space (if any)
1695 and the base address of the mapped space. Quit when we hit
1696 the end of the mappings or the function returns nonzero.
1700 proc_iterate_over_mappings (func
)
1701 int (*func
) PARAMS ((int, CORE_ADDR
));
1706 struct prmap
*prmaps
;
1707 struct prmap
*prmap
;
1708 struct procinfo
*pi
;
1710 pi
= current_procinfo
;
1712 if (ioctl (pi
->fd
, PIOCNMAP
, &nmap
) == 0)
1714 prmaps
= (struct prmap
*) alloca ((nmap
+ 1) * sizeof (*prmaps
));
1715 if (ioctl (pi
->fd
, PIOCMAP
, prmaps
) == 0)
1717 for (prmap
= prmaps
; prmap
-> pr_size
&& funcstat
== 0; ++prmap
)
1719 fd
= proc_address_to_fd (pi
, (CORE_ADDR
) prmap
-> pr_vaddr
, 0);
1720 funcstat
= (*func
) (fd
, (CORE_ADDR
) prmap
-> pr_vaddr
);
1728 #if 0 /* Currently unused */
1733 proc_base_address -- find base address for segment containing address
1737 CORE_ADDR proc_base_address (CORE_ADDR addr)
1741 Given an address of a location in the inferior, find and return
1742 the base address of the mapped segment containing that address.
1744 This is used for example, by the shared library support code,
1745 where we have the pc value for some location in the shared library
1746 where we are stopped, and need to know the base address of the
1747 segment containing that address.
1751 proc_base_address (addr
)
1755 struct prmap
*prmaps
;
1756 struct prmap
*prmap
;
1757 CORE_ADDR baseaddr
= 0;
1758 struct procinfo
*pi
;
1760 pi
= current_procinfo
;
1762 if (ioctl (pi
->fd
, PIOCNMAP
, &nmap
) == 0)
1764 prmaps
= (struct prmap
*) alloca ((nmap
+ 1) * sizeof (*prmaps
));
1765 if (ioctl (pi
->fd
, PIOCMAP
, prmaps
) == 0)
1767 for (prmap
= prmaps
; prmap
-> pr_size
; ++prmap
)
1769 if ((prmap
-> pr_vaddr
<= (caddr_t
) addr
) &&
1770 (prmap
-> pr_vaddr
+ prmap
-> pr_size
> (caddr_t
) addr
))
1772 baseaddr
= (CORE_ADDR
) prmap
-> pr_vaddr
;
1787 proc_address_to_fd -- return open fd for file mapped to address
1791 int proc_address_to_fd (struct procinfo *pi, CORE_ADDR addr, complain)
1795 Given an address in the current inferior's address space, use the
1796 /proc interface to find an open file descriptor for the file that
1797 this address was mapped in from. Return -1 if there is no current
1798 inferior. Print a warning message if there is an inferior but
1799 the address corresponds to no file (IE a bogus address).
1804 proc_address_to_fd (pi
, addr
, complain
)
1805 struct procinfo
*pi
;
1811 if ((fd
= ioctl (pi
->fd
, PIOCOPENM
, (caddr_t
*) &addr
)) < 0)
1815 print_sys_errmsg (pi
->pathname
, errno
);
1816 warning ("can't find mapped file for address 0x%x", addr
);
1823 /* Attach to process PID, then initialize for debugging it
1824 and wait for the trace-trap that results from attaching. */
1827 procfs_attach (args
, from_tty
)
1835 error_no_arg ("process-id to attach");
1839 if (pid
== getpid()) /* Trying to masturbate? */
1840 error ("I refuse to debug myself!");
1844 exec_file
= (char *) get_exec_file (0);
1847 printf_unfiltered ("Attaching to program `%s', %s\n", exec_file
, target_pid_to_str (pid
));
1849 printf_unfiltered ("Attaching to %s\n", target_pid_to_str (pid
));
1851 gdb_flush (gdb_stdout
);
1856 push_target (&procfs_ops
);
1860 /* Take a program previously attached to and detaches it.
1861 The program resumes execution and will no longer stop
1862 on signals, etc. We'd better not have left any breakpoints
1863 in the program or it'll die when it hits one. For this
1864 to work, it may be necessary for the process to have been
1865 previously attached. It *might* work if the program was
1866 started via the normal ptrace (PTRACE_TRACEME). */
1869 procfs_detach (args
, from_tty
)
1877 char *exec_file
= get_exec_file (0);
1880 printf_unfiltered ("Detaching from program: %s %s\n",
1881 exec_file
, target_pid_to_str (inferior_pid
));
1882 gdb_flush (gdb_stdout
);
1885 siggnal
= atoi (args
);
1887 do_detach (siggnal
);
1889 unpush_target (&procfs_ops
); /* Pop out of handling an inferior */
1892 /* Get ready to modify the registers array. On machines which store
1893 individual registers, this doesn't need to do anything. On machines
1894 which store all the registers in one fell swoop, this makes sure
1895 that registers contains all the registers from the program being
1899 procfs_prepare_to_store ()
1901 #ifdef CHILD_PREPARE_TO_STORE
1902 CHILD_PREPARE_TO_STORE ();
1906 /* Print status information about what we're accessing. */
1909 procfs_files_info (ignore
)
1910 struct target_ops
*ignore
;
1912 printf_unfiltered ("\tUsing the running image of %s %s via /proc.\n",
1913 attach_flag
? "attached": "child", target_pid_to_str (inferior_pid
));
1918 procfs_open (arg
, from_tty
)
1922 error ("Use the \"run\" command to start a Unix child process.");
1929 do_attach -- attach to an already existing process
1933 int do_attach (int pid)
1937 Attach to an already existing process with the specified process
1938 id. If the process is not already stopped, query whether to
1943 The option of stopping at attach time is specific to the /proc
1944 versions of gdb. Versions using ptrace force the attachee
1945 to stop. (I have changed this version to do so, too. All you
1946 have to do is "continue" to make it go on. -- gnu@cygnus.com)
1955 struct procinfo
*pi
;
1957 pi
= (struct procinfo
*) xmalloc (sizeof (struct procinfo
));
1959 if (!open_proc_file (pid
, pi
, O_RDWR
))
1962 perror_with_name (pi
->pathname
);
1966 /* Add new process to process info list */
1968 pi
->next
= procinfo_list
;
1971 add_fd (pi
); /* Add to list for poll/select */
1973 /* Get current status of process and if it is not already stopped,
1974 then stop it. Remember whether or not it was stopped when we first
1977 if (ioctl (pi
->fd
, PIOCSTATUS
, &pi
->prstatus
) < 0)
1979 print_sys_errmsg (pi
->pathname
, errno
);
1980 close_proc_file (pi
);
1981 error ("PIOCSTATUS failed");
1983 if (pi
->prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
))
1985 pi
->was_stopped
= 1;
1989 pi
->was_stopped
= 0;
1990 if (1 || query ("Process is currently running, stop it? "))
1992 /* Make it run again when we close it. */
1993 #if defined (PIOCSET) /* New method */
1997 result
= ioctl (pi
->fd
, PIOCSET
, &pr_flags
);
2000 #if defined (PIOCSRLC) /* Original method */
2001 result
= ioctl (pi
->fd
, PIOCSRLC
, 0);
2006 print_sys_errmsg (pi
->pathname
, errno
);
2007 close_proc_file (pi
);
2008 error ("PIOCSRLC or PIOCSET failed");
2010 if (ioctl (pi
->fd
, PIOCSTOP
, &pi
->prstatus
) < 0)
2012 print_sys_errmsg (pi
->pathname
, errno
);
2013 close_proc_file (pi
);
2014 error ("PIOCSTOP failed");
2016 pi
->nopass_next_sigstop
= 1;
2020 printf_unfiltered ("Ok, gdb will wait for %s to stop.\n", target_pid_to_str (pid
));
2024 /* Remember some things about the inferior that we will, or might, change
2025 so that we can restore them when we detach. */
2027 ioctl (pi
->fd
, PIOCGTRACE
, &pi
->saved_trace
);
2028 ioctl (pi
->fd
, PIOCGHOLD
, &pi
->saved_sighold
);
2029 ioctl (pi
->fd
, PIOCGFAULT
, &pi
->saved_fltset
);
2030 ioctl (pi
->fd
, PIOCGENTRY
, &pi
->saved_entryset
);
2031 ioctl (pi
->fd
, PIOCGEXIT
, &pi
->saved_exitset
);
2033 /* Set up trace and fault sets, as gdb expects them. */
2035 memset (&pi
->prrun
, 0, sizeof (pi
->prrun
));
2036 prfillset (&pi
->prrun
.pr_trace
);
2037 procfs_notice_signals (pid
);
2038 prfillset (&pi
->prrun
.pr_fault
);
2039 prdelset (&pi
->prrun
.pr_fault
, FLTPAGE
);
2040 if (ioctl (pi
->fd
, PIOCSFAULT
, &pi
->prrun
.pr_fault
))
2042 print_sys_errmsg ("PIOCSFAULT failed", errno
);
2044 if (ioctl (pi
->fd
, PIOCSTRACE
, &pi
->prrun
.pr_trace
))
2046 print_sys_errmsg ("PIOCSTRACE failed", errno
);
2056 do_detach -- detach from an attached-to process
2060 void do_detach (int signal)
2064 Detach from the current attachee.
2066 If signal is non-zero, the attachee is started running again and sent
2067 the specified signal.
2069 If signal is zero and the attachee was not already stopped when we
2070 attached to it, then we make it runnable again when we detach.
2072 Otherwise, we query whether or not to make the attachee runnable
2073 again, since we may simply want to leave it in the state it was in
2076 We report any problems, but do not consider them errors, since we
2077 MUST detach even if some things don't seem to go right. This may not
2078 be the ideal situation. (FIXME).
2086 struct procinfo
*pi
;
2088 pi
= current_procinfo
;
2092 set_proc_siginfo (pi
, signal
);
2094 if (ioctl (pi
->fd
, PIOCSEXIT
, &pi
->saved_exitset
) < 0)
2096 print_sys_errmsg (pi
->pathname
, errno
);
2097 printf_unfiltered ("PIOCSEXIT failed.\n");
2099 if (ioctl (pi
->fd
, PIOCSENTRY
, &pi
->saved_entryset
) < 0)
2101 print_sys_errmsg (pi
->pathname
, errno
);
2102 printf_unfiltered ("PIOCSENTRY failed.\n");
2104 if (ioctl (pi
->fd
, PIOCSTRACE
, &pi
->saved_trace
) < 0)
2106 print_sys_errmsg (pi
->pathname
, errno
);
2107 printf_unfiltered ("PIOCSTRACE failed.\n");
2109 if (ioctl (pi
->fd
, PIOCSHOLD
, &pi
->saved_sighold
) < 0)
2111 print_sys_errmsg (pi
->pathname
, errno
);
2112 printf_unfiltered ("PIOSCHOLD failed.\n");
2114 if (ioctl (pi
->fd
, PIOCSFAULT
, &pi
->saved_fltset
) < 0)
2116 print_sys_errmsg (pi
->pathname
, errno
);
2117 printf_unfiltered ("PIOCSFAULT failed.\n");
2119 if (ioctl (pi
->fd
, PIOCSTATUS
, &pi
->prstatus
) < 0)
2121 print_sys_errmsg (pi
->pathname
, errno
);
2122 printf_unfiltered ("PIOCSTATUS failed.\n");
2126 if (signal
|| (pi
->prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
)))
2128 if (signal
|| !pi
->was_stopped
||
2129 query ("Was stopped when attached, make it runnable again? "))
2131 /* Clear any fault that might have stopped it. */
2132 if (ioctl (pi
->fd
, PIOCCFAULT
, 0))
2134 print_sys_errmsg (pi
->pathname
, errno
);
2135 printf_unfiltered ("PIOCCFAULT failed.\n");
2138 /* Make it run again when we close it. */
2139 #if defined (PIOCSET) /* New method */
2143 result
= ioctl (pi
->fd
, PIOCSET
, &pr_flags
);
2146 #if defined (PIOCSRLC) /* Original method */
2147 result
= ioctl (pi
->fd
, PIOCSRLC
, 0);
2152 print_sys_errmsg (pi
->pathname
, errno
);
2153 printf_unfiltered ("PIOCSRLC or PIOCSET failed.\n");
2158 close_proc_file (pi
);
2162 /* emulate wait() as much as possible.
2163 Wait for child to do something. Return pid of child, or -1 in case
2164 of error; store status in *OURSTATUS.
2166 Not sure why we can't
2167 just use wait(), but it seems to have problems when applied to a
2168 process being controlled with the /proc interface.
2170 We have a race problem here with no obvious solution. We need to let
2171 the inferior run until it stops on an event of interest, which means
2172 that we need to use the PIOCWSTOP ioctl. However, we cannot use this
2173 ioctl if the process is already stopped on something that is not an
2174 event of interest, or the call will hang indefinitely. Thus we first
2175 use PIOCSTATUS to see if the process is not stopped. If not, then we
2176 use PIOCWSTOP. But during the window between the two, if the process
2177 stops for any reason that is not an event of interest (such as a job
2178 control signal) then gdb will hang. One possible workaround is to set
2179 an alarm to wake up every minute of so and check to see if the process
2180 is still running, and if so, then reissue the PIOCWSTOP. But this is
2181 a real kludge, so has not been implemented. FIXME: investigate
2184 FIXME: Investigate why wait() seems to have problems with programs
2185 being control by /proc routines. */
2188 procfs_wait (pid
, ourstatus
)
2190 struct target_waitstatus
*ourstatus
;
2197 struct procinfo
*pi
;
2199 if (pid
!= -1) /* Non-specific process? */
2202 for (pi
= procinfo_list
; pi
; pi
= pi
->next
)
2214 for (pi
= procinfo_list
; pi
; pi
= pi
->next
)
2215 if (pi
->pid
== pid
&& pi
->had_event
)
2218 if (!pi
&& !checkerr
)
2221 if (!checkerr
&& !(pi
->prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
)))
2223 if (ioctl (pi
->fd
, PIOCWSTOP
, &pi
->prstatus
) < 0)
2230 if (errno
== ENOENT
)
2232 rtnval
= wait (&statval
);
2233 if (rtnval
!= inferior_pid
)
2235 print_sys_errmsg (pi
->pathname
, errno
);
2236 error ("PIOCWSTOP, wait failed, returned %d", rtnval
);
2242 print_sys_errmsg (pi
->pathname
, errno
);
2243 error ("PIOCSTATUS or PIOCWSTOP failed.");
2247 else if (pi
->prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
))
2249 rtnval
= pi
->prstatus
.pr_pid
;
2250 why
= pi
->prstatus
.pr_why
;
2251 what
= pi
->prstatus
.pr_what
;
2256 statval
= (what
<< 8) | 0177;
2259 if (what
!= SYS_exit
)
2260 error ("PR_SYSENTRY, unknown system call %d", what
);
2262 pi
->prrun
.pr_flags
= PRCFAULT
;
2264 if (ioctl (pi
->fd
, PIOCRUN
, &pi
->prrun
) != 0)
2265 perror_with_name (pi
->pathname
);
2267 rtnval
= wait (&statval
);
2282 statval
= (SIGTRAP
<< 8) | 0177;
2286 /* We've just detected the completion of an sproc system call. Now we need to
2287 setup a procinfo struct for this thread, and notify the thread system of the
2290 /* If sproc failed, then nothing interesting happened. Continue the process and
2291 go back to sleep. */
2293 if (pi
->prstatus
.pr_errno
!= 0)
2295 pi
->prrun
.pr_flags
&= PRSTEP
;
2296 pi
->prrun
.pr_flags
|= PRCFAULT
;
2298 if (ioctl (pi
->fd
, PIOCRUN
, &pi
->prrun
) != 0)
2299 perror_with_name (pi
->pathname
);
2304 /* At this point, the new thread is stopped at it's first instruction, and
2305 the parent is stopped at the exit from sproc. */
2307 /* Notify the caller of the arrival of a new thread. */
2308 create_procinfo (pi
->prstatus
.pr_rval1
);
2310 rtnval
= pi
->prstatus
.pr_rval1
;
2311 statval
= (SIGTRAP
<< 8) | 0177;
2318 /* At this point, we've detected the completion of a fork (or vfork) call in
2319 our child. The grandchild is also stopped because we set inherit-on-fork
2320 earlier. (Note that nobody has the grandchilds' /proc file open at this
2321 point.) We will release the grandchild from the debugger by opening it's
2322 /proc file and then closing it. Since run-on-last-close is set, the
2323 grandchild continues on its' merry way. */
2326 struct procinfo
*pitemp
;
2328 pitemp
= create_procinfo (pi
->prstatus
.pr_rval1
);
2330 close_proc_file (pitemp
);
2332 if (ioctl (pi
->fd
, PIOCRUN
, &pi
->prrun
) != 0)
2333 perror_with_name (pi
->pathname
);
2336 #endif /* SYS_sproc */
2339 error ("PIOCSTATUS (PR_SYSEXIT): Unknown system call %d", what
);
2343 statval
= (SIGSTOP
<< 8) | 0177;
2346 statval
= (what
<< 8) | 0177;
2353 statval
= (SIGTRAP
<< 8) | 0177;
2358 statval
= (SIGTRAP
<< 8) | 0177;
2361 #ifndef FAULTED_USE_SIGINFO
2362 /* Irix, contrary to the documentation, fills in 0 for si_signo.
2363 Solaris fills in si_signo. I'm not sure about others. */
2366 statval
= (SIGILL
<< 8) | 0177;
2370 statval
= (SIGTRAP
<< 8) | 0177;
2375 statval
= (SIGSEGV
<< 8) | 0177;
2380 statval
= (SIGFPE
<< 8) | 0177;
2382 case FLTPAGE
: /* Recoverable page fault */
2383 #endif /* not FAULTED_USE_SIGINFO */
2385 /* Use the signal which the kernel assigns. This is better than
2386 trying to second-guess it from the fault. In fact, I suspect
2387 that FLTACCESS can be either SIGSEGV or SIGBUS. */
2388 statval
= ((pi
->prstatus
.pr_info
.si_signo
) << 8) | 0177;
2393 error ("PIOCWSTOP, unknown why %d, what %d", why
, what
);
2395 /* Stop all the other threads when any of them stops. */
2398 struct procinfo
*procinfo
;
2400 for (procinfo
= procinfo_list
; procinfo
; procinfo
= procinfo
->next
)
2402 if (!procinfo
->had_event
)
2403 if (ioctl (procinfo
->fd
, PIOCSTOP
, &procinfo
->prstatus
) < 0)
2405 print_sys_errmsg (procinfo
->pathname
, errno
);
2406 error ("PIOCSTOP failed");
2413 error ("PIOCWSTOP, stopped for unknown/unhandled reason, flags %#x",
2414 pi
->prstatus
.pr_flags
);
2417 store_waitstatus (ourstatus
, statval
);
2419 if (rtnval
== -1) /* No more children to wait for */
2421 fprintf_unfiltered (gdb_stderr
, "Child process unexpectedly missing.\n");
2422 /* Claim it exited with unknown signal. */
2423 ourstatus
->kind
= TARGET_WAITKIND_SIGNALLED
;
2424 ourstatus
->value
.sig
= TARGET_SIGNAL_UNKNOWN
;
2428 pi
->had_event
= 0; /* Indicate that we've seen this one */
2436 set_proc_siginfo - set a process's current signal info
2440 void set_proc_siginfo (struct procinfo *pip, int signo);
2444 Given a pointer to a process info struct in PIP and a signal number
2445 in SIGNO, set the process's current signal and its associated signal
2446 information. The signal will be delivered to the process immediately
2447 after execution is resumed, even if it is being held. In addition,
2448 this particular delivery will not cause another PR_SIGNALLED stop
2449 even if the signal is being traced.
2451 If we are not delivering the same signal that the prstatus siginfo
2452 struct contains information about, then synthesize a siginfo struct
2453 to match the signal we are doing to deliver, make it of the type
2454 "generated by a user process", and send this synthesized copy. When
2455 used to set the inferior's signal state, this will be required if we
2456 are not currently stopped because of a traced signal, or if we decide
2457 to continue with a different signal.
2459 Note that when continuing the inferior from a stop due to receipt
2460 of a traced signal, we either have set PRCSIG to clear the existing
2461 signal, or we have to call this function to do a PIOCSSIG with either
2462 the existing siginfo struct from pr_info, or one we have synthesized
2463 appropriately for the signal we want to deliver. Otherwise if the
2464 signal is still being traced, the inferior will immediately stop
2467 See siginfo(5) for more details.
2471 set_proc_siginfo (pip
, signo
)
2472 struct procinfo
*pip
;
2475 struct siginfo newsiginfo
;
2476 struct siginfo
*sip
;
2478 if (signo
== pip
-> prstatus
.pr_info
.si_signo
)
2480 sip
= &pip
-> prstatus
.pr_info
;
2484 memset ((char *) &newsiginfo
, 0, sizeof (newsiginfo
));
2486 sip
-> si_signo
= signo
;
2488 sip
-> si_errno
= 0;
2489 sip
-> si_pid
= getpid ();
2490 sip
-> si_uid
= getuid ();
2492 if (ioctl (pip
-> fd
, PIOCSSIG
, sip
) < 0)
2494 print_sys_errmsg (pip
-> pathname
, errno
);
2495 warning ("PIOCSSIG failed");
2499 /* Resume execution of process PID. If STEP is nozero, then
2500 just single step it. If SIGNAL is nonzero, restart it with that
2501 signal activated. */
2504 procfs_resume (pid
, step
, signo
)
2507 enum target_signal signo
;
2510 struct procinfo
*pi
, *procinfo
;
2512 pi
= find_procinfo (pid
== -1 ? inferior_pid
: pid
, 0);
2515 pi
->prrun
.pr_flags
= PRSTRACE
| PRSFAULT
| PRCFAULT
;
2518 /* It should not be necessary. If the user explicitly changes the value,
2519 value_assign calls write_register_bytes, which writes it. */
2520 /* It may not be absolutely necessary to specify the PC value for
2521 restarting, but to be safe we use the value that gdb considers
2522 to be current. One case where this might be necessary is if the
2523 user explicitly changes the PC value that gdb considers to be
2524 current. FIXME: Investigate if this is necessary or not. */
2526 #ifdef PRSVADDR_BROKEN
2527 /* Can't do this under Solaris running on a Sparc, as there seems to be no
2528 place to put nPC. In fact, if you use this, nPC seems to be set to some
2529 random garbage. We have to rely on the fact that PC and nPC have been
2530 written previously via PIOCSREG during a register flush. */
2532 pi
->prrun
.pr_vaddr
= (caddr_t
) *(int *) ®isters
[REGISTER_BYTE (PC_REGNUM
)];
2533 pi
->prrun
.pr_flags
!= PRSVADDR
;
2537 if (signo
== TARGET_SIGNAL_STOP
&& pi
->nopass_next_sigstop
)
2538 /* When attaching to a child process, if we forced it to stop with
2539 a PIOCSTOP, then we will have set the nopass_next_sigstop flag.
2540 Upon resuming the first time after such a stop, we explicitly
2541 inhibit sending it another SIGSTOP, which would be the normal
2542 result of default signal handling. One potential drawback to
2543 this is that we will also ignore any attempt to by the user
2544 to explicitly continue after the attach with a SIGSTOP. Ultimately
2545 this problem should be dealt with by making the routines that
2546 deal with the inferior a little smarter, and possibly even allow
2547 an inferior to continue running at the same time as gdb. (FIXME?) */
2549 else if (signo
== TARGET_SIGNAL_TSTP
2550 && pi
->prstatus
.pr_cursig
== SIGTSTP
2551 && pi
->prstatus
.pr_action
.sa_handler
== SIG_DFL
)
2553 /* We are about to pass the inferior a SIGTSTP whose action is
2554 SIG_DFL. The SIG_DFL action for a SIGTSTP is to stop
2555 (notifying the parent via wait()), and then keep going from the
2556 same place when the parent is ready for you to keep going. So
2557 under the debugger, it should do nothing (as if the program had
2558 been stopped and then later resumed. Under ptrace, this
2559 happens for us, but under /proc, the system obligingly stops
2560 the process, and wait_for_inferior would have no way of
2561 distinguishing that type of stop (which indicates that we
2562 should just start it again), with a stop due to the pr_trace
2563 field of the prrun_t struct.
2565 Note that if the SIGTSTP is being caught, we *do* need to pass it,
2566 because the handler needs to get executed. */
2569 signal_to_pass
= target_signal_to_host (signo
);
2573 set_proc_siginfo (pi
, signal_to_pass
);
2577 pi
->prrun
.pr_flags
|= PRCSIG
;
2579 pi
->nopass_next_sigstop
= 0;
2582 pi
->prrun
.pr_flags
|= PRSTEP
;
2584 if (ioctl (pi
->fd
, PIOCRUN
, &pi
->prrun
) != 0)
2586 perror_with_name (pi
->pathname
);
2592 /* Continue all the other threads that haven't had an event of
2596 for (procinfo
= procinfo_list
; procinfo
; procinfo
= procinfo
->next
)
2598 if (pi
!= procinfo
&& !procinfo
->had_event
)
2600 procinfo
->prrun
.pr_flags
&= PRSTEP
;
2601 procinfo
->prrun
.pr_flags
|= PRCFAULT
| PRCSIG
;
2602 ioctl (procinfo
->fd
, PIOCSTATUS
, &procinfo
->prstatus
);
2603 if (ioctl (procinfo
->fd
, PIOCRUN
, &procinfo
->prrun
) < 0)
2605 if (ioctl (procinfo
->fd
, PIOCSTATUS
, &procinfo
->prstatus
) < 0)
2607 fprintf_unfiltered(gdb_stderr
, "PIOCSTATUS failed, errno=%d\n", errno
);
2609 print_sys_errmsg (procinfo
->pathname
, errno
);
2610 error ("PIOCRUN failed");
2612 ioctl (procinfo
->fd
, PIOCSTATUS
, &procinfo
->prstatus
);
2621 procfs_fetch_registers -- fetch current registers from inferior
2625 void procfs_fetch_registers (int regno)
2629 Read the current values of the inferior's registers, both the
2630 general register set and floating point registers (if supported)
2631 and update gdb's idea of their current values.
2636 procfs_fetch_registers (regno
)
2639 struct procinfo
*pi
;
2641 pi
= current_procinfo
;
2643 if (ioctl (pi
->fd
, PIOCGREG
, &pi
->gregset
) != -1)
2645 supply_gregset (&pi
->gregset
);
2647 #if defined (FP0_REGNUM)
2648 if (ioctl (pi
->fd
, PIOCGFPREG
, &pi
->fpregset
) != -1)
2650 supply_fpregset (&pi
->fpregset
);
2659 proc_init_failed - called whenever /proc access initialization
2664 static void proc_init_failed (struct procinfo *pi, char *why)
2668 This function is called whenever initialization of access to a /proc
2669 entry fails. It prints a suitable error message, does some cleanup,
2670 and then invokes the standard error processing routine which dumps
2671 us back into the command loop.
2675 proc_init_failed (pi
, why
)
2676 struct procinfo
*pi
;
2679 print_sys_errmsg (pi
->pathname
, errno
);
2680 kill (pi
->pid
, SIGKILL
);
2681 close_proc_file (pi
);
2690 close_proc_file - close any currently open /proc entry
2694 static void close_proc_file (struct procinfo *pip)
2698 Close any currently open /proc entry and mark the process information
2699 entry as invalid. In order to ensure that we don't try to reuse any
2700 stale information, the pid, fd, and pathnames are explicitly
2701 invalidated, which may be overkill.
2706 close_proc_file (pip
)
2707 struct procinfo
*pip
;
2709 struct procinfo
*procinfo
;
2711 remove_fd (pip
); /* Remove fd from poll/select list */
2715 free (pip
-> pathname
);
2717 /* Unlink pip from the procinfo chain. Note pip might not be on the list. */
2719 if (procinfo_list
== pip
)
2720 procinfo_list
= pip
->next
;
2722 for (procinfo
= procinfo_list
; procinfo
; procinfo
= procinfo
->next
)
2723 if (procinfo
->next
== pip
)
2724 procinfo
->next
= pip
->next
;
2733 open_proc_file - open a /proc entry for a given process id
2737 static int open_proc_file (int pid, struct procinfo *pip, int mode)
2741 Given a process id and a mode, close the existing open /proc
2742 entry (if any) and open one for the new process id, in the
2743 specified mode. Once it is open, then mark the local process
2744 information structure as valid, which guarantees that the pid,
2745 fd, and pathname fields match an open /proc entry. Returns
2746 zero if the open fails, nonzero otherwise.
2748 Note that the pathname is left intact, even when the open fails,
2749 so that callers can use it to construct meaningful error messages
2750 rather than just "file open failed".
2754 open_proc_file (pid
, pip
, mode
)
2756 struct procinfo
*pip
;
2760 pip
-> had_event
= 0;
2761 pip
-> pathname
= xmalloc (32);
2764 sprintf (pip
-> pathname
, PROC_NAME_FMT
, pid
);
2765 if ((pip
-> fd
= open (pip
-> pathname
, mode
)) < 0)
2772 mappingflags (flags
)
2775 static char asciiflags
[8];
2777 strcpy (asciiflags
, "-------");
2778 #if defined (MA_PHYS)
2779 if (flags
& MA_PHYS
) asciiflags
[0] = 'd';
2781 if (flags
& MA_STACK
) asciiflags
[1] = 's';
2782 if (flags
& MA_BREAK
) asciiflags
[2] = 'b';
2783 if (flags
& MA_SHARED
) asciiflags
[3] = 's';
2784 if (flags
& MA_READ
) asciiflags
[4] = 'r';
2785 if (flags
& MA_WRITE
) asciiflags
[5] = 'w';
2786 if (flags
& MA_EXEC
) asciiflags
[6] = 'x';
2787 return (asciiflags
);
2791 info_proc_flags (pip
, summary
)
2792 struct procinfo
*pip
;
2795 struct trans
*transp
;
2797 printf_filtered ("%-32s", "Process status flags:");
2800 printf_filtered ("\n\n");
2802 for (transp
= pr_flag_table
; transp
-> name
!= NULL
; transp
++)
2804 if (pip
-> prstatus
.pr_flags
& transp
-> value
)
2808 printf_filtered ("%s ", transp
-> name
);
2812 printf_filtered ("\t%-16s %s.\n", transp
-> name
, transp
-> desc
);
2816 printf_filtered ("\n");
2820 info_proc_stop (pip
, summary
)
2821 struct procinfo
*pip
;
2824 struct trans
*transp
;
2828 why
= pip
-> prstatus
.pr_why
;
2829 what
= pip
-> prstatus
.pr_what
;
2831 if (pip
-> prstatus
.pr_flags
& PR_STOPPED
)
2833 printf_filtered ("%-32s", "Reason for stopping:");
2836 printf_filtered ("\n\n");
2838 for (transp
= pr_why_table
; transp
-> name
!= NULL
; transp
++)
2840 if (why
== transp
-> value
)
2844 printf_filtered ("%s ", transp
-> name
);
2848 printf_filtered ("\t%-16s %s.\n",
2849 transp
-> name
, transp
-> desc
);
2855 /* Use the pr_why field to determine what the pr_what field means, and
2856 print more information. */
2861 /* pr_what is unused for this case */
2867 printf_filtered ("%s ", signalname (what
));
2871 printf_filtered ("\t%-16s %s.\n", signalname (what
),
2872 safe_strsignal (what
));
2878 printf_filtered ("%s ", syscallname (what
));
2882 printf_filtered ("\t%-16s %s.\n", syscallname (what
),
2883 "Entered this system call");
2889 printf_filtered ("%s ", syscallname (what
));
2893 printf_filtered ("\t%-16s %s.\n", syscallname (what
),
2894 "Returned from this system call");
2900 printf_filtered ("%s ",
2901 lookupname (faults_table
, what
, "fault"));
2905 printf_filtered ("\t%-16s %s.\n",
2906 lookupname (faults_table
, what
, "fault"),
2907 lookupdesc (faults_table
, what
));
2911 printf_filtered ("\n");
2916 info_proc_siginfo (pip
, summary
)
2917 struct procinfo
*pip
;
2920 struct siginfo
*sip
;
2922 if ((pip
-> prstatus
.pr_flags
& PR_STOPPED
) &&
2923 (pip
-> prstatus
.pr_why
== PR_SIGNALLED
||
2924 pip
-> prstatus
.pr_why
== PR_FAULTED
))
2926 printf_filtered ("%-32s", "Additional signal/fault info:");
2927 sip
= &pip
-> prstatus
.pr_info
;
2930 printf_filtered ("%s ", signalname (sip
-> si_signo
));
2931 if (sip
-> si_errno
> 0)
2933 printf_filtered ("%s ", errnoname (sip
-> si_errno
));
2935 if (sip
-> si_code
<= 0)
2937 printf_filtered ("sent by %s, uid %d ",
2938 target_pid_to_str (sip
-> si_pid
),
2943 printf_filtered ("%s ", sigcodename (sip
));
2944 if ((sip
-> si_signo
== SIGILL
) ||
2945 (sip
-> si_signo
== SIGFPE
) ||
2946 (sip
-> si_signo
== SIGSEGV
) ||
2947 (sip
-> si_signo
== SIGBUS
))
2949 printf_filtered ("addr=%#x ", sip
-> si_addr
);
2951 else if ((sip
-> si_signo
== SIGCHLD
))
2953 printf_filtered ("child %s, status %u ",
2954 target_pid_to_str (sip
-> si_pid
),
2957 else if ((sip
-> si_signo
== SIGPOLL
))
2959 printf_filtered ("band %u ", sip
-> si_band
);
2965 printf_filtered ("\n\n");
2966 printf_filtered ("\t%-16s %s.\n", signalname (sip
-> si_signo
),
2967 safe_strsignal (sip
-> si_signo
));
2968 if (sip
-> si_errno
> 0)
2970 printf_filtered ("\t%-16s %s.\n",
2971 errnoname (sip
-> si_errno
),
2972 safe_strerror (sip
-> si_errno
));
2974 if (sip
-> si_code
<= 0)
2976 printf_filtered ("\t%-16u %s\n", sip
-> si_pid
, /* XXX need target_pid_to_str() */
2977 "PID of process sending signal");
2978 printf_filtered ("\t%-16u %s\n", sip
-> si_uid
,
2979 "UID of process sending signal");
2983 printf_filtered ("\t%-16s %s.\n", sigcodename (sip
),
2985 if ((sip
-> si_signo
== SIGILL
) ||
2986 (sip
-> si_signo
== SIGFPE
))
2988 printf_filtered ("\t%-16#x %s.\n", sip
-> si_addr
,
2989 "Address of faulting instruction");
2991 else if ((sip
-> si_signo
== SIGSEGV
) ||
2992 (sip
-> si_signo
== SIGBUS
))
2994 printf_filtered ("\t%-16#x %s.\n", sip
-> si_addr
,
2995 "Address of faulting memory reference");
2997 else if ((sip
-> si_signo
== SIGCHLD
))
2999 printf_filtered ("\t%-16u %s.\n", sip
-> si_pid
, /* XXX need target_pid_to_str() */
3000 "Child process ID");
3001 printf_filtered ("\t%-16u %s.\n", sip
-> si_status
,
3002 "Child process exit value or signal");
3004 else if ((sip
-> si_signo
== SIGPOLL
))
3006 printf_filtered ("\t%-16u %s.\n", sip
-> si_band
,
3007 "Band event for POLL_{IN,OUT,MSG}");
3011 printf_filtered ("\n");
3016 info_proc_syscalls (pip
, summary
)
3017 struct procinfo
*pip
;
3025 #if 0 /* FIXME: Needs to use gdb-wide configured info about system calls. */
3026 if (pip
-> prstatus
.pr_flags
& PR_ASLEEP
)
3028 int syscallnum
= pip
-> prstatus
.pr_reg
[R_D0
];
3031 printf_filtered ("%-32s", "Sleeping in system call:");
3032 printf_filtered ("%s", syscallname (syscallnum
));
3036 printf_filtered ("Sleeping in system call '%s'.\n",
3037 syscallname (syscallnum
));
3042 if (ioctl (pip
-> fd
, PIOCGENTRY
, &pip
-> entryset
) < 0)
3044 print_sys_errmsg (pip
-> pathname
, errno
);
3045 error ("PIOCGENTRY failed");
3048 if (ioctl (pip
-> fd
, PIOCGEXIT
, &pip
-> exitset
) < 0)
3050 print_sys_errmsg (pip
-> pathname
, errno
);
3051 error ("PIOCGEXIT failed");
3054 printf_filtered ("System call tracing information:\n\n");
3056 printf_filtered ("\t%-12s %-8s %-8s\n",
3060 for (syscallnum
= 0; syscallnum
< MAX_SYSCALLS
; syscallnum
++)
3063 if (syscall_table
[syscallnum
] != NULL
)
3065 printf_filtered ("\t%-12s ", syscall_table
[syscallnum
]);
3066 printf_filtered ("%-8s ",
3067 prismember (&pip
-> entryset
, syscallnum
)
3069 printf_filtered ("%-8s ",
3070 prismember (&pip
-> exitset
, syscallnum
)
3072 printf_filtered ("\n");
3075 printf_filtered ("\n");
3084 static char locbuf
[32];
3086 name
= strsigno (signo
);
3089 sprintf (locbuf
, "Signal %d", signo
);
3093 sprintf (locbuf
, "%s (%d)", name
, signo
);
3103 static char locbuf
[32];
3105 name
= strerrno (errnum
);
3108 sprintf (locbuf
, "Errno %d", errnum
);
3112 sprintf (locbuf
, "%s (%d)", name
, errnum
);
3118 info_proc_signals (pip
, summary
)
3119 struct procinfo
*pip
;
3126 if (ioctl (pip
-> fd
, PIOCGTRACE
, &pip
-> trace
) < 0)
3128 print_sys_errmsg (pip
-> pathname
, errno
);
3129 error ("PIOCGTRACE failed");
3132 printf_filtered ("Disposition of signals:\n\n");
3133 printf_filtered ("\t%-15s %-8s %-8s %-8s %s\n\n",
3134 "Signal", "Trace", "Hold", "Pending", "Description");
3135 for (signo
= 0; signo
< NSIG
; signo
++)
3138 printf_filtered ("\t%-15s ", signalname (signo
));
3139 printf_filtered ("%-8s ",
3140 prismember (&pip
-> trace
, signo
)
3142 printf_filtered ("%-8s ",
3143 prismember (&pip
-> prstatus
.pr_sighold
, signo
)
3145 printf_filtered ("%-8s ",
3146 prismember (&pip
-> prstatus
.pr_sigpend
, signo
)
3148 printf_filtered (" %s\n", safe_strsignal (signo
));
3150 printf_filtered ("\n");
3155 info_proc_faults (pip
, summary
)
3156 struct procinfo
*pip
;
3159 struct trans
*transp
;
3163 if (ioctl (pip
-> fd
, PIOCGFAULT
, &pip
-> fltset
) < 0)
3165 print_sys_errmsg (pip
-> pathname
, errno
);
3166 error ("PIOCGFAULT failed");
3169 printf_filtered ("Current traced hardware fault set:\n\n");
3170 printf_filtered ("\t%-12s %-8s\n", "Fault", "Trace");
3172 for (transp
= faults_table
; transp
-> name
!= NULL
; transp
++)
3175 printf_filtered ("\t%-12s ", transp
-> name
);
3176 printf_filtered ("%-8s", prismember (&pip
-> fltset
, transp
-> value
)
3178 printf_filtered ("\n");
3180 printf_filtered ("\n");
3185 info_proc_mappings (pip
, summary
)
3186 struct procinfo
*pip
;
3190 struct prmap
*prmaps
;
3191 struct prmap
*prmap
;
3195 printf_filtered ("Mapped address spaces:\n\n");
3196 printf_filtered ("\t%10s %10s %10s %10s %7s\n",
3202 if (ioctl (pip
-> fd
, PIOCNMAP
, &nmap
) == 0)
3204 prmaps
= (struct prmap
*) alloca ((nmap
+ 1) * sizeof (*prmaps
));
3205 if (ioctl (pip
-> fd
, PIOCMAP
, prmaps
) == 0)
3207 for (prmap
= prmaps
; prmap
-> pr_size
; ++prmap
)
3209 printf_filtered ("\t%#10x %#10x %#10x %#10x %7s\n",
3211 prmap
-> pr_vaddr
+ prmap
-> pr_size
- 1,
3214 mappingflags (prmap
-> pr_mflags
));
3218 printf_filtered ("\n");
3226 info_proc -- implement the "info proc" command
3230 void info_proc (char *args, int from_tty)
3234 Implement gdb's "info proc" command by using the /proc interface
3235 to print status information about any currently running process.
3237 Examples of the use of "info proc" are:
3239 info proc (prints summary info for current inferior)
3240 info proc 123 (prints summary info for process with pid 123)
3241 info proc mappings (prints address mappings)
3242 info proc times (prints process/children times)
3243 info proc id (prints pid, ppid, gid, sid, etc)
3244 FIXME: i proc id not implemented.
3245 info proc status (prints general process state info)
3246 FIXME: i proc status not implemented.
3247 info proc signals (prints info about signal handling)
3248 info proc all (prints all info)
3253 info_proc (args
, from_tty
)
3258 struct procinfo
*pip
;
3259 struct cleanup
*old_chain
;
3273 old_chain
= make_cleanup (null_cleanup
, 0);
3275 /* Default to using the current inferior if no pid specified. Note
3276 that inferior_pid may be 0, hence we set okerr. */
3278 pip
= find_procinfo (inferior_pid
, 1);
3282 if ((argv
= buildargv (args
)) == NULL
)
3286 make_cleanup (freeargv
, (char *) argv
);
3288 while (*argv
!= NULL
)
3290 argsize
= strlen (*argv
);
3291 if (argsize
>= 1 && strncmp (*argv
, "all", argsize
) == 0)
3296 else if (argsize
>= 2 && strncmp (*argv
, "faults", argsize
) == 0)
3301 else if (argsize
>= 2 && strncmp (*argv
, "flags", argsize
) == 0)
3306 else if (argsize
>= 1 && strncmp (*argv
, "id", argsize
) == 0)
3311 else if (argsize
>= 1 && strncmp (*argv
, "mappings", argsize
) == 0)
3316 else if (argsize
>= 2 && strncmp (*argv
, "signals", argsize
) == 0)
3321 else if (argsize
>= 2 && strncmp (*argv
, "status", argsize
) == 0)
3326 else if (argsize
>= 2 && strncmp (*argv
, "syscalls", argsize
) == 0)
3331 else if (argsize
>= 1 && strncmp (*argv
, "times", argsize
) == 0)
3336 else if ((pid
= atoi (*argv
)) > 0)
3338 pip
= (struct procinfo
*) xmalloc (sizeof (struct procinfo
));
3339 memset (pip
, 0, sizeof (*pip
));
3342 if (!open_proc_file (pid
, pip
, O_RDONLY
))
3344 perror_with_name (pip
-> pathname
);
3347 make_cleanup (close_proc_file
, pip
);
3349 else if (**argv
!= '\000')
3351 error ("Unrecognized or ambiguous keyword `%s'.", *argv
);
3357 /* If we don't have a valid open process at this point, then we have no
3358 inferior or didn't specify a specific pid. */
3363 No process. Start debugging a program or specify an explicit process ID.");
3365 if (ioctl (pip
-> fd
, PIOCSTATUS
, &(pip
-> prstatus
)) < 0)
3367 print_sys_errmsg (pip
-> pathname
, errno
);
3368 error ("PIOCSTATUS failed");
3371 /* Print verbose information of the requested type(s), or just a summary
3372 of the information for all types. */
3374 printf_filtered ("\nInformation for %s:\n\n", pip
-> pathname
);
3375 if (summary
|| all
|| flags
)
3377 info_proc_flags (pip
, summary
);
3381 info_proc_stop (pip
, summary
);
3383 if (summary
|| all
|| signals
|| faults
)
3385 info_proc_siginfo (pip
, summary
);
3387 if (summary
|| all
|| syscalls
)
3389 info_proc_syscalls (pip
, summary
);
3391 if (summary
|| all
|| mappings
)
3393 info_proc_mappings (pip
, summary
);
3395 if (summary
|| all
|| signals
)
3397 info_proc_signals (pip
, summary
);
3399 if (summary
|| all
|| faults
)
3401 info_proc_faults (pip
, summary
);
3403 printf_filtered ("\n");
3405 /* All done, deal with closing any temporary process info structure,
3406 freeing temporary memory , etc. */
3408 do_cleanups (old_chain
);
3415 procfs_set_sproc_trap -- arrange for child to stop on sproc().
3419 void procfs_set_sproc_trap (struct procinfo *)
3423 This function sets up a trap on sproc system call exits so that we can
3424 detect the arrival of a new thread. We are called with the new thread
3425 stopped prior to it's first instruction.
3427 Also note that we turn on the inherit-on-fork flag in the child process
3428 so that any grand-children start with all tracing flags set.
3434 procfs_set_sproc_trap (pi
)
3435 struct procinfo
*pi
;
3439 if (ioctl (pi
->fd
, PIOCGEXIT
, &exitset
) < 0)
3441 print_sys_errmsg (pi
->pathname
, errno
);
3442 error ("PIOCGEXIT failed");
3445 praddset (&exitset
, SYS_sproc
);
3447 /* We trap on fork() and vfork() in order to disable debugging in our grand-
3448 children and descendant processes. At this time, GDB can only handle
3449 threads (multiple processes, one address space). forks (and execs) result
3450 in the creation of multiple address spaces, which GDB can't handle yet. */
3452 praddset (&exitset
, SYS_fork
);
3454 praddset (&exitset
, SYS_vfork
);
3457 if (ioctl (pi
->fd
, PIOCSEXIT
, &exitset
) < 0)
3459 print_sys_errmsg (pi
->pathname
, errno
);
3460 error ("PIOCSEXIT failed");
3463 /* Turn on inherit-on-fork flag so that all grand-children of gdb start with
3464 tracing flags set. */
3466 #ifdef PIOCSET /* New method */
3470 ioctl (pi
->fd
, PIOCSET
, &pr_flags
);
3473 #ifdef PIOCSFORK /* Original method */
3474 ioctl (pi
->fd
, PIOCSFORK
, NULL
);
3478 #endif /* SYS_sproc */
3480 /* Fork an inferior process, and start debugging it with /proc. */
3483 procfs_create_inferior (exec_file
, allargs
, env
)
3488 char *shell_file
= getenv ("SHELL");
3490 if (shell_file
!= NULL
&& strchr (shell_file
, '/') == NULL
)
3493 /* We will be looking down the PATH to find shell_file. If we
3494 just do this the normal way (via execlp, which operates by
3495 attempting an exec for each element of the PATH until it
3496 finds one which succeeds), then there will be an exec for
3497 each failed attempt, each of which will cause a PR_SYSEXIT
3498 stop, and we won't know how to distinguish the PR_SYSEXIT's
3499 for these failed execs with the ones for successful execs
3500 (whether the exec has succeeded is stored at that time in the
3501 carry bit or some such architecture-specific and
3502 non-ABI-specified place).
3504 So I can't think of anything better than to search the PATH
3505 now. This has several disadvantages: (1) There is a race
3506 condition; if we find a file now and it is deleted before we
3507 exec it, we lose, even if the deletion leaves a valid file
3508 further down in the PATH, (2) there is no way to know exactly
3509 what an executable (in the sense of "capable of being
3510 exec'd") file is. Using access() loses because it may lose
3511 if the caller is the superuser; failing to use it loses if
3512 there are ACLs or some such. */
3516 /* FIXME-maybe: might want "set path" command so user can change what
3517 path is used from within GDB. */
3518 char *path
= getenv ("PATH");
3520 struct stat statbuf
;
3523 path
= "/bin:/usr/bin";
3525 tryname
= alloca (strlen (path
) + strlen (shell_file
) + 2);
3526 for (p
= path
; p
!= NULL
; p
= p1
? p1
+ 1: NULL
)
3528 p1
= strchr (p
, ':');
3533 strncpy (tryname
, p
, len
);
3534 tryname
[len
] = '\0';
3535 strcat (tryname
, "/");
3536 strcat (tryname
, shell_file
);
3537 if (access (tryname
, X_OK
) < 0)
3539 if (stat (tryname
, &statbuf
) < 0)
3541 if (!S_ISREG (statbuf
.st_mode
))
3542 /* We certainly need to reject directories. I'm not quite
3543 as sure about FIFOs, sockets, etc., but I kind of doubt
3544 that people want to exec() these things. */
3549 /* Not found. This must be an error rather than merely passing
3550 the file to execlp(), because execlp() would try all the
3551 exec()s, causing GDB to get confused. */
3552 error ("Can't find shell %s in PATH", shell_file
);
3554 shell_file
= tryname
;
3557 fork_inferior (exec_file
, allargs
, env
,
3558 proc_set_exec_trap
, procfs_init_inferior
, shell_file
);
3560 /* We are at the first instruction we care about. */
3561 /* Pedal to the metal... */
3563 /* Setup traps on exit from sproc() */
3566 procfs_set_sproc_trap (current_procinfo
);
3569 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_0
, 0);
3572 /* Clean up after the inferior dies. */
3575 procfs_mourn_inferior ()
3577 struct procinfo
*pi
;
3578 struct procinfo
*next_pi
;
3580 for (pi
= procinfo_list
; pi
; pi
= next_pi
)
3583 unconditionally_kill_inferior (pi
);
3586 unpush_target (&procfs_ops
);
3587 generic_mourn_inferior ();
3591 /* Mark our target-struct as eligible for stray "run" and "attach" commands. */
3597 #ifdef TARGET_CAN_USE_HARDWARE_WATCHPOINT
3599 /* Insert a watchpoint */
3601 procfs_set_watchpoint(pid
, addr
, len
, rw
)
3607 struct procinfo
*pi
;
3610 pi
= find_procinfo (pid
== -1 ? inferior_pid
: pid
, 0);
3611 wpt
.pr_vaddr
= (caddr_t
)addr
;
3613 wpt
.pr_wflags
= ((rw
& 1) ? MA_READ
: 0) | ((rw
& 2) ? MA_WRITE
: 0);
3614 if (ioctl (pi
->fd
, PIOCSWATCH
, &wpt
) < 0)
3618 /* Currently it sometimes happens that the same watchpoint gets
3619 deleted twice - don't die in this case (FIXME please) */
3620 if (errno
== ESRCH
&& len
== 0)
3622 print_sys_errmsg (pi
->pathname
, errno
);
3623 error ("PIOCSWATCH failed");
3629 procfs_stopped_by_watchpoint(pid
)
3632 struct procinfo
*pi
;
3636 pi
= find_procinfo (pid
== -1 ? inferior_pid
: pid
, 0);
3637 if (pi
->prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
))
3639 why
= pi
->prstatus
.pr_why
;
3640 what
= pi
->prstatus
.pr_what
;
3641 if (why
== PR_FAULTED
3642 #if defined (FLTWATCH) && defined (FLTKWATCH)
3643 && (what
== FLTWATCH
) || (what
== FLTKWATCH
)
3646 && (what
== FLTWATCH
)
3649 && (what
== FLTKWATCH
)
3660 struct target_ops procfs_ops
= {
3661 "procfs", /* to_shortname */
3662 "Unix /proc child process", /* to_longname */
3663 "Unix /proc child process (started by the \"run\" command).", /* to_doc */
3664 procfs_open
, /* to_open */
3666 procfs_attach
, /* to_attach */
3667 procfs_detach
, /* to_detach */
3668 procfs_resume
, /* to_resume */
3669 procfs_wait
, /* to_wait */
3670 procfs_fetch_registers
, /* to_fetch_registers */
3671 procfs_store_registers
, /* to_store_registers */
3672 procfs_prepare_to_store
, /* to_prepare_to_store */
3673 procfs_xfer_memory
, /* to_xfer_memory */
3674 procfs_files_info
, /* to_files_info */
3675 memory_insert_breakpoint
, /* to_insert_breakpoint */
3676 memory_remove_breakpoint
, /* to_remove_breakpoint */
3677 terminal_init_inferior
, /* to_terminal_init */
3678 terminal_inferior
, /* to_terminal_inferior */
3679 terminal_ours_for_output
, /* to_terminal_ours_for_output */
3680 terminal_ours
, /* to_terminal_ours */
3681 child_terminal_info
, /* to_terminal_info */
3682 procfs_kill_inferior
, /* to_kill */
3684 0, /* to_lookup_symbol */
3685 procfs_create_inferior
, /* to_create_inferior */
3686 procfs_mourn_inferior
, /* to_mourn_inferior */
3687 procfs_can_run
, /* to_can_run */
3688 procfs_notice_signals
, /* to_notice_signals */
3689 process_stratum
, /* to_stratum */
3691 1, /* to_has_all_memory */
3692 1, /* to_has_memory */
3693 1, /* to_has_stack */
3694 1, /* to_has_registers */
3695 1, /* to_has_execution */
3697 0, /* sections_end */
3698 OPS_MAGIC
/* to_magic */
3702 _initialize_procfs ()
3704 add_target (&procfs_ops
);
3706 add_info ("proc", info_proc
,
3707 "Show process status information using /proc entry.\n\
3708 Specify process id or use current inferior by default.\n\
3709 Specify keywords for detailed information; default is summary.\n\
3710 Keywords are: `all', `faults', `flags', `id', `mappings', `signals',\n\
3711 `status', `syscalls', and `times'.\n\
3712 Unambiguous abbreviations may be used.");
3714 init_syscall_table ();