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 struct procinfo
*next
;
80 int pid
; /* Process ID of inferior */
81 int fd
; /* File descriptor for /proc entry */
82 char *pathname
; /* Pathname to /proc entry */
83 int had_event
; /* poll/select says something happened */
84 int was_stopped
; /* Nonzero if was stopped prior to attach */
85 int nopass_next_sigstop
; /* Don't pass a sigstop on next resume */
86 prrun_t prrun
; /* Control state when it is run */
87 prstatus_t prstatus
; /* Current process status info */
88 gregset_t gregset
; /* General register set */
89 fpregset_t fpregset
; /* Floating point register set */
90 fltset_t fltset
; /* Current traced hardware fault set */
91 sigset_t trace
; /* Current traced signal set */
92 sysset_t exitset
; /* Current traced system call exit set */
93 sysset_t entryset
; /* Current traced system call entry set */
94 fltset_t saved_fltset
; /* Saved traced hardware fault set */
95 sigset_t saved_trace
; /* Saved traced signal set */
96 sigset_t saved_sighold
; /* Saved held signal set */
97 sysset_t saved_exitset
; /* Saved traced system call exit set */
98 sysset_t saved_entryset
; /* Saved traced system call entry set */
101 /* List of inferior process information */
102 static struct procinfo
*procinfo_list
= NULL
;
104 static struct pollfd
*poll_list
; /* pollfds used for waiting on /proc */
106 static int num_poll_list
= 0; /* Number of entries in poll_list */
108 static int last_resume_pid
= -1; /* Last pid used with procfs_resume */
110 /* Much of the information used in the /proc interface, particularly for
111 printing status information, is kept as tables of structures of the
112 following form. These tables can be used to map numeric values to
113 their symbolic names and to a string that describes their specific use. */
116 int value
; /* The numeric value */
117 char *name
; /* The equivalent symbolic value */
118 char *desc
; /* Short description of value */
121 /* Translate bits in the pr_flags member of the prstatus structure, into the
122 names and desc information. */
124 static struct trans pr_flag_table
[] =
126 #if defined (PR_STOPPED)
127 PR_STOPPED
, "PR_STOPPED", "Process is stopped",
129 #if defined (PR_ISTOP)
130 PR_ISTOP
, "PR_ISTOP", "Stopped on an event of interest",
132 #if defined (PR_DSTOP)
133 PR_DSTOP
, "PR_DSTOP", "A stop directive is in effect",
135 #if defined (PR_ASLEEP)
136 PR_ASLEEP
, "PR_ASLEEP", "Sleeping in an interruptible system call",
138 #if defined (PR_FORK)
139 PR_FORK
, "PR_FORK", "Inherit-on-fork is in effect",
142 PR_RLC
, "PR_RLC", "Run-on-last-close is in effect",
144 #if defined (PR_PTRACE)
145 PR_PTRACE
, "PR_PTRACE", "Process is being controlled by ptrace",
147 #if defined (PR_PCINVAL)
148 PR_PCINVAL
, "PR_PCINVAL", "PC refers to an invalid virtual address",
150 #if defined (PR_ISSYS)
151 PR_ISSYS
, "PR_ISSYS", "Is a system process",
153 #if defined (PR_STEP)
154 PR_STEP
, "PR_STEP", "Process has single step pending",
157 PR_KLC
, "PR_KLC", "Kill-on-last-close is in effect",
159 #if defined (PR_ASYNC)
160 PR_ASYNC
, "PR_ASYNC", "Asynchronous stop is in effect",
162 #if defined (PR_PCOMPAT)
163 PR_PCOMPAT
, "PR_PCOMPAT", "Ptrace compatibility mode in effect",
168 /* Translate values in the pr_why field of the prstatus struct. */
170 static struct trans pr_why_table
[] =
172 #if defined (PR_REQUESTED)
173 PR_REQUESTED
, "PR_REQUESTED", "Directed to stop via PIOCSTOP/PIOCWSTOP",
175 #if defined (PR_SIGNALLED)
176 PR_SIGNALLED
, "PR_SIGNALLED", "Receipt of a traced signal",
178 #if defined (PR_FAULTED)
179 PR_FAULTED
, "PR_FAULTED", "Incurred a traced hardware fault",
181 #if defined (PR_SYSENTRY)
182 PR_SYSENTRY
, "PR_SYSENTRY", "Entry to a traced system call",
184 #if defined (PR_SYSEXIT)
185 PR_SYSEXIT
, "PR_SYSEXIT", "Exit from a traced system call",
187 #if defined (PR_JOBCONTROL)
188 PR_JOBCONTROL
, "PR_JOBCONTROL", "Default job control stop signal action",
190 #if defined (PR_SUSPENDED)
191 PR_SUSPENDED
, "PR_SUSPENDED", "Process suspended",
196 /* Hardware fault translation table. */
198 static struct trans faults_table
[] =
201 FLTILL
, "FLTILL", "Illegal instruction",
203 #if defined (FLTPRIV)
204 FLTPRIV
, "FLTPRIV", "Privileged instruction",
207 FLTBPT
, "FLTBPT", "Breakpoint trap",
209 #if defined (FLTTRACE)
210 FLTTRACE
, "FLTTRACE", "Trace trap",
212 #if defined (FLTACCESS)
213 FLTACCESS
, "FLTACCESS", "Memory access fault",
215 #if defined (FLTBOUNDS)
216 FLTBOUNDS
, "FLTBOUNDS", "Memory bounds violation",
218 #if defined (FLTIOVF)
219 FLTIOVF
, "FLTIOVF", "Integer overflow",
221 #if defined (FLTIZDIV)
222 FLTIZDIV
, "FLTIZDIV", "Integer zero divide",
225 FLTFPE
, "FLTFPE", "Floating-point exception",
227 #if defined (FLTSTACK)
228 FLTSTACK
, "FLTSTACK", "Unrecoverable stack fault",
230 #if defined (FLTPAGE)
231 FLTPAGE
, "FLTPAGE", "Recoverable page fault",
236 /* Translation table for signal generation information. See UNIX System
237 V Release 4 Programmer's Reference Manual, siginfo(5). */
239 static struct sigcode
{
244 } siginfo_table
[] = {
245 #if defined (SIGILL) && defined (ILL_ILLOPC)
246 SIGILL
, ILL_ILLOPC
, "ILL_ILLOPC", "Illegal opcode",
248 #if defined (SIGILL) && defined (ILL_ILLOPN)
249 SIGILL
, ILL_ILLOPN
, "ILL_ILLOPN", "Illegal operand",
251 #if defined (SIGILL) && defined (ILL_ILLADR)
252 SIGILL
, ILL_ILLADR
, "ILL_ILLADR", "Illegal addressing mode",
254 #if defined (SIGILL) && defined (ILL_ILLTRP)
255 SIGILL
, ILL_ILLTRP
, "ILL_ILLTRP", "Illegal trap",
257 #if defined (SIGILL) && defined (ILL_PRVOPC)
258 SIGILL
, ILL_PRVOPC
, "ILL_PRVOPC", "Privileged opcode",
260 #if defined (SIGILL) && defined (ILL_PRVREG)
261 SIGILL
, ILL_PRVREG
, "ILL_PRVREG", "Privileged register",
263 #if defined (SIGILL) && defined (ILL_COPROC)
264 SIGILL
, ILL_COPROC
, "ILL_COPROC", "Coprocessor error",
266 #if defined (SIGILL) && defined (ILL_BADSTK)
267 SIGILL
, ILL_BADSTK
, "ILL_BADSTK", "Internal stack error",
269 #if defined (SIGFPE) && defined (FPE_INTDIV)
270 SIGFPE
, FPE_INTDIV
, "FPE_INTDIV", "Integer divide by zero",
272 #if defined (SIGFPE) && defined (FPE_INTOVF)
273 SIGFPE
, FPE_INTOVF
, "FPE_INTOVF", "Integer overflow",
275 #if defined (SIGFPE) && defined (FPE_FLTDIV)
276 SIGFPE
, FPE_FLTDIV
, "FPE_FLTDIV", "Floating point divide by zero",
278 #if defined (SIGFPE) && defined (FPE_FLTOVF)
279 SIGFPE
, FPE_FLTOVF
, "FPE_FLTOVF", "Floating point overflow",
281 #if defined (SIGFPE) && defined (FPE_FLTUND)
282 SIGFPE
, FPE_FLTUND
, "FPE_FLTUND", "Floating point underflow",
284 #if defined (SIGFPE) && defined (FPE_FLTRES)
285 SIGFPE
, FPE_FLTRES
, "FPE_FLTRES", "Floating point inexact result",
287 #if defined (SIGFPE) && defined (FPE_FLTINV)
288 SIGFPE
, FPE_FLTINV
, "FPE_FLTINV", "Invalid floating point operation",
290 #if defined (SIGFPE) && defined (FPE_FLTSUB)
291 SIGFPE
, FPE_FLTSUB
, "FPE_FLTSUB", "Subscript out of range",
293 #if defined (SIGSEGV) && defined (SEGV_MAPERR)
294 SIGSEGV
, SEGV_MAPERR
, "SEGV_MAPERR", "Address not mapped to object",
296 #if defined (SIGSEGV) && defined (SEGV_ACCERR)
297 SIGSEGV
, SEGV_ACCERR
, "SEGV_ACCERR", "Invalid permissions for object",
299 #if defined (SIGBUS) && defined (BUS_ADRALN)
300 SIGBUS
, BUS_ADRALN
, "BUS_ADRALN", "Invalid address alignment",
302 #if defined (SIGBUS) && defined (BUS_ADRERR)
303 SIGBUS
, BUS_ADRERR
, "BUS_ADRERR", "Non-existent physical address",
305 #if defined (SIGBUS) && defined (BUS_OBJERR)
306 SIGBUS
, BUS_OBJERR
, "BUS_OBJERR", "Object specific hardware error",
308 #if defined (SIGTRAP) && defined (TRAP_BRKPT)
309 SIGTRAP
, TRAP_BRKPT
, "TRAP_BRKPT", "Process breakpoint",
311 #if defined (SIGTRAP) && defined (TRAP_TRACE)
312 SIGTRAP
, TRAP_TRACE
, "TRAP_TRACE", "Process trace trap",
314 #if defined (SIGCLD) && defined (CLD_EXITED)
315 SIGCLD
, CLD_EXITED
, "CLD_EXITED", "Child has exited",
317 #if defined (SIGCLD) && defined (CLD_KILLED)
318 SIGCLD
, CLD_KILLED
, "CLD_KILLED", "Child was killed",
320 #if defined (SIGCLD) && defined (CLD_DUMPED)
321 SIGCLD
, CLD_DUMPED
, "CLD_DUMPED", "Child has terminated abnormally",
323 #if defined (SIGCLD) && defined (CLD_TRAPPED)
324 SIGCLD
, CLD_TRAPPED
, "CLD_TRAPPED", "Traced child has trapped",
326 #if defined (SIGCLD) && defined (CLD_STOPPED)
327 SIGCLD
, CLD_STOPPED
, "CLD_STOPPED", "Child has stopped",
329 #if defined (SIGCLD) && defined (CLD_CONTINUED)
330 SIGCLD
, CLD_CONTINUED
, "CLD_CONTINUED", "Stopped child had continued",
332 #if defined (SIGPOLL) && defined (POLL_IN)
333 SIGPOLL
, POLL_IN
, "POLL_IN", "Input input available",
335 #if defined (SIGPOLL) && defined (POLL_OUT)
336 SIGPOLL
, POLL_OUT
, "POLL_OUT", "Output buffers available",
338 #if defined (SIGPOLL) && defined (POLL_MSG)
339 SIGPOLL
, POLL_MSG
, "POLL_MSG", "Input message available",
341 #if defined (SIGPOLL) && defined (POLL_ERR)
342 SIGPOLL
, POLL_ERR
, "POLL_ERR", "I/O error",
344 #if defined (SIGPOLL) && defined (POLL_PRI)
345 SIGPOLL
, POLL_PRI
, "POLL_PRI", "High priority input available",
347 #if defined (SIGPOLL) && defined (POLL_HUP)
348 SIGPOLL
, POLL_HUP
, "POLL_HUP", "Device disconnected",
353 static char *syscall_table
[MAX_SYSCALLS
];
355 /* Prototypes for local functions */
358 set_proc_siginfo
PARAMS ((struct procinfo
*, int));
361 init_syscall_table
PARAMS ((void));
364 syscallname
PARAMS ((int));
367 signalname
PARAMS ((int));
370 errnoname
PARAMS ((int));
373 proc_address_to_fd
PARAMS ((struct procinfo
*, CORE_ADDR
, int));
376 open_proc_file
PARAMS ((int, struct procinfo
*, int));
379 close_proc_file
PARAMS ((struct procinfo
*));
382 unconditionally_kill_inferior
PARAMS ((struct procinfo
*));
385 proc_init_failed
PARAMS ((struct procinfo
*, char *));
388 info_proc
PARAMS ((char *, int));
391 info_proc_flags
PARAMS ((struct procinfo
*, int));
394 info_proc_stop
PARAMS ((struct procinfo
*, int));
397 info_proc_siginfo
PARAMS ((struct procinfo
*, int));
400 info_proc_syscalls
PARAMS ((struct procinfo
*, int));
403 info_proc_mappings
PARAMS ((struct procinfo
*, int));
406 info_proc_signals
PARAMS ((struct procinfo
*, int));
409 info_proc_faults
PARAMS ((struct procinfo
*, int));
412 mappingflags
PARAMS ((long));
415 lookupname
PARAMS ((struct trans
*, unsigned int, char *));
418 lookupdesc
PARAMS ((struct trans
*, unsigned int));
421 do_attach
PARAMS ((int pid
));
424 do_detach
PARAMS ((int siggnal
));
427 procfs_create_inferior
PARAMS ((char *, char *, char **));
430 procfs_notice_signals
PARAMS ((int pid
));
432 static struct procinfo
*
433 find_procinfo
PARAMS ((pid_t pid
, int okfail
));
435 /* External function prototypes that can't be easily included in any
436 header file because the args are typedefs in system include files. */
439 supply_gregset
PARAMS ((gregset_t
*));
442 fill_gregset
PARAMS ((gregset_t
*, int));
445 supply_fpregset
PARAMS ((fpregset_t
*));
448 fill_fpregset
PARAMS ((fpregset_t
*, int));
454 find_procinfo -- convert a process id to a struct procinfo
458 static struct procinfo * find_procinfo (pid_t pid, int okfail);
462 Given a process id, look it up in the procinfo chain. Returns
463 a struct procinfo *. If can't find pid, then call error(),
464 unless okfail is set, in which case, return NULL;
467 static struct procinfo
*
468 find_procinfo (pid
, okfail
)
472 struct procinfo
*procinfo
;
474 for (procinfo
= procinfo_list
; procinfo
; procinfo
= procinfo
->next
)
475 if (procinfo
->pid
== pid
)
481 error ("procfs (find_procinfo): Couldn't locate pid %d", pid
);
488 current_procinfo -- convert inferior_pid to a struct procinfo
492 static struct procinfo * current_procinfo;
496 Looks up inferior_pid in the procinfo chain. Always returns a
497 struct procinfo *. If process can't be found, we error() out.
500 #define current_procinfo find_procinfo (inferior_pid, 0)
506 add_fd -- Add the fd to the poll/select list
510 static void add_fd (struct procinfo *);
514 Add the fd of the supplied procinfo to the list of fds used for
515 poll/select operations.
522 if (num_poll_list
<= 0)
523 poll_list
= (struct pollfd
*) xmalloc (sizeof (struct pollfd
));
525 poll_list
= (struct pollfd
*) xrealloc (poll_list
,
527 * sizeof (struct pollfd
));
528 poll_list
[num_poll_list
].fd
= pi
->fd
;
529 poll_list
[num_poll_list
].events
= POLLPRI
;
540 for (i
= 0; i
< num_poll_list
; i
++)
542 if (poll_list
[i
].fd
== pi
->fd
)
544 if (i
!= num_poll_list
- 1)
545 memcpy (poll_list
, poll_list
+ i
+ 1,
546 (num_poll_list
- i
- 1) * sizeof (struct pollfd
));
550 if (num_poll_list
== 0)
553 poll_list
= (struct pollfd
*) xrealloc (poll_list
,
555 * sizeof (struct pollfd
));
561 #define LOSING_POLL unixware_sux
563 static struct procinfo
*
571 set_sigint_trap (); /* Causes SIGINT to be passed on to the
575 num_fds
= poll (poll_list
, num_poll_list
, -1);
577 pi
= current_procinfo
;
579 if (ioctl (pi
->fd
, PIOCWSTOP
, &pi
->prstatus
) < 0)
581 print_sys_errmsg (pi
->pathname
, errno
);
582 error ("PIOCWSTOP failed");
593 print_sys_errmsg ("poll failed\n", errno
);
594 error ("Poll failed, returned %d", num_fds
);
597 for (i
= 0; i
< num_poll_list
&& num_fds
> 0; i
++)
599 if ((poll_list
[i
].revents
& (POLLPRI
|POLLERR
|POLLHUP
|POLLNVAL
)) == 0)
601 for (pi
= procinfo_list
; pi
; pi
= pi
->next
)
603 if (poll_list
[i
].fd
== pi
->fd
)
605 if (ioctl (pi
->fd
, PIOCSTATUS
, &pi
->prstatus
) < 0)
607 print_sys_errmsg (pi
->pathname
, errno
);
608 error ("PIOCSTATUS failed");
616 error ("procfs_wait: Couldn't find procinfo for fd %d\n",
619 #endif /* LOSING_POLL */
628 lookupdesc -- translate a value to a summary desc string
632 static char *lookupdesc (struct trans *transp, unsigned int val);
636 Given a pointer to a translation table and a value to be translated,
637 lookup the desc string and return it.
641 lookupdesc (transp
, val
)
642 struct trans
*transp
;
647 for (desc
= NULL
; transp
-> name
!= NULL
; transp
++)
649 if (transp
-> value
== val
)
651 desc
= transp
-> desc
;
656 /* Didn't find a translation for the specified value, set a default one. */
669 lookupname -- translate a value to symbolic name
673 static char *lookupname (struct trans *transp, unsigned int val,
678 Given a pointer to a translation table, a value to be translated,
679 and a default prefix to return if the value can't be translated,
680 match the value with one of the translation table entries and
681 return a pointer to the symbolic name.
683 If no match is found it just returns the value as a printable string,
684 with the given prefix. The previous such value, if any, is freed
689 lookupname (transp
, val
, prefix
)
690 struct trans
*transp
;
697 for (name
= NULL
; transp
-> name
!= NULL
; transp
++)
699 if (transp
-> value
== val
)
701 name
= transp
-> name
;
706 /* Didn't find a translation for the specified value, build a default
707 one using the specified prefix and return it. The lifetime of
708 the value is only until the next one is needed. */
716 locbuf
= xmalloc (strlen (prefix
) + 16);
717 sprintf (locbuf
, "%s %u", prefix
, val
);
729 static char locbuf
[32];
731 for (scp
= siginfo_table
; scp
-> codename
!= NULL
; scp
++)
733 if ((scp
-> signo
== sip
-> si_signo
) &&
734 (scp
-> code
== sip
-> si_code
))
736 name
= scp
-> codename
;
742 sprintf (locbuf
, "sigcode %u", sip
-> si_signo
);
755 for (scp
= siginfo_table
; scp
-> codename
!= NULL
; scp
++)
757 if ((scp
-> signo
== sip
-> si_signo
) &&
758 (scp
-> code
== sip
-> si_code
))
766 desc
= "Unrecognized signal or trap use";
775 syscallname - translate a system call number into a system call name
779 char *syscallname (int syscallnum)
783 Given a system call number, translate it into the printable name
784 of a system call, or into "syscall <num>" if it is an unknown
789 syscallname (syscallnum
)
792 static char locbuf
[32];
795 if (syscallnum
>= 0 && syscallnum
< MAX_SYSCALLS
)
797 rtnval
= syscall_table
[syscallnum
];
801 sprintf (locbuf
, "syscall %u", syscallnum
);
811 init_syscall_table - initialize syscall translation table
815 void init_syscall_table (void)
819 Dynamically initialize the translation table to convert system
820 call numbers into printable system call names. Done once per
821 gdb run, on initialization.
825 This is awfully ugly, but preprocessor tricks to make it prettier
826 tend to be nonportable.
830 init_syscall_table ()
832 #if defined (SYS_exit)
833 syscall_table
[SYS_exit
] = "exit";
835 #if defined (SYS_fork)
836 syscall_table
[SYS_fork
] = "fork";
838 #if defined (SYS_read)
839 syscall_table
[SYS_read
] = "read";
841 #if defined (SYS_write)
842 syscall_table
[SYS_write
] = "write";
844 #if defined (SYS_open)
845 syscall_table
[SYS_open
] = "open";
847 #if defined (SYS_close)
848 syscall_table
[SYS_close
] = "close";
850 #if defined (SYS_wait)
851 syscall_table
[SYS_wait
] = "wait";
853 #if defined (SYS_creat)
854 syscall_table
[SYS_creat
] = "creat";
856 #if defined (SYS_link)
857 syscall_table
[SYS_link
] = "link";
859 #if defined (SYS_unlink)
860 syscall_table
[SYS_unlink
] = "unlink";
862 #if defined (SYS_exec)
863 syscall_table
[SYS_exec
] = "exec";
865 #if defined (SYS_execv)
866 syscall_table
[SYS_execv
] = "execv";
868 #if defined (SYS_execve)
869 syscall_table
[SYS_execve
] = "execve";
871 #if defined (SYS_chdir)
872 syscall_table
[SYS_chdir
] = "chdir";
874 #if defined (SYS_time)
875 syscall_table
[SYS_time
] = "time";
877 #if defined (SYS_mknod)
878 syscall_table
[SYS_mknod
] = "mknod";
880 #if defined (SYS_chmod)
881 syscall_table
[SYS_chmod
] = "chmod";
883 #if defined (SYS_chown)
884 syscall_table
[SYS_chown
] = "chown";
886 #if defined (SYS_brk)
887 syscall_table
[SYS_brk
] = "brk";
889 #if defined (SYS_stat)
890 syscall_table
[SYS_stat
] = "stat";
892 #if defined (SYS_lseek)
893 syscall_table
[SYS_lseek
] = "lseek";
895 #if defined (SYS_getpid)
896 syscall_table
[SYS_getpid
] = "getpid";
898 #if defined (SYS_mount)
899 syscall_table
[SYS_mount
] = "mount";
901 #if defined (SYS_umount)
902 syscall_table
[SYS_umount
] = "umount";
904 #if defined (SYS_setuid)
905 syscall_table
[SYS_setuid
] = "setuid";
907 #if defined (SYS_getuid)
908 syscall_table
[SYS_getuid
] = "getuid";
910 #if defined (SYS_stime)
911 syscall_table
[SYS_stime
] = "stime";
913 #if defined (SYS_ptrace)
914 syscall_table
[SYS_ptrace
] = "ptrace";
916 #if defined (SYS_alarm)
917 syscall_table
[SYS_alarm
] = "alarm";
919 #if defined (SYS_fstat)
920 syscall_table
[SYS_fstat
] = "fstat";
922 #if defined (SYS_pause)
923 syscall_table
[SYS_pause
] = "pause";
925 #if defined (SYS_utime)
926 syscall_table
[SYS_utime
] = "utime";
928 #if defined (SYS_stty)
929 syscall_table
[SYS_stty
] = "stty";
931 #if defined (SYS_gtty)
932 syscall_table
[SYS_gtty
] = "gtty";
934 #if defined (SYS_access)
935 syscall_table
[SYS_access
] = "access";
937 #if defined (SYS_nice)
938 syscall_table
[SYS_nice
] = "nice";
940 #if defined (SYS_statfs)
941 syscall_table
[SYS_statfs
] = "statfs";
943 #if defined (SYS_sync)
944 syscall_table
[SYS_sync
] = "sync";
946 #if defined (SYS_kill)
947 syscall_table
[SYS_kill
] = "kill";
949 #if defined (SYS_fstatfs)
950 syscall_table
[SYS_fstatfs
] = "fstatfs";
952 #if defined (SYS_pgrpsys)
953 syscall_table
[SYS_pgrpsys
] = "pgrpsys";
955 #if defined (SYS_xenix)
956 syscall_table
[SYS_xenix
] = "xenix";
958 #if defined (SYS_dup)
959 syscall_table
[SYS_dup
] = "dup";
961 #if defined (SYS_pipe)
962 syscall_table
[SYS_pipe
] = "pipe";
964 #if defined (SYS_times)
965 syscall_table
[SYS_times
] = "times";
967 #if defined (SYS_profil)
968 syscall_table
[SYS_profil
] = "profil";
970 #if defined (SYS_plock)
971 syscall_table
[SYS_plock
] = "plock";
973 #if defined (SYS_setgid)
974 syscall_table
[SYS_setgid
] = "setgid";
976 #if defined (SYS_getgid)
977 syscall_table
[SYS_getgid
] = "getgid";
979 #if defined (SYS_signal)
980 syscall_table
[SYS_signal
] = "signal";
982 #if defined (SYS_msgsys)
983 syscall_table
[SYS_msgsys
] = "msgsys";
985 #if defined (SYS_sys3b)
986 syscall_table
[SYS_sys3b
] = "sys3b";
988 #if defined (SYS_acct)
989 syscall_table
[SYS_acct
] = "acct";
991 #if defined (SYS_shmsys)
992 syscall_table
[SYS_shmsys
] = "shmsys";
994 #if defined (SYS_semsys)
995 syscall_table
[SYS_semsys
] = "semsys";
997 #if defined (SYS_ioctl)
998 syscall_table
[SYS_ioctl
] = "ioctl";
1000 #if defined (SYS_uadmin)
1001 syscall_table
[SYS_uadmin
] = "uadmin";
1003 #if defined (SYS_utssys)
1004 syscall_table
[SYS_utssys
] = "utssys";
1006 #if defined (SYS_fsync)
1007 syscall_table
[SYS_fsync
] = "fsync";
1009 #if defined (SYS_umask)
1010 syscall_table
[SYS_umask
] = "umask";
1012 #if defined (SYS_chroot)
1013 syscall_table
[SYS_chroot
] = "chroot";
1015 #if defined (SYS_fcntl)
1016 syscall_table
[SYS_fcntl
] = "fcntl";
1018 #if defined (SYS_ulimit)
1019 syscall_table
[SYS_ulimit
] = "ulimit";
1021 #if defined (SYS_rfsys)
1022 syscall_table
[SYS_rfsys
] = "rfsys";
1024 #if defined (SYS_rmdir)
1025 syscall_table
[SYS_rmdir
] = "rmdir";
1027 #if defined (SYS_mkdir)
1028 syscall_table
[SYS_mkdir
] = "mkdir";
1030 #if defined (SYS_getdents)
1031 syscall_table
[SYS_getdents
] = "getdents";
1033 #if defined (SYS_sysfs)
1034 syscall_table
[SYS_sysfs
] = "sysfs";
1036 #if defined (SYS_getmsg)
1037 syscall_table
[SYS_getmsg
] = "getmsg";
1039 #if defined (SYS_putmsg)
1040 syscall_table
[SYS_putmsg
] = "putmsg";
1042 #if defined (SYS_poll)
1043 syscall_table
[SYS_poll
] = "poll";
1045 #if defined (SYS_lstat)
1046 syscall_table
[SYS_lstat
] = "lstat";
1048 #if defined (SYS_symlink)
1049 syscall_table
[SYS_symlink
] = "symlink";
1051 #if defined (SYS_readlink)
1052 syscall_table
[SYS_readlink
] = "readlink";
1054 #if defined (SYS_setgroups)
1055 syscall_table
[SYS_setgroups
] = "setgroups";
1057 #if defined (SYS_getgroups)
1058 syscall_table
[SYS_getgroups
] = "getgroups";
1060 #if defined (SYS_fchmod)
1061 syscall_table
[SYS_fchmod
] = "fchmod";
1063 #if defined (SYS_fchown)
1064 syscall_table
[SYS_fchown
] = "fchown";
1066 #if defined (SYS_sigprocmask)
1067 syscall_table
[SYS_sigprocmask
] = "sigprocmask";
1069 #if defined (SYS_sigsuspend)
1070 syscall_table
[SYS_sigsuspend
] = "sigsuspend";
1072 #if defined (SYS_sigaltstack)
1073 syscall_table
[SYS_sigaltstack
] = "sigaltstack";
1075 #if defined (SYS_sigaction)
1076 syscall_table
[SYS_sigaction
] = "sigaction";
1078 #if defined (SYS_sigpending)
1079 syscall_table
[SYS_sigpending
] = "sigpending";
1081 #if defined (SYS_context)
1082 syscall_table
[SYS_context
] = "context";
1084 #if defined (SYS_evsys)
1085 syscall_table
[SYS_evsys
] = "evsys";
1087 #if defined (SYS_evtrapret)
1088 syscall_table
[SYS_evtrapret
] = "evtrapret";
1090 #if defined (SYS_statvfs)
1091 syscall_table
[SYS_statvfs
] = "statvfs";
1093 #if defined (SYS_fstatvfs)
1094 syscall_table
[SYS_fstatvfs
] = "fstatvfs";
1096 #if defined (SYS_nfssys)
1097 syscall_table
[SYS_nfssys
] = "nfssys";
1099 #if defined (SYS_waitsys)
1100 syscall_table
[SYS_waitsys
] = "waitsys";
1102 #if defined (SYS_sigsendsys)
1103 syscall_table
[SYS_sigsendsys
] = "sigsendsys";
1105 #if defined (SYS_hrtsys)
1106 syscall_table
[SYS_hrtsys
] = "hrtsys";
1108 #if defined (SYS_acancel)
1109 syscall_table
[SYS_acancel
] = "acancel";
1111 #if defined (SYS_async)
1112 syscall_table
[SYS_async
] = "async";
1114 #if defined (SYS_priocntlsys)
1115 syscall_table
[SYS_priocntlsys
] = "priocntlsys";
1117 #if defined (SYS_pathconf)
1118 syscall_table
[SYS_pathconf
] = "pathconf";
1120 #if defined (SYS_mincore)
1121 syscall_table
[SYS_mincore
] = "mincore";
1123 #if defined (SYS_mmap)
1124 syscall_table
[SYS_mmap
] = "mmap";
1126 #if defined (SYS_mprotect)
1127 syscall_table
[SYS_mprotect
] = "mprotect";
1129 #if defined (SYS_munmap)
1130 syscall_table
[SYS_munmap
] = "munmap";
1132 #if defined (SYS_fpathconf)
1133 syscall_table
[SYS_fpathconf
] = "fpathconf";
1135 #if defined (SYS_vfork)
1136 syscall_table
[SYS_vfork
] = "vfork";
1138 #if defined (SYS_fchdir)
1139 syscall_table
[SYS_fchdir
] = "fchdir";
1141 #if defined (SYS_readv)
1142 syscall_table
[SYS_readv
] = "readv";
1144 #if defined (SYS_writev)
1145 syscall_table
[SYS_writev
] = "writev";
1147 #if defined (SYS_xstat)
1148 syscall_table
[SYS_xstat
] = "xstat";
1150 #if defined (SYS_lxstat)
1151 syscall_table
[SYS_lxstat
] = "lxstat";
1153 #if defined (SYS_fxstat)
1154 syscall_table
[SYS_fxstat
] = "fxstat";
1156 #if defined (SYS_xmknod)
1157 syscall_table
[SYS_xmknod
] = "xmknod";
1159 #if defined (SYS_clocal)
1160 syscall_table
[SYS_clocal
] = "clocal";
1162 #if defined (SYS_setrlimit)
1163 syscall_table
[SYS_setrlimit
] = "setrlimit";
1165 #if defined (SYS_getrlimit)
1166 syscall_table
[SYS_getrlimit
] = "getrlimit";
1168 #if defined (SYS_lchown)
1169 syscall_table
[SYS_lchown
] = "lchown";
1171 #if defined (SYS_memcntl)
1172 syscall_table
[SYS_memcntl
] = "memcntl";
1174 #if defined (SYS_getpmsg)
1175 syscall_table
[SYS_getpmsg
] = "getpmsg";
1177 #if defined (SYS_putpmsg)
1178 syscall_table
[SYS_putpmsg
] = "putpmsg";
1180 #if defined (SYS_rename)
1181 syscall_table
[SYS_rename
] = "rename";
1183 #if defined (SYS_uname)
1184 syscall_table
[SYS_uname
] = "uname";
1186 #if defined (SYS_setegid)
1187 syscall_table
[SYS_setegid
] = "setegid";
1189 #if defined (SYS_sysconfig)
1190 syscall_table
[SYS_sysconfig
] = "sysconfig";
1192 #if defined (SYS_adjtime)
1193 syscall_table
[SYS_adjtime
] = "adjtime";
1195 #if defined (SYS_systeminfo)
1196 syscall_table
[SYS_systeminfo
] = "systeminfo";
1198 #if defined (SYS_seteuid)
1199 syscall_table
[SYS_seteuid
] = "seteuid";
1201 #if defined (SYS_sproc)
1202 syscall_table
[SYS_sproc
] = "sproc";
1210 ptrace -- override library version to force errors for /proc version
1214 int ptrace (int request, int pid, PTRACE_ARG3_TYPE arg3, int arg4)
1218 When gdb is configured to use /proc, it should not be calling
1219 or otherwise attempting to use ptrace. In order to catch errors
1220 where use of /proc is configured, but some routine is still calling
1221 ptrace, we provide a local version of a function with that name
1222 that does nothing but issue an error message.
1226 ptrace (request
, pid
, arg3
, arg4
)
1229 PTRACE_ARG3_TYPE arg3
;
1232 error ("internal error - there is a call to ptrace() somewhere");
1240 procfs_kill_inferior - kill any currently inferior
1244 void procfs_kill_inferior (void)
1248 Kill any current inferior.
1252 Kills even attached inferiors. Presumably the user has already
1253 been prompted that the inferior is an attached one rather than
1254 one started by gdb. (FIXME?)
1259 procfs_kill_inferior ()
1261 struct procinfo
*pi
;
1263 for (pi
= procinfo_list
; pi
; pi
= pi
->next
)
1264 unconditionally_kill_inferior (pi
);
1266 target_mourn_inferior ();
1273 unconditionally_kill_inferior - terminate the inferior
1277 static void unconditionally_kill_inferior (struct procinfo *)
1281 Kill the specified inferior.
1285 A possibly useful enhancement would be to first try sending
1286 the inferior a terminate signal, politely asking it to commit
1287 suicide, before we murder it (we could call that
1288 politely_kill_inferior()).
1293 unconditionally_kill_inferior (pi
)
1294 struct procinfo
*pi
;
1299 ppid
= pi
->prstatus
.pr_ppid
;
1302 ioctl (pi
->fd
, PIOCKILL
, &signo
);
1303 close_proc_file (pi
);
1305 /* Only wait() for our direct children. Our grandchildren zombies are killed
1306 by the death of their parents. */
1308 if (ppid
== getpid())
1316 procfs_xfer_memory -- copy data to or from inferior memory space
1320 int procfs_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len,
1321 int dowrite, struct target_ops target)
1325 Copy LEN bytes to/from inferior's memory starting at MEMADDR
1326 from/to debugger memory starting at MYADDR. Copy from inferior
1327 if DOWRITE is zero or to inferior if DOWRITE is nonzero.
1329 Returns the length copied, which is either the LEN argument or
1330 zero. This xfer function does not do partial moves, since procfs_ops
1331 doesn't allow memory operations to cross below us in the target stack
1336 The /proc interface makes this an almost trivial task.
1340 procfs_xfer_memory (memaddr
, myaddr
, len
, dowrite
, target
)
1345 struct target_ops
*target
; /* ignored */
1348 struct procinfo
*pi
;
1350 pi
= current_procinfo
;
1352 if (lseek(pi
->fd
, (off_t
) memaddr
, 0) == (off_t
) memaddr
)
1356 nbytes
= write (pi
->fd
, myaddr
, len
);
1360 nbytes
= read (pi
->fd
, myaddr
, len
);
1374 procfs_store_registers -- copy register values back to inferior
1378 void procfs_store_registers (int regno)
1382 Store our current register values back into the inferior. If
1383 REGNO is -1 then store all the register, otherwise store just
1384 the value specified by REGNO.
1388 If we are storing only a single register, we first have to get all
1389 the current values from the process, overwrite the desired register
1390 in the gregset with the one we want from gdb's registers, and then
1391 send the whole set back to the process. For writing all the
1392 registers, all we have to do is generate the gregset and send it to
1395 Also note that the process has to be stopped on an event of interest
1396 for this to work, which basically means that it has to have been
1397 run under the control of one of the other /proc ioctl calls and not
1398 ptrace. Since we don't use ptrace anyway, we don't worry about this
1399 fine point, but it is worth noting for future reference.
1401 Gdb is confused about what this function is supposed to return.
1402 Some versions return a value, others return nothing. Some are
1403 declared to return a value and actually return nothing. Gdb ignores
1404 anything returned. (FIXME)
1409 procfs_store_registers (regno
)
1412 struct procinfo
*pi
;
1414 pi
= current_procinfo
;
1418 ioctl (pi
->fd
, PIOCGREG
, &pi
->gregset
);
1420 fill_gregset (&pi
->gregset
, regno
);
1421 ioctl (pi
->fd
, PIOCSREG
, &pi
->gregset
);
1423 #if defined (FP0_REGNUM)
1425 /* Now repeat everything using the floating point register set, if the
1426 target has floating point hardware. Since we ignore the returned value,
1427 we'll never know whether it worked or not anyway. */
1431 ioctl (pi
->fd
, PIOCGFPREG
, &pi
->fpregset
);
1433 fill_fpregset (&pi
->fpregset
, regno
);
1434 ioctl (pi
->fd
, PIOCSFPREG
, &pi
->fpregset
);
1436 #endif /* FP0_REGNUM */
1444 create_procinfo - initialize access to a /proc entry
1448 void create_procinfo (int pid)
1452 Allocate a procinfo structure, open the /proc file and then sets up
1453 the set of signals and faults that are to be traced.
1457 If proc_init_failed ever gets called, control returns to the command
1458 processing loop via the standard error handling code.
1463 create_procinfo (pid
)
1466 struct procinfo
*pi
;
1468 if (find_procinfo (pid
, 1))
1469 return; /* All done! It already exists */
1471 pi
= (struct procinfo
*) xmalloc (sizeof (struct procinfo
));
1473 if (!open_proc_file (pid
, pi
, O_RDWR
))
1474 proc_init_failed (pi
, "can't open process file");
1476 /* Add new process to process info list */
1478 pi
->next
= procinfo_list
;
1481 add_fd (pi
); /* Add to list for poll/select */
1483 memset ((char *) &pi
->prrun
, 0, sizeof (pi
->prrun
));
1484 prfillset (&pi
->prrun
.pr_trace
);
1485 procfs_notice_signals (pid
);
1486 prfillset (&pi
->prrun
.pr_fault
);
1487 prdelset (&pi
->prrun
.pr_fault
, FLTPAGE
);
1489 if (ioctl (pi
->fd
, PIOCWSTOP
, &pi
->prstatus
) < 0)
1490 proc_init_failed (pi
, "PIOCWSTOP failed");
1492 if (ioctl (pi
->fd
, PIOCSFAULT
, &pi
->prrun
.pr_fault
) < 0)
1493 proc_init_failed (pi
, "PIOCSFAULT failed");
1500 procfs_init_inferior - initialize target vector and access to a
1505 void procfs_init_inferior (int pid)
1509 When gdb starts an inferior, this function is called in the parent
1510 process immediately after the fork. It waits for the child to stop
1511 on the return from the exec system call (the child itself takes care
1512 of ensuring that this is set up), then sets up the set of signals
1513 and faults that are to be traced.
1517 If proc_init_failed ever gets called, control returns to the command
1518 processing loop via the standard error handling code.
1523 procfs_init_inferior (pid
)
1526 push_target (&procfs_ops
);
1528 create_procinfo (pid
);
1529 add_thread (pid
); /* Setup initial thread */
1536 procfs_notice_signals
1540 static void procfs_notice_signals (int pid);
1544 When the user changes the state of gdb's signal handling via the
1545 "handle" command, this function gets called to see if any change
1546 in the /proc interface is required. It is also called internally
1547 by other /proc interface functions to initialize the state of
1548 the traced signal set.
1550 One thing it does is that signals for which the state is "nostop",
1551 "noprint", and "pass", have their trace bits reset in the pr_trace
1552 field, so that they are no longer traced. This allows them to be
1553 delivered directly to the inferior without the debugger ever being
1558 procfs_notice_signals (pid
)
1562 struct procinfo
*pi
;
1564 pi
= find_procinfo (pid
, 0);
1566 for (signo
= 0; signo
< NSIG
; signo
++)
1568 if (signal_stop_state (signo
) == 0 &&
1569 signal_print_state (signo
) == 0 &&
1570 signal_pass_state (signo
) == 1)
1572 prdelset (&pi
->prrun
.pr_trace
, signo
);
1576 praddset (&pi
->prrun
.pr_trace
, signo
);
1579 if (ioctl (pi
->fd
, PIOCSTRACE
, &pi
->prrun
.pr_trace
))
1581 print_sys_errmsg ("PIOCSTRACE failed", errno
);
1589 proc_set_exec_trap -- arrange for exec'd child to halt at startup
1593 void proc_set_exec_trap (void)
1597 This function is called in the child process when starting up
1598 an inferior, prior to doing the exec of the actual inferior.
1599 It sets the child process's exitset to make exit from the exec
1600 system call an event of interest to stop on, and then simply
1601 returns. The child does the exec, the system call returns, and
1602 the child stops at the first instruction, ready for the gdb
1603 parent process to take control of it.
1607 We need to use all local variables since the child may be sharing
1608 it's data space with the parent, if vfork was used rather than
1611 Also note that we want to turn off the inherit-on-fork flag in
1612 the child process so that any grand-children start with all
1613 tracing flags cleared.
1617 proc_set_exec_trap ()
1620 auto char procname
[32];
1623 sprintf (procname
, PROC_NAME_FMT
, getpid ());
1624 if ((fd
= open (procname
, O_RDWR
)) < 0)
1630 premptyset (&exitset
);
1633 Not all systems with /proc have all the exec* syscalls with the same
1634 names. On the SGI, for example, there is no SYS_exec, but there
1635 *is* a SYS_execv. So, we try to account for that. */
1638 praddset (&exitset
, SYS_exec
);
1641 praddset (&exitset
, SYS_execve
);
1644 praddset(&exitset
, SYS_execv
);
1647 if (ioctl (fd
, PIOCSEXIT
, &exitset
) < 0)
1654 /* Turn off inherit-on-fork flag so that all grand-children of gdb
1655 start with tracing flags cleared. */
1657 #if defined (PIOCRESET) /* New method */
1661 ioctl (fd
, PIOCRESET
, &pr_flags
);
1664 #if defined (PIOCRFORK) /* Original method */
1665 ioctl (fd
, PIOCRFORK
, NULL
);
1669 /* Turn on run-on-last-close flag so that this process will not hang
1670 if GDB goes away for some reason. */
1672 #if defined (PIOCSET) /* New method */
1676 (void) ioctl (fd
, PIOCSET
, &pr_flags
);
1679 #if defined (PIOCSRLC) /* Original method */
1680 (void) ioctl (fd
, PIOCSRLC
, 0);
1689 proc_iterate_over_mappings -- call function for every mapped space
1693 int proc_iterate_over_mappings (int (*func)())
1697 Given a pointer to a function, call that function for every
1698 mapped address space, passing it an open file descriptor for
1699 the file corresponding to that mapped address space (if any)
1700 and the base address of the mapped space. Quit when we hit
1701 the end of the mappings or the function returns nonzero.
1705 proc_iterate_over_mappings (func
)
1706 int (*func
) PARAMS ((int, CORE_ADDR
));
1711 struct prmap
*prmaps
;
1712 struct prmap
*prmap
;
1713 struct procinfo
*pi
;
1715 pi
= current_procinfo
;
1717 if (ioctl (pi
->fd
, PIOCNMAP
, &nmap
) == 0)
1719 prmaps
= (struct prmap
*) alloca ((nmap
+ 1) * sizeof (*prmaps
));
1720 if (ioctl (pi
->fd
, PIOCMAP
, prmaps
) == 0)
1722 for (prmap
= prmaps
; prmap
-> pr_size
&& funcstat
== 0; ++prmap
)
1724 fd
= proc_address_to_fd (pi
, (CORE_ADDR
) prmap
-> pr_vaddr
, 0);
1725 funcstat
= (*func
) (fd
, (CORE_ADDR
) prmap
-> pr_vaddr
);
1733 #if 0 /* Currently unused */
1738 proc_base_address -- find base address for segment containing address
1742 CORE_ADDR proc_base_address (CORE_ADDR addr)
1746 Given an address of a location in the inferior, find and return
1747 the base address of the mapped segment containing that address.
1749 This is used for example, by the shared library support code,
1750 where we have the pc value for some location in the shared library
1751 where we are stopped, and need to know the base address of the
1752 segment containing that address.
1756 proc_base_address (addr
)
1760 struct prmap
*prmaps
;
1761 struct prmap
*prmap
;
1762 CORE_ADDR baseaddr
= 0;
1763 struct procinfo
*pi
;
1765 pi
= current_procinfo
;
1767 if (ioctl (pi
->fd
, PIOCNMAP
, &nmap
) == 0)
1769 prmaps
= (struct prmap
*) alloca ((nmap
+ 1) * sizeof (*prmaps
));
1770 if (ioctl (pi
->fd
, PIOCMAP
, prmaps
) == 0)
1772 for (prmap
= prmaps
; prmap
-> pr_size
; ++prmap
)
1774 if ((prmap
-> pr_vaddr
<= (caddr_t
) addr
) &&
1775 (prmap
-> pr_vaddr
+ prmap
-> pr_size
> (caddr_t
) addr
))
1777 baseaddr
= (CORE_ADDR
) prmap
-> pr_vaddr
;
1792 proc_address_to_fd -- return open fd for file mapped to address
1796 int proc_address_to_fd (struct procinfo *pi, CORE_ADDR addr, complain)
1800 Given an address in the current inferior's address space, use the
1801 /proc interface to find an open file descriptor for the file that
1802 this address was mapped in from. Return -1 if there is no current
1803 inferior. Print a warning message if there is an inferior but
1804 the address corresponds to no file (IE a bogus address).
1809 proc_address_to_fd (pi
, addr
, complain
)
1810 struct procinfo
*pi
;
1816 if ((fd
= ioctl (pi
->fd
, PIOCOPENM
, (caddr_t
*) &addr
)) < 0)
1820 print_sys_errmsg (pi
->pathname
, errno
);
1821 warning ("can't find mapped file for address 0x%x", addr
);
1828 /* Attach to process PID, then initialize for debugging it
1829 and wait for the trace-trap that results from attaching. */
1832 procfs_attach (args
, from_tty
)
1840 error_no_arg ("process-id to attach");
1844 if (pid
== getpid()) /* Trying to masturbate? */
1845 error ("I refuse to debug myself!");
1849 exec_file
= (char *) get_exec_file (0);
1852 printf ("Attaching to program `%s', %s\n", exec_file
, target_pid_to_str (pid
));
1854 printf ("Attaching to %s\n", target_pid_to_str (pid
));
1861 push_target (&procfs_ops
);
1865 /* Take a program previously attached to and detaches it.
1866 The program resumes execution and will no longer stop
1867 on signals, etc. We'd better not have left any breakpoints
1868 in the program or it'll die when it hits one. For this
1869 to work, it may be necessary for the process to have been
1870 previously attached. It *might* work if the program was
1871 started via the normal ptrace (PTRACE_TRACEME). */
1874 procfs_detach (args
, from_tty
)
1882 char *exec_file
= get_exec_file (0);
1885 printf ("Detaching from program: %s %s\n",
1886 exec_file
, target_pid_to_str (inferior_pid
));
1890 siggnal
= atoi (args
);
1892 do_detach (siggnal
);
1894 unpush_target (&procfs_ops
); /* Pop out of handling an inferior */
1897 /* Get ready to modify the registers array. On machines which store
1898 individual registers, this doesn't need to do anything. On machines
1899 which store all the registers in one fell swoop, this makes sure
1900 that registers contains all the registers from the program being
1904 procfs_prepare_to_store ()
1906 #ifdef CHILD_PREPARE_TO_STORE
1907 CHILD_PREPARE_TO_STORE ();
1911 /* Print status information about what we're accessing. */
1914 procfs_files_info (ignore
)
1915 struct target_ops
*ignore
;
1917 printf ("\tUsing the running image of %s %s via /proc.\n",
1918 attach_flag
? "attached": "child", target_pid_to_str (inferior_pid
));
1923 procfs_open (arg
, from_tty
)
1927 error ("Use the \"run\" command to start a Unix child process.");
1934 do_attach -- attach to an already existing process
1938 int do_attach (int pid)
1942 Attach to an already existing process with the specified process
1943 id. If the process is not already stopped, query whether to
1948 The option of stopping at attach time is specific to the /proc
1949 versions of gdb. Versions using ptrace force the attachee
1950 to stop. (I have changed this version to do so, too. All you
1951 have to do is "continue" to make it go on. -- gnu@cygnus.com)
1960 struct procinfo
*pi
;
1962 pi
= (struct procinfo
*) xmalloc (sizeof (struct procinfo
));
1964 if (!open_proc_file (pid
, pi
, O_RDWR
))
1967 perror_with_name (pi
->pathname
);
1971 /* Add new process to process info list */
1973 pi
->next
= procinfo_list
;
1976 add_fd (pi
); /* Add to list for poll/select */
1978 /* Get current status of process and if it is not already stopped,
1979 then stop it. Remember whether or not it was stopped when we first
1982 if (ioctl (pi
->fd
, PIOCSTATUS
, &pi
->prstatus
) < 0)
1984 print_sys_errmsg (pi
->pathname
, errno
);
1985 close_proc_file (pi
);
1986 error ("PIOCSTATUS failed");
1988 if (pi
->prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
))
1990 pi
->was_stopped
= 1;
1994 pi
->was_stopped
= 0;
1995 if (1 || query ("Process is currently running, stop it? "))
1997 /* Make it run again when we close it. */
1998 #if defined (PIOCSET) /* New method */
2002 result
= ioctl (pi
->fd
, PIOCSET
, &pr_flags
);
2005 #if defined (PIOCSRLC) /* Original method */
2006 result
= ioctl (pi
->fd
, PIOCSRLC
, 0);
2011 print_sys_errmsg (pi
->pathname
, errno
);
2012 close_proc_file (pi
);
2013 error ("PIOCSRLC or PIOCSET failed");
2015 if (ioctl (pi
->fd
, PIOCSTOP
, &pi
->prstatus
) < 0)
2017 print_sys_errmsg (pi
->pathname
, errno
);
2018 close_proc_file (pi
);
2019 error ("PIOCSTOP failed");
2021 pi
->nopass_next_sigstop
= 1;
2025 printf ("Ok, gdb will wait for %s to stop.\n", target_pid_to_str (pid
));
2029 /* Remember some things about the inferior that we will, or might, change
2030 so that we can restore them when we detach. */
2032 ioctl (pi
->fd
, PIOCGTRACE
, &pi
->saved_trace
);
2033 ioctl (pi
->fd
, PIOCGHOLD
, &pi
->saved_sighold
);
2034 ioctl (pi
->fd
, PIOCGFAULT
, &pi
->saved_fltset
);
2035 ioctl (pi
->fd
, PIOCGENTRY
, &pi
->saved_entryset
);
2036 ioctl (pi
->fd
, PIOCGEXIT
, &pi
->saved_exitset
);
2038 /* Set up trace and fault sets, as gdb expects them. */
2040 memset (&pi
->prrun
, 0, sizeof (pi
->prrun
));
2041 prfillset (&pi
->prrun
.pr_trace
);
2042 procfs_notice_signals (pid
);
2043 prfillset (&pi
->prrun
.pr_fault
);
2044 prdelset (&pi
->prrun
.pr_fault
, FLTPAGE
);
2045 if (ioctl (pi
->fd
, PIOCSFAULT
, &pi
->prrun
.pr_fault
))
2047 print_sys_errmsg ("PIOCSFAULT failed", errno
);
2049 if (ioctl (pi
->fd
, PIOCSTRACE
, &pi
->prrun
.pr_trace
))
2051 print_sys_errmsg ("PIOCSTRACE failed", errno
);
2061 do_detach -- detach from an attached-to process
2065 void do_detach (int signal)
2069 Detach from the current attachee.
2071 If signal is non-zero, the attachee is started running again and sent
2072 the specified signal.
2074 If signal is zero and the attachee was not already stopped when we
2075 attached to it, then we make it runnable again when we detach.
2077 Otherwise, we query whether or not to make the attachee runnable
2078 again, since we may simply want to leave it in the state it was in
2081 We report any problems, but do not consider them errors, since we
2082 MUST detach even if some things don't seem to go right. This may not
2083 be the ideal situation. (FIXME).
2091 struct procinfo
*pi
;
2093 pi
= current_procinfo
;
2097 set_proc_siginfo (pi
, signal
);
2099 if (ioctl (pi
->fd
, PIOCSEXIT
, &pi
->saved_exitset
) < 0)
2101 print_sys_errmsg (pi
->pathname
, errno
);
2102 printf ("PIOCSEXIT failed.\n");
2104 if (ioctl (pi
->fd
, PIOCSENTRY
, &pi
->saved_entryset
) < 0)
2106 print_sys_errmsg (pi
->pathname
, errno
);
2107 printf ("PIOCSENTRY failed.\n");
2109 if (ioctl (pi
->fd
, PIOCSTRACE
, &pi
->saved_trace
) < 0)
2111 print_sys_errmsg (pi
->pathname
, errno
);
2112 printf ("PIOCSTRACE failed.\n");
2114 if (ioctl (pi
->fd
, PIOCSHOLD
, &pi
->saved_sighold
) < 0)
2116 print_sys_errmsg (pi
->pathname
, errno
);
2117 printf ("PIOSCHOLD failed.\n");
2119 if (ioctl (pi
->fd
, PIOCSFAULT
, &pi
->saved_fltset
) < 0)
2121 print_sys_errmsg (pi
->pathname
, errno
);
2122 printf ("PIOCSFAULT failed.\n");
2124 if (ioctl (pi
->fd
, PIOCSTATUS
, &pi
->prstatus
) < 0)
2126 print_sys_errmsg (pi
->pathname
, errno
);
2127 printf ("PIOCSTATUS failed.\n");
2131 if (signal
|| (pi
->prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
)))
2133 if (signal
|| !pi
->was_stopped
||
2134 query ("Was stopped when attached, make it runnable again? "))
2136 /* Clear any fault that might have stopped it. */
2137 if (ioctl (pi
->fd
, PIOCCFAULT
, 0))
2139 print_sys_errmsg (pi
->pathname
, errno
);
2140 printf ("PIOCCFAULT failed.\n");
2143 /* Make it run again when we close it. */
2144 #if defined (PIOCSET) /* New method */
2148 result
= ioctl (pi
->fd
, PIOCSET
, &pr_flags
);
2151 #if defined (PIOCSRLC) /* Original method */
2152 result
= ioctl (pi
->fd
, PIOCSRLC
, 0);
2157 print_sys_errmsg (pi
->pathname
, errno
);
2158 printf ("PIOCSRLC or PIOCSET failed.\n");
2163 close_proc_file (pi
);
2171 procfs_wait -- emulate wait() as much as possible
2172 Wait for child to do something. Return pid of child, or -1 in case
2173 of error; store status through argument pointer STATUS.
2178 int procfs_wait (int pid, int *statloc)
2182 Try to emulate wait() as much as possible. Not sure why we can't
2183 just use wait(), but it seems to have problems when applied to a
2184 process being controlled with the /proc interface.
2188 We have a race problem here with no obvious solution. We need to let
2189 the inferior run until it stops on an event of interest, which means
2190 that we need to use the PIOCWSTOP ioctl. However, we cannot use this
2191 ioctl if the process is already stopped on something that is not an
2192 event of interest, or the call will hang indefinitely. Thus we first
2193 use PIOCSTATUS to see if the process is not stopped. If not, then we
2194 use PIOCWSTOP. But during the window between the two, if the process
2195 stops for any reason that is not an event of interest (such as a job
2196 control signal) then gdb will hang. One possible workaround is to set
2197 an alarm to wake up every minute of so and check to see if the process
2198 is still running, and if so, then reissue the PIOCWSTOP. But this is
2199 a real kludge, so has not been implemented. FIXME: investigate
2202 FIXME: Investigate why wait() seems to have problems with programs
2203 being control by /proc routines.
2208 procfs_wait (pid
, statloc
)
2217 struct procinfo
*pi
;
2219 if (pid
!= -1) /* Non-specific process? */
2222 for (pi
= procinfo_list
; pi
; pi
= pi
->next
)
2232 for (pi
= procinfo_list
; pi
; pi
= pi
->next
)
2233 if (pi
->pid
== pid
&& pi
->had_event
)
2236 if (!pi
&& !checkerr
)
2239 if (!checkerr
&& !(pi
->prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
)))
2241 if (ioctl (pi
->fd
, PIOCWSTOP
, &pi
->prstatus
) < 0)
2248 if (errno
== ENOENT
)
2250 rtnval
= wait (&statval
);
2251 if (rtnval
!= inferior_pid
)
2253 print_sys_errmsg (pi
->pathname
, errno
);
2254 error ("PIOCWSTOP, wait failed, returned %d", rtnval
);
2260 print_sys_errmsg (pi
->pathname
, errno
);
2261 error ("PIOCSTATUS or PIOCWSTOP failed.");
2265 else if (pi
->prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
))
2267 rtnval
= pi
->prstatus
.pr_pid
;
2268 why
= pi
->prstatus
.pr_why
;
2269 what
= pi
->prstatus
.pr_what
;
2274 statval
= (what
<< 8) | 0177;
2288 statval
= (SIGTRAP
<< 8) | 0177;
2292 /* We've just detected the completion of an sproc system call. Now we need to
2293 setup a procinfo struct for this thread, and notify the thread system of the
2296 /* If sproc failed, then nothing interesting happened. Continue the process and
2297 go back to sleep. */
2299 if (pi
->prstatus
.pr_errno
!= 0)
2301 pi
->prrun
.pr_flags
&= PRSTEP
;
2302 pi
->prrun
.pr_flags
|= PRCFAULT
;
2304 if (ioctl (pi
->fd
, PIOCRUN
, &pi
->prrun
) != 0)
2305 perror_with_name (pi
->pathname
);
2310 /* At this point, the new thread is stopped at it's first instruction, and
2311 the parent is stopped at the exit from sproc. */
2313 /* Notify the caller of the arrival of a new thread. */
2314 create_procinfo (pi
->prstatus
.pr_rval1
);
2316 rtnval
= pi
->prstatus
.pr_rval1
;
2317 statval
= (SIGTRAP
<< 8) | 0177;
2320 #endif /* SYS_sproc */
2323 error ("PIOCSTATUS (PR_SYSEXIT): Unknown system call %d", what
);
2327 statval
= (SIGSTOP
<< 8) | 0177;
2330 statval
= (what
<< 8) | 0177;
2337 statval
= (SIGILL
<< 8) | 0177;
2341 statval
= (SIGTRAP
<< 8) | 0177;
2346 statval
= (SIGSEGV
<< 8) | 0177;
2351 statval
= (SIGFPE
<< 8) | 0177;
2353 case FLTPAGE
: /* Recoverable page fault */
2355 error ("PIOCWSTOP, unknown why %d, what %d", why
, what
);
2359 error ("PIOCWSTOP, unknown why %d, what %d", why
, what
);
2361 /* Stop all the other threads when any of them stops. */
2364 struct procinfo
*procinfo
;
2366 for (procinfo
= procinfo_list
; procinfo
; procinfo
= procinfo
->next
)
2368 if (!procinfo
->had_event
)
2369 if (ioctl (procinfo
->fd
, PIOCSTOP
, &procinfo
->prstatus
) < 0)
2371 print_sys_errmsg (procinfo
->pathname
, errno
);
2372 error ("PIOCSTOP failed");
2379 error ("PIOCWSTOP, stopped for unknown/unhandled reason, flags %#x",
2380 pi
->prstatus
.pr_flags
);
2388 if (rtnval
== -1) /* No more children to wait for */
2390 fprintf (stderr
, "Child process unexpectedly missing.\n");
2391 *statloc
= 42; /* Claim it exited with signal 42 */
2395 pi
->had_event
= 0; /* Indicate that we've seen this one */
2403 set_proc_siginfo - set a process's current signal info
2407 void set_proc_siginfo (struct procinfo *pip, int signo);
2411 Given a pointer to a process info struct in PIP and a signal number
2412 in SIGNO, set the process's current signal and its associated signal
2413 information. The signal will be delivered to the process immediately
2414 after execution is resumed, even if it is being held. In addition,
2415 this particular delivery will not cause another PR_SIGNALLED stop
2416 even if the signal is being traced.
2418 If we are not delivering the same signal that the prstatus siginfo
2419 struct contains information about, then synthesize a siginfo struct
2420 to match the signal we are doing to deliver, make it of the type
2421 "generated by a user process", and send this synthesized copy. When
2422 used to set the inferior's signal state, this will be required if we
2423 are not currently stopped because of a traced signal, or if we decide
2424 to continue with a different signal.
2426 Note that when continuing the inferior from a stop due to receipt
2427 of a traced signal, we either have set PRCSIG to clear the existing
2428 signal, or we have to call this function to do a PIOCSSIG with either
2429 the existing siginfo struct from pr_info, or one we have synthesized
2430 appropriately for the signal we want to deliver. Otherwise if the
2431 signal is still being traced, the inferior will immediately stop
2434 See siginfo(5) for more details.
2438 set_proc_siginfo (pip
, signo
)
2439 struct procinfo
*pip
;
2442 struct siginfo newsiginfo
;
2443 struct siginfo
*sip
;
2445 if (signo
== pip
-> prstatus
.pr_info
.si_signo
)
2447 sip
= &pip
-> prstatus
.pr_info
;
2451 memset ((char *) &newsiginfo
, 0, sizeof (newsiginfo
));
2453 sip
-> si_signo
= signo
;
2455 sip
-> si_errno
= 0;
2456 sip
-> si_pid
= getpid ();
2457 sip
-> si_uid
= getuid ();
2459 if (ioctl (pip
-> fd
, PIOCSSIG
, sip
) < 0)
2461 print_sys_errmsg (pip
-> pathname
, errno
);
2462 warning ("PIOCSSIG failed");
2466 /* Resume execution of process PID. If STEP is nozero, then
2467 just single step it. If SIGNAL is nonzero, restart it with that
2468 signal activated. */
2471 procfs_resume (pid
, step
, signo
)
2477 struct procinfo
*pi
, *procinfo
;
2479 pi
= find_procinfo (pid
== -1 ? inferior_pid
: pid
, 0);
2482 pi
->prrun
.pr_flags
= PRSTRACE
| PRSFAULT
| PRCFAULT
;
2485 /* It should not be necessary. If the user explicitly changes the value,
2486 value_assign calls write_register_bytes, which writes it. */
2487 /* It may not be absolutely necessary to specify the PC value for
2488 restarting, but to be safe we use the value that gdb considers
2489 to be current. One case where this might be necessary is if the
2490 user explicitly changes the PC value that gdb considers to be
2491 current. FIXME: Investigate if this is necessary or not. */
2493 #ifdef PRSVADDR_BROKEN
2494 /* Can't do this under Solaris running on a Sparc, as there seems to be no
2495 place to put nPC. In fact, if you use this, nPC seems to be set to some
2496 random garbage. We have to rely on the fact that PC and nPC have been
2497 written previously via PIOCSREG during a register flush. */
2499 pi
->prrun
.pr_vaddr
= (caddr_t
) *(int *) ®isters
[REGISTER_BYTE (PC_REGNUM
)];
2500 pi
->prrun
.pr_flags
!= PRSVADDR
;
2504 if (signo
== SIGSTOP
&& pi
->nopass_next_sigstop
)
2505 /* When attaching to a child process, if we forced it to stop with
2506 a PIOCSTOP, then we will have set the nopass_next_sigstop flag.
2507 Upon resuming the first time after such a stop, we explicitly
2508 inhibit sending it another SIGSTOP, which would be the normal
2509 result of default signal handling. One potential drawback to
2510 this is that we will also ignore any attempt to by the user
2511 to explicitly continue after the attach with a SIGSTOP. Ultimately
2512 this problem should be dealt with by making the routines that
2513 deal with the inferior a little smarter, and possibly even allow
2514 an inferior to continue running at the same time as gdb. (FIXME?) */
2516 else if (signo
== SIGTSTP
2517 && pi
->prstatus
.pr_cursig
== SIGTSTP
2518 && pi
->prstatus
.pr_action
.sa_handler
== SIG_DFL
)
2520 /* We are about to pass the inferior a SIGTSTP whose action is
2521 SIG_DFL. The SIG_DFL action for a SIGTSTP is to stop
2522 (notifying the parent via wait()), and then keep going from the
2523 same place when the parent is ready for you to keep going. So
2524 under the debugger, it should do nothing (as if the program had
2525 been stopped and then later resumed. Under ptrace, this
2526 happens for us, but under /proc, the system obligingly stops
2527 the process, and wait_for_inferior would have no way of
2528 distinguishing that type of stop (which indicates that we
2529 should just start it again), with a stop due to the pr_trace
2530 field of the prrun_t struct.
2532 Note that if the SIGTSTP is being caught, we *do* need to pass it,
2533 because the handler needs to get executed. */
2536 signal_to_pass
= signo
;
2540 set_proc_siginfo (pi
, signal_to_pass
);
2544 pi
->prrun
.pr_flags
|= PRCSIG
;
2546 pi
->nopass_next_sigstop
= 0;
2549 pi
->prrun
.pr_flags
|= PRSTEP
;
2551 if (ioctl (pi
->fd
, PIOCRUN
, &pi
->prrun
) != 0)
2553 perror_with_name (pi
->pathname
);
2559 /* Continue all the other threads that haven't had an event of
2563 for (procinfo
= procinfo_list
; procinfo
; procinfo
= procinfo
->next
)
2565 if (pi
!= procinfo
&& !procinfo
->had_event
)
2567 procinfo
->prrun
.pr_flags
&= PRSTEP
;
2568 procinfo
->prrun
.pr_flags
|= PRCFAULT
| PRCSIG
;
2569 ioctl (procinfo
->fd
, PIOCSTATUS
, &procinfo
->prstatus
);
2570 if (ioctl (procinfo
->fd
, PIOCRUN
, &procinfo
->prrun
) < 0)
2572 if (ioctl (procinfo
->fd
, PIOCSTATUS
, &procinfo
->prstatus
) < 0)
2574 fprintf(stderr
, "PIOCSTATUS failed, errno=%d\n", errno
);
2576 print_sys_errmsg (procinfo
->pathname
, errno
);
2577 error ("PIOCRUN failed");
2579 ioctl (procinfo
->fd
, PIOCSTATUS
, &procinfo
->prstatus
);
2588 procfs_fetch_registers -- fetch current registers from inferior
2592 void procfs_fetch_registers (int regno)
2596 Read the current values of the inferior's registers, both the
2597 general register set and floating point registers (if supported)
2598 and update gdb's idea of their current values.
2603 procfs_fetch_registers (regno
)
2606 struct procinfo
*pi
;
2608 pi
= current_procinfo
;
2610 if (ioctl (pi
->fd
, PIOCGREG
, &pi
->gregset
) != -1)
2612 supply_gregset (&pi
->gregset
);
2614 #if defined (FP0_REGNUM)
2615 if (ioctl (pi
->fd
, PIOCGFPREG
, &pi
->fpregset
) != -1)
2617 supply_fpregset (&pi
->fpregset
);
2626 proc_init_failed - called whenever /proc access initialization
2631 static void proc_init_failed (struct procinfo *pi, char *why)
2635 This function is called whenever initialization of access to a /proc
2636 entry fails. It prints a suitable error message, does some cleanup,
2637 and then invokes the standard error processing routine which dumps
2638 us back into the command loop.
2642 proc_init_failed (pi
, why
)
2643 struct procinfo
*pi
;
2646 print_sys_errmsg (pi
->pathname
, errno
);
2647 kill (pi
->pid
, SIGKILL
);
2648 close_proc_file (pi
);
2657 close_proc_file - close any currently open /proc entry
2661 static void close_proc_file (struct procinfo *pip)
2665 Close any currently open /proc entry and mark the process information
2666 entry as invalid. In order to ensure that we don't try to reuse any
2667 stale information, the pid, fd, and pathnames are explicitly
2668 invalidated, which may be overkill.
2673 close_proc_file (pip
)
2674 struct procinfo
*pip
;
2676 struct procinfo
*procinfo
;
2678 remove_fd (pip
); /* Remove fd from poll/select list */
2682 free (pip
-> pathname
);
2684 /* Unlink pip from the procinfo chain. Note pip might not be on the list. */
2686 if (procinfo_list
== pip
)
2687 procinfo_list
= pip
->next
;
2689 for (procinfo
= procinfo_list
; procinfo
; procinfo
= procinfo
->next
)
2690 if (procinfo
->next
== pip
)
2691 procinfo
->next
= pip
->next
;
2700 open_proc_file - open a /proc entry for a given process id
2704 static int open_proc_file (int pid, struct procinfo *pip, int mode)
2708 Given a process id and a mode, close the existing open /proc
2709 entry (if any) and open one for the new process id, in the
2710 specified mode. Once it is open, then mark the local process
2711 information structure as valid, which guarantees that the pid,
2712 fd, and pathname fields match an open /proc entry. Returns
2713 zero if the open fails, nonzero otherwise.
2715 Note that the pathname is left intact, even when the open fails,
2716 so that callers can use it to construct meaningful error messages
2717 rather than just "file open failed".
2721 open_proc_file (pid
, pip
, mode
)
2723 struct procinfo
*pip
;
2727 pip
-> had_event
= 0;
2728 pip
-> pathname
= xmalloc (32);
2731 sprintf (pip
-> pathname
, PROC_NAME_FMT
, pid
);
2732 if ((pip
-> fd
= open (pip
-> pathname
, mode
)) < 0)
2739 mappingflags (flags
)
2742 static char asciiflags
[8];
2744 strcpy (asciiflags
, "-------");
2745 #if defined (MA_PHYS)
2746 if (flags
& MA_PHYS
) asciiflags
[0] = 'd';
2748 if (flags
& MA_STACK
) asciiflags
[1] = 's';
2749 if (flags
& MA_BREAK
) asciiflags
[2] = 'b';
2750 if (flags
& MA_SHARED
) asciiflags
[3] = 's';
2751 if (flags
& MA_READ
) asciiflags
[4] = 'r';
2752 if (flags
& MA_WRITE
) asciiflags
[5] = 'w';
2753 if (flags
& MA_EXEC
) asciiflags
[6] = 'x';
2754 return (asciiflags
);
2758 info_proc_flags (pip
, summary
)
2759 struct procinfo
*pip
;
2762 struct trans
*transp
;
2764 printf_filtered ("%-32s", "Process status flags:");
2767 printf_filtered ("\n\n");
2769 for (transp
= pr_flag_table
; transp
-> name
!= NULL
; transp
++)
2771 if (pip
-> prstatus
.pr_flags
& transp
-> value
)
2775 printf_filtered ("%s ", transp
-> name
);
2779 printf_filtered ("\t%-16s %s.\n", transp
-> name
, transp
-> desc
);
2783 printf_filtered ("\n");
2787 info_proc_stop (pip
, summary
)
2788 struct procinfo
*pip
;
2791 struct trans
*transp
;
2795 why
= pip
-> prstatus
.pr_why
;
2796 what
= pip
-> prstatus
.pr_what
;
2798 if (pip
-> prstatus
.pr_flags
& PR_STOPPED
)
2800 printf_filtered ("%-32s", "Reason for stopping:");
2803 printf_filtered ("\n\n");
2805 for (transp
= pr_why_table
; transp
-> name
!= NULL
; transp
++)
2807 if (why
== transp
-> value
)
2811 printf_filtered ("%s ", transp
-> name
);
2815 printf_filtered ("\t%-16s %s.\n",
2816 transp
-> name
, transp
-> desc
);
2822 /* Use the pr_why field to determine what the pr_what field means, and
2823 print more information. */
2828 /* pr_what is unused for this case */
2834 printf_filtered ("%s ", signalname (what
));
2838 printf_filtered ("\t%-16s %s.\n", signalname (what
),
2839 safe_strsignal (what
));
2845 printf_filtered ("%s ", syscallname (what
));
2849 printf_filtered ("\t%-16s %s.\n", syscallname (what
),
2850 "Entered this system call");
2856 printf_filtered ("%s ", syscallname (what
));
2860 printf_filtered ("\t%-16s %s.\n", syscallname (what
),
2861 "Returned from this system call");
2867 printf_filtered ("%s ",
2868 lookupname (faults_table
, what
, "fault"));
2872 printf_filtered ("\t%-16s %s.\n",
2873 lookupname (faults_table
, what
, "fault"),
2874 lookupdesc (faults_table
, what
));
2878 printf_filtered ("\n");
2883 info_proc_siginfo (pip
, summary
)
2884 struct procinfo
*pip
;
2887 struct siginfo
*sip
;
2889 if ((pip
-> prstatus
.pr_flags
& PR_STOPPED
) &&
2890 (pip
-> prstatus
.pr_why
== PR_SIGNALLED
||
2891 pip
-> prstatus
.pr_why
== PR_FAULTED
))
2893 printf_filtered ("%-32s", "Additional signal/fault info:");
2894 sip
= &pip
-> prstatus
.pr_info
;
2897 printf_filtered ("%s ", signalname (sip
-> si_signo
));
2898 if (sip
-> si_errno
> 0)
2900 printf_filtered ("%s ", errnoname (sip
-> si_errno
));
2902 if (sip
-> si_code
<= 0)
2904 printf_filtered ("sent by %s, uid %d ",
2905 target_pid_to_str (sip
-> si_pid
),
2910 printf_filtered ("%s ", sigcodename (sip
));
2911 if ((sip
-> si_signo
== SIGILL
) ||
2912 (sip
-> si_signo
== SIGFPE
) ||
2913 (sip
-> si_signo
== SIGSEGV
) ||
2914 (sip
-> si_signo
== SIGBUS
))
2916 printf_filtered ("addr=%#x ", sip
-> si_addr
);
2918 else if ((sip
-> si_signo
== SIGCHLD
))
2920 printf_filtered ("child %s, status %u ",
2921 target_pid_to_str (sip
-> si_pid
),
2924 else if ((sip
-> si_signo
== SIGPOLL
))
2926 printf_filtered ("band %u ", sip
-> si_band
);
2932 printf_filtered ("\n\n");
2933 printf_filtered ("\t%-16s %s.\n", signalname (sip
-> si_signo
),
2934 safe_strsignal (sip
-> si_signo
));
2935 if (sip
-> si_errno
> 0)
2937 printf_filtered ("\t%-16s %s.\n",
2938 errnoname (sip
-> si_errno
),
2939 safe_strerror (sip
-> si_errno
));
2941 if (sip
-> si_code
<= 0)
2943 printf_filtered ("\t%-16u %s\n", sip
-> si_pid
, /* XXX need target_pid_to_str() */
2944 "PID of process sending signal");
2945 printf_filtered ("\t%-16u %s\n", sip
-> si_uid
,
2946 "UID of process sending signal");
2950 printf_filtered ("\t%-16s %s.\n", sigcodename (sip
),
2952 if ((sip
-> si_signo
== SIGILL
) ||
2953 (sip
-> si_signo
== SIGFPE
))
2955 printf_filtered ("\t%-16#x %s.\n", sip
-> si_addr
,
2956 "Address of faulting instruction");
2958 else if ((sip
-> si_signo
== SIGSEGV
) ||
2959 (sip
-> si_signo
== SIGBUS
))
2961 printf_filtered ("\t%-16#x %s.\n", sip
-> si_addr
,
2962 "Address of faulting memory reference");
2964 else if ((sip
-> si_signo
== SIGCHLD
))
2966 printf_filtered ("\t%-16u %s.\n", sip
-> si_pid
, /* XXX need target_pid_to_str() */
2967 "Child process ID");
2968 printf_filtered ("\t%-16u %s.\n", sip
-> si_status
,
2969 "Child process exit value or signal");
2971 else if ((sip
-> si_signo
== SIGPOLL
))
2973 printf_filtered ("\t%-16u %s.\n", sip
-> si_band
,
2974 "Band event for POLL_{IN,OUT,MSG}");
2978 printf_filtered ("\n");
2983 info_proc_syscalls (pip
, summary
)
2984 struct procinfo
*pip
;
2992 #if 0 /* FIXME: Needs to use gdb-wide configured info about system calls. */
2993 if (pip
-> prstatus
.pr_flags
& PR_ASLEEP
)
2995 int syscallnum
= pip
-> prstatus
.pr_reg
[R_D0
];
2998 printf_filtered ("%-32s", "Sleeping in system call:");
2999 printf_filtered ("%s", syscallname (syscallnum
));
3003 printf_filtered ("Sleeping in system call '%s'.\n",
3004 syscallname (syscallnum
));
3009 if (ioctl (pip
-> fd
, PIOCGENTRY
, &pip
-> entryset
) < 0)
3011 print_sys_errmsg (pip
-> pathname
, errno
);
3012 error ("PIOCGENTRY failed");
3015 if (ioctl (pip
-> fd
, PIOCGEXIT
, &pip
-> exitset
) < 0)
3017 print_sys_errmsg (pip
-> pathname
, errno
);
3018 error ("PIOCGEXIT failed");
3021 printf_filtered ("System call tracing information:\n\n");
3023 printf_filtered ("\t%-12s %-8s %-8s\n",
3027 for (syscallnum
= 0; syscallnum
< MAX_SYSCALLS
; syscallnum
++)
3030 if (syscall_table
[syscallnum
] != NULL
)
3032 printf_filtered ("\t%-12s ", syscall_table
[syscallnum
]);
3033 printf_filtered ("%-8s ",
3034 prismember (&pip
-> entryset
, syscallnum
)
3036 printf_filtered ("%-8s ",
3037 prismember (&pip
-> exitset
, syscallnum
)
3039 printf_filtered ("\n");
3042 printf_filtered ("\n");
3051 static char locbuf
[32];
3053 name
= strsigno (signo
);
3056 sprintf (locbuf
, "Signal %d", signo
);
3060 sprintf (locbuf
, "%s (%d)", name
, signo
);
3070 static char locbuf
[32];
3072 name
= strerrno (errnum
);
3075 sprintf (locbuf
, "Errno %d", errnum
);
3079 sprintf (locbuf
, "%s (%d)", name
, errnum
);
3085 info_proc_signals (pip
, summary
)
3086 struct procinfo
*pip
;
3093 if (ioctl (pip
-> fd
, PIOCGTRACE
, &pip
-> trace
) < 0)
3095 print_sys_errmsg (pip
-> pathname
, errno
);
3096 error ("PIOCGTRACE failed");
3099 printf_filtered ("Disposition of signals:\n\n");
3100 printf_filtered ("\t%-15s %-8s %-8s %-8s %s\n\n",
3101 "Signal", "Trace", "Hold", "Pending", "Description");
3102 for (signo
= 0; signo
< NSIG
; signo
++)
3105 printf_filtered ("\t%-15s ", signalname (signo
));
3106 printf_filtered ("%-8s ",
3107 prismember (&pip
-> trace
, signo
)
3109 printf_filtered ("%-8s ",
3110 prismember (&pip
-> prstatus
.pr_sighold
, signo
)
3112 printf_filtered ("%-8s ",
3113 prismember (&pip
-> prstatus
.pr_sigpend
, signo
)
3115 printf_filtered (" %s\n", safe_strsignal (signo
));
3117 printf_filtered ("\n");
3122 info_proc_faults (pip
, summary
)
3123 struct procinfo
*pip
;
3126 struct trans
*transp
;
3130 if (ioctl (pip
-> fd
, PIOCGFAULT
, &pip
-> fltset
) < 0)
3132 print_sys_errmsg (pip
-> pathname
, errno
);
3133 error ("PIOCGFAULT failed");
3136 printf_filtered ("Current traced hardware fault set:\n\n");
3137 printf_filtered ("\t%-12s %-8s\n", "Fault", "Trace");
3139 for (transp
= faults_table
; transp
-> name
!= NULL
; transp
++)
3142 printf_filtered ("\t%-12s ", transp
-> name
);
3143 printf_filtered ("%-8s", prismember (&pip
-> fltset
, transp
-> value
)
3145 printf_filtered ("\n");
3147 printf_filtered ("\n");
3152 info_proc_mappings (pip
, summary
)
3153 struct procinfo
*pip
;
3157 struct prmap
*prmaps
;
3158 struct prmap
*prmap
;
3162 printf_filtered ("Mapped address spaces:\n\n");
3163 printf_filtered ("\t%10s %10s %10s %10s %7s\n",
3169 if (ioctl (pip
-> fd
, PIOCNMAP
, &nmap
) == 0)
3171 prmaps
= (struct prmap
*) alloca ((nmap
+ 1) * sizeof (*prmaps
));
3172 if (ioctl (pip
-> fd
, PIOCMAP
, prmaps
) == 0)
3174 for (prmap
= prmaps
; prmap
-> pr_size
; ++prmap
)
3176 printf_filtered ("\t%#10x %#10x %#10x %#10x %7s\n",
3178 prmap
-> pr_vaddr
+ prmap
-> pr_size
- 1,
3181 mappingflags (prmap
-> pr_mflags
));
3185 printf_filtered ("\n");
3193 info_proc -- implement the "info proc" command
3197 void info_proc (char *args, int from_tty)
3201 Implement gdb's "info proc" command by using the /proc interface
3202 to print status information about any currently running process.
3204 Examples of the use of "info proc" are:
3206 info proc (prints summary info for current inferior)
3207 info proc 123 (prints summary info for process with pid 123)
3208 info proc mappings (prints address mappings)
3209 info proc times (prints process/children times)
3210 info proc id (prints pid, ppid, gid, sid, etc)
3211 FIXME: i proc id not implemented.
3212 info proc status (prints general process state info)
3213 FIXME: i proc status not implemented.
3214 info proc signals (prints info about signal handling)
3215 info proc all (prints all info)
3220 info_proc (args
, from_tty
)
3225 struct procinfo
*pip
;
3226 struct cleanup
*old_chain
;
3240 old_chain
= make_cleanup (null_cleanup
, 0);
3242 /* Default to using the current inferior if no pid specified. Note
3243 that inferior_pid may be 0, hence we set okerr. */
3245 pip
= find_procinfo (inferior_pid
, 1);
3249 if ((argv
= buildargv (args
)) == NULL
)
3253 make_cleanup (freeargv
, (char *) argv
);
3255 while (*argv
!= NULL
)
3257 argsize
= strlen (*argv
);
3258 if (argsize
>= 1 && strncmp (*argv
, "all", argsize
) == 0)
3263 else if (argsize
>= 2 && strncmp (*argv
, "faults", argsize
) == 0)
3268 else if (argsize
>= 2 && strncmp (*argv
, "flags", argsize
) == 0)
3273 else if (argsize
>= 1 && strncmp (*argv
, "id", argsize
) == 0)
3278 else if (argsize
>= 1 && strncmp (*argv
, "mappings", argsize
) == 0)
3283 else if (argsize
>= 2 && strncmp (*argv
, "signals", argsize
) == 0)
3288 else if (argsize
>= 2 && strncmp (*argv
, "status", argsize
) == 0)
3293 else if (argsize
>= 2 && strncmp (*argv
, "syscalls", argsize
) == 0)
3298 else if (argsize
>= 1 && strncmp (*argv
, "times", argsize
) == 0)
3303 else if ((pid
= atoi (*argv
)) > 0)
3305 pip
= (struct procinfo
*) xmalloc (sizeof (struct procinfo
));
3306 memset (pip
, 0, sizeof (*pip
));
3309 if (!open_proc_file (pid
, pip
, O_RDONLY
))
3311 perror_with_name (pip
-> pathname
);
3314 make_cleanup (close_proc_file
, pip
);
3316 else if (**argv
!= '\000')
3318 error ("Unrecognized or ambiguous keyword `%s'.", *argv
);
3324 /* If we don't have a valid open process at this point, then we have no
3325 inferior or didn't specify a specific pid. */
3330 No process. Start debugging a program or specify an explicit process ID.");
3332 if (ioctl (pip
-> fd
, PIOCSTATUS
, &(pip
-> prstatus
)) < 0)
3334 print_sys_errmsg (pip
-> pathname
, errno
);
3335 error ("PIOCSTATUS failed");
3338 /* Print verbose information of the requested type(s), or just a summary
3339 of the information for all types. */
3341 printf_filtered ("\nInformation for %s:\n\n", pip
-> pathname
);
3342 if (summary
|| all
|| flags
)
3344 info_proc_flags (pip
, summary
);
3348 info_proc_stop (pip
, summary
);
3350 if (summary
|| all
|| signals
|| faults
)
3352 info_proc_siginfo (pip
, summary
);
3354 if (summary
|| all
|| syscalls
)
3356 info_proc_syscalls (pip
, summary
);
3358 if (summary
|| all
|| mappings
)
3360 info_proc_mappings (pip
, summary
);
3362 if (summary
|| all
|| signals
)
3364 info_proc_signals (pip
, summary
);
3366 if (summary
|| all
|| faults
)
3368 info_proc_faults (pip
, summary
);
3370 printf_filtered ("\n");
3372 /* All done, deal with closing any temporary process info structure,
3373 freeing temporary memory , etc. */
3375 do_cleanups (old_chain
);
3382 procfs_set_sproc_trap -- arrange for exec'd child stop on sproc
3386 void procfs_set_sproc_trap (void)
3390 This function sets up a trap on sproc system call exits so that we can
3391 detect the arrival of a new thread. We are called with the child
3392 stopped prior to it's first instruction.
3394 Also note that we turn on the inherit-on-fork flag in the child process
3395 so that any grand-children start with all tracing flags set.
3401 procfs_set_sproc_trap (pi
)
3402 struct procinfo
*pi
;
3406 if (ioctl (pi
->fd
, PIOCGEXIT
, &exitset
) < 0)
3408 print_sys_errmsg (pi
->pathname
, errno
);
3409 error ("PIOCGEXIT failed");
3412 praddset (&exitset
, SYS_sproc
);
3414 if (ioctl (pi
->fd
, PIOCSEXIT
, &exitset
) < 0)
3416 print_sys_errmsg (pi
->pathname
, errno
);
3417 error ("PIOCSEXIT failed");
3420 /* Turn on inherit-on-fork flag so that all grand-children of gdb start with
3421 tracing flags set. */
3423 #ifdef PIOCSET /* New method */
3427 ioctl (pi
->fd
, PIOCSET
, &pr_flags
);
3430 #ifdef PIOCSFORK /* Original method */
3431 ioctl (pi
->fd
, PIOCSFORK
, NULL
);
3435 #endif /* SYS_sproc */
3437 /* Fork an inferior process, and start debugging it with /proc. */
3440 procfs_create_inferior (exec_file
, allargs
, env
)
3445 fork_inferior (exec_file
, allargs
, env
,
3446 proc_set_exec_trap
, procfs_init_inferior
);
3447 /* We are at the first instruction we care about. */
3448 /* Pedal to the metal... */
3450 /* Setup traps on exit from sproc() */
3453 procfs_set_sproc_trap (current_procinfo
);
3456 proceed ((CORE_ADDR
) -1, 0, 0);
3459 /* Clean up after the inferior dies. */
3462 procfs_mourn_inferior ()
3464 unpush_target (&procfs_ops
);
3465 generic_mourn_inferior ();
3468 /* Mark our target-struct as eligible for stray "run" and "attach" commands. */
3475 struct target_ops procfs_ops
= {
3476 "procfs", /* to_shortname */
3477 "Unix /proc child process", /* to_longname */
3478 "Unix /proc child process (started by the \"run\" command).", /* to_doc */
3479 procfs_open
, /* to_open */
3481 procfs_attach
, /* to_attach */
3482 procfs_detach
, /* to_detach */
3483 procfs_resume
, /* to_resume */
3484 procfs_wait
, /* to_wait */
3485 procfs_fetch_registers
, /* to_fetch_registers */
3486 procfs_store_registers
, /* to_store_registers */
3487 procfs_prepare_to_store
, /* to_prepare_to_store */
3488 procfs_xfer_memory
, /* to_xfer_memory */
3489 procfs_files_info
, /* to_files_info */
3490 memory_insert_breakpoint
, /* to_insert_breakpoint */
3491 memory_remove_breakpoint
, /* to_remove_breakpoint */
3492 terminal_init_inferior
, /* to_terminal_init */
3493 terminal_inferior
, /* to_terminal_inferior */
3494 terminal_ours_for_output
, /* to_terminal_ours_for_output */
3495 terminal_ours
, /* to_terminal_ours */
3496 child_terminal_info
, /* to_terminal_info */
3497 procfs_kill_inferior
, /* to_kill */
3499 0, /* to_lookup_symbol */
3500 procfs_create_inferior
, /* to_create_inferior */
3501 procfs_mourn_inferior
, /* to_mourn_inferior */
3502 procfs_can_run
, /* to_can_run */
3503 procfs_notice_signals
, /* to_notice_signals */
3504 process_stratum
, /* to_stratum */
3506 1, /* to_has_all_memory */
3507 1, /* to_has_memory */
3508 1, /* to_has_stack */
3509 1, /* to_has_registers */
3510 1, /* to_has_execution */
3512 0, /* sections_end */
3513 OPS_MAGIC
/* to_magic */
3520 _initialize_procfs -- initialize the process file system stuff
3524 void _initialize_procfs (void)
3528 Do required initializations during gdb startup for using the
3529 /proc file system interface.
3534 _initialize_procfs ()
3536 add_target (&procfs_ops
);
3538 add_info ("proc", info_proc
,
3539 "Show process status information using /proc entry.\n\
3540 Specify process id or use current inferior by default.\n\
3541 Specify keywords for detailed information; default is summary.\n\
3542 Keywords are: `all', `faults', `flags', `id', `mappings', `signals',\n\
3543 `status', `syscalls', and `times'.\n\
3544 Unambiguous abbreviations may be used.");
3546 init_syscall_table ();