summaryrefslogtreecommitdiff
path: root/gdb/printcmd.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/printcmd.c
parent7c218e6c9c88cb8120adf1a7a530cfdec23aaf81 (diff)
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/printcmd.c')
-rw-r--r--gdb/printcmd.c10
1 files changed, 3 insertions, 7 deletions
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index a8cc052f0a..d5c83f0a72 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -898,8 +898,6 @@ find_string_backward (struct gdbarch *gdbarch,
int *strings_counted)
{
const int chunk_size = 0x20;
- gdb_byte *buffer = NULL;
- struct cleanup *cleanup = NULL;
int read_error = 0;
int chars_read = 0;
int chars_to_read = chunk_size;
@@ -908,14 +906,13 @@ find_string_backward (struct gdbarch *gdbarch,
CORE_ADDR string_start_addr = addr;
gdb_assert (char_size == 1 || char_size == 2 || char_size == 4);
- buffer = (gdb_byte *) xmalloc (chars_to_read * char_size);
- cleanup = make_cleanup (xfree, buffer);
+ gdb::byte_vector buffer (chars_to_read * char_size);
while (count > 0 && read_error == 0)
{
int i;
addr -= chars_to_read * char_size;
- chars_read = read_memory_backward (gdbarch, addr, buffer,
+ chars_read = read_memory_backward (gdbarch, addr, buffer.data (),
chars_to_read * char_size);
chars_read /= char_size;
read_error = (chars_read == chars_to_read) ? 0 : 1;
@@ -924,7 +921,7 @@ find_string_backward (struct gdbarch *gdbarch,
{
int offset = (chars_to_read - i - 1) * char_size;
- if (integer_is_zero (buffer + offset, char_size)
+ if (integer_is_zero (&buffer[offset], char_size)
|| chars_counted == options->print_max)
{
/* Found '\0' or reached print_max. As OFFSET is the offset to
@@ -947,7 +944,6 @@ find_string_backward (struct gdbarch *gdbarch,
string_start_addr -= chars_counted * char_size;
}
- do_cleanups (cleanup);
return string_start_addr;
}