diff options
author | Mark Kettenis <kettenis@gnu.org> | 2002-03-31 17:47:17 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@gnu.org> | 2002-03-31 17:47:17 +0000 |
commit | a90cd31de1fafcf359bfe2d36b67f41b74773515 (patch) | |
tree | 3ce37e20ca5bc4526c004a793438ab6b3423d778 | |
parent | 2d1bfe2ed3c516f905558527a804cc7e751f7aae (diff) | |
download | gdb-a90cd31de1fafcf359bfe2d36b67f41b74773515.zip gdb-a90cd31de1fafcf359bfe2d36b67f41b74773515.tar.gz gdb-a90cd31de1fafcf359bfe2d36b67f41b74773515.tar.bz2 |
* fbsd-proc.c: New file.
* config/i386/nm-fbsd.h (CHILD_PID_TO_EXEC_FILE): Define.
* config/i386/fbsd.mh (NATDEPFILES): Add gcore.o and fbsd-proc.o.
-rw-r--r-- | gdb/ChangeLog | 4 | ||||
-rw-r--r-- | gdb/config/i386/fbsd.mh | 2 | ||||
-rw-r--r-- | gdb/config/i386/nm-fbsd.h | 3 | ||||
-rw-r--r-- | gdb/fbsd-proc.c | 173 |
4 files changed, 181 insertions, 1 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 4c7b844..204a88b 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,9 @@ 2002-03-31 Mark Kettenis <kettenis@gnu.org> + * fbsd-proc.c: New file. + * config/i386/nm-fbsd.h (CHILD_PID_TO_EXEC_FILE): Define. + * config/i386/fbsd.mh (NATDEPFILES): Add gcore.o and fbsd-proc.o. + * lin-lwp.c (child_wait): Check SAVE_ERRNO instead of ERRNO in while statement. diff --git a/gdb/config/i386/fbsd.mh b/gdb/config/i386/fbsd.mh index 364dfa6..4509b9c 100644 --- a/gdb/config/i386/fbsd.mh +++ b/gdb/config/i386/fbsd.mh @@ -4,4 +4,4 @@ XM_FILE= xm-i386.h NAT_FILE= nm-fbsd.h # NOTE: Do not spread NATDEPFILES over several lines - it hurts BSD make. -NATDEPFILES= fork-child.o infptrace.o inftarg.o solib.o solib-svr4.o solib-legacy.o corelow.o core-aout.o core-regset.o i386-nat.o i387-nat.o i386bsd-nat.o i386fbsd-nat.o +NATDEPFILES= fork-child.o infptrace.o inftarg.o solib.o solib-svr4.o solib-legacy.o corelow.o core-aout.o core-regset.o i386-nat.o i387-nat.o i386bsd-nat.o i386fbsd-nat.o gcore.o fbsd-proc.o diff --git a/gdb/config/i386/nm-fbsd.h b/gdb/config/i386/nm-fbsd.h index 939b880..b791903 100644 --- a/gdb/config/i386/nm-fbsd.h +++ b/gdb/config/i386/nm-fbsd.h @@ -56,6 +56,9 @@ extern unsigned long i386bsd_dr_get_status (void); /* Override child_resume in `infptrace.c' to work around a kernel bug. */ #define CHILD_RESUME +/* Override child_pid_to_exec_file in 'inftarg.c'. */ +#define CHILD_PID_TO_EXEC_FILE + /* We can attach and detach. */ #define ATTACH_DETACH diff --git a/gdb/fbsd-proc.c b/gdb/fbsd-proc.c new file mode 100644 index 0000000..91746d6 --- /dev/null +++ b/gdb/fbsd-proc.c @@ -0,0 +1,173 @@ +/* FreeBSD-specific methods for using the /proc file system. + Copyright 2002 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include "defs.h" +#include "gdbcore.h" +#include "inferior.h" + +#include <sys/procfs.h> +#include <sys/types.h> + +#include "elf-bfd.h" + +#include "gregset.h" + +char * +child_pid_to_exec_file (int pid) +{ + char *path; + char *buf; + + asprintf (&path, "/proc/%d/file", pid); + buf = xcalloc (MAXPATHLEN, sizeof (char)); + make_cleanup (xfree, path); + make_cleanup (xfree, buf); + + if (readlink (path, buf, MAXPATHLEN) > 0) + return buf; + + return NULL; +} + +static int +read_mapping (FILE *mapfile, + unsigned long *start, + unsigned long *end, + char *protection) +{ + int resident, privateresident; + unsigned long obj; + int ref_count, shadow_count; + unsigned flags; + char cow[5], access[4]; + char type[8]; + int ret; + + /* The layout is described in /usr/src/miscfs/procfs/procfs_map.c. */ + ret = fscanf (mapfile, "%lx %lx %d %d %lx %s %d %d %x %s %s %s\n", + start, end, + &resident, &privateresident, &obj, + protection, + &ref_count, &shadow_count, &flags, cow, access, type); + + return (ret != 0 && ret != EOF); +} + +static int +fbsd_find_memory_regions (int (*func) (CORE_ADDR, + unsigned long, + int, int, int, + void *), + void *obfd) +{ + pid_t pid = ptid_get_pid (inferior_ptid); + char *mapfilename; + FILE *mapfile; + unsigned long start, end, size; + char protection[4]; + int read, write, exec; + + asprintf (&mapfilename, "/proc/%ld/map", (long) pid); + mapfile = fopen (mapfilename, "r"); + if (mapfile == NULL) + error ("Couldn't open %s\n", mapfilename); + + if (info_verbose) + fprintf_filtered (gdb_stdout, + "Reading memory regions from %s\n", mapfilename); + + /* Now iterate until end-of-file. */ + while (read_mapping (mapfile, &start, &end, &protection[0])) + { + size = end - start; + + read = (strchr (protection, 'r') != 0); + write = (strchr (protection, 'w') != 0); + exec = (strchr (protection, 'x') != 0); + + if (info_verbose) + { + fprintf_filtered (gdb_stdout, + "Save segment, %ld bytes at 0x%s (%c%c%c)\n", + size, paddr_nz (start), + read ? 'r' : '-', + write ? 'w' : '-', + exec ? 'x' : '-'); + } + + /* Invoke the callback function to create the corefile segment. */ + func (start, size, read, write, exec, obfd); + } + + fclose (mapfile); + return 0; +} + +static char * +fbsd_make_corefile_notes (bfd *obfd, int *note_size) +{ + gregset_t gregs; + fpregset_t fpregs; + char *note_data = NULL; + + fill_gregset (&gregs, -1); + note_data = (char *) elfcore_write_prstatus (obfd, + note_data, + note_size, + ptid_get_pid (inferior_ptid), + stop_signal, + &gregs); + + fill_fpregset (&fpregs, -1); + note_data = (char *) elfcore_write_prfpreg (obfd, + note_data, + note_size, + &fpregs, + sizeof (fpregs)); + + if (get_exec_file (0)) + { + char *fname = strrchr (get_exec_file (0), '/') + 1; + char *psargs = strdup (fname); + + if (get_inferior_args ()) + psargs = reconcat (psargs, psargs, " ", get_inferior_args (), NULL); + + note_data = (char *) elfcore_write_prpsinfo (obfd, + note_data, + note_size, + fname, + psargs); + } + + make_cleanup (xfree, note_data); + return note_data; +} + + +void +_initialize_fbsd_proc (void) +{ + extern void inftarg_set_find_memory_regions (); + extern void inftarg_set_make_corefile_notes (); + + inftarg_set_find_memory_regions (fbsd_find_memory_regions); + inftarg_set_make_corefile_notes (fbsd_make_corefile_notes); +} |