#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
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;
bfd *obfd = arg;
const char *filename = obfd->filename;
- bfd_close (arg);
+ gdb_bfd_unref (arg);
unlink (filename);
}
fprintf_filtered (gdb_stdout, "Saved corefile %s\n", corefilename);
discard_cleanups (old_chain);
- bfd_close (obfd);
+ gdb_bfd_unref (obfd);
}
static unsigned long
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);