1 /* Machine independent support for SVR4 /proc (process file system) for GDB.
2 Copyright 1991, 1992, 1993, 1994, 1995 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/fault.h>
40 #include <sys/syscall.h>
41 #include <sys/procfs.h>
56 #define MAX_SYSCALLS 256 /* Maximum number of syscalls for table */
59 #define PROC_NAME_FMT "/proc/%05d"
62 extern struct target_ops procfs_ops
; /* Forward declaration */
64 #if 1 /* FIXME: Gross and ugly hack to resolve coredep.c global */
65 CORE_ADDR kernel_u_addr
;
68 #ifdef BROKEN_SIGINFO_H /* Workaround broken SGS <sys/siginfo.h> */
70 #define si_pid _data._proc.pid
72 #define si_uid _data._proc._pdata._kill.uid
73 #endif /* BROKEN_SIGINFO_H */
75 /* All access to the inferior, either one started by gdb or one that has
76 been attached to, is controlled by an instance of a procinfo structure,
77 defined below. Since gdb currently only handles one inferior at a time,
78 the procinfo structure for the inferior is statically allocated and
79 only one exists at any given time. There is a separate procinfo
80 structure for use by the "info proc" command, so that we can print
81 useful information about any random process without interfering with
82 the inferior's procinfo information. */
85 struct procinfo
*next
;
86 int pid
; /* Process ID of inferior */
87 int fd
; /* File descriptor for /proc entry */
88 char *pathname
; /* Pathname to /proc entry */
89 int had_event
; /* poll/select says something happened */
90 int was_stopped
; /* Nonzero if was stopped prior to attach */
91 int nopass_next_sigstop
; /* Don't pass a sigstop on next resume */
92 prrun_t prrun
; /* Control state when it is run */
93 prstatus_t prstatus
; /* Current process status info */
94 gregset_t gregset
; /* General register set */
95 fpregset_t fpregset
; /* Floating point register set */
96 fltset_t fltset
; /* Current traced hardware fault set */
97 sigset_t trace
; /* Current traced signal set */
98 sysset_t exitset
; /* Current traced system call exit set */
99 sysset_t entryset
; /* Current traced system call entry set */
100 fltset_t saved_fltset
; /* Saved traced hardware fault set */
101 sigset_t saved_trace
; /* Saved traced signal set */
102 sigset_t saved_sighold
; /* Saved held signal set */
103 sysset_t saved_exitset
; /* Saved traced system call exit set */
104 sysset_t saved_entryset
; /* Saved traced system call entry set */
107 /* List of inferior process information */
108 static struct procinfo
*procinfo_list
= NULL
;
110 static struct pollfd
*poll_list
; /* pollfds used for waiting on /proc */
112 static int num_poll_list
= 0; /* Number of entries in poll_list */
114 static int last_resume_pid
= -1; /* Last pid used with procfs_resume */
116 /* Much of the information used in the /proc interface, particularly for
117 printing status information, is kept as tables of structures of the
118 following form. These tables can be used to map numeric values to
119 their symbolic names and to a string that describes their specific use. */
122 int value
; /* The numeric value */
123 char *name
; /* The equivalent symbolic value */
124 char *desc
; /* Short description of value */
127 /* Translate bits in the pr_flags member of the prstatus structure, into the
128 names and desc information. */
130 static struct trans pr_flag_table
[] =
132 #if defined (PR_STOPPED)
133 { PR_STOPPED
, "PR_STOPPED", "Process is stopped" },
135 #if defined (PR_ISTOP)
136 { PR_ISTOP
, "PR_ISTOP", "Stopped on an event of interest" },
138 #if defined (PR_DSTOP)
139 { PR_DSTOP
, "PR_DSTOP", "A stop directive is in effect" },
141 #if defined (PR_ASLEEP)
142 { PR_ASLEEP
, "PR_ASLEEP", "Sleeping in an interruptible system call" },
144 #if defined (PR_FORK)
145 { PR_FORK
, "PR_FORK", "Inherit-on-fork is in effect" },
148 { PR_RLC
, "PR_RLC", "Run-on-last-close is in effect" },
150 #if defined (PR_PTRACE)
151 { PR_PTRACE
, "PR_PTRACE", "Process is being controlled by ptrace" },
153 #if defined (PR_PCINVAL)
154 { PR_PCINVAL
, "PR_PCINVAL", "PC refers to an invalid virtual address" },
156 #if defined (PR_ISSYS)
157 { PR_ISSYS
, "PR_ISSYS", "Is a system process" },
159 #if defined (PR_STEP)
160 { PR_STEP
, "PR_STEP", "Process has single step pending" },
163 { PR_KLC
, "PR_KLC", "Kill-on-last-close is in effect" },
165 #if defined (PR_ASYNC)
166 { PR_ASYNC
, "PR_ASYNC", "Asynchronous stop is in effect" },
168 #if defined (PR_PCOMPAT)
169 { PR_PCOMPAT
, "PR_PCOMPAT", "Ptrace compatibility mode in effect" },
174 /* Translate values in the pr_why field of the prstatus struct. */
176 static struct trans pr_why_table
[] =
178 #if defined (PR_REQUESTED)
179 { PR_REQUESTED
, "PR_REQUESTED", "Directed to stop via PIOCSTOP/PIOCWSTOP" },
181 #if defined (PR_SIGNALLED)
182 { PR_SIGNALLED
, "PR_SIGNALLED", "Receipt of a traced signal" },
184 #if defined (PR_FAULTED)
185 { PR_FAULTED
, "PR_FAULTED", "Incurred a traced hardware fault" },
187 #if defined (PR_SYSENTRY)
188 { PR_SYSENTRY
, "PR_SYSENTRY", "Entry to a traced system call" },
190 #if defined (PR_SYSEXIT)
191 { PR_SYSEXIT
, "PR_SYSEXIT", "Exit from a traced system call" },
193 #if defined (PR_JOBCONTROL)
194 { PR_JOBCONTROL
, "PR_JOBCONTROL", "Default job control stop signal action" },
196 #if defined (PR_SUSPENDED)
197 { PR_SUSPENDED
, "PR_SUSPENDED", "Process suspended" },
202 /* Hardware fault translation table. */
204 static struct trans faults_table
[] =
207 { FLTILL
, "FLTILL", "Illegal instruction" },
209 #if defined (FLTPRIV)
210 { FLTPRIV
, "FLTPRIV", "Privileged instruction" },
213 { FLTBPT
, "FLTBPT", "Breakpoint trap" },
215 #if defined (FLTTRACE)
216 { FLTTRACE
, "FLTTRACE", "Trace trap" },
218 #if defined (FLTACCESS)
219 { FLTACCESS
, "FLTACCESS", "Memory access fault" },
221 #if defined (FLTBOUNDS)
222 { FLTBOUNDS
, "FLTBOUNDS", "Memory bounds violation" },
224 #if defined (FLTIOVF)
225 { FLTIOVF
, "FLTIOVF", "Integer overflow" },
227 #if defined (FLTIZDIV)
228 { FLTIZDIV
, "FLTIZDIV", "Integer zero divide" },
231 { FLTFPE
, "FLTFPE", "Floating-point exception" },
233 #if defined (FLTSTACK)
234 { FLTSTACK
, "FLTSTACK", "Unrecoverable stack fault" },
236 #if defined (FLTPAGE)
237 { FLTPAGE
, "FLTPAGE", "Recoverable page fault" },
242 /* Translation table for signal generation information. See UNIX System
243 V Release 4 Programmer's Reference Manual, siginfo(5). */
245 static struct sigcode
{
250 } siginfo_table
[] = {
251 #if defined (SIGILL) && defined (ILL_ILLOPC)
252 { SIGILL
, ILL_ILLOPC
, "ILL_ILLOPC", "Illegal opcode" },
254 #if defined (SIGILL) && defined (ILL_ILLOPN)
255 { SIGILL
, ILL_ILLOPN
, "ILL_ILLOPN", "Illegal operand", },
257 #if defined (SIGILL) && defined (ILL_ILLADR)
258 { SIGILL
, ILL_ILLADR
, "ILL_ILLADR", "Illegal addressing mode" },
260 #if defined (SIGILL) && defined (ILL_ILLTRP)
261 { SIGILL
, ILL_ILLTRP
, "ILL_ILLTRP", "Illegal trap" },
263 #if defined (SIGILL) && defined (ILL_PRVOPC)
264 { SIGILL
, ILL_PRVOPC
, "ILL_PRVOPC", "Privileged opcode" },
266 #if defined (SIGILL) && defined (ILL_PRVREG)
267 { SIGILL
, ILL_PRVREG
, "ILL_PRVREG", "Privileged register" },
269 #if defined (SIGILL) && defined (ILL_COPROC)
270 { SIGILL
, ILL_COPROC
, "ILL_COPROC", "Coprocessor error" },
272 #if defined (SIGILL) && defined (ILL_BADSTK)
273 { SIGILL
, ILL_BADSTK
, "ILL_BADSTK", "Internal stack error" },
275 #if defined (SIGFPE) && defined (FPE_INTDIV)
276 { SIGFPE
, FPE_INTDIV
, "FPE_INTDIV", "Integer divide by zero" },
278 #if defined (SIGFPE) && defined (FPE_INTOVF)
279 { SIGFPE
, FPE_INTOVF
, "FPE_INTOVF", "Integer overflow" },
281 #if defined (SIGFPE) && defined (FPE_FLTDIV)
282 { SIGFPE
, FPE_FLTDIV
, "FPE_FLTDIV", "Floating point divide by zero" },
284 #if defined (SIGFPE) && defined (FPE_FLTOVF)
285 { SIGFPE
, FPE_FLTOVF
, "FPE_FLTOVF", "Floating point overflow" },
287 #if defined (SIGFPE) && defined (FPE_FLTUND)
288 { SIGFPE
, FPE_FLTUND
, "FPE_FLTUND", "Floating point underflow" },
290 #if defined (SIGFPE) && defined (FPE_FLTRES)
291 { SIGFPE
, FPE_FLTRES
, "FPE_FLTRES", "Floating point inexact result" },
293 #if defined (SIGFPE) && defined (FPE_FLTINV)
294 { SIGFPE
, FPE_FLTINV
, "FPE_FLTINV", "Invalid floating point operation" },
296 #if defined (SIGFPE) && defined (FPE_FLTSUB)
297 { SIGFPE
, FPE_FLTSUB
, "FPE_FLTSUB", "Subscript out of range" },
299 #if defined (SIGSEGV) && defined (SEGV_MAPERR)
300 { SIGSEGV
, SEGV_MAPERR
, "SEGV_MAPERR", "Address not mapped to object" },
302 #if defined (SIGSEGV) && defined (SEGV_ACCERR)
303 { SIGSEGV
, SEGV_ACCERR
, "SEGV_ACCERR", "Invalid permissions for object" },
305 #if defined (SIGBUS) && defined (BUS_ADRALN)
306 { SIGBUS
, BUS_ADRALN
, "BUS_ADRALN", "Invalid address alignment" },
308 #if defined (SIGBUS) && defined (BUS_ADRERR)
309 { SIGBUS
, BUS_ADRERR
, "BUS_ADRERR", "Non-existent physical address" },
311 #if defined (SIGBUS) && defined (BUS_OBJERR)
312 { SIGBUS
, BUS_OBJERR
, "BUS_OBJERR", "Object specific hardware error" },
314 #if defined (SIGTRAP) && defined (TRAP_BRKPT)
315 { SIGTRAP
, TRAP_BRKPT
, "TRAP_BRKPT", "Process breakpoint" },
317 #if defined (SIGTRAP) && defined (TRAP_TRACE)
318 { SIGTRAP
, TRAP_TRACE
, "TRAP_TRACE", "Process trace trap" },
320 #if defined (SIGCLD) && defined (CLD_EXITED)
321 { SIGCLD
, CLD_EXITED
, "CLD_EXITED", "Child has exited" },
323 #if defined (SIGCLD) && defined (CLD_KILLED)
324 { SIGCLD
, CLD_KILLED
, "CLD_KILLED", "Child was killed" },
326 #if defined (SIGCLD) && defined (CLD_DUMPED)
327 { SIGCLD
, CLD_DUMPED
, "CLD_DUMPED", "Child has terminated abnormally" },
329 #if defined (SIGCLD) && defined (CLD_TRAPPED)
330 { SIGCLD
, CLD_TRAPPED
, "CLD_TRAPPED", "Traced child has trapped" },
332 #if defined (SIGCLD) && defined (CLD_STOPPED)
333 { SIGCLD
, CLD_STOPPED
, "CLD_STOPPED", "Child has stopped" },
335 #if defined (SIGCLD) && defined (CLD_CONTINUED)
336 { SIGCLD
, CLD_CONTINUED
, "CLD_CONTINUED", "Stopped child had continued" },
338 #if defined (SIGPOLL) && defined (POLL_IN)
339 { SIGPOLL
, POLL_IN
, "POLL_IN", "Input input available" },
341 #if defined (SIGPOLL) && defined (POLL_OUT)
342 { SIGPOLL
, POLL_OUT
, "POLL_OUT", "Output buffers available" },
344 #if defined (SIGPOLL) && defined (POLL_MSG)
345 { SIGPOLL
, POLL_MSG
, "POLL_MSG", "Input message available" },
347 #if defined (SIGPOLL) && defined (POLL_ERR)
348 { SIGPOLL
, POLL_ERR
, "POLL_ERR", "I/O error" },
350 #if defined (SIGPOLL) && defined (POLL_PRI)
351 { SIGPOLL
, POLL_PRI
, "POLL_PRI", "High priority input available" },
353 #if defined (SIGPOLL) && defined (POLL_HUP)
354 { SIGPOLL
, POLL_HUP
, "POLL_HUP", "Device disconnected" },
359 static char *syscall_table
[MAX_SYSCALLS
];
361 /* Prototypes for local functions */
363 static void set_proc_siginfo
PARAMS ((struct procinfo
*, int));
365 static void init_syscall_table
PARAMS ((void));
367 static char *syscallname
PARAMS ((int));
369 static char *signalname
PARAMS ((int));
371 static char *errnoname
PARAMS ((int));
373 static int proc_address_to_fd
PARAMS ((struct procinfo
*, CORE_ADDR
, int));
375 static int open_proc_file
PARAMS ((int, struct procinfo
*, int));
377 static void close_proc_file
PARAMS ((struct procinfo
*));
379 static void unconditionally_kill_inferior
PARAMS ((struct procinfo
*));
381 static NORETURN
void proc_init_failed
PARAMS ((struct procinfo
*, char *)) ATTR_NORETURN
;
383 static void info_proc
PARAMS ((char *, int));
385 static void info_proc_flags
PARAMS ((struct procinfo
*, int));
387 static void info_proc_stop
PARAMS ((struct procinfo
*, int));
389 static void info_proc_siginfo
PARAMS ((struct procinfo
*, int));
391 static void info_proc_syscalls
PARAMS ((struct procinfo
*, int));
393 static void info_proc_mappings
PARAMS ((struct procinfo
*, int));
395 static void info_proc_signals
PARAMS ((struct procinfo
*, int));
397 static void info_proc_faults
PARAMS ((struct procinfo
*, int));
399 static char *mappingflags
PARAMS ((long));
401 static char *lookupname
PARAMS ((struct trans
*, unsigned int, char *));
403 static char *lookupdesc
PARAMS ((struct trans
*, unsigned int));
405 static int do_attach
PARAMS ((int pid
));
407 static void do_detach
PARAMS ((int siggnal
));
409 static void procfs_create_inferior
PARAMS ((char *, char *, char **));
411 static void procfs_notice_signals
PARAMS ((int pid
));
413 static struct procinfo
*find_procinfo
PARAMS ((pid_t pid
, int okfail
));
415 /* External function prototypes that can't be easily included in any
416 header file because the args are typedefs in system include files. */
418 extern void supply_gregset
PARAMS ((gregset_t
*));
420 extern void fill_gregset
PARAMS ((gregset_t
*, int));
422 extern void supply_fpregset
PARAMS ((fpregset_t
*));
424 extern void fill_fpregset
PARAMS ((fpregset_t
*, int));
430 find_procinfo -- convert a process id to a struct procinfo
434 static struct procinfo * find_procinfo (pid_t pid, int okfail);
438 Given a process id, look it up in the procinfo chain. Returns
439 a struct procinfo *. If can't find pid, then call error(),
440 unless okfail is set, in which case, return NULL;
443 static struct procinfo
*
444 find_procinfo (pid
, okfail
)
448 struct procinfo
*procinfo
;
450 for (procinfo
= procinfo_list
; procinfo
; procinfo
= procinfo
->next
)
451 if (procinfo
->pid
== pid
)
457 error ("procfs (find_procinfo): Couldn't locate pid %d", pid
);
464 current_procinfo -- convert inferior_pid to a struct procinfo
468 static struct procinfo * current_procinfo;
472 Looks up inferior_pid in the procinfo chain. Always returns a
473 struct procinfo *. If process can't be found, we error() out.
476 #define current_procinfo find_procinfo (inferior_pid, 0)
482 add_fd -- Add the fd to the poll/select list
486 static void add_fd (struct procinfo *);
490 Add the fd of the supplied procinfo to the list of fds used for
491 poll/select operations.
498 if (num_poll_list
<= 0)
499 poll_list
= (struct pollfd
*) xmalloc (sizeof (struct pollfd
));
501 poll_list
= (struct pollfd
*) xrealloc (poll_list
,
503 * sizeof (struct pollfd
));
504 poll_list
[num_poll_list
].fd
= pi
->fd
;
505 poll_list
[num_poll_list
].events
= POLLPRI
;
516 for (i
= 0; i
< num_poll_list
; i
++)
518 if (poll_list
[i
].fd
== pi
->fd
)
520 if (i
!= num_poll_list
- 1)
521 memcpy (poll_list
, poll_list
+ i
+ 1,
522 (num_poll_list
- i
- 1) * sizeof (struct pollfd
));
526 if (num_poll_list
== 0)
529 poll_list
= (struct pollfd
*) xrealloc (poll_list
,
531 * sizeof (struct pollfd
));
537 #define LOSING_POLL unixware_sux
539 static struct procinfo
*
546 set_sigint_trap (); /* Causes SIGINT to be passed on to the
551 num_fds
= poll (poll_list
, num_poll_list
, -1);
553 pi
= current_procinfo
;
555 while (ioctl (pi
->fd
, PIOCWSTOP
, &pi
->prstatus
) < 0)
559 /* Process exited. */
560 pi
->prstatus
.pr_flags
= 0;
563 else if (errno
!= EINTR
)
565 print_sys_errmsg (pi
->pathname
, errno
);
566 error ("PIOCWSTOP failed");
572 clear_sigint_trap ();
579 print_sys_errmsg ("poll failed\n", errno
);
580 error ("Poll failed, returned %d", num_fds
);
583 for (i
= 0; i
< num_poll_list
&& num_fds
> 0; i
++)
585 if ((poll_list
[i
].revents
& (POLLPRI
|POLLERR
|POLLHUP
|POLLNVAL
)) == 0)
587 for (pi
= procinfo_list
; pi
; pi
= pi
->next
)
589 if (poll_list
[i
].fd
== pi
->fd
)
591 if (ioctl (pi
->fd
, PIOCSTATUS
, &pi
->prstatus
) < 0)
593 print_sys_errmsg (pi
->pathname
, errno
);
594 error ("PIOCSTATUS failed");
602 error ("procfs_wait: Couldn't find procinfo for fd %d\n",
605 #endif /* LOSING_POLL */
614 lookupdesc -- translate a value to a summary desc string
618 static char *lookupdesc (struct trans *transp, unsigned int val);
622 Given a pointer to a translation table and a value to be translated,
623 lookup the desc string and return it.
627 lookupdesc (transp
, val
)
628 struct trans
*transp
;
633 for (desc
= NULL
; transp
-> name
!= NULL
; transp
++)
635 if (transp
-> value
== val
)
637 desc
= transp
-> desc
;
642 /* Didn't find a translation for the specified value, set a default one. */
655 lookupname -- translate a value to symbolic name
659 static char *lookupname (struct trans *transp, unsigned int val,
664 Given a pointer to a translation table, a value to be translated,
665 and a default prefix to return if the value can't be translated,
666 match the value with one of the translation table entries and
667 return a pointer to the symbolic name.
669 If no match is found it just returns the value as a printable string,
670 with the given prefix. The previous such value, if any, is freed
675 lookupname (transp
, val
, prefix
)
676 struct trans
*transp
;
683 for (name
= NULL
; transp
-> name
!= NULL
; transp
++)
685 if (transp
-> value
== val
)
687 name
= transp
-> name
;
692 /* Didn't find a translation for the specified value, build a default
693 one using the specified prefix and return it. The lifetime of
694 the value is only until the next one is needed. */
702 locbuf
= xmalloc (strlen (prefix
) + 16);
703 sprintf (locbuf
, "%s %u", prefix
, val
);
715 static char locbuf
[32];
717 for (scp
= siginfo_table
; scp
-> codename
!= NULL
; scp
++)
719 if ((scp
-> signo
== sip
-> si_signo
) &&
720 (scp
-> code
== sip
-> si_code
))
722 name
= scp
-> codename
;
728 sprintf (locbuf
, "sigcode %u", sip
-> si_signo
);
741 for (scp
= siginfo_table
; scp
-> codename
!= NULL
; scp
++)
743 if ((scp
-> signo
== sip
-> si_signo
) &&
744 (scp
-> code
== sip
-> si_code
))
752 desc
= "Unrecognized signal or trap use";
761 syscallname - translate a system call number into a system call name
765 char *syscallname (int syscallnum)
769 Given a system call number, translate it into the printable name
770 of a system call, or into "syscall <num>" if it is an unknown
775 syscallname (syscallnum
)
778 static char locbuf
[32];
781 if (syscallnum
>= 0 && syscallnum
< MAX_SYSCALLS
)
783 rtnval
= syscall_table
[syscallnum
];
787 sprintf (locbuf
, "syscall %u", syscallnum
);
797 init_syscall_table - initialize syscall translation table
801 void init_syscall_table (void)
805 Dynamically initialize the translation table to convert system
806 call numbers into printable system call names. Done once per
807 gdb run, on initialization.
811 This is awfully ugly, but preprocessor tricks to make it prettier
812 tend to be nonportable.
816 init_syscall_table ()
818 #if defined (SYS_exit)
819 syscall_table
[SYS_exit
] = "exit";
821 #if defined (SYS_fork)
822 syscall_table
[SYS_fork
] = "fork";
824 #if defined (SYS_read)
825 syscall_table
[SYS_read
] = "read";
827 #if defined (SYS_write)
828 syscall_table
[SYS_write
] = "write";
830 #if defined (SYS_open)
831 syscall_table
[SYS_open
] = "open";
833 #if defined (SYS_close)
834 syscall_table
[SYS_close
] = "close";
836 #if defined (SYS_wait)
837 syscall_table
[SYS_wait
] = "wait";
839 #if defined (SYS_creat)
840 syscall_table
[SYS_creat
] = "creat";
842 #if defined (SYS_link)
843 syscall_table
[SYS_link
] = "link";
845 #if defined (SYS_unlink)
846 syscall_table
[SYS_unlink
] = "unlink";
848 #if defined (SYS_exec)
849 syscall_table
[SYS_exec
] = "exec";
851 #if defined (SYS_execv)
852 syscall_table
[SYS_execv
] = "execv";
854 #if defined (SYS_execve)
855 syscall_table
[SYS_execve
] = "execve";
857 #if defined (SYS_chdir)
858 syscall_table
[SYS_chdir
] = "chdir";
860 #if defined (SYS_time)
861 syscall_table
[SYS_time
] = "time";
863 #if defined (SYS_mknod)
864 syscall_table
[SYS_mknod
] = "mknod";
866 #if defined (SYS_chmod)
867 syscall_table
[SYS_chmod
] = "chmod";
869 #if defined (SYS_chown)
870 syscall_table
[SYS_chown
] = "chown";
872 #if defined (SYS_brk)
873 syscall_table
[SYS_brk
] = "brk";
875 #if defined (SYS_stat)
876 syscall_table
[SYS_stat
] = "stat";
878 #if defined (SYS_lseek)
879 syscall_table
[SYS_lseek
] = "lseek";
881 #if defined (SYS_getpid)
882 syscall_table
[SYS_getpid
] = "getpid";
884 #if defined (SYS_mount)
885 syscall_table
[SYS_mount
] = "mount";
887 #if defined (SYS_umount)
888 syscall_table
[SYS_umount
] = "umount";
890 #if defined (SYS_setuid)
891 syscall_table
[SYS_setuid
] = "setuid";
893 #if defined (SYS_getuid)
894 syscall_table
[SYS_getuid
] = "getuid";
896 #if defined (SYS_stime)
897 syscall_table
[SYS_stime
] = "stime";
899 #if defined (SYS_ptrace)
900 syscall_table
[SYS_ptrace
] = "ptrace";
902 #if defined (SYS_alarm)
903 syscall_table
[SYS_alarm
] = "alarm";
905 #if defined (SYS_fstat)
906 syscall_table
[SYS_fstat
] = "fstat";
908 #if defined (SYS_pause)
909 syscall_table
[SYS_pause
] = "pause";
911 #if defined (SYS_utime)
912 syscall_table
[SYS_utime
] = "utime";
914 #if defined (SYS_stty)
915 syscall_table
[SYS_stty
] = "stty";
917 #if defined (SYS_gtty)
918 syscall_table
[SYS_gtty
] = "gtty";
920 #if defined (SYS_access)
921 syscall_table
[SYS_access
] = "access";
923 #if defined (SYS_nice)
924 syscall_table
[SYS_nice
] = "nice";
926 #if defined (SYS_statfs)
927 syscall_table
[SYS_statfs
] = "statfs";
929 #if defined (SYS_sync)
930 syscall_table
[SYS_sync
] = "sync";
932 #if defined (SYS_kill)
933 syscall_table
[SYS_kill
] = "kill";
935 #if defined (SYS_fstatfs)
936 syscall_table
[SYS_fstatfs
] = "fstatfs";
938 #if defined (SYS_pgrpsys)
939 syscall_table
[SYS_pgrpsys
] = "pgrpsys";
941 #if defined (SYS_xenix)
942 syscall_table
[SYS_xenix
] = "xenix";
944 #if defined (SYS_dup)
945 syscall_table
[SYS_dup
] = "dup";
947 #if defined (SYS_pipe)
948 syscall_table
[SYS_pipe
] = "pipe";
950 #if defined (SYS_times)
951 syscall_table
[SYS_times
] = "times";
953 #if defined (SYS_profil)
954 syscall_table
[SYS_profil
] = "profil";
956 #if defined (SYS_plock)
957 syscall_table
[SYS_plock
] = "plock";
959 #if defined (SYS_setgid)
960 syscall_table
[SYS_setgid
] = "setgid";
962 #if defined (SYS_getgid)
963 syscall_table
[SYS_getgid
] = "getgid";
965 #if defined (SYS_signal)
966 syscall_table
[SYS_signal
] = "signal";
968 #if defined (SYS_msgsys)
969 syscall_table
[SYS_msgsys
] = "msgsys";
971 #if defined (SYS_sys3b)
972 syscall_table
[SYS_sys3b
] = "sys3b";
974 #if defined (SYS_acct)
975 syscall_table
[SYS_acct
] = "acct";
977 #if defined (SYS_shmsys)
978 syscall_table
[SYS_shmsys
] = "shmsys";
980 #if defined (SYS_semsys)
981 syscall_table
[SYS_semsys
] = "semsys";
983 #if defined (SYS_ioctl)
984 syscall_table
[SYS_ioctl
] = "ioctl";
986 #if defined (SYS_uadmin)
987 syscall_table
[SYS_uadmin
] = "uadmin";
989 #if defined (SYS_utssys)
990 syscall_table
[SYS_utssys
] = "utssys";
992 #if defined (SYS_fsync)
993 syscall_table
[SYS_fsync
] = "fsync";
995 #if defined (SYS_umask)
996 syscall_table
[SYS_umask
] = "umask";
998 #if defined (SYS_chroot)
999 syscall_table
[SYS_chroot
] = "chroot";
1001 #if defined (SYS_fcntl)
1002 syscall_table
[SYS_fcntl
] = "fcntl";
1004 #if defined (SYS_ulimit)
1005 syscall_table
[SYS_ulimit
] = "ulimit";
1007 #if defined (SYS_rfsys)
1008 syscall_table
[SYS_rfsys
] = "rfsys";
1010 #if defined (SYS_rmdir)
1011 syscall_table
[SYS_rmdir
] = "rmdir";
1013 #if defined (SYS_mkdir)
1014 syscall_table
[SYS_mkdir
] = "mkdir";
1016 #if defined (SYS_getdents)
1017 syscall_table
[SYS_getdents
] = "getdents";
1019 #if defined (SYS_sysfs)
1020 syscall_table
[SYS_sysfs
] = "sysfs";
1022 #if defined (SYS_getmsg)
1023 syscall_table
[SYS_getmsg
] = "getmsg";
1025 #if defined (SYS_putmsg)
1026 syscall_table
[SYS_putmsg
] = "putmsg";
1028 #if defined (SYS_poll)
1029 syscall_table
[SYS_poll
] = "poll";
1031 #if defined (SYS_lstat)
1032 syscall_table
[SYS_lstat
] = "lstat";
1034 #if defined (SYS_symlink)
1035 syscall_table
[SYS_symlink
] = "symlink";
1037 #if defined (SYS_readlink)
1038 syscall_table
[SYS_readlink
] = "readlink";
1040 #if defined (SYS_setgroups)
1041 syscall_table
[SYS_setgroups
] = "setgroups";
1043 #if defined (SYS_getgroups)
1044 syscall_table
[SYS_getgroups
] = "getgroups";
1046 #if defined (SYS_fchmod)
1047 syscall_table
[SYS_fchmod
] = "fchmod";
1049 #if defined (SYS_fchown)
1050 syscall_table
[SYS_fchown
] = "fchown";
1052 #if defined (SYS_sigprocmask)
1053 syscall_table
[SYS_sigprocmask
] = "sigprocmask";
1055 #if defined (SYS_sigsuspend)
1056 syscall_table
[SYS_sigsuspend
] = "sigsuspend";
1058 #if defined (SYS_sigaltstack)
1059 syscall_table
[SYS_sigaltstack
] = "sigaltstack";
1061 #if defined (SYS_sigaction)
1062 syscall_table
[SYS_sigaction
] = "sigaction";
1064 #if defined (SYS_sigpending)
1065 syscall_table
[SYS_sigpending
] = "sigpending";
1067 #if defined (SYS_context)
1068 syscall_table
[SYS_context
] = "context";
1070 #if defined (SYS_evsys)
1071 syscall_table
[SYS_evsys
] = "evsys";
1073 #if defined (SYS_evtrapret)
1074 syscall_table
[SYS_evtrapret
] = "evtrapret";
1076 #if defined (SYS_statvfs)
1077 syscall_table
[SYS_statvfs
] = "statvfs";
1079 #if defined (SYS_fstatvfs)
1080 syscall_table
[SYS_fstatvfs
] = "fstatvfs";
1082 #if defined (SYS_nfssys)
1083 syscall_table
[SYS_nfssys
] = "nfssys";
1085 #if defined (SYS_waitsys)
1086 syscall_table
[SYS_waitsys
] = "waitsys";
1088 #if defined (SYS_sigsendsys)
1089 syscall_table
[SYS_sigsendsys
] = "sigsendsys";
1091 #if defined (SYS_hrtsys)
1092 syscall_table
[SYS_hrtsys
] = "hrtsys";
1094 #if defined (SYS_acancel)
1095 syscall_table
[SYS_acancel
] = "acancel";
1097 #if defined (SYS_async)
1098 syscall_table
[SYS_async
] = "async";
1100 #if defined (SYS_priocntlsys)
1101 syscall_table
[SYS_priocntlsys
] = "priocntlsys";
1103 #if defined (SYS_pathconf)
1104 syscall_table
[SYS_pathconf
] = "pathconf";
1106 #if defined (SYS_mincore)
1107 syscall_table
[SYS_mincore
] = "mincore";
1109 #if defined (SYS_mmap)
1110 syscall_table
[SYS_mmap
] = "mmap";
1112 #if defined (SYS_mprotect)
1113 syscall_table
[SYS_mprotect
] = "mprotect";
1115 #if defined (SYS_munmap)
1116 syscall_table
[SYS_munmap
] = "munmap";
1118 #if defined (SYS_fpathconf)
1119 syscall_table
[SYS_fpathconf
] = "fpathconf";
1121 #if defined (SYS_vfork)
1122 syscall_table
[SYS_vfork
] = "vfork";
1124 #if defined (SYS_fchdir)
1125 syscall_table
[SYS_fchdir
] = "fchdir";
1127 #if defined (SYS_readv)
1128 syscall_table
[SYS_readv
] = "readv";
1130 #if defined (SYS_writev)
1131 syscall_table
[SYS_writev
] = "writev";
1133 #if defined (SYS_xstat)
1134 syscall_table
[SYS_xstat
] = "xstat";
1136 #if defined (SYS_lxstat)
1137 syscall_table
[SYS_lxstat
] = "lxstat";
1139 #if defined (SYS_fxstat)
1140 syscall_table
[SYS_fxstat
] = "fxstat";
1142 #if defined (SYS_xmknod)
1143 syscall_table
[SYS_xmknod
] = "xmknod";
1145 #if defined (SYS_clocal)
1146 syscall_table
[SYS_clocal
] = "clocal";
1148 #if defined (SYS_setrlimit)
1149 syscall_table
[SYS_setrlimit
] = "setrlimit";
1151 #if defined (SYS_getrlimit)
1152 syscall_table
[SYS_getrlimit
] = "getrlimit";
1154 #if defined (SYS_lchown)
1155 syscall_table
[SYS_lchown
] = "lchown";
1157 #if defined (SYS_memcntl)
1158 syscall_table
[SYS_memcntl
] = "memcntl";
1160 #if defined (SYS_getpmsg)
1161 syscall_table
[SYS_getpmsg
] = "getpmsg";
1163 #if defined (SYS_putpmsg)
1164 syscall_table
[SYS_putpmsg
] = "putpmsg";
1166 #if defined (SYS_rename)
1167 syscall_table
[SYS_rename
] = "rename";
1169 #if defined (SYS_uname)
1170 syscall_table
[SYS_uname
] = "uname";
1172 #if defined (SYS_setegid)
1173 syscall_table
[SYS_setegid
] = "setegid";
1175 #if defined (SYS_sysconfig)
1176 syscall_table
[SYS_sysconfig
] = "sysconfig";
1178 #if defined (SYS_adjtime)
1179 syscall_table
[SYS_adjtime
] = "adjtime";
1181 #if defined (SYS_systeminfo)
1182 syscall_table
[SYS_systeminfo
] = "systeminfo";
1184 #if defined (SYS_seteuid)
1185 syscall_table
[SYS_seteuid
] = "seteuid";
1187 #if defined (SYS_sproc)
1188 syscall_table
[SYS_sproc
] = "sproc";
1196 procfs_kill_inferior - kill any currently inferior
1200 void procfs_kill_inferior (void)
1204 Kill any current inferior.
1208 Kills even attached inferiors. Presumably the user has already
1209 been prompted that the inferior is an attached one rather than
1210 one started by gdb. (FIXME?)
1215 procfs_kill_inferior ()
1217 target_mourn_inferior ();
1224 unconditionally_kill_inferior - terminate the inferior
1228 static void unconditionally_kill_inferior (struct procinfo *)
1232 Kill the specified inferior.
1236 A possibly useful enhancement would be to first try sending
1237 the inferior a terminate signal, politely asking it to commit
1238 suicide, before we murder it (we could call that
1239 politely_kill_inferior()).
1244 unconditionally_kill_inferior (pi
)
1245 struct procinfo
*pi
;
1250 ppid
= pi
->prstatus
.pr_ppid
;
1254 #ifdef PROCFS_NEED_PIOCSSIG_FOR_KILL
1255 /* Alpha OSF/1 procfs needs a PIOCSSIG call with a SIGKILL signal
1256 to kill the inferior, otherwise it might remain stopped with a
1258 We do not check the result of the PIOCSSIG, the inferior might have
1261 struct siginfo newsiginfo
;
1263 memset ((char *) &newsiginfo
, 0, sizeof (newsiginfo
));
1264 newsiginfo
.si_signo
= signo
;
1265 newsiginfo
.si_code
= 0;
1266 newsiginfo
.si_errno
= 0;
1267 newsiginfo
.si_pid
= getpid ();
1268 newsiginfo
.si_uid
= getuid ();
1269 ioctl (pi
->fd
, PIOCSSIG
, &newsiginfo
);
1272 ioctl (pi
->fd
, PIOCKILL
, &signo
);
1275 close_proc_file (pi
);
1277 /* Only wait() for our direct children. Our grandchildren zombies are killed
1278 by the death of their parents. */
1280 if (ppid
== getpid())
1288 procfs_xfer_memory -- copy data to or from inferior memory space
1292 int procfs_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len,
1293 int dowrite, struct target_ops target)
1297 Copy LEN bytes to/from inferior's memory starting at MEMADDR
1298 from/to debugger memory starting at MYADDR. Copy from inferior
1299 if DOWRITE is zero or to inferior if DOWRITE is nonzero.
1301 Returns the length copied, which is either the LEN argument or
1302 zero. This xfer function does not do partial moves, since procfs_ops
1303 doesn't allow memory operations to cross below us in the target stack
1308 The /proc interface makes this an almost trivial task.
1312 procfs_xfer_memory (memaddr
, myaddr
, len
, dowrite
, target
)
1317 struct target_ops
*target
; /* ignored */
1320 struct procinfo
*pi
;
1322 pi
= current_procinfo
;
1324 if (lseek(pi
->fd
, (off_t
) memaddr
, 0) == (off_t
) memaddr
)
1328 nbytes
= write (pi
->fd
, myaddr
, len
);
1332 nbytes
= read (pi
->fd
, myaddr
, len
);
1346 procfs_store_registers -- copy register values back to inferior
1350 void procfs_store_registers (int regno)
1354 Store our current register values back into the inferior. If
1355 REGNO is -1 then store all the register, otherwise store just
1356 the value specified by REGNO.
1360 If we are storing only a single register, we first have to get all
1361 the current values from the process, overwrite the desired register
1362 in the gregset with the one we want from gdb's registers, and then
1363 send the whole set back to the process. For writing all the
1364 registers, all we have to do is generate the gregset and send it to
1367 Also note that the process has to be stopped on an event of interest
1368 for this to work, which basically means that it has to have been
1369 run under the control of one of the other /proc ioctl calls and not
1370 ptrace. Since we don't use ptrace anyway, we don't worry about this
1371 fine point, but it is worth noting for future reference.
1373 Gdb is confused about what this function is supposed to return.
1374 Some versions return a value, others return nothing. Some are
1375 declared to return a value and actually return nothing. Gdb ignores
1376 anything returned. (FIXME)
1381 procfs_store_registers (regno
)
1384 struct procinfo
*pi
;
1386 pi
= current_procinfo
;
1390 ioctl (pi
->fd
, PIOCGREG
, &pi
->gregset
);
1392 fill_gregset (&pi
->gregset
, regno
);
1393 ioctl (pi
->fd
, PIOCSREG
, &pi
->gregset
);
1395 #if defined (FP0_REGNUM)
1397 /* Now repeat everything using the floating point register set, if the
1398 target has floating point hardware. Since we ignore the returned value,
1399 we'll never know whether it worked or not anyway. */
1403 ioctl (pi
->fd
, PIOCGFPREG
, &pi
->fpregset
);
1405 fill_fpregset (&pi
->fpregset
, regno
);
1406 ioctl (pi
->fd
, PIOCSFPREG
, &pi
->fpregset
);
1408 #endif /* FP0_REGNUM */
1416 create_procinfo - initialize access to a /proc entry
1420 struct procinfo * create_procinfo (int pid)
1424 Allocate a procinfo structure, open the /proc file and then set up the
1425 set of signals and faults that are to be traced. Returns a pointer to
1426 the new procinfo structure.
1430 If proc_init_failed ever gets called, control returns to the command
1431 processing loop via the standard error handling code.
1435 static struct procinfo
*
1436 create_procinfo (pid
)
1439 struct procinfo
*pi
;
1441 pi
= find_procinfo (pid
, 1);
1443 return pi
; /* All done! It already exists */
1445 pi
= (struct procinfo
*) xmalloc (sizeof (struct procinfo
));
1447 if (!open_proc_file (pid
, pi
, O_RDWR
))
1448 proc_init_failed (pi
, "can't open process file");
1450 /* Add new process to process info list */
1452 pi
->next
= procinfo_list
;
1455 add_fd (pi
); /* Add to list for poll/select */
1457 memset ((char *) &pi
->prrun
, 0, sizeof (pi
->prrun
));
1458 prfillset (&pi
->prrun
.pr_trace
);
1459 procfs_notice_signals (pid
);
1460 prfillset (&pi
->prrun
.pr_fault
);
1461 prdelset (&pi
->prrun
.pr_fault
, FLTPAGE
);
1463 #ifdef PROCFS_DONT_TRACE_IFAULT
1464 /* Tracing T_IFAULT under Alpha OSF/1 causes a `floating point enable'
1465 fault from which we cannot continue (except by disabling the
1466 tracing). We rely on the delivery of a SIGTRAP signal (which is traced)
1467 for the other T_IFAULT faults if tracing them is disabled. */
1468 prdelset (&pi
->prrun
.pr_fault
, T_IFAULT
);
1471 if (ioctl (pi
->fd
, PIOCWSTOP
, &pi
->prstatus
) < 0)
1472 proc_init_failed (pi
, "PIOCWSTOP failed");
1474 if (ioctl (pi
->fd
, PIOCSFAULT
, &pi
->prrun
.pr_fault
) < 0)
1475 proc_init_failed (pi
, "PIOCSFAULT failed");
1484 procfs_init_inferior - initialize target vector and access to a
1489 void procfs_init_inferior (int pid)
1493 When gdb starts an inferior, this function is called in the parent
1494 process immediately after the fork. It waits for the child to stop
1495 on the return from the exec system call (the child itself takes care
1496 of ensuring that this is set up), then sets up the set of signals
1497 and faults that are to be traced.
1501 If proc_init_failed ever gets called, control returns to the command
1502 processing loop via the standard error handling code.
1507 procfs_init_inferior (pid
)
1510 push_target (&procfs_ops
);
1512 create_procinfo (pid
);
1513 add_thread (pid
); /* Setup initial thread */
1515 #ifdef START_INFERIOR_TRAPS_EXPECTED
1516 startup_inferior (START_INFERIOR_TRAPS_EXPECTED
);
1518 /* One trap to exec the shell, one to exec the program being debugged. */
1519 startup_inferior (2);
1527 procfs_notice_signals
1531 static void procfs_notice_signals (int pid);
1535 When the user changes the state of gdb's signal handling via the
1536 "handle" command, this function gets called to see if any change
1537 in the /proc interface is required. It is also called internally
1538 by other /proc interface functions to initialize the state of
1539 the traced signal set.
1541 One thing it does is that signals for which the state is "nostop",
1542 "noprint", and "pass", have their trace bits reset in the pr_trace
1543 field, so that they are no longer traced. This allows them to be
1544 delivered directly to the inferior without the debugger ever being
1549 procfs_notice_signals (pid
)
1553 struct procinfo
*pi
;
1555 pi
= find_procinfo (pid
, 0);
1557 for (signo
= 0; signo
< NSIG
; signo
++)
1559 if (signal_stop_state (target_signal_from_host (signo
)) == 0 &&
1560 signal_print_state (target_signal_from_host (signo
)) == 0 &&
1561 signal_pass_state (target_signal_from_host (signo
)) == 1)
1563 prdelset (&pi
->prrun
.pr_trace
, signo
);
1567 praddset (&pi
->prrun
.pr_trace
, signo
);
1570 if (ioctl (pi
->fd
, PIOCSTRACE
, &pi
->prrun
.pr_trace
))
1572 print_sys_errmsg ("PIOCSTRACE failed", errno
);
1580 proc_set_exec_trap -- arrange for exec'd child to halt at startup
1584 void proc_set_exec_trap (void)
1588 This function is called in the child process when starting up
1589 an inferior, prior to doing the exec of the actual inferior.
1590 It sets the child process's exitset to make exit from the exec
1591 system call an event of interest to stop on, and then simply
1592 returns. The child does the exec, the system call returns, and
1593 the child stops at the first instruction, ready for the gdb
1594 parent process to take control of it.
1598 We need to use all local variables since the child may be sharing
1599 it's data space with the parent, if vfork was used rather than
1602 Also note that we want to turn off the inherit-on-fork flag in
1603 the child process so that any grand-children start with all
1604 tracing flags cleared.
1608 proc_set_exec_trap ()
1612 auto char procname
[32];
1615 sprintf (procname
, PROC_NAME_FMT
, getpid ());
1616 if ((fd
= open (procname
, O_RDWR
)) < 0)
1619 gdb_flush (gdb_stderr
);
1622 premptyset (&exitset
);
1623 premptyset (&entryset
);
1626 /* Under Alpha OSF/1 we have to use a PIOCSSPCACT ioctl to trace
1627 exits from exec system calls because of the user level loader. */
1631 if (ioctl (fd
, PIOCGSPCACT
, &prfs_flags
) < 0)
1634 gdb_flush (gdb_stderr
);
1637 prfs_flags
|= PRFS_STOPEXEC
;
1638 if (ioctl (fd
, PIOCSSPCACT
, &prfs_flags
) < 0)
1641 gdb_flush (gdb_stderr
);
1647 Not all systems with /proc have all the exec* syscalls with the same
1648 names. On the SGI, for example, there is no SYS_exec, but there
1649 *is* a SYS_execv. So, we try to account for that. */
1652 praddset (&exitset
, SYS_exec
);
1655 praddset (&exitset
, SYS_execve
);
1658 praddset (&exitset
, SYS_execv
);
1661 if (ioctl (fd
, PIOCSEXIT
, &exitset
) < 0)
1664 gdb_flush (gdb_stderr
);
1669 praddset (&entryset
, SYS_exit
);
1671 if (ioctl (fd
, PIOCSENTRY
, &entryset
) < 0)
1674 gdb_flush (gdb_stderr
);
1678 /* Turn off inherit-on-fork flag so that all grand-children of gdb
1679 start with tracing flags cleared. */
1681 #if defined (PIOCRESET) /* New method */
1685 ioctl (fd
, PIOCRESET
, &pr_flags
);
1688 #if defined (PIOCRFORK) /* Original method */
1689 ioctl (fd
, PIOCRFORK
, NULL
);
1693 /* Turn on run-on-last-close flag so that this process will not hang
1694 if GDB goes away for some reason. */
1696 #if defined (PIOCSET) /* New method */
1700 (void) ioctl (fd
, PIOCSET
, &pr_flags
);
1703 #if defined (PIOCSRLC) /* Original method */
1704 (void) ioctl (fd
, PIOCSRLC
, 0);
1713 proc_iterate_over_mappings -- call function for every mapped space
1717 int proc_iterate_over_mappings (int (*func)())
1721 Given a pointer to a function, call that function for every
1722 mapped address space, passing it an open file descriptor for
1723 the file corresponding to that mapped address space (if any)
1724 and the base address of the mapped space. Quit when we hit
1725 the end of the mappings or the function returns nonzero.
1729 proc_iterate_over_mappings (func
)
1730 int (*func
) PARAMS ((int, CORE_ADDR
));
1735 struct prmap
*prmaps
;
1736 struct prmap
*prmap
;
1737 struct procinfo
*pi
;
1739 pi
= current_procinfo
;
1741 if (ioctl (pi
->fd
, PIOCNMAP
, &nmap
) == 0)
1743 prmaps
= (struct prmap
*) alloca ((nmap
+ 1) * sizeof (*prmaps
));
1744 if (ioctl (pi
->fd
, PIOCMAP
, prmaps
) == 0)
1746 for (prmap
= prmaps
; prmap
-> pr_size
&& funcstat
== 0; ++prmap
)
1748 fd
= proc_address_to_fd (pi
, (CORE_ADDR
) prmap
-> pr_vaddr
, 0);
1749 funcstat
= (*func
) (fd
, (CORE_ADDR
) prmap
-> pr_vaddr
);
1757 #if 0 /* Currently unused */
1762 proc_base_address -- find base address for segment containing address
1766 CORE_ADDR proc_base_address (CORE_ADDR addr)
1770 Given an address of a location in the inferior, find and return
1771 the base address of the mapped segment containing that address.
1773 This is used for example, by the shared library support code,
1774 where we have the pc value for some location in the shared library
1775 where we are stopped, and need to know the base address of the
1776 segment containing that address.
1780 proc_base_address (addr
)
1784 struct prmap
*prmaps
;
1785 struct prmap
*prmap
;
1786 CORE_ADDR baseaddr
= 0;
1787 struct procinfo
*pi
;
1789 pi
= current_procinfo
;
1791 if (ioctl (pi
->fd
, PIOCNMAP
, &nmap
) == 0)
1793 prmaps
= (struct prmap
*) alloca ((nmap
+ 1) * sizeof (*prmaps
));
1794 if (ioctl (pi
->fd
, PIOCMAP
, prmaps
) == 0)
1796 for (prmap
= prmaps
; prmap
-> pr_size
; ++prmap
)
1798 if ((prmap
-> pr_vaddr
<= (caddr_t
) addr
) &&
1799 (prmap
-> pr_vaddr
+ prmap
-> pr_size
> (caddr_t
) addr
))
1801 baseaddr
= (CORE_ADDR
) prmap
-> pr_vaddr
;
1816 proc_address_to_fd -- return open fd for file mapped to address
1820 int proc_address_to_fd (struct procinfo *pi, CORE_ADDR addr, complain)
1824 Given an address in the current inferior's address space, use the
1825 /proc interface to find an open file descriptor for the file that
1826 this address was mapped in from. Return -1 if there is no current
1827 inferior. Print a warning message if there is an inferior but
1828 the address corresponds to no file (IE a bogus address).
1833 proc_address_to_fd (pi
, addr
, complain
)
1834 struct procinfo
*pi
;
1840 if ((fd
= ioctl (pi
->fd
, PIOCOPENM
, (caddr_t
*) &addr
)) < 0)
1844 print_sys_errmsg (pi
->pathname
, errno
);
1845 warning ("can't find mapped file for address 0x%x", addr
);
1852 /* Attach to process PID, then initialize for debugging it
1853 and wait for the trace-trap that results from attaching. */
1856 procfs_attach (args
, from_tty
)
1864 error_no_arg ("process-id to attach");
1868 if (pid
== getpid()) /* Trying to masturbate? */
1869 error ("I refuse to debug myself!");
1873 exec_file
= (char *) get_exec_file (0);
1876 printf_unfiltered ("Attaching to program `%s', %s\n", exec_file
, target_pid_to_str (pid
));
1878 printf_unfiltered ("Attaching to %s\n", target_pid_to_str (pid
));
1880 gdb_flush (gdb_stdout
);
1885 push_target (&procfs_ops
);
1889 /* Take a program previously attached to and detaches it.
1890 The program resumes execution and will no longer stop
1891 on signals, etc. We'd better not have left any breakpoints
1892 in the program or it'll die when it hits one. For this
1893 to work, it may be necessary for the process to have been
1894 previously attached. It *might* work if the program was
1895 started via the normal ptrace (PTRACE_TRACEME). */
1898 procfs_detach (args
, from_tty
)
1906 char *exec_file
= get_exec_file (0);
1909 printf_unfiltered ("Detaching from program: %s %s\n",
1910 exec_file
, target_pid_to_str (inferior_pid
));
1911 gdb_flush (gdb_stdout
);
1914 siggnal
= atoi (args
);
1916 do_detach (siggnal
);
1918 unpush_target (&procfs_ops
); /* Pop out of handling an inferior */
1921 /* Get ready to modify the registers array. On machines which store
1922 individual registers, this doesn't need to do anything. On machines
1923 which store all the registers in one fell swoop, this makes sure
1924 that registers contains all the registers from the program being
1928 procfs_prepare_to_store ()
1930 #ifdef CHILD_PREPARE_TO_STORE
1931 CHILD_PREPARE_TO_STORE ();
1935 /* Print status information about what we're accessing. */
1938 procfs_files_info (ignore
)
1939 struct target_ops
*ignore
;
1941 printf_unfiltered ("\tUsing the running image of %s %s via /proc.\n",
1942 attach_flag
? "attached": "child", target_pid_to_str (inferior_pid
));
1947 procfs_open (arg
, from_tty
)
1951 error ("Use the \"run\" command to start a Unix child process.");
1958 do_attach -- attach to an already existing process
1962 int do_attach (int pid)
1966 Attach to an already existing process with the specified process
1967 id. If the process is not already stopped, query whether to
1972 The option of stopping at attach time is specific to the /proc
1973 versions of gdb. Versions using ptrace force the attachee
1974 to stop. (I have changed this version to do so, too. All you
1975 have to do is "continue" to make it go on. -- gnu@cygnus.com)
1984 struct procinfo
*pi
;
1986 pi
= (struct procinfo
*) xmalloc (sizeof (struct procinfo
));
1988 if (!open_proc_file (pid
, pi
, O_RDWR
))
1991 perror_with_name (pi
->pathname
);
1995 /* Add new process to process info list */
1997 pi
->next
= procinfo_list
;
2000 add_fd (pi
); /* Add to list for poll/select */
2002 /* Get current status of process and if it is not already stopped,
2003 then stop it. Remember whether or not it was stopped when we first
2006 if (ioctl (pi
->fd
, PIOCSTATUS
, &pi
->prstatus
) < 0)
2008 print_sys_errmsg (pi
->pathname
, errno
);
2009 close_proc_file (pi
);
2010 error ("PIOCSTATUS failed");
2012 if (pi
->prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
))
2014 pi
->was_stopped
= 1;
2018 pi
->was_stopped
= 0;
2019 if (1 || query ("Process is currently running, stop it? "))
2021 /* Make it run again when we close it. */
2022 #if defined (PIOCSET) /* New method */
2026 result
= ioctl (pi
->fd
, PIOCSET
, &pr_flags
);
2029 #if defined (PIOCSRLC) /* Original method */
2030 result
= ioctl (pi
->fd
, PIOCSRLC
, 0);
2035 print_sys_errmsg (pi
->pathname
, errno
);
2036 close_proc_file (pi
);
2037 error ("PIOCSRLC or PIOCSET failed");
2039 if (ioctl (pi
->fd
, PIOCSTOP
, &pi
->prstatus
) < 0)
2041 print_sys_errmsg (pi
->pathname
, errno
);
2042 close_proc_file (pi
);
2043 error ("PIOCSTOP failed");
2045 pi
->nopass_next_sigstop
= 1;
2049 printf_unfiltered ("Ok, gdb will wait for %s to stop.\n", target_pid_to_str (pid
));
2053 /* Remember some things about the inferior that we will, or might, change
2054 so that we can restore them when we detach. */
2056 ioctl (pi
->fd
, PIOCGTRACE
, &pi
->saved_trace
);
2057 ioctl (pi
->fd
, PIOCGHOLD
, &pi
->saved_sighold
);
2058 ioctl (pi
->fd
, PIOCGFAULT
, &pi
->saved_fltset
);
2059 ioctl (pi
->fd
, PIOCGENTRY
, &pi
->saved_entryset
);
2060 ioctl (pi
->fd
, PIOCGEXIT
, &pi
->saved_exitset
);
2062 /* Set up trace and fault sets, as gdb expects them. */
2064 memset (&pi
->prrun
, 0, sizeof (pi
->prrun
));
2065 prfillset (&pi
->prrun
.pr_trace
);
2066 procfs_notice_signals (pid
);
2067 prfillset (&pi
->prrun
.pr_fault
);
2068 prdelset (&pi
->prrun
.pr_fault
, FLTPAGE
);
2070 #ifdef PROCFS_DONT_TRACE_IFAULT
2071 /* Tracing T_IFAULT under Alpha OSF/1 causes a `floating point enable'
2072 fault from which we cannot continue (except by disabling the
2073 tracing). We rely on the delivery of a SIGTRAP signal (which is traced)
2074 for the other T_IFAULT faults if tracing them is disabled. */
2075 prdelset (&pi
->prrun
.pr_fault
, T_IFAULT
);
2078 if (ioctl (pi
->fd
, PIOCSFAULT
, &pi
->prrun
.pr_fault
))
2080 print_sys_errmsg ("PIOCSFAULT failed", errno
);
2082 if (ioctl (pi
->fd
, PIOCSTRACE
, &pi
->prrun
.pr_trace
))
2084 print_sys_errmsg ("PIOCSTRACE failed", errno
);
2094 do_detach -- detach from an attached-to process
2098 void do_detach (int signal)
2102 Detach from the current attachee.
2104 If signal is non-zero, the attachee is started running again and sent
2105 the specified signal.
2107 If signal is zero and the attachee was not already stopped when we
2108 attached to it, then we make it runnable again when we detach.
2110 Otherwise, we query whether or not to make the attachee runnable
2111 again, since we may simply want to leave it in the state it was in
2114 We report any problems, but do not consider them errors, since we
2115 MUST detach even if some things don't seem to go right. This may not
2116 be the ideal situation. (FIXME).
2124 struct procinfo
*pi
;
2126 pi
= current_procinfo
;
2130 set_proc_siginfo (pi
, signal
);
2132 if (ioctl (pi
->fd
, PIOCSEXIT
, &pi
->saved_exitset
) < 0)
2134 print_sys_errmsg (pi
->pathname
, errno
);
2135 printf_unfiltered ("PIOCSEXIT failed.\n");
2137 if (ioctl (pi
->fd
, PIOCSENTRY
, &pi
->saved_entryset
) < 0)
2139 print_sys_errmsg (pi
->pathname
, errno
);
2140 printf_unfiltered ("PIOCSENTRY failed.\n");
2142 if (ioctl (pi
->fd
, PIOCSTRACE
, &pi
->saved_trace
) < 0)
2144 print_sys_errmsg (pi
->pathname
, errno
);
2145 printf_unfiltered ("PIOCSTRACE failed.\n");
2147 if (ioctl (pi
->fd
, PIOCSHOLD
, &pi
->saved_sighold
) < 0)
2149 print_sys_errmsg (pi
->pathname
, errno
);
2150 printf_unfiltered ("PIOSCHOLD failed.\n");
2152 if (ioctl (pi
->fd
, PIOCSFAULT
, &pi
->saved_fltset
) < 0)
2154 print_sys_errmsg (pi
->pathname
, errno
);
2155 printf_unfiltered ("PIOCSFAULT failed.\n");
2157 if (ioctl (pi
->fd
, PIOCSTATUS
, &pi
->prstatus
) < 0)
2159 print_sys_errmsg (pi
->pathname
, errno
);
2160 printf_unfiltered ("PIOCSTATUS failed.\n");
2164 if (signal
|| (pi
->prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
)))
2166 if (signal
|| !pi
->was_stopped
||
2167 query ("Was stopped when attached, make it runnable again? "))
2169 /* Clear any pending signal if we want to detach without
2172 set_proc_siginfo (pi
, signal
);
2174 /* Clear any fault that might have stopped it. */
2175 if (ioctl (pi
->fd
, PIOCCFAULT
, 0))
2177 print_sys_errmsg (pi
->pathname
, errno
);
2178 printf_unfiltered ("PIOCCFAULT failed.\n");
2181 /* Make it run again when we close it. */
2182 #if defined (PIOCSET) /* New method */
2186 result
= ioctl (pi
->fd
, PIOCSET
, &pr_flags
);
2189 #if defined (PIOCSRLC) /* Original method */
2190 result
= ioctl (pi
->fd
, PIOCSRLC
, 0);
2195 print_sys_errmsg (pi
->pathname
, errno
);
2196 printf_unfiltered ("PIOCSRLC or PIOCSET failed.\n");
2201 close_proc_file (pi
);
2205 /* emulate wait() as much as possible.
2206 Wait for child to do something. Return pid of child, or -1 in case
2207 of error; store status in *OURSTATUS.
2209 Not sure why we can't
2210 just use wait(), but it seems to have problems when applied to a
2211 process being controlled with the /proc interface.
2213 We have a race problem here with no obvious solution. We need to let
2214 the inferior run until it stops on an event of interest, which means
2215 that we need to use the PIOCWSTOP ioctl. However, we cannot use this
2216 ioctl if the process is already stopped on something that is not an
2217 event of interest, or the call will hang indefinitely. Thus we first
2218 use PIOCSTATUS to see if the process is not stopped. If not, then we
2219 use PIOCWSTOP. But during the window between the two, if the process
2220 stops for any reason that is not an event of interest (such as a job
2221 control signal) then gdb will hang. One possible workaround is to set
2222 an alarm to wake up every minute of so and check to see if the process
2223 is still running, and if so, then reissue the PIOCWSTOP. But this is
2224 a real kludge, so has not been implemented. FIXME: investigate
2227 FIXME: Investigate why wait() seems to have problems with programs
2228 being control by /proc routines. */
2231 procfs_wait (pid
, ourstatus
)
2233 struct target_waitstatus
*ourstatus
;
2240 struct procinfo
*pi
;
2242 if (pid
!= -1) /* Non-specific process? */
2245 for (pi
= procinfo_list
; pi
; pi
= pi
->next
)
2257 for (pi
= procinfo_list
; pi
; pi
= pi
->next
)
2258 if (pi
->pid
== pid
&& pi
->had_event
)
2261 if (!pi
&& !checkerr
)
2264 if (!checkerr
&& !(pi
->prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
)))
2266 if (ioctl (pi
->fd
, PIOCWSTOP
, &pi
->prstatus
) < 0)
2273 if (errno
== ENOENT
)
2275 rtnval
= wait (&statval
);
2276 if (rtnval
!= inferior_pid
)
2278 print_sys_errmsg (pi
->pathname
, errno
);
2279 error ("PIOCWSTOP, wait failed, returned %d", rtnval
);
2285 print_sys_errmsg (pi
->pathname
, errno
);
2286 error ("PIOCSTATUS or PIOCWSTOP failed.");
2290 else if (pi
->prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
))
2292 rtnval
= pi
->prstatus
.pr_pid
;
2293 why
= pi
->prstatus
.pr_why
;
2294 what
= pi
->prstatus
.pr_what
;
2299 statval
= (what
<< 8) | 0177;
2302 if (what
!= SYS_exit
)
2303 error ("PR_SYSENTRY, unknown system call %d", what
);
2305 pi
->prrun
.pr_flags
= PRCFAULT
;
2307 if (ioctl (pi
->fd
, PIOCRUN
, &pi
->prrun
) != 0)
2308 perror_with_name (pi
->pathname
);
2310 rtnval
= wait (&statval
);
2325 statval
= (SIGTRAP
<< 8) | 0177;
2329 /* We've just detected the completion of an sproc system call. Now we need to
2330 setup a procinfo struct for this thread, and notify the thread system of the
2333 /* If sproc failed, then nothing interesting happened. Continue the process and
2334 go back to sleep. */
2336 if (pi
->prstatus
.pr_errno
!= 0)
2338 pi
->prrun
.pr_flags
&= PRSTEP
;
2339 pi
->prrun
.pr_flags
|= PRCFAULT
;
2341 if (ioctl (pi
->fd
, PIOCRUN
, &pi
->prrun
) != 0)
2342 perror_with_name (pi
->pathname
);
2347 /* At this point, the new thread is stopped at it's first instruction, and
2348 the parent is stopped at the exit from sproc. */
2350 /* Notify the caller of the arrival of a new thread. */
2351 create_procinfo (pi
->prstatus
.pr_rval1
);
2353 rtnval
= pi
->prstatus
.pr_rval1
;
2354 statval
= (SIGTRAP
<< 8) | 0177;
2361 /* At this point, we've detected the completion of a fork (or vfork) call in
2362 our child. The grandchild is also stopped because we set inherit-on-fork
2363 earlier. (Note that nobody has the grandchilds' /proc file open at this
2364 point.) We will release the grandchild from the debugger by opening it's
2365 /proc file and then closing it. Since run-on-last-close is set, the
2366 grandchild continues on its' merry way. */
2369 struct procinfo
*pitemp
;
2371 pitemp
= create_procinfo (pi
->prstatus
.pr_rval1
);
2373 close_proc_file (pitemp
);
2375 if (ioctl (pi
->fd
, PIOCRUN
, &pi
->prrun
) != 0)
2376 perror_with_name (pi
->pathname
);
2379 #endif /* SYS_sproc */
2382 error ("PIOCSTATUS (PR_SYSEXIT): Unknown system call %d", what
);
2386 statval
= (SIGSTOP
<< 8) | 0177;
2389 statval
= (what
<< 8) | 0177;
2396 statval
= (SIGTRAP
<< 8) | 0177;
2401 statval
= (SIGTRAP
<< 8) | 0177;
2404 #ifndef FAULTED_USE_SIGINFO
2405 /* Irix, contrary to the documentation, fills in 0 for si_signo.
2406 Solaris fills in si_signo. I'm not sure about others. */
2409 statval
= (SIGILL
<< 8) | 0177;
2413 statval
= (SIGTRAP
<< 8) | 0177;
2418 statval
= (SIGSEGV
<< 8) | 0177;
2423 statval
= (SIGFPE
<< 8) | 0177;
2425 case FLTPAGE
: /* Recoverable page fault */
2426 #endif /* not FAULTED_USE_SIGINFO */
2428 /* Use the signal which the kernel assigns. This is better than
2429 trying to second-guess it from the fault. In fact, I suspect
2430 that FLTACCESS can be either SIGSEGV or SIGBUS. */
2431 statval
= ((pi
->prstatus
.pr_info
.si_signo
) << 8) | 0177;
2436 error ("PIOCWSTOP, unknown why %d, what %d", why
, what
);
2438 /* Stop all the other threads when any of them stops. */
2441 struct procinfo
*procinfo
;
2443 for (procinfo
= procinfo_list
; procinfo
; procinfo
= procinfo
->next
)
2445 if (!procinfo
->had_event
)
2446 if (ioctl (procinfo
->fd
, PIOCSTOP
, &procinfo
->prstatus
) < 0)
2448 print_sys_errmsg (procinfo
->pathname
, errno
);
2449 error ("PIOCSTOP failed");
2456 error ("PIOCWSTOP, stopped for unknown/unhandled reason, flags %#x",
2457 pi
->prstatus
.pr_flags
);
2460 store_waitstatus (ourstatus
, statval
);
2462 if (rtnval
== -1) /* No more children to wait for */
2464 fprintf_unfiltered (gdb_stderr
, "Child process unexpectedly missing.\n");
2465 /* Claim it exited with unknown signal. */
2466 ourstatus
->kind
= TARGET_WAITKIND_SIGNALLED
;
2467 ourstatus
->value
.sig
= TARGET_SIGNAL_UNKNOWN
;
2471 pi
->had_event
= 0; /* Indicate that we've seen this one */
2479 set_proc_siginfo - set a process's current signal info
2483 void set_proc_siginfo (struct procinfo *pip, int signo);
2487 Given a pointer to a process info struct in PIP and a signal number
2488 in SIGNO, set the process's current signal and its associated signal
2489 information. The signal will be delivered to the process immediately
2490 after execution is resumed, even if it is being held. In addition,
2491 this particular delivery will not cause another PR_SIGNALLED stop
2492 even if the signal is being traced.
2494 If we are not delivering the same signal that the prstatus siginfo
2495 struct contains information about, then synthesize a siginfo struct
2496 to match the signal we are doing to deliver, make it of the type
2497 "generated by a user process", and send this synthesized copy. When
2498 used to set the inferior's signal state, this will be required if we
2499 are not currently stopped because of a traced signal, or if we decide
2500 to continue with a different signal.
2502 Note that when continuing the inferior from a stop due to receipt
2503 of a traced signal, we either have set PRCSIG to clear the existing
2504 signal, or we have to call this function to do a PIOCSSIG with either
2505 the existing siginfo struct from pr_info, or one we have synthesized
2506 appropriately for the signal we want to deliver. Otherwise if the
2507 signal is still being traced, the inferior will immediately stop
2510 See siginfo(5) for more details.
2514 set_proc_siginfo (pip
, signo
)
2515 struct procinfo
*pip
;
2518 struct siginfo newsiginfo
;
2519 struct siginfo
*sip
;
2521 #ifdef PROCFS_DONT_PIOCSSIG_CURSIG
2522 /* With Alpha OSF/1 procfs, the kernel gets really confused if it
2523 receives a PIOCSSSIG with a signal identical to the current signal,
2524 it messes up the current signal. Work around the kernel bug. */
2525 if (signo
== pip
-> prstatus
.pr_cursig
)
2529 if (signo
== pip
-> prstatus
.pr_info
.si_signo
)
2531 sip
= &pip
-> prstatus
.pr_info
;
2535 memset ((char *) &newsiginfo
, 0, sizeof (newsiginfo
));
2537 sip
-> si_signo
= signo
;
2539 sip
-> si_errno
= 0;
2540 sip
-> si_pid
= getpid ();
2541 sip
-> si_uid
= getuid ();
2543 if (ioctl (pip
-> fd
, PIOCSSIG
, sip
) < 0)
2545 print_sys_errmsg (pip
-> pathname
, errno
);
2546 warning ("PIOCSSIG failed");
2550 /* Resume execution of process PID. If STEP is nozero, then
2551 just single step it. If SIGNAL is nonzero, restart it with that
2552 signal activated. */
2555 procfs_resume (pid
, step
, signo
)
2558 enum target_signal signo
;
2561 struct procinfo
*pi
, *procinfo
;
2563 pi
= find_procinfo (pid
== -1 ? inferior_pid
: pid
, 0);
2566 pi
->prrun
.pr_flags
= PRSTRACE
| PRSFAULT
| PRCFAULT
;
2569 /* It should not be necessary. If the user explicitly changes the value,
2570 value_assign calls write_register_bytes, which writes it. */
2571 /* It may not be absolutely necessary to specify the PC value for
2572 restarting, but to be safe we use the value that gdb considers
2573 to be current. One case where this might be necessary is if the
2574 user explicitly changes the PC value that gdb considers to be
2575 current. FIXME: Investigate if this is necessary or not. */
2577 #ifdef PRSVADDR_BROKEN
2578 /* Can't do this under Solaris running on a Sparc, as there seems to be no
2579 place to put nPC. In fact, if you use this, nPC seems to be set to some
2580 random garbage. We have to rely on the fact that PC and nPC have been
2581 written previously via PIOCSREG during a register flush. */
2583 pi
->prrun
.pr_vaddr
= (caddr_t
) *(int *) ®isters
[REGISTER_BYTE (PC_REGNUM
)];
2584 pi
->prrun
.pr_flags
!= PRSVADDR
;
2588 if (signo
== TARGET_SIGNAL_STOP
&& pi
->nopass_next_sigstop
)
2589 /* When attaching to a child process, if we forced it to stop with
2590 a PIOCSTOP, then we will have set the nopass_next_sigstop flag.
2591 Upon resuming the first time after such a stop, we explicitly
2592 inhibit sending it another SIGSTOP, which would be the normal
2593 result of default signal handling. One potential drawback to
2594 this is that we will also ignore any attempt to by the user
2595 to explicitly continue after the attach with a SIGSTOP. Ultimately
2596 this problem should be dealt with by making the routines that
2597 deal with the inferior a little smarter, and possibly even allow
2598 an inferior to continue running at the same time as gdb. (FIXME?) */
2600 else if (signo
== TARGET_SIGNAL_TSTP
2601 && pi
->prstatus
.pr_cursig
== SIGTSTP
2602 && pi
->prstatus
.pr_action
.sa_handler
== SIG_DFL
)
2604 /* We are about to pass the inferior a SIGTSTP whose action is
2605 SIG_DFL. The SIG_DFL action for a SIGTSTP is to stop
2606 (notifying the parent via wait()), and then keep going from the
2607 same place when the parent is ready for you to keep going. So
2608 under the debugger, it should do nothing (as if the program had
2609 been stopped and then later resumed. Under ptrace, this
2610 happens for us, but under /proc, the system obligingly stops
2611 the process, and wait_for_inferior would have no way of
2612 distinguishing that type of stop (which indicates that we
2613 should just start it again), with a stop due to the pr_trace
2614 field of the prrun_t struct.
2616 Note that if the SIGTSTP is being caught, we *do* need to pass it,
2617 because the handler needs to get executed. */
2620 signal_to_pass
= target_signal_to_host (signo
);
2624 set_proc_siginfo (pi
, signal_to_pass
);
2628 pi
->prrun
.pr_flags
|= PRCSIG
;
2630 pi
->nopass_next_sigstop
= 0;
2633 pi
->prrun
.pr_flags
|= PRSTEP
;
2635 if (ioctl (pi
->fd
, PIOCRUN
, &pi
->prrun
) != 0)
2637 perror_with_name (pi
->pathname
);
2643 /* Continue all the other threads that haven't had an event of
2647 for (procinfo
= procinfo_list
; procinfo
; procinfo
= procinfo
->next
)
2649 if (pi
!= procinfo
&& !procinfo
->had_event
)
2651 procinfo
->prrun
.pr_flags
&= PRSTEP
;
2652 procinfo
->prrun
.pr_flags
|= PRCFAULT
| PRCSIG
;
2653 ioctl (procinfo
->fd
, PIOCSTATUS
, &procinfo
->prstatus
);
2654 if (ioctl (procinfo
->fd
, PIOCRUN
, &procinfo
->prrun
) < 0)
2656 if (ioctl (procinfo
->fd
, PIOCSTATUS
, &procinfo
->prstatus
) < 0)
2658 fprintf_unfiltered(gdb_stderr
, "PIOCSTATUS failed, errno=%d\n", errno
);
2660 print_sys_errmsg (procinfo
->pathname
, errno
);
2661 error ("PIOCRUN failed");
2663 ioctl (procinfo
->fd
, PIOCSTATUS
, &procinfo
->prstatus
);
2672 procfs_fetch_registers -- fetch current registers from inferior
2676 void procfs_fetch_registers (int regno)
2680 Read the current values of the inferior's registers, both the
2681 general register set and floating point registers (if supported)
2682 and update gdb's idea of their current values.
2687 procfs_fetch_registers (regno
)
2690 struct procinfo
*pi
;
2692 pi
= current_procinfo
;
2694 if (ioctl (pi
->fd
, PIOCGREG
, &pi
->gregset
) != -1)
2696 supply_gregset (&pi
->gregset
);
2698 #if defined (FP0_REGNUM)
2699 if (ioctl (pi
->fd
, PIOCGFPREG
, &pi
->fpregset
) != -1)
2701 supply_fpregset (&pi
->fpregset
);
2710 proc_init_failed - called whenever /proc access initialization
2715 static void proc_init_failed (struct procinfo *pi, char *why)
2719 This function is called whenever initialization of access to a /proc
2720 entry fails. It prints a suitable error message, does some cleanup,
2721 and then invokes the standard error processing routine which dumps
2722 us back into the command loop.
2726 proc_init_failed (pi
, why
)
2727 struct procinfo
*pi
;
2730 print_sys_errmsg (pi
->pathname
, errno
);
2731 kill (pi
->pid
, SIGKILL
);
2732 close_proc_file (pi
);
2741 close_proc_file - close any currently open /proc entry
2745 static void close_proc_file (struct procinfo *pip)
2749 Close any currently open /proc entry and mark the process information
2750 entry as invalid. In order to ensure that we don't try to reuse any
2751 stale information, the pid, fd, and pathnames are explicitly
2752 invalidated, which may be overkill.
2757 close_proc_file (pip
)
2758 struct procinfo
*pip
;
2760 struct procinfo
*procinfo
;
2762 remove_fd (pip
); /* Remove fd from poll/select list */
2766 free (pip
-> pathname
);
2768 /* Unlink pip from the procinfo chain. Note pip might not be on the list. */
2770 if (procinfo_list
== pip
)
2771 procinfo_list
= pip
->next
;
2773 for (procinfo
= procinfo_list
; procinfo
; procinfo
= procinfo
->next
)
2774 if (procinfo
->next
== pip
)
2775 procinfo
->next
= pip
->next
;
2784 open_proc_file - open a /proc entry for a given process id
2788 static int open_proc_file (int pid, struct procinfo *pip, int mode)
2792 Given a process id and a mode, close the existing open /proc
2793 entry (if any) and open one for the new process id, in the
2794 specified mode. Once it is open, then mark the local process
2795 information structure as valid, which guarantees that the pid,
2796 fd, and pathname fields match an open /proc entry. Returns
2797 zero if the open fails, nonzero otherwise.
2799 Note that the pathname is left intact, even when the open fails,
2800 so that callers can use it to construct meaningful error messages
2801 rather than just "file open failed".
2805 open_proc_file (pid
, pip
, mode
)
2807 struct procinfo
*pip
;
2811 pip
-> had_event
= 0;
2812 pip
-> pathname
= xmalloc (32);
2815 sprintf (pip
-> pathname
, PROC_NAME_FMT
, pid
);
2816 if ((pip
-> fd
= open (pip
-> pathname
, mode
)) < 0)
2823 mappingflags (flags
)
2826 static char asciiflags
[8];
2828 strcpy (asciiflags
, "-------");
2829 #if defined (MA_PHYS)
2830 if (flags
& MA_PHYS
) asciiflags
[0] = 'd';
2832 if (flags
& MA_STACK
) asciiflags
[1] = 's';
2833 if (flags
& MA_BREAK
) asciiflags
[2] = 'b';
2834 if (flags
& MA_SHARED
) asciiflags
[3] = 's';
2835 if (flags
& MA_READ
) asciiflags
[4] = 'r';
2836 if (flags
& MA_WRITE
) asciiflags
[5] = 'w';
2837 if (flags
& MA_EXEC
) asciiflags
[6] = 'x';
2838 return (asciiflags
);
2842 info_proc_flags (pip
, summary
)
2843 struct procinfo
*pip
;
2846 struct trans
*transp
;
2848 printf_filtered ("%-32s", "Process status flags:");
2851 printf_filtered ("\n\n");
2853 for (transp
= pr_flag_table
; transp
-> name
!= NULL
; transp
++)
2855 if (pip
-> prstatus
.pr_flags
& transp
-> value
)
2859 printf_filtered ("%s ", transp
-> name
);
2863 printf_filtered ("\t%-16s %s.\n", transp
-> name
, transp
-> desc
);
2867 printf_filtered ("\n");
2871 info_proc_stop (pip
, summary
)
2872 struct procinfo
*pip
;
2875 struct trans
*transp
;
2879 why
= pip
-> prstatus
.pr_why
;
2880 what
= pip
-> prstatus
.pr_what
;
2882 if (pip
-> prstatus
.pr_flags
& PR_STOPPED
)
2884 printf_filtered ("%-32s", "Reason for stopping:");
2887 printf_filtered ("\n\n");
2889 for (transp
= pr_why_table
; transp
-> name
!= NULL
; transp
++)
2891 if (why
== transp
-> value
)
2895 printf_filtered ("%s ", transp
-> name
);
2899 printf_filtered ("\t%-16s %s.\n",
2900 transp
-> name
, transp
-> desc
);
2906 /* Use the pr_why field to determine what the pr_what field means, and
2907 print more information. */
2912 /* pr_what is unused for this case */
2918 printf_filtered ("%s ", signalname (what
));
2922 printf_filtered ("\t%-16s %s.\n", signalname (what
),
2923 safe_strsignal (what
));
2929 printf_filtered ("%s ", syscallname (what
));
2933 printf_filtered ("\t%-16s %s.\n", syscallname (what
),
2934 "Entered this system call");
2940 printf_filtered ("%s ", syscallname (what
));
2944 printf_filtered ("\t%-16s %s.\n", syscallname (what
),
2945 "Returned from this system call");
2951 printf_filtered ("%s ",
2952 lookupname (faults_table
, what
, "fault"));
2956 printf_filtered ("\t%-16s %s.\n",
2957 lookupname (faults_table
, what
, "fault"),
2958 lookupdesc (faults_table
, what
));
2962 printf_filtered ("\n");
2967 info_proc_siginfo (pip
, summary
)
2968 struct procinfo
*pip
;
2971 struct siginfo
*sip
;
2973 if ((pip
-> prstatus
.pr_flags
& PR_STOPPED
) &&
2974 (pip
-> prstatus
.pr_why
== PR_SIGNALLED
||
2975 pip
-> prstatus
.pr_why
== PR_FAULTED
))
2977 printf_filtered ("%-32s", "Additional signal/fault info:");
2978 sip
= &pip
-> prstatus
.pr_info
;
2981 printf_filtered ("%s ", signalname (sip
-> si_signo
));
2982 if (sip
-> si_errno
> 0)
2984 printf_filtered ("%s ", errnoname (sip
-> si_errno
));
2986 if (sip
-> si_code
<= 0)
2988 printf_filtered ("sent by %s, uid %d ",
2989 target_pid_to_str (sip
-> si_pid
),
2994 printf_filtered ("%s ", sigcodename (sip
));
2995 if ((sip
-> si_signo
== SIGILL
) ||
2996 (sip
-> si_signo
== SIGFPE
) ||
2997 (sip
-> si_signo
== SIGSEGV
) ||
2998 (sip
-> si_signo
== SIGBUS
))
3000 printf_filtered ("addr=%#x ", sip
-> si_addr
);
3002 else if ((sip
-> si_signo
== SIGCHLD
))
3004 printf_filtered ("child %s, status %u ",
3005 target_pid_to_str (sip
-> si_pid
),
3008 else if ((sip
-> si_signo
== SIGPOLL
))
3010 printf_filtered ("band %u ", sip
-> si_band
);
3016 printf_filtered ("\n\n");
3017 printf_filtered ("\t%-16s %s.\n", signalname (sip
-> si_signo
),
3018 safe_strsignal (sip
-> si_signo
));
3019 if (sip
-> si_errno
> 0)
3021 printf_filtered ("\t%-16s %s.\n",
3022 errnoname (sip
-> si_errno
),
3023 safe_strerror (sip
-> si_errno
));
3025 if (sip
-> si_code
<= 0)
3027 printf_filtered ("\t%-16u %s\n", sip
-> si_pid
, /* XXX need target_pid_to_str() */
3028 "PID of process sending signal");
3029 printf_filtered ("\t%-16u %s\n", sip
-> si_uid
,
3030 "UID of process sending signal");
3034 printf_filtered ("\t%-16s %s.\n", sigcodename (sip
),
3036 if ((sip
-> si_signo
== SIGILL
) ||
3037 (sip
-> si_signo
== SIGFPE
))
3039 printf_filtered ("\t%-16#x %s.\n", sip
-> si_addr
,
3040 "Address of faulting instruction");
3042 else if ((sip
-> si_signo
== SIGSEGV
) ||
3043 (sip
-> si_signo
== SIGBUS
))
3045 printf_filtered ("\t%-16#x %s.\n", sip
-> si_addr
,
3046 "Address of faulting memory reference");
3048 else if ((sip
-> si_signo
== SIGCHLD
))
3050 printf_filtered ("\t%-16u %s.\n", sip
-> si_pid
, /* XXX need target_pid_to_str() */
3051 "Child process ID");
3052 printf_filtered ("\t%-16u %s.\n", sip
-> si_status
,
3053 "Child process exit value or signal");
3055 else if ((sip
-> si_signo
== SIGPOLL
))
3057 printf_filtered ("\t%-16u %s.\n", sip
-> si_band
,
3058 "Band event for POLL_{IN,OUT,MSG}");
3062 printf_filtered ("\n");
3067 info_proc_syscalls (pip
, summary
)
3068 struct procinfo
*pip
;
3076 #if 0 /* FIXME: Needs to use gdb-wide configured info about system calls. */
3077 if (pip
-> prstatus
.pr_flags
& PR_ASLEEP
)
3079 int syscallnum
= pip
-> prstatus
.pr_reg
[R_D0
];
3082 printf_filtered ("%-32s", "Sleeping in system call:");
3083 printf_filtered ("%s", syscallname (syscallnum
));
3087 printf_filtered ("Sleeping in system call '%s'.\n",
3088 syscallname (syscallnum
));
3093 if (ioctl (pip
-> fd
, PIOCGENTRY
, &pip
-> entryset
) < 0)
3095 print_sys_errmsg (pip
-> pathname
, errno
);
3096 error ("PIOCGENTRY failed");
3099 if (ioctl (pip
-> fd
, PIOCGEXIT
, &pip
-> exitset
) < 0)
3101 print_sys_errmsg (pip
-> pathname
, errno
);
3102 error ("PIOCGEXIT failed");
3105 printf_filtered ("System call tracing information:\n\n");
3107 printf_filtered ("\t%-12s %-8s %-8s\n",
3111 for (syscallnum
= 0; syscallnum
< MAX_SYSCALLS
; syscallnum
++)
3114 if (syscall_table
[syscallnum
] != NULL
)
3116 printf_filtered ("\t%-12s ", syscall_table
[syscallnum
]);
3117 printf_filtered ("%-8s ",
3118 prismember (&pip
-> entryset
, syscallnum
)
3120 printf_filtered ("%-8s ",
3121 prismember (&pip
-> exitset
, syscallnum
)
3123 printf_filtered ("\n");
3126 printf_filtered ("\n");
3135 static char locbuf
[32];
3137 name
= strsigno (signo
);
3140 sprintf (locbuf
, "Signal %d", signo
);
3144 sprintf (locbuf
, "%s (%d)", name
, signo
);
3154 static char locbuf
[32];
3156 name
= strerrno (errnum
);
3159 sprintf (locbuf
, "Errno %d", errnum
);
3163 sprintf (locbuf
, "%s (%d)", name
, errnum
);
3169 info_proc_signals (pip
, summary
)
3170 struct procinfo
*pip
;
3177 if (ioctl (pip
-> fd
, PIOCGTRACE
, &pip
-> trace
) < 0)
3179 print_sys_errmsg (pip
-> pathname
, errno
);
3180 error ("PIOCGTRACE failed");
3183 printf_filtered ("Disposition of signals:\n\n");
3184 printf_filtered ("\t%-15s %-8s %-8s %-8s %s\n\n",
3185 "Signal", "Trace", "Hold", "Pending", "Description");
3186 for (signo
= 0; signo
< NSIG
; signo
++)
3189 printf_filtered ("\t%-15s ", signalname (signo
));
3190 printf_filtered ("%-8s ",
3191 prismember (&pip
-> trace
, signo
)
3193 printf_filtered ("%-8s ",
3194 prismember (&pip
-> prstatus
.pr_sighold
, signo
)
3197 #ifdef PROCFS_SIGPEND_OFFSET
3198 /* Alpha OSF/1 numbers the pending signals from 1. */
3199 printf_filtered ("%-8s ",
3200 (signo
? prismember (&pip
-> prstatus
.pr_sigpend
,
3205 printf_filtered ("%-8s ",
3206 prismember (&pip
-> prstatus
.pr_sigpend
, signo
)
3209 printf_filtered (" %s\n", safe_strsignal (signo
));
3211 printf_filtered ("\n");
3216 info_proc_faults (pip
, summary
)
3217 struct procinfo
*pip
;
3220 struct trans
*transp
;
3224 if (ioctl (pip
-> fd
, PIOCGFAULT
, &pip
-> fltset
) < 0)
3226 print_sys_errmsg (pip
-> pathname
, errno
);
3227 error ("PIOCGFAULT failed");
3230 printf_filtered ("Current traced hardware fault set:\n\n");
3231 printf_filtered ("\t%-12s %-8s\n", "Fault", "Trace");
3233 for (transp
= faults_table
; transp
-> name
!= NULL
; transp
++)
3236 printf_filtered ("\t%-12s ", transp
-> name
);
3237 printf_filtered ("%-8s", prismember (&pip
-> fltset
, transp
-> value
)
3239 printf_filtered ("\n");
3241 printf_filtered ("\n");
3246 info_proc_mappings (pip
, summary
)
3247 struct procinfo
*pip
;
3251 struct prmap
*prmaps
;
3252 struct prmap
*prmap
;
3256 printf_filtered ("Mapped address spaces:\n\n");
3257 #ifdef BFD_HOST_64_BIT
3258 printf_filtered (" %18s %18s %10s %10s %7s\n",
3260 printf_filtered ("\t%10s %10s %10s %10s %7s\n",
3267 if (ioctl (pip
-> fd
, PIOCNMAP
, &nmap
) == 0)
3269 prmaps
= (struct prmap
*) alloca ((nmap
+ 1) * sizeof (*prmaps
));
3270 if (ioctl (pip
-> fd
, PIOCMAP
, prmaps
) == 0)
3272 for (prmap
= prmaps
; prmap
-> pr_size
; ++prmap
)
3274 #ifdef BFD_HOST_64_BIT
3275 printf_filtered (" %#18lx %#18lx %#10x %#10x %7s\n",
3277 printf_filtered ("\t%#10lx %#10lx %#10x %#10x %7s\n",
3279 (unsigned long)prmap
-> pr_vaddr
,
3280 (unsigned long)prmap
-> pr_vaddr
3281 + prmap
-> pr_size
- 1,
3284 mappingflags (prmap
-> pr_mflags
));
3288 printf_filtered ("\n");
3296 info_proc -- implement the "info proc" command
3300 void info_proc (char *args, int from_tty)
3304 Implement gdb's "info proc" command by using the /proc interface
3305 to print status information about any currently running process.
3307 Examples of the use of "info proc" are:
3309 info proc (prints summary info for current inferior)
3310 info proc 123 (prints summary info for process with pid 123)
3311 info proc mappings (prints address mappings)
3312 info proc times (prints process/children times)
3313 info proc id (prints pid, ppid, gid, sid, etc)
3314 FIXME: i proc id not implemented.
3315 info proc status (prints general process state info)
3316 FIXME: i proc status not implemented.
3317 info proc signals (prints info about signal handling)
3318 info proc all (prints all info)
3323 info_proc (args
, from_tty
)
3328 struct procinfo
*pip
;
3329 struct cleanup
*old_chain
;
3343 old_chain
= make_cleanup (null_cleanup
, 0);
3345 /* Default to using the current inferior if no pid specified. Note
3346 that inferior_pid may be 0, hence we set okerr. */
3348 pip
= find_procinfo (inferior_pid
, 1);
3352 if ((argv
= buildargv (args
)) == NULL
)
3356 make_cleanup (freeargv
, (char *) argv
);
3358 while (*argv
!= NULL
)
3360 argsize
= strlen (*argv
);
3361 if (argsize
>= 1 && strncmp (*argv
, "all", argsize
) == 0)
3366 else if (argsize
>= 2 && strncmp (*argv
, "faults", argsize
) == 0)
3371 else if (argsize
>= 2 && strncmp (*argv
, "flags", argsize
) == 0)
3376 else if (argsize
>= 1 && strncmp (*argv
, "id", argsize
) == 0)
3381 else if (argsize
>= 1 && strncmp (*argv
, "mappings", argsize
) == 0)
3386 else if (argsize
>= 2 && strncmp (*argv
, "signals", argsize
) == 0)
3391 else if (argsize
>= 2 && strncmp (*argv
, "status", argsize
) == 0)
3396 else if (argsize
>= 2 && strncmp (*argv
, "syscalls", argsize
) == 0)
3401 else if (argsize
>= 1 && strncmp (*argv
, "times", argsize
) == 0)
3406 else if ((pid
= atoi (*argv
)) > 0)
3408 pip
= (struct procinfo
*) xmalloc (sizeof (struct procinfo
));
3409 memset (pip
, 0, sizeof (*pip
));
3412 if (!open_proc_file (pid
, pip
, O_RDONLY
))
3414 perror_with_name (pip
-> pathname
);
3417 make_cleanup (close_proc_file
, pip
);
3419 else if (**argv
!= '\000')
3421 error ("Unrecognized or ambiguous keyword `%s'.", *argv
);
3427 /* If we don't have a valid open process at this point, then we have no
3428 inferior or didn't specify a specific pid. */
3433 No process. Start debugging a program or specify an explicit process ID.");
3435 if (ioctl (pip
-> fd
, PIOCSTATUS
, &(pip
-> prstatus
)) < 0)
3437 print_sys_errmsg (pip
-> pathname
, errno
);
3438 error ("PIOCSTATUS failed");
3441 /* Print verbose information of the requested type(s), or just a summary
3442 of the information for all types. */
3444 printf_filtered ("\nInformation for %s:\n\n", pip
-> pathname
);
3445 if (summary
|| all
|| flags
)
3447 info_proc_flags (pip
, summary
);
3451 info_proc_stop (pip
, summary
);
3453 if (summary
|| all
|| signals
|| faults
)
3455 info_proc_siginfo (pip
, summary
);
3457 if (summary
|| all
|| syscalls
)
3459 info_proc_syscalls (pip
, summary
);
3461 if (summary
|| all
|| mappings
)
3463 info_proc_mappings (pip
, summary
);
3465 if (summary
|| all
|| signals
)
3467 info_proc_signals (pip
, summary
);
3469 if (summary
|| all
|| faults
)
3471 info_proc_faults (pip
, summary
);
3473 printf_filtered ("\n");
3475 /* All done, deal with closing any temporary process info structure,
3476 freeing temporary memory , etc. */
3478 do_cleanups (old_chain
);
3485 procfs_set_sproc_trap -- arrange for child to stop on sproc().
3489 void procfs_set_sproc_trap (struct procinfo *)
3493 This function sets up a trap on sproc system call exits so that we can
3494 detect the arrival of a new thread. We are called with the new thread
3495 stopped prior to it's first instruction.
3497 Also note that we turn on the inherit-on-fork flag in the child process
3498 so that any grand-children start with all tracing flags set.
3504 procfs_set_sproc_trap (pi
)
3505 struct procinfo
*pi
;
3509 if (ioctl (pi
->fd
, PIOCGEXIT
, &exitset
) < 0)
3511 print_sys_errmsg (pi
->pathname
, errno
);
3512 error ("PIOCGEXIT failed");
3515 praddset (&exitset
, SYS_sproc
);
3517 /* We trap on fork() and vfork() in order to disable debugging in our grand-
3518 children and descendant processes. At this time, GDB can only handle
3519 threads (multiple processes, one address space). forks (and execs) result
3520 in the creation of multiple address spaces, which GDB can't handle yet. */
3522 praddset (&exitset
, SYS_fork
);
3524 praddset (&exitset
, SYS_vfork
);
3527 if (ioctl (pi
->fd
, PIOCSEXIT
, &exitset
) < 0)
3529 print_sys_errmsg (pi
->pathname
, errno
);
3530 error ("PIOCSEXIT failed");
3533 /* Turn on inherit-on-fork flag so that all grand-children of gdb start with
3534 tracing flags set. */
3536 #ifdef PIOCSET /* New method */
3540 ioctl (pi
->fd
, PIOCSET
, &pr_flags
);
3543 #ifdef PIOCSFORK /* Original method */
3544 ioctl (pi
->fd
, PIOCSFORK
, NULL
);
3548 #endif /* SYS_sproc */
3550 /* Fork an inferior process, and start debugging it with /proc. */
3553 procfs_create_inferior (exec_file
, allargs
, env
)
3558 char *shell_file
= getenv ("SHELL");
3560 if (shell_file
!= NULL
&& strchr (shell_file
, '/') == NULL
)
3563 /* We will be looking down the PATH to find shell_file. If we
3564 just do this the normal way (via execlp, which operates by
3565 attempting an exec for each element of the PATH until it
3566 finds one which succeeds), then there will be an exec for
3567 each failed attempt, each of which will cause a PR_SYSEXIT
3568 stop, and we won't know how to distinguish the PR_SYSEXIT's
3569 for these failed execs with the ones for successful execs
3570 (whether the exec has succeeded is stored at that time in the
3571 carry bit or some such architecture-specific and
3572 non-ABI-specified place).
3574 So I can't think of anything better than to search the PATH
3575 now. This has several disadvantages: (1) There is a race
3576 condition; if we find a file now and it is deleted before we
3577 exec it, we lose, even if the deletion leaves a valid file
3578 further down in the PATH, (2) there is no way to know exactly
3579 what an executable (in the sense of "capable of being
3580 exec'd") file is. Using access() loses because it may lose
3581 if the caller is the superuser; failing to use it loses if
3582 there are ACLs or some such. */
3586 /* FIXME-maybe: might want "set path" command so user can change what
3587 path is used from within GDB. */
3588 char *path
= getenv ("PATH");
3590 struct stat statbuf
;
3593 path
= "/bin:/usr/bin";
3595 tryname
= alloca (strlen (path
) + strlen (shell_file
) + 2);
3596 for (p
= path
; p
!= NULL
; p
= p1
? p1
+ 1: NULL
)
3598 p1
= strchr (p
, ':');
3603 strncpy (tryname
, p
, len
);
3604 tryname
[len
] = '\0';
3605 strcat (tryname
, "/");
3606 strcat (tryname
, shell_file
);
3607 if (access (tryname
, X_OK
) < 0)
3609 if (stat (tryname
, &statbuf
) < 0)
3611 if (!S_ISREG (statbuf
.st_mode
))
3612 /* We certainly need to reject directories. I'm not quite
3613 as sure about FIFOs, sockets, etc., but I kind of doubt
3614 that people want to exec() these things. */
3619 /* Not found. This must be an error rather than merely passing
3620 the file to execlp(), because execlp() would try all the
3621 exec()s, causing GDB to get confused. */
3622 error ("Can't find shell %s in PATH", shell_file
);
3624 shell_file
= tryname
;
3627 fork_inferior (exec_file
, allargs
, env
,
3628 proc_set_exec_trap
, procfs_init_inferior
, shell_file
);
3630 /* We are at the first instruction we care about. */
3631 /* Pedal to the metal... */
3633 /* Setup traps on exit from sproc() */
3636 procfs_set_sproc_trap (current_procinfo
);
3639 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_0
, 0);
3642 /* Clean up after the inferior dies. */
3645 procfs_mourn_inferior ()
3647 struct procinfo
*pi
;
3648 struct procinfo
*next_pi
;
3650 for (pi
= procinfo_list
; pi
; pi
= next_pi
)
3653 unconditionally_kill_inferior (pi
);
3656 unpush_target (&procfs_ops
);
3657 generic_mourn_inferior ();
3661 /* Mark our target-struct as eligible for stray "run" and "attach" commands. */
3667 #ifdef TARGET_CAN_USE_HARDWARE_WATCHPOINT
3669 /* Insert a watchpoint */
3671 procfs_set_watchpoint(pid
, addr
, len
, rw
)
3677 struct procinfo
*pi
;
3680 pi
= find_procinfo (pid
== -1 ? inferior_pid
: pid
, 0);
3681 wpt
.pr_vaddr
= (caddr_t
)addr
;
3683 wpt
.pr_wflags
= ((rw
& 1) ? MA_READ
: 0) | ((rw
& 2) ? MA_WRITE
: 0);
3684 if (ioctl (pi
->fd
, PIOCSWATCH
, &wpt
) < 0)
3688 /* Currently it sometimes happens that the same watchpoint gets
3689 deleted twice - don't die in this case (FIXME please) */
3690 if (errno
== ESRCH
&& len
== 0)
3692 print_sys_errmsg (pi
->pathname
, errno
);
3693 error ("PIOCSWATCH failed");
3699 procfs_stopped_by_watchpoint(pid
)
3702 struct procinfo
*pi
;
3706 pi
= find_procinfo (pid
== -1 ? inferior_pid
: pid
, 0);
3707 if (pi
->prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
))
3709 why
= pi
->prstatus
.pr_why
;
3710 what
= pi
->prstatus
.pr_what
;
3711 if (why
== PR_FAULTED
3712 #if defined (FLTWATCH) && defined (FLTKWATCH)
3713 && (what
== FLTWATCH
) || (what
== FLTKWATCH
)
3716 && (what
== FLTWATCH
)
3719 && (what
== FLTKWATCH
)
3729 /* Send a SIGINT to the process group. This acts just like the user typed a
3730 ^C on the controlling terminal.
3732 XXX - This may not be correct for all systems. Some may want to use
3733 killpg() instead of kill (-pgrp). */
3738 extern pid_t inferior_process_group
;
3740 kill (-inferior_process_group
, SIGINT
);
3744 struct target_ops procfs_ops
= {
3745 "procfs", /* to_shortname */
3746 "Unix /proc child process", /* to_longname */
3747 "Unix /proc child process (started by the \"run\" command).", /* to_doc */
3748 procfs_open
, /* to_open */
3750 procfs_attach
, /* to_attach */
3751 procfs_detach
, /* to_detach */
3752 procfs_resume
, /* to_resume */
3753 procfs_wait
, /* to_wait */
3754 procfs_fetch_registers
, /* to_fetch_registers */
3755 procfs_store_registers
, /* to_store_registers */
3756 procfs_prepare_to_store
, /* to_prepare_to_store */
3757 procfs_xfer_memory
, /* to_xfer_memory */
3758 procfs_files_info
, /* to_files_info */
3759 memory_insert_breakpoint
, /* to_insert_breakpoint */
3760 memory_remove_breakpoint
, /* to_remove_breakpoint */
3761 terminal_init_inferior
, /* to_terminal_init */
3762 terminal_inferior
, /* to_terminal_inferior */
3763 terminal_ours_for_output
, /* to_terminal_ours_for_output */
3764 terminal_ours
, /* to_terminal_ours */
3765 child_terminal_info
, /* to_terminal_info */
3766 procfs_kill_inferior
, /* to_kill */
3768 0, /* to_lookup_symbol */
3769 procfs_create_inferior
, /* to_create_inferior */
3770 procfs_mourn_inferior
, /* to_mourn_inferior */
3771 procfs_can_run
, /* to_can_run */
3772 procfs_notice_signals
, /* to_notice_signals */
3773 procfs_stop
, /* to_stop */
3774 process_stratum
, /* to_stratum */
3776 1, /* to_has_all_memory */
3777 1, /* to_has_memory */
3778 1, /* to_has_stack */
3779 1, /* to_has_registers */
3780 1, /* to_has_execution */
3782 0, /* sections_end */
3783 OPS_MAGIC
/* to_magic */
3787 _initialize_procfs ()
3789 #ifdef HAVE_OPTIONAL_PROC_FS
3793 /* If we have an optional /proc filesystem (e.g. under OSF/1),
3794 don't add procfs support if we cannot access the running
3796 sprintf (procname
, PROC_NAME_FMT
, getpid ());
3797 if ((fd
= open (procname
, O_RDONLY
)) < 0)
3802 add_target (&procfs_ops
);
3804 add_info ("proc", info_proc
,
3805 "Show process status information using /proc entry.\n\
3806 Specify process id or use current inferior by default.\n\
3807 Specify keywords for detailed information; default is summary.\n\
3808 Keywords are: `all', `faults', `flags', `id', `mappings', `signals',\n\
3809 `status', `syscalls', and `times'.\n\
3810 Unambiguous abbreviations may be used.");
3812 init_syscall_table ();