aboutsummaryrefslogtreecommitdiff
path: root/gdb/cli/cli-dump.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2017-04-28 23:34:32 -0600
committerTom Tromey <tom@tromey.com>2017-08-03 07:59:02 -0600
commit26fcd5d7572ea1bf0cc697158969749420900e0b (patch)
tree4fd942f6a9ce113d4c1733b77c3191c5fe679a47 /gdb/cli/cli-dump.c
parent7c218e6c9c88cb8120adf1a7a530cfdec23aaf81 (diff)
downloadgdb-26fcd5d7572ea1bf0cc697158969749420900e0b.zip
gdb-26fcd5d7572ea1bf0cc697158969749420900e0b.tar.gz
gdb-26fcd5d7572ea1bf0cc697158969749420900e0b.tar.bz2
Use containers to avoid cleanups
This patch introduces the use of various containers -- std::vector, std::string, or gdb::byte_vector -- in several spots in gdb that were using xmalloc and a cleanup. ChangeLog 2017-08-03 Tom Tromey <tom@tromey.com> * valops.c (search_struct_method): Use gdb::byte_vector. * valarith.c (value_concat): Use std::vector. * target.c (memory_xfer_partial): Use gdb::byte_vector. (simple_search_memory): Likewise. * printcmd.c (find_string_backward): Use gdb::byte_vector. * mi/mi-main.c (mi_cmd_data_write_memory): Use gdb::byte_vector. * gcore.c (gcore_copy_callback): Use gdb::byte_vector. * elfread.c (elf_rel_plt_read): Use std::string. * cp-valprint.c (cp_print_value): Use gdb::byte_vector. * cli/cli-dump.c (restore_section_callback): Use gdb::byte_vector.
Diffstat (limited to 'gdb/cli/cli-dump.c')
-rw-r--r--gdb/cli/cli-dump.c11
1 files changed, 3 insertions, 8 deletions
diff --git a/gdb/cli/cli-dump.c b/gdb/cli/cli-dump.c
index 3d8d386..6d55a02 100644
--- a/gdb/cli/cli-dump.c
+++ b/gdb/cli/cli-dump.c
@@ -434,8 +434,6 @@ restore_section_callback (bfd *ibfd, asection *isec, void *args)
bfd_vma sec_end = sec_start + size;
bfd_size_type sec_offset = 0;
bfd_size_type sec_load_count = size;
- struct cleanup *old_chain;
- gdb_byte *buf;
int ret;
/* Ignore non-loadable sections, eg. from elf files. */
@@ -463,9 +461,8 @@ restore_section_callback (bfd *ibfd, asection *isec, void *args)
sec_load_count -= sec_end - data->load_end;
/* Get the data. */
- buf = (gdb_byte *) xmalloc (size);
- old_chain = make_cleanup (xfree, buf);
- if (!bfd_get_section_contents (ibfd, isec, buf, 0, size))
+ gdb::byte_vector buf (size);
+ if (!bfd_get_section_contents (ibfd, isec, buf.data (), 0, size))
error (_("Failed to read bfd file %s: '%s'."), bfd_get_filename (ibfd),
bfd_errmsg (bfd_get_error ()));
@@ -487,11 +484,9 @@ restore_section_callback (bfd *ibfd, asection *isec, void *args)
/* Write the data. */
ret = target_write_memory (sec_start + sec_offset + data->load_offset,
- buf + sec_offset, sec_load_count);
+ &buf[sec_offset], sec_load_count);
if (ret != 0)
warning (_("restore: memory write failed (%s)."), safe_strerror (ret));
- do_cleanups (old_chain);
- return;
}
static void