[RFA 12/13] Introduce gdb_breakpoint_up

Tom Tromey
2017-11-02T22:36:24Z

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-02 Tom Tromey <tom@tromey.com>

* breakpoint.c (set_momentary_breakpoint): Return
gdb_breakpoint_up.
(until_break_command): Update.
(new_until_break_fsm): Change argument types to
gdb_breakpoint_up.
(set_momentary_breakpoint_at_pc): Return gdb_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 gdb_breakpoint_up.
(make_cleanup_delete_breakpoint): Remove.
(struct gdb_breakpoint_deleter): New.
(gdb_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 | 24 ++++++++++++++++++++++++
gdb/arm-linux-tdep.c | 2 +-
gdb/breakpoint.c | 35 +++++++++++------------------------
gdb/breakpoint.h | 21 +++++++++++++++------
gdb/elfread.c | 7 ++++---
gdb/infcall.c | 5 +++--
gdb/infcmd.c | 2 +-
gdb/infrun.c | 9 +++++----
8 files changed, 64 insertions(+), 41 deletions(-)

diff --git a/gdb/arm-linux-tdep.c b/gdb/arm-linux-tdep.c
index 525474c4db..7769c9c2e2 100644
--- a/gdb/arm-linux-tdep.c
+++ b/gdb/arm-linux-tdep.c
@@ -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;
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 61e41283b1..7237e81b41 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -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 *
+gdb_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 gdb_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 *
+gdb_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)
+ gdb_breakpoint_up &&location_breakpoint,
+ gdb_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. */

+ gdb_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;

+ gdb_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. */

diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index 69b63ea932..494d05aa7d 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -1223,10 +1223,23 @@ 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 gdb_breakpoint_deleter
+{
+ void operator() (struct breakpoint *b) const
+ {
+ delete_breakpoint (b);
+ }
+};
+
+typedef std::unique_ptr<struct breakpoint, gdb_breakpoint_deleter>
+ gdb_breakpoint_up;
+
+extern gdb_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 gdb_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 +1248,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 *);
diff --git a/gdb/elfread.c b/gdb/elfread.c
index 4e110716c3..cdef5a8c59 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -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;
diff --git a/gdb/infcall.c b/gdb/infcall.c
index 03749f3dc2..b06758085d 100644
--- a/gdb/infcall.c
+++ b/gdb/infcall.c
@@ -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;
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 669631bdb4..49349c169e 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -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;
diff --git a/gdb/infrun.c b/gdb/infrun.c
index ef5a505d89..d425664957 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -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;
}
--
2.13.6