* ppcnbsd-nat.c: Include <machine/frame.h>, <machine/pcb.h>,
[deliverable/binutils-gdb.git] / gdb / fbsd-proc.c
index 07272b19863b41203ec1385c19dfea58c94082db..f021d275b9aa16d1de6f8b9a9aa9feb7c32d88d3 100644 (file)
 #include "defs.h"
 #include "gdbcore.h"
 #include "inferior.h"
-#include "gdb_string.h"
+#include "regcache.h"
+#include "regset.h"
 
+#include "gdb_assert.h"
+#include "gdb_string.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;
 
-  xasprintf (&path, "/proc/%d/file", pid);
+  path = xstrprintf ("/proc/%d/file", pid);
   buf = xcalloc (MAXPATHLEN, sizeof (char));
   make_cleanup (xfree, path);
   make_cleanup (xfree, buf);
@@ -52,20 +53,19 @@ static int
 read_mapping (FILE *mapfile, unsigned long *start, unsigned long *end,
              char *protection)
 {
+  /* FreeBSD 5.1-RELEASE uses a 256-byte buffer.  */
+  char buf[256];
   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);
+  int ret = EOF;
+
+  /* As of FreeBSD 5.0-RELEASE, the layout is described in
+     /usr/src/sys/fs/procfs/procfs_map.c.  Somewhere in 5.1-CURRENT a
+     new column was added to the procfs map.  Therefore we can't use
+     fscanf since we need to support older releases too.  */
+  if (fgets (buf, sizeof buf, mapfile) != NULL)
+    ret = sscanf (buf, "%lx %lx %d %d %lx %s", start, end,
+                 &resident, &privateresident, &obj, protection);
 
   return (ret != 0 && ret != EOF);
 }
@@ -82,7 +82,7 @@ fbsd_find_memory_regions (int (*func) (CORE_ADDR, unsigned long,
   char protection[4];
   int read, write, exec;
 
-  xasprintf (&mapfilename, "/proc/%ld/map", (long) pid);
+  mapfilename = xstrprintf ("/proc/%ld/map", (long) pid);
   mapfile = fopen (mapfilename, "r");
   if (mapfile == NULL)
     error ("Couldn't open %s\n", mapfilename);
@@ -121,21 +121,35 @@ fbsd_find_memory_regions (int (*func) (CORE_ADDR, unsigned long,
 static char *
 fbsd_make_corefile_notes (bfd *obfd, int *note_size)
 {
+  struct gdbarch *gdbarch = current_gdbarch;
+  const struct regcache *regcache = current_regcache;
   gregset_t gregs;
   fpregset_t fpregs;
   char *note_data = NULL;
   Elf_Internal_Ehdr *i_ehdrp;
+  const struct regset *regset;
+  size_t size;
 
   /* Put a "FreeBSD" label in the ELF header.  */
   i_ehdrp = elf_elfheader (obfd);
   i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_FREEBSD;
 
-  fill_gregset (&gregs, -1);
+  gdb_assert (gdbarch_regset_from_core_section_p (gdbarch));
+
+  size = sizeof gregs;
+  regset = gdbarch_regset_from_core_section (gdbarch, ".reg", size);
+  gdb_assert (regset && regset->collect_regset);
+  regset->collect_regset (regset, regcache, -1, &gregs, size);
+
   note_data = elfcore_write_prstatus (obfd, note_data, note_size,
                                      ptid_get_pid (inferior_ptid),
                                      stop_signal, &gregs);
 
-  fill_fpregset (&fpregs, -1);
+  size = sizeof fpregs;
+  regset = gdbarch_regset_from_core_section (gdbarch, ".reg2", size);
+  gdb_assert (regset && regset->collect_regset);
+  regset->collect_regset (regset, regcache, -1, &fpregs, size);
+
   note_data = elfcore_write_prfpreg (obfd, note_data, note_size,
                                     &fpregs, sizeof (fpregs));
 
This page took 0.025887 seconds and 4 git commands to generate.