[RFA,1/8] Change record_full_gdb_operation_disable_set not to return a cleanup

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

Commit Message

Tom Tromey Oct. 1, 2017, 4:06 a.m. UTC
  This changes record_full_gdb_operation_disable_set to return a
scoped_restore rather than a cleanup, and fixes all the users.

ChangeLog
2017-09-30  Tom Tromey  <tom@tromey.com>

	* record-full.h (record_full_gdb_operation_disable_set): Return
	scoped_restore_tmpl<int>.
	* infrun.c (adjust_pc_after_break): Update.
	(handle_signal_stop): Update.
	* record-full.c (record_full_gdb_operation_disable_set): Return
	scoped_restore_tmpl<int>.
	(record_full_wait_1, record_full_insert_breakpoint)
	(record_full_remove_breakpoint, record_full_save)
	(record_full_goto_insn): Update.
---
 gdb/ChangeLog     | 12 ++++++++++++
 gdb/infrun.c      | 15 +++++++--------
 gdb/record-full.c | 34 ++++++++++++----------------------
 gdb/record-full.h |  2 +-
 4 files changed, 32 insertions(+), 31 deletions(-)
  

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index ed5d20c..a415c18 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,15 @@ 
+2017-09-30  Tom Tromey  <tom@tromey.com>
+
+	* record-full.h (record_full_gdb_operation_disable_set): Return
+	scoped_restore_tmpl<int>.
+	* infrun.c (adjust_pc_after_break): Update.
+	(handle_signal_stop): Update.
+	* record-full.c (record_full_gdb_operation_disable_set): Return
+	scoped_restore_tmpl<int>.
+	(record_full_wait_1, record_full_insert_breakpoint)
+	(record_full_remove_breakpoint, record_full_save)
+	(record_full_goto_insn): Update.
+
 2017-09-29  Tom Tromey  <tom@tromey.com>
 
 	* target.c (read_whatever_is_readable): Change type of "result".
diff --git a/gdb/infrun.c b/gdb/infrun.c
index fba0079..e82f61f 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -4178,10 +4178,11 @@  adjust_pc_after_break (struct thread_info *thread,
       || (target_is_non_stop_p ()
 	  && moribund_breakpoint_here_p (aspace, breakpoint_pc)))
     {
-      struct cleanup *old_cleanups = make_cleanup (null_cleanup, NULL);
+      gdb::optional<scoped_restore_tmpl<int>> restore_operation_disable;
 
       if (record_full_is_used ())
-	record_full_gdb_operation_disable_set ();
+	restore_operation_disable.emplace
+	  (record_full_gdb_operation_disable_set ());
 
       /* When using hardware single-step, a SIGTRAP is reported for both
 	 a completed single-step and a software breakpoint.  Need to
@@ -4205,8 +4206,6 @@  adjust_pc_after_break (struct thread_info *thread,
 	  || (thread->stepped_breakpoint
 	      && thread->prev_pc == breakpoint_pc))
 	regcache_write_pc (regcache, breakpoint_pc);
-
-      do_cleanups (old_cleanups);
     }
 }
 
@@ -6008,14 +6007,14 @@  handle_signal_stop (struct execution_control_state *ecs)
 	  decr_pc = gdbarch_decr_pc_after_break (gdbarch);
 	  if (decr_pc != 0)
 	    {
-	      struct cleanup *old_cleanups = make_cleanup (null_cleanup, NULL);
+	      gdb::optional<scoped_restore_tmpl<int>>
+		restore_operation_disable;
 
 	      if (record_full_is_used ())
-		record_full_gdb_operation_disable_set ();
+		restore_operation_disable.emplace
+		  (record_full_gdb_operation_disable_set ());
 
 	      regcache_write_pc (regcache, stop_pc + decr_pc);
-
-	      do_cleanups (old_cleanups);
 	    }
 	}
       else
diff --git a/gdb/record-full.c b/gdb/record-full.c
index 5073be3..5bd8900 100644
--- a/gdb/record-full.c
+++ b/gdb/record-full.c
@@ -670,16 +670,10 @@  record_full_message_wrapper_safe (struct regcache *regcache,
 
 static int record_full_gdb_operation_disable = 0;
 
-struct cleanup *
+scoped_restore_tmpl<int>
 record_full_gdb_operation_disable_set (void)
 {
-  struct cleanup *old_cleanups = NULL;
-
-  old_cleanups =
-    make_cleanup_restore_integer (&record_full_gdb_operation_disable);
-  record_full_gdb_operation_disable = 1;
-
-  return old_cleanups;
+  return make_scoped_restore (&record_full_gdb_operation_disable, 1);
 }
 
 /* Flag set to TRUE for target_stopped_by_watchpoint.  */
@@ -1051,7 +1045,8 @@  record_full_wait_1 (struct target_ops *ops,
 		    ptid_t ptid, struct target_waitstatus *status,
 		    int options)
 {
-  struct cleanup *set_cleanups = record_full_gdb_operation_disable_set ();
+  scoped_restore restore_operation_disable
+    = record_full_gdb_operation_disable_set ();
 
   if (record_debug)
     fprintf_unfiltered (gdb_stdlog,
@@ -1334,7 +1329,6 @@  replay_out:
 
   signal (SIGINT, handle_sigint);
 
-  do_cleanups (set_cleanups);
   return inferior_ptid;
 }
 
@@ -1653,12 +1647,11 @@  record_full_insert_breakpoint (struct target_ops *ops,
 	 However, we do have to insert software single-step
 	 breakpoints, in case the target can't hardware step.  To keep
 	 things simple, we always insert.  */
-      struct cleanup *old_cleanups;
       int ret;
 
-      old_cleanups = record_full_gdb_operation_disable_set ();
+      scoped_restore restore_operation_disable
+	= record_full_gdb_operation_disable_set ();
       ret = ops->beneath->to_insert_breakpoint (ops->beneath, gdbarch, bp_tgt);
-      do_cleanups (old_cleanups);
 
       if (ret != 0)
 	return ret;
@@ -1711,14 +1704,12 @@  record_full_remove_breakpoint (struct target_ops *ops,
 	{
 	  if (bp->in_target_beneath)
 	    {
-	      struct cleanup *old_cleanups;
 	      int ret;
 
-	      old_cleanups = record_full_gdb_operation_disable_set ();
+	      scoped_restore restore_operation_disable
+		= record_full_gdb_operation_disable_set ();
 	      ret = ops->beneath->to_remove_breakpoint (ops->beneath, gdbarch,
 							bp_tgt, reason);
-	      do_cleanups (old_cleanups);
-
 	      if (ret != 0)
 		return ret;
 	    }
@@ -2549,7 +2540,6 @@  record_full_save (struct target_ops *self, const char *recfilename)
   uint32_t magic;
   struct regcache *regcache;
   struct gdbarch *gdbarch;
-  struct cleanup *set_cleanups;
   int save_size = 0;
   asection *osec = NULL;
   int bfd_offset = 0;
@@ -2573,7 +2563,8 @@  record_full_save (struct target_ops *self, const char *recfilename)
   gdbarch = get_regcache_arch (regcache);
 
   /* Disable the GDB operation record.  */
-  set_cleanups = record_full_gdb_operation_disable_set ();
+  scoped_restore restore_operation_disable
+    = record_full_gdb_operation_disable_set ();
 
   /* Reverse execute to the begin of record list.  */
   while (1)
@@ -2737,7 +2728,6 @@  record_full_save (struct target_ops *self, const char *recfilename)
         record_full_list = record_full_list->prev;
     }
 
-  do_cleanups (set_cleanups);
   unlink_file.keep ();
 
   /* Succeeded.  */
@@ -2753,7 +2743,8 @@  static void
 record_full_goto_insn (struct record_full_entry *entry,
 		       enum exec_direction_kind dir)
 {
-  struct cleanup *set_cleanups = record_full_gdb_operation_disable_set ();
+  scoped_restore restore_operation_disable
+    = record_full_gdb_operation_disable_set ();
   struct regcache *regcache = get_current_regcache ();
   struct gdbarch *gdbarch = get_regcache_arch (regcache);
 
@@ -2771,7 +2762,6 @@  record_full_goto_insn (struct record_full_entry *entry,
       else
 	record_full_list = record_full_list->next;
     } while (record_full_list != entry);
-  do_cleanups (set_cleanups);
 }
 
 /* Alias for "target record-full".  */
diff --git a/gdb/record-full.h b/gdb/record-full.h
index 7d53b63..728bf59 100644
--- a/gdb/record-full.h
+++ b/gdb/record-full.h
@@ -29,6 +29,6 @@  extern int record_full_arch_list_add_end (void);
 /* Returns true if the process record target is open.  */
 extern int record_full_is_used (void);
 
-extern struct cleanup *record_full_gdb_operation_disable_set (void);
+extern scoped_restore_tmpl<int> record_full_gdb_operation_disable_set ();
 
 #endif /* RECORD_FULL_H */