From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1551) id 013DC3830886; Fri, 20 May 2022 19:43:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 013DC3830886 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Pedro Alves To: gdb-cvs@sourceware.org Subject: [binutils-gdb] init_breakpoint_sal -> base_breakpoint::base_breakpoint X-Act-Checkin: binutils-gdb X-Git-Author: Pedro Alves X-Git-Refname: refs/heads/master X-Git-Oldrev: d837fd813d9c72ea7d06ef839b95857dcf0da811 X-Git-Newrev: 3b003a6126610d16015c5aee997ed702788d3be6 Message-Id: <20220520194309.013DC3830886@sourceware.org> Date: Fri, 20 May 2022 19:43:09 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 May 2022 19:43:09 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D3b003a612661= 0d16015c5aee997ed702788d3be6 commit 3b003a6126610d16015c5aee997ed702788d3be6 Author: Pedro Alves Date: Fri May 6 23:18:57 2022 +0100 init_breakpoint_sal -> base_breakpoint::base_breakpoint =20 This converts init_breakpoint_sal to a base_breakpoint constructor. =20 It removes a use of init_raw_breakpoint. =20 To avoid manually adding a bunch of parameters to new_breakpoint_from_type, and manually passing them down to the constructors of a number of different base_breakpoint subclasses, make new_breakpoint_from_type a variable template function. =20 Change-Id: I4cc24133ac4c292f547289ec782fc78e5bbe2510 Diff: --- gdb/breakpoint.c | 235 ++++++++++++++++++++++++++-------------------------= ---- gdb/breakpoint.h | 16 ++++ 2 files changed, 129 insertions(+), 122 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index dd6623dd6b5..485488a933d 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -1257,8 +1257,10 @@ is_tracepoint (const struct breakpoint *b) /* Factory function to create an appropriate instance of breakpoint given TYPE. */ =20 +template static std::unique_ptr -new_breakpoint_from_type (struct gdbarch *gdbarch, bptype type) +new_breakpoint_from_type (struct gdbarch *gdbarch, bptype type, + Arg&&... args) { base_breakpoint *b; =20 @@ -1266,21 +1268,25 @@ new_breakpoint_from_type (struct gdbarch *gdbarch, = bptype type) { case bp_breakpoint: case bp_hardware_breakpoint: - b =3D new ordinary_breakpoint (gdbarch, type); + b =3D new ordinary_breakpoint (gdbarch, type, + std::forward (args)...); break; =20 case bp_fast_tracepoint: case bp_static_tracepoint: case bp_tracepoint: - b =3D new tracepoint (gdbarch, type); + b =3D new tracepoint (gdbarch, type, + std::forward (args)...); break; =20 case bp_static_marker_tracepoint: - b =3D new static_marker_tracepoint (gdbarch, type); + b =3D new static_marker_tracepoint (gdbarch, type, + std::forward (args)...); break; =20 case bp_dprintf: - b =3D new dprintf_breakpoint (gdbarch, type); + b =3D new dprintf_breakpoint (gdbarch, type, + std::forward (args)...); break; =20 case bp_overlay_event: @@ -1290,12 +1296,14 @@ new_breakpoint_from_type (struct gdbarch *gdbarch, = bptype type) case bp_thread_event: case bp_jit_event: case bp_shlib_event: - b =3D new internal_breakpoint (gdbarch, type); + b =3D new internal_breakpoint (gdbarch, type, + std::forward (args)...); break; =20 case bp_longjmp: case bp_exception: - b =3D new longjmp_breakpoint (gdbarch, type); + b =3D new longjmp_breakpoint (gdbarch, type, + std::forward (args)...); break; =20 case bp_watchpoint_scope: @@ -1309,7 +1317,8 @@ new_breakpoint_from_type (struct gdbarch *gdbarch, bp= type type) case bp_call_dummy: case bp_until: case bp_std_terminate: - b =3D new momentary_breakpoint (gdbarch, type); + b =3D new momentary_breakpoint (gdbarch, type, + std::forward (args)...); break; =20 default: @@ -8290,23 +8299,19 @@ update_dprintf_commands (const char *args, int from= _tty, update_dprintf_command_list (b); } =20 -/* Create a breakpoint with SAL as location. Use LOCATION - as a description of the location, and COND_STRING - as condition expression. If LOCATION is NULL then create an - "address location" from the address in the SAL. */ - -static void -init_breakpoint_sal (base_breakpoint *b, struct gdbarch *gdbarch, - gdb::array_view sals, - event_location_up &&location, - gdb::unique_xmalloc_ptr filter, - gdb::unique_xmalloc_ptr cond_string, - gdb::unique_xmalloc_ptr extra_string, - enum bptype type, enum bpdisp disposition, - int thread, int task, int ignore_count, - int from_tty, - int enabled, unsigned flags, - int display_canonical) +base_breakpoint::base_breakpoint (struct gdbarch *gdbarch_, + enum bptype type_, + gdb::array_view sals, + event_location_up &&location_, + gdb::unique_xmalloc_ptr filter_, + gdb::unique_xmalloc_ptr cond_string_, + gdb::unique_xmalloc_ptr extra_string_, + enum bpdisp disposition_, + int thread_, int task_, int ignore_count_, + int from_tty, + int enabled_, unsigned flags, + int display_canonical_) + : breakpoint (gdbarch_, type_) { int i; =20 @@ -8326,81 +8331,64 @@ init_breakpoint_sal (base_breakpoint *b, struct gdb= arch *gdbarch, =20 gdb_assert (!sals.empty ()); =20 - for (const auto &sal : sals) - { - struct bp_location *loc; + thread =3D thread_; + task =3D task_; =20 - if (from_tty) - { - struct gdbarch *loc_gdbarch =3D get_sal_arch (sal); - if (!loc_gdbarch) - loc_gdbarch =3D gdbarch; + cond_string =3D std::move (cond_string_); + extra_string =3D std::move (extra_string_); + ignore_count =3D ignore_count_; + enable_state =3D enabled_ ? bp_enabled : bp_disabled; + disposition =3D disposition_; =20 - describe_other_breakpoints (loc_gdbarch, - sal.pspace, sal.pc, sal.section, thread); - } + if (type =3D=3D bp_static_tracepoint + || type =3D=3D bp_static_marker_tracepoint) + { + auto *t =3D static_cast (this); + struct static_tracepoint_marker marker; =20 - if (&sal =3D=3D &sals[0]) + if (strace_marker_p (this)) { - init_raw_breakpoint (b, sal, type); - b->thread =3D thread; - b->task =3D task; + /* We already know the marker exists, otherwise, we wouldn't + see a sal for it. */ + const char *p =3D &event_location_to_string (location_.get ())[3]; + const char *endp; =20 - b->cond_string =3D std::move (cond_string); - b->extra_string =3D std::move (extra_string); - b->ignore_count =3D ignore_count; - b->enable_state =3D enabled ? bp_enabled : bp_disabled; - b->disposition =3D disposition; + p =3D skip_spaces (p); =20 - if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) !=3D 0) - b->loc->inserted =3D 1; + endp =3D skip_to_space (p); =20 - if (type =3D=3D bp_static_tracepoint - || type =3D=3D bp_static_marker_tracepoint) - { - auto *t =3D static_cast (b); - struct static_tracepoint_marker marker; - - if (strace_marker_p (b)) - { - /* We already know the marker exists, otherwise, we - wouldn't see a sal for it. */ - const char *p - =3D &event_location_to_string (b->location.get ())[3]; - const char *endp; + t->static_trace_marker_id.assign (p, endp - p); =20 - p =3D skip_spaces (p); - - endp =3D skip_to_space (p); - - t->static_trace_marker_id.assign (p, endp - p); - - gdb_printf (_("Probed static tracepoint " - "marker \"%s\"\n"), - t->static_trace_marker_id.c_str ()); - } - else if (target_static_tracepoint_marker_at (sal.pc, &marker)) - { - t->static_trace_marker_id =3D std::move (marker.str_id); - - gdb_printf (_("Probed static tracepoint " - "marker \"%s\"\n"), - t->static_trace_marker_id.c_str ()); - } - else - warning (_("Couldn't determine the static " - "tracepoint marker to probe")); - } + gdb_printf (_("Probed static tracepoint marker \"%s\"\n"), + t->static_trace_marker_id.c_str ()); + } + else if (target_static_tracepoint_marker_at (sals[0].pc, &marker)) + { + t->static_trace_marker_id =3D std::move (marker.str_id); =20 - loc =3D b->loc; + gdb_printf (_("Probed static tracepoint marker \"%s\"\n"), + t->static_trace_marker_id.c_str ()); } else + warning (_("Couldn't determine the static tracepoint marker to probe")); + } + + for (const auto &sal : sals) + { + if (from_tty) { - loc =3D b->add_location (sal); - if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) !=3D 0) - loc->inserted =3D 1; + struct gdbarch *loc_gdbarch =3D get_sal_arch (sal); + if (loc_gdbarch =3D=3D nullptr) + loc_gdbarch =3D gdbarch; + + describe_other_breakpoints (loc_gdbarch, + sal.pspace, sal.pc, sal.section, thread); } =20 + bp_location *new_loc =3D add_location (sal); + if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) !=3D 0) + new_loc->inserted =3D 1; + /* Do not set breakpoint locations conditions yet. As locations are inserted, they get sorted based on their addresses. Let the list stabilize to have reliable location numbers. */ @@ -8409,34 +8397,33 @@ init_breakpoint_sal (base_breakpoint *b, struct gdb= arch *gdbarch, command line, otherwise it's an error. */ if (type =3D=3D bp_dprintf) { - if (b->extra_string) - update_dprintf_command_list (b); + if (extra_string !=3D nullptr) + update_dprintf_command_list (this); else error (_("Format string required")); } - else if (b->extra_string) - error (_("Garbage '%s' at end of command"), b->extra_string.get ()); + else if (extra_string !=3D nullptr) + error (_("Garbage '%s' at end of command"), extra_string.get ()); } =20 - /* The order of the locations is now stable. Set the location condition using the location's number. */ int loc_num =3D 1; - for (bp_location *loc : b->locations ()) + for (bp_location *bl : locations ()) { - if (b->cond_string !=3D nullptr) - set_breakpoint_location_condition (b->cond_string.get (), loc, - b->number, loc_num); + if (cond_string !=3D nullptr) + set_breakpoint_location_condition (cond_string.get (), bl, + number, loc_num); =20 ++loc_num; } =20 - b->display_canonical =3D display_canonical; - if (location !=3D NULL) - b->location =3D std::move (location); + display_canonical =3D display_canonical_; + if (location_ !=3D nullptr) + location =3D std::move (location_); else - b->location =3D new_address_location (b->loc->address, NULL, 0); - b->filter =3D std::move (filter); + location =3D new_address_location (this->loc->address, NULL, 0); + filter =3D std::move (filter_); } =20 static void @@ -8452,18 +8439,19 @@ create_breakpoint_sal (struct gdbarch *gdbarch, int enabled, int internal, unsigned flags, int display_canonical) { - std::unique_ptr b =3D new_breakpoint_from_type (gdbarch= , type); - - init_breakpoint_sal (b.get (), gdbarch, - sals, std::move (location), - std::move (filter), - std::move (cond_string), - std::move (extra_string), - type, disposition, - thread, task, ignore_count, - from_tty, - enabled, flags, - display_canonical); + std::unique_ptr b + =3D new_breakpoint_from_type (gdbarch, + type, + sals, + std::move (location), + std::move (filter), + std::move (cond_string), + std::move (extra_string), + disposition, + thread, task, ignore_count, + from_tty, + enabled, flags, + display_canonical); =20 install_breakpoint (internal, std::move (b), 0); } @@ -12144,16 +12132,19 @@ strace_marker_create_breakpoints_sal (struct gdba= rch *gdbarch, event_location_up location =3D copy_event_location (canonical->location.get ()); =20 - 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), - std::move (extra_string), - type_wanted, disposition, - thread, task, ignore_count, - from_tty, enabled, flags, - canonical->special_display); + std::unique_ptr tp + (new tracepoint (gdbarch, + type_wanted, + lsal.sals[i], + std::move (location), + NULL, + std::move (cond_string), + std::move (extra_string), + disposition, + thread, task, ignore_count, + from_tty, enabled, flags, + canonical->special_display)); + /* Given that its possible to have multiple markers with the same string id, if the user is creating a static tracepoint by marker id ("strace -m MARKER_ID"), then diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h index fb2bbd729c0..40ba98b7496 100644 --- a/gdb/breakpoint.h +++ b/gdb/breakpoint.h @@ -861,6 +861,22 @@ struct base_breakpoint : public breakpoint { using breakpoint::breakpoint; =20 + /* Create a breakpoint with SALS as locations. Use LOCATION as a + description of the location, and COND_STRING as condition + expression. If LOCATION is NULL then create an "address + location" from the address in the SAL. */ + base_breakpoint (struct gdbarch *gdbarch, bptype type, + gdb::array_view sals, + event_location_up &&location, + gdb::unique_xmalloc_ptr filter, + gdb::unique_xmalloc_ptr cond_string, + gdb::unique_xmalloc_ptr extra_string, + enum bpdisp disposition, + int thread, int task, int ignore_count, + int from_tty, + int enabled, unsigned flags, + int display_canonical); + ~base_breakpoint () override =3D 0; =20 void re_set () override;