[RFA,2/5] More uses of ui_out_emit_tuple

Message ID 20170414022337.28368-3-tom@tromey.com
State New, archived
Headers

Commit Message

Tom Tromey April 14, 2017, 2:23 a.m. UTC
  This patch adds a few more uses of ui_out_emit_tuple.  In these cases
a slightly more complicated change was needed.

gdb/ChangeLog
2017-04-13  Tom Tromey  <tom@tromey.com>

	* stack.c (print_frame_arg): Use ui_out_emit_tuple.
	* breakpoint.c (print_mention_watchpoint)
	(print_mention_masked_watchpoint): Use ui_out_emit_tuple.
---
 gdb/ChangeLog    |   6 +++
 gdb/breakpoint.c |  22 ++++-----
 gdb/stack.c      | 141 ++++++++++++++++++++++++++++---------------------------
 3 files changed, 88 insertions(+), 81 deletions(-)
  

Comments

Pedro Alves April 18, 2017, 6:42 p.m. UTC | #1
On 04/14/2017 03:23 AM, Tom Tromey wrote:

> -  do_cleanups (old_chain);
> +    uiout->field_stream ("value", stb);
> +  }
>  
>    annotate_arg_end ();

Looks like the reason that this needed a new scope was
this annotate_arg_end call.

How about instead adding something like this:

struct annotate_arg_emitter
{
  annotate_arg_emitter () { annotate_arg_begin (); }
  ~annotate_arg_emitter () { annotate_arg_end (); }
};

and using it in the function alongside the tuple emitter, like:

    annotate_arg_emitter annotate_arg;
    ui_out_emit_tuple tuple_emitter (uiout, NULL);

Thanks,
Pedro Alves
  

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 688d11f..1ec48a3 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,11 @@ 
 2017-04-13  Tom Tromey  <tom@tromey.com>
 
+	* stack.c (print_frame_arg): Use ui_out_emit_tuple.
+	* breakpoint.c (print_mention_watchpoint)
+	(print_mention_masked_watchpoint): Use ui_out_emit_tuple.
+
+2017-04-13  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.
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 2ff4406..269cddd 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -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
diff --git a/gdb/stack.c b/gdb/stack.c
index 32acca1..05081fa 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -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;
@@ -237,77 +236,79 @@  print_frame_arg (const struct frame_arg *arg)
 
   annotate_arg_begin ();
 
-  old_chain = make_cleanup_ui_out_tuple_begin_end (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)
-    {
-      /* It is OK to provide invalid MI-like stream as with
-	 PRINT_ENTRY_VALUE_COMPACT we never use MI.  */
-      stb.puts ("=");
-
-      fprintf_symbol_filtered (&stb, SYMBOL_PRINT_NAME (arg->sym),
-			       SYMBOL_LANGUAGE (arg->sym),
-			       DMGL_PARAMS | DMGL_ANSI);
-    }
-  if (arg->entry_kind == print_entry_values_only
-      || arg->entry_kind == print_entry_values_compact)
-    stb.puts ("@entry");
-  uiout->field_stream ("name", stb);
-  annotate_arg_name_end ();
-  uiout->text ("=");
-
-  if (!arg->val && !arg->error)
-    uiout->text ("...");
-  else
-    {
-      if (arg->error)
-	error_message = arg->error;
-      else
-	{
-	  TRY
-	    {
-	      const struct language_defn *language;
-	      struct value_print_options opts;
-
-	      /* Avoid value_print because it will deref ref parameters.  We
-		 just want to print their addresses.  Print ??? for args whose
-		 address we do not know.  We pass 2 as "recurse" to val_print
-		 because our standard indentation here is 4 spaces, and
-		 val_print indents 2 for each recurse.  */ 
-
-	      annotate_arg_value (value_type (arg->val));
-
-	      /* Use the appropriate language to display our symbol, unless the
-		 user forced the language to a specific language.  */
-	      if (language_mode == language_mode_auto)
-		language = language_def (SYMBOL_LANGUAGE (arg->sym));
-	      else
-		language = current_language;
-
-	      get_no_prettyformat_print_options (&opts);
-	      opts.deref_ref = 1;
-	      opts.raw = print_raw_frame_arguments;
-
-	      /* True in "summary" mode, false otherwise.  */
-	      opts.summary = !strcmp (print_frame_arguments, "scalars");
-
-	      common_val_print (arg->val, &stb, 2, &opts, language);
-	    }
-	  CATCH (except, RETURN_MASK_ERROR)
-	    {
-	      error_message = except.message;
-	    }
-	  END_CATCH
-	}
-      if (error_message != NULL)
-	stb.printf (_("<error reading variable: %s>"), error_message);
-    }
+  {
+    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)
+      {
+	/* It is OK to provide invalid MI-like stream as with
+	   PRINT_ENTRY_VALUE_COMPACT we never use MI.  */
+	stb.puts ("=");
 
-  uiout->field_stream ("value", stb);
+	fprintf_symbol_filtered (&stb, SYMBOL_PRINT_NAME (arg->sym),
+				 SYMBOL_LANGUAGE (arg->sym),
+				 DMGL_PARAMS | DMGL_ANSI);
+      }
+    if (arg->entry_kind == print_entry_values_only
+	|| arg->entry_kind == print_entry_values_compact)
+      stb.puts ("@entry");
+    uiout->field_stream ("name", stb);
+    annotate_arg_name_end ();
+    uiout->text ("=");
+
+    if (!arg->val && !arg->error)
+      uiout->text ("...");
+    else
+      {
+	if (arg->error)
+	  error_message = arg->error;
+	else
+	  {
+	    TRY
+	      {
+		const struct language_defn *language;
+		struct value_print_options opts;
+
+		/* Avoid value_print because it will deref ref
+		   parameters.  We just want to print their addresses.
+		   Print ??? for args whose address we do not know.
+		   We pass 2 as "recurse" to val_print because our
+		   standard indentation here is 4 spaces, and
+		   val_print indents 2 for each recurse.  */ 
+
+		annotate_arg_value (value_type (arg->val));
+
+		/* Use the appropriate language to display our symbol,
+		   unless the user forced the language to a specific
+		   language.  */
+		if (language_mode == language_mode_auto)
+		  language = language_def (SYMBOL_LANGUAGE (arg->sym));
+		else
+		  language = current_language;
+
+		get_no_prettyformat_print_options (&opts);
+		opts.deref_ref = 1;
+		opts.raw = print_raw_frame_arguments;
+
+		/* True in "summary" mode, false otherwise.  */
+		opts.summary = !strcmp (print_frame_arguments, "scalars");
+
+		common_val_print (arg->val, &stb, 2, &opts, language);
+	      }
+	    CATCH (except, RETURN_MASK_ERROR)
+	      {
+		error_message = except.message;
+	      }
+	    END_CATCH
+	      }
+	if (error_message != NULL)
+	  stb.printf (_("<error reading variable: %s>"), error_message);
+      }
 
-  /* Also invoke ui_out_tuple_end.  */
-  do_cleanups (old_chain);
+    uiout->field_stream ("value", stb);
+  }
 
   annotate_arg_end ();
 }