1 /* Machine independent support for SVR4 /proc (process file system) for GDB.
2 Copyright 1991, 1992-97, 1998 Free Software Foundation, Inc.
3 Written by Fred Fish at Cygnus Support. Changes for sysv4.2mp procfs
4 compatibility by Geoffrey Noer at Cygnus Solutions.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
25 For information on the details of using /proc consult section proc(4)
26 in the UNIX System V Release 4 System Administrator's Reference Manual.
28 The general register and floating point register sets are manipulated
29 separately. This file makes the assumption that if FP0_REGNUM is
30 defined, then support for the floating point register set is desired,
31 regardless of whether or not the actual target has floating point hardware.
38 #include <sys/types.h>
40 #include <sys/fault.h>
41 #include <sys/syscall.h>
42 #include <sys/procfs.h>
45 #include "gdb_string.h"
55 #include "gdbthread.h"
57 #if !defined(SYS_lwp_create) && defined(SYS_lwpcreate)
58 # define SYS_lwp_create SYS_lwpcreate
61 #if !defined(SYS_lwp_exit) && defined(SYS_lwpexit)
62 # define SYS_lwp_exit SYS_lwpexit
65 #if !defined(SYS_lwp_wait) && defined(SYS_lwpwait)
66 # define SYS_lwp_wait SYS_lwpwait
69 #if !defined(SYS_lwp_self) && defined(SYS_lwpself)
70 # define SYS_lwp_self SYS_lwpself
73 #if !defined(SYS_lwp_info) && defined(SYS_lwpinfo)
74 # define SYS_lwp_info SYS_lwpinfo
77 #if !defined(SYS_lwp_private) && defined(SYS_lwpprivate)
78 # define SYS_lwp_private SYS_lwpprivate
81 #if !defined(SYS_lwp_kill) && defined(SYS_lwpkill)
82 # define SYS_lwp_kill SYS_lwpkill
85 #if !defined(SYS_lwp_suspend) && defined(SYS_lwpsuspend)
86 # define SYS_lwp_suspend SYS_lwpsuspend
89 #if !defined(SYS_lwp_continue) && defined(SYS_lwpcontinue)
90 # define SYS_lwp_continue SYS_lwpcontinue
93 /* the name of the proc status struct depends on the implementation */
95 typedef pstatus_t gdb_prstatus_t
;
97 typedef prstatus_t gdb_prstatus_t
;
100 #define MAX_SYSCALLS 256 /* Maximum number of syscalls for table */
102 /* proc name formats may vary depending on the proc implementation */
103 #ifdef HAVE_MULTIPLE_PROC_FDS
104 # ifndef CTL_PROC_NAME_FMT
105 # define CTL_PROC_NAME_FMT "/proc/%d/ctl"
106 # define AS_PROC_NAME_FMT "/proc/%d/as"
107 # define MAP_PROC_NAME_FMT "/proc/%d/map"
108 # define STATUS_PROC_NAME_FMT "/proc/%d/status"
110 #else /* HAVE_MULTIPLE_PROC_FDS */
111 # ifndef CTL_PROC_NAME_FMT
112 # define CTL_PROC_NAME_FMT "/proc/%05d"
113 # define AS_PROC_NAME_FMT "/proc/%05d"
114 # define MAP_PROC_NAME_FMT "/proc/%05d"
115 # define STATUS_PROC_NAME_FMT "/proc/%05d"
117 #endif /* HAVE_MULTIPLE_PROC_FDS */
120 /* These #ifdefs are for sol2.x in particular. sol2.x has
121 both a "gregset_t" and a "prgregset_t", which have
122 similar uses but different layouts. sol2.x gdb tries to
123 use prgregset_t (and prfpregset_t) everywhere. */
125 #ifdef GDB_GREGSET_TYPE
126 typedef GDB_GREGSET_TYPE gdb_gregset_t
;
128 typedef gregset_t gdb_gregset_t
;
131 #ifdef GDB_FPREGSET_TYPE
132 typedef GDB_FPREGSET_TYPE gdb_fpregset_t
;
134 typedef fpregset_t gdb_fpregset_t
;
138 #define MAX_PROC_NAME_SIZE sizeof("/proc/1234567890/status")
140 extern struct target_ops procfs_ops
; /* Forward declaration */
142 int procfs_suppress_run
= 0; /* Non-zero if procfs should pretend not to
143 be a runnable target. Used by targets
144 that can sit atop procfs, such as solaris
147 #if 1 /* FIXME: Gross and ugly hack to resolve coredep.c global */
148 CORE_ADDR kernel_u_addr
;
151 #ifdef BROKEN_SIGINFO_H /* Workaround broken SGS <sys/siginfo.h> */
153 #define si_pid _data._proc.pid
155 #define si_uid _data._proc._pdata._kill.uid
156 #endif /* BROKEN_SIGINFO_H */
158 /* Define structures for passing commands to /proc/pid/ctl file. Note that
159 while we create these for the PROCFS_USE_READ_WRITE world, we use them
160 and ignore the extra cmd int in other proc schemes.
162 /* generic ctl msg */
168 /* set general registers */
171 gdb_gregset_t gregset
;
174 /* set fp registers */
177 gdb_fpregset_t fpregset
;
180 /* set signals to be traced */
186 /* set faults to be traced */
192 /* set system calls to be traced */
198 /* set current signal to be traced */
204 /* All access to the inferior, either one started by gdb or one that has
205 been attached to, is controlled by an instance of a procinfo structure,
206 defined below. Since gdb currently only handles one inferior at a time,
207 the procinfo structure for the inferior is statically allocated and
208 only one exists at any given time. There is a separate procinfo
209 structure for use by the "info proc" command, so that we can print
210 useful information about any random process without interfering with
211 the inferior's procinfo information. */
214 struct procinfo
*next
;
215 int pid
; /* Process ID of inferior */
216 int ctl_fd
; /* File descriptor for /proc ctl file */
217 int status_fd
; /* File descriptor for /proc status file */
218 int as_fd
; /* File descriptor for /proc as file */
219 int map_fd
; /* File descriptor for /proc map file */
220 char *pathname
; /* Pathname to /proc entry */
221 int had_event
; /* poll/select says something happened */
222 int was_stopped
; /* Nonzero if was stopped prior to attach */
223 int nopass_next_sigstop
; /* Don't pass a sigstop on next resume */
224 #ifndef HAVE_NO_PRRUN_T
225 prrun_t prrun
; /* Control state when it is run */
227 gdb_prstatus_t prstatus
; /* Current process status info */
228 struct greg_ctl gregset
; /* General register set */
229 struct fpreg_ctl fpregset
; /* Floating point register set */
230 struct flt_ctl fltset
; /* Current traced hardware fault set */
231 struct sig_ctl trace
; /* Current traced signal set */
232 struct sys_ctl exitset
; /* Current traced system call exit set */
233 struct sys_ctl entryset
; /* Current traced system call entry set */
234 struct sig_ctl saved_sighold
; /* Saved held signal set */
235 struct flt_ctl saved_fltset
; /* Saved traced hardware fault set */
236 struct sig_ctl saved_trace
; /* Saved traced signal set */
237 struct sys_ctl saved_exitset
; /* Saved traced system call exit set */
238 struct sys_ctl saved_entryset
;/* Saved traced system call entry set */
239 int num_syscall_handlers
; /* Number of syscall trap handlers
240 currently installed */
241 /* Pointer to list of syscall trap handlers */
242 struct procfs_syscall_handler
*syscall_handlers
;
243 int saved_rtnval
; /* return value and status for wait(), */
244 int saved_statval
; /* as supplied by a syscall handler. */
245 int new_child
; /* Non-zero if it's a new thread */
248 /* List of inferior process information */
249 static struct procinfo
*procinfo_list
= NULL
;
250 static struct pollfd
*poll_list
; /* pollfds used for waiting on /proc */
252 static int num_poll_list
= 0; /* Number of entries in poll_list */
254 /* Much of the information used in the /proc interface, particularly for
255 printing status information, is kept as tables of structures of the
256 following form. These tables can be used to map numeric values to
257 their symbolic names and to a string that describes their specific use. */
260 int value
; /* The numeric value */
261 char *name
; /* The equivalent symbolic value */
262 char *desc
; /* Short description of value */
265 /* Translate bits in the pr_flags member of the prstatus structure, into the
266 names and desc information. */
268 static struct trans pr_flag_table
[] =
270 #if defined (PR_STOPPED)
271 { PR_STOPPED
, "PR_STOPPED", "Process is stopped" },
273 #if defined (PR_ISTOP)
274 { PR_ISTOP
, "PR_ISTOP", "Stopped on an event of interest" },
276 #if defined (PR_DSTOP)
277 { PR_DSTOP
, "PR_DSTOP", "A stop directive is in effect" },
279 #if defined (PR_ASLEEP)
280 { PR_ASLEEP
, "PR_ASLEEP", "Sleeping in an interruptible system call" },
282 #if defined (PR_FORK)
283 { PR_FORK
, "PR_FORK", "Inherit-on-fork is in effect" },
286 { PR_RLC
, "PR_RLC", "Run-on-last-close is in effect" },
288 #if defined (PR_PTRACE)
289 { PR_PTRACE
, "PR_PTRACE", "Process is being controlled by ptrace" },
291 #if defined (PR_PCINVAL)
292 { PR_PCINVAL
, "PR_PCINVAL", "PC refers to an invalid virtual address" },
294 #if defined (PR_ISSYS)
295 { PR_ISSYS
, "PR_ISSYS", "Is a system process" },
297 #if defined (PR_STEP)
298 { PR_STEP
, "PR_STEP", "Process has single step pending" },
301 { PR_KLC
, "PR_KLC", "Kill-on-last-close is in effect" },
303 #if defined (PR_ASYNC)
304 { PR_ASYNC
, "PR_ASYNC", "Asynchronous stop is in effect" },
306 #if defined (PR_PCOMPAT)
307 { PR_PCOMPAT
, "PR_PCOMPAT", "Ptrace compatibility mode in effect" },
309 #if defined (PR_MSACCT)
310 { PR_MSACCT
, "PR_MSACCT", "Microstate accounting enabled" },
312 #if defined (PR_BPTADJ)
313 { PR_BPTADJ
, "PR_BPTADJ", "Breakpoint PC adjustment in effect" },
315 #if defined (PR_ASLWP)
316 { PR_ASLWP
, "PR_ASLWP", "Asynchronus signal LWP" },
321 /* Translate values in the pr_why field of the prstatus struct. */
323 static struct trans pr_why_table
[] =
325 #if defined (PR_REQUESTED)
326 { PR_REQUESTED
, "PR_REQUESTED", "Directed to stop via PIOCSTOP/PIOCWSTOP" },
328 #if defined (PR_SIGNALLED)
329 { PR_SIGNALLED
, "PR_SIGNALLED", "Receipt of a traced signal" },
331 #if defined (PR_SYSENTRY)
332 { PR_SYSENTRY
, "PR_SYSENTRY", "Entry to a traced system call" },
334 #if defined (PR_SYSEXIT)
335 { PR_SYSEXIT
, "PR_SYSEXIT", "Exit from a traced system call" },
337 #if defined (PR_JOBCONTROL)
338 { PR_JOBCONTROL
, "PR_JOBCONTROL", "Default job control stop signal action" },
340 #if defined (PR_FAULTED)
341 { PR_FAULTED
, "PR_FAULTED", "Incurred a traced hardware fault" },
343 #if defined (PR_SUSPENDED)
344 { PR_SUSPENDED
, "PR_SUSPENDED", "Process suspended" },
346 #if defined (PR_CHECKPOINT)
347 { PR_CHECKPOINT
, "PR_CHECKPOINT", "(???)" },
352 /* Hardware fault translation table. */
354 static struct trans faults_table
[] =
357 { FLTILL
, "FLTILL", "Illegal instruction" },
359 #if defined (FLTPRIV)
360 { FLTPRIV
, "FLTPRIV", "Privileged instruction" },
363 { FLTBPT
, "FLTBPT", "Breakpoint trap" },
365 #if defined (FLTTRACE)
366 { FLTTRACE
, "FLTTRACE", "Trace trap" },
368 #if defined (FLTACCESS)
369 { FLTACCESS
, "FLTACCESS", "Memory access fault" },
371 #if defined (FLTBOUNDS)
372 { FLTBOUNDS
, "FLTBOUNDS", "Memory bounds violation" },
374 #if defined (FLTIOVF)
375 { FLTIOVF
, "FLTIOVF", "Integer overflow" },
377 #if defined (FLTIZDIV)
378 { FLTIZDIV
, "FLTIZDIV", "Integer zero divide" },
381 { FLTFPE
, "FLTFPE", "Floating-point exception" },
383 #if defined (FLTSTACK)
384 { FLTSTACK
, "FLTSTACK", "Unrecoverable stack fault" },
386 #if defined (FLTPAGE)
387 { FLTPAGE
, "FLTPAGE", "Recoverable page fault" },
392 /* Translation table for signal generation information. See UNIX System
393 V Release 4 Programmer's Reference Manual, siginfo(5). */
395 static struct sigcode
{
400 } siginfo_table
[] = {
401 #if defined (SIGILL) && defined (ILL_ILLOPC)
402 { SIGILL
, ILL_ILLOPC
, "ILL_ILLOPC", "Illegal opcode" },
404 #if defined (SIGILL) && defined (ILL_ILLOPN)
405 { SIGILL
, ILL_ILLOPN
, "ILL_ILLOPN", "Illegal operand", },
407 #if defined (SIGILL) && defined (ILL_ILLADR)
408 { SIGILL
, ILL_ILLADR
, "ILL_ILLADR", "Illegal addressing mode" },
410 #if defined (SIGILL) && defined (ILL_ILLTRP)
411 { SIGILL
, ILL_ILLTRP
, "ILL_ILLTRP", "Illegal trap" },
413 #if defined (SIGILL) && defined (ILL_PRVOPC)
414 { SIGILL
, ILL_PRVOPC
, "ILL_PRVOPC", "Privileged opcode" },
416 #if defined (SIGILL) && defined (ILL_PRVREG)
417 { SIGILL
, ILL_PRVREG
, "ILL_PRVREG", "Privileged register" },
419 #if defined (SIGILL) && defined (ILL_COPROC)
420 { SIGILL
, ILL_COPROC
, "ILL_COPROC", "Coprocessor error" },
422 #if defined (SIGILL) && defined (ILL_BADSTK)
423 { SIGILL
, ILL_BADSTK
, "ILL_BADSTK", "Internal stack error" },
425 #if defined (SIGFPE) && defined (FPE_INTDIV)
426 { SIGFPE
, FPE_INTDIV
, "FPE_INTDIV", "Integer divide by zero" },
428 #if defined (SIGFPE) && defined (FPE_INTOVF)
429 { SIGFPE
, FPE_INTOVF
, "FPE_INTOVF", "Integer overflow" },
431 #if defined (SIGFPE) && defined (FPE_FLTDIV)
432 { SIGFPE
, FPE_FLTDIV
, "FPE_FLTDIV", "Floating point divide by zero" },
434 #if defined (SIGFPE) && defined (FPE_FLTOVF)
435 { SIGFPE
, FPE_FLTOVF
, "FPE_FLTOVF", "Floating point overflow" },
437 #if defined (SIGFPE) && defined (FPE_FLTUND)
438 { SIGFPE
, FPE_FLTUND
, "FPE_FLTUND", "Floating point underflow" },
440 #if defined (SIGFPE) && defined (FPE_FLTRES)
441 { SIGFPE
, FPE_FLTRES
, "FPE_FLTRES", "Floating point inexact result" },
443 #if defined (SIGFPE) && defined (FPE_FLTINV)
444 { SIGFPE
, FPE_FLTINV
, "FPE_FLTINV", "Invalid floating point operation" },
446 #if defined (SIGFPE) && defined (FPE_FLTSUB)
447 { SIGFPE
, FPE_FLTSUB
, "FPE_FLTSUB", "Subscript out of range" },
449 #if defined (SIGSEGV) && defined (SEGV_MAPERR)
450 { SIGSEGV
, SEGV_MAPERR
, "SEGV_MAPERR", "Address not mapped to object" },
452 #if defined (SIGSEGV) && defined (SEGV_ACCERR)
453 { SIGSEGV
, SEGV_ACCERR
, "SEGV_ACCERR", "Invalid permissions for object" },
455 #if defined (SIGBUS) && defined (BUS_ADRALN)
456 { SIGBUS
, BUS_ADRALN
, "BUS_ADRALN", "Invalid address alignment" },
458 #if defined (SIGBUS) && defined (BUS_ADRERR)
459 { SIGBUS
, BUS_ADRERR
, "BUS_ADRERR", "Non-existent physical address" },
461 #if defined (SIGBUS) && defined (BUS_OBJERR)
462 { SIGBUS
, BUS_OBJERR
, "BUS_OBJERR", "Object specific hardware error" },
464 #if defined (SIGTRAP) && defined (TRAP_BRKPT)
465 { SIGTRAP
, TRAP_BRKPT
, "TRAP_BRKPT", "Process breakpoint" },
467 #if defined (SIGTRAP) && defined (TRAP_TRACE)
468 { SIGTRAP
, TRAP_TRACE
, "TRAP_TRACE", "Process trace trap" },
470 #if defined (SIGCLD) && defined (CLD_EXITED)
471 { SIGCLD
, CLD_EXITED
, "CLD_EXITED", "Child has exited" },
473 #if defined (SIGCLD) && defined (CLD_KILLED)
474 { SIGCLD
, CLD_KILLED
, "CLD_KILLED", "Child was killed" },
476 #if defined (SIGCLD) && defined (CLD_DUMPED)
477 { SIGCLD
, CLD_DUMPED
, "CLD_DUMPED", "Child has terminated abnormally" },
479 #if defined (SIGCLD) && defined (CLD_TRAPPED)
480 { SIGCLD
, CLD_TRAPPED
, "CLD_TRAPPED", "Traced child has trapped" },
482 #if defined (SIGCLD) && defined (CLD_STOPPED)
483 { SIGCLD
, CLD_STOPPED
, "CLD_STOPPED", "Child has stopped" },
485 #if defined (SIGCLD) && defined (CLD_CONTINUED)
486 { SIGCLD
, CLD_CONTINUED
, "CLD_CONTINUED", "Stopped child had continued" },
488 #if defined (SIGPOLL) && defined (POLL_IN)
489 { SIGPOLL
, POLL_IN
, "POLL_IN", "Input input available" },
491 #if defined (SIGPOLL) && defined (POLL_OUT)
492 { SIGPOLL
, POLL_OUT
, "POLL_OUT", "Output buffers available" },
494 #if defined (SIGPOLL) && defined (POLL_MSG)
495 { SIGPOLL
, POLL_MSG
, "POLL_MSG", "Input message available" },
497 #if defined (SIGPOLL) && defined (POLL_ERR)
498 { SIGPOLL
, POLL_ERR
, "POLL_ERR", "I/O error" },
500 #if defined (SIGPOLL) && defined (POLL_PRI)
501 { SIGPOLL
, POLL_PRI
, "POLL_PRI", "High priority input available" },
503 #if defined (SIGPOLL) && defined (POLL_HUP)
504 { SIGPOLL
, POLL_HUP
, "POLL_HUP", "Device disconnected" },
509 static char *syscall_table
[MAX_SYSCALLS
];
511 /* Prototypes for local functions */
513 static void procfs_stop
PARAMS ((void));
515 static int procfs_thread_alive
PARAMS ((int));
517 static int procfs_can_run
PARAMS ((void));
519 static void procfs_mourn_inferior
PARAMS ((void));
521 static void procfs_fetch_registers
PARAMS ((int));
523 static int procfs_wait
PARAMS ((int, struct target_waitstatus
*));
525 static void procfs_open
PARAMS ((char *, int));
527 static void procfs_files_info
PARAMS ((struct target_ops
*));
529 static void procfs_prepare_to_store
PARAMS ((void));
531 static void procfs_detach
PARAMS ((char *, int));
533 static void procfs_attach
PARAMS ((char *, int));
535 static void proc_set_exec_trap
PARAMS ((void));
537 static int procfs_init_inferior
PARAMS ((int));
539 static struct procinfo
*create_procinfo
PARAMS ((int));
541 static void procfs_store_registers
PARAMS ((int));
543 static int procfs_xfer_memory
PARAMS ((CORE_ADDR
, char *, int, int, struct target_ops
*));
545 static void procfs_kill_inferior
PARAMS ((void));
547 static char *sigcodedesc
PARAMS ((siginfo_t
*));
549 static char *sigcodename
PARAMS ((siginfo_t
*));
551 static struct procinfo
*wait_fd
PARAMS ((void));
553 static void remove_fd
PARAMS ((struct procinfo
*));
555 static void add_fd
PARAMS ((struct procinfo
*));
557 static void set_proc_siginfo
PARAMS ((struct procinfo
*, int));
559 static void init_syscall_table
PARAMS ((void));
561 static char *syscallname
PARAMS ((int));
563 static char *signalname
PARAMS ((int));
565 static char *errnoname
PARAMS ((int));
567 static int proc_address_to_fd
PARAMS ((struct procinfo
*, CORE_ADDR
, int));
569 static int open_proc_file
PARAMS ((int, struct procinfo
*, int, int));
571 static void close_proc_file
PARAMS ((struct procinfo
*));
573 static void unconditionally_kill_inferior
PARAMS ((struct procinfo
*));
575 static NORETURN
void proc_init_failed
PARAMS ((struct procinfo
*, char *, int)) ATTR_NORETURN
;
577 static void info_proc
PARAMS ((char *, int));
579 static void info_proc_flags
PARAMS ((struct procinfo
*, int));
581 static void info_proc_stop
PARAMS ((struct procinfo
*, int));
583 static void info_proc_siginfo
PARAMS ((struct procinfo
*, int));
585 static void info_proc_syscalls
PARAMS ((struct procinfo
*, int));
587 static void info_proc_mappings
PARAMS ((struct procinfo
*, int));
589 static void info_proc_signals
PARAMS ((struct procinfo
*, int));
591 static void info_proc_faults
PARAMS ((struct procinfo
*, int));
593 static char *mappingflags
PARAMS ((long));
595 static char *lookupname
PARAMS ((struct trans
*, unsigned int, char *));
597 static char *lookupdesc
PARAMS ((struct trans
*, unsigned int));
599 static int do_attach
PARAMS ((int pid
));
601 static void do_detach
PARAMS ((int siggnal
));
603 static void procfs_create_inferior
PARAMS ((char *, char *, char **));
605 static void procfs_notice_signals
PARAMS ((int pid
));
607 static void notice_signals
PARAMS ((struct procinfo
*, struct sig_ctl
*));
609 static struct procinfo
*find_procinfo
PARAMS ((pid_t pid
, int okfail
));
611 static int procfs_write_pcwstop
PARAMS ((struct procinfo
*));
612 static int procfs_read_status
PARAMS ((struct procinfo
*));
613 static void procfs_write_pckill
PARAMS ((struct procinfo
*));
615 typedef int syscall_func_t
PARAMS ((struct procinfo
*pi
, int syscall_num
,
616 int why
, int *rtnval
, int *statval
));
618 static void procfs_set_syscall_trap
PARAMS ((struct procinfo
*pi
,
619 int syscall_num
, int flags
,
620 syscall_func_t
*func
));
622 static void procfs_clear_syscall_trap
PARAMS ((struct procinfo
*pi
,
623 int syscall_num
, int errok
));
625 #define PROCFS_SYSCALL_ENTRY 0x1 /* Trap on entry to sys call */
626 #define PROCFS_SYSCALL_EXIT 0x2 /* Trap on exit from sys call */
628 static syscall_func_t procfs_exit_handler
;
630 static syscall_func_t procfs_exec_handler
;
633 static syscall_func_t procfs_sproc_handler
;
634 static syscall_func_t procfs_fork_handler
;
637 #ifdef SYS_lwp_create
638 static syscall_func_t procfs_lwp_creation_handler
;
641 static void modify_inherit_on_fork_flag
PARAMS ((int fd
, int flag
));
642 static void modify_run_on_last_close_flag
PARAMS ((int fd
, int flag
));
646 struct procfs_syscall_handler
648 int syscall_num
; /* The number of the system call being handled */
649 /* The function to be called */
650 syscall_func_t
*func
;
653 static void procfs_resume
PARAMS ((int pid
, int step
,
654 enum target_signal signo
));
656 /* External function prototypes that can't be easily included in any
657 header file because the args are typedefs in system include files. */
659 extern void supply_gregset
PARAMS ((gdb_gregset_t
*));
661 extern void fill_gregset
PARAMS ((gdb_gregset_t
*, int));
664 extern void supply_fpregset
PARAMS ((gdb_fpregset_t
*));
666 extern void fill_fpregset
PARAMS ((gdb_fpregset_t
*, int));
673 find_procinfo -- convert a process id to a struct procinfo
677 static struct procinfo * find_procinfo (pid_t pid, int okfail);
681 Given a process id, look it up in the procinfo chain. Returns
682 a struct procinfo *. If can't find pid, then call error(),
683 unless okfail is set, in which case, return NULL;
686 static struct procinfo
*
687 find_procinfo (pid
, okfail
)
691 struct procinfo
*procinfo
;
693 for (procinfo
= procinfo_list
; procinfo
; procinfo
= procinfo
->next
)
694 if (procinfo
->pid
== pid
)
700 error ("procfs (find_procinfo): Couldn't locate pid %d", pid
);
707 current_procinfo -- convert inferior_pid to a struct procinfo
711 static struct procinfo * current_procinfo;
715 Looks up inferior_pid in the procinfo chain. Always returns a
716 struct procinfo *. If process can't be found, we error() out.
719 #define current_procinfo find_procinfo (inferior_pid, 0)
725 add_fd -- Add the fd to the poll/select list
729 static void add_fd (struct procinfo *);
733 Add the fd of the supplied procinfo to the list of fds used for
734 poll/select operations.
741 if (num_poll_list
<= 0)
742 poll_list
= (struct pollfd
*) xmalloc (sizeof (struct pollfd
));
744 poll_list
= (struct pollfd
*) xrealloc (poll_list
,
746 * sizeof (struct pollfd
));
747 poll_list
[num_poll_list
].fd
= pi
->ctl_fd
;
749 poll_list
[num_poll_list
].events
= POLLWRNORM
;
751 poll_list
[num_poll_list
].events
= POLLPRI
;
761 remove_fd -- Remove the fd from the poll/select list
765 static void remove_fd (struct procinfo *);
769 Remove the fd of the supplied procinfo from the list of fds used
770 for poll/select operations.
779 for (i
= 0; i
< num_poll_list
; i
++)
781 if (poll_list
[i
].fd
== pi
->ctl_fd
)
783 if (i
!= num_poll_list
- 1)
784 memcpy (poll_list
+ i
, poll_list
+ i
+ 1,
785 (num_poll_list
- i
- 1) * sizeof (struct pollfd
));
789 if (num_poll_list
== 0)
792 poll_list
= (struct pollfd
*) xrealloc (poll_list
,
794 * sizeof (struct pollfd
));
804 procfs_read_status - get procfs fd status
808 static int procfs_read_status (pi) struct procinfo *pi;
812 Given a pointer to a procinfo struct, get the status of
813 the status_fd in the appropriate way. Returns 0 on failure,
818 procfs_read_status (pi
)
821 #ifdef PROCFS_USE_READ_WRITE
822 if ((lseek (pi
->status_fd
, 0, SEEK_SET
) < 0) ||
823 (read (pi
->status_fd
, (char *) &pi
->prstatus
,
824 sizeof (gdb_prstatus_t
)) != sizeof (gdb_prstatus_t
)))
826 if (ioctl (pi
->status_fd
, PIOCSTATUS
, &pi
->prstatus
) < 0)
837 procfs_write_pcwstop - send a PCWSTOP to procfs fd
841 static int procfs_write_pcwstop (pi) struct procinfo *pi;
845 Given a pointer to a procinfo struct, send a PCWSTOP to
846 the ctl_fd in the appropriate way. Returns 0 on failure,
851 procfs_write_pcwstop (pi
)
854 #ifdef PROCFS_USE_READ_WRITE
856 if (write (pi
->ctl_fd
, (char *) &cmd
, sizeof (long)) < 0)
858 if (ioctl (pi
->ctl_fd
, PIOCWSTOP
, &pi
->prstatus
) < 0)
869 procfs_write_pckill - send a kill to procfs fd
873 static void procfs_write_pckill (pi) struct procinfo *pi;
877 Given a pointer to a procinfo struct, send a kill to
878 the ctl_fd in the appropriate way. Returns 0 on failure,
883 procfs_write_pckill (pi
)
886 #ifdef PROCFS_USE_READ_WRITE
887 struct proc_ctl pctl
;
890 write (pi
->ctl_fd
, &pctl
, sizeof (struct proc_ctl
));
893 ioctl (pi
->ctl_fd
, PIOCKILL
, &signo
);
897 static struct procinfo
*
900 struct procinfo
*pi
, *next_pi
;
906 set_sigint_trap (); /* Causes SIGINT to be passed on to the
914 num_fds
= poll (poll_list
, num_poll_list
, -1);
917 if (num_fds
< 0 && errno
== EINTR
)
919 print_sys_errmsg ("poll failed", errno
);
920 error ("Poll failed, returned %d", num_fds
);
922 #else /* LOSING_POLL */
923 pi
= current_procinfo
;
925 while (!procfs_write_pcwstop (pi
))
929 /* Process exited. */
930 pi
->prstatus
.pr_flags
= 0;
933 else if (errno
!= EINTR
)
935 print_sys_errmsg (pi
->pathname
, errno
);
936 error ("procfs_write_pcwstop failed");
940 #endif /* LOSING_POLL */
942 clear_sigint_trap ();
947 for (i
= 0; i
< num_poll_list
&& num_fds
> 0; i
++)
949 if (0 == (poll_list
[i
].revents
&
950 (POLLWRNORM
| POLLPRI
| POLLERR
| POLLHUP
| POLLNVAL
)))
952 for (pi
= procinfo_list
; pi
; pi
= next_pi
)
955 if (poll_list
[i
].fd
== pi
->ctl_fd
)
958 if ((poll_list
[i
].revents
& POLLHUP
) != 0 ||
959 !procfs_read_status(pi
))
960 { /* The LWP has apparently terminated. */
961 if (num_poll_list
<= 1)
963 pi
->prstatus
.pr_flags
= 0;
968 printf_filtered ("LWP %d exited.\n",
969 (pi
->pid
>> 16) & 0xffff);
970 close_proc_file (pi
);
972 continue; /* already another event to process */
974 goto wait_again
; /* wait for another event */
981 error ("wait_fd: Couldn't find procinfo for fd %d\n",
984 #endif /* LOSING_POLL */
993 lookupdesc -- translate a value to a summary desc string
997 static char *lookupdesc (struct trans *transp, unsigned int val);
1001 Given a pointer to a translation table and a value to be translated,
1002 lookup the desc string and return it.
1006 lookupdesc (transp
, val
)
1007 struct trans
*transp
;
1012 for (desc
= NULL
; transp
-> name
!= NULL
; transp
++)
1014 if (transp
-> value
== val
)
1016 desc
= transp
-> desc
;
1021 /* Didn't find a translation for the specified value, set a default one. */
1034 lookupname -- translate a value to symbolic name
1038 static char *lookupname (struct trans *transp, unsigned int val,
1043 Given a pointer to a translation table, a value to be translated,
1044 and a default prefix to return if the value can't be translated,
1045 match the value with one of the translation table entries and
1046 return a pointer to the symbolic name.
1048 If no match is found it just returns the value as a printable string,
1049 with the given prefix. The previous such value, if any, is freed
1054 lookupname (transp
, val
, prefix
)
1055 struct trans
*transp
;
1059 static char *locbuf
;
1062 for (name
= NULL
; transp
-> name
!= NULL
; transp
++)
1064 if (transp
-> value
== val
)
1066 name
= transp
-> name
;
1071 /* Didn't find a translation for the specified value, build a default
1072 one using the specified prefix and return it. The lifetime of
1073 the value is only until the next one is needed. */
1081 locbuf
= xmalloc (strlen (prefix
) + 16);
1082 sprintf (locbuf
, "%s %u", prefix
, val
);
1092 struct sigcode
*scp
;
1094 static char locbuf
[32];
1096 for (scp
= siginfo_table
; scp
-> codename
!= NULL
; scp
++)
1098 if ((scp
-> signo
== sip
-> si_signo
) &&
1099 (scp
-> code
== sip
-> si_code
))
1101 name
= scp
-> codename
;
1107 sprintf (locbuf
, "sigcode %u", sip
-> si_signo
);
1117 struct sigcode
*scp
;
1120 for (scp
= siginfo_table
; scp
-> codename
!= NULL
; scp
++)
1122 if ((scp
-> signo
== sip
-> si_signo
) &&
1123 (scp
-> code
== sip
-> si_code
))
1131 desc
= "Unrecognized signal or trap use";
1140 syscallname - translate a system call number into a system call name
1144 char *syscallname (int syscallnum)
1148 Given a system call number, translate it into the printable name
1149 of a system call, or into "syscall <num>" if it is an unknown
1154 syscallname (syscallnum
)
1157 static char locbuf
[32];
1159 if (syscallnum
>= 0 && syscallnum
< MAX_SYSCALLS
1160 && syscall_table
[syscallnum
] != NULL
)
1161 return syscall_table
[syscallnum
];
1164 sprintf (locbuf
, "syscall %u", syscallnum
);
1173 init_syscall_table - initialize syscall translation table
1177 void init_syscall_table (void)
1181 Dynamically initialize the translation table to convert system
1182 call numbers into printable system call names. Done once per
1183 gdb run, on initialization.
1187 This is awfully ugly, but preprocessor tricks to make it prettier
1188 tend to be nonportable.
1192 init_syscall_table ()
1194 #if defined (SYS_exit)
1195 syscall_table
[SYS_exit
] = "exit";
1197 #if defined (SYS_fork)
1198 syscall_table
[SYS_fork
] = "fork";
1200 #if defined (SYS_read)
1201 syscall_table
[SYS_read
] = "read";
1203 #if defined (SYS_write)
1204 syscall_table
[SYS_write
] = "write";
1206 #if defined (SYS_open)
1207 syscall_table
[SYS_open
] = "open";
1209 #if defined (SYS_close)
1210 syscall_table
[SYS_close
] = "close";
1212 #if defined (SYS_wait)
1213 syscall_table
[SYS_wait
] = "wait";
1215 #if defined (SYS_creat)
1216 syscall_table
[SYS_creat
] = "creat";
1218 #if defined (SYS_link)
1219 syscall_table
[SYS_link
] = "link";
1221 #if defined (SYS_unlink)
1222 syscall_table
[SYS_unlink
] = "unlink";
1224 #if defined (SYS_exec)
1225 syscall_table
[SYS_exec
] = "exec";
1227 #if defined (SYS_execv)
1228 syscall_table
[SYS_execv
] = "execv";
1230 #if defined (SYS_execve)
1231 syscall_table
[SYS_execve
] = "execve";
1233 #if defined (SYS_chdir)
1234 syscall_table
[SYS_chdir
] = "chdir";
1236 #if defined (SYS_time)
1237 syscall_table
[SYS_time
] = "time";
1239 #if defined (SYS_mknod)
1240 syscall_table
[SYS_mknod
] = "mknod";
1242 #if defined (SYS_chmod)
1243 syscall_table
[SYS_chmod
] = "chmod";
1245 #if defined (SYS_chown)
1246 syscall_table
[SYS_chown
] = "chown";
1248 #if defined (SYS_brk)
1249 syscall_table
[SYS_brk
] = "brk";
1251 #if defined (SYS_stat)
1252 syscall_table
[SYS_stat
] = "stat";
1254 #if defined (SYS_lseek)
1255 syscall_table
[SYS_lseek
] = "lseek";
1257 #if defined (SYS_getpid)
1258 syscall_table
[SYS_getpid
] = "getpid";
1260 #if defined (SYS_mount)
1261 syscall_table
[SYS_mount
] = "mount";
1263 #if defined (SYS_umount)
1264 syscall_table
[SYS_umount
] = "umount";
1266 #if defined (SYS_setuid)
1267 syscall_table
[SYS_setuid
] = "setuid";
1269 #if defined (SYS_getuid)
1270 syscall_table
[SYS_getuid
] = "getuid";
1272 #if defined (SYS_stime)
1273 syscall_table
[SYS_stime
] = "stime";
1275 #if defined (SYS_ptrace)
1276 syscall_table
[SYS_ptrace
] = "ptrace";
1278 #if defined (SYS_alarm)
1279 syscall_table
[SYS_alarm
] = "alarm";
1281 #if defined (SYS_fstat)
1282 syscall_table
[SYS_fstat
] = "fstat";
1284 #if defined (SYS_pause)
1285 syscall_table
[SYS_pause
] = "pause";
1287 #if defined (SYS_utime)
1288 syscall_table
[SYS_utime
] = "utime";
1290 #if defined (SYS_stty)
1291 syscall_table
[SYS_stty
] = "stty";
1293 #if defined (SYS_gtty)
1294 syscall_table
[SYS_gtty
] = "gtty";
1296 #if defined (SYS_access)
1297 syscall_table
[SYS_access
] = "access";
1299 #if defined (SYS_nice)
1300 syscall_table
[SYS_nice
] = "nice";
1302 #if defined (SYS_statfs)
1303 syscall_table
[SYS_statfs
] = "statfs";
1305 #if defined (SYS_sync)
1306 syscall_table
[SYS_sync
] = "sync";
1308 #if defined (SYS_kill)
1309 syscall_table
[SYS_kill
] = "kill";
1311 #if defined (SYS_fstatfs)
1312 syscall_table
[SYS_fstatfs
] = "fstatfs";
1314 #if defined (SYS_pgrpsys)
1315 syscall_table
[SYS_pgrpsys
] = "pgrpsys";
1317 #if defined (SYS_xenix)
1318 syscall_table
[SYS_xenix
] = "xenix";
1320 #if defined (SYS_dup)
1321 syscall_table
[SYS_dup
] = "dup";
1323 #if defined (SYS_pipe)
1324 syscall_table
[SYS_pipe
] = "pipe";
1326 #if defined (SYS_times)
1327 syscall_table
[SYS_times
] = "times";
1329 #if defined (SYS_profil)
1330 syscall_table
[SYS_profil
] = "profil";
1332 #if defined (SYS_plock)
1333 syscall_table
[SYS_plock
] = "plock";
1335 #if defined (SYS_setgid)
1336 syscall_table
[SYS_setgid
] = "setgid";
1338 #if defined (SYS_getgid)
1339 syscall_table
[SYS_getgid
] = "getgid";
1341 #if defined (SYS_signal)
1342 syscall_table
[SYS_signal
] = "signal";
1344 #if defined (SYS_msgsys)
1345 syscall_table
[SYS_msgsys
] = "msgsys";
1347 #if defined (SYS_sys3b)
1348 syscall_table
[SYS_sys3b
] = "sys3b";
1350 #if defined (SYS_sysi86)
1351 syscall_table
[SYS_sysi86
] = "sysi86";
1353 #if defined (SYS_acct)
1354 syscall_table
[SYS_acct
] = "acct";
1356 #if defined (SYS_shmsys)
1357 syscall_table
[SYS_shmsys
] = "shmsys";
1359 #if defined (SYS_semsys)
1360 syscall_table
[SYS_semsys
] = "semsys";
1362 #if defined (SYS_ioctl)
1363 syscall_table
[SYS_ioctl
] = "ioctl";
1365 #if defined (SYS_uadmin)
1366 syscall_table
[SYS_uadmin
] = "uadmin";
1368 #if defined (SYS_utssys)
1369 syscall_table
[SYS_utssys
] = "utssys";
1371 #if defined (SYS_fsync)
1372 syscall_table
[SYS_fsync
] = "fsync";
1374 #if defined (SYS_umask)
1375 syscall_table
[SYS_umask
] = "umask";
1377 #if defined (SYS_chroot)
1378 syscall_table
[SYS_chroot
] = "chroot";
1380 #if defined (SYS_fcntl)
1381 syscall_table
[SYS_fcntl
] = "fcntl";
1383 #if defined (SYS_ulimit)
1384 syscall_table
[SYS_ulimit
] = "ulimit";
1386 #if defined (SYS_rfsys)
1387 syscall_table
[SYS_rfsys
] = "rfsys";
1389 #if defined (SYS_rmdir)
1390 syscall_table
[SYS_rmdir
] = "rmdir";
1392 #if defined (SYS_mkdir)
1393 syscall_table
[SYS_mkdir
] = "mkdir";
1395 #if defined (SYS_getdents)
1396 syscall_table
[SYS_getdents
] = "getdents";
1398 #if defined (SYS_sysfs)
1399 syscall_table
[SYS_sysfs
] = "sysfs";
1401 #if defined (SYS_getmsg)
1402 syscall_table
[SYS_getmsg
] = "getmsg";
1404 #if defined (SYS_putmsg)
1405 syscall_table
[SYS_putmsg
] = "putmsg";
1407 #if defined (SYS_poll)
1408 syscall_table
[SYS_poll
] = "poll";
1410 #if defined (SYS_lstat)
1411 syscall_table
[SYS_lstat
] = "lstat";
1413 #if defined (SYS_symlink)
1414 syscall_table
[SYS_symlink
] = "symlink";
1416 #if defined (SYS_readlink)
1417 syscall_table
[SYS_readlink
] = "readlink";
1419 #if defined (SYS_setgroups)
1420 syscall_table
[SYS_setgroups
] = "setgroups";
1422 #if defined (SYS_getgroups)
1423 syscall_table
[SYS_getgroups
] = "getgroups";
1425 #if defined (SYS_fchmod)
1426 syscall_table
[SYS_fchmod
] = "fchmod";
1428 #if defined (SYS_fchown)
1429 syscall_table
[SYS_fchown
] = "fchown";
1431 #if defined (SYS_sigprocmask)
1432 syscall_table
[SYS_sigprocmask
] = "sigprocmask";
1434 #if defined (SYS_sigsuspend)
1435 syscall_table
[SYS_sigsuspend
] = "sigsuspend";
1437 #if defined (SYS_sigaltstack)
1438 syscall_table
[SYS_sigaltstack
] = "sigaltstack";
1440 #if defined (SYS_sigaction)
1441 syscall_table
[SYS_sigaction
] = "sigaction";
1443 #if defined (SYS_sigpending)
1444 syscall_table
[SYS_sigpending
] = "sigpending";
1446 #if defined (SYS_context)
1447 syscall_table
[SYS_context
] = "context";
1449 #if defined (SYS_evsys)
1450 syscall_table
[SYS_evsys
] = "evsys";
1452 #if defined (SYS_evtrapret)
1453 syscall_table
[SYS_evtrapret
] = "evtrapret";
1455 #if defined (SYS_statvfs)
1456 syscall_table
[SYS_statvfs
] = "statvfs";
1458 #if defined (SYS_fstatvfs)
1459 syscall_table
[SYS_fstatvfs
] = "fstatvfs";
1461 #if defined (SYS_nfssys)
1462 syscall_table
[SYS_nfssys
] = "nfssys";
1464 #if defined (SYS_waitsys)
1465 syscall_table
[SYS_waitsys
] = "waitsys";
1467 #if defined (SYS_sigsendsys)
1468 syscall_table
[SYS_sigsendsys
] = "sigsendsys";
1470 #if defined (SYS_hrtsys)
1471 syscall_table
[SYS_hrtsys
] = "hrtsys";
1473 #if defined (SYS_acancel)
1474 syscall_table
[SYS_acancel
] = "acancel";
1476 #if defined (SYS_async)
1477 syscall_table
[SYS_async
] = "async";
1479 #if defined (SYS_priocntlsys)
1480 syscall_table
[SYS_priocntlsys
] = "priocntlsys";
1482 #if defined (SYS_pathconf)
1483 syscall_table
[SYS_pathconf
] = "pathconf";
1485 #if defined (SYS_mincore)
1486 syscall_table
[SYS_mincore
] = "mincore";
1488 #if defined (SYS_mmap)
1489 syscall_table
[SYS_mmap
] = "mmap";
1491 #if defined (SYS_mprotect)
1492 syscall_table
[SYS_mprotect
] = "mprotect";
1494 #if defined (SYS_munmap)
1495 syscall_table
[SYS_munmap
] = "munmap";
1497 #if defined (SYS_fpathconf)
1498 syscall_table
[SYS_fpathconf
] = "fpathconf";
1500 #if defined (SYS_vfork)
1501 syscall_table
[SYS_vfork
] = "vfork";
1503 #if defined (SYS_fchdir)
1504 syscall_table
[SYS_fchdir
] = "fchdir";
1506 #if defined (SYS_readv)
1507 syscall_table
[SYS_readv
] = "readv";
1509 #if defined (SYS_writev)
1510 syscall_table
[SYS_writev
] = "writev";
1512 #if defined (SYS_xstat)
1513 syscall_table
[SYS_xstat
] = "xstat";
1515 #if defined (SYS_lxstat)
1516 syscall_table
[SYS_lxstat
] = "lxstat";
1518 #if defined (SYS_fxstat)
1519 syscall_table
[SYS_fxstat
] = "fxstat";
1521 #if defined (SYS_xmknod)
1522 syscall_table
[SYS_xmknod
] = "xmknod";
1524 #if defined (SYS_clocal)
1525 syscall_table
[SYS_clocal
] = "clocal";
1527 #if defined (SYS_setrlimit)
1528 syscall_table
[SYS_setrlimit
] = "setrlimit";
1530 #if defined (SYS_getrlimit)
1531 syscall_table
[SYS_getrlimit
] = "getrlimit";
1533 #if defined (SYS_lchown)
1534 syscall_table
[SYS_lchown
] = "lchown";
1536 #if defined (SYS_memcntl)
1537 syscall_table
[SYS_memcntl
] = "memcntl";
1539 #if defined (SYS_getpmsg)
1540 syscall_table
[SYS_getpmsg
] = "getpmsg";
1542 #if defined (SYS_putpmsg)
1543 syscall_table
[SYS_putpmsg
] = "putpmsg";
1545 #if defined (SYS_rename)
1546 syscall_table
[SYS_rename
] = "rename";
1548 #if defined (SYS_uname)
1549 syscall_table
[SYS_uname
] = "uname";
1551 #if defined (SYS_setegid)
1552 syscall_table
[SYS_setegid
] = "setegid";
1554 #if defined (SYS_sysconfig)
1555 syscall_table
[SYS_sysconfig
] = "sysconfig";
1557 #if defined (SYS_adjtime)
1558 syscall_table
[SYS_adjtime
] = "adjtime";
1560 #if defined (SYS_systeminfo)
1561 syscall_table
[SYS_systeminfo
] = "systeminfo";
1563 #if defined (SYS_seteuid)
1564 syscall_table
[SYS_seteuid
] = "seteuid";
1566 #if defined (SYS_sproc)
1567 syscall_table
[SYS_sproc
] = "sproc";
1569 #if defined (SYS_keyctl)
1570 syscall_table
[SYS_keyctl
] = "keyctl";
1572 #if defined (SYS_secsys)
1573 syscall_table
[SYS_secsys
] = "secsys";
1575 #if defined (SYS_filepriv)
1576 syscall_table
[SYS_filepriv
] = "filepriv";
1578 #if defined (SYS_procpriv)
1579 syscall_table
[SYS_procpriv
] = "procpriv";
1581 #if defined (SYS_devstat)
1582 syscall_table
[SYS_devstat
] = "devstat";
1584 #if defined (SYS_aclipc)
1585 syscall_table
[SYS_aclipc
] = "aclipc";
1587 #if defined (SYS_fdevstat)
1588 syscall_table
[SYS_fdevstat
] = "fdevstat";
1590 #if defined (SYS_flvlfile)
1591 syscall_table
[SYS_flvlfile
] = "flvlfile";
1593 #if defined (SYS_lvlfile)
1594 syscall_table
[SYS_lvlfile
] = "lvlfile";
1596 #if defined (SYS_lvlequal)
1597 syscall_table
[SYS_lvlequal
] = "lvlequal";
1599 #if defined (SYS_lvlproc)
1600 syscall_table
[SYS_lvlproc
] = "lvlproc";
1602 #if defined (SYS_lvlipc)
1603 syscall_table
[SYS_lvlipc
] = "lvlipc";
1605 #if defined (SYS_acl)
1606 syscall_table
[SYS_acl
] = "acl";
1608 #if defined (SYS_auditevt)
1609 syscall_table
[SYS_auditevt
] = "auditevt";
1611 #if defined (SYS_auditctl)
1612 syscall_table
[SYS_auditctl
] = "auditctl";
1614 #if defined (SYS_auditdmp)
1615 syscall_table
[SYS_auditdmp
] = "auditdmp";
1617 #if defined (SYS_auditlog)
1618 syscall_table
[SYS_auditlog
] = "auditlog";
1620 #if defined (SYS_auditbuf)
1621 syscall_table
[SYS_auditbuf
] = "auditbuf";
1623 #if defined (SYS_lvldom)
1624 syscall_table
[SYS_lvldom
] = "lvldom";
1626 #if defined (SYS_lvlvfs)
1627 syscall_table
[SYS_lvlvfs
] = "lvlvfs";
1629 #if defined (SYS_mkmld)
1630 syscall_table
[SYS_mkmld
] = "mkmld";
1632 #if defined (SYS_mldmode)
1633 syscall_table
[SYS_mldmode
] = "mldmode";
1635 #if defined (SYS_secadvise)
1636 syscall_table
[SYS_secadvise
] = "secadvise";
1638 #if defined (SYS_online)
1639 syscall_table
[SYS_online
] = "online";
1641 #if defined (SYS_setitimer)
1642 syscall_table
[SYS_setitimer
] = "setitimer";
1644 #if defined (SYS_getitimer)
1645 syscall_table
[SYS_getitimer
] = "getitimer";
1647 #if defined (SYS_gettimeofday)
1648 syscall_table
[SYS_gettimeofday
] = "gettimeofday";
1650 #if defined (SYS_settimeofday)
1651 syscall_table
[SYS_settimeofday
] = "settimeofday";
1653 #if defined (SYS_lwp_create)
1654 syscall_table
[SYS_lwp_create
] = "_lwp_create";
1656 #if defined (SYS_lwp_exit)
1657 syscall_table
[SYS_lwp_exit
] = "_lwp_exit";
1659 #if defined (SYS_lwp_wait)
1660 syscall_table
[SYS_lwp_wait
] = "_lwp_wait";
1662 #if defined (SYS_lwp_self)
1663 syscall_table
[SYS_lwp_self
] = "_lwp_self";
1665 #if defined (SYS_lwp_info)
1666 syscall_table
[SYS_lwp_info
] = "_lwp_info";
1668 #if defined (SYS_lwp_private)
1669 syscall_table
[SYS_lwp_private
] = "_lwp_private";
1671 #if defined (SYS_processor_bind)
1672 syscall_table
[SYS_processor_bind
] = "processor_bind";
1674 #if defined (SYS_processor_exbind)
1675 syscall_table
[SYS_processor_exbind
] = "processor_exbind";
1677 #if defined (SYS_prepblock)
1678 syscall_table
[SYS_prepblock
] = "prepblock";
1680 #if defined (SYS_block)
1681 syscall_table
[SYS_block
] = "block";
1683 #if defined (SYS_rdblock)
1684 syscall_table
[SYS_rdblock
] = "rdblock";
1686 #if defined (SYS_unblock)
1687 syscall_table
[SYS_unblock
] = "unblock";
1689 #if defined (SYS_cancelblock)
1690 syscall_table
[SYS_cancelblock
] = "cancelblock";
1692 #if defined (SYS_pread)
1693 syscall_table
[SYS_pread
] = "pread";
1695 #if defined (SYS_pwrite)
1696 syscall_table
[SYS_pwrite
] = "pwrite";
1698 #if defined (SYS_truncate)
1699 syscall_table
[SYS_truncate
] = "truncate";
1701 #if defined (SYS_ftruncate)
1702 syscall_table
[SYS_ftruncate
] = "ftruncate";
1704 #if defined (SYS_lwp_kill)
1705 syscall_table
[SYS_lwp_kill
] = "_lwp_kill";
1707 #if defined (SYS_sigwait)
1708 syscall_table
[SYS_sigwait
] = "sigwait";
1710 #if defined (SYS_fork1)
1711 syscall_table
[SYS_fork1
] = "fork1";
1713 #if defined (SYS_forkall)
1714 syscall_table
[SYS_forkall
] = "forkall";
1716 #if defined (SYS_modload)
1717 syscall_table
[SYS_modload
] = "modload";
1719 #if defined (SYS_moduload)
1720 syscall_table
[SYS_moduload
] = "moduload";
1722 #if defined (SYS_modpath)
1723 syscall_table
[SYS_modpath
] = "modpath";
1725 #if defined (SYS_modstat)
1726 syscall_table
[SYS_modstat
] = "modstat";
1728 #if defined (SYS_modadm)
1729 syscall_table
[SYS_modadm
] = "modadm";
1731 #if defined (SYS_getksym)
1732 syscall_table
[SYS_getksym
] = "getksym";
1734 #if defined (SYS_lwp_suspend)
1735 syscall_table
[SYS_lwp_suspend
] = "_lwp_suspend";
1737 #if defined (SYS_lwp_continue)
1738 syscall_table
[SYS_lwp_continue
] = "_lwp_continue";
1740 #if defined (SYS_priocntllst)
1741 syscall_table
[SYS_priocntllst
] = "priocntllst";
1743 #if defined (SYS_sleep)
1744 syscall_table
[SYS_sleep
] = "sleep";
1746 #if defined (SYS_lwp_sema_wait)
1747 syscall_table
[SYS_lwp_sema_wait
] = "_lwp_sema_wait";
1749 #if defined (SYS_lwp_sema_post)
1750 syscall_table
[SYS_lwp_sema_post
] = "_lwp_sema_post";
1752 #if defined (SYS_lwp_sema_trywait)
1753 syscall_table
[SYS_lwp_sema_trywait
] = "lwp_sema_trywait";
1755 #if defined(SYS_fstatvfs64)
1756 syscall_table
[SYS_fstatvfs64
] = "fstatvfs64";
1758 #if defined(SYS_statvfs64)
1759 syscall_table
[SYS_statvfs64
] = "statvfs64";
1761 #if defined(SYS_ftruncate64)
1762 syscall_table
[SYS_ftruncate64
] = "ftruncate64";
1764 #if defined(SYS_truncate64)
1765 syscall_table
[SYS_truncate64
] = "truncate64";
1767 #if defined(SYS_getrlimit64)
1768 syscall_table
[SYS_getrlimit64
] = "getrlimit64";
1770 #if defined(SYS_setrlimit64)
1771 syscall_table
[SYS_setrlimit64
] = "setrlimit64";
1773 #if defined(SYS_lseek64)
1774 syscall_table
[SYS_lseek64
] = "lseek64";
1776 #if defined(SYS_mmap64)
1777 syscall_table
[SYS_mmap64
] = "mmap64";
1779 #if defined(SYS_pread64)
1780 syscall_table
[SYS_pread64
] = "pread64";
1782 #if defined(SYS_creat64)
1783 syscall_table
[SYS_creat64
] = "creat64";
1785 #if defined(SYS_dshmsys)
1786 syscall_table
[SYS_dshmsys
] = "dshmsys";
1788 #if defined(SYS_invlpg)
1789 syscall_table
[SYS_invlpg
] = "invlpg";
1791 #if defined(SYS_cg_ids)
1792 syscall_table
[SYS_cg_ids
] = "cg_ids";
1794 #if defined(SYS_cg_processors)
1795 syscall_table
[SYS_cg_processors
] = "cg_processors";
1797 #if defined(SYS_cg_info)
1798 syscall_table
[SYS_cg_info
] = "cg_info";
1800 #if defined(SYS_cg_bind)
1801 syscall_table
[SYS_cg_bind
] = "cg_bind";
1803 #if defined(SYS_cg_current)
1804 syscall_table
[SYS_cg_current
] = "cg_current";
1806 #if defined(SYS_cg_memloc)
1807 syscall_table
[SYS_cg_memloc
] = "cg_memloc";
1815 procfs_kill_inferior - kill any currently inferior
1819 void procfs_kill_inferior (void)
1823 Kill any current inferior.
1827 Kills even attached inferiors. Presumably the user has already
1828 been prompted that the inferior is an attached one rather than
1829 one started by gdb. (FIXME?)
1834 procfs_kill_inferior ()
1836 target_mourn_inferior ();
1843 unconditionally_kill_inferior - terminate the inferior
1847 static void unconditionally_kill_inferior (struct procinfo *)
1851 Kill the specified inferior.
1855 A possibly useful enhancement would be to first try sending
1856 the inferior a terminate signal, politely asking it to commit
1857 suicide, before we murder it (we could call that
1858 politely_kill_inferior()).
1863 unconditionally_kill_inferior (pi
)
1864 struct procinfo
*pi
;
1867 struct proc_ctl pctl
;
1869 ppid
= pi
->prstatus
.pr_ppid
;
1871 #ifdef PROCFS_NEED_CLEAR_CURSIG_FOR_KILL
1872 /* Alpha OSF/1-3.x procfs needs a clear of the current signal
1873 before the PIOCKILL, otherwise it might generate a corrupted core
1874 file for the inferior. */
1875 ioctl (pi
->ctl_fd
, PIOCSSIG
, NULL
);
1877 #ifdef PROCFS_NEED_PIOCSSIG_FOR_KILL
1878 /* Alpha OSF/1-2.x procfs needs a PIOCSSIG call with a SIGKILL signal
1879 to kill the inferior, otherwise it might remain stopped with a
1881 We do not check the result of the PIOCSSIG, the inferior might have
1884 struct siginfo newsiginfo
;
1886 memset ((char *) &newsiginfo
, 0, sizeof (newsiginfo
));
1887 newsiginfo
.si_signo
= SIGKILL
;
1888 newsiginfo
.si_code
= 0;
1889 newsiginfo
.si_errno
= 0;
1890 newsiginfo
.si_pid
= getpid ();
1891 newsiginfo
.si_uid
= getuid ();
1892 ioctl (pi
->ctl_fd
, PIOCSSIG
, &newsiginfo
);
1894 #else /* PROCFS_NEED_PIOCSSIG_FOR_KILL */
1895 procfs_write_pckill (pi
);
1896 #endif /* PROCFS_NEED_PIOCSSIG_FOR_KILL */
1898 close_proc_file (pi
);
1900 /* Only wait() for our direct children. Our grandchildren zombies are killed
1901 by the death of their parents. */
1903 if (ppid
== getpid())
1911 procfs_xfer_memory -- copy data to or from inferior memory space
1915 int procfs_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len,
1916 int dowrite, struct target_ops target)
1920 Copy LEN bytes to/from inferior's memory starting at MEMADDR
1921 from/to debugger memory starting at MYADDR. Copy from inferior
1922 if DOWRITE is zero or to inferior if DOWRITE is nonzero.
1924 Returns the length copied, which is either the LEN argument or
1925 zero. This xfer function does not do partial moves, since procfs_ops
1926 doesn't allow memory operations to cross below us in the target stack
1931 The /proc interface makes this an almost trivial task.
1935 procfs_xfer_memory (memaddr
, myaddr
, len
, dowrite
, target
)
1940 struct target_ops
*target
; /* ignored */
1943 struct procinfo
*pi
;
1945 pi
= current_procinfo
;
1947 if (lseek(pi
->as_fd
, (off_t
) memaddr
, SEEK_SET
) == (off_t
) memaddr
)
1951 nbytes
= write (pi
->as_fd
, myaddr
, len
);
1955 nbytes
= read (pi
->as_fd
, myaddr
, len
);
1969 procfs_store_registers -- copy register values back to inferior
1973 void procfs_store_registers (int regno)
1977 Store our current register values back into the inferior. If
1978 REGNO is -1 then store all the register, otherwise store just
1979 the value specified by REGNO.
1983 If we are storing only a single register, we first have to get all
1984 the current values from the process, overwrite the desired register
1985 in the gregset with the one we want from gdb's registers, and then
1986 send the whole set back to the process. For writing all the
1987 registers, all we have to do is generate the gregset and send it to
1990 Also note that the process has to be stopped on an event of interest
1991 for this to work, which basically means that it has to have been
1992 run under the control of one of the other /proc ioctl calls and not
1993 ptrace. Since we don't use ptrace anyway, we don't worry about this
1994 fine point, but it is worth noting for future reference.
1996 Gdb is confused about what this function is supposed to return.
1997 Some versions return a value, others return nothing. Some are
1998 declared to return a value and actually return nothing. Gdb ignores
1999 anything returned. (FIXME)
2004 procfs_store_registers (regno
)
2007 struct procinfo
*pi
;
2008 #ifdef PROCFS_USE_READ_WRITE
2009 struct greg_ctl greg
;
2010 struct fpreg_ctl fpreg
;
2013 pi
= current_procinfo
;
2015 #ifdef PROCFS_USE_READ_WRITE
2018 procfs_read_status (pi
);
2019 memcpy ((char *) &greg
.gregset
,
2020 (char *) &pi
->prstatus
.pr_lwp
.pr_context
.uc_mcontext
.gregs
,
2021 sizeof (gdb_gregset_t
));
2023 fill_gregset (&greg
.gregset
, regno
);
2025 write (pi
->ctl_fd
, &greg
, sizeof (greg
));
2026 #else /* PROCFS_USE_READ_WRITE */
2029 ioctl (pi
->ctl_fd
, PIOCGREG
, &pi
->gregset
.gregset
);
2031 fill_gregset (&pi
->gregset
.gregset
, regno
);
2032 ioctl (pi
->ctl_fd
, PIOCSREG
, &pi
->gregset
.gregset
);
2033 #endif /* PROCFS_USE_READ_WRITE */
2035 #if defined (FP0_REGNUM)
2037 /* Now repeat everything using the floating point register set, if the
2038 target has floating point hardware. Since we ignore the returned value,
2039 we'll never know whether it worked or not anyway. */
2041 #ifdef PROCFS_USE_READ_WRITE
2044 procfs_read_status (pi
);
2045 memcpy ((char *) &fpreg
.fpregset
,
2046 (char *) &pi
->prstatus
.pr_lwp
.pr_context
.uc_mcontext
.fpregs
,
2047 sizeof (gdb_fpregset_t
));
2049 fill_fpregset (&fpreg
.fpregset
, regno
);
2050 fpreg
.cmd
= PCSFPREG
;
2051 write (pi
->ctl_fd
, &fpreg
, sizeof (fpreg
));
2052 #else /* PROCFS_USE_READ_WRITE */
2055 ioctl (pi
->ctl_fd
, PIOCGFPREG
, &pi
->fpregset
.fpregset
);
2057 fill_fpregset (&pi
->fpregset
.fpregset
, regno
);
2058 ioctl (pi
->ctl_fd
, PIOCSFPREG
, &pi
->fpregset
.fpregset
);
2059 #endif /* PROCFS_USE_READ_WRITE */
2061 #endif /* FP0_REGNUM */
2069 init_procinfo - setup a procinfo struct and connect it to a process
2073 struct procinfo * init_procinfo (int pid)
2077 Allocate a procinfo structure, open the /proc file and then set up the
2078 set of signals and faults that are to be traced. Returns a pointer to
2079 the new procinfo structure.
2083 If proc_init_failed ever gets called, control returns to the command
2084 processing loop via the standard error handling code.
2088 static struct procinfo
*
2089 init_procinfo (pid
, kill
)
2093 struct procinfo
*pi
= (struct procinfo
*)
2094 xmalloc (sizeof (struct procinfo
));
2095 struct sig_ctl sctl
;
2096 struct flt_ctl fctl
;
2098 memset ((char *) pi
, 0, sizeof (*pi
));
2099 if (!open_proc_file (pid
, pi
, O_RDWR
, 1))
2100 proc_init_failed (pi
, "can't open process file", kill
);
2102 /* open_proc_file may modify pid. */
2106 /* Add new process to process info list */
2108 pi
->next
= procinfo_list
;
2111 add_fd (pi
); /* Add to list for poll/select */
2113 /* Remember some things about the inferior that we will, or might, change
2114 so that we can restore them when we detach. */
2116 memcpy ((char *) &pi
->saved_trace
.sigset
,
2117 (char *) &pi
->prstatus
.pr_sigtrace
, sizeof (sigset_t
));
2118 memcpy ((char *) &pi
->saved_fltset
.fltset
,
2119 (char *) &pi
->prstatus
.pr_flttrace
, sizeof (fltset_t
));
2120 memcpy ((char *) &pi
->saved_entryset
.sysset
,
2121 (char *) &pi
->prstatus
.pr_sysentry
, sizeof (sysset_t
));
2122 memcpy ((char *) &pi
->saved_exitset
.sysset
,
2123 (char *) &pi
->prstatus
.pr_sysexit
, sizeof (sysset_t
));
2125 /* Set up trace and fault sets, as gdb expects them. */
2127 prfillset (&sctl
.sigset
);
2128 notice_signals (pi
, &sctl
);
2129 prfillset (&fctl
.fltset
);
2130 prdelset (&fctl
.fltset
, FLTPAGE
);
2132 #else /* ! UNIXWARE */
2133 ioctl (pi
->ctl_fd
, PIOCGTRACE
, &pi
->saved_trace
.sigset
);
2134 ioctl (pi
->ctl_fd
, PIOCGHOLD
, &pi
->saved_sighold
.sigset
);
2135 ioctl (pi
->ctl_fd
, PIOCGFAULT
, &pi
->saved_fltset
.fltset
);
2136 ioctl (pi
->ctl_fd
, PIOCGENTRY
, &pi
->saved_entryset
.sysset
);
2137 ioctl (pi
->ctl_fd
, PIOCGEXIT
, &pi
->saved_exitset
.sysset
);
2139 /* Set up trace and fault sets, as gdb expects them. */
2141 memset ((char *) &pi
->prrun
, 0, sizeof (pi
->prrun
));
2142 prfillset (&pi
->prrun
.pr_trace
);
2143 procfs_notice_signals (pid
);
2144 prfillset (&pi
->prrun
.pr_fault
);
2145 prdelset (&pi
->prrun
.pr_fault
, FLTPAGE
);
2146 #ifdef PROCFS_DONT_TRACE_FAULTS
2147 premptyset (&pi
->prrun
.pr_fault
);
2149 #endif /* UNIXWARE */
2151 if (!procfs_read_status (pi
))
2152 proc_init_failed (pi
, "procfs_read_status failed", kill
);
2161 create_procinfo - initialize access to a /proc entry
2165 struct procinfo * create_procinfo (int pid)
2169 Allocate a procinfo structure, open the /proc file and then set up the
2170 set of signals and faults that are to be traced. Returns a pointer to
2171 the new procinfo structure.
2175 If proc_init_failed ever gets called, control returns to the command
2176 processing loop via the standard error handling code.
2180 static struct procinfo
*
2181 create_procinfo (pid
)
2184 struct procinfo
*pi
;
2185 struct sig_ctl sctl
;
2186 struct flt_ctl fctl
;
2188 pi
= find_procinfo (pid
, 1);
2190 return pi
; /* All done! It already exists */
2192 pi
= init_procinfo (pid
, 1);
2195 /* A bug in Solaris (2.5 at least) causes PIOCWSTOP to hang on LWPs that are
2196 already stopped, even if they all have PR_ASYNC set. */
2197 if (!(pi
->prstatus
.pr_flags
& PR_STOPPED
))
2199 if (!procfs_write_pcwstop (pi
))
2200 proc_init_failed (pi
, "procfs_write_pcwstop failed", 1);
2202 #ifdef PROCFS_USE_READ_WRITE
2203 fctl
.cmd
= PCSFAULT
;
2204 if (write (pi
->ctl_fd
, (char *) &fctl
, sizeof (struct flt_ctl
)) < 0)
2205 proc_init_failed (pi
, "PCSFAULT failed", 1);
2207 if (ioctl (pi
->ctl_fd
, PIOCSFAULT
, &pi
->prrun
.pr_fault
) < 0)
2208 proc_init_failed (pi
, "PIOCSFAULT failed", 1);
2218 procfs_exit_handler - handle entry into the _exit syscall
2222 int procfs_exit_handler (pi, syscall_num, why, rtnvalp, statvalp)
2226 This routine is called when an inferior process enters the _exit()
2227 system call. It continues the process, and then collects the exit
2228 status and pid which are returned in *statvalp and *rtnvalp. After
2229 that it returns non-zero to indicate that procfs_wait should wake up.
2232 There is probably a better way to do this.
2237 procfs_exit_handler (pi
, syscall_num
, why
, rtnvalp
, statvalp
)
2238 struct procinfo
*pi
;
2244 struct procinfo
*temp_pi
, *next_pi
;
2245 struct proc_ctl pctl
;
2249 pctl
.data
= PRCFAULT
;
2251 pi
->prrun
.pr_flags
= PRCFAULT
;
2254 #ifdef PROCFS_USE_READ_WRITE
2255 if (write (pi
->ctl_fd
, (char *)&pctl
, sizeof (struct proc_ctl
)) < 0)
2257 if (ioctl (pi
->ctl_fd
, PIOCRUN
, &pi
->prrun
) != 0)
2259 perror_with_name (pi
->pathname
);
2263 /* Claim it exited (don't call wait). */
2265 printf_filtered ("(attached process has exited)\n");
2267 *rtnvalp
= inferior_pid
;
2271 *rtnvalp
= wait (statvalp
);
2276 /* Close ALL open proc file handles,
2277 except the one that called SYS_exit. */
2278 for (temp_pi
= procinfo_list
; temp_pi
; temp_pi
= next_pi
)
2280 next_pi
= temp_pi
->next
;
2282 continue; /* Handled below */
2283 close_proc_file (temp_pi
);
2292 procfs_exec_handler - handle exit from the exec family of syscalls
2296 int procfs_exec_handler (pi, syscall_num, why, rtnvalp, statvalp)
2300 This routine is called when an inferior process is about to finish any
2301 of the exec() family of system calls. It pretends that we got a
2302 SIGTRAP (for compatibility with ptrace behavior), and returns non-zero
2303 to tell procfs_wait to wake up.
2306 This need for compatibility with ptrace is questionable. In the
2307 future, it shouldn't be necessary.
2312 procfs_exec_handler (pi
, syscall_num
, why
, rtnvalp
, statvalp
)
2313 struct procinfo
*pi
;
2319 *statvalp
= (SIGTRAP
<< 8) | 0177;
2324 #if defined(SYS_sproc) && !defined(UNIXWARE)
2325 /* IRIX lwp creation system call */
2331 procfs_sproc_handler - handle exit from the sproc syscall
2335 int procfs_sproc_handler (pi, syscall_num, why, rtnvalp, statvalp)
2339 This routine is called when an inferior process is about to finish an
2340 sproc() system call. This is the system call that IRIX uses to create
2341 a lightweight process. When the target process gets this event, we can
2342 look at rval1 to find the new child processes ID, and create a new
2343 procinfo struct from that.
2345 After that, it pretends that we got a SIGTRAP, and returns non-zero
2346 to tell procfs_wait to wake up. Subsequently, wait_for_inferior gets
2347 woken up, sees the new process and continues it.
2350 We actually never see the child exiting from sproc because we will
2351 shortly stop the child with PIOCSTOP, which is then registered as the
2356 procfs_sproc_handler (pi
, syscall_num
, why
, rtnvalp
, statvalp
)
2357 struct procinfo
*pi
;
2363 /* We've just detected the completion of an sproc system call. Now we need to
2364 setup a procinfo struct for this thread, and notify the thread system of the
2367 /* If sproc failed, then nothing interesting happened. Continue the process
2368 and go back to sleep. */
2370 if (pi
->prstatus
.pr_errno
!= 0)
2372 pi
->prrun
.pr_flags
&= PRSTEP
;
2373 pi
->prrun
.pr_flags
|= PRCFAULT
;
2375 if (ioctl (pi
->ctl_fd
, PIOCRUN
, &pi
->prrun
) != 0)
2376 perror_with_name (pi
->pathname
);
2381 /* At this point, the new thread is stopped at it's first instruction, and
2382 the parent is stopped at the exit from sproc. */
2384 /* Notify the caller of the arrival of a new thread. */
2385 create_procinfo (pi
->prstatus
.pr_rval1
);
2387 *rtnvalp
= pi
->prstatus
.pr_rval1
;
2388 *statvalp
= (SIGTRAP
<< 8) | 0177;
2397 procfs_fork_handler - handle exit from the fork syscall
2401 int procfs_fork_handler (pi, syscall_num, why, rtnvalp, statvalp)
2405 This routine is called when an inferior process is about to finish a
2406 fork() system call. We will open up the new process, and then close
2407 it, which releases it from the clutches of the debugger.
2409 After that, we continue the target process as though nothing had
2413 This is necessary for IRIX because we have to set PR_FORK in order
2414 to catch the creation of lwps (via sproc()). When an actual fork
2415 occurs, it becomes necessary to reset the forks debugger flags and
2416 continue it because we can't hack multiple processes yet.
2420 procfs_fork_handler (pi
, syscall_num
, why
, rtnvalp
, statvalp
)
2421 struct procinfo
*pi
;
2427 struct procinfo
*pitemp
;
2429 /* At this point, we've detected the completion of a fork (or vfork) call in
2430 our child. The grandchild is also stopped because we set inherit-on-fork
2431 earlier. (Note that nobody has the grandchilds' /proc file open at this
2432 point.) We will release the grandchild from the debugger by opening it's
2433 /proc file and then closing it. Since run-on-last-close is set, the
2434 grandchild continues on its' merry way. */
2437 pitemp
= create_procinfo (pi
->prstatus
.pr_rval1
);
2439 close_proc_file (pitemp
);
2441 if (ioctl (pi
->ctl_fd
, PIOCRUN
, &pi
->prrun
) != 0)
2442 perror_with_name (pi
->pathname
);
2446 #endif /* SYS_sproc && !UNIXWARE */
2452 procfs_set_inferior_syscall_traps - setup the syscall traps
2456 void procfs_set_inferior_syscall_traps (struct procinfo *pip)
2460 Called for each "procinfo" (process, thread, or LWP) in the
2461 inferior, to register for notification of and handlers for
2462 syscall traps in the inferior.
2467 procfs_set_inferior_syscall_traps (pip
)
2468 struct procinfo
*pip
;
2470 procfs_set_syscall_trap (pip
, SYS_exit
, PROCFS_SYSCALL_ENTRY
,
2471 procfs_exit_handler
);
2473 #ifndef PRFS_STOPEXEC
2475 procfs_set_syscall_trap (pip
, SYS_exec
, PROCFS_SYSCALL_EXIT
,
2476 procfs_exec_handler
);
2479 procfs_set_syscall_trap (pip
, SYS_execv
, PROCFS_SYSCALL_EXIT
,
2480 procfs_exec_handler
);
2483 procfs_set_syscall_trap (pip
, SYS_execve
, PROCFS_SYSCALL_EXIT
,
2484 procfs_exec_handler
);
2486 #endif /* PRFS_STOPEXEC */
2488 /* Setup traps on exit from sproc() */
2491 procfs_set_syscall_trap (pip
, SYS_sproc
, PROCFS_SYSCALL_EXIT
,
2492 procfs_sproc_handler
);
2493 procfs_set_syscall_trap (pip
, SYS_fork
, PROCFS_SYSCALL_EXIT
,
2494 procfs_fork_handler
);
2496 procfs_set_syscall_trap (pip
, SYS_vfork
, PROCFS_SYSCALL_EXIT
,
2497 procfs_fork_handler
);
2499 /* Turn on inherit-on-fork flag so that all children of the target process
2500 start with tracing flags set. This allows us to trap lwp creation. Note
2501 that we also have to trap on fork and vfork in order to disable all tracing
2502 in the targets child processes. */
2504 modify_inherit_on_fork_flag (pip
->ctl_fd
, 1);
2507 #ifdef SYS_lwp_create
2508 procfs_set_syscall_trap (pip
, SYS_lwp_create
, PROCFS_SYSCALL_EXIT
,
2509 procfs_lwp_creation_handler
);
2517 procfs_init_inferior - initialize target vector and access to a
2522 int procfs_init_inferior (int pid)
2526 When gdb starts an inferior, this function is called in the parent
2527 process immediately after the fork. It waits for the child to stop
2528 on the return from the exec system call (the child itself takes care
2529 of ensuring that this is set up), then sets up the set of signals
2530 and faults that are to be traced. Returns the pid, which may have had
2531 the thread-id added to it.
2535 If proc_init_failed ever gets called, control returns to the command
2536 processing loop via the standard error handling code.
2541 procfs_init_inferior (pid
)
2544 struct procinfo
*pip
;
2546 push_target (&procfs_ops
);
2548 pip
= create_procinfo (pid
);
2550 procfs_set_inferior_syscall_traps (pip
);
2552 /* create_procinfo may change the pid, so we have to update inferior_pid
2553 here before calling other gdb routines that need the right pid. */
2558 add_thread (pip
-> pid
); /* Setup initial thread */
2560 #ifdef START_INFERIOR_TRAPS_EXPECTED
2561 startup_inferior (START_INFERIOR_TRAPS_EXPECTED
);
2563 /* One trap to exec the shell, one to exec the program being debugged. */
2564 startup_inferior (2);
2574 procfs_notice_signals
2578 static void procfs_notice_signals (int pid);
2582 When the user changes the state of gdb's signal handling via the
2583 "handle" command, this function gets called to see if any change
2584 in the /proc interface is required. It is also called internally
2585 by other /proc interface functions to initialize the state of
2586 the traced signal set.
2588 One thing it does is that signals for which the state is "nostop",
2589 "noprint", and "pass", have their trace bits reset in the pr_trace
2590 field, so that they are no longer traced. This allows them to be
2591 delivered directly to the inferior without the debugger ever being
2596 procfs_notice_signals (pid
)
2599 struct procinfo
*pi
;
2600 struct sig_ctl sctl
;
2602 pi
= find_procinfo (pid
, 0);
2605 premptyset (&sctl
.sigset
);
2607 sctl
.sigset
= pi
->prrun
.pr_trace
;
2610 notice_signals (pi
, &sctl
);
2613 pi
->prrun
.pr_trace
= sctl
.sigset
;
2618 notice_signals (pi
, sctl
)
2619 struct procinfo
*pi
;
2620 struct sig_ctl
*sctl
;
2624 for (signo
= 0; signo
< NSIG
; signo
++)
2626 if (signal_stop_state (target_signal_from_host (signo
)) == 0 &&
2627 signal_print_state (target_signal_from_host (signo
)) == 0 &&
2628 signal_pass_state (target_signal_from_host (signo
)) == 1)
2630 prdelset (&sctl
->sigset
, signo
);
2634 praddset (&sctl
->sigset
, signo
);
2637 #ifdef PROCFS_USE_READ_WRITE
2638 sctl
->cmd
= PCSTRACE
;
2639 if (write (pi
->ctl_fd
, (char *) sctl
, sizeof (struct sig_ctl
)) < 0)
2641 if (ioctl (pi
->ctl_fd
, PIOCSTRACE
, &sctl
->sigset
))
2644 print_sys_errmsg ("PIOCSTRACE failed", errno
);
2652 proc_set_exec_trap -- arrange for exec'd child to halt at startup
2656 void proc_set_exec_trap (void)
2660 This function is called in the child process when starting up
2661 an inferior, prior to doing the exec of the actual inferior.
2662 It sets the child process's exitset to make exit from the exec
2663 system call an event of interest to stop on, and then simply
2664 returns. The child does the exec, the system call returns, and
2665 the child stops at the first instruction, ready for the gdb
2666 parent process to take control of it.
2670 We need to use all local variables since the child may be sharing
2671 it's data space with the parent, if vfork was used rather than
2674 Also note that we want to turn off the inherit-on-fork flag in
2675 the child process so that any grand-children start with all
2676 tracing flags cleared.
2680 proc_set_exec_trap ()
2682 struct sys_ctl exitset
;
2683 struct sys_ctl entryset
;
2684 char procname
[MAX_PROC_NAME_SIZE
];
2687 sprintf (procname
, CTL_PROC_NAME_FMT
, getpid ());
2689 if ((fd
= open (procname
, O_WRONLY
)) < 0)
2691 if ((fd
= open (procname
, O_RDWR
)) < 0)
2695 gdb_flush (gdb_stderr
);
2698 premptyset (&exitset
.sysset
);
2699 premptyset (&entryset
.sysset
);
2701 #ifdef PRFS_STOPEXEC
2702 /* Under Alpha OSF/1 we have to use a PIOCSSPCACT ioctl to trace
2703 exits from exec system calls because of the user level loader. */
2707 if (ioctl (fd
, PIOCGSPCACT
, &prfs_flags
) < 0)
2710 gdb_flush (gdb_stderr
);
2713 prfs_flags
|= PRFS_STOPEXEC
;
2714 if (ioctl (fd
, PIOCSSPCACT
, &prfs_flags
) < 0)
2717 gdb_flush (gdb_stderr
);
2721 #else /* PRFS_STOPEXEC */
2723 Not all systems with /proc have all the exec* syscalls with the same
2724 names. On the SGI, for example, there is no SYS_exec, but there
2725 *is* a SYS_execv. So, we try to account for that. */
2728 praddset (&exitset
.sysset
, SYS_exec
);
2731 praddset (&exitset
.sysset
, SYS_execve
);
2734 praddset (&exitset
.sysset
, SYS_execv
);
2737 #ifdef PROCFS_USE_READ_WRITE
2738 exitset
.cmd
= PCSEXIT
;
2739 if (write (fd
, (char *) &exitset
, sizeof (struct sys_ctl
)) < 0)
2741 if (ioctl (fd
, PIOCSEXIT
, &exitset
.sysset
) < 0)
2745 gdb_flush (gdb_stderr
);
2748 #endif /* PRFS_STOPEXEC */
2750 praddset (&entryset
.sysset
, SYS_exit
);
2752 #ifdef PROCFS_USE_READ_WRITE
2753 entryset
.cmd
= PCSENTRY
;
2754 if (write (fd
, (char *) &entryset
, sizeof (struct sys_ctl
)) < 0)
2756 if (ioctl (fd
, PIOCSENTRY
, &entryset
.sysset
) < 0)
2760 gdb_flush (gdb_stderr
);
2764 /* Turn off inherit-on-fork flag so that all grand-children of gdb
2765 start with tracing flags cleared. */
2767 modify_inherit_on_fork_flag (fd
, 0);
2769 /* Turn on run-on-last-close flag so that this process will not hang
2770 if GDB goes away for some reason. */
2772 modify_run_on_last_close_flag (fd
, 1);
2774 #ifndef UNIXWARE /* since this is a solaris-ism, we don't want it */
2775 /* NOTE: revisit when doing thread support for UW */
2779 struct proc_ctl pctl
;
2781 /* Solaris needs this to make procfs treat all threads seperately. Without
2782 this, all threads halt whenever something happens to any thread. Since
2783 GDB wants to control all this itself, it needs to set PR_ASYNC. */
2785 pr_flags
= PR_ASYNC
;
2786 #ifdef PROCFS_USE_READ_WRITE
2788 pctl
.data
= PR_FORK
|PR_ASYNC
;
2789 write (fd
, (char *) &pctl
, sizeof (struct proc_ctl
));
2791 ioctl (fd
, PIOCSET
, &pr_flags
);
2794 #endif /* PR_ASYNC */
2795 #endif /* !UNIXWARE */
2802 proc_iterate_over_mappings -- call function for every mapped space
2806 int proc_iterate_over_mappings (int (*func)())
2810 Given a pointer to a function, call that function for every
2811 mapped address space, passing it an open file descriptor for
2812 the file corresponding to that mapped address space (if any)
2813 and the base address of the mapped space. Quit when we hit
2814 the end of the mappings or the function returns nonzero.
2819 proc_iterate_over_mappings (func
)
2820 int (*func
) PARAMS ((int, CORE_ADDR
));
2827 struct procinfo
*pi
;
2830 pi
= current_procinfo
;
2832 if (fstat (pi
->map_fd
, &sbuf
) < 0)
2835 nmap
= sbuf
.st_size
/ sizeof (prmap_t
);
2836 prmaps
= (prmap_t
*) alloca (nmap
* sizeof(prmap_t
));
2837 if ((lseek (pi
->map_fd
, 0, SEEK_SET
) == 0) &&
2838 (read (pi
->map_fd
, (char *) prmaps
, nmap
* sizeof (prmap_t
)) ==
2839 (nmap
* sizeof (prmap_t
))))
2842 for (prmap
= prmaps
; i
< nmap
&& funcstat
== 0; ++prmap
, ++i
)
2844 char name
[sizeof ("/proc/1234567890/object") +
2845 sizeof (prmap
->pr_mapname
)];
2846 sprintf (name
, "/proc/%d/object/%s", pi
->pid
, prmap
->pr_mapname
);
2847 if ((fd
= open (name
, O_RDONLY
)) == -1)
2852 funcstat
= (*func
) (fd
, (CORE_ADDR
) prmap
->pr_vaddr
);
2858 #else /* UNIXWARE */
2860 proc_iterate_over_mappings (func
)
2861 int (*func
) PARAMS ((int, CORE_ADDR
));
2866 struct prmap
*prmaps
;
2867 struct prmap
*prmap
;
2868 struct procinfo
*pi
;
2870 pi
= current_procinfo
;
2872 if (ioctl (pi
->map_fd
, PIOCNMAP
, &nmap
) == 0)
2874 prmaps
= (struct prmap
*) alloca ((nmap
+ 1) * sizeof (*prmaps
));
2875 if (ioctl (pi
->map_fd
, PIOCMAP
, prmaps
) == 0)
2877 for (prmap
= prmaps
; prmap
-> pr_size
&& funcstat
== 0; ++prmap
)
2879 fd
= proc_address_to_fd (pi
, (CORE_ADDR
) prmap
-> pr_vaddr
, 0);
2880 funcstat
= (*func
) (fd
, (CORE_ADDR
) prmap
-> pr_vaddr
);
2887 #endif /* UNIXWARE */
2889 #if 0 /* Currently unused */
2894 proc_base_address -- find base address for segment containing address
2898 CORE_ADDR proc_base_address (CORE_ADDR addr)
2902 Given an address of a location in the inferior, find and return
2903 the base address of the mapped segment containing that address.
2905 This is used for example, by the shared library support code,
2906 where we have the pc value for some location in the shared library
2907 where we are stopped, and need to know the base address of the
2908 segment containing that address.
2912 proc_base_address (addr
)
2916 struct prmap
*prmaps
;
2917 struct prmap
*prmap
;
2918 CORE_ADDR baseaddr
= 0;
2919 struct procinfo
*pi
;
2921 pi
= current_procinfo
;
2923 if (ioctl (pi
->map_fd
, PIOCNMAP
, &nmap
) == 0)
2925 prmaps
= (struct prmap
*) alloca ((nmap
+ 1) * sizeof (*prmaps
));
2926 if (ioctl (pi
->map_fd
, PIOCMAP
, prmaps
) == 0)
2928 for (prmap
= prmaps
; prmap
-> pr_size
; ++prmap
)
2930 if ((prmap
-> pr_vaddr
<= (caddr_t
) addr
) &&
2931 (prmap
-> pr_vaddr
+ prmap
-> pr_size
> (caddr_t
) addr
))
2933 baseaddr
= (CORE_ADDR
) prmap
-> pr_vaddr
;
2949 proc_address_to_fd -- return open fd for file mapped to address
2953 int proc_address_to_fd (struct procinfo *pi, CORE_ADDR addr, complain)
2957 Given an address in the current inferior's address space, use the
2958 /proc interface to find an open file descriptor for the file that
2959 this address was mapped in from. Return -1 if there is no current
2960 inferior. Print a warning message if there is an inferior but
2961 the address corresponds to no file (IE a bogus address).
2966 proc_address_to_fd (pi
, addr
, complain
)
2967 struct procinfo
*pi
;
2973 if ((fd
= ioctl (pi
->ctl_fd
, PIOCOPENM
, (caddr_t
*) &addr
)) < 0)
2977 print_sys_errmsg (pi
->pathname
, errno
);
2978 warning ("can't find mapped file for address 0x%x", addr
);
2983 #endif /* !UNIXWARE */
2985 /* Attach to process PID, then initialize for debugging it
2986 and wait for the trace-trap that results from attaching. */
2989 procfs_attach (args
, from_tty
)
2997 error_no_arg ("process-id to attach");
3001 if (pid
== getpid()) /* Trying to masturbate? */
3002 error ("I refuse to debug myself!");
3006 exec_file
= (char *) get_exec_file (0);
3009 printf_unfiltered ("Attaching to program `%s', %s\n", exec_file
, target_pid_to_str (pid
));
3011 printf_unfiltered ("Attaching to %s\n", target_pid_to_str (pid
));
3013 gdb_flush (gdb_stdout
);
3016 inferior_pid
= pid
= do_attach (pid
);
3017 push_target (&procfs_ops
);
3021 /* Take a program previously attached to and detaches it.
3022 The program resumes execution and will no longer stop
3023 on signals, etc. We'd better not have left any breakpoints
3024 in the program or it'll die when it hits one. For this
3025 to work, it may be necessary for the process to have been
3026 previously attached. It *might* work if the program was
3027 started via the normal ptrace (PTRACE_TRACEME). */
3030 procfs_detach (args
, from_tty
)
3038 char *exec_file
= get_exec_file (0);
3041 printf_unfiltered ("Detaching from program: %s %s\n",
3042 exec_file
, target_pid_to_str (inferior_pid
));
3043 gdb_flush (gdb_stdout
);
3046 siggnal
= atoi (args
);
3048 do_detach (siggnal
);
3050 unpush_target (&procfs_ops
); /* Pop out of handling an inferior */
3053 /* Get ready to modify the registers array. On machines which store
3054 individual registers, this doesn't need to do anything. On machines
3055 which store all the registers in one fell swoop, this makes sure
3056 that registers contains all the registers from the program being
3060 procfs_prepare_to_store ()
3062 #ifdef CHILD_PREPARE_TO_STORE
3063 CHILD_PREPARE_TO_STORE ();
3067 /* Print status information about what we're accessing. */
3070 procfs_files_info (ignore
)
3071 struct target_ops
*ignore
;
3073 printf_unfiltered ("\tUsing the running image of %s %s via /proc.\n",
3074 attach_flag
? "attached": "child", target_pid_to_str (inferior_pid
));
3079 procfs_open (arg
, from_tty
)
3083 error ("Use the \"run\" command to start a Unix child process.");
3090 do_attach -- attach to an already existing process
3094 int do_attach (int pid)
3098 Attach to an already existing process with the specified process
3099 id. If the process is not already stopped, query whether to
3104 The option of stopping at attach time is specific to the /proc
3105 versions of gdb. Versions using ptrace force the attachee
3106 to stop. (I have changed this version to do so, too. All you
3107 have to do is "continue" to make it go on. -- gnu@cygnus.com)
3115 struct procinfo
*pi
;
3116 struct sig_ctl sctl
;
3117 struct flt_ctl fctl
;
3120 pi
= init_procinfo (pid
, 0);
3123 nlwp
= pi
->prstatus
.pr_nlwp
;
3124 lwps
= alloca ((2 * nlwp
+ 2) * sizeof (id_t
));
3126 if (ioctl (pi
->ctl_fd
, PIOCLWPIDS
, lwps
))
3128 print_sys_errmsg (pi
-> pathname
, errno
);
3129 error ("PIOCLWPIDS failed");
3131 #else /* PIOCLWPIDS */
3133 lwps
= alloca ((2 * nlwp
+ 2) * sizeof *lwps
);
3136 for (; nlwp
> 0; nlwp
--, lwps
++)
3138 /* First one has already been created above. */
3139 if ((pi
= find_procinfo ((*lwps
<< 16) | pid
, 1)) == 0)
3140 pi
= init_procinfo ((*lwps
<< 16) | pid
, 0);
3143 if (pi
->prstatus
.pr_lwp
.pr_flags
& (PR_STOPPED
| PR_ISTOP
))
3145 if (pi
->prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
))
3148 pi
->was_stopped
= 1;
3152 pi
->was_stopped
= 0;
3153 if (1 || query ("Process is currently running, stop it? "))
3156 /* Make it run again when we close it. */
3157 modify_run_on_last_close_flag (pi
->ctl_fd
, 1);
3158 #ifdef PROCFS_USE_READ_WRITE
3160 if (write (pi
->ctl_fd
, (char *) &cmd
, sizeof (long)) < 0)
3162 if (ioctl (pi
->ctl_fd
, PIOCSTOP
, &pi
->prstatus
) < 0)
3165 print_sys_errmsg (pi
->pathname
, errno
);
3166 close_proc_file (pi
);
3167 error ("PIOCSTOP failed");
3170 if (!procfs_read_status (pi
))
3172 print_sys_errmsg (pi
->pathname
, errno
);
3173 close_proc_file (pi
);
3174 error ("procfs_read_status failed");
3177 pi
->nopass_next_sigstop
= 1;
3181 printf_unfiltered ("Ok, gdb will wait for %s to stop.\n",
3182 target_pid_to_str (pi
->pid
));
3186 #ifdef PROCFS_USE_READ_WRITE
3187 fctl
.cmd
= PCSFAULT
;
3188 if (write (pi
->ctl_fd
, (char *) &fctl
, sizeof (struct flt_ctl
)) < 0)
3189 print_sys_errmsg ("PCSFAULT failed", errno
);
3190 #else /* PROCFS_USE_READ_WRITE */
3191 if (ioctl (pi
->ctl_fd
, PIOCSFAULT
, &pi
->prrun
.pr_fault
))
3193 print_sys_errmsg ("PIOCSFAULT failed", errno
);
3195 if (ioctl (pi
->ctl_fd
, PIOCSTRACE
, &pi
->prrun
.pr_trace
))
3197 print_sys_errmsg ("PIOCSTRACE failed", errno
);
3199 add_thread (pi
->pid
);
3200 procfs_set_inferior_syscall_traps (pi
);
3201 #endif /* PROCFS_USE_READ_WRITE */
3211 do_detach -- detach from an attached-to process
3215 void do_detach (int signal)
3219 Detach from the current attachee.
3221 If signal is non-zero, the attachee is started running again and sent
3222 the specified signal.
3224 If signal is zero and the attachee was not already stopped when we
3225 attached to it, then we make it runnable again when we detach.
3227 Otherwise, we query whether or not to make the attachee runnable
3228 again, since we may simply want to leave it in the state it was in
3231 We report any problems, but do not consider them errors, since we
3232 MUST detach even if some things don't seem to go right. This may not
3233 be the ideal situation. (FIXME).
3240 struct procinfo
*pi
;
3242 for (pi
= procinfo_list
; pi
; pi
= pi
->next
)
3246 set_proc_siginfo (pi
, signal
);
3248 #ifdef PROCFS_USE_READ_WRITE
3249 pi
->saved_exitset
.cmd
= PCSEXIT
;
3250 if (write (pi
->ctl_fd
, (char *) &pi
->saved_exitset
,
3251 sizeof (struct sys_ctl
)) < 0)
3253 if (ioctl (pi
->ctl_fd
, PIOCSEXIT
, &pi
->saved_exitset
.sysset
) < 0)
3256 print_sys_errmsg (pi
->pathname
, errno
);
3257 printf_unfiltered ("PIOCSEXIT failed.\n");
3259 #ifdef PROCFS_USE_READ_WRITE
3260 pi
->saved_entryset
.cmd
= PCSENTRY
;
3261 if (write (pi
->ctl_fd
, (char *) &pi
->saved_entryset
,
3262 sizeof (struct sys_ctl
)) < 0)
3264 if (ioctl (pi
->ctl_fd
, PIOCSENTRY
, &pi
->saved_entryset
.sysset
) < 0)
3267 print_sys_errmsg (pi
->pathname
, errno
);
3268 printf_unfiltered ("PIOCSENTRY failed.\n");
3270 #ifdef PROCFS_USE_READ_WRITE
3271 pi
->saved_trace
.cmd
= PCSTRACE
;
3272 if (write (pi
->ctl_fd
, (char *) &pi
->saved_trace
,
3273 sizeof (struct sig_ctl
)) < 0)
3275 if (ioctl (pi
->ctl_fd
, PIOCSTRACE
, &pi
->saved_trace
.sigset
) < 0)
3278 print_sys_errmsg (pi
->pathname
, errno
);
3279 printf_unfiltered ("PIOCSTRACE failed.\n");
3282 if (ioctl (pi
->ctl_fd
, PIOCSHOLD
, &pi
->saved_sighold
.sigset
) < 0)
3284 print_sys_errmsg (pi
->pathname
, errno
);
3285 printf_unfiltered ("PIOSCHOLD failed.\n");
3288 #ifdef PROCFS_USE_READ_WRITE
3289 pi
->saved_fltset
.cmd
= PCSFAULT
;
3290 if (write (pi
->ctl_fd
, (char *) &pi
->saved_fltset
,
3291 sizeof (struct flt_ctl
)) < 0)
3293 if (ioctl (pi
->ctl_fd
, PIOCSFAULT
, &pi
->saved_fltset
.fltset
) < 0)
3296 print_sys_errmsg (pi
->pathname
, errno
);
3297 printf_unfiltered ("PIOCSFAULT failed.\n");
3299 if (!procfs_read_status (pi
))
3301 print_sys_errmsg (pi
->pathname
, errno
);
3302 printf_unfiltered ("procfs_read_status failed.\n");
3307 if (signal
|| (pi
->prstatus
.pr_lwp
.pr_flags
& (PR_STOPPED
| PR_ISTOP
)))
3309 if (signal
|| (pi
->prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
)))
3313 struct proc_ctl pctl
;
3315 if (signal
|| !pi
->was_stopped
||
3316 query ("Was stopped when attached, make it runnable again? "))
3318 /* Clear any pending signal if we want to detach without
3321 set_proc_siginfo (pi
, signal
);
3323 /* Clear any fault that might have stopped it. */
3324 #ifdef PROCFS_USE_READ_WRITE
3326 if (write (pi
->ctl_fd
, (char *) &cmd
, sizeof (long)) < 0)
3328 if (ioctl (pi
->ctl_fd
, PIOCCFAULT
, 0))
3331 print_sys_errmsg (pi
->pathname
, errno
);
3332 printf_unfiltered ("PIOCCFAULT failed.\n");
3335 /* Make it run again when we close it. */
3337 modify_run_on_last_close_flag (pi
->ctl_fd
, 1);
3341 close_proc_file (pi
);
3346 /* emulate wait() as much as possible.
3347 Wait for child to do something. Return pid of child, or -1 in case
3348 of error; store status in *OURSTATUS.
3350 Not sure why we can't
3351 just use wait(), but it seems to have problems when applied to a
3352 process being controlled with the /proc interface.
3354 We have a race problem here with no obvious solution. We need to let
3355 the inferior run until it stops on an event of interest, which means
3356 that we need to use the PIOCWSTOP ioctl. However, we cannot use this
3357 ioctl if the process is already stopped on something that is not an
3358 event of interest, or the call will hang indefinitely. Thus we first
3359 use PIOCSTATUS to see if the process is not stopped. If not, then we
3360 use PIOCWSTOP. But during the window between the two, if the process
3361 stops for any reason that is not an event of interest (such as a job
3362 control signal) then gdb will hang. One possible workaround is to set
3363 an alarm to wake up every minute of so and check to see if the process
3364 is still running, and if so, then reissue the PIOCWSTOP. But this is
3365 a real kludge, so has not been implemented. FIXME: investigate
3368 FIXME: Investigate why wait() seems to have problems with programs
3369 being control by /proc routines. */
3371 procfs_wait (pid
, ourstatus
)
3373 struct target_waitstatus
*ourstatus
;
3380 struct procinfo
*pi
;
3381 struct proc_ctl pctl
;
3385 /* handle all syscall events first, otherwise we might not
3386 notice a thread was created until too late. */
3388 for (pi
= procinfo_list
; pi
; pi
= pi
->next
)
3394 if (! (pi
->prstatus
.pr_lwp
.pr_flags
& (PR_STOPPED
| PR_ISTOP
)) )
3397 why
= pi
->prstatus
.pr_lwp
.pr_why
;
3398 what
= pi
->prstatus
.pr_lwp
.pr_what
;
3400 if (! (pi
->prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
)) )
3403 why
= pi
->prstatus
.pr_why
;
3404 what
= pi
->prstatus
.pr_what
;
3406 if (why
== PR_SYSENTRY
|| why
== PR_SYSEXIT
)
3409 int found_handler
= 0;
3411 for (i
= 0; i
< pi
->num_syscall_handlers
; i
++)
3412 if (pi
->syscall_handlers
[i
].syscall_num
== what
)
3415 pi
->saved_rtnval
= pi
->pid
;
3416 pi
->saved_statval
= 0;
3417 if (!pi
->syscall_handlers
[i
].func
3418 (pi
, what
, why
, &pi
->saved_rtnval
, &pi
->saved_statval
))
3425 if (why
== PR_SYSENTRY
)
3426 error ("PR_SYSENTRY, unhandled system call %d", what
);
3428 error ("PR_SYSEXIT, unhandled system call %d", what
);
3433 /* find a relevant process with an event */
3435 for (pi
= procinfo_list
; pi
; pi
= pi
->next
)
3436 if (pi
->had_event
&& (pid
== -1 || pi
->pid
== pid
))
3446 if (!checkerr
&& !(pi
->prstatus
.pr_lwp
.pr_flags
& (PR_STOPPED
| PR_ISTOP
)))
3448 if (!checkerr
&& !(pi
->prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
)))
3451 if (!procfs_write_pcwstop (pi
))
3458 if (errno
== ENOENT
)
3460 /* XXX Fixme -- what to do if attached? Can't call wait... */
3461 rtnval
= wait (&statval
);
3462 if ((rtnval
) != (PIDGET (inferior_pid
)))
3464 print_sys_errmsg (pi
->pathname
, errno
);
3465 error ("procfs_wait: wait failed, returned %d", rtnval
);
3471 print_sys_errmsg (pi
->pathname
, errno
);
3472 error ("PIOCSTATUS or PIOCWSTOP failed.");
3477 else if (pi
->prstatus
.pr_lwp
.pr_flags
& (PR_STOPPED
| PR_ISTOP
))
3479 else if (pi
->prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
))
3483 rtnval
= pi
->prstatus
.pr_pid
;
3484 why
= pi
->prstatus
.pr_lwp
.pr_why
;
3485 what
= pi
->prstatus
.pr_lwp
.pr_what
;
3488 why
= pi
->prstatus
.pr_why
;
3489 what
= pi
->prstatus
.pr_what
;
3495 statval
= (what
<< 8) | 0177;
3499 rtnval
= pi
->saved_rtnval
;
3500 statval
= pi
->saved_statval
;
3503 statval
= (SIGSTOP
<< 8) | 0177;
3506 statval
= (what
<< 8) | 0177;
3513 statval
= (SIGTRAP
<< 8) | 0177;
3518 statval
= (SIGTRAP
<< 8) | 0177;
3521 #ifndef FAULTED_USE_SIGINFO
3522 /* Irix, contrary to the documentation, fills in 0 for si_signo.
3523 Solaris fills in si_signo. I'm not sure about others. */
3526 statval
= (SIGILL
<< 8) | 0177;
3530 statval
= (SIGTRAP
<< 8) | 0177;
3535 statval
= (SIGSEGV
<< 8) | 0177;
3540 statval
= (SIGFPE
<< 8) | 0177;
3542 case FLTPAGE
: /* Recoverable page fault */
3543 #endif /* not FAULTED_USE_SIGINFO */
3545 /* Use the signal which the kernel assigns. This is better than
3546 trying to second-guess it from the fault. In fact, I suspect
3547 that FLTACCESS can be either SIGSEGV or SIGBUS. */
3549 statval
= ((pi
->prstatus
.pr_lwp
.pr_info
.si_signo
) << 8) | 0177;
3551 statval
= ((pi
->prstatus
.pr_info
.si_signo
) << 8) | 0177;
3557 error ("PIOCWSTOP, unknown why %d, what %d", why
, what
);
3559 /* Stop all the other threads when any of them stops. */
3562 struct procinfo
*procinfo
, *next_pi
;
3564 for (procinfo
= procinfo_list
; procinfo
; procinfo
= next_pi
)
3566 next_pi
= procinfo
->next
;
3567 if (!procinfo
->had_event
)
3569 #ifdef PROCFS_USE_READ_WRITE
3571 if (write (pi
->ctl_fd
, (char *) &cmd
, sizeof (long)) < 0)
3573 print_sys_errmsg (procinfo
->pathname
, errno
);
3574 error ("PCSTOP failed");
3577 /* A bug in Solaris (2.5) causes us to hang when trying to
3578 stop a stopped process. So, we have to check first in
3579 order to avoid the hang. */
3580 if (!procfs_read_status (procinfo
))
3582 /* The LWP has apparently terminated. */
3584 printf_filtered ("LWP %d doesn't respond.\n",
3585 (procinfo
->pid
>> 16) & 0xffff);
3586 close_proc_file (procinfo
);
3590 if (!(procinfo
->prstatus
.pr_flags
& PR_STOPPED
))
3591 if (ioctl (procinfo
->ctl_fd
, PIOCSTOP
, &procinfo
->prstatus
)
3594 print_sys_errmsg (procinfo
->pathname
, errno
);
3595 warning ("PIOCSTOP failed");
3604 error ("PIOCWSTOP, stopped for unknown/unhandled reason, flags %#x",
3606 pi
->prstatus
.pr_lwp
.pr_flags
);
3608 pi
->prstatus
.pr_flags
);
3612 store_waitstatus (ourstatus
, statval
);
3614 if (rtnval
== -1) /* No more children to wait for */
3616 warning ("Child process unexpectedly missing");
3617 /* Claim it exited with unknown signal. */
3618 ourstatus
->kind
= TARGET_WAITKIND_SIGNALLED
;
3619 ourstatus
->value
.sig
= TARGET_SIGNAL_UNKNOWN
;
3623 pi
->had_event
= 0; /* Indicate that we've seen this one */
3631 set_proc_siginfo - set a process's current signal info
3635 void set_proc_siginfo (struct procinfo *pip, int signo);
3639 Given a pointer to a process info struct in PIP and a signal number
3640 in SIGNO, set the process's current signal and its associated signal
3641 information. The signal will be delivered to the process immediately
3642 after execution is resumed, even if it is being held. In addition,
3643 this particular delivery will not cause another PR_SIGNALLED stop
3644 even if the signal is being traced.
3646 If we are not delivering the same signal that the prstatus siginfo
3647 struct contains information about, then synthesize a siginfo struct
3648 to match the signal we are doing to deliver, make it of the type
3649 "generated by a user process", and send this synthesized copy. When
3650 used to set the inferior's signal state, this will be required if we
3651 are not currently stopped because of a traced signal, or if we decide
3652 to continue with a different signal.
3654 Note that when continuing the inferior from a stop due to receipt
3655 of a traced signal, we either have set PRCSIG to clear the existing
3656 signal, or we have to call this function to do a PIOCSSIG with either
3657 the existing siginfo struct from pr_info, or one we have synthesized
3658 appropriately for the signal we want to deliver. Otherwise if the
3659 signal is still being traced, the inferior will immediately stop
3662 See siginfo(5) for more details.
3666 set_proc_siginfo (pip
, signo
)
3667 struct procinfo
*pip
;
3670 struct siginfo newsiginfo
;
3671 struct siginfo
*sip
;
3672 struct sigi_ctl sictl
;
3674 #ifdef PROCFS_DONT_PIOCSSIG_CURSIG
3675 /* With Alpha OSF/1 procfs, the kernel gets really confused if it
3676 receives a PIOCSSIG with a signal identical to the current signal,
3677 it messes up the current signal. Work around the kernel bug. */
3679 if (signo
== pip
-> prstatus
.pr_lwp
.pr_cursig
)
3681 if (signo
== pip
-> prstatus
.pr_cursig
)
3687 if (signo
== pip
->prstatus
.pr_lwp
.pr_info
.si_signo
)
3689 memcpy ((char *) &sictl
.siginfo
, (char *) &pip
->prstatus
.pr_lwp
.pr_info
,
3690 sizeof (siginfo_t
));
3693 if (signo
== pip
-> prstatus
.pr_info
.si_signo
)
3695 sip
= &pip
-> prstatus
.pr_info
;
3701 siginfo_t
*sip
= &sictl
.siginfo
;
3702 memset ((char *) sip
, 0, sizeof (siginfo_t
));
3704 memset ((char *) &newsiginfo
, 0, sizeof (newsiginfo
));
3707 sip
-> si_signo
= signo
;
3709 sip
-> si_errno
= 0;
3710 sip
-> si_pid
= getpid ();
3711 sip
-> si_uid
= getuid ();
3713 #ifdef PROCFS_USE_READ_WRITE
3715 if (write (pip
->ctl_fd
, (char *) &sictl
, sizeof (struct sigi_ctl
)) < 0)
3717 if (ioctl (pip
->ctl_fd
, PIOCSSIG
, sip
) < 0)
3720 print_sys_errmsg (pip
-> pathname
, errno
);
3721 warning ("PIOCSSIG failed");
3725 /* Resume execution of process PID. If STEP is nozero, then
3726 just single step it. If SIGNAL is nonzero, restart it with that
3727 signal activated. */
3730 procfs_resume (pid
, step
, signo
)
3733 enum target_signal signo
;
3736 struct procinfo
*pi
, *procinfo
, *next_pi
;
3737 struct proc_ctl pctl
;
3739 pi
= find_procinfo (pid
== -1 ? inferior_pid
: pid
, 0);
3744 pctl
.data
= PRCFAULT
;
3746 pi
->prrun
.pr_flags
= PRSTRACE
| PRSFAULT
| PRCFAULT
;
3750 /* It should not be necessary. If the user explicitly changes the value,
3751 value_assign calls write_register_bytes, which writes it. */
3752 /* It may not be absolutely necessary to specify the PC value for
3753 restarting, but to be safe we use the value that gdb considers
3754 to be current. One case where this might be necessary is if the
3755 user explicitly changes the PC value that gdb considers to be
3756 current. FIXME: Investigate if this is necessary or not. */
3758 #ifdef PRSVADDR_BROKEN
3759 /* Can't do this under Solaris running on a Sparc, as there seems to be no
3760 place to put nPC. In fact, if you use this, nPC seems to be set to some
3761 random garbage. We have to rely on the fact that PC and nPC have been
3762 written previously via PIOCSREG during a register flush. */
3764 pi
->prrun
.pr_vaddr
= (caddr_t
) *(int *) ®isters
[REGISTER_BYTE (PC_REGNUM
)];
3765 pi
->prrun
.pr_flags
!= PRSVADDR
;
3769 if (signo
== TARGET_SIGNAL_STOP
&& pi
->nopass_next_sigstop
)
3770 /* When attaching to a child process, if we forced it to stop with
3771 a PIOCSTOP, then we will have set the nopass_next_sigstop flag.
3772 Upon resuming the first time after such a stop, we explicitly
3773 inhibit sending it another SIGSTOP, which would be the normal
3774 result of default signal handling. One potential drawback to
3775 this is that we will also ignore any attempt to by the user
3776 to explicitly continue after the attach with a SIGSTOP. Ultimately
3777 this problem should be dealt with by making the routines that
3778 deal with the inferior a little smarter, and possibly even allow
3779 an inferior to continue running at the same time as gdb. (FIXME?) */
3781 else if (signo
== TARGET_SIGNAL_TSTP
3783 && pi
->prstatus
.pr_lwp
.pr_cursig
== SIGTSTP
3784 && pi
->prstatus
.pr_lwp
.pr_action
.sa_handler
== SIG_DFL
3786 && pi
->prstatus
.pr_cursig
== SIGTSTP
3787 && pi
->prstatus
.pr_action
.sa_handler
== SIG_DFL
3791 /* We are about to pass the inferior a SIGTSTP whose action is
3792 SIG_DFL. The SIG_DFL action for a SIGTSTP is to stop
3793 (notifying the parent via wait()), and then keep going from the
3794 same place when the parent is ready for you to keep going. So
3795 under the debugger, it should do nothing (as if the program had
3796 been stopped and then later resumed. Under ptrace, this
3797 happens for us, but under /proc, the system obligingly stops
3798 the process, and wait_for_inferior would have no way of
3799 distinguishing that type of stop (which indicates that we
3800 should just start it again), with a stop due to the pr_trace
3801 field of the prrun_t struct.
3803 Note that if the SIGTSTP is being caught, we *do* need to pass it,
3804 because the handler needs to get executed. */
3807 signal_to_pass
= target_signal_to_host (signo
);
3811 set_proc_siginfo (pi
, signal_to_pass
);
3816 pctl
.data
|= PRCSIG
;
3818 pi
->prrun
.pr_flags
|= PRCSIG
;
3821 pi
->nopass_next_sigstop
= 0;
3825 pctl
.data
|= PRSTEP
;
3827 pi
->prrun
.pr_flags
|= PRSTEP
;
3831 /* Don't try to start a process unless it's stopped on an
3832 `event of interest'. Doing so will cause errors. */
3834 if (!procfs_read_status (pi
))
3836 /* The LWP has apparently terminated. */
3838 printf_filtered ("LWP %d doesn't respond.\n",
3839 (pi
->pid
>> 16) & 0xffff);
3840 close_proc_file (pi
);
3844 #ifdef PROCFS_USE_READ_WRITE
3845 if (write (pi
->ctl_fd
, (char *) &pctl
, sizeof (struct proc_ctl
)) < 0)
3847 if ((pi
->prstatus
.pr_flags
& PR_ISTOP
)
3848 && ioctl (pi
->ctl_fd
, PIOCRUN
, &pi
->prrun
) != 0)
3851 /* The LWP has apparently terminated. */
3853 printf_filtered ("LWP %d doesn't respond.\n",
3854 (pi
->pid
>> 16) & 0xffff);
3855 close_proc_file (pi
);
3859 /* Continue all the other threads that haven't had an event of interest.
3860 Also continue them if they have NOPASS_NEXT_SIGSTOP set; this is only
3861 set by do_attach, and means this is the first resume after an attach.
3862 All threads were CSTOP'd by do_attach, and should be resumed now. */
3865 for (procinfo
= procinfo_list
; procinfo
; procinfo
= next_pi
)
3867 next_pi
= procinfo
->next
;
3869 if (!procinfo
->had_event
||
3870 (procinfo
->nopass_next_sigstop
&& signo
== TARGET_SIGNAL_STOP
))
3872 procinfo
->had_event
= procinfo
->nopass_next_sigstop
= 0;
3873 #ifdef PROCFS_USE_READ_WRITE
3874 pctl
.data
= PRCFAULT
| PRCSIG
;
3875 if (write (procinfo
->ctl_fd
, (char *) &pctl
,
3876 sizeof (struct proc_ctl
)) < 0)
3878 if (!procfs_read_status (procinfo
))
3879 fprintf_unfiltered(gdb_stderr
,
3880 "procfs_read_status failed, errno=%d\n",
3882 print_sys_errmsg (procinfo
->pathname
, errno
);
3883 error ("PCRUN failed");
3886 procinfo
->prrun
.pr_flags
&= PRSTEP
;
3887 procinfo
->prrun
.pr_flags
|= PRCFAULT
| PRCSIG
;
3888 if (!procfs_read_status (procinfo
))
3890 /* The LWP has apparently terminated. */
3892 printf_filtered ("LWP %d doesn't respond.\n",
3893 (procinfo
->pid
>> 16) & 0xffff);
3894 close_proc_file (procinfo
);
3898 /* Don't try to start a process unless it's stopped on an
3899 `event of interest'. Doing so will cause errors. */
3901 if ((procinfo
->prstatus
.pr_flags
& PR_ISTOP
)
3902 && ioctl (procinfo
->ctl_fd
, PIOCRUN
, &procinfo
->prrun
) < 0)
3904 if (!procfs_read_status (procinfo
))
3905 fprintf_unfiltered(gdb_stderr
,
3906 "procfs_read_status failed, errno=%d\n",
3908 print_sys_errmsg (procinfo
->pathname
, errno
);
3909 warning ("PIOCRUN failed");
3913 procfs_read_status (procinfo
);
3921 procfs_fetch_registers -- fetch current registers from inferior
3925 void procfs_fetch_registers (int regno)
3929 Read the current values of the inferior's registers, both the
3930 general register set and floating point registers (if supported)
3931 and update gdb's idea of their current values.
3936 procfs_fetch_registers (regno
)
3939 struct procinfo
*pi
;
3941 pi
= current_procinfo
;
3944 if (procfs_read_status (pi
))
3946 supply_gregset (&pi
->prstatus
.pr_lwp
.pr_context
.uc_mcontext
.gregs
);
3947 #if defined (FP0_REGNUM)
3948 supply_fpregset (&pi
->prstatus
.pr_lwp
.pr_context
.uc_mcontext
.fpregs
);
3951 #else /* UNIXWARE */
3952 if (ioctl (pi
->ctl_fd
, PIOCGREG
, &pi
->gregset
.gregset
) != -1)
3954 supply_gregset (&pi
->gregset
.gregset
);
3956 #if defined (FP0_REGNUM)
3957 if (ioctl (pi
->ctl_fd
, PIOCGFPREG
, &pi
->fpregset
.fpregset
) != -1)
3959 supply_fpregset (&pi
->fpregset
.fpregset
);
3962 #endif /* UNIXWARE */
3969 proc_init_failed - called when /proc access initialization fails
3974 static void proc_init_failed (struct procinfo *pi,
3975 char *why, int kill_p)
3979 This function is called whenever initialization of access to a /proc
3980 entry fails. It prints a suitable error message, does some cleanup,
3981 and then invokes the standard error processing routine which dumps
3982 us back into the command loop. If KILL_P is true, sends SIGKILL.
3986 proc_init_failed (pi
, why
, kill_p
)
3987 struct procinfo
*pi
;
3991 print_sys_errmsg (pi
->pathname
, errno
);
3993 kill (pi
->pid
, SIGKILL
);
3994 close_proc_file (pi
);
4003 close_proc_file - close any currently open /proc entry
4007 static void close_proc_file (struct procinfo *pip)
4011 Close any currently open /proc entry and mark the process information
4012 entry as invalid. In order to ensure that we don't try to reuse any
4013 stale information, the pid, fd, and pathnames are explicitly
4014 invalidated, which may be overkill.
4019 close_proc_file (pip
)
4020 struct procinfo
*pip
;
4022 struct procinfo
*procinfo
;
4024 delete_thread (pip
->pid
); /* remove thread from GDB's thread list */
4025 remove_fd (pip
); /* Remove fd from poll/select list */
4027 close (pip
->ctl_fd
);
4028 #ifdef HAVE_MULTIPLE_PROC_FDS
4030 close (pip
->status_fd
);
4031 close (pip
->map_fd
);
4034 free (pip
-> pathname
);
4036 /* Unlink pip from the procinfo chain. Note pip might not be on the list. */
4038 if (procinfo_list
== pip
)
4039 procinfo_list
= pip
->next
;
4042 for (procinfo
= procinfo_list
; procinfo
; procinfo
= procinfo
->next
)
4044 if (procinfo
->next
== pip
)
4046 procinfo
->next
= pip
->next
;
4058 open_proc_file - open a /proc entry for a given process id
4062 static int open_proc_file (int pid, struct procinfo *pip, int mode)
4066 Given a process id and a mode, close the existing open /proc
4067 entry (if any) and open one for the new process id, in the
4068 specified mode. Once it is open, then mark the local process
4069 information structure as valid, which guarantees that the pid,
4070 fd, and pathname fields match an open /proc entry. Returns
4071 zero if the open fails, nonzero otherwise.
4073 Note that the pathname is left intact, even when the open fails,
4074 so that callers can use it to construct meaningful error messages
4075 rather than just "file open failed".
4077 Note that for Solaris, the process-id also includes an LWP-id, so we
4078 actually attempt to open that. If we are handed a pid with a 0 LWP-id,
4079 then we will ask the kernel what it is and add it to the pid. Hence,
4080 the pid can be changed by us.
4084 open_proc_file (pid
, pip
, mode
, control
)
4086 struct procinfo
*pip
;
4093 pip
-> had_event
= 0;
4094 pip
-> pathname
= xmalloc (MAX_PROC_NAME_SIZE
);
4103 #ifdef HAVE_MULTIPLE_PROC_FDS
4104 sprintf (pip
->pathname
, STATUS_PROC_NAME_FMT
, tmp
);
4105 if ((pip
->status_fd
= open (pip
->pathname
, O_RDONLY
)) < 0)
4110 sprintf (pip
->pathname
, AS_PROC_NAME_FMT
, tmp
);
4111 if ((pip
->as_fd
= open (pip
->pathname
, O_RDWR
)) < 0)
4113 close (pip
->status_fd
);
4117 sprintf (pip
->pathname
, MAP_PROC_NAME_FMT
, tmp
);
4118 if ((pip
->map_fd
= open (pip
->pathname
, O_RDONLY
)) < 0)
4120 close (pip
->status_fd
);
4125 sprintf (pip
->pathname
, MAP_PROC_NAME_FMT
, tmp
);
4126 if ((pip
->map_fd
= open (pip
->pathname
, O_RDONLY
)) < 0)
4128 close (pip
->status_fd
);
4135 sprintf (pip
->pathname
, CTL_PROC_NAME_FMT
, tmp
);
4136 if ((pip
->ctl_fd
= open (pip
->pathname
, O_WRONLY
)) < 0)
4138 close (pip
->status_fd
);
4140 close (pip
->map_fd
);
4145 #else /* HAVE_MULTIPLE_PROC_FDS */
4146 sprintf (pip
-> pathname
, CTL_PROC_NAME_FMT
, tmp
);
4148 if ((tmpfd
= open (pip
-> pathname
, mode
)) < 0)
4152 pip
-> ctl_fd
= tmpfd
;
4153 pip
-> as_fd
= tmpfd
;
4154 pip
-> map_fd
= tmpfd
;
4155 pip
-> status_fd
= tmpfd
;
4157 tmp
= (pid
>> 16) & 0xffff; /* Extract thread id */
4160 { /* Don't know thread id yet */
4161 if (ioctl (tmpfd
, PIOCSTATUS
, &pip
-> prstatus
) < 0)
4163 print_sys_errmsg (pip
-> pathname
, errno
);
4165 error ("open_proc_file: PIOCSTATUS failed");
4168 tmp
= pip
-> prstatus
.pr_who
; /* Get thread id from prstatus_t */
4169 pip
-> pid
= (tmp
<< 16) | pid
; /* Update pip */
4172 if ((pip
-> ctl_fd
= ioctl (tmpfd
, PIOCOPENLWP
, &tmp
)) < 0)
4178 #ifdef PIOCSET /* New method */
4181 pr_flags
= PR_ASYNC
;
4182 ioctl (pip
-> ctl_fd
, PIOCSET
, &pr_flags
);
4186 /* keep extra fds in sync */
4187 pip
->as_fd
= pip
->ctl_fd
;
4188 pip
->map_fd
= pip
->ctl_fd
;
4189 pip
->status_fd
= pip
->ctl_fd
;
4191 close (tmpfd
); /* All done with main pid */
4192 #endif /* PIOCOPENLWP */
4194 #endif /* HAVE_MULTIPLE_PROC_FDS */
4200 mappingflags (flags
)
4203 static char asciiflags
[8];
4205 strcpy (asciiflags
, "-------");
4206 #if defined (MA_PHYS)
4207 if (flags
& MA_PHYS
) asciiflags
[0] = 'd';
4209 if (flags
& MA_STACK
) asciiflags
[1] = 's';
4210 if (flags
& MA_BREAK
) asciiflags
[2] = 'b';
4211 if (flags
& MA_SHARED
) asciiflags
[3] = 's';
4212 if (flags
& MA_READ
) asciiflags
[4] = 'r';
4213 if (flags
& MA_WRITE
) asciiflags
[5] = 'w';
4214 if (flags
& MA_EXEC
) asciiflags
[6] = 'x';
4215 return (asciiflags
);
4219 info_proc_flags (pip
, summary
)
4220 struct procinfo
*pip
;
4223 struct trans
*transp
;
4225 long flags
= pip
->prstatus
.pr_flags
| pip
->prstatus
.pr_lwp
.pr_flags
;
4227 long flags
= pip
->prstatus
.pr_flags
;
4230 printf_filtered ("%-32s", "Process status flags:");
4233 printf_filtered ("\n\n");
4235 for (transp
= pr_flag_table
; transp
-> name
!= NULL
; transp
++)
4237 if (flags
& transp
-> value
)
4241 printf_filtered ("%s ", transp
-> name
);
4245 printf_filtered ("\t%-16s %s.\n", transp
-> name
, transp
-> desc
);
4249 printf_filtered ("\n");
4253 info_proc_stop (pip
, summary
)
4254 struct procinfo
*pip
;
4257 struct trans
*transp
;
4262 why
= pip
-> prstatus
.pr_lwp
.pr_why
;
4263 what
= pip
-> prstatus
.pr_lwp
.pr_what
;
4265 why
= pip
-> prstatus
.pr_why
;
4266 what
= pip
-> prstatus
.pr_what
;
4270 if (pip
-> prstatus
.pr_lwp
.pr_flags
& PR_STOPPED
)
4272 if (pip
-> prstatus
.pr_flags
& PR_STOPPED
)
4275 printf_filtered ("%-32s", "Reason for stopping:");
4278 printf_filtered ("\n\n");
4280 for (transp
= pr_why_table
; transp
-> name
!= NULL
; transp
++)
4282 if (why
== transp
-> value
)
4286 printf_filtered ("%s ", transp
-> name
);
4290 printf_filtered ("\t%-16s %s.\n",
4291 transp
-> name
, transp
-> desc
);
4297 /* Use the pr_why field to determine what the pr_what field means, and
4298 print more information. */
4303 /* pr_what is unused for this case */
4309 printf_filtered ("%s ", signalname (what
));
4313 printf_filtered ("\t%-16s %s.\n", signalname (what
),
4314 safe_strsignal (what
));
4320 printf_filtered ("%s ", syscallname (what
));
4324 printf_filtered ("\t%-16s %s.\n", syscallname (what
),
4325 "Entered this system call");
4331 printf_filtered ("%s ", syscallname (what
));
4335 printf_filtered ("\t%-16s %s.\n", syscallname (what
),
4336 "Returned from this system call");
4342 printf_filtered ("%s ",
4343 lookupname (faults_table
, what
, "fault"));
4347 printf_filtered ("\t%-16s %s.\n",
4348 lookupname (faults_table
, what
, "fault"),
4349 lookupdesc (faults_table
, what
));
4353 printf_filtered ("\n");
4358 info_proc_siginfo (pip
, summary
)
4359 struct procinfo
*pip
;
4362 struct siginfo
*sip
;
4365 if ((pip
-> prstatus
.pr_lwp
.pr_flags
& PR_STOPPED
) &&
4366 (pip
-> prstatus
.pr_lwp
.pr_why
== PR_SIGNALLED
||
4367 pip
-> prstatus
.pr_lwp
.pr_why
== PR_FAULTED
))
4369 if ((pip
-> prstatus
.pr_flags
& PR_STOPPED
) &&
4370 (pip
-> prstatus
.pr_why
== PR_SIGNALLED
||
4371 pip
-> prstatus
.pr_why
== PR_FAULTED
))
4374 printf_filtered ("%-32s", "Additional signal/fault info:");
4376 sip
= &pip
-> prstatus
.pr_lwp
.pr_info
;
4378 sip
= &pip
-> prstatus
.pr_info
;
4382 printf_filtered ("%s ", signalname (sip
-> si_signo
));
4383 if (sip
-> si_errno
> 0)
4385 printf_filtered ("%s ", errnoname (sip
-> si_errno
));
4387 if (sip
-> si_code
<= 0)
4389 printf_filtered ("sent by %s, uid %d ",
4390 target_pid_to_str (sip
-> si_pid
),
4395 printf_filtered ("%s ", sigcodename (sip
));
4396 if ((sip
-> si_signo
== SIGILL
) ||
4397 (sip
-> si_signo
== SIGFPE
) ||
4398 (sip
-> si_signo
== SIGSEGV
) ||
4399 (sip
-> si_signo
== SIGBUS
))
4401 printf_filtered ("addr=%#lx ",
4402 (unsigned long) sip
-> si_addr
);
4404 else if ((sip
-> si_signo
== SIGCHLD
))
4406 printf_filtered ("child %s, status %u ",
4407 target_pid_to_str (sip
-> si_pid
),
4410 else if ((sip
-> si_signo
== SIGPOLL
))
4412 printf_filtered ("band %u ", sip
-> si_band
);
4418 printf_filtered ("\n\n");
4419 printf_filtered ("\t%-16s %s.\n", signalname (sip
-> si_signo
),
4420 safe_strsignal (sip
-> si_signo
));
4421 if (sip
-> si_errno
> 0)
4423 printf_filtered ("\t%-16s %s.\n",
4424 errnoname (sip
-> si_errno
),
4425 safe_strerror (sip
-> si_errno
));
4427 if (sip
-> si_code
<= 0)
4429 printf_filtered ("\t%-16u %s\n", sip
-> si_pid
, /* XXX need target_pid_to_str() */
4430 "PID of process sending signal");
4431 printf_filtered ("\t%-16u %s\n", sip
-> si_uid
,
4432 "UID of process sending signal");
4436 printf_filtered ("\t%-16s %s.\n", sigcodename (sip
),
4438 if ((sip
-> si_signo
== SIGILL
) ||
4439 (sip
-> si_signo
== SIGFPE
))
4441 printf_filtered ("\t%#-16lx %s.\n",
4442 (unsigned long) sip
-> si_addr
,
4443 "Address of faulting instruction");
4445 else if ((sip
-> si_signo
== SIGSEGV
) ||
4446 (sip
-> si_signo
== SIGBUS
))
4448 printf_filtered ("\t%#-16lx %s.\n",
4449 (unsigned long) sip
-> si_addr
,
4450 "Address of faulting memory reference");
4452 else if ((sip
-> si_signo
== SIGCHLD
))
4454 printf_filtered ("\t%-16u %s.\n", sip
-> si_pid
, /* XXX need target_pid_to_str() */
4455 "Child process ID");
4456 printf_filtered ("\t%-16u %s.\n", sip
-> si_status
,
4457 "Child process exit value or signal");
4459 else if ((sip
-> si_signo
== SIGPOLL
))
4461 printf_filtered ("\t%-16u %s.\n", sip
-> si_band
,
4462 "Band event for POLL_{IN,OUT,MSG}");
4466 printf_filtered ("\n");
4471 info_proc_syscalls (pip
, summary
)
4472 struct procinfo
*pip
;
4480 #if 0 /* FIXME: Needs to use gdb-wide configured info about system calls. */
4481 if (pip
-> prstatus
.pr_flags
& PR_ASLEEP
)
4483 int syscallnum
= pip
-> prstatus
.pr_reg
[R_D0
];
4486 printf_filtered ("%-32s", "Sleeping in system call:");
4487 printf_filtered ("%s", syscallname (syscallnum
));
4491 printf_filtered ("Sleeping in system call '%s'.\n",
4492 syscallname (syscallnum
));
4498 if (ioctl (pip
-> ctl_fd
, PIOCGENTRY
, &pip
-> entryset
) < 0)
4500 print_sys_errmsg (pip
-> pathname
, errno
);
4501 error ("PIOCGENTRY failed");
4504 if (ioctl (pip
-> ctl_fd
, PIOCGEXIT
, &pip
-> exitset
) < 0)
4506 print_sys_errmsg (pip
-> pathname
, errno
);
4507 error ("PIOCGEXIT failed");
4511 printf_filtered ("System call tracing information:\n\n");
4513 printf_filtered ("\t%-12s %-8s %-8s\n",
4517 for (syscallnum
= 0; syscallnum
< MAX_SYSCALLS
; syscallnum
++)
4520 if (syscall_table
[syscallnum
] != NULL
)
4521 printf_filtered ("\t%-12s ", syscall_table
[syscallnum
]);
4523 printf_filtered ("\t%-12d ", syscallnum
);
4526 printf_filtered ("%-8s ",
4527 prismember (&pip
->prstatus
.pr_sysentry
, syscallnum
)
4529 printf_filtered ("%-8s ",
4530 prismember (&pip
->prstatus
.pr_sysexit
, syscallnum
)
4533 printf_filtered ("%-8s ",
4534 prismember (&pip
-> entryset
, syscallnum
)
4536 printf_filtered ("%-8s ",
4537 prismember (&pip
-> exitset
, syscallnum
)
4540 printf_filtered ("\n");
4542 printf_filtered ("\n");
4551 static char locbuf
[32];
4553 name
= strsigno (signo
);
4556 sprintf (locbuf
, "Signal %d", signo
);
4560 sprintf (locbuf
, "%s (%d)", name
, signo
);
4570 static char locbuf
[32];
4572 name
= strerrno (errnum
);
4575 sprintf (locbuf
, "Errno %d", errnum
);
4579 sprintf (locbuf
, "%s (%d)", name
, errnum
);
4585 info_proc_signals (pip
, summary
)
4586 struct procinfo
*pip
;
4593 #ifndef PROCFS_USE_READ_WRITE
4594 if (ioctl (pip
-> ctl_fd
, PIOCGTRACE
, &pip
-> trace
) < 0)
4596 print_sys_errmsg (pip
-> pathname
, errno
);
4597 error ("PIOCGTRACE failed");
4601 printf_filtered ("Disposition of signals:\n\n");
4602 printf_filtered ("\t%-15s %-8s %-8s %-8s %s\n\n",
4603 "Signal", "Trace", "Hold", "Pending", "Description");
4604 for (signo
= 0; signo
< NSIG
; signo
++)
4607 printf_filtered ("\t%-15s ", signalname (signo
));
4609 printf_filtered ("%-8s ",
4610 prismember (&pip
-> prstatus
.pr_sigtrace
, signo
)
4612 printf_filtered ("%-8s ",
4613 prismember (&pip
-> prstatus
.pr_lwp
.pr_context
.uc_sigmask
, signo
)
4616 printf_filtered ("%-8s ",
4617 prismember (&pip
-> trace
, signo
)
4619 printf_filtered ("%-8s ",
4620 prismember (&pip
-> prstatus
.pr_sighold
, signo
)
4625 if (prismember (&pip
->prstatus
.pr_sigpend
, signo
) ||
4626 prismember (&pip
->prstatus
.pr_lwp
.pr_lwppend
, signo
))
4627 printf_filtered("%-8s ", "yes");
4629 printf_filtered("%-8s ", "no");
4630 #else /* UNIXWARE */
4631 #ifdef PROCFS_SIGPEND_OFFSET
4632 /* Alpha OSF/1 numbers the pending signals from 1. */
4633 printf_filtered ("%-8s ",
4634 (signo
? prismember (&pip
-> prstatus
.pr_sigpend
,
4639 printf_filtered ("%-8s ",
4640 prismember (&pip
-> prstatus
.pr_sigpend
, signo
)
4643 #endif /* UNIXWARE */
4644 printf_filtered (" %s\n", safe_strsignal (signo
));
4646 printf_filtered ("\n");
4651 info_proc_faults (pip
, summary
)
4652 struct procinfo
*pip
;
4655 struct trans
*transp
;
4660 if (ioctl (pip
-> ctl_fd
, PIOCGFAULT
, &pip
->fltset
.fltset
) < 0)
4662 print_sys_errmsg (pip
-> pathname
, errno
);
4663 error ("PIOCGFAULT failed");
4667 printf_filtered ("Current traced hardware fault set:\n\n");
4668 printf_filtered ("\t%-12s %-8s\n", "Fault", "Trace");
4670 for (transp
= faults_table
; transp
-> name
!= NULL
; transp
++)
4673 printf_filtered ("\t%-12s ", transp
-> name
);
4675 printf_filtered ("%-8s", prismember (&pip
->prstatus
.pr_flttrace
, transp
-> value
)
4678 printf_filtered ("%-8s", prismember (&pip
->fltset
.fltset
, transp
-> value
)
4681 printf_filtered ("\n");
4683 printf_filtered ("\n");
4688 info_proc_mappings (pip
, summary
)
4689 struct procinfo
*pip
;
4693 struct prmap
*prmaps
;
4694 struct prmap
*prmap
;
4699 printf_filtered ("Mapped address spaces:\n\n");
4700 #ifdef BFD_HOST_64_BIT
4701 printf_filtered (" %18s %18s %10s %10s %7s\n",
4703 printf_filtered ("\t%10s %10s %10s %10s %7s\n",
4710 #ifdef PROCFS_USE_READ_WRITE
4711 if (fstat (pip
->map_fd
, &sbuf
) == 0)
4713 nmap
= sbuf
.st_size
/ sizeof (prmap_t
);
4714 prmaps
= (struct prmap
*) alloca ((nmap
+ 1) * sizeof (*prmaps
));
4715 if ((lseek (pip
->map_fd
, 0, SEEK_SET
) == 0) &&
4716 (read (pip
->map_fd
, (char *) prmaps
,
4717 nmap
* sizeof (*prmaps
)) == (nmap
* sizeof (*prmaps
))))
4720 for (prmap
= prmaps
; i
< nmap
; ++prmap
, ++i
)
4722 if (ioctl (pip
-> ctl_fd
, PIOCNMAP
, &nmap
) == 0)
4724 prmaps
= (struct prmap
*) alloca ((nmap
+ 1) * sizeof (*prmaps
));
4725 if (ioctl (pip
-> ctl_fd
, PIOCMAP
, prmaps
) == 0)
4727 for (prmap
= prmaps
; prmap
-> pr_size
; ++prmap
)
4728 #endif /* PROCFS_USE_READ_WRITE */
4730 #ifdef BFD_HOST_64_BIT
4731 printf_filtered (" %#18lx %#18lx %#10x %#10x %7s\n",
4733 printf_filtered ("\t%#10lx %#10lx %#10x %#10x %7s\n",
4735 (unsigned long)prmap
-> pr_vaddr
,
4736 (unsigned long)prmap
-> pr_vaddr
4737 + prmap
-> pr_size
- 1,
4740 mappingflags (prmap
-> pr_mflags
));
4744 printf_filtered ("\n");
4752 info_proc -- implement the "info proc" command
4756 void info_proc (char *args, int from_tty)
4760 Implement gdb's "info proc" command by using the /proc interface
4761 to print status information about any currently running process.
4763 Examples of the use of "info proc" are:
4765 info proc (prints summary info for current inferior)
4766 info proc 123 (prints summary info for process with pid 123)
4767 info proc mappings (prints address mappings)
4768 info proc times (prints process/children times)
4769 info proc id (prints pid, ppid, gid, sid, etc)
4770 FIXME: i proc id not implemented.
4771 info proc status (prints general process state info)
4772 FIXME: i proc status not implemented.
4773 info proc signals (prints info about signal handling)
4774 info proc all (prints all info)
4779 info_proc (args
, from_tty
)
4784 struct procinfo
*pip
;
4785 struct cleanup
*old_chain
;
4801 old_chain
= make_cleanup (null_cleanup
, 0);
4803 /* Default to using the current inferior if no pid specified. Note
4804 that inferior_pid may be 0, hence we set okerr. */
4806 pid
= inferior_pid
& 0x7fffffff; /* strip off sol-thread bit */
4807 if (!(pip
= find_procinfo (pid
, 1))) /* inferior_pid no good? */
4808 pip
= procinfo_list
; /* take first available */
4809 pid
= pid
& 0xffff; /* extract "real" pid */
4813 if ((argv
= buildargv (args
)) == NULL
)
4817 make_cleanup (freeargv
, (char *) argv
);
4819 while (*argv
!= NULL
)
4821 argsize
= strlen (*argv
);
4822 if (argsize
>= 1 && strncmp (*argv
, "all", argsize
) == 0)
4827 else if (argsize
>= 2 && strncmp (*argv
, "faults", argsize
) == 0)
4832 else if (argsize
>= 2 && strncmp (*argv
, "flags", argsize
) == 0)
4837 else if (argsize
>= 1 && strncmp (*argv
, "id", argsize
) == 0)
4842 else if (argsize
>= 1 && strncmp (*argv
, "mappings", argsize
) == 0)
4847 else if (argsize
>= 2 && strncmp (*argv
, "signals", argsize
) == 0)
4852 else if (argsize
>= 2 && strncmp (*argv
, "status", argsize
) == 0)
4857 else if (argsize
>= 2 && strncmp (*argv
, "syscalls", argsize
) == 0)
4862 else if (argsize
>= 1 && strncmp (*argv
, "times", argsize
) == 0)
4867 else if ((pid
= atoi (*argv
)) > 0)
4869 pip
= (struct procinfo
*) xmalloc (sizeof (struct procinfo
));
4870 memset (pip
, 0, sizeof (*pip
));
4873 if (!open_proc_file (pid
, pip
, O_RDONLY
, 0))
4875 perror_with_name (pip
-> pathname
);
4879 make_cleanup (close_proc_file
, pip
);
4881 else if (**argv
!= '\000')
4883 error ("Unrecognized or ambiguous keyword `%s'.", *argv
);
4889 /* If we don't have a valid open process at this point, then we have no
4890 inferior or didn't specify a specific pid. */
4895 No process. Start debugging a program or specify an explicit process ID.");
4898 if (!procfs_read_status (pip
))
4900 print_sys_errmsg (pip
-> pathname
, errno
);
4901 error ("procfs_read_status failed");
4904 #ifndef PROCFS_USE_READ_WRITE
4906 nlwp
= pip
->prstatus
.pr_nlwp
;
4907 lwps
= alloca ((2 * nlwp
+ 2) * sizeof (*lwps
));
4909 if (ioctl (pip
->ctl_fd
, PIOCLWPIDS
, lwps
))
4911 print_sys_errmsg (pip
-> pathname
, errno
);
4912 error ("PIOCLWPIDS failed");
4914 #else /* PIOCLWPIDS */
4916 lwps
= alloca ((2 * nlwp
+ 2) * sizeof *lwps
);
4918 #endif /* PIOCLWPIDS */
4920 for (; nlwp
> 0; nlwp
--, lwps
++)
4922 pip
= find_procinfo ((*lwps
<< 16) | pid
, 1);
4926 pip
= (struct procinfo
*) xmalloc (sizeof (struct procinfo
));
4927 memset (pip
, 0, sizeof (*pip
));
4928 if (!open_proc_file ((*lwps
<< 16) | pid
, pip
, O_RDONLY
, 0))
4931 make_cleanup (close_proc_file
, pip
);
4933 if (!procfs_read_status (pip
))
4935 print_sys_errmsg (pip
-> pathname
, errno
);
4936 error ("procfs_read_status failed");
4940 #endif /* PROCFS_USE_READ_WRITE */
4942 /* Print verbose information of the requested type(s), or just a summary
4943 of the information for all types. */
4945 printf_filtered ("\nInformation for %s.%d:\n\n", pip
-> pathname
, *lwps
);
4946 if (summary
|| all
|| flags
)
4948 info_proc_flags (pip
, summary
);
4952 info_proc_stop (pip
, summary
);
4954 supply_gregset (&pip
->prstatus
.pr_lwp
.pr_context
.uc_mcontext
.gregs
);
4956 supply_gregset (&pip
->prstatus
.pr_reg
);
4958 printf_filtered ("PC: ");
4959 print_address (read_pc (), gdb_stdout
);
4960 printf_filtered ("\n");
4962 if (summary
|| all
|| signals
|| faults
)
4964 info_proc_siginfo (pip
, summary
);
4966 if (summary
|| all
|| syscalls
)
4968 info_proc_syscalls (pip
, summary
);
4970 if (summary
|| all
|| mappings
)
4972 info_proc_mappings (pip
, summary
);
4974 if (summary
|| all
|| signals
)
4976 info_proc_signals (pip
, summary
);
4978 if (summary
|| all
|| faults
)
4980 info_proc_faults (pip
, summary
);
4982 printf_filtered ("\n");
4984 /* All done, deal with closing any temporary process info structure,
4985 freeing temporary memory , etc. */
4987 do_cleanups (old_chain
);
4988 #ifndef PROCFS_USE_READ_WRITE
4997 modify_inherit_on_fork_flag - Change the inherit-on-fork flag
5001 void modify_inherit_on_fork_flag (fd, flag)
5005 Call this routine to modify the inherit-on-fork flag. This routine is
5006 just a nice wrapper to hide the #ifdefs needed by various systems to
5012 modify_inherit_on_fork_flag (fd
, flag
)
5016 #if defined (PIOCSET) || defined (PCSET)
5020 struct proc_ctl pctl
;
5022 #if defined (PIOCSET) || defined (PCSET) /* New method */
5026 #ifdef PROCFS_USE_READ_WRITE
5028 pctl
.data
= PR_FORK
;
5029 if (write (fd
, (char *) &pctl
, sizeof (struct proc_ctl
)) < 0)
5032 retval
= ioctl (fd
, PIOCSET
, &pr_flags
);
5037 #ifdef PROCFS_USE_READ_WRITE
5039 pctl
.data
= PR_FORK
;
5040 if (write (fd
, (char *) &pctl
, sizeof (struct proc_ctl
)) < 0)
5043 retval
= ioctl (fd
, PIOCRESET
, &pr_flags
);
5048 #ifdef PIOCSFORK /* Original method */
5051 retval
= ioctl (fd
, PIOCSFORK
, NULL
);
5055 retval
= ioctl (fd
, PIOCRFORK
, NULL
);
5058 Neither PR_FORK nor PIOCSFORK exist
!!!
5065 print_sys_errmsg ("modify_inherit_on_fork_flag", errno
);
5066 error ("PIOCSFORK or PR_FORK modification failed");
5073 modify_run_on_last_close_flag - Change the run-on-last-close flag
5077 void modify_run_on_last_close_flag (fd, flag)
5081 Call this routine to modify the run-on-last-close flag. This routine
5082 is just a nice wrapper to hide the #ifdefs needed by various systems to
5088 modify_run_on_last_close_flag (fd
, flag
)
5092 #if defined (PIOCSET) || defined (PCSET)
5096 struct proc_ctl pctl
;
5098 #if defined (PIOCSET) || defined (PCSET) /* New method */
5102 #ifdef PROCFS_USE_READ_WRITE
5105 if (write (fd
, (char *) &pctl
, sizeof (struct proc_ctl
)) < 0)
5108 retval
= ioctl (fd
, PIOCSET
, &pr_flags
);
5113 #ifdef PROCFS_USE_READ_WRITE
5116 if (write (fd
, (char *) &pctl
, sizeof (struct proc_ctl
)) < 0)
5119 retval
= ioctl (fd
, PIOCRESET
, &pr_flags
);
5124 #ifdef PIOCSRLC /* Original method */
5126 retval
= ioctl (fd
, PIOCSRLC
, NULL
);
5128 retval
= ioctl (fd
, PIOCRRLC
, NULL
);
5130 Neither PR_RLC nor PIOCSRLC exist
!!!
5137 print_sys_errmsg ("modify_run_on_last_close_flag", errno
);
5138 error ("PIOCSRLC or PR_RLC modification failed");
5145 procfs_clear_syscall_trap -- Deletes the trap for the specified system call.
5149 void procfs_clear_syscall_trap (struct procinfo *, int syscall_num, int errok)
5153 This function function disables traps for the specified system call.
5154 errok is non-zero if errors should be ignored.
5158 procfs_clear_syscall_trap (pi
, syscall_num
, errok
)
5159 struct procinfo
*pi
;
5167 goterr
= ioctl (pi
->ctl_fd
, PIOCGENTRY
, &sysset
) < 0;
5169 if (goterr
&& !errok
)
5171 print_sys_errmsg (pi
->pathname
, errno
);
5172 error ("PIOCGENTRY failed");
5177 prdelset (&sysset
, syscall_num
);
5179 if ((ioctl (pi
->ctl_fd
, PIOCSENTRY
, &sysset
) < 0) && !errok
)
5181 print_sys_errmsg (pi
->pathname
, errno
);
5182 error ("PIOCSENTRY failed");
5186 goterr
= ioctl (pi
->ctl_fd
, PIOCGEXIT
, &sysset
) < 0;
5188 if (goterr
&& !errok
)
5190 procfs_clear_syscall_trap (pi
, syscall_num
, 1);
5191 print_sys_errmsg (pi
->pathname
, errno
);
5192 error ("PIOCGEXIT failed");
5197 praddset (&sysset
, syscall_num
);
5199 if ((ioctl (pi
->ctl_fd
, PIOCSEXIT
, &sysset
) < 0) && !errok
)
5201 procfs_clear_syscall_trap (pi
, syscall_num
, 1);
5202 print_sys_errmsg (pi
->pathname
, errno
);
5203 error ("PIOCSEXIT failed");
5208 if (!pi
->syscall_handlers
)
5211 error ("procfs_clear_syscall_trap: syscall_handlers is empty");
5215 /* Remove handler func from the handler list */
5217 for (i
= 0; i
< pi
->num_syscall_handlers
; i
++)
5218 if (pi
->syscall_handlers
[i
].syscall_num
== syscall_num
)
5220 if (i
+ 1 != pi
->num_syscall_handlers
)
5221 { /* Not the last entry.
5222 Move subsequent entries fwd. */
5223 memcpy (&pi
->syscall_handlers
[i
], &pi
->syscall_handlers
[i
+ 1],
5224 (pi
->num_syscall_handlers
- i
- 1)
5225 * sizeof (struct procfs_syscall_handler
));
5228 pi
->syscall_handlers
= xrealloc (pi
->syscall_handlers
,
5229 (pi
->num_syscall_handlers
- 1)
5230 * sizeof (struct procfs_syscall_handler
));
5231 pi
->num_syscall_handlers
--;
5236 error ("procfs_clear_syscall_trap: Couldn't find handler for sys call %d",
5244 procfs_set_syscall_trap -- arrange for a function to be called when the
5245 child executes the specified system call.
5249 void procfs_set_syscall_trap (struct procinfo *, int syscall_num, int flags,
5250 syscall_func_t *function)
5254 This function sets up an entry and/or exit trap for the specified system
5255 call. When the child executes the specified system call, your function
5256 will be called with the call #, a flag that indicates entry or exit, and
5257 pointers to rtnval and statval (which are used by procfs_wait). The
5258 function should return non-zero if something interesting happened, zero
5263 procfs_set_syscall_trap (pi
, syscall_num
, flags
, func
)
5264 struct procinfo
*pi
;
5267 syscall_func_t
*func
;
5272 if (flags
& PROCFS_SYSCALL_ENTRY
)
5274 if (ioctl (pi
->ctl_fd
, PIOCGENTRY
, &sysset
) < 0)
5276 print_sys_errmsg (pi
->pathname
, errno
);
5277 error ("PIOCGENTRY failed");
5280 praddset (&sysset
, syscall_num
);
5282 if (ioctl (pi
->ctl_fd
, PIOCSENTRY
, &sysset
) < 0)
5284 print_sys_errmsg (pi
->pathname
, errno
);
5285 error ("PIOCSENTRY failed");
5289 if (flags
& PROCFS_SYSCALL_EXIT
)
5291 if (ioctl (pi
->ctl_fd
, PIOCGEXIT
, &sysset
) < 0)
5293 procfs_clear_syscall_trap (pi
, syscall_num
, 1);
5294 print_sys_errmsg (pi
->pathname
, errno
);
5295 error ("PIOCGEXIT failed");
5298 praddset (&sysset
, syscall_num
);
5300 if (ioctl (pi
->ctl_fd
, PIOCSEXIT
, &sysset
) < 0)
5302 procfs_clear_syscall_trap (pi
, syscall_num
, 1);
5303 print_sys_errmsg (pi
->pathname
, errno
);
5304 error ("PIOCSEXIT failed");
5309 if (!pi
->syscall_handlers
)
5311 pi
->syscall_handlers
= xmalloc (sizeof (struct procfs_syscall_handler
));
5312 pi
->syscall_handlers
[0].syscall_num
= syscall_num
;
5313 pi
->syscall_handlers
[0].func
= func
;
5314 pi
->num_syscall_handlers
= 1;
5320 for (i
= 0; i
< pi
->num_syscall_handlers
; i
++)
5321 if (pi
->syscall_handlers
[i
].syscall_num
== syscall_num
)
5323 pi
->syscall_handlers
[i
].func
= func
;
5327 pi
->syscall_handlers
= xrealloc (pi
->syscall_handlers
, (i
+ 1)
5328 * sizeof (struct procfs_syscall_handler
));
5329 pi
->syscall_handlers
[i
].syscall_num
= syscall_num
;
5330 pi
->syscall_handlers
[i
].func
= func
;
5331 pi
->num_syscall_handlers
++;
5335 #ifdef SYS_lwp_create
5341 procfs_lwp_creation_handler - handle exit from the _lwp_create syscall
5345 int procfs_lwp_creation_handler (pi, syscall_num, why, rtnvalp, statvalp)
5349 This routine is called both when an inferior process and it's new lwp
5350 are about to finish a _lwp_create() system call. This is the system
5351 call that Solaris uses to create a lightweight process. When the
5352 target process gets this event, we can look at sysarg[2] to find the
5353 new childs lwp ID, and create a procinfo struct from that. After that,
5354 we pretend that we got a SIGTRAP, and return non-zero to tell
5355 procfs_wait to wake up. Subsequently, wait_for_inferior gets woken up,
5356 sees the new process and continues it.
5358 When we see the child exiting from lwp_create, we just contine it,
5359 since everything was handled when the parent trapped.
5362 In effect, we are only paying attention to the parent's completion of
5363 the lwp_create syscall. If we only paid attention to the child
5364 instead, then we wouldn't detect the creation of a suspended thread.
5368 procfs_lwp_creation_handler (pi
, syscall_num
, why
, rtnvalp
, statvalp
)
5369 struct procinfo
*pi
;
5376 struct procinfo
*childpi
;
5377 struct proc_ctl pctl
;
5379 /* We've just detected the completion of an lwp_create system call. Now we
5380 need to setup a procinfo struct for this thread, and notify the thread
5381 system of the new arrival. */
5383 /* If lwp_create failed, then nothing interesting happened. Continue the
5384 process and go back to sleep. */
5387 /* Joel ... can you check this logic out please? JKJ */
5388 if (pi
->prstatus
.pr_lwp
.pr_context
.uc_mcontext
.gregs
[R_EFL
] & 1)
5389 { /* _lwp_create failed */
5391 pctl
.data
= PRCFAULT
;
5393 if (write (pi
->ctl_fd
, (char *) &pctl
, sizeof (struct proc_ctl
)) < 0)
5394 perror_with_name (pi
->pathname
);
5398 #else /* UNIXWARE */
5399 if (PROCFS_GET_CARRY (pi
->prstatus
.pr_reg
))
5400 { /* _lwp_create failed */
5401 pi
->prrun
.pr_flags
&= PRSTEP
;
5402 pi
->prrun
.pr_flags
|= PRCFAULT
;
5404 if (ioctl (pi
->ctl_fd
, PIOCRUN
, &pi
->prrun
) != 0)
5405 perror_with_name (pi
->pathname
);
5411 /* At this point, the new thread is stopped at it's first instruction, and
5412 the parent is stopped at the exit from lwp_create. */
5414 if (pi
->new_child
) /* Child? */
5415 { /* Yes, just continue it */
5418 pctl
.data
= PRCFAULT
;
5420 if (write(pi
->ctl_fd
, (char *)&pctl
, sizeof (struct proc_ctl
)) < 0)
5421 #else /* !UNIXWARE */
5422 pi
->prrun
.pr_flags
&= PRSTEP
;
5423 pi
->prrun
.pr_flags
|= PRCFAULT
;
5425 if ((pi
->prstatus
.pr_flags
& PR_ISTOP
)
5426 && ioctl (pi
->ctl_fd
, PIOCRUN
, &pi
->prrun
) != 0)
5427 #endif /* !UNIXWARE */
5428 perror_with_name (pi
->pathname
);
5430 pi
->new_child
= 0; /* No longer new */
5435 /* We're the proud parent of a new thread. Setup an exit trap for lwp_create
5436 in the child and continue the parent. */
5438 /* Third arg is pointer to new thread id. */
5440 lwp_id
= read_memory_integer (pi
->prstatus
.pr_lwp
.pr_sysarg
[2], sizeof (int));
5442 lwp_id
= read_memory_integer (pi
->prstatus
.pr_sysarg
[2], sizeof (int));
5445 lwp_id
= (lwp_id
<< 16) | PIDGET (pi
->pid
);
5447 childpi
= create_procinfo (lwp_id
);
5449 /* The new process has actually inherited the lwp_create syscall trap from
5450 it's parent, but we still have to call this to register handlers for
5453 procfs_set_inferior_syscall_traps (childpi
);
5454 add_thread (lwp_id
);
5455 printf_filtered ("[New %s]\n", target_pid_to_str (lwp_id
));
5457 /* Continue the parent */
5460 pctl
.data
= PRCFAULT
;
5462 if (write(pi
->ctl_fd
, (char *)&pctl
, sizeof (struct proc_ctl
)) < 0)
5464 pi
->prrun
.pr_flags
&= PRSTEP
;
5465 pi
->prrun
.pr_flags
|= PRCFAULT
;
5466 if (ioctl (pi
->ctl_fd
, PIOCRUN
, &pi
->prrun
) != 0)
5468 perror_with_name (pi
->pathname
);
5470 /* The new child may have been created in one of two states:
5471 SUSPENDED or RUNNABLE. If runnable, we will simply signal it to run.
5472 If suspended, we flag it to be continued later, when it has an event. */
5475 if (childpi
->prstatus
.pr_lwp
.pr_why
== PR_SUSPENDED
)
5477 if (childpi
->prstatus
.pr_why
== PR_SUSPENDED
)
5479 childpi
->new_child
= 1; /* Flag this as an unseen child process */
5482 /* Continue the child */
5485 pctl
.data
= PRCFAULT
;
5487 if (write(pi
->ctl_fd
, (char *)&pctl
, sizeof (struct proc_ctl
)) < 0)
5489 childpi
->prrun
.pr_flags
&= PRSTEP
;
5490 childpi
->prrun
.pr_flags
|= PRCFAULT
;
5492 if (ioctl (childpi
->ctl_fd
, PIOCRUN
, &childpi
->prrun
) != 0)
5494 perror_with_name (childpi
->pathname
);
5498 #endif /* SYS_lwp_create */
5500 /* Fork an inferior process, and start debugging it with /proc. */
5503 procfs_create_inferior (exec_file
, allargs
, env
)
5508 char *shell_file
= getenv ("SHELL");
5510 if (shell_file
!= NULL
&& strchr (shell_file
, '/') == NULL
)
5513 /* We will be looking down the PATH to find shell_file. If we
5514 just do this the normal way (via execlp, which operates by
5515 attempting an exec for each element of the PATH until it
5516 finds one which succeeds), then there will be an exec for
5517 each failed attempt, each of which will cause a PR_SYSEXIT
5518 stop, and we won't know how to distinguish the PR_SYSEXIT's
5519 for these failed execs with the ones for successful execs
5520 (whether the exec has succeeded is stored at that time in the
5521 carry bit or some such architecture-specific and
5522 non-ABI-specified place).
5524 So I can't think of anything better than to search the PATH
5525 now. This has several disadvantages: (1) There is a race
5526 condition; if we find a file now and it is deleted before we
5527 exec it, we lose, even if the deletion leaves a valid file
5528 further down in the PATH, (2) there is no way to know exactly
5529 what an executable (in the sense of "capable of being
5530 exec'd") file is. Using access() loses because it may lose
5531 if the caller is the superuser; failing to use it loses if
5532 there are ACLs or some such. */
5536 /* FIXME-maybe: might want "set path" command so user can change what
5537 path is used from within GDB. */
5538 char *path
= getenv ("PATH");
5540 struct stat statbuf
;
5543 path
= "/bin:/usr/bin";
5545 tryname
= alloca (strlen (path
) + strlen (shell_file
) + 2);
5546 for (p
= path
; p
!= NULL
; p
= p1
? p1
+ 1: NULL
)
5548 p1
= strchr (p
, ':');
5553 strncpy (tryname
, p
, len
);
5554 tryname
[len
] = '\0';
5555 strcat (tryname
, "/");
5556 strcat (tryname
, shell_file
);
5557 if (access (tryname
, X_OK
) < 0)
5559 if (stat (tryname
, &statbuf
) < 0)
5561 if (!S_ISREG (statbuf
.st_mode
))
5562 /* We certainly need to reject directories. I'm not quite
5563 as sure about FIFOs, sockets, etc., but I kind of doubt
5564 that people want to exec() these things. */
5569 /* Not found. This must be an error rather than merely passing
5570 the file to execlp(), because execlp() would try all the
5571 exec()s, causing GDB to get confused. */
5572 error ("Can't find shell %s in PATH", shell_file
);
5574 shell_file
= tryname
;
5577 fork_inferior (exec_file
, allargs
, env
,
5578 proc_set_exec_trap
, procfs_init_inferior
, shell_file
);
5580 /* We are at the first instruction we care about. */
5581 /* Pedal to the metal... */
5583 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_0
, 0);
5586 /* Clean up after the inferior dies. */
5589 procfs_mourn_inferior ()
5591 struct procinfo
*pi
;
5592 struct procinfo
*next_pi
;
5594 for (pi
= procinfo_list
; pi
; pi
= next_pi
)
5597 unconditionally_kill_inferior (pi
);
5600 unpush_target (&procfs_ops
);
5601 generic_mourn_inferior ();
5605 /* Mark our target-struct as eligible for stray "run" and "attach" commands. */
5609 /* This variable is controlled by modules that sit atop procfs that may layer
5610 their own process structure atop that provided here. sol-thread.c does
5611 this because of the Solaris two-level thread model. */
5613 return !procfs_suppress_run
;
5615 #ifdef TARGET_HAS_HARDWARE_WATCHPOINTS
5618 /* Insert a watchpoint */
5620 procfs_set_watchpoint(pid
, addr
, len
, rw
)
5626 struct procinfo
*pi
;
5629 pi
= find_procinfo (pid
== -1 ? inferior_pid
: pid
, 0);
5630 wpt
.pr_vaddr
= (caddr_t
)addr
;
5632 wpt
.pr_wflags
= ((rw
& 1) ? MA_READ
: 0) | ((rw
& 2) ? MA_WRITE
: 0);
5633 if (ioctl (pi
->ctl_fd
, PIOCSWATCH
, &wpt
) < 0)
5637 /* Currently it sometimes happens that the same watchpoint gets
5638 deleted twice - don't die in this case (FIXME please) */
5639 if (errno
== ESRCH
&& len
== 0)
5641 print_sys_errmsg (pi
->pathname
, errno
);
5642 error ("PIOCSWATCH failed");
5648 procfs_stopped_by_watchpoint(pid
)
5651 struct procinfo
*pi
;
5655 pi
= find_procinfo (pid
== -1 ? inferior_pid
: pid
, 0);
5656 if (pi
->prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
))
5658 why
= pi
->prstatus
.pr_why
;
5659 what
= pi
->prstatus
.pr_what
;
5660 if (why
== PR_FAULTED
5661 #if defined (FLTWATCH) && defined (FLTKWATCH)
5662 && (what
== FLTWATCH
|| what
== FLTKWATCH
)
5665 && (what
== FLTWATCH
)
5668 && (what
== FLTKWATCH
)
5676 #endif /* !UNIXWARE */
5677 #endif /* TARGET_HAS_HARDWARE_WATCHPOINTS */
5679 /* Why is this necessary? Shouldn't dead threads just be removed from the
5683 procfs_thread_alive (pid
)
5686 struct procinfo
*pi
, *next_pi
;
5688 for (pi
= procinfo_list
; pi
; pi
= next_pi
)
5691 if (pi
-> pid
== pid
)
5692 if (procfs_read_status (pi
)) /* alive */
5694 else /* defunct (exited) */
5696 close_proc_file (pi
);
5704 procfs_first_available ()
5706 struct procinfo
*pi
;
5708 for (pi
= procinfo_list
; pi
; pi
= pi
->next
)
5710 if (procfs_read_status (pi
))
5717 procfs_get_pid_fd (pid
)
5720 struct procinfo
*pi
= find_procinfo (pid
, 1);
5728 /* Send a SIGINT to the process group. This acts just like the user typed a
5729 ^C on the controlling terminal.
5731 XXX - This may not be correct for all systems. Some may want to use
5732 killpg() instead of kill (-pgrp). */
5737 extern pid_t inferior_process_group
;
5739 kill (-inferior_process_group
, SIGINT
);
5742 /* Convert a pid to printable form. */
5746 procfs_pid_to_str (pid
)
5749 static char buf
[100];
5751 sprintf (buf
, "Kernel thread %d", TIDGET (pid
));
5757 struct target_ops procfs_ops
= {
5758 "procfs", /* to_shortname */
5759 "Unix /proc child process", /* to_longname */
5760 "Unix /proc child process (started by the \"run\" command).", /* to_doc */
5761 procfs_open
, /* to_open */
5763 procfs_attach
, /* to_attach */
5764 procfs_detach
, /* to_detach */
5765 procfs_resume
, /* to_resume */
5766 procfs_wait
, /* to_wait */
5767 procfs_fetch_registers
, /* to_fetch_registers */
5768 procfs_store_registers
, /* to_store_registers */
5769 procfs_prepare_to_store
, /* to_prepare_to_store */
5770 procfs_xfer_memory
, /* to_xfer_memory */
5771 procfs_files_info
, /* to_files_info */
5772 memory_insert_breakpoint
, /* to_insert_breakpoint */
5773 memory_remove_breakpoint
, /* to_remove_breakpoint */
5774 terminal_init_inferior
, /* to_terminal_init */
5775 terminal_inferior
, /* to_terminal_inferior */
5776 terminal_ours_for_output
, /* to_terminal_ours_for_output */
5777 terminal_ours
, /* to_terminal_ours */
5778 child_terminal_info
, /* to_terminal_info */
5779 procfs_kill_inferior
, /* to_kill */
5781 0, /* to_lookup_symbol */
5782 procfs_create_inferior
, /* to_create_inferior */
5783 procfs_mourn_inferior
, /* to_mourn_inferior */
5784 procfs_can_run
, /* to_can_run */
5785 procfs_notice_signals
, /* to_notice_signals */
5786 procfs_thread_alive
, /* to_thread_alive */
5787 procfs_stop
, /* to_stop */
5788 process_stratum
, /* to_stratum */
5790 1, /* to_has_all_memory */
5791 1, /* to_has_memory */
5792 1, /* to_has_stack */
5793 1, /* to_has_registers */
5794 1, /* to_has_execution */
5796 0, /* sections_end */
5797 OPS_MAGIC
/* to_magic */
5801 _initialize_procfs ()
5803 #ifdef HAVE_OPTIONAL_PROC_FS
5804 char procname
[MAX_PROC_NAME_SIZE
];
5807 /* If we have an optional /proc filesystem (e.g. under OSF/1),
5808 don't add procfs support if we cannot access the running
5810 sprintf (procname
, STATUS_PROC_NAME_FMT
, getpid ());
5811 if ((fd
= open (procname
, O_RDONLY
)) < 0)
5816 add_target (&procfs_ops
);
5818 add_info ("processes", info_proc
,
5819 "Show process status information using /proc entry.\n\
5820 Specify process id or use current inferior by default.\n\
5821 Specify keywords for detailed information; default is summary.\n\
5822 Keywords are: `all', `faults', `flags', `id', `mappings', `signals',\n\
5823 `status', `syscalls', and `times'.\n\
5824 Unambiguous abbreviations may be used.");
5826 init_syscall_table ();