Re: [RFA 3/7] Use ui_out_emit_tuple in more places

Simon Marchi
2017-09-09T18:32:03Z

On 2017-09-09 17:35, Tom Tromey wrote:
> diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
> index c485544..ca66a77 100644
> --- a/gdb/mi/mi-main.c
> +++ b/gdb/mi/mi-main.c
> @@ -2873,36 +2873,32 @@ mi_cmd_trace_frame_collected (const char
> *command, char **argv, int argc)
>
> for (i = 0; VEC_iterate (mem_range_s, available_memory, i, r);
> i++)
> {
> - struct cleanup *cleanup_child;
> - gdb_byte *data;
> struct gdbarch *gdbarch = target_gdbarch ();
>
> - cleanup_child = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
> + ui_out_emit_tuple tuple_emitter (uiout, NULL);
>
> uiout->field_core_addr ("address", gdbarch, r->start);
> uiout->field_int ("length", r->length);
>
> - data = (gdb_byte *) xmalloc (r->length);
> - make_cleanup (xfree, data);
> + gdb::byte_vector data (r->length);
>
> if (memory_contents)
> {
> - if (target_read_memory (r->start, data, r->length) == 0)
> + if (target_read_memory (r->start, data.data (), r->length) == 0)
> {
> int m;
> - char *data_str, *p;
> + char *p;
>
> - data_str = (char *) xmalloc (r->length * 2 + 1);
> - make_cleanup (xfree, data_str);
> + gdb::unique_xmalloc_ptr<char> data_str
> + ((char *) xmalloc (r->length * 2 + 1));
>
> - for (m = 0, p = data_str; m < r->length; ++m, p += 2)
> + for (m = 0, p = data_str.get (); m < r->length; ++m, p += 2)
> sprintf (p, "%02x", data[m]);
> - uiout->field_string ("contents", data_str);
> + uiout->field_string ("contents", data_str.get ());

Can this conversion to hex be replaced with a call to bin2hex (the
version that returns an std::string) ?

Otherwise, LGTM.

Simon