337
338
B ? (TMP=B->next, 1): 0; \
340
/* Similar iterators for the low-level breakpoints. */
342
#define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->global_next)
344
#define ALL_BP_LOCATIONS_SAFE(B,TMP) \
345
for (B = bp_location_chain; \
346
B ? (TMP=B->global_next, 1): 0; \
341
/* Similar iterator for the low-level breakpoints. SAFE variant is not
342
provided so update_global_location_list must not be called while executing
343
the block of ALL_BP_LOCATIONS. */
345
#define ALL_BP_LOCATIONS(B,BP_TMP) \
346
for (BP_TMP = bp_location; \
347
BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
349
350
/* Iterator for tracepoints only. */
351
352
#define ALL_TRACEPOINTS(B) \
352
353
for (B = breakpoint_chain; B; B = B->next) \
353
if ((B)->type == bp_tracepoint)
354
if (tracepoint_type (B))
355
356
/* Chains of all breakpoints defined. */
357
358
struct breakpoint *breakpoint_chain;
359
struct bp_location *bp_location_chain;
360
/* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
362
static struct bp_location **bp_location;
364
/* Number of elements of BP_LOCATION. */
366
static unsigned bp_location_count;
368
/* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and ADDRESS
369
for the current elements of BP_LOCATION which get a valid result from
370
bp_location_has_shadow. You can use it for roughly limiting the subrange of
371
BP_LOCATION to scan for shadow bytes for an address you need to read. */
373
static CORE_ADDR bp_location_placed_address_before_address_max;
375
/* Maximum offset plus alignment between
376
bp_target_info.PLACED_ADDRESS + bp_target_info.SHADOW_LEN and ADDRESS for
377
the current elements of BP_LOCATION which get a valid result from
378
bp_location_has_shadow. You can use it for roughly limiting the subrange of
379
BP_LOCATION to scan for shadow bytes for an address you need to read. */
381
static CORE_ADDR bp_location_shadow_len_after_address_max;
361
383
/* The locations that no longer correspond to any breakpoint,
362
unlinked from bp_location_chain, but for which a hit
384
unlinked from bp_location array, but for which a hit
363
385
may still be reported by a target. */
364
386
VEC(bp_location_p) *moribund_locations = NULL;
736
768
error (_("No breakpoint number %d."), bnum);
771
/* Return non-zero if BL->TARGET_INFO contains valid information. */
774
bp_location_has_shadow (struct bp_location *bl)
776
if (bl->loc_type != bp_loc_software_breakpoint)
780
if (bl->target_info.shadow_len == 0)
781
/* bp isn't valid, or doesn't shadow memory. */
739
786
/* Update BUF, which is LEN bytes read from the target address MEMADDR,
740
by replacing any memory breakpoints with their shadowed contents. */
787
by replacing any memory breakpoints with their shadowed contents.
789
The range of shadowed area by each bp_location is:
790
b->address - bp_location_placed_address_before_address_max
791
up to b->address + bp_location_shadow_len_after_address_max
792
The range we were requested to resolve shadows for is:
793
memaddr ... memaddr + len
794
Thus the safe cutoff boundaries for performance optimization are
795
memaddr + len <= b->address - bp_location_placed_address_before_address_max
797
b->address + bp_location_shadow_len_after_address_max <= memaddr */
743
800
breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len)
745
struct bp_location *b;
746
CORE_ADDR bp_addr = 0;
802
/* Left boundary, right boundary and median element of our binary search. */
803
unsigned bc_l, bc_r, bc;
805
/* Find BC_L which is a leftmost element which may affect BUF content. It is
806
safe to report lower value but a failure to report higher one. */
809
bc_r = bp_location_count;
810
while (bc_l + 1 < bc_r)
812
struct bp_location *b;
814
bc = (bc_l + bc_r) / 2;
817
/* Check first B->ADDRESS will not overflow due to the added constant.
818
Then advance the left boundary only if we are sure the BC element can
819
in no way affect the BUF content (MEMADDR to MEMADDR + LEN range).
821
Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety offset so that
822
we cannot miss a breakpoint with its shadow range tail still reaching
825
if (b->address + bp_location_shadow_len_after_address_max >= b->address
826
&& b->address + bp_location_shadow_len_after_address_max <= memaddr)
832
/* Now do full processing of the found relevant range of elements. */
834
for (bc = bc_l; bc < bp_location_count; bc++)
836
struct bp_location *b = bp_location[bc];
837
CORE_ADDR bp_addr = 0;
752
841
if (b->owner->type == bp_none)
753
842
warning (_("reading through apparently deleted breakpoint #%d?"),
754
843
b->owner->number);
756
if (b->loc_type != bp_loc_software_breakpoint)
845
/* Performance optimization: any futher element can no longer affect BUF
848
if (b->address >= bp_location_placed_address_before_address_max
849
&& memaddr + len <= b->address
850
- bp_location_placed_address_before_address_max)
853
if (!bp_location_has_shadow (b))
855
if (!breakpoint_address_match (b->target_info.placed_address_space, 0,
856
current_program_space->aspace, 0))
760
859
/* Addresses and length of the part of the breakpoint that
761
860
we need to copy. */
762
861
bp_addr = b->target_info.placed_address;
763
862
bp_size = b->target_info.shadow_len;
765
/* bp isn't valid, or doesn't shadow memory. */
768
864
if (bp_addr + bp_size <= memaddr)
769
865
/* The breakpoint is entirely before the chunk of memory we
903
1017
- Update the list of values that must be watched in B->loc.
905
1019
If the watchpoint disposition is disp_del_at_next_stop, then do nothing.
906
If this is local watchpoint that is out of scope, delete it. */
1020
If this is local watchpoint that is out of scope, delete it.
1022
Even with `set breakpoint always-inserted on' the watchpoints are removed
1023
+ inserted on each stop here. Normal breakpoints must never be removed
1024
because they might be missed by a running thread when debugging in non-stop
1025
mode. On the other hand, hardware watchpoints (is_hardware_watchpoint;
1026
processed here) are specific to each LWP since they are stored in each LWP's
1027
hardware debug registers. Therefore, such LWP must be stopped first in
1028
order to be able to modify its hardware watchpoints.
1030
Hardware watchpoints must be reset exactly once after being presented to the
1031
user. It cannot be done sooner, because it would reset the data used to
1032
present the watchpoint hit to the user. And it must not be done later
1033
because it could display the same single watchpoint hit during multiple GDB
1034
stops. Note that the latter is relevant only to the hardware watchpoint
1035
types bp_read_watchpoint and bp_access_watchpoint. False hit by
1036
bp_hardware_watchpoint is not user-visible - its hit is suppressed if the
1037
memory content has not changed.
1039
The following constraints influence the location where we can reset hardware
1042
* target_stopped_by_watchpoint and target_stopped_data_address are called
1043
several times when GDB stops.
1046
* Multiple hardware watchpoints can be hit at the same time, causing GDB to
1047
stop. GDB only presents one hardware watchpoint hit at a time as the
1048
reason for stopping, and all the other hits are presented later, one after
1049
the other, each time the user requests the execution to be resumed.
1050
Execution is not resumed for the threads still having pending hit event
1051
stored in LWP_INFO->STATUS. While the watchpoint is already removed from
1052
the inferior on the first stop the thread hit event is kept being reported
1053
from its cached value by linux_nat_stopped_data_address until the real
1054
thread resume happens after the watchpoint gets presented and thus its
1055
LWP_INFO->STATUS gets reset.
1057
Therefore the hardware watchpoint hit can get safely reset on the watchpoint
1058
removal from inferior. */
908
1061
update_watchpoint (struct breakpoint *b, int reparse)
910
1063
int within_current_scope;
911
1064
struct frame_id saved_frame_id;
912
1065
struct bp_location *loc;
915
/* We don't free locations. They are stored in bp_location_chain and
1069
/* If this is a local watchpoint, we only want to check if the
1070
watchpoint frame is in scope if the current thread is the thread
1071
that was used to create the watchpoint. */
1072
if (!watchpoint_in_thread_scope (b))
1075
/* We don't free locations. They are stored in bp_location array and
916
1076
update_global_locations will eventually delete them and remove
917
1077
breakpoints if needed. */
1514
/* This function is called when program space PSPACE is about to be
1515
deleted. It takes care of updating breakpoints to not reference
1519
breakpoint_program_space_exit (struct program_space *pspace)
1521
struct breakpoint *b, *b_temp;
1522
struct bp_location *loc, **loc_temp;
1524
/* Remove any breakpoint that was set through this program space. */
1525
ALL_BREAKPOINTS_SAFE (b, b_temp)
1527
if (b->pspace == pspace)
1528
delete_breakpoint (b);
1531
/* Breakpoints set through other program spaces could have locations
1532
bound to PSPACE as well. Remove those. */
1533
ALL_BP_LOCATIONS (loc, loc_temp)
1535
struct bp_location *tmp;
1537
if (loc->pspace == pspace)
1539
if (loc->owner->loc == loc)
1540
loc->owner->loc = loc->next;
1542
for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next)
1543
if (tmp->next == loc)
1545
tmp->next = loc->next;
1551
/* Now update the global location list to permanently delete the
1552
removed locations above. */
1553
update_global_location_list (0);
1319
1556
/* Make sure all breakpoints are inserted in inferior.
1320
1557
Throws exception on any error.
1321
1558
A breakpoint that is already inserted won't be inserted
1688
1991
detach_breakpoints (int pid)
1690
struct bp_location *b;
1993
struct bp_location *b, **bp_tmp;
1692
1995
struct cleanup *old_chain = save_inferior_ptid ();
1996
struct inferior *inf = current_inferior ();
1694
1998
if (pid == PIDGET (inferior_ptid))
1695
1999
error (_("Cannot detach breakpoints of inferior_ptid"));
1697
/* Set inferior_ptid; remove_breakpoint uses this global. */
2001
/* Set inferior_ptid; remove_breakpoint_1 uses this global. */
1698
2002
inferior_ptid = pid_to_ptid (pid);
1699
ALL_BP_LOCATIONS (b)
2003
ALL_BP_LOCATIONS (b, bp_tmp)
2005
if (b->pspace != inf->pspace)
1701
2008
if (b->inserted)
1702
val |= remove_breakpoint (b, mark_inserted);
2009
val |= remove_breakpoint_1 (b, mark_inserted);
1704
2011
do_cleanups (old_chain);
2015
/* Remove the breakpoint location B from the current address space.
2016
Note that this is used to detach breakpoints from a child fork.
2017
When we get here, the child isn't in the inferior list, and neither
2018
do we have objects to represent its address space --- we should
2019
*not* look at b->pspace->aspace here. */
1709
remove_breakpoint (struct bp_location *b, insertion_state_t is)
2022
remove_breakpoint_1 (struct bp_location *b, insertion_state_t is)
2025
struct cleanup *old_chain;
1713
2027
if (b->owner->enable_state == bp_permanent)
1714
2028
/* Permanent breakpoints cannot be inserted or removed. */
1948
2300
/* Return true if there's a moribund breakpoint at PC. */
1951
moribund_breakpoint_here_p (CORE_ADDR pc)
2303
moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
1953
2305
struct bp_location *loc;
1956
2308
for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
1957
if (loc->address == pc)
2309
if (breakpoint_address_match (loc->pspace->aspace, loc->address,
1963
2316
/* Returns non-zero if there's a breakpoint inserted at PC, which is
1964
inserted using regular breakpoint_chain/bp_location_chain mechanism.
2317
inserted using regular breakpoint_chain / bp_location array mechanism.
1965
2318
This does not check for single-step breakpoints, which are
1966
2319
inserted and removed using direct target manipulation. */
1969
regular_breakpoint_inserted_here_p (CORE_ADDR pc)
2322
regular_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
1971
const struct bp_location *bpt;
2324
struct bp_location *bpt, **bptp_tmp;
1973
ALL_BP_LOCATIONS (bpt)
2326
ALL_BP_LOCATIONS (bpt, bptp_tmp)
1975
2328
if (bpt->loc_type != bp_loc_software_breakpoint
1976
2329
&& bpt->loc_type != bp_loc_hardware_breakpoint)
1979
2332
if (bpt->inserted
1980
&& bpt->address == pc) /* bp is inserted and matches pc */
2333
&& breakpoint_address_match (bpt->pspace->aspace, bpt->address,
1982
2336
if (overlay_debugging
1983
2337
&& section_is_overlay (bpt->section)
2034
2389
/* Also check for software single-step breakpoints. */
2035
if (single_step_breakpoint_inserted_here_p (pc))
2390
if (single_step_breakpoint_inserted_here_p (aspace, pc))
2397
hardware_watchpoint_inserted_in_range (struct address_space *aspace,
2398
CORE_ADDR addr, ULONGEST len)
2400
struct breakpoint *bpt;
2402
ALL_BREAKPOINTS (bpt)
2404
struct bp_location *loc;
2406
if (bpt->type != bp_hardware_watchpoint
2407
&& bpt->type != bp_access_watchpoint)
2410
if (!breakpoint_enabled (bpt))
2413
for (loc = bpt->loc; loc; loc = loc->next)
2414
if (loc->pspace->aspace == aspace && loc->inserted)
2418
/* Check for intersection. */
2419
l = max (loc->address, addr);
2420
h = min (loc->address + loc->length, addr + len);
2041
2428
/* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
2042
2429
PC is valid for process/thread PTID. */
2045
breakpoint_thread_match (CORE_ADDR pc, ptid_t ptid)
2432
breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc,
2047
const struct bp_location *bpt;
2435
struct bp_location *bpt, **bptp_tmp;
2048
2436
/* The thread and task IDs associated to PTID, computed lazily. */
2049
2437
int thread = -1;
2052
ALL_BP_LOCATIONS (bpt)
2440
ALL_BP_LOCATIONS (bpt, bptp_tmp)
2054
2442
if (bpt->loc_type != bp_loc_software_breakpoint
2055
2443
&& bpt->loc_type != bp_loc_hardware_breakpoint)
3167
3578
int need_remove_insert;
3169
ALL_BP_LOCATIONS (bl)
3173
if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
3176
/* For hardware watchpoints, we look only at the first location.
3177
The watchpoint_check function will work on entire expression,
3178
not the individual locations. For read watchopints, the
3179
watchpoints_triggered function have checked all locations
3182
if (b->type == bp_hardware_watchpoint && bl != b->loc)
3185
if (!bpstat_check_location (bl, bp_addr))
3188
/* Come here if it's a watchpoint, or if the break address matches */
3190
bs = bpstat_alloc (bl, bs); /* Alloc a bpstat to explain stop */
3192
/* Assume we stop. Should we find watchpoint that is not actually
3193
triggered, or if condition of breakpoint is false, we'll reset
3198
bpstat_check_watchpoint (bs);
3202
if (b->type == bp_thread_event || b->type == bp_overlay_event
3203
|| b->type == bp_longjmp_master)
3204
/* We do not stop for these. */
3207
bpstat_check_breakpoint_conditions (bs, ptid);
3213
/* We will stop here */
3214
if (b->disposition == disp_disable)
3216
if (b->enable_state != bp_permanent)
3217
b->enable_state = bp_disabled;
3218
update_global_location_list (0);
3222
bs->commands = b->commands;
3224
&& (strcmp ("silent", bs->commands->line) == 0
3225
|| (xdb_commands && strcmp ("Q", bs->commands->line) == 0)))
3227
bs->commands = bs->commands->next;
3230
bs->commands = copy_command_lines (bs->commands);
3233
/* Print nothing for this entry if we dont stop or if we dont print. */
3234
if (bs->stop == 0 || bs->print == 0)
3235
bs->print_it = print_it_noop;
3580
/* ALL_BP_LOCATIONS iteration would break across
3581
update_global_location_list possibly executed by
3582
bpstat_check_breakpoint_conditions's inferior call. */
3586
if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
3589
for (bl = b->loc; bl != NULL; bl = bl->next)
3591
/* For hardware watchpoints, we look only at the first location.
3592
The watchpoint_check function will work on entire expression,
3593
not the individual locations. For read watchopints, the
3594
watchpoints_triggered function have checked all locations
3596
if (b->type == bp_hardware_watchpoint && bl != b->loc)
3599
if (bl->shlib_disabled)
3602
if (!bpstat_check_location (bl, aspace, bp_addr))
3605
/* Come here if it's a watchpoint, or if the break address matches */
3607
bs = bpstat_alloc (bl, bs); /* Alloc a bpstat to explain stop */
3609
/* Assume we stop. Should we find watchpoint that is not actually
3610
triggered, or if condition of breakpoint is false, we'll reset
3615
bpstat_check_watchpoint (bs);
3619
if (b->type == bp_thread_event || b->type == bp_overlay_event
3620
|| b->type == bp_longjmp_master)
3621
/* We do not stop for these. */
3624
bpstat_check_breakpoint_conditions (bs, ptid);
3630
/* We will stop here */
3631
if (b->disposition == disp_disable)
3633
if (b->enable_state != bp_permanent)
3634
b->enable_state = bp_disabled;
3635
update_global_location_list (0);
3639
bs->commands = b->commands;
3641
&& (strcmp ("silent", bs->commands->line) == 0
3642
|| (xdb_commands && strcmp ("Q",
3643
bs->commands->line) == 0)))
3645
bs->commands = bs->commands->next;
3648
bs->commands = copy_command_lines (bs->commands);
3651
/* Print nothing for this entry if we dont stop or dont print. */
3652
if (bs->stop == 0 || bs->print == 0)
3653
bs->print_it = print_it_noop;
3238
3657
for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
3240
if (loc->address == bp_addr)
3659
if (breakpoint_address_match (loc->pspace->aspace, loc->address,
3242
3662
bs = bpstat_alloc (loc, bs);
3243
3663
/* For hits of moribund locations, we should just proceed. */
4125
4596
breakpoint_has_pc (struct breakpoint *b,
4597
struct program_space *pspace,
4126
4598
CORE_ADDR pc, struct obj_section *section)
4128
4600
struct bp_location *bl = b->loc;
4129
4601
for (; bl; bl = bl->next)
4131
if (bl->address == pc
4603
if (bl->pspace == pspace
4604
&& bl->address == pc
4132
4605
&& (!overlay_debugging || bl->section == section))
4138
/* Print a message describing any breakpoints set at PC. */
4611
/* Print a message describing any breakpoints set at PC. This
4612
concerns with logical breakpoints, so we match program spaces, not
4141
describe_other_breakpoints (struct gdbarch *gdbarch, CORE_ADDR pc,
4616
describe_other_breakpoints (struct gdbarch *gdbarch,
4617
struct program_space *pspace, CORE_ADDR pc,
4142
4618
struct obj_section *section, int thread)
4144
4620
int others = 0;
4145
4621
struct breakpoint *b;
4147
4623
ALL_BREAKPOINTS (b)
4148
others += breakpoint_has_pc (b, pc, section);
4624
others += breakpoint_has_pc (b, pspace, pc, section);
4149
4625
if (others > 0)
4151
4627
if (others == 1)
4197
4675
(or use it for any other purpose either).
4199
4677
More specifically, each of the following breakpoint types will always
4200
have a zero valued address and we don't want check_duplicates() to mark
4201
breakpoints of any of these types to be a duplicate of an actual
4202
breakpoint at address zero:
4678
have a zero valued address and we don't want to mark breakpoints of any of
4679
these types to be a duplicate of an actual breakpoint at address zero:
4205
bp_hardware_watchpoint
4207
bp_access_watchpoint
4211
4687
breakpoint_address_is_meaningful (struct breakpoint *bpt)
4213
4689
enum bptype type = bpt->type;
4215
return (type != bp_watchpoint
4216
&& type != bp_hardware_watchpoint
4217
&& type != bp_read_watchpoint
4218
&& type != bp_access_watchpoint
4219
&& type != bp_catchpoint);
4222
/* Rescan breakpoints at the same address and section as BPT,
4223
marking the first one as "first" and any others as "duplicates".
4224
This is so that the bpt instruction is only inserted once.
4225
If we have a permanent breakpoint at the same place as BPT, make
4226
that one the official one, and the rest as duplicates. */
4229
check_duplicates_for (CORE_ADDR address, struct obj_section *section)
4231
struct bp_location *b;
4233
struct bp_location *perm_bp = 0;
4235
ALL_BP_LOCATIONS (b)
4236
if (b->owner->enable_state != bp_disabled
4237
&& b->owner->enable_state != bp_call_disabled
4238
&& b->owner->enable_state != bp_startup_disabled
4240
&& !b->shlib_disabled
4241
&& b->address == address /* address / overlay match */
4242
&& (!overlay_debugging || b->section == section)
4243
&& breakpoint_address_is_meaningful (b->owner))
4245
/* Have we found a permanent breakpoint? */
4246
if (b->owner->enable_state == bp_permanent)
4253
b->duplicate = count > 1;
4256
/* If we found a permanent breakpoint at this address, go over the
4257
list again and declare all the other breakpoints there (except
4258
other permanent breakpoints) to be the duplicates. */
4261
perm_bp->duplicate = 0;
4263
/* Permanent breakpoint should always be inserted. */
4264
if (! perm_bp->inserted)
4265
internal_error (__FILE__, __LINE__,
4266
_("allegedly permanent breakpoint is not "
4267
"actually inserted"));
4269
ALL_BP_LOCATIONS (b)
4272
if (b->owner->enable_state != bp_permanent
4273
&& b->owner->enable_state != bp_disabled
4274
&& b->owner->enable_state != bp_call_disabled
4275
&& b->owner->enable_state != bp_startup_disabled
4276
&& b->enabled && !b->shlib_disabled
4277
&& b->address == address /* address / overlay match */
4278
&& (!overlay_debugging || b->section == section)
4279
&& breakpoint_address_is_meaningful (b->owner))
4282
internal_error (__FILE__, __LINE__,
4283
_("another breakpoint was inserted on top of "
4284
"a permanent breakpoint"));
4293
check_duplicates (struct breakpoint *bpt)
4295
struct bp_location *bl = bpt->loc;
4297
if (! breakpoint_address_is_meaningful (bpt))
4300
for (; bl; bl = bl->next)
4301
check_duplicates_for (bl->address, bl->section);
4691
return (type != bp_watchpoint && type != bp_catchpoint);
4694
/* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
4695
true if LOC1 and LOC2 represent the same watchpoint location. */
4698
watchpoint_locations_match (struct bp_location *loc1, struct bp_location *loc2)
4700
return (loc1->owner->type == loc2->owner->type
4701
&& loc1->pspace->aspace == loc2->pspace->aspace
4702
&& loc1->address == loc2->address
4703
&& loc1->length == loc2->length);
4706
/* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
4707
same breakpoint location. In most targets, this can only be true
4708
if ASPACE1 matches ASPACE2. On targets that have global
4709
breakpoints, the address space doesn't really matter. */
4712
breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1,
4713
struct address_space *aspace2, CORE_ADDR addr2)
4715
return ((gdbarch_has_global_breakpoints (target_gdbarch)
4716
|| aspace1 == aspace2)
4720
/* Assuming LOC1 and LOC2's types' have meaningful target addresses
4721
(breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
4722
represent the same location. */
4725
breakpoint_locations_match (struct bp_location *loc1, struct bp_location *loc2)
4727
int hw_point1 = is_hardware_watchpoint (loc1->owner);
4728
int hw_point2 = is_hardware_watchpoint (loc2->owner);
4730
if (hw_point1 != hw_point2)
4733
return watchpoint_locations_match (loc1, loc2);
4735
return breakpoint_address_match (loc1->pspace->aspace, loc1->address,
4736
loc2->pspace->aspace, loc2->address);
5864
6341
--(sal->nelts);
5867
/* If appropriate, obtains all sals that correspond
5868
to the same file and line as SAL. This is done
5869
only if SAL does not have explicit PC and has
5870
line and file information. If we got just a single
5871
expanded sal, return the original.
5873
Otherwise, if SAL.explicit_line is not set, filter out
5874
all sals for which the name of enclosing function
5875
is different from SAL. This makes sure that if we have
5876
breakpoint originally set in template instantiation, say
5877
foo<int>(), we won't expand SAL to locations at the same
5878
line in all existing instantiations of 'foo'.
6344
/* If appropriate, obtains all sals that correspond to the same file
6345
and line as SAL, in all program spaces. Users debugging with IDEs,
6346
will want to set a breakpoint at foo.c:line, and not really care
6347
about program spaces. This is done only if SAL does not have
6348
explicit PC and has line and file information. If we got just a
6349
single expanded sal, return the original.
6351
Otherwise, if SAL.explicit_line is not set, filter out all sals for
6352
which the name of enclosing function is different from SAL. This
6353
makes sure that if we have breakpoint originally set in template
6354
instantiation, say foo<int>(), we won't expand SAL to locations at
6355
the same line in all existing instantiations of 'foo'. */
5881
6357
static struct symtabs_and_lines
5882
6358
expand_line_sal_maybe (struct symtab_and_line sal)
6120
6613
resolve_sal_pc (&sals->sals[i]);
6616
/* Fast tracepoints may have restrictions on valid locations. For
6617
instance, a fast tracepoint using a jump instead of a trap will
6618
likely have to overwrite more bytes than a trap would, and so can
6619
only be placed where the instruction is longer than the jump, or a
6620
multi-instruction sequence does not have a jump into the middle of
6624
check_fast_tracepoint_sals (struct gdbarch *gdbarch,
6625
struct symtabs_and_lines *sals)
6628
struct symtab_and_line *sal;
6630
struct cleanup *old_chain;
6632
for (i = 0; i < sals->nelts; i++)
6634
sal = &sals->sals[i];
6636
rslt = gdbarch_fast_tracepoint_valid_at (gdbarch, sal->pc,
6638
old_chain = make_cleanup (xfree, msg);
6641
error (_("May not have a fast tracepoint at 0x%s%s"),
6642
paddress (gdbarch, sal->pc), (msg ? msg : ""));
6644
do_cleanups (old_chain);
6124
6649
do_captured_parse_breakpoint (struct ui_out *ui, void *data)
6190
6715
if (tok == tmptok)
6191
6716
error (_("Junk after task keyword."));
6192
6717
if (!valid_task_id (*task))
6193
error (_("Unknown task %d\n"), *task);
6718
error (_("Unknown task %d."), *task);
6196
6721
error (_("Junk at end of arguments."));
6200
/* Set a breakpoint. This function is shared between
6201
CLI and MI functions for setting a breakpoint.
6202
This function has two major modes of operations,
6203
selected by the PARSE_CONDITION_AND_THREAD parameter.
6204
If non-zero, the function will parse arg, extracting
6205
breakpoint location, address and thread. Otherwise,
6206
ARG is just the location of breakpoint, with condition
6207
and thread specified by the COND_STRING and THREAD
6725
/* Set a breakpoint. This function is shared between CLI and MI
6726
functions for setting a breakpoint. This function has two major
6727
modes of operations, selected by the PARSE_CONDITION_AND_THREAD
6728
parameter. If non-zero, the function will parse arg, extracting
6729
breakpoint location, address and thread. Otherwise, ARG is just the
6730
location of breakpoint, with condition and thread specified by the
6731
COND_STRING and THREAD parameters. Returns true if any breakpoint
6732
was created; false otherwise. */
6211
6735
break_command_really (struct gdbarch *gdbarch,
6212
6736
char *arg, char *cond_string, int thread,
6213
6737
int parse_condition_and_thread,
7751
/* A cleanup function which destroys a vector. */
8260
/* A comparison function for bp_location AP and BP being interfaced to qsort.
8261
Sort elements primarily by their ADDRESS (no matter what does
8262
breakpoint_address_is_meaningful say for its OWNER), secondarily by ordering
8263
first bp_permanent OWNERed elements and terciarily just ensuring the array
8264
is sorted stable way despite qsort being an instable algorithm. */
8267
bp_location_compare (const void *ap, const void *bp)
8269
struct bp_location *a = *(void **) ap;
8270
struct bp_location *b = *(void **) bp;
8271
int a_perm = a->owner->enable_state == bp_permanent;
8272
int b_perm = b->owner->enable_state == bp_permanent;
8274
if (a->address != b->address)
8275
return (a->address > b->address) - (a->address < b->address);
8277
/* Sort permanent breakpoints first. */
8278
if (a_perm != b_perm)
8279
return (a_perm < b_perm) - (a_perm > b_perm);
8281
/* Make the user-visible order stable across GDB runs. Locations of the same
8282
breakpoint can be sorted in arbitrary order. */
8284
if (a->owner->number != b->owner->number)
8285
return (a->owner->number > b->owner->number)
8286
- (a->owner->number < b->owner->number);
8288
return (a > b) - (a < b);
8291
/* Set bp_location_placed_address_before_address_max and
8292
bp_location_shadow_len_after_address_max according to the current content of
8293
the bp_location array. */
7754
do_vec_free (void *p)
8296
bp_location_target_extensions_update (void)
7756
VEC(bp_location_p) **vec = p;
7758
VEC_free (bp_location_p, *vec);
8298
struct bp_location *bl, **blp_tmp;
8300
bp_location_placed_address_before_address_max = 0;
8301
bp_location_shadow_len_after_address_max = 0;
8303
ALL_BP_LOCATIONS (bl, blp_tmp)
8305
CORE_ADDR start, end, addr;
8307
if (!bp_location_has_shadow (bl))
8310
start = bl->target_info.placed_address;
8311
end = start + bl->target_info.shadow_len;
8313
gdb_assert (bl->address >= start);
8314
addr = bl->address - start;
8315
if (addr > bp_location_placed_address_before_address_max)
8316
bp_location_placed_address_before_address_max = addr;
8318
/* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
8320
gdb_assert (bl->address < end);
8321
addr = end - bl->address;
8322
if (addr > bp_location_shadow_len_after_address_max)
8323
bp_location_shadow_len_after_address_max = addr;
7761
8327
/* If SHOULD_INSERT is false, do not insert any breakpoint locations
7777
8343
update_global_location_list (int should_insert)
7779
8345
struct breakpoint *b;
7780
struct bp_location **next = &bp_location_chain;
7781
struct bp_location *loc;
7782
struct bp_location *loc2;
7783
VEC(bp_location_p) *old_locations = NULL;
8346
struct bp_location **locp, *loc;
7786
8347
struct cleanup *cleanups;
7788
cleanups = make_cleanup (do_vec_free, &old_locations);
7789
/* Store old locations for future reference. */
7790
for (loc = bp_location_chain; loc; loc = loc->global_next)
7791
VEC_safe_push (bp_location_p, old_locations, loc);
7793
bp_location_chain = NULL;
7796
for (loc = b->loc; loc; loc = loc->next)
7799
next = &(loc->global_next);
8349
/* Used in the duplicates detection below. When iterating over all
8350
bp_locations, points to the first bp_location of a given address.
8351
Breakpoints and watchpoints of different types are never
8352
duplicates of each other. Keep one pointer for each type of
8353
breakpoint/watchpoint, so we only need to loop over all locations
8355
struct bp_location *bp_loc_first; /* breakpoint */
8356
struct bp_location *wp_loc_first; /* hardware watchpoint */
8357
struct bp_location *awp_loc_first; /* access watchpoint */
8358
struct bp_location *rwp_loc_first; /* read watchpoint */
8360
/* Saved former bp_location array which we compare against the newly built
8361
bp_location from the current state of ALL_BREAKPOINTS. */
8362
struct bp_location **old_location, **old_locp;
8363
unsigned old_location_count;
8365
old_location = bp_location;
8366
old_location_count = bp_location_count;
8368
bp_location_count = 0;
8369
cleanups = make_cleanup (xfree, old_location);
8372
for (loc = b->loc; loc; loc = loc->next)
8373
bp_location_count++;
8375
bp_location = xmalloc (sizeof (*bp_location) * bp_location_count);
8378
for (loc = b->loc; loc; loc = loc->next)
8380
qsort (bp_location, bp_location_count, sizeof (*bp_location),
8381
bp_location_compare);
8383
bp_location_target_extensions_update ();
7804
8385
/* Identify bp_location instances that are no longer present in the new
7805
8386
list, and therefore should be freed. Note that it's not necessary that
7806
8387
those locations should be removed from inferior -- if there's another
7807
8388
location at the same address (previously marked as duplicate),
7808
we don't need to remove/insert the location. */
7809
for (ix = 0; VEC_iterate(bp_location_p, old_locations, ix, loc); ++ix)
8389
we don't need to remove/insert the location.
8391
LOCP is kept in sync with OLD_LOCP, each pointing to the current and
8392
former bp_location array state respectively. */
8395
for (old_locp = old_location; old_locp < old_location + old_location_count;
7811
/* Tells if 'loc' is found amoung the new locations. If not, we
8398
struct bp_location *old_loc = *old_locp;
8399
struct bp_location **loc2p;
8401
/* Tells if 'old_loc' is found amoung the new locations. If not, we
7812
8402
have to free it. */
7813
8403
int found_object = 0;
7814
8404
/* Tells if the location should remain inserted in the target. */
7815
8405
int keep_in_target = 0;
7816
8406
int removed = 0;
7817
for (loc2 = bp_location_chain; loc2; loc2 = loc2->global_next)
8408
/* Skip LOCP entries which will definitely never be needed. Stop either
8409
at or being the one matching OLD_LOC. */
8410
while (locp < bp_location + bp_location_count
8411
&& (*locp)->address < old_loc->address)
8415
(loc2p < bp_location + bp_location_count
8416
&& (*loc2p)->address == old_loc->address);
8419
if (*loc2p == old_loc)
7824
8426
/* If this location is no longer present, and inserted, look if there's
7825
8427
maybe a new location at the same address. If so, mark that one
7842
8444
/* The location is either no longer present, or got disabled.
7843
8445
See if there's another location at the same address, in which
7844
8446
case we don't need to remove this one from the target. */
7845
if (breakpoint_address_is_meaningful (loc->owner))
7846
for (loc2 = bp_location_chain; loc2; loc2 = loc2->global_next)
7848
/* For the sake of should_insert_location. The
7849
call to check_duplicates will fix up this later. */
7850
loc2->duplicate = 0;
7851
if (should_be_inserted (loc2)
7852
&& loc2 != loc && loc2->address == loc->address)
7855
loc2->target_info = loc->target_info;
8448
if (breakpoint_address_is_meaningful (old_loc->owner))
8451
(loc2p < bp_location + bp_location_count
8452
&& (*loc2p)->address == old_loc->address);
8455
struct bp_location *loc2 = *loc2p;
8457
if (breakpoint_locations_match (loc2, old_loc))
8459
/* For the sake of should_be_inserted.
8460
Duplicates check below will fix up this later. */
8461
loc2->duplicate = 0;
8462
if (loc2 != old_loc && should_be_inserted (loc2))
8465
loc2->target_info = old_loc->target_info;
7862
8474
if (!keep_in_target)
7864
if (remove_breakpoint (loc, mark_uninserted))
8476
if (remove_breakpoint (old_loc, mark_uninserted))
7866
8478
/* This is just about all we can do. We could keep this
7867
8479
location on the global list, and try to remove it next
7868
8480
time, but there's no particular reason why we will
7869
8481
succeed next time.
7871
Note that at this point, loc->owner is still valid,
8483
Note that at this point, old_loc->owner is still valid,
7872
8484
as delete_breakpoint frees the breakpoint only
7873
8485
after calling us. */
7874
8486
printf_filtered (_("warning: Error removing breakpoint %d\n"),
7875
loc->owner->number);
8487
old_loc->owner->number);
7881
8493
if (!found_object)
7883
if (removed && non_stop)
8495
if (removed && non_stop
8496
&& breakpoint_address_is_meaningful (old_loc->owner)
8497
&& !is_hardware_watchpoint (old_loc->owner))
7885
/* This location was removed from the targets. In non-stop mode,
7886
a race condition is possible where we've removed a breakpoint,
7887
but stop events for that breakpoint are already queued and will
7888
arrive later. To suppress spurious SIGTRAPs reported to user,
7889
we keep this breakpoint location for a bit, and will retire it
7890
after we see 3 * thread_count events.
7891
The theory here is that reporting of events should,
7892
"on the average", be fair, so after that many event we'll see
7893
events from all threads that have anything of interest, and no
7894
longer need to keep this breakpoint. This is just a
7895
heuristic, but if it's wrong, we'll report unexpected SIGTRAP,
7896
which is usability issue, but not a correctness problem. */
7897
loc->events_till_retirement = 3 * (thread_count () + 1);
7900
VEC_safe_push (bp_location_p, moribund_locations, loc);
8499
/* This location was removed from the target. In
8500
non-stop mode, a race condition is possible where
8501
we've removed a breakpoint, but stop events for that
8502
breakpoint are already queued and will arrive later.
8503
We apply an heuristic to be able to distinguish such
8504
SIGTRAPs from other random SIGTRAPs: we keep this
8505
breakpoint location for a bit, and will retire it
8506
after we see some number of events. The theory here
8507
is that reporting of events should, "on the average",
8508
be fair, so after a while we'll see events from all
8509
threads that have anything of interest, and no longer
8510
need to keep this breakpoint location around. We
8511
don't hold locations forever so to reduce chances of
8512
mistaking a non-breakpoint SIGTRAP for a breakpoint
8515
The heuristic failing can be disastrous on
8516
decr_pc_after_break targets.
8518
On decr_pc_after_break targets, like e.g., x86-linux,
8519
if we fail to recognize a late breakpoint SIGTRAP,
8520
because events_till_retirement has reached 0 too
8521
soon, we'll fail to do the PC adjustment, and report
8522
a random SIGTRAP to the user. When the user resumes
8523
the inferior, it will most likely immediately crash
8524
with SIGILL/SIGBUS/SEGSEGV, or worse, get silently
8525
corrupted, because of being resumed e.g., in the
8526
middle of a multi-byte instruction, or skipped a
8527
one-byte instruction. This was actually seen happen
8528
on native x86-linux, and should be less rare on
8529
targets that do not support new thread events, like
8530
remote, due to the heuristic depending on
8533
Mistaking a random SIGTRAP for a breakpoint trap
8534
causes similar symptoms (PC adjustment applied when
8535
it shouldn't), but then again, playing with SIGTRAPs
8536
behind the debugger's back is asking for trouble.
8538
Since hardware watchpoint traps are always
8539
distinguishable from other traps, so we don't need to
8540
apply keep hardware watchpoint moribund locations
8541
around. We simply always ignore hardware watchpoint
8542
traps we can no longer explain. */
8544
old_loc->events_till_retirement = 3 * (thread_count () + 1);
8545
old_loc->owner = NULL;
8547
VEC_safe_push (bp_location_p, moribund_locations, old_loc);
7903
free_bp_location (loc);
8550
free_bp_location (old_loc);
8554
/* Rescan breakpoints at the same address and section, marking the
8555
first one as "first" and any others as "duplicates". This is so
8556
that the bpt instruction is only inserted once. If we have a
8557
permanent breakpoint at the same place as BPT, make that one the
8558
official one, and the rest as duplicates. Permanent breakpoints
8559
are sorted first for the same address.
8561
Do the same for hardware watchpoints, but also considering the
8562
watchpoint's type (regular/access/read) and length. */
8564
bp_loc_first = NULL;
8565
wp_loc_first = NULL;
8566
awp_loc_first = NULL;
8567
rwp_loc_first = NULL;
8568
ALL_BP_LOCATIONS (loc, locp)
7909
check_duplicates (b);
8570
struct breakpoint *b = loc->owner;
8571
struct bp_location **loc_first_p;
8573
if (b->enable_state == bp_disabled
8574
|| b->enable_state == bp_call_disabled
8575
|| b->enable_state == bp_startup_disabled
8577
|| loc->shlib_disabled
8578
|| !breakpoint_address_is_meaningful (b)
8579
|| tracepoint_type (b))
8582
/* Permanent breakpoint should always be inserted. */
8583
if (b->enable_state == bp_permanent && ! loc->inserted)
8584
internal_error (__FILE__, __LINE__,
8585
_("allegedly permanent breakpoint is not "
8586
"actually inserted"));
8588
if (b->type == bp_hardware_watchpoint)
8589
loc_first_p = &wp_loc_first;
8590
else if (b->type == bp_read_watchpoint)
8591
loc_first_p = &rwp_loc_first;
8592
else if (b->type == bp_access_watchpoint)
8593
loc_first_p = &awp_loc_first;
8595
loc_first_p = &bp_loc_first;
8597
if (*loc_first_p == NULL
8598
|| (overlay_debugging && loc->section != (*loc_first_p)->section)
8599
|| !breakpoint_locations_match (loc, *loc_first_p))
8608
if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted
8609
&& b->enable_state != bp_permanent)
8610
internal_error (__FILE__, __LINE__,
8611
_("another breakpoint was inserted on top of "
8612
"a permanent breakpoint"));
7912
8615
if (breakpoints_always_inserted_mode () && should_insert
8341
gdb_assert (sals.nelts == 1);
8342
resolve_sal_pc (&sals.sals[0]);
8343
if (b->condition_not_parsed && s && s[0])
8345
char *cond_string = 0;
8349
find_condition_and_thread (s, sals.sals[0].pc,
8350
&cond_string, &thread, &task);
8352
b->cond_string = cond_string;
8355
b->condition_not_parsed = 0;
9059
gdb_assert (sals.nelts == 1);
9061
resolve_sal_pc (&sals.sals[0]);
9062
if (b->condition_not_parsed && s && s[0])
9064
char *cond_string = 0;
9068
find_condition_and_thread (s, sals.sals[0].pc,
9069
&cond_string, &thread, &task);
9071
b->cond_string = cond_string;
9074
b->condition_not_parsed = 0;
9077
expanded = expand_line_sal_maybe (sals.sals[0]);
8357
expanded = expand_line_sal_maybe (sals.sals[0]);
8358
cleanups = make_cleanup (xfree, sals.sals);
9080
make_cleanup (xfree, sals.sals);
8359
9081
update_breakpoint_locations (b, expanded);
8360
do_cleanups (cleanups);
8363
9084
case bp_watchpoint:
9022
9792
trace_command (char *arg, int from_tty)
9024
break_command_really (get_current_arch (),
9026
NULL, 0, 1 /* parse arg */,
9027
0 /* tempflag */, 0 /* hardwareflag */,
9029
0 /* Ignore count */,
9030
pending_break_support,
9794
if (break_command_really (get_current_arch (),
9796
NULL, 0, 1 /* parse arg */,
9797
0 /* tempflag */, 0 /* hardwareflag */,
9799
0 /* Ignore count */,
9800
pending_break_support,
9804
set_tracepoint_count (breakpoint_count);
9808
ftrace_command (char *arg, int from_tty)
9810
if (break_command_really (get_current_arch (),
9812
NULL, 0, 1 /* parse arg */,
9813
0 /* tempflag */, 1 /* hardwareflag */,
9815
0 /* Ignore count */,
9816
pending_break_support,
9820
set_tracepoint_count (breakpoint_count);
9823
/* Given information about a tracepoint as recorded on a target (which
9824
can be either a live system or a trace file), attempt to create an
9825
equivalent GDB tracepoint. This is not a reliable process, since
9826
the target does not necessarily have all the information used when
9827
the tracepoint was originally defined. */
9830
create_tracepoint_from_upload (struct uploaded_tp *utp)
9833
struct breakpoint *tp;
9835
/* In the absence of a source location, fall back to raw address. */
9836
sprintf (buf, "*%s", paddress (get_current_arch(), utp->addr));
9838
if (!break_command_really (get_current_arch (),
9840
NULL, 0, 1 /* parse arg */,
9842
(utp->type == bp_fast_tracepoint) /* hardwareflag */,
9844
0 /* Ignore count */,
9845
pending_break_support,
9848
utp->enabled /* enabled */))
9034
9851
set_tracepoint_count (breakpoint_count);
9853
tp = get_tracepoint (tracepoint_count);
9854
gdb_assert (tp != NULL);
9858
sprintf (buf, "%d %d", utp->pass, tp->number);
9860
trace_pass_command (buf, 0);
9865
printf_filtered ("Want to restore a condition\n");
9868
if (utp->numactions > 0)
9870
printf_filtered ("Want to restore action list\n");
9873
if (utp->num_step_actions > 0)
9875
printf_filtered ("Want to restore action list\n");
9037
9881
/* Print information on tracepoint number TPNUM_EXP, or all if