From 76f9c9cfd42eb8df90ce8455a92109c0f71b41e1 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Fri, 11 Aug 2017 15:02:04 -0600 Subject: [PATCH] Use ui_out_emit_tuple in more places This changes more places to use ui_out_emit_tuple, removing cleanups. ChangeLog 2017-09-09 Tom Tromey * target.c (flash_erase_command): Use ui_out_emit_tuple. * stack.c (print_frame): Use ui_out_emit_tuple. * spu-tdep.c (info_spu_event_command): Use ui_out_emit_tuple. (info_spu_mailbox_command, info_spu_dma_command) (info_spu_proxydma_command): Likewise. * mi/mi-main.c (mi_cmd_trace_frame_collected): Use ui_out_emit_tuple, gdb::byte_vector, bin2hex. * mi/mi-cmd-file.c (mi_cmd_file_list_shared_libraries): Use ui_out_emit_tuple. * breakpoint.c (print_it_watchpoint): Use ui_out_emit_tuple. --- gdb/ChangeLog | 13 ++++ gdb/breakpoint.c | 14 ++-- gdb/mi/mi-cmd-file.c | 5 +- gdb/mi/mi-main.c | 22 ++---- gdb/spu-tdep.c | 24 ++---- gdb/stack.c | 174 +++++++++++++++++++++---------------------- gdb/target.c | 5 +- 7 files changed, 119 insertions(+), 138 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 8ea7ddfd4d7..0d1b6a9681e 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,16 @@ +2017-09-09 Tom Tromey + + * target.c (flash_erase_command): Use ui_out_emit_tuple. + * stack.c (print_frame): Use ui_out_emit_tuple. + * spu-tdep.c (info_spu_event_command): Use ui_out_emit_tuple. + (info_spu_mailbox_command, info_spu_dma_command) + (info_spu_proxydma_command): Likewise. + * mi/mi-main.c (mi_cmd_trace_frame_collected): Use + ui_out_emit_tuple, gdb::byte_vector, bin2hex. + * mi/mi-cmd-file.c (mi_cmd_file_list_shared_libraries): Use + ui_out_emit_tuple. + * breakpoint.c (print_it_watchpoint): Use ui_out_emit_tuple. + 2017-09-09 Tom Tromey * ui-out.h (make_cleanup_ui_out_table_begin_end): Remove. diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 4b329b9bfed..123420c6ae8 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -82,6 +82,7 @@ #include #include "progspace-and-thread.h" #include "common/array-view.h" +#include "common/gdb_optional.h" /* Enums for exception-handling support. */ enum exception_event_kind @@ -10536,7 +10537,6 @@ works_in_software_mode_watchpoint (const struct breakpoint *b) static enum print_stop_action print_it_watchpoint (bpstat bs) { - struct cleanup *old_chain; struct breakpoint *b; enum print_stop_action result; struct watchpoint *w; @@ -10547,13 +10547,12 @@ print_it_watchpoint (bpstat bs) b = bs->breakpoint_at; w = (struct watchpoint *) b; - old_chain = make_cleanup (null_cleanup, NULL); - annotate_watchpoint (b->number); maybe_print_thread_hit_breakpoint (uiout); string_file stb; + gdb::optional tuple_emitter; switch (b->type) { case bp_watchpoint: @@ -10562,7 +10561,7 @@ print_it_watchpoint (bpstat bs) uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); mention (b); - make_cleanup_ui_out_tuple_begin_end (uiout, "value"); + tuple_emitter.emplace (uiout, "value"); uiout->text ("\nOld value = "); watchpoint_value_print (bs->old_val, &stb); uiout->field_stream ("old", stb); @@ -10579,7 +10578,7 @@ print_it_watchpoint (bpstat bs) uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); mention (b); - make_cleanup_ui_out_tuple_begin_end (uiout, "value"); + tuple_emitter.emplace (uiout, "value"); uiout->text ("\nValue = "); watchpoint_value_print (w->val, &stb); uiout->field_stream ("value", stb); @@ -10595,7 +10594,7 @@ print_it_watchpoint (bpstat bs) ("reason", async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); mention (b); - make_cleanup_ui_out_tuple_begin_end (uiout, "value"); + tuple_emitter.emplace (uiout, "value"); uiout->text ("\nOld value = "); watchpoint_value_print (bs->old_val, &stb); uiout->field_stream ("old", stb); @@ -10608,7 +10607,7 @@ print_it_watchpoint (bpstat bs) uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); - make_cleanup_ui_out_tuple_begin_end (uiout, "value"); + tuple_emitter.emplace (uiout, "value"); uiout->text ("\nValue = "); } watchpoint_value_print (w->val, &stb); @@ -10620,7 +10619,6 @@ print_it_watchpoint (bpstat bs) result = PRINT_UNKNOWN; } - do_cleanups (old_chain); return result; } diff --git a/gdb/mi/mi-cmd-file.c b/gdb/mi/mi-cmd-file.c index 2b3522b7b16..a39ef3b35b4 100644 --- a/gdb/mi/mi-cmd-file.c +++ b/gdb/mi/mi-cmd-file.c @@ -153,10 +153,7 @@ mi_cmd_file_list_shared_libraries (const char *command, char **argv, int argc) if (pattern != NULL && !re_exec (so->so_name)) continue; - struct cleanup *tuple_clean_up - = make_cleanup_ui_out_tuple_begin_end (uiout, NULL); + ui_out_emit_tuple tuple_emitter (uiout, NULL); mi_output_solib_attribs (uiout, so); - - do_cleanups (tuple_clean_up); } } diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c index 8e3684abaf2..d4e2e8f2871 100644 --- a/gdb/mi/mi-main.c +++ b/gdb/mi/mi-main.c @@ -61,6 +61,7 @@ #include "run-time-clock.h" #include #include "progspace-and-thread.h" +#include "common/rsp-low.h" enum { @@ -2872,36 +2873,25 @@ 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; - - data_str = (char *) xmalloc (r->length * 2 + 1); - make_cleanup (xfree, data_str); - - for (m = 0, p = data_str; m < r->length; ++m, p += 2) - sprintf (p, "%02x", data[m]); - uiout->field_string ("contents", data_str); + std::string data_str = bin2hex (data.data (), r->length); + uiout->field_string ("contents", data_str.c_str ()); } else uiout->field_skip ("contents"); } - do_cleanups (cleanup_child); } do_cleanups (list_cleanup); diff --git a/gdb/spu-tdep.c b/gdb/spu-tdep.c index 7133ab64bc0..4338d5c4be0 100644 --- a/gdb/spu-tdep.c +++ b/gdb/spu-tdep.c @@ -2064,7 +2064,6 @@ info_spu_event_command (char *args, int from_tty) struct frame_info *frame = get_selected_frame (NULL); ULONGEST event_status = 0; ULONGEST event_mask = 0; - struct cleanup *chain; gdb_byte buf[100]; char annex[32]; LONGEST len; @@ -2091,7 +2090,7 @@ info_spu_event_command (char *args, int from_tty) buf[len] = '\0'; event_mask = strtoulst ((char *) buf, NULL, 16); - chain = make_cleanup_ui_out_tuple_begin_end (current_uiout, "SPUInfoEvent"); + ui_out_emit_tuple tuple_emitter (current_uiout, "SPUInfoEvent"); if (current_uiout->is_mi_like_p ()) { @@ -2105,8 +2104,6 @@ info_spu_event_command (char *args, int from_tty) printf_filtered (_("Event Status 0x%s\n"), phex (event_status, 4)); printf_filtered (_("Event Mask 0x%s\n"), phex (event_mask, 4)); } - - do_cleanups (chain); } static void @@ -2121,7 +2118,6 @@ info_spu_signal_command (char *args, int from_tty) ULONGEST signal2 = 0; ULONGEST signal2_type = 0; int signal2_pending = 0; - struct cleanup *chain; char annex[32]; gdb_byte buf[100]; LONGEST len; @@ -2168,7 +2164,7 @@ info_spu_signal_command (char *args, int from_tty) buf[len] = '\0'; signal2_type = strtoulst ((char *) buf, NULL, 16); - chain = make_cleanup_ui_out_tuple_begin_end (current_uiout, "SPUInfoSignal"); + ui_out_emit_tuple tuple_emitter (current_uiout, "SPUInfoSignal"); if (current_uiout->is_mi_like_p ()) { @@ -2201,8 +2197,6 @@ info_spu_signal_command (char *args, int from_tty) else printf_filtered (_("(Type Overwrite)\n")); } - - do_cleanups (chain); } static void @@ -2239,7 +2233,6 @@ info_spu_mailbox_command (char *args, int from_tty) struct frame_info *frame = get_selected_frame (NULL); struct gdbarch *gdbarch = get_frame_arch (frame); enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); - struct cleanup *chain; char annex[32]; gdb_byte buf[1024]; LONGEST len; @@ -2250,7 +2243,7 @@ info_spu_mailbox_command (char *args, int from_tty) id = get_frame_register_unsigned (frame, SPU_ID_REGNUM); - chain = make_cleanup_ui_out_tuple_begin_end (current_uiout, "SPUInfoMailbox"); + ui_out_emit_tuple tuple_emitter (current_uiout, "SPUInfoMailbox"); xsnprintf (annex, sizeof annex, "%d/mbox_info", id); len = target_read (¤t_target, TARGET_OBJECT_SPU, annex, @@ -2278,8 +2271,6 @@ info_spu_mailbox_command (char *args, int from_tty) info_spu_mailbox_list (buf, len / 4, byte_order, "wbox", "SPU Inbound Mailbox"); - - do_cleanups (chain); } static ULONGEST @@ -2475,7 +2466,6 @@ info_spu_dma_command (char *args, int from_tty) ULONGEST dma_info_status; ULONGEST dma_info_stall_and_notify; ULONGEST dma_info_atomic_command_status; - struct cleanup *chain; char annex[32]; gdb_byte buf[1024]; LONGEST len; @@ -2503,7 +2493,7 @@ info_spu_dma_command (char *args, int from_tty) dma_info_atomic_command_status = extract_unsigned_integer (buf + 32, 8, byte_order); - chain = make_cleanup_ui_out_tuple_begin_end (current_uiout, "SPUInfoDMA"); + ui_out_emit_tuple tuple_emitter (current_uiout, "SPUInfoDMA"); if (current_uiout->is_mi_like_p ()) { @@ -2542,7 +2532,6 @@ info_spu_dma_command (char *args, int from_tty) } info_spu_dma_cmdlist (buf + 40, 16, byte_order); - do_cleanups (chain); } static void @@ -2554,7 +2543,6 @@ info_spu_proxydma_command (char *args, int from_tty) ULONGEST dma_info_type; ULONGEST dma_info_mask; ULONGEST dma_info_status; - struct cleanup *chain; char annex[32]; gdb_byte buf[1024]; LONGEST len; @@ -2575,8 +2563,7 @@ info_spu_proxydma_command (char *args, int from_tty) dma_info_mask = extract_unsigned_integer (buf + 8, 8, byte_order); dma_info_status = extract_unsigned_integer (buf + 16, 8, byte_order); - chain = make_cleanup_ui_out_tuple_begin_end (current_uiout, - "SPUInfoProxyDMA"); + ui_out_emit_tuple tuple_emitter (current_uiout, "SPUInfoProxyDMA"); if (current_uiout->is_mi_like_p ()) { @@ -2607,7 +2594,6 @@ info_spu_proxydma_command (char *args, int from_tty) } info_spu_dma_cmdlist (buf + 24, 8, byte_order); - do_cleanups (chain); } static void diff --git a/gdb/stack.c b/gdb/stack.c index 06d891d1673..a3bc9a3b2e2 100644 --- a/gdb/stack.c +++ b/gdb/stack.c @@ -1139,7 +1139,7 @@ print_frame (struct frame_info *frame, int print_level, struct ui_out *uiout = current_uiout; char *funname = NULL; enum language funlang = language_unknown; - struct cleanup *old_chain, *list_chain; + struct cleanup *old_chain; struct value_print_options opts; struct symbol *func; CORE_ADDR pc = 0; @@ -1154,107 +1154,107 @@ print_frame (struct frame_info *frame, int print_level, annotate_frame_begin (print_level ? frame_relative_level (frame) : 0, gdbarch, pc); - list_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "frame"); + { + ui_out_emit_tuple tuple_emitter (uiout, "frame"); - if (print_level) - { - uiout->text ("#"); - uiout->field_fmt_int (2, ui_left, "level", - frame_relative_level (frame)); - } - get_user_print_options (&opts); - if (opts.addressprint) - if (!sal.symtab - || frame_show_address (frame, sal) - || print_what == LOC_AND_ADDRESS) + if (print_level) { - annotate_frame_address (); - if (pc_p) - uiout->field_core_addr ("addr", gdbarch, pc); - else - uiout->field_string ("addr", ""); - annotate_frame_address_end (); - uiout->text (" in "); + uiout->text ("#"); + uiout->field_fmt_int (2, ui_left, "level", + frame_relative_level (frame)); } - annotate_frame_function_name (); - - string_file stb; - fprintf_symbol_filtered (&stb, funname ? funname : "??", - funlang, DMGL_ANSI); - uiout->field_stream ("func", stb); - uiout->wrap_hint (" "); - annotate_frame_args (); - - uiout->text (" ("); - if (print_args) - { - struct gdbarch *gdbarch = get_frame_arch (frame); - int numargs; - - if (gdbarch_frame_num_args_p (gdbarch)) + get_user_print_options (&opts); + if (opts.addressprint) + if (!sal.symtab + || frame_show_address (frame, sal) + || print_what == LOC_AND_ADDRESS) { - numargs = gdbarch_frame_num_args (gdbarch, frame); - gdb_assert (numargs >= 0); + annotate_frame_address (); + if (pc_p) + uiout->field_core_addr ("addr", gdbarch, pc); + else + uiout->field_string ("addr", ""); + annotate_frame_address_end (); + uiout->text (" in "); } - else - numargs = -1; - + annotate_frame_function_name (); + + string_file stb; + fprintf_symbol_filtered (&stb, funname ? funname : "??", + funlang, DMGL_ANSI); + uiout->field_stream ("func", stb); + uiout->wrap_hint (" "); + annotate_frame_args (); + + uiout->text (" ("); + if (print_args) { - ui_out_emit_list list_emitter (uiout, "args"); - TRY - { - print_frame_args (func, frame, numargs, gdb_stdout); - } - CATCH (e, RETURN_MASK_ERROR) + struct gdbarch *gdbarch = get_frame_arch (frame); + int numargs; + + if (gdbarch_frame_num_args_p (gdbarch)) { + numargs = gdbarch_frame_num_args (gdbarch, frame); + gdb_assert (numargs >= 0); } - END_CATCH + else + numargs = -1; + + { + ui_out_emit_list list_emitter (uiout, "args"); + TRY + { + print_frame_args (func, frame, numargs, gdb_stdout); + } + CATCH (e, RETURN_MASK_ERROR) + { + } + END_CATCH - /* FIXME: ARGS must be a list. If one argument is a string it - will have " that will not be properly escaped. */ + /* FIXME: ARGS must be a list. If one argument is a string it + will have " that will not be properly escaped. */ + } + QUIT; } - QUIT; - } - uiout->text (")"); - if (sal.symtab) - { - const char *filename_display; + uiout->text (")"); + if (sal.symtab) + { + const char *filename_display; - filename_display = symtab_to_filename_for_display (sal.symtab); - annotate_frame_source_begin (); - uiout->wrap_hint (" "); - uiout->text (" at "); - annotate_frame_source_file (); - uiout->field_string ("file", filename_display); - if (uiout->is_mi_like_p ()) - { - const char *fullname = symtab_to_fullname (sal.symtab); + filename_display = symtab_to_filename_for_display (sal.symtab); + annotate_frame_source_begin (); + uiout->wrap_hint (" "); + uiout->text (" at "); + annotate_frame_source_file (); + uiout->field_string ("file", filename_display); + if (uiout->is_mi_like_p ()) + { + const char *fullname = symtab_to_fullname (sal.symtab); - uiout->field_string ("fullname", fullname); - } - annotate_frame_source_file_end (); - uiout->text (":"); - annotate_frame_source_line (); - uiout->field_int ("line", sal.line); - annotate_frame_source_end (); - } + uiout->field_string ("fullname", fullname); + } + annotate_frame_source_file_end (); + uiout->text (":"); + annotate_frame_source_line (); + uiout->field_int ("line", sal.line); + annotate_frame_source_end (); + } - if (pc_p && (funname == NULL || sal.symtab == NULL)) - { - char *lib = solib_name_from_address (get_frame_program_space (frame), - get_frame_pc (frame)); + if (pc_p && (funname == NULL || sal.symtab == NULL)) + { + char *lib = solib_name_from_address (get_frame_program_space (frame), + get_frame_pc (frame)); - if (lib) - { - annotate_frame_where (); - uiout->wrap_hint (" "); - uiout->text (" from "); - uiout->field_string ("from", lib); - } - } + if (lib) + { + annotate_frame_where (); + uiout->wrap_hint (" "); + uiout->text (" from "); + uiout->field_string ("from", lib); + } + } + } - /* do_cleanups will call ui_out_tuple_end() for us. */ - do_cleanups (list_chain); uiout->text ("\n"); do_cleanups (old_chain); } diff --git a/gdb/target.c b/gdb/target.c index 3312b8985fe..2f7f317f40f 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -3926,9 +3926,7 @@ flash_erase_command (char *cmd, int from_tty) found_flash_region = true; target_flash_erase (m->lo, m->hi - m->lo); - struct cleanup *cleanup_tuple - = make_cleanup_ui_out_tuple_begin_end (current_uiout, - "erased-regions"); + ui_out_emit_tuple tuple_emitter (current_uiout, "erased-regions"); current_uiout->message (_("Erasing flash memory region at address ")); current_uiout->field_fmt ("address", "%s", paddress (gdbarch, @@ -3936,7 +3934,6 @@ flash_erase_command (char *cmd, int from_tty) current_uiout->message (", size = "); current_uiout->field_fmt ("size", "%s", hex_string (m->hi - m->lo)); current_uiout->message ("\n"); - do_cleanups (cleanup_tuple); } } -- 2.30.2