From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1879) id B46EE385770D; Thu, 25 May 2023 14:01:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B46EE385770D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1685023285; bh=ueM+5WKEctJUMbJAKtWdb0P7NwQm4clwVEZlNcT5Muo=; h=From:To:Subject:Date:From; b=GEXx1D86SfzmT1RUk2KXOzRsfscEIg/fTEk47ioE2wobk41IpiI1JCKIZOQasUrmU mkYSw389vSnjZScyWgGKgH6vanwtC4lmTQLUFFXCmgKP456BdM6LrkQXsSsz5hnOlw ZBQ8bKOzQoWDnp3N2uxyOAie3KlY8ExQtJUQni+c= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Simon Marchi To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb: add breakpoint "has locations" methods X-Act-Checkin: binutils-gdb X-Git-Author: Simon Marchi X-Git-Refname: refs/heads/master X-Git-Oldrev: 5e632eca05f38ea7229f103e0636e02c6dfcd9fa X-Git-Newrev: 9dc1523b573cc065d6124e3127009c1d7cb8317b Message-Id: <20230525140125.B46EE385770D@sourceware.org> Date: Thu, 25 May 2023 14:01:25 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D9dc1523b573c= c065d6124e3127009c1d7cb8317b commit 9dc1523b573cc065d6124e3127009c1d7cb8317b Author: Simon Marchi Date: Tue May 9 10:23:44 2023 -0400 gdb: add breakpoint "has locations" methods =20 Add three convenience methods to struct breakpoint: =20 - has_locations: returns true if the breakpoint has at least one location - has_single_location: returns true if the breakpoint has exactly one location - has_multiple_locations: returns true if the breakpoint has more than one location =20 A subsequent patch changes the list of breakpoints to be an intrusive_list, so all these spots would need to change. But in any case, I think that this: =20 if (b->has_multiple_locations ()) =20 conveys the intention better than: =20 if (b->loc !=3D nullptr && b->loc->next !=3D nullptr) =20 Change-Id: Ib18c3605fd35d425ef9df82cb7aacff1606c6747 Reviewed-By: Andrew Burgess Diff: --- gdb/ada-lang.c | 2 +- gdb/breakpoint.c | 62 +++++++++++++++++++++++++++--------------------= ---- gdb/breakpoint.h | 12 ++++++++++ gdb/elfread.c | 4 ++-- gdb/tracectf.c | 2 +- gdb/tracefile-tfile.c | 2 +- gdb/tracefile.c | 4 ++-- gdb/tracepoint.c | 2 +- 8 files changed, 53 insertions(+), 37 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index b5a8b4bf544..db07f5b95f3 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -12218,7 +12218,7 @@ create_excep_cond_exprs (struct ada_catchpoint *c, return; =20 /* Same if there are no locations... */ - if (c->loc =3D=3D NULL) + if (!c->has_locations ()) return; =20 /* Compute the condition expression in text form, from the specific diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 30b985ab5bc..4fcaf007d05 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -818,7 +818,7 @@ has_multiple_locations (int num) { for (breakpoint *b : all_breakpoints ()) if (b->number =3D=3D num) - return b->loc !=3D nullptr && b->loc->next !=3D nullptr; + return b->has_multiple_locations (); =20 return false; } @@ -1877,7 +1877,7 @@ static void add_dummy_location (struct breakpoint *b, struct program_space *pspace) { - gdb_assert (b->loc =3D=3D NULL); + gdb_assert (!b->has_locations ()); =20 b->loc =3D new bp_location (b, bp_loc_other); b->loc->pspace =3D pspace; @@ -2242,7 +2242,7 @@ update_watchpoint (struct watchpoint *b, bool reparse) above left it without any location set up. But, bpstat_stop_status requires a location to be able to report stops, so make sure there's at least a dummy one. */ - if (b->type =3D=3D bp_watchpoint && b->loc =3D=3D NULL) + if (b->type =3D=3D bp_watchpoint && !b->has_locations ()) add_dummy_location (b, frame_pspace); } else if (!within_current_scope) @@ -4108,7 +4108,7 @@ breakpoint_init_inferior (enum inf_context context) =20 for (breakpoint *b : all_breakpoints_safe ()) { - if (b->loc && b->loc->pspace !=3D pspace) + if (b->has_locations () && b->loc->pspace !=3D pspace) continue; =20 switch (b->type) @@ -4522,7 +4522,7 @@ bpstat_locno (const bpstat *bs) =20 int locno =3D 0; =20 - if (b !=3D nullptr && b->loc !=3D nullptr && b->loc->next !=3D nullptr) + if (b !=3D nullptr && b->has_multiple_locations ()) { const bp_location *bl_i; =20 @@ -6056,7 +6056,9 @@ bool bpstat_should_step () { for (breakpoint *b : all_breakpoints ()) - if (breakpoint_enabled (b) && b->type =3D=3D bp_watchpoint && b->loc != =3D NULL) + if (breakpoint_enabled (b) + && b->type =3D=3D bp_watchpoint + && b->has_locations ()) return true; =20 return false; @@ -6359,10 +6361,11 @@ print_one_breakpoint_location (struct breakpoint *b, /* See comment in print_one_breakpoint concerning treatment of breakpoints with single disabled location. */ if (loc =3D=3D NULL=20 - && (b->loc !=3D NULL=20 - && (b->loc->next !=3D NULL + && (b->has_locations () + && (b->has_multiple_locations () || !b->loc->enabled || b->loc->disabled_by_cond))) header_of_multiple =3D true; + if (loc =3D=3D NULL) loc =3D b->loc; =20 @@ -6453,7 +6456,7 @@ print_one_breakpoint_location (struct breakpoint *b, if (header_of_multiple) uiout->field_string ("addr", "", metadata_style.style ()); - else if (b->loc =3D=3D NULL || loc->shlib_disabled) + else if (!b->has_locations () || loc->shlib_disabled) uiout->field_string ("addr", "", metadata_style.style ()); else @@ -6463,7 +6466,7 @@ print_one_breakpoint_location (struct breakpoint *b, annotate_field (5); if (!header_of_multiple) print_breakpoint_location (b, loc); - if (b->loc) + if (b->has_locations ()) *last_loc =3D b->loc; } } @@ -6742,9 +6745,10 @@ print_one_breakpoint (breakpoint *b, const bp_locati= on **last_loc, int allflag) && (!is_catchpoint (b) || is_exception_catchpoint (b) || is_ada_exception_catchpoint (b)) && (allflag - || (b->loc && (b->loc->next - || !b->loc->enabled - || b->loc->disabled_by_cond)))) + || (b->has_locations () + && (b->has_multiple_locations () + || !b->loc->enabled + || b->loc->disabled_by_cond)))) { gdb::optional locations_list; =20 @@ -6807,7 +6811,7 @@ user_breakpoint_p (struct breakpoint *b) int pending_breakpoint_p (struct breakpoint *b) { - return b->loc =3D=3D NULL; + return !b->has_locations (); } =20 /* Print information on breakpoints (including watchpoints and tracepoints= ). @@ -7484,8 +7488,9 @@ set_breakpoint_location_function (struct bp_location = *loc) =20 function_name =3D loc->msymbol->linkage_name (); =20 - if (b->type =3D=3D bp_breakpoint && b->loc =3D=3D loc - && loc->next =3D=3D NULL && b->related_breakpoint =3D=3D b) + if (b->type =3D=3D bp_breakpoint + && b->has_single_location () + && b->related_breakpoint =3D=3D b) { /* Create only the whole new breakpoint of this type but do not mess more complicated breakpoints with multiple locations. */ @@ -9376,13 +9381,12 @@ ranged_breakpoint::resources_needed (const struct b= p_location *bl) enum print_stop_action ranged_breakpoint::print_it (const bpstat *bs) const { - struct bp_location *bl =3D loc; struct ui_out *uiout =3D current_uiout; =20 gdb_assert (type =3D=3D bp_hardware_breakpoint); =20 /* Ranged breakpoints have only one location. */ - gdb_assert (bl && bl->next =3D=3D NULL); + gdb_assert (this->has_single_location ()); =20 annotate_breakpoint (number); =20 @@ -9414,7 +9418,7 @@ ranged_breakpoint::print_one (const bp_location **las= t_loc) const struct ui_out *uiout =3D current_uiout; =20 /* Ranged breakpoints have only one location. */ - gdb_assert (bl && bl->next =3D=3D NULL); + gdb_assert (this->has_single_location ()); =20 get_user_print_options (&opts); =20 @@ -9941,7 +9945,7 @@ masked_watchpoint::print_it (const bpstat *bs) const struct ui_out *uiout =3D current_uiout; =20 /* Masked watchpoints have only one location. */ - gdb_assert (this->loc && this->loc->next =3D=3D nullptr); + gdb_assert (this->has_single_location ()); =20 annotate_watchpoint (this->number); maybe_print_thread_hit_breakpoint (uiout); @@ -9987,7 +9991,7 @@ void masked_watchpoint::print_one_detail (struct ui_out *uiout) const { /* Masked watchpoints have only one location. */ - gdb_assert (loc && loc->next =3D=3D NULL); + gdb_assert (this->has_single_location ()); =20 uiout->text ("\tmask "); uiout->field_core_addr ("mask", loc->gdbarch, hw_wp_mask); @@ -11573,7 +11577,7 @@ code_breakpoint::say_where () const =20 /* i18n: cagney/2005-02-11: Below needs to be merged into a single string. */ - if (loc =3D=3D NULL) + if (!this->has_locations ()) { /* For pending locations, the output differs slightly based on extra_string. If this is non-NULL, it contains either @@ -11606,7 +11610,7 @@ code_breakpoint::say_where () const { /* If there is a single location, we can print the location more nicely. */ - if (loc->next =3D=3D NULL) + if (!this->has_multiple_locations ()) { const char *filename =3D symtab_to_filename_for_display (loc->symtab); @@ -11622,7 +11626,7 @@ code_breakpoint::say_where () const gdb_printf (": %s.", locspec->to_string ()); } =20 - if (loc->next) + if (this->has_multiple_locations ()) { struct bp_location *iter =3D loc; int n =3D 0; @@ -11881,7 +11885,7 @@ ordinary_breakpoint::print_recreate (struct ui_file= *fp) const =20 /* Print out extra_string if this breakpoint is pending. It might contain, for example, conditions that were set by the user. */ - if (loc =3D=3D NULL && extra_string !=3D NULL) + if (!this->has_locations () && extra_string !=3D NULL) gdb_printf (fp, " %s", extra_string.get ()); =20 print_recreate_thread (fp); @@ -12869,11 +12873,11 @@ code_breakpoint::location_spec_to_sals (location_= spec *locspec, errors. */ if (e.error =3D=3D NOT_FOUND_ERROR && (condition_not_parsed - || (loc !=3D NULL + || (this->has_locations () && search_pspace !=3D NULL && loc->pspace !=3D search_pspace) - || (loc && loc->shlib_disabled) - || (loc && loc->pspace->executing_startup) + || (this->has_locations () && loc->shlib_disabled) + || (this->has_locations () && loc->pspace->executing_startup) || enable_state =3D=3D bp_disabled)) not_found_and_ok =3D true; =20 @@ -14267,7 +14271,7 @@ save_breakpoints (const char *filename, int from_tt= y, /* If this is a multi-location breakpoint, check if the locations should be individually disabled. Watchpoint locations are special, and not user visible. */ - if (!is_watchpoint (tp) && tp->loc && tp->loc->next) + if (!is_watchpoint (tp) && tp->has_multiple_locations ()) { int n =3D 1; =20 diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h index 80cb91b1a91..2a3a5cf57b8 100644 --- a/gdb/breakpoint.h +++ b/gdb/breakpoint.h @@ -633,6 +633,18 @@ struct breakpoint /* Allocate a location for this breakpoint. */ virtual struct bp_location *allocate_location (); =20 + /* Return true if this breakpoint has a least one location. */ + bool has_locations () const + { return this->loc !=3D nullptr; } + + /* Return true if this breakpoint has a single location. */ + bool has_single_location () const + { return this->loc !=3D nullptr && this->loc->next =3D=3D nullptr; } + + /* Return true if this breakpoint has multiple locations. */ + bool has_multiple_locations () const + { return this->loc !=3D nullptr && this->loc->next !=3D nullptr; } + /* Reevaluate a breakpoint. This is necessary after symbols change (e.g., an executable or DSO was loaded, or the inferior just started). */ diff --git a/gdb/elfread.c b/gdb/elfread.c index c17b256df11..83b20a388c8 100644 --- a/gdb/elfread.c +++ b/gdb/elfread.c @@ -973,7 +973,7 @@ elf_gnu_ifunc_resolver_stop (code_breakpoint *b) b_return =3D b_return->related_breakpoint) { gdb_assert (b_return->type =3D=3D bp_gnu_ifunc_resolver_return); - gdb_assert (b_return->loc !=3D NULL && b_return->loc->next =3D=3D NU= LL); + gdb_assert (b_return->has_single_location ()); gdb_assert (frame_id_p (b_return->frame_id)); =20 if (b_return->thread =3D=3D thread_id @@ -1042,7 +1042,7 @@ elf_gnu_ifunc_resolver_return_stop (code_breakpoint *= b) b =3D (code_breakpoint *) b_next; } gdb_assert (b->type =3D=3D bp_gnu_ifunc_resolver); - gdb_assert (b->loc->next =3D=3D NULL); + gdb_assert (b->has_single_location ()); =20 func_func =3D value::allocate (func_func_type); func_func->set_lval (lval_memory); diff --git a/gdb/tracectf.c b/gdb/tracectf.c index d8d0f05d049..ab513b1fa15 100644 --- a/gdb/tracectf.c +++ b/gdb/tracectf.c @@ -1535,7 +1535,7 @@ ctf_get_traceframe_address (void) struct tracepoint *tp =3D get_tracepoint_by_number_on_target (tpnum); =20 - if (tp && tp->loc) + if (tp !=3D nullptr && tp->has_locations ()) addr =3D tp->loc->address; } =20 diff --git a/gdb/tracefile-tfile.c b/gdb/tracefile-tfile.c index 31eb974d416..9c1adee11bc 100644 --- a/gdb/tracefile-tfile.c +++ b/gdb/tracefile-tfile.c @@ -667,7 +667,7 @@ tfile_get_traceframe_address (off_t tframe_offset) =20 tp =3D get_tracepoint_by_number_on_target (tpnum); /* FIXME this is a poor heuristic if multiple locations. */ - if (tp && tp->loc) + if (tp !=3D nullptr && tp->has_locations ()) addr =3D tp->loc->address; =20 /* Restore our seek position. */ diff --git a/gdb/tracefile.c b/gdb/tracefile.c index b4543c9bf5f..883ce4bf375 100644 --- a/gdb/tracefile.c +++ b/gdb/tracefile.c @@ -390,11 +390,11 @@ tracefile_fetch_registers (struct regcache *regcache,= int regno) =20 /* We can often usefully guess that the PC is going to be the same as the address of the tracepoint. */ - if (tp =3D=3D NULL || tp->loc =3D=3D NULL) + if (tp =3D=3D nullptr || !tp->has_locations ()) return; =20 /* But don't try to guess if tracepoint is multi-location... */ - if (tp->loc->next) + if (tp->has_multiple_locations ()) { warning (_("Tracepoint %d has multiple " "locations, cannot infer $pc"), diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c index 9e5ced1893e..4b775d1a4a2 100644 --- a/gdb/tracepoint.c +++ b/gdb/tracepoint.c @@ -1524,7 +1524,7 @@ process_tracepoint_on_disconnect (void) user that pending tracepoint will no longer work. */ for (breakpoint *b : all_tracepoints ()) { - if (b->loc =3D=3D NULL) + if (!b->has_locations ()) { has_pending_p =3D 1; break;