aboutsummaryrefslogtreecommitdiff
path: root/gdb/cli/cli-dump.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/cli/cli-dump.c')
-rw-r--r--gdb/cli/cli-dump.c55
1 files changed, 24 insertions, 31 deletions
diff --git a/gdb/cli/cli-dump.c b/gdb/cli/cli-dump.c
index 9097867..9630261 100644
--- a/gdb/cli/cli-dump.c
+++ b/gdb/cli/cli-dump.c
@@ -103,45 +103,40 @@ fopen_with_cleanup (const char *filename, const char *mode)
return file;
}
-static bfd *
-bfd_openr_with_cleanup (const char *filename, const char *target)
+static gdb_bfd_ref_ptr
+bfd_openr_or_error (const char *filename, const char *target)
{
- bfd *ibfd;
-
- ibfd = gdb_bfd_openr (filename, target);
+ gdb_bfd_ref_ptr ibfd (gdb_bfd_openr (filename, target));
if (ibfd == NULL)
- error (_("Failed to open %s: %s."), filename,
+ error (_("Failed to open %s: %s."), filename,
bfd_errmsg (bfd_get_error ()));
- make_cleanup_bfd_unref (ibfd);
- if (!bfd_check_format (ibfd, bfd_object))
+ if (!bfd_check_format (ibfd.get (), bfd_object))
error (_("'%s' is not a recognized file format."), filename);
return ibfd;
}
-static bfd *
-bfd_openw_with_cleanup (const char *filename, const char *target,
- const char *mode)
+static gdb_bfd_ref_ptr
+bfd_openw_or_error (const char *filename, const char *target, const char *mode)
{
- bfd *obfd;
+ gdb_bfd_ref_ptr obfd;
if (*mode == 'w') /* Write: create new file */
{
obfd = gdb_bfd_openw (filename, target);
if (obfd == NULL)
- error (_("Failed to open %s: %s."), filename,
+ error (_("Failed to open %s: %s."), filename,
bfd_errmsg (bfd_get_error ()));
- make_cleanup_bfd_unref (obfd);
- if (!bfd_set_format (obfd, bfd_object))
- error (_("bfd_openw_with_cleanup: %s."), bfd_errmsg (bfd_get_error ()));
+ if (!bfd_set_format (obfd.get (), bfd_object))
+ error (_("bfd_openw_or_error: %s."), bfd_errmsg (bfd_get_error ()));
}
else if (*mode == 'a') /* Append to existing file. */
{ /* FIXME -- doesn't work... */
error (_("bfd_openw does not work with append."));
}
else
- error (_("bfd_openw_with_cleanup: unknown mode %s."), mode);
+ error (_("bfd_openw_or_error: unknown mode %s."), mode);
return obfd;
}
@@ -187,20 +182,19 @@ dump_bfd_file (const char *filename, const char *mode,
const char *target, CORE_ADDR vaddr,
const bfd_byte *buf, ULONGEST len)
{
- bfd *obfd;
asection *osection;
- obfd = bfd_openw_with_cleanup (filename, target, mode);
- osection = bfd_make_section_anyway (obfd, ".newsec");
- bfd_set_section_size (obfd, osection, len);
- bfd_set_section_vma (obfd, osection, vaddr);
- bfd_set_section_alignment (obfd, osection, 0);
- bfd_set_section_flags (obfd, osection, (SEC_HAS_CONTENTS
- | SEC_ALLOC
- | SEC_LOAD));
+ gdb_bfd_ref_ptr obfd (bfd_openw_or_error (filename, target, mode));
+ osection = bfd_make_section_anyway (obfd.get (), ".newsec");
+ bfd_set_section_size (obfd.get (), osection, len);
+ bfd_set_section_vma (obfd.get (), osection, vaddr);
+ bfd_set_section_alignment (obfd.get (), osection, 0);
+ bfd_set_section_flags (obfd.get (), osection, (SEC_HAS_CONTENTS
+ | SEC_ALLOC
+ | SEC_LOAD));
osection->entsize = 0;
- if (!bfd_set_section_contents (obfd, osection, buf, 0, len))
- warning (_("writing dump file '%s' (%s)"), filename,
+ if (!bfd_set_section_contents (obfd.get (), osection, buf, 0, len))
+ warning (_("writing dump file '%s' (%s)"), filename,
bfd_errmsg (bfd_get_error ()));
}
@@ -624,12 +618,11 @@ restore_command (char *args_in, int from_tty)
else
{
/* Open the file for loading. */
- ibfd = bfd_openr_with_cleanup (filename, NULL);
+ gdb_bfd_ref_ptr ibfd (bfd_openr_or_error (filename, NULL));
/* Process the sections. */
- bfd_map_over_sections (ibfd, restore_section_callback, &data);
+ bfd_map_over_sections (ibfd.get (), restore_section_callback, &data);
}
- return;
}
static void