Change record_full_gdb_operation_disable_set not to return a cleanup
authorTom Tromey <tom@tromey.com>
Sat, 30 Sep 2017 03:49:04 +0000 (21:49 -0600)
committerTom Tromey <tom@tromey.com>
Tue, 3 Oct 2017 11:33:44 +0000 (05:33 -0600)
This changes record_full_gdb_operation_disable_set to return a
scoped_restore rather than a cleanup, and fixes all the users.

ChangeLog
2017-10-03  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
gdb/infrun.c
gdb/record-full.c
gdb/record-full.h

index e0cf4c027099b4c289e5fa8bd2e77fcf5490e382..2415a07094ffd6a480bf61dcc6951e848f943c71 100644 (file)
@@ -1,3 +1,15 @@
+2017-10-03  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-10-02  Tom Tromey  <tom@tromey.com>
 
        PR rust/22236:
index fba00795ac7d39bb62d4458e98b59f570064946b..e82f61f079f47339797308efb9214e9c564d6649 100644 (file)
@@ -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
index 5073be3c5b7a329b9685008fadfb7762ce79514c..5bd890044e27647f3ba9b6eb38059615c26554e1 100644 (file)
@@ -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".  */
index 7d53b635e49e898578a585a3928839211cef35e8..728bf59958bf87dc55fe2e0cc3c424a53fe4fa7d 100644 (file)
@@ -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 */