aboutsummaryrefslogtreecommitdiff
path: root/gdb/mi
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2017-09-23 11:21:58 -0600
committerTom Tromey <tom@tromey.com>2017-09-29 21:12:19 -0600
commit386c8614d5e65431e977b1b20cc4642f944faca1 (patch)
tree22cdc54c0b8c61dfc6aa1da002e2fa7b2e7bdc40 /gdb/mi
parent789c4b5ea14b0c441e6021f07503e61ccfacb427 (diff)
downloadgdb-386c8614d5e65431e977b1b20cc4642f944faca1.zip
gdb-386c8614d5e65431e977b1b20cc4642f944faca1.tar.gz
gdb-386c8614d5e65431e977b1b20cc4642f944faca1.tar.bz2
Remove free_memory_read_result_vector
This changes read_memory_robust to return a std::vector, allowing the removal of free_memory_read_result_vector and associated cleanups. This patch also changes the functions it touches to be a bit more robust with regards to deallocation; it's perhaps possible that read_memory_robust could have leaked in some situations. This patch is based on my earlier series to remove some MI cleanups. Regression tested by the buildbot. gdb/ChangeLog 2017-09-29 Tom Tromey <tom@tromey.com> * target.c (read_whatever_is_readable): Change type of "result". Update. (free_memory_read_result_vector): Remove. (read_memory_robust): Change return type. Update. * mi/mi-main.c (mi_cmd_data_read_memory_bytes): Update. Use bin2hex, std::string. * target.h (memory_read_result_s): Remove typedef. (free_memory_read_result_vector): Remove. (read_memory_robust): Return std::vector.
Diffstat (limited to 'gdb/mi')
-rw-r--r--gdb/mi/mi-main.c40
1 files changed, 11 insertions, 29 deletions
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 29acf2d..4a61efd 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -1506,12 +1506,8 @@ mi_cmd_data_read_memory_bytes (const char *command, char **argv, int argc)
{
struct gdbarch *gdbarch = get_current_arch ();
struct ui_out *uiout = current_uiout;
- struct cleanup *cleanups;
CORE_ADDR addr;
LONGEST length;
- memory_read_result_s *read_result;
- int ix;
- VEC(memory_read_result_s) *result;
long offset = 0;
int unit_size = gdbarch_addressable_memory_unit_size (gdbarch);
int oind = 0;
@@ -1548,40 +1544,26 @@ mi_cmd_data_read_memory_bytes (const char *command, char **argv, int argc)
addr = parse_and_eval_address (argv[0]) + offset;
length = atol (argv[1]);
- result = read_memory_robust (current_target.beneath, addr, length);
+ std::vector<memory_read_result> result
+ = read_memory_robust (current_target.beneath, addr, length);
- cleanups = make_cleanup (free_memory_read_result_vector, &result);
-
- if (VEC_length (memory_read_result_s, result) == 0)
+ if (result.size () == 0)
error (_("Unable to read memory."));
ui_out_emit_list list_emitter (uiout, "memory");
- for (ix = 0;
- VEC_iterate (memory_read_result_s, result, ix, read_result);
- ++ix)
+ for (const memory_read_result &read_result : result)
{
ui_out_emit_tuple tuple_emitter (uiout, NULL);
- char *data, *p;
- int i;
- int alloc_len;
-
- uiout->field_core_addr ("begin", gdbarch, read_result->begin);
- uiout->field_core_addr ("offset", gdbarch, read_result->begin - addr);
- uiout->field_core_addr ("end", gdbarch, read_result->end);
- alloc_len = (read_result->end - read_result->begin) * 2 * unit_size + 1;
- data = (char *) xmalloc (alloc_len);
+ uiout->field_core_addr ("begin", gdbarch, read_result.begin);
+ uiout->field_core_addr ("offset", gdbarch, read_result.begin - addr);
+ uiout->field_core_addr ("end", gdbarch, read_result.end);
- for (i = 0, p = data;
- i < ((read_result->end - read_result->begin) * unit_size);
- ++i, p += 2)
- {
- sprintf (p, "%02x", read_result->data[i]);
- }
- uiout->field_string ("contents", data);
- xfree (data);
+ std::string data = bin2hex (read_result.data.get (),
+ (read_result.end - read_result.begin)
+ * unit_size);
+ uiout->field_string ("contents", data.c_str ());
}
- do_cleanups (cleanups);
}
/* Implementation of the -data-write_memory command.