Introduce gdb_breakpoint_up
authorTom Tromey <tom@tromey.com>
Thu, 2 Nov 2017 04:32:45 +0000 (22:32 -0600)
committerTom Tromey <tom@tromey.com>
Sat, 4 Nov 2017 16:27:20 +0000 (10:27 -0600)
This introduces gdb_breakpoint_up, a unique_ptr typedef that owns a
breakpoint.  It then changes set_momentary_breakpoint to return a
gdb_breakpoint_up and fixes up the fallout.  This then allows the
removal of make_cleanup_delete_breakpoint.

Once breakpoints are fully C++-ified, this typedef can be removed in
favor of a plain std::unique_ptr.

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

* breakpoint.c (set_momentary_breakpoint): Return
breakpoint_up.
(until_break_command): Update.
(new_until_break_fsm): Change argument types to
breakpoint_up.
(set_momentary_breakpoint_at_pc): Return breakpoint_up.
(do_delete_breakpoint_cleanup, make_cleanup_delete_breakpoint):
Remove.
* infcmd.c (finish_forward): Update.
* breakpoint.h (set_momentary_breakpoint)
(set_momentary_breakpoint_at_pc): Return breakpoint_up.
(make_cleanup_delete_breakpoint): Remove.
(struct breakpoint_deleter): New.
(breakpoint_up): New typedef.
* infrun.c (insert_step_resume_breakpoint_at_sal_1): Update.
(insert_exception_resume_breakpoint): Update.
(insert_exception_resume_from_probe): Update.
(insert_longjmp_resume_breakpoint): Update.
* arm-linux-tdep.c (arm_linux_copy_svc): Update.
* elfread.c (elf_gnu_ifunc_resolver_stop): Update.
* infcall.c (call_function_by_hand_dummy): Update

gdb/ChangeLog
gdb/arm-linux-tdep.c
gdb/breakpoint.c
gdb/breakpoint.h
gdb/elfread.c
gdb/infcall.c
gdb/infcmd.c
gdb/infrun.c

index 04fee5e..e309283 100644 (file)
@@ -1,5 +1,29 @@
 2017-11-04  Tom Tromey  <tom@tromey.com>
 
+       * breakpoint.c (set_momentary_breakpoint): Return
+       breakpoint_up.
+       (until_break_command): Update.
+       (new_until_break_fsm): Change argument types to
+       breakpoint_up.
+       (set_momentary_breakpoint_at_pc): Return breakpoint_up.
+       (do_delete_breakpoint_cleanup, make_cleanup_delete_breakpoint):
+       Remove.
+       * infcmd.c (finish_forward): Update.
+       * breakpoint.h (set_momentary_breakpoint)
+       (set_momentary_breakpoint_at_pc): Return breakpoint_up.
+       (make_cleanup_delete_breakpoint): Remove.
+       (struct breakpoint_deleter): New.
+       (breakpoint_up): New typedef.
+       * infrun.c (insert_step_resume_breakpoint_at_sal_1): Update.
+       (insert_exception_resume_breakpoint): Update.
+       (insert_exception_resume_from_probe): Update.
+       (insert_longjmp_resume_breakpoint): Update.
+       * arm-linux-tdep.c (arm_linux_copy_svc): Update.
+       * elfread.c (elf_gnu_ifunc_resolver_stop): Update.
+       * infcall.c (call_function_by_hand_dummy): Update
+
+2017-11-04  Tom Tromey  <tom@tromey.com>
+
        * c-typeprint.c (c_type_print_base): Use gdb::unique_xmalloc_ptr.
 
 2017-11-04  Tom Tromey  <tom@tromey.com>
index 525474c..7769c9c 100644 (file)
@@ -1020,7 +1020,7 @@ arm_linux_copy_svc (struct gdbarch *gdbarch, struct regcache *regs,
        {
          inferior_thread ()->control.step_resume_breakpoint
            = set_momentary_breakpoint (gdbarch, sal, get_frame_id (frame),
-                                       bp_step_resume);
+                                       bp_step_resume).release ();
 
          /* set_momentary_breakpoint invalidates FRAME.  */
          frame = NULL;
index 61e4128..adc8950 100644 (file)
@@ -8582,7 +8582,7 @@ new_single_step_breakpoint (int thread, struct gdbarch *gdbarch)
    SAL.  If FRAME_ID is valid, the breakpoint is restricted to that
    frame.  */
 
-struct breakpoint *
+breakpoint_up
 set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal,
                          struct frame_id frame_id, enum bptype type)
 {
@@ -8605,7 +8605,7 @@ set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal,
 
   update_global_location_list_nothrow (UGLL_MAY_INSERT);
 
-  return b;
+  return breakpoint_up (b);
 }
 
 /* Make a momentary breakpoint based on the master breakpoint ORIG.
@@ -8658,7 +8658,7 @@ clone_momentary_breakpoint (struct breakpoint *orig)
   return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0);
 }
 
-struct breakpoint *
+breakpoint_up
 set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc,
                                enum bptype type)
 {
@@ -11146,8 +11146,8 @@ static struct thread_fsm_ops until_break_fsm_ops =
 
 static struct until_break_fsm *
 new_until_break_fsm (struct interp *cmd_interp, int thread,
-                    struct breakpoint *location_breakpoint,
-                    struct breakpoint *caller_breakpoint)
+                    breakpoint_up &&location_breakpoint,
+                    breakpoint_up &&caller_breakpoint)
 {
   struct until_break_fsm *sm;
 
@@ -11155,8 +11155,8 @@ new_until_break_fsm (struct interp *cmd_interp, int thread,
   thread_fsm_ctor (&sm->thread_fsm, &until_break_fsm_ops, cmd_interp);
 
   sm->thread = thread;
-  sm->location_breakpoint = location_breakpoint;
-  sm->caller_breakpoint = caller_breakpoint;
+  sm->location_breakpoint = location_breakpoint.release ();
+  sm->caller_breakpoint = caller_breakpoint.release ();
 
   return sm;
 }
@@ -11219,8 +11219,6 @@ until_break_command (const char *arg, int from_tty, int anywhere)
   struct gdbarch *frame_gdbarch;
   struct frame_id stack_frame_id;
   struct frame_id caller_frame_id;
-  struct breakpoint *location_breakpoint;
-  struct breakpoint *caller_breakpoint = NULL;
   struct cleanup *old_chain;
   int thread;
   struct thread_info *tp;
@@ -11269,6 +11267,7 @@ until_break_command (const char *arg, int from_tty, int anywhere)
   /* Keep within the current frame, or in frames called by the current
      one.  */
 
+  breakpoint_up caller_breakpoint;
   if (frame_id_p (caller_frame_id))
     {
       struct symtab_and_line sal2;
@@ -11281,7 +11280,6 @@ until_break_command (const char *arg, int from_tty, int anywhere)
                                                    sal2,
                                                    caller_frame_id,
                                                    bp_until);
-      make_cleanup_delete_breakpoint (caller_breakpoint);
 
       set_longjmp_breakpoint (tp, caller_frame_id);
       make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
@@ -11290,6 +11288,7 @@ until_break_command (const char *arg, int from_tty, int anywhere)
   /* set_momentary_breakpoint could invalidate FRAME.  */
   frame = NULL;
 
+  breakpoint_up location_breakpoint;
   if (anywhere)
     /* If the user told us to continue until a specified location,
        we don't specify a frame at which we need to stop.  */
@@ -11300,10 +11299,10 @@ until_break_command (const char *arg, int from_tty, int anywhere)
        only at the very same frame.  */
     location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
                                                    stack_frame_id, bp_until);
-  make_cleanup_delete_breakpoint (location_breakpoint);
 
   sm = new_until_break_fsm (command_interp (), tp->global_num,
-                           location_breakpoint, caller_breakpoint);
+                           std::move (location_breakpoint),
+                           std::move (caller_breakpoint));
   tp->thread_fsm = &sm->thread_fsm;
 
   discard_cleanups (old_chain);
@@ -13366,18 +13365,6 @@ delete_breakpoint (struct breakpoint *bpt)
   delete bpt;
 }
 
-static void
-do_delete_breakpoint_cleanup (void *b)
-{
-  delete_breakpoint ((struct breakpoint *) b);
-}
-
-struct cleanup *
-make_cleanup_delete_breakpoint (struct breakpoint *b)
-{
-  return make_cleanup (do_delete_breakpoint_cleanup, b);
-}
-
 /* Iterator function to call a user-provided callback function once
    for each of B and its related breakpoints.  */
 
index 69b63ea..aa06d11 100644 (file)
@@ -1223,10 +1223,22 @@ extern void breakpoint_re_set (void);
 
 extern void breakpoint_re_set_thread (struct breakpoint *);
 
-extern struct breakpoint *set_momentary_breakpoint
+extern void delete_breakpoint (struct breakpoint *);
+
+struct breakpoint_deleter
+{
+  void operator() (struct breakpoint *b) const
+  {
+    delete_breakpoint (b);
+  }
+};
+
+typedef std::unique_ptr<struct breakpoint, breakpoint_deleter> breakpoint_up;
+
+extern breakpoint_up set_momentary_breakpoint
   (struct gdbarch *, struct symtab_and_line, struct frame_id, enum bptype);
 
-extern struct breakpoint *set_momentary_breakpoint_at_pc
+extern breakpoint_up set_momentary_breakpoint_at_pc
   (struct gdbarch *, CORE_ADDR pc, enum bptype type);
 
 extern struct breakpoint *clone_momentary_breakpoint (struct breakpoint *bpkt);
@@ -1235,10 +1247,6 @@ extern void set_ignore_count (int, int, int);
 
 extern void breakpoint_init_inferior (enum inf_context);
 
-extern struct cleanup *make_cleanup_delete_breakpoint (struct breakpoint *);
-
-extern void delete_breakpoint (struct breakpoint *);
-
 extern void breakpoint_auto_delete (bpstat);
 
 typedef void (*walk_bp_location_callback) (struct bp_location *, void *);
index 4e11071..cdef5a8 100644 (file)
@@ -923,9 +923,10 @@ elf_gnu_ifunc_resolver_stop (struct breakpoint *b)
       sal.pc = prev_pc;
       sal.section = find_pc_overlay (sal.pc);
       sal.explicit_pc = 1;
-      b_return = set_momentary_breakpoint (get_frame_arch (prev_frame), sal,
-                                          prev_frame_id,
-                                          bp_gnu_ifunc_resolver_return);
+      b_return
+       = set_momentary_breakpoint (get_frame_arch (prev_frame), sal,
+                                   prev_frame_id,
+                                   bp_gnu_ifunc_resolver_return).release ();
 
       /* set_momentary_breakpoint invalidates PREV_FRAME.  */
       prev_frame = NULL;
index 03749f3..b067580 100644 (file)
@@ -1100,8 +1100,9 @@ call_function_by_hand_dummy (struct value *function,
     /* Sanity.  The exact same SP value is returned by
        PUSH_DUMMY_CALL, saved as the dummy-frame TOS, and used by
        dummy_id to form the frame ID's stack address.  */
-    breakpoint *bpt = set_momentary_breakpoint (gdbarch, sal,
-                                               dummy_id, bp_call_dummy);
+    breakpoint *bpt
+      = set_momentary_breakpoint (gdbarch, sal,
+                                 dummy_id, bp_call_dummy).release ();
 
     /* set_momentary_breakpoint invalidates FRAME.  */
     frame = NULL;
index 669631b..49349c1 100644 (file)
@@ -1986,7 +1986,7 @@ finish_forward (struct finish_command_fsm *sm, struct frame_info *frame)
 
   sm->breakpoint = set_momentary_breakpoint (gdbarch, sal,
                                             get_stack_frame_id (frame),
-                                            bp_finish);
+                                            bp_finish).release ();
 
   /* set_momentary_breakpoint invalidates FRAME.  */
   frame = NULL;
index ef5a505..d425664 100644 (file)
@@ -7402,7 +7402,7 @@ insert_step_resume_breakpoint_at_sal_1 (struct gdbarch *gdbarch,
                        paddress (gdbarch, sr_sal.pc));
 
   inferior_thread ()->control.step_resume_breakpoint
-    = set_momentary_breakpoint (gdbarch, sr_sal, sr_id, sr_type);
+    = set_momentary_breakpoint (gdbarch, sr_sal, sr_id, sr_type).release ();
 }
 
 void
@@ -7491,7 +7491,7 @@ insert_longjmp_resume_breakpoint (struct gdbarch *gdbarch, CORE_ADDR pc)
                        paddress (gdbarch, pc));
 
   inferior_thread ()->control.exception_resume_breakpoint =
-    set_momentary_breakpoint_at_pc (gdbarch, pc, bp_longjmp_resume);
+    set_momentary_breakpoint_at_pc (gdbarch, pc, bp_longjmp_resume).release ();
 }
 
 /* Insert an exception resume breakpoint.  TP is the thread throwing
@@ -7526,7 +7526,8 @@ insert_exception_resume_breakpoint (struct thread_info *tp,
                                (unsigned long) handler);
 
          bp = set_momentary_breakpoint_at_pc (get_frame_arch (frame),
-                                              handler, bp_exception_resume);
+                                              handler,
+                                              bp_exception_resume).release ();
 
          /* set_momentary_breakpoint_at_pc invalidates FRAME.  */
          frame = NULL;
@@ -7567,7 +7568,7 @@ insert_exception_resume_from_probe (struct thread_info *tp,
                                  handler));
 
   bp = set_momentary_breakpoint_at_pc (get_frame_arch (frame),
-                                      handler, bp_exception_resume);
+                                      handler, bp_exception_resume).release ();
   bp->thread = tp->global_num;
   inferior_thread ()->control.exception_resume_breakpoint = bp;
 }