Constify breakpoint::print_recreate
[binutils-gdb.git] / gdb / breakpoint.h
1 /* Data structures associated with breakpoints in GDB.
2 Copyright (C) 1992-2022 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18
19 #if !defined (BREAKPOINT_H)
20 #define BREAKPOINT_H 1
21
22 #include "frame.h"
23 #include "value.h"
24 #include "ax.h"
25 #include "command.h"
26 #include "gdbsupport/break-common.h"
27 #include "probe.h"
28 #include "location.h"
29 #include <vector>
30 #include "gdbsupport/array-view.h"
31 #include "gdbsupport/filtered-iterator.h"
32 #include "gdbsupport/function-view.h"
33 #include "gdbsupport/next-iterator.h"
34 #include "gdbsupport/iterator-range.h"
35 #include "gdbsupport/refcounted-object.h"
36 #include "gdbsupport/safe-iterator.h"
37 #include "cli/cli-script.h"
38
39 struct block;
40 struct gdbpy_breakpoint_object;
41 struct gdbscm_breakpoint_object;
42 struct number_or_range_parser;
43 struct thread_info;
44 struct bpstat;
45 struct bp_location;
46 struct linespec_result;
47 struct linespec_sals;
48 struct inferior;
49
50 /* Enum for exception-handling support in 'catch throw', 'catch rethrow',
51 'catch catch' and the MI equivalent. */
52
53 enum exception_event_kind
54 {
55 EX_EVENT_THROW,
56 EX_EVENT_RETHROW,
57 EX_EVENT_CATCH
58 };
59
60 /* Why are we removing the breakpoint from the target? */
61
62 enum remove_bp_reason
63 {
64 /* A regular remove. Remove the breakpoint and forget everything
65 about it. */
66 REMOVE_BREAKPOINT,
67
68 /* Detach the breakpoints from a fork child. */
69 DETACH_BREAKPOINT,
70 };
71
72 /* This is the maximum number of bytes a breakpoint instruction can
73 take. Feel free to increase it. It's just used in a few places to
74 size arrays that should be independent of the target
75 architecture. */
76
77 #define BREAKPOINT_MAX 16
78 \f
79
80 /* Type of breakpoint. */
81
82 enum bptype
83 {
84 bp_none = 0, /* Eventpoint has been deleted */
85 bp_breakpoint, /* Normal breakpoint */
86 bp_hardware_breakpoint, /* Hardware assisted breakpoint */
87 bp_single_step, /* Software single-step */
88 bp_until, /* used by until command */
89 bp_finish, /* used by finish command */
90 bp_watchpoint, /* Watchpoint */
91 bp_hardware_watchpoint, /* Hardware assisted watchpoint */
92 bp_read_watchpoint, /* read watchpoint, (hardware assisted) */
93 bp_access_watchpoint, /* access watchpoint, (hardware assisted) */
94 bp_longjmp, /* secret breakpoint to find longjmp() */
95 bp_longjmp_resume, /* secret breakpoint to escape longjmp() */
96
97 /* Breakpoint placed to the same location(s) like bp_longjmp but used to
98 protect against stale DUMMY_FRAME. Multiple bp_longjmp_call_dummy and
99 one bp_call_dummy are chained together by related_breakpoint for each
100 DUMMY_FRAME. */
101 bp_longjmp_call_dummy,
102
103 /* An internal breakpoint that is installed on the unwinder's
104 debug hook. */
105 bp_exception,
106 /* An internal breakpoint that is set at the point where an
107 exception will land. */
108 bp_exception_resume,
109
110 /* Used by wait_for_inferior for stepping over subroutine calls,
111 and for skipping prologues. */
112 bp_step_resume,
113
114 /* Used by wait_for_inferior for stepping over signal
115 handlers. */
116 bp_hp_step_resume,
117
118 /* Used to detect when a watchpoint expression has gone out of
119 scope. These breakpoints are usually not visible to the user.
120
121 This breakpoint has some interesting properties:
122
123 1) There's always a 1:1 mapping between watchpoints
124 on local variables and watchpoint_scope breakpoints.
125
126 2) It automatically deletes itself and the watchpoint it's
127 associated with when hit.
128
129 3) It can never be disabled. */
130 bp_watchpoint_scope,
131
132 /* The breakpoint at the end of a call dummy. See bp_longjmp_call_dummy it
133 is chained with by related_breakpoint. */
134 bp_call_dummy,
135
136 /* A breakpoint set on std::terminate, that is used to catch
137 otherwise uncaught exceptions thrown during an inferior call. */
138 bp_std_terminate,
139
140 /* Some dynamic linkers (HP, maybe Solaris) can arrange for special
141 code in the inferior to run when significant events occur in the
142 dynamic linker (for example a library is loaded or unloaded).
143
144 By placing a breakpoint in this magic code GDB will get control
145 when these significant events occur. GDB can then re-examine
146 the dynamic linker's data structures to discover any newly loaded
147 dynamic libraries. */
148 bp_shlib_event,
149
150 /* Some multi-threaded systems can arrange for a location in the
151 inferior to be executed when certain thread-related events occur
152 (such as thread creation or thread death).
153
154 By placing a breakpoint at one of these locations, GDB will get
155 control when these events occur. GDB can then update its thread
156 lists etc. */
157
158 bp_thread_event,
159
160 /* On the same principal, an overlay manager can arrange to call a
161 magic location in the inferior whenever there is an interesting
162 change in overlay status. GDB can update its overlay tables
163 and fiddle with breakpoints in overlays when this breakpoint
164 is hit. */
165
166 bp_overlay_event,
167
168 /* Master copies of longjmp breakpoints. These are always installed
169 as soon as an objfile containing longjmp is loaded, but they are
170 always disabled. While necessary, temporary clones of bp_longjmp
171 type will be created and enabled. */
172
173 bp_longjmp_master,
174
175 /* Master copies of std::terminate breakpoints. */
176 bp_std_terminate_master,
177
178 /* Like bp_longjmp_master, but for exceptions. */
179 bp_exception_master,
180
181 bp_catchpoint,
182
183 bp_tracepoint,
184 bp_fast_tracepoint,
185 bp_static_tracepoint,
186 /* Like bp_static_tracepoint but for static markers. */
187 bp_static_marker_tracepoint,
188
189 /* A dynamic printf stops at the given location, does a formatted
190 print, then automatically continues. (Although this is sort of
191 like a macro packaging up standard breakpoint functionality,
192 GDB doesn't have a way to construct types of breakpoint from
193 elements of behavior.) */
194 bp_dprintf,
195
196 /* Event for JIT compiled code generation or deletion. */
197 bp_jit_event,
198
199 /* Breakpoint is placed at the STT_GNU_IFUNC resolver. When hit GDB
200 inserts new bp_gnu_ifunc_resolver_return at the caller.
201 bp_gnu_ifunc_resolver is still being kept here as a different thread
202 may still hit it before bp_gnu_ifunc_resolver_return is hit by the
203 original thread. */
204 bp_gnu_ifunc_resolver,
205
206 /* On its hit GDB now know the resolved address of the target
207 STT_GNU_IFUNC function. Associated bp_gnu_ifunc_resolver can be
208 deleted now and the breakpoint moved to the target function entry
209 point. */
210 bp_gnu_ifunc_resolver_return,
211 };
212
213 /* States of enablement of breakpoint. */
214
215 enum enable_state
216 {
217 bp_disabled, /* The eventpoint is inactive, and cannot
218 trigger. */
219 bp_enabled, /* The eventpoint is active, and can
220 trigger. */
221 bp_call_disabled, /* The eventpoint has been disabled while a
222 call into the inferior is "in flight",
223 because some eventpoints interfere with
224 the implementation of a call on some
225 targets. The eventpoint will be
226 automatically enabled and reset when the
227 call "lands" (either completes, or stops
228 at another eventpoint). */
229 };
230
231
232 /* Disposition of breakpoint. Ie: what to do after hitting it. */
233
234 enum bpdisp
235 {
236 disp_del, /* Delete it */
237 disp_del_at_next_stop, /* Delete at next stop,
238 whether hit or not */
239 disp_disable, /* Disable it */
240 disp_donttouch /* Leave it alone */
241 };
242
243 /* Status of breakpoint conditions used when synchronizing
244 conditions with the target. */
245
246 enum condition_status
247 {
248 condition_unchanged = 0,
249 condition_modified,
250 condition_updated
251 };
252
253 /* Information used by targets to insert and remove breakpoints. */
254
255 struct bp_target_info
256 {
257 /* Address space at which the breakpoint was placed. */
258 struct address_space *placed_address_space;
259
260 /* Address at which the breakpoint was placed. This is normally
261 the same as REQUESTED_ADDRESS, except when adjustment happens in
262 gdbarch_breakpoint_from_pc. The most common form of adjustment
263 is stripping an alternate ISA marker from the PC which is used
264 to determine the type of breakpoint to insert. */
265 CORE_ADDR placed_address;
266
267 /* Address at which the breakpoint was requested. */
268 CORE_ADDR reqstd_address;
269
270 /* If this is a ranged breakpoint, then this field contains the
271 length of the range that will be watched for execution. */
272 int length;
273
274 /* If the breakpoint lives in memory and reading that memory would
275 give back the breakpoint, instead of the original contents, then
276 the original contents are cached here. Only SHADOW_LEN bytes of
277 this buffer are valid, and only when the breakpoint is inserted. */
278 gdb_byte shadow_contents[BREAKPOINT_MAX];
279
280 /* The length of the data cached in SHADOW_CONTENTS. */
281 int shadow_len;
282
283 /* The breakpoint's kind. It is used in 'kind' parameter in Z
284 packets. */
285 int kind;
286
287 /* Conditions the target should evaluate if it supports target-side
288 breakpoint conditions. These are non-owning pointers. */
289 std::vector<agent_expr *> conditions;
290
291 /* Commands the target should evaluate if it supports target-side
292 breakpoint commands. These are non-owning pointers. */
293 std::vector<agent_expr *> tcommands;
294
295 /* Flag that is true if the breakpoint should be left in place even
296 when GDB is not connected. */
297 int persist;
298 };
299
300 /* GDB maintains two types of information about each breakpoint (or
301 watchpoint, or other related event). The first type corresponds
302 to struct breakpoint; this is a relatively high-level structure
303 which contains the source location(s), stopping conditions, user
304 commands to execute when the breakpoint is hit, and so forth.
305
306 The second type of information corresponds to struct bp_location.
307 Each breakpoint has one or (eventually) more locations associated
308 with it, which represent target-specific and machine-specific
309 mechanisms for stopping the program. For instance, a watchpoint
310 expression may require multiple hardware watchpoints in order to
311 catch all changes in the value of the expression being watched. */
312
313 enum bp_loc_type
314 {
315 bp_loc_software_breakpoint,
316 bp_loc_hardware_breakpoint,
317 bp_loc_hardware_watchpoint,
318 bp_loc_other /* Miscellaneous... */
319 };
320
321 class bp_location : public refcounted_object
322 {
323 public:
324 bp_location () = default;
325
326 /* Construct a bp_location with the type inferred from OWNER's
327 type. */
328 explicit bp_location (breakpoint *owner);
329
330 /* Construct a bp_location with type TYPE. */
331 bp_location (breakpoint *owner, bp_loc_type type);
332
333 virtual ~bp_location () = default;
334
335 /* Chain pointer to the next breakpoint location for
336 the same parent breakpoint. */
337 bp_location *next = NULL;
338
339 /* Type of this breakpoint location. */
340 bp_loc_type loc_type {};
341
342 /* Each breakpoint location must belong to exactly one higher-level
343 breakpoint. This pointer is NULL iff this bp_location is no
344 longer attached to a breakpoint. For example, when a breakpoint
345 is deleted, its locations may still be found in the
346 moribund_locations list, or if we had stopped for it, in
347 bpstats. */
348 breakpoint *owner = NULL;
349
350 /* Conditional. Break only if this expression's value is nonzero.
351 Unlike string form of condition, which is associated with
352 breakpoint, this is associated with location, since if breakpoint
353 has several locations, the evaluation of expression can be
354 different for different locations. Only valid for real
355 breakpoints; a watchpoint's conditional expression is stored in
356 the owner breakpoint object. */
357 expression_up cond;
358
359 /* Conditional expression in agent expression
360 bytecode form. This is used for stub-side breakpoint
361 condition evaluation. */
362 agent_expr_up cond_bytecode;
363
364 /* Signals that the condition has changed since the last time
365 we updated the global location list. This means the condition
366 needs to be sent to the target again. This is used together
367 with target-side breakpoint conditions.
368
369 condition_unchanged: It means there has been no condition changes.
370
371 condition_modified: It means this location had its condition modified.
372
373 condition_updated: It means we already marked all the locations that are
374 duplicates of this location and thus we don't need to call
375 force_breakpoint_reinsertion (...) for this location. */
376
377 condition_status condition_changed {};
378
379 agent_expr_up cmd_bytecode;
380
381 /* Signals that breakpoint conditions and/or commands need to be
382 re-synced with the target. This has no use other than
383 target-side breakpoints. */
384 bool needs_update = false;
385
386 /* This location's address is in an unloaded solib, and so this
387 location should not be inserted. It will be automatically
388 enabled when that solib is loaded. */
389 bool shlib_disabled = false;
390
391 /* Is this particular location enabled. */
392 bool enabled = false;
393
394 /* Is this particular location disabled because the condition
395 expression is invalid at this location. For a location to be
396 reported as enabled, the ENABLED field above has to be true *and*
397 the DISABLED_BY_COND field has to be false. */
398 bool disabled_by_cond = false;
399
400 /* True if this breakpoint is now inserted. */
401 bool inserted = false;
402
403 /* True if this is a permanent breakpoint. There is a breakpoint
404 instruction hard-wired into the target's code. Don't try to
405 write another breakpoint instruction on top of it, or restore its
406 value. Step over it using the architecture's
407 gdbarch_skip_permanent_breakpoint method. */
408 bool permanent = false;
409
410 /* True if this is not the first breakpoint in the list
411 for the given address. location of tracepoint can _never_
412 be duplicated with other locations of tracepoints and other
413 kinds of breakpoints, because two locations at the same
414 address may have different actions, so both of these locations
415 should be downloaded and so that `tfind N' always works. */
416 bool duplicate = false;
417
418 /* If we someday support real thread-specific breakpoints, then
419 the breakpoint location will need a thread identifier. */
420
421 /* Data for specific breakpoint types. These could be a union, but
422 simplicity is more important than memory usage for breakpoints. */
423
424 /* Architecture associated with this location's address. May be
425 different from the breakpoint architecture. */
426 struct gdbarch *gdbarch = NULL;
427
428 /* The program space associated with this breakpoint location
429 address. Note that an address space may be represented in more
430 than one program space (e.g. each uClinux program will be given
431 its own program space, but there will only be one address space
432 for all of them), but we must not insert more than one location
433 at the same address in the same address space. */
434 program_space *pspace = NULL;
435
436 /* Note that zero is a perfectly valid code address on some platforms
437 (for example, the mn10200 (OBSOLETE) and mn10300 simulators). NULL
438 is not a special value for this field. Valid for all types except
439 bp_loc_other. */
440 CORE_ADDR address = 0;
441
442 /* For hardware watchpoints, the size of the memory region being
443 watched. For hardware ranged breakpoints, the size of the
444 breakpoint range. */
445 int length = 0;
446
447 /* Type of hardware watchpoint. */
448 target_hw_bp_type watchpoint_type {};
449
450 /* For any breakpoint type with an address, this is the section
451 associated with the address. Used primarily for overlay
452 debugging. */
453 obj_section *section = NULL;
454
455 /* Address at which breakpoint was requested, either by the user or
456 by GDB for internal breakpoints. This will usually be the same
457 as ``address'' (above) except for cases in which
458 ADJUST_BREAKPOINT_ADDRESS has computed a different address at
459 which to place the breakpoint in order to comply with a
460 processor's architectual constraints. */
461 CORE_ADDR requested_address = 0;
462
463 /* An additional address assigned with this location. This is currently
464 only used by STT_GNU_IFUNC resolver breakpoints to hold the address
465 of the resolver function. */
466 CORE_ADDR related_address = 0;
467
468 /* If the location comes from a probe point, this is the probe associated
469 with it. */
470 bound_probe probe {};
471
472 gdb::unique_xmalloc_ptr<char> function_name;
473
474 /* Details of the placed breakpoint, when inserted. */
475 bp_target_info target_info {};
476
477 /* Similarly, for the breakpoint at an overlay's LMA, if necessary. */
478 bp_target_info overlay_target_info {};
479
480 /* In a non-stop mode, it's possible that we delete a breakpoint,
481 but as we do that, some still running thread hits that breakpoint.
482 For that reason, we need to keep locations belonging to deleted
483 breakpoints for a bit, so that don't report unexpected SIGTRAP.
484 We can't keep such locations forever, so we use a heuristic --
485 after we process certain number of inferior events since
486 breakpoint was deleted, we retire all locations of that breakpoint.
487 This variable keeps a number of events still to go, when
488 it becomes 0 this location is retired. */
489 int events_till_retirement = 0;
490
491 /* Line number which was used to place this location.
492
493 Breakpoint placed into a comment keeps it's user specified line number
494 despite ADDRESS resolves into a different line number. */
495
496 int line_number = 0;
497
498 /* Symtab which was used to place this location. This is used
499 to find the corresponding source file name. */
500
501 struct symtab *symtab = NULL;
502
503 /* The symbol found by the location parser, if any. This may be used to
504 ascertain when an event location was set at a different location than
505 the one originally selected by parsing, e.g., inlined symbols. */
506 const struct symbol *symbol = NULL;
507
508 /* Similarly, the minimal symbol found by the location parser, if
509 any. This may be used to ascertain if the location was
510 originally set on a GNU ifunc symbol. */
511 const minimal_symbol *msymbol = NULL;
512
513 /* The objfile the symbol or minimal symbol were found in. */
514 const struct objfile *objfile = NULL;
515 };
516
517 /* A policy class for bp_location reference counting. */
518 struct bp_location_ref_policy
519 {
520 static void incref (bp_location *loc)
521 {
522 loc->incref ();
523 }
524
525 static void decref (bp_location *loc)
526 {
527 gdb_assert (loc->refcount () > 0);
528 loc->decref ();
529 if (loc->refcount () == 0)
530 delete loc;
531 }
532 };
533
534 /* A gdb::ref_ptr that has been specialized for bp_location. */
535 typedef gdb::ref_ptr<bp_location, bp_location_ref_policy>
536 bp_location_ref_ptr;
537
538 /* The possible return values for print_bpstat, print_it_normal,
539 print_it_done, print_it_noop. */
540 enum print_stop_action
541 {
542 /* We printed nothing or we need to do some more analysis. */
543 PRINT_UNKNOWN = -1,
544
545 /* We printed something, and we *do* desire that something to be
546 followed by a location. */
547 PRINT_SRC_AND_LOC,
548
549 /* We printed something, and we do *not* desire that something to be
550 followed by a location. */
551 PRINT_SRC_ONLY,
552
553 /* We already printed all we needed to print, don't print anything
554 else. */
555 PRINT_NOTHING
556 };
557
558 /* This structure is a collection of function pointers that, if available,
559 will be called instead of the performing the default action for this
560 bptype. */
561
562 struct breakpoint_ops
563 {
564 /* Create SALs from location, storing the result in linespec_result.
565
566 For an explanation about the arguments, see the function
567 `create_sals_from_location_default'.
568
569 This function is called inside `create_breakpoint'. */
570 void (*create_sals_from_location) (struct event_location *location,
571 struct linespec_result *canonical);
572
573 /* This method will be responsible for creating a breakpoint given its SALs.
574 Usually, it just calls `create_breakpoints_sal' (for ordinary
575 breakpoints). However, there may be some special cases where we might
576 need to do some tweaks, e.g., see
577 `strace_marker_create_breakpoints_sal'.
578
579 This function is called inside `create_breakpoint'. */
580 void (*create_breakpoints_sal) (struct gdbarch *,
581 struct linespec_result *,
582 gdb::unique_xmalloc_ptr<char>,
583 gdb::unique_xmalloc_ptr<char>,
584 enum bptype, enum bpdisp, int, int,
585 int, const struct breakpoint_ops *,
586 int, int, int, unsigned);
587 };
588
589 enum watchpoint_triggered
590 {
591 /* This watchpoint definitely did not trigger. */
592 watch_triggered_no = 0,
593
594 /* Some hardware watchpoint triggered, and it might have been this
595 one, but we do not know which it was. */
596 watch_triggered_unknown,
597
598 /* This hardware watchpoint definitely did trigger. */
599 watch_triggered_yes
600 };
601
602 /* Some targets (e.g., embedded PowerPC) need two debug registers to set
603 a watchpoint over a memory region. If this flag is true, GDB will use
604 only one register per watchpoint, thus assuming that all accesses that
605 modify a memory location happen at its starting address. */
606
607 extern bool target_exact_watchpoints;
608
609 /* bp_location linked list range. */
610
611 using bp_location_range = next_range<bp_location>;
612
613 /* Note that the ->silent field is not currently used by any commands
614 (though the code is in there if it was to be, and set_raw_breakpoint
615 does set it to 0). I implemented it because I thought it would be
616 useful for a hack I had to put in; I'm going to leave it in because
617 I can see how there might be times when it would indeed be useful */
618
619 /* This is for all kinds of breakpoints. */
620
621 struct breakpoint
622 {
623 virtual ~breakpoint () = default;
624
625 /* Allocate a location for this breakpoint. */
626 virtual struct bp_location *allocate_location ();
627
628 /* Reevaluate a breakpoint. This is necessary after symbols change
629 (e.g., an executable or DSO was loaded, or the inferior just
630 started). */
631 virtual void re_set ()
632 {
633 /* Nothing to re-set. */
634 }
635
636 /* Insert the breakpoint or watchpoint or activate the catchpoint.
637 Return 0 for success, 1 if the breakpoint, watchpoint or
638 catchpoint type is not supported, -1 for failure. */
639 virtual int insert_location (struct bp_location *);
640
641 /* Remove the breakpoint/catchpoint that was previously inserted
642 with the "insert" method above. Return 0 for success, 1 if the
643 breakpoint, watchpoint or catchpoint type is not supported,
644 -1 for failure. */
645 virtual int remove_location (struct bp_location *,
646 enum remove_bp_reason reason);
647
648 /* Return true if it the target has stopped due to hitting
649 breakpoint location BL. This function does not check if we
650 should stop, only if BL explains the stop. ASPACE is the address
651 space in which the event occurred, BP_ADDR is the address at
652 which the inferior stopped, and WS is the target_waitstatus
653 describing the event. */
654 virtual int breakpoint_hit (const struct bp_location *bl,
655 const address_space *aspace,
656 CORE_ADDR bp_addr,
657 const target_waitstatus &ws);
658
659 /* Check internal conditions of the breakpoint referred to by BS.
660 If we should not stop for this breakpoint, set BS->stop to 0. */
661 virtual void check_status (struct bpstat *bs)
662 {
663 /* Always stop. */
664 }
665
666 /* Tell how many hardware resources (debug registers) are needed
667 for this breakpoint. If this function is not provided, then
668 the breakpoint or watchpoint needs one debug register. */
669 virtual int resources_needed (const struct bp_location *);
670
671 /* The normal print routine for this breakpoint, called when we
672 hit it. */
673 virtual enum print_stop_action print_it (const bpstat *bs) const;
674
675 /* Display information about this breakpoint, for "info
676 breakpoints". Returns false if this method should use the
677 default behavior. */
678 virtual bool print_one (bp_location **) const
679 {
680 return false;
681 }
682
683 /* Display extra information about this breakpoint, below the normal
684 breakpoint description in "info breakpoints".
685
686 In the example below, the "address range" line was printed
687 by print_one_detail_ranged_breakpoint.
688
689 (gdb) info breakpoints
690 Num Type Disp Enb Address What
691 2 hw breakpoint keep y in main at test-watch.c:70
692 address range: [0x10000458, 0x100004c7]
693
694 */
695 virtual void print_one_detail (struct ui_out *) const
696 {
697 /* Nothing. */
698 }
699
700 /* Display information about this breakpoint after setting it
701 (roughly speaking; this is called from "mention"). */
702 virtual void print_mention () const;
703
704 /* Print to FP the CLI command that recreates this breakpoint. */
705 virtual void print_recreate (struct ui_file *fp) const;
706
707 /* Given the location (second parameter), this method decodes it and
708 returns the SAL locations related to it. For ordinary
709 breakpoints, it calls `decode_line_full'. If SEARCH_PSPACE is
710 not NULL, symbol search is restricted to just that program space.
711
712 This function is called inside `location_to_sals'. */
713 virtual std::vector<symtab_and_line> decode_location
714 (struct event_location *location,
715 struct program_space *search_pspace);
716
717 /* Return true if this breakpoint explains a signal. See
718 bpstat_explains_signal. */
719 virtual bool explains_signal (enum gdb_signal)
720 {
721 return true;
722 }
723
724 /* Called after evaluating the breakpoint's condition,
725 and only if it evaluated true. */
726 virtual void after_condition_true (struct bpstat *bs)
727 {
728 /* Nothing to do. */
729 }
730
731 /* Return a range of this breakpoint's locations. */
732 bp_location_range locations () const;
733
734 breakpoint *next = NULL;
735 /* Type of breakpoint. */
736 bptype type = bp_none;
737 /* Zero means disabled; remember the info but don't break here. */
738 enum enable_state enable_state = bp_enabled;
739 /* What to do with this breakpoint after we hit it. */
740 bpdisp disposition = disp_del;
741 /* Number assigned to distinguish breakpoints. */
742 int number = 0;
743
744 /* Location(s) associated with this high-level breakpoint. */
745 bp_location *loc = NULL;
746
747 /* True means a silent breakpoint (don't print frame info if we stop
748 here). */
749 bool silent = false;
750 /* True means display ADDR_STRING to the user verbatim. */
751 bool display_canonical = false;
752 /* Number of stops at this breakpoint that should be continued
753 automatically before really stopping. */
754 int ignore_count = 0;
755
756 /* Number of stops at this breakpoint before it will be
757 disabled. */
758 int enable_count = 0;
759
760 /* Chain of command lines to execute when this breakpoint is
761 hit. */
762 counted_command_line commands;
763 /* Stack depth (address of frame). If nonzero, break only if fp
764 equals this. */
765 struct frame_id frame_id = null_frame_id;
766
767 /* The program space used to set the breakpoint. This is only set
768 for breakpoints which are specific to a program space; for
769 non-thread-specific ordinary breakpoints this is NULL. */
770 program_space *pspace = NULL;
771
772 /* Location we used to set the breakpoint. */
773 event_location_up location;
774
775 /* The filter that should be passed to decode_line_full when
776 re-setting this breakpoint. This may be NULL. */
777 gdb::unique_xmalloc_ptr<char> filter;
778
779 /* For a ranged breakpoint, the location we used to find the end of
780 the range. */
781 event_location_up location_range_end;
782
783 /* Architecture we used to set the breakpoint. */
784 struct gdbarch *gdbarch = NULL;
785 /* Language we used to set the breakpoint. */
786 enum language language = language_unknown;
787 /* Input radix we used to set the breakpoint. */
788 int input_radix = 0;
789 /* String form of the breakpoint condition (malloc'd), or NULL if
790 there is no condition. */
791 gdb::unique_xmalloc_ptr<char> cond_string;
792
793 /* String form of extra parameters, or NULL if there are none.
794 Malloc'd. */
795 gdb::unique_xmalloc_ptr<char> extra_string;
796
797 /* Holds the address of the related watchpoint_scope breakpoint when
798 using watchpoints on local variables (might the concept of a
799 related breakpoint be useful elsewhere, if not just call it the
800 watchpoint_scope breakpoint or something like that. FIXME). */
801 breakpoint *related_breakpoint = NULL;
802
803 /* Thread number for thread-specific breakpoint, or -1 if don't
804 care. */
805 int thread = -1;
806
807 /* Ada task number for task-specific breakpoint, or 0 if don't
808 care. */
809 int task = 0;
810
811 /* Count of the number of times this breakpoint was taken, dumped
812 with the info, but not used for anything else. Useful for seeing
813 how many times you hit a break prior to the program aborting, so
814 you can back up to just before the abort. */
815 int hit_count = 0;
816
817 /* Is breakpoint's condition not yet parsed because we found no
818 location initially so had no context to parse the condition
819 in. */
820 int condition_not_parsed = 0;
821
822 /* With a Python scripting enabled GDB, store a reference to the
823 Python object that has been associated with this breakpoint.
824 This is always NULL for a GDB that is not script enabled. It can
825 sometimes be NULL for enabled GDBs as not all breakpoint types
826 are tracked by the scripting language API. */
827 gdbpy_breakpoint_object *py_bp_object = NULL;
828
829 /* Same as py_bp_object, but for Scheme. */
830 gdbscm_breakpoint_object *scm_bp_object = NULL;
831
832 protected:
833
834 /* Helper for breakpoint_ops->print_recreate implementations. Prints
835 the "thread" or "task" condition of B, and then a newline.
836
837 Necessary because most breakpoint implementations accept
838 thread/task conditions at the end of the spec line, like "break foo
839 thread 1", which needs outputting before any breakpoint-type
840 specific extra command necessary for B's recreation. */
841 void print_recreate_thread (struct ui_file *fp) const;
842 };
843
844 /* The structure to be inherit by all kinds of breakpoints (real
845 breakpoints, i.e., user "break" breakpoints, internal and momentary
846 breakpoints, etc.). */
847 struct base_breakpoint : public breakpoint
848 {
849 void re_set () override;
850 int insert_location (struct bp_location *) override;
851 int remove_location (struct bp_location *,
852 enum remove_bp_reason reason) override;
853 int breakpoint_hit (const struct bp_location *bl,
854 const address_space *aspace,
855 CORE_ADDR bp_addr,
856 const target_waitstatus &ws) override;
857 std::vector<symtab_and_line> decode_location
858 (struct event_location *location,
859 struct program_space *search_pspace) override;
860 };
861
862 /* An instance of this type is used to represent a watchpoint. */
863
864 struct watchpoint : public breakpoint
865 {
866 void re_set () override;
867 int insert_location (struct bp_location *) override;
868 int remove_location (struct bp_location *,
869 enum remove_bp_reason reason) override;
870 int breakpoint_hit (const struct bp_location *bl,
871 const address_space *aspace,
872 CORE_ADDR bp_addr,
873 const target_waitstatus &ws) override;
874 void check_status (struct bpstat *bs) override;
875 int resources_needed (const struct bp_location *) override;
876
877 /* Tell whether we can downgrade from a hardware watchpoint to a software
878 one. If not, the user will not be able to enable the watchpoint when
879 there are not enough hardware resources available. */
880 virtual bool works_in_software_mode () const;
881
882 enum print_stop_action print_it (const bpstat *bs) const override;
883 void print_mention () const override;
884 void print_recreate (struct ui_file *fp) const override;
885 bool explains_signal (enum gdb_signal) override;
886
887 /* String form of exp to use for displaying to the user (malloc'd),
888 or NULL if none. */
889 gdb::unique_xmalloc_ptr<char> exp_string;
890 /* String form to use for reparsing of EXP (malloc'd) or NULL. */
891 gdb::unique_xmalloc_ptr<char> exp_string_reparse;
892
893 /* The expression we are watching, or NULL if not a watchpoint. */
894 expression_up exp;
895 /* The largest block within which it is valid, or NULL if it is
896 valid anywhere (e.g. consists just of global symbols). */
897 const struct block *exp_valid_block;
898 /* The conditional expression if any. */
899 expression_up cond_exp;
900 /* The largest block within which it is valid, or NULL if it is
901 valid anywhere (e.g. consists just of global symbols). */
902 const struct block *cond_exp_valid_block;
903 /* Value of the watchpoint the last time we checked it, or NULL when
904 we do not know the value yet or the value was not readable. VAL
905 is never lazy. */
906 value_ref_ptr val;
907
908 /* True if VAL is valid. If VAL_VALID is set but VAL is NULL,
909 then an error occurred reading the value. */
910 bool val_valid;
911
912 /* When watching the location of a bitfield, contains the offset and size of
913 the bitfield. Otherwise contains 0. */
914 int val_bitpos;
915 int val_bitsize;
916
917 /* Holds the frame address which identifies the frame this
918 watchpoint should be evaluated in, or `null' if the watchpoint
919 should be evaluated on the outermost frame. */
920 struct frame_id watchpoint_frame;
921
922 /* Holds the thread which identifies the frame this watchpoint
923 should be considered in scope for, or `null_ptid' if the
924 watchpoint should be evaluated in all threads. */
925 ptid_t watchpoint_thread;
926
927 /* For hardware watchpoints, the triggered status according to the
928 hardware. */
929 enum watchpoint_triggered watchpoint_triggered;
930
931 /* Whether this watchpoint is exact (see
932 target_exact_watchpoints). */
933 int exact;
934
935 /* The mask address for a masked hardware watchpoint. */
936 CORE_ADDR hw_wp_mask;
937 };
938
939 /* Return true if BPT is either a software breakpoint or a hardware
940 breakpoint. */
941
942 extern bool is_breakpoint (const struct breakpoint *bpt);
943
944 /* Return true if BPT is of any watchpoint kind, hardware or
945 software. */
946
947 extern bool is_watchpoint (const struct breakpoint *bpt);
948
949 /* Return true if BPT is a C++ exception catchpoint (catch
950 catch/throw/rethrow). */
951
952 extern bool is_exception_catchpoint (breakpoint *bp);
953
954 /* An instance of this type is used to represent all kinds of
955 tracepoints. */
956
957 struct tracepoint : public breakpoint
958 {
959 void re_set () override;
960 int breakpoint_hit (const struct bp_location *bl,
961 const address_space *aspace, CORE_ADDR bp_addr,
962 const target_waitstatus &ws) override;
963 void print_one_detail (struct ui_out *uiout) const override;
964 void print_mention () const override;
965 void print_recreate (struct ui_file *fp) const override;
966 std::vector<symtab_and_line> decode_location
967 (struct event_location *location,
968 struct program_space *search_pspace) override;
969
970
971 /* Number of times this tracepoint should single-step and collect
972 additional data. */
973 long step_count;
974
975 /* Number of times this tracepoint should be hit before
976 disabling/ending. */
977 int pass_count;
978
979 /* The number of the tracepoint on the target. */
980 int number_on_target;
981
982 /* The total space taken by all the trace frames for this
983 tracepoint. */
984 ULONGEST traceframe_usage;
985
986 /* The static tracepoint marker id, if known. */
987 std::string static_trace_marker_id;
988
989 /* LTTng/UST allow more than one marker with the same ID string,
990 although it unadvised because it confuses tools. When setting
991 static tracepoints by marker ID, this will record the index in
992 the array of markers we found for the given marker ID for which
993 this static tracepoint corresponds. When resetting breakpoints,
994 we will use this index to try to find the same marker again. */
995 int static_trace_marker_id_idx;
996 };
997
998 \f
999 /* The following stuff is an abstract data type "bpstat" ("breakpoint
1000 status"). This provides the ability to determine whether we have
1001 stopped at a breakpoint, and what we should do about it. */
1002
1003 /* Clears a chain of bpstat, freeing storage
1004 of each. */
1005 extern void bpstat_clear (bpstat **);
1006
1007 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1008 is part of the bpstat is copied as well. */
1009 extern bpstat *bpstat_copy (bpstat *);
1010
1011 /* Build the (raw) bpstat chain for the stop information given by ASPACE,
1012 BP_ADDR, and WS. Returns the head of the bpstat chain. */
1013
1014 extern bpstat *build_bpstat_chain (const address_space *aspace,
1015 CORE_ADDR bp_addr,
1016 const target_waitstatus &ws);
1017
1018 /* Get a bpstat associated with having just stopped at address
1019 BP_ADDR in thread PTID. STOP_CHAIN may be supplied as a previously
1020 computed stop chain or NULL, in which case the stop chain will be
1021 computed using build_bpstat_chain.
1022
1023 Determine whether we stopped at a breakpoint, etc, or whether we
1024 don't understand this stop. Result is a chain of bpstat's such
1025 that:
1026
1027 if we don't understand the stop, the result is a null pointer.
1028
1029 if we understand why we stopped, the result is not null.
1030
1031 Each element of the chain refers to a particular breakpoint or
1032 watchpoint at which we have stopped. (We may have stopped for
1033 several reasons concurrently.)
1034
1035 Each element of the chain has valid next, breakpoint_at,
1036 commands, FIXME??? fields.
1037
1038 watchpoints_triggered must be called beforehand to set up each
1039 watchpoint's watchpoint_triggered value.
1040
1041 */
1042
1043 extern bpstat *bpstat_stop_status (const address_space *aspace,
1044 CORE_ADDR pc, thread_info *thread,
1045 const target_waitstatus &ws,
1046 bpstat *stop_chain = nullptr);
1047
1048 /* Like bpstat_stop_status, but clears all watchpoints'
1049 watchpoint_triggered flag. Unlike with bpstat_stop_status, there's
1050 no need to call watchpoint_triggered beforehand. You'll typically
1051 use this variant when handling a known-non-watchpoint event, like a
1052 fork or exec event. */
1053
1054 extern bpstat *bpstat_stop_status_nowatch (const address_space *aspace,
1055 CORE_ADDR bp_addr,
1056 thread_info *thread,
1057 const target_waitstatus &ws);
1058 \f
1059
1060
1061 /* This bpstat_what stuff tells wait_for_inferior what to do with a
1062 breakpoint (a challenging task).
1063
1064 The enum values order defines priority-like order of the actions.
1065 Once you've decided that some action is appropriate, you'll never
1066 go back and decide something of a lower priority is better. Each
1067 of these actions is mutually exclusive with the others. That
1068 means, that if you find yourself adding a new action class here and
1069 wanting to tell GDB that you have two simultaneous actions to
1070 handle, something is wrong, and you probably don't actually need a
1071 new action type.
1072
1073 Note that a step resume breakpoint overrides another breakpoint of
1074 signal handling (see comment in wait_for_inferior at where we set
1075 the step_resume breakpoint). */
1076
1077 enum bpstat_what_main_action
1078 {
1079 /* Perform various other tests; that is, this bpstat does not
1080 say to perform any action (e.g. failed watchpoint and nothing
1081 else). */
1082 BPSTAT_WHAT_KEEP_CHECKING,
1083
1084 /* Remove breakpoints, single step once, then put them back in and
1085 go back to what we were doing. It's possible that this should
1086 be removed from the main_action and put into a separate field,
1087 to more cleanly handle
1088 BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE. */
1089 BPSTAT_WHAT_SINGLE,
1090
1091 /* Set longjmp_resume breakpoint, remove all other breakpoints,
1092 and continue. The "remove all other breakpoints" part is
1093 required if we are also stepping over another breakpoint as
1094 well as doing the longjmp handling. */
1095 BPSTAT_WHAT_SET_LONGJMP_RESUME,
1096
1097 /* Clear longjmp_resume breakpoint, then handle as
1098 BPSTAT_WHAT_KEEP_CHECKING. */
1099 BPSTAT_WHAT_CLEAR_LONGJMP_RESUME,
1100
1101 /* Clear step resume breakpoint, and keep checking. */
1102 BPSTAT_WHAT_STEP_RESUME,
1103
1104 /* Rather than distinguish between noisy and silent stops here, it
1105 might be cleaner to have bpstat_print make that decision (also
1106 taking into account stop_print_frame and source_only). But the
1107 implications are a bit scary (interaction with auto-displays,
1108 etc.), so I won't try it. */
1109
1110 /* Stop silently. */
1111 BPSTAT_WHAT_STOP_SILENT,
1112
1113 /* Stop and print. */
1114 BPSTAT_WHAT_STOP_NOISY,
1115
1116 /* Clear step resume breakpoint, and keep checking. High-priority
1117 step-resume breakpoints are used when even if there's a user
1118 breakpoint at the current PC when we set the step-resume
1119 breakpoint, we don't want to re-handle any breakpoint other
1120 than the step-resume when it's hit; instead we want to move
1121 past the breakpoint. This is used in the case of skipping
1122 signal handlers. */
1123 BPSTAT_WHAT_HP_STEP_RESUME,
1124 };
1125
1126 /* An enum indicating the kind of "stack dummy" stop. This is a bit
1127 of a misnomer because only one kind of truly a stack dummy. */
1128 enum stop_stack_kind
1129 {
1130 /* We didn't stop at a stack dummy breakpoint. */
1131 STOP_NONE = 0,
1132
1133 /* Stopped at a stack dummy. */
1134 STOP_STACK_DUMMY,
1135
1136 /* Stopped at std::terminate. */
1137 STOP_STD_TERMINATE
1138 };
1139
1140 struct bpstat_what
1141 {
1142 enum bpstat_what_main_action main_action;
1143
1144 /* Did we hit a call dummy breakpoint? This only goes with a
1145 main_action of BPSTAT_WHAT_STOP_SILENT or
1146 BPSTAT_WHAT_STOP_NOISY (the concept of continuing from a call
1147 dummy without popping the frame is not a useful one). */
1148 enum stop_stack_kind call_dummy;
1149
1150 /* Used for BPSTAT_WHAT_SET_LONGJMP_RESUME and
1151 BPSTAT_WHAT_CLEAR_LONGJMP_RESUME. True if we are handling a
1152 longjmp, false if we are handling an exception. */
1153 bool is_longjmp;
1154 };
1155
1156 /* Tell what to do about this bpstat. */
1157 struct bpstat_what bpstat_what (bpstat *);
1158
1159 /* Run breakpoint event callbacks associated with the breakpoints that
1160 triggered. */
1161 extern void bpstat_run_callbacks (bpstat *bs_head);
1162
1163 /* Find the bpstat associated with a breakpoint. NULL otherwise. */
1164 bpstat *bpstat_find_breakpoint (bpstat *, struct breakpoint *);
1165
1166 /* True if a signal that we got in target_wait() was due to
1167 circumstances explained by the bpstat; the signal is therefore not
1168 random. */
1169 extern bool bpstat_explains_signal (bpstat *, enum gdb_signal);
1170
1171 /* True if this bpstat causes a stop. */
1172 extern bool bpstat_causes_stop (bpstat *);
1173
1174 /* True if we should step constantly (e.g. watchpoints on machines
1175 without hardware support). This isn't related to a specific bpstat,
1176 just to things like whether watchpoints are set. */
1177 extern bool bpstat_should_step ();
1178
1179 /* Print a message indicating what happened. Returns nonzero to
1180 say that only the source line should be printed after this (zero
1181 return means print the frame as well as the source line). */
1182 extern enum print_stop_action bpstat_print (bpstat *, int);
1183
1184 /* Put in *NUM the breakpoint number of the first breakpoint we are
1185 stopped at. *BSP upon return is a bpstat which points to the
1186 remaining breakpoints stopped at (but which is not guaranteed to be
1187 good for anything but further calls to bpstat_num).
1188
1189 Return 0 if passed a bpstat which does not indicate any breakpoints.
1190 Return -1 if stopped at a breakpoint that has been deleted since
1191 we set it.
1192 Return 1 otherwise. */
1193 extern int bpstat_num (bpstat **, int *);
1194
1195 /* Perform actions associated with the stopped inferior. Actually, we
1196 just use this for breakpoint commands. Perhaps other actions will
1197 go here later, but this is executed at a late time (from the
1198 command loop). */
1199 extern void bpstat_do_actions (void);
1200
1201 /* Modify all entries of STOP_BPSTAT of INFERIOR_PTID so that the actions will
1202 not be performed. */
1203 extern void bpstat_clear_actions (void);
1204
1205 /* Implementation: */
1206
1207 /* Values used to tell the printing routine how to behave for this
1208 bpstat. */
1209 enum bp_print_how
1210 {
1211 /* This is used when we want to do a normal printing of the reason
1212 for stopping. The output will depend on the type of eventpoint
1213 we are dealing with. This is the default value, most commonly
1214 used. */
1215 print_it_normal,
1216 /* This is used when nothing should be printed for this bpstat
1217 entry. */
1218 print_it_noop,
1219 /* This is used when everything which needs to be printed has
1220 already been printed. But we still want to print the frame. */
1221 print_it_done
1222 };
1223
1224 struct bpstat
1225 {
1226 bpstat ();
1227 bpstat (struct bp_location *bl, bpstat ***bs_link_pointer);
1228
1229 bpstat (const bpstat &);
1230 bpstat &operator= (const bpstat &) = delete;
1231
1232 /* Linked list because there can be more than one breakpoint at
1233 the same place, and a bpstat reflects the fact that all have
1234 been hit. */
1235 bpstat *next;
1236
1237 /* Location that caused the stop. Locations are refcounted, so
1238 this will never be NULL. Note that this location may end up
1239 detached from a breakpoint, but that does not necessary mean
1240 that the struct breakpoint is gone. E.g., consider a
1241 watchpoint with a condition that involves an inferior function
1242 call. Watchpoint locations are recreated often (on resumes,
1243 hence on infcalls too). Between creating the bpstat and after
1244 evaluating the watchpoint condition, this location may hence
1245 end up detached from its original owner watchpoint, even though
1246 the watchpoint is still listed. If it's condition evaluates as
1247 true, we still want this location to cause a stop, and we will
1248 still need to know which watchpoint it was originally attached.
1249 What this means is that we should not (in most cases) follow
1250 the `bpstat->bp_location->owner' link, but instead use the
1251 `breakpoint_at' field below. */
1252 bp_location_ref_ptr bp_location_at;
1253
1254 /* Breakpoint that caused the stop. This is nullified if the
1255 breakpoint ends up being deleted. See comments on
1256 `bp_location_at' above for why do we need this field instead of
1257 following the location's owner. */
1258 struct breakpoint *breakpoint_at;
1259
1260 /* The associated command list. */
1261 counted_command_line commands;
1262
1263 /* Old value associated with a watchpoint. */
1264 value_ref_ptr old_val;
1265
1266 /* Nonzero if this breakpoint tells us to print the frame. */
1267 char print;
1268
1269 /* Nonzero if this breakpoint tells us to stop. */
1270 char stop;
1271
1272 /* Tell bpstat_print and print_bp_stop_message how to print stuff
1273 associated with this element of the bpstat chain. */
1274 enum bp_print_how print_it;
1275 };
1276
1277 enum inf_context
1278 {
1279 inf_starting,
1280 inf_running,
1281 inf_exited,
1282 inf_execd
1283 };
1284
1285 /* The possible return values for breakpoint_here_p.
1286 We guarantee that zero always means "no breakpoint here". */
1287 enum breakpoint_here
1288 {
1289 no_breakpoint_here = 0,
1290 ordinary_breakpoint_here,
1291 permanent_breakpoint_here
1292 };
1293 \f
1294
1295 /* Prototypes for breakpoint-related functions. */
1296
1297 extern enum breakpoint_here breakpoint_here_p (const address_space *,
1298 CORE_ADDR);
1299
1300 /* Return true if an enabled breakpoint exists in the range defined by
1301 ADDR and LEN, in ASPACE. */
1302 extern int breakpoint_in_range_p (const address_space *aspace,
1303 CORE_ADDR addr, ULONGEST len);
1304
1305 extern int moribund_breakpoint_here_p (const address_space *, CORE_ADDR);
1306
1307 extern int breakpoint_inserted_here_p (const address_space *,
1308 CORE_ADDR);
1309
1310 extern int software_breakpoint_inserted_here_p (const address_space *,
1311 CORE_ADDR);
1312
1313 /* Return non-zero iff there is a hardware breakpoint inserted at
1314 PC. */
1315 extern int hardware_breakpoint_inserted_here_p (const address_space *,
1316 CORE_ADDR);
1317
1318 /* Check whether any location of BP is inserted at PC. */
1319
1320 extern int breakpoint_has_location_inserted_here (struct breakpoint *bp,
1321 const address_space *aspace,
1322 CORE_ADDR pc);
1323
1324 extern int single_step_breakpoint_inserted_here_p (const address_space *,
1325 CORE_ADDR);
1326
1327 /* Returns true if there's a hardware watchpoint or access watchpoint
1328 inserted in the range defined by ADDR and LEN. */
1329 extern int hardware_watchpoint_inserted_in_range (const address_space *,
1330 CORE_ADDR addr,
1331 ULONGEST len);
1332
1333 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
1334 same breakpoint location. In most targets, this can only be true
1335 if ASPACE1 matches ASPACE2. On targets that have global
1336 breakpoints, the address space doesn't really matter. */
1337
1338 extern int breakpoint_address_match (const address_space *aspace1,
1339 CORE_ADDR addr1,
1340 const address_space *aspace2,
1341 CORE_ADDR addr2);
1342
1343 extern void until_break_command (const char *, int, int);
1344
1345 /* Initialize a struct bp_location. */
1346
1347 extern void update_breakpoint_locations
1348 (struct breakpoint *b,
1349 struct program_space *filter_pspace,
1350 gdb::array_view<const symtab_and_line> sals,
1351 gdb::array_view<const symtab_and_line> sals_end);
1352
1353 extern void breakpoint_re_set (void);
1354
1355 extern void breakpoint_re_set_thread (struct breakpoint *);
1356
1357 extern void delete_breakpoint (struct breakpoint *);
1358
1359 struct breakpoint_deleter
1360 {
1361 void operator() (struct breakpoint *b) const
1362 {
1363 delete_breakpoint (b);
1364 }
1365 };
1366
1367 typedef std::unique_ptr<struct breakpoint, breakpoint_deleter> breakpoint_up;
1368
1369 extern breakpoint_up set_momentary_breakpoint
1370 (struct gdbarch *, struct symtab_and_line, struct frame_id, enum bptype);
1371
1372 extern breakpoint_up set_momentary_breakpoint_at_pc
1373 (struct gdbarch *, CORE_ADDR pc, enum bptype type);
1374
1375 extern struct breakpoint *clone_momentary_breakpoint (struct breakpoint *bpkt);
1376
1377 extern void set_ignore_count (int, int, int);
1378
1379 extern void breakpoint_init_inferior (enum inf_context);
1380
1381 extern void breakpoint_auto_delete (bpstat *);
1382
1383 /* Return the chain of command lines to execute when this breakpoint
1384 is hit. */
1385 extern struct command_line *breakpoint_commands (struct breakpoint *b);
1386
1387 /* Return a string image of DISP. The string is static, and thus should
1388 NOT be deallocated after use. */
1389 const char *bpdisp_text (enum bpdisp disp);
1390
1391 extern void break_command (const char *, int);
1392
1393 extern void watch_command_wrapper (const char *, int, bool);
1394 extern void awatch_command_wrapper (const char *, int, bool);
1395 extern void rwatch_command_wrapper (const char *, int, bool);
1396 extern void tbreak_command (const char *, int);
1397
1398 extern const struct breakpoint_ops base_breakpoint_ops;
1399
1400 /* Arguments to pass as context to some catch command handlers. */
1401 #define CATCH_PERMANENT ((void *) (uintptr_t) 0)
1402 #define CATCH_TEMPORARY ((void *) (uintptr_t) 1)
1403
1404 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
1405 lists, and pass some additional user data to the command
1406 function. */
1407
1408 extern void
1409 add_catch_command (const char *name, const char *docstring,
1410 cmd_func_ftype *func,
1411 completer_ftype *completer,
1412 void *user_data_catch,
1413 void *user_data_tcatch);
1414
1415 /* Initialize a breakpoint struct for Ada exception catchpoints. */
1416
1417 extern void
1418 init_ada_exception_breakpoint (struct breakpoint *b,
1419 struct gdbarch *gdbarch,
1420 struct symtab_and_line sal,
1421 const char *addr_string,
1422 int tempflag,
1423 int enabled,
1424 int from_tty);
1425
1426 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMP
1427 is true, then make the breakpoint temporary. If COND_STRING is
1428 not NULL, then store it in the breakpoint. */
1429
1430 extern void init_catchpoint (struct breakpoint *b,
1431 struct gdbarch *gdbarch, bool temp,
1432 const char *cond_string);
1433
1434 /* Add breakpoint B on the breakpoint list, and notify the user, the
1435 target and breakpoint_created observers of its existence. If
1436 INTERNAL is non-zero, the breakpoint number will be allocated from
1437 the internal breakpoint count. If UPDATE_GLL is non-zero,
1438 update_global_location_list will be called. */
1439
1440 extern void install_breakpoint (int internal, std::unique_ptr<breakpoint> &&b,
1441 int update_gll);
1442
1443 /* Returns the breakpoint ops appropriate for use with with LOCATION and
1444 according to IS_TRACEPOINT. Use this to ensure, for example, that you pass
1445 the correct ops to create_breakpoint for probe locations. If LOCATION is
1446 NULL, returns base_breakpoint_ops. */
1447
1448 extern const struct breakpoint_ops *breakpoint_ops_for_event_location
1449 (const struct event_location *location, bool is_tracepoint);
1450
1451 /* Flags that can be passed down to create_breakpoint, etc., to affect
1452 breakpoint creation in several ways. */
1453
1454 enum breakpoint_create_flags
1455 {
1456 /* We're adding a breakpoint to our tables that is already
1457 inserted in the target. */
1458 CREATE_BREAKPOINT_FLAGS_INSERTED = 1 << 0
1459 };
1460
1461 /* Set a breakpoint. This function is shared between CLI and MI functions
1462 for setting a breakpoint at LOCATION.
1463
1464 This function has two major modes of operations, selected by the
1465 PARSE_EXTRA parameter.
1466
1467 If PARSE_EXTRA is zero, LOCATION is just the breakpoint's location,
1468 with condition, thread, and extra string specified by the COND_STRING,
1469 THREAD, and EXTRA_STRING parameters.
1470
1471 If PARSE_EXTRA is non-zero, this function will attempt to extract
1472 the condition, thread, and extra string from EXTRA_STRING, ignoring
1473 the similarly named parameters.
1474
1475 If FORCE_CONDITION is true, the condition is accepted even when it is
1476 invalid at all of the locations. However, if PARSE_EXTRA is non-zero,
1477 the FORCE_CONDITION parameter is ignored and the corresponding argument
1478 is parsed from EXTRA_STRING.
1479
1480 If INTERNAL is non-zero, the breakpoint number will be allocated
1481 from the internal breakpoint count.
1482
1483 Returns true if any breakpoint was created; false otherwise. */
1484
1485 extern int create_breakpoint (struct gdbarch *gdbarch,
1486 struct event_location *location,
1487 const char *cond_string, int thread,
1488 const char *extra_string,
1489 bool force_condition,
1490 int parse_extra,
1491 int tempflag, enum bptype wanted_type,
1492 int ignore_count,
1493 enum auto_boolean pending_break_support,
1494 const struct breakpoint_ops *ops,
1495 int from_tty,
1496 int enabled,
1497 int internal, unsigned flags);
1498
1499 extern void insert_breakpoints (void);
1500
1501 extern int remove_breakpoints (void);
1502
1503 /* Remove breakpoints of inferior INF. */
1504
1505 extern void remove_breakpoints_inf (inferior *inf);
1506
1507 /* This function can be used to update the breakpoint package's state
1508 after an exec() system call has been executed.
1509
1510 This function causes the following:
1511
1512 - All eventpoints are marked "not inserted".
1513 - All eventpoints with a symbolic address are reset such that
1514 the symbolic address must be reevaluated before the eventpoints
1515 can be reinserted.
1516 - The solib breakpoints are explicitly removed from the breakpoint
1517 list.
1518 - A step-resume breakpoint, if any, is explicitly removed from the
1519 breakpoint list.
1520 - All eventpoints without a symbolic address are removed from the
1521 breakpoint list. */
1522 extern void update_breakpoints_after_exec (void);
1523
1524 /* This function can be used to physically remove hardware breakpoints
1525 and watchpoints from the specified traced inferior process, without
1526 modifying the breakpoint package's state. This can be useful for
1527 those targets which support following the processes of a fork() or
1528 vfork() system call, when one of the resulting two processes is to
1529 be detached and allowed to run free.
1530
1531 It is an error to use this function on the process whose id is
1532 inferior_ptid. */
1533 extern int detach_breakpoints (ptid_t ptid);
1534
1535 /* This function is called when program space PSPACE is about to be
1536 deleted. It takes care of updating breakpoints to not reference
1537 this PSPACE anymore. */
1538 extern void breakpoint_program_space_exit (struct program_space *pspace);
1539
1540 extern void set_longjmp_breakpoint (struct thread_info *tp,
1541 struct frame_id frame);
1542 extern void delete_longjmp_breakpoint (int thread);
1543
1544 /* Mark all longjmp breakpoints from THREAD for later deletion. */
1545 extern void delete_longjmp_breakpoint_at_next_stop (int thread);
1546
1547 extern struct breakpoint *set_longjmp_breakpoint_for_call_dummy (void);
1548 extern void check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp);
1549
1550 extern void enable_overlay_breakpoints (void);
1551 extern void disable_overlay_breakpoints (void);
1552
1553 extern void set_std_terminate_breakpoint (void);
1554 extern void delete_std_terminate_breakpoint (void);
1555
1556 /* These functions respectively disable or reenable all currently
1557 enabled watchpoints. When disabled, the watchpoints are marked
1558 call_disabled. When re-enabled, they are marked enabled.
1559
1560 The intended client of these functions is call_function_by_hand.
1561
1562 The inferior must be stopped, and all breakpoints removed, when
1563 these functions are used.
1564
1565 The need for these functions is that on some targets (e.g., HP-UX),
1566 gdb is unable to unwind through the dummy frame that is pushed as
1567 part of the implementation of a call command. Watchpoints can
1568 cause the inferior to stop in places where this frame is visible,
1569 and that can cause execution control to become very confused.
1570
1571 Note that if a user sets breakpoints in an interactively called
1572 function, the call_disabled watchpoints will have been re-enabled
1573 when the first such breakpoint is reached. However, on targets
1574 that are unable to unwind through the call dummy frame, watches
1575 of stack-based storage may then be deleted, because gdb will
1576 believe that their watched storage is out of scope. (Sigh.) */
1577 extern void disable_watchpoints_before_interactive_call_start (void);
1578
1579 extern void enable_watchpoints_after_interactive_call_stop (void);
1580
1581 /* These functions disable and re-enable all breakpoints during
1582 inferior startup. They are intended to be called from solib
1583 code where necessary. This is needed on platforms where the
1584 main executable is relocated at some point during startup
1585 processing, making breakpoint addresses invalid.
1586
1587 If additional breakpoints are created after the routine
1588 disable_breakpoints_before_startup but before the routine
1589 enable_breakpoints_after_startup was called, they will also
1590 be marked as disabled. */
1591 extern void disable_breakpoints_before_startup (void);
1592 extern void enable_breakpoints_after_startup (void);
1593
1594 /* For script interpreters that need to define breakpoint commands
1595 after they've already read the commands into a struct
1596 command_line. */
1597 extern enum command_control_type commands_from_control_command
1598 (const char *arg, struct command_line *cmd);
1599
1600 extern void clear_breakpoint_hit_counts (void);
1601
1602 extern struct breakpoint *get_breakpoint (int num);
1603
1604 /* The following are for displays, which aren't really breakpoints,
1605 but here is as good a place as any for them. */
1606
1607 extern void disable_current_display (void);
1608
1609 extern void do_displays (void);
1610
1611 extern void disable_display (int);
1612
1613 extern void clear_displays (void);
1614
1615 extern void disable_breakpoint (struct breakpoint *);
1616
1617 extern void enable_breakpoint (struct breakpoint *);
1618
1619 extern void breakpoint_set_commands (struct breakpoint *b,
1620 counted_command_line &&commands);
1621
1622 extern void breakpoint_set_silent (struct breakpoint *b, int silent);
1623
1624 extern void breakpoint_set_thread (struct breakpoint *b, int thread);
1625
1626 extern void breakpoint_set_task (struct breakpoint *b, int task);
1627
1628 /* Clear the "inserted" flag in all breakpoints. */
1629 extern void mark_breakpoints_out (void);
1630
1631 extern struct breakpoint *create_jit_event_breakpoint (struct gdbarch *,
1632 CORE_ADDR);
1633
1634 extern struct breakpoint *create_solib_event_breakpoint (struct gdbarch *,
1635 CORE_ADDR);
1636
1637 /* Create an solib event breakpoint at ADDRESS in the current program
1638 space, and immediately try to insert it. Returns a pointer to the
1639 breakpoint on success. Deletes the new breakpoint and returns NULL
1640 if inserting the breakpoint fails. */
1641 extern struct breakpoint *create_and_insert_solib_event_breakpoint
1642 (struct gdbarch *gdbarch, CORE_ADDR address);
1643
1644 extern struct breakpoint *create_thread_event_breakpoint (struct gdbarch *,
1645 CORE_ADDR);
1646
1647 extern void remove_jit_event_breakpoints (void);
1648
1649 extern void remove_solib_event_breakpoints (void);
1650
1651 /* Mark solib event breakpoints of the current program space with
1652 delete at next stop disposition. */
1653 extern void remove_solib_event_breakpoints_at_next_stop (void);
1654
1655 extern void disable_breakpoints_in_shlibs (void);
1656
1657 /* This function returns true if B is a catchpoint. */
1658
1659 extern bool is_catchpoint (struct breakpoint *b);
1660
1661 /* Shared helper function (MI and CLI) for creating and installing
1662 a shared object event catchpoint. If IS_LOAD is true then
1663 the events to be caught are load events, otherwise they are
1664 unload events. If IS_TEMP is true the catchpoint is a
1665 temporary one. If ENABLED is true the catchpoint is
1666 created in an enabled state. */
1667
1668 extern void add_solib_catchpoint (const char *arg, bool is_load, bool is_temp,
1669 bool enabled);
1670
1671 /* Create and insert a new software single step breakpoint for the
1672 current thread. May be called multiple times; each time will add a
1673 new location to the set of potential addresses the next instruction
1674 is at. */
1675 extern void insert_single_step_breakpoint (struct gdbarch *,
1676 const address_space *,
1677 CORE_ADDR);
1678
1679 /* Insert all software single step breakpoints for the current frame.
1680 Return true if any software single step breakpoints are inserted,
1681 otherwise, return false. */
1682 extern int insert_single_step_breakpoints (struct gdbarch *);
1683
1684 /* Check whether any hardware watchpoints have triggered or not,
1685 according to the target, and record it in each watchpoint's
1686 'watchpoint_triggered' field. */
1687 int watchpoints_triggered (const target_waitstatus &);
1688
1689 /* Helper for transparent breakpoint hiding for memory read and write
1690 routines.
1691
1692 Update one of READBUF or WRITEBUF with either the shadows
1693 (READBUF), or the breakpoint instructions (WRITEBUF) of inserted
1694 breakpoints at the memory range defined by MEMADDR and extending
1695 for LEN bytes. If writing, then WRITEBUF is a copy of WRITEBUF_ORG
1696 on entry.*/
1697 extern void breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf,
1698 const gdb_byte *writebuf_org,
1699 ULONGEST memaddr, LONGEST len);
1700
1701 /* Return true if breakpoints should be inserted now. That'll be the
1702 case if either:
1703
1704 - the target has global breakpoints.
1705
1706 - "breakpoint always-inserted" is on, and the target has
1707 execution.
1708
1709 - threads are executing.
1710 */
1711 extern int breakpoints_should_be_inserted_now (void);
1712
1713 /* Called each time new event from target is processed.
1714 Retires previously deleted breakpoint locations that
1715 in our opinion won't ever trigger. */
1716 extern void breakpoint_retire_moribund (void);
1717
1718 /* Set break condition of breakpoint B to EXP.
1719 If FORCE, define the condition even if it is invalid in
1720 all of the breakpoint locations. */
1721 extern void set_breakpoint_condition (struct breakpoint *b, const char *exp,
1722 int from_tty, bool force);
1723
1724 /* Set break condition for the breakpoint with number BPNUM to EXP.
1725 Raise an error if no breakpoint with the given number is found.
1726 Also raise an error if the breakpoint already has stop conditions.
1727 If FORCE, define the condition even if it is invalid in
1728 all of the breakpoint locations. */
1729 extern void set_breakpoint_condition (int bpnum, const char *exp,
1730 int from_tty, bool force);
1731
1732 /* Checks if we are catching syscalls or not.
1733 Returns 0 if not, greater than 0 if we are. */
1734 extern int catch_syscall_enabled (void);
1735
1736 /* Checks if we are catching syscalls with the specific
1737 syscall_number. Used for "filtering" the catchpoints.
1738 Returns false if not, true if we are. */
1739 extern bool catching_syscall_number (int syscall_number);
1740
1741 /* Return a tracepoint with the given number if found. */
1742 extern struct tracepoint *get_tracepoint (int num);
1743
1744 extern struct tracepoint *get_tracepoint_by_number_on_target (int num);
1745
1746 /* Find a tracepoint by parsing a number in the supplied string. */
1747 extern struct tracepoint *
1748 get_tracepoint_by_number (const char **arg,
1749 number_or_range_parser *parser);
1750
1751 /* Return true if B is of tracepoint kind. */
1752
1753 extern bool is_tracepoint (const struct breakpoint *b);
1754
1755 /* Return a vector of all static tracepoints defined at ADDR. */
1756 extern std::vector<breakpoint *> static_tracepoints_here (CORE_ADDR addr);
1757
1758 /* Create an instance of this to start registering breakpoint numbers
1759 for a later "commands" command. */
1760
1761 class scoped_rbreak_breakpoints
1762 {
1763 public:
1764
1765 scoped_rbreak_breakpoints ();
1766 ~scoped_rbreak_breakpoints ();
1767
1768 DISABLE_COPY_AND_ASSIGN (scoped_rbreak_breakpoints);
1769 };
1770
1771 /* Breakpoint linked list iterator. */
1772
1773 using breakpoint_iterator = next_iterator<breakpoint>;
1774
1775 /* Breakpoint linked list range. */
1776
1777 using breakpoint_range = iterator_range<breakpoint_iterator>;
1778
1779 /* Return a range to iterate over all breakpoints. */
1780
1781 breakpoint_range all_breakpoints ();
1782
1783 /* Breakpoint linked list range, safe against deletion of the current
1784 breakpoint while iterating. */
1785
1786 using breakpoint_safe_range = basic_safe_range<breakpoint_range>;
1787
1788 /* Return a range to iterate over all breakpoints. This range is safe against
1789 deletion of the current breakpoint while iterating. */
1790
1791 breakpoint_safe_range all_breakpoints_safe ();
1792
1793 /* Breakpoint filter to only keep tracepoints. */
1794
1795 struct tracepoint_filter
1796 {
1797 bool operator() (breakpoint *b)
1798 { return is_tracepoint (b); }
1799 };
1800
1801 /* Breakpoint linked list iterator, filtering to only keep tracepoints. */
1802
1803 using tracepoint_iterator
1804 = filtered_iterator<breakpoint_iterator, tracepoint_filter>;
1805
1806 /* Breakpoint linked list range, filtering to only keep tracepoints. */
1807
1808 using tracepoint_range = iterator_range<tracepoint_iterator>;
1809
1810 /* Return a range to iterate over all tracepoints. */
1811
1812 tracepoint_range all_tracepoints ();
1813
1814 /* Return a range to iterate over all breakpoint locations. */
1815
1816 const std::vector<bp_location *> &all_bp_locations ();
1817
1818 /* Nonzero if the specified PC cannot be a location where functions
1819 have been inlined. */
1820
1821 extern int pc_at_non_inline_function (const address_space *aspace,
1822 CORE_ADDR pc,
1823 const target_waitstatus &ws);
1824
1825 extern int user_breakpoint_p (struct breakpoint *);
1826
1827 /* Return true if this breakpoint is pending, false if not. */
1828 extern int pending_breakpoint_p (struct breakpoint *);
1829
1830 /* Attempt to determine architecture of location identified by SAL. */
1831 extern struct gdbarch *get_sal_arch (struct symtab_and_line sal);
1832
1833 extern void breakpoint_free_objfile (struct objfile *objfile);
1834
1835 extern const char *ep_parse_optional_if_clause (const char **arg);
1836
1837 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" to
1838 UIOUT iff debugging multiple threads. */
1839 extern void maybe_print_thread_hit_breakpoint (struct ui_out *uiout);
1840
1841 /* Print the specified breakpoint. */
1842 extern void print_breakpoint (breakpoint *bp);
1843
1844 /* Command element for the 'commands' command. */
1845 extern cmd_list_element *commands_cmd_element;
1846
1847 /* Whether to use the fixed output when printing information about a
1848 multi-location breakpoint (see PR 9659). */
1849
1850 extern bool fix_multi_location_breakpoint_output_globally;
1851
1852 /* Deal with "catch catch", "catch throw", and "catch rethrow" commands and
1853 the MI equivalents. Sets up to catch events of type EX_EVENT. When
1854 TEMPFLAG is true only the next matching event is caught after which the
1855 catch-point is deleted. If REGEX is not NULL then only exceptions whose
1856 type name matches REGEX will trigger the event. */
1857
1858 extern void catch_exception_event (enum exception_event_kind ex_event,
1859 const char *regex, bool tempflag,
1860 int from_tty);
1861
1862 /* A helper function that prints a shared library stopped event.
1863 IS_CATCHPOINT is true if the event is due to a "catch load"
1864 catchpoint, false otherwise. */
1865
1866 extern void print_solib_event (bool is_catchpoint);
1867
1868 #endif /* !defined (BREAKPOINT_H) */