gdb: add breakpoint::locations method

Add the breakpoint::locations method, which returns a range that can be
used to iterate over a breakpoint's locations.  This shortens

  for (bp_location *loc = b->loc; loc != nullptr; loc = loc->next)

into

  for (bp_location *loc : b->locations ())

Change all the places that I found that could use it.

gdb/ChangeLog:

	* breakpoint.h (bp_locations_range): New.
	(struct breakpoint) <locations>: New.  Use where possible.

Change-Id: I1ba2f7d93d57e544e1f8609124587dcf2e1da037
This commit is contained in:
Simon Marchi 2021-05-27 14:58:37 -04:00
parent f6d17b2b1c
commit 40cb8ca539
9 changed files with 83 additions and 101 deletions

View file

@ -1,3 +1,8 @@
2021-05-27 Simon Marchi <simon.marchi@polymtl.ca>
* breakpoint.h (bp_locations_range): New.
(struct breakpoint) <locations>: New. Use where possible.
2021-05-27 Simon Marchi <simon.marchi@polymtl.ca> 2021-05-27 Simon Marchi <simon.marchi@polymtl.ca>
* breakpoint.h (all_tracepoints): Remove. * breakpoint.h (all_tracepoints): Remove.

View file

@ -11552,8 +11552,6 @@ static void
create_excep_cond_exprs (struct ada_catchpoint *c, create_excep_cond_exprs (struct ada_catchpoint *c,
enum ada_exception_catchpoint_kind ex) enum ada_exception_catchpoint_kind ex)
{ {
struct bp_location *bl;
/* Nothing to do if there's no specific exception to catch. */ /* Nothing to do if there's no specific exception to catch. */
if (c->excep_string.empty ()) if (c->excep_string.empty ())
return; return;
@ -11569,7 +11567,7 @@ create_excep_cond_exprs (struct ada_catchpoint *c,
/* Iterate over all the catchpoint's locations, and parse an /* Iterate over all the catchpoint's locations, and parse an
expression for each. */ expression for each. */
for (bl = c->loc; bl != NULL; bl = bl->next) for (bp_location *bl : c->locations ())
{ {
struct ada_catchpoint_location *ada_loc struct ada_catchpoint_location *ada_loc
= (struct ada_catchpoint_location *) bl; = (struct ada_catchpoint_location *) bl;

View file

@ -680,8 +680,6 @@ get_breakpoint (int num)
static void static void
mark_breakpoint_modified (struct breakpoint *b) mark_breakpoint_modified (struct breakpoint *b)
{ {
struct bp_location *loc;
/* This is only meaningful if the target is /* This is only meaningful if the target is
evaluating conditions and if the user has evaluating conditions and if the user has
opted for condition evaluation on the target's opted for condition evaluation on the target's
@ -693,7 +691,7 @@ mark_breakpoint_modified (struct breakpoint *b)
if (!is_breakpoint (b)) if (!is_breakpoint (b))
return; return;
for (loc = b->loc; loc; loc = loc->next) for (bp_location *loc : b->locations ())
loc->condition_changed = condition_modified; loc->condition_changed = condition_modified;
} }
@ -910,7 +908,7 @@ set_breakpoint_condition (struct breakpoint *b, const char *exp,
else else
{ {
int loc_num = 1; int loc_num = 1;
for (bp_location *loc = b->loc; loc != nullptr; loc = loc->next) for (bp_location *loc : b->locations ())
{ {
loc->cond.reset (); loc->cond.reset ();
if (loc->disabled_by_cond && loc->enabled) if (loc->disabled_by_cond && loc->enabled)
@ -952,7 +950,7 @@ set_breakpoint_condition (struct breakpoint *b, const char *exp,
the error and the condition string will be rejected. the error and the condition string will be rejected.
This two-pass approach is taken to avoid setting the This two-pass approach is taken to avoid setting the
state of locations in case of a reject. */ state of locations in case of a reject. */
for (bp_location *loc = b->loc; loc != nullptr; loc = loc->next) for (bp_location *loc : b->locations ())
{ {
try try
{ {
@ -975,9 +973,11 @@ set_breakpoint_condition (struct breakpoint *b, const char *exp,
/* If we reach here, the condition is valid at some locations. */ /* If we reach here, the condition is valid at some locations. */
int loc_num = 1; int loc_num = 1;
for (bp_location *loc = b->loc; loc != nullptr; for (bp_location *loc : b->locations ())
loc = loc->next, loc_num++) {
set_breakpoint_location_condition (exp, loc, b->number, loc_num); set_breakpoint_location_condition (exp, loc, b->number, loc_num);
loc_num++;
}
} }
/* We know that the new condition parsed successfully. The /* We know that the new condition parsed successfully. The
@ -1287,12 +1287,11 @@ std::vector<breakpoint *>
static_tracepoints_here (CORE_ADDR addr) static_tracepoints_here (CORE_ADDR addr)
{ {
std::vector<breakpoint *> found; std::vector<breakpoint *> found;
struct bp_location *loc;
for (breakpoint *b : all_breakpoints ()) for (breakpoint *b : all_breakpoints ())
if (b->type == bp_static_tracepoint) if (b->type == bp_static_tracepoint)
{ {
for (loc = b->loc; loc; loc = loc->next) for (bp_location *loc : b->locations ())
if (loc->address == addr) if (loc->address == addr)
found.push_back (b); found.push_back (b);
} }
@ -2032,7 +2031,6 @@ update_watchpoint (struct watchpoint *b, int reparse)
{ {
int reg_cnt; int reg_cnt;
enum bp_loc_type loc_type; enum bp_loc_type loc_type;
struct bp_location *bl;
reg_cnt = can_use_hardware_watchpoint (val_chain); reg_cnt = can_use_hardware_watchpoint (val_chain);
@ -2108,7 +2106,7 @@ update_watchpoint (struct watchpoint *b, int reparse)
loc_type = (b->type == bp_watchpoint? bp_loc_other loc_type = (b->type == bp_watchpoint? bp_loc_other
: bp_loc_hardware_watchpoint); : bp_loc_hardware_watchpoint);
for (bl = b->loc; bl; bl = bl->next) for (bp_location *bl : b->locations ())
bl->loc_type = loc_type; bl->loc_type = loc_type;
} }
@ -3083,7 +3081,6 @@ insert_breakpoint_locations (void)
for (breakpoint *bpt : all_breakpoints ()) for (breakpoint *bpt : all_breakpoints ())
{ {
int some_failed = 0; int some_failed = 0;
struct bp_location *loc;
if (!is_hardware_watchpoint (bpt)) if (!is_hardware_watchpoint (bpt))
continue; continue;
@ -3094,15 +3091,16 @@ insert_breakpoint_locations (void)
if (bpt->disposition == disp_del_at_next_stop) if (bpt->disposition == disp_del_at_next_stop)
continue; continue;
for (loc = bpt->loc; loc; loc = loc->next) for (bp_location *loc : bpt->locations ())
if (!loc->inserted && should_be_inserted (loc)) if (!loc->inserted && should_be_inserted (loc))
{ {
some_failed = 1; some_failed = 1;
break; break;
} }
if (some_failed) if (some_failed)
{ {
for (loc = bpt->loc; loc; loc = loc->next) for (bp_location *loc : bpt->locations ())
if (loc->inserted) if (loc->inserted)
remove_breakpoint (loc); remove_breakpoint (loc);
@ -4287,8 +4285,6 @@ hardware_watchpoint_inserted_in_range (const address_space *aspace,
{ {
for (breakpoint *bpt : all_breakpoints ()) for (breakpoint *bpt : all_breakpoints ())
{ {
struct bp_location *loc;
if (bpt->type != bp_hardware_watchpoint if (bpt->type != bp_hardware_watchpoint
&& bpt->type != bp_access_watchpoint) && bpt->type != bp_access_watchpoint)
continue; continue;
@ -4296,7 +4292,7 @@ hardware_watchpoint_inserted_in_range (const address_space *aspace,
if (!breakpoint_enabled (bpt)) if (!breakpoint_enabled (bpt))
continue; continue;
for (loc = bpt->loc; loc; loc = loc->next) for (bp_location *loc : bpt->locations ())
if (loc->pspace->aspace == aspace && loc->inserted) if (loc->pspace->aspace == aspace && loc->inserted)
{ {
CORE_ADDR l, h; CORE_ADDR l, h;
@ -4903,10 +4899,9 @@ watchpoints_triggered (struct target_waitstatus *ws)
if (is_hardware_watchpoint (b)) if (is_hardware_watchpoint (b))
{ {
struct watchpoint *w = (struct watchpoint *) b; struct watchpoint *w = (struct watchpoint *) b;
struct bp_location *loc;
w->watchpoint_triggered = watch_triggered_no; w->watchpoint_triggered = watch_triggered_no;
for (loc = b->loc; loc; loc = loc->next) for (bp_location *loc : b->locations ())
{ {
if (is_masked_watchpoint (b)) if (is_masked_watchpoint (b))
{ {
@ -5448,7 +5443,7 @@ build_bpstat_chain (const address_space *aspace, CORE_ADDR bp_addr,
if (!breakpoint_enabled (b)) if (!breakpoint_enabled (b))
continue; continue;
for (bp_location *bl = b->loc; bl != NULL; bl = bl->next) for (bp_location *bl : b->locations ())
{ {
/* For hardware watchpoints, we look only at the first /* For hardware watchpoints, we look only at the first
location. The watchpoint_check function will work on the location. The watchpoint_check function will work on the
@ -5918,7 +5913,6 @@ wrap_indent_at_field (struct ui_out *uiout, const char *col_name)
static const char * static const char *
bp_condition_evaluator (struct breakpoint *b) bp_condition_evaluator (struct breakpoint *b)
{ {
struct bp_location *bl;
char host_evals = 0; char host_evals = 0;
char target_evals = 0; char target_evals = 0;
@ -5932,7 +5926,7 @@ bp_condition_evaluator (struct breakpoint *b)
|| !target_supports_evaluation_of_breakpoint_conditions ()) || !target_supports_evaluation_of_breakpoint_conditions ())
return condition_evaluation_host; return condition_evaluation_host;
for (bl = b->loc; bl; bl = bl->next) for (bp_location *bl : b->locations ())
{ {
if (bl->cond_bytecode) if (bl->cond_bytecode)
target_evals++; target_evals++;
@ -6516,11 +6510,12 @@ print_one_breakpoint (struct breakpoint *b,
locations_list.emplace (uiout, "locations"); locations_list.emplace (uiout, "locations");
int n = 1; int n = 1;
for (bp_location *loc = b->loc; loc != NULL; loc = loc->next, ++n) for (bp_location *loc : b->locations ())
{ {
ui_out_emit_tuple loc_tuple_emitter (uiout, NULL); ui_out_emit_tuple loc_tuple_emitter (uiout, NULL);
print_one_breakpoint_location (b, loc, n, last_loc, print_one_breakpoint_location (b, loc, n, last_loc,
allflag, allflag); allflag, allflag);
n++;
} }
} }
} }
@ -6530,14 +6525,13 @@ static int
breakpoint_address_bits (struct breakpoint *b) breakpoint_address_bits (struct breakpoint *b)
{ {
int print_address_bits = 0; int print_address_bits = 0;
struct bp_location *loc;
/* Software watchpoints that aren't watching memory don't have an /* Software watchpoints that aren't watching memory don't have an
address to print. */ address to print. */
if (is_no_memory_software_watchpoint (b)) if (is_no_memory_software_watchpoint (b))
return 0; return 0;
for (loc = b->loc; loc; loc = loc->next) for (bp_location *loc : b->locations ())
{ {
int addr_bit; int addr_bit;
@ -6701,7 +6695,7 @@ breakpoint_1 (const char *bp_num_list, bool show_internal,
if (show_internal || user_breakpoint_p (b)) if (show_internal || user_breakpoint_p (b))
{ {
print_one_breakpoint (b, &last_loc, show_internal); print_one_breakpoint (b, &last_loc, show_internal);
for (bp_location *loc = b->loc; loc != NULL; loc = loc->next) for (bp_location *loc : b->locations ())
if (loc->disabled_by_cond) if (loc->disabled_by_cond)
has_disabled_by_cond_location = true; has_disabled_by_cond_location = true;
} }
@ -6795,9 +6789,7 @@ breakpoint_has_pc (struct breakpoint *b,
struct program_space *pspace, struct program_space *pspace,
CORE_ADDR pc, struct obj_section *section) CORE_ADDR pc, struct obj_section *section)
{ {
struct bp_location *bl = b->loc; for (bp_location *bl : b->locations ())
for (; bl; bl = bl->next)
{ {
if (bl->pspace == pspace if (bl->pspace == pspace
&& bl->address == pc && bl->address == pc
@ -7731,13 +7723,12 @@ disable_breakpoints_in_freed_objfile (struct objfile *objfile)
for (breakpoint *b : all_breakpoints ()) for (breakpoint *b : all_breakpoints ())
{ {
struct bp_location *loc;
int bp_modified = 0; int bp_modified = 0;
if (!is_breakpoint (b) && !is_tracepoint (b)) if (!is_breakpoint (b) && !is_tracepoint (b))
continue; continue;
for (loc = b->loc; loc != NULL; loc = loc->next) for (bp_location *loc : b->locations ())
{ {
CORE_ADDR loc_addr = loc->address; CORE_ADDR loc_addr = loc->address;
@ -8067,8 +8058,6 @@ breakpoint_hit_catch_solib (const struct bp_location *bl,
for (breakpoint *other : all_breakpoints ()) for (breakpoint *other : all_breakpoints ())
{ {
struct bp_location *other_bl;
if (other == bl->owner) if (other == bl->owner)
continue; continue;
@ -8078,7 +8067,7 @@ breakpoint_hit_catch_solib (const struct bp_location *bl,
if (self->pspace != NULL && other->pspace != self->pspace) if (self->pspace != NULL && other->pspace != self->pspace)
continue; continue;
for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) for (bp_location *other_bl : other->locations ())
{ {
if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws))
return 1; return 1;
@ -8426,11 +8415,10 @@ static int
hw_breakpoint_used_count (void) hw_breakpoint_used_count (void)
{ {
int i = 0; int i = 0;
struct bp_location *bl;
for (breakpoint *b : all_breakpoints ()) for (breakpoint *b : all_breakpoints ())
if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b))
for (bl = b->loc; bl; bl = bl->next) for (bp_location *bl : b->locations ())
{ {
/* Special types of hardware breakpoints may use more than /* Special types of hardware breakpoints may use more than
one register. */ one register. */
@ -8447,12 +8435,11 @@ static int
hw_watchpoint_use_count (struct breakpoint *b) hw_watchpoint_use_count (struct breakpoint *b)
{ {
int i = 0; int i = 0;
struct bp_location *bl;
if (!breakpoint_enabled (b)) if (!breakpoint_enabled (b))
return 0; return 0;
for (bl = b->loc; bl; bl = bl->next) for (bp_location *bl : b->locations ())
{ {
/* Special types of hardware watchpoints may use more than /* Special types of hardware watchpoints may use more than
one register. */ one register. */
@ -8995,7 +8982,7 @@ init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch,
/* The order of the locations is now stable. Set the location /* The order of the locations is now stable. Set the location
condition using the location's number. */ condition using the location's number. */
int loc_num = 1; int loc_num = 1;
for (bp_location *loc = b->loc; loc != nullptr; loc = loc->next) for (bp_location *loc : b->locations ())
{ {
if (b->cond_string != nullptr) if (b->cond_string != nullptr)
set_breakpoint_location_condition (b->cond_string, loc, b->number, set_breakpoint_location_condition (b->cond_string, loc, b->number,
@ -11531,8 +11518,7 @@ clear_command (const char *arg, int from_tty)
/* Are we going to delete b? */ /* Are we going to delete b? */
if (b->type != bp_none && !is_watchpoint (b)) if (b->type != bp_none && !is_watchpoint (b))
{ {
struct bp_location *loc = b->loc; for (bp_location *loc : b->locations ())
for (; loc; loc = loc->next)
{ {
/* If the user specified file:line, don't allow a PC /* If the user specified file:line, don't allow a PC
match. This matches historical gdb behavior. */ match. This matches historical gdb behavior. */
@ -11718,7 +11704,6 @@ download_tracepoint_locations (void)
for (breakpoint *b : all_tracepoints ()) for (breakpoint *b : all_tracepoints ())
{ {
struct bp_location *bl;
struct tracepoint *t; struct tracepoint *t;
int bp_location_downloaded = 0; int bp_location_downloaded = 0;
@ -11738,7 +11723,7 @@ download_tracepoint_locations (void)
if (can_download_tracepoint == TRIBOOL_FALSE) if (can_download_tracepoint == TRIBOOL_FALSE)
break; break;
for (bl = b->loc; bl; bl = bl->next) for (bp_location *bl : b->locations ())
{ {
/* In tracepoint, locations are _never_ duplicated, so /* In tracepoint, locations are _never_ duplicated, so
should_be_inserted is equivalent to should_be_inserted is equivalent to
@ -11846,7 +11831,7 @@ force_breakpoint_reinsertion (struct bp_location *bl)
static void static void
update_global_location_list (enum ugll_insert_mode insert_mode) update_global_location_list (enum ugll_insert_mode insert_mode)
{ {
struct bp_location **locp, *loc; struct bp_location **locp;
/* Last breakpoint location address that was marked for update. */ /* Last breakpoint location address that was marked for update. */
CORE_ADDR last_addr = 0; CORE_ADDR last_addr = 0;
/* Last breakpoint location program space that was marked for update. */ /* Last breakpoint location program space that was marked for update. */
@ -11874,13 +11859,13 @@ update_global_location_list (enum ugll_insert_mode insert_mode)
bp_locations_count = 0; bp_locations_count = 0;
for (breakpoint *b : all_breakpoints ()) for (breakpoint *b : all_breakpoints ())
for (loc = b->loc; loc; loc = loc->next) for (bp_location *loc ATTRIBUTE_UNUSED : b->locations ())
bp_locations_count++; bp_locations_count++;
bp_locations = XNEWVEC (struct bp_location *, bp_locations_count); bp_locations = XNEWVEC (struct bp_location *, bp_locations_count);
locp = bp_locations; locp = bp_locations;
for (breakpoint *b : all_breakpoints ()) for (breakpoint *b : all_breakpoints ())
for (loc = b->loc; loc; loc = loc->next) for (bp_location *loc : b->locations ())
*locp++ = loc; *locp++ = loc;
/* See if we need to "upgrade" a software breakpoint to a hardware /* See if we need to "upgrade" a software breakpoint to a hardware
@ -11891,7 +11876,7 @@ update_global_location_list (enum ugll_insert_mode insert_mode)
locp < bp_locations + bp_locations_count; locp < bp_locations + bp_locations_count;
locp++) locp++)
{ {
loc = *locp; bp_location *loc = *locp;
if (!loc->inserted && should_be_inserted (loc)) if (!loc->inserted && should_be_inserted (loc))
handle_automatic_hardware_breakpoints (loc); handle_automatic_hardware_breakpoints (loc);
} }
@ -12135,6 +12120,8 @@ update_global_location_list (enum ugll_insert_mode insert_mode)
wp_loc_first = NULL; wp_loc_first = NULL;
awp_loc_first = NULL; awp_loc_first = NULL;
rwp_loc_first = NULL; rwp_loc_first = NULL;
bp_location *loc;
ALL_BP_LOCATIONS (loc, locp) ALL_BP_LOCATIONS (loc, locp)
{ {
/* ALL_BP_LOCATIONS bp_location has LOC->OWNER always /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
@ -12352,6 +12339,13 @@ breakpoint::~breakpoint ()
xfree (this->extra_string); xfree (this->extra_string);
} }
/* See breakpoint.h. */
bp_locations_range breakpoint::locations ()
{
return bp_locations_range (this->loc);
}
static struct bp_location * static struct bp_location *
base_breakpoint_allocate_location (struct breakpoint *self) base_breakpoint_allocate_location (struct breakpoint *self)
{ {
@ -13398,9 +13392,7 @@ delete_command (const char *arg, int from_tty)
static int static int
all_locations_are_pending (struct breakpoint *b, struct program_space *pspace) all_locations_are_pending (struct breakpoint *b, struct program_space *pspace)
{ {
struct bp_location *loc; for (bp_location *loc : b->locations ())
for (loc = b->loc; loc != NULL; loc = loc->next)
if ((pspace == NULL if ((pspace == NULL
|| loc->pspace == pspace) || loc->pspace == pspace)
&& !loc->shlib_disabled && !loc->shlib_disabled
@ -13719,10 +13711,9 @@ update_breakpoint_locations (struct breakpoint *b,
{ {
if ((!e->enabled || e->disabled_by_cond) && e->function_name) if ((!e->enabled || e->disabled_by_cond) && e->function_name)
{ {
struct bp_location *l = b->loc;
if (have_ambiguous_names) if (have_ambiguous_names)
{ {
for (; l; l = l->next) for (bp_location *l : b->locations ())
{ {
/* Ignore software vs hardware location type at /* Ignore software vs hardware location type at
this point, because with "set breakpoint this point, because with "set breakpoint
@ -13741,7 +13732,7 @@ update_breakpoint_locations (struct breakpoint *b,
} }
else else
{ {
for (; l; l = l->next) for (bp_location *l : b->locations ())
if (l->function_name if (l->function_name
&& strcmp (e->function_name, l->function_name) == 0) && strcmp (e->function_name, l->function_name) == 0)
{ {
@ -14154,7 +14145,7 @@ find_location_by_number (int bp_num, int loc_num)
error (_("Bad breakpoint location number '%d'"), loc_num); error (_("Bad breakpoint location number '%d'"), loc_num);
int n = 0; int n = 0;
for (bp_location *loc = b->loc; loc != NULL; loc = loc->next) for (bp_location *loc : b->locations ())
if (++n == loc_num) if (++n == loc_num)
return loc; return loc;
@ -14350,9 +14341,7 @@ disable_breakpoint (struct breakpoint *bpt)
if (target_supports_enable_disable_tracepoint () if (target_supports_enable_disable_tracepoint ()
&& current_trace_status ()->running && is_tracepoint (bpt)) && current_trace_status ()->running && is_tracepoint (bpt))
{ {
struct bp_location *location; for (bp_location *location : bpt->locations ())
for (location = bpt->loc; location; location = location->next)
target_disable_tracepoint (location); target_disable_tracepoint (location);
} }
@ -14471,9 +14460,7 @@ enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition,
if (target_supports_enable_disable_tracepoint () if (target_supports_enable_disable_tracepoint ()
&& current_trace_status ()->running && is_tracepoint (bpt)) && current_trace_status ()->running && is_tracepoint (bpt))
{ {
struct bp_location *location; for (bp_location *location : bpt->locations ())
for (location = bpt->loc; location; location = location->next)
target_enable_tracepoint (location); target_enable_tracepoint (location);
} }
@ -14568,9 +14555,7 @@ invalidate_bp_value_on_memory_change (struct inferior *inferior,
if (wp->val_valid && wp->val != nullptr) if (wp->val_valid && wp->val != nullptr)
{ {
struct bp_location *loc; for (bp_location *loc : bp->locations ())
for (loc = bp->loc; loc != NULL; loc = loc->next)
if (loc->loc_type == bp_loc_hardware_watchpoint if (loc->loc_type == bp_loc_hardware_watchpoint
&& loc->address + loc->length > addr && loc->address + loc->length > addr
&& addr + len > loc->address) && addr + len > loc->address)
@ -14639,9 +14624,7 @@ breakpoint_has_location_inserted_here (struct breakpoint *bp,
const address_space *aspace, const address_space *aspace,
CORE_ADDR pc) CORE_ADDR pc)
{ {
struct bp_location *loc; for (bp_location *loc : bp->locations ())
for (loc = bp->loc; loc != NULL; loc = loc->next)
if (loc->inserted if (loc->inserted
&& breakpoint_location_address_match (loc, aspace, pc)) && breakpoint_location_address_match (loc, aspace, pc))
return 1; return 1;
@ -15182,12 +15165,15 @@ save_breakpoints (const char *filename, int from_tty,
special, and not user visible. */ special, and not user visible. */
if (!is_watchpoint (tp) && tp->loc && tp->loc->next) if (!is_watchpoint (tp) && tp->loc && tp->loc->next)
{ {
struct bp_location *loc;
int n = 1; int n = 1;
for (loc = tp->loc; loc != NULL; loc = loc->next, n++) for (bp_location *loc : tp->locations ())
if (!loc->enabled) {
fp.printf ("disable $bpnum.%d\n", n); if (!loc->enabled)
fp.printf ("disable $bpnum.%d\n", n);
n++;
}
} }
} }
@ -15330,14 +15316,12 @@ int
pc_at_non_inline_function (const address_space *aspace, CORE_ADDR pc, pc_at_non_inline_function (const address_space *aspace, CORE_ADDR pc,
const struct target_waitstatus *ws) const struct target_waitstatus *ws)
{ {
struct bp_location *bl;
for (breakpoint *b : all_breakpoints ()) for (breakpoint *b : all_breakpoints ())
{ {
if (!is_non_inline_function (b)) if (!is_non_inline_function (b))
continue; continue;
for (bl = b->loc; bl != NULL; bl = bl->next) for (bp_location *bl : b->locations ())
{ {
if (!bl->shlib_disabled if (!bl->shlib_disabled
&& bpstat_check_location (bl, aspace, pc, ws)) && bpstat_check_location (bl, aspace, pc, ws))

View file

@ -703,6 +703,10 @@ enum watchpoint_triggered
extern bool target_exact_watchpoints; extern bool target_exact_watchpoints;
/* bp_location linked list range. */
using bp_locations_range = next_adapter<bp_location>;
/* Note that the ->silent field is not currently used by any commands /* Note that the ->silent field is not currently used by any commands
(though the code is in there if it was to be, and set_raw_breakpoint (though the code is in there if it was to be, and set_raw_breakpoint
does set it to 0). I implemented it because I thought it would be does set it to 0). I implemented it because I thought it would be
@ -715,6 +719,9 @@ struct breakpoint
{ {
virtual ~breakpoint (); virtual ~breakpoint ();
/* Return a range of this breakpoint's locations. */
bp_locations_range locations ();
/* Methods associated with this breakpoint. */ /* Methods associated with this breakpoint. */
const breakpoint_ops *ops = NULL; const breakpoint_ops *ops = NULL;

View file

@ -783,7 +783,7 @@ jit_breakpoint_deleted (struct breakpoint *b)
if (b->type != bp_jit_event) if (b->type != bp_jit_event)
return; return;
for (bp_location *iter = b->loc; iter != nullptr; iter = iter->next) for (bp_location *iter : b->locations ())
{ {
for (objfile *objf : iter->pspace->objfiles ()) for (objfile *objf : iter->pspace->objfiles ())
{ {

View file

@ -13521,7 +13521,6 @@ remote_target::get_tracepoint_status (struct breakpoint *bp,
{ {
struct remote_state *rs = get_remote_state (); struct remote_state *rs = get_remote_state ();
char *reply; char *reply;
struct bp_location *loc;
struct tracepoint *tp = (struct tracepoint *) bp; struct tracepoint *tp = (struct tracepoint *) bp;
size_t size = get_remote_packet_size (); size_t size = get_remote_packet_size ();
@ -13529,7 +13528,7 @@ remote_target::get_tracepoint_status (struct breakpoint *bp,
{ {
tp->hit_count = 0; tp->hit_count = 0;
tp->traceframe_usage = 0; tp->traceframe_usage = 0;
for (loc = tp->loc; loc; loc = loc->next) for (bp_location *loc : tp->locations ())
{ {
/* If the tracepoint was never downloaded, don't go asking for /* If the tracepoint was never downloaded, don't go asking for
any status. */ any status. */

View file

@ -2019,15 +2019,13 @@ svr4_handle_solib_event (void)
static bool static bool
svr4_update_solib_event_breakpoint (struct breakpoint *b) svr4_update_solib_event_breakpoint (struct breakpoint *b)
{ {
struct bp_location *loc;
if (b->type != bp_shlib_event) if (b->type != bp_shlib_event)
{ {
/* Continue iterating. */ /* Continue iterating. */
return false; return false;
} }
for (loc = b->loc; loc != NULL; loc = loc->next) for (bp_location *loc : b->locations ())
{ {
struct svr4_info *info; struct svr4_info *info;
struct probe_and_action *pa; struct probe_and_action *pa;

View file

@ -636,7 +636,6 @@ validate_actionline (const char *line, struct breakpoint *b)
struct cmd_list_element *c; struct cmd_list_element *c;
const char *tmp_p; const char *tmp_p;
const char *p; const char *p;
struct bp_location *loc;
struct tracepoint *t = (struct tracepoint *) b; struct tracepoint *t = (struct tracepoint *) b;
/* If EOF is typed, *line is NULL. */ /* If EOF is typed, *line is NULL. */
@ -682,7 +681,7 @@ validate_actionline (const char *line, struct breakpoint *b)
/* else fall thru, treat p as an expression and parse it! */ /* else fall thru, treat p as an expression and parse it! */
} }
tmp_p = p; tmp_p = p;
for (loc = t->loc; loc; loc = loc->next) for (bp_location *loc : t->locations ())
{ {
p = tmp_p; p = tmp_p;
expression_up exp = parse_exp_1 (&p, loc->address, expression_up exp = parse_exp_1 (&p, loc->address,
@ -732,7 +731,7 @@ validate_actionline (const char *line, struct breakpoint *b)
p = skip_spaces (p); p = skip_spaces (p);
tmp_p = p; tmp_p = p;
for (loc = t->loc; loc; loc = loc->next) for (bp_location *loc : t->locations ())
{ {
p = tmp_p; p = tmp_p;
@ -1565,9 +1564,7 @@ process_tracepoint_on_disconnect (void)
} }
else else
{ {
struct bp_location *loc1; for (bp_location *loc1 : b->locations ())
for (loc1 = b->loc; loc1; loc1 = loc1->next)
{ {
if (loc1->shlib_disabled) if (loc1->shlib_disabled)
{ {
@ -1643,11 +1640,10 @@ start_tracing (const char *notes)
for (breakpoint *b : tracepoint_range) for (breakpoint *b : tracepoint_range)
{ {
struct tracepoint *t = (struct tracepoint *) b; struct tracepoint *t = (struct tracepoint *) b;
struct bp_location *loc;
int bp_location_downloaded = 0; int bp_location_downloaded = 0;
/* Clear `inserted' flag. */ /* Clear `inserted' flag. */
for (loc = b->loc; loc; loc = loc->next) for (bp_location *loc : b->locations ())
loc->inserted = 0; loc->inserted = 0;
if ((b->type == bp_fast_tracepoint if ((b->type == bp_fast_tracepoint
@ -1657,7 +1653,7 @@ start_tracing (const char *notes)
t->number_on_target = 0; t->number_on_target = 0;
for (loc = b->loc; loc; loc = loc->next) for (bp_location *loc : b->locations ())
{ {
/* Since tracepoint locations are never duplicated, `inserted' /* Since tracepoint locations are never duplicated, `inserted'
flag should be zero. */ flag should be zero. */
@ -1671,7 +1667,7 @@ start_tracing (const char *notes)
t->number_on_target = b->number; t->number_on_target = b->number;
for (loc = b->loc; loc; loc = loc->next) for (bp_location *loc : b->locations ())
if (loc->probe.prob != NULL) if (loc->probe.prob != NULL)
loc->probe.prob->set_semaphore (loc->probe.objfile, loc->probe.prob->set_semaphore (loc->probe.objfile,
loc->gdbarch); loc->gdbarch);
@ -1750,14 +1746,12 @@ stop_tracing (const char *note)
for (breakpoint *t : all_tracepoints ()) for (breakpoint *t : all_tracepoints ())
{ {
struct bp_location *loc;
if ((t->type == bp_fast_tracepoint if ((t->type == bp_fast_tracepoint
? !may_insert_fast_tracepoints ? !may_insert_fast_tracepoints
: !may_insert_tracepoints)) : !may_insert_tracepoints))
continue; continue;
for (loc = t->loc; loc; loc = loc->next) for (bp_location *loc : t->locations ())
{ {
/* GDB can be totally absent in some disconnected trace scenarios, /* GDB can be totally absent in some disconnected trace scenarios,
but we don't really care if this semaphore goes out of sync. but we don't really care if this semaphore goes out of sync.
@ -2763,7 +2757,6 @@ struct bp_location *
get_traceframe_location (int *stepping_frame_p) get_traceframe_location (int *stepping_frame_p)
{ {
struct tracepoint *t; struct tracepoint *t;
struct bp_location *tloc;
struct regcache *regcache; struct regcache *regcache;
if (tracepoint_number == -1) if (tracepoint_number == -1)
@ -2784,7 +2777,7 @@ get_traceframe_location (int *stepping_frame_p)
locations, assume it is a direct hit rather than a while-stepping locations, assume it is a direct hit rather than a while-stepping
frame. (FIXME this is not reliable, should record each frame's frame. (FIXME this is not reliable, should record each frame's
type.) */ type.) */
for (tloc = t->loc; tloc; tloc = tloc->next) for (bp_location *tloc : t->locations ())
if (tloc->address == regcache_read_pc (regcache)) if (tloc->address == regcache_read_pc (regcache))
{ {
*stepping_frame_p = 0; *stepping_frame_p = 0;

View file

@ -459,12 +459,10 @@ tui_source_window_base::update_breakpoint_info
tui_bp_flags mode = 0; tui_bp_flags mode = 0;
iterate_over_breakpoints ([&] (breakpoint *bp) -> bool iterate_over_breakpoints ([&] (breakpoint *bp) -> bool
{ {
struct bp_location *loc;
if (bp == being_deleted) if (bp == being_deleted)
return false; return false;
for (loc = bp->loc; loc != NULL; loc = loc->next) for (bp_location *loc : bp->locations ())
{ {
if (location_matches_p (loc, i)) if (location_matches_p (loc, i))
{ {