[RFA,1/5] Use ui_out_emit_tuple

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

Commit Message

Tom Tromey April 14, 2017, 2:23 a.m. UTC
  This patch changes various places to use ui_out_emit_tuple,
eliminating a number of cleanups.  This patch only tackles "easy"
cases, which are ones where the cleanups in question were
block-structured and did not involve any changes other than the
obvious replacement.

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.
	* thread.c (do_captured_list_thread_ids, print_thread_info_1): Use
	ui_out_emit_tuple.
	* stack.c (print_frame_info): Use ui_out_emit_tuple.
	* solib.c (info_sharedlibrary_command): Use ui_out_emit_tuple.
	* skip.c (skip_info): Use ui_out_emit_tuple.
	* remote.c (show_remote_cmd): Use ui_out_emit_tuple.
	* progspace.c (print_program_space): Use ui_out_emit_tuple.
	* probe.c (info_probes_for_ops): Use ui_out_emit_tuple.
	* osdata.c (info_osdata): Use ui_out_emit_tuple.
	* mi/mi-symbol-cmds.c (mi_cmd_symbol_list_lines): Use
	ui_out_emit_tuple.
	* mi/mi-main.c (print_one_inferior, list_available_thread_groups)
	(output_register, mi_cmd_data_read_memory)
	(mi_cmd_data_read_memory_bytes, mi_load_progress)
	(mi_cmd_trace_frame_collected): Use ui_out_emit_tuple.
	* mi/mi-cmd-var.c (mi_cmd_var_list_children, varobj_update_one):
	Use ui_out_emit_tuple.
	* mi/mi-cmd-stack.c (mi_cmd_stack_list_args): Use
	ui_out_emit_tuple.
	* mi/mi-cmd-info.c (mi_cmd_info_ada_exceptions)
	(mi_cmd_info_gdb_mi_command): Use ui_out_emit_tuple.
	* linux-thread-db.c (info_auto_load_libthread_db): Use
	ui_out_emit_tuple.
	* inferior.c (print_inferior): Use ui_out_emit_tuple.
	* gdb_bfd.c (print_one_bfd): Use ui_out_emit_tuple.
	* disasm.c (do_mixed_source_and_assembly_deprecated)
	(do_mixed_source_and_assembly): Use ui_out_emit_tuple.
	* cp-abi.c (list_cp_abis): Use ui_out_emit_tuple.
	* cli/cli-setshow.c (cmd_show_list): Use ui_out_emit_tuple.
	* breakpoint.c (print_one_breakpoint_location)
	(print_one_breakpoint): Use ui_out_emit_tuple.
	* auto-load.c (print_script, info_auto_load_cmd): Use
	ui_out_emit_tuple.
	* ada-tasks.c (print_ada_task_info): Use ui_out_emit_tuple.
---
 gdb/ChangeLog           | 40 +++++++++++++++++++++++++++++++
 gdb/ada-tasks.c         |  4 +---
 gdb/auto-load.c         | 16 +++----------
 gdb/breakpoint.c        | 17 +++++--------
 gdb/cli/cli-setshow.c   | 15 +++---------
 gdb/cp-abi.c            |  5 +---
 gdb/disasm.c            | 13 +++-------
 gdb/gdb_bfd.c           |  4 +---
 gdb/inferior.c          |  5 +---
 gdb/linux-thread-db.c   |  3 +--
 gdb/mi/mi-cmd-info.c    | 10 ++------
 gdb/mi/mi-cmd-stack.c   |  5 +---
 gdb/mi/mi-cmd-var.c     | 10 ++------
 gdb/mi/mi-main.c        | 63 +++++++++++++++++--------------------------------
 gdb/mi/mi-symbol-cmds.c |  5 ++--
 gdb/osdata.c            | 29 +++++++++++------------
 gdb/probe.c             |  5 +---
 gdb/progspace.c         |  4 +---
 gdb/record-btrace.c     | 22 ++++-------------
 gdb/remote.c            | 11 ++-------
 gdb/skip.c              |  5 +---
 gdb/solib.c             |  6 +----
 gdb/stack.c             |  4 +---
 gdb/thread.c            | 30 ++++++++++-------------
 24 files changed, 126 insertions(+), 205 deletions(-)
  

Comments

Pedro Alves April 18, 2017, 6:42 p.m. UTC | #1
On 04/14/2017 03:23 AM, Tom Tromey wrote:
> This patch changes various places to use ui_out_emit_tuple,
> eliminating a number of cleanups.  This patch only tackles "easy"
> cases, which are ones where the cleanups in question were
> block-structured and did not involve any changes other than the
> obvious replacement.
> 
> 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.
> 	* thread.c (do_captured_list_thread_ids, print_thread_info_1): Use
> 	ui_out_emit_tuple.
> 	* stack.c (print_frame_info): Use ui_out_emit_tuple.
> 	* solib.c (info_sharedlibrary_command): Use ui_out_emit_tuple.
> 	* skip.c (skip_info): Use ui_out_emit_tuple.
> 	* remote.c (show_remote_cmd): Use ui_out_emit_tuple.
> 	* progspace.c (print_program_space): Use ui_out_emit_tuple.
> 	* probe.c (info_probes_for_ops): Use ui_out_emit_tuple.
> 	* osdata.c (info_osdata): Use ui_out_emit_tuple.
> 	* mi/mi-symbol-cmds.c (mi_cmd_symbol_list_lines): Use
> 	ui_out_emit_tuple.
> 	* mi/mi-main.c (print_one_inferior, list_available_thread_groups)
> 	(output_register, mi_cmd_data_read_memory)
> 	(mi_cmd_data_read_memory_bytes, mi_load_progress)
> 	(mi_cmd_trace_frame_collected): Use ui_out_emit_tuple.
> 	* mi/mi-cmd-var.c (mi_cmd_var_list_children, varobj_update_one):
> 	Use ui_out_emit_tuple.
> 	* mi/mi-cmd-stack.c (mi_cmd_stack_list_args): Use
> 	ui_out_emit_tuple.
> 	* mi/mi-cmd-info.c (mi_cmd_info_ada_exceptions)
> 	(mi_cmd_info_gdb_mi_command): Use ui_out_emit_tuple.
> 	* linux-thread-db.c (info_auto_load_libthread_db): Use
> 	ui_out_emit_tuple.
> 	* inferior.c (print_inferior): Use ui_out_emit_tuple.
> 	* gdb_bfd.c (print_one_bfd): Use ui_out_emit_tuple.
> 	* disasm.c (do_mixed_source_and_assembly_deprecated)
> 	(do_mixed_source_and_assembly): Use ui_out_emit_tuple.
> 	* cp-abi.c (list_cp_abis): Use ui_out_emit_tuple.
> 	* cli/cli-setshow.c (cmd_show_list): Use ui_out_emit_tuple.
> 	* breakpoint.c (print_one_breakpoint_location)
> 	(print_one_breakpoint): Use ui_out_emit_tuple.
> 	* auto-load.c (print_script, info_auto_load_cmd): Use
> 	ui_out_emit_tuple.
> 	* ada-tasks.c (print_ada_task_info): Use ui_out_emit_tuple.

LGTM.

Thanks,
Pedro Alves
  

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 11d77be..688d11f 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,43 @@ 
+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.
+	* thread.c (do_captured_list_thread_ids, print_thread_info_1): Use
+	ui_out_emit_tuple.
+	* stack.c (print_frame_info): Use ui_out_emit_tuple.
+	* solib.c (info_sharedlibrary_command): Use ui_out_emit_tuple.
+	* skip.c (skip_info): Use ui_out_emit_tuple.
+	* remote.c (show_remote_cmd): Use ui_out_emit_tuple.
+	* progspace.c (print_program_space): Use ui_out_emit_tuple.
+	* probe.c (info_probes_for_ops): Use ui_out_emit_tuple.
+	* osdata.c (info_osdata): Use ui_out_emit_tuple.
+	* mi/mi-symbol-cmds.c (mi_cmd_symbol_list_lines): Use
+	ui_out_emit_tuple.
+	* mi/mi-main.c (print_one_inferior, list_available_thread_groups)
+	(output_register, mi_cmd_data_read_memory)
+	(mi_cmd_data_read_memory_bytes, mi_load_progress)
+	(mi_cmd_trace_frame_collected): Use ui_out_emit_tuple.
+	* mi/mi-cmd-var.c (mi_cmd_var_list_children, varobj_update_one):
+	Use ui_out_emit_tuple.
+	* mi/mi-cmd-stack.c (mi_cmd_stack_list_args): Use
+	ui_out_emit_tuple.
+	* mi/mi-cmd-info.c (mi_cmd_info_ada_exceptions)
+	(mi_cmd_info_gdb_mi_command): Use ui_out_emit_tuple.
+	* linux-thread-db.c (info_auto_load_libthread_db): Use
+	ui_out_emit_tuple.
+	* inferior.c (print_inferior): Use ui_out_emit_tuple.
+	* gdb_bfd.c (print_one_bfd): Use ui_out_emit_tuple.
+	* disasm.c (do_mixed_source_and_assembly_deprecated)
+	(do_mixed_source_and_assembly): Use ui_out_emit_tuple.
+	* cp-abi.c (list_cp_abis): Use ui_out_emit_tuple.
+	* cli/cli-setshow.c (cmd_show_list): Use ui_out_emit_tuple.
+	* breakpoint.c (print_one_breakpoint_location)
+	(print_one_breakpoint): Use ui_out_emit_tuple.
+	* auto-load.c (print_script, info_auto_load_cmd): Use
+	ui_out_emit_tuple.
+	* ada-tasks.c (print_ada_task_info): Use ui_out_emit_tuple.
+
 2017-04-13  Sergio Durigan Junior  <sergiodj@redhat.com>
 
 	PR gdb/21385
diff --git a/gdb/ada-tasks.c b/gdb/ada-tasks.c
index 624bbdd..ae43da5 100644
--- a/gdb/ada-tasks.c
+++ b/gdb/ada-tasks.c
@@ -1073,7 +1073,6 @@  print_ada_task_info (struct ui_out *uiout,
       const struct ada_task_info *const task_info =
 	VEC_index (ada_task_info_s, data->task_list, taskno - 1);
       int parent_id;
-      struct cleanup *chain2;
 
       gdb_assert (task_info != NULL);
 
@@ -1083,7 +1082,7 @@  print_ada_task_info (struct ui_out *uiout,
       if (taskno_arg && taskno != taskno_arg)
         continue;
 
-      chain2 = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
+      ui_out_emit_tuple tuple_emitter (uiout, NULL);
 
       /* Print a star if this task is the current task (or the task
          currently selected).  */
@@ -1143,7 +1142,6 @@  print_ada_task_info (struct ui_out *uiout,
 						   : _("<no name>"));
 
       uiout->text ("\n");
-      do_cleanups (chain2);
     }
 
   do_cleanups (old_chain);
diff --git a/gdb/auto-load.c b/gdb/auto-load.c
index edaf264..37bf942 100644
--- a/gdb/auto-load.c
+++ b/gdb/auto-load.c
@@ -1268,9 +1268,8 @@  static void
 print_script (struct loaded_script *script)
 {
   struct ui_out *uiout = current_uiout;
-  struct cleanup *chain;
 
-  chain = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
+  ui_out_emit_tuple tuple_emitter (uiout, NULL);
 
   uiout->field_string ("loaded", script->loaded ? "Yes" : "No");
   uiout->field_string ("script", script->name);
@@ -1284,8 +1283,6 @@  print_script (struct loaded_script *script)
       uiout->field_string ("full_path", script->full_path);
       uiout->text ("\n");
     }
-
-  do_cleanups (chain);
 }
 
 /* Helper for info_auto_load_scripts to sort the scripts by name.  */
@@ -1561,12 +1558,11 @@  info_auto_load_cmd (char *args, int from_tty)
   struct cleanup *infolist_chain;
   struct ui_out *uiout = current_uiout;
 
-  infolist_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "infolist");
+  ui_out_emit_tuple tuple_emitter (uiout, "infolist");
 
   for (list = *auto_load_info_cmdlist_get (); list != NULL; list = list->next)
     {
-      struct cleanup *option_chain
-	= make_cleanup_ui_out_tuple_begin_end (uiout, "option");
+      ui_out_emit_tuple option_emitter (uiout, "option");
 
       gdb_assert (!list->prefixlist);
       gdb_assert (list->type == not_set_cmd);
@@ -1574,13 +1570,7 @@  info_auto_load_cmd (char *args, int from_tty)
       uiout->field_string ("name", list->name);
       uiout->text (":  ");
       cmd_func (list, auto_load_info_scripts_pattern_nl, from_tty);
-
-      /* Close the tuple.  */
-      do_cleanups (option_chain);
     }
-
-  /* Close the tuple.  */
-  do_cleanups (infolist_chain);
 }
 
 /* Initialize "info auto-load " commands prefix and return it.  */
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 4940ec2..2ff4406 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -6619,12 +6619,9 @@  print_one_breakpoint_location (struct breakpoint *b,
   l = b->commands ? b->commands->commands : NULL;
   if (!part_of_multiple && l)
     {
-      struct cleanup *script_chain;
-
       annotate_field (9);
-      script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
+      ui_out_emit_tuple tuple_emitter (uiout, "script");
       print_command_lines (uiout, l, 4);
-      do_cleanups (script_chain);
     }
 
   if (is_tracepoint (b))
@@ -6679,13 +6676,13 @@  print_one_breakpoint (struct breakpoint *b,
 		      struct bp_location **last_loc, 
 		      int allflag)
 {
-  struct cleanup *bkpt_chain;
   struct ui_out *uiout = current_uiout;
 
-  bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
+  {
+    ui_out_emit_tuple tuple_emitter (uiout, "bkpt");
 
-  print_one_breakpoint_location (b, NULL, 0, last_loc, allflag);
-  do_cleanups (bkpt_chain);
+    print_one_breakpoint_location (b, NULL, 0, last_loc, allflag);
+  }
 
   /* If this breakpoint has custom print function,
      it's already printed.  Otherwise, print individual
@@ -6708,10 +6705,8 @@  print_one_breakpoint (struct breakpoint *b,
 
 	  for (loc = b->loc; loc; loc = loc->next, ++n)
 	    {
-	      struct cleanup *inner2 =
-		make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
+	      ui_out_emit_tuple tuple_emitter (uiout, NULL);
 	      print_one_breakpoint_location (b, loc, n, last_loc, allflag);
-	      do_cleanups (inner2);
 	    }
 	}
     }
diff --git a/gdb/cli/cli-setshow.c b/gdb/cli/cli-setshow.c
index 218e1f3..fb0bd49 100644
--- a/gdb/cli/cli-setshow.c
+++ b/gdb/cli/cli-setshow.c
@@ -664,32 +664,27 @@  do_show_command (const char *arg, int from_tty, struct cmd_list_element *c)
 void
 cmd_show_list (struct cmd_list_element *list, int from_tty, const char *prefix)
 {
-  struct cleanup *showlist_chain;
   struct ui_out *uiout = current_uiout;
 
-  showlist_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "showlist");
+  ui_out_emit_tuple tuple_emitter (uiout, "showlist");
   for (; list != NULL; list = list->next)
     {
       /* If we find a prefix, run its list, prefixing our output by its
          prefix (with "show " skipped).  */
       if (list->prefixlist && !list->abbrev_flag)
 	{
-	  struct cleanup *optionlist_chain
-	    = make_cleanup_ui_out_tuple_begin_end (uiout, "optionlist");
+	  ui_out_emit_tuple optionlist_emitter (uiout, "optionlist");
 	  const char *new_prefix = strstr (list->prefixname, "show ") + 5;
 
 	  if (uiout->is_mi_like_p ())
 	    uiout->field_string ("prefix", new_prefix);
 	  cmd_show_list (*list->prefixlist, from_tty, new_prefix);
-	  /* Close the tuple.  */
-	  do_cleanups (optionlist_chain);
 	}
       else
 	{
 	  if (list->theclass != no_set_class)
 	    {
-	      struct cleanup *option_chain
-		= make_cleanup_ui_out_tuple_begin_end (uiout, "option");
+	      ui_out_emit_tuple option_emitter (uiout, "option");
 
 	      uiout->text (prefix);
 	      uiout->field_string ("name", list->name);
@@ -698,12 +693,8 @@  cmd_show_list (struct cmd_list_element *list, int from_tty, const char *prefix)
 		do_show_command ((char *) NULL, from_tty, list);
 	      else
 		cmd_func (list, NULL, from_tty);
-	      /* Close the tuple.  */
-	      do_cleanups (option_chain);
 	    }
 	}
     }
-  /* Close the tuple.  */
-  do_cleanups (showlist_chain);
 }
 
diff --git a/gdb/cp-abi.c b/gdb/cp-abi.c
index 510dfd0..b72f227 100644
--- a/gdb/cp-abi.c
+++ b/gdb/cp-abi.c
@@ -314,12 +314,10 @@  static void
 list_cp_abis (int from_tty)
 {
   struct ui_out *uiout = current_uiout;
-  struct cleanup *cleanup_chain;
   int i;
 
   uiout->text ("The available C++ ABIs are:\n");
-  cleanup_chain = make_cleanup_ui_out_tuple_begin_end (uiout,
-						       "cp-abi-list");
+  ui_out_emit_tuple tuple_emitter (uiout, "cp-abi-list");
   for (i = 0; i < num_cp_abis; i++)
     {
       char pad[14];
@@ -337,7 +335,6 @@  list_cp_abis (int from_tty)
       uiout->field_string ("doc", cp_abis[i]->doc);
       uiout->text ("\n");
     }
-  do_cleanups (cleanup_chain);
 }
 
 /* Set the current C++ ABI, or display the list of options if no
diff --git a/gdb/disasm.c b/gdb/disasm.c
index 734db2b..fde52c3 100644
--- a/gdb/disasm.c
+++ b/gdb/disasm.c
@@ -437,18 +437,15 @@  do_mixed_source_and_assembly_deprecated
 		  for (; next_line < mle[i].line; next_line++)
 		    {
 		      struct cleanup *ui_out_list_chain_line;
-		      struct cleanup *ui_out_tuple_chain_line;
 		      
-		      ui_out_tuple_chain_line
-			= make_cleanup_ui_out_tuple_begin_end (uiout,
-							       "src_and_asm_line");
+		      ui_out_emit_tuple tuple_emitter (uiout,
+						       "src_and_asm_line");
 		      print_source_lines (symtab, next_line, next_line + 1,
 					  psl_flags);
 		      ui_out_list_chain_line
 			= make_cleanup_ui_out_list_begin_end (uiout,
 							      "line_asm_insn");
 		      do_cleanups (ui_out_list_chain_line);
-		      do_cleanups (ui_out_tuple_chain_line);
 		    }
 		  /* Print the last line and leave list open for
 		     asm instructions to be added.  */
@@ -680,22 +677,18 @@  do_mixed_source_and_assembly (struct gdbarch *gdbarch,
 		 a bunch of line tuples with no asm entries.  */
 	      int l;
 	      struct cleanup *ui_out_list_chain_line;
-	      struct cleanup *ui_out_tuple_chain_line;
 
 	      gdb_assert (sal.symtab != NULL);
 	      for (l = start_preceding_line_to_display;
 		   l < end_preceding_line_to_display;
 		   ++l)
 		{
-		  ui_out_tuple_chain_line
-		    = make_cleanup_ui_out_tuple_begin_end (uiout,
-							   "src_and_asm_line");
+		  ui_out_emit_tuple tuple_emitter (uiout, "src_and_asm_line");
 		  print_source_lines (sal.symtab, l, l + 1, psl_flags);
 		  ui_out_list_chain_line
 		    = make_cleanup_ui_out_list_begin_end (uiout,
 							  "line_asm_insn");
 		  do_cleanups (ui_out_list_chain_line);
-		  do_cleanups (ui_out_tuple_chain_line);
 		}
 	    }
 	  ui_out_tuple_chain
diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c
index 37cf6e2..2230127 100644
--- a/gdb/gdb_bfd.c
+++ b/gdb/gdb_bfd.c
@@ -961,14 +961,12 @@  print_one_bfd (void **slot, void *data)
   bfd *abfd = (struct bfd *) *slot;
   struct gdb_bfd_data *gdata = (struct gdb_bfd_data *) bfd_usrdata (abfd);
   struct ui_out *uiout = (struct ui_out *) data;
-  struct cleanup *inner;
 
-  inner = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
+  ui_out_emit_tuple tuple_emitter (uiout, NULL);
   uiout->field_int ("refcount", gdata->refc);
   uiout->field_string ("addr", host_address_to_string (abfd));
   uiout->field_string ("filename", bfd_get_filename (abfd));
   uiout->text ("\n");
-  do_cleanups (inner);
 
   return 1;
 }
diff --git a/gdb/inferior.c b/gdb/inferior.c
index 327590a..a5e993f 100644
--- a/gdb/inferior.c
+++ b/gdb/inferior.c
@@ -584,12 +584,10 @@  print_inferior (struct ui_out *uiout, char *requested_inferiors)
   uiout->table_body ();
   for (inf = inferior_list; inf; inf = inf->next)
     {
-      struct cleanup *chain2;
-
       if (!number_is_in_list (requested_inferiors, inf->num))
 	continue;
 
-      chain2 = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
+      ui_out_emit_tuple tuple_emitter (uiout, NULL);
 
       if (inf == current_inferior ())
 	uiout->field_string ("current", "*");
@@ -620,7 +618,6 @@  print_inferior (struct ui_out *uiout, char *requested_inferiors)
 	}
 
       uiout->text ("\n");
-      do_cleanups (chain2);
     }
 
   do_cleanups (old_chain);
diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c
index eda3d7b..86254f8 100644
--- a/gdb/linux-thread-db.c
+++ b/gdb/linux-thread-db.c
@@ -1636,7 +1636,7 @@  info_auto_load_libthread_db (char *args, int from_tty)
   /* Note I is incremented inside the cycle, not at its end.  */
   for (i = 0; i < info_count;)
     {
-      struct cleanup *chain = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
+      ui_out_emit_tuple tuple_emitter (uiout, NULL);
       char *pids_end;
 
       info = array[i];
@@ -1661,7 +1661,6 @@  info_auto_load_libthread_db (char *args, int from_tty)
       uiout->field_string ("pids", pids);
 
       uiout->text ("\n");
-      do_cleanups (chain);
     }
 
   do_cleanups (back_to);
diff --git a/gdb/mi/mi-cmd-info.c b/gdb/mi/mi-cmd-info.c
index 1a96d6f..7da4f90 100644
--- a/gdb/mi/mi-cmd-info.c
+++ b/gdb/mi/mi-cmd-info.c
@@ -59,13 +59,9 @@  mi_cmd_info_ada_exceptions (const char *command, char **argv, int argc)
 
   for (ix = 0; VEC_iterate(ada_exc_info, exceptions, ix, info); ix++)
     {
-      struct cleanup *sub_chain;
-
-      sub_chain = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
+      ui_out_emit_tuple tuple_emitter (uiout, NULL);
       uiout->field_string ("name", info->name);
       uiout->field_core_addr ("address", gdbarch, info->addr);
-
-      do_cleanups (sub_chain);
     }
 
   do_cleanups (old_chain);
@@ -79,7 +75,6 @@  mi_cmd_info_gdb_mi_command (const char *command, char **argv, int argc)
   const char *cmd_name;
   struct mi_cmd *cmd;
   struct ui_out *uiout = current_uiout;
-  struct cleanup *old_chain;
 
   /* This command takes exactly one argument.  */
   if (argc != 1)
@@ -95,9 +90,8 @@  mi_cmd_info_gdb_mi_command (const char *command, char **argv, int argc)
 
   cmd = mi_lookup (cmd_name);
 
-  old_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "command");
+  ui_out_emit_tuple tuple_emitter (uiout, "command");
   uiout->field_string ("exists", cmd != NULL ? "true" : "false");
-  do_cleanups (old_chain);
 }
 
 void
diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c
index bd91033..f288817 100644
--- a/gdb/mi/mi-cmd-stack.c
+++ b/gdb/mi/mi-cmd-stack.c
@@ -387,13 +387,10 @@  mi_cmd_stack_list_args (const char *command, char **argv, int argc)
 	   fi && (i <= frame_high || frame_high == -1);
 	   i++, fi = get_prev_frame (fi))
 	{
-	  struct cleanup *cleanup_frame;
-
 	  QUIT;
-	  cleanup_frame = make_cleanup_ui_out_tuple_begin_end (uiout, "frame");
+	  ui_out_emit_tuple tuple_emitter (uiout, "frame");
 	  uiout->field_int ("level", i);
 	  list_args_or_locals (arguments, print_values, fi, skip_unavailable);
-	  do_cleanups (cleanup_frame);
 	}
     }
   do_cleanups (cleanup_stack_args);
diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c
index 78ef8e0..0a4ed62 100644
--- a/gdb/mi/mi-cmd-var.c
+++ b/gdb/mi/mi-cmd-var.c
@@ -421,11 +421,9 @@  mi_cmd_var_list_children (const char *command, char **argv, int argc)
 	   ix < to && VEC_iterate (varobj_p, children, ix, child);
 	   ++ix)
 	{
-	  struct cleanup *cleanup_child;
+	  ui_out_emit_tuple child_emitter (uiout, "child");
 
-	  cleanup_child = make_cleanup_ui_out_tuple_begin_end (uiout, "child");
 	  print_varobj (child, print_values, 1 /* print expression */);
-	  do_cleanups (cleanup_child);
 	}
       do_cleanups (cleanup_children);
     }
@@ -778,12 +776,8 @@  varobj_update_one (struct varobj *var, enum print_values print_values,
 	  cleanup = make_cleanup_ui_out_list_begin_end (uiout, "new_children");
 	  for (j = 0; VEC_iterate (varobj_p, r->newobj, j, child); ++j)
 	    {
-	      struct cleanup *cleanup_child;
-
-	      cleanup_child
-		= make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
+	      ui_out_emit_tuple tuple_emitter (uiout, NULL);
 	      print_varobj (child, print_values, 1 /* print_expression */);
-	      do_cleanups (cleanup_child);
 	    }
 
 	  do_cleanups (cleanup);
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index c3e7bf7..d309ba3 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -660,8 +660,7 @@  print_one_inferior (struct inferior *inferior, void *xdata)
 		  compare_positive_ints))
     {
       struct collect_cores_data data;
-      struct cleanup *back_to
-	= make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
+      ui_out_emit_tuple tuple_emitter (uiout, NULL);
 
       uiout->field_fmt ("id", "i%d", inferior->num);
       uiout->field_string ("type", "process");
@@ -706,8 +705,6 @@  print_one_inferior (struct inferior *inferior, void *xdata)
 
       if (top_data->recurse)
 	print_thread_info (uiout, NULL, inferior->pid);
-
-      do_cleanups (back_to);
     }
 
   return 0;
@@ -831,8 +828,6 @@  list_available_thread_groups (VEC (int) *ids, int recurse)
 		    ix_items, item);
        ix_items++)
     {
-      struct cleanup *back_to;
-
       const char *pid = get_osdata_column (item, "pid");
       const char *cmd = get_osdata_column (item, "command");
       const char *user = get_osdata_column (item, "user");
@@ -849,7 +844,7 @@  list_available_thread_groups (VEC (int) *ids, int recurse)
 	continue;
 
 
-      back_to = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
+      ui_out_emit_tuple tuple_emitter (uiout, NULL);
 
       uiout->field_fmt ("id", "%s", pid);
       uiout->field_string ("type", "process");
@@ -875,21 +870,16 @@  list_available_thread_groups (VEC (int) *ids, int recurse)
 		   VEC_iterate (osdata_item_s, children, ix_child, child);
 		   ++ix_child)
 		{
-		  struct cleanup *back_to_2 =
-		    make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
+		  ui_out_emit_tuple tuple_emitter (uiout, NULL);
 		  const char *tid = get_osdata_column (child, "tid");
 		  const char *tcore = get_osdata_column (child, "core");
 
 		  uiout->field_string ("id", tid);
 		  if (tcore)
 		    uiout->field_string ("core", tcore);
-
-		  do_cleanups (back_to_2);
 		}
 	    }
 	}
-
-      do_cleanups (back_to);
     }
 
   do_cleanups (cleanup);
@@ -1257,13 +1247,12 @@  output_register (struct frame_info *frame, int regnum, int format,
 {
   struct ui_out *uiout = current_uiout;
   struct value *val = value_of_register (regnum, frame);
-  struct cleanup *tuple_cleanup;
   struct value_print_options opts;
 
   if (skip_unavailable && !value_entirely_available (val))
     return;
 
-  tuple_cleanup = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
+  ui_out_emit_tuple tuple_emitter (uiout, NULL);
   uiout->field_int ("number", regnum);
 
   if (format == 'N')
@@ -1280,8 +1269,6 @@  output_register (struct frame_info *frame, int regnum, int format,
 	     value_embedded_offset (val), 0,
 	     &stb, 0, val, &opts, current_language);
   uiout->field_stream ("value", stb);
-
-  do_cleanups (tuple_cleanup);
 }
 
 /* Write given values into registers. The registers and values are
@@ -1520,11 +1507,10 @@  mi_cmd_data_read_memory (const char *command, char **argv, int argc)
       {
 	int col;
 	int col_byte;
-	struct cleanup *cleanup_tuple;
 	struct cleanup *cleanup_list_data;
 	struct value_print_options opts;
 
-	cleanup_tuple = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
+	ui_out_emit_tuple tuple_emitter (uiout, NULL);
 	uiout->field_core_addr ("addr", gdbarch, addr + row_byte);
 	/* ui_out_field_core_addr_symbolic (uiout, "saddr", addr +
 	   row_byte); */
@@ -1564,7 +1550,6 @@  mi_cmd_data_read_memory (const char *command, char **argv, int argc)
 	      }
 	    uiout->field_stream ("ascii", stream);
 	  }
-	do_cleanups (cleanup_tuple);
       }
     do_cleanups (cleanup_list);
   }
@@ -1629,7 +1614,7 @@  mi_cmd_data_read_memory_bytes (const char *command, char **argv, int argc)
        VEC_iterate (memory_read_result_s, result, ix, read_result);
        ++ix)
     {
-      struct cleanup *t = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
+      ui_out_emit_tuple tuple_emitter (uiout, NULL);
       char *data, *p;
       int i;
       int alloc_len;
@@ -1649,7 +1634,6 @@  mi_cmd_data_read_memory_bytes (const char *command, char **argv, int argc)
 	}
       uiout->field_string ("contents", data);
       xfree (data);
-      do_cleanups (t);
     }
   do_cleanups (cleanups);
 }
@@ -2385,19 +2369,18 @@  mi_load_progress (const char *section_name,
 		 strcmp (previous_sect_name, section_name) : 1);
   if (new_section)
     {
-      struct cleanup *cleanup_tuple;
-
       xfree (previous_sect_name);
       previous_sect_name = xstrdup (section_name);
 
       if (current_token)
 	fputs_unfiltered (current_token, mi->raw_stdout);
       fputs_unfiltered ("+download", mi->raw_stdout);
-      cleanup_tuple = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
-      uiout->field_string ("section", section_name);
-      uiout->field_int ("section-size", total_section);
-      uiout->field_int ("total-size", grand_total);
-      do_cleanups (cleanup_tuple);
+      {
+	ui_out_emit_tuple tuple_emitter (uiout, NULL);
+	uiout->field_string ("section", section_name);
+	uiout->field_int ("section-size", total_section);
+	uiout->field_int ("total-size", grand_total);
+      }
       mi_out_put (uiout, mi->raw_stdout);
       fputs_unfiltered ("\n", mi->raw_stdout);
       gdb_flush (mi->raw_stdout);
@@ -2406,19 +2389,18 @@  mi_load_progress (const char *section_name,
   steady_clock::time_point time_now = steady_clock::now ();
   if (time_now - last_update > milliseconds (500))
     {
-      struct cleanup *cleanup_tuple;
-
       last_update = time_now;
       if (current_token)
 	fputs_unfiltered (current_token, mi->raw_stdout);
       fputs_unfiltered ("+download", mi->raw_stdout);
-      cleanup_tuple = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
-      uiout->field_string ("section", section_name);
-      uiout->field_int ("section-sent", sent_so_far);
-      uiout->field_int ("section-size", total_section);
-      uiout->field_int ("total-sent", total_sent);
-      uiout->field_int ("total-size", grand_total);
-      do_cleanups (cleanup_tuple);
+      {
+	ui_out_emit_tuple tuple_emitter (uiout, NULL);
+	uiout->field_string ("section", section_name);
+	uiout->field_int ("section-sent", sent_so_far);
+	uiout->field_int ("section-size", total_section);
+	uiout->field_int ("total-sent", total_sent);
+	uiout->field_int ("total-size", grand_total);
+      }
       mi_out_put (uiout, mi->raw_stdout);
       fputs_unfiltered ("\n", mi->raw_stdout);
       gdb_flush (mi->raw_stdout);
@@ -2888,12 +2870,11 @@  mi_cmd_trace_frame_collected (const char *command, char **argv, int argc)
 
     for (i = 0; VEC_iterate (int, tinfo->tvars, i, tvar); i++)
       {
-	struct cleanup *cleanup_child;
 	struct trace_state_variable *tsv;
 
 	tsv = find_trace_state_variable_by_number (tvar);
 
-	cleanup_child = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
+	ui_out_emit_tuple tuple_emitter (uiout, NULL);
 
 	if (tsv != NULL)
 	  {
@@ -2911,8 +2892,6 @@  mi_cmd_trace_frame_collected (const char *command, char **argv, int argc)
 	    uiout->field_skip ("name");
 	    uiout->field_skip ("current");
 	  }
-
-	do_cleanups (cleanup_child);
       }
 
     do_cleanups (list_cleanup);
diff --git a/gdb/mi/mi-symbol-cmds.c b/gdb/mi/mi-symbol-cmds.c
index 6614447..f9e464d 100644
--- a/gdb/mi/mi-symbol-cmds.c
+++ b/gdb/mi/mi-symbol-cmds.c
@@ -33,7 +33,7 @@  mi_cmd_symbol_list_lines (const char *command, char **argv, int argc)
   char *filename;
   struct symtab *s;
   int i;
-  struct cleanup *cleanup_stack, *cleanup_tuple;
+  struct cleanup *cleanup_stack;
   struct ui_out *uiout = current_uiout;
 
   if (argc != 1)
@@ -55,10 +55,9 @@  mi_cmd_symbol_list_lines (const char *command, char **argv, int argc)
   if (SYMTAB_LINETABLE (s) != NULL && SYMTAB_LINETABLE (s)->nitems > 0)
     for (i = 0; i < SYMTAB_LINETABLE (s)->nitems; i++)
     {
-      cleanup_tuple = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
+      ui_out_emit_tuple tuple_emitter (uiout, NULL);
       uiout->field_core_addr ("pc", gdbarch, SYMTAB_LINETABLE (s)->item[i].pc);
       uiout->field_int ("line", SYMTAB_LINETABLE (s)->item[i].line);
-      do_cleanups (cleanup_tuple);
     }
 
   do_cleanups (cleanup_stack);
diff --git a/gdb/osdata.c b/gdb/osdata.c
index 84c4ed7..b9014dd 100644
--- a/gdb/osdata.c
+++ b/gdb/osdata.c
@@ -381,27 +381,26 @@  info_osdata (const char *type)
                        ix_items, item);
           ix_items++)
        {
-         struct cleanup *old_chain;
          int ix_cols;
          struct osdata_column *col;
 
-         old_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "item");
+	 {
+	   ui_out_emit_tuple tuple_emitter (uiout, "item");
 
-         for (ix_cols = 0;
-              VEC_iterate (osdata_column_s, item->columns,
-                           ix_cols, col);
-              ix_cols++)
-	   {
-	     char col_name[32];
+	   for (ix_cols = 0;
+		VEC_iterate (osdata_column_s, item->columns,
+			     ix_cols, col);
+		ix_cols++)
+	     {
+	       char col_name[32];
 
-	     if (ix_cols == col_to_skip)
-	       continue;
+	       if (ix_cols == col_to_skip)
+		 continue;
 
-	     snprintf (col_name, 32, "col%d", ix_cols);
-	     uiout->field_string (col_name, col->value);
-	   }
-	 
-         do_cleanups (old_chain);
+	       snprintf (col_name, 32, "col%d", ix_cols);
+	       uiout->field_string (col_name, col->value);
+	     }
+	 }
 
          uiout->text ("\n");
        }
diff --git a/gdb/probe.c b/gdb/probe.c
index c147810..e65e031 100644
--- a/gdb/probe.c
+++ b/gdb/probe.c
@@ -678,10 +678,9 @@  info_probes_for_ops (const char *arg, int from_tty,
 
   for (i = 0; VEC_iterate (bound_probe_s, probes, i, probe); ++i)
     {
-      struct cleanup *inner;
       const char *probe_type = probe->probe->pops->type_name (probe->probe);
 
-      inner = make_cleanup_ui_out_tuple_begin_end (current_uiout, "probe");
+      ui_out_emit_tuple tuple_emitter (current_uiout, "probe");
 
       current_uiout->field_string ("type",probe_type);
       current_uiout->field_string ("provider", probe->probe->provider);
@@ -708,8 +707,6 @@  info_probes_for_ops (const char *arg, int from_tty,
       current_uiout->field_string ("object",
 			   objfile_name (probe->objfile));
       current_uiout->text ("\n");
-
-      do_cleanups (inner);
     }
 
   any_found = !VEC_empty (bound_probe_s, probes);
diff --git a/gdb/progspace.c b/gdb/progspace.c
index 4efbafe..b37701e 100644
--- a/gdb/progspace.c
+++ b/gdb/progspace.c
@@ -310,14 +310,13 @@  print_program_space (struct ui_out *uiout, int requested)
 
   ALL_PSPACES (pspace)
     {
-      struct cleanup *chain2;
       struct inferior *inf;
       int printed_header;
 
       if (requested != -1 && requested != pspace->num)
 	continue;
 
-      chain2 = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
+      ui_out_emit_tuple tuple_emitter (uiout, NULL);
 
       if (pspace == current_program_space)
 	uiout->field_string ("current", "*");
@@ -354,7 +353,6 @@  print_program_space (struct ui_out *uiout, int requested)
 	  }
 
       uiout->text ("\n");
-      do_cleanups (chain2);
     }
 
   do_cleanups (old_chain);
diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c
index 61fba1e..d4f1bcf 100644
--- a/gdb/record-btrace.c
+++ b/gdb/record-btrace.c
@@ -725,13 +725,11 @@  record_btrace_insn_history (struct target_ops *self, int size, int flags)
   struct btrace_thread_info *btinfo;
   struct btrace_insn_history *history;
   struct btrace_insn_iterator begin, end;
-  struct cleanup *uiout_cleanup;
   struct ui_out *uiout;
   unsigned int context, covered;
 
   uiout = current_uiout;
-  uiout_cleanup = make_cleanup_ui_out_tuple_begin_end (uiout,
-						       "insn history");
+  ui_out_emit_tuple tuple_emitter (uiout, "insn history");
   context = abs (size);
   if (context == 0)
     error (_("Bad record instruction-history-size."));
@@ -800,7 +798,6 @@  record_btrace_insn_history (struct target_ops *self, int size, int flags)
     }
 
   btrace_set_insn_history (btinfo, &begin, &end);
-  do_cleanups (uiout_cleanup);
 }
 
 /* The to_insn_history_range method of target record-btrace.  */
@@ -812,14 +809,12 @@  record_btrace_insn_history_range (struct target_ops *self,
   struct btrace_thread_info *btinfo;
   struct btrace_insn_history *history;
   struct btrace_insn_iterator begin, end;
-  struct cleanup *uiout_cleanup;
   struct ui_out *uiout;
   unsigned int low, high;
   int found;
 
   uiout = current_uiout;
-  uiout_cleanup = make_cleanup_ui_out_tuple_begin_end (uiout,
-						       "insn history");
+  ui_out_emit_tuple tuple_emitter (uiout, "insn history");
   low = from;
   high = to;
 
@@ -852,8 +847,6 @@  record_btrace_insn_history_range (struct target_ops *self,
 
   btrace_insn_history (uiout, btinfo, &begin, &end, flags);
   btrace_set_insn_history (btinfo, &begin, &end);
-
-  do_cleanups (uiout_cleanup);
 }
 
 /* The to_insn_history_from method of target record-btrace.  */
@@ -1085,14 +1078,12 @@  record_btrace_call_history (struct target_ops *self, int size, int int_flags)
   struct btrace_thread_info *btinfo;
   struct btrace_call_history *history;
   struct btrace_call_iterator begin, end;
-  struct cleanup *uiout_cleanup;
   struct ui_out *uiout;
   unsigned int context, covered;
   record_print_flags flags = (enum record_print_flag) int_flags;
 
   uiout = current_uiout;
-  uiout_cleanup = make_cleanup_ui_out_tuple_begin_end (uiout,
-						       "insn history");
+  ui_out_emit_tuple tuple_emitter (uiout, "insn history");
   context = abs (size);
   if (context == 0)
     error (_("Bad record function-call-history-size."));
@@ -1164,7 +1155,6 @@  record_btrace_call_history (struct target_ops *self, int size, int int_flags)
     }
 
   btrace_set_call_history (btinfo, &begin, &end);
-  do_cleanups (uiout_cleanup);
 }
 
 /* The to_call_history_range method of target record-btrace.  */
@@ -1177,15 +1167,13 @@  record_btrace_call_history_range (struct target_ops *self,
   struct btrace_thread_info *btinfo;
   struct btrace_call_history *history;
   struct btrace_call_iterator begin, end;
-  struct cleanup *uiout_cleanup;
   struct ui_out *uiout;
   unsigned int low, high;
   int found;
   record_print_flags flags = (enum record_print_flag) int_flags;
 
   uiout = current_uiout;
-  uiout_cleanup = make_cleanup_ui_out_tuple_begin_end (uiout,
-						       "func history");
+  ui_out_emit_tuple tuple_emitter (uiout, "func history");
   low = from;
   high = to;
 
@@ -1218,8 +1206,6 @@  record_btrace_call_history_range (struct target_ops *self,
 
   btrace_call_history (uiout, btinfo, &begin, &end, flags);
   btrace_set_call_history (btinfo, &begin, &end);
-
-  do_cleanups (uiout_cleanup);
 }
 
 /* The to_call_history_from method of target record-btrace.  */
diff --git a/gdb/remote.c b/gdb/remote.c
index 694897d..2cd9850 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -13799,11 +13799,10 @@  show_remote_cmd (char *args, int from_tty)
 {
   /* We can't just use cmd_show_list here, because we want to skip
      the redundant "show remote Z-packet" and the legacy aliases.  */
-  struct cleanup *showlist_chain;
   struct cmd_list_element *list = remote_show_cmdlist;
   struct ui_out *uiout = current_uiout;
 
-  showlist_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "showlist");
+  ui_out_emit_tuple tuple_emitter (uiout, "showlist");
   for (; list != NULL; list = list->next)
     if (strcmp (list->name, "Z-packet") == 0)
       continue;
@@ -13813,8 +13812,7 @@  show_remote_cmd (char *args, int from_tty)
       continue;
     else
       {
-	struct cleanup *option_chain
-	  = make_cleanup_ui_out_tuple_begin_end (uiout, "option");
+	ui_out_emit_tuple option_emitter (uiout, "option");
 
 	uiout->field_string ("name", list->name);
 	uiout->text (":  ");
@@ -13822,12 +13820,7 @@  show_remote_cmd (char *args, int from_tty)
 	  do_show_command (NULL, from_tty, list);
 	else
 	  cmd_func (list, NULL, from_tty);
-	/* Close the tuple.  */
-	do_cleanups (option_chain);
       }
-
-  /* Close the tuple.  */
-  do_cleanups (showlist_chain);
 }
 
 
diff --git a/gdb/skip.c b/gdb/skip.c
index 26ff000..4bd8a9e 100644
--- a/gdb/skip.c
+++ b/gdb/skip.c
@@ -395,14 +395,12 @@  skip_info (char *arg, int from_tty)
 
   ALL_SKIPLIST_ENTRIES (e)
     {
-      struct cleanup *entry_chain;
 
       QUIT;
       if (arg != NULL && !number_is_in_list (arg, e->number))
 	continue;
 
-      entry_chain = make_cleanup_ui_out_tuple_begin_end (current_uiout,
-							 "blklst-entry");
+      ui_out_emit_tuple tuple_emitter (current_uiout, "blklst-entry");
       current_uiout->field_int ("number", e->number); /* 1 */
 
       if (e->enabled)
@@ -426,7 +424,6 @@  skip_info (char *arg, int from_tty)
 	"function", e->function ? e->function : "<none>"); /* 6 */
 
       current_uiout->text ("\n");
-      do_cleanups (entry_chain);
     }
 
   do_cleanups (tbl_chain);
diff --git a/gdb/solib.c b/gdb/solib.c
index af94383..491c18a 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -1090,14 +1090,12 @@  info_sharedlibrary_command (char *pattern, int from_tty)
 
   ALL_SO_LIBS (so)
     {
-      struct cleanup *lib_cleanup;
-
       if (! so->so_name[0])
 	continue;
       if (pattern && ! re_exec (so->so_name))
 	continue;
 
-      lib_cleanup = make_cleanup_ui_out_tuple_begin_end (uiout, "lib");
+      ui_out_emit_tuple tuple_emitter (uiout, "lib");
 
       if (so->addr_high != 0)
 	{
@@ -1123,8 +1121,6 @@  info_sharedlibrary_command (char *pattern, int from_tty)
       uiout->field_string ("name", so->so_name);
 
       uiout->text ("\n");
-
-      do_cleanups (lib_cleanup);
     }
 
   do_cleanups (table_cleanup);
diff --git a/gdb/stack.c b/gdb/stack.c
index 1bad88e..32acca1 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -805,8 +805,7 @@  print_frame_info (struct frame_info *frame, int print_level,
       || get_frame_type (frame) == SIGTRAMP_FRAME
       || get_frame_type (frame) == ARCH_FRAME)
     {
-      struct cleanup *uiout_cleanup
-	= make_cleanup_ui_out_tuple_begin_end (uiout, "frame");
+      ui_out_emit_tuple tuple_emitter (uiout, "frame");
 
       annotate_frame_begin (print_level ? frame_relative_level (frame) : 0,
 			    gdbarch, get_frame_pc (frame));
@@ -851,7 +850,6 @@  print_frame_info (struct frame_info *frame, int print_level,
 	do_gdb_disassembly (get_frame_arch (frame), 1,
 			    get_frame_pc (frame), get_frame_pc (frame) + 1);
 
-      do_cleanups (uiout_cleanup);
       return;
     }
 
diff --git a/gdb/thread.c b/gdb/thread.c
index 88fd521..c0776a2 100644
--- a/gdb/thread.c
+++ b/gdb/thread.c
@@ -719,26 +719,25 @@  do_captured_list_thread_ids (struct ui_out *uiout, void *arg)
 {
   struct thread_info *tp;
   int num = 0;
-  struct cleanup *cleanup_chain;
   int current_thread = -1;
 
   update_thread_list ();
 
-  cleanup_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "thread-ids");
-
-  for (tp = thread_list; tp; tp = tp->next)
-    {
-      if (tp->state == THREAD_EXITED)
-	continue;
+  {
+    ui_out_emit_tuple tuple_emitter (uiout, "thread-ids");
 
-      if (tp->ptid == inferior_ptid)
-	current_thread = tp->global_num;
+    for (tp = thread_list; tp; tp = tp->next)
+      {
+	if (tp->state == THREAD_EXITED)
+	  continue;
 
-      num++;
-      uiout->field_int ("thread-id", tp->global_num);
-    }
+	if (tp->ptid == inferior_ptid)
+	  current_thread = tp->global_num;
 
-  do_cleanups (cleanup_chain);
+	num++;
+	uiout->field_int ("thread-id", tp->global_num);
+      }
+  }
 
   if (current_thread != -1)
     uiout->field_int ("current-thread-id", current_thread);
@@ -1300,14 +1299,13 @@  print_thread_info_1 (struct ui_out *uiout, char *requested_threads,
 
   ALL_THREADS_BY_INFERIOR (inf, tp)
     {
-      struct cleanup *chain2;
       int core;
 
       if (!should_print_thread (requested_threads, default_inf_num,
 				global_ids, pid, tp))
 	continue;
 
-      chain2 = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
+      ui_out_emit_tuple tuple_emitter (uiout, NULL);
 
       if (uiout->is_mi_like_p ())
 	{
@@ -1395,8 +1393,6 @@  print_thread_info_1 (struct ui_out *uiout, char *requested_threads,
       core = target_core_of_thread (tp->ptid);
       if (uiout->is_mi_like_p () && core != -1)
 	uiout->field_int ("core", core);
-
-      do_cleanups (chain2);
     }
 
   /* Restores the current thread and the frame selected before