From 73063f5180a07b9c8042887cd4cada0b89388556 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Sun, 1 May 2022 11:20:34 -0600 Subject: [PATCH] Remove init_raw_breakpoint_without_location This removes init_raw_breakpoint_without_location, replacing it with a constructor on 'breakpoint' itself. The subclasses and callers are all updated. --- gdb/ada-lang.c | 8 ++-- gdb/break-catch-exec.c | 7 ++- gdb/break-catch-fork.c | 8 ++-- gdb/break-catch-load.c | 8 ++-- gdb/break-catch-sig.c | 8 ++-- gdb/break-catch-syscall.c | 7 +-- gdb/break-catch-throw.c | 12 +++-- gdb/breakpoint.c | 95 ++++++++++++++++++++------------------- gdb/breakpoint.h | 24 +++++++--- 9 files changed, 105 insertions(+), 72 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index b11808acb71..8333671c48b 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -12122,8 +12122,10 @@ public: struct ada_catchpoint : public base_breakpoint { - explicit ada_catchpoint (enum ada_exception_catchpoint_kind kind) - : m_kind (kind) + ada_catchpoint (struct gdbarch *gdbarch_, + enum ada_exception_catchpoint_kind kind) + : base_breakpoint (gdbarch_, bp_catchpoint), + m_kind (kind) { } @@ -12757,7 +12759,7 @@ create_ada_exception_catchpoint (struct gdbarch *gdbarch, std::string addr_string; struct symtab_and_line sal = ada_exception_sal (ex_kind, &addr_string); - std::unique_ptr c (new ada_catchpoint (ex_kind)); + std::unique_ptr c (new ada_catchpoint (gdbarch, ex_kind)); init_ada_exception_breakpoint (c.get (), gdbarch, sal, addr_string.c_str (), tempflag, disabled, from_tty); c->excep_string = excep_string; diff --git a/gdb/break-catch-exec.c b/gdb/break-catch-exec.c index fbdc1c20e50..c828b50cc62 100644 --- a/gdb/break-catch-exec.c +++ b/gdb/break-catch-exec.c @@ -36,6 +36,11 @@ struct exec_catchpoint : public breakpoint { + explicit exec_catchpoint (struct gdbarch *gdbarch) + : breakpoint (gdbarch, bp_catchpoint) + { + } + int insert_location (struct bp_location *) override; int remove_location (struct bp_location *, enum remove_bp_reason reason) override; @@ -203,7 +208,7 @@ catch_exec_command_1 (const char *arg, int from_tty, if ((*arg != '\0') && !isspace (*arg)) error (_("Junk at end of arguments.")); - std::unique_ptr c (new exec_catchpoint ()); + std::unique_ptr c (new exec_catchpoint (gdbarch)); init_catchpoint (c.get (), gdbarch, temp, cond_string); install_breakpoint (0, std::move (c), 1); diff --git a/gdb/break-catch-fork.c b/gdb/break-catch-fork.c index 3ad4bafcf1c..913ccecba35 100644 --- a/gdb/break-catch-fork.c +++ b/gdb/break-catch-fork.c @@ -34,8 +34,9 @@ struct fork_catchpoint : public breakpoint { - explicit fork_catchpoint (bool is_vfork_) - : is_vfork (is_vfork_) + fork_catchpoint (struct gdbarch *gdbarch, bool is_vfork_) + : breakpoint (gdbarch, bp_catchpoint), + is_vfork (is_vfork_) { } @@ -185,7 +186,8 @@ create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, bool temp, const char *cond_string, bool is_vfork) { - std::unique_ptr c (new fork_catchpoint (is_vfork)); + std::unique_ptr c (new fork_catchpoint (gdbarch, + is_vfork)); init_catchpoint (c.get (), gdbarch, temp, cond_string); diff --git a/gdb/break-catch-load.c b/gdb/break-catch-load.c index 3e3bed2f861..8579f4e3b23 100644 --- a/gdb/break-catch-load.c +++ b/gdb/break-catch-load.c @@ -35,8 +35,9 @@ struct solib_catchpoint : public breakpoint { - solib_catchpoint (bool is_load_, const char *arg) - : is_load (is_load_), + solib_catchpoint (struct gdbarch *gdbarch, bool is_load_, const char *arg) + : breakpoint (gdbarch, bp_catchpoint), + is_load (is_load_), regex (arg == nullptr ? nullptr : make_unique_xstrdup (arg)), compiled (arg == nullptr ? nullptr @@ -228,7 +229,8 @@ add_solib_catchpoint (const char *arg, bool is_load, bool is_temp, bool enabled) if (*arg == '\0') arg = nullptr; - std::unique_ptr c (new solib_catchpoint (is_load, arg)); + std::unique_ptr c (new solib_catchpoint (gdbarch, + is_load, arg)); init_catchpoint (c.get (), gdbarch, is_temp, NULL); diff --git a/gdb/break-catch-sig.c b/gdb/break-catch-sig.c index 1c29a057d60..4430dd0b2b8 100644 --- a/gdb/break-catch-sig.c +++ b/gdb/break-catch-sig.c @@ -40,8 +40,10 @@ struct signal_catchpoint : public breakpoint { - signal_catchpoint (std::vector &&sigs, bool catch_all_) - : signals_to_be_caught (std::move (sigs)), + signal_catchpoint (struct gdbarch *gdbarch, std::vector &&sigs, + bool catch_all_) + : breakpoint (gdbarch, bp_catchpoint), + signals_to_be_caught (std::move (sigs)), catch_all (catch_all_) { } @@ -323,7 +325,7 @@ create_signal_catchpoint (int tempflag, std::vector &&filter, struct gdbarch *gdbarch = get_current_arch (); std::unique_ptr c - (new signal_catchpoint (std::move (filter), catch_all)); + (new signal_catchpoint (gdbarch, std::move (filter), catch_all)); init_catchpoint (c.get (), gdbarch, tempflag, nullptr); install_breakpoint (0, std::move (c), 1); diff --git a/gdb/break-catch-syscall.c b/gdb/break-catch-syscall.c index d25d7ba7c5e..5ed15ac8bf9 100644 --- a/gdb/break-catch-syscall.c +++ b/gdb/break-catch-syscall.c @@ -37,8 +37,9 @@ struct syscall_catchpoint : public breakpoint { - explicit syscall_catchpoint (std::vector &&calls) - : syscalls_to_be_caught (std::move (calls)) + syscall_catchpoint (struct gdbarch *gdbarch, std::vector &&calls) + : breakpoint (gdbarch, bp_catchpoint), + syscalls_to_be_caught (std::move (calls)) { } @@ -353,7 +354,7 @@ create_syscall_event_catchpoint (int tempflag, std::vector &&filter) struct gdbarch *gdbarch = get_current_arch (); std::unique_ptr c - (new syscall_catchpoint (std::move (filter))); + (new syscall_catchpoint (gdbarch, std::move (filter))); init_catchpoint (c.get (), gdbarch, tempflag, nullptr); install_breakpoint (0, std::move (c), 1); diff --git a/gdb/break-catch-throw.c b/gdb/break-catch-throw.c index 59e73da2c28..0237af7b2a7 100644 --- a/gdb/break-catch-throw.c +++ b/gdb/break-catch-throw.c @@ -67,9 +67,11 @@ static const struct exception_names exception_functions[] = struct exception_catchpoint : public base_breakpoint { - exception_catchpoint (enum exception_event_kind kind_, + exception_catchpoint (struct gdbarch *gdbarch, + enum exception_event_kind kind_, std::string &&except_rx) - : kind (kind_), + : base_breakpoint (gdbarch, bp_catchpoint), + kind (kind_), exception_rx (std::move (except_rx)), pattern (exception_rx.empty () ? nullptr @@ -366,10 +368,12 @@ handle_gnu_v3_exceptions (int tempflag, std::string &&except_rx, const char *cond_string, enum exception_event_kind ex_event, int from_tty) { + struct gdbarch *gdbarch = get_current_arch (); + std::unique_ptr cp - (new exception_catchpoint (ex_event, std::move (except_rx))); + (new exception_catchpoint (gdbarch, ex_event, std::move (except_rx))); - init_catchpoint (cp.get (), get_current_arch (), tempflag, cond_string); + init_catchpoint (cp.get (), gdbarch, tempflag, cond_string); cp->re_set (); diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index ef8a7001834..4c7542a52c8 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -258,6 +258,8 @@ static const struct breakpoint_ops tracepoint_probe_breakpoint_ops = /* The structure to be used in regular breakpoints. */ struct ordinary_breakpoint : public base_breakpoint { + using base_breakpoint::base_breakpoint; + int resources_needed (const struct bp_location *) override; enum print_stop_action print_it (const bpstat *bs) const override; void print_mention () const override; @@ -267,6 +269,8 @@ struct ordinary_breakpoint : public base_breakpoint /* Internal breakpoints. */ struct internal_breakpoint : public base_breakpoint { + using base_breakpoint::base_breakpoint; + void re_set () override; void check_status (struct bpstat *bs) override; enum print_stop_action print_it (const bpstat *bs) const override; @@ -276,6 +280,8 @@ struct internal_breakpoint : public base_breakpoint /* Momentary breakpoints. */ struct momentary_breakpoint : public base_breakpoint { + using base_breakpoint::base_breakpoint; + void re_set () override; void check_status (struct bpstat *bs) override; enum print_stop_action print_it (const bpstat *bs) const override; @@ -285,6 +291,8 @@ struct momentary_breakpoint : public base_breakpoint /* DPrintf breakpoints. */ struct dprintf_breakpoint : public ordinary_breakpoint { + using ordinary_breakpoint::ordinary_breakpoint; + void re_set () override; int breakpoint_hit (const struct bp_location *bl, const address_space *aspace, @@ -297,6 +305,11 @@ struct dprintf_breakpoint : public ordinary_breakpoint /* Ranged breakpoints. */ struct ranged_breakpoint : public ordinary_breakpoint { + explicit ranged_breakpoint (struct gdbarch *gdbarch) + : ordinary_breakpoint (gdbarch, bp_hardware_breakpoint) + { + } + int breakpoint_hit (const struct bp_location *bl, const address_space *aspace, CORE_ADDR bp_addr, @@ -312,6 +325,8 @@ struct ranged_breakpoint : public ordinary_breakpoint /* Static tracepoints with marker (`-m'). */ struct static_marker_tracepoint : public tracepoint { + using tracepoint::tracepoint; + std::vector decode_location (struct event_location *location, struct program_space *search_pspace) override; @@ -1193,6 +1208,8 @@ check_no_tracepoint_commands (struct command_line *commands) struct longjmp_breakpoint : public momentary_breakpoint { + using momentary_breakpoint::momentary_breakpoint; + ~longjmp_breakpoint () override; }; @@ -1219,7 +1236,7 @@ is_tracepoint (const struct breakpoint *b) TYPE. */ static std::unique_ptr -new_breakpoint_from_type (bptype type) +new_breakpoint_from_type (struct gdbarch *gdbarch, bptype type) { breakpoint *b; @@ -1227,21 +1244,21 @@ new_breakpoint_from_type (bptype type) { case bp_breakpoint: case bp_hardware_breakpoint: - b = new ordinary_breakpoint (); + b = new ordinary_breakpoint (gdbarch, type); break; case bp_fast_tracepoint: case bp_static_tracepoint: case bp_tracepoint: - b = new tracepoint (); + b = new tracepoint (gdbarch, type); break; case bp_static_marker_tracepoint: - b = new static_marker_tracepoint (); + b = new static_marker_tracepoint (gdbarch, type); break; case bp_dprintf: - b = new dprintf_breakpoint (); + b = new dprintf_breakpoint (gdbarch, type); break; case bp_overlay_event: @@ -1251,12 +1268,12 @@ new_breakpoint_from_type (bptype type) case bp_thread_event: case bp_jit_event: case bp_shlib_event: - b = new internal_breakpoint (); + b = new internal_breakpoint (gdbarch, type); break; case bp_longjmp: case bp_exception: - b = new longjmp_breakpoint (); + b = new longjmp_breakpoint (gdbarch, type); break; case bp_watchpoint_scope: @@ -1270,7 +1287,7 @@ new_breakpoint_from_type (bptype type) case bp_call_dummy: case bp_until: case bp_std_terminate: - b = new momentary_breakpoint (); + b = new momentary_breakpoint (gdbarch, type); break; default: @@ -7215,20 +7232,6 @@ add_to_breakpoint_chain (std::unique_ptr &&b) return result; } -/* Initializes breakpoint B with type BPTYPE and no locations yet. */ - -static void -init_raw_breakpoint_without_location (struct breakpoint *b, - struct gdbarch *gdbarch, - enum bptype bptype) -{ - b->type = bptype; - b->gdbarch = gdbarch; - b->language = current_language->la_language; - b->input_radix = input_radix; - b->related_breakpoint = b; -} - /* Helper to set_raw_breakpoint below. Creates a breakpoint that has type BPTYPE and has no locations as yet. */ @@ -7236,9 +7239,8 @@ static struct breakpoint * set_raw_breakpoint_without_location (struct gdbarch *gdbarch, enum bptype bptype) { - std::unique_ptr b = new_breakpoint_from_type (bptype); + std::unique_ptr b = new_breakpoint_from_type (gdbarch, bptype); - init_raw_breakpoint_without_location (b.get (), gdbarch, bptype); return add_to_breakpoint_chain (std::move (b)); } @@ -7303,11 +7305,9 @@ get_sal_arch (struct symtab_and_line sal) information regarding the creation of a new breakpoint. */ static void -init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, - struct symtab_and_line sal, enum bptype bptype) +init_raw_breakpoint (struct breakpoint *b, struct symtab_and_line sal, + enum bptype bptype) { - init_raw_breakpoint_without_location (b, gdbarch, bptype); - add_location_to_breakpoint (b, &sal); if (bptype != bp_catchpoint) @@ -7339,9 +7339,9 @@ static struct breakpoint * set_raw_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, enum bptype bptype) { - std::unique_ptr b = new_breakpoint_from_type (bptype); + std::unique_ptr b = new_breakpoint_from_type (gdbarch, bptype); - init_raw_breakpoint (b.get (), gdbarch, sal, bptype); + init_raw_breakpoint (b.get (), sal, bptype); return add_to_breakpoint_chain (std::move (b)); } @@ -7812,7 +7812,9 @@ init_catchpoint (struct breakpoint *b, symtab_and_line sal; sal.pspace = current_program_space; - init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint); + /* This should already have been set in the constructor. */ + gdb_assert (b->type == bp_catchpoint); + init_raw_breakpoint (b, sal, bp_catchpoint); if (cond_string == nullptr) b->cond_string.reset (); @@ -7944,9 +7946,8 @@ enable_breakpoints_after_startup (void) static struct breakpoint * new_single_step_breakpoint (int thread, struct gdbarch *gdbarch) { - std::unique_ptr b (new momentary_breakpoint ()); - - init_raw_breakpoint_without_location (b.get (), gdbarch, bp_single_step); + std::unique_ptr b (new momentary_breakpoint (gdbarch, + bp_single_step)); b->disposition = disp_donttouch; b->frame_id = null_frame_id; @@ -8325,7 +8326,7 @@ init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, if (&sal == &sals[0]) { - init_raw_breakpoint (b, gdbarch, sal, type); + init_raw_breakpoint (b, sal, type); b->thread = thread; b->task = task; @@ -8435,7 +8436,7 @@ create_breakpoint_sal (struct gdbarch *gdbarch, int enabled, int internal, unsigned flags, int display_canonical) { - std::unique_ptr b = new_breakpoint_from_type (type); + std::unique_ptr b = new_breakpoint_from_type (gdbarch, type); init_breakpoint_sal (b.get (), gdbarch, sals, std::move (location), @@ -8984,9 +8985,8 @@ create_breakpoint (struct gdbarch *gdbarch, } else { - std::unique_ptr b = new_breakpoint_from_type (type_wanted); - - init_raw_breakpoint_without_location (b.get (), gdbarch, type_wanted); + std::unique_ptr b = new_breakpoint_from_type (gdbarch, + type_wanted); b->location = copy_event_location (location); if (parse_extra) @@ -9432,9 +9432,8 @@ break_range_command (const char *arg, int from_tty) } /* Now set up the breakpoint. */ - std::unique_ptr br (new ranged_breakpoint ()); - init_raw_breakpoint (br.get (), get_current_arch (), - sal_start, bp_hardware_breakpoint); + std::unique_ptr br (new ranged_breakpoint (get_current_arch ())); + init_raw_breakpoint (br.get (), sal_start, bp_hardware_breakpoint); b = add_to_breakpoint_chain (std::move (br)); set_breakpoint_count (breakpoint_count + 1); @@ -9729,6 +9728,8 @@ watchpoint::explains_signal (enum gdb_signal sig) struct masked_watchpoint : public watchpoint { + using watchpoint::watchpoint; + int insert_location (struct bp_location *) override; int remove_location (struct bp_location *, enum remove_bp_reason reason) override; @@ -10164,10 +10165,9 @@ watch_command_1 (const char *arg, int accessflag, int from_tty, std::unique_ptr w; if (use_mask) - w.reset (new masked_watchpoint ()); + w.reset (new masked_watchpoint (nullptr, bp_type)); else - w.reset (new watchpoint ()); - init_raw_breakpoint_without_location (w.get (), nullptr, bp_type); + w.reset (new watchpoint (nullptr, bp_type)); w->thread = thread; w->task = task; @@ -10620,7 +10620,7 @@ init_ada_exception_breakpoint (struct breakpoint *b, enough for now, though. */ } - init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint); + init_raw_breakpoint (b, sal, bp_catchpoint); b->enable_state = enabled ? bp_enabled : bp_disabled; b->disposition = tempflag ? disp_del : disp_donttouch; @@ -12154,7 +12154,8 @@ strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, event_location_up location = copy_event_location (canonical->location.get ()); - std::unique_ptr tp (new tracepoint ()); + std::unique_ptr tp (new tracepoint (gdbarch, + type_wanted)); init_breakpoint_sal (tp.get (), gdbarch, lsal.sals[i], std::move (location), NULL, std::move (cond_string), diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h index 6923478f60a..356af45accd 100644 --- a/gdb/breakpoint.h +++ b/gdb/breakpoint.h @@ -620,7 +620,15 @@ using bp_location_range = next_range; struct breakpoint { - breakpoint () = default; + breakpoint (struct gdbarch *gdbarch_, enum bptype bptype) + : type (bptype), + gdbarch (gdbarch_), + language (current_language->la_language), + input_radix (::input_radix), + related_breakpoint (this) + { + } + DISABLE_COPY_AND_ASSIGN (breakpoint); virtual ~breakpoint () = default; @@ -784,11 +792,11 @@ struct breakpoint event_location_up location_range_end; /* Architecture we used to set the breakpoint. */ - struct gdbarch *gdbarch = NULL; + struct gdbarch *gdbarch; /* Language we used to set the breakpoint. */ - enum language language = language_unknown; + enum language language; /* Input radix we used to set the breakpoint. */ - int input_radix = 0; + int input_radix; /* String form of the breakpoint condition (malloc'd), or NULL if there is no condition. */ gdb::unique_xmalloc_ptr cond_string; @@ -801,7 +809,7 @@ struct breakpoint using watchpoints on local variables (might the concept of a related breakpoint be useful elsewhere, if not just call it the watchpoint_scope breakpoint or something like that. FIXME). */ - breakpoint *related_breakpoint = NULL; + breakpoint *related_breakpoint; /* Thread number for thread-specific breakpoint, or -1 if don't care. */ @@ -849,6 +857,8 @@ protected: breakpoints, etc.). */ struct base_breakpoint : public breakpoint { + using breakpoint::breakpoint; + void re_set () override; int insert_location (struct bp_location *) override; int remove_location (struct bp_location *, @@ -866,6 +876,8 @@ struct base_breakpoint : public breakpoint struct watchpoint : public breakpoint { + using breakpoint::breakpoint; + void re_set () override; int insert_location (struct bp_location *) override; int remove_location (struct bp_location *, @@ -959,6 +971,8 @@ extern bool is_exception_catchpoint (breakpoint *bp); struct tracepoint : public breakpoint { + using breakpoint::breakpoint; + void re_set () override; int breakpoint_hit (const struct bp_location *bl, const address_space *aspace, CORE_ADDR bp_addr, -- 2.30.2