27 #include <sys/types.h>
28 #include <sys/procfs.h>
29 #include <sys/ptrace.h>
30 #include <sys/sysctl.h>
31 #ifdef HAVE_KINFO_GETVMMAP
45 ssize_t len = PATH_MAX;
46 static char buf[PATH_MAX];
49 #ifdef KERN_PROC_PATHNAME
54 mib[2] = KERN_PROC_PATHNAME;
56 if (sysctl (mib, 4, buf, &len, NULL, 0) == 0)
60 xsnprintf (name, PATH_MAX,
"/proc/%d/exe", pid);
61 len = readlink (name, buf, PATH_MAX - 1);
71 #ifdef HAVE_KINFO_GETVMMAP
81 struct kinfo_vmentry *vmentl, *kve;
83 struct cleanup *cleanup;
86 vmentl = kinfo_getvmmap (pid, &nitems);
91 for (i = 0; i < nitems; i++)
96 if (!(kve->kve_protection & KVME_PROT_READ)
97 || kve->kve_flags & KVME_FLAG_NOCOREDUMP)
101 if (kve->kve_type != KVME_TYPE_DEFAULT
102 && kve->kve_type != KVME_TYPE_VNODE
103 && kve->kve_type != KVME_TYPE_SWAP
104 && kve->kve_type != KVME_TYPE_PHYS)
107 size = kve->kve_end - kve->kve_start;
111 "Save segment, %ld bytes at %s (%c%c%c)\n",
114 kve->kve_protection & KVME_PROT_READ ?
'r' :
'-',
115 kve->kve_protection & KVME_PROT_WRITE ?
'w' :
'-',
116 kve->kve_protection & KVME_PROT_EXEC ?
'x' :
'-');
121 func (kve->kve_start, size, kve->kve_protection & KVME_PROT_READ,
122 kve->kve_protection & KVME_PROT_WRITE,
123 kve->kve_protection & KVME_PROT_EXEC, 1, obfd);
135 int resident, privateresident;
143 if (fgets (buf,
sizeof buf, mapfile) != NULL)
144 ret = sscanf (buf,
"%lx %lx %d %d %lx %s", start, end,
145 &resident, &privateresident, &obj, protection);
147 return (ret != 0 && ret != EOF);
161 unsigned long start, end,
size;
163 int read, write, exec;
164 struct cleanup *cleanup;
166 mapfilename =
xstrprintf (
"/proc/%ld/map", (
long) pid);
168 mapfile = fopen (mapfilename,
"r");
170 error (
_(
"Couldn't open %s."), mapfilename);
175 "Reading memory regions from %s\n", mapfilename);
182 read = (strchr (protection,
'r') != 0);
183 write = (strchr (protection,
'w') != 0);
184 exec = (strchr (protection,
'x') != 0);
189 "Save segment, %ld bytes at %s (%c%c%c)\n",
198 func (start, size, read, write, exec, 1, obfd);
246 struct fbsd_fork_child_info
248 struct fbsd_fork_child_info *next;
252 static struct fbsd_fork_child_info *fbsd_pending_children;
258 fbsd_remember_child (pid_t pid)
260 struct fbsd_fork_child_info *info;
262 info =
xcalloc (1,
sizeof *info);
265 info->next = fbsd_pending_children;
266 fbsd_pending_children = info;
273 fbsd_is_child_pending (pid_t pid)
275 struct fbsd_fork_child_info *info, *prev;
278 for (info = fbsd_pending_children; info; prev = info, info = info->next)
280 if (info->child == pid)
283 fbsd_pending_children = info->next;
285 prev->next = info->next;
297 fbsd_fetch_kinfo_proc (pid_t pid,
struct kinfo_proc *kp)
305 mib[2] = KERN_PROC_PID;
307 if (sysctl (mib, 4, kp, &len, NULL, 0) == -1)
325 wptid = super_wait (ops, ptid, ourstatus, target_options);
328 struct ptrace_lwpinfo pl;
333 if (
ptrace (PT_LWPINFO, pid, (caddr_t)&pl,
sizeof pl) == -1)
337 if (pl.pl_flags & PL_FLAG_FORKED)
339 struct kinfo_proc kp;
342 child = pl.pl_child_pid;
347 if (!fbsd_is_child_pending (child))
349 pid = waitpid (child, &status, 0);
355 if (
ptrace (PT_LWPINFO, child, (caddr_t)&pl,
sizeof pl) == -1)
363 fbsd_fetch_kinfo_proc (child, &kp);
364 if (kp.ki_flag & P_PPWAIT)
370 if (pl.pl_flags & PL_FLAG_CHILD)
381 if (pl.pl_flags & PL_FLAG_EXEC)
399 fbsd_follow_fork (
struct target_ops *ops,
int follow_child,
418 fbsd_insert_fork_catchpoint (
struct target_ops *
self,
int pid)
424 fbsd_remove_fork_catchpoint (
struct target_ops *
self,
int pid)
430 fbsd_insert_vfork_catchpoint (
struct target_ops *
self,
int pid)
436 fbsd_remove_vfork_catchpoint (
struct target_ops *
self,
int pid)
449 fbsd_enable_follow_fork (pid_t pid)
458 fbsd_post_startup_inferior (
struct target_ops *
self, ptid_t pid)
466 fbsd_post_attach (
struct target_ops *
self,
int pid)
468 fbsd_enable_follow_fork (pid);
477 fbsd_insert_exec_catchpoint (
struct target_ops *
self,
int pid)
483 fbsd_remove_exec_catchpoint (
struct target_ops *
self,
int pid)
struct gdbarch * target_gdbarch(void)
void add_target(struct target_ops *t)
ssize_t read(int fd, void *buf, size_t count)
static int fbsd_find_memory_regions(struct target_ops *self, find_memory_region_ftype func, void *obfd)
int(* to_find_memory_regions)(struct target_ops *, find_memory_region_ftype func, void *data) TARGET_DEFAULT_FUNC(dummy_find_memory_regions)
void fbsd_nat_add_target(struct target_ops *t)
struct target_waitstatus pending_follow
struct ui_file * gdb_stdout
int(* to_follow_fork)(struct target_ops *, int, int) TARGET_DEFAULT_FUNC(default_follow_fork)
struct thread_info * inferior_thread(void)
ptid_t(* to_wait)(struct target_ops *, ptid_t, struct target_waitstatus *, int TARGET_DEBUG_PRINTER(target_debug_print_options)) TARGET_DEFAULT_NORETURN(noprocess())
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
int(* to_remove_exec_catchpoint)(struct target_ops *, int) TARGET_DEFAULT_RETURN(1)
int(* to_remove_fork_catchpoint)(struct target_ops *, int) TARGET_DEFAULT_RETURN(1)
void fprintf_filtered(struct ui_file *stream, const char *format,...)
int(* to_remove_vfork_catchpoint)(struct target_ops *, int) TARGET_DEFAULT_RETURN(1)
mach_port_t mach_port_t name mach_port_t mach_port_t name error_t int status
ptid_t pid_to_ptid(int pid)
int(* to_insert_exec_catchpoint)(struct target_ops *, int) TARGET_DEFAULT_RETURN(1)
struct cleanup * make_cleanup(make_cleanup_ftype *function, void *arg)
union target_waitstatus::@161 value
int(* to_insert_fork_catchpoint)(struct target_ops *, int) TARGET_DEFAULT_RETURN(1)
char * xstrprintf(const char *format,...)
static char * fbsd_pid_to_exec_file(struct target_ops *self, int pid)
char *(* to_pid_to_exec_file)(struct target_ops *, int pid) TARGET_DEFAULT_RETURN(NULL)
int ptid_get_pid(ptid_t ptid)
struct cleanup * make_cleanup_fclose(FILE *file)
const char const char int
static int fbsd_read_mapping(FILE *mapfile, unsigned long *start, unsigned long *end, char *protection)
void void void void void void void void void perror_with_name(const char *string) ATTRIBUTE_NORETURN
int xsnprintf(char *str, size_t size, const char *format,...)
enum target_waitkind kind
void(* to_post_attach)(struct target_ops *, int) TARGET_DEFAULT_IGNORE()
int(* to_insert_vfork_catchpoint)(struct target_ops *, int) TARGET_DEFAULT_RETURN(1)
int(* find_memory_region_ftype)(CORE_ADDR addr, unsigned long size, int read, int write, int exec, int modified, void *data)
PTR xcalloc(size_t number, size_t size)
void error(const char *fmt,...)
mach_port_t mach_port_t name mach_port_t mach_port_t name error_t int int rusage_t pid_t pid
void do_cleanups(struct cleanup *old_chain)
void(* to_post_startup_inferior)(struct target_ops *, ptid_t) TARGET_DEFAULT_IGNORE()
const ULONGEST const LONGEST len