*** empty log message ***
[deliverable/binutils-gdb.git] / gdb / gcore.c
index 2a769d3b49cd2c478b2830c939267fb860359f43..f9a138995d47942a142c4eb41670295dc2cc7306 100644 (file)
@@ -33,6 +33,7 @@
 #include <fcntl.h>
 #include "regcache.h"
 #include "regset.h"
+#include "gdb_bfd.h"
 
 /* The largest amount of memory to read from the target at once.  We
    must throttle it to limit the amount of memory used by GDB during
@@ -50,10 +51,11 @@ static int gcore_memory_sections (bfd *);
 bfd *
 create_gcore_bfd (char *filename)
 {
-  bfd *obfd = bfd_openw (filename, default_gcore_target ());
+  bfd *obfd = gdb_bfd_ref (bfd_openw (filename, default_gcore_target ()));
 
   if (!obfd)
     error (_("Failed to open '%s' for output."), filename);
+  gdb_bfd_stash_filename (obfd);
   bfd_set_format (obfd, bfd_core);
   bfd_set_arch_mach (obfd, default_gcore_arch (), default_gcore_mach ());
   return obfd;
@@ -110,7 +112,7 @@ do_bfd_delete_cleanup (void *arg)
   bfd *obfd = arg;
   const char *filename = obfd->filename;
 
-  bfd_close (arg);
+  gdb_bfd_unref (arg);
   unlink (filename);
 }
 
@@ -154,7 +156,7 @@ gcore_command (char *args, int from_tty)
   fprintf_filtered (gdb_stdout, "Saved corefile %s\n", corefilename);
 
   discard_cleanups (old_chain);
-  bfd_close (obfd);
+  gdb_bfd_unref (obfd);
 }
 
 static unsigned long
@@ -561,8 +563,14 @@ gcore_copy_callback (bfd *obfd, asection *osec, void *ignored)
 static int
 gcore_memory_sections (bfd *obfd)
 {
-  if (target_find_memory_regions (gcore_create_callback, obfd) != 0)
-    return 0;                  /* FIXME: error return/msg?  */
+  /* Try gdbarch method first, then fall back to target method.  */
+  if (!gdbarch_find_memory_regions_p (target_gdbarch)
+      || gdbarch_find_memory_regions (target_gdbarch,
+                                     gcore_create_callback, obfd) != 0)
+    {
+      if (target_find_memory_regions (gcore_create_callback, obfd) != 0)
+       return 0;                       /* FIXME: error return/msg?  */
+    }
 
   /* Record phdrs for section-to-segment mapping.  */
   bfd_map_over_sections (obfd, make_output_phdrs, NULL);
This page took 0.025114 seconds and 4 git commands to generate.