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  <tom@tromey.com>

	* 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.
This commit is contained in:
Tom Tromey 2017-08-11 15:02:04 -06:00
parent dc9fe180a4
commit 76f9c9cfd4
7 changed files with 123 additions and 142 deletions

View file

@ -1,3 +1,16 @@
2017-09-09 Tom Tromey <tom@tromey.com>
* 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 <tom@tromey.com> 2017-09-09 Tom Tromey <tom@tromey.com>
* ui-out.h (make_cleanup_ui_out_table_begin_end): Remove. * ui-out.h (make_cleanup_ui_out_table_begin_end): Remove.

View file

@ -82,6 +82,7 @@
#include <algorithm> #include <algorithm>
#include "progspace-and-thread.h" #include "progspace-and-thread.h"
#include "common/array-view.h" #include "common/array-view.h"
#include "common/gdb_optional.h"
/* Enums for exception-handling support. */ /* Enums for exception-handling support. */
enum exception_event_kind enum exception_event_kind
@ -10536,7 +10537,6 @@ works_in_software_mode_watchpoint (const struct breakpoint *b)
static enum print_stop_action static enum print_stop_action
print_it_watchpoint (bpstat bs) print_it_watchpoint (bpstat bs)
{ {
struct cleanup *old_chain;
struct breakpoint *b; struct breakpoint *b;
enum print_stop_action result; enum print_stop_action result;
struct watchpoint *w; struct watchpoint *w;
@ -10547,13 +10547,12 @@ print_it_watchpoint (bpstat bs)
b = bs->breakpoint_at; b = bs->breakpoint_at;
w = (struct watchpoint *) b; w = (struct watchpoint *) b;
old_chain = make_cleanup (null_cleanup, NULL);
annotate_watchpoint (b->number); annotate_watchpoint (b->number);
maybe_print_thread_hit_breakpoint (uiout); maybe_print_thread_hit_breakpoint (uiout);
string_file stb; string_file stb;
gdb::optional<ui_out_emit_tuple> tuple_emitter;
switch (b->type) switch (b->type)
{ {
case bp_watchpoint: case bp_watchpoint:
@ -10562,7 +10561,7 @@ print_it_watchpoint (bpstat bs)
uiout->field_string uiout->field_string
("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
mention (b); mention (b);
make_cleanup_ui_out_tuple_begin_end (uiout, "value"); tuple_emitter.emplace (uiout, "value");
uiout->text ("\nOld value = "); uiout->text ("\nOld value = ");
watchpoint_value_print (bs->old_val, &stb); watchpoint_value_print (bs->old_val, &stb);
uiout->field_stream ("old", stb); uiout->field_stream ("old", stb);
@ -10579,7 +10578,7 @@ print_it_watchpoint (bpstat bs)
uiout->field_string uiout->field_string
("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
mention (b); mention (b);
make_cleanup_ui_out_tuple_begin_end (uiout, "value"); tuple_emitter.emplace (uiout, "value");
uiout->text ("\nValue = "); uiout->text ("\nValue = ");
watchpoint_value_print (w->val, &stb); watchpoint_value_print (w->val, &stb);
uiout->field_stream ("value", stb); uiout->field_stream ("value", stb);
@ -10595,7 +10594,7 @@ print_it_watchpoint (bpstat bs)
("reason", ("reason",
async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
mention (b); mention (b);
make_cleanup_ui_out_tuple_begin_end (uiout, "value"); tuple_emitter.emplace (uiout, "value");
uiout->text ("\nOld value = "); uiout->text ("\nOld value = ");
watchpoint_value_print (bs->old_val, &stb); watchpoint_value_print (bs->old_val, &stb);
uiout->field_stream ("old", stb); uiout->field_stream ("old", stb);
@ -10608,7 +10607,7 @@ print_it_watchpoint (bpstat bs)
uiout->field_string uiout->field_string
("reason", ("reason",
async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); 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 = "); uiout->text ("\nValue = ");
} }
watchpoint_value_print (w->val, &stb); watchpoint_value_print (w->val, &stb);
@ -10620,7 +10619,6 @@ print_it_watchpoint (bpstat bs)
result = PRINT_UNKNOWN; result = PRINT_UNKNOWN;
} }
do_cleanups (old_chain);
return result; return result;
} }

View file

@ -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)) if (pattern != NULL && !re_exec (so->so_name))
continue; continue;
struct cleanup *tuple_clean_up ui_out_emit_tuple tuple_emitter (uiout, NULL);
= make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
mi_output_solib_attribs (uiout, so); mi_output_solib_attribs (uiout, so);
do_cleanups (tuple_clean_up);
} }
} }

View file

@ -61,6 +61,7 @@
#include "run-time-clock.h" #include "run-time-clock.h"
#include <chrono> #include <chrono>
#include "progspace-and-thread.h" #include "progspace-and-thread.h"
#include "common/rsp-low.h"
enum 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++) 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 (); 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_core_addr ("address", gdbarch, r->start);
uiout->field_int ("length", r->length); uiout->field_int ("length", r->length);
data = (gdb_byte *) xmalloc (r->length); gdb::byte_vector data (r->length);
make_cleanup (xfree, data);
if (memory_contents) 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; std::string data_str = bin2hex (data.data (), r->length);
char *data_str, *p; uiout->field_string ("contents", data_str.c_str ());
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);
} }
else else
uiout->field_skip ("contents"); uiout->field_skip ("contents");
} }
do_cleanups (cleanup_child);
} }
do_cleanups (list_cleanup); do_cleanups (list_cleanup);

View file

@ -2064,7 +2064,6 @@ info_spu_event_command (char *args, int from_tty)
struct frame_info *frame = get_selected_frame (NULL); struct frame_info *frame = get_selected_frame (NULL);
ULONGEST event_status = 0; ULONGEST event_status = 0;
ULONGEST event_mask = 0; ULONGEST event_mask = 0;
struct cleanup *chain;
gdb_byte buf[100]; gdb_byte buf[100];
char annex[32]; char annex[32];
LONGEST len; LONGEST len;
@ -2091,7 +2090,7 @@ info_spu_event_command (char *args, int from_tty)
buf[len] = '\0'; buf[len] = '\0';
event_mask = strtoulst ((char *) buf, NULL, 16); 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 ()) 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 Status 0x%s\n"), phex (event_status, 4));
printf_filtered (_("Event Mask 0x%s\n"), phex (event_mask, 4)); printf_filtered (_("Event Mask 0x%s\n"), phex (event_mask, 4));
} }
do_cleanups (chain);
} }
static void static void
@ -2121,7 +2118,6 @@ info_spu_signal_command (char *args, int from_tty)
ULONGEST signal2 = 0; ULONGEST signal2 = 0;
ULONGEST signal2_type = 0; ULONGEST signal2_type = 0;
int signal2_pending = 0; int signal2_pending = 0;
struct cleanup *chain;
char annex[32]; char annex[32];
gdb_byte buf[100]; gdb_byte buf[100];
LONGEST len; LONGEST len;
@ -2168,7 +2164,7 @@ info_spu_signal_command (char *args, int from_tty)
buf[len] = '\0'; buf[len] = '\0';
signal2_type = strtoulst ((char *) buf, NULL, 16); 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 ()) if (current_uiout->is_mi_like_p ())
{ {
@ -2201,8 +2197,6 @@ info_spu_signal_command (char *args, int from_tty)
else else
printf_filtered (_("(Type Overwrite)\n")); printf_filtered (_("(Type Overwrite)\n"));
} }
do_cleanups (chain);
} }
static void static void
@ -2239,7 +2233,6 @@ info_spu_mailbox_command (char *args, int from_tty)
struct frame_info *frame = get_selected_frame (NULL); struct frame_info *frame = get_selected_frame (NULL);
struct gdbarch *gdbarch = get_frame_arch (frame); struct gdbarch *gdbarch = get_frame_arch (frame);
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
struct cleanup *chain;
char annex[32]; char annex[32];
gdb_byte buf[1024]; gdb_byte buf[1024];
LONGEST len; LONGEST len;
@ -2250,7 +2243,7 @@ info_spu_mailbox_command (char *args, int from_tty)
id = get_frame_register_unsigned (frame, SPU_ID_REGNUM); 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); xsnprintf (annex, sizeof annex, "%d/mbox_info", id);
len = target_read (&current_target, TARGET_OBJECT_SPU, annex, len = target_read (&current_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, info_spu_mailbox_list (buf, len / 4, byte_order,
"wbox", "SPU Inbound Mailbox"); "wbox", "SPU Inbound Mailbox");
do_cleanups (chain);
} }
static ULONGEST static ULONGEST
@ -2475,7 +2466,6 @@ info_spu_dma_command (char *args, int from_tty)
ULONGEST dma_info_status; ULONGEST dma_info_status;
ULONGEST dma_info_stall_and_notify; ULONGEST dma_info_stall_and_notify;
ULONGEST dma_info_atomic_command_status; ULONGEST dma_info_atomic_command_status;
struct cleanup *chain;
char annex[32]; char annex[32];
gdb_byte buf[1024]; gdb_byte buf[1024];
LONGEST len; LONGEST len;
@ -2503,7 +2493,7 @@ info_spu_dma_command (char *args, int from_tty)
dma_info_atomic_command_status dma_info_atomic_command_status
= extract_unsigned_integer (buf + 32, 8, byte_order); = 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 ()) 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); info_spu_dma_cmdlist (buf + 40, 16, byte_order);
do_cleanups (chain);
} }
static void static void
@ -2554,7 +2543,6 @@ info_spu_proxydma_command (char *args, int from_tty)
ULONGEST dma_info_type; ULONGEST dma_info_type;
ULONGEST dma_info_mask; ULONGEST dma_info_mask;
ULONGEST dma_info_status; ULONGEST dma_info_status;
struct cleanup *chain;
char annex[32]; char annex[32];
gdb_byte buf[1024]; gdb_byte buf[1024];
LONGEST len; 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_mask = extract_unsigned_integer (buf + 8, 8, byte_order);
dma_info_status = extract_unsigned_integer (buf + 16, 8, byte_order); dma_info_status = extract_unsigned_integer (buf + 16, 8, byte_order);
chain = make_cleanup_ui_out_tuple_begin_end (current_uiout, ui_out_emit_tuple tuple_emitter (current_uiout, "SPUInfoProxyDMA");
"SPUInfoProxyDMA");
if (current_uiout->is_mi_like_p ()) 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); info_spu_dma_cmdlist (buf + 24, 8, byte_order);
do_cleanups (chain);
} }
static void static void

View file

@ -1139,7 +1139,7 @@ print_frame (struct frame_info *frame, int print_level,
struct ui_out *uiout = current_uiout; struct ui_out *uiout = current_uiout;
char *funname = NULL; char *funname = NULL;
enum language funlang = language_unknown; enum language funlang = language_unknown;
struct cleanup *old_chain, *list_chain; struct cleanup *old_chain;
struct value_print_options opts; struct value_print_options opts;
struct symbol *func; struct symbol *func;
CORE_ADDR pc = 0; 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, annotate_frame_begin (print_level ? frame_relative_level (frame) : 0,
gdbarch, pc); gdbarch, pc);
list_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "frame"); {
ui_out_emit_tuple tuple_emitter (uiout, "frame");
if (print_level) 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)
{ {
annotate_frame_address (); uiout->text ("#");
if (pc_p) uiout->field_fmt_int (2, ui_left, "level",
uiout->field_core_addr ("addr", gdbarch, pc); 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)
{
annotate_frame_address ();
if (pc_p)
uiout->field_core_addr ("addr", gdbarch, pc);
else
uiout->field_string ("addr", "<unavailable>");
annotate_frame_address_end ();
uiout->text (" in ");
}
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))
{
numargs = gdbarch_frame_num_args (gdbarch, frame);
gdb_assert (numargs >= 0);
}
else else
uiout->field_string ("addr", "<unavailable>"); numargs = -1;
annotate_frame_address_end ();
uiout->text (" in ");
}
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))
{
numargs = gdbarch_frame_num_args (gdbarch, frame);
gdb_assert (numargs >= 0);
}
else
numargs = -1;
{ {
ui_out_emit_list list_emitter (uiout, "args"); ui_out_emit_list list_emitter (uiout, "args");
TRY TRY
{ {
print_frame_args (func, frame, numargs, gdb_stdout); print_frame_args (func, frame, numargs, gdb_stdout);
} }
CATCH (e, RETURN_MASK_ERROR) CATCH (e, RETURN_MASK_ERROR)
{ {
} }
END_CATCH END_CATCH
/* FIXME: ARGS must be a list. If one argument is a string it /* FIXME: ARGS must be a list. If one argument is a string it
will have " that will not be properly escaped. */ will have " that will not be properly escaped. */
}
QUIT;
} }
QUIT; uiout->text (")");
} if (sal.symtab)
uiout->text (")"); {
if (sal.symtab) const char *filename_display;
{
const char *filename_display;
filename_display = symtab_to_filename_for_display (sal.symtab); filename_display = symtab_to_filename_for_display (sal.symtab);
annotate_frame_source_begin (); annotate_frame_source_begin ();
uiout->wrap_hint (" "); uiout->wrap_hint (" ");
uiout->text (" at "); uiout->text (" at ");
annotate_frame_source_file (); annotate_frame_source_file ();
uiout->field_string ("file", filename_display); uiout->field_string ("file", filename_display);
if (uiout->is_mi_like_p ()) if (uiout->is_mi_like_p ())
{ {
const char *fullname = symtab_to_fullname (sal.symtab); const char *fullname = symtab_to_fullname (sal.symtab);
uiout->field_string ("fullname", fullname); uiout->field_string ("fullname", fullname);
} }
annotate_frame_source_file_end (); annotate_frame_source_file_end ();
uiout->text (":"); uiout->text (":");
annotate_frame_source_line (); annotate_frame_source_line ();
uiout->field_int ("line", sal.line); uiout->field_int ("line", sal.line);
annotate_frame_source_end (); annotate_frame_source_end ();
} }
if (pc_p && (funname == NULL || sal.symtab == NULL)) if (pc_p && (funname == NULL || sal.symtab == NULL))
{ {
char *lib = solib_name_from_address (get_frame_program_space (frame), char *lib = solib_name_from_address (get_frame_program_space (frame),
get_frame_pc (frame)); get_frame_pc (frame));
if (lib) if (lib)
{ {
annotate_frame_where (); annotate_frame_where ();
uiout->wrap_hint (" "); uiout->wrap_hint (" ");
uiout->text (" from "); uiout->text (" from ");
uiout->field_string ("from", lib); uiout->field_string ("from", lib);
} }
} }
}
/* do_cleanups will call ui_out_tuple_end() for us. */
do_cleanups (list_chain);
uiout->text ("\n"); uiout->text ("\n");
do_cleanups (old_chain); do_cleanups (old_chain);
} }

View file

@ -3926,9 +3926,7 @@ flash_erase_command (char *cmd, int from_tty)
found_flash_region = true; found_flash_region = true;
target_flash_erase (m->lo, m->hi - m->lo); target_flash_erase (m->lo, m->hi - m->lo);
struct cleanup *cleanup_tuple ui_out_emit_tuple tuple_emitter (current_uiout, "erased-regions");
= make_cleanup_ui_out_tuple_begin_end (current_uiout,
"erased-regions");
current_uiout->message (_("Erasing flash memory region at address ")); current_uiout->message (_("Erasing flash memory region at address "));
current_uiout->field_fmt ("address", "%s", paddress (gdbarch, 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->message (", size = ");
current_uiout->field_fmt ("size", "%s", hex_string (m->hi - m->lo)); current_uiout->field_fmt ("size", "%s", hex_string (m->hi - m->lo));
current_uiout->message ("\n"); current_uiout->message ("\n");
do_cleanups (cleanup_tuple);
} }
} }