1 /* Machine independent support for SVR4 /proc (process file system) for GDB.
3 Copyright 1999, 2000, 2001, 2002, 2003 Free Software Foundation,
6 Written by Michael Snyder at Cygnus Solutions.
7 Based on work by Fred Fish, Stu Grossman, Geoff Noer, and others.
9 This file is part of GDB.
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software Foundation,
23 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
29 #include "elf-bfd.h" /* for elfcore_write_* */
31 #include "gdbthread.h"
33 #if defined (NEW_PROC_API)
34 #define _STRUCTURED_PROC 1 /* Should be done by configure script. */
37 #include <sys/procfs.h>
38 #ifdef HAVE_SYS_FAULT_H
39 #include <sys/fault.h>
41 #ifdef HAVE_SYS_SYSCALL_H
42 #include <sys/syscall.h>
44 #include <sys/errno.h>
48 #include "gdb_string.h"
49 #include "gdb_assert.h"
56 * This module provides the interface between GDB and the
57 * /proc file system, which is used on many versions of Unix
58 * as a means for debuggers to control other processes.
59 * Examples of the systems that use this interface are:
66 * /proc works by imitating a file system: you open a simulated file
67 * that represents the process you wish to interact with, and
68 * perform operations on that "file" in order to examine or change
69 * the state of the other process.
71 * The most important thing to know about /proc and this module
72 * is that there are two very different interfaces to /proc:
73 * One that uses the ioctl system call, and
74 * another that uses read and write system calls.
75 * This module has to support both /proc interfaces. This means
76 * that there are two different ways of doing every basic operation.
78 * In order to keep most of the code simple and clean, I have
79 * defined an interface "layer" which hides all these system calls.
80 * An ifdef (NEW_PROC_API) determines which interface we are using,
81 * and most or all occurrances of this ifdef should be confined to
82 * this interface layer.
86 /* Determine which /proc API we are using:
87 The ioctl API defines PIOCSTATUS, while
88 the read/write (multiple fd) API never does. */
91 #include <sys/types.h>
92 #include "gdb_dirent.h" /* opendir/readdir, for listing the LWP's */
95 #include <fcntl.h> /* for O_RDONLY */
96 #include <unistd.h> /* for "X_OK" */
97 #include "gdb_stat.h" /* for struct stat */
99 /* Note: procfs-utils.h must be included after the above system header
100 files, because it redefines various system calls using macros.
101 This may be incompatible with the prototype declarations. */
103 #include "proc-utils.h"
105 /* Prototypes for supply_gregset etc. */
108 /* =================== TARGET_OPS "MODULE" =================== */
111 * This module defines the GDB target vector and its methods.
114 static void procfs_open (char *, int);
115 static void procfs_attach (char *, int);
116 static void procfs_detach (char *, int);
117 static void procfs_resume (ptid_t
, int, enum target_signal
);
118 static int procfs_can_run (void);
119 static void procfs_stop (void);
120 static void procfs_files_info (struct target_ops
*);
121 static void procfs_fetch_registers (int);
122 static void procfs_store_registers (int);
123 static void procfs_notice_signals (ptid_t
);
124 static void procfs_prepare_to_store (void);
125 static void procfs_kill_inferior (void);
126 static void procfs_mourn_inferior (void);
127 static void procfs_create_inferior (char *, char *, char **, int);
128 static ptid_t
procfs_wait (ptid_t
, struct target_waitstatus
*);
129 static int procfs_xfer_memory (CORE_ADDR
, char *, int, int,
130 struct mem_attrib
*attrib
,
131 struct target_ops
*);
132 static LONGEST
procfs_xfer_partial (struct target_ops
*ops
,
133 enum target_object object
,
135 void *readbuf
, const void *writebuf
,
136 ULONGEST offset
, LONGEST len
);
138 static int procfs_thread_alive (ptid_t
);
140 void procfs_find_new_threads (void);
141 char *procfs_pid_to_str (ptid_t
);
143 static int proc_find_memory_regions (int (*) (CORE_ADDR
,
149 static char * procfs_make_note_section (bfd
*, int *);
151 static int procfs_can_use_hw_breakpoint (int, int, int);
153 struct target_ops procfs_ops
; /* the target vector */
156 init_procfs_ops (void)
158 procfs_ops
.to_shortname
= "procfs";
159 procfs_ops
.to_longname
= "Unix /proc child process";
161 "Unix /proc child process (started by the \"run\" command).";
162 procfs_ops
.to_open
= procfs_open
;
163 procfs_ops
.to_can_run
= procfs_can_run
;
164 procfs_ops
.to_create_inferior
= procfs_create_inferior
;
165 procfs_ops
.to_kill
= procfs_kill_inferior
;
166 procfs_ops
.to_mourn_inferior
= procfs_mourn_inferior
;
167 procfs_ops
.to_attach
= procfs_attach
;
168 procfs_ops
.to_detach
= procfs_detach
;
169 procfs_ops
.to_wait
= procfs_wait
;
170 procfs_ops
.to_resume
= procfs_resume
;
171 procfs_ops
.to_prepare_to_store
= procfs_prepare_to_store
;
172 procfs_ops
.to_fetch_registers
= procfs_fetch_registers
;
173 procfs_ops
.to_store_registers
= procfs_store_registers
;
174 procfs_ops
.to_xfer_partial
= procfs_xfer_partial
;
175 procfs_ops
.deprecated_xfer_memory
= procfs_xfer_memory
;
176 procfs_ops
.to_insert_breakpoint
= memory_insert_breakpoint
;
177 procfs_ops
.to_remove_breakpoint
= memory_remove_breakpoint
;
178 procfs_ops
.to_notice_signals
= procfs_notice_signals
;
179 procfs_ops
.to_files_info
= procfs_files_info
;
180 procfs_ops
.to_stop
= procfs_stop
;
182 procfs_ops
.to_terminal_init
= terminal_init_inferior
;
183 procfs_ops
.to_terminal_inferior
= terminal_inferior
;
184 procfs_ops
.to_terminal_ours_for_output
= terminal_ours_for_output
;
185 procfs_ops
.to_terminal_ours
= terminal_ours
;
186 procfs_ops
.to_terminal_save_ours
= terminal_save_ours
;
187 procfs_ops
.to_terminal_info
= child_terminal_info
;
189 procfs_ops
.to_find_new_threads
= procfs_find_new_threads
;
190 procfs_ops
.to_thread_alive
= procfs_thread_alive
;
191 procfs_ops
.to_pid_to_str
= procfs_pid_to_str
;
193 procfs_ops
.to_has_all_memory
= 1;
194 procfs_ops
.to_has_memory
= 1;
195 procfs_ops
.to_has_execution
= 1;
196 procfs_ops
.to_has_stack
= 1;
197 procfs_ops
.to_has_registers
= 1;
198 procfs_ops
.to_stratum
= process_stratum
;
199 procfs_ops
.to_has_thread_control
= tc_schedlock
;
200 procfs_ops
.to_find_memory_regions
= proc_find_memory_regions
;
201 procfs_ops
.to_make_corefile_notes
= procfs_make_note_section
;
202 procfs_ops
.to_can_use_hw_breakpoint
= procfs_can_use_hw_breakpoint
;
203 procfs_ops
.to_magic
= OPS_MAGIC
;
206 /* =================== END, TARGET_OPS "MODULE" =================== */
211 * Put any typedefs, defines etc. here that are required for
212 * the unification of code that handles different versions of /proc.
215 #ifdef NEW_PROC_API /* Solaris 7 && 8 method for watchpoints */
217 enum { READ_WATCHFLAG
= WA_READ
,
218 WRITE_WATCHFLAG
= WA_WRITE
,
219 EXEC_WATCHFLAG
= WA_EXEC
,
220 AFTER_WATCHFLAG
= WA_TRAPAFTER
223 #else /* Irix method for watchpoints */
224 enum { READ_WATCHFLAG
= MA_READ
,
225 WRITE_WATCHFLAG
= MA_WRITE
,
226 EXEC_WATCHFLAG
= MA_EXEC
,
227 AFTER_WATCHFLAG
= 0 /* trapafter not implemented */
232 #ifdef HAVE_PR_SIGSET_T
233 typedef pr_sigset_t gdb_sigset_t
;
235 typedef sigset_t gdb_sigset_t
;
239 #ifdef HAVE_PR_SIGACTION64_T
240 typedef pr_sigaction64_t gdb_sigaction_t
;
242 typedef struct sigaction gdb_sigaction_t
;
246 #ifdef HAVE_PR_SIGINFO64_T
247 typedef pr_siginfo64_t gdb_siginfo_t
;
249 typedef struct siginfo gdb_siginfo_t
;
252 /* gdb_premptysysset */
254 #define gdb_premptysysset premptysysset
256 #define gdb_premptysysset premptyset
261 #define gdb_praddsysset praddsysset
263 #define gdb_praddsysset praddset
268 #define gdb_prdelsysset prdelsysset
270 #define gdb_prdelsysset prdelset
273 /* prissyssetmember */
274 #ifdef prissyssetmember
275 #define gdb_pr_issyssetmember prissyssetmember
277 #define gdb_pr_issyssetmember prismember
280 /* As a feature test, saying ``#if HAVE_PRSYSENT_T'' everywhere isn't
281 as intuitively descriptive as it could be, so we'll define
282 DYNAMIC_SYSCALLS to mean the same thing. Anyway, at the time of
283 this writing, this feature is only found on AIX5 systems and
284 basically means that the set of syscalls is not fixed. I.e,
285 there's no nice table that one can #include to get all of the
286 syscall numbers. Instead, they're stored in /proc/PID/sysent
287 for each process. We are at least guaranteed that they won't
288 change over the lifetime of the process. But each process could
289 (in theory) have different syscall numbers.
291 #ifdef HAVE_PRSYSENT_T
292 #define DYNAMIC_SYSCALLS
297 /* =================== STRUCT PROCINFO "MODULE" =================== */
299 /* FIXME: this comment will soon be out of date W.R.T. threads. */
301 /* The procinfo struct is a wrapper to hold all the state information
302 concerning a /proc process. There should be exactly one procinfo
303 for each process, and since GDB currently can debug only one
304 process at a time, that means there should be only one procinfo.
305 All of the LWP's of a process can be accessed indirectly thru the
306 single process procinfo.
308 However, against the day when GDB may debug more than one process,
309 this data structure is kept in a list (which for now will hold no
310 more than one member), and many functions will have a pointer to a
311 procinfo as an argument.
313 There will be a separate procinfo structure for use by the (not yet
314 implemented) "info proc" command, so that we can print useful
315 information about any random process without interfering with the
316 inferior's procinfo information. */
319 /* format strings for /proc paths */
320 # ifndef CTL_PROC_NAME_FMT
321 # define MAIN_PROC_NAME_FMT "/proc/%d"
322 # define CTL_PROC_NAME_FMT "/proc/%d/ctl"
323 # define AS_PROC_NAME_FMT "/proc/%d/as"
324 # define MAP_PROC_NAME_FMT "/proc/%d/map"
325 # define STATUS_PROC_NAME_FMT "/proc/%d/status"
326 # define MAX_PROC_NAME_SIZE sizeof("/proc/99999/lwp/8096/lstatus")
328 /* the name of the proc status struct depends on the implementation */
329 typedef pstatus_t gdb_prstatus_t
;
330 typedef lwpstatus_t gdb_lwpstatus_t
;
331 #else /* ! NEW_PROC_API */
332 /* format strings for /proc paths */
333 # ifndef CTL_PROC_NAME_FMT
334 # define MAIN_PROC_NAME_FMT "/proc/%05d"
335 # define CTL_PROC_NAME_FMT "/proc/%05d"
336 # define AS_PROC_NAME_FMT "/proc/%05d"
337 # define MAP_PROC_NAME_FMT "/proc/%05d"
338 # define STATUS_PROC_NAME_FMT "/proc/%05d"
339 # define MAX_PROC_NAME_SIZE sizeof("/proc/ttttppppp")
341 /* the name of the proc status struct depends on the implementation */
342 typedef prstatus_t gdb_prstatus_t
;
343 typedef prstatus_t gdb_lwpstatus_t
;
344 #endif /* NEW_PROC_API */
346 typedef struct procinfo
{
347 struct procinfo
*next
;
348 int pid
; /* Process ID */
349 int tid
; /* Thread/LWP id */
353 int ignore_next_sigstop
;
355 /* The following four fd fields may be identical, or may contain
356 several different fd's, depending on the version of /proc
357 (old ioctl or new read/write). */
359 int ctl_fd
; /* File descriptor for /proc control file */
361 * The next three file descriptors are actually only needed in the
362 * read/write, multiple-file-descriptor implemenation (NEW_PROC_API).
363 * However, to avoid a bunch of #ifdefs in the code, we will use
364 * them uniformly by (in the case of the ioctl single-file-descriptor
365 * implementation) filling them with copies of the control fd.
367 int status_fd
; /* File descriptor for /proc status file */
368 int as_fd
; /* File descriptor for /proc as file */
370 char pathname
[MAX_PROC_NAME_SIZE
]; /* Pathname to /proc entry */
372 fltset_t saved_fltset
; /* Saved traced hardware fault set */
373 gdb_sigset_t saved_sigset
; /* Saved traced signal set */
374 gdb_sigset_t saved_sighold
; /* Saved held signal set */
375 sysset_t
*saved_exitset
; /* Saved traced system call exit set */
376 sysset_t
*saved_entryset
; /* Saved traced system call entry set */
378 gdb_prstatus_t prstatus
; /* Current process status info */
381 gdb_fpregset_t fpregset
; /* Current floating point registers */
384 #ifdef DYNAMIC_SYSCALLS
385 int num_syscalls
; /* Total number of syscalls */
386 char **syscall_names
; /* Syscall number to name map */
389 struct procinfo
*thread_list
;
391 int status_valid
: 1;
393 int fpregs_valid
: 1;
394 int threads_valid
: 1;
397 static char errmsg
[128]; /* shared error msg buffer */
399 /* Function prototypes for procinfo module: */
401 static procinfo
*find_procinfo_or_die (int pid
, int tid
);
402 static procinfo
*find_procinfo (int pid
, int tid
);
403 static procinfo
*create_procinfo (int pid
, int tid
);
404 static void destroy_procinfo (procinfo
* p
);
405 static void do_destroy_procinfo_cleanup (void *);
406 static void dead_procinfo (procinfo
* p
, char *msg
, int killp
);
407 static int open_procinfo_files (procinfo
* p
, int which
);
408 static void close_procinfo_files (procinfo
* p
);
409 static int sysset_t_size (procinfo
*p
);
410 static sysset_t
*sysset_t_alloc (procinfo
* pi
);
411 #ifdef DYNAMIC_SYSCALLS
412 static void load_syscalls (procinfo
*pi
);
413 static void free_syscalls (procinfo
*pi
);
414 static int find_syscall (procinfo
*pi
, char *name
);
415 #endif /* DYNAMIC_SYSCALLS */
417 /* The head of the procinfo list: */
418 static procinfo
* procinfo_list
;
421 * Function: find_procinfo
423 * Search the procinfo list.
425 * Returns: pointer to procinfo, or NULL if not found.
429 find_procinfo (int pid
, int tid
)
433 for (pi
= procinfo_list
; pi
; pi
= pi
->next
)
440 /* Don't check threads_valid. If we're updating the
441 thread_list, we want to find whatever threads are already
442 here. This means that in general it is the caller's
443 responsibility to check threads_valid and update before
444 calling find_procinfo, if the caller wants to find a new
447 for (pi
= pi
->thread_list
; pi
; pi
= pi
->next
)
456 * Function: find_procinfo_or_die
458 * Calls find_procinfo, but errors on failure.
462 find_procinfo_or_die (int pid
, int tid
)
464 procinfo
*pi
= find_procinfo (pid
, tid
);
469 error ("procfs: couldn't find pid %d (kernel thread %d) in procinfo list.",
472 error ("procfs: couldn't find pid %d in procinfo list.", pid
);
477 /* open_with_retry() is a wrapper for open(). The appropriate
478 open() call is attempted; if unsuccessful, it will be retried as
479 many times as needed for the EAGAIN and EINTR conditions.
481 For other conditions, open_with_retry() will retry the open() a
482 limited number of times. In addition, a short sleep is imposed
483 prior to retrying the open(). The reason for this sleep is to give
484 the kernel a chance to catch up and create the file in question in
485 the event that GDB "wins" the race to open a file before the kernel
489 open_with_retry (const char *pathname
, int flags
)
491 int retries_remaining
, status
;
493 retries_remaining
= 2;
497 status
= open (pathname
, flags
);
499 if (status
>= 0 || retries_remaining
== 0)
501 else if (errno
!= EINTR
&& errno
!= EAGAIN
)
512 * Function: open_procinfo_files
514 * Open the file descriptor for the process or LWP.
515 * ifdef NEW_PROC_API, we only open the control file descriptor;
516 * the others are opened lazily as needed.
517 * else (if not NEW_PROC_API), there is only one real
518 * file descriptor, but we keep multiple copies of it so that
519 * the code that uses them does not have to be #ifdef'd.
521 * Return: file descriptor, or zero for failure.
524 enum { FD_CTL
, FD_STATUS
, FD_AS
};
527 open_procinfo_files (procinfo
*pi
, int which
)
530 char tmp
[MAX_PROC_NAME_SIZE
];
535 * This function is getting ALMOST long enough to break up into several.
536 * Here is some rationale:
538 * NEW_PROC_API (Solaris 2.6, Solaris 2.7, Unixware):
539 * There are several file descriptors that may need to be open
540 * for any given process or LWP. The ones we're intereted in are:
541 * - control (ctl) write-only change the state
542 * - status (status) read-only query the state
543 * - address space (as) read/write access memory
544 * - map (map) read-only virtual addr map
545 * Most of these are opened lazily as they are needed.
546 * The pathnames for the 'files' for an LWP look slightly
547 * different from those of a first-class process:
548 * Pathnames for a process (<proc-id>):
549 * /proc/<proc-id>/ctl
550 * /proc/<proc-id>/status
552 * /proc/<proc-id>/map
553 * Pathnames for an LWP (lwp-id):
554 * /proc/<proc-id>/lwp/<lwp-id>/lwpctl
555 * /proc/<proc-id>/lwp/<lwp-id>/lwpstatus
556 * An LWP has no map or address space file descriptor, since
557 * the memory map and address space are shared by all LWPs.
559 * Everyone else (Solaris 2.5, Irix, OSF)
560 * There is only one file descriptor for each process or LWP.
561 * For convenience, we copy the same file descriptor into all
562 * three fields of the procinfo struct (ctl_fd, status_fd, and
563 * as_fd, see NEW_PROC_API above) so that code that uses them
564 * doesn't need any #ifdef's.
569 * Each LWP has an independent file descriptor, but these
570 * are not obtained via the 'open' system call like the rest:
571 * instead, they're obtained thru an ioctl call (PIOCOPENLWP)
572 * to the file descriptor of the parent process.
575 * These do not even have their own independent file descriptor.
576 * All operations are carried out on the file descriptor of the
577 * parent process. Therefore we just call open again for each
578 * thread, getting a new handle for the same 'file'.
583 * In this case, there are several different file descriptors that
584 * we might be asked to open. The control file descriptor will be
585 * opened early, but the others will be opened lazily as they are
589 strcpy (tmp
, pi
->pathname
);
590 switch (which
) { /* which file descriptor to open? */
593 strcat (tmp
, "/lwpctl");
595 strcat (tmp
, "/ctl");
596 fd
= open_with_retry (tmp
, O_WRONLY
);
603 return 0; /* there is no 'as' file descriptor for an lwp */
605 fd
= open_with_retry (tmp
, O_RDWR
);
612 strcat (tmp
, "/lwpstatus");
614 strcat (tmp
, "/status");
615 fd
= open_with_retry (tmp
, O_RDONLY
);
621 return 0; /* unknown file descriptor */
623 #else /* not NEW_PROC_API */
625 * In this case, there is only one file descriptor for each procinfo
626 * (ie. each process or LWP). In fact, only the file descriptor for
627 * the process can actually be opened by an 'open' system call.
628 * The ones for the LWPs have to be obtained thru an IOCTL call
629 * on the process's file descriptor.
631 * For convenience, we copy each procinfo's single file descriptor
632 * into all of the fields occupied by the several file descriptors
633 * of the NEW_PROC_API implementation. That way, the code that uses
634 * them can be written without ifdefs.
638 #ifdef PIOCTSTATUS /* OSF */
639 /* Only one FD; just open it. */
640 if ((fd
= open_with_retry (pi
->pathname
, O_RDWR
)) == 0)
642 #else /* Sol 2.5, Irix, other? */
643 if (pi
->tid
== 0) /* Master procinfo for the process */
645 fd
= open_with_retry (pi
->pathname
, O_RDWR
);
649 else /* LWP thread procinfo */
651 #ifdef PIOCOPENLWP /* Sol 2.5, thread/LWP */
655 /* Find the procinfo for the entire process. */
656 if ((process
= find_procinfo (pi
->pid
, 0)) == NULL
)
659 /* Now obtain the file descriptor for the LWP. */
660 if ((fd
= ioctl (process
->ctl_fd
, PIOCOPENLWP
, &lwpid
)) <= 0)
662 #else /* Irix, other? */
663 return 0; /* Don't know how to open threads */
664 #endif /* Sol 2.5 PIOCOPENLWP */
666 #endif /* OSF PIOCTSTATUS */
667 pi
->ctl_fd
= pi
->as_fd
= pi
->status_fd
= fd
;
668 #endif /* NEW_PROC_API */
670 return 1; /* success */
674 * Function: create_procinfo
676 * Allocate a data structure and link it into the procinfo list.
677 * (First tries to find a pre-existing one (FIXME: why?)
679 * Return: pointer to new procinfo struct.
683 create_procinfo (int pid
, int tid
)
685 procinfo
*pi
, *parent
;
687 if ((pi
= find_procinfo (pid
, tid
)))
688 return pi
; /* Already exists, nothing to do. */
690 /* find parent before doing malloc, to save having to cleanup */
692 parent
= find_procinfo_or_die (pid
, 0); /* FIXME: should I
694 doesn't exist yet? */
696 pi
= (procinfo
*) xmalloc (sizeof (procinfo
));
697 memset (pi
, 0, sizeof (procinfo
));
701 #ifdef DYNAMIC_SYSCALLS
705 pi
->saved_entryset
= sysset_t_alloc (pi
);
706 pi
->saved_exitset
= sysset_t_alloc (pi
);
708 /* Chain into list. */
711 sprintf (pi
->pathname
, MAIN_PROC_NAME_FMT
, pid
);
712 pi
->next
= procinfo_list
;
718 sprintf (pi
->pathname
, "/proc/%05d/lwp/%d", pid
, tid
);
720 sprintf (pi
->pathname
, MAIN_PROC_NAME_FMT
, pid
);
722 pi
->next
= parent
->thread_list
;
723 parent
->thread_list
= pi
;
729 * Function: close_procinfo_files
731 * Close all file descriptors associated with the procinfo
735 close_procinfo_files (procinfo
*pi
)
742 if (pi
->status_fd
> 0)
743 close (pi
->status_fd
);
745 pi
->ctl_fd
= pi
->as_fd
= pi
->status_fd
= 0;
749 * Function: destroy_procinfo
751 * Destructor function. Close, unlink and deallocate the object.
755 destroy_one_procinfo (procinfo
**list
, procinfo
*pi
)
759 /* Step one: unlink the procinfo from its list */
763 for (ptr
= *list
; ptr
; ptr
= ptr
->next
)
766 ptr
->next
= pi
->next
;
770 /* Step two: close any open file descriptors */
771 close_procinfo_files (pi
);
773 /* Step three: free the memory. */
774 #ifdef DYNAMIC_SYSCALLS
777 xfree (pi
->saved_entryset
);
778 xfree (pi
->saved_exitset
);
783 destroy_procinfo (procinfo
*pi
)
787 if (pi
->tid
!= 0) /* destroy a thread procinfo */
789 tmp
= find_procinfo (pi
->pid
, 0); /* find the parent process */
790 destroy_one_procinfo (&tmp
->thread_list
, pi
);
792 else /* destroy a process procinfo and all its threads */
794 /* First destroy the children, if any; */
795 while (pi
->thread_list
!= NULL
)
796 destroy_one_procinfo (&pi
->thread_list
, pi
->thread_list
);
797 /* Then destroy the parent. Genocide!!! */
798 destroy_one_procinfo (&procinfo_list
, pi
);
803 do_destroy_procinfo_cleanup (void *pi
)
805 destroy_procinfo (pi
);
808 enum { NOKILL
, KILL
};
811 * Function: dead_procinfo
813 * To be called on a non_recoverable error for a procinfo.
814 * Prints error messages, optionally sends a SIGKILL to the process,
815 * then destroys the data structure.
819 dead_procinfo (procinfo
*pi
, char *msg
, int kill_p
)
825 print_sys_errmsg (pi
->pathname
, errno
);
829 sprintf (procfile
, "process %d", pi
->pid
);
830 print_sys_errmsg (procfile
, errno
);
833 kill (pi
->pid
, SIGKILL
);
835 destroy_procinfo (pi
);
840 * Function: sysset_t_size
842 * Returns the (complete) size of a sysset_t struct. Normally, this
843 * is just sizeof (syset_t), but in the case of Monterey/64, the actual
844 * size of sysset_t isn't known until runtime.
848 sysset_t_size (procinfo
* pi
)
850 #ifndef DYNAMIC_SYSCALLS
851 return sizeof (sysset_t
);
853 return sizeof (sysset_t
) - sizeof (uint64_t)
854 + sizeof (uint64_t) * ((pi
->num_syscalls
+ (8 * sizeof (uint64_t) - 1))
855 / (8 * sizeof (uint64_t)));
859 /* Function: sysset_t_alloc
861 Allocate and (partially) initialize a sysset_t struct. */
864 sysset_t_alloc (procinfo
* pi
)
867 int size
= sysset_t_size (pi
);
868 ret
= xmalloc (size
);
869 #ifdef DYNAMIC_SYSCALLS
870 ret
->pr_size
= (pi
->num_syscalls
+ (8 * sizeof (uint64_t) - 1))
871 / (8 * sizeof (uint64_t));
876 #ifdef DYNAMIC_SYSCALLS
878 /* Function: load_syscalls
880 Extract syscall numbers and names from /proc/<pid>/sysent. Initialize
881 pi->num_syscalls with the number of syscalls and pi->syscall_names
882 with the names. (Certain numbers may be skipped in which case the
883 names for these numbers will be left as NULL.) */
885 #define MAX_SYSCALL_NAME_LENGTH 256
886 #define MAX_SYSCALLS 65536
889 load_syscalls (procinfo
*pi
)
891 char pathname
[MAX_PROC_NAME_SIZE
];
894 prsyscall_t
*syscalls
;
895 int i
, size
, maxcall
;
897 pi
->num_syscalls
= 0;
898 pi
->syscall_names
= 0;
900 /* Open the file descriptor for the sysent file */
901 sprintf (pathname
, "/proc/%d/sysent", pi
->pid
);
902 sysent_fd
= open_with_retry (pathname
, O_RDONLY
);
905 error ("load_syscalls: Can't open /proc/%d/sysent", pi
->pid
);
908 size
= sizeof header
- sizeof (prsyscall_t
);
909 if (read (sysent_fd
, &header
, size
) != size
)
911 error ("load_syscalls: Error reading /proc/%d/sysent", pi
->pid
);
914 if (header
.pr_nsyscalls
== 0)
916 error ("load_syscalls: /proc/%d/sysent contains no syscalls!", pi
->pid
);
919 size
= header
.pr_nsyscalls
* sizeof (prsyscall_t
);
920 syscalls
= xmalloc (size
);
922 if (read (sysent_fd
, syscalls
, size
) != size
)
925 error ("load_syscalls: Error reading /proc/%d/sysent", pi
->pid
);
928 /* Find maximum syscall number. This may not be the same as
929 pr_nsyscalls since that value refers to the number of entries
930 in the table. (Also, the docs indicate that some system
931 call numbers may be skipped.) */
933 maxcall
= syscalls
[0].pr_number
;
935 for (i
= 1; i
< header
.pr_nsyscalls
; i
++)
936 if (syscalls
[i
].pr_number
> maxcall
937 && syscalls
[i
].pr_nameoff
> 0
938 && syscalls
[i
].pr_number
< MAX_SYSCALLS
)
939 maxcall
= syscalls
[i
].pr_number
;
941 pi
->num_syscalls
= maxcall
+1;
942 pi
->syscall_names
= xmalloc (pi
->num_syscalls
* sizeof (char *));
944 for (i
= 0; i
< pi
->num_syscalls
; i
++)
945 pi
->syscall_names
[i
] = NULL
;
947 /* Read the syscall names in */
948 for (i
= 0; i
< header
.pr_nsyscalls
; i
++)
950 char namebuf
[MAX_SYSCALL_NAME_LENGTH
];
954 if (syscalls
[i
].pr_number
>= MAX_SYSCALLS
955 || syscalls
[i
].pr_number
< 0
956 || syscalls
[i
].pr_nameoff
<= 0
957 || (lseek (sysent_fd
, (off_t
) syscalls
[i
].pr_nameoff
, SEEK_SET
)
958 != (off_t
) syscalls
[i
].pr_nameoff
))
961 nread
= read (sysent_fd
, namebuf
, sizeof namebuf
);
965 callnum
= syscalls
[i
].pr_number
;
967 if (pi
->syscall_names
[callnum
] != NULL
)
969 /* FIXME: Generate warning */
973 namebuf
[nread
-1] = '\0';
974 size
= strlen (namebuf
) + 1;
975 pi
->syscall_names
[callnum
] = xmalloc (size
);
976 strncpy (pi
->syscall_names
[callnum
], namebuf
, size
-1);
977 pi
->syscall_names
[callnum
][size
-1] = '\0';
984 /* Function: free_syscalls
986 Free the space allocated for the syscall names from the procinfo
990 free_syscalls (procinfo
*pi
)
992 if (pi
->syscall_names
)
996 for (i
= 0; i
< pi
->num_syscalls
; i
++)
997 if (pi
->syscall_names
[i
] != NULL
)
998 xfree (pi
->syscall_names
[i
]);
1000 xfree (pi
->syscall_names
);
1001 pi
->syscall_names
= 0;
1005 /* Function: find_syscall
1007 Given a name, look up (and return) the corresponding syscall number.
1008 If no match is found, return -1. */
1011 find_syscall (procinfo
*pi
, char *name
)
1014 for (i
= 0; i
< pi
->num_syscalls
; i
++)
1016 if (pi
->syscall_names
[i
] && strcmp (name
, pi
->syscall_names
[i
]) == 0)
1023 /* =================== END, STRUCT PROCINFO "MODULE" =================== */
1025 /* =================== /proc "MODULE" =================== */
1028 * This "module" is the interface layer between the /proc system API
1029 * and the gdb target vector functions. This layer consists of
1030 * access functions that encapsulate each of the basic operations
1031 * that we need to use from the /proc API.
1033 * The main motivation for this layer is to hide the fact that
1034 * there are two very different implementations of the /proc API.
1035 * Rather than have a bunch of #ifdefs all thru the gdb target vector
1036 * functions, we do our best to hide them all in here.
1039 int proc_get_status (procinfo
* pi
);
1040 long proc_flags (procinfo
* pi
);
1041 int proc_why (procinfo
* pi
);
1042 int proc_what (procinfo
* pi
);
1043 int proc_set_run_on_last_close (procinfo
* pi
);
1044 int proc_unset_run_on_last_close (procinfo
* pi
);
1045 int proc_set_inherit_on_fork (procinfo
* pi
);
1046 int proc_unset_inherit_on_fork (procinfo
* pi
);
1047 int proc_set_async (procinfo
* pi
);
1048 int proc_unset_async (procinfo
* pi
);
1049 int proc_stop_process (procinfo
* pi
);
1050 int proc_trace_signal (procinfo
* pi
, int signo
);
1051 int proc_ignore_signal (procinfo
* pi
, int signo
);
1052 int proc_clear_current_fault (procinfo
* pi
);
1053 int proc_set_current_signal (procinfo
* pi
, int signo
);
1054 int proc_clear_current_signal (procinfo
* pi
);
1055 int proc_set_gregs (procinfo
* pi
);
1056 int proc_set_fpregs (procinfo
* pi
);
1057 int proc_wait_for_stop (procinfo
* pi
);
1058 int proc_run_process (procinfo
* pi
, int step
, int signo
);
1059 int proc_kill (procinfo
* pi
, int signo
);
1060 int proc_parent_pid (procinfo
* pi
);
1061 int proc_get_nthreads (procinfo
* pi
);
1062 int proc_get_current_thread (procinfo
* pi
);
1063 int proc_set_held_signals (procinfo
* pi
, gdb_sigset_t
* sighold
);
1064 int proc_set_traced_sysexit (procinfo
* pi
, sysset_t
* sysset
);
1065 int proc_set_traced_sysentry (procinfo
* pi
, sysset_t
* sysset
);
1066 int proc_set_traced_faults (procinfo
* pi
, fltset_t
* fltset
);
1067 int proc_set_traced_signals (procinfo
* pi
, gdb_sigset_t
* sigset
);
1069 int proc_update_threads (procinfo
* pi
);
1070 int proc_iterate_over_threads (procinfo
* pi
,
1071 int (*func
) (procinfo
*, procinfo
*, void *),
1074 gdb_gregset_t
*proc_get_gregs (procinfo
* pi
);
1075 gdb_fpregset_t
*proc_get_fpregs (procinfo
* pi
);
1076 sysset_t
*proc_get_traced_sysexit (procinfo
* pi
, sysset_t
* save
);
1077 sysset_t
*proc_get_traced_sysentry (procinfo
* pi
, sysset_t
* save
);
1078 fltset_t
*proc_get_traced_faults (procinfo
* pi
, fltset_t
* save
);
1079 gdb_sigset_t
*proc_get_traced_signals (procinfo
* pi
, gdb_sigset_t
* save
);
1080 gdb_sigset_t
*proc_get_held_signals (procinfo
* pi
, gdb_sigset_t
* save
);
1081 gdb_sigset_t
*proc_get_pending_signals (procinfo
* pi
, gdb_sigset_t
* save
);
1082 gdb_sigaction_t
*proc_get_signal_actions (procinfo
* pi
, gdb_sigaction_t
*save
);
1084 void proc_warn (procinfo
* pi
, char *func
, int line
);
1085 void proc_error (procinfo
* pi
, char *func
, int line
);
1088 proc_warn (procinfo
*pi
, char *func
, int line
)
1090 sprintf (errmsg
, "procfs: %s line %d, %s", func
, line
, pi
->pathname
);
1091 print_sys_errmsg (errmsg
, errno
);
1095 proc_error (procinfo
*pi
, char *func
, int line
)
1097 sprintf (errmsg
, "procfs: %s line %d, %s", func
, line
, pi
->pathname
);
1098 perror_with_name (errmsg
);
1102 * Function: proc_get_status
1104 * Updates the status struct in the procinfo.
1105 * There is a 'valid' flag, to let other functions know when
1106 * this function needs to be called (so the status is only
1107 * read when it is needed). The status file descriptor is
1108 * also only opened when it is needed.
1110 * Return: non-zero for success, zero for failure.
1114 proc_get_status (procinfo
*pi
)
1116 /* Status file descriptor is opened "lazily" */
1117 if (pi
->status_fd
== 0 &&
1118 open_procinfo_files (pi
, FD_STATUS
) == 0)
1120 pi
->status_valid
= 0;
1125 if (lseek (pi
->status_fd
, 0, SEEK_SET
) < 0)
1126 pi
->status_valid
= 0; /* fail */
1129 /* Sigh... I have to read a different data structure,
1130 depending on whether this is a main process or an LWP. */
1132 pi
->status_valid
= (read (pi
->status_fd
,
1133 (char *) &pi
->prstatus
.pr_lwp
,
1134 sizeof (lwpstatus_t
))
1135 == sizeof (lwpstatus_t
));
1138 pi
->status_valid
= (read (pi
->status_fd
,
1139 (char *) &pi
->prstatus
,
1140 sizeof (gdb_prstatus_t
))
1141 == sizeof (gdb_prstatus_t
));
1142 #if 0 /*def UNIXWARE*/
1143 if (pi
->status_valid
&&
1144 (pi
->prstatus
.pr_lwp
.pr_flags
& PR_ISTOP
) &&
1145 pi
->prstatus
.pr_lwp
.pr_why
== PR_REQUESTED
)
1146 /* Unixware peculiarity -- read the damn thing again! */
1147 pi
->status_valid
= (read (pi
->status_fd
,
1148 (char *) &pi
->prstatus
,
1149 sizeof (gdb_prstatus_t
))
1150 == sizeof (gdb_prstatus_t
));
1151 #endif /* UNIXWARE */
1154 #else /* ioctl method */
1155 #ifdef PIOCTSTATUS /* osf */
1156 if (pi
->tid
== 0) /* main process */
1158 /* Just read the danged status. Now isn't that simple? */
1160 (ioctl (pi
->status_fd
, PIOCSTATUS
, &pi
->prstatus
) >= 0);
1167 tid_t pr_error_thread
;
1168 struct prstatus status
;
1171 thread_status
.pr_count
= 1;
1172 thread_status
.status
.pr_tid
= pi
->tid
;
1173 win
= (ioctl (pi
->status_fd
, PIOCTSTATUS
, &thread_status
) >= 0);
1176 memcpy (&pi
->prstatus
, &thread_status
.status
,
1177 sizeof (pi
->prstatus
));
1178 pi
->status_valid
= 1;
1182 /* Just read the danged status. Now isn't that simple? */
1183 pi
->status_valid
= (ioctl (pi
->status_fd
, PIOCSTATUS
, &pi
->prstatus
) >= 0);
1187 if (pi
->status_valid
)
1189 PROC_PRETTYFPRINT_STATUS (proc_flags (pi
),
1192 proc_get_current_thread (pi
));
1195 /* The status struct includes general regs, so mark them valid too */
1196 pi
->gregs_valid
= pi
->status_valid
;
1198 /* In the read/write multiple-fd model,
1199 the status struct includes the fp regs too, so mark them valid too */
1200 pi
->fpregs_valid
= pi
->status_valid
;
1202 return pi
->status_valid
; /* True if success, false if failure. */
1206 * Function: proc_flags
1208 * returns the process flags (pr_flags field).
1212 proc_flags (procinfo
*pi
)
1214 if (!pi
->status_valid
)
1215 if (!proc_get_status (pi
))
1216 return 0; /* FIXME: not a good failure value (but what is?) */
1220 /* UnixWare 7.1 puts process status flags, e.g. PR_ASYNC, in
1221 pstatus_t and LWP status flags, e.g. PR_STOPPED, in lwpstatus_t.
1222 The two sets of flags don't overlap. */
1223 return pi
->prstatus
.pr_flags
| pi
->prstatus
.pr_lwp
.pr_flags
;
1225 return pi
->prstatus
.pr_lwp
.pr_flags
;
1228 return pi
->prstatus
.pr_flags
;
1233 * Function: proc_why
1235 * returns the pr_why field (why the process stopped).
1239 proc_why (procinfo
*pi
)
1241 if (!pi
->status_valid
)
1242 if (!proc_get_status (pi
))
1243 return 0; /* FIXME: not a good failure value (but what is?) */
1246 return pi
->prstatus
.pr_lwp
.pr_why
;
1248 return pi
->prstatus
.pr_why
;
1253 * Function: proc_what
1255 * returns the pr_what field (details of why the process stopped).
1259 proc_what (procinfo
*pi
)
1261 if (!pi
->status_valid
)
1262 if (!proc_get_status (pi
))
1263 return 0; /* FIXME: not a good failure value (but what is?) */
1266 return pi
->prstatus
.pr_lwp
.pr_what
;
1268 return pi
->prstatus
.pr_what
;
1272 #ifndef PIOCSSPCACT /* The following is not supported on OSF. */
1274 * Function: proc_nsysarg
1276 * returns the pr_nsysarg field (number of args to the current syscall).
1280 proc_nsysarg (procinfo
*pi
)
1282 if (!pi
->status_valid
)
1283 if (!proc_get_status (pi
))
1287 return pi
->prstatus
.pr_lwp
.pr_nsysarg
;
1289 return pi
->prstatus
.pr_nsysarg
;
1294 * Function: proc_sysargs
1296 * returns the pr_sysarg field (pointer to the arguments of current syscall).
1300 proc_sysargs (procinfo
*pi
)
1302 if (!pi
->status_valid
)
1303 if (!proc_get_status (pi
))
1307 return (long *) &pi
->prstatus
.pr_lwp
.pr_sysarg
;
1309 return (long *) &pi
->prstatus
.pr_sysarg
;
1314 * Function: proc_syscall
1316 * returns the pr_syscall field (id of current syscall if we are in one).
1320 proc_syscall (procinfo
*pi
)
1322 if (!pi
->status_valid
)
1323 if (!proc_get_status (pi
))
1327 return pi
->prstatus
.pr_lwp
.pr_syscall
;
1329 return pi
->prstatus
.pr_syscall
;
1332 #endif /* PIOCSSPCACT */
1335 * Function: proc_cursig:
1337 * returns the pr_cursig field (current signal).
1341 proc_cursig (struct procinfo
*pi
)
1343 if (!pi
->status_valid
)
1344 if (!proc_get_status (pi
))
1345 return 0; /* FIXME: not a good failure value (but what is?) */
1348 return pi
->prstatus
.pr_lwp
.pr_cursig
;
1350 return pi
->prstatus
.pr_cursig
;
1355 * Function: proc_modify_flag
1357 * === I appologize for the messiness of this function.
1358 * === This is an area where the different versions of
1359 * === /proc are more inconsistent than usual. MVS
1361 * Set or reset any of the following process flags:
1362 * PR_FORK -- forked child will inherit trace flags
1363 * PR_RLC -- traced process runs when last /proc file closed.
1364 * PR_KLC -- traced process is killed when last /proc file closed.
1365 * PR_ASYNC -- LWP's get to run/stop independently.
1367 * There are three methods for doing this function:
1368 * 1) Newest: read/write [PCSET/PCRESET/PCUNSET]
1370 * 2) Middle: PIOCSET/PIOCRESET
1372 * 3) Oldest: PIOCSFORK/PIOCRFORK/PIOCSRLC/PIOCRRLC
1375 * Note: Irix does not define PR_ASYNC.
1376 * Note: OSF does not define PR_KLC.
1377 * Note: OSF is the only one that can ONLY use the oldest method.
1380 * pi -- the procinfo
1381 * flag -- one of PR_FORK, PR_RLC, or PR_ASYNC
1382 * mode -- 1 for set, 0 for reset.
1384 * Returns non-zero for success, zero for failure.
1387 enum { FLAG_RESET
, FLAG_SET
};
1390 proc_modify_flag (procinfo
*pi
, long flag
, long mode
)
1392 long win
= 0; /* default to fail */
1395 * These operations affect the process as a whole, and applying
1396 * them to an individual LWP has the same meaning as applying them
1397 * to the main process. Therefore, if we're ever called with a
1398 * pointer to an LWP's procinfo, let's substitute the process's
1399 * procinfo and avoid opening the LWP's file descriptor
1404 pi
= find_procinfo_or_die (pi
->pid
, 0);
1406 #ifdef NEW_PROC_API /* Newest method: UnixWare and newer Solarii */
1407 /* First normalize the PCUNSET/PCRESET command opcode
1408 (which for no obvious reason has a different definition
1409 from one operating system to the next...) */
1411 #define GDBRESET PCUNSET
1414 #define GDBRESET PCRESET
1418 procfs_ctl_t arg
[2];
1420 if (mode
== FLAG_SET
) /* Set the flag (RLC, FORK, or ASYNC) */
1422 else /* Reset the flag */
1426 win
= (write (pi
->ctl_fd
, (void *) &arg
, sizeof (arg
)) == sizeof (arg
));
1429 #ifdef PIOCSET /* Irix/Sol5 method */
1430 if (mode
== FLAG_SET
) /* Set the flag (hopefully RLC, FORK, or ASYNC) */
1432 win
= (ioctl (pi
->ctl_fd
, PIOCSET
, &flag
) >= 0);
1434 else /* Reset the flag */
1436 win
= (ioctl (pi
->ctl_fd
, PIOCRESET
, &flag
) >= 0);
1440 #ifdef PIOCSRLC /* Oldest method: OSF */
1443 if (mode
== FLAG_SET
) /* Set run-on-last-close */
1445 win
= (ioctl (pi
->ctl_fd
, PIOCSRLC
, NULL
) >= 0);
1447 else /* Clear run-on-last-close */
1449 win
= (ioctl (pi
->ctl_fd
, PIOCRRLC
, NULL
) >= 0);
1453 if (mode
== FLAG_SET
) /* Set inherit-on-fork */
1455 win
= (ioctl (pi
->ctl_fd
, PIOCSFORK
, NULL
) >= 0);
1457 else /* Clear inherit-on-fork */
1459 win
= (ioctl (pi
->ctl_fd
, PIOCRFORK
, NULL
) >= 0);
1463 win
= 0; /* fail -- unknown flag (can't do PR_ASYNC) */
1470 /* The above operation renders the procinfo's cached pstatus obsolete. */
1471 pi
->status_valid
= 0;
1474 warning ("procfs: modify_flag failed to turn %s %s",
1475 flag
== PR_FORK
? "PR_FORK" :
1476 flag
== PR_RLC
? "PR_RLC" :
1478 flag
== PR_ASYNC
? "PR_ASYNC" :
1481 flag
== PR_KLC
? "PR_KLC" :
1484 mode
== FLAG_RESET
? "off" : "on");
1490 * Function: proc_set_run_on_last_close
1492 * Set the run_on_last_close flag.
1493 * Process with all threads will become runnable
1494 * when debugger closes all /proc fds.
1496 * Returns non-zero for success, zero for failure.
1500 proc_set_run_on_last_close (procinfo
*pi
)
1502 return proc_modify_flag (pi
, PR_RLC
, FLAG_SET
);
1506 * Function: proc_unset_run_on_last_close
1508 * Reset the run_on_last_close flag.
1509 * Process will NOT become runnable
1510 * when debugger closes its file handles.
1512 * Returns non-zero for success, zero for failure.
1516 proc_unset_run_on_last_close (procinfo
*pi
)
1518 return proc_modify_flag (pi
, PR_RLC
, FLAG_RESET
);
1523 * Function: proc_set_kill_on_last_close
1525 * Set the kill_on_last_close flag.
1526 * Process with all threads will be killed when debugger
1527 * closes all /proc fds (or debugger exits or dies).
1529 * Returns non-zero for success, zero for failure.
1533 proc_set_kill_on_last_close (procinfo
*pi
)
1535 return proc_modify_flag (pi
, PR_KLC
, FLAG_SET
);
1539 * Function: proc_unset_kill_on_last_close
1541 * Reset the kill_on_last_close flag.
1542 * Process will NOT be killed when debugger
1543 * closes its file handles (or exits or dies).
1545 * Returns non-zero for success, zero for failure.
1549 proc_unset_kill_on_last_close (procinfo
*pi
)
1551 return proc_modify_flag (pi
, PR_KLC
, FLAG_RESET
);
1556 * Function: proc_set_inherit_on_fork
1558 * Set inherit_on_fork flag.
1559 * If the process forks a child while we are registered for events
1560 * in the parent, then we will also recieve events from the child.
1562 * Returns non-zero for success, zero for failure.
1566 proc_set_inherit_on_fork (procinfo
*pi
)
1568 return proc_modify_flag (pi
, PR_FORK
, FLAG_SET
);
1572 * Function: proc_unset_inherit_on_fork
1574 * Reset inherit_on_fork flag.
1575 * If the process forks a child while we are registered for events
1576 * in the parent, then we will NOT recieve events from the child.
1578 * Returns non-zero for success, zero for failure.
1582 proc_unset_inherit_on_fork (procinfo
*pi
)
1584 return proc_modify_flag (pi
, PR_FORK
, FLAG_RESET
);
1589 * Function: proc_set_async
1591 * Set PR_ASYNC flag.
1592 * If one LWP stops because of a debug event (signal etc.),
1593 * the remaining LWPs will continue to run.
1595 * Returns non-zero for success, zero for failure.
1599 proc_set_async (procinfo
*pi
)
1601 return proc_modify_flag (pi
, PR_ASYNC
, FLAG_SET
);
1605 * Function: proc_unset_async
1607 * Reset PR_ASYNC flag.
1608 * If one LWP stops because of a debug event (signal etc.),
1609 * then all other LWPs will stop as well.
1611 * Returns non-zero for success, zero for failure.
1615 proc_unset_async (procinfo
*pi
)
1617 return proc_modify_flag (pi
, PR_ASYNC
, FLAG_RESET
);
1619 #endif /* PR_ASYNC */
1622 * Function: proc_stop_process
1624 * Request the process/LWP to stop. Does not wait.
1625 * Returns non-zero for success, zero for failure.
1629 proc_stop_process (procinfo
*pi
)
1634 * We might conceivably apply this operation to an LWP, and
1635 * the LWP's ctl file descriptor might not be open.
1638 if (pi
->ctl_fd
== 0 &&
1639 open_procinfo_files (pi
, FD_CTL
) == 0)
1644 procfs_ctl_t cmd
= PCSTOP
;
1645 win
= (write (pi
->ctl_fd
, (char *) &cmd
, sizeof (cmd
)) == sizeof (cmd
));
1646 #else /* ioctl method */
1647 win
= (ioctl (pi
->ctl_fd
, PIOCSTOP
, &pi
->prstatus
) >= 0);
1648 /* Note: the call also reads the prstatus. */
1651 pi
->status_valid
= 1;
1652 PROC_PRETTYFPRINT_STATUS (proc_flags (pi
),
1655 proc_get_current_thread (pi
));
1664 * Function: proc_wait_for_stop
1666 * Wait for the process or LWP to stop (block until it does).
1667 * Returns non-zero for success, zero for failure.
1671 proc_wait_for_stop (procinfo
*pi
)
1676 * We should never have to apply this operation to any procinfo
1677 * except the one for the main process. If that ever changes
1678 * for any reason, then take out the following clause and
1679 * replace it with one that makes sure the ctl_fd is open.
1683 pi
= find_procinfo_or_die (pi
->pid
, 0);
1687 procfs_ctl_t cmd
= PCWSTOP
;
1688 win
= (write (pi
->ctl_fd
, (char *) &cmd
, sizeof (cmd
)) == sizeof (cmd
));
1689 /* We been runnin' and we stopped -- need to update status. */
1690 pi
->status_valid
= 0;
1692 #else /* ioctl method */
1693 win
= (ioctl (pi
->ctl_fd
, PIOCWSTOP
, &pi
->prstatus
) >= 0);
1694 /* Above call also refreshes the prstatus. */
1697 pi
->status_valid
= 1;
1698 PROC_PRETTYFPRINT_STATUS (proc_flags (pi
),
1701 proc_get_current_thread (pi
));
1709 * Function: proc_run_process
1711 * Make the process or LWP runnable.
1712 * Options (not all are implemented):
1714 * - clear current fault
1715 * - clear current signal
1716 * - abort the current system call
1717 * - stop as soon as finished with system call
1718 * - (ioctl): set traced signal set
1719 * - (ioctl): set held signal set
1720 * - (ioctl): set traced fault set
1721 * - (ioctl): set start pc (vaddr)
1722 * Always clear the current fault.
1723 * Clear the current signal if 'signo' is zero.
1726 * pi the process or LWP to operate on.
1727 * step if true, set the process or LWP to trap after one instr.
1728 * signo if zero, clear the current signal if any.
1729 * if non-zero, set the current signal to this one.
1731 * Returns non-zero for success, zero for failure.
1735 proc_run_process (procinfo
*pi
, int step
, int signo
)
1741 * We will probably have to apply this operation to individual threads,
1742 * so make sure the control file descriptor is open.
1745 if (pi
->ctl_fd
== 0 &&
1746 open_procinfo_files (pi
, FD_CTL
) == 0)
1751 runflags
= PRCFAULT
; /* always clear current fault */
1756 else if (signo
!= -1) /* -1 means do nothing W.R.T. signals */
1757 proc_set_current_signal (pi
, signo
);
1761 procfs_ctl_t cmd
[2];
1765 win
= (write (pi
->ctl_fd
, (char *) &cmd
, sizeof (cmd
)) == sizeof (cmd
));
1767 #else /* ioctl method */
1771 memset (&prrun
, 0, sizeof (prrun
));
1772 prrun
.pr_flags
= runflags
;
1773 win
= (ioctl (pi
->ctl_fd
, PIOCRUN
, &prrun
) >= 0);
1781 * Function: proc_set_traced_signals
1783 * Register to trace signals in the process or LWP.
1784 * Returns non-zero for success, zero for failure.
1788 proc_set_traced_signals (procinfo
*pi
, gdb_sigset_t
*sigset
)
1793 * We should never have to apply this operation to any procinfo
1794 * except the one for the main process. If that ever changes
1795 * for any reason, then take out the following clause and
1796 * replace it with one that makes sure the ctl_fd is open.
1800 pi
= find_procinfo_or_die (pi
->pid
, 0);
1806 /* Use char array to avoid alignment issues. */
1807 char sigset
[sizeof (gdb_sigset_t
)];
1811 memcpy (&arg
.sigset
, sigset
, sizeof (gdb_sigset_t
));
1813 win
= (write (pi
->ctl_fd
, (char *) &arg
, sizeof (arg
)) == sizeof (arg
));
1815 #else /* ioctl method */
1816 win
= (ioctl (pi
->ctl_fd
, PIOCSTRACE
, sigset
) >= 0);
1818 /* The above operation renders the procinfo's cached pstatus obsolete. */
1819 pi
->status_valid
= 0;
1822 warning ("procfs: set_traced_signals failed");
1827 * Function: proc_set_traced_faults
1829 * Register to trace hardware faults in the process or LWP.
1830 * Returns non-zero for success, zero for failure.
1834 proc_set_traced_faults (procinfo
*pi
, fltset_t
*fltset
)
1839 * We should never have to apply this operation to any procinfo
1840 * except the one for the main process. If that ever changes
1841 * for any reason, then take out the following clause and
1842 * replace it with one that makes sure the ctl_fd is open.
1846 pi
= find_procinfo_or_die (pi
->pid
, 0);
1852 /* Use char array to avoid alignment issues. */
1853 char fltset
[sizeof (fltset_t
)];
1857 memcpy (&arg
.fltset
, fltset
, sizeof (fltset_t
));
1859 win
= (write (pi
->ctl_fd
, (char *) &arg
, sizeof (arg
)) == sizeof (arg
));
1861 #else /* ioctl method */
1862 win
= (ioctl (pi
->ctl_fd
, PIOCSFAULT
, fltset
) >= 0);
1864 /* The above operation renders the procinfo's cached pstatus obsolete. */
1865 pi
->status_valid
= 0;
1871 * Function: proc_set_traced_sysentry
1873 * Register to trace entry to system calls in the process or LWP.
1874 * Returns non-zero for success, zero for failure.
1878 proc_set_traced_sysentry (procinfo
*pi
, sysset_t
*sysset
)
1883 * We should never have to apply this operation to any procinfo
1884 * except the one for the main process. If that ever changes
1885 * for any reason, then take out the following clause and
1886 * replace it with one that makes sure the ctl_fd is open.
1890 pi
= find_procinfo_or_die (pi
->pid
, 0);
1894 struct gdb_proc_ctl_pcsentry
{
1896 /* Use char array to avoid alignment issues. */
1897 char sysset
[sizeof (sysset_t
)];
1899 int argp_size
= sizeof (struct gdb_proc_ctl_pcsentry
)
1901 + sysset_t_size (pi
);
1903 argp
= xmalloc (argp_size
);
1905 argp
->cmd
= PCSENTRY
;
1906 memcpy (&argp
->sysset
, sysset
, sysset_t_size (pi
));
1908 win
= (write (pi
->ctl_fd
, (char *) argp
, argp_size
) == argp_size
);
1911 #else /* ioctl method */
1912 win
= (ioctl (pi
->ctl_fd
, PIOCSENTRY
, sysset
) >= 0);
1914 /* The above operation renders the procinfo's cached pstatus obsolete. */
1915 pi
->status_valid
= 0;
1921 * Function: proc_set_traced_sysexit
1923 * Register to trace exit from system calls in the process or LWP.
1924 * Returns non-zero for success, zero for failure.
1928 proc_set_traced_sysexit (procinfo
*pi
, sysset_t
*sysset
)
1933 * We should never have to apply this operation to any procinfo
1934 * except the one for the main process. If that ever changes
1935 * for any reason, then take out the following clause and
1936 * replace it with one that makes sure the ctl_fd is open.
1940 pi
= find_procinfo_or_die (pi
->pid
, 0);
1944 struct gdb_proc_ctl_pcsexit
{
1946 /* Use char array to avoid alignment issues. */
1947 char sysset
[sizeof (sysset_t
)];
1949 int argp_size
= sizeof (struct gdb_proc_ctl_pcsexit
)
1951 + sysset_t_size (pi
);
1953 argp
= xmalloc (argp_size
);
1955 argp
->cmd
= PCSEXIT
;
1956 memcpy (&argp
->sysset
, sysset
, sysset_t_size (pi
));
1958 win
= (write (pi
->ctl_fd
, (char *) argp
, argp_size
) == argp_size
);
1961 #else /* ioctl method */
1962 win
= (ioctl (pi
->ctl_fd
, PIOCSEXIT
, sysset
) >= 0);
1964 /* The above operation renders the procinfo's cached pstatus obsolete. */
1965 pi
->status_valid
= 0;
1971 * Function: proc_set_held_signals
1973 * Specify the set of blocked / held signals in the process or LWP.
1974 * Returns non-zero for success, zero for failure.
1978 proc_set_held_signals (procinfo
*pi
, gdb_sigset_t
*sighold
)
1983 * We should never have to apply this operation to any procinfo
1984 * except the one for the main process. If that ever changes
1985 * for any reason, then take out the following clause and
1986 * replace it with one that makes sure the ctl_fd is open.
1990 pi
= find_procinfo_or_die (pi
->pid
, 0);
1996 /* Use char array to avoid alignment issues. */
1997 char hold
[sizeof (gdb_sigset_t
)];
2001 memcpy (&arg
.hold
, sighold
, sizeof (gdb_sigset_t
));
2002 win
= (write (pi
->ctl_fd
, (void *) &arg
, sizeof (arg
)) == sizeof (arg
));
2005 win
= (ioctl (pi
->ctl_fd
, PIOCSHOLD
, sighold
) >= 0);
2007 /* The above operation renders the procinfo's cached pstatus obsolete. */
2008 pi
->status_valid
= 0;
2014 * Function: proc_get_pending_signals
2016 * returns the set of signals that are pending in the process or LWP.
2017 * Will also copy the sigset if 'save' is non-zero.
2021 proc_get_pending_signals (procinfo
*pi
, gdb_sigset_t
*save
)
2023 gdb_sigset_t
*ret
= NULL
;
2026 * We should never have to apply this operation to any procinfo
2027 * except the one for the main process. If that ever changes
2028 * for any reason, then take out the following clause and
2029 * replace it with one that makes sure the ctl_fd is open.
2033 pi
= find_procinfo_or_die (pi
->pid
, 0);
2035 if (!pi
->status_valid
)
2036 if (!proc_get_status (pi
))
2040 ret
= &pi
->prstatus
.pr_lwp
.pr_lwppend
;
2042 ret
= &pi
->prstatus
.pr_sigpend
;
2045 memcpy (save
, ret
, sizeof (gdb_sigset_t
));
2051 * Function: proc_get_signal_actions
2053 * returns the set of signal actions.
2054 * Will also copy the sigactionset if 'save' is non-zero.
2058 proc_get_signal_actions (procinfo
*pi
, gdb_sigaction_t
*save
)
2060 gdb_sigaction_t
*ret
= NULL
;
2063 * We should never have to apply this operation to any procinfo
2064 * except the one for the main process. If that ever changes
2065 * for any reason, then take out the following clause and
2066 * replace it with one that makes sure the ctl_fd is open.
2070 pi
= find_procinfo_or_die (pi
->pid
, 0);
2072 if (!pi
->status_valid
)
2073 if (!proc_get_status (pi
))
2077 ret
= &pi
->prstatus
.pr_lwp
.pr_action
;
2079 ret
= &pi
->prstatus
.pr_action
;
2082 memcpy (save
, ret
, sizeof (gdb_sigaction_t
));
2088 * Function: proc_get_held_signals
2090 * returns the set of signals that are held / blocked.
2091 * Will also copy the sigset if 'save' is non-zero.
2095 proc_get_held_signals (procinfo
*pi
, gdb_sigset_t
*save
)
2097 gdb_sigset_t
*ret
= NULL
;
2100 * We should never have to apply this operation to any procinfo
2101 * except the one for the main process. If that ever changes
2102 * for any reason, then take out the following clause and
2103 * replace it with one that makes sure the ctl_fd is open.
2107 pi
= find_procinfo_or_die (pi
->pid
, 0);
2110 if (!pi
->status_valid
)
2111 if (!proc_get_status (pi
))
2115 ret
= &pi
->prstatus
.pr_lwp
.pr_context
.uc_sigmask
;
2117 ret
= &pi
->prstatus
.pr_lwp
.pr_lwphold
;
2118 #endif /* UNIXWARE */
2119 #else /* not NEW_PROC_API */
2121 static gdb_sigset_t sigheld
;
2123 if (ioctl (pi
->ctl_fd
, PIOCGHOLD
, &sigheld
) >= 0)
2126 #endif /* NEW_PROC_API */
2128 memcpy (save
, ret
, sizeof (gdb_sigset_t
));
2134 * Function: proc_get_traced_signals
2136 * returns the set of signals that are traced / debugged.
2137 * Will also copy the sigset if 'save' is non-zero.
2141 proc_get_traced_signals (procinfo
*pi
, gdb_sigset_t
*save
)
2143 gdb_sigset_t
*ret
= NULL
;
2146 * We should never have to apply this operation to any procinfo
2147 * except the one for the main process. If that ever changes
2148 * for any reason, then take out the following clause and
2149 * replace it with one that makes sure the ctl_fd is open.
2153 pi
= find_procinfo_or_die (pi
->pid
, 0);
2156 if (!pi
->status_valid
)
2157 if (!proc_get_status (pi
))
2160 ret
= &pi
->prstatus
.pr_sigtrace
;
2163 static gdb_sigset_t sigtrace
;
2165 if (ioctl (pi
->ctl_fd
, PIOCGTRACE
, &sigtrace
) >= 0)
2170 memcpy (save
, ret
, sizeof (gdb_sigset_t
));
2176 * Function: proc_trace_signal
2178 * Add 'signo' to the set of signals that are traced.
2179 * Returns non-zero for success, zero for failure.
2183 proc_trace_signal (procinfo
*pi
, int signo
)
2188 * We should never have to apply this operation to any procinfo
2189 * except the one for the main process. If that ever changes
2190 * for any reason, then take out the following clause and
2191 * replace it with one that makes sure the ctl_fd is open.
2195 pi
= find_procinfo_or_die (pi
->pid
, 0);
2199 if (proc_get_traced_signals (pi
, &temp
))
2201 praddset (&temp
, signo
);
2202 return proc_set_traced_signals (pi
, &temp
);
2206 return 0; /* failure */
2210 * Function: proc_ignore_signal
2212 * Remove 'signo' from the set of signals that are traced.
2213 * Returns non-zero for success, zero for failure.
2217 proc_ignore_signal (procinfo
*pi
, int signo
)
2222 * We should never have to apply this operation to any procinfo
2223 * except the one for the main process. If that ever changes
2224 * for any reason, then take out the following clause and
2225 * replace it with one that makes sure the ctl_fd is open.
2229 pi
= find_procinfo_or_die (pi
->pid
, 0);
2233 if (proc_get_traced_signals (pi
, &temp
))
2235 prdelset (&temp
, signo
);
2236 return proc_set_traced_signals (pi
, &temp
);
2240 return 0; /* failure */
2244 * Function: proc_get_traced_faults
2246 * returns the set of hardware faults that are traced /debugged.
2247 * Will also copy the faultset if 'save' is non-zero.
2251 proc_get_traced_faults (procinfo
*pi
, fltset_t
*save
)
2253 fltset_t
*ret
= NULL
;
2256 * We should never have to apply this operation to any procinfo
2257 * except the one for the main process. If that ever changes
2258 * for any reason, then take out the following clause and
2259 * replace it with one that makes sure the ctl_fd is open.
2263 pi
= find_procinfo_or_die (pi
->pid
, 0);
2266 if (!pi
->status_valid
)
2267 if (!proc_get_status (pi
))
2270 ret
= &pi
->prstatus
.pr_flttrace
;
2273 static fltset_t flttrace
;
2275 if (ioctl (pi
->ctl_fd
, PIOCGFAULT
, &flttrace
) >= 0)
2280 memcpy (save
, ret
, sizeof (fltset_t
));
2286 * Function: proc_get_traced_sysentry
2288 * returns the set of syscalls that are traced /debugged on entry.
2289 * Will also copy the syscall set if 'save' is non-zero.
2293 proc_get_traced_sysentry (procinfo
*pi
, sysset_t
*save
)
2295 sysset_t
*ret
= NULL
;
2298 * We should never have to apply this operation to any procinfo
2299 * except the one for the main process. If that ever changes
2300 * for any reason, then take out the following clause and
2301 * replace it with one that makes sure the ctl_fd is open.
2305 pi
= find_procinfo_or_die (pi
->pid
, 0);
2308 if (!pi
->status_valid
)
2309 if (!proc_get_status (pi
))
2312 #ifndef DYNAMIC_SYSCALLS
2313 ret
= &pi
->prstatus
.pr_sysentry
;
2314 #else /* DYNAMIC_SYSCALLS */
2316 static sysset_t
*sysentry
;
2320 sysentry
= sysset_t_alloc (pi
);
2322 if (pi
->status_fd
== 0 && open_procinfo_files (pi
, FD_STATUS
) == 0)
2324 if (pi
->prstatus
.pr_sysentry_offset
== 0)
2326 gdb_premptysysset (sysentry
);
2332 if (lseek (pi
->status_fd
, (off_t
) pi
->prstatus
.pr_sysentry_offset
,
2334 != (off_t
) pi
->prstatus
.pr_sysentry_offset
)
2336 size
= sysset_t_size (pi
);
2337 gdb_premptysysset (sysentry
);
2338 rsize
= read (pi
->status_fd
, sysentry
, size
);
2343 #endif /* DYNAMIC_SYSCALLS */
2344 #else /* !NEW_PROC_API */
2346 static sysset_t sysentry
;
2348 if (ioctl (pi
->ctl_fd
, PIOCGENTRY
, &sysentry
) >= 0)
2351 #endif /* NEW_PROC_API */
2353 memcpy (save
, ret
, sysset_t_size (pi
));
2359 * Function: proc_get_traced_sysexit
2361 * returns the set of syscalls that are traced /debugged on exit.
2362 * Will also copy the syscall set if 'save' is non-zero.
2366 proc_get_traced_sysexit (procinfo
*pi
, sysset_t
*save
)
2368 sysset_t
* ret
= NULL
;
2371 * We should never have to apply this operation to any procinfo
2372 * except the one for the main process. If that ever changes
2373 * for any reason, then take out the following clause and
2374 * replace it with one that makes sure the ctl_fd is open.
2378 pi
= find_procinfo_or_die (pi
->pid
, 0);
2381 if (!pi
->status_valid
)
2382 if (!proc_get_status (pi
))
2385 #ifndef DYNAMIC_SYSCALLS
2386 ret
= &pi
->prstatus
.pr_sysexit
;
2387 #else /* DYNAMIC_SYSCALLS */
2389 static sysset_t
*sysexit
;
2393 sysexit
= sysset_t_alloc (pi
);
2395 if (pi
->status_fd
== 0 && open_procinfo_files (pi
, FD_STATUS
) == 0)
2397 if (pi
->prstatus
.pr_sysexit_offset
== 0)
2399 gdb_premptysysset (sysexit
);
2405 if (lseek (pi
->status_fd
, (off_t
) pi
->prstatus
.pr_sysexit_offset
, SEEK_SET
)
2406 != (off_t
) pi
->prstatus
.pr_sysexit_offset
)
2408 size
= sysset_t_size (pi
);
2409 gdb_premptysysset (sysexit
);
2410 rsize
= read (pi
->status_fd
, sysexit
, size
);
2415 #endif /* DYNAMIC_SYSCALLS */
2418 static sysset_t sysexit
;
2420 if (ioctl (pi
->ctl_fd
, PIOCGEXIT
, &sysexit
) >= 0)
2425 memcpy (save
, ret
, sysset_t_size (pi
));
2431 * Function: proc_clear_current_fault
2433 * The current fault (if any) is cleared; the associated signal
2434 * will not be sent to the process or LWP when it resumes.
2435 * Returns non-zero for success, zero for failure.
2439 proc_clear_current_fault (procinfo
*pi
)
2444 * We should never have to apply this operation to any procinfo
2445 * except the one for the main process. If that ever changes
2446 * for any reason, then take out the following clause and
2447 * replace it with one that makes sure the ctl_fd is open.
2451 pi
= find_procinfo_or_die (pi
->pid
, 0);
2455 procfs_ctl_t cmd
= PCCFAULT
;
2456 win
= (write (pi
->ctl_fd
, (void *) &cmd
, sizeof (cmd
)) == sizeof (cmd
));
2459 win
= (ioctl (pi
->ctl_fd
, PIOCCFAULT
, 0) >= 0);
2466 * Function: proc_set_current_signal
2468 * Set the "current signal" that will be delivered next to the process.
2469 * NOTE: semantics are different from those of KILL.
2470 * This signal will be delivered to the process or LWP
2471 * immediately when it is resumed (even if the signal is held/blocked);
2472 * it will NOT immediately cause another event of interest, and will NOT
2473 * first trap back to the debugger.
2475 * Returns non-zero for success, zero for failure.
2479 proc_set_current_signal (procinfo
*pi
, int signo
)
2484 /* Use char array to avoid alignment issues. */
2485 char sinfo
[sizeof (gdb_siginfo_t
)];
2487 gdb_siginfo_t
*mysinfo
;
2490 * We should never have to apply this operation to any procinfo
2491 * except the one for the main process. If that ever changes
2492 * for any reason, then take out the following clause and
2493 * replace it with one that makes sure the ctl_fd is open.
2497 pi
= find_procinfo_or_die (pi
->pid
, 0);
2499 #ifdef PROCFS_DONT_PIOCSSIG_CURSIG
2500 /* With Alpha OSF/1 procfs, the kernel gets really confused if it
2501 * receives a PIOCSSIG with a signal identical to the current signal,
2502 * it messes up the current signal. Work around the kernel bug.
2505 signo
== proc_cursig (pi
))
2506 return 1; /* I assume this is a success? */
2509 /* The pointer is just a type alias. */
2510 mysinfo
= (gdb_siginfo_t
*) &arg
.sinfo
;
2511 mysinfo
->si_signo
= signo
;
2512 mysinfo
->si_code
= 0;
2513 mysinfo
->si_pid
= getpid (); /* ?why? */
2514 mysinfo
->si_uid
= getuid (); /* ?why? */
2518 win
= (write (pi
->ctl_fd
, (void *) &arg
, sizeof (arg
)) == sizeof (arg
));
2520 win
= (ioctl (pi
->ctl_fd
, PIOCSSIG
, (void *) &arg
.sinfo
) >= 0);
2527 * Function: proc_clear_current_signal
2529 * The current signal (if any) is cleared, and
2530 * is not sent to the process or LWP when it resumes.
2531 * Returns non-zero for success, zero for failure.
2535 proc_clear_current_signal (procinfo
*pi
)
2540 * We should never have to apply this operation to any procinfo
2541 * except the one for the main process. If that ever changes
2542 * for any reason, then take out the following clause and
2543 * replace it with one that makes sure the ctl_fd is open.
2547 pi
= find_procinfo_or_die (pi
->pid
, 0);
2553 /* Use char array to avoid alignment issues. */
2554 char sinfo
[sizeof (gdb_siginfo_t
)];
2556 gdb_siginfo_t
*mysinfo
;
2559 /* The pointer is just a type alias. */
2560 mysinfo
= (gdb_siginfo_t
*) &arg
.sinfo
;
2561 mysinfo
->si_signo
= 0;
2562 mysinfo
->si_code
= 0;
2563 mysinfo
->si_errno
= 0;
2564 mysinfo
->si_pid
= getpid (); /* ?why? */
2565 mysinfo
->si_uid
= getuid (); /* ?why? */
2567 win
= (write (pi
->ctl_fd
, (void *) &arg
, sizeof (arg
)) == sizeof (arg
));
2570 win
= (ioctl (pi
->ctl_fd
, PIOCSSIG
, 0) >= 0);
2576 /* Return the general-purpose registers for the process or LWP
2577 corresponding to PI. Upon failure, return NULL. */
2580 proc_get_gregs (procinfo
*pi
)
2582 if (!pi
->status_valid
|| !pi
->gregs_valid
)
2583 if (!proc_get_status (pi
))
2586 /* OK, sorry about the ifdef's. There's three cases instead of two,
2587 because in this case Unixware and Solaris/RW differ. */
2590 # ifdef UNIXWARE /* FIXME: Should be autoconfigured. */
2591 return &pi
->prstatus
.pr_lwp
.pr_context
.uc_mcontext
.gregs
;
2593 return &pi
->prstatus
.pr_lwp
.pr_reg
;
2596 return &pi
->prstatus
.pr_reg
;
2600 /* Return the general-purpose registers for the process or LWP
2601 corresponding to PI. Upon failure, return NULL. */
2604 proc_get_fpregs (procinfo
*pi
)
2607 if (!pi
->status_valid
|| !pi
->fpregs_valid
)
2608 if (!proc_get_status (pi
))
2611 # ifdef UNIXWARE /* FIXME: Should be autoconfigured. */
2612 return &pi
->prstatus
.pr_lwp
.pr_context
.uc_mcontext
.fpregs
;
2614 return &pi
->prstatus
.pr_lwp
.pr_fpreg
;
2617 #else /* not NEW_PROC_API */
2618 if (pi
->fpregs_valid
)
2619 return &pi
->fpregset
; /* Already got 'em. */
2622 if (pi
->ctl_fd
== 0 && open_procinfo_files (pi
, FD_CTL
) == 0)
2631 tid_t pr_error_thread
;
2632 tfpregset_t thread_1
;
2635 thread_fpregs
.pr_count
= 1;
2636 thread_fpregs
.thread_1
.tid
= pi
->tid
;
2639 && ioctl (pi
->ctl_fd
, PIOCGFPREG
, &pi
->fpregset
) >= 0)
2641 pi
->fpregs_valid
= 1;
2642 return &pi
->fpregset
; /* Got 'em now! */
2644 else if (pi
->tid
!= 0
2645 && ioctl (pi
->ctl_fd
, PIOCTGFPREG
, &thread_fpregs
) >= 0)
2647 memcpy (&pi
->fpregset
, &thread_fpregs
.thread_1
.pr_fpregs
,
2648 sizeof (pi
->fpregset
));
2649 pi
->fpregs_valid
= 1;
2650 return &pi
->fpregset
; /* Got 'em now! */
2657 if (ioctl (pi
->ctl_fd
, PIOCGFPREG
, &pi
->fpregset
) >= 0)
2659 pi
->fpregs_valid
= 1;
2660 return &pi
->fpregset
; /* Got 'em now! */
2669 #endif /* NEW_PROC_API */
2672 /* Write the general-purpose registers back to the process or LWP
2673 corresponding to PI. Return non-zero for success, zero for
2677 proc_set_gregs (procinfo
*pi
)
2679 gdb_gregset_t
*gregs
;
2682 gregs
= proc_get_gregs (pi
);
2684 return 0; /* proc_get_regs has already warned. */
2686 if (pi
->ctl_fd
== 0 && open_procinfo_files (pi
, FD_CTL
) == 0)
2695 /* Use char array to avoid alignment issues. */
2696 char gregs
[sizeof (gdb_gregset_t
)];
2700 memcpy (&arg
.gregs
, gregs
, sizeof (arg
.gregs
));
2701 win
= (write (pi
->ctl_fd
, (void *) &arg
, sizeof (arg
)) == sizeof (arg
));
2703 win
= (ioctl (pi
->ctl_fd
, PIOCSREG
, gregs
) >= 0);
2707 /* Policy: writing the registers invalidates our cache. */
2708 pi
->gregs_valid
= 0;
2712 /* Write the floating-pointer registers back to the process or LWP
2713 corresponding to PI. Return non-zero for success, zero for
2717 proc_set_fpregs (procinfo
*pi
)
2719 gdb_fpregset_t
*fpregs
;
2722 fpregs
= proc_get_fpregs (pi
);
2724 return 0; /* proc_get_fpregs has already warned. */
2726 if (pi
->ctl_fd
== 0 && open_procinfo_files (pi
, FD_CTL
) == 0)
2735 /* Use char array to avoid alignment issues. */
2736 char fpregs
[sizeof (gdb_fpregset_t
)];
2740 memcpy (&arg
.fpregs
, fpregs
, sizeof (arg
.fpregs
));
2741 win
= (write (pi
->ctl_fd
, (void *) &arg
, sizeof (arg
)) == sizeof (arg
));
2745 win
= (ioctl (pi
->ctl_fd
, PIOCSFPREG
, fpregs
) >= 0);
2750 tid_t pr_error_thread
;
2751 tfpregset_t thread_1
;
2754 thread_fpregs
.pr_count
= 1;
2755 thread_fpregs
.thread_1
.tid
= pi
->tid
;
2756 memcpy (&thread_fpregs
.thread_1
.pr_fpregs
, fpregs
,
2758 win
= (ioctl (pi
->ctl_fd
, PIOCTSFPREG
, &thread_fpregs
) >= 0);
2761 win
= (ioctl (pi
->ctl_fd
, PIOCSFPREG
, fpregs
) >= 0);
2763 #endif /* NEW_PROC_API */
2766 /* Policy: writing the registers invalidates our cache. */
2767 pi
->fpregs_valid
= 0;
2772 * Function: proc_kill
2774 * Send a signal to the proc or lwp with the semantics of "kill()".
2775 * Returns non-zero for success, zero for failure.
2779 proc_kill (procinfo
*pi
, int signo
)
2784 * We might conceivably apply this operation to an LWP, and
2785 * the LWP's ctl file descriptor might not be open.
2788 if (pi
->ctl_fd
== 0 &&
2789 open_procinfo_files (pi
, FD_CTL
) == 0)
2796 procfs_ctl_t cmd
[2];
2800 win
= (write (pi
->ctl_fd
, (char *) &cmd
, sizeof (cmd
)) == sizeof (cmd
));
2801 #else /* ioctl method */
2802 /* FIXME: do I need the Alpha OSF fixups present in
2803 procfs.c/unconditionally_kill_inferior? Perhaps only for SIGKILL? */
2804 win
= (ioctl (pi
->ctl_fd
, PIOCKILL
, &signo
) >= 0);
2812 * Function: proc_parent_pid
2814 * Find the pid of the process that started this one.
2815 * Returns the parent process pid, or zero.
2819 proc_parent_pid (procinfo
*pi
)
2822 * We should never have to apply this operation to any procinfo
2823 * except the one for the main process. If that ever changes
2824 * for any reason, then take out the following clause and
2825 * replace it with one that makes sure the ctl_fd is open.
2829 pi
= find_procinfo_or_die (pi
->pid
, 0);
2831 if (!pi
->status_valid
)
2832 if (!proc_get_status (pi
))
2835 return pi
->prstatus
.pr_ppid
;
2839 /* Convert a target address (a.k.a. CORE_ADDR) into a host address
2840 (a.k.a void pointer)! */
2843 procfs_address_to_host_pointer (CORE_ADDR addr
)
2847 gdb_assert (sizeof (ptr
) == TYPE_LENGTH (builtin_type_void_data_ptr
));
2848 ADDRESS_TO_POINTER (builtin_type_void_data_ptr
, &ptr
, addr
);
2853 * Function: proc_set_watchpoint
2858 proc_set_watchpoint (procinfo
*pi
, CORE_ADDR addr
, int len
, int wflags
)
2860 #if !defined (TARGET_HAS_HARDWARE_WATCHPOINTS)
2863 /* Horrible hack! Detect Solaris 2.5, because this doesn't work on 2.5 */
2864 #if defined (PIOCOPENLWP) || defined (UNIXWARE) /* Solaris 2.5: bail out */
2869 char watch
[sizeof (prwatch_t
)];
2873 pwatch
= (prwatch_t
*) &arg
.watch
;
2874 /* NOTE: cagney/2003-02-01: Even more horrible hack. Need to
2875 convert a target address into something that can be stored in a
2876 native data structure. */
2877 #ifdef PCAGENT /* Horrible hack: only defined on Solaris 2.6+ */
2878 pwatch
->pr_vaddr
= (uintptr_t) procfs_address_to_host_pointer (addr
);
2880 pwatch
->pr_vaddr
= (caddr_t
) procfs_address_to_host_pointer (addr
);
2882 pwatch
->pr_size
= len
;
2883 pwatch
->pr_wflags
= wflags
;
2884 #if defined(NEW_PROC_API) && defined (PCWATCH)
2886 return (write (pi
->ctl_fd
, &arg
, sizeof (arg
)) == sizeof (arg
));
2888 #if defined (PIOCSWATCH)
2889 return (ioctl (pi
->ctl_fd
, PIOCSWATCH
, pwatch
) >= 0);
2891 return 0; /* Fail */
2898 #ifdef TM_I386SOL2_H /* Is it hokey to use this? */
2900 #include <sys/sysi86.h>
2903 * Function: proc_get_LDT_entry
2909 * The 'key' is actually the value of the lower 16 bits of
2910 * the GS register for the LWP that we're interested in.
2912 * Return: matching ssh struct (LDT entry).
2916 proc_get_LDT_entry (procinfo
*pi
, int key
)
2918 static struct ssd
*ldt_entry
= NULL
;
2920 char pathname
[MAX_PROC_NAME_SIZE
];
2921 struct cleanup
*old_chain
= NULL
;
2924 /* Allocate space for one LDT entry.
2925 This alloc must persist, because we return a pointer to it. */
2926 if (ldt_entry
== NULL
)
2927 ldt_entry
= (struct ssd
*) xmalloc (sizeof (struct ssd
));
2929 /* Open the file descriptor for the LDT table. */
2930 sprintf (pathname
, "/proc/%d/ldt", pi
->pid
);
2931 if ((fd
= open_with_retry (pathname
, O_RDONLY
)) < 0)
2933 proc_warn (pi
, "proc_get_LDT_entry (open)", __LINE__
);
2936 /* Make sure it gets closed again! */
2937 old_chain
= make_cleanup_close (fd
);
2939 /* Now 'read' thru the table, find a match and return it. */
2940 while (read (fd
, ldt_entry
, sizeof (struct ssd
)) == sizeof (struct ssd
))
2942 if (ldt_entry
->sel
== 0 &&
2943 ldt_entry
->bo
== 0 &&
2944 ldt_entry
->acc1
== 0 &&
2945 ldt_entry
->acc2
== 0)
2946 break; /* end of table */
2947 /* If key matches, return this entry. */
2948 if (ldt_entry
->sel
== key
)
2951 /* Loop ended, match not found. */
2955 static int nalloc
= 0;
2957 /* Get the number of LDT entries. */
2958 if (ioctl (pi
->ctl_fd
, PIOCNLDT
, &nldt
) < 0)
2960 proc_warn (pi
, "proc_get_LDT_entry (PIOCNLDT)", __LINE__
);
2964 /* Allocate space for the number of LDT entries. */
2965 /* This alloc has to persist, 'cause we return a pointer to it. */
2968 ldt_entry
= (struct ssd
*)
2969 xrealloc (ldt_entry
, (nldt
+ 1) * sizeof (struct ssd
));
2973 /* Read the whole table in one gulp. */
2974 if (ioctl (pi
->ctl_fd
, PIOCLDT
, ldt_entry
) < 0)
2976 proc_warn (pi
, "proc_get_LDT_entry (PIOCLDT)", __LINE__
);
2980 /* Search the table and return the (first) entry matching 'key'. */
2981 for (i
= 0; i
< nldt
; i
++)
2982 if (ldt_entry
[i
].sel
== key
)
2983 return &ldt_entry
[i
];
2985 /* Loop ended, match not found. */
2990 #endif /* TM_I386SOL2_H */
2992 /* =============== END, non-thread part of /proc "MODULE" =============== */
2994 /* =================== Thread "MODULE" =================== */
2996 /* NOTE: you'll see more ifdefs and duplication of functions here,
2997 since there is a different way to do threads on every OS. */
3000 * Function: proc_get_nthreads
3002 * Return the number of threads for the process
3005 #if defined (PIOCNTHR) && defined (PIOCTLIST)
3010 proc_get_nthreads (procinfo
*pi
)
3014 if (ioctl (pi
->ctl_fd
, PIOCNTHR
, &nthreads
) < 0)
3015 proc_warn (pi
, "procfs: PIOCNTHR failed", __LINE__
);
3021 #if defined (SYS_lwpcreate) || defined (SYS_lwp_create) /* FIXME: multiple */
3023 * Solaris and Unixware version
3026 proc_get_nthreads (procinfo
*pi
)
3028 if (!pi
->status_valid
)
3029 if (!proc_get_status (pi
))
3033 * NEW_PROC_API: only works for the process procinfo,
3034 * because the LWP procinfos do not get prstatus filled in.
3037 if (pi
->tid
!= 0) /* find the parent process procinfo */
3038 pi
= find_procinfo_or_die (pi
->pid
, 0);
3040 return pi
->prstatus
.pr_nlwp
;
3048 proc_get_nthreads (procinfo
*pi
)
3056 * Function: proc_get_current_thread (LWP version)
3058 * Return the ID of the thread that had an event of interest.
3059 * (ie. the one that hit a breakpoint or other traced event).
3060 * All other things being equal, this should be the ID of a
3061 * thread that is currently executing.
3064 #if defined (SYS_lwpcreate) || defined (SYS_lwp_create) /* FIXME: multiple */
3066 * Solaris and Unixware version
3069 proc_get_current_thread (procinfo
*pi
)
3072 * Note: this should be applied to the root procinfo for the process,
3073 * not to the procinfo for an LWP. If applied to the procinfo for
3074 * an LWP, it will simply return that LWP's ID. In that case,
3075 * find the parent process procinfo.
3079 pi
= find_procinfo_or_die (pi
->pid
, 0);
3081 if (!pi
->status_valid
)
3082 if (!proc_get_status (pi
))
3086 return pi
->prstatus
.pr_lwp
.pr_lwpid
;
3088 return pi
->prstatus
.pr_who
;
3093 #if defined (PIOCNTHR) && defined (PIOCTLIST)
3098 proc_get_current_thread (procinfo
*pi
)
3100 #if 0 /* FIXME: not ready for prime time? */
3101 return pi
->prstatus
.pr_tid
;
3112 proc_get_current_thread (procinfo
*pi
)
3121 * Function: proc_update_threads
3123 * Discover the IDs of all the threads within the process, and
3124 * create a procinfo for each of them (chained to the parent).
3126 * This unfortunately requires a different method on every OS.
3128 * Return: non-zero for success, zero for failure.
3132 proc_delete_dead_threads (procinfo
*parent
, procinfo
*thread
, void *ignore
)
3134 if (thread
&& parent
) /* sanity */
3136 thread
->status_valid
= 0;
3137 if (!proc_get_status (thread
))
3138 destroy_one_procinfo (&parent
->thread_list
, thread
);
3140 return 0; /* keep iterating */
3143 #if defined (PIOCLSTATUS)
3145 * Solaris 2.5 (ioctl) version
3148 proc_update_threads (procinfo
*pi
)
3150 gdb_prstatus_t
*prstatus
;
3151 struct cleanup
*old_chain
= NULL
;
3156 * We should never have to apply this operation to any procinfo
3157 * except the one for the main process. If that ever changes
3158 * for any reason, then take out the following clause and
3159 * replace it with one that makes sure the ctl_fd is open.
3163 pi
= find_procinfo_or_die (pi
->pid
, 0);
3165 proc_iterate_over_threads (pi
, proc_delete_dead_threads
, NULL
);
3167 if ((nlwp
= proc_get_nthreads (pi
)) <= 1)
3168 return 1; /* Process is not multi-threaded; nothing to do. */
3170 prstatus
= xmalloc (sizeof (gdb_prstatus_t
) * (nlwp
+ 1));
3172 old_chain
= make_cleanup (xfree
, prstatus
);
3173 if (ioctl (pi
->ctl_fd
, PIOCLSTATUS
, prstatus
) < 0)
3174 proc_error (pi
, "update_threads (PIOCLSTATUS)", __LINE__
);
3176 /* Skip element zero, which represents the process as a whole. */
3177 for (i
= 1; i
< nlwp
+ 1; i
++)
3179 if ((thread
= create_procinfo (pi
->pid
, prstatus
[i
].pr_who
)) == NULL
)
3180 proc_error (pi
, "update_threads, create_procinfo", __LINE__
);
3182 memcpy (&thread
->prstatus
, &prstatus
[i
], sizeof (*prstatus
));
3183 thread
->status_valid
= 1;
3185 pi
->threads_valid
= 1;
3186 do_cleanups (old_chain
);
3192 * Unixware and Solaris 6 (and later) version
3195 do_closedir_cleanup (void *dir
)
3201 proc_update_threads (procinfo
*pi
)
3203 char pathname
[MAX_PROC_NAME_SIZE
+ 16];
3204 struct dirent
*direntry
;
3205 struct cleanup
*old_chain
= NULL
;
3211 * We should never have to apply this operation to any procinfo
3212 * except the one for the main process. If that ever changes
3213 * for any reason, then take out the following clause and
3214 * replace it with one that makes sure the ctl_fd is open.
3218 pi
= find_procinfo_or_die (pi
->pid
, 0);
3220 proc_iterate_over_threads (pi
, proc_delete_dead_threads
, NULL
);
3225 * Note: this brute-force method is the only way I know of
3226 * to accomplish this task on Unixware. This method will
3227 * also work on Solaris 2.6 and 2.7. There is a much simpler
3228 * and more elegant way to do this on Solaris, but the margins
3229 * of this manuscript are too small to write it here... ;-)
3232 strcpy (pathname
, pi
->pathname
);
3233 strcat (pathname
, "/lwp");
3234 if ((dirp
= opendir (pathname
)) == NULL
)
3235 proc_error (pi
, "update_threads, opendir", __LINE__
);
3237 old_chain
= make_cleanup (do_closedir_cleanup
, dirp
);
3238 while ((direntry
= readdir (dirp
)) != NULL
)
3239 if (direntry
->d_name
[0] != '.') /* skip '.' and '..' */
3241 lwpid
= atoi (&direntry
->d_name
[0]);
3242 if ((thread
= create_procinfo (pi
->pid
, lwpid
)) == NULL
)
3243 proc_error (pi
, "update_threads, create_procinfo", __LINE__
);
3245 pi
->threads_valid
= 1;
3246 do_cleanups (old_chain
);
3255 proc_update_threads (procinfo
*pi
)
3261 * We should never have to apply this operation to any procinfo
3262 * except the one for the main process. If that ever changes
3263 * for any reason, then take out the following clause and
3264 * replace it with one that makes sure the ctl_fd is open.
3268 pi
= find_procinfo_or_die (pi
->pid
, 0);
3270 proc_iterate_over_threads (pi
, proc_delete_dead_threads
, NULL
);
3272 nthreads
= proc_get_nthreads (pi
);
3274 return 0; /* nothing to do for 1 or fewer threads */
3276 threads
= xmalloc (nthreads
* sizeof (tid_t
));
3278 if (ioctl (pi
->ctl_fd
, PIOCTLIST
, threads
) < 0)
3279 proc_error (pi
, "procfs: update_threads (PIOCTLIST)", __LINE__
);
3281 for (i
= 0; i
< nthreads
; i
++)
3283 if (!find_procinfo (pi
->pid
, threads
[i
]))
3284 if (!create_procinfo (pi
->pid
, threads
[i
]))
3285 proc_error (pi
, "update_threads, create_procinfo", __LINE__
);
3287 pi
->threads_valid
= 1;
3295 proc_update_threads (procinfo
*pi
)
3299 #endif /* OSF PIOCTLIST */
3300 #endif /* NEW_PROC_API */
3301 #endif /* SOL 2.5 PIOCLSTATUS */
3304 * Function: proc_iterate_over_threads
3307 * Given a pointer to a function, call that function once
3308 * for each lwp in the procinfo list, until the function
3309 * returns non-zero, in which event return the value
3310 * returned by the function.
3312 * Note: this function does NOT call update_threads.
3313 * If you want to discover new threads first, you must
3314 * call that function explicitly. This function just makes
3315 * a quick pass over the currently-known procinfos.
3318 * pi - parent process procinfo
3319 * func - per-thread function
3320 * ptr - opaque parameter for function.
3323 * First non-zero return value from the callee, or zero.
3327 proc_iterate_over_threads (procinfo
*pi
,
3328 int (*func
) (procinfo
*, procinfo
*, void *),
3331 procinfo
*thread
, *next
;
3335 * We should never have to apply this operation to any procinfo
3336 * except the one for the main process. If that ever changes
3337 * for any reason, then take out the following clause and
3338 * replace it with one that makes sure the ctl_fd is open.
3342 pi
= find_procinfo_or_die (pi
->pid
, 0);
3344 for (thread
= pi
->thread_list
; thread
!= NULL
; thread
= next
)
3346 next
= thread
->next
; /* in case thread is destroyed */
3347 if ((retval
= (*func
) (pi
, thread
, ptr
)) != 0)
3354 /* =================== END, Thread "MODULE" =================== */
3356 /* =================== END, /proc "MODULE" =================== */
3358 /* =================== GDB "MODULE" =================== */
3361 * Here are all of the gdb target vector functions and their friends.
3364 static ptid_t
do_attach (ptid_t ptid
);
3365 static void do_detach (int signo
);
3366 static int register_gdb_signals (procinfo
*, gdb_sigset_t
*);
3367 static void proc_trace_syscalls_1 (procinfo
*pi
, int syscallnum
,
3368 int entry_or_exit
, int mode
, int from_tty
);
3369 static int insert_dbx_link_breakpoint (procinfo
*pi
);
3370 static void remove_dbx_link_breakpoint (void);
3372 /* On mips-irix, we need to insert a breakpoint at __dbx_link during
3373 the startup phase. The following two variables are used to record
3374 the address of the breakpoint, and the code that was replaced by
3376 static int dbx_link_bpt_addr
= 0;
3377 static char dbx_link_shadow_contents
[BREAKPOINT_MAX
];
3380 * Function: procfs_debug_inferior
3382 * Sets up the inferior to be debugged.
3383 * Registers to trace signals, hardware faults, and syscalls.
3384 * Note: does not set RLC flag: caller may want to customize that.
3386 * Returns: zero for success (note! unlike most functions in this module)
3387 * On failure, returns the LINE NUMBER where it failed!
3391 procfs_debug_inferior (procinfo
*pi
)
3393 fltset_t traced_faults
;
3394 gdb_sigset_t traced_signals
;
3395 sysset_t
*traced_syscall_entries
;
3396 sysset_t
*traced_syscall_exits
;
3399 #ifdef PROCFS_DONT_TRACE_FAULTS
3400 /* On some systems (OSF), we don't trace hardware faults.
3401 Apparently it's enough that we catch them as signals.
3402 Wonder why we don't just do that in general? */
3403 premptyset (&traced_faults
); /* don't trace faults. */
3405 /* Register to trace hardware faults in the child. */
3406 prfillset (&traced_faults
); /* trace all faults... */
3407 prdelset (&traced_faults
, FLTPAGE
); /* except page fault. */
3409 if (!proc_set_traced_faults (pi
, &traced_faults
))
3412 /* Register to trace selected signals in the child. */
3413 premptyset (&traced_signals
);
3414 if (!register_gdb_signals (pi
, &traced_signals
))
3418 /* Register to trace the 'exit' system call (on entry). */
3419 traced_syscall_entries
= sysset_t_alloc (pi
);
3420 gdb_premptysysset (traced_syscall_entries
);
3422 gdb_praddsysset (traced_syscall_entries
, SYS_exit
);
3425 gdb_praddsysset (traced_syscall_entries
, SYS_lwpexit
); /* And _lwp_exit... */
3428 gdb_praddsysset (traced_syscall_entries
, SYS_lwp_exit
);
3430 #ifdef DYNAMIC_SYSCALLS
3432 int callnum
= find_syscall (pi
, "_exit");
3434 gdb_praddsysset (traced_syscall_entries
, callnum
);
3438 status
= proc_set_traced_sysentry (pi
, traced_syscall_entries
);
3439 xfree (traced_syscall_entries
);
3443 #ifdef PRFS_STOPEXEC /* defined on OSF */
3444 /* OSF method for tracing exec syscalls. Quoting:
3445 Under Alpha OSF/1 we have to use a PIOCSSPCACT ioctl to trace
3446 exits from exec system calls because of the user level loader. */
3447 /* FIXME: make nice and maybe move into an access function. */
3451 if (ioctl (pi
->ctl_fd
, PIOCGSPCACT
, &prfs_flags
) < 0)
3454 prfs_flags
|= PRFS_STOPEXEC
;
3456 if (ioctl (pi
->ctl_fd
, PIOCSSPCACT
, &prfs_flags
) < 0)
3459 #else /* not PRFS_STOPEXEC */
3460 /* Everyone else's (except OSF) method for tracing exec syscalls */
3462 Not all systems with /proc have all the exec* syscalls with the same
3463 names. On the SGI, for example, there is no SYS_exec, but there
3464 *is* a SYS_execv. So, we try to account for that. */
3466 traced_syscall_exits
= sysset_t_alloc (pi
);
3467 gdb_premptysysset (traced_syscall_exits
);
3469 gdb_praddsysset (traced_syscall_exits
, SYS_exec
);
3472 gdb_praddsysset (traced_syscall_exits
, SYS_execve
);
3475 gdb_praddsysset (traced_syscall_exits
, SYS_execv
);
3478 #ifdef SYS_lwpcreate
3479 gdb_praddsysset (traced_syscall_exits
, SYS_lwpcreate
);
3480 gdb_praddsysset (traced_syscall_exits
, SYS_lwpexit
);
3483 #ifdef SYS_lwp_create /* FIXME: once only, please */
3484 gdb_praddsysset (traced_syscall_exits
, SYS_lwp_create
);
3485 gdb_praddsysset (traced_syscall_exits
, SYS_lwp_exit
);
3488 #ifdef DYNAMIC_SYSCALLS
3490 int callnum
= find_syscall (pi
, "execve");
3492 gdb_praddsysset (traced_syscall_exits
, callnum
);
3493 callnum
= find_syscall (pi
, "ra_execve");
3495 gdb_praddsysset (traced_syscall_exits
, callnum
);
3499 status
= proc_set_traced_sysexit (pi
, traced_syscall_exits
);
3500 xfree (traced_syscall_exits
);
3504 #endif /* PRFS_STOPEXEC */
3509 procfs_attach (char *args
, int from_tty
)
3515 error_no_arg ("process-id to attach");
3518 if (pid
== getpid ())
3519 error ("Attaching GDB to itself is not a good idea...");
3523 exec_file
= get_exec_file (0);
3526 printf_filtered ("Attaching to program `%s', %s\n",
3527 exec_file
, target_pid_to_str (pid_to_ptid (pid
)));
3529 printf_filtered ("Attaching to %s\n",
3530 target_pid_to_str (pid_to_ptid (pid
)));
3534 inferior_ptid
= do_attach (pid_to_ptid (pid
));
3535 push_target (&procfs_ops
);
3539 procfs_detach (char *args
, int from_tty
)
3548 int pid
= PIDGET (inferior_ptid
);
3551 exec_file
= get_exec_file (0);
3552 if (exec_file
== NULL
)
3555 printf_filtered ("Detaching from program: %s, %s\n", exec_file
,
3556 target_pid_to_str (pid_to_ptid (pid
)));
3557 gdb_flush (gdb_stdout
);
3562 inferior_ptid
= null_ptid
;
3563 unpush_target (&procfs_ops
);
3567 do_attach (ptid_t ptid
)
3572 if ((pi
= create_procinfo (PIDGET (ptid
), 0)) == NULL
)
3573 perror ("procfs: out of memory in 'attach'");
3575 if (!open_procinfo_files (pi
, FD_CTL
))
3577 fprintf_filtered (gdb_stderr
, "procfs:%d -- ", __LINE__
);
3578 sprintf (errmsg
, "do_attach: couldn't open /proc file for process %d",
3580 dead_procinfo (pi
, errmsg
, NOKILL
);
3583 /* Stop the process (if it isn't already stopped). */
3584 if (proc_flags (pi
) & (PR_STOPPED
| PR_ISTOP
))
3586 pi
->was_stopped
= 1;
3587 proc_prettyprint_why (proc_why (pi
), proc_what (pi
), 1);
3591 pi
->was_stopped
= 0;
3592 /* Set the process to run again when we close it. */
3593 if (!proc_set_run_on_last_close (pi
))
3594 dead_procinfo (pi
, "do_attach: couldn't set RLC.", NOKILL
);
3596 /* Now stop the process. */
3597 if (!proc_stop_process (pi
))
3598 dead_procinfo (pi
, "do_attach: couldn't stop the process.", NOKILL
);
3599 pi
->ignore_next_sigstop
= 1;
3601 /* Save some of the /proc state to be restored if we detach. */
3602 if (!proc_get_traced_faults (pi
, &pi
->saved_fltset
))
3603 dead_procinfo (pi
, "do_attach: couldn't save traced faults.", NOKILL
);
3604 if (!proc_get_traced_signals (pi
, &pi
->saved_sigset
))
3605 dead_procinfo (pi
, "do_attach: couldn't save traced signals.", NOKILL
);
3606 if (!proc_get_traced_sysentry (pi
, pi
->saved_entryset
))
3607 dead_procinfo (pi
, "do_attach: couldn't save traced syscall entries.",
3609 if (!proc_get_traced_sysexit (pi
, pi
->saved_exitset
))
3610 dead_procinfo (pi
, "do_attach: couldn't save traced syscall exits.",
3612 if (!proc_get_held_signals (pi
, &pi
->saved_sighold
))
3613 dead_procinfo (pi
, "do_attach: couldn't save held signals.", NOKILL
);
3615 if ((fail
= procfs_debug_inferior (pi
)) != 0)
3616 dead_procinfo (pi
, "do_attach: failed in procfs_debug_inferior", NOKILL
);
3618 /* Let GDB know that the inferior was attached. */
3620 return MERGEPID (pi
->pid
, proc_get_current_thread (pi
));
3624 do_detach (int signo
)
3628 /* Find procinfo for the main process */
3629 pi
= find_procinfo_or_die (PIDGET (inferior_ptid
), 0); /* FIXME: threads */
3631 if (!proc_set_current_signal (pi
, signo
))
3632 proc_warn (pi
, "do_detach, set_current_signal", __LINE__
);
3634 if (!proc_set_traced_signals (pi
, &pi
->saved_sigset
))
3635 proc_warn (pi
, "do_detach, set_traced_signal", __LINE__
);
3637 if (!proc_set_traced_faults (pi
, &pi
->saved_fltset
))
3638 proc_warn (pi
, "do_detach, set_traced_faults", __LINE__
);
3640 if (!proc_set_traced_sysentry (pi
, pi
->saved_entryset
))
3641 proc_warn (pi
, "do_detach, set_traced_sysentry", __LINE__
);
3643 if (!proc_set_traced_sysexit (pi
, pi
->saved_exitset
))
3644 proc_warn (pi
, "do_detach, set_traced_sysexit", __LINE__
);
3646 if (!proc_set_held_signals (pi
, &pi
->saved_sighold
))
3647 proc_warn (pi
, "do_detach, set_held_signals", __LINE__
);
3649 if (signo
|| (proc_flags (pi
) & (PR_STOPPED
| PR_ISTOP
)))
3650 if (signo
|| !(pi
->was_stopped
) ||
3651 query ("Was stopped when attached, make it runnable again? "))
3653 /* Clear any pending signal. */
3654 if (!proc_clear_current_fault (pi
))
3655 proc_warn (pi
, "do_detach, clear_current_fault", __LINE__
);
3657 if (signo
== 0 && !proc_clear_current_signal (pi
))
3658 proc_warn (pi
, "do_detach, clear_current_signal", __LINE__
);
3660 if (!proc_set_run_on_last_close (pi
))
3661 proc_warn (pi
, "do_detach, set_rlc", __LINE__
);
3665 destroy_procinfo (pi
);
3668 /* Fetch register REGNUM from the inferior. If REGNUM is -1, do this
3671 ??? Is the following note still relevant? We can't get individual
3672 registers with the PT_GETREGS ptrace(2) request either, yet we
3673 don't bother with caching at all in that case.
3675 NOTE: Since the /proc interface cannot give us individual
3676 registers, we pay no attention to REGNUM, and just fetch them all.
3677 This results in the possibility that we will do unnecessarily many
3678 fetches, since we may be called repeatedly for individual
3679 registers. So we cache the results, and mark the cache invalid
3680 when the process is resumed. */
3683 procfs_fetch_registers (int regnum
)
3685 gdb_gregset_t
*gregs
;
3687 int pid
= PIDGET (inferior_ptid
);
3688 int tid
= TIDGET (inferior_ptid
);
3690 /* First look up procinfo for the main process. */
3691 pi
= find_procinfo_or_die (pid
, 0);
3693 /* If the event thread is not the same as GDB's requested thread
3694 (ie. inferior_ptid), then look up procinfo for the requested
3696 if (tid
!= 0 && tid
!= proc_get_current_thread (pi
))
3697 pi
= find_procinfo_or_die (pid
, tid
);
3700 error ("procfs: fetch_registers failed to find procinfo for %s",
3701 target_pid_to_str (inferior_ptid
));
3703 gregs
= proc_get_gregs (pi
);
3705 proc_error (pi
, "fetch_registers, get_gregs", __LINE__
);
3707 supply_gregset (gregs
);
3709 if (FP0_REGNUM
>= 0) /* Do we have an FPU? */
3711 gdb_fpregset_t
*fpregs
;
3713 if ((regnum
>= 0 && regnum
< FP0_REGNUM
)
3714 || regnum
== PC_REGNUM
3715 || regnum
== DEPRECATED_FP_REGNUM
3716 || regnum
== SP_REGNUM
)
3717 return; /* Not a floating point register. */
3719 fpregs
= proc_get_fpregs (pi
);
3721 proc_error (pi
, "fetch_registers, get_fpregs", __LINE__
);
3723 supply_fpregset (fpregs
);
3727 /* Get ready to modify the registers array. On machines which store
3728 individual registers, this doesn't need to do anything. On
3729 machines which store all the registers in one fell swoop, such as
3730 /proc, this makes sure that registers contains all the registers
3731 from the program being debugged. */
3734 procfs_prepare_to_store (void)
3736 #ifdef CHILD_PREPARE_TO_STORE
3737 CHILD_PREPARE_TO_STORE ();
3741 /* Store register REGNUM back into the inferior. If REGNUM is -1, do
3742 this for all registers.
3744 NOTE: Since the /proc interface will not read individual registers,
3745 we will cache these requests until the process is resumed, and only
3746 then write them back to the inferior process.
3748 FIXME: is that a really bad idea? Have to think about cases where
3749 writing one register might affect the value of others, etc. */
3752 procfs_store_registers (int regnum
)
3754 gdb_gregset_t
*gregs
;
3756 int pid
= PIDGET (inferior_ptid
);
3757 int tid
= TIDGET (inferior_ptid
);
3759 /* First find procinfo for main process. */
3760 pi
= find_procinfo_or_die (pid
, 0);
3762 /* If the event thread is not the same as GDB's requested thread
3763 (ie. inferior_ptid), then look up procinfo for the requested
3765 if (tid
!= 0 && tid
!= proc_get_current_thread (pi
))
3766 pi
= find_procinfo_or_die (pid
, tid
);
3769 error ("procfs: store_registers: failed to find procinfo for %s",
3770 target_pid_to_str (inferior_ptid
));
3772 gregs
= proc_get_gregs (pi
);
3774 proc_error (pi
, "store_registers, get_gregs", __LINE__
);
3776 fill_gregset (gregs
, regnum
);
3777 if (!proc_set_gregs (pi
))
3778 proc_error (pi
, "store_registers, set_gregs", __LINE__
);
3780 if (FP0_REGNUM
>= 0) /* Do we have an FPU? */
3782 gdb_fpregset_t
*fpregs
;
3784 if ((regnum
>= 0 && regnum
< FP0_REGNUM
)
3785 || regnum
== PC_REGNUM
3786 || regnum
== DEPRECATED_FP_REGNUM
3787 || regnum
== SP_REGNUM
)
3788 return; /* Not a floating point register. */
3790 fpregs
= proc_get_fpregs (pi
);
3792 proc_error (pi
, "store_registers, get_fpregs", __LINE__
);
3794 fill_fpregset (fpregs
, regnum
);
3795 if (!proc_set_fpregs (pi
))
3796 proc_error (pi
, "store_registers, set_fpregs", __LINE__
);
3801 syscall_is_lwp_exit (procinfo
*pi
, int scall
)
3805 if (scall
== SYS_lwp_exit
)
3809 if (scall
== SYS_lwpexit
)
3816 syscall_is_exit (procinfo
*pi
, int scall
)
3819 if (scall
== SYS_exit
)
3822 #ifdef DYNAMIC_SYSCALLS
3823 if (find_syscall (pi
, "_exit") == scall
)
3830 syscall_is_exec (procinfo
*pi
, int scall
)
3833 if (scall
== SYS_exec
)
3837 if (scall
== SYS_execv
)
3841 if (scall
== SYS_execve
)
3844 #ifdef DYNAMIC_SYSCALLS
3845 if (find_syscall (pi
, "_execve"))
3847 if (find_syscall (pi
, "ra_execve"))
3854 syscall_is_lwp_create (procinfo
*pi
, int scall
)
3856 #ifdef SYS_lwp_create
3857 if (scall
== SYS_lwp_create
)
3860 #ifdef SYS_lwpcreate
3861 if (scall
== SYS_lwpcreate
)
3868 * Function: target_wait
3870 * Retrieve the next stop event from the child process.
3871 * If child has not stopped yet, wait for it to stop.
3872 * Translate /proc eventcodes (or possibly wait eventcodes)
3873 * into gdb internal event codes.
3875 * Return: id of process (and possibly thread) that incurred the event.
3876 * event codes are returned thru a pointer parameter.
3880 procfs_wait (ptid_t ptid
, struct target_waitstatus
*status
)
3882 /* First cut: loosely based on original version 2.1 */
3886 ptid_t retval
, temp_ptid
;
3887 int why
, what
, flags
;
3894 retval
= pid_to_ptid (-1);
3896 /* Find procinfo for main process */
3897 pi
= find_procinfo_or_die (PIDGET (inferior_ptid
), 0);
3900 /* We must assume that the status is stale now... */
3901 pi
->status_valid
= 0;
3902 pi
->gregs_valid
= 0;
3903 pi
->fpregs_valid
= 0;
3905 #if 0 /* just try this out... */
3906 flags
= proc_flags (pi
);
3907 why
= proc_why (pi
);
3908 if ((flags
& PR_STOPPED
) && (why
== PR_REQUESTED
))
3909 pi
->status_valid
= 0; /* re-read again, IMMEDIATELY... */
3911 /* If child is not stopped, wait for it to stop. */
3912 if (!(proc_flags (pi
) & (PR_STOPPED
| PR_ISTOP
)) &&
3913 !proc_wait_for_stop (pi
))
3915 /* wait_for_stop failed: has the child terminated? */
3916 if (errno
== ENOENT
)
3920 /* /proc file not found; presumably child has terminated. */
3921 wait_retval
= wait (&wstat
); /* "wait" for the child's exit */
3923 if (wait_retval
!= PIDGET (inferior_ptid
)) /* wrong child? */
3924 error ("procfs: couldn't stop process %d: wait returned %d\n",
3925 PIDGET (inferior_ptid
), wait_retval
);
3926 /* FIXME: might I not just use waitpid?
3927 Or try find_procinfo to see if I know about this child? */
3928 retval
= pid_to_ptid (wait_retval
);
3930 else if (errno
== EINTR
)
3934 /* Unknown error from wait_for_stop. */
3935 proc_error (pi
, "target_wait (wait_for_stop)", __LINE__
);
3940 /* This long block is reached if either:
3941 a) the child was already stopped, or
3942 b) we successfully waited for the child with wait_for_stop.
3943 This block will analyze the /proc status, and translate it
3944 into a waitstatus for GDB.
3946 If we actually had to call wait because the /proc file
3947 is gone (child terminated), then we skip this block,
3948 because we already have a waitstatus. */
3950 flags
= proc_flags (pi
);
3951 why
= proc_why (pi
);
3952 what
= proc_what (pi
);
3954 if (flags
& (PR_STOPPED
| PR_ISTOP
))
3957 /* If it's running async (for single_thread control),
3958 set it back to normal again. */
3959 if (flags
& PR_ASYNC
)
3960 if (!proc_unset_async (pi
))
3961 proc_error (pi
, "target_wait, unset_async", __LINE__
);
3965 proc_prettyprint_why (why
, what
, 1);
3967 /* The 'pid' we will return to GDB is composed of
3968 the process ID plus the lwp ID. */
3969 retval
= MERGEPID (pi
->pid
, proc_get_current_thread (pi
));
3973 wstat
= (what
<< 8) | 0177;
3976 if (syscall_is_lwp_exit (pi
, what
))
3978 printf_filtered ("[%s exited]\n",
3979 target_pid_to_str (retval
));
3980 delete_thread (retval
);
3981 status
->kind
= TARGET_WAITKIND_SPURIOUS
;
3984 else if (syscall_is_exit (pi
, what
))
3986 /* Handle SYS_exit call only */
3987 /* Stopped at entry to SYS_exit.
3988 Make it runnable, resume it, then use
3989 the wait system call to get its exit code.
3990 Proc_run_process always clears the current
3992 Then return its exit status. */
3993 pi
->status_valid
= 0;
3995 /* FIXME: what we should do is return
3996 TARGET_WAITKIND_SPURIOUS. */
3997 if (!proc_run_process (pi
, 0, 0))
3998 proc_error (pi
, "target_wait, run_process", __LINE__
);
4001 /* Don't call wait: simulate waiting for exit,
4002 return a "success" exit code. Bogus: what if
4003 it returns something else? */
4005 retval
= inferior_ptid
; /* ? ? ? */
4009 int temp
= wait (&wstat
);
4011 /* FIXME: shouldn't I make sure I get the right
4012 event from the right process? If (for
4013 instance) I have killed an earlier inferior
4014 process but failed to clean up after it
4015 somehow, I could get its termination event
4018 /* If wait returns -1, that's what we return to GDB. */
4020 retval
= pid_to_ptid (temp
);
4025 printf_filtered ("procfs: trapped on entry to ");
4026 proc_prettyprint_syscall (proc_what (pi
), 0);
4027 printf_filtered ("\n");
4030 long i
, nsysargs
, *sysargs
;
4032 if ((nsysargs
= proc_nsysarg (pi
)) > 0 &&
4033 (sysargs
= proc_sysargs (pi
)) != NULL
)
4035 printf_filtered ("%ld syscall arguments:\n", nsysargs
);
4036 for (i
= 0; i
< nsysargs
; i
++)
4037 printf_filtered ("#%ld: 0x%08lx\n",
4045 /* How to exit gracefully, returning "unknown event" */
4046 status
->kind
= TARGET_WAITKIND_SPURIOUS
;
4047 return inferior_ptid
;
4051 /* How to keep going without returning to wfi: */
4052 target_resume (ptid
, 0, TARGET_SIGNAL_0
);
4058 if (syscall_is_exec (pi
, what
))
4060 /* Hopefully this is our own "fork-child" execing
4061 the real child. Hoax this event into a trap, and
4062 GDB will see the child about to execute its start
4064 wstat
= (SIGTRAP
<< 8) | 0177;
4067 else if (what
== SYS_syssgi
)
4069 /* see if we can break on dbx_link(). If yes, then
4070 we no longer need the SYS_syssgi notifications. */
4071 if (insert_dbx_link_breakpoint (pi
))
4072 proc_trace_syscalls_1 (pi
, SYS_syssgi
, PR_SYSEXIT
,
4075 /* This is an internal event and should be transparent
4076 to wfi, so resume the execution and wait again. See
4077 comment in procfs_init_inferior() for more details. */
4078 target_resume (ptid
, 0, TARGET_SIGNAL_0
);
4082 else if (syscall_is_lwp_create (pi
, what
))
4085 * This syscall is somewhat like fork/exec.
4086 * We will get the event twice: once for the parent LWP,
4087 * and once for the child. We should already know about
4088 * the parent LWP, but the child will be new to us. So,
4089 * whenever we get this event, if it represents a new
4090 * thread, simply add the thread to the list.
4093 /* If not in procinfo list, add it. */
4094 temp_tid
= proc_get_current_thread (pi
);
4095 if (!find_procinfo (pi
->pid
, temp_tid
))
4096 create_procinfo (pi
->pid
, temp_tid
);
4098 temp_ptid
= MERGEPID (pi
->pid
, temp_tid
);
4099 /* If not in GDB's thread list, add it. */
4100 if (!in_thread_list (temp_ptid
))
4102 printf_filtered ("[New %s]\n",
4103 target_pid_to_str (temp_ptid
));
4104 add_thread (temp_ptid
);
4106 /* Return to WFI, but tell it to immediately resume. */
4107 status
->kind
= TARGET_WAITKIND_SPURIOUS
;
4108 return inferior_ptid
;
4110 else if (syscall_is_lwp_exit (pi
, what
))
4112 printf_filtered ("[%s exited]\n",
4113 target_pid_to_str (retval
));
4114 delete_thread (retval
);
4115 status
->kind
= TARGET_WAITKIND_SPURIOUS
;
4120 /* FIXME: Do we need to handle SYS_sproc,
4121 SYS_fork, or SYS_vfork here? The old procfs
4122 seemed to use this event to handle threads on
4123 older (non-LWP) systems, where I'm assuming
4124 that threads were actually separate processes.
4125 Irix, maybe? Anyway, low priority for now. */
4129 printf_filtered ("procfs: trapped on exit from ");
4130 proc_prettyprint_syscall (proc_what (pi
), 0);
4131 printf_filtered ("\n");
4134 long i
, nsysargs
, *sysargs
;
4136 if ((nsysargs
= proc_nsysarg (pi
)) > 0 &&
4137 (sysargs
= proc_sysargs (pi
)) != NULL
)
4139 printf_filtered ("%ld syscall arguments:\n", nsysargs
);
4140 for (i
= 0; i
< nsysargs
; i
++)
4141 printf_filtered ("#%ld: 0x%08lx\n",
4146 status
->kind
= TARGET_WAITKIND_SPURIOUS
;
4147 return inferior_ptid
;
4152 wstat
= (SIGSTOP
<< 8) | 0177;
4157 printf_filtered ("Retry #%d:\n", retry
);
4158 pi
->status_valid
= 0;
4163 /* If not in procinfo list, add it. */
4164 temp_tid
= proc_get_current_thread (pi
);
4165 if (!find_procinfo (pi
->pid
, temp_tid
))
4166 create_procinfo (pi
->pid
, temp_tid
);
4168 /* If not in GDB's thread list, add it. */
4169 temp_ptid
= MERGEPID (pi
->pid
, temp_tid
);
4170 if (!in_thread_list (temp_ptid
))
4172 printf_filtered ("[New %s]\n",
4173 target_pid_to_str (temp_ptid
));
4174 add_thread (temp_ptid
);
4177 status
->kind
= TARGET_WAITKIND_STOPPED
;
4178 status
->value
.sig
= 0;
4183 wstat
= (what
<< 8) | 0177;
4189 wstat
= (SIGTRAP
<< 8) | 0177;
4194 wstat
= (SIGTRAP
<< 8) | 0177;
4197 /* FIXME: use si_signo where possible. */
4199 #if (FLTILL != FLTPRIV) /* avoid "duplicate case" error */
4202 wstat
= (SIGILL
<< 8) | 0177;
4205 #if (FLTTRACE != FLTBPT) /* avoid "duplicate case" error */
4208 /* If we hit our __dbx_link() internal breakpoint,
4209 then remove it. See comments in procfs_init_inferior()
4210 for more details. */
4211 if (dbx_link_bpt_addr
!= 0
4212 && dbx_link_bpt_addr
== read_pc ())
4213 remove_dbx_link_breakpoint ();
4215 wstat
= (SIGTRAP
<< 8) | 0177;
4219 #if (FLTBOUNDS != FLTSTACK) /* avoid "duplicate case" error */
4222 wstat
= (SIGSEGV
<< 8) | 0177;
4226 #if (FLTFPE != FLTIOVF) /* avoid "duplicate case" error */
4229 wstat
= (SIGFPE
<< 8) | 0177;
4231 case FLTPAGE
: /* Recoverable page fault */
4232 default: /* FIXME: use si_signo if possible for fault */
4233 retval
= pid_to_ptid (-1);
4234 printf_filtered ("procfs:%d -- ", __LINE__
);
4235 printf_filtered ("child stopped for unknown reason:\n");
4236 proc_prettyprint_why (why
, what
, 1);
4237 error ("... giving up...");
4240 break; /* case PR_FAULTED: */
4241 default: /* switch (why) unmatched */
4242 printf_filtered ("procfs:%d -- ", __LINE__
);
4243 printf_filtered ("child stopped for unknown reason:\n");
4244 proc_prettyprint_why (why
, what
, 1);
4245 error ("... giving up...");
4249 * Got this far without error:
4250 * If retval isn't in the threads database, add it.
4252 if (PIDGET (retval
) > 0 &&
4253 !ptid_equal (retval
, inferior_ptid
) &&
4254 !in_thread_list (retval
))
4257 * We have a new thread.
4258 * We need to add it both to GDB's list and to our own.
4259 * If we don't create a procinfo, resume may be unhappy
4262 printf_filtered ("[New %s]\n", target_pid_to_str (retval
));
4263 add_thread (retval
);
4264 if (find_procinfo (PIDGET (retval
), TIDGET (retval
)) == NULL
)
4265 create_procinfo (PIDGET (retval
), TIDGET (retval
));
4267 /* In addition, it's possible that this is the first
4268 * new thread we've seen, in which case we may not
4269 * have created entries for inferior_ptid yet.
4271 if (TIDGET (inferior_ptid
) != 0)
4273 if (!in_thread_list (inferior_ptid
))
4274 add_thread (inferior_ptid
);
4275 if (find_procinfo (PIDGET (inferior_ptid
),
4276 TIDGET (inferior_ptid
)) == NULL
)
4277 create_procinfo (PIDGET (inferior_ptid
),
4278 TIDGET (inferior_ptid
));
4282 else /* flags do not indicate STOPPED */
4284 /* surely this can't happen... */
4285 printf_filtered ("procfs:%d -- process not stopped.\n",
4287 proc_prettyprint_flags (flags
, 1);
4288 error ("procfs: ...giving up...");
4293 store_waitstatus (status
, wstat
);
4299 /* Perform a partial transfer to/from the specified object. For
4300 memory transfers, fall back to the old memory xfer functions. */
4303 procfs_xfer_partial (struct target_ops
*ops
, enum target_object object
,
4304 const char *annex
, void *readbuf
,
4305 const void *writebuf
, ULONGEST offset
, LONGEST len
)
4309 case TARGET_OBJECT_MEMORY
:
4311 return (*ops
->deprecated_xfer_memory
) (offset
, readbuf
, len
,
4312 0/*write*/, NULL
, ops
);
4314 return (*ops
->deprecated_xfer_memory
) (offset
, writebuf
, len
,
4315 1/*write*/, NULL
, ops
);
4319 case TARGET_OBJECT_AUXV
:
4320 return procfs_xfer_auxv (ops
, object
, annex
, readbuf
, writebuf
,
4325 if (ops
->beneath
!= NULL
)
4326 return ops
->beneath
->to_xfer_partial (ops
->beneath
, object
, annex
,
4327 readbuf
, writebuf
, offset
, len
);
4333 /* Transfer LEN bytes between GDB address MYADDR and target address
4334 MEMADDR. If DOWRITE is non-zero, transfer them to the target,
4335 otherwise transfer them from the target. TARGET is unused.
4337 The return value is 0 if an error occurred or no bytes were
4338 transferred. Otherwise, it will be a positive value which
4339 indicates the number of bytes transferred between gdb and the
4340 target. (Note that the interface also makes provisions for
4341 negative values, but this capability isn't implemented here.) */
4344 procfs_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int dowrite
,
4345 struct mem_attrib
*attrib
, struct target_ops
*target
)
4350 /* Find procinfo for main process */
4351 pi
= find_procinfo_or_die (PIDGET (inferior_ptid
), 0);
4352 if (pi
->as_fd
== 0 &&
4353 open_procinfo_files (pi
, FD_AS
) == 0)
4355 proc_warn (pi
, "xfer_memory, open_proc_files", __LINE__
);
4359 if (lseek (pi
->as_fd
, (off_t
) memaddr
, SEEK_SET
) == (off_t
) memaddr
)
4364 PROCFS_NOTE ("write memory: ");
4366 PROCFS_NOTE ("write memory: \n");
4368 nbytes
= write (pi
->as_fd
, myaddr
, len
);
4372 PROCFS_NOTE ("read memory: \n");
4373 nbytes
= read (pi
->as_fd
, myaddr
, len
);
4384 * Function: invalidate_cache
4386 * Called by target_resume before making child runnable.
4387 * Mark cached registers and status's invalid.
4388 * If there are "dirty" caches that need to be written back
4389 * to the child process, do that.
4391 * File descriptors are also cached.
4392 * As they are a limited resource, we cannot hold onto them indefinitely.
4393 * However, as they are expensive to open, we don't want to throw them
4394 * away indescriminately either. As a compromise, we will keep the
4395 * file descriptors for the parent process, but discard any file
4396 * descriptors we may have accumulated for the threads.
4399 * As this function is called by iterate_over_threads, it always
4400 * returns zero (so that iterate_over_threads will keep iterating).
4405 invalidate_cache (procinfo
*parent
, procinfo
*pi
, void *ptr
)
4408 * About to run the child; invalidate caches and do any other cleanup.
4412 if (pi
->gregs_dirty
)
4413 if (parent
== NULL
||
4414 proc_get_current_thread (parent
) != pi
->tid
)
4415 if (!proc_set_gregs (pi
)) /* flush gregs cache */
4416 proc_warn (pi
, "target_resume, set_gregs",
4418 if (FP0_REGNUM
>= 0)
4419 if (pi
->fpregs_dirty
)
4420 if (parent
== NULL
||
4421 proc_get_current_thread (parent
) != pi
->tid
)
4422 if (!proc_set_fpregs (pi
)) /* flush fpregs cache */
4423 proc_warn (pi
, "target_resume, set_fpregs",
4429 /* The presence of a parent indicates that this is an LWP.
4430 Close any file descriptors that it might have open.
4431 We don't do this to the master (parent) procinfo. */
4433 close_procinfo_files (pi
);
4435 pi
->gregs_valid
= 0;
4436 pi
->fpregs_valid
= 0;
4438 pi
->gregs_dirty
= 0;
4439 pi
->fpregs_dirty
= 0;
4441 pi
->status_valid
= 0;
4442 pi
->threads_valid
= 0;
4449 * Function: make_signal_thread_runnable
4451 * A callback function for iterate_over_threads.
4452 * Find the asynchronous signal thread, and make it runnable.
4453 * See if that helps matters any.
4457 make_signal_thread_runnable (procinfo
*process
, procinfo
*pi
, void *ptr
)
4460 if (proc_flags (pi
) & PR_ASLWP
)
4462 if (!proc_run_process (pi
, 0, -1))
4463 proc_error (pi
, "make_signal_thread_runnable", __LINE__
);
4472 * Function: target_resume
4474 * Make the child process runnable. Normally we will then call
4475 * procfs_wait and wait for it to stop again (unles gdb is async).
4478 * step: if true, then arrange for the child to stop again
4479 * after executing a single instruction.
4480 * signo: if zero, then cancel any pending signal.
4481 * If non-zero, then arrange for the indicated signal
4482 * to be delivered to the child when it runs.
4483 * pid: if -1, then allow any child thread to run.
4484 * if non-zero, then allow only the indicated thread to run.
4485 ******* (not implemented yet)
4489 procfs_resume (ptid_t ptid
, int step
, enum target_signal signo
)
4491 procinfo
*pi
, *thread
;
4495 prrun.prflags |= PRSVADDR;
4496 prrun.pr_vaddr = $PC; set resume address
4497 prrun.prflags |= PRSTRACE; trace signals in pr_trace (all)
4498 prrun.prflags |= PRSFAULT; trace faults in pr_fault (all but PAGE)
4499 prrun.prflags |= PRCFAULT; clear current fault.
4501 PRSTRACE and PRSFAULT can be done by other means
4502 (proc_trace_signals, proc_trace_faults)
4503 PRSVADDR is unnecessary.
4504 PRCFAULT may be replaced by a PIOCCFAULT call (proc_clear_current_fault)
4505 This basically leaves PRSTEP and PRCSIG.
4506 PRCSIG is like PIOCSSIG (proc_clear_current_signal).
4507 So basically PR_STEP is the sole argument that must be passed
4508 to proc_run_process (for use in the prrun struct by ioctl). */
4510 /* Find procinfo for main process */
4511 pi
= find_procinfo_or_die (PIDGET (inferior_ptid
), 0);
4513 /* First cut: ignore pid argument */
4516 /* Convert signal to host numbering. */
4518 (signo
== TARGET_SIGNAL_STOP
&& pi
->ignore_next_sigstop
))
4521 native_signo
= target_signal_to_host (signo
);
4523 pi
->ignore_next_sigstop
= 0;
4525 /* Running the process voids all cached registers and status. */
4526 /* Void the threads' caches first */
4527 proc_iterate_over_threads (pi
, invalidate_cache
, NULL
);
4528 /* Void the process procinfo's caches. */
4529 invalidate_cache (NULL
, pi
, NULL
);
4531 if (PIDGET (ptid
) != -1)
4533 /* Resume a specific thread, presumably suppressing the others. */
4534 thread
= find_procinfo (PIDGET (ptid
), TIDGET (ptid
));
4537 if (thread
->tid
!= 0)
4539 /* We're to resume a specific thread, and not the others.
4540 * Set the child process's PR_ASYNC flag.
4543 if (!proc_set_async (pi
))
4544 proc_error (pi
, "target_resume, set_async", __LINE__
);
4547 proc_iterate_over_threads (pi
,
4548 make_signal_thread_runnable
,
4551 pi
= thread
; /* substitute the thread's procinfo for run */
4556 if (!proc_run_process (pi
, step
, native_signo
))
4559 warning ("resume: target already running. Pretend to resume, and hope for the best!\n");
4561 proc_error (pi
, "target_resume", __LINE__
);
4566 * Function: register_gdb_signals
4568 * Traverse the list of signals that GDB knows about
4569 * (see "handle" command), and arrange for the target
4570 * to be stopped or not, according to these settings.
4572 * Returns non-zero for success, zero for failure.
4576 register_gdb_signals (procinfo
*pi
, gdb_sigset_t
*signals
)
4580 for (signo
= 0; signo
< NSIG
; signo
++)
4581 if (signal_stop_state (target_signal_from_host (signo
)) == 0 &&
4582 signal_print_state (target_signal_from_host (signo
)) == 0 &&
4583 signal_pass_state (target_signal_from_host (signo
)) == 1)
4584 prdelset (signals
, signo
);
4586 praddset (signals
, signo
);
4588 return proc_set_traced_signals (pi
, signals
);
4592 * Function: target_notice_signals
4594 * Set up to trace signals in the child process.
4598 procfs_notice_signals (ptid_t ptid
)
4600 gdb_sigset_t signals
;
4601 procinfo
*pi
= find_procinfo_or_die (PIDGET (ptid
), 0);
4603 if (proc_get_traced_signals (pi
, &signals
) &&
4604 register_gdb_signals (pi
, &signals
))
4607 proc_error (pi
, "notice_signals", __LINE__
);
4611 * Function: target_files_info
4613 * Print status information about the child process.
4617 procfs_files_info (struct target_ops
*ignore
)
4619 printf_filtered ("\tUsing the running image of %s %s via /proc.\n",
4620 attach_flag
? "attached": "child",
4621 target_pid_to_str (inferior_ptid
));
4625 * Function: target_open
4627 * A dummy: you don't open procfs.
4631 procfs_open (char *args
, int from_tty
)
4633 error ("Use the \"run\" command to start a Unix child process.");
4637 * Function: target_can_run
4639 * This tells GDB that this target vector can be invoked
4640 * for "run" or "attach".
4643 int procfs_suppress_run
= 0; /* Non-zero if procfs should pretend not to
4644 be a runnable target. Used by targets
4645 that can sit atop procfs, such as solaris
4650 procfs_can_run (void)
4652 /* This variable is controlled by modules that sit atop procfs that
4653 may layer their own process structure atop that provided here.
4654 sol-thread.c does this because of the Solaris two-level thread
4657 /* NOTE: possibly obsolete -- use the thread_stratum approach instead. */
4659 return !procfs_suppress_run
;
4663 * Function: target_stop
4665 * Stop the child process asynchronously, as when the
4666 * gdb user types control-c or presses a "stop" button.
4668 * Works by sending kill(SIGINT) to the child's process group.
4674 kill (-inferior_process_group
, SIGINT
);
4678 * Function: unconditionally_kill_inferior
4680 * Make it die. Wait for it to die. Clean up after it.
4681 * Note: this should only be applied to the real process,
4682 * not to an LWP, because of the check for parent-process.
4683 * If we need this to work for an LWP, it needs some more logic.
4687 unconditionally_kill_inferior (procinfo
*pi
)
4691 parent_pid
= proc_parent_pid (pi
);
4692 #ifdef PROCFS_NEED_CLEAR_CURSIG_FOR_KILL
4693 /* FIXME: use access functions */
4694 /* Alpha OSF/1-3.x procfs needs a clear of the current signal
4695 before the PIOCKILL, otherwise it might generate a corrupted core
4696 file for the inferior. */
4697 if (ioctl (pi
->ctl_fd
, PIOCSSIG
, NULL
) < 0)
4699 printf_filtered ("unconditionally_kill: SSIG failed!\n");
4702 #ifdef PROCFS_NEED_PIOCSSIG_FOR_KILL
4703 /* Alpha OSF/1-2.x procfs needs a PIOCSSIG call with a SIGKILL signal
4704 to kill the inferior, otherwise it might remain stopped with a
4706 We do not check the result of the PIOCSSIG, the inferior might have
4709 gdb_siginfo_t newsiginfo
;
4711 memset ((char *) &newsiginfo
, 0, sizeof (newsiginfo
));
4712 newsiginfo
.si_signo
= SIGKILL
;
4713 newsiginfo
.si_code
= 0;
4714 newsiginfo
.si_errno
= 0;
4715 newsiginfo
.si_pid
= getpid ();
4716 newsiginfo
.si_uid
= getuid ();
4717 /* FIXME: use proc_set_current_signal */
4718 ioctl (pi
->ctl_fd
, PIOCSSIG
, &newsiginfo
);
4720 #else /* PROCFS_NEED_PIOCSSIG_FOR_KILL */
4721 if (!proc_kill (pi
, SIGKILL
))
4722 proc_error (pi
, "unconditionally_kill, proc_kill", __LINE__
);
4723 #endif /* PROCFS_NEED_PIOCSSIG_FOR_KILL */
4724 destroy_procinfo (pi
);
4726 /* If pi is GDB's child, wait for it to die. */
4727 if (parent_pid
== getpid ())
4728 /* FIXME: should we use waitpid to make sure we get the right event?
4729 Should we check the returned event? */
4734 ret
= waitpid (pi
->pid
, &status
, 0);
4742 * Function: target_kill_inferior
4744 * We're done debugging it, and we want it to go away.
4745 * Then we want GDB to forget all about it.
4749 procfs_kill_inferior (void)
4751 if (!ptid_equal (inferior_ptid
, null_ptid
)) /* ? */
4753 /* Find procinfo for main process */
4754 procinfo
*pi
= find_procinfo (PIDGET (inferior_ptid
), 0);
4757 unconditionally_kill_inferior (pi
);
4758 target_mourn_inferior ();
4763 * Function: target_mourn_inferior
4765 * Forget we ever debugged this thing!
4769 procfs_mourn_inferior (void)
4773 if (!ptid_equal (inferior_ptid
, null_ptid
))
4775 /* Find procinfo for main process */
4776 pi
= find_procinfo (PIDGET (inferior_ptid
), 0);
4778 destroy_procinfo (pi
);
4780 unpush_target (&procfs_ops
);
4781 generic_mourn_inferior ();
4785 * Function: init_inferior
4787 * When GDB forks to create a runnable inferior process,
4788 * this function is called on the parent side of the fork.
4789 * It's job is to do whatever is necessary to make the child
4790 * ready to be debugged, and then wait for the child to synchronize.
4794 procfs_init_inferior (int pid
)
4797 gdb_sigset_t signals
;
4800 /* This routine called on the parent side (GDB side)
4801 after GDB forks the inferior. */
4803 push_target (&procfs_ops
);
4805 if ((pi
= create_procinfo (pid
, 0)) == NULL
)
4806 perror ("procfs: out of memory in 'init_inferior'");
4808 if (!open_procinfo_files (pi
, FD_CTL
))
4809 proc_error (pi
, "init_inferior, open_proc_files", __LINE__
);
4813 open_procinfo_files // done
4816 procfs_notice_signals
4823 /* If not stopped yet, wait for it to stop. */
4824 if (!(proc_flags (pi
) & PR_STOPPED
) &&
4825 !(proc_wait_for_stop (pi
)))
4826 dead_procinfo (pi
, "init_inferior: wait_for_stop failed", KILL
);
4828 /* Save some of the /proc state to be restored if we detach. */
4829 /* FIXME: Why? In case another debugger was debugging it?
4830 We're it's parent, for Ghu's sake! */
4831 if (!proc_get_traced_signals (pi
, &pi
->saved_sigset
))
4832 proc_error (pi
, "init_inferior, get_traced_signals", __LINE__
);
4833 if (!proc_get_held_signals (pi
, &pi
->saved_sighold
))
4834 proc_error (pi
, "init_inferior, get_held_signals", __LINE__
);
4835 if (!proc_get_traced_faults (pi
, &pi
->saved_fltset
))
4836 proc_error (pi
, "init_inferior, get_traced_faults", __LINE__
);
4837 if (!proc_get_traced_sysentry (pi
, pi
->saved_entryset
))
4838 proc_error (pi
, "init_inferior, get_traced_sysentry", __LINE__
);
4839 if (!proc_get_traced_sysexit (pi
, pi
->saved_exitset
))
4840 proc_error (pi
, "init_inferior, get_traced_sysexit", __LINE__
);
4842 /* Register to trace selected signals in the child. */
4843 prfillset (&signals
);
4844 if (!register_gdb_signals (pi
, &signals
))
4845 proc_error (pi
, "init_inferior, register_signals", __LINE__
);
4847 if ((fail
= procfs_debug_inferior (pi
)) != 0)
4848 proc_error (pi
, "init_inferior (procfs_debug_inferior)", fail
);
4850 /* FIXME: logically, we should really be turning OFF run-on-last-close,
4851 and possibly even turning ON kill-on-last-close at this point. But
4852 I can't make that change without careful testing which I don't have
4853 time to do right now... */
4854 /* Turn on run-on-last-close flag so that the child
4855 will die if GDB goes away for some reason. */
4856 if (!proc_set_run_on_last_close (pi
))
4857 proc_error (pi
, "init_inferior, set_RLC", __LINE__
);
4859 /* The 'process ID' we return to GDB is composed of
4860 the actual process ID plus the lwp ID. */
4861 inferior_ptid
= MERGEPID (pi
->pid
, proc_get_current_thread (pi
));
4863 /* Typically two, one trap to exec the shell, one to exec the
4864 program being debugged. Defined by "inferior.h". */
4865 startup_inferior (START_INFERIOR_TRAPS_EXPECTED
);
4868 /* On mips-irix, we need to stop the inferior early enough during
4869 the startup phase in order to be able to load the shared library
4870 symbols and insert the breakpoints that are located in these shared
4871 libraries. Stopping at the program entry point is not good enough
4872 because the -init code is executed before the execution reaches
4875 So what we need to do is to insert a breakpoint in the runtime
4876 loader (rld), more precisely in __dbx_link(). This procedure is
4877 called by rld once all shared libraries have been mapped, but before
4878 the -init code is executed. Unfortuantely, this is not straightforward,
4879 as rld is not part of the executable we are running, and thus we need
4880 the inferior to run until rld itself has been mapped in memory.
4882 For this, we trace all syssgi() syscall exit events. Each time
4883 we detect such an event, we iterate over each text memory maps,
4884 get its associated fd, and scan the symbol table for __dbx_link().
4885 When found, we know that rld has been mapped, and that we can insert
4886 the breakpoint at the symbol address. Once the dbx_link() breakpoint
4887 has been inserted, the syssgi() notifications are no longer necessary,
4888 so they should be canceled. */
4889 proc_trace_syscalls_1 (pi
, SYS_syssgi
, PR_SYSEXIT
, FLAG_SET
, 0);
4890 dbx_link_bpt_addr
= 0;
4895 * Function: set_exec_trap
4897 * When GDB forks to create a new process, this function is called
4898 * on the child side of the fork before GDB exec's the user program.
4899 * Its job is to make the child minimally debuggable, so that the
4900 * parent GDB process can connect to the child and take over.
4901 * This function should do only the minimum to make that possible,
4902 * and to synchronize with the parent process. The parent process
4903 * should take care of the details.
4907 procfs_set_exec_trap (void)
4909 /* This routine called on the child side (inferior side)
4910 after GDB forks the inferior. It must use only local variables,
4911 because it may be sharing data space with its parent. */
4916 if ((pi
= create_procinfo (getpid (), 0)) == NULL
)
4917 perror_with_name ("procfs: create_procinfo failed in child.");
4919 if (open_procinfo_files (pi
, FD_CTL
) == 0)
4921 proc_warn (pi
, "set_exec_trap, open_proc_files", __LINE__
);
4922 gdb_flush (gdb_stderr
);
4923 /* no need to call "dead_procinfo", because we're going to exit. */
4927 #ifdef PRFS_STOPEXEC /* defined on OSF */
4928 /* OSF method for tracing exec syscalls. Quoting:
4929 Under Alpha OSF/1 we have to use a PIOCSSPCACT ioctl to trace
4930 exits from exec system calls because of the user level loader. */
4931 /* FIXME: make nice and maybe move into an access function. */
4935 if (ioctl (pi
->ctl_fd
, PIOCGSPCACT
, &prfs_flags
) < 0)
4937 proc_warn (pi
, "set_exec_trap (PIOCGSPCACT)", __LINE__
);
4938 gdb_flush (gdb_stderr
);
4941 prfs_flags
|= PRFS_STOPEXEC
;
4943 if (ioctl (pi
->ctl_fd
, PIOCSSPCACT
, &prfs_flags
) < 0)
4945 proc_warn (pi
, "set_exec_trap (PIOCSSPCACT)", __LINE__
);
4946 gdb_flush (gdb_stderr
);
4950 #else /* not PRFS_STOPEXEC */
4951 /* Everyone else's (except OSF) method for tracing exec syscalls */
4953 Not all systems with /proc have all the exec* syscalls with the same
4954 names. On the SGI, for example, there is no SYS_exec, but there
4955 *is* a SYS_execv. So, we try to account for that. */
4957 exitset
= sysset_t_alloc (pi
);
4958 gdb_premptysysset (exitset
);
4960 gdb_praddsysset (exitset
, SYS_exec
);
4963 gdb_praddsysset (exitset
, SYS_execve
);
4966 gdb_praddsysset (exitset
, SYS_execv
);
4968 #ifdef DYNAMIC_SYSCALLS
4970 int callnum
= find_syscall (pi
, "execve");
4973 gdb_praddsysset (exitset
, callnum
);
4975 callnum
= find_syscall (pi
, "ra_execve");
4977 gdb_praddsysset (exitset
, callnum
);
4979 #endif /* DYNAMIC_SYSCALLS */
4981 if (!proc_set_traced_sysexit (pi
, exitset
))
4983 proc_warn (pi
, "set_exec_trap, set_traced_sysexit", __LINE__
);
4984 gdb_flush (gdb_stderr
);
4987 #endif /* PRFS_STOPEXEC */
4989 /* FIXME: should this be done in the parent instead? */
4990 /* Turn off inherit on fork flag so that all grand-children
4991 of gdb start with tracing flags cleared. */
4992 if (!proc_unset_inherit_on_fork (pi
))
4993 proc_warn (pi
, "set_exec_trap, unset_inherit", __LINE__
);
4995 /* Turn off run on last close flag, so that the child process
4996 cannot run away just because we close our handle on it.
4997 We want it to wait for the parent to attach. */
4998 if (!proc_unset_run_on_last_close (pi
))
4999 proc_warn (pi
, "set_exec_trap, unset_RLC", __LINE__
);
5001 /* FIXME: No need to destroy the procinfo --
5002 we have our own address space, and we're about to do an exec! */
5003 /*destroy_procinfo (pi);*/
5007 * Function: create_inferior
5009 * This function is called BEFORE gdb forks the inferior process.
5010 * Its only real responsibility is to set things up for the fork,
5011 * and tell GDB which two functions to call after the fork (one
5012 * for the parent, and one for the child).
5014 * This function does a complicated search for a unix shell program,
5015 * which it then uses to parse arguments and environment variables
5016 * to be sent to the child. I wonder whether this code could not
5017 * be abstracted out and shared with other unix targets such as
5022 procfs_create_inferior (char *exec_file
, char *allargs
, char **env
,
5025 char *shell_file
= getenv ("SHELL");
5027 if (shell_file
!= NULL
&& strchr (shell_file
, '/') == NULL
)
5030 /* We will be looking down the PATH to find shell_file. If we
5031 just do this the normal way (via execlp, which operates by
5032 attempting an exec for each element of the PATH until it
5033 finds one which succeeds), then there will be an exec for
5034 each failed attempt, each of which will cause a PR_SYSEXIT
5035 stop, and we won't know how to distinguish the PR_SYSEXIT's
5036 for these failed execs with the ones for successful execs
5037 (whether the exec has succeeded is stored at that time in the
5038 carry bit or some such architecture-specific and
5039 non-ABI-specified place).
5041 So I can't think of anything better than to search the PATH
5042 now. This has several disadvantages: (1) There is a race
5043 condition; if we find a file now and it is deleted before we
5044 exec it, we lose, even if the deletion leaves a valid file
5045 further down in the PATH, (2) there is no way to know exactly
5046 what an executable (in the sense of "capable of being
5047 exec'd") file is. Using access() loses because it may lose
5048 if the caller is the superuser; failing to use it loses if
5049 there are ACLs or some such. */
5053 /* FIXME-maybe: might want "set path" command so user can change what
5054 path is used from within GDB. */
5055 char *path
= getenv ("PATH");
5057 struct stat statbuf
;
5060 path
= "/bin:/usr/bin";
5062 tryname
= alloca (strlen (path
) + strlen (shell_file
) + 2);
5063 for (p
= path
; p
!= NULL
; p
= p1
? p1
+ 1: NULL
)
5065 p1
= strchr (p
, ':');
5070 strncpy (tryname
, p
, len
);
5071 tryname
[len
] = '\0';
5072 strcat (tryname
, "/");
5073 strcat (tryname
, shell_file
);
5074 if (access (tryname
, X_OK
) < 0)
5076 if (stat (tryname
, &statbuf
) < 0)
5078 if (!S_ISREG (statbuf
.st_mode
))
5079 /* We certainly need to reject directories. I'm not quite
5080 as sure about FIFOs, sockets, etc., but I kind of doubt
5081 that people want to exec() these things. */
5086 /* Not found. This must be an error rather than merely passing
5087 the file to execlp(), because execlp() would try all the
5088 exec()s, causing GDB to get confused. */
5089 error ("procfs:%d -- Can't find shell %s in PATH",
5090 __LINE__
, shell_file
);
5092 shell_file
= tryname
;
5095 fork_inferior (exec_file
, allargs
, env
, procfs_set_exec_trap
,
5096 procfs_init_inferior
, NULL
, shell_file
);
5099 /* Make sure to cancel the syssgi() syscall-exit notifications.
5100 They should normally have been removed by now, but they may still
5101 be activated if the inferior doesn't use shared libraries, or if
5102 we didn't locate __dbx_link, or if we never stopped in __dbx_link.
5103 See procfs_init_inferior() for more details. */
5104 proc_trace_syscalls_1 (find_procinfo_or_die (PIDGET (inferior_ptid
), 0),
5105 SYS_syssgi
, PR_SYSEXIT
, FLAG_RESET
, 0);
5108 /* We are at the first instruction we care about. */
5109 /* Pedal to the metal... */
5111 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_0
, 0);
5115 * Function: notice_thread
5117 * Callback for find_new_threads.
5118 * Calls "add_thread".
5122 procfs_notice_thread (procinfo
*pi
, procinfo
*thread
, void *ptr
)
5124 ptid_t gdb_threadid
= MERGEPID (pi
->pid
, thread
->tid
);
5126 if (!in_thread_list (gdb_threadid
))
5127 add_thread (gdb_threadid
);
5133 * Function: target_find_new_threads
5135 * Query all the threads that the target knows about,
5136 * and give them back to GDB to add to its list.
5140 procfs_find_new_threads (void)
5144 /* Find procinfo for main process */
5145 pi
= find_procinfo_or_die (PIDGET (inferior_ptid
), 0);
5146 proc_update_threads (pi
);
5147 proc_iterate_over_threads (pi
, procfs_notice_thread
, NULL
);
5151 * Function: target_thread_alive
5153 * Return true if the thread is still 'alive'.
5155 * This guy doesn't really seem to be doing his job.
5156 * Got to investigate how to tell when a thread is really gone.
5160 procfs_thread_alive (ptid_t ptid
)
5165 proc
= PIDGET (ptid
);
5166 thread
= TIDGET (ptid
);
5167 /* If I don't know it, it ain't alive! */
5168 if ((pi
= find_procinfo (proc
, thread
)) == NULL
)
5171 /* If I can't get its status, it ain't alive!
5172 What's more, I need to forget about it! */
5173 if (!proc_get_status (pi
))
5175 destroy_procinfo (pi
);
5178 /* I couldn't have got its status if it weren't alive, so it's alive. */
5182 /* Convert PTID to a string. Returns the string in a static buffer. */
5185 procfs_pid_to_str (ptid_t ptid
)
5187 static char buf
[80];
5189 if (TIDGET (ptid
) == 0)
5190 sprintf (buf
, "process %d", PIDGET (ptid
));
5192 sprintf (buf
, "LWP %ld", TIDGET (ptid
));
5198 * Function: procfs_set_watchpoint
5199 * Insert a watchpoint
5203 procfs_set_watchpoint (ptid_t ptid
, CORE_ADDR addr
, int len
, int rwflag
,
5211 pi
= find_procinfo_or_die (PIDGET (ptid
) == -1 ?
5212 PIDGET (inferior_ptid
) : PIDGET (ptid
), 0);
5214 /* Translate from GDB's flags to /proc's */
5215 if (len
> 0) /* len == 0 means delete watchpoint */
5217 switch (rwflag
) { /* FIXME: need an enum! */
5218 case hw_write
: /* default watchpoint (write) */
5219 pflags
= WRITE_WATCHFLAG
;
5221 case hw_read
: /* read watchpoint */
5222 pflags
= READ_WATCHFLAG
;
5224 case hw_access
: /* access watchpoint */
5225 pflags
= READ_WATCHFLAG
| WRITE_WATCHFLAG
;
5227 case hw_execute
: /* execution HW breakpoint */
5228 pflags
= EXEC_WATCHFLAG
;
5230 default: /* Something weird. Return error. */
5233 if (after
) /* Stop after r/w access is completed. */
5234 pflags
|= AFTER_WATCHFLAG
;
5237 if (!proc_set_watchpoint (pi
, addr
, len
, pflags
))
5239 if (errno
== E2BIG
) /* Typical error for no resources */
5240 return -1; /* fail */
5241 /* GDB may try to remove the same watchpoint twice.
5242 If a remove request returns no match, don't error. */
5243 if (errno
== ESRCH
&& len
== 0)
5244 return 0; /* ignore */
5245 proc_error (pi
, "set_watchpoint", __LINE__
);
5248 #endif /* UNIXWARE */
5252 /* Return non-zero if we can set a hardware watchpoint of type TYPE. TYPE
5253 is one of bp_hardware_watchpoint, bp_read_watchpoint, bp_write_watchpoint,
5254 or bp_hardware_watchpoint. CNT is the number of watchpoints used so
5257 Note: procfs_can_use_hw_breakpoint() is not yet used by all
5258 procfs.c targets due to the fact that some of them still define
5259 TARGET_CAN_USE_HARDWARE_WATCHPOINT. */
5262 procfs_can_use_hw_breakpoint (int type
, int cnt
, int othertype
)
5264 #ifndef TARGET_HAS_HARDWARE_WATCHPOINTS
5267 /* Due to the way that proc_set_watchpoint() is implemented, host
5268 and target pointers must be of the same size. If they are not,
5269 we can't use hardware watchpoints. This limitation is due to the
5270 fact that proc_set_watchpoint() calls
5271 procfs_address_to_host_pointer(); a close inspection of
5272 procfs_address_to_host_pointer will reveal that an internal error
5273 will be generated when the host and target pointer sizes are
5275 if (sizeof (void *) != TYPE_LENGTH (builtin_type_void_data_ptr
))
5278 /* Other tests here??? */
5285 * Function: stopped_by_watchpoint
5287 * Returns non-zero if process is stopped on a hardware watchpoint fault,
5288 * else returns zero.
5292 procfs_stopped_by_watchpoint (ptid_t ptid
)
5296 pi
= find_procinfo_or_die (PIDGET (ptid
) == -1 ?
5297 PIDGET (inferior_ptid
) : PIDGET (ptid
), 0);
5299 if (!pi
) /* If no process, then not stopped by watchpoint! */
5302 if (proc_flags (pi
) & (PR_STOPPED
| PR_ISTOP
))
5304 if (proc_why (pi
) == PR_FAULTED
)
5307 if (proc_what (pi
) == FLTWATCH
)
5311 if (proc_what (pi
) == FLTKWATCH
)
5319 #ifdef TM_I386SOL2_H
5321 * Function: procfs_find_LDT_entry
5324 * ptid_t ptid; // The GDB-style pid-plus-LWP.
5327 * pointer to the corresponding LDT entry.
5331 procfs_find_LDT_entry (ptid_t ptid
)
5333 gdb_gregset_t
*gregs
;
5337 /* Find procinfo for the lwp. */
5338 if ((pi
= find_procinfo (PIDGET (ptid
), TIDGET (ptid
))) == NULL
)
5340 warning ("procfs_find_LDT_entry: could not find procinfo for %d:%d.",
5341 PIDGET (ptid
), TIDGET (ptid
));
5344 /* get its general registers. */
5345 if ((gregs
= proc_get_gregs (pi
)) == NULL
)
5347 warning ("procfs_find_LDT_entry: could not read gregs for %d:%d.",
5348 PIDGET (ptid
), TIDGET (ptid
));
5351 /* Now extract the GS register's lower 16 bits. */
5352 key
= (*gregs
)[GS
] & 0xffff;
5354 /* Find the matching entry and return it. */
5355 return proc_get_LDT_entry (pi
, key
);
5357 #endif /* TM_I386SOL2_H */
5360 * Memory Mappings Functions:
5364 * Function: iterate_over_mappings
5366 * Call a callback function once for each mapping, passing it the mapping,
5367 * an optional secondary callback function, and some optional opaque data.
5368 * Quit and return the first non-zero value returned from the callback.
5371 * pi -- procinfo struct for the process to be mapped.
5372 * func -- callback function to be called by this iterator.
5373 * data -- optional opaque data to be passed to the callback function.
5374 * child_func -- optional secondary function pointer to be passed
5375 * to the child function.
5377 * Return: First non-zero return value from the callback function,
5382 iterate_over_mappings (procinfo
*pi
, int (*child_func
) (), void *data
,
5383 int (*func
) (struct prmap
*map
,
5384 int (*child_func
) (),
5387 char pathname
[MAX_PROC_NAME_SIZE
];
5388 struct prmap
*prmaps
;
5389 struct prmap
*prmap
;
5397 /* Get the number of mappings, allocate space,
5398 and read the mappings into prmaps. */
5401 sprintf (pathname
, "/proc/%d/map", pi
->pid
);
5402 if ((map_fd
= open (pathname
, O_RDONLY
)) < 0)
5403 proc_error (pi
, "iterate_over_mappings (open)", __LINE__
);
5405 /* Make sure it gets closed again. */
5406 make_cleanup_close (map_fd
);
5408 /* Use stat to determine the file size, and compute
5409 the number of prmap_t objects it contains. */
5410 if (fstat (map_fd
, &sbuf
) != 0)
5411 proc_error (pi
, "iterate_over_mappings (fstat)", __LINE__
);
5413 nmap
= sbuf
.st_size
/ sizeof (prmap_t
);
5414 prmaps
= (struct prmap
*) alloca ((nmap
+ 1) * sizeof (*prmaps
));
5415 if (read (map_fd
, (char *) prmaps
, nmap
* sizeof (*prmaps
))
5416 != (nmap
* sizeof (*prmaps
)))
5417 proc_error (pi
, "iterate_over_mappings (read)", __LINE__
);
5419 /* Use ioctl command PIOCNMAP to get number of mappings. */
5420 if (ioctl (pi
->ctl_fd
, PIOCNMAP
, &nmap
) != 0)
5421 proc_error (pi
, "iterate_over_mappings (PIOCNMAP)", __LINE__
);
5423 prmaps
= (struct prmap
*) alloca ((nmap
+ 1) * sizeof (*prmaps
));
5424 if (ioctl (pi
->ctl_fd
, PIOCMAP
, prmaps
) != 0)
5425 proc_error (pi
, "iterate_over_mappings (PIOCMAP)", __LINE__
);
5428 for (prmap
= prmaps
; nmap
> 0; prmap
++, nmap
--)
5429 if ((funcstat
= (*func
) (prmap
, child_func
, data
)) != 0)
5436 * Function: solib_mappings_callback
5438 * Calls the supplied callback function once for each mapped address
5439 * space in the process. The callback function receives an open
5440 * file descriptor for the file corresponding to that mapped
5441 * address space (if there is one), and the base address of the
5442 * mapped space. Quit when the callback function returns a
5443 * nonzero value, or at teh end of the mappings.
5445 * Returns: the first non-zero return value of the callback function,
5449 int solib_mappings_callback (struct prmap
*map
,
5450 int (*func
) (int, CORE_ADDR
),
5453 procinfo
*pi
= data
;
5457 char name
[MAX_PROC_NAME_SIZE
+ sizeof (map
->pr_mapname
)];
5459 if (map
->pr_vaddr
== 0 && map
->pr_size
== 0)
5460 return -1; /* sanity */
5462 if (map
->pr_mapname
[0] == 0)
5464 fd
= -1; /* no map file */
5468 sprintf (name
, "/proc/%d/object/%s", pi
->pid
, map
->pr_mapname
);
5469 /* Note: caller's responsibility to close this fd! */
5470 fd
= open_with_retry (name
, O_RDONLY
);
5471 /* Note: we don't test the above call for failure;
5472 we just pass the FD on as given. Sometimes there is
5473 no file, so the open may return failure, but that's
5477 fd
= ioctl (pi
->ctl_fd
, PIOCOPENM
, &map
->pr_vaddr
);
5478 /* Note: we don't test the above call for failure;
5479 we just pass the FD on as given. Sometimes there is
5480 no file, so the ioctl may return failure, but that's
5483 return (*func
) (fd
, (CORE_ADDR
) map
->pr_vaddr
);
5487 * Function: proc_iterate_over_mappings
5489 * Uses the unified "iterate_over_mappings" function
5490 * to implement the exported interface to solib-svr4.c.
5492 * Given a pointer to a function, call that function once for every
5493 * mapped address space in the process. The callback function
5494 * receives an open file descriptor for the file corresponding to
5495 * that mapped address space (if there is one), and the base address
5496 * of the mapped space. Quit when the callback function returns a
5497 * nonzero value, or at teh end of the mappings.
5499 * Returns: the first non-zero return value of the callback function,
5504 proc_iterate_over_mappings (int (*func
) (int, CORE_ADDR
))
5506 procinfo
*pi
= find_procinfo_or_die (PIDGET (inferior_ptid
), 0);
5508 return iterate_over_mappings (pi
, func
, pi
, solib_mappings_callback
);
5512 * Function: find_memory_regions_callback
5514 * Implements the to_find_memory_regions method.
5515 * Calls an external function for each memory region.
5516 * External function will have the signiture:
5518 * int callback (CORE_ADDR vaddr,
5519 * unsigned long size,
5520 * int read, int write, int execute,
5523 * Returns the integer value returned by the callback.
5527 find_memory_regions_callback (struct prmap
*map
,
5528 int (*func
) (CORE_ADDR
,
5534 return (*func
) ((CORE_ADDR
) map
->pr_vaddr
,
5536 (map
->pr_mflags
& MA_READ
) != 0,
5537 (map
->pr_mflags
& MA_WRITE
) != 0,
5538 (map
->pr_mflags
& MA_EXEC
) != 0,
5543 * Function: proc_find_memory_regions
5545 * External interface. Calls a callback function once for each
5546 * mapped memory region in the child process, passing as arguments
5547 * CORE_ADDR virtual_address,
5548 * unsigned long size,
5549 * int read, TRUE if region is readable by the child
5550 * int write, TRUE if region is writable by the child
5551 * int execute TRUE if region is executable by the child.
5553 * Stops iterating and returns the first non-zero value
5554 * returned by the callback.
5558 proc_find_memory_regions (int (*func
) (CORE_ADDR
,
5564 procinfo
*pi
= find_procinfo_or_die (PIDGET (inferior_ptid
), 0);
5566 return iterate_over_mappings (pi
, func
, data
,
5567 find_memory_regions_callback
);
5570 /* Remove the breakpoint that we inserted in __dbx_link().
5571 Does nothing if the breakpoint hasn't been inserted or has already
5575 remove_dbx_link_breakpoint (void)
5577 if (dbx_link_bpt_addr
== 0)
5580 if (memory_remove_breakpoint (dbx_link_bpt_addr
,
5581 dbx_link_shadow_contents
) != 0)
5582 warning ("Unable to remove __dbx_link breakpoint.");
5584 dbx_link_bpt_addr
= 0;
5587 /* Return the address of the __dbx_link() function in the file
5588 refernced by ABFD by scanning its symbol table. Return 0 if
5589 the symbol was not found. */
5592 dbx_link_addr (bfd
*abfd
)
5594 long storage_needed
;
5595 asymbol
**symbol_table
;
5596 long number_of_symbols
;
5599 storage_needed
= bfd_get_symtab_upper_bound (abfd
);
5600 if (storage_needed
<= 0)
5603 symbol_table
= (asymbol
**) xmalloc (storage_needed
);
5604 make_cleanup (xfree
, symbol_table
);
5606 number_of_symbols
= bfd_canonicalize_symtab (abfd
, symbol_table
);
5608 for (i
= 0; i
< number_of_symbols
; i
++)
5610 asymbol
*sym
= symbol_table
[i
];
5612 if ((sym
->flags
& BSF_GLOBAL
)
5613 && sym
->name
!= NULL
&& strcmp (sym
->name
, "__dbx_link") == 0)
5614 return (sym
->value
+ sym
->section
->vma
);
5617 /* Symbol not found, return NULL. */
5621 /* Search the symbol table of the file referenced by FD for a symbol
5622 named __dbx_link(). If found, then insert a breakpoint at this location,
5623 and return nonzero. Return zero otherwise. */
5626 insert_dbx_link_bpt_in_file (int fd
, CORE_ADDR ignored
)
5629 long storage_needed
;
5632 abfd
= bfd_fdopenr ("unamed", 0, fd
);
5635 warning ("Failed to create a bfd: %s.\n", bfd_errmsg (bfd_get_error ()));
5639 if (!bfd_check_format (abfd
, bfd_object
))
5641 /* Not the correct format, so we can not possibly find the dbx_link
5647 sym_addr
= dbx_link_addr (abfd
);
5650 /* Insert the breakpoint. */
5651 dbx_link_bpt_addr
= sym_addr
;
5652 if (target_insert_breakpoint (sym_addr
, dbx_link_shadow_contents
) != 0)
5654 warning ("Failed to insert dbx_link breakpoint.");
5666 /* If the given memory region MAP contains a symbol named __dbx_link,
5667 insert a breakpoint at this location and return nonzero. Return
5671 insert_dbx_link_bpt_in_region (struct prmap
*map
,
5672 int (*child_func
) (),
5675 procinfo
*pi
= (procinfo
*) data
;
5677 /* We know the symbol we're looking for is in a text region, so
5678 only look for it if the region is a text one. */
5679 if (map
->pr_mflags
& MA_EXEC
)
5680 return solib_mappings_callback (map
, insert_dbx_link_bpt_in_file
, pi
);
5685 /* Search all memory regions for a symbol named __dbx_link. If found,
5686 insert a breakpoint at its location, and return nonzero. Return zero
5690 insert_dbx_link_breakpoint (procinfo
*pi
)
5692 return iterate_over_mappings (pi
, NULL
, pi
, insert_dbx_link_bpt_in_region
);
5696 * Function: mappingflags
5698 * Returns an ascii representation of a memory mapping's flags.
5702 mappingflags (long flags
)
5704 static char asciiflags
[8];
5706 strcpy (asciiflags
, "-------");
5707 #if defined (MA_PHYS)
5708 if (flags
& MA_PHYS
)
5709 asciiflags
[0] = 'd';
5711 if (flags
& MA_STACK
)
5712 asciiflags
[1] = 's';
5713 if (flags
& MA_BREAK
)
5714 asciiflags
[2] = 'b';
5715 if (flags
& MA_SHARED
)
5716 asciiflags
[3] = 's';
5717 if (flags
& MA_READ
)
5718 asciiflags
[4] = 'r';
5719 if (flags
& MA_WRITE
)
5720 asciiflags
[5] = 'w';
5721 if (flags
& MA_EXEC
)
5722 asciiflags
[6] = 'x';
5723 return (asciiflags
);
5727 * Function: info_mappings_callback
5729 * Callback function, does the actual work for 'info proc mappings'.
5733 info_mappings_callback (struct prmap
*map
, int (*ignore
) (), void *unused
)
5735 char *data_fmt_string
;
5737 if (TARGET_ADDR_BIT
== 32)
5738 data_fmt_string
= "\t%#10lx %#10lx %#10x %#10x %7s\n";
5740 data_fmt_string
= " %#18lx %#18lx %#10x %#10x %7s\n";
5742 printf_filtered (data_fmt_string
,
5743 (unsigned long) map
->pr_vaddr
,
5744 (unsigned long) map
->pr_vaddr
+ map
->pr_size
- 1,
5746 #ifdef PCAGENT /* Horrible hack: only defined on Solaris 2.6+ */
5747 (unsigned int) map
->pr_offset
,
5751 mappingflags (map
->pr_mflags
));
5757 * Function: info_proc_mappings
5759 * Implement the "info proc mappings" subcommand.
5763 info_proc_mappings (procinfo
*pi
, int summary
)
5765 char *header_fmt_string
;
5767 if (TARGET_PTR_BIT
== 32)
5768 header_fmt_string
= "\t%10s %10s %10s %10s %7s\n";
5770 header_fmt_string
= " %18s %18s %10s %10s %7s\n";
5773 return; /* No output for summary mode. */
5775 printf_filtered ("Mapped address spaces:\n\n");
5776 printf_filtered (header_fmt_string
,
5783 iterate_over_mappings (pi
, NULL
, NULL
, info_mappings_callback
);
5784 printf_filtered ("\n");
5788 * Function: info_proc_cmd
5790 * Implement the "info proc" command.
5794 info_proc_cmd (char *args
, int from_tty
)
5796 struct cleanup
*old_chain
;
5797 procinfo
*process
= NULL
;
5798 procinfo
*thread
= NULL
;
5805 old_chain
= make_cleanup (null_cleanup
, 0);
5808 if ((argv
= buildargv (args
)) == NULL
)
5811 make_cleanup_freeargv (argv
);
5813 while (argv
!= NULL
&& *argv
!= NULL
)
5815 if (isdigit (argv
[0][0]))
5817 pid
= strtoul (argv
[0], &tmp
, 10);
5819 tid
= strtoul (++tmp
, NULL
, 10);
5821 else if (argv
[0][0] == '/')
5823 tid
= strtoul (argv
[0] + 1, NULL
, 10);
5825 else if (strncmp (argv
[0], "mappings", strlen (argv
[0])) == 0)
5836 pid
= PIDGET (inferior_ptid
);
5838 error ("No current process: you must name one.");
5841 /* Have pid, will travel.
5842 First see if it's a process we're already debugging. */
5843 process
= find_procinfo (pid
, 0);
5844 if (process
== NULL
)
5846 /* No. So open a procinfo for it, but
5847 remember to close it again when finished. */
5848 process
= create_procinfo (pid
, 0);
5849 make_cleanup (do_destroy_procinfo_cleanup
, process
);
5850 if (!open_procinfo_files (process
, FD_CTL
))
5851 proc_error (process
, "info proc, open_procinfo_files", __LINE__
);
5855 thread
= create_procinfo (pid
, tid
);
5859 printf_filtered ("process %d flags:\n", process
->pid
);
5860 proc_prettyprint_flags (proc_flags (process
), 1);
5861 if (proc_flags (process
) & (PR_STOPPED
| PR_ISTOP
))
5862 proc_prettyprint_why (proc_why (process
), proc_what (process
), 1);
5863 if (proc_get_nthreads (process
) > 1)
5864 printf_filtered ("Process has %d threads.\n",
5865 proc_get_nthreads (process
));
5869 printf_filtered ("thread %d flags:\n", thread
->tid
);
5870 proc_prettyprint_flags (proc_flags (thread
), 1);
5871 if (proc_flags (thread
) & (PR_STOPPED
| PR_ISTOP
))
5872 proc_prettyprint_why (proc_why (thread
), proc_what (thread
), 1);
5877 info_proc_mappings (process
, 0);
5880 do_cleanups (old_chain
);
5883 /* Modify the status of the system call identified by SYSCALLNUM in
5884 the set of syscalls that are currently traced/debugged.
5886 If ENTRY_OR_EXIT is set to PR_SYSENTRY, then the entry syscalls set
5887 will be updated. Otherwise, the exit syscalls set will be updated.
5889 If MODE is FLAG_SET, then traces will be enabled. Otherwise, they
5890 will be disabled. */
5893 proc_trace_syscalls_1 (procinfo
*pi
, int syscallnum
, int entry_or_exit
,
5894 int mode
, int from_tty
)
5898 if (entry_or_exit
== PR_SYSENTRY
)
5899 sysset
= proc_get_traced_sysentry (pi
, NULL
);
5901 sysset
= proc_get_traced_sysexit (pi
, NULL
);
5904 proc_error (pi
, "proc-trace, get_traced_sysset", __LINE__
);
5906 if (mode
== FLAG_SET
)
5907 gdb_praddsysset (sysset
, syscallnum
);
5909 gdb_prdelsysset (sysset
, syscallnum
);
5911 if (entry_or_exit
== PR_SYSENTRY
)
5913 if (!proc_set_traced_sysentry (pi
, sysset
))
5914 proc_error (pi
, "proc-trace, set_traced_sysentry", __LINE__
);
5918 if (!proc_set_traced_sysexit (pi
, sysset
))
5919 proc_error (pi
, "proc-trace, set_traced_sysexit", __LINE__
);
5924 proc_trace_syscalls (char *args
, int from_tty
, int entry_or_exit
, int mode
)
5928 if (PIDGET (inferior_ptid
) <= 0)
5929 error ("you must be debugging a process to use this command.");
5931 if (args
== NULL
|| args
[0] == 0)
5932 error_no_arg ("system call to trace");
5934 pi
= find_procinfo_or_die (PIDGET (inferior_ptid
), 0);
5935 if (isdigit (args
[0]))
5937 const int syscallnum
= atoi (args
);
5939 proc_trace_syscalls_1 (pi
, syscallnum
, entry_or_exit
, mode
, from_tty
);
5944 proc_trace_sysentry_cmd (char *args
, int from_tty
)
5946 proc_trace_syscalls (args
, from_tty
, PR_SYSENTRY
, FLAG_SET
);
5950 proc_trace_sysexit_cmd (char *args
, int from_tty
)
5952 proc_trace_syscalls (args
, from_tty
, PR_SYSEXIT
, FLAG_SET
);
5956 proc_untrace_sysentry_cmd (char *args
, int from_tty
)
5958 proc_trace_syscalls (args
, from_tty
, PR_SYSENTRY
, FLAG_RESET
);
5962 proc_untrace_sysexit_cmd (char *args
, int from_tty
)
5964 proc_trace_syscalls (args
, from_tty
, PR_SYSEXIT
, FLAG_RESET
);
5969 _initialize_procfs (void)
5972 add_target (&procfs_ops
);
5973 add_info ("proc", info_proc_cmd
,
5974 "Show /proc process information about any running process.\n\
5975 Specify process id, or use the program being debugged by default.\n\
5976 Specify keyword 'mappings' for detailed info on memory mappings.");
5977 add_com ("proc-trace-entry", no_class
, proc_trace_sysentry_cmd
,
5978 "Give a trace of entries into the syscall.");
5979 add_com ("proc-trace-exit", no_class
, proc_trace_sysexit_cmd
,
5980 "Give a trace of exits from the syscall.");
5981 add_com ("proc-untrace-entry", no_class
, proc_untrace_sysentry_cmd
,
5982 "Cancel a trace of entries into the syscall.");
5983 add_com ("proc-untrace-exit", no_class
, proc_untrace_sysexit_cmd
,
5984 "Cancel a trace of exits from the syscall.");
5987 /* =================== END, GDB "MODULE" =================== */
5991 /* miscellaneous stubs: */
5992 /* The following satisfy a few random symbols mostly created by */
5993 /* the solaris threads implementation, which I will chase down */
5997 * Return a pid for which we guarantee
5998 * we will be able to find a 'live' procinfo.
6002 procfs_first_available (void)
6004 return pid_to_ptid (procinfo_list
? procinfo_list
->pid
: -1);
6007 /* =================== GCORE .NOTE "MODULE" =================== */
6008 #if defined (UNIXWARE) || defined (PIOCOPENLWP) || defined (PCAGENT)
6009 /* gcore only implemented on solaris and unixware (so far) */
6012 procfs_do_thread_registers (bfd
*obfd
, ptid_t ptid
,
6013 char *note_data
, int *note_size
)
6015 gdb_gregset_t gregs
;
6016 gdb_fpregset_t fpregs
;
6017 unsigned long merged_pid
;
6019 merged_pid
= TIDGET (ptid
) << 16 | PIDGET (ptid
);
6021 fill_gregset (&gregs
, -1);
6022 #if defined (UNIXWARE)
6023 note_data
= (char *) elfcore_write_lwpstatus (obfd
,
6030 note_data
= (char *) elfcore_write_prstatus (obfd
,
6037 fill_fpregset (&fpregs
, -1);
6038 note_data
= (char *) elfcore_write_prfpreg (obfd
,
6046 struct procfs_corefile_thread_data
{
6053 procfs_corefile_thread_callback (procinfo
*pi
, procinfo
*thread
, void *data
)
6055 struct procfs_corefile_thread_data
*args
= data
;
6057 if (pi
!= NULL
&& thread
->tid
!= 0)
6059 ptid_t saved_ptid
= inferior_ptid
;
6060 inferior_ptid
= MERGEPID (pi
->pid
, thread
->tid
);
6061 args
->note_data
= procfs_do_thread_registers (args
->obfd
, inferior_ptid
,
6064 inferior_ptid
= saved_ptid
;
6070 procfs_make_note_section (bfd
*obfd
, int *note_size
)
6072 struct cleanup
*old_chain
;
6073 gdb_gregset_t gregs
;
6074 gdb_fpregset_t fpregs
;
6075 char fname
[16] = {'\0'};
6076 char psargs
[80] = {'\0'};
6077 procinfo
*pi
= find_procinfo_or_die (PIDGET (inferior_ptid
), 0);
6078 char *note_data
= NULL
;
6080 struct procfs_corefile_thread_data thread_args
;
6084 if (get_exec_file (0))
6086 strncpy (fname
, strrchr (get_exec_file (0), '/') + 1, sizeof (fname
));
6087 strncpy (psargs
, get_exec_file (0),
6090 inf_args
= get_inferior_args ();
6091 if (inf_args
&& *inf_args
&&
6092 strlen (inf_args
) < ((int) sizeof (psargs
) - (int) strlen (psargs
)))
6094 strncat (psargs
, " ",
6095 sizeof (psargs
) - strlen (psargs
));
6096 strncat (psargs
, inf_args
,
6097 sizeof (psargs
) - strlen (psargs
));
6101 note_data
= (char *) elfcore_write_prpsinfo (obfd
,
6108 fill_gregset (&gregs
, -1);
6109 note_data
= elfcore_write_pstatus (obfd
, note_data
, note_size
,
6110 PIDGET (inferior_ptid
),
6111 stop_signal
, &gregs
);
6114 thread_args
.obfd
= obfd
;
6115 thread_args
.note_data
= note_data
;
6116 thread_args
.note_size
= note_size
;
6117 proc_iterate_over_threads (pi
, procfs_corefile_thread_callback
, &thread_args
);
6119 if (thread_args
.note_data
== note_data
)
6121 /* iterate_over_threads didn't come up with any threads;
6122 just use inferior_ptid. */
6123 note_data
= procfs_do_thread_registers (obfd
, inferior_ptid
,
6124 note_data
, note_size
);
6128 note_data
= thread_args
.note_data
;
6131 auxv_len
= target_auxv_read (¤t_target
, &auxv
);
6134 note_data
= elfcore_write_note (obfd
, note_data
, note_size
,
6135 "CORE", NT_AUXV
, auxv
, auxv_len
);
6139 make_cleanup (xfree
, note_data
);
6142 #else /* !(Solaris or Unixware) */
6144 procfs_make_note_section (bfd
*obfd
, int *note_size
)
6146 error ("gcore not implemented for this host.");
6147 return NULL
; /* lint */
6149 #endif /* Solaris or Unixware */
6150 /* =================== END GCORE .NOTE "MODULE" =================== */