1 /* Machine independent support for SVR4 /proc (process file system) for GDB.
2 Copyright 1991, 1992-96, 1997 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 /* the name of the proc status struct depends on the implementation */
59 typedef pstatus_t gdb_prstatus_t
;
61 typedef prstatus_t gdb_prstatus_t
;
64 #define MAX_SYSCALLS 256 /* Maximum number of syscalls for table */
66 /* proc name formats may vary depending on the proc implementation */
67 #ifdef HAVE_MULTIPLE_PROC_FDS
68 #ifndef CTL_PROC_NAME_FMT
69 #define CTL_PROC_NAME_FMT "/proc/%d/ctl"
70 #define AS_PROC_NAME_FMT "/proc/%d/as"
71 #define MAP_PROC_NAME_FMT "/proc/%d/map"
72 #define STATUS_PROC_NAME_FMT "/proc/%d/status"
74 #else /* HAVE_MULTIPLE_PROC_FDS */
75 #ifndef CTL_PROC_NAME_FMT
76 #define CTL_PROC_NAME_FMT "/proc/%05d"
77 #define AS_PROC_NAME_FMT "/proc/%05d"
78 #define MAP_PROC_NAME_FMT "/proc/%05d"
79 #define STATUS_PROC_NAME_FMT "/proc/%05d"
81 #endif /* HAVE_MULTIPLE_PROC_FDS */
83 #define MAX_PROC_NAME_SIZE sizeof("/proc/1234567890/status")
85 extern struct target_ops procfs_ops
; /* Forward declaration */
87 int procfs_suppress_run
= 0; /* Non-zero if procfs should pretend not to
88 be a runnable target. Used by targets
89 that can sit atop procfs, such as solaris
92 #if 1 /* FIXME: Gross and ugly hack to resolve coredep.c global */
93 CORE_ADDR kernel_u_addr
;
96 #ifdef BROKEN_SIGINFO_H /* Workaround broken SGS <sys/siginfo.h> */
98 #define si_pid _data._proc.pid
100 #define si_uid _data._proc._pdata._kill.uid
101 #endif /* BROKEN_SIGINFO_H */
103 /* Define structures for passing commands to /proc/pid/ctl file. Note that
104 while we create these for the PROCFS_USE_READ_WRITE world, we use them
105 and ignore the extra cmd int in other proc schemes.
107 /* generic ctl msg */
113 /* set general registers */
119 /* set fp registers */
125 /* set signals to be traced */
131 /* set faults to be traced */
137 /* set system calls to be traced */
143 /* set current signal to be traced */
149 /* All access to the inferior, either one started by gdb or one that has
150 been attached to, is controlled by an instance of a procinfo structure,
151 defined below. Since gdb currently only handles one inferior at a time,
152 the procinfo structure for the inferior is statically allocated and
153 only one exists at any given time. There is a separate procinfo
154 structure for use by the "info proc" command, so that we can print
155 useful information about any random process without interfering with
156 the inferior's procinfo information. */
159 struct procinfo
*next
;
160 int pid
; /* Process ID of inferior */
161 int ctl_fd
; /* File descriptor for /proc ctl file */
162 int status_fd
; /* File descriptor for /proc status file */
163 int as_fd
; /* File descriptor for /proc as file */
164 int map_fd
; /* File descriptor for /proc map file */
165 char *pathname
; /* Pathname to /proc entry */
166 int had_event
; /* poll/select says something happened */
167 int was_stopped
; /* Nonzero if was stopped prior to attach */
168 int nopass_next_sigstop
; /* Don't pass a sigstop on next resume */
169 #ifndef HAVE_NO_PRRUN_T
170 prrun_t prrun
; /* Control state when it is run */
172 gdb_prstatus_t prstatus
; /* Current process status info */
173 struct greg_ctl gregset
; /* General register set */
174 struct fpreg_ctl fpregset
; /* Floating point register set */
175 struct flt_ctl fltset
; /* Current traced hardware fault set */
176 struct sig_ctl trace
; /* Current traced signal set */
177 struct sys_ctl exitset
; /* Current traced system call exit set */
178 struct sys_ctl entryset
; /* Current traced system call entry set */
179 struct sig_ctl saved_sighold
; /* Saved held signal set */
180 struct flt_ctl saved_fltset
; /* Saved traced hardware fault set */
181 struct sig_ctl saved_trace
; /* Saved traced signal set */
182 struct sys_ctl saved_exitset
; /* Saved traced system call exit set */
183 struct sys_ctl saved_entryset
;/* Saved traced system call entry set */
184 int num_syscall_handlers
; /* Number of syscall handlers currently installed */
185 struct procfs_syscall_handler
*syscall_handlers
; /* Pointer to list of syscall trap handlers */
186 int new_child
; /* Non-zero if it's a new thread */
189 /* List of inferior process information */
190 static struct procinfo
*procinfo_list
= NULL
;
192 static struct pollfd
*poll_list
; /* pollfds used for waiting on /proc */
194 static int num_poll_list
= 0; /* Number of entries in poll_list */
196 /* Much of the information used in the /proc interface, particularly for
197 printing status information, is kept as tables of structures of the
198 following form. These tables can be used to map numeric values to
199 their symbolic names and to a string that describes their specific use. */
202 int value
; /* The numeric value */
203 char *name
; /* The equivalent symbolic value */
204 char *desc
; /* Short description of value */
207 /* Translate bits in the pr_flags member of the prstatus structure, into the
208 names and desc information. */
210 static struct trans pr_flag_table
[] =
212 #if defined (PR_STOPPED)
213 { PR_STOPPED
, "PR_STOPPED", "Process is stopped" },
215 #if defined (PR_ISTOP)
216 { PR_ISTOP
, "PR_ISTOP", "Stopped on an event of interest" },
218 #if defined (PR_DSTOP)
219 { PR_DSTOP
, "PR_DSTOP", "A stop directive is in effect" },
221 #if defined (PR_ASLEEP)
222 { PR_ASLEEP
, "PR_ASLEEP", "Sleeping in an interruptible system call" },
224 #if defined (PR_FORK)
225 { PR_FORK
, "PR_FORK", "Inherit-on-fork is in effect" },
228 { PR_RLC
, "PR_RLC", "Run-on-last-close is in effect" },
230 #if defined (PR_PTRACE)
231 { PR_PTRACE
, "PR_PTRACE", "Process is being controlled by ptrace" },
233 #if defined (PR_PCINVAL)
234 { PR_PCINVAL
, "PR_PCINVAL", "PC refers to an invalid virtual address" },
236 #if defined (PR_ISSYS)
237 { PR_ISSYS
, "PR_ISSYS", "Is a system process" },
239 #if defined (PR_STEP)
240 { PR_STEP
, "PR_STEP", "Process has single step pending" },
243 { PR_KLC
, "PR_KLC", "Kill-on-last-close is in effect" },
245 #if defined (PR_ASYNC)
246 { PR_ASYNC
, "PR_ASYNC", "Asynchronous stop is in effect" },
248 #if defined (PR_PCOMPAT)
249 { PR_PCOMPAT
, "PR_PCOMPAT", "Ptrace compatibility mode in effect" },
254 /* Translate values in the pr_why field of the prstatus struct. */
256 static struct trans pr_why_table
[] =
258 #if defined (PR_REQUESTED)
259 { PR_REQUESTED
, "PR_REQUESTED", "Directed to stop via PIOCSTOP/PIOCWSTOP" },
261 #if defined (PR_SIGNALLED)
262 { PR_SIGNALLED
, "PR_SIGNALLED", "Receipt of a traced signal" },
264 #if defined (PR_FAULTED)
265 { PR_FAULTED
, "PR_FAULTED", "Incurred a traced hardware fault" },
267 #if defined (PR_SYSENTRY)
268 { PR_SYSENTRY
, "PR_SYSENTRY", "Entry to a traced system call" },
270 #if defined (PR_SYSEXIT)
271 { PR_SYSEXIT
, "PR_SYSEXIT", "Exit from a traced system call" },
273 #if defined (PR_JOBCONTROL)
274 { PR_JOBCONTROL
, "PR_JOBCONTROL", "Default job control stop signal action" },
276 #if defined (PR_SUSPENDED)
277 { PR_SUSPENDED
, "PR_SUSPENDED", "Process suspended" },
282 /* Hardware fault translation table. */
284 static struct trans faults_table
[] =
287 { FLTILL
, "FLTILL", "Illegal instruction" },
289 #if defined (FLTPRIV)
290 { FLTPRIV
, "FLTPRIV", "Privileged instruction" },
293 { FLTBPT
, "FLTBPT", "Breakpoint trap" },
295 #if defined (FLTTRACE)
296 { FLTTRACE
, "FLTTRACE", "Trace trap" },
298 #if defined (FLTACCESS)
299 { FLTACCESS
, "FLTACCESS", "Memory access fault" },
301 #if defined (FLTBOUNDS)
302 { FLTBOUNDS
, "FLTBOUNDS", "Memory bounds violation" },
304 #if defined (FLTIOVF)
305 { FLTIOVF
, "FLTIOVF", "Integer overflow" },
307 #if defined (FLTIZDIV)
308 { FLTIZDIV
, "FLTIZDIV", "Integer zero divide" },
311 { FLTFPE
, "FLTFPE", "Floating-point exception" },
313 #if defined (FLTSTACK)
314 { FLTSTACK
, "FLTSTACK", "Unrecoverable stack fault" },
316 #if defined (FLTPAGE)
317 { FLTPAGE
, "FLTPAGE", "Recoverable page fault" },
322 /* Translation table for signal generation information. See UNIX System
323 V Release 4 Programmer's Reference Manual, siginfo(5). */
325 static struct sigcode
{
330 } siginfo_table
[] = {
331 #if defined (SIGILL) && defined (ILL_ILLOPC)
332 { SIGILL
, ILL_ILLOPC
, "ILL_ILLOPC", "Illegal opcode" },
334 #if defined (SIGILL) && defined (ILL_ILLOPN)
335 { SIGILL
, ILL_ILLOPN
, "ILL_ILLOPN", "Illegal operand", },
337 #if defined (SIGILL) && defined (ILL_ILLADR)
338 { SIGILL
, ILL_ILLADR
, "ILL_ILLADR", "Illegal addressing mode" },
340 #if defined (SIGILL) && defined (ILL_ILLTRP)
341 { SIGILL
, ILL_ILLTRP
, "ILL_ILLTRP", "Illegal trap" },
343 #if defined (SIGILL) && defined (ILL_PRVOPC)
344 { SIGILL
, ILL_PRVOPC
, "ILL_PRVOPC", "Privileged opcode" },
346 #if defined (SIGILL) && defined (ILL_PRVREG)
347 { SIGILL
, ILL_PRVREG
, "ILL_PRVREG", "Privileged register" },
349 #if defined (SIGILL) && defined (ILL_COPROC)
350 { SIGILL
, ILL_COPROC
, "ILL_COPROC", "Coprocessor error" },
352 #if defined (SIGILL) && defined (ILL_BADSTK)
353 { SIGILL
, ILL_BADSTK
, "ILL_BADSTK", "Internal stack error" },
355 #if defined (SIGFPE) && defined (FPE_INTDIV)
356 { SIGFPE
, FPE_INTDIV
, "FPE_INTDIV", "Integer divide by zero" },
358 #if defined (SIGFPE) && defined (FPE_INTOVF)
359 { SIGFPE
, FPE_INTOVF
, "FPE_INTOVF", "Integer overflow" },
361 #if defined (SIGFPE) && defined (FPE_FLTDIV)
362 { SIGFPE
, FPE_FLTDIV
, "FPE_FLTDIV", "Floating point divide by zero" },
364 #if defined (SIGFPE) && defined (FPE_FLTOVF)
365 { SIGFPE
, FPE_FLTOVF
, "FPE_FLTOVF", "Floating point overflow" },
367 #if defined (SIGFPE) && defined (FPE_FLTUND)
368 { SIGFPE
, FPE_FLTUND
, "FPE_FLTUND", "Floating point underflow" },
370 #if defined (SIGFPE) && defined (FPE_FLTRES)
371 { SIGFPE
, FPE_FLTRES
, "FPE_FLTRES", "Floating point inexact result" },
373 #if defined (SIGFPE) && defined (FPE_FLTINV)
374 { SIGFPE
, FPE_FLTINV
, "FPE_FLTINV", "Invalid floating point operation" },
376 #if defined (SIGFPE) && defined (FPE_FLTSUB)
377 { SIGFPE
, FPE_FLTSUB
, "FPE_FLTSUB", "Subscript out of range" },
379 #if defined (SIGSEGV) && defined (SEGV_MAPERR)
380 { SIGSEGV
, SEGV_MAPERR
, "SEGV_MAPERR", "Address not mapped to object" },
382 #if defined (SIGSEGV) && defined (SEGV_ACCERR)
383 { SIGSEGV
, SEGV_ACCERR
, "SEGV_ACCERR", "Invalid permissions for object" },
385 #if defined (SIGBUS) && defined (BUS_ADRALN)
386 { SIGBUS
, BUS_ADRALN
, "BUS_ADRALN", "Invalid address alignment" },
388 #if defined (SIGBUS) && defined (BUS_ADRERR)
389 { SIGBUS
, BUS_ADRERR
, "BUS_ADRERR", "Non-existent physical address" },
391 #if defined (SIGBUS) && defined (BUS_OBJERR)
392 { SIGBUS
, BUS_OBJERR
, "BUS_OBJERR", "Object specific hardware error" },
394 #if defined (SIGTRAP) && defined (TRAP_BRKPT)
395 { SIGTRAP
, TRAP_BRKPT
, "TRAP_BRKPT", "Process breakpoint" },
397 #if defined (SIGTRAP) && defined (TRAP_TRACE)
398 { SIGTRAP
, TRAP_TRACE
, "TRAP_TRACE", "Process trace trap" },
400 #if defined (SIGCLD) && defined (CLD_EXITED)
401 { SIGCLD
, CLD_EXITED
, "CLD_EXITED", "Child has exited" },
403 #if defined (SIGCLD) && defined (CLD_KILLED)
404 { SIGCLD
, CLD_KILLED
, "CLD_KILLED", "Child was killed" },
406 #if defined (SIGCLD) && defined (CLD_DUMPED)
407 { SIGCLD
, CLD_DUMPED
, "CLD_DUMPED", "Child has terminated abnormally" },
409 #if defined (SIGCLD) && defined (CLD_TRAPPED)
410 { SIGCLD
, CLD_TRAPPED
, "CLD_TRAPPED", "Traced child has trapped" },
412 #if defined (SIGCLD) && defined (CLD_STOPPED)
413 { SIGCLD
, CLD_STOPPED
, "CLD_STOPPED", "Child has stopped" },
415 #if defined (SIGCLD) && defined (CLD_CONTINUED)
416 { SIGCLD
, CLD_CONTINUED
, "CLD_CONTINUED", "Stopped child had continued" },
418 #if defined (SIGPOLL) && defined (POLL_IN)
419 { SIGPOLL
, POLL_IN
, "POLL_IN", "Input input available" },
421 #if defined (SIGPOLL) && defined (POLL_OUT)
422 { SIGPOLL
, POLL_OUT
, "POLL_OUT", "Output buffers available" },
424 #if defined (SIGPOLL) && defined (POLL_MSG)
425 { SIGPOLL
, POLL_MSG
, "POLL_MSG", "Input message available" },
427 #if defined (SIGPOLL) && defined (POLL_ERR)
428 { SIGPOLL
, POLL_ERR
, "POLL_ERR", "I/O error" },
430 #if defined (SIGPOLL) && defined (POLL_PRI)
431 { SIGPOLL
, POLL_PRI
, "POLL_PRI", "High priority input available" },
433 #if defined (SIGPOLL) && defined (POLL_HUP)
434 { SIGPOLL
, POLL_HUP
, "POLL_HUP", "Device disconnected" },
439 static char *syscall_table
[MAX_SYSCALLS
];
441 /* Prototypes for local functions */
443 static void procfs_stop
PARAMS ((void));
445 static int procfs_thread_alive
PARAMS ((int));
447 static int procfs_can_run
PARAMS ((void));
449 static void procfs_mourn_inferior
PARAMS ((void));
451 static void procfs_fetch_registers
PARAMS ((int));
453 static int procfs_wait
PARAMS ((int, struct target_waitstatus
*));
455 static void procfs_open
PARAMS ((char *, int));
457 static void procfs_files_info
PARAMS ((struct target_ops
*));
459 static void procfs_prepare_to_store
PARAMS ((void));
461 static void procfs_detach
PARAMS ((char *, int));
463 static void procfs_attach
PARAMS ((char *, int));
465 static void proc_set_exec_trap
PARAMS ((void));
467 static int procfs_init_inferior
PARAMS ((int));
469 static struct procinfo
*create_procinfo
PARAMS ((int));
471 static void procfs_store_registers
PARAMS ((int));
473 static int procfs_xfer_memory
PARAMS ((CORE_ADDR
, char *, int, int, struct target_ops
*));
475 static void procfs_kill_inferior
PARAMS ((void));
477 static char *sigcodedesc
PARAMS ((siginfo_t
*));
479 static char *sigcodename
PARAMS ((siginfo_t
*));
481 static struct procinfo
*wait_fd
PARAMS ((void));
483 static void remove_fd
PARAMS ((struct procinfo
*));
485 static void add_fd
PARAMS ((struct procinfo
*));
487 static void set_proc_siginfo
PARAMS ((struct procinfo
*, int));
489 static void init_syscall_table
PARAMS ((void));
491 static char *syscallname
PARAMS ((int));
493 static char *signalname
PARAMS ((int));
495 static char *errnoname
PARAMS ((int));
497 static int proc_address_to_fd
PARAMS ((struct procinfo
*, CORE_ADDR
, int));
499 static int open_proc_file
PARAMS ((int, struct procinfo
*, int, int));
501 static void close_proc_file
PARAMS ((struct procinfo
*));
503 static void unconditionally_kill_inferior
PARAMS ((struct procinfo
*));
505 static NORETURN
void proc_init_failed
PARAMS ((struct procinfo
*, char *)) ATTR_NORETURN
;
507 static void info_proc
PARAMS ((char *, int));
509 static void info_proc_flags
PARAMS ((struct procinfo
*, int));
511 static void info_proc_stop
PARAMS ((struct procinfo
*, int));
513 static void info_proc_siginfo
PARAMS ((struct procinfo
*, int));
515 static void info_proc_syscalls
PARAMS ((struct procinfo
*, int));
517 static void info_proc_mappings
PARAMS ((struct procinfo
*, int));
519 static void info_proc_signals
PARAMS ((struct procinfo
*, int));
521 static void info_proc_faults
PARAMS ((struct procinfo
*, int));
523 static char *mappingflags
PARAMS ((long));
525 static char *lookupname
PARAMS ((struct trans
*, unsigned int, char *));
527 static char *lookupdesc
PARAMS ((struct trans
*, unsigned int));
529 static int do_attach
PARAMS ((int pid
));
531 static void do_detach
PARAMS ((int siggnal
));
533 static void procfs_create_inferior
PARAMS ((char *, char *, char **));
535 static void procfs_notice_signals
PARAMS ((int pid
));
537 static void notice_signals
PARAMS ((struct procinfo
*, struct sig_ctl
*));
539 static struct procinfo
*find_procinfo
PARAMS ((pid_t pid
, int okfail
));
541 static int procfs_read_status
PARAMS ((struct procinfo
*));
542 static int procfs_write_pcwstop
PARAMS ((struct procinfo
*));
543 static void procfs_write_pckill
PARAMS ((struct procinfo
*));
545 typedef int syscall_func_t
PARAMS ((struct procinfo
*pi
, int syscall_num
,
546 int why
, int *rtnval
, int *statval
));
548 static void procfs_set_syscall_trap
PARAMS ((struct procinfo
*pi
,
549 int syscall_num
, int flags
,
550 syscall_func_t
*func
));
552 static void procfs_clear_syscall_trap
PARAMS ((struct procinfo
*pi
,
553 int syscall_num
, int errok
));
555 #define PROCFS_SYSCALL_ENTRY 0x1 /* Trap on entry to sys call */
556 #define PROCFS_SYSCALL_EXIT 0x2 /* Trap on exit from sys call */
558 static syscall_func_t procfs_exit_handler
;
560 static syscall_func_t procfs_exec_handler
;
563 static syscall_func_t procfs_sproc_handler
;
564 static syscall_func_t procfs_fork_handler
;
567 #ifdef SYS_lwp_create
568 static syscall_func_t procfs_lwp_creation_handler
;
571 static void modify_inherit_on_fork_flag
PARAMS ((int fd
, int flag
));
572 static void modify_run_on_last_close_flag
PARAMS ((int fd
, int flag
));
576 struct procfs_syscall_handler
578 int syscall_num
; /* The number of the system call being handled */
579 /* The function to be called */
580 syscall_func_t
*func
;
583 static void procfs_resume
PARAMS ((int pid
, int step
,
584 enum target_signal signo
));
586 /* External function prototypes that can't be easily included in any
587 header file because the args are typedefs in system include files. */
589 extern void supply_gregset
PARAMS ((gregset_t
*));
591 extern void fill_gregset
PARAMS ((gregset_t
*, int));
594 extern void supply_fpregset
PARAMS ((fpregset_t
*));
596 extern void fill_fpregset
PARAMS ((fpregset_t
*, int));
603 find_procinfo -- convert a process id to a struct procinfo
607 static struct procinfo * find_procinfo (pid_t pid, int okfail);
611 Given a process id, look it up in the procinfo chain. Returns
612 a struct procinfo *. If can't find pid, then call error(),
613 unless okfail is set, in which case, return NULL;
616 static struct procinfo
*
617 find_procinfo (pid
, okfail
)
621 struct procinfo
*procinfo
;
623 for (procinfo
= procinfo_list
; procinfo
; procinfo
= procinfo
->next
)
624 if (procinfo
->pid
== pid
)
630 error ("procfs (find_procinfo): Couldn't locate pid %d", pid
);
637 current_procinfo -- convert inferior_pid to a struct procinfo
641 static struct procinfo * current_procinfo;
645 Looks up inferior_pid in the procinfo chain. Always returns a
646 struct procinfo *. If process can't be found, we error() out.
649 #define current_procinfo find_procinfo (inferior_pid, 0)
655 add_fd -- Add the fd to the poll/select list
659 static void add_fd (struct procinfo *);
663 Add the fd of the supplied procinfo to the list of fds used for
664 poll/select operations.
671 if (num_poll_list
<= 0)
672 poll_list
= (struct pollfd
*) xmalloc (sizeof (struct pollfd
));
674 poll_list
= (struct pollfd
*) xrealloc (poll_list
,
676 * sizeof (struct pollfd
));
677 poll_list
[num_poll_list
].fd
= pi
->ctl_fd
;
679 poll_list
[num_poll_list
].events
= POLLWRNORM
;
681 poll_list
[num_poll_list
].events
= POLLPRI
;
693 for (i
= 0; i
< num_poll_list
; i
++)
695 if (poll_list
[i
].fd
== pi
->ctl_fd
)
697 if (i
!= num_poll_list
- 1)
698 memcpy (poll_list
+ i
, poll_list
+ i
+ 1,
699 (num_poll_list
- i
- 1) * sizeof (struct pollfd
));
703 if (num_poll_list
== 0)
706 poll_list
= (struct pollfd
*) xrealloc (poll_list
,
708 * sizeof (struct pollfd
));
718 procfs_read_status - get procfs fd status
722 static int procfs_read_status (pi) struct procinfo *pi;
726 Given a pointer to a procinfo struct, get the status of
727 the status_fd in the appropriate way. Returns 0 on failure,
732 procfs_read_status (pi
)
735 #ifdef PROCFS_USE_READ_WRITE
736 if ((lseek (pi
->status_fd
, 0, SEEK_SET
) < 0) ||
737 (read (pi
->status_fd
, (char *) &pi
->prstatus
,
738 sizeof (gdb_prstatus_t
)) != sizeof (gdb_prstatus_t
)))
740 if (ioctl (pi
->status_fd
, PIOCSTATUS
, &pi
->prstatus
) < 0)
751 procfs_write_pcwstop - send a PCWSTOP to procfs fd
755 static int procfs_write_pcwstop (pi) struct procinfo *pi;
759 Given a pointer to a procinfo struct, send a PCWSTOP to
760 the ctl_fd in the appropriate way. Returns 0 on failure,
765 procfs_write_pcwstop (pi
)
768 #ifdef PROCFS_USE_READ_WRITE
770 if (write (pi
->ctl_fd
, (char *) &cmd
, sizeof (long)) < 0)
772 if (ioctl (pi
->ctl_fd
, PIOCWSTOP
, &pi
->prstatus
) < 0)
783 procfs_write_pckill - send a kill to procfs fd
787 static void procfs_write_pckill (pi) struct procinfo *pi;
791 Given a pointer to a procinfo struct, send a kill to
792 the ctl_fd in the appropriate way. Returns 0 on failure,
797 procfs_write_pckill (pi
)
800 #ifdef PROCFS_USE_READ_WRITE
801 struct proc_ctl pctl
;
804 write (pi
->ctl_fd
, &pctl
, sizeof (struct proc_ctl
));
807 ioctl (pi
->ctl_fd
, PIOCKILL
, &signo
);
811 static struct procinfo
*
820 set_sigint_trap (); /* Causes SIGINT to be passed on to the
827 num_fds
= poll (poll_list
, num_poll_list
, -1);
830 if (num_fds
< 0 && errno
== EINTR
)
832 print_sys_errmsg ("poll failed", errno
);
833 error ("Poll failed, returned %d", num_fds
);
835 #else /* LOSING_POLL */
836 pi
= current_procinfo
;
838 while (!procfs_write_pcwstop (pi
))
842 /* Process exited. */
843 pi
->prstatus
.pr_flags
= 0;
846 else if (errno
!= EINTR
)
848 print_sys_errmsg (pi
->pathname
, errno
);
849 error ("procfs_write_pcwstop failed");
853 #endif /* LOSING_POLL */
855 clear_sigint_trap ();
860 for (i
= 0; i
< num_poll_list
&& num_fds
> 0; i
++)
862 if ((poll_list
[i
].revents
& (POLLWRNORM
|POLLPRI
|POLLERR
|POLLHUP
|POLLNVAL
)) == 0)
864 for (pi
= procinfo_list
; pi
; pi
= pi
->next
)
866 if (poll_list
[i
].fd
== pi
->ctl_fd
)
868 if (!procfs_read_status(pi
))
870 print_sys_errmsg (pi
->pathname
, errno
);
871 error ("procfs_read_status failed");
880 error ("wait_fd: Couldn't find procinfo for fd %d\n",
883 #endif /* LOSING_POLL */
892 lookupdesc -- translate a value to a summary desc string
896 static char *lookupdesc (struct trans *transp, unsigned int val);
900 Given a pointer to a translation table and a value to be translated,
901 lookup the desc string and return it.
905 lookupdesc (transp
, val
)
906 struct trans
*transp
;
911 for (desc
= NULL
; transp
-> name
!= NULL
; transp
++)
913 if (transp
-> value
== val
)
915 desc
= transp
-> desc
;
920 /* Didn't find a translation for the specified value, set a default one. */
933 lookupname -- translate a value to symbolic name
937 static char *lookupname (struct trans *transp, unsigned int val,
942 Given a pointer to a translation table, a value to be translated,
943 and a default prefix to return if the value can't be translated,
944 match the value with one of the translation table entries and
945 return a pointer to the symbolic name.
947 If no match is found it just returns the value as a printable string,
948 with the given prefix. The previous such value, if any, is freed
953 lookupname (transp
, val
, prefix
)
954 struct trans
*transp
;
961 for (name
= NULL
; transp
-> name
!= NULL
; transp
++)
963 if (transp
-> value
== val
)
965 name
= transp
-> name
;
970 /* Didn't find a translation for the specified value, build a default
971 one using the specified prefix and return it. The lifetime of
972 the value is only until the next one is needed. */
980 locbuf
= xmalloc (strlen (prefix
) + 16);
981 sprintf (locbuf
, "%s %u", prefix
, val
);
993 static char locbuf
[32];
995 for (scp
= siginfo_table
; scp
-> codename
!= NULL
; scp
++)
997 if ((scp
-> signo
== sip
-> si_signo
) &&
998 (scp
-> code
== sip
-> si_code
))
1000 name
= scp
-> codename
;
1006 sprintf (locbuf
, "sigcode %u", sip
-> si_signo
);
1016 struct sigcode
*scp
;
1019 for (scp
= siginfo_table
; scp
-> codename
!= NULL
; scp
++)
1021 if ((scp
-> signo
== sip
-> si_signo
) &&
1022 (scp
-> code
== sip
-> si_code
))
1030 desc
= "Unrecognized signal or trap use";
1039 syscallname - translate a system call number into a system call name
1043 char *syscallname (int syscallnum)
1047 Given a system call number, translate it into the printable name
1048 of a system call, or into "syscall <num>" if it is an unknown
1053 syscallname (syscallnum
)
1056 static char locbuf
[32];
1058 if (syscallnum
>= 0 && syscallnum
< MAX_SYSCALLS
1059 && syscall_table
[syscallnum
] != NULL
)
1060 return syscall_table
[syscallnum
];
1063 sprintf (locbuf
, "syscall %u", syscallnum
);
1072 init_syscall_table - initialize syscall translation table
1076 void init_syscall_table (void)
1080 Dynamically initialize the translation table to convert system
1081 call numbers into printable system call names. Done once per
1082 gdb run, on initialization.
1086 This is awfully ugly, but preprocessor tricks to make it prettier
1087 tend to be nonportable.
1091 init_syscall_table ()
1093 #if defined (SYS_exit)
1094 syscall_table
[SYS_exit
] = "exit";
1096 #if defined (SYS_fork)
1097 syscall_table
[SYS_fork
] = "fork";
1099 #if defined (SYS_read)
1100 syscall_table
[SYS_read
] = "read";
1102 #if defined (SYS_write)
1103 syscall_table
[SYS_write
] = "write";
1105 #if defined (SYS_open)
1106 syscall_table
[SYS_open
] = "open";
1108 #if defined (SYS_close)
1109 syscall_table
[SYS_close
] = "close";
1111 #if defined (SYS_wait)
1112 syscall_table
[SYS_wait
] = "wait";
1114 #if defined (SYS_creat)
1115 syscall_table
[SYS_creat
] = "creat";
1117 #if defined (SYS_link)
1118 syscall_table
[SYS_link
] = "link";
1120 #if defined (SYS_unlink)
1121 syscall_table
[SYS_unlink
] = "unlink";
1123 #if defined (SYS_exec)
1124 syscall_table
[SYS_exec
] = "exec";
1126 #if defined (SYS_execv)
1127 syscall_table
[SYS_execv
] = "execv";
1129 #if defined (SYS_execve)
1130 syscall_table
[SYS_execve
] = "execve";
1132 #if defined (SYS_chdir)
1133 syscall_table
[SYS_chdir
] = "chdir";
1135 #if defined (SYS_time)
1136 syscall_table
[SYS_time
] = "time";
1138 #if defined (SYS_mknod)
1139 syscall_table
[SYS_mknod
] = "mknod";
1141 #if defined (SYS_chmod)
1142 syscall_table
[SYS_chmod
] = "chmod";
1144 #if defined (SYS_chown)
1145 syscall_table
[SYS_chown
] = "chown";
1147 #if defined (SYS_brk)
1148 syscall_table
[SYS_brk
] = "brk";
1150 #if defined (SYS_stat)
1151 syscall_table
[SYS_stat
] = "stat";
1153 #if defined (SYS_lseek)
1154 syscall_table
[SYS_lseek
] = "lseek";
1156 #if defined (SYS_getpid)
1157 syscall_table
[SYS_getpid
] = "getpid";
1159 #if defined (SYS_mount)
1160 syscall_table
[SYS_mount
] = "mount";
1162 #if defined (SYS_umount)
1163 syscall_table
[SYS_umount
] = "umount";
1165 #if defined (SYS_setuid)
1166 syscall_table
[SYS_setuid
] = "setuid";
1168 #if defined (SYS_getuid)
1169 syscall_table
[SYS_getuid
] = "getuid";
1171 #if defined (SYS_stime)
1172 syscall_table
[SYS_stime
] = "stime";
1174 #if defined (SYS_ptrace)
1175 syscall_table
[SYS_ptrace
] = "ptrace";
1177 #if defined (SYS_alarm)
1178 syscall_table
[SYS_alarm
] = "alarm";
1180 #if defined (SYS_fstat)
1181 syscall_table
[SYS_fstat
] = "fstat";
1183 #if defined (SYS_pause)
1184 syscall_table
[SYS_pause
] = "pause";
1186 #if defined (SYS_utime)
1187 syscall_table
[SYS_utime
] = "utime";
1189 #if defined (SYS_stty)
1190 syscall_table
[SYS_stty
] = "stty";
1192 #if defined (SYS_gtty)
1193 syscall_table
[SYS_gtty
] = "gtty";
1195 #if defined (SYS_access)
1196 syscall_table
[SYS_access
] = "access";
1198 #if defined (SYS_nice)
1199 syscall_table
[SYS_nice
] = "nice";
1201 #if defined (SYS_statfs)
1202 syscall_table
[SYS_statfs
] = "statfs";
1204 #if defined (SYS_sync)
1205 syscall_table
[SYS_sync
] = "sync";
1207 #if defined (SYS_kill)
1208 syscall_table
[SYS_kill
] = "kill";
1210 #if defined (SYS_fstatfs)
1211 syscall_table
[SYS_fstatfs
] = "fstatfs";
1213 #if defined (SYS_pgrpsys)
1214 syscall_table
[SYS_pgrpsys
] = "pgrpsys";
1216 #if defined (SYS_xenix)
1217 syscall_table
[SYS_xenix
] = "xenix";
1219 #if defined (SYS_dup)
1220 syscall_table
[SYS_dup
] = "dup";
1222 #if defined (SYS_pipe)
1223 syscall_table
[SYS_pipe
] = "pipe";
1225 #if defined (SYS_times)
1226 syscall_table
[SYS_times
] = "times";
1228 #if defined (SYS_profil)
1229 syscall_table
[SYS_profil
] = "profil";
1231 #if defined (SYS_plock)
1232 syscall_table
[SYS_plock
] = "plock";
1234 #if defined (SYS_setgid)
1235 syscall_table
[SYS_setgid
] = "setgid";
1237 #if defined (SYS_getgid)
1238 syscall_table
[SYS_getgid
] = "getgid";
1240 #if defined (SYS_signal)
1241 syscall_table
[SYS_signal
] = "signal";
1243 #if defined (SYS_msgsys)
1244 syscall_table
[SYS_msgsys
] = "msgsys";
1246 #if defined (SYS_sys3b)
1247 syscall_table
[SYS_sys3b
] = "sys3b";
1249 #if defined (SYS_sysi86)
1250 syscall_table
[SYS_sysi86
] = "sysi86";
1252 #if defined (SYS_acct)
1253 syscall_table
[SYS_acct
] = "acct";
1255 #if defined (SYS_shmsys)
1256 syscall_table
[SYS_shmsys
] = "shmsys";
1258 #if defined (SYS_semsys)
1259 syscall_table
[SYS_semsys
] = "semsys";
1261 #if defined (SYS_ioctl)
1262 syscall_table
[SYS_ioctl
] = "ioctl";
1264 #if defined (SYS_uadmin)
1265 syscall_table
[SYS_uadmin
] = "uadmin";
1267 #if defined (SYS_utssys)
1268 syscall_table
[SYS_utssys
] = "utssys";
1270 #if defined (SYS_fsync)
1271 syscall_table
[SYS_fsync
] = "fsync";
1273 #if defined (SYS_umask)
1274 syscall_table
[SYS_umask
] = "umask";
1276 #if defined (SYS_chroot)
1277 syscall_table
[SYS_chroot
] = "chroot";
1279 #if defined (SYS_fcntl)
1280 syscall_table
[SYS_fcntl
] = "fcntl";
1282 #if defined (SYS_ulimit)
1283 syscall_table
[SYS_ulimit
] = "ulimit";
1285 #if defined (SYS_rfsys)
1286 syscall_table
[SYS_rfsys
] = "rfsys";
1288 #if defined (SYS_rmdir)
1289 syscall_table
[SYS_rmdir
] = "rmdir";
1291 #if defined (SYS_mkdir)
1292 syscall_table
[SYS_mkdir
] = "mkdir";
1294 #if defined (SYS_getdents)
1295 syscall_table
[SYS_getdents
] = "getdents";
1297 #if defined (SYS_sysfs)
1298 syscall_table
[SYS_sysfs
] = "sysfs";
1300 #if defined (SYS_getmsg)
1301 syscall_table
[SYS_getmsg
] = "getmsg";
1303 #if defined (SYS_putmsg)
1304 syscall_table
[SYS_putmsg
] = "putmsg";
1306 #if defined (SYS_poll)
1307 syscall_table
[SYS_poll
] = "poll";
1309 #if defined (SYS_lstat)
1310 syscall_table
[SYS_lstat
] = "lstat";
1312 #if defined (SYS_symlink)
1313 syscall_table
[SYS_symlink
] = "symlink";
1315 #if defined (SYS_readlink)
1316 syscall_table
[SYS_readlink
] = "readlink";
1318 #if defined (SYS_setgroups)
1319 syscall_table
[SYS_setgroups
] = "setgroups";
1321 #if defined (SYS_getgroups)
1322 syscall_table
[SYS_getgroups
] = "getgroups";
1324 #if defined (SYS_fchmod)
1325 syscall_table
[SYS_fchmod
] = "fchmod";
1327 #if defined (SYS_fchown)
1328 syscall_table
[SYS_fchown
] = "fchown";
1330 #if defined (SYS_sigprocmask)
1331 syscall_table
[SYS_sigprocmask
] = "sigprocmask";
1333 #if defined (SYS_sigsuspend)
1334 syscall_table
[SYS_sigsuspend
] = "sigsuspend";
1336 #if defined (SYS_sigaltstack)
1337 syscall_table
[SYS_sigaltstack
] = "sigaltstack";
1339 #if defined (SYS_sigaction)
1340 syscall_table
[SYS_sigaction
] = "sigaction";
1342 #if defined (SYS_sigpending)
1343 syscall_table
[SYS_sigpending
] = "sigpending";
1345 #if defined (SYS_context)
1346 syscall_table
[SYS_context
] = "context";
1348 #if defined (SYS_evsys)
1349 syscall_table
[SYS_evsys
] = "evsys";
1351 #if defined (SYS_evtrapret)
1352 syscall_table
[SYS_evtrapret
] = "evtrapret";
1354 #if defined (SYS_statvfs)
1355 syscall_table
[SYS_statvfs
] = "statvfs";
1357 #if defined (SYS_fstatvfs)
1358 syscall_table
[SYS_fstatvfs
] = "fstatvfs";
1360 #if defined (SYS_nfssys)
1361 syscall_table
[SYS_nfssys
] = "nfssys";
1363 #if defined (SYS_waitsys)
1364 syscall_table
[SYS_waitsys
] = "waitsys";
1366 #if defined (SYS_sigsendsys)
1367 syscall_table
[SYS_sigsendsys
] = "sigsendsys";
1369 #if defined (SYS_hrtsys)
1370 syscall_table
[SYS_hrtsys
] = "hrtsys";
1372 #if defined (SYS_acancel)
1373 syscall_table
[SYS_acancel
] = "acancel";
1375 #if defined (SYS_async)
1376 syscall_table
[SYS_async
] = "async";
1378 #if defined (SYS_priocntlsys)
1379 syscall_table
[SYS_priocntlsys
] = "priocntlsys";
1381 #if defined (SYS_pathconf)
1382 syscall_table
[SYS_pathconf
] = "pathconf";
1384 #if defined (SYS_mincore)
1385 syscall_table
[SYS_mincore
] = "mincore";
1387 #if defined (SYS_mmap)
1388 syscall_table
[SYS_mmap
] = "mmap";
1390 #if defined (SYS_mprotect)
1391 syscall_table
[SYS_mprotect
] = "mprotect";
1393 #if defined (SYS_munmap)
1394 syscall_table
[SYS_munmap
] = "munmap";
1396 #if defined (SYS_fpathconf)
1397 syscall_table
[SYS_fpathconf
] = "fpathconf";
1399 #if defined (SYS_vfork)
1400 syscall_table
[SYS_vfork
] = "vfork";
1402 #if defined (SYS_fchdir)
1403 syscall_table
[SYS_fchdir
] = "fchdir";
1405 #if defined (SYS_readv)
1406 syscall_table
[SYS_readv
] = "readv";
1408 #if defined (SYS_writev)
1409 syscall_table
[SYS_writev
] = "writev";
1411 #if defined (SYS_xstat)
1412 syscall_table
[SYS_xstat
] = "xstat";
1414 #if defined (SYS_lxstat)
1415 syscall_table
[SYS_lxstat
] = "lxstat";
1417 #if defined (SYS_fxstat)
1418 syscall_table
[SYS_fxstat
] = "fxstat";
1420 #if defined (SYS_xmknod)
1421 syscall_table
[SYS_xmknod
] = "xmknod";
1423 #if defined (SYS_clocal)
1424 syscall_table
[SYS_clocal
] = "clocal";
1426 #if defined (SYS_setrlimit)
1427 syscall_table
[SYS_setrlimit
] = "setrlimit";
1429 #if defined (SYS_getrlimit)
1430 syscall_table
[SYS_getrlimit
] = "getrlimit";
1432 #if defined (SYS_lchown)
1433 syscall_table
[SYS_lchown
] = "lchown";
1435 #if defined (SYS_memcntl)
1436 syscall_table
[SYS_memcntl
] = "memcntl";
1438 #if defined (SYS_getpmsg)
1439 syscall_table
[SYS_getpmsg
] = "getpmsg";
1441 #if defined (SYS_putpmsg)
1442 syscall_table
[SYS_putpmsg
] = "putpmsg";
1444 #if defined (SYS_rename)
1445 syscall_table
[SYS_rename
] = "rename";
1447 #if defined (SYS_uname)
1448 syscall_table
[SYS_uname
] = "uname";
1450 #if defined (SYS_setegid)
1451 syscall_table
[SYS_setegid
] = "setegid";
1453 #if defined (SYS_sysconfig)
1454 syscall_table
[SYS_sysconfig
] = "sysconfig";
1456 #if defined (SYS_adjtime)
1457 syscall_table
[SYS_adjtime
] = "adjtime";
1459 #if defined (SYS_systeminfo)
1460 syscall_table
[SYS_systeminfo
] = "systeminfo";
1462 #if defined (SYS_seteuid)
1463 syscall_table
[SYS_seteuid
] = "seteuid";
1465 #if defined (SYS_sproc)
1466 syscall_table
[SYS_sproc
] = "sproc";
1468 #if defined (SYS_keyctl)
1469 syscall_table
[SYS_keyctl
] = "keyctl";
1471 #if defined (SYS_secsys)
1472 syscall_table
[SYS_secsys
] = "secsys";
1474 #if defined (SYS_filepriv)
1475 syscall_table
[SYS_filepriv
] = "filepriv";
1477 #if defined (SYS_procpriv)
1478 syscall_table
[SYS_procpriv
] = "procpriv";
1480 #if defined (SYS_devstat)
1481 syscall_table
[SYS_devstat
] = "devstat";
1483 #if defined (SYS_aclipc)
1484 syscall_table
[SYS_aclipc
] = "aclipc";
1486 #if defined (SYS_fdevstat)
1487 syscall_table
[SYS_fdevstat
] = "fdevstat";
1489 #if defined (SYS_flvlfile)
1490 syscall_table
[SYS_flvlfile
] = "flvlfile";
1492 #if defined (SYS_lvlfile)
1493 syscall_table
[SYS_lvlfile
] = "lvlfile";
1495 #if defined (SYS_lvlequal)
1496 syscall_table
[SYS_lvlequal
] = "lvlequal";
1498 #if defined (SYS_lvlproc)
1499 syscall_table
[SYS_lvlproc
] = "lvlproc";
1501 #if defined (SYS_lvlipc)
1502 syscall_table
[SYS_lvlipc
] = "lvlipc";
1504 #if defined (SYS_acl)
1505 syscall_table
[SYS_acl
] = "acl";
1507 #if defined (SYS_auditevt)
1508 syscall_table
[SYS_auditevt
] = "auditevt";
1510 #if defined (SYS_auditctl)
1511 syscall_table
[SYS_auditctl
] = "auditctl";
1513 #if defined (SYS_auditdmp)
1514 syscall_table
[SYS_auditdmp
] = "auditdmp";
1516 #if defined (SYS_auditlog)
1517 syscall_table
[SYS_auditlog
] = "auditlog";
1519 #if defined (SYS_auditbuf)
1520 syscall_table
[SYS_auditbuf
] = "auditbuf";
1522 #if defined (SYS_lvldom)
1523 syscall_table
[SYS_lvldom
] = "lvldom";
1525 #if defined (SYS_lvlvfs)
1526 syscall_table
[SYS_lvlvfs
] = "lvlvfs";
1528 #if defined (SYS_mkmld)
1529 syscall_table
[SYS_mkmld
] = "mkmld";
1531 #if defined (SYS_mldmode)
1532 syscall_table
[SYS_mldmode
] = "mldmode";
1534 #if defined (SYS_secadvise)
1535 syscall_table
[SYS_secadvise
] = "secadvise";
1537 #if defined (SYS_online)
1538 syscall_table
[SYS_online
] = "online";
1540 #if defined (SYS_setitimer)
1541 syscall_table
[SYS_setitimer
] = "setitimer";
1543 #if defined (SYS_getitimer)
1544 syscall_table
[SYS_getitimer
] = "getitimer";
1546 #if defined (SYS_gettimeofday)
1547 syscall_table
[SYS_gettimeofday
] = "gettimeofday";
1549 #if defined (SYS_settimeofday)
1550 syscall_table
[SYS_settimeofday
] = "settimeofday";
1552 #if defined (SYS_lwpcreate)
1553 syscall_table
[SYS_lwpcreate
] = "lwpcreate";
1555 #if defined (SYS_lwpexit)
1556 syscall_table
[SYS_lwpexit
] = "lwpexit";
1558 #if defined (SYS_lwpwait)
1559 syscall_table
[SYS_lwpwait
] = "lwpwait";
1561 #if defined (SYS_lwpself)
1562 syscall_table
[SYS_lwpself
] = "lwpself";
1564 #if defined (SYS_lwpinfo)
1565 syscall_table
[SYS_lwpinfo
] = "lwpinfo";
1567 #if defined (SYS_lwpprivate)
1568 syscall_table
[SYS_lwpprivate
] = "lwpprivate";
1570 #if defined (SYS_processor_bind)
1571 syscall_table
[SYS_processor_bind
] = "processor_bind";
1573 #if defined (SYS_processor_exbind)
1574 syscall_table
[SYS_processor_exbind
] = "processor_exbind";
1576 #if defined (SYS_prepblock)
1577 syscall_table
[SYS_prepblock
] = "prepblock";
1579 #if defined (SYS_block)
1580 syscall_table
[SYS_block
] = "block";
1582 #if defined (SYS_rdblock)
1583 syscall_table
[SYS_rdblock
] = "rdblock";
1585 #if defined (SYS_unblock)
1586 syscall_table
[SYS_unblock
] = "unblock";
1588 #if defined (SYS_cancelblock)
1589 syscall_table
[SYS_cancelblock
] = "cancelblock";
1591 #if defined (SYS_pread)
1592 syscall_table
[SYS_pread
] = "pread";
1594 #if defined (SYS_pwrite)
1595 syscall_table
[SYS_pwrite
] = "pwrite";
1597 #if defined (SYS_truncate)
1598 syscall_table
[SYS_truncate
] = "truncate";
1600 #if defined (SYS_ftruncate)
1601 syscall_table
[SYS_ftruncate
] = "ftruncate";
1603 #if defined (SYS_lwpkill)
1604 syscall_table
[SYS_lwpkill
] = "lwpkill";
1606 #if defined (SYS_sigwait)
1607 syscall_table
[SYS_sigwait
] = "sigwait";
1609 #if defined (SYS_fork1)
1610 syscall_table
[SYS_fork1
] = "fork1";
1612 #if defined (SYS_forkall)
1613 syscall_table
[SYS_forkall
] = "forkall";
1615 #if defined (SYS_modload)
1616 syscall_table
[SYS_modload
] = "modload";
1618 #if defined (SYS_moduload)
1619 syscall_table
[SYS_moduload
] = "moduload";
1621 #if defined (SYS_modpath)
1622 syscall_table
[SYS_modpath
] = "modpath";
1624 #if defined (SYS_modstat)
1625 syscall_table
[SYS_modstat
] = "modstat";
1627 #if defined (SYS_modadm)
1628 syscall_table
[SYS_modadm
] = "modadm";
1630 #if defined (SYS_getksym)
1631 syscall_table
[SYS_getksym
] = "getksym";
1633 #if defined (SYS_lwpsuspend)
1634 syscall_table
[SYS_lwpsuspend
] = "lwpsuspend";
1636 #if defined (SYS_lwpcontinue)
1637 syscall_table
[SYS_lwpcontinue
] = "lwpcontinue";
1639 #if defined (SYS_priocntllst)
1640 syscall_table
[SYS_priocntllst
] = "priocntllst";
1642 #if defined (SYS_sleep)
1643 syscall_table
[SYS_sleep
] = "sleep";
1645 #if defined (SYS_lwp_sema_wait)
1646 syscall_table
[SYS_lwp_sema_wait
] = "lwp_sema_wait";
1648 #if defined (SYS_lwp_sema_post)
1649 syscall_table
[SYS_lwp_sema_post
] = "lwp_sema_post";
1651 #if defined (SYS_lwp_sema_trywait)
1652 syscall_table
[SYS_lwp_sema_trywait
] = "lwp_sema_trywait";
1660 procfs_kill_inferior - kill any currently inferior
1664 void procfs_kill_inferior (void)
1668 Kill any current inferior.
1672 Kills even attached inferiors. Presumably the user has already
1673 been prompted that the inferior is an attached one rather than
1674 one started by gdb. (FIXME?)
1679 procfs_kill_inferior ()
1681 target_mourn_inferior ();
1688 unconditionally_kill_inferior - terminate the inferior
1692 static void unconditionally_kill_inferior (struct procinfo *)
1696 Kill the specified inferior.
1700 A possibly useful enhancement would be to first try sending
1701 the inferior a terminate signal, politely asking it to commit
1702 suicide, before we murder it (we could call that
1703 politely_kill_inferior()).
1708 unconditionally_kill_inferior (pi
)
1709 struct procinfo
*pi
;
1712 struct proc_ctl pctl
;
1714 ppid
= pi
->prstatus
.pr_ppid
;
1716 #ifdef PROCFS_NEED_CLEAR_CURSIG_FOR_KILL
1717 /* Alpha OSF/1-3.x procfs needs a clear of the current signal
1718 before the PIOCKILL, otherwise it might generate a corrupted core
1719 file for the inferior. */
1720 ioctl (pi
->ctl_fd
, PIOCSSIG
, NULL
);
1722 #ifdef PROCFS_NEED_PIOCSSIG_FOR_KILL
1723 /* Alpha OSF/1-2.x procfs needs a PIOCSSIG call with a SIGKILL signal
1724 to kill the inferior, otherwise it might remain stopped with a
1726 We do not check the result of the PIOCSSIG, the inferior might have
1729 struct siginfo newsiginfo
;
1731 memset ((char *) &newsiginfo
, 0, sizeof (newsiginfo
));
1732 newsiginfo
.si_signo
= SIGKILL
;
1733 newsiginfo
.si_code
= 0;
1734 newsiginfo
.si_errno
= 0;
1735 newsiginfo
.si_pid
= getpid ();
1736 newsiginfo
.si_uid
= getuid ();
1737 ioctl (pi
->ctl_fd
, PIOCSSIG
, &newsiginfo
);
1739 #else /* PROCFS_NEED_PIOCSSIG_FOR_KILL */
1740 procfs_write_pckill (pi
);
1741 #endif /* PROCFS_NEED_PIOCSSIG_FOR_KILL */
1743 close_proc_file (pi
);
1745 /* Only wait() for our direct children. Our grandchildren zombies are killed
1746 by the death of their parents. */
1748 if (ppid
== getpid())
1756 procfs_xfer_memory -- copy data to or from inferior memory space
1760 int procfs_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len,
1761 int dowrite, struct target_ops target)
1765 Copy LEN bytes to/from inferior's memory starting at MEMADDR
1766 from/to debugger memory starting at MYADDR. Copy from inferior
1767 if DOWRITE is zero or to inferior if DOWRITE is nonzero.
1769 Returns the length copied, which is either the LEN argument or
1770 zero. This xfer function does not do partial moves, since procfs_ops
1771 doesn't allow memory operations to cross below us in the target stack
1776 The /proc interface makes this an almost trivial task.
1780 procfs_xfer_memory (memaddr
, myaddr
, len
, dowrite
, target
)
1785 struct target_ops
*target
; /* ignored */
1788 struct procinfo
*pi
;
1790 pi
= current_procinfo
;
1792 if (lseek(pi
->as_fd
, (off_t
) memaddr
, SEEK_SET
) == (off_t
) memaddr
)
1796 nbytes
= write (pi
->as_fd
, myaddr
, len
);
1800 nbytes
= read (pi
->as_fd
, myaddr
, len
);
1814 procfs_store_registers -- copy register values back to inferior
1818 void procfs_store_registers (int regno)
1822 Store our current register values back into the inferior. If
1823 REGNO is -1 then store all the register, otherwise store just
1824 the value specified by REGNO.
1828 If we are storing only a single register, we first have to get all
1829 the current values from the process, overwrite the desired register
1830 in the gregset with the one we want from gdb's registers, and then
1831 send the whole set back to the process. For writing all the
1832 registers, all we have to do is generate the gregset and send it to
1835 Also note that the process has to be stopped on an event of interest
1836 for this to work, which basically means that it has to have been
1837 run under the control of one of the other /proc ioctl calls and not
1838 ptrace. Since we don't use ptrace anyway, we don't worry about this
1839 fine point, but it is worth noting for future reference.
1841 Gdb is confused about what this function is supposed to return.
1842 Some versions return a value, others return nothing. Some are
1843 declared to return a value and actually return nothing. Gdb ignores
1844 anything returned. (FIXME)
1849 procfs_store_registers (regno
)
1852 struct procinfo
*pi
;
1853 #ifdef PROCFS_USE_READ_WRITE
1854 struct greg_ctl greg
;
1855 struct fpreg_ctl fpreg
;
1858 pi
= current_procinfo
;
1860 #ifdef PROCFS_USE_READ_WRITE
1863 procfs_read_status (pi
);
1864 memcpy ((char *) &greg
.gregset
,
1865 (char *) &pi
->prstatus
.pr_lwp
.pr_context
.uc_mcontext
.gregs
,
1866 sizeof (gregset_t
));
1868 fill_gregset (&greg
.gregset
, regno
);
1870 write (pi
->ctl_fd
, &greg
, sizeof (greg
));
1871 #else /* PROCFS_USE_READ_WRITE */
1874 ioctl (pi
->ctl_fd
, PIOCGREG
, &pi
->gregset
.gregset
);
1876 fill_gregset (&pi
->gregset
.gregset
, regno
);
1877 ioctl (pi
->ctl_fd
, PIOCSREG
, &pi
->gregset
.gregset
);
1878 #endif /* PROCFS_USE_READ_WRITE */
1880 #if defined (FP0_REGNUM)
1882 /* Now repeat everything using the floating point register set, if the
1883 target has floating point hardware. Since we ignore the returned value,
1884 we'll never know whether it worked or not anyway. */
1886 #ifdef PROCFS_USE_READ_WRITE
1889 procfs_read_status (pi
);
1890 memcpy ((char *) &fpreg
.fpregset
,
1891 (char *) &pi
->prstatus
.pr_lwp
.pr_context
.uc_mcontext
.fpregs
,
1892 sizeof (fpregset_t
));
1894 fill_fpregset (&fpreg
.fpregset
, regno
);
1895 fpreg
.cmd
= PCSFPREG
;
1896 write (pi
->ctl_fd
, &fpreg
, sizeof (fpreg
));
1897 #else /* PROCFS_USE_READ_WRITE */
1900 ioctl (pi
->ctl_fd
, PIOCGFPREG
, &pi
->fpregset
.fpregset
);
1902 fill_fpregset (&pi
->fpregset
.fpregset
, regno
);
1903 ioctl (pi
->ctl_fd
, PIOCSFPREG
, &pi
->fpregset
.fpregset
);
1904 #endif /* PROCFS_USE_READ_WRITE */
1906 #endif /* FP0_REGNUM */
1914 create_procinfo - initialize access to a /proc entry
1918 struct procinfo * create_procinfo (int pid)
1922 Allocate a procinfo structure, open the /proc file and then set up the
1923 set of signals and faults that are to be traced. Returns a pointer to
1924 the new procinfo structure.
1928 If proc_init_failed ever gets called, control returns to the command
1929 processing loop via the standard error handling code.
1933 static struct procinfo
*
1934 create_procinfo (pid
)
1937 struct procinfo
*pi
;
1938 struct sig_ctl sctl
;
1939 struct flt_ctl fctl
;
1941 pi
= find_procinfo (pid
, 1);
1943 return pi
; /* All done! It already exists */
1945 pi
= (struct procinfo
*) xmalloc (sizeof (struct procinfo
));
1947 if (!open_proc_file (pid
, pi
, O_RDWR
, 1))
1948 proc_init_failed (pi
, "can't open process file");
1950 /* open_proc_file may modify pid. */
1954 /* Add new process to process info list */
1956 pi
->next
= procinfo_list
;
1959 add_fd (pi
); /* Add to list for poll/select */
1961 pi
->num_syscall_handlers
= 0;
1962 pi
->syscall_handlers
= NULL
;
1964 prfillset (&sctl
.sigset
);
1965 notice_signals (pi
, &sctl
);
1966 prfillset (&fctl
.fltset
);
1967 prdelset (&fctl
.fltset
, FLTPAGE
);
1968 #else /* UNIXWARE */
1969 memset ((char *) &pi
->prrun
, 0, sizeof (pi
->prrun
));
1970 prfillset (&pi
->prrun
.pr_trace
);
1971 procfs_notice_signals (pid
);
1972 prfillset (&pi
->prrun
.pr_fault
);
1973 prdelset (&pi
->prrun
.pr_fault
, FLTPAGE
);
1974 #ifdef PROCFS_DONT_TRACE_FAULTS
1975 premptyset (&pi
->prrun
.pr_fault
);
1977 #endif /* UNIXWARE */
1979 if (!procfs_read_status (pi
))
1980 proc_init_failed (pi
, "procfs_read_status failed");
1982 /* A bug in Solaris (2.5 at least) causes PIOCWSTOP to hang on LWPs that are
1983 already stopped, even if they all have PR_ASYNC set. */
1986 if (!(pi
->prstatus
.pr_flags
& PR_STOPPED
))
1988 if (!procfs_write_pcwstop (pi
))
1989 proc_init_failed (pi
, "procfs_write_pcwstop failed");
1991 #ifdef PROCFS_USE_READ_WRITE
1992 fctl
.cmd
= PCSFAULT
;
1993 if (write (pi
->ctl_fd
, (char *) &fctl
, sizeof (struct flt_ctl
)) < 0)
1994 proc_init_failed (pi
, "PCSFAULT failed");
1996 if (ioctl (pi
->ctl_fd
, PIOCSFAULT
, &pi
->prrun
.pr_fault
) < 0)
1997 proc_init_failed (pi
, "PIOCSFAULT failed");
2007 procfs_exit_handler - handle entry into the _exit syscall
2011 int procfs_exit_handler (pi, syscall_num, why, rtnvalp, statvalp)
2015 This routine is called when an inferior process enters the _exit()
2016 system call. It continues the process, and then collects the exit
2017 status and pid which are returned in *statvalp and *rtnvalp. After
2018 that it returns non-zero to indicate that procfs_wait should wake up.
2021 There is probably a better way to do this.
2026 procfs_exit_handler (pi
, syscall_num
, why
, rtnvalp
, statvalp
)
2027 struct procinfo
*pi
;
2033 pi
->prrun
.pr_flags
= PRCFAULT
;
2035 if (ioctl (pi
->ctl_fd
, PIOCRUN
, &pi
->prrun
) != 0)
2036 perror_with_name (pi
->pathname
);
2038 *rtnvalp
= wait (statvalp
);
2049 procfs_exec_handler - handle exit from the exec family of syscalls
2053 int procfs_exec_handler (pi, syscall_num, why, rtnvalp, statvalp)
2057 This routine is called when an inferior process is about to finish any
2058 of the exec() family of system calls. It pretends that we got a
2059 SIGTRAP (for compatibility with ptrace behavior), and returns non-zero
2060 to tell procfs_wait to wake up.
2063 This need for compatibility with ptrace is questionable. In the
2064 future, it shouldn't be necessary.
2069 procfs_exec_handler (pi
, syscall_num
, why
, rtnvalp
, statvalp
)
2070 struct procinfo
*pi
;
2076 *statvalp
= (SIGTRAP
<< 8) | 0177;
2081 #if defined(SYS_sproc) && !defined(UNIXWARE)
2082 /* IRIX lwp creation system call */
2088 procfs_sproc_handler - handle exit from the sproc syscall
2092 int procfs_sproc_handler (pi, syscall_num, why, rtnvalp, statvalp)
2096 This routine is called when an inferior process is about to finish an
2097 sproc() system call. This is the system call that IRIX uses to create
2098 a lightweight process. When the target process gets this event, we can
2099 look at rval1 to find the new child processes ID, and create a new
2100 procinfo struct from that.
2102 After that, it pretends that we got a SIGTRAP, and returns non-zero
2103 to tell procfs_wait to wake up. Subsequently, wait_for_inferior gets
2104 woken up, sees the new process and continues it.
2107 We actually never see the child exiting from sproc because we will
2108 shortly stop the child with PIOCSTOP, which is then registered as the
2113 procfs_sproc_handler (pi
, syscall_num
, why
, rtnvalp
, statvalp
)
2114 struct procinfo
*pi
;
2120 /* We've just detected the completion of an sproc system call. Now we need to
2121 setup a procinfo struct for this thread, and notify the thread system of the
2124 /* If sproc failed, then nothing interesting happened. Continue the process
2125 and go back to sleep. */
2127 if (pi
->prstatus
.pr_errno
!= 0)
2129 pi
->prrun
.pr_flags
&= PRSTEP
;
2130 pi
->prrun
.pr_flags
|= PRCFAULT
;
2132 if (ioctl (pi
->ctl_fd
, PIOCRUN
, &pi
->prrun
) != 0)
2133 perror_with_name (pi
->pathname
);
2138 /* At this point, the new thread is stopped at it's first instruction, and
2139 the parent is stopped at the exit from sproc. */
2141 /* Notify the caller of the arrival of a new thread. */
2142 create_procinfo (pi
->prstatus
.pr_rval1
);
2144 *rtnvalp
= pi
->prstatus
.pr_rval1
;
2145 *statvalp
= (SIGTRAP
<< 8) | 0177;
2154 procfs_fork_handler - handle exit from the fork syscall
2158 int procfs_fork_handler (pi, syscall_num, why, rtnvalp, statvalp)
2162 This routine is called when an inferior process is about to finish a
2163 fork() system call. We will open up the new process, and then close
2164 it, which releases it from the clutches of the debugger.
2166 After that, we continue the target process as though nothing had
2170 This is necessary for IRIX because we have to set PR_FORK in order
2171 to catch the creation of lwps (via sproc()). When an actual fork
2172 occurs, it becomes necessary to reset the forks debugger flags and
2173 continue it because we can't hack multiple processes yet.
2177 procfs_fork_handler (pi
, syscall_num
, why
, rtnvalp
, statvalp
)
2178 struct procinfo
*pi
;
2184 struct procinfo
*pitemp
;
2186 /* At this point, we've detected the completion of a fork (or vfork) call in
2187 our child. The grandchild is also stopped because we set inherit-on-fork
2188 earlier. (Note that nobody has the grandchilds' /proc file open at this
2189 point.) We will release the grandchild from the debugger by opening it's
2190 /proc file and then closing it. Since run-on-last-close is set, the
2191 grandchild continues on its' merry way. */
2194 pitemp
= create_procinfo (pi
->prstatus
.pr_rval1
);
2196 close_proc_file (pitemp
);
2198 if (ioctl (pi
->ctl_fd
, PIOCRUN
, &pi
->prrun
) != 0)
2199 perror_with_name (pi
->pathname
);
2203 #endif /* SYS_sproc && !UNIXWARE */
2209 procfs_init_inferior - initialize target vector and access to a
2214 int procfs_init_inferior (int pid)
2218 When gdb starts an inferior, this function is called in the parent
2219 process immediately after the fork. It waits for the child to stop
2220 on the return from the exec system call (the child itself takes care
2221 of ensuring that this is set up), then sets up the set of signals
2222 and faults that are to be traced. Returns the pid, which may have had
2223 the thread-id added to it.
2227 If proc_init_failed ever gets called, control returns to the command
2228 processing loop via the standard error handling code.
2233 procfs_init_inferior (pid
)
2236 struct procinfo
*pip
;
2238 push_target (&procfs_ops
);
2240 pip
= create_procinfo (pid
);
2243 procfs_set_syscall_trap (pip
, SYS_exit
, PROCFS_SYSCALL_ENTRY
,
2244 procfs_exit_handler
);
2247 procfs_set_syscall_trap (pip
, SYS_exec
, PROCFS_SYSCALL_EXIT
,
2248 procfs_exec_handler
);
2251 procfs_set_syscall_trap (pip
, SYS_execv
, PROCFS_SYSCALL_EXIT
,
2252 procfs_exec_handler
);
2255 procfs_set_syscall_trap (pip
, SYS_execve
, PROCFS_SYSCALL_EXIT
,
2256 procfs_exec_handler
);
2258 #endif /* PIOCSSPCACT */
2260 /* Setup traps on exit from sproc() */
2263 procfs_set_syscall_trap (pip
, SYS_sproc
, PROCFS_SYSCALL_EXIT
,
2264 procfs_sproc_handler
);
2265 procfs_set_syscall_trap (pip
, SYS_fork
, PROCFS_SYSCALL_EXIT
,
2266 procfs_fork_handler
);
2268 procfs_set_syscall_trap (pip
, SYS_vfork
, PROCFS_SYSCALL_EXIT
,
2269 procfs_fork_handler
);
2271 /* Turn on inherit-on-fork flag so that all children of the target process
2272 start with tracing flags set. This allows us to trap lwp creation. Note
2273 that we also have to trap on fork and vfork in order to disable all tracing
2274 in the targets child processes. */
2276 modify_inherit_on_fork_flag (pip
->ctl_fd
, 1);
2279 #ifdef SYS_lwp_create
2280 procfs_set_syscall_trap (pip
, SYS_lwp_create
, PROCFS_SYSCALL_EXIT
,
2281 procfs_lwp_creation_handler
);
2284 /* create_procinfo may change the pid, so we have to update inferior_pid
2285 here before calling other gdb routines that need the right pid. */
2290 add_thread (pip
-> pid
); /* Setup initial thread */
2292 #ifdef START_INFERIOR_TRAPS_EXPECTED
2293 startup_inferior (START_INFERIOR_TRAPS_EXPECTED
);
2295 /* One trap to exec the shell, one to exec the program being debugged. */
2296 startup_inferior (2);
2306 procfs_notice_signals
2310 static void procfs_notice_signals (int pid);
2314 When the user changes the state of gdb's signal handling via the
2315 "handle" command, this function gets called to see if any change
2316 in the /proc interface is required. It is also called internally
2317 by other /proc interface functions to initialize the state of
2318 the traced signal set.
2320 One thing it does is that signals for which the state is "nostop",
2321 "noprint", and "pass", have their trace bits reset in the pr_trace
2322 field, so that they are no longer traced. This allows them to be
2323 delivered directly to the inferior without the debugger ever being
2328 procfs_notice_signals (pid
)
2331 struct procinfo
*pi
;
2332 struct sig_ctl sctl
;
2334 pi
= find_procinfo (pid
, 0);
2337 premptyset (&sctl
.sigset
);
2339 sctl
.sigset
= &pi
->prrun
.pr_trace
;
2342 notice_signals (pi
, &sctl
);
2346 notice_signals (pi
, sctl
)
2347 struct procinfo
*pi
;
2348 struct sig_ctl
*sctl
;
2352 for (signo
= 0; signo
< NSIG
; signo
++)
2354 if (signal_stop_state (target_signal_from_host (signo
)) == 0 &&
2355 signal_print_state (target_signal_from_host (signo
)) == 0 &&
2356 signal_pass_state (target_signal_from_host (signo
)) == 1)
2358 prdelset (&sctl
->sigset
, signo
);
2362 praddset (&sctl
->sigset
, signo
);
2365 #ifdef PROCFS_USE_READ_WRITE
2366 sctl
->cmd
= PCSTRACE
;
2367 if (write (pi
->ctl_fd
, (char *) sctl
, sizeof (struct sig_ctl
)) < 0)
2369 if (ioctl (pi
->ctl_fd
, PIOCSTRACE
, &sctl
->sigset
))
2372 print_sys_errmsg ("PIOCSTRACE failed", errno
);
2380 proc_set_exec_trap -- arrange for exec'd child to halt at startup
2384 void proc_set_exec_trap (void)
2388 This function is called in the child process when starting up
2389 an inferior, prior to doing the exec of the actual inferior.
2390 It sets the child process's exitset to make exit from the exec
2391 system call an event of interest to stop on, and then simply
2392 returns. The child does the exec, the system call returns, and
2393 the child stops at the first instruction, ready for the gdb
2394 parent process to take control of it.
2398 We need to use all local variables since the child may be sharing
2399 it's data space with the parent, if vfork was used rather than
2402 Also note that we want to turn off the inherit-on-fork flag in
2403 the child process so that any grand-children start with all
2404 tracing flags cleared.
2408 proc_set_exec_trap ()
2410 struct sys_ctl exitset
;
2411 struct sys_ctl entryset
;
2412 char procname
[MAX_PROC_NAME_SIZE
];
2415 sprintf (procname
, CTL_PROC_NAME_FMT
, getpid ());
2417 if ((fd
= open (procname
, O_WRONLY
)) < 0)
2419 if ((fd
= open (procname
, O_RDWR
)) < 0)
2423 gdb_flush (gdb_stderr
);
2426 premptyset (&exitset
.sysset
);
2427 premptyset (&entryset
.sysset
);
2430 /* Under Alpha OSF/1 we have to use a PIOCSSPCACT ioctl to trace
2431 exits from exec system calls because of the user level loader.
2432 Starting with OSF/1-4.0, tracing the entry to the exit system
2433 call no longer works. So we have to use PRFS_STOPTERM to trace
2434 termination of the inferior. */
2438 if (ioctl (fd
, PIOCGSPCACT
, &prfs_flags
) < 0)
2441 gdb_flush (gdb_stderr
);
2444 prfs_flags
|= PRFS_STOPEXEC
| PRFS_STOPTERM
;
2445 if (ioctl (fd
, PIOCSSPCACT
, &prfs_flags
) < 0)
2448 gdb_flush (gdb_stderr
);
2452 #else /* PIOCSSPCACT */
2454 Not all systems with /proc have all the exec* syscalls with the same
2455 names. On the SGI, for example, there is no SYS_exec, but there
2456 *is* a SYS_execv. So, we try to account for that. */
2459 praddset (&exitset
.sysset
, SYS_exec
);
2462 praddset (&exitset
.sysset
, SYS_execve
);
2465 praddset (&exitset
.sysset
, SYS_execv
);
2468 #ifdef PROCFS_USE_READ_WRITE
2469 exitset
.cmd
= PCSEXIT
;
2470 if (write (fd
, (char *) &exitset
, sizeof (struct sys_ctl
)) < 0)
2472 if (ioctl (fd
, PIOCSEXIT
, &exitset
.sysset
) < 0)
2476 gdb_flush (gdb_stderr
);
2480 praddset (&entryset
.sysset
, SYS_exit
);
2482 #ifdef PROCFS_USE_READ_WRITE
2483 entryset
.cmd
= PCSENTRY
;
2484 if (write (fd
, (char *) &entryset
, sizeof (struct sys_ctl
)) < 0)
2486 if (ioctl (fd
, PIOCSENTRY
, &entryset
.sysset
) < 0)
2490 gdb_flush (gdb_stderr
);
2493 #endif /* PIOCSSPCACT */
2495 /* Turn off inherit-on-fork flag so that all grand-children of gdb
2496 start with tracing flags cleared. */
2498 modify_inherit_on_fork_flag (fd
, 0);
2500 /* Turn on run-on-last-close flag so that this process will not hang
2501 if GDB goes away for some reason. */
2503 modify_run_on_last_close_flag (fd
, 1);
2508 struct proc_ctl pctl
;
2510 /* Solaris needs this to make procfs treat all threads seperately. Without
2511 this, all threads halt whenever something happens to any thread. Since
2512 GDB wants to control all this itself, it needs to set PR_ASYNC. */
2514 pr_flags
= PR_ASYNC
;
2515 #ifdef PROCFS_USE_READ_WRITE
2517 pctl
.data
= PR_FORK
|PR_ASYNC
;
2518 write (fd
, (char *) &pctl
, sizeof (struct proc_ctl
));
2520 ioctl (fd
, PIOCSET
, &pr_flags
);
2523 #endif /* PR_ASYNC */
2530 proc_iterate_over_mappings -- call function for every mapped space
2534 int proc_iterate_over_mappings (int (*func)())
2538 Given a pointer to a function, call that function for every
2539 mapped address space, passing it an open file descriptor for
2540 the file corresponding to that mapped address space (if any)
2541 and the base address of the mapped space. Quit when we hit
2542 the end of the mappings or the function returns nonzero.
2547 proc_iterate_over_mappings (func
)
2548 int (*func
) PARAMS ((int, CORE_ADDR
));
2555 struct procinfo
*pi
;
2558 pi
= current_procinfo
;
2560 if (fstat (pi
->map_fd
, &sbuf
) < 0)
2563 nmap
= sbuf
.st_size
/ sizeof (prmap_t
);
2564 prmaps
= (prmap_t
*) alloca (nmap
* sizeof(prmap_t
));
2565 if ((lseek (pi
->map_fd
, 0, SEEK_SET
) == 0) &&
2566 (read (pi
->map_fd
, (char *) prmaps
, nmap
* sizeof (prmap_t
)) ==
2567 (nmap
* sizeof (prmap_t
))))
2570 for (prmap
= prmaps
; i
< nmap
&& funcstat
== 0; ++prmap
, ++i
)
2572 char name
[sizeof ("/proc/1234567890/object") +
2573 sizeof (prmap
->pr_mapname
)];
2574 sprintf (name
, "/proc/%d/object/%s", pi
->pid
, prmap
->pr_mapname
);
2575 if ((fd
= open (name
, O_RDONLY
)) == -1)
2580 funcstat
= (*func
) (fd
, (CORE_ADDR
) prmap
->pr_vaddr
);
2586 #else /* UNIXWARE */
2588 proc_iterate_over_mappings (func
)
2589 int (*func
) PARAMS ((int, CORE_ADDR
));
2594 struct prmap
*prmaps
;
2595 struct prmap
*prmap
;
2596 struct procinfo
*pi
;
2598 pi
= current_procinfo
;
2600 if (ioctl (pi
->map_fd
, PIOCNMAP
, &nmap
) == 0)
2602 prmaps
= (struct prmap
*) alloca ((nmap
+ 1) * sizeof (*prmaps
));
2603 if (ioctl (pi
->map_fd
, PIOCMAP
, prmaps
) == 0)
2605 for (prmap
= prmaps
; prmap
-> pr_size
&& funcstat
== 0; ++prmap
)
2607 fd
= proc_address_to_fd (pi
, (CORE_ADDR
) prmap
-> pr_vaddr
, 0);
2608 funcstat
= (*func
) (fd
, (CORE_ADDR
) prmap
-> pr_vaddr
);
2615 #endif /* UNIXWARE */
2617 #if 0 /* Currently unused */
2622 proc_base_address -- find base address for segment containing address
2626 CORE_ADDR proc_base_address (CORE_ADDR addr)
2630 Given an address of a location in the inferior, find and return
2631 the base address of the mapped segment containing that address.
2633 This is used for example, by the shared library support code,
2634 where we have the pc value for some location in the shared library
2635 where we are stopped, and need to know the base address of the
2636 segment containing that address.
2640 proc_base_address (addr
)
2644 struct prmap
*prmaps
;
2645 struct prmap
*prmap
;
2646 CORE_ADDR baseaddr
= 0;
2647 struct procinfo
*pi
;
2649 pi
= current_procinfo
;
2651 if (ioctl (pi
->map_fd
, PIOCNMAP
, &nmap
) == 0)
2653 prmaps
= (struct prmap
*) alloca ((nmap
+ 1) * sizeof (*prmaps
));
2654 if (ioctl (pi
->map_fd
, PIOCMAP
, prmaps
) == 0)
2656 for (prmap
= prmaps
; prmap
-> pr_size
; ++prmap
)
2658 if ((prmap
-> pr_vaddr
<= (caddr_t
) addr
) &&
2659 (prmap
-> pr_vaddr
+ prmap
-> pr_size
> (caddr_t
) addr
))
2661 baseaddr
= (CORE_ADDR
) prmap
-> pr_vaddr
;
2676 proc_address_to_fd -- return open fd for file mapped to address
2680 int proc_address_to_fd (struct procinfo *pi, CORE_ADDR addr, complain)
2684 Given an address in the current inferior's address space, use the
2685 /proc interface to find an open file descriptor for the file that
2686 this address was mapped in from. Return -1 if there is no current
2687 inferior. Print a warning message if there is an inferior but
2688 the address corresponds to no file (IE a bogus address).
2693 proc_address_to_fd (pi
, addr
, complain
)
2694 struct procinfo
*pi
;
2700 if ((fd
= ioctl (pi
->ctl_fd
, PIOCOPENM
, (caddr_t
*) &addr
)) < 0)
2704 print_sys_errmsg (pi
->pathname
, errno
);
2705 warning ("can't find mapped file for address 0x%x", addr
);
2712 /* Attach to process PID, then initialize for debugging it
2713 and wait for the trace-trap that results from attaching. */
2716 procfs_attach (args
, from_tty
)
2724 error_no_arg ("process-id to attach");
2728 if (pid
== getpid()) /* Trying to masturbate? */
2729 error ("I refuse to debug myself!");
2733 exec_file
= (char *) get_exec_file (0);
2736 printf_unfiltered ("Attaching to program `%s', %s\n", exec_file
, target_pid_to_str (pid
));
2738 printf_unfiltered ("Attaching to %s\n", target_pid_to_str (pid
));
2740 gdb_flush (gdb_stdout
);
2743 inferior_pid
= pid
= do_attach (pid
);
2744 push_target (&procfs_ops
);
2748 /* Take a program previously attached to and detaches it.
2749 The program resumes execution and will no longer stop
2750 on signals, etc. We'd better not have left any breakpoints
2751 in the program or it'll die when it hits one. For this
2752 to work, it may be necessary for the process to have been
2753 previously attached. It *might* work if the program was
2754 started via the normal ptrace (PTRACE_TRACEME). */
2757 procfs_detach (args
, from_tty
)
2765 char *exec_file
= get_exec_file (0);
2768 printf_unfiltered ("Detaching from program: %s %s\n",
2769 exec_file
, target_pid_to_str (inferior_pid
));
2770 gdb_flush (gdb_stdout
);
2773 siggnal
= atoi (args
);
2775 do_detach (siggnal
);
2777 unpush_target (&procfs_ops
); /* Pop out of handling an inferior */
2780 /* Get ready to modify the registers array. On machines which store
2781 individual registers, this doesn't need to do anything. On machines
2782 which store all the registers in one fell swoop, this makes sure
2783 that registers contains all the registers from the program being
2787 procfs_prepare_to_store ()
2789 #ifdef CHILD_PREPARE_TO_STORE
2790 CHILD_PREPARE_TO_STORE ();
2794 /* Print status information about what we're accessing. */
2797 procfs_files_info (ignore
)
2798 struct target_ops
*ignore
;
2800 printf_unfiltered ("\tUsing the running image of %s %s via /proc.\n",
2801 attach_flag
? "attached": "child", target_pid_to_str (inferior_pid
));
2806 procfs_open (arg
, from_tty
)
2810 error ("Use the \"run\" command to start a Unix child process.");
2817 do_attach -- attach to an already existing process
2821 int do_attach (int pid)
2825 Attach to an already existing process with the specified process
2826 id. If the process is not already stopped, query whether to
2831 The option of stopping at attach time is specific to the /proc
2832 versions of gdb. Versions using ptrace force the attachee
2833 to stop. (I have changed this version to do so, too. All you
2834 have to do is "continue" to make it go on. -- gnu@cygnus.com)
2842 struct procinfo
*pi
;
2843 struct sig_ctl sctl
;
2844 struct flt_ctl fctl
;
2846 pi
= (struct procinfo
*) xmalloc (sizeof (struct procinfo
));
2848 if (!open_proc_file (pid
, pi
, O_RDWR
, 1))
2851 perror_with_name (pi
->pathname
);
2857 /* Add new process to process info list */
2859 pi
->next
= procinfo_list
;
2862 add_fd (pi
); /* Add to list for poll/select */
2864 /* Get current status of process and if it is not already stopped,
2865 then stop it. Remember whether or not it was stopped when we first
2867 if (!procfs_read_status (pi
))
2869 print_sys_errmsg (pi
->pathname
, errno
);
2870 close_proc_file (pi
);
2871 error ("procfs_read_status failed");
2874 if (pi
->prstatus
.pr_lwp
.pr_flags
& (PR_STOPPED
| PR_ISTOP
))
2876 if (pi
->prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
))
2879 pi
->was_stopped
= 1;
2883 pi
->was_stopped
= 0;
2884 if (1 || query ("Process is currently running, stop it? "))
2887 /* Make it run again when we close it. */
2889 modify_run_on_last_close_flag (pi
->ctl_fd
, 1);
2891 #ifdef PROCFS_USE_READ_WRITE
2893 if (write (pi
->ctl_fd
, (char *) &cmd
, sizeof (long)) < 0)
2895 if (ioctl (pi
->ctl_fd
, PIOCSTOP
, &pi
->prstatus
) < 0)
2898 print_sys_errmsg (pi
->pathname
, errno
);
2899 close_proc_file (pi
);
2900 error ("PIOCSTOP failed");
2903 if (!procfs_read_status (pi
))
2905 print_sys_errmsg (pi
->pathname
, errno
);
2906 close_proc_file (pi
);
2907 error ("procfs_read_status failed");
2910 pi
->nopass_next_sigstop
= 1;
2914 printf_unfiltered ("Ok, gdb will wait for %s to stop.\n", target_pid_to_str (pid
));
2918 /* Remember some things about the inferior that we will, or might, change
2919 so that we can restore them when we detach. */
2920 #ifdef PROCFS_USE_READ_WRITE
2921 memcpy ((char *) &pi
->saved_trace
.sigset
,
2922 (char *) &pi
->prstatus
.pr_sigtrace
, sizeof (sigset_t
));
2923 memcpy ((char *) &pi
->saved_fltset
.fltset
,
2924 (char *) &pi
->prstatus
.pr_flttrace
, sizeof (fltset_t
));
2925 memcpy ((char *) &pi
->saved_entryset
.sysset
,
2926 (char *) &pi
->prstatus
.pr_sysentry
, sizeof (sysset_t
));
2927 memcpy ((char *) &pi
->saved_exitset
.sysset
,
2928 (char *) &pi
->prstatus
.pr_sysexit
, sizeof (sysset_t
));
2930 /* Set up trace and fault sets, as gdb expects them. */
2932 prfillset (&sctl
.sigset
);
2933 notice_signals (pi
, &sctl
);
2934 prfillset (&fctl
.fltset
);
2935 prdelset (&fctl
.fltset
, FLTPAGE
);
2937 fctl
.cmd
= PCSFAULT
;
2938 if (write (pi
->ctl_fd
, (char *) &fctl
, sizeof (struct flt_ctl
)) < 0)
2939 print_sys_errmsg ("PCSFAULT failed", errno
);
2940 #else /* PROCFS_USE_READ_WRITE */
2941 ioctl (pi
->ctl_fd
, PIOCGTRACE
, &pi
->saved_trace
.sigset
);
2942 ioctl (pi
->ctl_fd
, PIOCGHOLD
, &pi
->saved_sighold
.sigset
);
2943 ioctl (pi
->ctl_fd
, PIOCGFAULT
, &pi
->saved_fltset
.fltset
);
2944 ioctl (pi
->ctl_fd
, PIOCGENTRY
, &pi
->saved_entryset
.sysset
);
2945 ioctl (pi
->ctl_fd
, PIOCGEXIT
, &pi
->saved_exitset
.sysset
);
2947 /* Set up trace and fault sets, as gdb expects them. */
2949 memset (&pi
->prrun
, 0, sizeof (pi
->prrun
));
2950 prfillset (&pi
->prrun
.pr_trace
);
2951 procfs_notice_signals (pid
);
2952 prfillset (&pi
->prrun
.pr_fault
);
2953 prdelset (&pi
->prrun
.pr_fault
, FLTPAGE
);
2955 #ifdef PROCFS_DONT_TRACE_FAULTS
2956 premptyset (&pi
->prrun
.pr_fault
);
2959 if (ioctl (pi
->ctl_fd
, PIOCSFAULT
, &pi
->prrun
.pr_fault
))
2961 print_sys_errmsg ("PIOCSFAULT failed", errno
);
2963 if (ioctl (pi
->ctl_fd
, PIOCSTRACE
, &pi
->prrun
.pr_trace
))
2965 print_sys_errmsg ("PIOCSTRACE failed", errno
);
2967 #endif /* PROCFS_USE_READ_WRITE */
2976 do_detach -- detach from an attached-to process
2980 void do_detach (int signal)
2984 Detach from the current attachee.
2986 If signal is non-zero, the attachee is started running again and sent
2987 the specified signal.
2989 If signal is zero and the attachee was not already stopped when we
2990 attached to it, then we make it runnable again when we detach.
2992 Otherwise, we query whether or not to make the attachee runnable
2993 again, since we may simply want to leave it in the state it was in
2996 We report any problems, but do not consider them errors, since we
2997 MUST detach even if some things don't seem to go right. This may not
2998 be the ideal situation. (FIXME).
3005 struct procinfo
*pi
;
3007 pi
= current_procinfo
;
3011 set_proc_siginfo (pi
, signal
);
3013 #ifdef PROCFS_USE_READ_WRITE
3014 pi
->saved_exitset
.cmd
= PCSEXIT
;
3015 if (write (pi
->ctl_fd
, (char *) &pi
->saved_exitset
,
3016 sizeof (struct sys_ctl
)) < 0)
3018 if (ioctl (pi
->ctl_fd
, PIOCSEXIT
, &pi
->saved_exitset
.sysset
) < 0)
3021 print_sys_errmsg (pi
->pathname
, errno
);
3022 printf_unfiltered ("PIOCSEXIT failed.\n");
3024 #ifdef PROCFS_USE_READ_WRITE
3025 pi
->saved_entryset
.cmd
= PCSENTRY
;
3026 if (write (pi
->ctl_fd
, (char *) &pi
->saved_entryset
,
3027 sizeof (struct sys_ctl
)) < 0)
3029 if (ioctl (pi
->ctl_fd
, PIOCSENTRY
, &pi
->saved_entryset
.sysset
) < 0)
3032 print_sys_errmsg (pi
->pathname
, errno
);
3033 printf_unfiltered ("PIOCSENTRY failed.\n");
3035 #ifdef PROCFS_USE_READ_WRITE
3036 pi
->saved_trace
.cmd
= PCSTRACE
;
3037 if (write (pi
->ctl_fd
, (char *) &pi
->saved_trace
,
3038 sizeof (struct sig_ctl
)) < 0)
3040 if (ioctl (pi
->ctl_fd
, PIOCSTRACE
, &pi
->saved_trace
.sigset
) < 0)
3043 print_sys_errmsg (pi
->pathname
, errno
);
3044 printf_unfiltered ("PIOCSTRACE failed.\n");
3047 if (ioctl (pi
->ctl_fd
, PIOCSHOLD
, &pi
->saved_sighold
.sigset
) < 0)
3049 print_sys_errmsg (pi
->pathname
, errno
);
3050 printf_unfiltered ("PIOSCHOLD failed.\n");
3053 #ifdef PROCFS_USE_READ_WRITE
3054 pi
->saved_fltset
.cmd
= PCSFAULT
;
3055 if (write (pi
->ctl_fd
, (char *) &pi
->saved_fltset
,
3056 sizeof (struct flt_ctl
)) < 0)
3058 if (ioctl (pi
->ctl_fd
, PIOCSFAULT
, &pi
->saved_fltset
.fltset
) < 0)
3061 print_sys_errmsg (pi
->pathname
, errno
);
3062 printf_unfiltered ("PIOCSFAULT failed.\n");
3064 if (!procfs_read_status (pi
))
3066 print_sys_errmsg (pi
->pathname
, errno
);
3067 printf_unfiltered ("procfs_read_status failed.\n");
3072 if (signal
|| (pi
->prstatus
.pr_lwp
.pr_flags
& (PR_STOPPED
| PR_ISTOP
)))
3074 if (signal
|| (pi
->prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
)))
3078 struct proc_ctl pctl
;
3080 if (signal
|| !pi
->was_stopped
||
3081 query ("Was stopped when attached, make it runnable again? "))
3083 /* Clear any pending signal if we want to detach without
3086 set_proc_siginfo (pi
, signal
);
3088 /* Clear any fault that might have stopped it. */
3089 #ifdef PROCFS_USE_READ_WRITE
3091 if (write (pi
->ctl_fd
, (char *) &cmd
, sizeof (long)) < 0)
3093 if (ioctl (pi
->ctl_fd
, PIOCCFAULT
, 0))
3096 print_sys_errmsg (pi
->pathname
, errno
);
3097 printf_unfiltered ("PIOCCFAULT failed.\n");
3100 /* Make it run again when we close it. */
3102 modify_run_on_last_close_flag (pi
->ctl_fd
, 1);
3106 close_proc_file (pi
);
3110 /* emulate wait() as much as possible.
3111 Wait for child to do something. Return pid of child, or -1 in case
3112 of error; store status in *OURSTATUS.
3114 Not sure why we can't
3115 just use wait(), but it seems to have problems when applied to a
3116 process being controlled with the /proc interface.
3118 We have a race problem here with no obvious solution. We need to let
3119 the inferior run until it stops on an event of interest, which means
3120 that we need to use the PIOCWSTOP ioctl. However, we cannot use this
3121 ioctl if the process is already stopped on something that is not an
3122 event of interest, or the call will hang indefinitely. Thus we first
3123 use PIOCSTATUS to see if the process is not stopped. If not, then we
3124 use PIOCWSTOP. But during the window between the two, if the process
3125 stops for any reason that is not an event of interest (such as a job
3126 control signal) then gdb will hang. One possible workaround is to set
3127 an alarm to wake up every minute of so and check to see if the process
3128 is still running, and if so, then reissue the PIOCWSTOP. But this is
3129 a real kludge, so has not been implemented. FIXME: investigate
3132 FIXME: Investigate why wait() seems to have problems with programs
3133 being control by /proc routines. */
3136 procfs_wait (pid
, ourstatus
)
3138 struct target_waitstatus
*ourstatus
;
3145 struct procinfo
*pi
;
3146 struct proc_ctl pctl
;
3149 if (pid
!= -1) /* Non-specific process? */
3152 for (pi
= procinfo_list
; pi
; pi
= pi
->next
)
3167 for (pi
= procinfo_list
; pi
; pi
= pi
->next
)
3168 if (pi
->pid
== pid
&& pi
->had_event
)
3172 if (!pi
&& !checkerr
)
3176 if (!checkerr
&& !(pi
->prstatus
.pr_lwp
.pr_flags
& (PR_STOPPED
| PR_ISTOP
)))
3178 if (!checkerr
&& !(pi
->prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
)))
3181 if (!procfs_write_pcwstop (pi
))
3188 if (errno
== ENOENT
)
3190 rtnval
= wait (&statval
);
3191 if (rtnval
!= inferior_pid
)
3193 print_sys_errmsg (pi
->pathname
, errno
);
3194 error ("procfs_write_pcwstop, wait failed, returned %d", rtnval
);
3200 print_sys_errmsg (pi
->pathname
, errno
);
3201 error ("PIOCSTATUS or PIOCWSTOP failed.");
3205 else if (pi
->prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
))
3208 rtnval
= pi
->prstatus
.pr_pid
;
3209 why
= pi
->prstatus
.pr_lwp
.pr_why
;
3210 what
= pi
->prstatus
.pr_lwp
.pr_what
;
3213 why
= pi
->prstatus
.pr_why
;
3214 what
= pi
->prstatus
.pr_what
;
3220 statval
= (what
<< 8) | 0177;
3226 int found_handler
= 0;
3228 for (i
= 0; i
< pi
->num_syscall_handlers
; i
++)
3229 if (pi
->syscall_handlers
[i
].syscall_num
== what
)
3232 if (!pi
->syscall_handlers
[i
].func (pi
, what
, why
,
3240 if (why
== PR_SYSENTRY
)
3241 error ("PR_SYSENTRY, unhandled system call %d", what
);
3243 error ("PR_SYSEXIT, unhandled system call %d", what
);
3247 case (short)PR_DEAD
:
3251 /* The inferior process is about to terminate.
3252 pr_what has the process's exit or return value.
3253 A PIOCRUN ioctl must be used to restart the process so it
3254 can finish exiting. */
3256 #ifdef PROCFS_USE_READ_WRITE
3258 pctl
.data
= PRCFAULT
;
3259 if (write (pi
->ctl_fd
, (char *) &pctl
, sizeof (struct proc_ctl
)) < 0)
3261 pi
->prrun
.pr_flags
= PRCFAULT
;
3262 if (ioctl (pi
->ctl_fd
, PIOCRUN
, &pi
->prrun
) != 0)
3264 perror_with_name (pi
->pathname
);
3266 if (wait (&dummy
) < 0)
3268 statval
= pi
->prstatus
.pr_what
;
3273 statval
= (SIGSTOP
<< 8) | 0177;
3276 statval
= (what
<< 8) | 0177;
3283 statval
= (SIGTRAP
<< 8) | 0177;
3288 statval
= (SIGTRAP
<< 8) | 0177;
3291 #ifndef FAULTED_USE_SIGINFO
3292 /* Irix, contrary to the documentation, fills in 0 for si_signo.
3293 Solaris fills in si_signo. I'm not sure about others. */
3296 statval
= (SIGILL
<< 8) | 0177;
3300 statval
= (SIGTRAP
<< 8) | 0177;
3305 statval
= (SIGSEGV
<< 8) | 0177;
3310 statval
= (SIGFPE
<< 8) | 0177;
3312 case FLTPAGE
: /* Recoverable page fault */
3313 #endif /* not FAULTED_USE_SIGINFO */
3315 /* Use the signal which the kernel assigns. This is better than
3316 trying to second-guess it from the fault. In fact, I suspect
3317 that FLTACCESS can be either SIGSEGV or SIGBUS. */
3319 statval
= ((pi
->prstatus
.pr_lwp
.pr_info
.si_signo
) << 8) | 0177;
3321 statval
= ((pi
->prstatus
.pr_info
.si_signo
) << 8) | 0177;
3327 error ("PIOCWSTOP, unknown why %d, what %d", why
, what
);
3329 /* Stop all the other threads when any of them stops. */
3332 struct procinfo
*procinfo
;
3334 for (procinfo
= procinfo_list
; procinfo
; procinfo
= procinfo
->next
)
3336 if (!procinfo
->had_event
)
3338 #ifdef PROCFS_USE_READ_WRITE
3340 if (write (pi
->ctl_fd
, (char *) &cmd
, sizeof (long)) < 0)
3342 print_sys_errmsg (procinfo
->pathname
, errno
);
3343 error ("PCSTOP failed");
3346 /* A bug in Solaris (2.5) causes us to hang when trying to
3347 stop a stopped process. So, we have to check first in
3348 order to avoid the hang. */
3349 if (!procfs_read_status (procinfo
))
3351 print_sys_errmsg (procinfo
->pathname
, errno
);
3352 error ("procfs_read_status failed");
3355 if (!(procinfo
->prstatus
.pr_flags
& PR_STOPPED
))
3356 if (ioctl (procinfo
->ctl_fd
, PIOCSTOP
, &procinfo
->prstatus
) < 0)
3358 print_sys_errmsg (procinfo
->pathname
, errno
);
3359 error ("PIOCSTOP failed");
3368 error ("PIOCWSTOP, stopped for unknown/unhandled reason, flags %#x",
3369 pi
->prstatus
.pr_flags
);
3372 store_waitstatus (ourstatus
, statval
);
3374 if (rtnval
== -1) /* No more children to wait for */
3376 fprintf_unfiltered (gdb_stderr
, "Child process unexpectedly missing.\n");
3377 /* Claim it exited with unknown signal. */
3378 ourstatus
->kind
= TARGET_WAITKIND_SIGNALLED
;
3379 ourstatus
->value
.sig
= TARGET_SIGNAL_UNKNOWN
;
3383 pi
->had_event
= 0; /* Indicate that we've seen this one */
3391 set_proc_siginfo - set a process's current signal info
3395 void set_proc_siginfo (struct procinfo *pip, int signo);
3399 Given a pointer to a process info struct in PIP and a signal number
3400 in SIGNO, set the process's current signal and its associated signal
3401 information. The signal will be delivered to the process immediately
3402 after execution is resumed, even if it is being held. In addition,
3403 this particular delivery will not cause another PR_SIGNALLED stop
3404 even if the signal is being traced.
3406 If we are not delivering the same signal that the prstatus siginfo
3407 struct contains information about, then synthesize a siginfo struct
3408 to match the signal we are doing to deliver, make it of the type
3409 "generated by a user process", and send this synthesized copy. When
3410 used to set the inferior's signal state, this will be required if we
3411 are not currently stopped because of a traced signal, or if we decide
3412 to continue with a different signal.
3414 Note that when continuing the inferior from a stop due to receipt
3415 of a traced signal, we either have set PRCSIG to clear the existing
3416 signal, or we have to call this function to do a PIOCSSIG with either
3417 the existing siginfo struct from pr_info, or one we have synthesized
3418 appropriately for the signal we want to deliver. Otherwise if the
3419 signal is still being traced, the inferior will immediately stop
3422 See siginfo(5) for more details.
3426 set_proc_siginfo (pip
, signo
)
3427 struct procinfo
*pip
;
3430 struct siginfo newsiginfo
;
3431 struct siginfo
*sip
;
3432 struct sigi_ctl sictl
;
3434 #ifdef PROCFS_DONT_PIOCSSIG_CURSIG
3435 /* With Alpha OSF/1 procfs, the kernel gets really confused if it
3436 receives a PIOCSSIG with a signal identical to the current signal,
3437 it messes up the current signal. Work around the kernel bug. */
3439 if (signo
== pip
-> prstatus
.pr_lwp
.pr_cursig
)
3441 if (signo
== pip
-> prstatus
.pr_cursig
)
3447 if (signo
== pip
->prstatus
.pr_lwp
.pr_info
.si_signo
)
3449 memcpy ((char *) &sictl
.siginfo
, (char *) &pip
->prstatus
.pr_lwp
.pr_info
,
3450 sizeof (siginfo_t
));
3453 if (signo
== pip
-> prstatus
.pr_info
.si_signo
)
3455 sip
= &pip
-> prstatus
.pr_info
;
3461 siginfo_t
*sip
= &sictl
.siginfo
;
3462 memset ((char *) sip
, 0, sizeof (siginfo_t
));
3464 memset ((char *) &newsiginfo
, 0, sizeof (newsiginfo
));
3467 sip
-> si_signo
= signo
;
3469 sip
-> si_errno
= 0;
3470 sip
-> si_pid
= getpid ();
3471 sip
-> si_uid
= getuid ();
3473 #ifdef PROCFS_USE_READ_WRITE
3475 if (write (pip
->ctl_fd
, (char *) &sictl
, sizeof (struct sigi_ctl
)) < 0)
3477 if (ioctl (pip
->ctl_fd
, PIOCSSIG
, sip
) < 0)
3480 print_sys_errmsg (pip
-> pathname
, errno
);
3481 warning ("PIOCSSIG failed");
3485 /* Resume execution of process PID. If STEP is nozero, then
3486 just single step it. If SIGNAL is nonzero, restart it with that
3487 signal activated. */
3490 procfs_resume (pid
, step
, signo
)
3493 enum target_signal signo
;
3496 struct procinfo
*pi
, *procinfo
;
3497 struct proc_ctl pctl
;
3499 pi
= find_procinfo (pid
== -1 ? inferior_pid
: pid
, 0);
3504 pctl
.data
= PRCFAULT
;
3506 pi
->prrun
.pr_flags
= PRSTRACE
| PRSFAULT
| PRCFAULT
;
3510 /* It should not be necessary. If the user explicitly changes the value,
3511 value_assign calls write_register_bytes, which writes it. */
3512 /* It may not be absolutely necessary to specify the PC value for
3513 restarting, but to be safe we use the value that gdb considers
3514 to be current. One case where this might be necessary is if the
3515 user explicitly changes the PC value that gdb considers to be
3516 current. FIXME: Investigate if this is necessary or not. */
3518 #ifdef PRSVADDR_BROKEN
3519 /* Can't do this under Solaris running on a Sparc, as there seems to be no
3520 place to put nPC. In fact, if you use this, nPC seems to be set to some
3521 random garbage. We have to rely on the fact that PC and nPC have been
3522 written previously via PIOCSREG during a register flush. */
3524 pi
->prrun
.pr_vaddr
= (caddr_t
) *(int *) ®isters
[REGISTER_BYTE (PC_REGNUM
)];
3525 pi
->prrun
.pr_flags
!= PRSVADDR
;
3529 if (signo
== TARGET_SIGNAL_STOP
&& pi
->nopass_next_sigstop
)
3530 /* When attaching to a child process, if we forced it to stop with
3531 a PIOCSTOP, then we will have set the nopass_next_sigstop flag.
3532 Upon resuming the first time after such a stop, we explicitly
3533 inhibit sending it another SIGSTOP, which would be the normal
3534 result of default signal handling. One potential drawback to
3535 this is that we will also ignore any attempt to by the user
3536 to explicitly continue after the attach with a SIGSTOP. Ultimately
3537 this problem should be dealt with by making the routines that
3538 deal with the inferior a little smarter, and possibly even allow
3539 an inferior to continue running at the same time as gdb. (FIXME?) */
3541 else if (signo
== TARGET_SIGNAL_TSTP
3543 && pi
->prstatus
.pr_lwp
.pr_cursig
== SIGTSTP
3544 && pi
->prstatus
.pr_lwp
.pr_action
.sa_handler
== SIG_DFL
)
3546 && pi
->prstatus
.pr_cursig
== SIGTSTP
3547 && pi
->prstatus
.pr_action
.sa_handler
== SIG_DFL
)
3550 /* We are about to pass the inferior a SIGTSTP whose action is
3551 SIG_DFL. The SIG_DFL action for a SIGTSTP is to stop
3552 (notifying the parent via wait()), and then keep going from the
3553 same place when the parent is ready for you to keep going. So
3554 under the debugger, it should do nothing (as if the program had
3555 been stopped and then later resumed. Under ptrace, this
3556 happens for us, but under /proc, the system obligingly stops
3557 the process, and wait_for_inferior would have no way of
3558 distinguishing that type of stop (which indicates that we
3559 should just start it again), with a stop due to the pr_trace
3560 field of the prrun_t struct.
3562 Note that if the SIGTSTP is being caught, we *do* need to pass it,
3563 because the handler needs to get executed. */
3566 signal_to_pass
= target_signal_to_host (signo
);
3570 set_proc_siginfo (pi
, signal_to_pass
);
3575 pctl
.data
|= PRCSIG
;
3577 pi
->prrun
.pr_flags
|= PRCSIG
;
3580 pi
->nopass_next_sigstop
= 0;
3584 pctl
.data
|= PRSTEP
;
3586 pi
->prrun
.pr_flags
|= PRSTEP
;
3590 /* Don't try to start a process unless it's stopped on an
3591 `event of interest'. Doing so will cause errors. */
3593 #ifdef PROCFS_USE_READ_WRITE
3594 if (write (pi
->ctl_fd
, (char *) &pctl
, sizeof (struct proc_ctl
)) < 0)
3596 if ((pi
->prstatus
.pr_flags
& PR_ISTOP
)
3597 && ioctl (pi
->ctl_fd
, PIOCRUN
, &pi
->prrun
) != 0)
3600 perror_with_name (pi
->pathname
);
3606 /* Continue all the other threads that haven't had an event of
3610 for (procinfo
= procinfo_list
; procinfo
; procinfo
= procinfo
->next
)
3612 if (pi
!= procinfo
&& !procinfo
->had_event
)
3614 #ifdef PROCFS_USE_READ_WRITE
3615 pctl
.data
= PRCFAULT
| PRCSIG
;
3616 if (write (procinfo
->ctl_fd
, (char *) &pctl
,
3617 sizeof (struct proc_ctl
)) < 0)
3619 if (!procfs_read_status (procinfo
))
3621 fprintf_unfiltered(gdb_stderr
, "procfs_read_status failed, errno=%d\n", errno
);
3623 print_sys_errmsg (procinfo
->pathname
, errno
);
3624 error ("PCRUN failed");
3626 procfs_read_status (procinfo
);
3628 procinfo
->prrun
.pr_flags
&= PRSTEP
;
3629 procinfo
->prrun
.pr_flags
|= PRCFAULT
| PRCSIG
;
3630 procfs_read_status (procinfo
);
3632 /* Don't try to start a process unless it's stopped on an
3633 `event of interest'. Doing so will cause errors. */
3635 if ((procinfo
->prstatus
.pr_flags
& PR_ISTOP
)
3636 && ioctl (procinfo
->ctl_fd
, PIOCRUN
, &procinfo
->prrun
) < 0)
3638 if (!procfs_read_status (procinfo
))
3640 fprintf_unfiltered(gdb_stderr
, "procfs_read_status failed, errno=%d\n", errno
);
3642 print_sys_errmsg (procinfo
->pathname
, errno
);
3643 error ("PIOCRUN failed");
3645 procfs_read_status (procinfo
);
3655 procfs_fetch_registers -- fetch current registers from inferior
3659 void procfs_fetch_registers (int regno)
3663 Read the current values of the inferior's registers, both the
3664 general register set and floating point registers (if supported)
3665 and update gdb's idea of their current values.
3670 procfs_fetch_registers (regno
)
3673 struct procinfo
*pi
;
3675 pi
= current_procinfo
;
3678 if (procfs_read_status (pi
))
3680 supply_gregset (&pi
->prstatus
.pr_lwp
.pr_context
.uc_mcontext
.gregs
);
3681 #if defined (FP0_REGNUM)
3682 supply_fpregset (&pi
->prstatus
.pr_lwp
.pr_context
.uc_mcontext
.fpregs
);
3685 #else /* UNIXWARE */
3686 if (ioctl (pi
->ctl_fd
, PIOCGREG
, &pi
->gregset
.gregset
) != -1)
3688 supply_gregset (&pi
->gregset
.gregset
);
3690 #if defined (FP0_REGNUM)
3691 if (ioctl (pi
->ctl_fd
, PIOCGFPREG
, &pi
->fpregset
.fpregset
) != -1)
3693 supply_fpregset (&pi
->fpregset
.fpregset
);
3696 #endif /* UNIXWARE */
3703 proc_init_failed - called whenever /proc access initialization
3708 static void proc_init_failed (struct procinfo *pi, char *why)
3712 This function is called whenever initialization of access to a /proc
3713 entry fails. It prints a suitable error message, does some cleanup,
3714 and then invokes the standard error processing routine which dumps
3715 us back into the command loop.
3719 proc_init_failed (pi
, why
)
3720 struct procinfo
*pi
;
3723 print_sys_errmsg (pi
->pathname
, errno
);
3724 kill (pi
->pid
, SIGKILL
);
3725 close_proc_file (pi
);
3734 close_proc_file - close any currently open /proc entry
3738 static void close_proc_file (struct procinfo *pip)
3742 Close any currently open /proc entry and mark the process information
3743 entry as invalid. In order to ensure that we don't try to reuse any
3744 stale information, the pid, fd, and pathnames are explicitly
3745 invalidated, which may be overkill.
3750 close_proc_file (pip
)
3751 struct procinfo
*pip
;
3753 struct procinfo
*procinfo
;
3755 remove_fd (pip
); /* Remove fd from poll/select list */
3757 close (pip
->ctl_fd
);
3758 #ifdef HAVE_MULTIPLE_PROC_FDS
3760 close (pip
->status_fd
);
3761 close (pip
->map_fd
);
3764 free (pip
-> pathname
);
3766 /* Unlink pip from the procinfo chain. Note pip might not be on the list. */
3768 if (procinfo_list
== pip
)
3769 procinfo_list
= pip
->next
;
3772 for (procinfo
= procinfo_list
; procinfo
; procinfo
= procinfo
->next
)
3774 if (procinfo
->next
== pip
)
3776 procinfo
->next
= pip
->next
;
3788 open_proc_file - open a /proc entry for a given process id
3792 static int open_proc_file (int pid, struct procinfo *pip, int mode)
3796 Given a process id and a mode, close the existing open /proc
3797 entry (if any) and open one for the new process id, in the
3798 specified mode. Once it is open, then mark the local process
3799 information structure as valid, which guarantees that the pid,
3800 fd, and pathname fields match an open /proc entry. Returns
3801 zero if the open fails, nonzero otherwise.
3803 Note that the pathname is left intact, even when the open fails,
3804 so that callers can use it to construct meaningful error messages
3805 rather than just "file open failed".
3807 Note that for Solaris, the process-id also includes an LWP-id, so we
3808 actually attempt to open that. If we are handed a pid with a 0 LWP-id,
3809 then we will ask the kernel what it is and add it to the pid. Hence,
3810 the pid can be changed by us.
3814 open_proc_file (pid
, pip
, mode
, control
)
3816 struct procinfo
*pip
;
3823 pip
-> had_event
= 0;
3824 pip
-> pathname
= xmalloc (MAX_PROC_NAME_SIZE
);
3833 #ifdef HAVE_MULTIPLE_PROC_FDS
3834 sprintf (pip
->pathname
, STATUS_PROC_NAME_FMT
, tmp
);
3835 if ((pip
->status_fd
= open (pip
->pathname
, O_RDONLY
)) < 0)
3840 sprintf (pip
->pathname
, AS_PROC_NAME_FMT
, tmp
);
3841 if ((pip
->as_fd
= open (pip
->pathname
, O_RDWR
)) < 0)
3843 close (pip
->status_fd
);
3847 sprintf (pip
->pathname
, MAP_PROC_NAME_FMT
, tmp
);
3848 if ((pip
->map_fd
= open (pip
->pathname
, O_RDONLY
)) < 0)
3850 close (pip
->status_fd
);
3855 sprintf (pip
->pathname
, MAP_PROC_NAME_FMT
, tmp
);
3856 if ((pip
->map_fd
= open (pip
->pathname
, O_RDONLY
)) < 0)
3858 close (pip
->status_fd
);
3865 sprintf (pip
->pathname
, CTL_PROC_NAME_FMT
, tmp
);
3866 if ((pip
->ctl_fd
= open (pip
->pathname
, O_WRONLY
)) < 0)
3868 close (pip
->status_fd
);
3870 close (pip
->map_fd
);
3875 #else /* HAVE_MULTIPLE_PROC_FDS */
3876 sprintf (pip
-> pathname
, CTL_PROC_NAME_FMT
, tmp
);
3878 if ((tmpfd
= open (pip
-> pathname
, mode
)) < 0)
3882 pip
-> ctl_fd
= tmpfd
;
3883 pip
-> as_fd
= tmpfd
;
3884 pip
-> map_fd
= tmpfd
;
3885 pip
-> status_fd
= tmpfd
;
3887 tmp
= (pid
>> 16) & 0xffff; /* Extract thread id */
3890 { /* Don't know thread id yet */
3891 if (ioctl (tmpfd
, PIOCSTATUS
, &pip
-> prstatus
) < 0)
3893 print_sys_errmsg (pip
-> pathname
, errno
);
3895 error ("open_proc_file: PIOCSTATUS failed");
3898 tmp
= pip
-> prstatus
.pr_who
; /* Get thread id from prstatus_t */
3899 pip
-> pid
= (tmp
<< 16) | pid
; /* Update pip */
3902 if ((pip
-> ctl_fd
= ioctl (tmpfd
, PIOCOPENLWP
, &tmp
)) < 0)
3908 #ifdef PIOCSET /* New method */
3911 pr_flags
= PR_ASYNC
;
3912 ioctl (pip
-> ctl_fd
, PIOCSET
, &pr_flags
);
3916 /* keep extra fds in sync */
3917 pip
->as_fd
= pip
->ctl_fd
;
3918 pip
->map_fd
= pip
->ctl_fd
;
3919 pip
->status_fd
= pip
->ctl_fd
;
3921 close (tmpfd
); /* All done with main pid */
3922 #endif /* PIOCOPENLWP */
3924 #endif /* HAVE_MULTIPLE_PROC_FDS */
3930 mappingflags (flags
)
3933 static char asciiflags
[8];
3935 strcpy (asciiflags
, "-------");
3936 #if defined (MA_PHYS)
3937 if (flags
& MA_PHYS
) asciiflags
[0] = 'd';
3939 if (flags
& MA_STACK
) asciiflags
[1] = 's';
3940 if (flags
& MA_BREAK
) asciiflags
[2] = 'b';
3941 if (flags
& MA_SHARED
) asciiflags
[3] = 's';
3942 if (flags
& MA_READ
) asciiflags
[4] = 'r';
3943 if (flags
& MA_WRITE
) asciiflags
[5] = 'w';
3944 if (flags
& MA_EXEC
) asciiflags
[6] = 'x';
3945 return (asciiflags
);
3949 info_proc_flags (pip
, summary
)
3950 struct procinfo
*pip
;
3953 struct trans
*transp
;
3955 long flags
= pip
->prstatus
.pr_flags
| pip
->prstatus
.pr_lwp
.pr_flags
;
3957 long flags
= pip
->prstatus
.pr_flags
;
3960 printf_filtered ("%-32s", "Process status flags:");
3963 printf_filtered ("\n\n");
3965 for (transp
= pr_flag_table
; transp
-> name
!= NULL
; transp
++)
3967 if (flags
& transp
-> value
)
3971 printf_filtered ("%s ", transp
-> name
);
3975 printf_filtered ("\t%-16s %s.\n", transp
-> name
, transp
-> desc
);
3979 printf_filtered ("\n");
3983 info_proc_stop (pip
, summary
)
3984 struct procinfo
*pip
;
3987 struct trans
*transp
;
3992 why
= pip
-> prstatus
.pr_lwp
.pr_why
;
3993 what
= pip
-> prstatus
.pr_lwp
.pr_what
;
3995 why
= pip
-> prstatus
.pr_why
;
3996 what
= pip
-> prstatus
.pr_what
;
4000 if (pip
-> prstatus
.pr_lwp
.pr_flags
& PR_STOPPED
)
4002 if (pip
-> prstatus
.pr_flags
& PR_STOPPED
)
4005 printf_filtered ("%-32s", "Reason for stopping:");
4008 printf_filtered ("\n\n");
4010 for (transp
= pr_why_table
; transp
-> name
!= NULL
; transp
++)
4012 if (why
== transp
-> value
)
4016 printf_filtered ("%s ", transp
-> name
);
4020 printf_filtered ("\t%-16s %s.\n",
4021 transp
-> name
, transp
-> desc
);
4027 /* Use the pr_why field to determine what the pr_what field means, and
4028 print more information. */
4033 /* pr_what is unused for this case */
4039 printf_filtered ("%s ", signalname (what
));
4043 printf_filtered ("\t%-16s %s.\n", signalname (what
),
4044 safe_strsignal (what
));
4050 printf_filtered ("%s ", syscallname (what
));
4054 printf_filtered ("\t%-16s %s.\n", syscallname (what
),
4055 "Entered this system call");
4061 printf_filtered ("%s ", syscallname (what
));
4065 printf_filtered ("\t%-16s %s.\n", syscallname (what
),
4066 "Returned from this system call");
4072 printf_filtered ("%s ",
4073 lookupname (faults_table
, what
, "fault"));
4077 printf_filtered ("\t%-16s %s.\n",
4078 lookupname (faults_table
, what
, "fault"),
4079 lookupdesc (faults_table
, what
));
4083 printf_filtered ("\n");
4088 info_proc_siginfo (pip
, summary
)
4089 struct procinfo
*pip
;
4092 struct siginfo
*sip
;
4095 if ((pip
-> prstatus
.pr_lwp
.pr_flags
& PR_STOPPED
) &&
4096 (pip
-> prstatus
.pr_lwp
.pr_why
== PR_SIGNALLED
||
4097 pip
-> prstatus
.pr_lwp
.pr_why
== PR_FAULTED
))
4099 if ((pip
-> prstatus
.pr_flags
& PR_STOPPED
) &&
4100 (pip
-> prstatus
.pr_why
== PR_SIGNALLED
||
4101 pip
-> prstatus
.pr_why
== PR_FAULTED
))
4104 printf_filtered ("%-32s", "Additional signal/fault info:");
4106 sip
= &pip
-> prstatus
.pr_lwp
.pr_info
;
4108 sip
= &pip
-> prstatus
.pr_info
;
4112 printf_filtered ("%s ", signalname (sip
-> si_signo
));
4113 if (sip
-> si_errno
> 0)
4115 printf_filtered ("%s ", errnoname (sip
-> si_errno
));
4117 if (sip
-> si_code
<= 0)
4119 printf_filtered ("sent by %s, uid %d ",
4120 target_pid_to_str (sip
-> si_pid
),
4125 printf_filtered ("%s ", sigcodename (sip
));
4126 if ((sip
-> si_signo
== SIGILL
) ||
4127 (sip
-> si_signo
== SIGFPE
) ||
4128 (sip
-> si_signo
== SIGSEGV
) ||
4129 (sip
-> si_signo
== SIGBUS
))
4131 printf_filtered ("addr=%#lx ",
4132 (unsigned long) sip
-> si_addr
);
4134 else if ((sip
-> si_signo
== SIGCHLD
))
4136 printf_filtered ("child %s, status %u ",
4137 target_pid_to_str (sip
-> si_pid
),
4140 else if ((sip
-> si_signo
== SIGPOLL
))
4142 printf_filtered ("band %u ", sip
-> si_band
);
4148 printf_filtered ("\n\n");
4149 printf_filtered ("\t%-16s %s.\n", signalname (sip
-> si_signo
),
4150 safe_strsignal (sip
-> si_signo
));
4151 if (sip
-> si_errno
> 0)
4153 printf_filtered ("\t%-16s %s.\n",
4154 errnoname (sip
-> si_errno
),
4155 safe_strerror (sip
-> si_errno
));
4157 if (sip
-> si_code
<= 0)
4159 printf_filtered ("\t%-16u %s\n", sip
-> si_pid
, /* XXX need target_pid_to_str() */
4160 "PID of process sending signal");
4161 printf_filtered ("\t%-16u %s\n", sip
-> si_uid
,
4162 "UID of process sending signal");
4166 printf_filtered ("\t%-16s %s.\n", sigcodename (sip
),
4168 if ((sip
-> si_signo
== SIGILL
) ||
4169 (sip
-> si_signo
== SIGFPE
))
4171 printf_filtered ("\t%#-16lx %s.\n",
4172 (unsigned long) sip
-> si_addr
,
4173 "Address of faulting instruction");
4175 else if ((sip
-> si_signo
== SIGSEGV
) ||
4176 (sip
-> si_signo
== SIGBUS
))
4178 printf_filtered ("\t%#-16lx %s.\n",
4179 (unsigned long) sip
-> si_addr
,
4180 "Address of faulting memory reference");
4182 else if ((sip
-> si_signo
== SIGCHLD
))
4184 printf_filtered ("\t%-16u %s.\n", sip
-> si_pid
, /* XXX need target_pid_to_str() */
4185 "Child process ID");
4186 printf_filtered ("\t%-16u %s.\n", sip
-> si_status
,
4187 "Child process exit value or signal");
4189 else if ((sip
-> si_signo
== SIGPOLL
))
4191 printf_filtered ("\t%-16u %s.\n", sip
-> si_band
,
4192 "Band event for POLL_{IN,OUT,MSG}");
4196 printf_filtered ("\n");
4201 info_proc_syscalls (pip
, summary
)
4202 struct procinfo
*pip
;
4210 #if 0 /* FIXME: Needs to use gdb-wide configured info about system calls. */
4211 if (pip
-> prstatus
.pr_flags
& PR_ASLEEP
)
4213 int syscallnum
= pip
-> prstatus
.pr_reg
[R_D0
];
4216 printf_filtered ("%-32s", "Sleeping in system call:");
4217 printf_filtered ("%s", syscallname (syscallnum
));
4221 printf_filtered ("Sleeping in system call '%s'.\n",
4222 syscallname (syscallnum
));
4228 if (ioctl (pip
-> ctl_fd
, PIOCGENTRY
, &pip
-> entryset
) < 0)
4230 print_sys_errmsg (pip
-> pathname
, errno
);
4231 error ("PIOCGENTRY failed");
4234 if (ioctl (pip
-> ctl_fd
, PIOCGEXIT
, &pip
-> exitset
) < 0)
4236 print_sys_errmsg (pip
-> pathname
, errno
);
4237 error ("PIOCGEXIT failed");
4241 printf_filtered ("System call tracing information:\n\n");
4243 printf_filtered ("\t%-12s %-8s %-8s\n",
4247 for (syscallnum
= 0; syscallnum
< MAX_SYSCALLS
; syscallnum
++)
4250 if (syscall_table
[syscallnum
] != NULL
)
4251 printf_filtered ("\t%-12s ", syscall_table
[syscallnum
]);
4253 printf_filtered ("\t%-12d ", syscallnum
);
4256 printf_filtered ("%-8s ",
4257 prismember (&pip
->prstatus
.pr_sysentry
, syscallnum
)
4259 printf_filtered ("%-8s ",
4260 prismember (&pip
->prstatus
.pr_sysexit
, syscallnum
)
4263 printf_filtered ("%-8s ",
4264 prismember (&pip
-> entryset
, syscallnum
)
4266 printf_filtered ("%-8s ",
4267 prismember (&pip
-> exitset
, syscallnum
)
4270 printf_filtered ("\n");
4272 printf_filtered ("\n");
4281 static char locbuf
[32];
4283 name
= strsigno (signo
);
4286 sprintf (locbuf
, "Signal %d", signo
);
4290 sprintf (locbuf
, "%s (%d)", name
, signo
);
4300 static char locbuf
[32];
4302 name
= strerrno (errnum
);
4305 sprintf (locbuf
, "Errno %d", errnum
);
4309 sprintf (locbuf
, "%s (%d)", name
, errnum
);
4315 info_proc_signals (pip
, summary
)
4316 struct procinfo
*pip
;
4323 #ifndef PROCFS_USE_READ_WRITE
4324 if (ioctl (pip
-> ctl_fd
, PIOCGTRACE
, &pip
-> trace
) < 0)
4326 print_sys_errmsg (pip
-> pathname
, errno
);
4327 error ("PIOCGTRACE failed");
4331 printf_filtered ("Disposition of signals:\n\n");
4332 printf_filtered ("\t%-15s %-8s %-8s %-8s %s\n\n",
4333 "Signal", "Trace", "Hold", "Pending", "Description");
4334 for (signo
= 0; signo
< NSIG
; signo
++)
4337 printf_filtered ("\t%-15s ", signalname (signo
));
4339 printf_filtered ("%-8s ",
4340 prismember (&pip
-> prstatus
.pr_sigtrace
, signo
)
4342 printf_filtered ("%-8s ",
4343 prismember (&pip
-> prstatus
.pr_lwp
.pr_context
.uc_sigmask
, signo
)
4346 printf_filtered ("%-8s ",
4347 prismember (&pip
-> trace
, signo
)
4349 printf_filtered ("%-8s ",
4350 prismember (&pip
-> prstatus
.pr_sighold
, signo
)
4355 if (prismember (&pip
->prstatus
.pr_sigpend
, signo
) ||
4356 prismember (&pip
->prstatus
.pr_lwp
.pr_lwppend
, signo
))
4357 printf_filtered("%-8s ", "yes");
4359 printf_filtered("%-8s ", "no");
4360 #else /* UNIXWARE */
4361 #ifdef PROCFS_SIGPEND_OFFSET
4362 /* Alpha OSF/1 numbers the pending signals from 1. */
4363 printf_filtered ("%-8s ",
4364 (signo
? prismember (&pip
-> prstatus
.pr_sigpend
,
4369 printf_filtered ("%-8s ",
4370 prismember (&pip
-> prstatus
.pr_sigpend
, signo
)
4373 #endif /* UNIXWARE */
4374 printf_filtered (" %s\n", safe_strsignal (signo
));
4376 printf_filtered ("\n");
4381 info_proc_faults (pip
, summary
)
4382 struct procinfo
*pip
;
4385 struct trans
*transp
;
4390 if (ioctl (pip
-> ctl_fd
, PIOCGFAULT
, &pip
->fltset
.fltset
) < 0)
4392 print_sys_errmsg (pip
-> pathname
, errno
);
4393 error ("PIOCGFAULT failed");
4397 printf_filtered ("Current traced hardware fault set:\n\n");
4398 printf_filtered ("\t%-12s %-8s\n", "Fault", "Trace");
4400 for (transp
= faults_table
; transp
-> name
!= NULL
; transp
++)
4403 printf_filtered ("\t%-12s ", transp
-> name
);
4405 printf_filtered ("%-8s", prismember (&pip
->prstatus
.pr_flttrace
, transp
-> value
)
4408 printf_filtered ("%-8s", prismember (&pip
->fltset
.fltset
, transp
-> value
)
4411 printf_filtered ("\n");
4413 printf_filtered ("\n");
4418 info_proc_mappings (pip
, summary
)
4419 struct procinfo
*pip
;
4423 struct prmap
*prmaps
;
4424 struct prmap
*prmap
;
4429 printf_filtered ("Mapped address spaces:\n\n");
4430 #ifdef BFD_HOST_64_BIT
4431 printf_filtered (" %18s %18s %10s %10s %7s\n",
4433 printf_filtered ("\t%10s %10s %10s %10s %7s\n",
4440 #ifdef PROCFS_USE_READ_WRITE
4441 if (fstat (pip
->map_fd
, &sbuf
) == 0)
4443 nmap
= sbuf
.st_size
/ sizeof (prmap_t
);
4444 prmaps
= (struct prmap
*) alloca ((nmap
+ 1) * sizeof (*prmaps
));
4445 if ((lseek (pip
->map_fd
, 0, SEEK_SET
) == 0) &&
4446 (read (pip
->map_fd
, (char *) prmaps
,
4447 nmap
* sizeof (*prmaps
)) == (nmap
* sizeof (*prmaps
))))
4450 for (prmap
= prmaps
; i
< nmap
; ++prmap
, ++i
)
4452 if (ioctl (pip
-> ctl_fd
, PIOCNMAP
, &nmap
) == 0)
4454 prmaps
= (struct prmap
*) alloca ((nmap
+ 1) * sizeof (*prmaps
));
4455 if (ioctl (pip
-> ctl_fd
, PIOCMAP
, prmaps
) == 0)
4457 for (prmap
= prmaps
; prmap
-> pr_size
; ++prmap
)
4458 #endif /* PROCFS_USE_READ_WRITE */
4460 #ifdef BFD_HOST_64_BIT
4461 printf_filtered (" %#18lx %#18lx %#10x %#10x %7s\n",
4463 printf_filtered ("\t%#10lx %#10lx %#10x %#10x %7s\n",
4465 (unsigned long)prmap
-> pr_vaddr
,
4466 (unsigned long)prmap
-> pr_vaddr
4467 + prmap
-> pr_size
- 1,
4470 mappingflags (prmap
-> pr_mflags
));
4474 printf_filtered ("\n");
4482 info_proc -- implement the "info proc" command
4486 void info_proc (char *args, int from_tty)
4490 Implement gdb's "info proc" command by using the /proc interface
4491 to print status information about any currently running process.
4493 Examples of the use of "info proc" are:
4495 info proc (prints summary info for current inferior)
4496 info proc 123 (prints summary info for process with pid 123)
4497 info proc mappings (prints address mappings)
4498 info proc times (prints process/children times)
4499 info proc id (prints pid, ppid, gid, sid, etc)
4500 FIXME: i proc id not implemented.
4501 info proc status (prints general process state info)
4502 FIXME: i proc status not implemented.
4503 info proc signals (prints info about signal handling)
4504 info proc all (prints all info)
4509 info_proc (args
, from_tty
)
4513 int pid
= inferior_pid
;
4514 struct procinfo
*pip
;
4515 struct cleanup
*old_chain
;
4531 old_chain
= make_cleanup (null_cleanup
, 0);
4533 /* Default to using the current inferior if no pid specified. Note
4534 that inferior_pid may be 0, hence we set okerr. */
4536 pip
= find_procinfo (inferior_pid
, 1);
4540 if ((argv
= buildargv (args
)) == NULL
)
4544 make_cleanup (freeargv
, (char *) argv
);
4546 while (*argv
!= NULL
)
4548 argsize
= strlen (*argv
);
4549 if (argsize
>= 1 && strncmp (*argv
, "all", argsize
) == 0)
4554 else if (argsize
>= 2 && strncmp (*argv
, "faults", argsize
) == 0)
4559 else if (argsize
>= 2 && strncmp (*argv
, "flags", argsize
) == 0)
4564 else if (argsize
>= 1 && strncmp (*argv
, "id", argsize
) == 0)
4569 else if (argsize
>= 1 && strncmp (*argv
, "mappings", argsize
) == 0)
4574 else if (argsize
>= 2 && strncmp (*argv
, "signals", argsize
) == 0)
4579 else if (argsize
>= 2 && strncmp (*argv
, "status", argsize
) == 0)
4584 else if (argsize
>= 2 && strncmp (*argv
, "syscalls", argsize
) == 0)
4589 else if (argsize
>= 1 && strncmp (*argv
, "times", argsize
) == 0)
4594 else if ((pid
= atoi (*argv
)) > 0)
4596 pip
= (struct procinfo
*) xmalloc (sizeof (struct procinfo
));
4597 memset (pip
, 0, sizeof (*pip
));
4600 if (!open_proc_file (pid
, pip
, O_RDONLY
, 0))
4602 perror_with_name (pip
-> pathname
);
4606 make_cleanup (close_proc_file
, pip
);
4608 else if (**argv
!= '\000')
4610 error ("Unrecognized or ambiguous keyword `%s'.", *argv
);
4616 /* If we don't have a valid open process at this point, then we have no
4617 inferior or didn't specify a specific pid. */
4622 No process. Start debugging a program or specify an explicit process ID.");
4625 if (!procfs_read_status (pip
))
4627 print_sys_errmsg (pip
-> pathname
, errno
);
4628 error ("procfs_read_status failed");
4631 #ifndef PROCFS_USE_READ_WRITE
4633 nlwp
= pip
->prstatus
.pr_nlwp
;
4634 lwps
= alloca ((2 * nlwp
+ 2) * sizeof (id_t
));
4636 if (ioctl (pip
->ctl_fd
, PIOCLWPIDS
, lwps
))
4638 print_sys_errmsg (pip
-> pathname
, errno
);
4639 error ("PIOCLWPIDS failed");
4641 #else /* PIOCLWPIDS */
4643 lwps
= alloca ((2 * nlwp
+ 2) * sizeof *lwps
);
4645 #endif /* PIOCLWPIDS */
4647 for (; nlwp
> 0; nlwp
--, lwps
++)
4649 pip
= find_procinfo ((*lwps
<< 16) | pid
, 1);
4653 pip
= (struct procinfo
*) xmalloc (sizeof (struct procinfo
));
4654 memset (pip
, 0, sizeof (*pip
));
4655 if (!open_proc_file ((*lwps
<< 16) | pid
, pip
, O_RDONLY
, 0))
4658 make_cleanup (close_proc_file
, pip
);
4660 if (!procfs_read_status (pip
))
4662 print_sys_errmsg (pip
-> pathname
, errno
);
4663 error ("procfs_read_status failed");
4667 #endif /* PROCFS_USE_READ_WRITE */
4669 /* Print verbose information of the requested type(s), or just a summary
4670 of the information for all types. */
4672 printf_filtered ("\nInformation for %s.%d:\n\n", pip
-> pathname
, *lwps
);
4673 if (summary
|| all
|| flags
)
4675 info_proc_flags (pip
, summary
);
4679 info_proc_stop (pip
, summary
);
4681 if (summary
|| all
|| signals
|| faults
)
4683 info_proc_siginfo (pip
, summary
);
4685 if (summary
|| all
|| syscalls
)
4687 info_proc_syscalls (pip
, summary
);
4689 if (summary
|| all
|| mappings
)
4691 info_proc_mappings (pip
, summary
);
4693 if (summary
|| all
|| signals
)
4695 info_proc_signals (pip
, summary
);
4697 if (summary
|| all
|| faults
)
4699 info_proc_faults (pip
, summary
);
4701 printf_filtered ("\n");
4703 /* All done, deal with closing any temporary process info structure,
4704 freeing temporary memory , etc. */
4706 do_cleanups (old_chain
);
4707 #ifndef PROCFS_USE_READ_WRITE
4716 modify_inherit_on_fork_flag - Change the inherit-on-fork flag
4720 void modify_inherit_on_fork_flag (fd, flag)
4724 Call this routine to modify the inherit-on-fork flag. This routine is
4725 just a nice wrapper to hide the #ifdefs needed by various systems to
4731 modify_inherit_on_fork_flag (fd
, flag
)
4735 #if defined (PIOCSET) || defined (PCSET)
4739 struct proc_ctl pctl
;
4741 #if defined (PIOCSET) || defined (PCSET) /* New method */
4745 #ifdef PROCFS_USE_READ_WRITE
4747 pctl
.data
= PR_FORK
;
4748 if (write (fd
, (char *) &pctl
, sizeof (struct proc_ctl
)) < 0)
4751 retval
= ioctl (fd
, PIOCSET
, &pr_flags
);
4756 #ifdef PROCFS_USE_READ_WRITE
4758 pctl
.data
= PR_FORK
;
4759 if (write (fd
, (char *) &pctl
, sizeof (struct proc_ctl
)) < 0)
4762 retval
= ioctl (fd
, PIOCRESET
, &pr_flags
);
4767 #ifdef PIOCSFORK /* Original method */
4770 retval
= ioctl (fd
, PIOCSFORK
, NULL
);
4774 retval
= ioctl (fd
, PIOCRFORK
, NULL
);
4777 Neither PR_FORK nor PIOCSFORK exist
!!!
4784 print_sys_errmsg ("modify_inherit_on_fork_flag", errno
);
4785 error ("PIOCSFORK or PR_FORK modification failed");
4792 modify_run_on_last_close_flag - Change the run-on-last-close flag
4796 void modify_run_on_last_close_flag (fd, flag)
4800 Call this routine to modify the run-on-last-close flag. This routine
4801 is just a nice wrapper to hide the #ifdefs needed by various systems to
4807 modify_run_on_last_close_flag (fd
, flag
)
4811 #if defined (PIOCSET) || defined (PCSET)
4815 struct proc_ctl pctl
;
4817 #if defined (PIOCSET) || defined (PCSET) /* New method */
4821 #ifdef PROCFS_USE_READ_WRITE
4824 if (write (fd
, (char *) &pctl
, sizeof (struct proc_ctl
)) < 0)
4827 retval
= ioctl (fd
, PIOCSET
, &pr_flags
);
4832 #ifdef PROCFS_USE_READ_WRITE
4835 if (write (fd
, (char *) &pctl
, sizeof (struct proc_ctl
)) < 0)
4838 retval
= ioctl (fd
, PIOCRESET
, &pr_flags
);
4843 #ifdef PIOCSRLC /* Original method */
4845 retval
= ioctl (fd
, PIOCSRLC
, NULL
);
4847 retval
= ioctl (fd
, PIOCRRLC
, NULL
);
4849 Neither PR_RLC nor PIOCSRLC exist
!!!
4856 print_sys_errmsg ("modify_run_on_last_close_flag", errno
);
4857 error ("PIOCSRLC or PR_RLC modification failed");
4864 procfs_clear_syscall_trap -- Deletes the trap for the specified system call.
4868 void procfs_clear_syscall_trap (struct procinfo *, int syscall_num, int errok)
4872 This function function disables traps for the specified system call.
4873 errok is non-zero if errors should be ignored.
4877 procfs_clear_syscall_trap (pi
, syscall_num
, errok
)
4878 struct procinfo
*pi
;
4885 goterr
= ioctl (pi
->ctl_fd
, PIOCGENTRY
, &sysset
) < 0;
4887 if (goterr
&& !errok
)
4889 print_sys_errmsg (pi
->pathname
, errno
);
4890 error ("PIOCGENTRY failed");
4895 prdelset (&sysset
, syscall_num
);
4897 if ((ioctl (pi
->ctl_fd
, PIOCSENTRY
, &sysset
) < 0) && !errok
)
4899 print_sys_errmsg (pi
->pathname
, errno
);
4900 error ("PIOCSENTRY failed");
4904 goterr
= ioctl (pi
->ctl_fd
, PIOCGEXIT
, &sysset
) < 0;
4906 if (goterr
&& !errok
)
4908 procfs_clear_syscall_trap (pi
, syscall_num
, 1);
4909 print_sys_errmsg (pi
->pathname
, errno
);
4910 error ("PIOCGEXIT failed");
4915 praddset (&sysset
, syscall_num
);
4917 if ((ioctl (pi
->ctl_fd
, PIOCSEXIT
, &sysset
) < 0) && !errok
)
4919 procfs_clear_syscall_trap (pi
, syscall_num
, 1);
4920 print_sys_errmsg (pi
->pathname
, errno
);
4921 error ("PIOCSEXIT failed");
4925 if (!pi
->syscall_handlers
)
4928 error ("procfs_clear_syscall_trap: syscall_handlers is empty");
4932 /* Remove handler func from the handler list */
4934 for (i
= 0; i
< pi
->num_syscall_handlers
; i
++)
4935 if (pi
->syscall_handlers
[i
].syscall_num
== syscall_num
)
4937 if (i
+ 1 != pi
->num_syscall_handlers
)
4938 { /* Not the last entry.
4939 Move subsequent entries fwd. */
4940 memcpy (&pi
->syscall_handlers
[i
], &pi
->syscall_handlers
[i
+ 1],
4941 (pi
->num_syscall_handlers
- i
- 1)
4942 * sizeof (struct procfs_syscall_handler
));
4945 pi
->syscall_handlers
= xrealloc (pi
->syscall_handlers
,
4946 (pi
->num_syscall_handlers
- 1)
4947 * sizeof (struct procfs_syscall_handler
));
4948 pi
->num_syscall_handlers
--;
4953 error ("procfs_clear_syscall_trap: Couldn't find handler for sys call %d",
4961 procfs_set_syscall_trap -- arrange for a function to be called when the
4962 child executes the specified system call.
4966 void procfs_set_syscall_trap (struct procinfo *, int syscall_num, int flags,
4967 syscall_func_t *function)
4971 This function sets up an entry and/or exit trap for the specified system
4972 call. When the child executes the specified system call, your function
4973 will be called with the call #, a flag that indicates entry or exit, and
4974 pointers to rtnval and statval (which are used by procfs_wait). The
4975 function should return non-zero if something interesting happened, zero
4980 procfs_set_syscall_trap (pi
, syscall_num
, flags
, func
)
4981 struct procinfo
*pi
;
4984 syscall_func_t
*func
;
4988 if (flags
& PROCFS_SYSCALL_ENTRY
)
4990 if (ioctl (pi
->ctl_fd
, PIOCGENTRY
, &sysset
) < 0)
4992 print_sys_errmsg (pi
->pathname
, errno
);
4993 error ("PIOCGENTRY failed");
4996 praddset (&sysset
, syscall_num
);
4998 if (ioctl (pi
->ctl_fd
, PIOCSENTRY
, &sysset
) < 0)
5000 print_sys_errmsg (pi
->pathname
, errno
);
5001 error ("PIOCSENTRY failed");
5005 if (flags
& PROCFS_SYSCALL_EXIT
)
5007 if (ioctl (pi
->ctl_fd
, PIOCGEXIT
, &sysset
) < 0)
5009 procfs_clear_syscall_trap (pi
, syscall_num
, 1);
5010 print_sys_errmsg (pi
->pathname
, errno
);
5011 error ("PIOCGEXIT failed");
5014 praddset (&sysset
, syscall_num
);
5016 if (ioctl (pi
->ctl_fd
, PIOCSEXIT
, &sysset
) < 0)
5018 procfs_clear_syscall_trap (pi
, syscall_num
, 1);
5019 print_sys_errmsg (pi
->pathname
, errno
);
5020 error ("PIOCSEXIT failed");
5024 if (!pi
->syscall_handlers
)
5026 pi
->syscall_handlers
= xmalloc (sizeof (struct procfs_syscall_handler
));
5027 pi
->syscall_handlers
[0].syscall_num
= syscall_num
;
5028 pi
->syscall_handlers
[0].func
= func
;
5029 pi
->num_syscall_handlers
= 1;
5035 for (i
= 0; i
< pi
->num_syscall_handlers
; i
++)
5036 if (pi
->syscall_handlers
[i
].syscall_num
== syscall_num
)
5038 pi
->syscall_handlers
[i
].func
= func
;
5042 pi
->syscall_handlers
= xrealloc (pi
->syscall_handlers
, (i
+ 1)
5043 * sizeof (struct procfs_syscall_handler
));
5044 pi
->syscall_handlers
[i
].syscall_num
= syscall_num
;
5045 pi
->syscall_handlers
[i
].func
= func
;
5046 pi
->num_syscall_handlers
++;
5050 #ifdef SYS_lwp_create
5056 procfs_lwp_creation_handler - handle exit from the _lwp_create syscall
5060 int procfs_lwp_creation_handler (pi, syscall_num, why, rtnvalp, statvalp)
5064 This routine is called both when an inferior process and it's new lwp
5065 are about to finish a _lwp_create() system call. This is the system
5066 call that Solaris uses to create a lightweight process. When the
5067 target process gets this event, we can look at sysarg[2] to find the
5068 new childs lwp ID, and create a procinfo struct from that. After that,
5069 we pretend that we got a SIGTRAP, and return non-zero to tell
5070 procfs_wait to wake up. Subsequently, wait_for_inferior gets woken up,
5071 sees the new process and continues it.
5073 When we see the child exiting from lwp_create, we just contine it,
5074 since everything was handled when the parent trapped.
5077 In effect, we are only paying attention to the parent's completion of
5078 the lwp_create syscall. If we only paid attention to the child
5079 instead, then we wouldn't detect the creation of a suspended thread.
5083 procfs_lwp_creation_handler (pi
, syscall_num
, why
, rtnvalp
, statvalp
)
5084 struct procinfo
*pi
;
5091 struct procinfo
*childpi
;
5093 /* We've just detected the completion of an lwp_create system call. Now we
5094 need to setup a procinfo struct for this thread, and notify the thread
5095 system of the new arrival. */
5097 /* If lwp_create failed, then nothing interesting happened. Continue the
5098 process and go back to sleep. */
5100 if (pi
->prstatus
.pr_reg
[R_PSR
] & PS_FLAG_CARRY
)
5101 { /* _lwp_create failed */
5102 pi
->prrun
.pr_flags
&= PRSTEP
;
5103 pi
->prrun
.pr_flags
|= PRCFAULT
;
5105 if (ioctl (pi
->ctl_fd
, PIOCRUN
, &pi
->prrun
) != 0)
5106 perror_with_name (pi
->pathname
);
5111 /* At this point, the new thread is stopped at it's first instruction, and
5112 the parent is stopped at the exit from lwp_create. */
5114 if (pi
->new_child
) /* Child? */
5115 { /* Yes, just continue it */
5116 pi
->prrun
.pr_flags
&= PRSTEP
;
5117 pi
->prrun
.pr_flags
|= PRCFAULT
;
5119 if ((pi
->prstatus
.pr_flags
& PR_ISTOP
)
5120 && ioctl (pi
->ctl_fd
, PIOCRUN
, &pi
->prrun
) != 0)
5121 perror_with_name (pi
->pathname
);
5123 pi
->new_child
= 0; /* No longer new */
5128 /* We're the proud parent of a new thread. Setup an exit trap for lwp_create
5129 in the child and continue the parent. */
5131 /* Third arg is pointer to new thread id. */
5132 lwp_id
= read_memory_integer (pi
->prstatus
.pr_sysarg
[2], sizeof (int));
5134 lwp_id
= (lwp_id
<< 16) | PIDGET (pi
->pid
);
5136 childpi
= create_procinfo (lwp_id
);
5138 /* The new process has actually inherited the lwp_create syscall trap from
5139 it's parent, but we still have to call this to register a handler for
5142 procfs_set_syscall_trap (childpi
, SYS_lwp_create
, PROCFS_SYSCALL_EXIT
,
5143 procfs_lwp_creation_handler
);
5145 childpi
->new_child
= 1; /* Flag this as an unseen child process */
5147 *rtnvalp
= lwp_id
; /* the new arrival. */
5148 *statvalp
= (SIGTRAP
<< 8) | 0177;
5152 #endif /* SYS_lwp_create */
5154 /* Fork an inferior process, and start debugging it with /proc. */
5157 procfs_create_inferior (exec_file
, allargs
, env
)
5162 char *shell_file
= getenv ("SHELL");
5164 if (shell_file
!= NULL
&& strchr (shell_file
, '/') == NULL
)
5167 /* We will be looking down the PATH to find shell_file. If we
5168 just do this the normal way (via execlp, which operates by
5169 attempting an exec for each element of the PATH until it
5170 finds one which succeeds), then there will be an exec for
5171 each failed attempt, each of which will cause a PR_SYSEXIT
5172 stop, and we won't know how to distinguish the PR_SYSEXIT's
5173 for these failed execs with the ones for successful execs
5174 (whether the exec has succeeded is stored at that time in the
5175 carry bit or some such architecture-specific and
5176 non-ABI-specified place).
5178 So I can't think of anything better than to search the PATH
5179 now. This has several disadvantages: (1) There is a race
5180 condition; if we find a file now and it is deleted before we
5181 exec it, we lose, even if the deletion leaves a valid file
5182 further down in the PATH, (2) there is no way to know exactly
5183 what an executable (in the sense of "capable of being
5184 exec'd") file is. Using access() loses because it may lose
5185 if the caller is the superuser; failing to use it loses if
5186 there are ACLs or some such. */
5190 /* FIXME-maybe: might want "set path" command so user can change what
5191 path is used from within GDB. */
5192 char *path
= getenv ("PATH");
5194 struct stat statbuf
;
5197 path
= "/bin:/usr/bin";
5199 tryname
= alloca (strlen (path
) + strlen (shell_file
) + 2);
5200 for (p
= path
; p
!= NULL
; p
= p1
? p1
+ 1: NULL
)
5202 p1
= strchr (p
, ':');
5207 strncpy (tryname
, p
, len
);
5208 tryname
[len
] = '\0';
5209 strcat (tryname
, "/");
5210 strcat (tryname
, shell_file
);
5211 if (access (tryname
, X_OK
) < 0)
5213 if (stat (tryname
, &statbuf
) < 0)
5215 if (!S_ISREG (statbuf
.st_mode
))
5216 /* We certainly need to reject directories. I'm not quite
5217 as sure about FIFOs, sockets, etc., but I kind of doubt
5218 that people want to exec() these things. */
5223 /* Not found. This must be an error rather than merely passing
5224 the file to execlp(), because execlp() would try all the
5225 exec()s, causing GDB to get confused. */
5226 error ("Can't find shell %s in PATH", shell_file
);
5228 shell_file
= tryname
;
5231 fork_inferior (exec_file
, allargs
, env
,
5232 proc_set_exec_trap
, procfs_init_inferior
, shell_file
);
5234 /* We are at the first instruction we care about. */
5235 /* Pedal to the metal... */
5237 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_0
, 0);
5240 /* Clean up after the inferior dies. */
5243 procfs_mourn_inferior ()
5245 struct procinfo
*pi
;
5246 struct procinfo
*next_pi
;
5248 for (pi
= procinfo_list
; pi
; pi
= next_pi
)
5251 unconditionally_kill_inferior (pi
);
5254 unpush_target (&procfs_ops
);
5255 generic_mourn_inferior ();
5259 /* Mark our target-struct as eligible for stray "run" and "attach" commands. */
5263 /* This variable is controlled by modules that sit atop procfs that may layer
5264 their own process structure atop that provided here. sol-thread.c does
5265 this because of the Solaris two-level thread model. */
5267 return !procfs_suppress_run
;
5269 #ifdef TARGET_HAS_HARDWARE_WATCHPOINTS
5271 /* Insert a watchpoint */
5273 procfs_set_watchpoint(pid
, addr
, len
, rw
)
5279 struct procinfo
*pi
;
5282 pi
= find_procinfo (pid
== -1 ? inferior_pid
: pid
, 0);
5283 wpt
.pr_vaddr
= (caddr_t
)addr
;
5285 wpt
.pr_wflags
= ((rw
& 1) ? MA_READ
: 0) | ((rw
& 2) ? MA_WRITE
: 0);
5286 if (ioctl (pi
->ctl_fd
, PIOCSWATCH
, &wpt
) < 0)
5290 /* Currently it sometimes happens that the same watchpoint gets
5291 deleted twice - don't die in this case (FIXME please) */
5292 if (errno
== ESRCH
&& len
== 0)
5294 print_sys_errmsg (pi
->pathname
, errno
);
5295 error ("PIOCSWATCH failed");
5301 procfs_stopped_by_watchpoint(pid
)
5304 struct procinfo
*pi
;
5308 pi
= find_procinfo (pid
== -1 ? inferior_pid
: pid
, 0);
5309 if (pi
->prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
))
5311 why
= pi
->prstatus
.pr_why
;
5312 what
= pi
->prstatus
.pr_what
;
5313 if (why
== PR_FAULTED
5314 #if defined (FLTWATCH) && defined (FLTKWATCH)
5315 && (what
== FLTWATCH
|| what
== FLTKWATCH
)
5318 && (what
== FLTWATCH
)
5321 && (what
== FLTKWATCH
)
5329 #endif /* TARGET_HAS_HARDWARE_WATCHPOINTS */
5331 /* Why is this necessary? Shouldn't dead threads just be removed from the
5335 procfs_thread_alive (pid
)
5341 /* Send a SIGINT to the process group. This acts just like the user typed a
5342 ^C on the controlling terminal.
5344 XXX - This may not be correct for all systems. Some may want to use
5345 killpg() instead of kill (-pgrp). */
5350 extern pid_t inferior_process_group
;
5352 kill (-inferior_process_group
, SIGINT
);
5355 /* Convert a pid to printable form. */
5359 procfs_pid_to_str (pid
)
5362 static char buf
[100];
5364 sprintf (buf
, "Kernel thread %d", TIDGET (pid
));
5370 struct target_ops procfs_ops
= {
5371 "procfs", /* to_shortname */
5372 "Unix /proc child process", /* to_longname */
5373 "Unix /proc child process (started by the \"run\" command).", /* to_doc */
5374 procfs_open
, /* to_open */
5376 procfs_attach
, /* to_attach */
5377 procfs_detach
, /* to_detach */
5378 procfs_resume
, /* to_resume */
5379 procfs_wait
, /* to_wait */
5380 procfs_fetch_registers
, /* to_fetch_registers */
5381 procfs_store_registers
, /* to_store_registers */
5382 procfs_prepare_to_store
, /* to_prepare_to_store */
5383 procfs_xfer_memory
, /* to_xfer_memory */
5384 procfs_files_info
, /* to_files_info */
5385 memory_insert_breakpoint
, /* to_insert_breakpoint */
5386 memory_remove_breakpoint
, /* to_remove_breakpoint */
5387 terminal_init_inferior
, /* to_terminal_init */
5388 terminal_inferior
, /* to_terminal_inferior */
5389 terminal_ours_for_output
, /* to_terminal_ours_for_output */
5390 terminal_ours
, /* to_terminal_ours */
5391 child_terminal_info
, /* to_terminal_info */
5392 procfs_kill_inferior
, /* to_kill */
5394 0, /* to_lookup_symbol */
5395 procfs_create_inferior
, /* to_create_inferior */
5396 procfs_mourn_inferior
, /* to_mourn_inferior */
5397 procfs_can_run
, /* to_can_run */
5398 procfs_notice_signals
, /* to_notice_signals */
5399 procfs_thread_alive
, /* to_thread_alive */
5400 procfs_stop
, /* to_stop */
5401 process_stratum
, /* to_stratum */
5403 1, /* to_has_all_memory */
5404 1, /* to_has_memory */
5405 1, /* to_has_stack */
5406 1, /* to_has_registers */
5407 1, /* to_has_execution */
5409 0, /* sections_end */
5410 OPS_MAGIC
/* to_magic */
5414 _initialize_procfs ()
5416 #ifdef HAVE_OPTIONAL_PROC_FS
5417 char procname
[MAX_PROC_NAME_SIZE
];
5420 /* If we have an optional /proc filesystem (e.g. under OSF/1),
5421 don't add procfs support if we cannot access the running
5423 sprintf (procname
, STATUS_PROC_NAME_FMT
, getpid ());
5424 if ((fd
= open (procname
, O_RDONLY
)) < 0)
5429 add_target (&procfs_ops
);
5431 add_info ("proc", info_proc
,
5432 "Show process status information using /proc entry.\n\
5433 Specify process id or use current inferior by default.\n\
5434 Specify keywords for detailed information; default is summary.\n\
5435 Keywords are: `all', `faults', `flags', `id', `mappings', `signals',\n\
5436 `status', `syscalls', and `times'.\n\
5437 Unambiguous abbreviations may be used.");
5439 init_syscall_table ();