diff options
author | Tom Tromey <tom@tromey.com> | 2017-04-28 23:34:32 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2017-08-03 07:59:02 -0600 |
commit | 26fcd5d7572ea1bf0cc697158969749420900e0b (patch) | |
tree | 4fd942f6a9ce113d4c1733b77c3191c5fe679a47 /gdb/gcore.c | |
parent | 7c218e6c9c88cb8120adf1a7a530cfdec23aaf81 (diff) | |
download | gdb-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/gcore.c')
-rw-r--r-- | gdb/gcore.c | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/gdb/gcore.c b/gdb/gcore.c index c32d2ff..50aff2c 100644 --- a/gdb/gcore.c +++ b/gdb/gcore.c @@ -36,6 +36,7 @@ #include "readline/tilde.h" #include <algorithm> #include "common/gdb_unlinker.h" +#include "byte-vector.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 @@ -548,8 +549,6 @@ gcore_copy_callback (bfd *obfd, asection *osec, void *ignored) { bfd_size_type size, total_size = bfd_section_size (obfd, osec); file_ptr offset = 0; - struct cleanup *old_chain = NULL; - gdb_byte *memhunk; /* Read-only sections are marked; we don't have to copy their contents. */ if ((bfd_get_section_flags (obfd, osec) & SEC_LOAD) == 0) @@ -560,8 +559,7 @@ gcore_copy_callback (bfd *obfd, asection *osec, void *ignored) return; size = std::min (total_size, (bfd_size_type) MAX_COPY_BYTES); - memhunk = (gdb_byte *) xmalloc (size); - old_chain = make_cleanup (xfree, memhunk); + gdb::byte_vector memhunk (size); while (total_size > 0) { @@ -569,7 +567,7 @@ gcore_copy_callback (bfd *obfd, asection *osec, void *ignored) size = total_size; if (target_read_memory (bfd_section_vma (obfd, osec) + offset, - memhunk, size) != 0) + memhunk.data (), size) != 0) { warning (_("Memory read failed for corefile " "section, %s bytes at %s."), @@ -577,7 +575,8 @@ gcore_copy_callback (bfd *obfd, asection *osec, void *ignored) paddress (target_gdbarch (), bfd_section_vma (obfd, osec))); break; } - if (!bfd_set_section_contents (obfd, osec, memhunk, offset, size)) + if (!bfd_set_section_contents (obfd, osec, memhunk.data (), + offset, size)) { warning (_("Failed to write corefile contents (%s)."), bfd_errmsg (bfd_get_error ())); @@ -587,8 +586,6 @@ gcore_copy_callback (bfd *obfd, asection *osec, void *ignored) total_size -= size; offset += size; } - - do_cleanups (old_chain); /* Frees MEMHUNK. */ } static int |