More uses of ui_out_emit_tuple
authorTom Tromey <tom@tromey.com>
Wed, 12 Apr 2017 22:10:02 +0000 (16:10 -0600)
committerTom Tromey <tom@tromey.com>
Sat, 22 Apr 2017 15:46:59 +0000 (09:46 -0600)
This patch adds a few more uses of ui_out_emit_tuple.  In these cases
a slightly more complicated change was needed.  This also adds
annotate_arg_emitter, for use in stack.c, to avoid having to introduce
a new scope and reindent the code for a single call.

ChangeLog
2017-04-22  Tom Tromey  <tom@tromey.com>

* stack.c (print_frame_arg): Use ui_out_emit_tuple,
annotate_arg_emitter.
* breakpoint.c (print_mention_watchpoint)
(print_mention_masked_watchpoint): Use ui_out_emit_tuple.
* annotate.h (struct annotate_arg_emitter): New.

gdb/ChangeLog
gdb/annotate.h
gdb/breakpoint.c
gdb/stack.c

index 2e0ea7a..9ea2c4b 100644 (file)
@@ -1,5 +1,13 @@
 2017-04-22  Tom Tromey  <tom@tromey.com>
 
+       * stack.c (print_frame_arg): Use ui_out_emit_tuple,
+       annotate_arg_emitter.
+       * breakpoint.c (print_mention_watchpoint)
+       (print_mention_masked_watchpoint): Use ui_out_emit_tuple.
+       * annotate.h (struct annotate_arg_emitter): New.
+
+2017-04-22  Tom Tromey  <tom@tromey.com>
+
        * record-btrace.c (record_btrace_insn_history)
        (record_btrace_insn_history_range, record_btrace_call_history)
        (record_btrace_call_history_range): Use ui_out_emit_tuple.
index a1454a1..7161689 100644 (file)
@@ -74,6 +74,17 @@ extern void annotate_arg_name_end (void);
 extern void annotate_arg_value (struct type *);
 extern void annotate_arg_end (void);
 
+/* Wrap calls to annotate_arg_begin and annotate_arg_end in an RAII
+   class. */
+struct annotate_arg_emitter
+{
+  annotate_arg_emitter () { annotate_arg_begin (); }
+  ~annotate_arg_emitter () { annotate_arg_end (); }
+
+  annotate_arg_emitter (const annotate_arg_emitter &) = delete;
+  annotate_arg_emitter &operator= (const annotate_arg_emitter &) = delete;
+};
+
 extern void annotate_source (char *, int, int, int,
                             struct gdbarch *, CORE_ADDR);
 
index 2ff4406..269cddd 100644 (file)
@@ -10778,37 +10778,37 @@ print_it_watchpoint (bpstat bs)
 static void
 print_mention_watchpoint (struct breakpoint *b)
 {
-  struct cleanup *ui_out_chain;
   struct watchpoint *w = (struct watchpoint *) b;
   struct ui_out *uiout = current_uiout;
+  const char *tuple_name;
 
   switch (b->type)
     {
     case bp_watchpoint:
       uiout->text ("Watchpoint ");
-      ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
+      tuple_name = "wpt";
       break;
     case bp_hardware_watchpoint:
       uiout->text ("Hardware watchpoint ");
-      ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
+      tuple_name = "wpt";
       break;
     case bp_read_watchpoint:
       uiout->text ("Hardware read watchpoint ");
-      ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
+      tuple_name = "hw-rwpt";
       break;
     case bp_access_watchpoint:
       uiout->text ("Hardware access (read/write) watchpoint ");
-      ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
+      tuple_name = "hw-awpt";
       break;
     default:
       internal_error (__FILE__, __LINE__,
                      _("Invalid hardware watchpoint type."));
     }
 
+  ui_out_emit_tuple tuple_emitter (uiout, tuple_name);
   uiout->field_int ("number", b->number);
   uiout->text (": ");
   uiout->field_string ("exp", w->exp_string);
-  do_cleanups (ui_out_chain);
 }
 
 /* Implement the "print_recreate" breakpoint_ops method for
@@ -10977,31 +10977,31 @@ print_mention_masked_watchpoint (struct breakpoint *b)
 {
   struct watchpoint *w = (struct watchpoint *) b;
   struct ui_out *uiout = current_uiout;
-  struct cleanup *ui_out_chain;
+  const char *tuple_name;
 
   switch (b->type)
     {
     case bp_hardware_watchpoint:
       uiout->text ("Masked hardware watchpoint ");
-      ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
+      tuple_name = "wpt";
       break;
     case bp_read_watchpoint:
       uiout->text ("Masked hardware read watchpoint ");
-      ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
+      tuple_name = "hw-rwpt";
       break;
     case bp_access_watchpoint:
       uiout->text ("Masked hardware access (read/write) watchpoint ");
-      ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
+      tuple_name = "hw-awpt";
       break;
     default:
       internal_error (__FILE__, __LINE__,
                      _("Invalid hardware watchpoint type."));
     }
 
+  ui_out_emit_tuple tuple_emitter (uiout, tuple_name);
   uiout->field_int ("number", b->number);
   uiout->text (": ");
   uiout->field_string ("exp", w->exp_string);
-  do_cleanups (ui_out_chain);
 }
 
 /* Implement the "print_recreate" breakpoint_ops method for
index 32acca1..fa47264 100644 (file)
@@ -224,7 +224,6 @@ static void
 print_frame_arg (const struct frame_arg *arg)
 {
   struct ui_out *uiout = current_uiout;
-  struct cleanup *old_chain;
   const char *error_message = NULL;
 
   string_file stb;
@@ -235,9 +234,8 @@ print_frame_arg (const struct frame_arg *arg)
              || (!uiout->is_mi_like_p ()
                  && arg->entry_kind == print_entry_values_compact));
 
-  annotate_arg_begin ();
-
-  old_chain = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
+  annotate_arg_emitter arg_emitter;
+  ui_out_emit_tuple tuple_emitter (uiout, NULL);
   fprintf_symbol_filtered (&stb, SYMBOL_PRINT_NAME (arg->sym),
                           SYMBOL_LANGUAGE (arg->sym), DMGL_PARAMS | DMGL_ANSI);
   if (arg->entry_kind == print_entry_values_compact)
@@ -305,11 +303,6 @@ print_frame_arg (const struct frame_arg *arg)
     }
 
   uiout->field_stream ("value", stb);
-
-  /* Also invoke ui_out_tuple_end.  */
-  do_cleanups (old_chain);
-
-  annotate_arg_end ();
 }
 
 /* Read in inferior function local SYM at FRAME into ARGP.  Caller is