GDB (xrefs)
Loading...
Searching...
No Matches
breakpoint.c
Go to the documentation of this file.
1/* Everything about breakpoints, for GDB.
2
3 Copyright (C) 1986-2023 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20#include "defs.h"
21#include "arch-utils.h"
22#include <ctype.h>
23#include "hashtab.h"
24#include "symtab.h"
25#include "frame.h"
26#include "breakpoint.h"
27#include "tracepoint.h"
28#include "gdbtypes.h"
29#include "expression.h"
30#include "gdbcore.h"
31#include "gdbcmd.h"
32#include "value.h"
33#include "command.h"
34#include "inferior.h"
35#include "infrun.h"
36#include "gdbthread.h"
37#include "target.h"
38#include "language.h"
39#include "gdb-demangle.h"
40#include "filenames.h"
41#include "annotate.h"
42#include "symfile.h"
43#include "objfiles.h"
44#include "source.h"
45#include "linespec.h"
46#include "completer.h"
47#include "ui-out.h"
48#include "cli/cli-script.h"
49#include "block.h"
50#include "solib.h"
51#include "solist.h"
52#include "observable.h"
53#include "memattr.h"
54#include "ada-lang.h"
55#include "top.h"
56#include "ui.h"
57#include "valprint.h"
58#include "jit.h"
59#include "parser-defs.h"
60#include "gdbsupport/gdb_regex.h"
61#include "probe.h"
62#include "cli/cli-utils.h"
63#include "stack.h"
64#include "ax-gdb.h"
65#include "dummy-frame.h"
66#include "interps.h"
67#include "gdbsupport/format.h"
68#include "thread-fsm.h"
69#include "tid-parse.h"
70#include "cli/cli-style.h"
71#include "cli/cli-decode.h"
72#include <unordered_set>
73
74/* readline include files */
75#include "readline/tilde.h"
76
77/* readline defines this. */
78#undef savestring
79
80#include "mi/mi-common.h"
81#include "extension.h"
82#include <algorithm>
84#include "gdbsupport/array-view.h"
85#include "gdbsupport/gdb_optional.h"
86#include "gdbsupport/common-utils.h"
87
88/* Prototypes for local functions. */
89
90static void map_breakpoint_numbers (const char *,
91 gdb::function_view<void (breakpoint *)>);
92
93static void
95 linespec_result *canonical);
96
97static void create_breakpoints_sal (struct gdbarch *,
98 struct linespec_result *,
99 gdb::unique_xmalloc_ptr<char>,
100 gdb::unique_xmalloc_ptr<char>,
101 enum bptype,
102 enum bpdisp, int, int, int,
103 int,
104 int, int, int, unsigned);
105
107 (const std::vector<value_ref_ptr> &vals);
108
109static void mention (const breakpoint *);
110
111static breakpoint *add_to_breakpoint_chain (std::unique_ptr<breakpoint> &&b);
112
113static breakpoint *add_to_breakpoint_chain (std::unique_ptr<breakpoint> &&b);
114
115static struct breakpoint *
117 enum bptype type,
118 int loc_enabled, int thread);
119
120static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, bool);
121
122static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch,
123 CORE_ADDR bpaddr,
124 enum bptype bptype,
125 struct program_space *pspace);
126
127static bool watchpoint_locations_match (const struct bp_location *loc1,
128 const struct bp_location *loc2);
129
130static bool breakpoint_locations_match (const struct bp_location *loc1,
131 const struct bp_location *loc2,
132 bool sw_hw_bps_match = false);
133
135 const struct address_space *aspace,
136 CORE_ADDR addr);
137
139 const address_space *,
140 CORE_ADDR, int);
141
142static int remove_breakpoint (struct bp_location *);
143static int remove_breakpoint_1 (struct bp_location *, enum remove_bp_reason);
144
146
147static int hw_breakpoint_used_count (void);
148
149static int hw_watchpoint_use_count (struct breakpoint *);
150
151static int hw_watchpoint_used_count_others (struct breakpoint *except,
152 enum bptype type,
153 int *other_type_used);
154
155static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp,
156 int count);
157
158static void decref_bp_location (struct bp_location **loc);
159
160static std::vector<symtab_and_line> bkpt_probe_decode_location_spec
161 (struct breakpoint *b,
163 struct program_space *search_pspace);
164
166
167static int find_loc_num_by_location (const bp_location *loc);
168
169/* update_global_location_list's modes of operation wrt to whether to
170 insert locations now. */
172{
173 /* Don't insert any breakpoint locations into the inferior, only
174 remove already-inserted locations that no longer should be
175 inserted. Functions that delete a breakpoint or breakpoints
176 should specify this mode, so that deleting a breakpoint doesn't
177 have the side effect of inserting the locations of other
178 breakpoints that are marked not-inserted, but should_be_inserted
179 returns true on them.
180
181 This behavior is useful is situations close to tear-down -- e.g.,
182 after an exec, while the target still has execution, but
183 breakpoint shadows of the previous executable image should *NOT*
184 be restored to the new image; or before detaching, where the
185 target still has execution and wants to delete breakpoints from
186 GDB's lists, and all breakpoints had already been removed from
187 the inferior. */
189
190 /* May insert breakpoints iff breakpoints_should_be_inserted_now
191 claims breakpoints should be inserted now. */
193
194 /* Insert locations now, irrespective of
195 breakpoints_should_be_inserted_now. E.g., say all threads are
196 stopped right now, and the user did "continue". We need to
197 insert breakpoints _before_ resuming the target, but
198 UGLL_MAY_INSERT wouldn't insert them, because
199 breakpoints_should_be_inserted_now returns false at that point,
200 as no thread is running yet. */
203
204/* Return a textual version of INSERT_MODE. */
205
206static const char *
208{
209/* Make sure the compiler warns if a new ugll_insert_mode enumerator is added
210 but not handled here. */
211DIAGNOSTIC_PUSH
212DIAGNOSTIC_ERROR_SWITCH
213 switch (insert_mode)
214 {
215 case UGLL_DONT_INSERT:
216 return "UGLL_DONT_INSERT";
217 case UGLL_MAY_INSERT:
218 return "UGLL_MAY_INSERT";
219 case UGLL_INSERT:
220 return "UGLL_INSERT";
221 }
222DIAGNOSTIC_POP
223
224 gdb_assert_not_reached ("must handle all enum values");
225}
226
227/* Return a textual version of REASON. */
228
229static const char *
231{
232/* Make sure the compiler warns if a new remove_bp_reason enumerator is added
233 but not handled here. */
234DIAGNOSTIC_PUSH
235DIAGNOSTIC_ERROR_SWITCH
236 switch (reason)
237 {
239 return "regular remove";
241 return "detach";
242 }
243DIAGNOSTIC_POP
244
245 gdb_assert_not_reached ("must handle all enum values");
246}
247
248/* Return a textual version of breakpoint location BL describing number,
249 location and address. */
250
251static std::string
253{
254 std::string str = string_printf ("Breakpoint %d (%s) at address %s",
255 bl->owner->number,
256 host_address_to_string (bl),
257 paddress (bl->gdbarch, bl->address));
258
259 std::string loc_string = bl->to_string ();
260 if (!loc_string.empty ())
261 str += string_printf (" %s", loc_string.c_str ());
262
263 return str;
264}
265
267
269
270static void insert_breakpoint_locations (void);
271
272static void trace_pass_command (const char *, int);
273
274static void set_tracepoint_count (int num);
275
276static bool is_masked_watchpoint (const struct breakpoint *b);
277
278/* Return true if B refers to a static tracepoint set by marker ("-m"),
279 zero otherwise. */
280
281static bool strace_marker_p (struct breakpoint *b);
282
285 struct linespec_result *canonical);
288 struct linespec_result *canonical);
289
295
296/* Breakpoints set on probes. */
302
303/* Tracepoints set on probes. */
309
310/* Implementation of abstract dtors. These must exist to satisfy the
311 linker. */
312
316
320
324
325/* The structure to be used in regular breakpoints. */
327{
329
330 int resources_needed (const struct bp_location *) override;
331 enum print_stop_action print_it (const bpstat *bs) const override;
332 void print_mention () const override;
333 void print_recreate (struct ui_file *fp) const override;
334};
335
336/* Internal breakpoints. These typically have a lifetime the same as
337 the program, and they end up installed on the breakpoint chain with
338 a negative breakpoint number. They're visible in "maint info
339 breakpoints", but not "info breakpoints". */
341{
343 enum bptype type, CORE_ADDR address)
345 {
346 symtab_and_line sal;
347 sal.pc = address;
348 sal.section = find_pc_overlay (sal.pc);
350 add_location (sal);
351
354 }
355
356 void re_set () override;
357 void check_status (struct bpstat *bs) override;
358 enum print_stop_action print_it (const bpstat *bs) const override;
359 void print_mention () const override;
360};
361
362/* Momentary breakpoints. These typically have a lifetime of some run
363 control command only, are always thread-specific, and have 0 for
364 breakpoint number. I.e., there can be many momentary breakpoints
365 on the breakpoint chain and they all same the same number (zero).
366 They're visible in "maint info breakpoints", but not "info
367 breakpoints". */
369{
370 momentary_breakpoint (struct gdbarch *gdbarch_, enum bptype bptype,
371 program_space *pspace_,
372 const struct frame_id &frame_id_,
373 int thread_)
374 : code_breakpoint (gdbarch_, bptype)
375 {
376 /* If FRAME_ID is valid, it should be a real frame, not an inlined
377 or tail-called one. */
378 gdb_assert (!frame_id_artificial_p (frame_id));
379
380 /* Momentary breakpoints are always thread-specific. */
381 gdb_assert (thread_ > 0);
382
383 pspace = pspace_;
386 frame_id = frame_id_;
387 thread = thread_;
388
389 /* The inferior should have been set by the parent constructor. */
390 gdb_assert (inferior == -1);
391 }
392
393 void re_set () override;
394 void check_status (struct bpstat *bs) override;
395 enum print_stop_action print_it (const bpstat *bs) const override;
396 void print_mention () const override;
397};
398
399/* DPrintf breakpoints. */
401{
402 using ordinary_breakpoint::ordinary_breakpoint;
403
404 void re_set () override;
405 int breakpoint_hit (const struct bp_location *bl,
406 const address_space *aspace,
407 CORE_ADDR bp_addr,
408 const target_waitstatus &ws) override;
409 void print_recreate (struct ui_file *fp) const override;
410 void after_condition_true (struct bpstat *bs) override;
411};
412
413/* Ranged breakpoints. */
415{
417 const symtab_and_line &sal_start,
418 int length,
419 location_spec_up start_locspec,
420 location_spec_up end_locspec)
422 {
423 bp_location *bl = add_location (sal_start);
424 bl->length = length;
425
427
428 locspec = std::move (start_locspec);
429 locspec_range_end = std::move (end_locspec);
430 }
431
432 int breakpoint_hit (const struct bp_location *bl,
433 const address_space *aspace,
434 CORE_ADDR bp_addr,
435 const target_waitstatus &ws) override;
436 int resources_needed (const struct bp_location *) override;
437 enum print_stop_action print_it (const bpstat *bs) const override;
438 bool print_one (const bp_location **) const override;
439 void print_one_detail (struct ui_out *) const override;
440 void print_mention () const override;
441 void print_recreate (struct ui_file *fp) const override;
442};
443
444/* Static tracepoints with marker (`-m'). */
446{
447 using tracepoint::tracepoint;
448
449 std::vector<symtab_and_line> decode_location_spec
450 (struct location_spec *locspec,
451 struct program_space *search_pspace) override;
452};
453
454/* The style in which to perform a dynamic printf. This is a user
455 option because different output options have different tradeoffs;
456 if GDB does the printing, there is better error handling if there
457 is a problem with any of the arguments, but using an inferior
458 function lets you have special-purpose printers and sending of
459 output to the same place as compiled-in print functions. */
460
461static const char dprintf_style_gdb[] = "gdb";
462static const char dprintf_style_call[] = "call";
463static const char dprintf_style_agent[] = "agent";
464static const char *const dprintf_style_enums[] = {
468 NULL
469};
470static const char *dprintf_style = dprintf_style_gdb;
471
472/* The function to use for dynamic printf if the preferred style is to
473 call into the inferior. The value is simply a string that is
474 copied into the command, so it can be anything that GDB can
475 evaluate to a callable address, not necessarily a function name. */
476
477static std::string dprintf_function = "printf";
478
479/* The channel to use for dynamic printf if the preferred style is to
480 call into the inferior; if a nonempty string, it will be passed to
481 the call as the first argument, with the format string as the
482 second. As with the dprintf function, this can be anything that
483 GDB knows how to evaluate, so in addition to common choices like
484 "stderr", this could be an app-specific expression like
485 "mystreams[curlogger]". */
486
487static std::string dprintf_channel;
488
489/* True if dprintf commands should continue to operate even if GDB
490 has disconnected. */
491static bool disconnected_dprintf = true;
492
493struct command_line *
495{
496 return b->commands ? b->commands.get () : NULL;
497}
498
499/* Flag indicating that a command has proceeded the inferior past the
500 current breakpoint. */
501
503
504const char *
506{
507 /* NOTE: the following values are a part of MI protocol and
508 represent values of 'disp' field returned when inferior stops at
509 a breakpoint. */
510 static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"};
511
512 return bpdisps[(int) disp];
513}
514
515/* Prototypes for exported functions. */
516/* If FALSE, gdb will not use hardware support for watchpoints, even
517 if such is available. */
519
520static void
521show_can_use_hw_watchpoints (struct ui_file *file, int from_tty,
522 struct cmd_list_element *c,
523 const char *value)
524{
525 gdb_printf (file,
526 _("Debugger's willingness to use "
527 "watchpoint hardware is %s.\n"),
528 value);
529}
530
531/* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
532 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
533 for unrecognized breakpoint locations.
534 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
536static void
537show_pending_break_support (struct ui_file *file, int from_tty,
538 struct cmd_list_element *c,
539 const char *value)
540{
541 gdb_printf (file,
542 _("Debugger's behavior regarding "
543 "pending breakpoints is %s.\n"),
544 value);
545}
546
547/* If true, gdb will automatically use hardware breakpoints for breakpoints
548 set with "break" but falling in read-only memory.
549 If false, gdb will warn about such breakpoints, but won't automatically
550 use hardware breakpoints. */
552static void
554 struct cmd_list_element *c,
555 const char *value)
556{
557 gdb_printf (file,
558 _("Automatic usage of hardware breakpoints is %s.\n"),
559 value);
560}
561
562/* If on, GDB keeps breakpoints inserted even if the inferior is
563 stopped, and immediately inserts any new breakpoints as soon as
564 they're created. If off (default), GDB keeps breakpoints off of
565 the target as long as possible. That is, it delays inserting
566 breakpoints until the next resume, and removes them again when the
567 target fully stops. This is a bit safer in case GDB crashes while
568 processing user input. */
569static bool always_inserted_mode = false;
570
571static void
572show_always_inserted_mode (struct ui_file *file, int from_tty,
573 struct cmd_list_element *c, const char *value)
574{
575 gdb_printf (file, _("Always inserted breakpoint mode is %s.\n"),
576 value);
577}
578
579/* True if breakpoint debug output is enabled. */
580static bool debug_breakpoint = false;
581
582/* Print a "breakpoint" debug statement. */
583#define breakpoint_debug_printf(fmt, ...) \
584 debug_prefixed_printf_cond (debug_breakpoint, "breakpoint", fmt, \
585 ##__VA_ARGS__)
586
587/* "show debug breakpoint" implementation. */
588static void
589show_debug_breakpoint (struct ui_file *file, int from_tty,
590 struct cmd_list_element *c, const char *value)
591{
592 gdb_printf (file, _("Breakpoint location debugging is %s.\n"), value);
593}
594
595/* See breakpoint.h. */
596
597int
599{
601 {
602 /* If breakpoints are global, they should be inserted even if no
603 thread under gdb's control is running, or even if there are
604 no threads under GDB's control yet. */
605 return 1;
606 }
607 else
608 {
610 {
611 /* The user wants breakpoints inserted even if all threads
612 are stopped. */
613 return 1;
614 }
615
616 for (inferior *inf : all_inferiors ())
617 if (inf->has_execution ()
618 && threads_are_executing (inf->process_target ()))
619 return 1;
620
621 /* Don't remove breakpoints yet if, even though all threads are
622 stopped, we still have events to process. */
624 if (tp->resumed () && tp->has_pending_waitstatus ())
625 return 1;
626 }
627 return 0;
628}
629
630static const char condition_evaluation_both[] = "host or target";
631
632/* Modes for breakpoint condition evaluation. */
633static const char condition_evaluation_auto[] = "auto";
634static const char condition_evaluation_host[] = "host";
635static const char condition_evaluation_target[] = "target";
642
643/* Global that holds the current mode for breakpoint condition evaluation. */
645
646/* Global that we use to display information to the user (gets its value from
647 condition_evaluation_mode_1. */
649
650/* Translate a condition evaluation mode MODE into either "host"
651 or "target". This is used mostly to translate from "auto" to the
652 real setting that is being used. It returns the translated
653 evaluation mode. */
654
655static const char *
657{
658 if (mode == condition_evaluation_auto)
659 {
662 else
664 }
665 else
666 return mode;
667}
668
669/* Discovers what condition_evaluation_auto translates to. */
670
671static const char *
676
677/* Return true if GDB should evaluate breakpoint conditions or false
678 otherwise. */
679
680static bool
682{
683 const char *mode = breakpoint_condition_evaluation_mode ();
684
685 return (mode == condition_evaluation_host);
686}
687
688/* Are we executing breakpoint commands? */
690
691/* Are overlay event breakpoints enabled? */
693
694/* See description in breakpoint.h. */
696
697/* Chains of all breakpoints defined. */
698
699static intrusive_list<breakpoint> breakpoint_chain;
700
701/* See breakpoint.h. */
702
705{
706 return breakpoint_range (breakpoint_chain.begin (), breakpoint_chain.end ());
707}
708
709/* See breakpoint.h. */
710
716
717/* See breakpoint.h. */
718
725
726/* Array is sorted by bp_location_is_less_than - primarily by the ADDRESS. */
727
728static std::vector<bp_location *> bp_locations;
729
730/* See breakpoint.h. */
731
732const std::vector<bp_location *> &
734{
735 return bp_locations;
736}
737
738/* Range to iterate over breakpoint locations at a given address. */
739
741{
742 using iterator = std::vector<bp_location *>::iterator;
743
745 {
746 struct compare
747 {
748 bool operator() (const bp_location *loc, CORE_ADDR addr_) const
749 { return loc->address < addr_; }
750
751 bool operator() (CORE_ADDR addr_, const bp_location *loc) const
752 { return addr_ < loc->address; }
753 };
754
755 auto it_pair = std::equal_range (bp_locations.begin (), bp_locations.end (),
756 addr, compare ());
757
758 m_begin = it_pair.first;
759 m_end = it_pair.second;
760 }
761
763 { return m_begin; }
764
765 iterator end () const
766 { return m_end; }
767
768private:
771};
772
773/* Return a range to iterate over all breakpoint locations exactly at address
774 ADDR.
775
776 If it's needed to iterate multiple times on the same range, it's possible
777 to save the range in a local variable and use it multiple times:
778
779 auto range = all_bp_locations_at_addr (addr);
780
781 for (bp_location *loc : range)
782 // use loc
783
784 for (bp_location *loc : range)
785 // use loc
786
787 This saves a bit of time, as it avoids re-doing the binary searches to find
788 the range's boundaries. Just remember not to change the bp_locations vector
789 in the mean time, as it could make the range's iterators stale. */
790
793{
794 return bp_locations_at_addr_range (addr);
795}
796
797/* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
798 ADDRESS for the current elements of BP_LOCATIONS which get a valid
799 result from bp_location_has_shadow. You can use it for roughly
800 limiting the subrange of BP_LOCATIONS to scan for shadow bytes for
801 an address you need to read. */
802
804
805/* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
806 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
807 BP_LOCATIONS which get a valid result from bp_location_has_shadow.
808 You can use it for roughly limiting the subrange of BP_LOCATIONS to
809 scan for shadow bytes for an address you need to read. */
810
812
813/* The locations that no longer correspond to any breakpoint, unlinked
814 from the bp_locations array, but for which a hit may still be
815 reported by a target. */
816static std::vector<bp_location *> moribund_locations;
817
818/* Number of last breakpoint made. */
819
821
822/* The value of `breakpoint_count' before the last command that
823 created breakpoints. If the last (break-like) command created more
824 than one breakpoint, then the difference between BREAKPOINT_COUNT
825 and PREV_BREAKPOINT_COUNT is more than one. */
827
828/* Number of last tracepoint made. */
829
831
835
836/* Return whether a breakpoint is an active enabled breakpoint. */
837static bool
839{
840 return (b->enable_state == bp_enabled);
841}
842
843/* Set breakpoint count to NUM. */
844
845static void
852
853/* Used by `start_rbreak_breakpoints' below, to record the current
854 breakpoint count before "rbreak" creates any breakpoint. */
856
857/* Called at the start an "rbreak" command to record the first
858 breakpoint made. */
859
864
865/* Called at the end of an "rbreak" command to record the last
866 breakpoint made. */
867
872
873/* Used in run_command to zero the hit count when a new run starts. */
874
875void
877{
878 for (breakpoint &b : all_breakpoints ())
879 b.hit_count = 0;
880}
881
882
883/* Return the breakpoint with the specified number, or NULL
884 if the number does not refer to an existing breakpoint. */
885
886struct breakpoint *
888{
889 for (breakpoint &b : all_breakpoints ())
890 if (b.number == num)
891 return &b;
892
893 return nullptr;
894}
895
896/* Return TRUE if NUM refer to an existing breakpoint that has
897 multiple code locations. */
898
899static bool
901{
902 for (breakpoint &b : all_breakpoints ())
903 if (b.number == num)
904 return b.has_multiple_locations ();
905
906 return false;
907}
908
909
910
911/* Mark locations as "conditions have changed" in case the target supports
912 evaluating conditions on its side. */
913
914static void
916{
917 /* This is only meaningful if the target is
918 evaluating conditions and if the user has
919 opted for condition evaluation on the target's
920 side. */
923 return;
924
925 if (!is_breakpoint (b))
926 return;
927
928 for (bp_location &loc : b->locations ())
929 loc.condition_changed = condition_modified;
930}
931
932/* Mark location as "conditions have changed" in case the target supports
933 evaluating conditions on its side. */
934
935static void
937{
938 /* This is only meaningful if the target is
939 evaluating conditions and if the user has
940 opted for condition evaluation on the target's
941 side. */
944
945 return;
946
947 if (!is_breakpoint (loc->owner))
948 return;
949
950 loc->condition_changed = condition_modified;
951}
952
953/* Sets the condition-evaluation mode using the static global
954 condition_evaluation_mode. */
955
956static void
957set_condition_evaluation_mode (const char *args, int from_tty,
958 struct cmd_list_element *c)
959{
960 const char *old_mode, *new_mode;
961
964 {
966 warning (_("Target does not support breakpoint condition evaluation.\n"
967 "Using host evaluation mode instead."));
968 return;
969 }
970
973
974 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
975 settings was "auto". */
977
978 /* Only update the mode if the user picked a different one. */
979 if (new_mode != old_mode)
980 {
981 /* If the user switched to a different evaluation mode, we
982 need to synch the changes with the target as follows:
983
984 "host" -> "target": Send all (valid) conditions to the target.
985 "target" -> "host": Remove all the conditions from the target.
986 */
987
988 if (new_mode == condition_evaluation_target)
989 {
990 /* Mark everything modified and synch conditions with the
991 target. */
994 }
995 else
996 {
997 /* Manually mark non-duplicate locations to synch conditions
998 with the target. We do this to remove all the conditions the
999 target knows about. */
1000 for (bp_location *loc : all_bp_locations ())
1001 if (is_breakpoint (loc->owner) && loc->inserted)
1002 loc->needs_update = 1;
1003 }
1004
1005 /* Do the update. */
1007 }
1008
1009 return;
1010}
1011
1012/* Shows the current mode of breakpoint condition evaluation. Explicitly shows
1013 what "auto" is translating to. */
1014
1015static void
1016show_condition_evaluation_mode (struct ui_file *file, int from_tty,
1017 struct cmd_list_element *c, const char *value)
1018{
1020 gdb_printf (file,
1021 _("Breakpoint condition evaluation "
1022 "mode is %s (currently %s).\n"),
1023 value,
1025 else
1026 gdb_printf (file, _("Breakpoint condition evaluation mode is %s.\n"),
1027 value);
1028}
1029
1030/* Parse COND_STRING in the context of LOC and set as the condition
1031 expression of LOC. BP_NUM is the number of LOC's owner, LOC_NUM is
1032 the number of LOC within its owner. In case of parsing error, mark
1033 LOC as DISABLED_BY_COND. In case of success, unset DISABLED_BY_COND. */
1034
1035static void
1037 int bp_num, int loc_num)
1038{
1039 bool has_junk = false;
1040 try
1041 {
1042 expression_up new_exp = parse_exp_1 (&cond_string, loc->address,
1043 block_for_pc (loc->address), 0);
1044 if (*cond_string != 0)
1045 has_junk = true;
1046 else
1047 {
1048 loc->cond = std::move (new_exp);
1049 if (loc->disabled_by_cond && loc->enabled)
1050 gdb_printf (_("Breakpoint %d's condition is now valid at "
1051 "location %d, enabling.\n"),
1052 bp_num, loc_num);
1053
1054 loc->disabled_by_cond = false;
1055 }
1056 }
1057 catch (const gdb_exception_error &e)
1058 {
1059 if (loc->enabled)
1060 {
1061 /* Warn if a user-enabled location is now becoming disabled-by-cond.
1062 BP_NUM is 0 if the breakpoint is being defined for the first
1063 time using the "break ... if ..." command, and non-zero if
1064 already defined. */
1065 if (bp_num != 0)
1066 warning (_("failed to validate condition at location %d.%d, "
1067 "disabling:\n %s"), bp_num, loc_num, e.what ());
1068 else
1069 warning (_("failed to validate condition at location %d, "
1070 "disabling:\n %s"), loc_num, e.what ());
1071 }
1072
1073 loc->disabled_by_cond = true;
1074 }
1075
1076 if (has_junk)
1077 error (_("Garbage '%s' follows condition"), cond_string);
1078}
1079
1080/* See breakpoint.h. */
1081
1082void
1088
1089void
1090set_breakpoint_condition (struct breakpoint *b, const char *exp,
1091 int from_tty, bool force)
1092{
1093 if (*exp == 0)
1094 {
1095 b->cond_string.reset ();
1096
1097 if (is_watchpoint (b))
1098 gdb::checked_static_cast<watchpoint *> (b)->cond_exp.reset ();
1099 else
1100 {
1101 int loc_num = 1;
1102 for (bp_location &loc : b->locations ())
1103 {
1104 loc.cond.reset ();
1105 if (loc.disabled_by_cond && loc.enabled)
1106 gdb_printf (_("Breakpoint %d's condition is now valid at "
1107 "location %d, enabling.\n"),
1108 b->number, loc_num);
1109 loc.disabled_by_cond = false;
1110 loc_num++;
1111
1112 /* No need to free the condition agent expression
1113 bytecode (if we have one). We will handle this
1114 when we go through update_global_location_list. */
1115 }
1116 }
1117
1118 if (from_tty)
1119 gdb_printf (_("Breakpoint %d now unconditional.\n"), b->number);
1120 }
1121 else
1122 {
1123 if (is_watchpoint (b))
1124 {
1126 const char *arg = exp;
1127 expression_up new_exp = parse_exp_1 (&arg, 0, 0, 0, &tracker);
1128 if (*arg != 0)
1129 error (_("Junk at end of expression"));
1130 watchpoint *w = gdb::checked_static_cast<watchpoint *> (b);
1131 w->cond_exp = std::move (new_exp);
1132 w->cond_exp_valid_block = tracker.block ();
1133 }
1134 else
1135 {
1136 /* Parse and set condition expressions. We make two passes.
1137 In the first, we parse the condition string to see if it
1138 is valid in at least one location. If so, the condition
1139 would be accepted. So we go ahead and set the locations'
1140 conditions. In case no valid case is found, we throw
1141 the error and the condition string will be rejected.
1142 This two-pass approach is taken to avoid setting the
1143 state of locations in case of a reject. */
1144 for (const bp_location &loc : b->locations ())
1145 {
1146 try
1147 {
1148 const char *arg = exp;
1149 parse_exp_1 (&arg, loc.address,
1150 block_for_pc (loc.address), 0);
1151 if (*arg != 0)
1152 error (_("Junk at end of expression"));
1153 break;
1154 }
1155 catch (const gdb_exception_error &e)
1156 {
1157 /* Condition string is invalid. If this happens to
1158 be the last loc, abandon (if not forced) or continue
1159 (if forced). */
1160 if (&loc == &b->last_loc () && !force)
1161 throw;
1162 }
1163 }
1164
1165 /* If we reach here, the condition is valid at some locations. */
1166 int loc_num = 1;
1167 for (bp_location &loc : b->locations ())
1168 {
1169 set_breakpoint_location_condition (exp, &loc, b->number, loc_num);
1170 loc_num++;
1171 }
1172 }
1173
1174 /* We know that the new condition parsed successfully. The
1175 condition string of the breakpoint can be safely updated. */
1176 b->cond_string = make_unique_xstrdup (exp);
1177 b->condition_not_parsed = 0;
1178 }
1180
1182}
1183
1184/* See breakpoint.h. */
1185
1186void
1187set_breakpoint_condition (int bpnum, const char *exp, int from_tty,
1188 bool force)
1189{
1190 for (breakpoint &b : all_breakpoints ())
1191 if (b.number == bpnum)
1192 {
1193 /* Check if this breakpoint has a "stop" method implemented in an
1194 extension language. This method and conditions entered into GDB
1195 from the CLI are mutually exclusive. */
1196 const struct extension_language_defn *extlang
1198
1199 if (extlang != NULL)
1200 {
1201 error (_("Only one stop condition allowed. There is currently"
1202 " a %s stop condition defined for this breakpoint."),
1203 ext_lang_capitalized_name (extlang));
1204 }
1205 set_breakpoint_condition (&b, exp, from_tty, force);
1206
1207 if (is_breakpoint (&b))
1209
1210 return;
1211 }
1212
1213 error (_("No breakpoint number %d."), bpnum);
1214}
1215
1216/* The options for the "condition" command. */
1217
1219{
1220 /* For "-force". */
1221 bool force_condition = false;
1222};
1223
1225
1227 "force",
1228 [] (condition_command_opts *opts) { return &opts->force_condition; },
1229 N_("Set the condition even if it is invalid for all current locations."),
1230 },
1231
1232};
1233
1234/* Create an option_def_group for the "condition" options, with
1235 CC_OPTS as context. */
1236
1242
1243/* Completion for the "condition" command. */
1244
1245static void
1247 completion_tracker &tracker,
1248 const char *text, const char * /*word*/)
1249{
1250 bool has_no_arguments = (*text == '\0');
1251 condition_command_opts cc_opts;
1252 const auto group = make_condition_command_options_def_group (&cc_opts);
1254 (tracker, &text, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR, group))
1255 return;
1256
1257 text = skip_spaces (text);
1258 const char *space = skip_to_space (text);
1259 if (*space == '\0')
1260 {
1261 int len;
1262
1263 if (text[0] == '$')
1264 {
1265 tracker.advance_custom_word_point_by (1);
1266 /* We don't support completion of history indices. */
1267 if (!isdigit (text[1]))
1268 complete_internalvar (tracker, &text[1]);
1269 return;
1270 }
1271
1272 /* Suggest the "-force" flag if no arguments are given. If
1273 arguments were passed, they either already include the flag,
1274 or we are beyond the point of suggesting it because it's
1275 positionally the first argument. */
1276 if (has_no_arguments)
1277 gdb::option::complete_on_all_options (tracker, group);
1278
1279 /* We're completing the breakpoint number. */
1280 len = strlen (text);
1281
1282 for (breakpoint &b : all_breakpoints ())
1283 {
1284 char number[50];
1285
1286 xsnprintf (number, sizeof (number), "%d", b.number);
1287
1288 if (strncmp (number, text, len) == 0)
1289 tracker.add_completion (make_unique_xstrdup (number));
1290 }
1291
1292 return;
1293 }
1294
1295 /* We're completing the expression part. Skip the breakpoint num. */
1296 const char *exp_start = skip_spaces (space);
1297 tracker.advance_custom_word_point_by (exp_start - text);
1298 text = exp_start;
1299 const char *word = advance_to_expression_complete_word_point (tracker, text);
1300 expression_completer (cmd, tracker, text, word);
1301}
1302
1303/* condition N EXP -- set break condition of breakpoint N to EXP. */
1304
1305static void
1306condition_command (const char *arg, int from_tty)
1307{
1308 const char *p;
1309 int bnum;
1310
1311 if (arg == 0)
1312 error_no_arg (_("breakpoint number"));
1313
1314 p = arg;
1315
1316 /* Check if the "-force" flag was passed. */
1317 condition_command_opts cc_opts;
1318 const auto group = make_condition_command_options_def_group (&cc_opts);
1321
1322 bnum = get_number (&p);
1323 if (bnum == 0)
1324 error (_("Bad breakpoint argument: '%s'"), arg);
1325
1326 set_breakpoint_condition (bnum, p, from_tty, cc_opts.force_condition);
1327}
1328
1329/* Check that COMMAND do not contain commands that are suitable
1330 only for tracepoints and not suitable for ordinary breakpoints.
1331 Throw if any such commands is found. */
1332
1333static void
1335{
1336 struct command_line *c;
1337
1338 for (c = commands; c; c = c->next)
1339 {
1341 error (_("The 'while-stepping' command can "
1342 "only be used for tracepoints"));
1343
1346
1347 /* Not that command parsing removes leading whitespace and comment
1348 lines and also empty lines. So, we only need to check for
1349 command directly. */
1350 if (strstr (c->line, "collect ") == c->line)
1351 error (_("The 'collect' command can only be used for tracepoints"));
1352
1353 if (strstr (c->line, "teval ") == c->line)
1354 error (_("The 'teval' command can only be used for tracepoints"));
1355 }
1356}
1357
1364
1365/* Encapsulate tests for different types of tracepoints. */
1366
1367static bool
1375
1376/* See breakpoint.h. */
1377
1378bool
1379is_tracepoint (const struct breakpoint *b)
1380{
1381 return is_tracepoint_type (b->type);
1382}
1383
1384/* Factory function to create an appropriate instance of breakpoint given
1385 TYPE. */
1386
1387template<typename... Arg>
1388static std::unique_ptr<code_breakpoint>
1390 Arg&&... args)
1391{
1392 code_breakpoint *b;
1393
1394 switch (type)
1395 {
1396 case bp_breakpoint:
1399 std::forward<Arg> (args)...);
1400 break;
1401
1402 case bp_fast_tracepoint:
1404 case bp_tracepoint:
1405 b = new tracepoint (gdbarch, type,
1406 std::forward<Arg> (args)...);
1407 break;
1408
1411 std::forward<Arg> (args)...);
1412 break;
1413
1414 case bp_dprintf:
1416 std::forward<Arg> (args)...);
1417 break;
1418
1419 default:
1420 gdb_assert_not_reached ("invalid type");
1421 }
1422
1423 return std::unique_ptr<code_breakpoint> (b);
1424}
1425
1426/* A helper function that validates that COMMANDS are valid for a
1427 breakpoint. This function will throw an exception if a problem is
1428 found. */
1429
1430static void
1432 struct command_line *commands)
1433{
1434 if (is_tracepoint (b))
1435 {
1436 tracepoint *t = gdb::checked_static_cast<tracepoint *> (b);
1437 struct command_line *c;
1438 struct command_line *while_stepping = 0;
1439
1440 /* Reset the while-stepping step count. The previous commands
1441 might have included a while-stepping action, while the new
1442 ones might not. */
1443 t->step_count = 0;
1444
1445 /* We need to verify that each top-level element of commands is
1446 valid for tracepoints, that there's at most one
1447 while-stepping element, and that the while-stepping's body
1448 has valid tracing commands excluding nested while-stepping.
1449 We also need to validate the tracepoint action line in the
1450 context of the tracepoint --- validate_actionline actually
1451 has side effects, like setting the tracepoint's
1452 while-stepping STEP_COUNT, in addition to checking if the
1453 collect/teval actions parse and make sense in the
1454 tracepoint's context. */
1455 for (c = commands; c; c = c->next)
1456 {
1458 {
1459 if (b->type == bp_fast_tracepoint)
1460 error (_("The 'while-stepping' command "
1461 "cannot be used for fast tracepoint"));
1462 else if (b->type == bp_static_tracepoint
1464 error (_("The 'while-stepping' command "
1465 "cannot be used for static tracepoint"));
1466
1467 if (while_stepping)
1468 error (_("The 'while-stepping' command "
1469 "can be used only once"));
1470 else
1471 while_stepping = c;
1472 }
1473
1474 validate_actionline (c->line, t);
1475 }
1476 if (while_stepping)
1477 {
1478 struct command_line *c2;
1479
1480 gdb_assert (while_stepping->body_list_1 == nullptr);
1481 c2 = while_stepping->body_list_0.get ();
1482 for (; c2; c2 = c2->next)
1483 {
1484 if (c2->control_type == while_stepping_control)
1485 error (_("The 'while-stepping' command cannot be nested"));
1486 }
1487 }
1488 }
1489 else
1490 {
1492 }
1493}
1494
1495/* Return a vector of all the static tracepoints set at ADDR. The
1496 caller is responsible for releasing the vector. */
1497
1498std::vector<breakpoint *>
1500{
1501 std::vector<breakpoint *> found;
1502
1503 for (breakpoint &b : all_breakpoints ())
1504 if (b.type == bp_static_tracepoint
1506 {
1507 for (bp_location &loc : b.locations ())
1508 if (loc.address == addr)
1509 found.push_back (&b);
1510 }
1511
1512 return found;
1513}
1514
1515/* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1516 validate that only allowed commands are included. */
1517
1518void
1520 counted_command_line &&commands)
1521{
1522 validate_commands_for_breakpoint (b, commands.get ());
1523
1524 b->commands = std::move (commands);
1526}
1527
1528/* Set the internal `silent' flag on the breakpoint. Note that this
1529 is not the same as the "silent" that may appear in the breakpoint's
1530 commands. */
1531
1532void
1533breakpoint_set_silent (struct breakpoint *b, int silent)
1534{
1535 int old_silent = b->silent;
1536
1537 b->silent = silent;
1538 if (old_silent != silent)
1540}
1541
1542/* See breakpoint.h. */
1543
1544void
1545breakpoint_set_thread (struct breakpoint *b, int thread)
1546{
1547 /* THREAD should be -1, meaning no thread restriction, or it should be a
1548 valid global thread-id, which are greater than zero. */
1549 gdb_assert (thread == -1 || thread > 0);
1550
1551 /* It is not valid to set a thread restriction for a breakpoint that
1552 already has task or inferior restriction. */
1553 gdb_assert (thread == -1 || (b->task == -1 && b->inferior == -1));
1554
1555 int old_thread = b->thread;
1556 b->thread = thread;
1557 if (old_thread != thread)
1559}
1560
1561/* See breakpoint.h. */
1562
1563void
1565{
1566 /* INFERIOR should be -1, meaning no inferior restriction, or it should
1567 be a valid inferior number, which are greater than zero. */
1568 gdb_assert (inferior == -1 || inferior > 0);
1569
1570 /* It is not valid to set an inferior restriction for a breakpoint that
1571 already has a task or thread restriction. */
1572 gdb_assert (inferior == -1 || (b->task == -1 && b->thread == -1));
1573
1574 int old_inferior = b->inferior;
1575 b->inferior = inferior;
1576 if (old_inferior != inferior)
1578}
1579
1580/* See breakpoint.h. */
1581
1582void
1583breakpoint_set_task (struct breakpoint *b, int task)
1584{
1585 /* TASK should be -1, meaning no task restriction, or it should be a
1586 valid task-id, which are greater than zero. */
1587 gdb_assert (task == -1 || task > 0);
1588
1589 /* It is not valid to set a task restriction for a breakpoint that
1590 already has a thread or inferior restriction. */
1591 gdb_assert (task == -1 || (b->thread == -1 && b->inferior == -1));
1592
1593 int old_task = b->task;
1594 b->task = task;
1595 if (old_task != task)
1597}
1598
1599static void
1600commands_command_1 (const char *arg, int from_tty,
1601 struct command_line *control)
1602{
1604 /* cmd_read will be true once we have read cmd. Note that cmd might still be
1605 NULL after the call to read_command_lines if the user provides an empty
1606 list of command by just typing "end". */
1607 bool cmd_read = false;
1608
1609 std::string new_arg;
1610
1611 if (arg == NULL || !*arg)
1612 {
1613 /* Argument not explicitly given. Synthesize it. */
1615 new_arg = string_printf ("%d-%d", prev_breakpoint_count + 1,
1617 else if (breakpoint_count > 0)
1618 new_arg = string_printf ("%d", breakpoint_count);
1619 }
1620 else
1621 {
1622 /* Create a copy of ARG. This is needed because the "commands"
1623 command may be coming from a script. In that case, the read
1624 line buffer is going to be overwritten in the lambda of
1625 'map_breakpoint_numbers' below when reading the next line
1626 before we are are done parsing the breakpoint numbers. */
1627 new_arg = arg;
1628 }
1629 arg = new_arg.c_str ();
1630
1632 (arg, [&] (breakpoint *b)
1633 {
1634 if (!cmd_read)
1635 {
1636 gdb_assert (cmd == NULL);
1637 if (control != NULL)
1638 cmd = control->body_list_0;
1639 else
1640 {
1641 std::string str
1642 = string_printf (_("Type commands for breakpoint(s) "
1643 "%s, one per line."),
1644 arg);
1645
1646 auto do_validate = [=] (const char *line)
1647 {
1648 tracepoint *t
1649 = gdb::checked_static_cast<tracepoint *> (b);
1651 };
1652 gdb::function_view<void (const char *)> validator;
1653 if (is_tracepoint (b))
1654 validator = do_validate;
1655
1656 cmd = read_command_lines (str.c_str (), from_tty, 1, validator);
1657 }
1658 cmd_read = true;
1659 }
1660
1661 /* If a breakpoint was on the list more than once, we don't need to
1662 do anything. */
1663 if (b->commands != cmd)
1664 {
1665 validate_commands_for_breakpoint (b, cmd.get ());
1666 b->commands = cmd;
1668 }
1669 });
1670}
1671
1672static void
1673commands_command (const char *arg, int from_tty)
1674{
1675 commands_command_1 (arg, from_tty, NULL);
1676}
1677
1678/* Like commands_command, but instead of reading the commands from
1679 input stream, takes them from an already parsed command structure.
1680
1681 This is used by cli-script.c to DTRT with breakpoint commands
1682 that are part of if and while bodies. */
1684commands_from_control_command (const char *arg, struct command_line *cmd)
1685{
1686 commands_command_1 (arg, 0, cmd);
1687 return simple_control;
1688}
1689
1690/* Return true if BL->TARGET_INFO contains valid information. */
1691
1692static bool
1694{
1696 return false;
1697 if (!bl->inserted)
1698 return false;
1699 if (bl->target_info.shadow_len == 0)
1700 /* BL isn't valid, or doesn't shadow memory. */
1701 return false;
1702 return true;
1703}
1704
1705/* Update BUF, which is LEN bytes read from the target address
1706 MEMADDR, by replacing a memory breakpoint with its shadowed
1707 contents.
1708
1709 If READBUF is not NULL, this buffer must not overlap with the of
1710 the breakpoint location's shadow_contents buffer. Otherwise, a
1711 failed assertion internal error will be raised. */
1712
1713static void
1714one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf,
1715 const gdb_byte *writebuf_org,
1716 ULONGEST memaddr, LONGEST len,
1718 struct gdbarch *gdbarch)
1719{
1720 /* Now do full processing of the found relevant range of elements. */
1721 CORE_ADDR bp_addr = 0;
1722 int bp_size = 0;
1723 int bptoffset = 0;
1724
1725 if (!breakpoint_address_match (target_info->placed_address_space, 0,
1727 {
1728 /* The breakpoint is inserted in a different address space. */
1729 return;
1730 }
1731
1732 /* Addresses and length of the part of the breakpoint that
1733 we need to copy. */
1734 bp_addr = target_info->placed_address;
1735 bp_size = target_info->shadow_len;
1736
1737 if (bp_addr + bp_size <= memaddr)
1738 {
1739 /* The breakpoint is entirely before the chunk of memory we are
1740 reading. */
1741 return;
1742 }
1743
1744 if (bp_addr >= memaddr + len)
1745 {
1746 /* The breakpoint is entirely after the chunk of memory we are
1747 reading. */
1748 return;
1749 }
1750
1751 /* Offset within shadow_contents. */
1752 if (bp_addr < memaddr)
1753 {
1754 /* Only copy the second part of the breakpoint. */
1755 bp_size -= memaddr - bp_addr;
1756 bptoffset = memaddr - bp_addr;
1757 bp_addr = memaddr;
1758 }
1759
1760 if (bp_addr + bp_size > memaddr + len)
1761 {
1762 /* Only copy the first part of the breakpoint. */
1763 bp_size -= (bp_addr + bp_size) - (memaddr + len);
1764 }
1765
1766 if (readbuf != NULL)
1767 {
1768 /* Verify that the readbuf buffer does not overlap with the
1769 shadow_contents buffer. */
1770 gdb_assert (target_info->shadow_contents >= readbuf + len
1771 || readbuf >= (target_info->shadow_contents
1772 + target_info->shadow_len));
1773
1774 /* Update the read buffer with this inserted breakpoint's
1775 shadow. */
1776 memcpy (readbuf + bp_addr - memaddr,
1777 target_info->shadow_contents + bptoffset, bp_size);
1778 }
1779 else
1780 {
1781 const unsigned char *bp;
1782 CORE_ADDR addr = target_info->reqstd_address;
1783 int placed_size;
1784
1785 /* Update the shadow with what we want to write to memory. */
1786 memcpy (target_info->shadow_contents + bptoffset,
1787 writebuf_org + bp_addr - memaddr, bp_size);
1788
1789 /* Determine appropriate breakpoint contents and size for this
1790 address. */
1791 bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &placed_size);
1792
1793 /* Update the final write buffer with this inserted
1794 breakpoint's INSN. */
1795 memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size);
1796 }
1797}
1798
1799/* Update BUF, which is LEN bytes read from the target address MEMADDR,
1800 by replacing any memory breakpoints with their shadowed contents.
1801
1802 If READBUF is not NULL, this buffer must not overlap with any of
1803 the breakpoint location's shadow_contents buffers. Otherwise,
1804 a failed assertion internal error will be raised.
1805
1806 The range of shadowed area by each bp_location is:
1807 bl->address - bp_locations_placed_address_before_address_max
1808 up to bl->address + bp_locations_shadow_len_after_address_max
1809 The range we were requested to resolve shadows for is:
1810 memaddr ... memaddr + len
1811 Thus the safe cutoff boundaries for performance optimization are
1812 memaddr + len <= (bl->address
1813 - bp_locations_placed_address_before_address_max)
1814 and:
1815 bl->address + bp_locations_shadow_len_after_address_max <= memaddr */
1816
1817void
1818breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf,
1819 const gdb_byte *writebuf_org,
1820 ULONGEST memaddr, LONGEST len)
1821{
1822 /* Left boundary, right boundary and median element of our binary
1823 search. */
1824 unsigned bc_l, bc_r, bc;
1825
1826 /* Find BC_L which is a leftmost element which may affect BUF
1827 content. It is safe to report lower value but a failure to
1828 report higher one. */
1829
1830 bc_l = 0;
1831 bc_r = bp_locations.size ();
1832 while (bc_l + 1 < bc_r)
1833 {
1834 struct bp_location *bl;
1835
1836 bc = (bc_l + bc_r) / 2;
1837 bl = bp_locations[bc];
1838
1839 /* Check first BL->ADDRESS will not overflow due to the added
1840 constant. Then advance the left boundary only if we are sure
1841 the BC element can in no way affect the BUF content (MEMADDR
1842 to MEMADDR + LEN range).
1843
1844 Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1845 offset so that we cannot miss a breakpoint with its shadow
1846 range tail still reaching MEMADDR. */
1847
1849 >= bl->address)
1851 <= memaddr))
1852 bc_l = bc;
1853 else
1854 bc_r = bc;
1855 }
1856
1857 /* Due to the binary search above, we need to make sure we pick the
1858 first location that's at BC_L's address. E.g., if there are
1859 multiple locations at the same address, BC_L may end up pointing
1860 at a duplicate location, and miss the "master"/"inserted"
1861 location. Say, given locations L1, L2 and L3 at addresses A and
1862 B:
1863
1864 L1@A, L2@A, L3@B, ...
1865
1866 BC_L could end up pointing at location L2, while the "master"
1867 location could be L1. Since the `loc->inserted' flag is only set
1868 on "master" locations, we'd forget to restore the shadow of L1
1869 and L2. */
1870 while (bc_l > 0
1871 && bp_locations[bc_l]->address == bp_locations[bc_l - 1]->address)
1872 bc_l--;
1873
1874 /* Now do full processing of the found relevant range of elements. */
1875
1876 for (bc = bc_l; bc < bp_locations.size (); bc++)
1877 {
1878 struct bp_location *bl = bp_locations[bc];
1879
1880 /* bp_location array has BL->OWNER always non-NULL. */
1881 if (bl->owner->type == bp_none)
1882 warning (_("reading through apparently deleted breakpoint #%d?"),
1883 bl->owner->number);
1884
1885 /* Performance optimization: any further element can no longer affect BUF
1886 content. */
1887
1889 && (memaddr + len
1890 <= (bl->address
1892 break;
1893
1894 if (!bp_location_has_shadow (bl))
1895 continue;
1896
1897 one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org,
1898 memaddr, len, &bl->target_info, bl->gdbarch);
1899 }
1900}
1901
1902/* See breakpoint.h. */
1903
1904bool
1905is_breakpoint (const struct breakpoint *bpt)
1906{
1907 return (bpt->type == bp_breakpoint
1908 || bpt->type == bp_hardware_breakpoint
1909 || bpt->type == bp_dprintf);
1910}
1911
1912/* Return true if BPT is of any hardware watchpoint kind. */
1913
1914static bool
1916{
1917 return (bpt->type == bp_hardware_watchpoint
1918 || bpt->type == bp_read_watchpoint
1919 || bpt->type == bp_access_watchpoint);
1920}
1921
1922/* See breakpoint.h. */
1923
1924bool
1925is_watchpoint (const struct breakpoint *bpt)
1926{
1927 return (is_hardware_watchpoint (bpt)
1928 || bpt->type == bp_watchpoint);
1929}
1930
1931/* Returns true if the current thread and its running state are safe
1932 to evaluate or update watchpoint B. Watchpoints on local
1933 expressions need to be evaluated in the context of the thread that
1934 was current when the watchpoint was created, and, that thread needs
1935 to be stopped to be able to select the correct frame context.
1936 Watchpoints on global expressions can be evaluated on any thread,
1937 and in any state. It is presently left to the target allowing
1938 memory accesses when threads are running. */
1939
1940static bool
1942{
1943 return (b->pspace == current_program_space
1944 && (b->watchpoint_thread == null_ptid
1946 && !inferior_thread ()->executing ())));
1947}
1948
1949/* Set watchpoint B to disp_del_at_next_stop, even including its possible
1950 associated bp_watchpoint_scope breakpoint. */
1951
1952static void
1966
1967/* Extract a bitfield value from value VAL using the bit parameters contained in
1968 watchpoint W. */
1969
1970static struct value *
1972{
1973 struct value *bit_val;
1974
1975 if (val == NULL)
1976 return NULL;
1977
1978 bit_val = value::allocate (val->type ());
1979
1980 val->unpack_bitfield (bit_val,
1981 w->val_bitpos,
1982 w->val_bitsize,
1983 val->contents_for_printing ().data (),
1984 val->offset ());
1985
1986 return bit_val;
1987}
1988
1989/* Allocate a dummy location and add it to B. This is required
1990 because bpstat_stop_status requires a location to be able to report
1991 stops. */
1992
1993static void
1995 struct program_space *pspace)
1996{
1997 gdb_assert (!b->has_locations ());
1998
2000 loc->pspace = pspace;
2001 b->add_location (*loc);
2002}
2003
2004/* Assuming that B is a watchpoint:
2005 - Reparse watchpoint expression, if REPARSE is true
2006 - Evaluate expression and store the result in B->val
2007 - Evaluate the condition if there is one, and store the result
2008 in b->loc->cond.
2009 - Update the list of values that must be watched in B->loc.
2010
2011 If the watchpoint disposition is disp_del_at_next_stop, then do
2012 nothing. If this is local watchpoint that is out of scope, delete
2013 it.
2014
2015 Even with `set breakpoint always-inserted on' the watchpoints are
2016 removed + inserted on each stop here. Normal breakpoints must
2017 never be removed because they might be missed by a running thread
2018 when debugging in non-stop mode. On the other hand, hardware
2019 watchpoints (is_hardware_watchpoint; processed here) are specific
2020 to each LWP since they are stored in each LWP's hardware debug
2021 registers. Therefore, such LWP must be stopped first in order to
2022 be able to modify its hardware watchpoints.
2023
2024 Hardware watchpoints must be reset exactly once after being
2025 presented to the user. It cannot be done sooner, because it would
2026 reset the data used to present the watchpoint hit to the user. And
2027 it must not be done later because it could display the same single
2028 watchpoint hit during multiple GDB stops. Note that the latter is
2029 relevant only to the hardware watchpoint types bp_read_watchpoint
2030 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
2031 not user-visible - its hit is suppressed if the memory content has
2032 not changed.
2033
2034 The following constraints influence the location where we can reset
2035 hardware watchpoints:
2036
2037 * target_stopped_by_watchpoint and target_stopped_data_address are
2038 called several times when GDB stops.
2039
2040 [linux]
2041 * Multiple hardware watchpoints can be hit at the same time,
2042 causing GDB to stop. GDB only presents one hardware watchpoint
2043 hit at a time as the reason for stopping, and all the other hits
2044 are presented later, one after the other, each time the user
2045 requests the execution to be resumed. Execution is not resumed
2046 for the threads still having pending hit event stored in
2047 LWP_INFO->STATUS. While the watchpoint is already removed from
2048 the inferior on the first stop the thread hit event is kept being
2049 reported from its cached value by linux_nat_stopped_data_address
2050 until the real thread resume happens after the watchpoint gets
2051 presented and thus its LWP_INFO->STATUS gets reset.
2052
2053 Therefore the hardware watchpoint hit can get safely reset on the
2054 watchpoint removal from inferior. */
2055
2056static void
2057update_watchpoint (struct watchpoint *b, bool reparse)
2058{
2059 bool within_current_scope;
2060
2061 /* If this is a local watchpoint, we only want to check if the
2062 watchpoint frame is in scope if the current thread is the thread
2063 that was used to create the watchpoint. */
2065 return;
2066
2068 return;
2069
2070 gdb::optional<scoped_restore_selected_frame> restore_frame;
2071
2072 /* Determine if the watchpoint is within scope. */
2073 if (b->exp_valid_block == NULL)
2074 within_current_scope = true;
2075 else
2076 {
2078 struct gdbarch *frame_arch = get_frame_arch (fi);
2079 CORE_ADDR frame_pc = get_frame_pc (fi);
2080
2081 /* If we're at a point where the stack has been destroyed
2082 (e.g. in a function epilogue), unwinding may not work
2083 properly. Do not attempt to recreate locations at this
2084 point. See similar comments in watchpoint_check. */
2085 if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc))
2086 return;
2087
2088 /* Save the current frame's ID so we can restore it after
2089 evaluating the watchpoint expression on its own frame. */
2090 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
2091 took a frame parameter, so that we didn't have to change the
2092 selected frame. */
2093 restore_frame.emplace ();
2094
2096 within_current_scope = (fi != NULL);
2097 if (within_current_scope)
2098 select_frame (fi);
2099 }
2100
2101 /* We don't free locations. They are stored in the bp_location array
2102 and update_global_location_list will eventually delete them and
2103 remove breakpoints if needed. */
2104 b->clear_locations ();
2105
2106 if (within_current_scope && reparse)
2107 {
2108 const char *s;
2109
2110 b->exp.reset ();
2111 s = (b->exp_string_reparse
2112 ? b->exp_string_reparse.get ()
2113 : b->exp_string.get ());
2114 b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0);
2115 /* If the meaning of expression itself changed, the old value is
2116 no longer relevant. We don't want to report a watchpoint hit
2117 to the user when the old value and the new value may actually
2118 be completely different objects. */
2119 b->val = NULL;
2120 b->val_valid = false;
2121
2122 /* Note that unlike with breakpoints, the watchpoint's condition
2123 expression is stored in the breakpoint object, not in the
2124 locations (re)created below. */
2125 if (b->cond_string != NULL)
2126 {
2127 b->cond_exp.reset ();
2128
2129 s = b->cond_string.get ();
2130 b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0);
2131 }
2132 }
2133
2134 /* If we failed to parse the expression, for example because
2135 it refers to a global variable in a not-yet-loaded shared library,
2136 don't try to insert watchpoint. We don't automatically delete
2137 such watchpoint, though, since failure to parse expression
2138 is different from out-of-scope watchpoint. */
2139 if (!target_has_execution ())
2140 {
2141 /* Without execution, memory can't change. No use to try and
2142 set watchpoint locations. The watchpoint will be reset when
2143 the target gains execution, through breakpoint_re_set. */
2145 {
2146 if (b->works_in_software_mode ())
2147 b->type = bp_watchpoint;
2148 else
2149 error (_("Can't set read/access watchpoint when "
2150 "hardware watchpoints are disabled."));
2151 }
2152 }
2153 else if (within_current_scope && b->exp)
2154 {
2155 std::vector<value_ref_ptr> val_chain;
2156 struct value *v, *result;
2157 struct program_space *frame_pspace;
2158
2159 fetch_subexp_value (b->exp.get (), b->exp->op.get (), &v, &result,
2160 &val_chain, false);
2161
2162 /* Avoid setting b->val if it's already set. The meaning of
2163 b->val is 'the last value' user saw, and we should update
2164 it only if we reported that last value to user. As it
2165 happens, the code that reports it updates b->val directly.
2166 We don't keep track of the memory value for masked
2167 watchpoints. */
2168 if (!b->val_valid && !is_masked_watchpoint (b))
2169 {
2170 if (b->val_bitsize != 0)
2172 b->val = release_value (v);
2173 b->val_valid = true;
2174 }
2175
2176 frame_pspace = get_frame_program_space (get_selected_frame (NULL));
2177
2178 /* Look at each value on the value chain. */
2179 gdb_assert (!val_chain.empty ());
2180 for (const value_ref_ptr &iter : val_chain)
2181 {
2182 v = iter.get ();
2183
2184 /* If it's a memory location, and GDB actually needed
2185 its contents to evaluate the expression, then we
2186 must watch it. If the first value returned is
2187 still lazy, that means an error occurred reading it;
2188 watch it anyway in case it becomes readable. */
2189 if (v->lval () == lval_memory
2190 && (v == val_chain[0] || ! v->lazy ()))
2191 {
2192 struct type *vtype = check_typedef (v->type ());
2193
2194 /* We only watch structs and arrays if user asked
2195 for it explicitly, never if they just happen to
2196 appear in the middle of some value chain. */
2197 if (v == result
2198 || (vtype->code () != TYPE_CODE_STRUCT
2199 && vtype->code () != TYPE_CODE_ARRAY))
2200 {
2201 CORE_ADDR addr;
2202 enum target_hw_bp_type type;
2203 int bitpos = 0, bitsize = 0;
2204
2205 if (v->bitsize () != 0)
2206 {
2207 /* Extract the bit parameters out from the bitfield
2208 sub-expression. */
2209 bitpos = v->bitpos ();
2210 bitsize = v->bitsize ();
2211 }
2212 else if (v == result && b->val_bitsize != 0)
2213 {
2214 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
2215 lvalue whose bit parameters are saved in the fields
2216 VAL_BITPOS and VAL_BITSIZE. */
2217 bitpos = b->val_bitpos;
2218 bitsize = b->val_bitsize;
2219 }
2220
2221 addr = v->address ();
2222 if (bitsize != 0)
2223 {
2224 /* Skip the bytes that don't contain the bitfield. */
2225 addr += bitpos / 8;
2226 }
2227
2228 type = hw_write;
2229 if (b->type == bp_read_watchpoint)
2230 type = hw_read;
2231 else if (b->type == bp_access_watchpoint)
2232 type = hw_access;
2233
2235 loc->gdbarch = v->type ()->arch ();
2236 loc->pspace = frame_pspace;
2237 loc->address
2238 = gdbarch_remove_non_address_bits (loc->gdbarch, addr);
2239 b->add_location (*loc);
2240
2241 if (bitsize != 0)
2242 {
2243 /* Just cover the bytes that make up the bitfield. */
2244 loc->length = ((bitpos % 8) + bitsize + 7) / 8;
2245 }
2246 else
2247 loc->length = v->type ()->length ();
2248
2249 loc->watchpoint_type = type;
2250 }
2251 }
2252 }
2253
2254 /* Helper function to bundle possibly emitting a warning along with
2255 changing the type of B to bp_watchpoint. */
2256 auto change_type_to_bp_watchpoint = [] (breakpoint *bp)
2257 {
2258 /* Only warn for breakpoints that have been assigned a +ve number,
2259 anything else is either an internal watchpoint (which we don't
2260 currently create) or has not yet been finalized, in which case
2261 this change of type will be occurring before the user is told
2262 the type of this watchpoint. */
2263 if (bp->type == bp_hardware_watchpoint && bp->number > 0)
2264 warning (_("watchpoint %d downgraded to software watchpoint"),
2265 bp->number);
2266 bp->type = bp_watchpoint;
2267 };
2268
2269 /* Change the type of breakpoint between hardware assisted or
2270 an ordinary watchpoint depending on the hardware support and
2271 free hardware slots. Recheck the number of free hardware slots
2272 as the value chain may have changed. */
2273 {
2274 int reg_cnt;
2275 enum bp_loc_type loc_type;
2276
2277 reg_cnt = can_use_hardware_watchpoint (val_chain);
2278
2279 if (reg_cnt)
2280 {
2281 int i, target_resources_ok, other_type_used;
2282 enum bptype type;
2283
2284 /* Use an exact watchpoint when there's only one memory region to be
2285 watched, and only one debug register is needed to watch it. */
2286 b->exact = target_exact_watchpoints && reg_cnt == 1;
2287
2288 /* We need to determine how many resources are already
2289 used for all other hardware watchpoints plus this one
2290 to see if we still have enough resources to also fit
2291 this watchpoint in as well. */
2292
2293 /* If this is a software watchpoint, we try to turn it
2294 to a hardware one -- count resources as if B was of
2295 hardware watchpoint type. */
2296 type = b->type;
2297 if (type == bp_watchpoint)
2299
2300 /* This watchpoint may or may not have been placed on
2301 the list yet at this point (it won't be in the list
2302 if we're trying to create it for the first time,
2303 through watch_command), so always account for it
2304 manually. */
2305
2306 /* Count resources used by all watchpoints except B. */
2307 i = hw_watchpoint_used_count_others (b, type, &other_type_used);
2308
2309 /* Add in the resources needed for B. */
2310 i += hw_watchpoint_use_count (b);
2311
2312 target_resources_ok
2313 = target_can_use_hardware_watchpoint (type, i, other_type_used);
2314 if (target_resources_ok <= 0)
2315 {
2316 bool sw_mode = b->works_in_software_mode ();
2317
2318 if (target_resources_ok == 0 && !sw_mode)
2319 error (_("Target does not support this type of "
2320 "hardware watchpoint."));
2321 else if (target_resources_ok < 0 && !sw_mode)
2322 error (_("There are not enough available hardware "
2323 "resources for this watchpoint."));
2324
2325 /* Downgrade to software watchpoint. */
2326 change_type_to_bp_watchpoint (b);
2327 }
2328 else
2329 {
2330 /* If this was a software watchpoint, we've just
2331 found we have enough resources to turn it to a
2332 hardware watchpoint. Otherwise, this is a
2333 nop. */
2334 b->type = type;
2335 }
2336 }
2337 else if (!b->works_in_software_mode ())
2338 {
2340 error (_("Can't set read/access watchpoint when "
2341 "hardware watchpoints are disabled."));
2342 else
2343 error (_("Expression cannot be implemented with "
2344 "read/access watchpoint."));
2345 }
2346 else
2347 change_type_to_bp_watchpoint (b);
2348
2351
2352 for (bp_location &bl : b->locations ())
2353 bl.loc_type = loc_type;
2354 }
2355
2356 /* If a software watchpoint is not watching any memory, then the
2357 above left it without any location set up. But,
2358 bpstat_stop_status requires a location to be able to report
2359 stops, so make sure there's at least a dummy one. */
2360 if (b->type == bp_watchpoint && !b->has_locations ())
2361 add_dummy_location (b, frame_pspace);
2362 }
2363 else if (!within_current_scope)
2364 {
2365 gdb_printf (_("\
2366Watchpoint %d deleted because the program has left the block\n\
2367in which its expression is valid.\n"),
2368 b->number);
2370 }
2371}
2372
2373/* Returns true iff breakpoint location should be
2374 inserted in the inferior. We don't differentiate the type of BL's owner
2375 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2376 breakpoint_ops is not defined, because in insert_bp_location,
2377 tracepoint's insert_location will not be called. */
2378
2379static bool
2381{
2382 if (bl->owner == NULL || !breakpoint_enabled (bl->owner))
2383 return false;
2384
2386 return false;
2387
2388 if (!bl->enabled || bl->disabled_by_cond
2389 || bl->shlib_disabled || bl->duplicate)
2390 return false;
2391
2393 return false;
2394
2395 /* This is set for example, when we're attached to the parent of a
2396 vfork, and have detached from the child. The child is running
2397 free, and we expect it to do an exec or exit, at which point the
2398 OS makes the parent schedulable again (and the target reports
2399 that the vfork is done). Until the child is done with the shared
2400 memory region, do not insert breakpoints in the parent, otherwise
2401 the child could still trip on the parent's breakpoints. Since
2402 the parent is blocked anyway, it won't miss any breakpoint. */
2404 return false;
2405
2406 /* Don't insert a breakpoint if we're trying to step past its
2407 location, except if the breakpoint is a single-step breakpoint,
2408 and the breakpoint's thread is the thread which is stepping past
2409 a breakpoint. */
2413 bl->address)
2414 /* The single-step breakpoint may be inserted at the location
2415 we're trying to step if the instruction branches to itself.
2416 However, the instruction won't be executed at all and it may
2417 break the semantics of the instruction, for example, the
2418 instruction is a conditional branch or updates some flags.
2419 We can't fix it unless GDB is able to emulate the instruction
2420 or switch to displaced stepping. */
2421 && !(bl->owner->type == bp_single_step
2423 {
2424 infrun_debug_printf ("skipping breakpoint: stepping past insn at: %s",
2425 paddress (bl->gdbarch, bl->address));
2426 return false;
2427 }
2428
2429 /* Don't insert watchpoints if we're trying to step past the
2430 instruction that triggered one. */
2433 {
2434 infrun_debug_printf ("stepping past non-steppable watchpoint. "
2435 "skipping watchpoint at %s:%d",
2436 paddress (bl->gdbarch, bl->address), bl->length);
2437 return false;
2438 }
2439
2440 return true;
2441}
2442
2443/* Same as should_be_inserted but does the check assuming
2444 that the location is not duplicated. */
2445
2446static bool
2448{
2449 scoped_restore restore_bl_duplicate
2450 = make_scoped_restore (&bl->duplicate, 0);
2451
2452 return should_be_inserted (bl);
2453}
2454
2455/* Parses a conditional described by an expression COND into an
2456 agent expression bytecode suitable for evaluation
2457 by the bytecode interpreter. Return NULL if there was
2458 any error during parsing. */
2459
2460static agent_expr_up
2461parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond)
2462{
2463 if (cond == NULL)
2464 return NULL;
2465
2466 agent_expr_up aexpr;
2467
2468 /* We don't want to stop processing, so catch any errors
2469 that may show up. */
2470 try
2471 {
2472 aexpr = gen_eval_for_expr (scope, cond);
2473 }
2474
2475 catch (const gdb_exception_error &ex)
2476 {
2477 /* If we got here, it means the condition could not be parsed to a valid
2478 bytecode expression and thus can't be evaluated on the target's side.
2479 It's no use iterating through the conditions. */
2480 }
2481
2482 /* We have a valid agent expression. */
2483 return aexpr;
2484}
2485
2486/* Based on location BL, create a list of breakpoint conditions to be
2487 passed on to the target. If we have duplicated locations with different
2488 conditions, we will add such conditions to the list. The idea is that the
2489 target will evaluate the list of conditions and will only notify GDB when
2490 one of them is true. */
2491
2492static void
2494{
2495 bool null_condition_or_parse_error = false;
2496 int modified = bl->needs_update;
2497
2498 /* Release conditions left over from a previous insert. */
2499 bl->target_info.conditions.clear ();
2500
2501 /* This is only meaningful if the target is
2502 evaluating conditions and if the user has
2503 opted for condition evaluation on the target's
2504 side. */
2507 return;
2508
2509 auto loc_range = all_bp_locations_at_addr (bl->address);
2510
2511 /* Do a first pass to check for locations with no assigned
2512 conditions or conditions that fail to parse to a valid agent
2513 expression bytecode. If any of these happen, then it's no use to
2514 send conditions to the target since this location will always
2515 trigger and generate a response back to GDB. Note we consider
2516 all locations at the same address irrespective of type, i.e.,
2517 even if the locations aren't considered duplicates (e.g.,
2518 software breakpoint and hardware breakpoint at the same
2519 address). */
2520 for (bp_location *loc : loc_range)
2521 {
2522 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2523 {
2524 if (modified)
2525 {
2526 /* Re-parse the conditions since something changed. In that
2527 case we already freed the condition bytecodes (see
2528 force_breakpoint_reinsertion). We just
2529 need to parse the condition to bytecodes again. */
2530 loc->cond_bytecode = parse_cond_to_aexpr (bl->address,
2531 loc->cond.get ());
2532 }
2533
2534 /* If we have a NULL bytecode expression, it means something
2535 went wrong or we have a null condition expression. */
2536 if (!loc->cond_bytecode)
2537 {
2538 null_condition_or_parse_error = true;
2539 break;
2540 }
2541 }
2542 }
2543
2544 /* If any of these happened, it means we will have to evaluate the conditions
2545 for the location's address on gdb's side. It is no use keeping bytecodes
2546 for all the other duplicate locations, thus we free all of them here.
2547
2548 This is so we have a finer control over which locations' conditions are
2549 being evaluated by GDB or the remote stub. */
2550 if (null_condition_or_parse_error)
2551 {
2552 for (bp_location *loc : loc_range)
2553 {
2554 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2555 {
2556 /* Only go as far as the first NULL bytecode is
2557 located. */
2558 if (!loc->cond_bytecode)
2559 return;
2560
2561 loc->cond_bytecode.reset ();
2562 }
2563 }
2564 }
2565
2566 /* No NULL conditions or failed bytecode generation. Build a
2567 condition list for this location's address. If we have software
2568 and hardware locations at the same address, they aren't
2569 considered duplicates, but we still merge all the conditions
2570 anyway, as it's simpler, and doesn't really make a practical
2571 difference. */
2572 for (bp_location *loc : loc_range)
2573 if (loc->cond
2574 && is_breakpoint (loc->owner)
2575 && loc->pspace->num == bl->pspace->num
2576 && loc->owner->enable_state == bp_enabled
2577 && loc->enabled
2578 && !loc->disabled_by_cond)
2579 {
2580 /* Add the condition to the vector. This will be used later
2581 to send the conditions to the target. */
2582 bl->target_info.conditions.push_back (loc->cond_bytecode.get ());
2583 }
2584
2585 return;
2586}
2587
2588/* Parses a command described by string CMD into an agent expression
2589 bytecode suitable for evaluation by the bytecode interpreter.
2590 Return NULL if there was any error during parsing. */
2591
2592static agent_expr_up
2593parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd)
2594{
2595 const char *cmdrest;
2596 const char *format_start, *format_end;
2597 struct gdbarch *gdbarch = get_current_arch ();
2598
2599 if (cmd == NULL)
2600 return NULL;
2601
2602 cmdrest = cmd;
2603
2604 if (*cmdrest == ',')
2605 ++cmdrest;
2606 cmdrest = skip_spaces (cmdrest);
2607
2608 if (*cmdrest++ != '"')
2609 error (_("No format string following the location"));
2610
2611 format_start = cmdrest;
2612
2613 format_pieces fpieces (&cmdrest);
2614
2615 format_end = cmdrest;
2616
2617 if (*cmdrest++ != '"')
2618 error (_("Bad format string, non-terminated '\"'."));
2619
2620 cmdrest = skip_spaces (cmdrest);
2621
2622 if (!(*cmdrest == ',' || *cmdrest == '\0'))
2623 error (_("Invalid argument syntax"));
2624
2625 if (*cmdrest == ',')
2626 cmdrest++;
2627 cmdrest = skip_spaces (cmdrest);
2628
2629 /* For each argument, make an expression. */
2630
2631 std::vector<struct expression *> argvec;
2632 while (*cmdrest != '\0')
2633 {
2634 const char *cmd1;
2635
2636 cmd1 = cmdrest;
2637 expression_up expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope),
2639 argvec.push_back (expr.release ());
2640 cmdrest = cmd1;
2641 if (*cmdrest == ',')
2642 ++cmdrest;
2643 }
2644
2645 agent_expr_up aexpr;
2646
2647 /* We don't want to stop processing, so catch any errors
2648 that may show up. */
2649 try
2650 {
2651 aexpr = gen_printf (scope, gdbarch, 0, 0,
2652 format_start, format_end - format_start,
2653 argvec.size (), argvec.data ());
2654 }
2655 catch (const gdb_exception_error &ex)
2656 {
2657 /* If we got here, it means the command could not be parsed to a valid
2658 bytecode expression and thus can't be evaluated on the target's side.
2659 It's no use iterating through the other commands. */
2660 }
2661
2662 /* We have a valid agent expression, return it. */
2663 return aexpr;
2664}
2665
2666/* Based on location BL, create a list of breakpoint commands to be
2667 passed on to the target. If we have duplicated locations with
2668 different commands, we will add any such to the list. */
2669
2670static void
2672{
2673 bool null_command_or_parse_error = false;
2674 int modified = bl->needs_update;
2675
2676 /* Clear commands left over from a previous insert. */
2677 bl->target_info.tcommands.clear ();
2678
2680 return;
2681
2682 /* For now, limit to agent-style dprintf breakpoints. */
2684 return;
2685
2686 auto loc_range = all_bp_locations_at_addr (bl->address);
2687
2688 /* For now, if we have any location at the same address that isn't a
2689 dprintf, don't install the target-side commands, as that would
2690 make the breakpoint not be reported to the core, and we'd lose
2691 control. */
2692 for (bp_location *loc : loc_range)
2693 if (is_breakpoint (loc->owner)
2694 && loc->pspace->num == bl->pspace->num
2695 && loc->owner->type != bp_dprintf)
2696 return;
2697
2698 /* Do a first pass to check for locations with no assigned
2699 conditions or conditions that fail to parse to a valid agent expression
2700 bytecode. If any of these happen, then it's no use to send conditions
2701 to the target since this location will always trigger and generate a
2702 response back to GDB. */
2703 for (bp_location *loc : loc_range)
2704 {
2705 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2706 {
2707 if (modified)
2708 {
2709 /* Re-parse the commands since something changed. In that
2710 case we already freed the command bytecodes (see
2711 force_breakpoint_reinsertion). We just
2712 need to parse the command to bytecodes again. */
2713 loc->cmd_bytecode
2715 loc->owner->extra_string.get ());
2716 }
2717
2718 /* If we have a NULL bytecode expression, it means something
2719 went wrong or we have a null command expression. */
2720 if (!loc->cmd_bytecode)
2721 {
2722 null_command_or_parse_error = true;
2723 break;
2724 }
2725 }
2726 }
2727
2728 /* If anything failed, then we're not doing target-side commands,
2729 and so clean up. */
2730 if (null_command_or_parse_error)
2731 {
2732 for (bp_location *loc : loc_range)
2733 if (is_breakpoint (loc->owner)
2734 && loc->pspace->num == bl->pspace->num)
2735 {
2736 /* Only go as far as the first NULL bytecode is
2737 located. */
2738 if (loc->cmd_bytecode == NULL)
2739 return;
2740
2741 loc->cmd_bytecode.reset ();
2742 }
2743 }
2744
2745 /* No NULL commands or failed bytecode generation. Build a command
2746 list for all duplicate locations at this location's address.
2747 Note that here we must care for whether the breakpoint location
2748 types are considered duplicates, otherwise, say, if we have a
2749 software and hardware location at the same address, the target
2750 could end up running the commands twice. For the moment, we only
2751 support targets-side commands with dprintf, but it doesn't hurt
2752 to be pedantically correct in case that changes. */
2753 for (bp_location *loc : loc_range)
2755 && loc->owner->extra_string
2756 && is_breakpoint (loc->owner)
2757 && loc->pspace->num == bl->pspace->num
2758 && loc->owner->enable_state == bp_enabled
2759 && loc->enabled
2760 && !loc->disabled_by_cond)
2761 {
2762 /* Add the command to the vector. This will be used later
2763 to send the commands to the target. */
2764 bl->target_info.tcommands.push_back (loc->cmd_bytecode.get ());
2765 }
2766
2767 bl->target_info.persist = 0;
2768 /* Maybe flag this location as persistent. */
2770 bl->target_info.persist = 1;
2771}
2772
2773/* Return the kind of breakpoint on address *ADDR. Get the kind
2774 of breakpoint according to ADDR except single-step breakpoint.
2775 Get the kind of single-step breakpoint according to the current
2776 registers state. */
2777
2778static int
2779breakpoint_kind (const struct bp_location *bl, CORE_ADDR *addr)
2780{
2781 if (bl->owner->type == bp_single_step)
2782 {
2783 struct thread_info *thr = find_thread_global_id (bl->owner->thread);
2784 struct regcache *regcache;
2785
2787
2789 regcache, addr);
2790 }
2791 else
2792 return gdbarch_breakpoint_kind_from_pc (bl->gdbarch, addr);
2793}
2794
2795/* Rethrow the currently handled exception, if it's a TARGET_CLOSE_ERROR.
2796 E is either the currently handled exception, or a copy, or a sliced copy,
2797 so we can't rethrow that one, but we can use it to inspect the properties
2798 of the currently handled exception. */
2799
2800static void
2801rethrow_on_target_close_error (const gdb_exception &e)
2802{
2803 if (e.reason == 0)
2804 return;
2805 /* Can't set the breakpoint. */
2806
2807 if (e.error != TARGET_CLOSE_ERROR)
2808 return;
2809
2810 /* If the target has closed then it will have deleted any breakpoints
2811 inserted within the target inferior, as a result any further attempts
2812 to interact with the breakpoint objects is not possible. Just rethrow
2813 the error. Don't use e to rethrow, to prevent object slicing of the
2814 exception. */
2815 throw;
2816}
2817
2818/* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2819 location. Any error messages are printed to TMP_ERROR_STREAM; and
2820 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2821 Returns 0 for success, 1 if the bp_location type is not supported or
2822 -1 for failure.
2823
2824 NOTE drow/2003-09-09: This routine could be broken down to an
2825 object-style method for each breakpoint or catchpoint type. */
2826static int
2828 struct ui_file *tmp_error_stream,
2829 int *disabled_breaks,
2830 int *hw_breakpoint_error,
2831 int *hw_bp_error_explained_already)
2832{
2833 gdb_exception bp_excpt;
2834
2835 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
2836 return 0;
2837
2839
2840 /* Note we don't initialize bl->target_info, as that wipes out
2841 the breakpoint location's shadow_contents if the breakpoint
2842 is still inserted at that location. This in turn breaks
2843 target_read_memory which depends on these buffers when
2844 a memory read is requested at the breakpoint location:
2845 Once the target_info has been wiped, we fail to see that
2846 we have a breakpoint inserted at that address and thus
2847 read the breakpoint instead of returning the data saved in
2848 the breakpoint location's shadow contents. */
2851 bl->target_info.length = bl->length;
2852
2853 /* When working with target-side conditions, we must pass all the conditions
2854 for the same breakpoint address down to the target since GDB will not
2855 insert those locations. With a list of breakpoint conditions, the target
2856 can decide when to stop and notify GDB. */
2857
2858 if (is_breakpoint (bl->owner))
2859 {
2862 /* Reset the modification marker. */
2863 bl->needs_update = 0;
2864 }
2865
2866 /* If "set breakpoint auto-hw" is "on" and a software breakpoint was
2867 set at a read-only address, then a breakpoint location will have
2868 been changed to hardware breakpoint before we get here. If it is
2869 "off" however, error out before actually trying to insert the
2870 breakpoint, with a nicer error message. */
2873 {
2875
2876 if (mr != nullptr && mr->attrib.mode != MEM_RW)
2877 {
2878 gdb_printf (tmp_error_stream,
2879 _("Cannot insert breakpoint %d.\n"
2880 "Cannot set software breakpoint "
2881 "at read-only address %s\n"),
2882 bl->owner->number,
2883 paddress (bl->gdbarch, bl->address));
2884 return 1;
2885 }
2886 }
2887
2890 {
2891 /* First check to see if we have to handle an overlay. */
2893 || bl->section == NULL
2894 || !(section_is_overlay (bl->section)))
2895 {
2896 /* No overlay handling: just set the breakpoint. */
2897 try
2898 {
2899 int val;
2900
2901 val = bl->owner->insert_location (bl);
2902 if (val)
2903 bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR};
2904 }
2905 catch (gdb_exception &e)
2906 {
2908 bp_excpt = std::move (e);
2909 }
2910 }
2911 else
2912 {
2913 /* This breakpoint is in an overlay section.
2914 Shall we set a breakpoint at the LMA? */
2916 {
2917 /* Yes -- overlay event support is not active,
2918 so we must try to set a breakpoint at the LMA.
2919 This will not work for a hardware breakpoint. */
2921 warning (_("hardware breakpoint %d not supported in overlay!"),
2922 bl->owner->number);
2923 else
2924 {
2925 CORE_ADDR addr = overlay_unmapped_address (bl->address,
2926 bl->section);
2927 /* Set a software (trap) breakpoint at the LMA. */
2930
2931 /* No overlay handling: just set the breakpoint. */
2932 try
2933 {
2934 int val;
2935
2937 = breakpoint_kind (bl, &addr);
2940 &bl->overlay_target_info);
2941 if (val)
2942 bp_excpt
2943 = gdb_exception {RETURN_ERROR, GENERIC_ERROR};
2944 }
2945 catch (gdb_exception &e)
2946 {
2948 bp_excpt = std::move (e);
2949 }
2950
2951 if (bp_excpt.reason != 0)
2952 gdb_printf (tmp_error_stream,
2953 "Overlay breakpoint %d "
2954 "failed: in ROM?\n",
2955 bl->owner->number);
2956 }
2957 }
2958 /* Shall we set a breakpoint at the VMA? */
2959 if (section_is_mapped (bl->section))
2960 {
2961 /* Yes. This overlay section is mapped into memory. */
2962 try
2963 {
2964 int val;
2965
2966 val = bl->owner->insert_location (bl);
2967 if (val)
2968 bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR};
2969 }
2970 catch (gdb_exception_error &e)
2971 {
2973 bp_excpt = std::move (e);
2974 }
2975 }
2976 else
2977 {
2978 /* No. This breakpoint will not be inserted.
2979 No error, but do not mark the bp as 'inserted'. */
2980 return 0;
2981 }
2982 }
2983
2984 if (bp_excpt.reason != 0)
2985 {
2986 /* Can't set the breakpoint. */
2987 gdb_assert (bl->owner != nullptr);
2988
2989 /* In some cases, we might not be able to insert a
2990 breakpoint in a shared library that has already been
2991 removed, but we have not yet processed the shlib unload
2992 event. Unfortunately, some targets that implement
2993 breakpoint insertion themselves can't tell why the
2994 breakpoint insertion failed (e.g., the remote target
2995 doesn't define error codes), so we must treat generic
2996 errors as memory errors. */
2997 if (bp_excpt.reason == RETURN_ERROR
2998 && (bp_excpt.error == GENERIC_ERROR
2999 || bp_excpt.error == MEMORY_ERROR)
3003 bl->address)))
3004 {
3005 /* See also: disable_breakpoints_in_shlibs. */
3006 bl->shlib_disabled = 1;
3008 if (!*disabled_breaks)
3009 {
3010 gdb_printf (tmp_error_stream,
3011 "Cannot insert breakpoint %d.\n",
3012 bl->owner->number);
3013 gdb_printf (tmp_error_stream,
3014 "Temporarily disabling shared "
3015 "library breakpoints:\n");
3016 }
3017 *disabled_breaks = 1;
3018 gdb_printf (tmp_error_stream,
3019 "breakpoint #%d\n", bl->owner->number);
3020 return 0;
3021 }
3022 else
3023 {
3025 {
3026 *hw_breakpoint_error = 1;
3027 *hw_bp_error_explained_already = bp_excpt.message != NULL;
3028 gdb_printf (tmp_error_stream,
3029 "Cannot insert hardware breakpoint %d%s",
3030 bl->owner->number,
3031 bp_excpt.message ? ":" : ".\n");
3032 if (bp_excpt.message != NULL)
3033 gdb_printf (tmp_error_stream, "%s.\n",
3034 bp_excpt.what ());
3035 }
3036 else
3037 {
3038 if (bp_excpt.message == NULL)
3039 {
3040 std::string message
3042 bl->gdbarch, bl->address);
3043
3044 gdb_printf (tmp_error_stream,
3045 "Cannot insert breakpoint %d.\n"
3046 "%s\n",
3047 bl->owner->number, message.c_str ());
3048 }
3049 else
3050 {
3051 gdb_printf (tmp_error_stream,
3052 "Cannot insert breakpoint %d: %s\n",
3053 bl->owner->number,
3054 bp_excpt.what ());
3055 }
3056 }
3057 return 1;
3058
3059 }
3060 }
3061 else
3062 bl->inserted = 1;
3063
3064 return 0;
3065 }
3066
3067 else if (bl->loc_type == bp_loc_hardware_watchpoint
3069 {
3070 int val;
3071
3072 val = bl->owner->insert_location (bl);
3073
3074 /* If trying to set a read-watchpoint, and it turns out it's not
3075 supported, try emulating one with an access watchpoint. */
3076 if (val == 1 && bl->watchpoint_type == hw_read)
3077 {
3078 /* But don't try to insert it, if there's already another
3079 hw_access location that would be considered a duplicate
3080 of this one. */
3081 for (bp_location *loc : all_bp_locations ())
3082 if (loc != bl
3083 && loc->watchpoint_type == hw_access
3085 {
3086 bl->duplicate = 1;
3087 bl->inserted = 1;
3088 bl->target_info = loc->target_info;
3089 bl->watchpoint_type = hw_access;
3090 val = 0;
3091 break;
3092 }
3093
3094 if (val == 1)
3095 {
3096 bl->watchpoint_type = hw_access;
3097 val = bl->owner->insert_location (bl);
3098
3099 if (val)
3100 /* Back to the original value. */
3101 bl->watchpoint_type = hw_read;
3102 }
3103 }
3104
3105 bl->inserted = (val == 0);
3106 }
3107
3108 else if (bl->owner->type == bp_catchpoint)
3109 {
3110 int val;
3111
3112 val = bl->owner->insert_location (bl);
3113 if (val)
3114 {
3116
3117 if (val == 1)
3118 warning (_("\
3119Error inserting catchpoint %d: Your system does not support this type\n\
3120of catchpoint."), bl->owner->number);
3121 else
3122 warning (_("Error inserting catchpoint %d."), bl->owner->number);
3123 }
3124
3125 bl->inserted = (val == 0);
3126
3127 /* We've already printed an error message if there was a problem
3128 inserting this catchpoint, and we've disabled the catchpoint,
3129 so just return success. */
3130 return 0;
3131 }
3132
3133 return 0;
3134}
3135
3136/* This function is called when program space PSPACE is about to be
3137 deleted. It takes care of updating breakpoints to not reference
3138 PSPACE anymore. */
3139
3140void
3142{
3143 /* Remove any breakpoint that was set through this program space. */
3144 for (breakpoint &b : all_breakpoints_safe ())
3145 if (b.pspace == pspace)
3146 delete_breakpoint (&b);
3147
3148 /* Breakpoints set through other program spaces could have locations
3149 bound to PSPACE as well. Remove those. */
3150 for (bp_location *loc : all_bp_locations ())
3151 if (loc->pspace == pspace)
3152 {
3153 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
3154 loc->owner->unadd_location (*loc);
3155 }
3156
3157 /* Now update the global location list to permanently delete the
3158 removed locations above. */
3160}
3161
3162/* Make sure all breakpoints are inserted in inferior.
3163 Throws exception on any error.
3164 A breakpoint that is already inserted won't be inserted
3165 again, so calling this function twice is safe. */
3166void
3168{
3169 for (breakpoint &bpt : all_breakpoints ())
3170 if (is_hardware_watchpoint (&bpt))
3171 {
3172 watchpoint &w = gdb::checked_static_cast<watchpoint &> (bpt);
3173
3174 update_watchpoint (&w, false /* don't reparse. */);
3175 }
3176
3177 /* Updating watchpoints creates new locations, so update the global
3178 location list. Explicitly tell ugll to insert locations and
3179 ignore breakpoints_always_inserted_mode. Also,
3180 update_global_location_list tries to "upgrade" software
3181 breakpoints to hardware breakpoints to handle "set breakpoint
3182 auto-hw", so we need to call it even if we don't have new
3183 locations. */
3185}
3186
3187/* This is used when we need to synch breakpoint conditions between GDB and the
3188 target. It is the case with deleting and disabling of breakpoints when using
3189 always-inserted mode. */
3190
3191static void
3193{
3194 int error_flag = 0;
3195 int val = 0;
3196 int disabled_breaks = 0;
3197 int hw_breakpoint_error = 0;
3198 int hw_bp_details_reported = 0;
3199
3200 string_file tmp_error_stream;
3201
3202 /* Explicitly mark the warning -- this will only be printed if
3203 there was an error. */
3204 tmp_error_stream.puts ("Warning:\n");
3205
3206 scoped_restore_current_pspace_and_thread restore_pspace_thread;
3207
3208 for (bp_location *bl : all_bp_locations ())
3209 {
3210 /* We only want to update software breakpoints and hardware
3211 breakpoints. */
3212 if (!is_breakpoint (bl->owner))
3213 continue;
3214
3215 /* We only want to update locations that are already inserted
3216 and need updating. This is to avoid unwanted insertion during
3217 deletion of breakpoints. */
3218 if (!bl->inserted || !bl->needs_update)
3219 continue;
3220
3222
3223 /* For targets that support global breakpoints, there's no need
3224 to select an inferior to insert breakpoint to. In fact, even
3225 if we aren't attached to any process yet, we should still
3226 insert breakpoints. */
3228 && (inferior_ptid == null_ptid || !target_has_execution ()))
3229 continue;
3230
3231 val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks,
3232 &hw_breakpoint_error, &hw_bp_details_reported);
3233 if (val)
3234 error_flag = val;
3235 }
3236
3237 if (error_flag)
3238 {
3240 error (("%s"), tmp_error_stream.c_str ());
3241 }
3242}
3243
3244/* Used when starting or continuing the program. */
3245
3246static void
3248{
3249 int error_flag = 0;
3250 int val = 0;
3251 int disabled_breaks = 0;
3252 int hw_breakpoint_error = 0;
3253 int hw_bp_error_explained_already = 0;
3254
3255 string_file tmp_error_stream;
3256
3257 /* Explicitly mark the warning -- this will only be printed if
3258 there was an error. */
3259 tmp_error_stream.puts ("Warning:\n");
3260
3261 scoped_restore_current_pspace_and_thread restore_pspace_thread;
3262
3263 for (bp_location *bl : all_bp_locations ())
3264 {
3265 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
3266 continue;
3267
3268 /* There is no point inserting thread-specific breakpoints if
3269 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3270 has BL->OWNER always non-NULL. */
3271 if (bl->owner->thread != -1
3272 && !valid_global_thread_id (bl->owner->thread))
3273 continue;
3274
3275 /* Or inferior specific breakpoints if the inferior no longer
3276 exists. */
3277 if (bl->owner->inferior != -1
3278 && !valid_global_inferior_id (bl->owner->inferior))
3279 continue;
3280
3282
3283 /* For targets that support global breakpoints, there's no need
3284 to select an inferior to insert breakpoint to. In fact, even
3285 if we aren't attached to any process yet, we should still
3286 insert breakpoints. */
3288 && (inferior_ptid == null_ptid || !target_has_execution ()))
3289 continue;
3290
3291 val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks,
3292 &hw_breakpoint_error, &hw_bp_error_explained_already);
3293 if (val)
3294 error_flag = val;
3295 }
3296
3297 /* If we failed to insert all locations of a watchpoint, remove
3298 them, as half-inserted watchpoint is of limited use. */
3299 for (breakpoint &bpt : all_breakpoints ())
3300 {
3301 bool some_failed = false;
3302
3303 if (!is_hardware_watchpoint (&bpt))
3304 continue;
3305
3306 if (!breakpoint_enabled (&bpt))
3307 continue;
3308
3309 if (bpt.disposition == disp_del_at_next_stop)
3310 continue;
3311
3312 for (bp_location &loc : bpt.locations ())
3313 if (!loc.inserted && should_be_inserted (&loc))
3314 {
3315 some_failed = true;
3316 break;
3317 }
3318
3319 if (some_failed)
3320 {
3321 for (bp_location &loc : bpt.locations ())
3322 if (loc.inserted)
3324
3325 hw_breakpoint_error = 1;
3326 tmp_error_stream.printf ("Could not insert "
3327 "hardware watchpoint %d.\n",
3328 bpt.number);
3329 error_flag = -1;
3330 }
3331 }
3332
3333 if (error_flag)
3334 {
3335 /* If a hardware breakpoint or watchpoint was inserted, add a
3336 message about possibly exhausted resources. */
3337 if (hw_breakpoint_error && !hw_bp_error_explained_already)
3338 {
3339 tmp_error_stream.printf ("Could not insert hardware breakpoints:\n\
3340You may have requested too many hardware breakpoints/watchpoints.\n");
3341 }
3343 error (("%s"), tmp_error_stream.c_str ());
3344 }
3345}
3346
3347/* Used when the program stops.
3348 Returns zero if successful, or non-zero if there was a problem
3349 removing a breakpoint location. */
3350
3351int
3353{
3354 int val = 0;
3355
3356 for (bp_location *bl : all_bp_locations ())
3357 if (bl->inserted && !is_tracepoint (bl->owner))
3358 val |= remove_breakpoint (bl);
3359
3360 return val;
3361}
3362
3363/* When a thread exits, remove breakpoints that are related to
3364 that thread. */
3365
3366static void
3368 gdb::optional<ULONGEST> /* exit_code */,
3369 int /* silent */)
3370{
3371 for (breakpoint &b : all_breakpoints_safe ())
3372 {
3373 if (b.thread == tp->global_num && user_breakpoint_p (&b))
3374 {
3375 gdb_printf (_("\
3376Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3377 b.number, print_thread_id (tp));
3378 delete_breakpoint (&b);
3379 }
3380 }
3381}
3382
3383/* Called when inferior INF has been removed from GDB. Remove associated
3384 per-inferior breakpoints. */
3385
3386static void
3388{
3389 for (breakpoint &b : all_breakpoints_safe ())
3390 {
3391 if (b.inferior == inf->num && user_breakpoint_p (&b))
3392 {
3393 /* Tell the user the breakpoint has been deleted. But only for
3394 breakpoints that would not normally have been deleted at the
3395 next stop anyway. */
3396 if (b.disposition != disp_del
3398 gdb_printf (_("\
3399Inferior-specific breakpoint %d deleted - inferior %d has been removed.\n"),
3400 b.number, inf->num);
3401 delete_breakpoint (&b);
3402 }
3403 }
3404}
3405
3406/* See breakpoint.h. */
3407
3408void
3410{
3411 int val;
3412
3413 breakpoint_debug_printf ("inf->num = %d", inf->num);
3414
3415 for (bp_location *bl : all_bp_locations ())
3416 {
3417 if (bl->pspace != inf->pspace)
3418 continue;
3419
3420 if (bl->inserted && !bl->target_info.persist)
3421 {
3422 val = remove_breakpoint (bl);
3423 if (val != 0)
3424 return;
3425 }
3426 }
3427}
3428
3430
3431/* Set the breakpoint number of B, depending on the value of INTERNAL.
3432 If INTERNAL is non-zero, the breakpoint number will be populated
3433 from internal_breakpoint_number and that variable decremented.
3434 Otherwise the breakpoint number will be populated from
3435 breakpoint_count and that value incremented. Internal breakpoints
3436 do not set the internal var bpnum. */
3437static void
3438set_breakpoint_number (int internal, struct breakpoint *b)
3439{
3440 if (internal)
3442 else
3443 {
3446 }
3447}
3448
3449/* Create a TYPE breakpoint on ADDRESS from an object file with GDBARCH. */
3450
3451static struct breakpoint *
3453 CORE_ADDR address, enum bptype type)
3454{
3455 std::unique_ptr<internal_breakpoint> b
3456 (new internal_breakpoint (gdbarch, type, address));
3457
3458 b->number = internal_breakpoint_number--;
3459
3460 return add_to_breakpoint_chain (std::move (b));
3461}
3462
3463/* Create a TYPE breakpoint on minimal symbol MSYM from an object file with
3464 GDBARCH. */
3465
3466static struct breakpoint *
3468 struct bound_minimal_symbol &msym, enum bptype type)
3469{
3470 CORE_ADDR address;
3471
3472 address = msym.value_address ();
3473
3475 (gdbarch, address, current_inferior ()->top_target ());
3476
3477 /* Note that we're not using gdbarch_addr_bits_remove here, because that's
3478 related to addresses in $pc. We're getting the address from the
3479 minimal symbol table. */
3480
3481 /* Is gdbarch_deprecated_function_start_offset needed here? Or is that dealt
3482 with elsewhere? Needs testing on vax. */
3483
3485 address = gdbarch_skip_entrypoint (gdbarch, address);
3486
3487 return create_internal_breakpoint (gdbarch, address, type);
3488}
3489
3490static const char *const longjmp_names[] =
3491 {
3492 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3493 };
3494#define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3495
3496/* Per-objfile data private to breakpoint.c. */
3498{
3499 /* Minimal symbol for "_ovly_debug_event" (if any). */
3501
3502 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3504
3505 /* True if we have looked for longjmp probes. */
3507
3508 /* SystemTap probe points for longjmp (if any). These are non-owning
3509 references. */
3510 std::vector<probe *> longjmp_probes;
3511
3512 /* Minimal symbol for "std::terminate()" (if any). */
3514
3515 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3517
3518 /* True if we have looked for exception probes. */
3520
3521 /* SystemTap probe points for unwinding (if any). These are non-owning
3522 references. */
3523 std::vector<probe *> exception_probes;
3524};
3525
3528
3529/* Minimal symbol not found sentinel. */
3531
3532/* Returns TRUE if MSYM point to the "not found" sentinel. */
3533
3534static bool
3536{
3537 return msym == &msym_not_found;
3538}
3539
3540/* Return per-objfile data needed by breakpoint.c.
3541 Allocate the data if necessary. */
3542
3543static struct breakpoint_objfile_data *
3545{
3546 struct breakpoint_objfile_data *bp_objfile_data;
3547
3548 bp_objfile_data = breakpoint_objfile_key.get (objfile);
3549 if (bp_objfile_data == NULL)
3550 bp_objfile_data = breakpoint_objfile_key.emplace (objfile);
3551 return bp_objfile_data;
3552}
3553
3554static void
3556{
3557 const char *const func_name = "_ovly_debug_event";
3558
3560 {
3561 struct breakpoint *b;
3562 struct breakpoint_objfile_data *bp_objfile_data;
3563 CORE_ADDR addr;
3564
3565 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3566
3567 if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym))
3568 continue;
3569
3570 if (bp_objfile_data->overlay_msym.minsym == NULL)
3571 {
3572 struct bound_minimal_symbol m;
3573
3574 m = lookup_minimal_symbol_text (func_name, objfile);
3575 if (m.minsym == NULL)
3576 {
3577 /* Avoid future lookups in this objfile. */
3578 bp_objfile_data->overlay_msym.minsym = &msym_not_found;
3579 continue;
3580 }
3581 bp_objfile_data->overlay_msym = m;
3582 }
3583
3584 addr = bp_objfile_data->overlay_msym.value_address ();
3588
3590 {
3593 }
3594 else
3595 {
3598 }
3599 }
3600}
3601
3602/* Install a master longjmp breakpoint for OBJFILE using a probe. Return
3603 true if a breakpoint was installed. */
3604
3605static bool
3607{
3608 struct gdbarch *gdbarch = objfile->arch ();
3609 struct breakpoint_objfile_data *bp_objfile_data
3611
3612 if (!bp_objfile_data->longjmp_searched)
3613 {
3614 std::vector<probe *> ret
3615 = find_probes_in_objfile (objfile, "libc", "longjmp");
3616
3617 if (!ret.empty ())
3618 {
3619 /* We are only interested in checking one element. */
3620 probe *p = ret[0];
3621
3622 if (!p->can_evaluate_arguments ())
3623 {
3624 /* We cannot use the probe interface here,
3625 because it does not know how to evaluate
3626 arguments. */
3627 ret.clear ();
3628 }
3629 }
3630 bp_objfile_data->longjmp_probes = ret;
3631 bp_objfile_data->longjmp_searched = 1;
3632 }
3633
3634 if (bp_objfile_data->longjmp_probes.empty ())
3635 return false;
3636
3637 for (probe *p : bp_objfile_data->longjmp_probes)
3638 {
3639 struct breakpoint *b;
3640
3642 p->get_relocated_address (objfile),
3644 b->locspec = new_probe_location_spec ("-probe-stap libc:longjmp");
3646 }
3647
3648 return true;
3649}
3650
3651/* Install master longjmp breakpoints for OBJFILE using longjmp_names.
3652 Return true if at least one breakpoint was installed. */
3653
3654static bool
3656{
3657 struct gdbarch *gdbarch = objfile->arch ();
3659 return false;
3660
3661 struct breakpoint_objfile_data *bp_objfile_data
3663 unsigned int installed_bp = 0;
3664
3665 for (int i = 0; i < NUM_LONGJMP_NAMES; i++)
3666 {
3667 struct breakpoint *b;
3668 const char *func_name;
3669 CORE_ADDR addr;
3670
3671 if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym))
3672 continue;
3673
3674 func_name = longjmp_names[i];
3675 if (bp_objfile_data->longjmp_msym[i].minsym == NULL)
3676 {
3677 struct bound_minimal_symbol m;
3678
3679 m = lookup_minimal_symbol_text (func_name, objfile);
3680 if (m.minsym == NULL)
3681 {
3682 /* Prevent future lookups in this objfile. */
3683 bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found;
3684 continue;
3685 }
3686 bp_objfile_data->longjmp_msym[i] = m;
3687 }
3688
3689 addr = bp_objfile_data->longjmp_msym[i].value_address ();
3693 installed_bp++;
3694 }
3695
3696 return installed_bp > 0;
3697}
3698
3699/* Create a master longjmp breakpoint. */
3700
3701static void
3703{
3705
3706 for (struct program_space *pspace : program_spaces)
3707 {
3709
3710 for (objfile *obj : current_program_space->objfiles ())
3711 {
3712 /* Skip separate debug object, it's handled in the loop below. */
3713 if (obj->separate_debug_objfile_backlink != nullptr)
3714 continue;
3715
3716 /* Try a probe kind breakpoint on main objfile. */
3718 continue;
3719
3720 /* Try longjmp_names kind breakpoints on main and separate_debug
3721 objfiles. */
3722 for (objfile *debug_objfile : obj->separate_debug_objfiles ())
3723 if (create_longjmp_master_breakpoint_names (debug_objfile))
3724 break;
3725 }
3726 }
3727}
3728
3729/* Create a master std::terminate breakpoint. */
3730static void
3732{
3733 const char *const func_name = "std::terminate()";
3734
3736
3737 for (struct program_space *pspace : program_spaces)
3738 {
3740
3742 {
3743 struct breakpoint *b;
3744 struct breakpoint_objfile_data *bp_objfile_data;
3745
3746 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3747
3748 if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym))
3749 continue;
3750
3751 if (bp_objfile_data->terminate_msym.minsym == NULL)
3752 {
3753 struct bound_minimal_symbol m;
3754
3755 m = lookup_minimal_symbol (func_name, NULL, objfile);
3756 if (m.minsym == NULL || (m.minsym->type () != mst_text
3757 && m.minsym->type () != mst_file_text))
3758 {
3759 /* Prevent future lookups in this objfile. */
3760 bp_objfile_data->terminate_msym.minsym = &msym_not_found;
3761 continue;
3762 }
3763 bp_objfile_data->terminate_msym = m;
3764 }
3765
3767 bp_objfile_data->terminate_msym,
3771 }
3772 }
3773}
3774
3775/* Install a master breakpoint on the unwinder's debug hook for OBJFILE using a
3776 probe. Return true if a breakpoint was installed. */
3777
3778static bool
3780{
3781 struct breakpoint *b;
3782 struct gdbarch *gdbarch;
3783 struct breakpoint_objfile_data *bp_objfile_data;
3784
3785 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3786
3787 /* We prefer the SystemTap probe point if it exists. */
3788 if (!bp_objfile_data->exception_searched)
3789 {
3790 std::vector<probe *> ret
3791 = find_probes_in_objfile (objfile, "libgcc", "unwind");
3792
3793 if (!ret.empty ())
3794 {
3795 /* We are only interested in checking one element. */
3796 probe *p = ret[0];
3797
3798 if (!p->can_evaluate_arguments ())
3799 {
3800 /* We cannot use the probe interface here, because it does
3801 not know how to evaluate arguments. */
3802 ret.clear ();
3803 }
3804 }
3805 bp_objfile_data->exception_probes = ret;
3806 bp_objfile_data->exception_searched = 1;
3807 }
3808
3809 if (bp_objfile_data->exception_probes.empty ())
3810 return false;
3811
3812 gdbarch = objfile->arch ();
3813
3814 for (probe *p : bp_objfile_data->exception_probes)
3815 {
3817 p->get_relocated_address (objfile),
3819 b->locspec = new_probe_location_spec ("-probe-stap libgcc:unwind");
3821 }
3822
3823 return true;
3824}
3825
3826/* Install a master breakpoint on the unwinder's debug hook for OBJFILE using
3827 _Unwind_DebugHook. Return true if a breakpoint was installed. */
3828
3829static bool
3831{
3832 const char *const func_name = "_Unwind_DebugHook";
3833 struct breakpoint *b;
3834 struct gdbarch *gdbarch;
3835 struct breakpoint_objfile_data *bp_objfile_data;
3836
3837 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3838
3839 if (msym_not_found_p (bp_objfile_data->exception_msym.minsym))
3840 return false;
3841
3842 gdbarch = objfile->arch ();
3843
3844 if (bp_objfile_data->exception_msym.minsym == NULL)
3845 {
3846 struct bound_minimal_symbol debug_hook;
3847
3848 debug_hook = lookup_minimal_symbol (func_name, NULL, objfile);
3849 if (debug_hook.minsym == NULL)
3850 {
3851 bp_objfile_data->exception_msym.minsym = &msym_not_found;
3852 return false;
3853 }
3854
3855 bp_objfile_data->exception_msym = debug_hook;
3856 }
3857
3858 b = create_internal_breakpoint (gdbarch, bp_objfile_data->exception_msym,
3862
3863 return true;
3864}
3865
3866/* Install a master breakpoint on the unwinder's debug hook. */
3867
3868static void
3870{
3871 for (objfile *obj : current_program_space->objfiles ())
3872 {
3873 /* Skip separate debug object. */
3874 if (obj->separate_debug_objfile_backlink)
3875 continue;
3876
3877 /* Try a probe kind breakpoint. */
3879 continue;
3880
3881 /* Iterate over main and separate debug objects and try an
3882 _Unwind_DebugHook kind breakpoint. */
3883 for (objfile *debug_objfile : obj->separate_debug_objfiles ())
3884 if (create_exception_master_breakpoint_hook (debug_objfile))
3885 break;
3886 }
3887}
3888
3889/* Does B have a location spec? */
3890
3891static bool
3893{
3894 return (b->locspec != nullptr && b->locspec->empty_p ());
3895}
3896
3897void
3899{
3900 /* We're about to delete breakpoints from GDB's lists. If the
3901 INSERTED flag is true, GDB will try to lift the breakpoints by
3902 writing the breakpoints' "shadow contents" back into memory. The
3903 "shadow contents" are NOT valid after an exec, so GDB should not
3904 do that. Instead, the target is responsible from marking
3905 breakpoints out as soon as it detects an exec. We don't do that
3906 here instead, because there may be other attempts to delete
3907 breakpoints after detecting an exec and before reaching here. */
3908 for (bp_location *bploc : all_bp_locations ())
3909 if (bploc->pspace == current_program_space)
3910 gdb_assert (!bploc->inserted);
3911
3912 for (breakpoint &b : all_breakpoints_safe ())
3913 {
3915 continue;
3916
3917 /* Solib breakpoints must be explicitly reset after an exec(). */
3918 if (b.type == bp_shlib_event)
3919 {
3920 delete_breakpoint (&b);
3921 continue;
3922 }
3923
3924 /* JIT breakpoints must be explicitly reset after an exec(). */
3925 if (b.type == bp_jit_event)
3926 {
3927 delete_breakpoint (&b);
3928 continue;
3929 }
3930
3931 /* Thread event breakpoints must be set anew after an exec(),
3932 as must overlay event and longjmp master breakpoints. */
3933 if (b.type == bp_thread_event || b.type == bp_overlay_event
3935 || b.type == bp_exception_master)
3936 {
3937 delete_breakpoint (&b);
3938 continue;
3939 }
3940
3941 /* Step-resume breakpoints are meaningless after an exec(). */
3942 if (b.type == bp_step_resume || b.type == bp_hp_step_resume)
3943 {
3944 delete_breakpoint (&b);
3945 continue;
3946 }
3947
3948 /* Just like single-step breakpoints. */
3949 if (b.type == bp_single_step)
3950 {
3951 delete_breakpoint (&b);
3952 continue;
3953 }
3954
3955 /* Longjmp and longjmp-resume breakpoints are also meaningless
3956 after an exec. */
3957 if (b.type == bp_longjmp || b.type == bp_longjmp_resume
3959 || b.type == bp_exception || b.type == bp_exception_resume)
3960 {
3961 delete_breakpoint (&b);
3962 continue;
3963 }
3964
3965 if (b.type == bp_catchpoint)
3966 {
3967 /* For now, none of the bp_catchpoint breakpoints need to
3968 do anything at this point. In the future, if some of
3969 the catchpoints need to something, we will need to add
3970 a new method, and call this method from here. */
3971 continue;
3972 }
3973
3974 /* bp_finish is a special case. The only way we ought to be able
3975 to see one of these when an exec() has happened, is if the user
3976 caught a vfork, and then said "finish". Ordinarily a finish just
3977 carries them to the call-site of the current callee, by setting
3978 a temporary bp there and resuming. But in this case, the finish
3979 will carry them entirely through the vfork & exec.
3980
3981 We don't want to allow a bp_finish to remain inserted now. But
3982 we can't safely delete it, 'cause finish_command has a handle to
3983 the bp on a bpstat, and will later want to delete it. There's a
3984 chance (and I've seen it happen) that if we delete the bp_finish
3985 here, that its storage will get reused by the time finish_command
3986 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3987 We really must allow finish_command to delete a bp_finish.
3988
3989 In the absence of a general solution for the "how do we know
3990 it's safe to delete something others may have handles to?"
3991 problem, what we'll do here is just uninsert the bp_finish, and
3992 let finish_command delete it.
3993
3994 (We know the bp_finish is "doomed" in the sense that it's
3995 momentary, and will be deleted as soon as finish_command sees
3996 the inferior stopped. So it doesn't matter that the bp's
3997 address is probably bogus in the new a.out, unlike e.g., the
3998 solib breakpoints.) */
3999
4000 if (b.type == bp_finish)
4001 {
4002 continue;
4003 }
4004
4005 /* Without a symbolic address, we have little hope of the
4006 pre-exec() address meaning the same thing in the post-exec()
4007 a.out. */
4009 {
4010 delete_breakpoint (&b);
4011 continue;
4012 }
4013 }
4014}
4015
4016int
4018{
4019 int val = 0;
4020 scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid);
4021 struct inferior *inf = current_inferior ();
4022
4023 if (ptid.pid () == inferior_ptid.pid ())
4024 error (_("Cannot detach breakpoints of inferior_ptid"));
4025
4026 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
4027 inferior_ptid = ptid;
4028 for (bp_location *bl : all_bp_locations ())
4029 {
4030 if (bl->pspace != inf->pspace)
4031 continue;
4032
4033 /* This function must physically remove breakpoints locations
4034 from the specified ptid, without modifying the breakpoint
4035 package's state. Locations of type bp_loc_other and
4036 bp_loc_software_watchpoint are only maintained at GDB side,
4037 so there is no need to remove them. Moreover, removing these
4038 would modify the breakpoint package's state. */
4039 if (bl->loc_type == bp_loc_other
4040 || bl->loc_type == bp_loc_software_watchpoint)
4041 continue;
4042
4043 if (bl->inserted)
4045 }
4046
4047 return val;
4048}
4049
4050/* Remove the breakpoint location BL from the current address space.
4051 Note that this is used to detach breakpoints from a child fork.
4052 When we get here, the child isn't in the inferior list, and neither
4053 do we have objects to represent its address space --- we should
4054 *not* look at bl->pspace->aspace here. */
4055
4056static int
4058{
4059 breakpoint_debug_printf ("%s due to %s",
4060 breakpoint_location_address_str (bl).c_str (),
4061 remove_bp_reason_str (reason));
4062
4063 int val;
4064
4065 /* BL is never in moribund_locations by our callers. */
4066 gdb_assert (bl->owner != NULL);
4067
4068 /* The type of none suggests that owner is actually deleted.
4069 This should not ever happen. */
4070 gdb_assert (bl->owner->type != bp_none);
4071
4074 {
4075 /* "Normal" instruction breakpoint: either the standard
4076 trap-instruction bp (bp_breakpoint), or a
4077 bp_hardware_breakpoint. */
4078
4079 /* First check to see if we have to handle an overlay. */
4081 || bl->section == NULL
4082 || !(section_is_overlay (bl->section)))
4083 {
4084 /* No overlay handling: just remove the breakpoint. */
4085
4086 /* If we're trying to uninsert a memory breakpoint that we
4087 know is set in a dynamic object that is marked
4088 shlib_disabled, then either the dynamic object was
4089 removed with "remove-symbol-file" or with
4090 "nosharedlibrary". In the former case, we don't know
4091 whether another dynamic object might have loaded over the
4092 breakpoint's address -- the user might well let us know
4093 about it next with add-symbol-file (the whole point of
4094 add-symbol-file is letting the user manually maintain a
4095 list of dynamically loaded objects). If we have the
4096 breakpoint's shadow memory, that is, this is a software
4097 breakpoint managed by GDB, check whether the breakpoint
4098 is still inserted in memory, to avoid overwriting wrong
4099 code with stale saved shadow contents. Note that HW
4100 breakpoints don't have shadow memory, as they're
4101 implemented using a mechanism that is not dependent on
4102 being able to modify the target's memory, and as such
4103 they should always be removed. */
4104 if (bl->shlib_disabled
4105 && bl->target_info.shadow_len != 0
4107 val = 0;
4108 else
4109 val = bl->owner->remove_location (bl, reason);
4110 }
4111 else
4112 {
4113 /* This breakpoint is in an overlay section.
4114 Did we set a breakpoint at the LMA? */
4116 {
4117 /* Yes -- overlay event support is not active, so we
4118 should have set a breakpoint at the LMA. Remove it.
4119 */
4120 /* Ignore any failures: if the LMA is in ROM, we will
4121 have already warned when we failed to insert it. */
4124 &bl->overlay_target_info);
4125 else
4128 reason);
4129 }
4130 /* Did we set a breakpoint at the VMA?
4131 If so, we will have marked the breakpoint 'inserted'. */
4132 if (bl->inserted)
4133 {
4134 /* Yes -- remove it. Previously we did not bother to
4135 remove the breakpoint if the section had been
4136 unmapped, but let's not rely on that being safe. We
4137 don't know what the overlay manager might do. */
4138
4139 /* However, we should remove *software* breakpoints only
4140 if the section is still mapped, or else we overwrite
4141 wrong code with the saved shadow contents. */
4143 || section_is_mapped (bl->section))
4144 val = bl->owner->remove_location (bl, reason);
4145 else
4146 val = 0;
4147 }
4148 else
4149 {
4150 /* No -- not inserted, so no need to remove. No error. */
4151 val = 0;
4152 }
4153 }
4154
4155 /* In some cases, we might not be able to remove a breakpoint in
4156 a shared library that has already been removed, but we have
4157 not yet processed the shlib unload event. Similarly for an
4158 unloaded add-symbol-file object - the user might not yet have
4159 had the chance to remove-symbol-file it. shlib_disabled will
4160 be set if the library/object has already been removed, but
4161 the breakpoint hasn't been uninserted yet, e.g., after
4162 "nosharedlibrary" or "remove-symbol-file" with breakpoints
4163 always-inserted mode. */
4164 if (val
4166 && (bl->shlib_disabled
4169 bl->address))))
4170 val = 0;
4171
4172 if (val)
4173 return val;
4174 bl->inserted = (reason == DETACH_BREAKPOINT);
4175 }
4176 else if (bl->loc_type == bp_loc_hardware_watchpoint)
4177 {
4178 bl->inserted = (reason == DETACH_BREAKPOINT);
4179 bl->owner->remove_location (bl, reason);
4180
4181 /* Failure to remove any of the hardware watchpoints comes here. */
4182 if (reason == REMOVE_BREAKPOINT && bl->inserted)
4183 warning (_("Could not remove hardware watchpoint %d."),
4184 bl->owner->number);
4185 }
4186 else if (bl->owner->type == bp_catchpoint
4187 && breakpoint_enabled (bl->owner)
4188 && !bl->duplicate)
4189 {
4190 val = bl->owner->remove_location (bl, reason);
4191 if (val)
4192 return val;
4193
4194 bl->inserted = (reason == DETACH_BREAKPOINT);
4195 }
4196
4197 return 0;
4198}
4199
4200static int
4202{
4203 /* BL is never in moribund_locations by our callers. */
4204 gdb_assert (bl->owner != NULL);
4205
4206 /* The type of none suggests that owner is actually deleted.
4207 This should not ever happen. */
4208 gdb_assert (bl->owner->type != bp_none);
4209
4210 scoped_restore_current_pspace_and_thread restore_pspace_thread;
4211
4213
4215}
4216
4217/* Clear the "inserted" flag in all breakpoints. */
4218
4219void
4221{
4222 for (bp_location *bl : all_bp_locations ())
4223 if (bl->pspace == current_program_space)
4224 bl->inserted = 0;
4225}
4226
4227/* Clear the "inserted" flag in all breakpoints and delete any
4228 breakpoints which should go away between runs of the program.
4229
4230 Plus other such housekeeping that has to be done for breakpoints
4231 between runs.
4232
4233 Note: this function gets called at the end of a run (by
4234 generic_mourn_inferior) and when a run begins (by
4235 init_wait_for_inferior). */
4236
4237
4238
4239void
4241{
4242 struct program_space *pspace = current_program_space;
4243
4244 /* If breakpoint locations are shared across processes, then there's
4245 nothing to do. */
4247 return;
4248
4250
4251 for (breakpoint &b : all_breakpoints_safe ())
4252 {
4253 if (b.has_locations () && b.first_loc ().pspace != pspace)
4254 continue;
4255
4256 switch (b.type)
4257 {
4258 case bp_call_dummy:
4260
4261 /* If the call dummy breakpoint is at the entry point it will
4262 cause problems when the inferior is rerun, so we better get
4263 rid of it. */
4264
4266
4267 /* Also get rid of scope breakpoints. */
4268
4269 case bp_shlib_event:
4270
4271 /* Also remove solib event breakpoints. Their addresses may
4272 have changed since the last time we ran the program.
4273 Actually we may now be debugging against different target;
4274 and so the solib backend that installed this breakpoint may
4275 not be used in by the target. E.g.,
4276
4277 (gdb) file prog-linux
4278 (gdb) run # native linux target
4279 ...
4280 (gdb) kill
4281 (gdb) file prog-win.exe
4282 (gdb) tar rem :9999 # remote Windows gdbserver.
4283 */
4284
4285 case bp_step_resume:
4286
4287 /* Also remove step-resume breakpoints. */
4288
4289 case bp_single_step:
4290
4291 /* Also remove single-step breakpoints. */
4292
4293 delete_breakpoint (&b);
4294 break;
4295
4296 case bp_watchpoint:
4298 case bp_read_watchpoint:
4300 {
4301 watchpoint &w = gdb::checked_static_cast<watchpoint &> (b);
4302
4303 /* Likewise for watchpoints on local expressions. */
4304 if (w.exp_valid_block != NULL)
4305 delete_breakpoint (&b);
4306 else
4307 {
4308 /* Get rid of existing locations, which are no longer
4309 valid. New ones will be created in
4310 update_watchpoint, when the inferior is restarted.
4311 The next update_global_location_list call will
4312 garbage collect them. */
4313 b.clear_locations ();
4314
4315 if (context == inf_starting)
4316 {
4317 /* Reset val field to force reread of starting value in
4318 insert_breakpoints. */
4319 w.val.reset (nullptr);
4320 w.val_valid = false;
4321 }
4322 }
4323 }
4324 break;
4325 default:
4326 break;
4327 }
4328 }
4329
4330 /* Get rid of the moribund locations. */
4332 decref_bp_location (&bl);
4333 moribund_locations.clear ();
4334}
4335
4336/* These functions concern about actual breakpoints inserted in the
4337 target --- to e.g. check if we need to do decr_pc adjustment or if
4338 we need to hop over the bkpt --- so we check for address space
4339 match, not program space. */
4340
4341/* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4342 exists at PC. It returns ordinary_breakpoint_here if it's an
4343 ordinary breakpoint, or permanent_breakpoint_here if it's a
4344 permanent breakpoint.
4345 - When continuing from a location with an ordinary breakpoint, we
4346 actually single step once before calling insert_breakpoints.
4347 - When continuing from a location with a permanent breakpoint, we
4348 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4349 the target, to advance the PC past the breakpoint. */
4350
4351enum breakpoint_here
4353{
4354 bool any_breakpoint_here = false;
4355
4356 for (bp_location *bl : all_bp_locations ())
4357 {
4358 if (bl->loc_type != bp_loc_software_breakpoint
4359 && bl->loc_type != bp_loc_hardware_breakpoint)
4360 continue;
4361
4362 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4363 if ((breakpoint_enabled (bl->owner)
4364 || bl->permanent)
4366 {
4368 && section_is_overlay (bl->section)
4369 && !section_is_mapped (bl->section))
4370 continue; /* unmapped overlay -- can't be a match */
4371 else if (bl->permanent)
4373 else
4374 any_breakpoint_here = true;
4375 }
4376 }
4377
4378 return any_breakpoint_here ? ordinary_breakpoint_here : no_breakpoint_here;
4379}
4380
4381/* See breakpoint.h. */
4382
4383int
4385 CORE_ADDR addr, ULONGEST len)
4386{
4387 for (bp_location *bl : all_bp_locations ())
4388 {
4389 if (bl->loc_type != bp_loc_software_breakpoint
4390 && bl->loc_type != bp_loc_hardware_breakpoint)
4391 continue;
4392
4393 if ((breakpoint_enabled (bl->owner)
4394 || bl->permanent)
4396 addr, len))
4397 {
4399 && section_is_overlay (bl->section)
4400 && !section_is_mapped (bl->section))
4401 {
4402 /* Unmapped overlay -- can't be a match. */
4403 continue;
4404 }
4405
4406 return 1;
4407 }
4408 }
4409
4410 return 0;
4411}
4412
4413/* Return true if there's a moribund breakpoint at PC. */
4414
4415int
4417{
4420 return 1;
4421
4422 return 0;
4423}
4424
4425/* Returns true iff BL is inserted at PC, in address space ASPACE. */
4426
4427static bool
4429 const address_space *aspace, CORE_ADDR pc)
4430{
4431 if (bl->inserted
4433 aspace, pc))
4434 {
4435 /* An unmapped overlay can't be a match. */
4436 return !(overlay_debugging
4438 && !section_is_mapped (bl->section));
4439 }
4440 return false;
4441}
4442
4443/* Returns non-zero iff there's a breakpoint inserted at PC. */
4444
4445int
4447{
4448 for (bp_location *bl : all_bp_locations_at_addr (pc))
4449 {
4450 if (bl->loc_type != bp_loc_software_breakpoint
4451 && bl->loc_type != bp_loc_hardware_breakpoint)
4452 continue;
4453
4454 if (bp_location_inserted_here_p (bl, aspace, pc))
4455 return 1;
4456 }
4457 return 0;
4458}
4459
4460/* This function returns non-zero iff there is a software breakpoint
4461 inserted at PC. */
4462
4463int
4465 CORE_ADDR pc)
4466{
4467 for (bp_location *bl : all_bp_locations_at_addr (pc))
4468 {
4469 if (bl->loc_type != bp_loc_software_breakpoint)
4470 continue;
4471
4472 if (bp_location_inserted_here_p (bl, aspace, pc))
4473 return 1;
4474 }
4475
4476 return 0;
4477}
4478
4479/* See breakpoint.h. */
4480
4481int
4483 CORE_ADDR pc)
4484{
4485 for (bp_location *bl : all_bp_locations_at_addr (pc))
4486 {
4487 if (bl->loc_type != bp_loc_hardware_breakpoint)
4488 continue;
4489
4490 if (bp_location_inserted_here_p (bl, aspace, pc))
4491 return 1;
4492 }
4493
4494 return 0;
4495}
4496
4497int
4499 CORE_ADDR addr, ULONGEST len)
4500{
4501 for (breakpoint &bpt : all_breakpoints ())
4502 {
4503 if (bpt.type != bp_hardware_watchpoint
4504 && bpt.type != bp_access_watchpoint)
4505 continue;
4506
4507 if (!breakpoint_enabled (&bpt))
4508 continue;
4509
4510 for (bp_location &loc : bpt.locations ())
4511 if (loc.pspace->aspace == aspace && loc.inserted)
4512 {
4513 CORE_ADDR l, h;
4514
4515 /* Check for intersection. */
4516 l = std::max<CORE_ADDR> (loc.address, addr);
4517 h = std::min<CORE_ADDR> (loc.address + loc.length, addr + len);
4518 if (l < h)
4519 return 1;
4520 }
4521 }
4522 return 0;
4523}
4524
4525/* See breakpoint.h. */
4526
4527bool
4529{
4530 return (b->type == bp_catchpoint);
4531}
4532
4533/* Clear a bpstat so that it says we are not at any breakpoint.
4534 Also free any storage that is part of a bpstat. */
4535
4536void
4538{
4539 bpstat *p;
4540 bpstat *q;
4541
4542 if (bsp == 0)
4543 return;
4544 p = *bsp;
4545 while (p != NULL)
4546 {
4547 q = p->next;
4548 delete p;
4549 p = q;
4550 }
4551 *bsp = NULL;
4552}
4553
4555 : next (NULL),
4556 bp_location_at (other.bp_location_at),
4557 breakpoint_at (other.breakpoint_at),
4558 commands (other.commands),
4559 print (other.print),
4560 stop (other.stop),
4561 print_it (other.print_it)
4562{
4563 if (other.old_val != NULL)
4564 old_val = release_value (other.old_val->copy ());
4565}
4566
4567/* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4568 is part of the bpstat is copied as well. */
4569
4570bpstat *
4572{
4573 bpstat *p = nullptr;
4574 bpstat *tmp;
4575 bpstat *retval = nullptr;
4576
4577 if (bs == NULL)
4578 return bs;
4579
4580 for (; bs != NULL; bs = bs->next)
4581 {
4582 tmp = new bpstat (*bs);
4583
4584 if (p == NULL)
4585 /* This is the first thing in the chain. */
4586 retval = tmp;
4587 else
4588 p->next = tmp;
4589 p = tmp;
4590 }
4591 p->next = NULL;
4592 return retval;
4593}
4594
4595/* Find the bpstat associated with this breakpoint. */
4596
4597bpstat *
4599{
4600 if (bsp == NULL)
4601 return NULL;
4602
4603 for (; bsp != NULL; bsp = bsp->next)
4604 {
4605 if (bsp->breakpoint_at == breakpoint)
4606 return bsp;
4607 }
4608 return NULL;
4609}
4610
4611/* See breakpoint.h. */
4612
4613bool
4614bpstat_explains_signal (bpstat *bsp, enum gdb_signal sig)
4615{
4616 for (; bsp != NULL; bsp = bsp->next)
4617 {
4618 if (bsp->breakpoint_at == NULL)
4619 {
4620 /* A moribund location can never explain a signal other than
4621 GDB_SIGNAL_TRAP. */
4622 if (sig == GDB_SIGNAL_TRAP)
4623 return true;
4624 }
4625 else
4626 {
4627 if (bsp->breakpoint_at->explains_signal (sig))
4628 return true;
4629 }
4630 }
4631
4632 return false;
4633}
4634
4635/* See breakpoint.h. */
4636
4637int
4638bpstat_num (bpstat **bsp, int *num)
4639{
4640 struct breakpoint *b;
4641
4642 if ((*bsp) == NULL)
4643 return 0; /* No more breakpoint values */
4644
4645 /* We assume we'll never have several bpstats that correspond to a
4646 single breakpoint -- otherwise, this function might return the
4647 same number more than once and this will look ugly. */
4648 b = (*bsp)->breakpoint_at;
4649 *bsp = (*bsp)->next;
4650 if (b == NULL)
4651 return -1; /* breakpoint that's been deleted since */
4652
4653 *num = b->number; /* We have its number */
4654 return 1;
4655}
4656
4657/* See breakpoint.h */
4658
4659int
4661{
4662 const struct breakpoint *b = bs->breakpoint_at;
4663 const struct bp_location *bl = bs->bp_location_at.get ();
4664
4665 if (b != nullptr && b->has_multiple_locations ())
4666 {
4667 int locno = 1;
4668
4669 for (bp_location &loc : b->locations ())
4670 {
4671 if (bl == &loc)
4672 return locno;
4673
4674 ++locno;
4675 }
4676
4677 warning (_("location number not found for breakpoint %d address %s."),
4678 b->number, paddress (bl->gdbarch, bl->address));
4679 }
4680
4681 return 0;
4682}
4683
4684/* See breakpoint.h. */
4685
4686void
4687print_num_locno (const bpstat *bs, struct ui_out *uiout)
4688{
4689 struct breakpoint *b = bs->breakpoint_at;
4690
4691 if (b == nullptr)
4692 uiout->text (_("deleted breakpoint"));
4693 else
4694 {
4695 uiout->field_signed ("bkptno", b->number);
4696
4697 int locno = bpstat_locno (bs);
4698 if (locno != 0)
4699 uiout->message (".%pF", signed_field ("locno", locno));
4700 }
4701}
4702
4703/* See breakpoint.h. */
4704
4705void
4707{
4708 bpstat *bs;
4709
4710 if (inferior_ptid == null_ptid)
4711 return;
4712
4714 for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next)
4715 {
4716 bs->commands = NULL;
4717 bs->old_val.reset (nullptr);
4718 }
4719}
4720
4721/* Called when a command is about to proceed the inferior. */
4722
4723static void
4725{
4726 if (inferior_ptid != null_ptid)
4727 {
4728 struct thread_info *tp = inferior_thread ();
4729
4730 /* Allow inferior function calls in breakpoint commands to not
4731 interrupt the command list. When the call finishes
4732 successfully, the inferior will be standing at the same
4733 breakpoint as if nothing happened. */
4734 if (tp->control.in_infcall)
4735 return;
4736 }
4737
4739}
4740
4741/* Return true iff CMD as the first line of a command sequence is `silent'
4742 or its equivalent. */
4743
4744static bool
4746{
4747 return cmd && (strcmp ("silent", cmd->line) == 0);
4748}
4749
4750/* Sets the $_hit_bpnum and $_hit_locno to bpnum and locno.
4751 A locno 0 is changed to 1 to e.g. let the user do
4752 (gdb) disable $_hit_bpnum.$_hit_locno
4753 for a single location breakpoint. */
4754
4755static void
4756set_hit_convenience_vars (int bpnum, int locno)
4757{
4758 set_internalvar_integer (lookup_internalvar ("_hit_bpnum"), bpnum);
4760 (locno > 0 ? locno : 1));
4761}
4762
4763/* Execute all the commands associated with all the breakpoints at
4764 this location. Any of these commands could cause the process to
4765 proceed beyond this point, etc. We look out for such changes by
4766 checking the global "breakpoint_proceeded" after each command.
4767
4768 Returns true if a breakpoint command resumed the inferior. In that
4769 case, it is the caller's responsibility to recall it again with the
4770 bpstat of the current thread. */
4771
4772static bool
4774{
4775 bpstat *bs;
4776 bool again = false;
4777
4778 /* Avoid endless recursion if a `source' command is contained
4779 in bs->commands. */
4781 return false;
4782
4783 scoped_restore save_executing
4784 = make_scoped_restore (&executing_breakpoint_commands, 1);
4785
4786 scoped_restore preventer = prevent_dont_repeat ();
4787
4788 /* This pointer will iterate over the list of bpstat's. */
4789 bs = *bsp;
4790
4791 /* The $_hit_* convenience variables are set before running the
4792 commands of BS. In case we have several bs, after the loop,
4793 we set again the variables to the first printed bpnum and locno.
4794 For multiple breakpoints, this ensures the variables are set to the
4795 breakpoint printed for the user. */
4796 int printed_hit_bpnum = -1;
4797 int printed_hit_locno = -1;
4798
4800 for (; bs != NULL; bs = bs->next)
4801 {
4802 struct command_line *cmd = NULL;
4803
4804 /* Set the _hit_* convenience variables before running BS's commands. */
4805 {
4806 const struct breakpoint *b = bs->breakpoint_at;
4807 if (b != nullptr)
4808 {
4809 int locno = bpstat_locno (bs);
4810
4811 set_hit_convenience_vars (b->number, locno);
4812 if (printed_hit_locno == -1 && bs->print)
4813 {
4814 printed_hit_bpnum = b->number;
4815 printed_hit_locno = locno;
4816 }
4817 }
4818 }
4819
4820 /* Take ownership of the BSP's command tree, if it has one.
4821
4822 The command tree could legitimately contain commands like
4823 'step' and 'next', which call clear_proceed_status, which
4824 frees the bpstat BS and its command tree. To make sure this doesn't
4825 free the tree we're executing out from under us, we need to
4826 take ownership of the tree ourselves. Since a given bpstat's
4827 commands are only executed once, we don't need to copy it; we
4828 can clear the pointer in the bpstat, and make sure we free
4829 the tree when we're done. */
4830 counted_command_line ccmd = bs->commands;
4831 bs->commands = NULL;
4832 if (ccmd != NULL)
4833 cmd = ccmd.get ();
4834 if (command_line_is_silent (cmd))
4835 {
4836 /* The action has been already done by bpstat_stop_status. */
4837 cmd = cmd->next;
4838 }
4839
4840 while (cmd != NULL)
4841 {
4843 /* After execute_control_command, if breakpoint_proceeded is true,
4844 BS has been freed and cannot be accessed anymore. */
4845
4847 break;
4848 else
4849 cmd = cmd->next;
4850 }
4851
4853 {
4854 if (current_ui->async)
4855 /* If we are in async mode, then the target might be still
4856 running, not stopped at any breakpoint, so nothing for
4857 us to do here -- just return to the event loop. */
4858 ;
4859 else
4860 /* In sync mode, when execute_control_command returns
4861 we're already standing on the next breakpoint.
4862 Breakpoint commands for that stop were not run, since
4863 execute_command does not run breakpoint commands --
4864 only command_line_handler does, but that one is not
4865 involved in execution of breakpoint commands. So, we
4866 can now execute breakpoint commands. It should be
4867 noted that making execute_command do bpstat actions is
4868 not an option -- in this case we'll have recursive
4869 invocation of bpstat for each breakpoint with a
4870 command, and can easily blow up GDB stack. Instead, we
4871 return true, which will trigger the caller to recall us
4872 with the new stop_bpstat. */
4873 again = true;
4874 break;
4875 }
4876 }
4877
4878 /* Now that we have executed the commands of all bs, set the _hit_*
4879 convenience variables to the printed values. */
4880 if (printed_hit_locno != -1)
4881 set_hit_convenience_vars (printed_hit_bpnum, printed_hit_locno);
4882
4883 return again;
4884}
4885
4886/* Helper for bpstat_do_actions. Get the current thread, if there's
4887 one, is alive and has execution. Return NULL otherwise. */
4888
4889static thread_info *
4891{
4892 if (inferior_ptid == null_ptid || !target_has_execution ())
4893 return NULL;
4894
4896 if (tp->state == THREAD_EXITED || tp->executing ())
4897 return NULL;
4898 return tp;
4899}
4900
4901void
4903{
4904 auto cleanup_if_error = make_scope_exit (bpstat_clear_actions);
4905 thread_info *tp;
4906
4907 /* Do any commands attached to breakpoint we are stopped at. */
4908 while ((tp = get_bpstat_thread ()) != NULL)
4909 {
4910 /* Since in sync mode, bpstat_do_actions may resume the
4911 inferior, and only return when it is stopped at the next
4912 breakpoint, we keep doing breakpoint actions until it returns
4913 false to indicate the inferior was not resumed. */
4915 break;
4916 }
4917
4918 cleanup_if_error.release ();
4919}
4920
4921/* Print out the (old or new) value associated with a watchpoint. */
4922
4923static void
4924watchpoint_value_print (struct value *val, struct ui_file *stream)
4925{
4926 if (val == NULL)
4927 fprintf_styled (stream, metadata_style.style (), _("<unreadable>"));
4928 else
4929 {
4930 struct value_print_options opts;
4931 get_user_print_options (&opts);
4932 value_print (val, stream, &opts);
4933 }
4934}
4935
4936/* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4937 debugging multiple threads. */
4938
4939void
4941{
4942 if (uiout->is_mi_like_p ())
4943 return;
4944
4945 uiout->text ("\n");
4946
4948 {
4949 struct thread_info *thr = inferior_thread ();
4950
4951 uiout->text ("Thread ");
4952 uiout->field_string ("thread-id", print_thread_id (thr));
4953
4954 const char *name = thread_name (thr);
4955 if (name != NULL)
4956 {
4957 uiout->text (" \"");
4958 uiout->field_string ("name", name);
4959 uiout->text ("\"");
4960 }
4961
4962 uiout->text (" hit ");
4963 }
4964}
4965
4966/* Generic routine for printing messages indicating why we
4967 stopped. The behavior of this function depends on the value
4968 'print_it' in the bpstat structure. Under some circumstances we
4969 may decide not to print anything here and delegate the task to
4970 normal_stop(). */
4971
4972static enum print_stop_action
4974{
4975 switch (bs->print_it)
4976 {
4977 case print_it_noop:
4978 /* Nothing should be printed for this bpstat entry. */
4979 return PRINT_UNKNOWN;
4980 break;
4981
4982 case print_it_done:
4983 /* We still want to print the frame, but we already printed the
4984 relevant messages. */
4985 return PRINT_SRC_AND_LOC;
4986 break;
4987
4988 case print_it_normal:
4989 {
4990 struct breakpoint *b = bs->breakpoint_at;
4991
4992 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4993 which has since been deleted. */
4994 if (b == NULL)
4995 return PRINT_UNKNOWN;
4996
4997 /* Normal case. Call the breakpoint's print_it method. */
4998 return b->print_it (bs);
4999 }
5000 break;
5001
5002 default:
5003 internal_error (_("print_bp_stop_message: unrecognized enum value"));
5004 break;
5005 }
5006}
5007
5008/* See breakpoint.h. */
5009
5010void
5012{
5013 bool any_deleted = !current_program_space->deleted_solibs.empty ();
5014 bool any_added = !current_program_space->added_solibs.empty ();
5015
5016 if (!is_catchpoint)
5017 {
5018 if (any_added || any_deleted)
5019 current_uiout->text (_("Stopped due to shared library event:\n"));
5020 else
5021 current_uiout->text (_("Stopped due to shared library event (no "
5022 "libraries added or removed)\n"));
5023 }
5024
5025 if (current_uiout->is_mi_like_p ())
5026 current_uiout->field_string ("reason",
5028
5029 if (any_deleted)
5030 {
5031 current_uiout->text (_(" Inferior unloaded "));
5032 ui_out_emit_list list_emitter (current_uiout, "removed");
5033 for (int ix = 0; ix < current_program_space->deleted_solibs.size (); ix++)
5034 {
5035 const std::string &name = current_program_space->deleted_solibs[ix];
5036
5037 if (ix > 0)
5038 current_uiout->text (" ");
5039 current_uiout->field_string ("library", name);
5040 current_uiout->text ("\n");
5041 }
5042 }
5043
5044 if (any_added)
5045 {
5046 current_uiout->text (_(" Inferior loaded "));
5047 ui_out_emit_list list_emitter (current_uiout, "added");
5048 bool first = true;
5050 {
5051 if (!first)
5052 current_uiout->text (" ");
5053 first = false;
5054 current_uiout->field_string ("library", iter->so_name);
5055 current_uiout->text ("\n");
5056 }
5057 }
5058}
5059
5060/* Print a message indicating what happened. This is called from
5061 normal_stop(). The input to this routine is the head of the bpstat
5062 list - a list of the eventpoints that caused this stop. KIND is
5063 the target_waitkind for the stopping event. This
5064 routine calls the generic print routine for printing a message
5065 about reasons for stopping. This will print (for example) the
5066 "Breakpoint n," part of the output. The return value of this
5067 routine is one of:
5068
5069 PRINT_UNKNOWN: Means we printed nothing.
5070 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
5071 code to print the location. An example is
5072 "Breakpoint 1, " which should be followed by
5073 the location.
5074 PRINT_SRC_ONLY: Means we printed something, but there is no need
5075 to also print the location part of the message.
5076 An example is the catch/throw messages, which
5077 don't require a location appended to the end.
5078 PRINT_NOTHING: We have done some printing and we don't need any
5079 further info to be printed. */
5080
5083{
5084 enum print_stop_action val;
5085
5086 /* Maybe another breakpoint in the chain caused us to stop.
5087 (Currently all watchpoints go on the bpstat whether hit or not.
5088 That probably could (should) be changed, provided care is taken
5089 with respect to bpstat_explains_signal). */
5090 for (; bs; bs = bs->next)
5091 {
5092 val = print_bp_stop_message (bs);
5093 if (val == PRINT_SRC_ONLY
5094 || val == PRINT_SRC_AND_LOC
5095 || val == PRINT_NOTHING)
5096 return val;
5097 }
5098
5099 /* If we had hit a shared library event breakpoint,
5100 print_bp_stop_message would print out this message. If we hit an
5101 OS-level shared library event, do the same thing. */
5102 if (kind == TARGET_WAITKIND_LOADED)
5103 {
5104 print_solib_event (false);
5105 return PRINT_NOTHING;
5106 }
5107
5108 /* We reached the end of the chain, or we got a null BS to start
5109 with and nothing was printed. */
5110 return PRINT_UNKNOWN;
5111}
5112
5113/* Evaluate the boolean expression EXP and return the result. */
5114
5115static bool
5117{
5118 scoped_value_mark mark;
5119 return value_true (exp->evaluate ());
5120}
5121
5122/* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
5123
5124bpstat::bpstat (struct bp_location *bl, bpstat ***bs_link_pointer)
5125 : next (NULL),
5126 bp_location_at (bp_location_ref_ptr::new_reference (bl)),
5127 breakpoint_at (bl->owner),
5128 commands (NULL),
5129 print (0),
5130 stop (0),
5132{
5133 **bs_link_pointer = this;
5134 *bs_link_pointer = &next;
5135}
5136
5138 : next (NULL),
5139 breakpoint_at (NULL),
5140 commands (NULL),
5141 print (0),
5142 stop (0),
5144{
5145}
5146
5147/* The target has stopped with waitstatus WS. Check if any hardware
5148 watchpoints have triggered, according to the target. */
5149
5150int
5152{
5153 bool stopped_by_watchpoint = target_stopped_by_watchpoint ();
5154 CORE_ADDR addr;
5155
5156 if (!stopped_by_watchpoint)
5157 {
5158 /* We were not stopped by a watchpoint. Mark all watchpoints
5159 as not triggered. */
5160 for (breakpoint &b : all_breakpoints ())
5161 if (is_hardware_watchpoint (&b))
5162 {
5163 watchpoint &w = gdb::checked_static_cast<watchpoint &> (b);
5164
5166 }
5167
5168 return 0;
5169 }
5170
5171 if (!target_stopped_data_address (current_inferior ()->top_target (), &addr))
5172 {
5173 /* We were stopped by a watchpoint, but we don't know where.
5174 Mark all watchpoints as unknown. */
5175 for (breakpoint &b : all_breakpoints ())
5176 if (is_hardware_watchpoint (&b))
5177 {
5178 watchpoint &w = gdb::checked_static_cast<watchpoint &> (b);
5179
5181 }
5182
5183 return 1;
5184 }
5185
5186 /* The target could report the data address. Mark watchpoints
5187 affected by this data address as triggered, and all others as not
5188 triggered. */
5189
5190 for (breakpoint &b : all_breakpoints ())
5191 if (is_hardware_watchpoint (&b))
5192 {
5193 watchpoint &w = gdb::checked_static_cast<watchpoint &> (b);
5194
5196 for (bp_location &loc : b.locations ())
5197 {
5198 if (is_masked_watchpoint (&b))
5199 {
5200 CORE_ADDR newaddr = addr & w.hw_wp_mask;
5201 CORE_ADDR start = loc.address & w.hw_wp_mask;
5202
5203 if (newaddr == start)
5204 {
5206 break;
5207 }
5208 }
5209 /* Exact match not required. Within range is sufficient. */
5211 (current_inferior ()->top_target (), addr, loc.address,
5212 loc.length))
5213 {
5215 break;
5216 }
5217 }
5218 }
5219
5220 return 1;
5221}
5222
5223/* Possible return values for watchpoint_check. */
5225 {
5226 /* The watchpoint has been deleted. */
5228
5229 /* The value has changed. */
5231
5232 /* The value has not changed. */
5234
5235 /* Ignore this watchpoint, no matter if the value changed or not. */
5237 };
5238
5239#define BP_TEMPFLAG 1
5240#define BP_HARDWAREFLAG 2
5241
5242/* Evaluate watchpoint condition expression and check if its value
5243 changed. */
5244
5245static wp_check_result
5247{
5248 frame_info_ptr fr;
5249 bool within_current_scope;
5250
5251 /* BS is built from an existing struct breakpoint. */
5252 gdb_assert (bs->breakpoint_at != NULL);
5253 watchpoint *b = gdb::checked_static_cast<watchpoint *> (bs->breakpoint_at);
5254
5255 /* If this is a local watchpoint, we only want to check if the
5256 watchpoint frame is in scope if the current thread is the thread
5257 that was used to create the watchpoint. */
5259 return WP_IGNORE;
5260
5261 if (b->exp_valid_block == NULL)
5262 within_current_scope = true;
5263 else
5264 {
5266 struct gdbarch *frame_arch = get_frame_arch (frame);
5267 CORE_ADDR frame_pc = get_frame_pc (frame);
5268
5269 /* stack_frame_destroyed_p() returns a non-zero value if we're
5270 still in the function but the stack frame has already been
5271 invalidated. Since we can't rely on the values of local
5272 variables after the stack has been destroyed, we are treating
5273 the watchpoint in that state as `not changed' without further
5274 checking. Don't mark watchpoints as changed if the current
5275 frame is in an epilogue - even if they are in some other
5276 frame, our view of the stack is likely to be wrong and
5277 frame_find_by_id could error out. */
5278 if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc))
5279 return WP_IGNORE;
5280
5282 within_current_scope = (fr != NULL);
5283
5284 /* If we've gotten confused in the unwinder, we might have
5285 returned a frame that can't describe this variable. */
5286 if (within_current_scope)
5287 {
5288 struct symbol *function;
5289
5290 function = get_frame_function (fr);
5291 if (function == NULL
5292 || !function->value_block ()->contains (b->exp_valid_block))
5293 within_current_scope = false;
5294 }
5295
5296 if (within_current_scope)
5297 /* If we end up stopping, the current frame will get selected
5298 in normal_stop. So this call to select_frame won't affect
5299 the user. */
5300 select_frame (fr);
5301 }
5302
5303 if (within_current_scope)
5304 {
5305 /* We use value_{,free_to_}mark because it could be a *long*
5306 time before we return to the command level and call
5307 free_all_values. We can't call free_all_values because we
5308 might be in the middle of evaluating a function call. */
5309
5310 struct value *mark;
5311 struct value *new_val;
5312
5313 if (is_masked_watchpoint (b))
5314 /* Since we don't know the exact trigger address (from
5315 stopped_data_address), just tell the user we've triggered
5316 a mask watchpoint. */
5317 return WP_VALUE_CHANGED;
5318
5319 mark = value_mark ();
5320 fetch_subexp_value (b->exp.get (), b->exp->op.get (), &new_val,
5321 NULL, NULL, false);
5322
5323 if (b->val_bitsize != 0)
5324 new_val = extract_bitfield_from_watchpoint_value (b, new_val);
5325
5326 /* We use value_equal_contents instead of value_equal because
5327 the latter coerces an array to a pointer, thus comparing just
5328 the address of the array instead of its contents. This is
5329 not what we want. */
5330 if ((b->val != NULL) != (new_val != NULL)
5331 || (b->val != NULL && !value_equal_contents (b->val.get (),
5332 new_val)))
5333 {
5334 bs->old_val = b->val;
5335 b->val = release_value (new_val);
5336 b->val_valid = true;
5337 if (new_val != NULL)
5338 value_free_to_mark (mark);
5339 return WP_VALUE_CHANGED;
5340 }
5341 else
5342 {
5343 /* Nothing changed. */
5344 value_free_to_mark (mark);
5345 return WP_VALUE_NOT_CHANGED;
5346 }
5347 }
5348 else
5349 {
5350 /* This seems like the only logical thing to do because
5351 if we temporarily ignored the watchpoint, then when
5352 we reenter the block in which it is valid it contains
5353 garbage (in the case of a function, it may have two
5354 garbage values, one before and one after the prologue).
5355 So we can't even detect the first assignment to it and
5356 watch after that (since the garbage may or may not equal
5357 the first value assigned). */
5358 /* We print all the stop information in
5359 breakpointprint_it, but in this case, by the time we
5360 call breakpoint->print_it this bp will be deleted
5361 already. So we have no choice but print the information
5362 here. */
5363
5365 {
5366 struct ui_out *uiout = current_uiout;
5367
5368 if (uiout->is_mi_like_p ())
5369 uiout->field_string
5371 uiout->message ("\nWatchpoint %pF deleted because the program has "
5372 "left the block in\n"
5373 "which its expression is valid.\n",
5374 signed_field ("wpnum", b->number));
5375 }
5376
5377 /* Make sure the watchpoint's commands aren't executed. */
5378 b->commands = NULL;
5380
5381 return WP_DELETED;
5382 }
5383}
5384
5385/* Return true if it looks like target has stopped due to hitting
5386 breakpoint location BL. This function does not check if we should
5387 stop, only if BL explains the stop. */
5388
5389static bool
5391 const address_space *aspace, CORE_ADDR bp_addr,
5392 const target_waitstatus &ws)
5393{
5394 struct breakpoint *b = bl->owner;
5395
5396 /* BL is from an existing breakpoint. */
5397 gdb_assert (b != NULL);
5398
5399 return b->breakpoint_hit (bl, aspace, bp_addr, ws);
5400}
5401
5402/* Determine if the watched values have actually changed, and we
5403 should stop. If not, set BS->stop to false. */
5404
5405static void
5407{
5408 const struct bp_location *bl;
5409
5410 /* BS is built for existing struct breakpoint. */
5411 bl = bs->bp_location_at.get ();
5412 gdb_assert (bl != NULL);
5413 watchpoint *b = gdb::checked_static_cast<watchpoint *> (bs->breakpoint_at);
5414
5415 bool must_check_value = false;
5416
5417 if (b->type == bp_watchpoint)
5418 /* For a software watchpoint, we must always check the
5419 watched value. */
5420 must_check_value = true;
5422 /* We have a hardware watchpoint (read, write, or access)
5423 and the target earlier reported an address watched by
5424 this watchpoint. */
5425 must_check_value = true;
5428 /* We were stopped by a hardware watchpoint, but the target could
5429 not report the data address. We must check the watchpoint's
5430 value. Access and read watchpoints are out of luck; without
5431 a data address, we can't figure it out. */
5432 must_check_value = true;
5433
5434 if (must_check_value)
5435 {
5437
5438 try
5439 {
5440 e = watchpoint_check (bs);
5441 }
5442 catch (const gdb_exception_error &ex)
5443 {
5445 "Error evaluating expression "
5446 "for watchpoint %d\n",
5447 b->number);
5448
5450 {
5451 gdb_printf (_("Watchpoint %d deleted.\n"),
5452 b->number);
5453 }
5455 e = WP_DELETED;
5456 }
5457
5458 switch (e)
5459 {
5460 case WP_DELETED:
5461 /* We've already printed what needs to be printed. */
5462 bs->print_it = print_it_done;
5463 /* Stop. */
5464 break;
5465 case WP_IGNORE:
5466 bs->print_it = print_it_noop;
5467 bs->stop = false;
5468 break;
5469 case WP_VALUE_CHANGED:
5470 if (b->type == bp_read_watchpoint)
5471 {
5472 /* There are two cases to consider here:
5473
5474 1. We're watching the triggered memory for reads.
5475 In that case, trust the target, and always report
5476 the watchpoint hit to the user. Even though
5477 reads don't cause value changes, the value may
5478 have changed since the last time it was read, and
5479 since we're not trapping writes, we will not see
5480 those, and as such we should ignore our notion of
5481 old value.
5482
5483 2. We're watching the triggered memory for both
5484 reads and writes. There are two ways this may
5485 happen:
5486
5487 2.1. This is a target that can't break on data
5488 reads only, but can break on accesses (reads or
5489 writes), such as e.g., x86. We detect this case
5490 at the time we try to insert read watchpoints.
5491
5492 2.2. Otherwise, the target supports read
5493 watchpoints, but, the user set an access or write
5494 watchpoint watching the same memory as this read
5495 watchpoint.
5496
5497 If we're watching memory writes as well as reads,
5498 ignore watchpoint hits when we find that the
5499 value hasn't changed, as reads don't cause
5500 changes. This still gives false positives when
5501 the program writes the same value to memory as
5502 what there was already in memory (we will confuse
5503 it for a read), but it's much better than
5504 nothing. */
5505
5506 int other_write_watchpoint = 0;
5507
5508 if (bl->watchpoint_type == hw_read)
5509 {
5510 for (breakpoint &other_b : all_breakpoints ())
5511 if (other_b.type == bp_hardware_watchpoint
5512 || other_b.type == bp_access_watchpoint)
5513 {
5514 watchpoint &other_w =
5515 gdb::checked_static_cast<watchpoint &> (other_b);
5516
5517 if (other_w.watchpoint_triggered
5519 {
5520 other_write_watchpoint = 1;
5521 break;
5522 }
5523 }
5524 }
5525
5526 if (other_write_watchpoint
5527 || bl->watchpoint_type == hw_access)
5528 {
5529 /* We're watching the same memory for writes,
5530 and the value changed since the last time we
5531 updated it, so this trap must be for a write.
5532 Ignore it. */
5533 bs->print_it = print_it_noop;
5534 bs->stop = false;
5535 }
5536 }
5537 break;
5540 || b->type == bp_watchpoint)
5541 {
5542 /* Don't stop: write watchpoints shouldn't fire if
5543 the value hasn't changed. */
5544 bs->print_it = print_it_noop;
5545 bs->stop = false;
5546 }
5547 /* Stop. */
5548 break;
5549 default:
5550 /* Can't happen. */
5551 break;
5552 }
5553 }
5554 else /* !must_check_value */
5555 {
5556 /* This is a case where some watchpoint(s) triggered, but
5557 not at the address of this watchpoint, or else no
5558 watchpoint triggered after all. So don't print
5559 anything for this watchpoint. */
5560 bs->print_it = print_it_noop;
5561 bs->stop = false;
5562 }
5563}
5564
5565/* For breakpoints that are currently marked as telling gdb to stop,
5566 check conditions (condition proper, frame, thread and ignore count)
5567 of breakpoint referred to by BS. If we should not stop for this
5568 breakpoint, set BS->stop to 0. */
5569
5570static void
5572{
5574
5575 const struct bp_location *bl;
5576 struct breakpoint *b;
5577 /* Assume stop. */
5578 bool condition_result = true;
5579 struct expression *cond;
5580
5581 gdb_assert (bs->stop);
5582
5583 /* BS is built for existing struct breakpoint. */
5584 bl = bs->bp_location_at.get ();
5585 gdb_assert (bl != NULL);
5586 b = bs->breakpoint_at;
5587 gdb_assert (b != NULL);
5588
5589 infrun_debug_printf ("thread = %s, breakpoint %d.%d",
5590 thread->ptid.to_string ().c_str (),
5592
5593 /* Even if the target evaluated the condition on its end and notified GDB, we
5594 need to do so again since GDB does not know if we stopped due to a
5595 breakpoint or a single step breakpoint. */
5596
5597 if (frame_id_p (b->frame_id)
5599 {
5600 infrun_debug_printf ("incorrect frame %s not %s, not stopping",
5602 b->frame_id.to_string ().c_str ());
5603 bs->stop = false;
5604 return;
5605 }
5606
5607 /* If this is a thread/task-specific breakpoint, don't waste cpu
5608 evaluating the condition if this isn't the specified
5609 thread/task. */
5610 if ((b->thread != -1 && b->thread != thread->global_num)
5611 || (b->inferior != -1 && b->inferior != thread->inf->num)
5612 || (b->task != -1 && b->task != ada_get_task_number (thread)))
5613 {
5614 infrun_debug_printf ("incorrect thread or task, not stopping");
5615 bs->stop = false;
5616 return;
5617 }
5618
5619 /* Evaluate extension language breakpoints that have a "stop" method
5620 implemented. */
5622
5623 if (is_watchpoint (b))
5624 {
5625 watchpoint *w = gdb::checked_static_cast<watchpoint *> (b);
5626
5627 cond = w->cond_exp.get ();
5628 }
5629 else
5630 cond = bl->cond.get ();
5631
5632 if (cond != nullptr && b->disposition != disp_del_at_next_stop)
5633 {
5634 bool within_current_scope = true;
5635
5636 /* We use scoped_value_mark because it could be a long time
5637 before we return to the command level and call
5638 free_all_values. We can't call free_all_values because we
5639 might be in the middle of evaluating a function call. */
5640 scoped_value_mark mark;
5641
5642 watchpoint *w = nullptr;
5643 if (is_watchpoint (b))
5644 w = gdb::checked_static_cast<watchpoint *> (b);
5645
5646 /* Need to select the frame, with all that implies so that
5647 the conditions will have the right context. Because we
5648 use the frame, we will not see an inlined function's
5649 variables when we arrive at a breakpoint at the start
5650 of the inlined function; the current frame will be the
5651 call site. */
5652 if (w == NULL || w->cond_exp_valid_block == NULL)
5654 else
5655 {
5656 frame_info_ptr frame;
5657
5658 /* For local watchpoint expressions, which particular
5659 instance of a local is being watched matters, so we
5660 keep track of the frame to evaluate the expression
5661 in. To evaluate the condition however, it doesn't
5662 really matter which instantiation of the function
5663 where the condition makes sense triggers the
5664 watchpoint. This allows an expression like "watch
5665 global if q > 10" set in `func', catch writes to
5666 global on all threads that call `func', or catch
5667 writes on all recursive calls of `func' by a single
5668 thread. We simply always evaluate the condition in
5669 the innermost frame that's executing where it makes
5670 sense to evaluate the condition. It seems
5671 intuitive. */
5673 if (frame != NULL)
5674 select_frame (frame);
5675 else
5676 within_current_scope = false;
5677 }
5678 if (within_current_scope)
5679 {
5680 try
5681 {
5682 condition_result = breakpoint_cond_eval (cond);
5683 }
5684 catch (const gdb_exception_error &ex)
5685 {
5686 int locno = bpstat_locno (bs);
5687 if (locno != 0)
5689 (gdb_stderr, ex,
5690 "Error in testing condition for breakpoint %d.%d:\n",
5691 b->number, locno);
5692 else
5694 (gdb_stderr, ex,
5695 "Error in testing condition for breakpoint %d:\n",
5696 b->number);
5697 }
5698 }
5699 else
5700 {
5701 warning (_("Watchpoint condition cannot be tested "
5702 "in the current scope"));
5703 /* If we failed to set the right context for this
5704 watchpoint, unconditionally report it. */
5705 }
5706 /* FIXME-someday, should give breakpoint #. */
5707 }
5708
5709 if (cond != nullptr && !condition_result)
5710 {
5711 infrun_debug_printf ("condition_result = false, not stopping");
5712 bs->stop = false;
5713 return;
5714 }
5715 else if (b->ignore_count > 0)
5716 {
5717 infrun_debug_printf ("ignore count %d, not stopping",
5718 b->ignore_count);
5719 b->ignore_count--;
5720 bs->stop = false;
5721 /* Increase the hit count even though we don't stop. */
5722 ++(b->hit_count);
5724 return;
5725 }
5726
5727 if (bs->stop)
5728 infrun_debug_printf ("stopping at this breakpoint");
5729 else
5730 infrun_debug_printf ("not stopping at this breakpoint");
5731}
5732
5733/* Returns true if we need to track moribund locations of LOC's type
5734 on the current target. */
5735
5736static bool
5744
5745/* See breakpoint.h. */
5746
5747bpstat *
5748build_bpstat_chain (const address_space *aspace, CORE_ADDR bp_addr,
5749 const target_waitstatus &ws)
5750{
5751 bpstat *bs_head = nullptr, **bs_link = &bs_head;
5752
5753 for (breakpoint &b : all_breakpoints ())
5754 {
5755 if (!breakpoint_enabled (&b))
5756 continue;
5757
5758 for (bp_location &bl : b.locations ())
5759 {
5760 /* For hardware watchpoints, we look only at the first
5761 location. The watchpoint_check function will work on the
5762 entire expression, not the individual locations. For
5763 read watchpoints, the watchpoints_triggered function has
5764 checked all locations already. */
5765 if (b.type == bp_hardware_watchpoint && &bl != &b.first_loc ())
5766 break;
5767
5768 if (!bl.enabled || bl.disabled_by_cond || bl.shlib_disabled)
5769 continue;
5770
5771 if (!bpstat_check_location (&bl, aspace, bp_addr, ws))
5772 continue;
5773
5774 /* Come here if it's a watchpoint, or if the break address
5775 matches. */
5776
5777 bpstat *bs = new bpstat (&bl, &bs_link); /* Alloc a bpstat to
5778 explain stop. */
5779
5780 /* Assume we stop. Should we find a watchpoint that is not
5781 actually triggered, or if the condition of the breakpoint
5782 evaluates as false, we'll reset 'stop' to 0. */
5783 bs->stop = true;
5784 bs->print = true;
5785
5786 /* If this is a scope breakpoint, mark the associated
5787 watchpoint as triggered so that we will handle the
5788 out-of-scope event. We'll get to the watchpoint next
5789 iteration. */
5790 if (b.type == bp_watchpoint_scope && b.related_breakpoint != &b)
5791 {
5792 watchpoint *w
5793 = gdb::checked_static_cast<watchpoint *> (b.related_breakpoint);
5794
5796 }
5797 }
5798 }
5799
5800 /* Check if a moribund breakpoint explains the stop. */
5803 {
5805 {
5806 if (breakpoint_location_address_match (loc, aspace, bp_addr)
5808 {
5809 bpstat *bs = new bpstat (loc, &bs_link);
5810 /* For hits of moribund locations, we should just proceed. */
5811 bs->stop = false;
5812 bs->print = false;
5813 bs->print_it = print_it_noop;
5814 }
5815 }
5816 }
5817
5818 return bs_head;
5819}
5820
5821/* See breakpoint.h. */
5822
5823bpstat *
5825 CORE_ADDR bp_addr, thread_info *thread,
5826 const target_waitstatus &ws,
5827 bpstat *stop_chain)
5828{
5829 struct breakpoint *b = NULL;
5830 /* First item of allocated bpstat's. */
5831 bpstat *bs_head = stop_chain;
5832 bpstat *bs;
5833 int need_remove_insert;
5834 int removed_any;
5835
5836 /* First, build the bpstat chain with locations that explain a
5837 target stop, while being careful to not set the target running,
5838 as that may invalidate locations (in particular watchpoint
5839 locations are recreated). Resuming will happen here with
5840 breakpoint conditions or watchpoint expressions that include
5841 inferior function calls. */
5842 if (bs_head == NULL)
5843 bs_head = build_bpstat_chain (aspace, bp_addr, ws);
5844
5845 /* A bit of special processing for shlib breakpoints. We need to
5846 process solib loading here, so that the lists of loaded and
5847 unloaded libraries are correct before we handle "catch load" and
5848 "catch unload". */
5849 for (bs = bs_head; bs != NULL; bs = bs->next)
5850 {
5852 {
5854 break;
5855 }
5856 }
5857
5858 /* Now go through the locations that caused the target to stop, and
5859 check whether we're interested in reporting this stop to higher
5860 layers, or whether we should resume the target transparently. */
5861
5862 removed_any = 0;
5863
5864 for (bs = bs_head; bs != NULL; bs = bs->next)
5865 {
5866 if (!bs->stop)
5867 continue;
5868
5869 b = bs->breakpoint_at;
5870 b->check_status (bs);
5871 if (bs->stop)
5872 {
5874
5875 if (bs->stop)
5876 {
5877 ++(b->hit_count);
5878
5879 /* We will stop here. */
5880 if (b->disposition == disp_disable)
5881 {
5882 --(b->enable_count);
5883 if (b->enable_count <= 0)
5885 removed_any = 1;
5886 }
5888 if (b->silent)
5889 bs->print = false;
5890 bs->commands = b->commands;
5892 ? bs->commands.get () : NULL))
5893 bs->print = false;
5894
5895 b->after_condition_true (bs);
5896 }
5897
5898 }
5899
5900 /* Print nothing for this entry if we don't stop or don't
5901 print. */
5902 if (!bs->stop || !bs->print)
5903 bs->print_it = print_it_noop;
5904 }
5905
5906 /* If we aren't stopping, the value of some hardware watchpoint may
5907 not have changed, but the intermediate memory locations we are
5908 watching may have. Don't bother if we're stopping; this will get
5909 done later. */
5910 need_remove_insert = 0;
5911 if (! bpstat_causes_stop (bs_head))
5912 for (bs = bs_head; bs != NULL; bs = bs->next)
5913 if (!bs->stop
5914 && bs->breakpoint_at
5916 {
5917 watchpoint *w
5918 = gdb::checked_static_cast<watchpoint *> (bs->breakpoint_at);
5919
5920 update_watchpoint (w, false /* don't reparse. */);
5921 need_remove_insert = 1;
5922 }
5923
5924 if (need_remove_insert)
5926 else if (removed_any)
5928
5929 return bs_head;
5930}
5931
5932/* See breakpoint.h. */
5933
5934bpstat *
5935bpstat_stop_status_nowatch (const address_space *aspace, CORE_ADDR bp_addr,
5937{
5938 gdb_assert (!target_stopped_by_watchpoint ());
5939
5940 /* Clear all watchpoints' 'watchpoint_triggered' value from a
5941 previous stop to avoid confusing bpstat_stop_status. */
5943
5944 return bpstat_stop_status (aspace, bp_addr, thread, ws);
5945}
5946
5947static void
5948handle_jit_event (CORE_ADDR address)
5949{
5950 struct gdbarch *gdbarch;
5951
5952 infrun_debug_printf ("handling bp_jit_event");
5953
5954 /* Switch terminal for any messages produced by
5955 breakpoint_re_set. */
5957
5959 /* This event is caused by a breakpoint set in `jit_breakpoint_re_set`,
5960 thus it is expected that its objectfile can be found through
5961 minimal symbol lookup. If it doesn't work (and assert fails), it
5962 most likely means that `jit_breakpoint_re_set` was changes and this
5963 function needs to be updated too. */
5965 gdb_assert (jit_bp_sym.objfile != nullptr);
5966 objfile *objfile = jit_bp_sym.objfile;
5970
5972}
5973
5974/* Prepare WHAT final decision for infrun. */
5975
5976/* Decide what infrun needs to do with this bpstat. */
5977
5978struct bpstat_what
5980{
5981 struct bpstat_what retval;
5982 bpstat *bs;
5983
5985 retval.call_dummy = STOP_NONE;
5986 retval.is_longjmp = false;
5987
5988 for (bs = bs_head; bs != NULL; bs = bs->next)
5989 {
5990 /* Extract this BS's action. After processing each BS, we check
5991 if its action overrides all we've seem so far. */
5993 enum bptype bptype;
5994
5995 if (bs->breakpoint_at == NULL)
5996 {
5997 /* I suspect this can happen if it was a momentary
5998 breakpoint which has since been deleted. */
5999 bptype = bp_none;
6000 }
6001 else
6002 bptype = bs->breakpoint_at->type;
6003
6004 switch (bptype)
6005 {
6006 case bp_none:
6007 break;
6008 case bp_breakpoint:
6010 case bp_single_step:
6011 case bp_until:
6012 case bp_finish:
6013 case bp_shlib_event:
6014 if (bs->stop)
6015 {
6016 if (bs->print)
6017 this_action = BPSTAT_WHAT_STOP_NOISY;
6018 else
6019 this_action = BPSTAT_WHAT_STOP_SILENT;
6020 }
6021 else
6022 this_action = BPSTAT_WHAT_SINGLE;
6023 break;
6024 case bp_watchpoint:
6026 case bp_read_watchpoint:
6028 if (bs->stop)
6029 {
6030 if (bs->print)
6031 this_action = BPSTAT_WHAT_STOP_NOISY;
6032 else
6033 this_action = BPSTAT_WHAT_STOP_SILENT;
6034 }
6035 else
6036 {
6037 /* There was a watchpoint, but we're not stopping.
6038 This requires no further action. */
6039 }
6040 break;
6041 case bp_longjmp:
6043 case bp_exception:
6044 if (bs->stop)
6045 {
6046 this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME;
6047 retval.is_longjmp = bptype != bp_exception;
6048 }
6049 else
6050 this_action = BPSTAT_WHAT_SINGLE;
6051 break;
6052 case bp_longjmp_resume:
6054 if (bs->stop)
6055 {
6058 }
6059 else
6060 this_action = BPSTAT_WHAT_SINGLE;
6061 break;
6062 case bp_step_resume:
6063 if (bs->stop)
6064 this_action = BPSTAT_WHAT_STEP_RESUME;
6065 else
6066 {
6067 /* It is for the wrong frame. */
6068 this_action = BPSTAT_WHAT_SINGLE;
6069 }
6070 break;
6071 case bp_hp_step_resume:
6072 if (bs->stop)
6073 this_action = BPSTAT_WHAT_HP_STEP_RESUME;
6074 else
6075 {
6076 /* It is for the wrong frame. */
6077 this_action = BPSTAT_WHAT_SINGLE;
6078 }
6079 break;
6081 case bp_thread_event:
6082 case bp_overlay_event:
6083 case bp_longjmp_master:
6086 this_action = BPSTAT_WHAT_SINGLE;
6087 break;
6088 case bp_catchpoint:
6089 if (bs->stop)
6090 {
6091 if (bs->print)
6092 this_action = BPSTAT_WHAT_STOP_NOISY;
6093 else
6094 this_action = BPSTAT_WHAT_STOP_SILENT;
6095 }
6096 else
6097 {
6098 /* Some catchpoints are implemented with breakpoints.
6099 For those, we need to step over the breakpoint. */
6100 if (bs->bp_location_at->loc_type == bp_loc_software_breakpoint
6101 || bs->bp_location_at->loc_type == bp_loc_hardware_breakpoint)
6102 this_action = BPSTAT_WHAT_SINGLE;
6103 }
6104 break;
6105 case bp_jit_event:
6106 this_action = BPSTAT_WHAT_SINGLE;
6107 break;
6108 case bp_call_dummy:
6109 /* Make sure the action is stop (silent or noisy),
6110 so infrun.c pops the dummy frame. */
6112 this_action = BPSTAT_WHAT_STOP_SILENT;
6113 break;
6114 case bp_std_terminate:
6115 /* Make sure the action is stop (silent or noisy),
6116 so infrun.c pops the dummy frame. */
6118 this_action = BPSTAT_WHAT_STOP_SILENT;
6119 break;
6120 case bp_tracepoint:
6121 case bp_fast_tracepoint:
6124 /* Tracepoint hits should not be reported back to GDB, and
6125 if one got through somehow, it should have been filtered
6126 out already. */
6127 internal_error (_("bpstat_what: tracepoint encountered"));
6128 break;
6130 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
6131 this_action = BPSTAT_WHAT_SINGLE;
6132 break;
6134 /* The breakpoint will be removed, execution will restart from the
6135 PC of the former breakpoint. */
6136 this_action = BPSTAT_WHAT_KEEP_CHECKING;
6137 break;
6138
6139 case bp_dprintf:
6140 if (bs->stop)
6141 this_action = BPSTAT_WHAT_STOP_SILENT;
6142 else
6143 this_action = BPSTAT_WHAT_SINGLE;
6144 break;
6145
6146 default:
6147 internal_error (_("bpstat_what: unhandled bptype %d"), (int) bptype);
6148 }
6149
6150 retval.main_action = std::max (retval.main_action, this_action);
6151 }
6152
6153 return retval;
6154}
6155
6156void
6158{
6159 bpstat *bs;
6160
6161 for (bs = bs_head; bs != NULL; bs = bs->next)
6162 {
6163 struct breakpoint *b = bs->breakpoint_at;
6164
6165 if (b == NULL)
6166 continue;
6167 switch (b->type)
6168 {
6169 case bp_jit_event:
6170 handle_jit_event (bs->bp_location_at->address);
6171 break;
6174 (gdb::checked_static_cast<code_breakpoint *> (b));
6175 break;
6178 (gdb::checked_static_cast<code_breakpoint *> (b));
6179 break;
6180 }
6181 }
6182}
6183
6184/* See breakpoint.h. */
6185
6186bool
6188{
6189 for (breakpoint &b : all_breakpoints ())
6190 if (breakpoint_enabled (&b)
6191 && b.type == bp_watchpoint
6192 && b.has_locations ())
6193 return true;
6194
6195 return false;
6196}
6197
6198/* See breakpoint.h. */
6199
6200bool
6202{
6203 for (; bs != NULL; bs = bs->next)
6204 if (bs->stop)
6205 return true;
6206
6207 return false;
6208}
6209
6210
6211
6212/* Compute a number of spaces suitable to indent the next line
6213 so it starts at the position corresponding to the table column
6214 named COL_NAME in the currently active table of UIOUT. */
6215
6216static int
6217wrap_indent_at_field (struct ui_out *uiout, const char *col_name)
6218{
6219 int i, total_width, width, align;
6220 const char *text;
6221
6222 total_width = 0;
6223 for (i = 1; uiout->query_table_field (i, &width, &align, &text); i++)
6224 {
6225 if (strcmp (text, col_name) == 0)
6226 return total_width;
6227
6228 total_width += width + 1;
6229 }
6230
6231 return 0;
6232}
6233
6234/* Determine if the locations of this breakpoint will have their conditions
6235 evaluated by the target, host or a mix of both. Returns the following:
6236
6237 "host": Host evals condition.
6238 "host or target": Host or Target evals condition.
6239 "target": Target evals condition.
6240*/
6241
6242static const char *
6244{
6245 char host_evals = 0;
6246 char target_evals = 0;
6247
6248 if (!b)
6249 return NULL;
6250
6251 if (!is_breakpoint (b))
6252 return NULL;
6253
6257
6258 for (bp_location &bl : b->locations ())
6259 {
6260 if (bl.cond_bytecode)
6261 target_evals++;
6262 else
6263 host_evals++;
6264 }
6265
6266 if (host_evals && target_evals)
6268 else if (target_evals)
6270 else
6272}
6273
6274/* Determine the breakpoint location's condition evaluator. This is
6275 similar to bp_condition_evaluator, but for locations. */
6276
6277static const char *
6279{
6280 if (bl && !is_breakpoint (bl->owner))
6281 return NULL;
6282
6286
6287 if (bl && bl->cond_bytecode)
6289 else
6291}
6292
6293/* Print the LOC location out of the list of B->LOC locations. */
6294
6295static void
6297{
6298 struct ui_out *uiout = current_uiout;
6299
6301
6302 if (loc != NULL && loc->shlib_disabled)
6303 loc = NULL;
6304
6305 if (loc != NULL)
6307
6308 if (b->display_canonical)
6309 uiout->field_string ("what", b->locspec->to_string ());
6310 else if (loc && loc->symtab)
6311 {
6312 const struct symbol *sym = loc->symbol;
6313
6314 if (sym)
6315 {
6316 uiout->text ("in ");
6317 uiout->field_string ("func", sym->print_name (),
6319 uiout->text (" ");
6320 uiout->wrap_hint (wrap_indent_at_field (uiout, "what"));
6321 uiout->text ("at ");
6322 }
6323 uiout->field_string ("file",
6326 uiout->text (":");
6327
6328 if (uiout->is_mi_like_p ())
6329 uiout->field_string ("fullname", symtab_to_fullname (loc->symtab));
6330
6331 uiout->field_signed ("line", loc->line_number);
6332 }
6333 else if (loc)
6334 {
6335 string_file stb;
6336
6337 print_address_symbolic (loc->gdbarch, loc->address, &stb,
6338 demangle, "");
6339 uiout->field_stream ("at", stb);
6340 }
6341 else
6342 {
6343 uiout->field_string ("pending", b->locspec->to_string ());
6344 /* If extra_string is available, it could be holding a condition
6345 or dprintf arguments. In either case, make sure it is printed,
6346 too, but only for non-MI streams. */
6347 if (!uiout->is_mi_like_p () && b->extra_string != NULL)
6348 {
6349 if (b->type == bp_dprintf)
6350 uiout->text (",");
6351 else
6352 uiout->text (" ");
6353 uiout->text (b->extra_string.get ());
6354 }
6355 }
6356
6357 if (loc && is_breakpoint (b)
6360 {
6361 uiout->text (" (");
6362 uiout->field_string ("evaluated-by",
6364 uiout->text (")");
6365 }
6366}
6367
6368static const char *
6370{
6371 struct ep_type_description
6372 {
6373 enum bptype type;
6374 const char *description;
6375 };
6376 static struct ep_type_description bptypes[] =
6377 {
6378 {bp_none, "?deleted?"},
6379 {bp_breakpoint, "breakpoint"},
6380 {bp_hardware_breakpoint, "hw breakpoint"},
6381 {bp_single_step, "sw single-step"},
6382 {bp_until, "until"},
6383 {bp_finish, "finish"},
6384 {bp_watchpoint, "watchpoint"},
6385 {bp_hardware_watchpoint, "hw watchpoint"},
6386 {bp_read_watchpoint, "read watchpoint"},
6387 {bp_access_watchpoint, "acc watchpoint"},
6388 {bp_longjmp, "longjmp"},
6389 {bp_longjmp_resume, "longjmp resume"},
6390 {bp_longjmp_call_dummy, "longjmp for call dummy"},
6391 {bp_exception, "exception"},
6392 {bp_exception_resume, "exception resume"},
6393 {bp_step_resume, "step resume"},
6394 {bp_hp_step_resume, "high-priority step resume"},
6395 {bp_watchpoint_scope, "watchpoint scope"},
6396 {bp_call_dummy, "call dummy"},
6397 {bp_std_terminate, "std::terminate"},
6398 {bp_shlib_event, "shlib events"},
6399 {bp_thread_event, "thread events"},
6400 {bp_overlay_event, "overlay events"},
6401 {bp_longjmp_master, "longjmp master"},
6402 {bp_std_terminate_master, "std::terminate master"},
6403 {bp_exception_master, "exception master"},
6404 {bp_catchpoint, "catchpoint"},
6405 {bp_tracepoint, "tracepoint"},
6406 {bp_fast_tracepoint, "fast tracepoint"},
6407 {bp_static_tracepoint, "static tracepoint"},
6408 {bp_static_marker_tracepoint, "static marker tracepoint"},
6409 {bp_dprintf, "dprintf"},
6410 {bp_jit_event, "jit events"},
6411 {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"},
6412 {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"},
6413 };
6414
6415 if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0])))
6416 || ((int) type != bptypes[(int) type].type))
6417 internal_error (_("bptypes table does not describe type #%d."),
6418 (int) type);
6419
6420 return bptypes[(int) type].description;
6421}
6422
6423/* For MI, output a field named 'thread-groups' with a list as the value.
6424 For CLI, prefix the list with the string 'inf'. */
6425
6426static void
6428 const char *field_name,
6429 const std::vector<int> &inf_nums,
6430 int mi_only)
6431{
6432 int is_mi = uiout->is_mi_like_p ();
6433
6434 /* For backward compatibility, don't display inferiors in CLI unless
6435 there are several. Always display them for MI. */
6436 if (!is_mi && mi_only)
6437 return;
6438
6439 ui_out_emit_list list_emitter (uiout, field_name);
6440
6441 for (size_t i = 0; i < inf_nums.size (); i++)
6442 {
6443 if (is_mi)
6444 {
6445 char mi_group[10];
6446
6447 xsnprintf (mi_group, sizeof (mi_group), "i%d", inf_nums[i]);
6448 uiout->field_string (NULL, mi_group);
6449 }
6450 else
6451 {
6452 if (i == 0)
6453 uiout->text (" inf ");
6454 else
6455 uiout->text (", ");
6456
6457 uiout->text (plongest (inf_nums[i]));
6458 }
6459 }
6460}
6461
6462/* See breakpoint.h. */
6463
6465
6466/* Print B to gdb_stdout. If RAW_LOC, print raw breakpoint locations
6467 instead of going via breakpoint_ops::print_one. This makes "maint
6468 info breakpoints" show the software breakpoint locations of
6469 catchpoints, which are considered internal implementation
6470 detail. Returns true if RAW_LOC is false and if the breakpoint's
6471 print_one method did something; false otherwise. */
6472
6473static bool
6475 struct bp_location *loc,
6476 int loc_number,
6477 const bp_location **last_loc,
6478 int allflag, bool raw_loc)
6479{
6480 struct command_line *l;
6481 static char bpenables[] = "nynny";
6482
6483 struct ui_out *uiout = current_uiout;
6484 bool header_of_multiple = false;
6485 bool part_of_multiple = (loc != NULL);
6486 struct value_print_options opts;
6487
6488 get_user_print_options (&opts);
6489
6490 gdb_assert (!loc || loc_number != 0);
6491 /* See comment in print_one_breakpoint concerning treatment of
6492 breakpoints with single disabled location. */
6493 if (loc == NULL
6494 && (b->has_locations ()
6495 && (b->has_multiple_locations ()
6496 || !b->first_loc ().enabled || b->first_loc ().disabled_by_cond)))
6497 header_of_multiple = true;
6498
6499 if (loc == NULL && b->has_locations ())
6500 loc = &b->first_loc ();
6501
6502 annotate_record ();
6503
6504 /* 1 */
6505 annotate_field (0);
6506 if (part_of_multiple)
6507 uiout->field_fmt ("number", "%d.%d", b->number, loc_number);
6508 else
6509 uiout->field_signed ("number", b->number);
6510
6511 /* 2 */
6512 annotate_field (1);
6513 if (part_of_multiple)
6514 uiout->field_skip ("type");
6515 else
6516 uiout->field_string ("type", bptype_string (b->type));
6517
6518 /* 3 */
6519 annotate_field (2);
6520 if (part_of_multiple)
6521 uiout->field_skip ("disp");
6522 else
6523 uiout->field_string ("disp", bpdisp_text (b->disposition));
6524
6525 /* 4 */
6526 annotate_field (3);
6527 if (part_of_multiple)
6528 {
6529 /* For locations that are disabled because of an invalid
6530 condition, display "N*" on the CLI, where "*" refers to a
6531 footnote below the table. For MI, simply display a "N"
6532 without a footnote. On the CLI, for enabled locations whose
6533 breakpoint is disabled, display "y-". */
6534 auto get_enable_state = [uiout, loc] () -> const char *
6535 {
6536 if (uiout->is_mi_like_p ())
6537 {
6538 if (loc->disabled_by_cond)
6539 return "N";
6540 else if (!loc->enabled)
6541 return "n";
6542 else
6543 return "y";
6544 }
6545 else
6546 {
6547 if (loc->disabled_by_cond)
6548 return "N*";
6549 else if (!loc->enabled)
6550 return "n";
6551 else if (!breakpoint_enabled (loc->owner))
6552 return "y-";
6553 else
6554 return "y";
6555 }
6556 };
6557 uiout->field_string ("enabled", get_enable_state ());
6558 }
6559 else
6560 uiout->field_fmt ("enabled", "%c", bpenables[(int) b->enable_state]);
6561
6562 /* 5 and 6 */
6563 bool result = false;
6564 if (!raw_loc && b->print_one (last_loc))
6565 result = true;
6566 else
6567 {
6568 if (is_watchpoint (b))
6569 {
6570 watchpoint *w = gdb::checked_static_cast<watchpoint *> (b);
6571
6572 /* Field 4, the address, is omitted (which makes the columns
6573 not line up too nicely with the headers, but the effect
6574 is relatively readable). */
6575 if (opts.addressprint)
6576 uiout->field_skip ("addr");
6577 annotate_field (5);
6578 uiout->field_string ("what", w->exp_string.get ());
6579 }
6580 else if (!is_catchpoint (b) || is_exception_catchpoint (b)
6582 {
6583 if (opts.addressprint)
6584 {
6585 annotate_field (4);
6586 if (header_of_multiple)
6587 uiout->field_string ("addr", "<MULTIPLE>",
6589 else if (!b->has_locations () || loc->shlib_disabled)
6590 uiout->field_string ("addr", "<PENDING>",
6592 else
6593 uiout->field_core_addr ("addr",
6594 loc->gdbarch, loc->address);
6595 }
6596 annotate_field (5);
6597 if (!header_of_multiple)
6599 if (b->has_locations ())
6600 *last_loc = &b->first_loc ();
6601 }
6602 }
6603
6604 if (loc != NULL && !header_of_multiple)
6605 {
6606 std::vector<int> inf_nums;
6607 int mi_only = 1;
6608
6609 for (inferior *inf : all_inferiors ())
6610 {
6611 if (inf->pspace == loc->pspace)
6612 inf_nums.push_back (inf->num);
6613 }
6614
6615 /* For backward compatibility, don't display inferiors in CLI unless
6616 there are several. Always display for MI. */
6617 if (allflag
6619 && (program_spaces.size () > 1
6620 || number_of_inferiors () > 1)
6621 /* LOC is for existing B, it cannot be in
6622 moribund_locations and thus having NULL OWNER. */
6623 && loc->owner->type != bp_catchpoint))
6624 mi_only = 0;
6625 output_thread_groups (uiout, "thread-groups", inf_nums, mi_only);
6626 }
6627
6628 /* In the MI output, each location of a thread or task specific
6629 breakpoint includes the relevant thread or task ID. This is done for
6630 backwards compatibility reasons.
6631
6632 For the CLI output, the thread/task information is printed on a
6633 separate line, see the 'stop only in thread' and 'stop only in task'
6634 output below. */
6635 if (part_of_multiple && uiout->is_mi_like_p ())
6636 {
6637 if (b->thread != -1)
6638 uiout->field_signed ("thread", b->thread);
6639 else if (b->task != -1)
6640 uiout->field_signed ("task", b->task);
6641 else if (b->inferior != -1)
6642 uiout->field_signed ("inferior", b->inferior);
6643 }
6644
6645 uiout->text ("\n");
6646
6647 if (!part_of_multiple)
6648 b->print_one_detail (uiout);
6649
6650 if (part_of_multiple && frame_id_p (b->frame_id))
6651 {
6652 annotate_field (6);
6653 uiout->text ("\tstop only in stack frame at ");
6654 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6655 the frame ID. */
6656 uiout->field_core_addr ("frame",
6657 b->gdbarch, b->frame_id.stack_addr);
6658 uiout->text ("\n");
6659 }
6660
6661 if (!part_of_multiple && b->cond_string)
6662 {
6663 annotate_field (7);
6664 if (is_tracepoint (b))
6665 uiout->text ("\ttrace only if ");
6666 else
6667 uiout->text ("\tstop only if ");
6668 uiout->field_string ("cond", b->cond_string.get ());
6669
6670 /* Print whether the target is doing the breakpoint's condition
6671 evaluation. If GDB is doing the evaluation, don't print anything. */
6672 if (is_breakpoint (b)
6675 {
6676 uiout->message (" (%pF evals)",
6677 string_field ("evaluated-by",
6679 }
6680 uiout->text ("\n");
6681 }
6682
6683 if (!part_of_multiple && b->thread != -1)
6684 {
6685 /* FIXME should make an annotation for this. */
6686 uiout->text ("\tstop only in thread ");
6687 if (uiout->is_mi_like_p ())
6688 uiout->field_signed ("thread", b->thread);
6689 else
6690 {
6691 struct thread_info *thr = find_thread_global_id (b->thread);
6692
6693 uiout->field_string ("thread", print_thread_id (thr));
6694 }
6695 uiout->text ("\n");
6696 }
6697
6698 if (!part_of_multiple && b->task != -1)
6699 {
6700 uiout->text ("\tstop only in task ");
6701 uiout->field_signed ("task", b->task);
6702 uiout->text ("\n");
6703 }
6704
6705 if (!part_of_multiple && b->inferior != -1)
6706 {
6707 uiout->text ("\tstop only in inferior ");
6708 uiout->field_signed ("inferior", b->inferior);
6709 uiout->text ("\n");
6710 }
6711
6712 if (!part_of_multiple)
6713 {
6714 if (b->hit_count)
6715 {
6716 /* FIXME should make an annotation for this. */
6717 if (is_catchpoint (b))
6718 uiout->text ("\tcatchpoint");
6719 else if (is_tracepoint (b))
6720 uiout->text ("\ttracepoint");
6721 else
6722 uiout->text ("\tbreakpoint");
6723 uiout->text (" already hit ");
6724 uiout->field_signed ("times", b->hit_count);
6725 if (b->hit_count == 1)
6726 uiout->text (" time\n");
6727 else
6728 uiout->text (" times\n");
6729 }
6730 else
6731 {
6732 /* Output the count also if it is zero, but only if this is mi. */
6733 if (uiout->is_mi_like_p ())
6734 uiout->field_signed ("times", b->hit_count);
6735 }
6736 }
6737
6738 if (!part_of_multiple && b->ignore_count)
6739 {
6740 annotate_field (8);
6741 uiout->message ("\tignore next %pF hits\n",
6742 signed_field ("ignore", b->ignore_count));
6743 }
6744
6745 /* Note that an enable count of 1 corresponds to "enable once"
6746 behavior, which is reported by the combination of enablement and
6747 disposition, so we don't need to mention it here. */
6748 if (!part_of_multiple && b->enable_count > 1)
6749 {
6750 annotate_field (8);
6751 uiout->text ("\tdisable after ");
6752 /* Tweak the wording to clarify that ignore and enable counts
6753 are distinct, and have additive effect. */
6754 if (b->ignore_count)
6755 uiout->text ("additional ");
6756 else
6757 uiout->text ("next ");
6758 uiout->field_signed ("enable", b->enable_count);
6759 uiout->text (" hits\n");
6760 }
6761
6762 if (!part_of_multiple && is_tracepoint (b))
6763 {
6764 tracepoint *tp = gdb::checked_static_cast<tracepoint *> (b);
6765
6766 if (tp->traceframe_usage)
6767 {
6768 uiout->text ("\ttrace buffer usage ");
6769 uiout->field_signed ("traceframe-usage", tp->traceframe_usage);
6770 uiout->text (" bytes\n");
6771 }
6772 }
6773
6774 l = b->commands ? b->commands.get () : NULL;
6775 if (!part_of_multiple && l)
6776 {
6777 annotate_field (9);
6778
6779 bool use_fixed_output =
6782
6783 gdb::optional<ui_out_emit_tuple> tuple_emitter;
6784 gdb::optional<ui_out_emit_list> list_emitter;
6785
6786 if (use_fixed_output)
6787 list_emitter.emplace (uiout, "script");
6788 else
6789 tuple_emitter.emplace (uiout, "script");
6790
6791 print_command_lines (uiout, l, 4);
6792 }
6793
6794 if (is_tracepoint (b))
6795 {
6796 tracepoint *t = gdb::checked_static_cast<tracepoint *> (b);
6797
6798 if (!part_of_multiple && t->pass_count)
6799 {
6800 annotate_field (10);
6801 uiout->text ("\tpass count ");
6802 uiout->field_signed ("pass", t->pass_count);
6803 uiout->text (" \n");
6804 }
6805
6806 /* Don't display it when tracepoint or tracepoint location is
6807 pending. */
6808 if (!header_of_multiple && loc != NULL && !loc->shlib_disabled)
6809 {
6810 annotate_field (11);
6811
6812 if (uiout->is_mi_like_p ())
6813 uiout->field_string ("installed",
6814 loc->inserted ? "y" : "n");
6815 else
6816 {
6817 if (loc->inserted)
6818 uiout->text ("\t");
6819 else
6820 uiout->text ("\tnot ");
6821 uiout->text ("installed on target\n");
6822 }
6823 }
6824 }
6825
6826 if (uiout->is_mi_like_p () && !part_of_multiple)
6827 {
6828 if (is_watchpoint (b))
6829 {
6830 watchpoint *w = gdb::checked_static_cast<watchpoint *> (b);
6831
6832 uiout->field_string ("original-location", w->exp_string.get ());
6833 }
6834 else if (b->locspec != nullptr)
6835 {
6836 const char *str = b->locspec->to_string ();
6837 if (str != nullptr)
6838 uiout->field_string ("original-location", str);
6839 }
6840 }
6841
6842 return result;
6843}
6844
6845/* See breakpoint.h. */
6846
6848
6849static void
6850print_one_breakpoint (breakpoint *b, const bp_location **last_loc, int allflag)
6851{
6852 struct ui_out *uiout = current_uiout;
6853 bool use_fixed_output
6856
6857 gdb::optional<ui_out_emit_tuple> bkpt_tuple_emitter (gdb::in_place, uiout, "bkpt");
6858 bool printed = print_one_breakpoint_location (b, NULL, 0, last_loc,
6859 allflag, false);
6860
6861 /* The mi2 broken format: the main breakpoint tuple ends here, the locations
6862 are outside. */
6863 if (!use_fixed_output)
6864 bkpt_tuple_emitter.reset ();
6865
6866 /* If this breakpoint has custom print function,
6867 it's already printed. Otherwise, print individual
6868 locations, if any. */
6869 if (!printed || allflag)
6870 {
6871 /* If breakpoint has a single location that is disabled, we
6872 print it as if it had several locations, since otherwise it's
6873 hard to represent "breakpoint enabled, location disabled"
6874 situation.
6875
6876 Note that while hardware watchpoints have several locations
6877 internally, that's not a property exposed to users.
6878
6879 Likewise, while catchpoints may be implemented with
6880 breakpoints (e.g., catch throw), that's not a property
6881 exposed to users. We do however display the internal
6882 breakpoint locations with "maint info breakpoints". */
6883 if (!is_hardware_watchpoint (b)
6886 && (allflag
6887 || (b->has_locations ()
6888 && (b->has_multiple_locations ()
6889 || !b->first_loc ().enabled
6890 || b->first_loc ().disabled_by_cond))))
6891 {
6892 gdb::optional<ui_out_emit_list> locations_list;
6893
6894 /* For MI version <= 2, keep the behavior where GDB outputs an invalid
6895 MI record. For later versions, place breakpoint locations in a
6896 list. */
6897 if (uiout->is_mi_like_p () && use_fixed_output)
6898 locations_list.emplace (uiout, "locations");
6899
6900 int n = 1;
6901 for (bp_location &loc : b->locations ())
6902 {
6903 ui_out_emit_tuple loc_tuple_emitter (uiout, NULL);
6904 print_one_breakpoint_location (b, &loc, n, last_loc,
6905 allflag, allflag);
6906 n++;
6907 }
6908 }
6909 }
6910}
6911
6912static int
6914{
6915 int print_address_bits = 0;
6916
6917 for (bp_location &loc : b->locations ())
6918 {
6920 continue;
6921
6922 int addr_bit = gdbarch_addr_bit (loc.gdbarch);
6923 if (addr_bit > print_address_bits)
6924 print_address_bits = addr_bit;
6925 }
6926
6927 return print_address_bits;
6928}
6929
6930/* See breakpoint.h. */
6931
6932void
6934{
6935 const bp_location *dummy_loc = nullptr;
6936 print_one_breakpoint (b, &dummy_loc, 0);
6937}
6938
6939/* Return true if this breakpoint was set by the user, false if it is
6940 internal or momentary. */
6941
6942int
6944{
6945 return b->number > 0;
6946}
6947
6948/* See breakpoint.h. */
6949
6950int
6952{
6953 return !b->has_locations ();
6954}
6955
6956/* Print information on breakpoints (including watchpoints and tracepoints).
6957
6958 If non-NULL, BP_NUM_LIST is a list of numbers and number ranges as
6959 understood by number_or_range_parser. Only breakpoints included in this
6960 list are then printed.
6961
6962 If SHOW_INTERNAL is true, print internal breakpoints.
6963
6964 If FILTER is non-NULL, call it on each breakpoint and only include the
6965 ones for which it returns true.
6966
6967 Return the total number of breakpoints listed. */
6968
6969static int
6970breakpoint_1 (const char *bp_num_list, bool show_internal,
6971 bool (*filter) (const struct breakpoint *))
6972{
6973 const bp_location *last_loc = nullptr;
6974 int nr_printable_breakpoints;
6975 struct value_print_options opts;
6976 int print_address_bits = 0;
6977 int print_type_col_width = 14;
6978 struct ui_out *uiout = current_uiout;
6979 bool has_disabled_by_cond_location = false;
6980
6981 get_user_print_options (&opts);
6982
6983 /* Compute the number of rows in the table, as well as the size
6984 required for address fields. */
6985 nr_printable_breakpoints = 0;
6986 for (breakpoint &b : all_breakpoints ())
6987 {
6988 /* If we have a filter, only list the breakpoints it accepts. */
6989 if (filter && !filter (&b))
6990 continue;
6991
6992 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6993 accept. Skip the others. */
6994 if (bp_num_list != NULL && *bp_num_list != '\0')
6995 {
6996 if (show_internal && parse_and_eval_long (bp_num_list) != b.number)
6997 continue;
6998 if (!show_internal && !number_is_in_list (bp_num_list, b.number))
6999 continue;
7000 }
7001
7002 if (show_internal || user_breakpoint_p (&b))
7003 {
7004 int addr_bit, type_len;
7005
7006 addr_bit = breakpoint_address_bits (&b);
7007 if (addr_bit > print_address_bits)
7008 print_address_bits = addr_bit;
7009
7010 type_len = strlen (bptype_string (b.type));
7011 if (type_len > print_type_col_width)
7012 print_type_col_width = type_len;
7013
7014 nr_printable_breakpoints++;
7015 }
7016 }
7017
7018 {
7019 ui_out_emit_table table_emitter (uiout,
7020 opts.addressprint ? 6 : 5,
7021 nr_printable_breakpoints,
7022 "BreakpointTable");
7023
7024 if (nr_printable_breakpoints > 0)
7026 if (nr_printable_breakpoints > 0)
7027 annotate_field (0);
7028 uiout->table_header (7, ui_left, "number", "Num"); /* 1 */
7029 if (nr_printable_breakpoints > 0)
7030 annotate_field (1);
7031 uiout->table_header (print_type_col_width, ui_left, "type", "Type"); /* 2 */
7032 if (nr_printable_breakpoints > 0)
7033 annotate_field (2);
7034 uiout->table_header (4, ui_left, "disp", "Disp"); /* 3 */
7035 if (nr_printable_breakpoints > 0)
7036 annotate_field (3);
7037 uiout->table_header (3, ui_left, "enabled", "Enb"); /* 4 */
7038 if (opts.addressprint)
7039 {
7040 if (nr_printable_breakpoints > 0)
7041 annotate_field (4);
7042 if (print_address_bits <= 32)
7043 uiout->table_header (10, ui_left, "addr", "Address"); /* 5 */
7044 else
7045 uiout->table_header (18, ui_left, "addr", "Address"); /* 5 */
7046 }
7047 if (nr_printable_breakpoints > 0)
7048 annotate_field (5);
7049 uiout->table_header (40, ui_noalign, "what", "What"); /* 6 */
7050 uiout->table_body ();
7051 if (nr_printable_breakpoints > 0)
7053
7054 for (breakpoint &b : all_breakpoints ())
7055 {
7056 QUIT;
7057 /* If we have a filter, only list the breakpoints it accepts. */
7058 if (filter && !filter (&b))
7059 continue;
7060
7061 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
7062 accept. Skip the others. */
7063
7064 if (bp_num_list != NULL && *bp_num_list != '\0')
7065 {
7066 if (show_internal) /* maintenance info breakpoint */
7067 {
7068 if (parse_and_eval_long (bp_num_list) != b.number)
7069 continue;
7070 }
7071 else /* all others */
7072 {
7073 if (!number_is_in_list (bp_num_list, b.number))
7074 continue;
7075 }
7076 }
7077 /* We only print out user settable breakpoints unless the
7078 show_internal is set. */
7079 if (show_internal || user_breakpoint_p (&b))
7080 {
7081 print_one_breakpoint (&b, &last_loc, show_internal);
7082 for (bp_location &loc : b.locations ())
7083 if (loc.disabled_by_cond)
7084 has_disabled_by_cond_location = true;
7085 }
7086 }
7087 }
7088
7089 if (nr_printable_breakpoints == 0)
7090 {
7091 /* If there's a filter, let the caller decide how to report
7092 empty list. */
7093 if (!filter)
7094 {
7095 if (bp_num_list == NULL || *bp_num_list == '\0')
7096 uiout->message ("No breakpoints or watchpoints.\n");
7097 else
7098 uiout->message ("No breakpoint or watchpoint matching '%s'.\n",
7099 bp_num_list);
7100 }
7101 }
7102 else
7103 {
7104 if (last_loc && !server_command)
7105 set_next_address (last_loc->gdbarch, last_loc->address);
7106
7107 if (has_disabled_by_cond_location && !uiout->is_mi_like_p ())
7108 uiout->message (_("(*): Breakpoint condition is invalid at this "
7109 "location.\n"));
7110 }
7111
7112 /* FIXME? Should this be moved up so that it is only called when
7113 there have been breakpoints? */
7115
7116 return nr_printable_breakpoints;
7117}
7118
7119/* Display the value of default-collect in a way that is generally
7120 compatible with the breakpoint list. */
7121
7122static void
7124{
7125 struct ui_out *uiout = current_uiout;
7126
7127 /* If it has no value (which is frequently the case), say nothing; a
7128 message like "No default-collect." gets in user's face when it's
7129 not wanted. */
7130 if (default_collect.empty ())
7131 return;
7132
7133 /* The following phrase lines up nicely with per-tracepoint collect
7134 actions. */
7135 uiout->text ("default collect ");
7136 uiout->field_string ("default-collect", default_collect);
7137 uiout->text (" \n");
7138}
7139
7140static void
7141info_breakpoints_command (const char *args, int from_tty)
7142{
7143 breakpoint_1 (args, false, NULL);
7144
7146}
7147
7148static void
7149info_watchpoints_command (const char *args, int from_tty)
7150{
7151 int num_printed = breakpoint_1 (args, false, is_watchpoint);
7152 struct ui_out *uiout = current_uiout;
7153
7154 if (num_printed == 0)
7155 {
7156 if (args == NULL || *args == '\0')
7157 uiout->message ("No watchpoints.\n");
7158 else
7159 uiout->message ("No watchpoint matching '%s'.\n", args);
7160 }
7161}
7162
7163static void
7164maintenance_info_breakpoints (const char *args, int from_tty)
7165{
7166 breakpoint_1 (args, true, NULL);
7167
7169}
7170
7171static bool
7173 struct program_space *pspace,
7174 CORE_ADDR pc, struct obj_section *section)
7175{
7176 for (bp_location &bl : b->locations ())
7177 {
7178 if (bl.pspace == pspace
7179 && bl.address == pc
7180 && (!overlay_debugging || bl.section == section))
7181 return true;
7182 }
7183 return false;
7184}
7185
7186/* See breakpoint.h. */
7187
7188void
7190 struct program_space *pspace, CORE_ADDR pc,
7191 struct obj_section *section, int thread)
7192{
7193 int others = 0;
7194
7195 for (breakpoint &b : all_breakpoints ())
7196 others += (user_breakpoint_p (&b)
7197 && breakpoint_has_pc (&b, pspace, pc, section));
7198
7199 if (others > 0)
7200 {
7201 if (others == 1)
7202 gdb_printf (_("Note: breakpoint "));
7203 else /* if (others == ???) */
7204 gdb_printf (_("Note: breakpoints "));
7205 for (breakpoint &b : all_breakpoints ())
7206 if (user_breakpoint_p (&b)
7207 && breakpoint_has_pc (&b, pspace, pc, section))
7208 {
7209 others--;
7210 gdb_printf ("%d", b.number);
7211 if (b.thread == -1 && thread != -1)
7212 gdb_printf (" (all threads)");
7213 else if (b.thread != -1)
7214 {
7215 struct thread_info *thr = find_thread_global_id (b.thread);
7216 gdb_printf (" (thread %s)", print_thread_id (thr));
7217 }
7218 else if (b.task != -1)
7219 gdb_printf (" (task %d)", b.task);
7220 gdb_printf ("%s%s ",
7223 ? " (disabled)"
7224 : ""),
7225 (others > 1) ? ","
7226 : ((others == 1) ? " and" : ""));
7227 }
7228 current_uiout->message (_("also set at pc %ps.\n"),
7230 paddress (gdbarch, pc)));
7231 }
7232}
7233
7234
7235/* Return true iff it is meaningful to use the address member of LOC.
7236 For some breakpoint types, the locations' address members are
7237 irrelevant and it makes no sense to attempt to compare them to
7238 other addresses (or use them for any other purpose either).
7239
7240 More specifically, software watchpoints and catchpoints that are
7241 not backed by breakpoints always have a zero valued location
7242 address and we don't want to mark breakpoints of any of these types
7243 to be a duplicate of an actual breakpoint location at address
7244 zero. */
7245
7246static bool
7248{
7249 return loc->loc_type != bp_loc_other;
7250}
7251
7252/* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
7253 true if LOC1 and LOC2 represent the same watchpoint location. */
7254
7255static bool
7257 const struct bp_location *loc2)
7258{
7259 watchpoint *w1 = gdb::checked_static_cast<watchpoint *> (loc1->owner);
7260 watchpoint *w2 = gdb::checked_static_cast<watchpoint *> (loc2->owner);
7261
7262 /* Both of them must exist. */
7263 gdb_assert (w1 != NULL);
7264 gdb_assert (w2 != NULL);
7265
7266 /* If the target can evaluate the condition expression in hardware,
7267 then we we need to insert both watchpoints even if they are at
7268 the same place. Otherwise the watchpoint will only trigger when
7269 the condition of whichever watchpoint was inserted evaluates to
7270 true, not giving a chance for GDB to check the condition of the
7271 other watchpoint. */
7272 if ((w1->cond_exp
7274 loc1->length,
7275 loc1->watchpoint_type,
7276 w1->cond_exp.get ()))
7277 || (w2->cond_exp
7279 loc2->length,
7280 loc2->watchpoint_type,
7281 w2->cond_exp.get ())))
7282 return false;
7283
7284 /* Note that this checks the owner's type, not the location's. In
7285 case the target does not support read watchpoints, but does
7286 support access watchpoints, we'll have bp_read_watchpoint
7287 watchpoints with hw_access locations. Those should be considered
7288 duplicates of hw_read locations. The hw_read locations will
7289 become hw_access locations later. */
7290 return (loc1->owner->type == loc2->owner->type
7291 && loc1->pspace->aspace == loc2->pspace->aspace
7292 && loc1->address == loc2->address
7293 && loc1->length == loc2->length);
7294}
7295
7296/* See breakpoint.h. */
7297
7298int
7299breakpoint_address_match (const address_space *aspace1, CORE_ADDR addr1,
7300 const address_space *aspace2, CORE_ADDR addr2)
7301{
7303 || aspace1 == aspace2)
7304 && addr1 == addr2);
7305}
7306
7307/* Returns true if {ASPACE2,ADDR2} falls within the range determined by
7308 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
7309 matches ASPACE2. On targets that have global breakpoints, the address
7310 space doesn't really matter. */
7311
7312static bool
7314 CORE_ADDR addr1,
7315 int len1, const address_space *aspace2,
7316 CORE_ADDR addr2)
7317{
7319 || aspace1 == aspace2)
7320 && addr2 >= addr1 && addr2 < addr1 + len1);
7321}
7322
7323/* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
7324 a ranged breakpoint. In most targets, a match happens only if ASPACE
7325 matches the breakpoint's address space. On targets that have global
7326 breakpoints, the address space doesn't really matter. */
7327
7328static bool
7330 const address_space *aspace,
7331 CORE_ADDR addr)
7332{
7333 return (breakpoint_address_match (bl->pspace->aspace, bl->address,
7334 aspace, addr)
7335 || (bl->length
7337 bl->address, bl->length,
7338 aspace, addr)));
7339}
7340
7341/* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
7342 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
7343 match happens only if ASPACE matches the breakpoint's address
7344 space. On targets that have global breakpoints, the address space
7345 doesn't really matter. */
7346
7347static bool
7349 const address_space *aspace,
7350 CORE_ADDR addr, int len)
7351{
7353 || bl->pspace->aspace == aspace)
7354 {
7355 int bl_len = bl->length != 0 ? bl->length : 1;
7356
7357 if (mem_ranges_overlap (addr, len, bl->address, bl_len))
7358 return 1;
7359 }
7360 return 0;
7361}
7362
7363/* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
7364 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
7365 true, otherwise returns false. */
7366
7367static bool
7369 const struct bp_location *loc2)
7370{
7371 if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner))
7372 /* Since tracepoint locations are never duplicated with others', tracepoint
7373 locations at the same address of different tracepoints are regarded as
7374 different locations. */
7375 return (loc1->address == loc2->address && loc1->owner == loc2->owner);
7376 else
7377 return false;
7378}
7379
7380/* Assuming LOC1 and LOC2's types' have meaningful target addresses
7381 (bl_address_is_meaningful), returns true if LOC1 and LOC2 represent
7382 the same location. If SW_HW_BPS_MATCH is true, then software
7383 breakpoint locations and hardware breakpoint locations match,
7384 otherwise they don't. */
7385
7386static bool
7388 const struct bp_location *loc2,
7389 bool sw_hw_bps_match)
7390{
7391 int hw_point1, hw_point2;
7392
7393 /* Both of them must not be in moribund_locations. */
7394 gdb_assert (loc1->owner != NULL);
7395 gdb_assert (loc2->owner != NULL);
7396
7397 hw_point1 = is_hardware_watchpoint (loc1->owner);
7398 hw_point2 = is_hardware_watchpoint (loc2->owner);
7399
7400 if (hw_point1 != hw_point2)
7401 return false;
7402 else if (hw_point1)
7403 return watchpoint_locations_match (loc1, loc2);
7404 else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner))
7405 return tracepoint_locations_match (loc1, loc2);
7406 else
7407 /* We compare bp_location.length in order to cover ranged
7408 breakpoints. Keep this in sync with
7409 bp_location_is_less_than. */
7410 return (breakpoint_address_match (loc1->pspace->aspace, loc1->address,
7411 loc2->pspace->aspace, loc2->address)
7412 && (loc1->loc_type == loc2->loc_type || sw_hw_bps_match)
7413 && loc1->length == loc2->length);
7414}
7415
7416static void
7417breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
7418 int bnum, bool have_bnum)
7419{
7420 /* The longest string possibly returned by hex_string_custom
7421 is 50 chars. These must be at least that big for safety. */
7422 char astr1[64];
7423 char astr2[64];
7424
7425 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
7426 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
7427 if (have_bnum)
7428 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7429 bnum, astr1, astr2);
7430 else
7431 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
7432}
7433
7434/* Adjust a breakpoint's address to account for architectural
7435 constraints on breakpoint placement. Return the adjusted address.
7436 Note: Very few targets require this kind of adjustment. For most
7437 targets, this function is simply the identity function. */
7438
7439static CORE_ADDR
7441 CORE_ADDR bpaddr, enum bptype bptype,
7442 struct program_space *pspace)
7443{
7444 gdb_assert (pspace != nullptr);
7445
7446 if (bptype == bp_watchpoint
7450 || bptype == bp_catchpoint)
7451 {
7452 /* Watchpoints and the various bp_catch_* eventpoints should not
7453 have their addresses modified. */
7454 return bpaddr;
7455 }
7456 else if (bptype == bp_single_step)
7457 {
7458 /* Single-step breakpoints should not have their addresses
7459 modified. If there's any architectural constrain that
7460 applies to this address, then it should have already been
7461 taken into account when the breakpoint was created in the
7462 first place. If we didn't do this, stepping through e.g.,
7463 Thumb-2 IT blocks would break. */
7464 return bpaddr;
7465 }
7466 else
7467 {
7468 CORE_ADDR adjusted_bpaddr = bpaddr;
7469
7470 /* Some targets have architectural constraints on the placement
7471 of breakpoint instructions. Obtain the adjusted address. */
7473 {
7474 /* Targets that implement this adjustment function will likely
7475 inspect either the symbol table, target memory at BPADDR, or
7476 even state registers, so ensure a suitable thread (and its
7477 associated program space) are currently selected. */
7478 scoped_restore_current_pspace_and_thread restore_pspace_thread;
7480 adjusted_bpaddr
7482 }
7483
7484 adjusted_bpaddr
7485 = gdbarch_remove_non_address_bits (gdbarch, adjusted_bpaddr);
7486
7487 /* An adjusted breakpoint address can significantly alter
7488 a user's expectations. Print a warning if an adjustment
7489 is required. */
7490 if (adjusted_bpaddr != bpaddr)
7491 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, false);
7492
7493 return adjusted_bpaddr;
7494 }
7495}
7496
7497static bp_loc_type
7499{
7500 switch (type)
7501 {
7502 case bp_breakpoint:
7503 case bp_single_step:
7504 case bp_until:
7505 case bp_finish:
7506 case bp_longjmp:
7507 case bp_longjmp_resume:
7509 case bp_exception:
7511 case bp_step_resume:
7512 case bp_hp_step_resume:
7514 case bp_call_dummy:
7515 case bp_std_terminate:
7516 case bp_shlib_event:
7517 case bp_thread_event:
7518 case bp_overlay_event:
7519 case bp_jit_event:
7520 case bp_longjmp_master:
7525 case bp_dprintf:
7527
7530
7532 case bp_read_watchpoint:
7535
7536 case bp_watchpoint:
7538
7539 case bp_tracepoint:
7540 case bp_fast_tracepoint:
7543 return bp_loc_tracepoint;
7544
7545 case bp_catchpoint:
7546 return bp_loc_other;
7547
7548 default:
7549 internal_error (_("unknown breakpoint type"));
7550 }
7551}
7552
7554{
7555 this->owner = owner;
7556 this->cond_bytecode = NULL;
7557 this->shlib_disabled = 0;
7558 this->enabled = 1;
7559 this->disabled_by_cond = false;
7560
7561 this->loc_type = type;
7562
7566
7567 incref ();
7568}
7569
7575
7576/* See breakpoint.h. */
7577
7578std::string
7580{
7581 string_file stb;
7582 ui_out_redirect_pop redir (current_uiout, &stb);
7583 print_breakpoint_location (this->owner, this);
7584 return stb.release ();
7585}
7586
7587/* Decrement reference count. If the reference count reaches 0,
7588 destroy the bp_location. Sets *BLP to NULL. */
7589
7590static void
7592{
7594 *blp = NULL;
7595}
7596
7597/* Add breakpoint B at the end of the global breakpoint chain. */
7598
7599static breakpoint *
7600add_to_breakpoint_chain (std::unique_ptr<breakpoint> &&b)
7601{
7602 /* Add this breakpoint to the end of the chain so that a list of
7603 breakpoints will come out in order of increasing numbers. */
7604
7605 breakpoint_chain.push_back (*b.release ());
7606
7607 return &breakpoint_chain.back ();
7608}
7609
7610/* Initialize loc->function_name. */
7611
7612static void
7614{
7615 gdb_assert (loc->owner != NULL);
7616
7617 if (loc->owner->type == bp_breakpoint
7618 || loc->owner->type == bp_hardware_breakpoint
7619 || is_tracepoint (loc->owner))
7620 {
7621 const char *function_name;
7622
7623 if (loc->msymbol != NULL
7624 && (loc->msymbol->type () == mst_text_gnu_ifunc
7625 || loc->msymbol->type () == mst_data_gnu_ifunc))
7626 {
7627 struct breakpoint *b = loc->owner;
7628
7629 function_name = loc->msymbol->linkage_name ();
7630
7631 if (b->type == bp_breakpoint
7632 && b->has_single_location ()
7633 && b->related_breakpoint == b)
7634 {
7635 /* Create only the whole new breakpoint of this type but do not
7636 mess more complicated breakpoints with multiple locations. */
7638 /* Remember the resolver's address for use by the return
7639 breakpoint. */
7640 loc->related_address = loc->address;
7641 }
7642 }
7643 else
7644 find_pc_partial_function (loc->address, &function_name, NULL, NULL);
7645
7646 if (function_name)
7647 loc->function_name = make_unique_xstrdup (function_name);
7648 }
7649}
7650
7651/* Attempt to determine architecture of location identified by SAL. */
7652struct gdbarch *
7654{
7655 if (sal.section)
7656 return sal.section->objfile->arch ();
7657 if (sal.symtab)
7658 return sal.symtab->compunit ()->objfile ()->arch ();
7659
7660 return NULL;
7661}
7662
7663/* Call this routine when stepping and nexting to enable a breakpoint
7664 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7665 initiated the operation. */
7666
7667void
7669{
7670 int thread = tp->global_num;
7671
7672 /* To avoid having to rescan all objfile symbols at every step,
7673 we maintain a list of continually-inserted but always disabled
7674 longjmp "master" breakpoints. Here, we simply create momentary
7675 clones of those and enable them for the requested thread. */
7676 for (breakpoint &b : all_breakpoints_safe ())
7678 && (b.type == bp_longjmp_master
7679 || b.type == bp_exception_master))
7680 {
7682 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7683 after their removal. */
7684 momentary_breakpoint_from_master (&b, type, 1, thread);
7685 }
7686
7687 tp->initiating_frame = frame;
7688}
7689
7690/* Delete all longjmp breakpoints from THREAD. */
7691void
7693{
7694 for (breakpoint &b : all_breakpoints_safe ())
7695 if (b.type == bp_longjmp || b.type == bp_exception)
7696 {
7697 if (b.thread == thread)
7698 {
7699 gdb_assert (b.inferior == -1);
7700 delete_breakpoint (&b);
7701 }
7702 }
7703}
7704
7705void
7707{
7708 for (breakpoint &b : all_breakpoints_safe ())
7709 if (b.type == bp_longjmp || b.type == bp_exception)
7710 {
7711 if (b.thread == thread)
7712 {
7713 gdb_assert (b.inferior == -1);
7715 }
7716 }
7717}
7718
7719/* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7720 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7721 pointer to any of them. Return NULL if this system cannot place longjmp
7722 breakpoints. */
7723
7724struct breakpoint *
7726{
7727 breakpoint *retval = nullptr;
7728
7729 for (breakpoint &b : all_breakpoints ())
7731 {
7733 breakpoint *new_b
7735 1, thread);
7736
7737 /* Link NEW_B into the chain of RETVAL breakpoints. */
7738
7739 gdb_assert (new_b->related_breakpoint == new_b);
7740 if (retval == NULL)
7741 retval = new_b;
7742 new_b->related_breakpoint = retval;
7743 while (retval->related_breakpoint != new_b->related_breakpoint)
7744 retval = retval->related_breakpoint;
7745 retval->related_breakpoint = new_b;
7746 }
7747
7748 return retval;
7749}
7750
7751/* Verify all existing dummy frames and their associated breakpoints for
7752 TP. Remove those which can no longer be found in the current frame
7753 stack.
7754
7755 If the unwind fails then there is not sufficient information to discard
7756 dummy frames. In this case, elide the clean up and the dummy frames will
7757 be cleaned up next time this function is called from a location where
7758 unwinding is possible. */
7759
7760void
7762{
7763 /* We would need to delete breakpoints other than the current one while
7764 iterating, so all_breakpoints_safe is not sufficient to make that safe.
7765 Save all breakpoints to delete in that set and delete them at the end. */
7766 std::unordered_set<breakpoint *> to_delete;
7767
7768 for (struct breakpoint &b : all_breakpoints ())
7769 {
7770 if (b.type == bp_longjmp_call_dummy && b.thread == tp->global_num)
7771 {
7772 gdb_assert (b.inferior == -1);
7773 struct breakpoint *dummy_b = b.related_breakpoint;
7774
7775 /* Find the bp_call_dummy breakpoint in the list of breakpoints
7776 chained off b->related_breakpoint. */
7777 while (dummy_b != &b && dummy_b->type != bp_call_dummy)
7778 dummy_b = dummy_b->related_breakpoint;
7779
7780 /* If there was no bp_call_dummy breakpoint then there's nothing
7781 more to do. Or, if the dummy frame associated with the
7782 bp_call_dummy is still on the stack then we need to leave this
7783 bp_call_dummy in place. */
7784 if (dummy_b->type != bp_call_dummy
7785 || frame_find_by_id (dummy_b->frame_id) != NULL)
7786 continue;
7787
7788 /* We didn't find the dummy frame on the stack, this could be
7789 because we have longjmp'd to a stack frame that is previous to
7790 the dummy frame, or it could be because the stack unwind is
7791 broken at some point between the longjmp frame and the dummy
7792 frame.
7793
7794 Next we figure out why the stack unwind stopped. If it looks
7795 like the unwind is complete then we assume the dummy frame has
7796 been jumped over, however, if the unwind stopped for an
7797 unexpected reason then we assume the stack unwind is currently
7798 broken, and that we will (eventually) return to the dummy
7799 frame.
7800
7801 It might be tempting to consider using frame_id_inner here, but
7802 that is not safe. There is no guarantee that the stack frames
7803 we are looking at here are even on the same stack as the
7804 original dummy frame, hence frame_id_inner can't be used. See
7805 the comments on frame_id_inner for more details. */
7806 bool unwind_finished_unexpectedly = false;
7807 for (frame_info_ptr fi = get_current_frame (); fi != nullptr; )
7808 {
7809 frame_info_ptr prev = get_prev_frame (fi);
7810 if (prev == nullptr)
7811 {
7812 /* FI is the last stack frame. Why did this frame not
7813 unwind further? */
7814 auto stop_reason = get_frame_unwind_stop_reason (fi);
7815 if (stop_reason != UNWIND_NO_REASON
7816 && stop_reason != UNWIND_OUTERMOST)
7817 unwind_finished_unexpectedly = true;
7818 }
7819 fi = prev;
7820 }
7821 if (unwind_finished_unexpectedly)
7822 continue;
7823
7824 dummy_frame_discard (dummy_b->frame_id, tp);
7825
7827 related_breakpoint != &b;
7829 to_delete.insert (b.related_breakpoint);
7830
7831 to_delete.insert (&b);
7832 }
7833 }
7834
7835 for (breakpoint *b : to_delete)
7837}
7838
7839void
7850
7851void
7862
7863/* Set an active std::terminate breakpoint for each std::terminate
7864 master breakpoint. */
7865void
7867{
7868 for (breakpoint &b : all_breakpoints_safe ())
7871 {
7873 inferior_thread ()->global_num);
7874 }
7875}
7876
7877/* Delete all the std::terminate breakpoints. */
7878void
7880{
7881 for (breakpoint &b : all_breakpoints_safe ())
7882 if (b.type == bp_std_terminate)
7883 delete_breakpoint (&b);
7884}
7885
7886struct breakpoint *
7888{
7889 struct breakpoint *b;
7890
7892
7894 /* locspec has to be used or breakpoint_re_set will delete me. */
7895 b->locspec = new_address_location_spec (b->first_loc ().address, NULL, 0);
7896
7898
7899 return b;
7900}
7901
7903 {
7906 };
7907
7908/* Create a breakpoint for JIT code registration and unregistration. */
7909
7910struct breakpoint *
7911create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7912{
7914}
7915
7916/* Remove JIT code registration and unregistration breakpoint(s). */
7917
7918void
7920{
7921 for (breakpoint &b : all_breakpoints_safe ())
7922 if (b.type == bp_jit_event
7924 delete_breakpoint (&b);
7925}
7926
7927void
7935
7936/* See breakpoint.h. */
7937
7938void
7946
7947/* Helper for create_solib_event_breakpoint /
7948 create_and_insert_solib_event_breakpoint. Allows specifying which
7949 INSERT_MODE to pass through to update_global_location_list. */
7950
7951static struct breakpoint *
7953 enum ugll_insert_mode insert_mode)
7954{
7955 struct breakpoint *b;
7956
7959 return b;
7960}
7961
7962struct breakpoint *
7964{
7966}
7967
7968/* See breakpoint.h. */
7969
7970struct breakpoint *
7972{
7973 struct breakpoint *b;
7974
7975 /* Explicitly tell update_global_location_list to insert
7976 locations. */
7978 if (!b->first_loc ().inserted)
7979 {
7981 return NULL;
7982 }
7983 return b;
7984}
7985
7986/* Disable any breakpoints that are on code in shared libraries. Only
7987 apply to enabled breakpoints, disabled ones can just stay disabled. */
7988
7989void
7991{
7992 for (bp_location *loc : all_bp_locations ())
7993 {
7994 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7995 struct breakpoint *b = loc->owner;
7996
7997 /* We apply the check to all breakpoints, including disabled for
7998 those with loc->duplicate set. This is so that when breakpoint
7999 becomes enabled, or the duplicate is removed, gdb will try to
8000 insert all breakpoints. If we don't set shlib_disabled here,
8001 we'll try to insert those breakpoints and fail. */
8002 if (((b->type == bp_breakpoint)
8003 || (b->type == bp_jit_event)
8004 || (b->type == bp_hardware_breakpoint)
8005 || (is_tracepoint (b)))
8006 && loc->pspace == current_program_space
8007 && !loc->shlib_disabled
8008 && solib_name_from_address (loc->pspace, loc->address)
8009 )
8010 {
8011 loc->shlib_disabled = 1;
8012 }
8013 }
8014}
8015
8016/* Disable any breakpoints and tracepoints that are in SOLIB upon
8017 notification of unloaded_shlib. Only apply to enabled breakpoints,
8018 disabled ones can just stay disabled. */
8019
8020static void
8022{
8023 bool disabled_shlib_breaks = false;
8024
8025 for (bp_location *loc : all_bp_locations ())
8026 {
8027 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
8028 struct breakpoint *b = loc->owner;
8029
8030 if (pspace == loc->pspace
8031 && !loc->shlib_disabled
8032 && (((b->type == bp_breakpoint
8033 || b->type == bp_jit_event
8035 && (loc->loc_type == bp_loc_hardware_breakpoint
8036 || loc->loc_type == bp_loc_software_breakpoint))
8037 || is_tracepoint (b))
8038 && solib_contains_address_p (solib, loc->address))
8039 {
8040 loc->shlib_disabled = 1;
8041 /* At this point, we cannot rely on remove_breakpoint
8042 succeeding so we must mark the breakpoint as not inserted
8043 to prevent future errors occurring in remove_breakpoints. */
8044 loc->inserted = 0;
8045
8046 /* This may cause duplicate notifications for the same breakpoint. */
8048
8049 if (!disabled_shlib_breaks)
8050 {
8052 warning (_("Temporarily disabling breakpoints "
8053 "for unloaded shared library \"%s\""),
8054 solib->so_name);
8055 }
8056 disabled_shlib_breaks = true;
8057 }
8058 }
8059}
8060
8061/* Disable any breakpoints and tracepoints in OBJFILE upon
8062 notification of free_objfile. Only apply to enabled breakpoints,
8063 disabled ones can just stay disabled. */
8064
8065static void
8067{
8068 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
8069 managed by the user with add-symbol-file/remove-symbol-file.
8070 Similarly to how breakpoints in shared libraries are handled in
8071 response to "nosharedlibrary", mark breakpoints in such modules
8072 shlib_disabled so they end up uninserted on the next global
8073 location list update. Shared libraries not loaded by the user
8074 aren't handled here -- they're already handled in
8075 disable_breakpoints_in_unloaded_shlib, called by solib.c's
8076 solib_unloaded observer. We skip objfiles that are not
8077 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
8078 main objfile). */
8079 if ((objfile->flags & OBJF_SHARED) == 0
8080 || (objfile->flags & OBJF_USERLOADED) == 0)
8081 return;
8082
8083 for (breakpoint &b : all_breakpoints ())
8084 {
8085 bool bp_modified = false;
8086
8087 if (!is_breakpoint (&b) && !is_tracepoint (&b))
8088 continue;
8089
8090 for (bp_location &loc : b.locations ())
8091 {
8092 CORE_ADDR loc_addr = loc.address;
8093
8094 if (loc.loc_type != bp_loc_hardware_breakpoint
8095 && loc.loc_type != bp_loc_software_breakpoint)
8096 continue;
8097
8098 if (loc.shlib_disabled != 0)
8099 continue;
8100
8101 if (objfile->pspace != loc.pspace)
8102 continue;
8103
8104 if (loc.loc_type != bp_loc_hardware_breakpoint
8105 && loc.loc_type != bp_loc_software_breakpoint)
8106 continue;
8107
8108 if (is_addr_in_objfile (loc_addr, objfile))
8109 {
8110 loc.shlib_disabled = 1;
8111 /* At this point, we don't know whether the object was
8112 unmapped from the inferior or not, so leave the
8113 inserted flag alone. We'll handle failure to
8114 uninsert quietly, in case the object was indeed
8115 unmapped. */
8116
8118
8119 bp_modified = true;
8120 }
8121 }
8122
8123 if (bp_modified)
8125 }
8126}
8127
8128/* See breakpoint.h. */
8129
8131 bool temp, const char *cond_string_)
8132 : type (bptype),
8134 gdbarch (gdbarch_),
8135 language (current_language->la_language),
8137 cond_string (cond_string_ != nullptr
8138 ? make_unique_xstrdup (cond_string_)
8139 : nullptr),
8140 related_breakpoint (this)
8141{
8142}
8143
8144/* See breakpoint.h. */
8145
8147 const char *cond_string)
8149{
8151
8153}
8154
8155/* Notify interpreters and observers that breakpoint B was created. */
8156
8157static void
8163
8164breakpoint *
8165install_breakpoint (int internal, std::unique_ptr<breakpoint> &&arg, int update_gll)
8166{
8167 breakpoint *b = add_to_breakpoint_chain (std::move (arg));
8168 set_breakpoint_number (internal, b);
8169 if (is_tracepoint (b))
8171 if (!internal)
8172 mention (b);
8173
8175
8176 if (update_gll)
8178
8179 return b;
8180}
8181
8182static int
8184{
8185 int i = 0;
8186
8187 for (breakpoint &b : all_breakpoints ())
8189 for (bp_location &bl : b.locations ())
8190 {
8191 /* Special types of hardware breakpoints may use more than
8192 one register. */
8193 i += b.resources_needed (&bl);
8194 }
8195
8196 return i;
8197}
8198
8199/* Returns the resources B would use if it were a hardware
8200 watchpoint. */
8201
8202static int
8204{
8205 int i = 0;
8206
8207 if (!breakpoint_enabled (b))
8208 return 0;
8209
8210 for (bp_location &bl : b->locations ())
8211 {
8212 /* Special types of hardware watchpoints may use more than
8213 one register. */
8214 i += b->resources_needed (&bl);
8215 }
8216
8217 return i;
8218}
8219
8220/* Returns the sum the used resources of all hardware watchpoints of
8221 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8222 the sum of the used resources of all hardware watchpoints of other
8223 types _not_ TYPE. */
8224
8225static int
8227 enum bptype type, int *other_type_used)
8228{
8229 int i = 0;
8230
8231 *other_type_used = 0;
8232 for (breakpoint &b : all_breakpoints ())
8233 {
8234 if (&b == except)
8235 continue;
8236 if (!breakpoint_enabled (&b))
8237 continue;
8238
8239 if (b.type == type)
8240 i += hw_watchpoint_use_count (&b);
8241 else if (is_hardware_watchpoint (&b))
8242 *other_type_used = 1;
8243 }
8244
8245 return i;
8246}
8247
8248void
8258
8259void
8269
8270void
8276
8277void
8283
8284/* Allocate a new momentary breakpoint. */
8285
8286template<typename... Arg>
8287static momentary_breakpoint *
8289 Arg&&... args)
8290{
8291 if (type == bp_longjmp || type == bp_exception)
8292 return new longjmp_breakpoint (gdbarch, type,
8293 std::forward<Arg> (args)...);
8294 else
8295 return new momentary_breakpoint (gdbarch, type,
8296 std::forward<Arg> (args)...);
8297}
8298
8299/* Set a momentary breakpoint of type TYPE at address specified by
8300 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8301 frame. */
8302
8305 struct frame_id frame_id, enum bptype type)
8306{
8307 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8308 tail-called one. */
8309 gdb_assert (!frame_id_artificial_p (frame_id));
8310
8311 std::unique_ptr<momentary_breakpoint> b
8313 inferior_thread ()->global_num));
8314
8315 b->add_location (sal);
8316
8317 breakpoint_up bp (add_to_breakpoint_chain (std::move (b)));
8318
8320
8321 return bp;
8322}
8323
8324/* Make a momentary breakpoint based on the master breakpoint ORIG.
8325 The new breakpoint will have type TYPE, use OPS as its
8326 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8327
8328static struct breakpoint *
8330 enum bptype type,
8331 int loc_enabled,
8332 int thread)
8333{
8334 std::unique_ptr<breakpoint> copy
8336 orig->frame_id, thread));
8337 const bp_location &orig_loc = orig->first_loc ();
8338 bp_location *copy_loc = copy->allocate_location ();
8339 copy->add_location (*copy_loc);
8341
8342 copy_loc->gdbarch = orig_loc.gdbarch;
8343 copy_loc->requested_address = orig_loc.requested_address;
8344 copy_loc->address = orig_loc.address;
8345 copy_loc->section = orig_loc.section;
8346 copy_loc->pspace = orig_loc.pspace;
8347 copy_loc->probe = orig_loc.probe;
8348 copy_loc->line_number = orig_loc.line_number;
8349 copy_loc->symtab = orig_loc.symtab;
8350 copy_loc->enabled = loc_enabled;
8351
8352 breakpoint *b = add_to_breakpoint_chain (std::move (copy));
8354 return b;
8355}
8356
8357/* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8358 ORIG is NULL. */
8359
8360struct breakpoint *
8362{
8363 /* If there's nothing to clone, then return nothing. */
8364 if (orig == NULL)
8365 return NULL;
8366
8367 return momentary_breakpoint_from_master (orig, orig->type, 0,
8368 orig->thread);
8369}
8370
8373 enum bptype type)
8374{
8375 struct symtab_and_line sal;
8376
8377 sal = find_pc_line (pc, 0);
8378 sal.pc = pc;
8379 sal.section = find_pc_overlay (pc);
8380 sal.explicit_pc = 1;
8381
8383}
8384
8385
8386/* Tell the user we have just set a breakpoint B. */
8387
8388static void
8390{
8391 b->print_mention ();
8392 current_uiout->text ("\n");
8393}
8394
8395
8396static bool bp_loc_is_permanent (struct bp_location *loc);
8397
8398/* Handle "set breakpoint auto-hw on".
8399
8400 If the explicitly specified breakpoint type is not hardware
8401 breakpoint, check the memory map to see whether the breakpoint
8402 address is in read-only memory.
8403
8404 - location type is not hardware breakpoint, memory is read-only.
8405 We change the type of the location to hardware breakpoint.
8406
8407 - location type is hardware breakpoint, memory is read-write. This
8408 means we've previously made the location hardware one, but then the
8409 memory map changed, so we undo.
8410*/
8411
8412static void
8414{
8419 {
8420 /* When breakpoints are removed, remove_breakpoints will use
8421 location types we've just set here, the only possible problem
8422 is that memory map has changed during running program, but
8423 it's not going to work anyway with current gdb. */
8425
8426 if (mr != nullptr)
8427 {
8428 enum bp_loc_type new_type;
8429
8430 if (mr->attrib.mode != MEM_RW)
8432 else
8434
8435 if (new_type != bl->loc_type)
8436 {
8437 static bool said = false;
8438
8439 bl->loc_type = new_type;
8440 if (!said)
8441 {
8442 gdb_printf (_("Note: automatically using "
8443 "hardware breakpoints for "
8444 "read-only addresses.\n"));
8445 said = true;
8446 }
8447 }
8448 }
8449 }
8450}
8451
8454{
8455 CORE_ADDR adjusted_address;
8456 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
8457
8458 if (loc_gdbarch == NULL)
8459 loc_gdbarch = gdbarch;
8460
8461 /* Adjust the breakpoint's address prior to allocating a location.
8462 Once we call allocate_location(), that mostly uninitialized
8463 location will be placed on the location chain. Adjustment of the
8464 breakpoint may cause target_read_memory() to be called and we do
8465 not want its scan of the location chain to find a breakpoint and
8466 location that's only been partially initialized. */
8467 adjusted_address = adjust_breakpoint_address (loc_gdbarch,
8468 sal.pc, type,
8469 sal.pspace);
8470
8471 /* Sort the locations by their ADDRESS. */
8472 bp_location *new_loc = this->allocate_location ();
8473
8474 new_loc->requested_address = sal.pc;
8475 new_loc->address = adjusted_address;
8476 new_loc->pspace = sal.pspace;
8477 new_loc->probe.prob = sal.prob;
8478 new_loc->probe.objfile = sal.objfile;
8479 gdb_assert (new_loc->pspace != NULL);
8480 new_loc->section = sal.section;
8481 new_loc->gdbarch = loc_gdbarch;
8482 new_loc->line_number = sal.line;
8483 new_loc->symtab = sal.symtab;
8484 new_loc->symbol = sal.symbol;
8485 new_loc->msymbol = sal.msymbol;
8486 new_loc->objfile = sal.objfile;
8487
8488 breakpoint::add_location (*new_loc);
8489
8491
8492 /* While by definition, permanent breakpoints are already present in the
8493 code, we don't mark the location as inserted. Normally one would expect
8494 that GDB could rely on that breakpoint instruction to stop the program,
8495 thus removing the need to insert its own breakpoint, except that executing
8496 the breakpoint instruction can kill the target instead of reporting a
8497 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
8498 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
8499 with "Trap 0x02 while interrupts disabled, Error state". Letting the
8500 breakpoint be inserted normally results in QEMU knowing about the GDB
8501 breakpoint, and thus trap before the breakpoint instruction is executed.
8502 (If GDB later needs to continue execution past the permanent breakpoint,
8503 it manually increments the PC, thus avoiding executing the breakpoint
8504 instruction.) */
8505 if (bp_loc_is_permanent (new_loc))
8506 new_loc->permanent = 1;
8507
8508 return new_loc;
8509}
8510
8511
8512/* Return true if LOC is pointing to a permanent breakpoint,
8513 return false otherwise. */
8514
8515static bool
8517{
8518 gdb_assert (loc != NULL);
8519
8520 /* If we have a non-breakpoint-backed catchpoint or a software
8521 watchpoint, just return 0. We should not attempt to read from
8522 the addresses the locations of these breakpoint types point to.
8523 gdbarch_program_breakpoint_here_p, below, will attempt to read
8524 memory. */
8526 return false;
8527
8528 scoped_restore_current_pspace_and_thread restore_pspace_thread;
8530 return gdbarch_program_breakpoint_here_p (loc->gdbarch, loc->address);
8531}
8532
8533/* Build a command list for the dprintf corresponding to the current
8534 settings of the dprintf style options. */
8535
8536static void
8538{
8539 const char *dprintf_args = b->extra_string.get ();
8540 gdb::unique_xmalloc_ptr<char> printf_line = nullptr;
8541
8542 if (!dprintf_args)
8543 return;
8544
8545 dprintf_args = skip_spaces (dprintf_args);
8546
8547 /* Allow a comma, as it may have terminated a location, but don't
8548 insist on it. */
8549 if (*dprintf_args == ',')
8550 ++dprintf_args;
8551 dprintf_args = skip_spaces (dprintf_args);
8552
8553 if (*dprintf_args != '"')
8554 error (_("Bad format string, missing '\"'."));
8555
8556 if (strcmp (dprintf_style, dprintf_style_gdb) == 0)
8557 printf_line = xstrprintf ("printf %s", dprintf_args);
8558 else if (strcmp (dprintf_style, dprintf_style_call) == 0)
8559 {
8560 if (dprintf_function.empty ())
8561 error (_("No function supplied for dprintf call"));
8562
8563 if (!dprintf_channel.empty ())
8564 printf_line = xstrprintf ("call (void) %s (%s,%s)",
8565 dprintf_function.c_str (),
8566 dprintf_channel.c_str (),
8567 dprintf_args);
8568 else
8569 printf_line = xstrprintf ("call (void) %s (%s)",
8570 dprintf_function.c_str (),
8571 dprintf_args);
8572 }
8573 else if (strcmp (dprintf_style, dprintf_style_agent) == 0)
8574 {
8576 printf_line = xstrprintf ("agent-printf %s", dprintf_args);
8577 else
8578 {
8579 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
8580 printf_line = xstrprintf ("printf %s", dprintf_args);
8581 }
8582 }
8583 else
8584 internal_error (_("Invalid dprintf style."));
8585
8586 gdb_assert (printf_line != NULL);
8587
8588 /* Manufacture a printf sequence. */
8589 struct command_line *printf_cmd_line
8590 = new struct command_line (simple_control, printf_line.release ());
8591 breakpoint_set_commands (b, counted_command_line (printf_cmd_line,
8593}
8594
8595/* Update all dprintf commands, making their command lists reflect
8596 current style settings. */
8597
8598static void
8599update_dprintf_commands (const char *args, int from_tty,
8600 struct cmd_list_element *c)
8601{
8602 for (breakpoint &b : all_breakpoints ())
8603 if (b.type == bp_dprintf)
8605}
8606
8608 enum bptype type_,
8609 gdb::array_view<const symtab_and_line> sals,
8610 location_spec_up &&locspec_,
8611 gdb::unique_xmalloc_ptr<char> filter_,
8612 gdb::unique_xmalloc_ptr<char> cond_string_,
8613 gdb::unique_xmalloc_ptr<char> extra_string_,
8614 enum bpdisp disposition_,
8615 int thread_, int task_, int inferior_,
8616 int ignore_count_,
8617 int from_tty,
8618 int enabled_, unsigned flags,
8619 int display_canonical_)
8620 : breakpoint (gdbarch_, type_)
8621{
8622 int i;
8623
8625 {
8626 int target_resources_ok;
8627
8629 target_resources_ok =
8631 i + 1, 0);
8632 if (target_resources_ok == 0)
8633 error (_("No hardware breakpoint support in the target."));
8634 else if (target_resources_ok < 0)
8635 error (_("Hardware breakpoints used exceeds limit."));
8636 }
8637
8638 gdb_assert (!sals.empty ());
8639
8640 /* At most one of thread, task, or inferior can be set on any breakpoint. */
8641 gdb_assert (((thread == -1 ? 0 : 1)
8642 + (task == -1 ? 0 : 1)
8643 + (inferior == -1 ? 0 : 1)) <= 1);
8644
8645 thread = thread_;
8646 task = task_;
8647 inferior = inferior_;
8648
8649 cond_string = std::move (cond_string_);
8650 extra_string = std::move (extra_string_);
8651 ignore_count = ignore_count_;
8652 enable_state = enabled_ ? bp_enabled : bp_disabled;
8653 disposition = disposition_;
8654
8657 {
8658 auto *t = gdb::checked_static_cast<tracepoint *> (this);
8659 struct static_tracepoint_marker marker;
8660
8661 if (strace_marker_p (this))
8662 {
8663 /* We already know the marker exists, otherwise, we wouldn't
8664 see a sal for it. */
8665 const char *p = &locspec_->to_string ()[3];
8666 const char *endp;
8667
8668 p = skip_spaces (p);
8669
8670 endp = skip_to_space (p);
8671
8672 t->static_trace_marker_id.assign (p, endp - p);
8673
8674 gdb_printf (_("Probed static tracepoint marker \"%s\"\n"),
8675 t->static_trace_marker_id.c_str ());
8676 }
8677 else if (target_static_tracepoint_marker_at (sals[0].pc, &marker))
8678 {
8679 t->static_trace_marker_id = std::move (marker.str_id);
8680
8681 gdb_printf (_("Probed static tracepoint marker \"%s\"\n"),
8682 t->static_trace_marker_id.c_str ());
8683 }
8684 else
8685 warning (_("Couldn't determine the static tracepoint marker to probe"));
8686 }
8687
8688 for (const auto &sal : sals)
8689 {
8690 if (from_tty)
8691 {
8692 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
8693 if (loc_gdbarch == nullptr)
8694 loc_gdbarch = gdbarch;
8695
8696 describe_other_breakpoints (loc_gdbarch,
8697 sal.pspace, sal.pc, sal.section, thread);
8698 }
8699
8700 bp_location *new_loc = add_location (sal);
8702 new_loc->inserted = 1;
8703
8704 /* Do not set breakpoint locations conditions yet. As locations
8705 are inserted, they get sorted based on their addresses. Let
8706 the list stabilize to have reliable location numbers. */
8707
8708 /* Dynamic printf requires and uses additional arguments on the
8709 command line, otherwise it's an error. */
8710 if (type == bp_dprintf)
8711 {
8712 if (extra_string != nullptr)
8714 else
8715 error (_("Format string required"));
8716 }
8717 else if (extra_string != nullptr)
8718 error (_("Garbage '%s' at end of command"), extra_string.get ());
8719 }
8720
8721 /* The order of the locations is now stable. Set the location
8722 condition using the location's number. */
8723 int loc_num = 1;
8724 for (bp_location &bl : locations ())
8725 {
8726 if (cond_string != nullptr)
8728 number, loc_num);
8729
8730 ++loc_num;
8731 }
8732
8733 display_canonical = display_canonical_;
8734 if (locspec_ != nullptr)
8735 locspec = std::move (locspec_);
8736 else
8737 locspec = new_address_location_spec (this->first_loc ().address, NULL, 0);
8738 filter = std::move (filter_);
8739}
8740
8741static void
8743 gdb::array_view<const symtab_and_line> sals,
8744 location_spec_up &&locspec,
8745 gdb::unique_xmalloc_ptr<char> filter,
8746 gdb::unique_xmalloc_ptr<char> cond_string,
8747 gdb::unique_xmalloc_ptr<char> extra_string,
8748 enum bptype type, enum bpdisp disposition,
8749 int thread, int task, int inferior, int ignore_count,
8750 int from_tty,
8751 int enabled, int internal, unsigned flags,
8752 int display_canonical)
8753{
8754 std::unique_ptr<code_breakpoint> b
8756 type,
8757 sals,
8758 std::move (locspec),
8759 std::move (filter),
8760 std::move (cond_string),
8761 std::move (extra_string),
8762 disposition,
8763 thread, task, inferior, ignore_count,
8764 from_tty,
8765 enabled, flags,
8766 display_canonical);
8767
8768 install_breakpoint (internal, std::move (b), 0);
8769}
8770
8771/* Add SALS.nelts breakpoints to the breakpoint table. For each
8772 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
8773 value. COND_STRING, if not NULL, specified the condition to be
8774 used for all breakpoints. Essentially the only case where
8775 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
8776 function. In that case, it's still not possible to specify
8777 separate conditions for different overloaded functions, so
8778 we take just a single condition string.
8779
8780 NOTE: If the function succeeds, the caller is expected to cleanup
8781 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
8782 array contents). If the function fails (error() is called), the
8783 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
8784 COND and SALS arrays and each of those arrays contents. */
8785
8786static void
8788 struct linespec_result *canonical,
8789 gdb::unique_xmalloc_ptr<char> cond_string,
8790 gdb::unique_xmalloc_ptr<char> extra_string,
8791 enum bptype type, enum bpdisp disposition,
8792 int thread, int task, int inferior,
8793 int ignore_count,
8794 int from_tty,
8795 int enabled, int internal, unsigned flags)
8796{
8797 if (canonical->pre_expanded)
8798 gdb_assert (canonical->lsals.size () == 1);
8799
8800 for (const auto &lsal : canonical->lsals)
8801 {
8802 /* Note that 'location' can be NULL in the case of a plain
8803 'break', without arguments. */
8804 location_spec_up locspec
8805 = (canonical->locspec != nullptr
8806 ? canonical->locspec->clone ()
8807 : nullptr);
8808 gdb::unique_xmalloc_ptr<char> filter_string
8809 (lsal.canonical != NULL ? xstrdup (lsal.canonical) : NULL);
8810
8811 create_breakpoint_sal (gdbarch, lsal.sals,
8812 std::move (locspec),
8813 std::move (filter_string),
8814 std::move (cond_string),
8815 std::move (extra_string),
8816 type, disposition,
8817 thread, task, inferior, ignore_count,
8818 from_tty, enabled, internal, flags,
8819 canonical->special_display);
8820 }
8821}
8822
8823/* Parse LOCSPEC which is assumed to be a SAL specification possibly
8824 followed by conditionals. On return, SALS contains an array of SAL
8825 addresses found. LOCSPEC points to the end of the SAL (for
8826 linespec locspecs).
8827
8828 The array and the line spec strings are allocated on the heap, it is
8829 the caller's responsibility to free them. */
8830
8831static void
8833 struct linespec_result *canonical)
8834{
8835 struct symtab_and_line cursal;
8836
8837 if (locspec->type () == LINESPEC_LOCATION_SPEC)
8838 {
8839 const char *spec = as_linespec_location_spec (locspec)->spec_string;
8840
8841 if (spec == NULL)
8842 {
8843 /* The last displayed codepoint, if it's valid, is our default
8844 breakpoint address. */
8846 {
8847 /* Set sal's pspace, pc, symtab, and line to the values
8848 corresponding to the last call to print_frame_info.
8849 Be sure to reinitialize LINE with NOTCURRENT == 0
8850 as the breakpoint line number is inappropriate otherwise.
8851 find_pc_line would adjust PC, re-set it back. */
8853 CORE_ADDR pc = sal.pc;
8854
8855 sal = find_pc_line (pc, 0);
8856
8857 /* "break" without arguments is equivalent to "break *PC"
8858 where PC is the last displayed codepoint's address. So
8859 make sure to set sal.explicit_pc to prevent GDB from
8860 trying to expand the list of sals to include all other
8861 instances with the same symtab and line. */
8862 sal.pc = pc;
8863 sal.explicit_pc = 1;
8864
8865 struct linespec_sals lsal;
8866 lsal.sals = {sal};
8867 lsal.canonical = NULL;
8868
8869 canonical->lsals.push_back (std::move (lsal));
8870 return;
8871 }
8872 else
8873 error (_("No default breakpoint address now."));
8874 }
8875 }
8876
8877 /* Force almost all breakpoints to be in terms of the
8878 current_source_symtab (which is decode_line_1's default).
8879 This should produce the results we want almost all of the
8880 time while leaving default_breakpoint_* alone.
8881
8882 ObjC: However, don't match an Objective-C method name which
8883 may have a '+' or '-' succeeded by a '['. */
8886 {
8887 const char *spec = NULL;
8888
8889 if (locspec->type () == LINESPEC_LOCATION_SPEC)
8890 spec = as_linespec_location_spec (locspec)->spec_string;
8891
8892 if (!cursal.symtab
8893 || (spec != NULL
8894 && strchr ("+-", spec[0]) != NULL
8895 && spec[1] != '['))
8896 {
8900 canonical, NULL, NULL);
8901 return;
8902 }
8903 }
8904
8906 cursal.symtab, cursal.line, canonical, NULL, NULL);
8907}
8908
8909
8910/* Convert each SAL into a real PC. Verify that the PC can be
8911 inserted as a breakpoint. If it can't throw an error. */
8912
8913static void
8914breakpoint_sals_to_pc (std::vector<symtab_and_line> &sals)
8915{
8916 for (auto &sal : sals)
8917 resolve_sal_pc (&sal);
8918}
8919
8920/* Fast tracepoints may have restrictions on valid locations. For
8921 instance, a fast tracepoint using a jump instead of a trap will
8922 likely have to overwrite more bytes than a trap would, and so can
8923 only be placed where the instruction is longer than the jump, or a
8924 multi-instruction sequence does not have a jump into the middle of
8925 it, etc. */
8926
8927static void
8929 gdb::array_view<const symtab_and_line> sals)
8930{
8931 for (const auto &sal : sals)
8932 {
8933 struct gdbarch *sarch;
8934
8935 sarch = get_sal_arch (sal);
8936 /* We fall back to GDBARCH if there is no architecture
8937 associated with SAL. */
8938 if (sarch == NULL)
8939 sarch = gdbarch;
8940 std::string msg;
8941 if (!gdbarch_fast_tracepoint_valid_at (sarch, sal.pc, &msg))
8942 error (_("May not have a fast tracepoint at %s%s"),
8943 paddress (sarch, sal.pc), msg.c_str ());
8944 }
8945}
8946
8947/* Given TOK, a string specification of condition and thread, as accepted
8948 by the 'break' command, extract the condition string into *COND_STRING.
8949 If no condition string is found then *COND_STRING is set to nullptr.
8950
8951 If the breakpoint specification has an associated thread, task, or
8952 inferior, these are extracted into *THREAD, *TASK, and *INFERIOR
8953 respectively, otherwise these arguments are set to -1 (for THREAD and
8954 INFERIOR) or 0 (for TASK).
8955
8956 PC identifies the context at which the condition should be parsed. */
8957
8958static void
8959find_condition_and_thread (const char *tok, CORE_ADDR pc,
8960 gdb::unique_xmalloc_ptr<char> *cond_string,
8961 int *thread, int *inferior, int *task,
8962 gdb::unique_xmalloc_ptr<char> *rest)
8963{
8964 cond_string->reset ();
8965 *thread = -1;
8966 *inferior = -1;
8967 *task = -1;
8968 rest->reset ();
8969 bool force = false;
8970
8971 while (tok && *tok)
8972 {
8973 const char *end_tok;
8974 int toklen;
8975 const char *cond_start = NULL;
8976 const char *cond_end = NULL;
8977
8978 tok = skip_spaces (tok);
8979
8980 if ((*tok == '"' || *tok == ',') && rest)
8981 {
8982 rest->reset (savestring (tok, strlen (tok)));
8983 break;
8984 }
8985
8986 end_tok = skip_to_space (tok);
8987
8988 toklen = end_tok - tok;
8989
8990 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
8991 {
8992 tok = cond_start = end_tok + 1;
8993 try
8994 {
8995 parse_exp_1 (&tok, pc, block_for_pc (pc), 0);
8996 }
8997 catch (const gdb_exception_error &)
8998 {
8999 if (!force)
9000 throw;
9001 else
9002 tok = tok + strlen (tok);
9003 }
9004 cond_end = tok;
9005 cond_string->reset (savestring (cond_start, cond_end - cond_start));
9006 }
9007 else if (toklen >= 1 && strncmp (tok, "-force-condition", toklen) == 0)
9008 {
9009 tok = tok + toklen;
9010 force = true;
9011 }
9012 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
9013 {
9014 const char *tmptok;
9015 struct thread_info *thr;
9016
9017 if (*thread != -1)
9018 error(_("You can specify only one thread."));
9019
9020 if (*task != -1)
9021 error (_("You can specify only one of thread or task."));
9022
9023 if (*inferior != -1)
9024 error (_("You can specify only one of inferior or thread."));
9025
9026 tok = end_tok + 1;
9027 thr = parse_thread_id (tok, &tmptok);
9028 if (tok == tmptok)
9029 error (_("Junk after thread keyword."));
9030 *thread = thr->global_num;
9031 tok = tmptok;
9032 }
9033 else if (toklen >= 1 && strncmp (tok, "inferior", toklen) == 0)
9034 {
9035 if (*inferior != -1)
9036 error(_("You can specify only one inferior."));
9037
9038 if (*task != -1)
9039 error (_("You can specify only one of inferior or task."));
9040
9041 if (*thread != -1)
9042 error (_("You can specify only one of inferior or thread."));
9043
9044 char *tmptok;
9045 tok = end_tok + 1;
9046 *inferior = strtol (tok, &tmptok, 0);
9047 if (tok == tmptok)
9048 error (_("Junk after inferior keyword."));
9050 error (_("Unknown inferior number %d."), *inferior);
9051 tok = tmptok;
9052 }
9053 else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0)
9054 {
9055 char *tmptok;
9056
9057 if (*task != -1)
9058 error(_("You can specify only one task."));
9059
9060 if (*thread != -1)
9061 error (_("You can specify only one of thread or task."));
9062
9063 if (*inferior != -1)
9064 error (_("You can specify only one of inferior or task."));
9065
9066 tok = end_tok + 1;
9067 *task = strtol (tok, &tmptok, 0);
9068 if (tok == tmptok)
9069 error (_("Junk after task keyword."));
9070 if (!valid_task_id (*task))
9071 error (_("Unknown task %d."), *task);
9072 tok = tmptok;
9073 }
9074 else if (rest)
9075 {
9076 rest->reset (savestring (tok, strlen (tok)));
9077 break;
9078 }
9079 else
9080 error (_("Junk at end of arguments."));
9081 }
9082}
9083
9084/* Call 'find_condition_and_thread' for each sal in SALS until a parse
9085 succeeds. The parsed values are written to COND_STRING, THREAD,
9086 TASK, and REST. See the comment of 'find_condition_and_thread'
9087 for the description of these parameters and INPUT. */
9088
9089static void
9090find_condition_and_thread_for_sals (const std::vector<symtab_and_line> &sals,
9091 const char *input,
9092 gdb::unique_xmalloc_ptr<char> *cond_string,
9093 int *thread, int *inferior, int *task,
9094 gdb::unique_xmalloc_ptr<char> *rest)
9095{
9096 int num_failures = 0;
9097 for (auto &sal : sals)
9098 {
9099 gdb::unique_xmalloc_ptr<char> cond;
9100 int thread_id = -1;
9101 int inferior_id = -1;
9102 int task_id = -1;
9103 gdb::unique_xmalloc_ptr<char> remaining;
9104
9105 /* Here we want to parse 'arg' to separate condition from thread
9106 number. But because parsing happens in a context and the
9107 contexts of sals might be different, try each until there is
9108 success. Finding one successful parse is sufficient for our
9109 goal. When setting the breakpoint we'll re-parse the
9110 condition in the context of each sal. */
9111 try
9112 {
9113 find_condition_and_thread (input, sal.pc, &cond, &thread_id,
9114 &inferior_id, &task_id, &remaining);
9115 *cond_string = std::move (cond);
9116 /* A value of -1 indicates that these fields are unset. At most
9117 one of these fields should be set (to a value other than -1)
9118 at this point. */
9119 gdb_assert (((thread_id == -1 ? 1 : 0)
9120 + (task_id == -1 ? 1 : 0)
9121 + (inferior_id == -1 ? 1 : 0)) >= 2);
9122 *thread = thread_id;
9123 *inferior = inferior_id;
9124 *task = task_id;
9125 *rest = std::move (remaining);
9126 break;
9127 }
9128 catch (const gdb_exception_error &e)
9129 {
9130 num_failures++;
9131 /* If no sal remains, do not continue. */
9132 if (num_failures == sals.size ())
9133 throw;
9134 }
9135 }
9136}
9137
9138/* Decode a static tracepoint marker spec. */
9139
9140static std::vector<symtab_and_line>
9142{
9143 const char *p = &(*arg_p)[3];
9144 const char *endp;
9145
9146 p = skip_spaces (p);
9147
9148 endp = skip_to_space (p);
9149
9150 std::string marker_str (p, endp - p);
9151
9152 std::vector<static_tracepoint_marker> markers
9153 = target_static_tracepoint_markers_by_strid (marker_str.c_str ());
9154 if (markers.empty ())
9155 error (_("No known static tracepoint marker named %s"),
9156 marker_str.c_str ());
9157
9158 std::vector<symtab_and_line> sals;
9159 sals.reserve (markers.size ());
9160
9161 for (const static_tracepoint_marker &marker : markers)
9162 {
9163 symtab_and_line sal = find_pc_line (marker.address, 0);
9164 sal.pc = marker.address;
9165 sals.push_back (sal);
9166 }
9167
9168 *arg_p = endp;
9169 return sals;
9170}
9171
9172/* Returns the breakpoint ops appropriate for use with with LOCATION_TYPE and
9173 according to IS_TRACEPOINT. */
9174
9175static const struct breakpoint_ops *
9177 bool is_tracepoint)
9178{
9179 if (is_tracepoint)
9180 {
9181 if (locspec_type == PROBE_LOCATION_SPEC)
9183 else
9184 return &code_breakpoint_ops;
9185 }
9186 else
9187 {
9188 if (locspec_type == PROBE_LOCATION_SPEC)
9190 else
9191 return &code_breakpoint_ops;
9192 }
9193}
9194
9195/* See breakpoint.h. */
9196
9197const struct breakpoint_ops *
9199 bool is_tracepoint)
9200{
9201 if (locspec != nullptr)
9203 (locspec->type (), is_tracepoint));
9204 return &code_breakpoint_ops;
9205}
9206
9207/* See breakpoint.h. */
9208
9209int
9211 location_spec *locspec,
9212 const char *cond_string,
9213 int thread, int inferior,
9214 const char *extra_string,
9215 bool force_condition, int parse_extra,
9216 int tempflag, enum bptype type_wanted,
9217 int ignore_count,
9219 const struct breakpoint_ops *ops,
9220 int from_tty, int enabled, int internal,
9221 unsigned flags)
9222{
9223 struct linespec_result canonical;
9224 bool pending = false;
9225 int task = -1;
9226 int prev_bkpt_count = breakpoint_count;
9227
9228 gdb_assert (thread == -1 || thread > 0);
9229 gdb_assert (inferior == -1 || inferior > 0);
9230 gdb_assert (thread == -1 || inferior == -1);
9231
9232 gdb_assert (ops != NULL);
9233
9234 /* If extra_string isn't useful, set it to NULL. */
9235 if (extra_string != NULL && *extra_string == '\0')
9236 extra_string = NULL;
9237
9238 try
9239 {
9240 ops->create_sals_from_location_spec (locspec, &canonical);
9241 }
9242 catch (const gdb_exception_error &e)
9243 {
9244 /* If caller is interested in rc value from parse, set
9245 value. */
9246 if (e.error == NOT_FOUND_ERROR)
9247 {
9248 /* If pending breakpoint support is turned off, throw
9249 error. */
9250
9252 throw;
9253
9255
9256 /* If pending breakpoint support is auto query and the user
9257 selects no, then simply return the error code. */
9259 && !nquery (_("Make %s pending on future shared library load? "),
9260 bptype_string (type_wanted)))
9261 return 0;
9262
9263 /* At this point, either the user was queried about setting
9264 a pending breakpoint and selected yes, or pending
9265 breakpoint behavior is on and thus a pending breakpoint
9266 is defaulted on behalf of the user. */
9267 pending = true;
9268 }
9269 else
9270 throw;
9271 }
9272
9273 if (!pending && canonical.lsals.empty ())
9274 return 0;
9275
9276 /* Resolve all line numbers to PC's and verify that the addresses
9277 are ok for the target. */
9278 if (!pending)
9279 {
9280 for (auto &lsal : canonical.lsals)
9281 breakpoint_sals_to_pc (lsal.sals);
9282 }
9283
9284 /* Fast tracepoints may have additional restrictions on location. */
9285 if (!pending && type_wanted == bp_fast_tracepoint)
9286 {
9287 for (const auto &lsal : canonical.lsals)
9289 }
9290
9291 /* Verify that condition can be parsed, before setting any
9292 breakpoints. Allocate a separate condition expression for each
9293 breakpoint. */
9294 if (!pending)
9295 {
9296 gdb::unique_xmalloc_ptr<char> cond_string_copy;
9297 gdb::unique_xmalloc_ptr<char> extra_string_copy;
9298
9299 if (parse_extra)
9300 {
9301 gdb::unique_xmalloc_ptr<char> rest;
9302 gdb::unique_xmalloc_ptr<char> cond;
9303
9304 const linespec_sals &lsal = canonical.lsals[0];
9305
9306 find_condition_and_thread_for_sals (lsal.sals, extra_string,
9307 &cond, &thread, &inferior,
9308 &task, &rest);
9309 cond_string_copy = std::move (cond);
9310 extra_string_copy = std::move (rest);
9311 }
9312 else
9313 {
9314 if (type_wanted != bp_dprintf
9315 && extra_string != NULL && *extra_string != '\0')
9316 error (_("Garbage '%s' at end of location"), extra_string);
9317
9318 /* Check the validity of the condition. We should error out
9319 if the condition is invalid at all of the locations and
9320 if it is not forced. In the PARSE_EXTRA case above, this
9321 check is done when parsing the EXTRA_STRING. */
9322 if (cond_string != nullptr && !force_condition)
9323 {
9324 int num_failures = 0;
9325 const linespec_sals &lsal = canonical.lsals[0];
9326 for (const auto &sal : lsal.sals)
9327 {
9328 const char *cond = cond_string;
9329 try
9330 {
9331 parse_exp_1 (&cond, sal.pc, block_for_pc (sal.pc), 0);
9332 /* One success is sufficient to keep going. */
9333 break;
9334 }
9335 catch (const gdb_exception_error &)
9336 {
9337 num_failures++;
9338 /* If this is the last sal, error out. */
9339 if (num_failures == lsal.sals.size ())
9340 throw;
9341 }
9342 }
9343 }
9344
9345 /* Create a private copy of condition string. */
9346 if (cond_string)
9347 cond_string_copy.reset (xstrdup (cond_string));
9348 /* Create a private copy of any extra string. */
9349 if (extra_string)
9350 extra_string_copy.reset (xstrdup (extra_string));
9351 }
9352
9353 ops->create_breakpoints_sal (gdbarch, &canonical,
9354 std::move (cond_string_copy),
9355 std::move (extra_string_copy),
9356 type_wanted,
9357 tempflag ? disp_del : disp_donttouch,
9358 thread, task, inferior, ignore_count,
9359 from_tty, enabled, internal, flags);
9360 }
9361 else
9362 {
9363 std::unique_ptr <breakpoint> b = new_breakpoint_from_type (gdbarch,
9364 type_wanted);
9365 b->locspec = locspec->clone ();
9366
9367 if (parse_extra)
9368 b->cond_string = NULL;
9369 else
9370 {
9371 /* Create a private copy of condition string. */
9372 b->cond_string.reset (cond_string != NULL
9373 ? xstrdup (cond_string)
9374 : NULL);
9375 b->thread = thread;
9376 }
9377
9378 /* Create a private copy of any extra string. */
9379 b->extra_string.reset (extra_string != NULL
9380 ? xstrdup (extra_string)
9381 : NULL);
9382 b->ignore_count = ignore_count;
9383 b->disposition = tempflag ? disp_del : disp_donttouch;
9384 b->condition_not_parsed = 1;
9385 b->enable_state = enabled ? bp_enabled : bp_disabled;
9386 if ((type_wanted != bp_breakpoint
9387 && type_wanted != bp_hardware_breakpoint) || thread != -1)
9388 b->pspace = current_program_space;
9389
9390 install_breakpoint (internal, std::move (b), 0);
9391 }
9392
9393 if (canonical.lsals.size () > 1)
9394 {
9395 warning (_("Multiple breakpoints were set.\nUse the "
9396 "\"delete\" command to delete unwanted breakpoints."));
9397 prev_breakpoint_count = prev_bkpt_count;
9398 }
9399
9401
9402 return 1;
9403}
9404
9405/* Set a breakpoint.
9406 ARG is a string describing breakpoint address,
9407 condition, and thread.
9408 FLAG specifies if a breakpoint is hardware on,
9409 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9410 and BP_TEMPFLAG. */
9411
9412static void
9413break_command_1 (const char *arg, int flag, int from_tty)
9414{
9415 int tempflag = flag & BP_TEMPFLAG;
9416 enum bptype type_wanted = (flag & BP_HARDWAREFLAG
9418 : bp_breakpoint);
9419
9421 const struct breakpoint_ops *ops
9422 = breakpoint_ops_for_location_spec (locspec.get (),
9423 false /* is_tracepoint */);
9424
9426 locspec.get (),
9427 NULL,
9428 -1 /* thread */, -1 /* inferior */,
9429 arg, false, 1 /* parse arg */,
9430 tempflag, type_wanted,
9431 0 /* Ignore count */,
9433 ops,
9434 from_tty,
9435 1 /* enabled */,
9436 0 /* internal */,
9437 0);
9438}
9439
9440/* Helper function for break_command_1 and disassemble_command. */
9441
9442void
9444{
9445 CORE_ADDR pc;
9446
9447 if (sal->pc == 0 && sal->symtab != NULL)
9448 {
9449 if (!find_line_pc (sal->symtab, sal->line, &pc))
9450 error (_("No line %d in file \"%s\"."),
9452 sal->pc = pc;
9453
9454 /* If this SAL corresponds to a breakpoint inserted using a line
9455 number, then skip the function prologue if necessary. */
9456 if (sal->explicit_line)
9457 skip_prologue_sal (sal);
9458 }
9459
9460 if (sal->section == 0 && sal->symtab != NULL)
9461 {
9462 const struct blockvector *bv;
9463 const struct block *b;
9464 struct symbol *sym;
9465
9466 bv = blockvector_for_pc_sect (sal->pc, 0, &b,
9467 sal->symtab->compunit ());
9468 if (bv != NULL)
9469 {
9470 sym = b->linkage_function ();
9471 if (sym != NULL)
9472 sal->section
9473 = sym->obj_section (sal->symtab->compunit ()->objfile ());
9474 else
9475 {
9476 /* It really is worthwhile to have the section, so we'll
9477 just have to look harder. This case can be executed
9478 if we have line numbers but no functions (as can
9479 happen in assembly source). */
9480
9481 scoped_restore_current_pspace_and_thread restore_pspace_thread;
9483
9485 if (msym.minsym)
9486 sal->section = msym.obj_section ();
9487 }
9488 }
9489 }
9490}
9491
9492void
9493break_command (const char *arg, int from_tty)
9494{
9495 break_command_1 (arg, 0, from_tty);
9496}
9497
9498void
9499tbreak_command (const char *arg, int from_tty)
9500{
9501 break_command_1 (arg, BP_TEMPFLAG, from_tty);
9502}
9503
9504static void
9505hbreak_command (const char *arg, int from_tty)
9506{
9507 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
9508}
9509
9510static void
9511thbreak_command (const char *arg, int from_tty)
9512{
9513 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
9514}
9515
9516/* The dynamic printf command is mostly like a regular breakpoint, but
9517 with a prewired command list consisting of a single output command,
9518 built from extra arguments supplied on the dprintf command
9519 line. */
9520
9521static void
9522dprintf_command (const char *arg, int from_tty)
9523{
9525
9526 /* If non-NULL, ARG should have been advanced past the location;
9527 the next character must be ','. */
9528 if (arg != NULL)
9529 {
9530 if (arg[0] != ',' || arg[1] == '\0')
9531 error (_("Format string required"));
9532 else
9533 {
9534 /* Skip the comma. */
9535 ++arg;
9536 }
9537 }
9538
9540 locspec.get (),
9541 NULL, -1, -1,
9542 arg, false, 1 /* parse arg */,
9543 0, bp_dprintf,
9544 0 /* Ignore count */,
9547 from_tty,
9548 1 /* enabled */,
9549 0 /* internal */,
9550 0);
9551}
9552
9553static void
9554agent_printf_command (const char *arg, int from_tty)
9555{
9556 error (_("May only run agent-printf on the target"));
9557}
9558
9559/* Implement the "breakpoint_hit" method for ranged breakpoints. */
9560
9561int
9563 const address_space *aspace,
9564 CORE_ADDR bp_addr,
9565 const target_waitstatus &ws)
9566{
9567 if (ws.kind () != TARGET_WAITKIND_STOPPED
9568 || ws.sig () != GDB_SIGNAL_TRAP)
9569 return 0;
9570
9572 bl->length, aspace, bp_addr);
9573}
9574
9575/* Implement the "resources_needed" method for ranged breakpoints. */
9576
9577int
9582
9583/* Implement the "print_it" method for ranged breakpoints. */
9584
9587{
9588 struct ui_out *uiout = current_uiout;
9589
9590 gdb_assert (type == bp_hardware_breakpoint);
9591
9592 /* Ranged breakpoints have only one location. */
9593 gdb_assert (this->has_single_location ());
9594
9596
9598
9599 if (disposition == disp_del)
9600 uiout->text ("Temporary ranged breakpoint ");
9601 else
9602 uiout->text ("Ranged breakpoint ");
9603 if (uiout->is_mi_like_p ())
9604 {
9605 uiout->field_string ("reason",
9607 uiout->field_string ("disp", bpdisp_text (disposition));
9608 }
9609 print_num_locno (bs, uiout);
9610 uiout->text (", ");
9611
9612 return PRINT_SRC_AND_LOC;
9613}
9614
9615/* Implement the "print_one" method for ranged breakpoints. */
9616
9617bool
9619{
9620 struct value_print_options opts;
9621 struct ui_out *uiout = current_uiout;
9622
9623 /* Ranged breakpoints have only one location. */
9624 gdb_assert (this->has_single_location ());
9625
9626 get_user_print_options (&opts);
9627
9628 if (opts.addressprint)
9629 /* We don't print the address range here, it will be printed later
9630 by ranged_breakpoint::print_one_detail. */
9631 uiout->field_skip ("addr");
9632 annotate_field (5);
9633 print_breakpoint_location (this, &this->first_loc ());
9634 *last_loc = &this->first_loc ();
9635
9636 return true;
9637}
9638
9639/* Implement the "print_one_detail" method for ranged breakpoints. */
9640
9641void
9643{
9644 CORE_ADDR address_start, address_end;
9645 const bp_location &bl = this->first_loc ();
9646 string_file stb;
9647
9648 address_start = bl.address;
9649 address_end = address_start + bl.length - 1;
9650
9651 uiout->text ("\taddress range: ");
9652 stb.printf ("[%s, %s]",
9653 print_core_address (bl.gdbarch, address_start),
9654 print_core_address (bl.gdbarch, address_end));
9655 uiout->field_stream ("addr", stb);
9656 uiout->text ("\n");
9657}
9658
9659/* Implement the "print_mention" method for ranged breakpoints. */
9660
9661void
9663{
9664 const bp_location &bl = this->first_loc ();
9665 struct ui_out *uiout = current_uiout;
9666
9667 gdb_assert (type == bp_hardware_breakpoint);
9668
9669 uiout->message (_("Hardware assisted ranged breakpoint %d from %s to %s."),
9670 number, paddress (bl.gdbarch, bl.address),
9671 paddress (bl.gdbarch, bl.address + bl.length - 1));
9672}
9673
9674/* Implement the "print_recreate" method for ranged breakpoints. */
9675
9676void
9678{
9679 gdb_printf (fp, "break-range %s, %s",
9680 locspec->to_string (),
9681 locspec_range_end->to_string ());
9683}
9684
9685/* Find the address where the end of the breakpoint range should be
9686 placed, given the SAL of the end of the range. This is so that if
9687 the user provides a line number, the end of the range is set to the
9688 last instruction of the given line. */
9689
9690static CORE_ADDR
9692{
9693 CORE_ADDR end;
9694
9695 /* If the user provided a PC value, use it. Otherwise,
9696 find the address of the end of the given location. */
9697 if (sal.explicit_pc)
9698 end = sal.pc;
9699 else
9700 {
9701 int ret;
9702 CORE_ADDR start;
9703
9704 ret = find_line_pc_range (sal, &start, &end);
9705 if (!ret)
9706 error (_("Could not find location of the end of the range."));
9707
9708 /* find_line_pc_range returns the start of the next line. */
9709 end--;
9710 }
9711
9712 return end;
9713}
9714
9715/* Implement the "break-range" CLI command. */
9716
9717static void
9718break_range_command (const char *arg, int from_tty)
9719{
9720 const char *arg_start;
9721 struct linespec_result canonical_start, canonical_end;
9722 int bp_count, can_use_bp, length;
9723 CORE_ADDR end;
9724
9725 /* We don't support software ranged breakpoints. */
9727 error (_("This target does not support hardware ranged breakpoints."));
9728
9729 bp_count = hw_breakpoint_used_count ();
9730 bp_count += target_ranged_break_num_registers ();
9732 bp_count, 0);
9733 if (can_use_bp < 0)
9734 error (_("Hardware breakpoints used exceeds limit."));
9735
9736 arg = skip_spaces (arg);
9737 if (arg == NULL || arg[0] == '\0')
9738 error(_("No address range specified."));
9739
9740 arg_start = arg;
9741 location_spec_up start_locspec
9743 parse_breakpoint_sals (start_locspec.get (), &canonical_start);
9744
9745 if (arg[0] != ',')
9746 error (_("Too few arguments."));
9747 else if (canonical_start.lsals.empty ())
9748 error (_("Could not find location of the beginning of the range."));
9749
9750 const linespec_sals &lsal_start = canonical_start.lsals[0];
9751
9752 if (canonical_start.lsals.size () > 1
9753 || lsal_start.sals.size () != 1)
9754 error (_("Cannot create a ranged breakpoint with multiple locations."));
9755
9756 const symtab_and_line &sal_start = lsal_start.sals[0];
9757 std::string addr_string_start (arg_start, arg - arg_start);
9758
9759 arg++; /* Skip the comma. */
9760 arg = skip_spaces (arg);
9761
9762 /* Parse the end location specification. */
9763
9764 arg_start = arg;
9765
9766 /* We call decode_line_full directly here instead of using
9767 parse_breakpoint_sals because we need to specify the start
9768 location spec's symtab and line as the default symtab and line
9769 for the end of the range. This makes it possible to have ranges
9770 like "foo.c:27, +14", where +14 means 14 lines from the start
9771 location spec. */
9772 location_spec_up end_locspec
9774 decode_line_full (end_locspec.get (), DECODE_LINE_FUNFIRSTLINE, NULL,
9775 sal_start.symtab, sal_start.line,
9776 &canonical_end, NULL, NULL);
9777
9778 if (canonical_end.lsals.empty ())
9779 error (_("Could not find location of the end of the range."));
9780
9781 const linespec_sals &lsal_end = canonical_end.lsals[0];
9782 if (canonical_end.lsals.size () > 1
9783 || lsal_end.sals.size () != 1)
9784 error (_("Cannot create a ranged breakpoint with multiple locations."));
9785
9786 const symtab_and_line &sal_end = lsal_end.sals[0];
9787
9788 end = find_breakpoint_range_end (sal_end);
9789 if (sal_start.pc > end)
9790 error (_("Invalid address range, end precedes start."));
9791
9792 length = end - sal_start.pc + 1;
9793 if (length < 0)
9794 /* Length overflowed. */
9795 error (_("Address range too large."));
9796 else if (length == 1)
9797 {
9798 /* This range is simple enough to be handled by
9799 the `hbreak' command. */
9800 hbreak_command (&addr_string_start[0], 1);
9801
9802 return;
9803 }
9804
9805 /* Now set up the breakpoint and install it. */
9806
9807 std::unique_ptr<breakpoint> br
9809 sal_start, length,
9810 std::move (start_locspec),
9811 std::move (end_locspec)));
9812
9813 install_breakpoint (false, std::move (br), true);
9814}
9815
9816/* See breakpoint.h. */
9817
9819{
9820 /* Make sure to unlink the destroyed watchpoint from the related
9821 breakpoint ring. */
9822
9823 breakpoint *bpt = this;
9824 while (bpt->related_breakpoint != this)
9825 bpt = bpt->related_breakpoint;
9826
9828}
9829
9830/* Return non-zero if EXP is verified as constant. Returned zero
9831 means EXP is variable. Also the constant detection may fail for
9832 some constant expressions and in such case still falsely return
9833 zero. */
9834
9835static bool
9837{
9838 return exp->op->constant_p ();
9839}
9840
9841/* Implement the "re_set" method for watchpoints. */
9842
9843void
9845{
9846 /* Watchpoint can be either on expression using entirely global
9847 variables, or it can be on local variables.
9848
9849 Watchpoints of the first kind are never auto-deleted, and even
9850 persist across program restarts. Since they can use variables
9851 from shared libraries, we need to reparse expression as libraries
9852 are loaded and unloaded.
9853
9854 Watchpoints on local variables can also change meaning as result
9855 of solib event. For example, if a watchpoint uses both a local
9856 and a global variables in expression, it's a local watchpoint,
9857 but unloading of a shared library will make the expression
9858 invalid. This is not a very common use case, but we still
9859 re-evaluate expression, to avoid surprises to the user.
9860
9861 Note that for local watchpoints, we re-evaluate it only if
9862 watchpoints frame id is still valid. If it's not, it means the
9863 watchpoint is out of scope and will be deleted soon. In fact,
9864 I'm not sure we'll ever be called in this case.
9865
9866 If a local watchpoint's frame id is still valid, then
9867 exp_valid_block is likewise valid, and we can safely use it.
9868
9869 Don't do anything about disabled watchpoints, since they will be
9870 reevaluated again when enabled. */
9871 update_watchpoint (this, true /* reparse */);
9872}
9873
9874/* Implement the "insert" method for hardware watchpoints. */
9875
9876int
9878{
9879 int length = exact ? 1 : bl->length;
9880
9881 return target_insert_watchpoint (bl->address, length, bl->watchpoint_type,
9882 cond_exp.get ());
9883}
9884
9885/* Implement the "remove" method for hardware watchpoints. */
9886
9887int
9889 enum remove_bp_reason reason)
9890{
9891 int length = exact ? 1 : bl->length;
9892
9893 return target_remove_watchpoint (bl->address, length, bl->watchpoint_type,
9894 cond_exp.get ());
9895}
9896
9897int
9899 const address_space *aspace, CORE_ADDR bp_addr,
9900 const target_waitstatus &ws)
9901{
9902 struct breakpoint *b = bl->owner;
9903
9904 /* Continuable hardware watchpoints are treated as non-existent if the
9905 reason we stopped wasn't a hardware watchpoint (we didn't stop on
9906 some data address). Otherwise gdb won't stop on a break instruction
9907 in the code (not from a breakpoint) when a hardware watchpoint has
9908 been defined. Also skip watchpoints which we know did not trigger
9909 (did not match the data address). */
9912 return 0;
9913
9914 return 1;
9915}
9916
9917void
9922
9923/* Implement the "resources_needed" method for hardware
9924 watchpoints. */
9925
9926int
9928{
9929 int length = exact? 1 : bl->length;
9930
9931 return target_region_ok_for_hw_watchpoint (bl->address, length);
9932}
9933
9934/* Implement the "works_in_software_mode" method for hardware
9935 watchpoints. */
9936
9937bool
9939{
9940 /* Read and access watchpoints only work with hardware support. */
9942}
9943
9946{
9947 enum print_stop_action result;
9948 struct ui_out *uiout = current_uiout;
9949
9950 gdb_assert (bs->bp_location_at != NULL);
9951
9954
9955 string_file stb;
9956
9957 gdb::optional<ui_out_emit_tuple> tuple_emitter;
9958 switch (this->type)
9959 {
9960 case bp_watchpoint:
9962 if (uiout->is_mi_like_p ())
9963 uiout->field_string
9965 mention (this);
9966 tuple_emitter.emplace (uiout, "value");
9967 uiout->text ("\nOld value = ");
9968 watchpoint_value_print (bs->old_val.get (), &stb);
9969 uiout->field_stream ("old", stb);
9970 uiout->text ("\nNew value = ");
9971 watchpoint_value_print (val.get (), &stb);
9972 uiout->field_stream ("new", stb);
9973 uiout->text ("\n");
9974 /* More than one watchpoint may have been triggered. */
9975 result = PRINT_UNKNOWN;
9976 break;
9977
9978 case bp_read_watchpoint:
9979 if (uiout->is_mi_like_p ())
9980 uiout->field_string
9982 mention (this);
9983 tuple_emitter.emplace (uiout, "value");
9984 uiout->text ("\nValue = ");
9985 watchpoint_value_print (val.get (), &stb);
9986 uiout->field_stream ("value", stb);
9987 uiout->text ("\n");
9988 result = PRINT_UNKNOWN;
9989 break;
9990
9992 if (bs->old_val != NULL)
9993 {
9994 if (uiout->is_mi_like_p ())
9995 uiout->field_string
9996 ("reason",
9998 mention (this);
9999 tuple_emitter.emplace (uiout, "value");
10000 uiout->text ("\nOld value = ");
10001 watchpoint_value_print (bs->old_val.get (), &stb);
10002 uiout->field_stream ("old", stb);
10003 uiout->text ("\nNew value = ");
10004 }
10005 else
10006 {
10007 mention (this);
10008 if (uiout->is_mi_like_p ())
10009 uiout->field_string
10010 ("reason",
10012 tuple_emitter.emplace (uiout, "value");
10013 uiout->text ("\nValue = ");
10014 }
10015 watchpoint_value_print (val.get (), &stb);
10016 uiout->field_stream ("new", stb);
10017 uiout->text ("\n");
10018 result = PRINT_UNKNOWN;
10019 break;
10020 default:
10021 result = PRINT_UNKNOWN;
10022 }
10023
10024 return result;
10025}
10026
10027/* Implement the "print_mention" method for hardware watchpoints. */
10028
10029void
10031{
10032 struct ui_out *uiout = current_uiout;
10033 const char *tuple_name;
10034
10035 switch (type)
10036 {
10037 case bp_watchpoint:
10038 uiout->text ("Watchpoint ");
10039 tuple_name = "wpt";
10040 break;
10042 uiout->text ("Hardware watchpoint ");
10043 tuple_name = "wpt";
10044 break;
10045 case bp_read_watchpoint:
10046 uiout->text ("Hardware read watchpoint ");
10047 tuple_name = "hw-rwpt";
10048 break;
10050 uiout->text ("Hardware access (read/write) watchpoint ");
10051 tuple_name = "hw-awpt";
10052 break;
10053 default:
10054 internal_error (_("Invalid hardware watchpoint type."));
10055 }
10056
10057 ui_out_emit_tuple tuple_emitter (uiout, tuple_name);
10058 uiout->field_signed ("number", number);
10059 uiout->text (": ");
10060 uiout->field_string ("exp", exp_string.get ());
10061}
10062
10063/* Implement the "print_recreate" method for watchpoints. */
10064
10065void
10067{
10068 switch (type)
10069 {
10070 case bp_watchpoint:
10072 gdb_printf (fp, "watch");
10073 break;
10074 case bp_read_watchpoint:
10075 gdb_printf (fp, "rwatch");
10076 break;
10078 gdb_printf (fp, "awatch");
10079 break;
10080 default:
10081 internal_error (_("Invalid watchpoint type."));
10082 }
10083
10084 gdb_printf (fp, " %s", exp_string.get ());
10086}
10087
10088/* Implement the "explains_signal" method for watchpoints. */
10089
10090bool
10091watchpoint::explains_signal (enum gdb_signal sig)
10092{
10093 /* A software watchpoint cannot cause a signal other than
10094 GDB_SIGNAL_TRAP. */
10095 if (type == bp_watchpoint && sig != GDB_SIGNAL_TRAP)
10096 return false;
10097
10098 return true;
10099}
10100
10102{
10103 using watchpoint::watchpoint;
10104
10105 int insert_location (struct bp_location *) override;
10106 int remove_location (struct bp_location *,
10107 enum remove_bp_reason reason) override;
10108 int resources_needed (const struct bp_location *) override;
10109 bool works_in_software_mode () const override;
10110 enum print_stop_action print_it (const bpstat *bs) const override;
10111 void print_one_detail (struct ui_out *) const override;
10112 void print_mention () const override;
10113 void print_recreate (struct ui_file *fp) const override;
10114};
10115
10116/* Implement the "insert" method for masked hardware watchpoints. */
10117
10118int
10124
10125/* Implement the "remove" method for masked hardware watchpoints. */
10126
10127int
10129 enum remove_bp_reason reason)
10130{
10132 bl->watchpoint_type);
10133}
10134
10135/* Implement the "resources_needed" method for masked hardware
10136 watchpoints. */
10137
10138int
10143
10144/* Implement the "works_in_software_mode" method for masked hardware
10145 watchpoints. */
10146
10147bool
10149{
10150 return false;
10151}
10152
10153/* Implement the "print_it" method for masked hardware
10154 watchpoints. */
10155
10158{
10159 struct ui_out *uiout = current_uiout;
10160
10161 /* Masked watchpoints have only one location. */
10162 gdb_assert (this->has_single_location ());
10163
10166
10167 switch (this->type)
10168 {
10170 if (uiout->is_mi_like_p ())
10171 uiout->field_string
10173 break;
10174
10175 case bp_read_watchpoint:
10176 if (uiout->is_mi_like_p ())
10177 uiout->field_string
10179 break;
10180
10182 if (uiout->is_mi_like_p ())
10183 uiout->field_string
10184 ("reason",
10186 break;
10187 default:
10188 internal_error (_("Invalid hardware watchpoint type."));
10189 }
10190
10191 mention (this);
10192 uiout->text (_("\n\
10193Check the underlying instruction at PC for the memory\n\
10194address and value which triggered this watchpoint.\n"));
10195 uiout->text ("\n");
10196
10197 /* More than one watchpoint may have been triggered. */
10198 return PRINT_UNKNOWN;
10199}
10200
10201/* Implement the "print_one_detail" method for masked hardware
10202 watchpoints. */
10203
10204void
10206{
10207 /* Masked watchpoints have only one location. */
10208 gdb_assert (this->has_single_location ());
10209
10210 uiout->text ("\tmask ");
10211 uiout->field_core_addr ("mask", this->first_loc ().gdbarch, hw_wp_mask);
10212 uiout->text ("\n");
10213}
10214
10215/* Implement the "print_mention" method for masked hardware
10216 watchpoints. */
10217
10218void
10220{
10221 struct ui_out *uiout = current_uiout;
10222 const char *tuple_name;
10223
10224 switch (type)
10225 {
10227 uiout->text ("Masked hardware watchpoint ");
10228 tuple_name = "wpt";
10229 break;
10230 case bp_read_watchpoint:
10231 uiout->text ("Masked hardware read watchpoint ");
10232 tuple_name = "hw-rwpt";
10233 break;
10235 uiout->text ("Masked hardware access (read/write) watchpoint ");
10236 tuple_name = "hw-awpt";
10237 break;
10238 default:
10239 internal_error (_("Invalid hardware watchpoint type."));
10240 }
10241
10242 ui_out_emit_tuple tuple_emitter (uiout, tuple_name);
10243 uiout->field_signed ("number", number);
10244 uiout->text (": ");
10245 uiout->field_string ("exp", exp_string.get ());
10246}
10247
10248/* Implement the "print_recreate" method for masked hardware
10249 watchpoints. */
10250
10251void
10253{
10254 switch (type)
10255 {
10257 gdb_printf (fp, "watch");
10258 break;
10259 case bp_read_watchpoint:
10260 gdb_printf (fp, "rwatch");
10261 break;
10263 gdb_printf (fp, "awatch");
10264 break;
10265 default:
10266 internal_error (_("Invalid hardware watchpoint type."));
10267 }
10268
10269 gdb_printf (fp, " %s mask 0x%s", exp_string.get (),
10270 phex (hw_wp_mask, sizeof (CORE_ADDR)));
10272}
10273
10274/* Tell whether the given watchpoint is a masked hardware watchpoint. */
10275
10276static bool
10278{
10279 return dynamic_cast<const masked_watchpoint *> (b) != nullptr;
10280}
10281
10282/* accessflag: hw_write: watch write,
10283 hw_read: watch read,
10284 hw_access: watch access (read or write) */
10285static void
10286watch_command_1 (const char *arg, int accessflag, int from_tty,
10287 bool just_location, bool internal)
10288{
10289 struct breakpoint *scope_breakpoint = NULL;
10290 const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL;
10291 struct value *result;
10292 int saved_bitpos = 0, saved_bitsize = 0;
10293 const char *exp_start = NULL;
10294 const char *exp_end = NULL;
10295 const char *tok, *end_tok;
10296 int toklen = -1;
10297 const char *cond_start = NULL;
10298 const char *cond_end = NULL;
10299 enum bptype bp_type;
10300 int thread = -1;
10301 int inferior = -1;
10302 /* Flag to indicate whether we are going to use masks for
10303 the hardware watchpoint. */
10304 bool use_mask = false;
10305 CORE_ADDR mask = 0;
10306 int task = -1;
10307
10308 /* Make sure that we actually have parameters to parse. */
10309 if (arg != NULL && arg[0] != '\0')
10310 {
10311 const char *value_start;
10312
10313 exp_end = arg + strlen (arg);
10314
10315 /* Look for "parameter value" pairs at the end
10316 of the arguments string. */
10317 for (tok = exp_end - 1; tok > arg; tok--)
10318 {
10319 /* Skip whitespace at the end of the argument list. */
10320 while (tok > arg && (*tok == ' ' || *tok == '\t'))
10321 tok--;
10322
10323 /* Find the beginning of the last token.
10324 This is the value of the parameter. */
10325 while (tok > arg && (*tok != ' ' && *tok != '\t'))
10326 tok--;
10327 value_start = tok + 1;
10328
10329 /* Skip whitespace. */
10330 while (tok > arg && (*tok == ' ' || *tok == '\t'))
10331 tok--;
10332
10333 end_tok = tok;
10334
10335 /* Find the beginning of the second to last token.
10336 This is the parameter itself. */
10337 while (tok > arg && (*tok != ' ' && *tok != '\t'))
10338 tok--;
10339 tok++;
10340 toklen = end_tok - tok + 1;
10341
10342 if (toklen == 6 && startswith (tok, "thread"))
10343 {
10344 struct thread_info *thr;
10345 /* At this point we've found a "thread" token, which means
10346 the user is trying to set a watchpoint that triggers
10347 only in a specific thread. */
10348 const char *endp;
10349
10350 if (thread != -1)
10351 error(_("You can specify only one thread."));
10352
10353 if (task != -1)
10354 error (_("You can specify only one of thread or task."));
10355
10356 if (inferior != -1)
10357 error (_("You can specify only one of inferior or thread."));
10358
10359 /* Extract the thread ID from the next token. */
10360 thr = parse_thread_id (value_start, &endp);
10361 if (value_start == endp)
10362 error (_("Junk after thread keyword."));
10363
10364 thread = thr->global_num;
10365 }
10366 else if (toklen == 4 && startswith (tok, "task"))
10367 {
10368 char *tmp;
10369
10370 if (task != -1)
10371 error(_("You can specify only one task."));
10372
10373 if (thread != -1)
10374 error (_("You can specify only one of thread or task."));
10375
10376 if (inferior != -1)
10377 error (_("You can specify only one of inferior or task."));
10378
10379 task = strtol (value_start, &tmp, 0);
10380 if (tmp == value_start)
10381 error (_("Junk after task keyword."));
10382 if (!valid_task_id (task))
10383 error (_("Unknown task %d."), task);
10384 }
10385 else if (toklen == 8 && startswith (tok, "inferior"))
10386 {
10387 /* Support for watchpoints will be added in a later commit. */
10388 error (_("Cannot use 'inferior' keyword with watchpoints"));
10389 }
10390 else if (toklen == 4 && startswith (tok, "mask"))
10391 {
10392 /* We've found a "mask" token, which means the user wants to
10393 create a hardware watchpoint that is going to have the mask
10394 facility. */
10395 struct value *mask_value;
10396
10397 if (use_mask)
10398 error(_("You can specify only one mask."));
10399
10400 use_mask = just_location = true;
10401
10402 scoped_value_mark mark;
10403 mask_value = parse_to_comma_and_eval (&value_start);
10404 mask = value_as_address (mask_value);
10405 }
10406 else
10407 /* We didn't recognize what we found. We should stop here. */
10408 break;
10409
10410 /* Truncate the string and get rid of the "parameter value" pair before
10411 the arguments string is parsed by the parse_exp_1 function. */
10412 exp_end = tok;
10413 }
10414 }
10415 else
10416 exp_end = arg;
10417
10418 /* Parse the rest of the arguments. From here on out, everything
10419 is in terms of a newly allocated string instead of the original
10420 ARG. */
10421 std::string expression (arg, exp_end - arg);
10422 exp_start = arg = expression.c_str ();
10424 expression_up exp = parse_exp_1 (&arg, 0, 0, 0, &tracker);
10425 exp_end = arg;
10426 /* Remove trailing whitespace from the expression before saving it.
10427 This makes the eventual display of the expression string a bit
10428 prettier. */
10429 while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t'))
10430 --exp_end;
10431
10432 /* Checking if the expression is not constant. */
10433 if (watchpoint_exp_is_const (exp.get ()))
10434 {
10435 int len;
10436
10437 len = exp_end - exp_start;
10438 while (len > 0 && isspace (exp_start[len - 1]))
10439 len--;
10440 error (_("Cannot watch constant value `%.*s'."), len, exp_start);
10441 }
10442
10443 exp_valid_block = tracker.block ();
10444 struct value *mark = value_mark ();
10445 struct value *val_as_value = nullptr;
10446 fetch_subexp_value (exp.get (), exp->op.get (), &val_as_value, &result, NULL,
10447 just_location);
10448
10449 if (val_as_value != NULL && just_location)
10450 {
10451 saved_bitpos = val_as_value->bitpos ();
10452 saved_bitsize = val_as_value->bitsize ();
10453 }
10454
10455 value_ref_ptr val;
10456 if (just_location)
10457 {
10458 int ret;
10459
10460 exp_valid_block = NULL;
10461 val = release_value (value_addr (result));
10462 value_free_to_mark (mark);
10463
10464 if (use_mask)
10465 {
10467 mask);
10468 if (ret == -1)
10469 error (_("This target does not support masked watchpoints."));
10470 else if (ret == -2)
10471 error (_("Invalid mask or memory region."));
10472 }
10473 }
10474 else if (val_as_value != NULL)
10475 val = release_value (val_as_value);
10476
10477 tok = skip_spaces (arg);
10478 end_tok = skip_to_space (tok);
10479
10480 toklen = end_tok - tok;
10481 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
10482 {
10483 tok = cond_start = end_tok + 1;
10484 innermost_block_tracker if_tracker;
10485 parse_exp_1 (&tok, 0, 0, 0, &if_tracker);
10486
10487 /* The watchpoint expression may not be local, but the condition
10488 may still be. E.g.: `watch global if local > 0'. */
10489 cond_exp_valid_block = if_tracker.block ();
10490
10491 cond_end = tok;
10492 }
10493 if (*tok)
10494 error (_("Junk at end of command."));
10495
10496 frame_info_ptr wp_frame = block_innermost_frame (exp_valid_block);
10497
10498 /* Save this because create_internal_breakpoint below invalidates
10499 'wp_frame'. */
10500 frame_id watchpoint_frame = get_frame_id (wp_frame);
10501
10502 /* If the expression is "local", then set up a "watchpoint scope"
10503 breakpoint at the point where we've left the scope of the watchpoint
10504 expression. Create the scope breakpoint before the watchpoint, so
10505 that we will encounter it first in bpstat_stop_status. */
10506 if (exp_valid_block != NULL && wp_frame != NULL)
10507 {
10508 frame_id caller_frame_id = frame_unwind_caller_id (wp_frame);
10509
10510 if (frame_id_p (caller_frame_id))
10511 {
10512 gdbarch *caller_arch = frame_unwind_caller_arch (wp_frame);
10513 CORE_ADDR caller_pc = frame_unwind_caller_pc (wp_frame);
10514
10515 scope_breakpoint
10516 = create_internal_breakpoint (caller_arch, caller_pc,
10518
10519 /* create_internal_breakpoint could invalidate WP_FRAME. */
10520 wp_frame = NULL;
10521
10522 scope_breakpoint->enable_state = bp_enabled;
10523
10524 /* Automatically delete the breakpoint when it hits. */
10525 scope_breakpoint->disposition = disp_del;
10526
10527 /* Only break in the proper frame (help with recursion). */
10528 scope_breakpoint->frame_id = caller_frame_id;
10529
10530 /* Set the address at which we will stop. */
10531 bp_location &loc = scope_breakpoint->first_loc ();
10532 loc.gdbarch = caller_arch;
10533 loc.requested_address = caller_pc;
10534 loc.address
10535 = adjust_breakpoint_address (loc.gdbarch, loc.requested_address,
10536 scope_breakpoint->type,
10538 }
10539 }
10540
10541 /* Now set up the breakpoint. We create all watchpoints as hardware
10542 watchpoints here even if hardware watchpoints are turned off, a call
10543 to update_watchpoint later in this function will cause the type to
10544 drop back to bp_watchpoint (software watchpoint) if required. */
10545
10546 if (accessflag == hw_read)
10548 else if (accessflag == hw_access)
10550 else
10552
10553 std::unique_ptr<watchpoint> w;
10554 if (use_mask)
10555 w.reset (new masked_watchpoint (nullptr, bp_type));
10556 else
10557 w.reset (new watchpoint (nullptr, bp_type));
10558
10559 /* At most one of thread or task can be set on a watchpoint. */
10560 gdb_assert (thread == -1 || task == -1);
10561 w->thread = thread;
10562 w->inferior = inferior;
10563 w->task = task;
10564 w->disposition = disp_donttouch;
10566 w->exp = std::move (exp);
10567 w->exp_valid_block = exp_valid_block;
10568 w->cond_exp_valid_block = cond_exp_valid_block;
10569 if (just_location)
10570 {
10571 struct type *t = val->type ();
10572 CORE_ADDR addr = value_as_address (val.get ());
10573
10574 w->exp_string_reparse
10576
10577 w->exp_string = xstrprintf ("-location %.*s",
10578 (int) (exp_end - exp_start), exp_start);
10579 }
10580 else
10581 w->exp_string.reset (savestring (exp_start, exp_end - exp_start));
10582
10583 if (use_mask)
10584 {
10585 w->hw_wp_mask = mask;
10586 }
10587 else
10588 {
10589 w->val = val;
10590 w->val_bitpos = saved_bitpos;
10591 w->val_bitsize = saved_bitsize;
10592 w->val_valid = true;
10593 }
10594
10595 if (cond_start)
10596 w->cond_string.reset (savestring (cond_start, cond_end - cond_start));
10597 else
10598 w->cond_string = 0;
10599
10600 if (frame_id_p (watchpoint_frame))
10601 {
10602 w->watchpoint_frame = watchpoint_frame;
10603 w->watchpoint_thread = inferior_ptid;
10604 }
10605 else
10606 {
10607 w->watchpoint_frame = null_frame_id;
10608 w->watchpoint_thread = null_ptid;
10609 }
10610
10611 if (scope_breakpoint != NULL)
10612 {
10613 /* The scope breakpoint is related to the watchpoint. We will
10614 need to act on them together. */
10615 w->related_breakpoint = scope_breakpoint;
10616 scope_breakpoint->related_breakpoint = w.get ();
10617 }
10618
10619 if (!just_location)
10620 value_free_to_mark (mark);
10621
10622 /* Finally update the new watchpoint. This creates the locations
10623 that should be inserted. */
10624 update_watchpoint (w.get (), true /* reparse */);
10625
10626 install_breakpoint (internal, std::move (w), 1);
10627}
10628
10629/* Return count of debug registers needed to watch the given expression.
10630 If the watchpoint cannot be handled in hardware return zero. */
10631
10632static int
10633can_use_hardware_watchpoint (const std::vector<value_ref_ptr> &vals)
10634{
10635 int found_memory_cnt = 0;
10636
10637 /* Did the user specifically forbid us to use hardware watchpoints? */
10639 return 0;
10640
10641 gdb_assert (!vals.empty ());
10642 struct value *head = vals[0].get ();
10643
10644 /* Make sure that the value of the expression depends only upon
10645 memory contents, and values computed from them within GDB. If we
10646 find any register references or function calls, we can't use a
10647 hardware watchpoint.
10648
10649 The idea here is that evaluating an expression generates a series
10650 of values, one holding the value of every subexpression. (The
10651 expression a*b+c has five subexpressions: a, b, a*b, c, and
10652 a*b+c.) GDB's values hold almost enough information to establish
10653 the criteria given above --- they identify memory lvalues,
10654 register lvalues, computed values, etcetera. So we can evaluate
10655 the expression, and then scan the chain of values that leaves
10656 behind to decide whether we can detect any possible change to the
10657 expression's final value using only hardware watchpoints.
10658
10659 However, I don't think that the values returned by inferior
10660 function calls are special in any way. So this function may not
10661 notice that an expression involving an inferior function call
10662 can't be watched with hardware watchpoints. FIXME. */
10663 for (const value_ref_ptr &iter : vals)
10664 {
10665 struct value *v = iter.get ();
10666
10667 if (v->lval () == lval_memory)
10668 {
10669 if (v != head && v->lazy ())
10670 /* A lazy memory lvalue in the chain is one that GDB never
10671 needed to fetch; we either just used its address (e.g.,
10672 `a' in `a.b') or we never needed it at all (e.g., `a'
10673 in `a,b'). This doesn't apply to HEAD; if that is
10674 lazy then it was not readable, but watch it anyway. */
10675 ;
10676 else
10677 {
10678 /* Ahh, memory we actually used! Check if we can cover
10679 it with hardware watchpoints. */
10680 struct type *vtype = check_typedef (v->type ());
10681
10682 /* We only watch structs and arrays if user asked for it
10683 explicitly, never if they just happen to appear in a
10684 middle of some value chain. */
10685 if (v == head
10686 || (vtype->code () != TYPE_CODE_STRUCT
10687 && vtype->code () != TYPE_CODE_ARRAY))
10688 {
10689 CORE_ADDR vaddr = v->address ();
10690 int len;
10691 int num_regs;
10692
10694 && is_scalar_type_recursive (vtype))?
10695 1 : v->type ()->length ();
10696
10697 num_regs = target_region_ok_for_hw_watchpoint (vaddr, len);
10698 if (!num_regs)
10699 return 0;
10700 else
10701 found_memory_cnt += num_regs;
10702 }
10703 }
10704 }
10705 else if (v->lval () != not_lval && !v->deprecated_modifiable ())
10706 return 0; /* These are values from the history (e.g., $1). */
10707 else if (v->lval () == lval_register)
10708 return 0; /* Cannot watch a register with a HW watchpoint. */
10709 }
10710
10711 /* The expression itself looks suitable for using a hardware
10712 watchpoint, but give the target machine a chance to reject it. */
10713 return found_memory_cnt;
10714}
10715
10716void
10717watch_command_wrapper (const char *arg, int from_tty, bool internal)
10718{
10719 watch_command_1 (arg, hw_write, from_tty, 0, internal);
10720}
10721
10722/* Options for the watch, awatch, and rwatch commands. */
10723
10725{
10726 /* For -location. */
10727 bool location = false;
10728};
10729
10730/* Definitions of options for the "watch", "awatch", and "rwatch" commands.
10731
10732 Historically GDB always accepted both '-location' and '-l' flags for
10733 these commands (both flags being synonyms). When converting to the
10734 newer option scheme only '-location' is added here. That's fine (for
10735 backward compatibility) as any non-ambiguous prefix of a flag will be
10736 accepted, so '-l', '-loc', are now all accepted.
10737
10738 What this means is that, if in the future, we add any new flag here
10739 that starts with '-l' then this will break backward compatibility, so
10740 please, don't do that! */
10741
10744 "location",
10745 [] (watch_options *opt) { return &opt->location; },
10746 N_("\
10747This evaluates EXPRESSION and watches the memory to which is refers.\n\
10748-l can be used as a short form of -location."),
10749 },
10750};
10751
10752/* Returns the option group used by 'watch', 'awatch', and 'rwatch'
10753 commands. */
10754
10757{
10758 return {{watch_option_defs}, opts};
10759}
10760
10761/* A helper function that looks for the "-location" argument and then
10762 calls watch_command_1. */
10763
10764static void
10765watch_maybe_just_location (const char *arg, int accessflag, int from_tty)
10766{
10767 watch_options opts;
10768 auto grp = make_watch_options_def_group (&opts);
10771 if (arg != nullptr && *arg == '\0')
10772 arg = nullptr;
10773
10774 watch_command_1 (arg, accessflag, from_tty, opts.location, false);
10775}
10776
10777/* Command completion for 'watch', 'awatch', and 'rwatch' commands. */
10778static void
10780 completion_tracker &tracker,
10781 const char *text, const char * /*word*/)
10782{
10783 const auto group = make_watch_options_def_group (nullptr);
10785 (tracker, &text, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND, group))
10786 return;
10787
10788 const char *word = advance_to_expression_complete_word_point (tracker, text);
10789 expression_completer (ignore, tracker, text, word);
10790}
10791
10792static void
10793watch_command (const char *arg, int from_tty)
10794{
10795 watch_maybe_just_location (arg, hw_write, from_tty);
10796}
10797
10798void
10799rwatch_command_wrapper (const char *arg, int from_tty, bool internal)
10800{
10801 watch_command_1 (arg, hw_read, from_tty, 0, internal);
10802}
10803
10804static void
10805rwatch_command (const char *arg, int from_tty)
10806{
10807 watch_maybe_just_location (arg, hw_read, from_tty);
10808}
10809
10810void
10811awatch_command_wrapper (const char *arg, int from_tty, bool internal)
10812{
10813 watch_command_1 (arg, hw_access, from_tty, 0, internal);
10814}
10815
10816static void
10817awatch_command (const char *arg, int from_tty)
10818{
10819 watch_maybe_just_location (arg, hw_access, from_tty);
10820}
10821
10822
10823/* Data for the FSM that manages the until(location)/advance commands
10824 in infcmd.c. Here because it uses the mechanisms of
10825 breakpoints. */
10826
10828{
10829 /* The thread that was current when the command was executed. */
10831
10832 /* The breakpoint set at the return address in the caller frame,
10833 plus breakpoints at all the destination locations. */
10834 std::vector<breakpoint_up> breakpoints;
10835
10836 until_break_fsm (struct interp *cmd_interp, int thread,
10837 std::vector<breakpoint_up> &&breakpoints)
10838 : thread_fsm (cmd_interp),
10839 thread (thread),
10840 breakpoints (std::move (breakpoints))
10841 {
10842 }
10843
10844 void clean_up (struct thread_info *thread) override;
10845 bool should_stop (struct thread_info *thread) override;
10847};
10848
10849/* Implementation of the 'should_stop' FSM method for the
10850 until(location)/advance commands. */
10851
10852bool
10854{
10855 for (const breakpoint_up &bp : breakpoints)
10857 bp.get ()) != NULL)
10858 {
10859 set_finished ();
10860 break;
10861 }
10862
10863 return true;
10864}
10865
10866/* Implementation of the 'clean_up' FSM method for the
10867 until(location)/advance commands. */
10868
10869void
10871{
10872 /* Clean up our temporary breakpoints. */
10873 breakpoints.clear ();
10875}
10876
10877/* Implementation of the 'async_reply_reason' FSM method for the
10878 until(location)/advance commands. */
10879
10885
10886void
10887until_break_command (const char *arg, int from_tty, int anywhere)
10888{
10889 frame_info_ptr frame;
10890 struct gdbarch *frame_gdbarch;
10891 struct frame_id stack_frame_id;
10892 struct frame_id caller_frame_id;
10893 int thread;
10894 struct thread_info *tp;
10895
10897
10898 /* Set a breakpoint where the user wants it and at return from
10899 this function. */
10900
10902
10903 std::vector<symtab_and_line> sals
10905 ? decode_line_1 (locspec.get (), DECODE_LINE_FUNFIRSTLINE, NULL,
10908 : decode_line_1 (locspec.get (), DECODE_LINE_FUNFIRSTLINE,
10909 NULL, NULL, 0));
10910
10911 if (sals.empty ())
10912 error (_("Couldn't get information on specified line."));
10913
10914 if (*arg)
10915 error (_("Junk at end of arguments."));
10916
10917 tp = inferior_thread ();
10918 thread = tp->global_num;
10919
10920 /* Note linespec handling above invalidates the frame chain.
10921 Installing a breakpoint also invalidates the frame chain (as it
10922 may need to switch threads), so do any frame handling before
10923 that. */
10924
10925 frame = get_selected_frame (NULL);
10926 frame_gdbarch = get_frame_arch (frame);
10927 stack_frame_id = get_stack_frame_id (frame);
10928 caller_frame_id = frame_unwind_caller_id (frame);
10929
10930 /* Keep within the current frame, or in frames called by the current
10931 one. */
10932
10933 std::vector<breakpoint_up> breakpoints;
10934
10935 gdb::optional<delete_longjmp_breakpoint_cleanup> lj_deleter;
10936
10937 if (frame_id_p (caller_frame_id))
10938 {
10939 struct symtab_and_line sal2;
10940 struct gdbarch *caller_gdbarch;
10941
10942 sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0);
10943 sal2.pc = frame_unwind_caller_pc (frame);
10944 caller_gdbarch = frame_unwind_caller_arch (frame);
10945
10946 breakpoint_up caller_breakpoint
10947 = set_momentary_breakpoint (caller_gdbarch, sal2,
10948 caller_frame_id, bp_until);
10949 breakpoints.emplace_back (std::move (caller_breakpoint));
10950
10951 set_longjmp_breakpoint (tp, stack_frame_id);
10952 lj_deleter.emplace (thread);
10953 }
10954
10955 /* set_momentary_breakpoint could invalidate FRAME. */
10956 frame = NULL;
10957
10958 /* If the user told us to continue until a specified location, we
10959 don't specify a frame at which we need to stop. Otherwise,
10960 specify the selected frame, because we want to stop only at the
10961 very same frame. */
10962 frame_id stop_frame_id = anywhere ? null_frame_id : stack_frame_id;
10963
10964 for (symtab_and_line &sal : sals)
10965 {
10966 resolve_sal_pc (&sal);
10967
10968 breakpoint_up location_breakpoint
10969 = set_momentary_breakpoint (frame_gdbarch, sal,
10970 stop_frame_id, bp_until);
10971 breakpoints.emplace_back (std::move (location_breakpoint));
10972 }
10973
10974 tp->set_thread_fsm
10975 (std::unique_ptr<thread_fsm>
10977 std::move (breakpoints))));
10978
10979 if (lj_deleter)
10980 lj_deleter->release ();
10981
10982 proceed (-1, GDB_SIGNAL_DEFAULT);
10983}
10984
10985
10986
10987/* Compare two breakpoints and return a strcmp-like result. */
10988
10989static int
10991{
10992 uintptr_t ua = (uintptr_t) a;
10993 uintptr_t ub = (uintptr_t) b;
10994
10995 if (a->number < b->number)
10996 return -1;
10997 else if (a->number > b->number)
10998 return 1;
10999
11000 /* Now sort by address, in case we see, e..g, two breakpoints with
11001 the number 0. */
11002 if (ua < ub)
11003 return -1;
11004 return ua > ub ? 1 : 0;
11005}
11006
11007/* Delete breakpoints by address or line. */
11008
11009static void
11010clear_command (const char *arg, int from_tty)
11011{
11012 int default_match;
11013
11014 std::vector<symtab_and_line> decoded_sals;
11015 symtab_and_line last_sal;
11016 gdb::array_view<symtab_and_line> sals;
11017 if (arg)
11018 {
11019 decoded_sals
11023 default_match = 0;
11024 sals = decoded_sals;
11025 }
11026 else
11027 {
11028 /* Set sal's line, symtab, pc, and pspace to the values
11029 corresponding to the last call to print_frame_info. If the
11030 codepoint is not valid, this will set all the fields to 0. */
11031 last_sal = get_last_displayed_sal ();
11032 if (last_sal.symtab == 0)
11033 error (_("No source file specified."));
11034
11035 default_match = 1;
11036 sals = last_sal;
11037 }
11038
11039 /* We don't call resolve_sal_pc here. That's not as bad as it
11040 seems, because all existing breakpoints typically have both
11041 file/line and pc set. So, if clear is given file/line, we can
11042 match this to existing breakpoint without obtaining pc at all.
11043
11044 We only support clearing given the address explicitly
11045 present in breakpoint table. Say, we've set breakpoint
11046 at file:line. There were several PC values for that file:line,
11047 due to optimization, all in one block.
11048
11049 We've picked one PC value. If "clear" is issued with another
11050 PC corresponding to the same file:line, the breakpoint won't
11051 be cleared. We probably can still clear the breakpoint, but
11052 since the other PC value is never presented to user, user
11053 can only find it by guessing, and it does not seem important
11054 to support that. */
11055
11056 /* For each line spec given, delete bps which correspond to it. Do
11057 it in two passes, solely to preserve the current behavior that
11058 from_tty is forced true if we delete more than one
11059 breakpoint. */
11060
11061 std::vector<struct breakpoint *> found;
11062 for (const auto &sal : sals)
11063 {
11064 const char *sal_fullname;
11065
11066 /* If exact pc given, clear bpts at that pc.
11067 If line given (pc == 0), clear all bpts on specified line.
11068 If defaulting, clear all bpts on default line
11069 or at default pc.
11070
11071 defaulting sal.pc != 0 tests to do
11072
11073 0 1 pc
11074 1 1 pc _and_ line
11075 0 0 line
11076 1 0 <can't happen> */
11077
11078 sal_fullname = (sal.symtab == NULL
11079 ? NULL : symtab_to_fullname (sal.symtab));
11080
11081 /* Find all matching breakpoints and add them to 'found'. */
11082 for (breakpoint &b : all_breakpoints ())
11083 {
11084 int match = 0;
11085 /* Are we going to delete b? */
11086 if (b.type != bp_none && !is_watchpoint (&b)
11087 && user_breakpoint_p (&b))
11088 {
11089 for (bp_location &loc : b.locations ())
11090 {
11091 /* If the user specified file:line, don't allow a PC
11092 match. This matches historical gdb behavior. */
11093 int pc_match = (!sal.explicit_line
11094 && sal.pc
11095 && (loc.pspace == sal.pspace)
11096 && (loc.address == sal.pc)
11097 && (!section_is_overlay (loc.section)
11098 || loc.section == sal.section));
11099 int line_match = 0;
11100
11101 if ((default_match || sal.explicit_line)
11102 && loc.symtab != NULL
11103 && sal_fullname != NULL
11104 && sal.pspace == loc.pspace
11105 && loc.line_number == sal.line
11106 && filename_cmp (symtab_to_fullname (loc.symtab),
11107 sal_fullname) == 0)
11108 line_match = 1;
11109
11110 if (pc_match || line_match)
11111 {
11112 match = 1;
11113 break;
11114 }
11115 }
11116 }
11117
11118 if (match)
11119 found.push_back (&b);
11120 }
11121 }
11122
11123 /* Now go thru the 'found' chain and delete them. */
11124 if (found.empty ())
11125 {
11126 if (arg)
11127 error (_("No breakpoint at %s."), arg);
11128 else
11129 error (_("No breakpoint at this line."));
11130 }
11131
11132 /* Remove duplicates from the vec. */
11133 std::sort (found.begin (), found.end (),
11134 [] (const breakpoint *bp_a, const breakpoint *bp_b)
11135 {
11136 return compare_breakpoints (bp_a, bp_b) < 0;
11137 });
11138 found.erase (std::unique (found.begin (), found.end (),
11139 [] (const breakpoint *bp_a, const breakpoint *bp_b)
11140 {
11141 return compare_breakpoints (bp_a, bp_b) == 0;
11142 }),
11143 found.end ());
11144
11145 if (found.size () > 1)
11146 from_tty = 1; /* Always report if deleted more than one. */
11147 if (from_tty)
11148 {
11149 if (found.size () == 1)
11150 gdb_printf (_("Deleted breakpoint "));
11151 else
11152 gdb_printf (_("Deleted breakpoints "));
11153 }
11154
11155 for (breakpoint *iter : found)
11156 {
11157 if (from_tty)
11158 gdb_printf ("%d ", iter->number);
11159 delete_breakpoint (iter);
11160 }
11161 if (from_tty)
11162 gdb_putc ('\n');
11163}
11164
11165/* Delete breakpoint in BS if they are `delete' breakpoints and
11166 all breakpoints that are marked for deletion, whether hit or not.
11167 This is called after any breakpoint is hit, or after errors. */
11168
11169void
11171{
11172 for (; bs; bs = bs->next)
11173 if (bs->breakpoint_at
11175 && bs->stop)
11177
11178 for (breakpoint &b : all_breakpoints_safe ())
11180 delete_breakpoint (&b);
11181}
11182
11183/* A comparison function for bp_location AP and BP being interfaced to
11184 std::sort. Sort elements primarily by their ADDRESS (no matter what
11185 bl_address_is_meaningful says), secondarily by ordering first
11186 permanent elements and tertiarily just ensuring the array is sorted
11187 stable way despite std::sort being an unstable algorithm. */
11188
11189static int
11191{
11192 if (a->address != b->address)
11193 return a->address < b->address;
11194
11195 /* Sort locations at the same address by their pspace number, keeping
11196 locations of the same inferior (in a multi-inferior environment)
11197 grouped. */
11198
11199 if (a->pspace->num != b->pspace->num)
11200 return a->pspace->num < b->pspace->num;
11201
11202 /* Sort permanent breakpoints first. */
11203 if (a->permanent != b->permanent)
11204 return a->permanent > b->permanent;
11205
11206 /* Sort by type in order to make duplicate determination easier.
11207 See update_global_location_list. This is kept in sync with
11208 breakpoint_locations_match. */
11209 if (a->loc_type < b->loc_type)
11210 return true;
11211
11212 /* Likewise, for range-breakpoints, sort by length. */
11215 && a->length < b->length)
11216 return true;
11217
11218 /* Make the internal GDB representation stable across GDB runs
11219 where A and B memory inside GDB can differ. Breakpoint locations of
11220 the same type at the same address can be sorted in arbitrary order. */
11221
11222 if (a->owner->number != b->owner->number)
11223 return a->owner->number < b->owner->number;
11224
11225 return a < b;
11226}
11227
11228/* Set bp_locations_placed_address_before_address_max and
11229 bp_locations_shadow_len_after_address_max according to the current
11230 content of the bp_locations array. */
11231
11232static void
11234{
11237
11238 for (bp_location *bl : all_bp_locations ())
11239 {
11240 CORE_ADDR start, end, addr;
11241
11242 if (!bp_location_has_shadow (bl))
11243 continue;
11244
11245 start = bl->target_info.placed_address;
11246 end = start + bl->target_info.shadow_len;
11247
11248 gdb_assert (bl->address >= start);
11249 addr = bl->address - start;
11252
11253 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11254
11255 gdb_assert (bl->address < end);
11256 addr = end - bl->address;
11259 }
11260}
11261
11262/* Download tracepoint locations if they haven't been. */
11263
11264static void
11266{
11267 enum tribool can_download_tracepoint = TRIBOOL_UNKNOWN;
11268
11269 scoped_restore_current_pspace_and_thread restore_pspace_thread;
11270
11271 for (breakpoint &b : all_tracepoints ())
11272 {
11273 bool bp_location_downloaded = false;
11274
11275 if ((b.type == bp_fast_tracepoint
11278 continue;
11279
11280 if (can_download_tracepoint == TRIBOOL_UNKNOWN)
11281 {
11283 can_download_tracepoint = TRIBOOL_TRUE;
11284 else
11285 can_download_tracepoint = TRIBOOL_FALSE;
11286 }
11287
11288 if (can_download_tracepoint == TRIBOOL_FALSE)
11289 break;
11290
11291 for (bp_location &bl : b.locations ())
11292 {
11293 /* In tracepoint, locations are _never_ duplicated, so
11294 should_be_inserted is equivalent to
11295 unduplicated_should_be_inserted. */
11296 if (!should_be_inserted (&bl) || bl.inserted)
11297 continue;
11298
11300
11302
11303 bl.inserted = 1;
11304 bp_location_downloaded = true;
11305 }
11306
11307 tracepoint &t = gdb::checked_static_cast<tracepoint &> (b);
11309 if (bp_location_downloaded)
11311 }
11312}
11313
11314/* Swap the insertion/duplication state between two locations. */
11315
11316static void
11317swap_insertion (struct bp_location *left, struct bp_location *right)
11318{
11319 const int left_inserted = left->inserted;
11320 const int left_duplicate = left->duplicate;
11321 const int left_needs_update = left->needs_update;
11322 const struct bp_target_info left_target_info = left->target_info;
11323
11324 /* Locations of tracepoints can never be duplicated. */
11325 if (is_tracepoint (left->owner))
11326 gdb_assert (!left->duplicate);
11327 if (is_tracepoint (right->owner))
11328 gdb_assert (!right->duplicate);
11329
11330 left->inserted = right->inserted;
11331 left->duplicate = right->duplicate;
11332 left->needs_update = right->needs_update;
11333 left->target_info = right->target_info;
11334 right->inserted = left_inserted;
11335 right->duplicate = left_duplicate;
11336 right->needs_update = left_needs_update;
11337 right->target_info = left_target_info;
11338}
11339
11340/* Force the re-insertion of the locations at ADDRESS. This is called
11341 once a new/deleted/modified duplicate location is found and we are evaluating
11342 conditions on the target's side. Such conditions need to be updated on
11343 the target. */
11344
11345static void
11347{
11348 CORE_ADDR address = 0;
11349 int pspace_num;
11350
11351 address = bl->address;
11352 pspace_num = bl->pspace->num;
11353
11354 /* This is only meaningful if the target is
11355 evaluating conditions and if the user has
11356 opted for condition evaluation on the target's
11357 side. */
11360 return;
11361
11362 /* Flag all breakpoint locations with this address and
11363 the same program space as the location
11364 as "its condition has changed". We need to
11365 update the conditions on the target's side. */
11366 for (bp_location *loc : all_bp_locations_at_addr (address))
11367 {
11368 if (!is_breakpoint (loc->owner)
11369 || pspace_num != loc->pspace->num)
11370 continue;
11371
11372 /* Flag the location appropriately. We use a different state to
11373 let everyone know that we already updated the set of locations
11374 with addr bl->address and program space bl->pspace. This is so
11375 we don't have to keep calling these functions just to mark locations
11376 that have already been marked. */
11377 loc->condition_changed = condition_updated;
11378
11379 /* Free the agent expression bytecode as well. We will compute
11380 it later on. */
11381 loc->cond_bytecode.reset ();
11382 }
11383}
11384
11385/* Called whether new breakpoints are created, or existing breakpoints
11386 deleted, to update the global location list and recompute which
11387 locations are duplicate of which.
11388
11389 The INSERT_MODE flag determines whether locations may not, may, or
11390 shall be inserted now. See 'enum ugll_insert_mode' for more
11391 info. */
11392
11393static void
11395{
11396 /* Last breakpoint location address that was marked for update. */
11397 CORE_ADDR last_addr = 0;
11398 /* Last breakpoint location program space that was marked for update. */
11399 int last_pspace_num = -1;
11400
11401 breakpoint_debug_printf ("insert_mode = %s",
11402 ugll_insert_mode_text (insert_mode));
11403
11404 /* Used in the duplicates detection below. When iterating over all
11405 bp_locations, points to the first bp_location of a given address.
11406 Breakpoints and watchpoints of different types are never
11407 duplicates of each other. Keep one pointer for each type of
11408 breakpoint/watchpoint, so we only need to loop over all locations
11409 once. */
11410 struct bp_location *bp_loc_first; /* breakpoint */
11411 struct bp_location *wp_loc_first; /* hardware watchpoint */
11412 struct bp_location *awp_loc_first; /* access watchpoint */
11413 struct bp_location *rwp_loc_first; /* read watchpoint */
11414
11415 /* Saved former bp_locations array which we compare against the newly
11416 built bp_locations from the current state of ALL_BREAKPOINTS. */
11417 std::vector<bp_location *> old_locations = std::move (bp_locations);
11418 bp_locations.clear ();
11419
11420 for (breakpoint &b : all_breakpoints ())
11421 for (bp_location &loc : b.locations ())
11422 bp_locations.push_back (&loc);
11423
11424 /* See if we need to "upgrade" a software breakpoint to a hardware
11425 breakpoint. Do this before deciding whether locations are
11426 duplicates. Also do this before sorting because sorting order
11427 depends on location type. */
11429 if (!loc->inserted && should_be_inserted (loc))
11431
11432 std::sort (bp_locations.begin (), bp_locations.end (),
11434
11436
11437 /* Identify bp_location instances that are no longer present in the
11438 new list, and therefore should be freed. Note that it's not
11439 necessary that those locations should be removed from inferior --
11440 if there's another location at the same address (previously
11441 marked as duplicate), we don't need to remove/insert the
11442 location.
11443
11444 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11445 and former bp_location array state respectively. */
11446
11447 size_t loc_i = 0;
11448 for (bp_location *old_loc : old_locations)
11449 {
11450 /* Tells if 'old_loc' is found among the new locations. If
11451 not, we have to free it. */
11452 bool found_object = false;
11453 /* Tells if the location should remain inserted in the target. */
11454 bool keep_in_target = false;
11455 bool removed = false;
11456
11457 /* Skip LOCP entries which will definitely never be needed.
11458 Stop either at or being the one matching OLD_LOC. */
11459 while (loc_i < bp_locations.size ()
11460 && bp_locations[loc_i]->address < old_loc->address)
11461 loc_i++;
11462
11463 for (size_t loc2_i = loc_i;
11464 (loc2_i < bp_locations.size ()
11465 && bp_locations[loc2_i]->address == old_loc->address);
11466 loc2_i++)
11467 {
11468 /* Check if this is a new/duplicated location or a duplicated
11469 location that had its condition modified. If so, we want to send
11470 its condition to the target if evaluation of conditions is taking
11471 place there. */
11473 && (last_addr != old_loc->address
11474 || last_pspace_num != old_loc->pspace->num))
11475 {
11477 last_pspace_num = old_loc->pspace->num;
11478 }
11479
11480 if (bp_locations[loc2_i] == old_loc)
11481 found_object = true;
11482 }
11483
11484 /* We have already handled this address, update it so that we don't
11485 have to go through updates again. */
11486 last_addr = old_loc->address;
11487
11488 /* Target-side condition evaluation: Handle deleted locations. */
11489 if (!found_object)
11491
11492 /* If this location is no longer present, and inserted, look if
11493 there's maybe a new location at the same address. If so,
11494 mark that one inserted, and don't remove this one. This is
11495 needed so that we don't have a time window where a breakpoint
11496 at certain location is not inserted. */
11497
11498 if (old_loc->inserted)
11499 {
11500 /* If the location is inserted now, we might have to remove
11501 it. */
11502
11503 if (found_object && should_be_inserted (old_loc))
11504 {
11505 /* The location is still present in the location list,
11506 and still should be inserted. Don't do anything. */
11507 keep_in_target = true;
11508 }
11509 else
11510 {
11511 /* This location still exists, but it won't be kept in the
11512 target since it may have been disabled. We proceed to
11513 remove its target-side condition. */
11514
11515 /* The location is either no longer present, or got
11516 disabled. See if there's another location at the
11517 same address, in which case we don't need to remove
11518 this one from the target. */
11519
11520 /* OLD_LOC comes from existing struct breakpoint. */
11521 if (bl_address_is_meaningful (old_loc))
11522 {
11523 for (size_t loc2_i = loc_i;
11524 (loc2_i < bp_locations.size ()
11525 && bp_locations[loc2_i]->address == old_loc->address);
11526 loc2_i++)
11527 {
11528 bp_location *loc2 = bp_locations[loc2_i];
11529
11530 if (loc2 == old_loc)
11531 continue;
11532
11533 if (breakpoint_locations_match (loc2, old_loc))
11534 {
11535 /* Read watchpoint locations are switched to
11536 access watchpoints, if the former are not
11537 supported, but the latter are. */
11538 if (is_hardware_watchpoint (old_loc->owner))
11539 {
11540 gdb_assert (is_hardware_watchpoint (loc2->owner));
11541 loc2->watchpoint_type = old_loc->watchpoint_type;
11542 }
11543
11544 /* loc2 is a duplicated location. We need to check
11545 if it should be inserted in case it will be
11546 unduplicated. */
11548 {
11549 swap_insertion (old_loc, loc2);
11550 keep_in_target = true;
11551 break;
11552 }
11553 }
11554 }
11555 }
11556 }
11557
11558 if (!keep_in_target)
11559 {
11560 if (remove_breakpoint (old_loc))
11561 {
11562 /* This is just about all we can do. We could keep
11563 this location on the global list, and try to
11564 remove it next time, but there's no particular
11565 reason why we will succeed next time.
11566
11567 Note that at this point, old_loc->owner is still
11568 valid, as delete_breakpoint frees the breakpoint
11569 only after calling us. */
11570 warning (_("error removing breakpoint %d at %s"),
11571 old_loc->owner->number,
11572 paddress (old_loc->gdbarch, old_loc->address));
11573 }
11574 removed = true;
11575 }
11576 }
11577
11578 if (!found_object)
11579 {
11580 if (removed && target_is_non_stop_p ()
11582 {
11583 /* This location was removed from the target. In
11584 non-stop mode, a race condition is possible where
11585 we've removed a breakpoint, but stop events for that
11586 breakpoint are already queued and will arrive later.
11587 We apply an heuristic to be able to distinguish such
11588 SIGTRAPs from other random SIGTRAPs: we keep this
11589 breakpoint location for a bit, and will retire it
11590 after we see some number of events. The theory here
11591 is that reporting of events should, "on the average",
11592 be fair, so after a while we'll see events from all
11593 threads that have anything of interest, and no longer
11594 need to keep this breakpoint location around. We
11595 don't hold locations forever so to reduce chances of
11596 mistaking a non-breakpoint SIGTRAP for a breakpoint
11597 SIGTRAP.
11598
11599 The heuristic failing can be disastrous on
11600 decr_pc_after_break targets.
11601
11602 On decr_pc_after_break targets, like e.g., x86-linux,
11603 if we fail to recognize a late breakpoint SIGTRAP,
11604 because events_till_retirement has reached 0 too
11605 soon, we'll fail to do the PC adjustment, and report
11606 a random SIGTRAP to the user. When the user resumes
11607 the inferior, it will most likely immediately crash
11608 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
11609 corrupted, because of being resumed e.g., in the
11610 middle of a multi-byte instruction, or skipped a
11611 one-byte instruction. This was actually seen happen
11612 on native x86-linux, and should be less rare on
11613 targets that do not support new thread events, like
11614 remote, due to the heuristic depending on
11615 thread_count.
11616
11617 Mistaking a random SIGTRAP for a breakpoint trap
11618 causes similar symptoms (PC adjustment applied when
11619 it shouldn't), but then again, playing with SIGTRAPs
11620 behind the debugger's back is asking for trouble.
11621
11622 Since hardware watchpoint traps are always
11623 distinguishable from other traps, so we don't need to
11624 apply keep hardware watchpoint moribund locations
11625 around. We simply always ignore hardware watchpoint
11626 traps we can no longer explain. */
11627
11628 process_stratum_target *proc_target = nullptr;
11629 for (inferior *inf : all_inferiors ())
11630 if (inf->pspace == old_loc->pspace)
11631 {
11632 proc_target = inf->process_target ();
11633 break;
11634 }
11635 if (proc_target != nullptr)
11636 old_loc->events_till_retirement
11637 = 3 * (thread_count (proc_target) + 1);
11638 else
11639 old_loc->events_till_retirement = 1;
11640 old_loc->owner = NULL;
11641
11642 moribund_locations.push_back (old_loc);
11643 }
11644 else
11645 {
11646 old_loc->owner = NULL;
11647 decref_bp_location (&old_loc);
11648 }
11649 }
11650 }
11651
11652 /* Rescan breakpoints at the same address and section, marking the
11653 first one as "first" and any others as "duplicates". This is so
11654 that the bpt instruction is only inserted once. If we have a
11655 permanent breakpoint at the same place as BPT, make that one the
11656 official one, and the rest as duplicates. Permanent breakpoints
11657 are sorted first for the same address.
11658
11659 Do the same for hardware watchpoints, but also considering the
11660 watchpoint's type (regular/access/read) and length. */
11661
11662 bp_loc_first = NULL;
11663 wp_loc_first = NULL;
11664 awp_loc_first = NULL;
11665 rwp_loc_first = NULL;
11666
11667 for (bp_location *loc : all_bp_locations ())
11668 {
11669 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
11670 non-NULL. */
11671 struct bp_location **loc_first_p;
11672 breakpoint *b = loc->owner;
11673
11676 /* Don't detect duplicate for tracepoint locations because they are
11677 never duplicated. See the comments in field `duplicate' of
11678 `struct bp_location'. */
11679 || is_tracepoint (b))
11680 {
11681 /* Clear the condition modification flag. */
11682 loc->condition_changed = condition_unchanged;
11683 continue;
11684 }
11685
11686 if (b->type == bp_hardware_watchpoint)
11687 loc_first_p = &wp_loc_first;
11688 else if (b->type == bp_read_watchpoint)
11689 loc_first_p = &rwp_loc_first;
11690 else if (b->type == bp_access_watchpoint)
11691 loc_first_p = &awp_loc_first;
11692 else
11693 loc_first_p = &bp_loc_first;
11694
11695 if (*loc_first_p == NULL
11696 || (overlay_debugging && loc->section != (*loc_first_p)->section)
11697 || !breakpoint_locations_match (loc, *loc_first_p))
11698 {
11699 *loc_first_p = loc;
11700 loc->duplicate = 0;
11701
11702 if (is_breakpoint (loc->owner) && loc->condition_changed)
11703 {
11704 loc->needs_update = 1;
11705 /* Clear the condition modification flag. */
11706 loc->condition_changed = condition_unchanged;
11707 }
11708 continue;
11709 }
11710
11711
11712 /* This and the above ensure the invariant that the first location
11713 is not duplicated, and is the inserted one.
11714 All following are marked as duplicated, and are not inserted. */
11715 if (loc->inserted)
11716 swap_insertion (loc, *loc_first_p);
11717 loc->duplicate = 1;
11718
11719 /* Clear the condition modification flag. */
11720 loc->condition_changed = condition_unchanged;
11721 }
11722
11723 if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ())
11724 {
11725 if (insert_mode != UGLL_DONT_INSERT)
11727 else
11728 {
11729 /* Even though the caller told us to not insert new
11730 locations, we may still need to update conditions on the
11731 target's side of breakpoints that were already inserted
11732 if the target is evaluating breakpoint conditions. We
11733 only update conditions for locations that are marked
11734 "needs_update". */
11736 }
11737 }
11738
11739 if (insert_mode != UGLL_DONT_INSERT)
11741}
11742
11743void
11745{
11746 for (int ix = 0; ix < moribund_locations.size (); ++ix)
11747 {
11748 struct bp_location *loc = moribund_locations[ix];
11749 if (--(loc->events_till_retirement) == 0)
11750 {
11752 unordered_remove (moribund_locations, ix);
11753 --ix;
11754 }
11755 }
11756}
11757
11758static void
11760{
11761
11762 try
11763 {
11764 update_global_location_list (insert_mode);
11765 }
11766 catch (const gdb_exception_error &e)
11767 {
11768 }
11769}
11770
11771/* Clear BKP from a BPS. */
11772
11773static void
11775{
11776 bpstat *bs;
11777
11778 for (bs = bps; bs; bs = bs->next)
11779 if (bs->breakpoint_at == bpt)
11780 {
11781 bs->breakpoint_at = NULL;
11782 bs->old_val = NULL;
11783 /* bs->commands will be freed later. */
11784 }
11785}
11786
11787/* Callback for iterate_over_threads. */
11788static int
11790{
11791 struct breakpoint *bpt = (struct breakpoint *) data;
11792
11794 return 0;
11795}
11796
11797/* See breakpoint.h. */
11798
11799void
11801{
11802 struct value_print_options opts;
11803
11804 get_user_print_options (&opts);
11805
11806 /* i18n: cagney/2005-02-11: Below needs to be merged into a
11807 single string. */
11808 if (!this->has_locations ())
11809 {
11810 /* For pending locations, the output differs slightly based
11811 on extra_string. If this is non-NULL, it contains either
11812 a condition or dprintf arguments. */
11813 if (extra_string == NULL)
11814 {
11815 gdb_printf (_(" (%s) pending."), locspec->to_string ());
11816 }
11817 else if (type == bp_dprintf)
11818 {
11819 gdb_printf (_(" (%s,%s) pending."),
11820 locspec->to_string (),
11821 extra_string.get ());
11822 }
11823 else
11824 {
11825 gdb_printf (_(" (%s %s) pending."),
11826 locspec->to_string (),
11827 extra_string.get ());
11828 }
11829 }
11830 else
11831 {
11832 const bp_location &bl = this->first_loc ();
11833 if (opts.addressprint || bl.symtab == nullptr)
11834 gdb_printf (" at %ps",
11836 paddress (bl.gdbarch,
11837 bl.address)));
11838 if (bl.symtab != NULL)
11839 {
11840 /* If there is a single location, we can print the location
11841 more nicely. */
11842 if (!this->has_multiple_locations ())
11843 {
11844 const char *filename
11846 gdb_printf (": file %ps, line %d.",
11848 filename),
11849 bl.line_number);
11850 }
11851 else
11852 /* This is not ideal, but each location may have a
11853 different file name, and this at least reflects the
11854 real situation somewhat. */
11855 gdb_printf (": %s.", locspec->to_string ());
11856 }
11857
11858 if (this->has_multiple_locations ())
11859 {
11860 int n = std::distance (m_locations.begin (), m_locations.end ());
11861 gdb_printf (" (%d locations)", n);
11862 }
11863 }
11864}
11865
11866/* See breakpoint.h. */
11867
11869{
11870 return bp_location_range (m_locations.begin (), m_locations.end ());
11871}
11872
11873struct bp_location *
11875{
11876 return new bp_location (this);
11877}
11878
11879/* See breakpoint.h. */
11880
11881void
11883{
11884 gdb_assert (loc.owner == this);
11885 gdb_assert (!loc.is_linked ());
11886
11887 auto ub = std::upper_bound (m_locations.begin (), m_locations.end (),
11888 loc,
11889 [] (const bp_location &left,
11890 const bp_location &right)
11891 { return left.address < right.address; });
11892 m_locations.insert (ub, loc);
11893}
11894
11895/* See breakpoint.h. */
11896
11897void
11899{
11900 gdb_assert (loc.owner == this);
11901 gdb_assert (loc.is_linked ());
11902
11903 m_locations.erase (m_locations.iterator_to (loc));
11904}
11905
11906#define internal_error_pure_virtual_called() \
11907 gdb_assert_not_reached ("pure virtual function called")
11908
11909int
11914
11915int
11921
11922int
11924 const address_space *aspace,
11925 CORE_ADDR bp_addr,
11926 const target_waitstatus &ws)
11927{
11929}
11930
11931int
11936
11939{
11941}
11942
11943void
11948
11949void
11954
11955/* Default breakpoint_ops methods. */
11956
11957void
11959{
11960 /* FIXME: is this still reachable? */
11962 {
11963 /* Anything without a location can't be re-set. */
11964 delete_breakpoint (this);
11965 return;
11966 }
11967
11968 re_set_default ();
11969}
11970
11971int
11973{
11974 CORE_ADDR addr = bl->target_info.reqstd_address;
11975
11976 bl->target_info.kind = breakpoint_kind (bl, &addr);
11977 bl->target_info.placed_address = addr;
11978
11979 int result;
11981 result = target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info);
11982 else
11983 result = target_insert_breakpoint (bl->gdbarch, &bl->target_info);
11984
11985 if (result == 0 && bl->probe.prob != nullptr)
11986 {
11987 /* The insertion was successful, now let's set the probe's semaphore
11988 if needed. */
11989 bl->probe.prob->set_semaphore (bl->probe.objfile, bl->gdbarch);
11990 }
11991
11992 return result;
11993}
11994
11995int
11997 enum remove_bp_reason reason)
11998{
11999 if (bl->probe.prob != nullptr)
12000 {
12001 /* Let's clear the semaphore before removing the location. */
12003 }
12004
12007 else
12008 return target_remove_breakpoint (bl->gdbarch, &bl->target_info, reason);
12009}
12010
12011int
12013 const address_space *aspace,
12014 CORE_ADDR bp_addr,
12015 const target_waitstatus &ws)
12016{
12017 if (ws.kind () != TARGET_WAITKIND_STOPPED
12018 || ws.sig () != GDB_SIGNAL_TRAP)
12019 return 0;
12020
12022 aspace, bp_addr))
12023 return 0;
12024
12025 if (overlay_debugging /* unmapped overlay section */
12027 && !section_is_mapped (bl->section))
12028 return 0;
12029
12030 return 1;
12031}
12032
12033int
12035 const address_space *aspace,
12036 CORE_ADDR bp_addr,
12037 const target_waitstatus &ws)
12038{
12041 {
12042 /* An agent-style dprintf never causes a stop. If we see a trap
12043 for this address it must be for a breakpoint that happens to
12044 be set at the same address. */
12045 return 0;
12046 }
12047
12048 return this->ordinary_breakpoint::breakpoint_hit (bl, aspace, bp_addr, ws);
12049}
12050
12051int
12053{
12054 gdb_assert (type == bp_hardware_breakpoint);
12055
12056 return 1;
12057}
12058
12061{
12062 const struct bp_location *bl;
12063 int bp_temp;
12064 struct ui_out *uiout = current_uiout;
12065
12066 bl = bs->bp_location_at.get ();
12067
12068 bp_temp = disposition == disp_del;
12069 if (bl->address != bl->requested_address)
12071 bl->address,
12072 number, true);
12075
12076 if (uiout->is_mi_like_p ())
12077 {
12078 uiout->field_string ("reason",
12080 uiout->field_string ("disp", bpdisp_text (disposition));
12081 }
12082
12083 if (bp_temp)
12084 uiout->text ("Temporary breakpoint ");
12085 else
12086 uiout->text ("Breakpoint ");
12087 print_num_locno (bs, uiout);
12088 uiout->text (", ");
12089
12090 return PRINT_SRC_AND_LOC;
12091}
12092
12093void
12095{
12096 if (current_uiout->is_mi_like_p ())
12097 return;
12098
12099 switch (type)
12100 {
12101 case bp_breakpoint:
12103 if (disposition == disp_del)
12104 gdb_printf (_("Temporary breakpoint"));
12105 else
12106 gdb_printf (_("Breakpoint"));
12107 gdb_printf (_(" %d"), number);
12109 gdb_printf (_(" at gnu-indirect-function resolver"));
12110 break;
12112 gdb_printf (_("Hardware assisted breakpoint %d"), number);
12113 break;
12114 case bp_dprintf:
12115 gdb_printf (_("Dprintf %d"), number);
12116 break;
12117 }
12118
12119 say_where ();
12120}
12121
12122void
12124{
12126 gdb_printf (fp, "tbreak");
12127 else if (type == bp_breakpoint)
12128 gdb_printf (fp, "break");
12129 else if (type == bp_hardware_breakpoint
12130 && disposition == disp_del)
12131 gdb_printf (fp, "thbreak");
12132 else if (type == bp_hardware_breakpoint)
12133 gdb_printf (fp, "hbreak");
12134 else
12135 internal_error (_("unhandled breakpoint type %d"), (int) type);
12136
12137 gdb_printf (fp, " %s", locspec->to_string ());
12138
12139 /* Print out extra_string if this breakpoint is pending. It might
12140 contain, for example, conditions that were set by the user. */
12141 if (!this->has_locations () && extra_string != NULL)
12142 gdb_printf (fp, " %s", extra_string.get ());
12143
12145}
12146
12147std::vector<symtab_and_line>
12149 program_space *search_pspace)
12150{
12151 if (locspec->type () == PROBE_LOCATION_SPEC)
12152 return bkpt_probe_decode_location_spec (this, locspec, search_pspace);
12153
12154 struct linespec_result canonical;
12155
12157 NULL, 0, &canonical, multiple_symbols_all,
12158 filter.get ());
12159
12160 /* We should get 0 or 1 resulting SALs. */
12161 gdb_assert (canonical.lsals.size () < 2);
12162
12163 if (!canonical.lsals.empty ())
12164 {
12165 const linespec_sals &lsal = canonical.lsals[0];
12166 return std::move (lsal.sals);
12167 }
12168 return {};
12169}
12170
12171/* Virtual table for internal breakpoints. */
12172
12173void
12175{
12176 switch (type)
12177 {
12178 /* Delete overlay event and longjmp master breakpoints; they
12179 will be reset later by breakpoint_re_set. */
12180 case bp_overlay_event:
12181 case bp_longjmp_master:
12184 delete_breakpoint (this);
12185 break;
12186
12187 /* This breakpoint is special, it's set up when the inferior
12188 starts and we really don't want to touch it. */
12189 case bp_shlib_event:
12190
12191 /* Like bp_shlib_event, this breakpoint type is special. Once
12192 it is set up, we do not want to touch it. */
12193 case bp_thread_event:
12194 break;
12195 }
12196}
12197
12198void
12200{
12201 if (type == bp_shlib_event)
12202 {
12203 /* If requested, stop when the dynamic linker notifies GDB of
12204 events. This allows the user to get control and place
12205 breakpoints in initializer routines for dynamically loaded
12206 objects (among other things). */
12207 bs->stop = stop_on_solib_events != 0;
12208 bs->print = stop_on_solib_events != 0;
12209 }
12210 else
12211 bs->stop = false;
12212}
12213
12216{
12217 switch (type)
12218 {
12219 case bp_shlib_event:
12220 /* Did we stop because the user set the stop_on_solib_events
12221 variable? (If so, we report this as a generic, "Stopped due
12222 to shlib event" message.) */
12223 print_solib_event (false);
12224 break;
12225
12226 case bp_thread_event:
12227 /* Not sure how we will get here.
12228 GDB should not stop for these breakpoints. */
12229 gdb_printf (_("Thread Event Breakpoint: gdb should not stop!\n"));
12230 break;
12231
12232 case bp_overlay_event:
12233 /* By analogy with the thread event, GDB should not stop for these. */
12234 gdb_printf (_("Overlay Event Breakpoint: gdb should not stop!\n"));
12235 break;
12236
12237 case bp_longjmp_master:
12238 /* These should never be enabled. */
12239 gdb_printf (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
12240 break;
12241
12243 /* These should never be enabled. */
12244 gdb_printf (_("std::terminate Master Breakpoint: "
12245 "gdb should not stop!\n"));
12246 break;
12247
12249 /* These should never be enabled. */
12250 gdb_printf (_("Exception Master Breakpoint: "
12251 "gdb should not stop!\n"));
12252 break;
12253 }
12254
12255 return PRINT_NOTHING;
12256}
12257
12258void
12260{
12261 /* Nothing to mention. These breakpoints are internal. */
12262}
12263
12264/* Virtual table for momentary breakpoints */
12265
12266void
12268{
12269 /* Keep temporary breakpoints, which can be encountered when we step
12270 over a dlopen call and solib_add is resetting the breakpoints.
12271 Otherwise these should have been blown away via the cleanup chain
12272 or by breakpoint_init_inferior when we rerun the executable. */
12273}
12274
12275void
12277{
12278 /* Nothing. The point of these breakpoints is causing a stop. */
12279}
12280
12283{
12284 return PRINT_UNKNOWN;
12285}
12286
12287void
12289{
12290 /* Nothing to mention. These breakpoints are internal. */
12291}
12292
12293/* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
12294
12295 It gets cleared already on the removal of the first one of such placed
12296 breakpoints. This is OK as they get all removed altogether. */
12297
12299{
12301
12302 if (tp != NULL)
12304}
12305
12306static void
12308 struct linespec_result *canonical)
12309
12310{
12311 struct linespec_sals lsal;
12312
12313 lsal.sals = parse_probes (locspec, NULL, canonical);
12314 lsal.canonical = xstrdup (canonical->locspec->to_string ());
12315 canonical->lsals.push_back (std::move (lsal));
12316}
12317
12318static std::vector<symtab_and_line>
12320 location_spec *locspec,
12321 program_space *search_pspace)
12322{
12323 std::vector<symtab_and_line> sals
12324 = parse_probes (locspec, search_pspace, NULL);
12325 if (sals.empty ())
12326 error (_("probe not found"));
12327 return sals;
12328}
12329
12330int
12332 const address_space *aspace, CORE_ADDR bp_addr,
12333 const target_waitstatus &ws)
12334{
12335 /* By definition, the inferior does not report stops at
12336 tracepoints. */
12337 return 0;
12338}
12339
12340void
12342{
12343 if (!static_trace_marker_id.empty ())
12344 {
12345 gdb_assert (type == bp_static_tracepoint
12347
12348 uiout->message ("\tmarker id is %pF\n",
12349 string_field ("static-tracepoint-marker-string-id",
12350 static_trace_marker_id.c_str ()));
12351 }
12352}
12353
12354void
12356{
12357 if (current_uiout->is_mi_like_p ())
12358 return;
12359
12360 switch (type)
12361 {
12362 case bp_tracepoint:
12363 gdb_printf (_("Tracepoint"));
12364 gdb_printf (_(" %d"), number);
12365 break;
12366 case bp_fast_tracepoint:
12367 gdb_printf (_("Fast tracepoint"));
12368 gdb_printf (_(" %d"), number);
12369 break;
12372 gdb_printf (_("Static tracepoint"));
12373 gdb_printf (_(" %d"), number);
12374 break;
12375 default:
12376 internal_error (_("unhandled tracepoint type %d"), (int) type);
12377 }
12378
12379 say_where ();
12380}
12381
12382void
12384{
12385 if (type == bp_fast_tracepoint)
12386 gdb_printf (fp, "ftrace");
12387 else if (type == bp_static_tracepoint
12389 gdb_printf (fp, "strace");
12390 else if (type == bp_tracepoint)
12391 gdb_printf (fp, "trace");
12392 else
12393 internal_error (_("unhandled tracepoint type %d"), (int) type);
12394
12395 gdb_printf (fp, " %s", locspec->to_string ());
12397
12398 if (pass_count)
12399 gdb_printf (fp, " passcount %d\n", pass_count);
12400}
12401
12402/* Virtual table for tracepoints on static probes. */
12403
12404static void
12406 (location_spec *locspec,
12407 struct linespec_result *canonical)
12408{
12409 /* We use the same method for breakpoint on probes. */
12411}
12412
12413void
12415{
12416 re_set_default ();
12417
12418 /* extra_string should never be non-NULL for dprintf. */
12419 gdb_assert (extra_string != NULL);
12420
12421 /* 1 - connect to target 1, that can run breakpoint commands.
12422 2 - create a dprintf, which resolves fine.
12423 3 - disconnect from target 1
12424 4 - connect to target 2, that can NOT run breakpoint commands.
12425
12426 After steps #3/#4, you'll want the dprintf command list to
12427 be updated, because target 1 and 2 may well return different
12428 answers for target_can_run_breakpoint_commands().
12429 Given absence of finer grained resetting, we get to do
12430 it all the time. */
12431 if (extra_string != NULL)
12433}
12434
12435/* Implement the "print_recreate" method for dprintf. */
12436
12437void
12439{
12440 gdb_printf (fp, "dprintf %s,%s", locspec->to_string (), extra_string.get ());
12442}
12443
12444/* Implement the "after_condition_true" method for dprintf.
12445
12446 dprintf's are implemented with regular commands in their command
12447 list, but we run the commands here instead of before presenting the
12448 stop to the user, as dprintf's don't actually cause a stop. This
12449 also makes it so that the commands of multiple dprintfs at the same
12450 address are all handled. */
12451
12452void
12454{
12455 /* dprintf's never cause a stop. This wasn't set in the
12456 check_status hook instead because that would make the dprintf's
12457 condition not be evaluated. */
12458 bs->stop = false;
12459
12460 /* Run the command list here. Take ownership of it instead of
12461 copying. We never want these commands to run later in
12462 bpstat_do_actions, if a breakpoint that causes a stop happens to
12463 be set at same address as this dprintf, or even if running the
12464 commands here throws. */
12465 counted_command_line cmds = std::move (bs->commands);
12466 gdb_assert (cmds != nullptr);
12467 execute_control_commands (cmds.get (), 0);
12468}
12469
12470/* The breakpoint_ops structure to be used on static tracepoints with
12471 markers (`-m'). */
12472
12473static void
12475 struct linespec_result *canonical)
12476{
12477 struct linespec_sals lsal;
12478 const char *arg_start, *arg;
12479
12480 arg = arg_start = as_linespec_location_spec (locspec)->spec_string;
12481 lsal.sals = decode_static_tracepoint_spec (&arg);
12482
12483 std::string str (arg_start, arg - arg_start);
12484 const char *ptr = str.c_str ();
12485 canonical->locspec
12487
12488 lsal.canonical = xstrdup (canonical->locspec->to_string ());
12489 canonical->lsals.push_back (std::move (lsal));
12490}
12491
12492static void
12494 struct linespec_result *canonical,
12495 gdb::unique_xmalloc_ptr<char> cond_string,
12496 gdb::unique_xmalloc_ptr<char> extra_string,
12497 enum bptype type_wanted,
12498 enum bpdisp disposition,
12499 int thread,
12500 int task, int inferior,
12501 int ignore_count,
12502 int from_tty, int enabled,
12503 int internal, unsigned flags)
12504{
12505 const linespec_sals &lsal = canonical->lsals[0];
12506
12507 /* If the user is creating a static tracepoint by marker id
12508 (strace -m MARKER_ID), then store the sals index, so that
12509 breakpoint_re_set can try to match up which of the newly
12510 found markers corresponds to this one, and, don't try to
12511 expand multiple locations for each sal, given than SALS
12512 already should contain all sals for MARKER_ID. */
12513
12514 for (size_t i = 0; i < lsal.sals.size (); i++)
12515 {
12516 location_spec_up locspec = canonical->locspec->clone ();
12517
12518 std::unique_ptr<tracepoint> tp
12519 (new tracepoint (gdbarch,
12520 type_wanted,
12521 lsal.sals[i],
12522 std::move (locspec),
12523 NULL,
12524 std::move (cond_string),
12525 std::move (extra_string),
12526 disposition,
12527 thread, task, inferior, ignore_count,
12528 from_tty, enabled, flags,
12529 canonical->special_display));
12530
12531 /* Given that its possible to have multiple markers with
12532 the same string id, if the user is creating a static
12533 tracepoint by marker id ("strace -m MARKER_ID"), then
12534 store the sals index, so that breakpoint_re_set can
12535 try to match up which of the newly found markers
12536 corresponds to this one */
12537 tp->static_trace_marker_id_idx = i;
12538
12539 install_breakpoint (internal, std::move (tp), 0);
12540 }
12541}
12542
12543std::vector<symtab_and_line>
12545 program_space *search_pspace)
12546{
12548
12549 std::vector<symtab_and_line> sals = decode_static_tracepoint_spec (&s);
12550 if (sals.size () > static_trace_marker_id_idx)
12551 {
12552 sals[0] = sals[static_trace_marker_id_idx];
12553 sals.resize (1);
12554 return sals;
12555 }
12556 else
12557 error (_("marker %s not found"), static_trace_marker_id.c_str ());
12558}
12559
12560/* Static tracepoints with marker (`-m'). */
12566
12567static bool
12569{
12570 return b->type == bp_static_marker_tracepoint;
12571}
12572
12573/* Notify interpreters and observers that breakpoint B was deleted. */
12574
12575static void
12581
12582/* Delete a breakpoint and clean up all traces of it in the data
12583 structures. */
12584
12585void
12587{
12588 gdb_assert (bpt != NULL);
12589
12590 /* Has this bp already been deleted? This can happen because
12591 multiple lists can hold pointers to bp's. bpstat lists are
12592 especial culprits.
12593
12594 One example of this happening is a watchpoint's scope bp. When
12595 the scope bp triggers, we notice that the watchpoint is out of
12596 scope, and delete it. We also delete its scope bp. But the
12597 scope bp is marked "auto-deleting", and is already on a bpstat.
12598 That bpstat is then checked for auto-deleting bp's, which are
12599 deleted.
12600
12601 A real solution to this problem might involve reference counts in
12602 bp's, and/or giving them pointers back to their referencing
12603 bpstat's, and teaching delete_breakpoint to only free a bp's
12604 storage when no more references were extent. A cheaper bandaid
12605 was chosen. */
12606 if (bpt->type == bp_none)
12607 return;
12608
12609 /* At least avoid this stale reference until the reference counting
12610 of breakpoints gets resolved. */
12611 if (bpt->related_breakpoint != bpt)
12612 {
12613 struct breakpoint *related;
12614 struct watchpoint *w;
12615
12616 if (bpt->type == bp_watchpoint_scope)
12617 w = gdb::checked_static_cast<watchpoint *> (bpt->related_breakpoint);
12619 w = gdb::checked_static_cast<watchpoint *> (bpt);
12620 else
12621 w = NULL;
12622 if (w != NULL)
12624
12625 /* Unlink bpt from the bpt->related_breakpoint ring. */
12626 for (related = bpt; related->related_breakpoint != bpt;
12627 related = related->related_breakpoint);
12628 related->related_breakpoint = bpt->related_breakpoint;
12629 bpt->related_breakpoint = bpt;
12630 }
12631
12632 /* watch_command_1 creates a watchpoint but only sets its number if
12633 update_watchpoint succeeds in creating its bp_locations. If there's
12634 a problem in that process, we'll be asked to delete the half-created
12635 watchpoint. In that case, don't announce the deletion. */
12636 if (bpt->number)
12638
12639 breakpoint_chain.erase (breakpoint_chain.iterator_to (*bpt));
12640
12641 /* Be sure no bpstat's are pointing at the breakpoint after it's
12642 been freed. */
12643 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
12644 in all threads for now. Note that we cannot just remove bpstats
12645 pointing at bpt from the stop_bpstat list entirely, as breakpoint
12646 commands are associated with the bpstat; if we remove it here,
12647 then the later call to bpstat_do_actions (&stop_bpstat); in
12648 event-top.c won't do anything, and temporary breakpoints with
12649 commands won't work. */
12650
12652
12653 /* Now that breakpoint is removed from breakpoint list, update the
12654 global location list. This will remove locations that used to
12655 belong to this breakpoint. Do this before freeing the breakpoint
12656 itself, since remove_breakpoint looks at location's owner. It
12657 might be better design to have location completely
12658 self-contained, but it's not the case now.
12659
12660 Clear the location linked list first, otherwise, the intrusive_list
12661 destructor accesses the locations after they are freed. */
12662 bpt->clear_locations ();
12664
12665 /* On the chance that someone will soon try again to delete this
12666 same bp, we mark it as deleted before freeing its storage. */
12667 bpt->type = bp_none;
12668 delete bpt;
12669}
12670
12671/* Iterator function to call a user-provided callback function once
12672 for each of B and its related breakpoints. */
12673
12674static void
12676 gdb::function_view<void (breakpoint *)> function)
12677{
12678 struct breakpoint *related;
12679
12680 related = b;
12681 do
12682 {
12683 struct breakpoint *next;
12684
12685 /* FUNCTION may delete RELATED. */
12686 next = related->related_breakpoint;
12687
12688 if (next == related)
12689 {
12690 /* RELATED is the last ring entry. */
12691 function (related);
12692
12693 /* FUNCTION may have deleted it, so we'd never reach back to
12694 B. There's nothing left to do anyway, so just break
12695 out. */
12696 break;
12697 }
12698 else
12699 function (related);
12700
12701 related = next;
12702 }
12703 while (related != b);
12704}
12705
12706static void
12707delete_command (const char *arg, int from_tty)
12708{
12709 dont_repeat ();
12710
12711 if (arg == 0)
12712 {
12713 int breaks_to_delete = 0;
12714
12715 /* Delete all breakpoints if no argument. Do not delete
12716 internal breakpoints, these have to be deleted with an
12717 explicit breakpoint number argument. */
12718 for (breakpoint &b : all_breakpoints ())
12719 if (user_breakpoint_p (&b))
12720 {
12721 breaks_to_delete = 1;
12722 break;
12723 }
12724
12725 /* Ask user only if there are some breakpoints to delete. */
12726 if (!from_tty
12727 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
12728 for (breakpoint &b : all_breakpoints_safe ())
12729 if (user_breakpoint_p (&b))
12730 delete_breakpoint (&b);
12731 }
12732 else
12734 (arg, [&] (breakpoint *br)
12735 {
12737 });
12738}
12739
12740/* Return true if all locations of B bound to PSPACE are pending. If
12741 PSPACE is NULL, all locations of all program spaces are
12742 considered. */
12743
12744static bool
12746{
12747 for (bp_location &loc : b->locations ())
12748 if ((pspace == NULL
12749 || loc.pspace == pspace)
12750 && !loc.shlib_disabled
12751 && !loc.pspace->executing_startup)
12752 return false;
12753 return true;
12754}
12755
12756/* Subroutine of update_breakpoint_locations to simplify it.
12757 Return true if multiple fns in list LOCS have the same name.
12758 Null names are ignored. */
12759
12760static bool
12762{
12763 htab_up htab (htab_create_alloc (13, htab_hash_string, htab_eq_string, NULL,
12764 xcalloc, xfree));
12765
12766 for (const bp_location &l : locs)
12767 {
12768 const char **slot;
12769 const char *name = l.function_name.get ();
12770
12771 /* Allow for some names to be NULL, ignore them. */
12772 if (name == NULL)
12773 continue;
12774
12775 slot = (const char **) htab_find_slot (htab.get (), (const void *) name,
12776 INSERT);
12777 /* NOTE: We can assume slot != NULL here because xcalloc never
12778 returns NULL. */
12779 if (*slot != NULL)
12780 return true;
12781 *slot = name;
12782 }
12783
12784 return false;
12785}
12786
12787/* When symbols change, it probably means the sources changed as well,
12788 and it might mean the static tracepoint markers are no longer at
12789 the same address or line numbers they used to be at last we
12790 checked. Losing your static tracepoints whenever you rebuild is
12791 undesirable. This function tries to resync/rematch gdb static
12792 tracepoints with the markers on the target, for static tracepoints
12793 that have not been set by marker id. Static tracepoint that have
12794 been set by marker id are reset by marker id in breakpoint_re_set.
12795 The heuristic is:
12796
12797 1) For a tracepoint set at a specific address, look for a marker at
12798 the old PC. If one is found there, assume to be the same marker.
12799 If the name / string id of the marker found is different from the
12800 previous known name, assume that means the user renamed the marker
12801 in the sources, and output a warning.
12802
12803 2) For a tracepoint set at a given line number, look for a marker
12804 at the new address of the old line number. If one is found there,
12805 assume to be the same marker. If the name / string id of the
12806 marker found is different from the previous known name, assume that
12807 means the user renamed the marker in the sources, and output a
12808 warning.
12809
12810 3) If a marker is no longer found at the same address or line, it
12811 may mean the marker no longer exists. But it may also just mean
12812 the code changed a bit. Maybe the user added a few lines of code
12813 that made the marker move up or down (in line number terms). Ask
12814 the target for info about the marker with the string id as we knew
12815 it. If found, update line number and address in the matching
12816 static tracepoint. This will get confused if there's more than one
12817 marker with the same ID (possible in UST, although unadvised
12818 precisely because it confuses tools). */
12819
12820static struct symtab_and_line
12822{
12823 struct static_tracepoint_marker marker;
12824 CORE_ADDR pc;
12825
12826 pc = sal.pc;
12827 if (sal.line)
12828 find_line_pc (sal.symtab, sal.line, &pc);
12829
12831 {
12832 if (tp->static_trace_marker_id != marker.str_id)
12833 warning (_("static tracepoint %d changed probed marker from %s to %s"),
12834 tp->number, tp->static_trace_marker_id.c_str (),
12835 marker.str_id.c_str ());
12836
12837 tp->static_trace_marker_id = std::move (marker.str_id);
12838
12839 return sal;
12840 }
12841
12842 /* Old marker wasn't found on target at lineno. Try looking it up
12843 by string ID. */
12844 if (!sal.explicit_pc
12845 && sal.line != 0
12846 && sal.symtab != NULL
12847 && !tp->static_trace_marker_id.empty ())
12848 {
12849 std::vector<static_tracepoint_marker> markers
12851 (tp->static_trace_marker_id.c_str ());
12852
12853 if (!markers.empty ())
12854 {
12855 struct symbol *sym;
12856 struct static_tracepoint_marker *tpmarker;
12857 struct ui_out *uiout = current_uiout;
12858
12859 tpmarker = &markers[0];
12860
12861 tp->static_trace_marker_id = std::move (tpmarker->str_id);
12862
12863 warning (_("marker for static tracepoint %d (%s) not "
12864 "found at previous line number"),
12865 tp->number, tp->static_trace_marker_id.c_str ());
12866
12867 symtab_and_line sal2 = find_pc_line (tpmarker->address, 0);
12868 sym = find_pc_sect_function (tpmarker->address, NULL);
12869 uiout->text ("Now in ");
12870 if (sym)
12871 {
12872 uiout->field_string ("func", sym->print_name (),
12874 uiout->text (" at ");
12875 }
12876 uiout->field_string ("file",
12879 uiout->text (":");
12880
12881 if (uiout->is_mi_like_p ())
12882 {
12883 const char *fullname = symtab_to_fullname (sal2.symtab);
12884
12885 uiout->field_string ("fullname", fullname);
12886 }
12887
12888 uiout->field_signed ("line", sal2.line);
12889 uiout->text ("\n");
12890
12891 tp->first_loc ().line_number = sal2.line;
12892 tp->first_loc ().symtab = sym != NULL ? sal2.symtab : NULL;
12893
12894 std::unique_ptr<explicit_location_spec> els
12895 (new explicit_location_spec ());
12896 els->source_filename
12897 = xstrdup (symtab_to_filename_for_display (sal2.symtab));
12898 els->line_offset.offset = tp->first_loc ().line_number;
12899 els->line_offset.sign = LINE_OFFSET_NONE;
12900
12901 tp->locspec = std::move (els);
12902
12903 /* Might be nice to check if function changed, and warn if
12904 so. */
12905 }
12906 }
12907 return sal;
12908}
12909
12910/* Returns true iff location lists A and B are sufficiently same that
12911 we don't need to report breakpoint as changed. */
12912
12913static bool
12915{
12916 auto a_iter = a.begin ();
12917 auto b_iter = b.begin ();
12918
12919 for (; a_iter != a.end () && b_iter != b.end (); ++a_iter, ++b_iter)
12920 {
12921 if (a_iter->address != b_iter->address)
12922 return false;
12923
12924 if (a_iter->shlib_disabled != b_iter->shlib_disabled)
12925 return false;
12926
12927 if (a_iter->enabled != b_iter->enabled)
12928 return false;
12929
12930 if (a_iter->disabled_by_cond != b_iter->disabled_by_cond)
12931 return false;
12932 }
12933
12934 return (a_iter == a.end ()) == (b_iter == b.end ());
12935}
12936
12937/* See breakpoint.h. */
12938
12941{
12942 if (pspace == NULL)
12943 return std::move (m_locations);
12944
12945 bp_location_list ret;
12946
12947 for (auto it = m_locations.begin (); it != m_locations.end (); )
12948 {
12949 if (it->pspace == pspace)
12950 {
12951 bp_location &loc = *it;
12952 it = m_locations.erase (it);
12953 ret.push_back (loc);
12954 }
12955 else
12956 ++it;
12957 }
12958
12959 return ret;
12960}
12961
12962/* Create new breakpoint locations for B (a hardware or software
12963 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
12964 zero, then B is a ranged breakpoint. Only recreates locations for
12965 FILTER_PSPACE. Locations of other program spaces are left
12966 untouched. */
12967
12968void
12970 struct program_space *filter_pspace,
12971 gdb::array_view<const symtab_and_line> sals,
12972 gdb::array_view<const symtab_and_line> sals_end)
12973{
12974 if (!sals_end.empty () && (sals.size () != 1 || sals_end.size () != 1))
12975 {
12976 /* Ranged breakpoints have only one start location and one end
12977 location. */
12980 _("Could not reset ranged breakpoint %d: "
12981 "multiple locations found\n"),
12982 b->number);
12983 return;
12984 }
12985
12986 /* If there's no new locations, and all existing locations are
12987 pending, don't do anything. This optimizes the common case where
12988 all locations are in the same shared library, that was unloaded.
12989 We'd like to retain the location, so that when the library is
12990 loaded again, we don't loose the enabled/disabled status of the
12991 individual locations. */
12992 if (all_locations_are_pending (b, filter_pspace) && sals.empty ())
12993 return;
12994
12995 bp_location_list existing_locations = b->steal_locations (filter_pspace);
12996
12997 for (const auto &sal : sals)
12998 {
12999 struct bp_location *new_loc;
13000
13002
13003 new_loc = b->add_location (sal);
13004
13005 /* Reparse conditions, they might contain references to the
13006 old symtab. */
13007 if (b->cond_string != NULL)
13008 {
13009 const char *s;
13010
13011 s = b->cond_string.get ();
13012 try
13013 {
13014 new_loc->cond = parse_exp_1 (&s, sal.pc,
13015 block_for_pc (sal.pc),
13016 0);
13017 }
13018 catch (const gdb_exception_error &e)
13019 {
13020 new_loc->disabled_by_cond = true;
13021 }
13022 }
13023
13024 if (!sals_end.empty ())
13025 {
13026 CORE_ADDR end = find_breakpoint_range_end (sals_end[0]);
13027
13028 new_loc->length = end - sals[0].pc + 1;
13029 }
13030 }
13031
13032 /* If possible, carry over 'disable' status from existing
13033 breakpoints. */
13034 {
13035 /* If there are multiple breakpoints with the same function name,
13036 e.g. for inline functions, comparing function names won't work.
13037 Instead compare pc addresses; this is just a heuristic as things
13038 may have moved, but in practice it gives the correct answer
13039 often enough until a better solution is found. */
13040 int have_ambiguous_names = ambiguous_names_p (b->locations ());
13041
13042 for (const bp_location &e : existing_locations)
13043 {
13044 if ((!e.enabled || e.disabled_by_cond) && e.function_name)
13045 {
13046 if (have_ambiguous_names)
13047 {
13048 for (bp_location &l : b->locations ())
13049 {
13050 /* Ignore software vs hardware location type at
13051 this point, because with "set breakpoint
13052 auto-hw", after a re-set, locations that were
13053 hardware can end up as software, or vice versa.
13054 As mentioned above, this is an heuristic and in
13055 practice should give the correct answer often
13056 enough. */
13057 if (breakpoint_locations_match (&e, &l, true))
13058 {
13059 l.enabled = e.enabled;
13060 l.disabled_by_cond = e.disabled_by_cond;
13061 break;
13062 }
13063 }
13064 }
13065 else
13066 {
13067 for (bp_location &l : b->locations ())
13068 if (l.function_name
13069 && strcmp (e.function_name.get (),
13070 l.function_name.get ()) == 0)
13071 {
13072 l.enabled = e.enabled;
13073 l.disabled_by_cond = e.disabled_by_cond;
13074 break;
13075 }
13076 }
13077 }
13078 }
13079 }
13080
13081 if (!locations_are_equal (existing_locations, b->locations ()))
13083}
13084
13085/* Find the SaL locations corresponding to the given LOCSPEC.
13086 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
13087
13088std::vector<symtab_and_line>
13090 struct program_space *search_pspace,
13091 int *found)
13092{
13093 struct gdb_exception exception;
13094
13095 std::vector<symtab_and_line> sals;
13096
13097 try
13098 {
13099 sals = decode_location_spec (locspec, search_pspace);
13100 }
13101 catch (gdb_exception_error &e)
13102 {
13103 int not_found_and_ok = false;
13104
13105 /* For pending breakpoints, it's expected that parsing will
13106 fail until the right shared library is loaded. User has
13107 already told to create pending breakpoints and don't need
13108 extra messages. If breakpoint is in bp_shlib_disabled
13109 state, then user already saw the message about that
13110 breakpoint being disabled, and don't want to see more
13111 errors. */
13112 if (e.error == NOT_FOUND_ERROR
13114 || (this->has_locations ()
13115 && search_pspace != NULL
13116 && this->first_loc ().pspace != search_pspace)
13117 || (this->has_locations () && this->first_loc ().shlib_disabled)
13118 || (this->has_locations ()
13119 && this->first_loc ().pspace->executing_startup)
13121 not_found_and_ok = true;
13122
13123 if (!not_found_and_ok)
13124 {
13125 /* We surely don't want to warn about the same breakpoint
13126 10 times. One solution, implemented here, is disable
13127 the breakpoint on error. Another solution would be to
13128 have separate 'warning emitted' flag. Since this
13129 happens only when a binary has changed, I don't know
13130 which approach is better. */
13132 throw;
13133 }
13134
13135 exception = std::move (e);
13136 }
13137
13138 if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR)
13139 {
13140 for (auto &sal : sals)
13141 resolve_sal_pc (&sal);
13142 if (condition_not_parsed && extra_string != NULL)
13143 {
13144 gdb::unique_xmalloc_ptr<char> local_cond, local_extra;
13145 int local_thread, local_task, local_inferior;
13146
13148 &local_cond, &local_thread,
13149 &local_inferior,
13150 &local_task, &local_extra);
13151 gdb_assert (cond_string == nullptr);
13152 if (local_cond != nullptr)
13153 cond_string = std::move (local_cond);
13154 thread = local_thread;
13155 task = local_task;
13156 if (local_extra != nullptr)
13157 extra_string = std::move (local_extra);
13159 }
13160
13162 {
13163 tracepoint *t = gdb::checked_static_cast<tracepoint *> (this);
13164 sals[0] = update_static_tracepoint (t, sals[0]);
13165 }
13166
13167 *found = 1;
13168 }
13169 else
13170 *found = 0;
13171
13172 return sals;
13173}
13174
13175/* The default re_set method, for typical hardware or software
13176 breakpoints. Reevaluate the breakpoint and recreate its
13177 locations. */
13178
13179void
13181{
13182 struct program_space *filter_pspace = current_program_space;
13183 std::vector<symtab_and_line> expanded, expanded_end;
13184
13185 int found;
13186 std::vector<symtab_and_line> sals = location_spec_to_sals (locspec.get (),
13187 filter_pspace,
13188 &found);
13189 if (found)
13190 expanded = std::move (sals);
13191
13192 if (locspec_range_end != nullptr)
13193 {
13194 std::vector<symtab_and_line> sals_end
13196 filter_pspace, &found);
13197 if (found)
13198 expanded_end = std::move (sals_end);
13199 }
13200
13201 update_breakpoint_locations (this, filter_pspace, expanded, expanded_end);
13202}
13203
13204/* Default method for creating SALs from an address string. It basically
13205 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
13206
13207static void
13209 struct linespec_result *canonical)
13210{
13211 parse_breakpoint_sals (locspec, canonical);
13212}
13213
13214/* Reset a breakpoint. */
13215
13216static void
13218{
13221
13222 b->re_set ();
13223}
13224
13225/* Re-set breakpoint locations for the current program space.
13226 Locations bound to other program spaces are left untouched. */
13227
13228void
13230{
13231 {
13232 scoped_restore_current_language save_language;
13233 scoped_restore save_input_radix = make_scoped_restore (&input_radix);
13234 scoped_restore_current_pspace_and_thread restore_pspace_thread;
13235
13236 /* breakpoint_re_set_one sets the current_language to the language
13237 of the breakpoint it is resetting (see prepare_re_set_context)
13238 before re-evaluating the breakpoint's location. This change can
13239 unfortunately get undone by accident if the language_mode is set
13240 to auto, and we either switch frames, or more likely in this context,
13241 we select the current frame.
13242
13243 We prevent this by temporarily turning the language_mode to
13244 language_mode_manual. We restore it once all breakpoints
13245 have been reset. */
13246 scoped_restore save_language_mode = make_scoped_restore (&language_mode);
13248
13249 /* Note: we must not try to insert locations until after all
13250 breakpoints have been re-set. Otherwise, e.g., when re-setting
13251 breakpoint 1, we'd insert the locations of breakpoint 2, which
13252 hadn't been re-set yet, and thus may have stale locations. */
13253
13254 for (breakpoint &b : all_breakpoints_safe ())
13255 {
13256 try
13257 {
13259 }
13260 catch (const gdb_exception &ex)
13261 {
13263 "Error in re-setting breakpoint %d: ",
13264 b.number);
13265 }
13266 }
13267
13269 }
13270
13275
13276 /* Now we can insert. */
13278}
13279
13280/* Reset the thread number of this breakpoint:
13281
13282 - If the breakpoint is for all threads, leave it as-is.
13283 - Else, reset it to the current thread for inferior_ptid. */
13284void
13286{
13287 if (b->thread != -1)
13288 {
13290
13291 /* We're being called after following a fork. The new fork is
13292 selected as current, and unless this was a vfork will have a
13293 different program space from the original thread. Reset that
13294 as well. */
13296 }
13297}
13298
13299/* Set ignore-count of breakpoint number BPTNUM to COUNT.
13300 If from_tty is nonzero, it prints a message to that effect,
13301 which ends with a period (no newline). */
13302
13303void
13304set_ignore_count (int bptnum, int count, int from_tty)
13305{
13306 if (count < 0)
13307 count = 0;
13308
13309 for (breakpoint &b : all_breakpoints ())
13310 if (b.number == bptnum)
13311 {
13312 if (is_tracepoint (&b))
13313 {
13314 if (from_tty && count != 0)
13315 gdb_printf (_("Ignore count ignored for tracepoint %d."),
13316 bptnum);
13317 return;
13318 }
13319
13320 b.ignore_count = count;
13321 if (from_tty)
13322 {
13323 if (count == 0)
13324 gdb_printf (_("Will stop next time "
13325 "breakpoint %d is reached."),
13326 bptnum);
13327 else if (count == 1)
13328 gdb_printf (_("Will ignore next crossing of breakpoint %d."),
13329 bptnum);
13330 else
13331 gdb_printf (_("Will ignore next %d "
13332 "crossings of breakpoint %d."),
13333 count, bptnum);
13334 }
13336 return;
13337 }
13338
13339 error (_("No breakpoint number %d."), bptnum);
13340}
13341
13342/* Command to set ignore-count of breakpoint N to COUNT. */
13343
13344static void
13345ignore_command (const char *args, int from_tty)
13346{
13347 const char *p = args;
13348 int num;
13349
13350 if (p == 0)
13351 error_no_arg (_("a breakpoint number"));
13352
13353 num = get_number (&p);
13354 if (num == 0)
13355 error (_("bad breakpoint number: '%s'"), args);
13356 if (*p == 0)
13357 error (_("Second argument (specified ignore-count) is missing."));
13358
13361 from_tty);
13362 if (from_tty)
13363 gdb_printf ("\n");
13364}
13365
13366
13367/* Call FUNCTION on each of the breakpoints with numbers in the range
13368 defined by BP_NUM_RANGE (an inclusive range). */
13369
13370static void
13371map_breakpoint_number_range (std::pair<int, int> bp_num_range,
13372 gdb::function_view<void (breakpoint *)> function)
13373{
13374 if (bp_num_range.first == 0)
13375 {
13376 warning (_("bad breakpoint number at or near '%d'"),
13377 bp_num_range.first);
13378 }
13379 else
13380 {
13381 for (int i = bp_num_range.first; i <= bp_num_range.second; i++)
13382 {
13383 bool match = false;
13384
13385 for (breakpoint &b : all_breakpoints_safe ())
13386 if (b.number == i)
13387 {
13388 match = true;
13389 function (&b);
13390 break;
13391 }
13392 if (!match)
13393 gdb_printf (_("No breakpoint number %d.\n"), i);
13394 }
13395 }
13396}
13397
13398/* Call FUNCTION on each of the breakpoints whose numbers are given in
13399 ARGS. */
13400
13401static void
13402map_breakpoint_numbers (const char *args,
13403 gdb::function_view<void (breakpoint *)> function)
13404{
13405 if (args == NULL || *args == '\0')
13406 error_no_arg (_("one or more breakpoint numbers"));
13407
13408 number_or_range_parser parser (args);
13409
13410 while (!parser.finished ())
13411 {
13412 int num = parser.get_number ();
13413 map_breakpoint_number_range (std::make_pair (num, num), function);
13414 }
13415}
13416
13417/* Return the breakpoint location structure corresponding to the
13418 BP_NUM and LOC_NUM values. */
13419
13420static struct bp_location *
13421find_location_by_number (int bp_num, int loc_num)
13422{
13423 breakpoint *b = get_breakpoint (bp_num);
13424
13425 if (!b || b->number != bp_num)
13426 error (_("Bad breakpoint number '%d'"), bp_num);
13427
13428 if (loc_num == 0)
13429 error (_("Bad breakpoint location number '%d'"), loc_num);
13430
13431 int n = 0;
13432 for (bp_location &loc : b->locations ())
13433 if (++n == loc_num)
13434 return &loc;
13435
13436 error (_("Bad breakpoint location number '%d'"), loc_num);
13437}
13438
13439/* Modes of operation for extract_bp_num. */
13441{
13442 /* Extracting a breakpoint number. */
13443 bp,
13444
13445 /* Extracting a location number. */
13446 loc,
13447};
13448
13449/* Extract a breakpoint or location number (as determined by KIND)
13450 from the string starting at START. TRAILER is a character which
13451 can be found after the number. If you don't want a trailer, use
13452 '\0'. If END_OUT is not NULL, it is set to point after the parsed
13453 string. This always returns a positive integer. */
13454
13455static int
13456extract_bp_num (extract_bp_kind kind, const char *start,
13457 int trailer, const char **end_out = NULL)
13458{
13459 const char *end = start;
13460 int num = get_number_trailer (&end, trailer);
13461 if (num < 0)
13462 error (kind == extract_bp_kind::bp
13463 ? _("Negative breakpoint number '%.*s'")
13464 : _("Negative breakpoint location number '%.*s'"),
13465 int (end - start), start);
13466 if (num == 0)
13467 error (kind == extract_bp_kind::bp
13468 ? _("Bad breakpoint number '%.*s'")
13469 : _("Bad breakpoint location number '%.*s'"),
13470 int (end - start), start);
13471
13472 if (end_out != NULL)
13473 *end_out = end;
13474 return num;
13475}
13476
13477/* Extract a breakpoint or location range (as determined by KIND) in
13478 the form NUM1-NUM2 stored at &ARG[arg_offset]. Returns a std::pair
13479 representing the (inclusive) range. The returned pair's elements
13480 are always positive integers. */
13481
13482static std::pair<int, int>
13484 const std::string &arg,
13485 std::string::size_type arg_offset)
13486{
13487 std::pair<int, int> range;
13488 const char *bp_loc = &arg[arg_offset];
13489 std::string::size_type dash = arg.find ('-', arg_offset);
13490 if (dash != std::string::npos)
13491 {
13492 /* bp_loc is a range (x-z). */
13493 if (arg.length () == dash + 1)
13494 error (kind == extract_bp_kind::bp
13495 ? _("Bad breakpoint number at or near: '%s'")
13496 : _("Bad breakpoint location number at or near: '%s'"),
13497 bp_loc);
13498
13499 const char *end;
13500 const char *start_first = bp_loc;
13501 const char *start_second = &arg[dash + 1];
13502 range.first = extract_bp_num (kind, start_first, '-');
13503 range.second = extract_bp_num (kind, start_second, '\0', &end);
13504
13505 if (range.first > range.second)
13506 error (kind == extract_bp_kind::bp
13507 ? _("Inverted breakpoint range at '%.*s'")
13508 : _("Inverted breakpoint location range at '%.*s'"),
13509 int (end - start_first), start_first);
13510 }
13511 else
13512 {
13513 /* bp_loc is a single value. */
13514 range.first = extract_bp_num (kind, bp_loc, '\0');
13515 range.second = range.first;
13516 }
13517 return range;
13518}
13519
13520/* Extract the breakpoint/location range specified by ARG. Returns
13521 the breakpoint range in BP_NUM_RANGE, and the location range in
13522 BP_LOC_RANGE.
13523
13524 ARG may be in any of the following forms:
13525
13526 x where 'x' is a breakpoint number.
13527 x-y where 'x' and 'y' specify a breakpoint numbers range.
13528 x.y where 'x' is a breakpoint number and 'y' a location number.
13529 x.y-z where 'x' is a breakpoint number and 'y' and 'z' specify a
13530 location number range.
13531*/
13532
13533static void
13534extract_bp_number_and_location (const std::string &arg,
13535 std::pair<int, int> &bp_num_range,
13536 std::pair<int, int> &bp_loc_range)
13537{
13538 std::string::size_type dot = arg.find ('.');
13539
13540 if (dot != std::string::npos)
13541 {
13542 /* Handle 'x.y' and 'x.y-z' cases. */
13543
13544 if (arg.length () == dot + 1 || dot == 0)
13545 error (_("Bad breakpoint number at or near: '%s'"), arg.c_str ());
13546
13547 bp_num_range.first
13548 = extract_bp_num (extract_bp_kind::bp, arg.c_str (), '.');
13549 bp_num_range.second = bp_num_range.first;
13550
13552 arg, dot + 1);
13553 }
13554 else
13555 {
13556 /* Handle x and x-y cases. */
13557
13558 bp_num_range = extract_bp_or_bp_range (extract_bp_kind::bp, arg, 0);
13559 bp_loc_range.first = 0;
13560 bp_loc_range.second = 0;
13561 }
13562}
13563
13564/* Enable or disable a breakpoint location BP_NUM.LOC_NUM. ENABLE
13565 specifies whether to enable or disable. */
13566
13567static void
13568enable_disable_bp_num_loc (int bp_num, int loc_num, bool enable)
13569{
13570 struct bp_location *loc = find_location_by_number (bp_num, loc_num);
13571 if (loc != NULL)
13572 {
13573 if (loc->disabled_by_cond && enable)
13574 error (_("Breakpoint %d's condition is invalid at location %d, "
13575 "cannot enable."), bp_num, loc_num);
13576
13577 if (loc->enabled != enable)
13578 {
13579 loc->enabled = enable;
13581 }
13583 && current_trace_status ()->running && loc->owner
13584 && is_tracepoint (loc->owner))
13586 }
13588
13590}
13591
13592/* Calculates LOC_NUM for LOC by traversing the bp_location chain of LOC's
13593 owner. 1-based indexing. -1 signals NOT FOUND. */
13594
13595static int
13597{
13598 if (loc != nullptr && loc->owner != nullptr)
13599 {
13600 /* Locations use 1-based indexing. */
13601 int loc_num = 1;
13602 for (bp_location &it : loc->owner->locations ())
13603 {
13604 if (&it == loc)
13605 return loc_num;
13606 loc_num++;
13607 }
13608 }
13609 return -1;
13610}
13611
13612/* Enable or disable a breakpoint location LOC. ENABLE
13613 specifies whether to enable or disable. */
13614
13615void
13617{
13618 if (loc == nullptr)
13619 error (_("Breakpoint location is invalid."));
13620
13621 if (loc->owner == nullptr)
13622 error (_("Breakpoint location does not have an owner breakpoint."));
13623
13624 if (loc->disabled_by_cond && enable)
13625 {
13626 int loc_num = find_loc_num_by_location (loc);
13627 if (loc_num == -1)
13628 error (_("Breakpoint location LOC_NUM could not be found."));
13629 else
13630 error (_("Breakpoint %d's condition is invalid at location %d, "
13631 "cannot enable."), loc->owner->number, loc_num);
13632 }
13633
13634 if (loc->enabled != enable)
13635 {
13636 loc->enabled = enable;
13638 }
13639
13641 && current_trace_status ()->running && loc->owner
13642 && is_tracepoint (loc->owner))
13644
13647}
13648
13649/* Enable or disable a range of breakpoint locations. BP_NUM is the
13650 number of the breakpoint, and BP_LOC_RANGE specifies the
13651 (inclusive) range of location numbers of that breakpoint to
13652 enable/disable. ENABLE specifies whether to enable or disable the
13653 location. */
13654
13655static void
13657 std::pair<int, int> &bp_loc_range,
13658 bool enable)
13659{
13660 for (int i = bp_loc_range.first; i <= bp_loc_range.second; i++)
13661 enable_disable_bp_num_loc (bp_num, i, enable);
13662}
13663
13664/* Set ignore-count of breakpoint number BPTNUM to COUNT.
13665 If from_tty is nonzero, it prints a message to that effect,
13666 which ends with a period (no newline). */
13667
13668void
13670{
13671 /* Never disable a watchpoint scope breakpoint; we want to
13672 hit them when we leave scope so we can delete both the
13673 watchpoint and its scope breakpoint at that time. */
13674 if (bpt->type == bp_watchpoint_scope)
13675 return;
13676
13678
13679 /* Mark breakpoint locations modified. */
13681
13683 && current_trace_status ()->running && is_tracepoint (bpt))
13684 {
13685 for (bp_location &location : bpt->locations ())
13686 target_disable_tracepoint (&location);
13687 }
13688
13690
13692}
13693
13694/* Enable or disable the breakpoint(s) or breakpoint location(s)
13695 specified in ARGS. ARGS may be in any of the formats handled by
13696 extract_bp_number_and_location. ENABLE specifies whether to enable
13697 or disable the breakpoints/locations. */
13698
13699static void
13700enable_disable_command (const char *args, int from_tty, bool enable)
13701{
13702 if (args == 0)
13703 {
13704 for (breakpoint &bpt : all_breakpoints ())
13705 if (user_breakpoint_p (&bpt))
13706 {
13707 if (enable)
13708 enable_breakpoint (&bpt);
13709 else
13710 disable_breakpoint (&bpt);
13711 }
13712 }
13713 else
13714 {
13715 std::string num = extract_arg (&args);
13716
13717 while (!num.empty ())
13718 {
13719 std::pair<int, int> bp_num_range, bp_loc_range;
13720
13721 extract_bp_number_and_location (num, bp_num_range, bp_loc_range);
13722
13723 if (bp_loc_range.first == bp_loc_range.second
13724 && (bp_loc_range.first == 0
13725 || (bp_loc_range.first == 1
13726 && bp_num_range.first == bp_num_range.second
13727 && !has_multiple_locations (bp_num_range.first))))
13728 {
13729 /* Handle breakpoint ids with formats 'x' or 'x-z'
13730 or 'y.1' where y has only one code location. */
13731 map_breakpoint_number_range (bp_num_range,
13732 enable
13735 }
13736 else
13737 {
13738 /* Handle breakpoint ids with formats 'x.y' or
13739 'x.y-z'. */
13741 (bp_num_range.first, bp_loc_range, enable);
13742 }
13743 num = extract_arg (&args);
13744 }
13745 }
13746}
13747
13748/* The disable command disables the specified breakpoints/locations
13749 (or all defined breakpoints) so they're no longer effective in
13750 stopping the inferior. ARGS may be in any of the forms defined in
13751 extract_bp_number_and_location. */
13752
13753static void
13754disable_command (const char *args, int from_tty)
13755{
13756 enable_disable_command (args, from_tty, false);
13757}
13758
13759static void
13760enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition,
13761 int count)
13762{
13763 int target_resources_ok;
13764
13765 if (bpt->type == bp_hardware_breakpoint)
13766 {
13767 int i;
13769 target_resources_ok =
13771 i + 1, 0);
13772 if (target_resources_ok == 0)
13773 error (_("No hardware breakpoint support in the target."));
13774 else if (target_resources_ok < 0)
13775 error (_("Hardware breakpoints used exceeds limit."));
13776 }
13777
13778 if (is_watchpoint (bpt))
13779 {
13780 /* Initialize it just to avoid a GCC false warning. */
13781 enum enable_state orig_enable_state = bp_disabled;
13782
13783 try
13784 {
13785 watchpoint *w = gdb::checked_static_cast<watchpoint *> (bpt);
13786
13787 orig_enable_state = bpt->enable_state;
13788 bpt->enable_state = bp_enabled;
13789 update_watchpoint (w, true /* reparse */);
13790 }
13791 catch (const gdb_exception_error &e)
13792 {
13793 bpt->enable_state = orig_enable_state;
13794 exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
13795 bpt->number);
13796 return;
13797 }
13798 }
13799
13800 bpt->enable_state = bp_enabled;
13801
13802 /* Mark breakpoint locations modified. */
13804
13806 && current_trace_status ()->running && is_tracepoint (bpt))
13807 {
13808 for (bp_location &location : bpt->locations ())
13809 target_enable_tracepoint (&location);
13810 }
13811
13812 bpt->disposition = disposition;
13813 bpt->enable_count = count;
13815
13817}
13818
13819
13820void
13822{
13823 enable_breakpoint_disp (bpt, bpt->disposition, 0);
13824}
13825
13826/* The enable command enables the specified breakpoints/locations (or
13827 all defined breakpoints) so they once again become (or continue to
13828 be) effective in stopping the inferior. ARGS may be in any of the
13829 forms defined in extract_bp_number_and_location. */
13830
13831static void
13832enable_command (const char *args, int from_tty)
13833{
13834 enable_disable_command (args, from_tty, true);
13835}
13836
13837static void
13838enable_once_command (const char *args, int from_tty)
13839{
13841 (args, [&] (breakpoint *b)
13842 {
13844 (b, [&] (breakpoint *bpt)
13845 {
13847 });
13848 });
13849}
13850
13851static void
13852enable_count_command (const char *args, int from_tty)
13853{
13854 int count;
13855
13856 if (args == NULL)
13857 error_no_arg (_("hit count"));
13858
13859 count = get_number (&args);
13860
13862 (args, [&] (breakpoint *b)
13863 {
13865 (b, [&] (breakpoint *bpt)
13866 {
13868 });
13869 });
13870}
13871
13872static void
13873enable_delete_command (const char *args, int from_tty)
13874{
13876 (args, [&] (breakpoint *b)
13877 {
13879 (b, [&] (breakpoint *bpt)
13880 {
13882 });
13883 });
13884}
13885
13886/* Invalidate last known value of any hardware watchpoint if
13887 the memory which that value represents has been written to by
13888 GDB itself. */
13889
13890static void
13892 CORE_ADDR addr, ssize_t len,
13893 const bfd_byte *data)
13894{
13895 for (breakpoint &bp : all_breakpoints ())
13896 if (bp.enable_state == bp_enabled
13897 && bp.type == bp_hardware_watchpoint)
13898 {
13899 watchpoint &wp = gdb::checked_static_cast<watchpoint &> (bp);
13900
13901 if (wp.val_valid && wp.val != nullptr)
13902 {
13903 for (bp_location &loc : bp.locations ())
13904 if (loc.loc_type == bp_loc_hardware_watchpoint
13905 && loc.address + loc.length > addr
13906 && addr + len > loc.address)
13907 {
13908 wp.val = NULL;
13909 wp.val_valid = false;
13910 }
13911 }
13912 }
13913}
13914
13915/* Create and insert a breakpoint for software single step. */
13916
13917void
13919 const address_space *aspace,
13920 CORE_ADDR next_pc)
13921{
13922 struct thread_info *tp = inferior_thread ();
13923 struct symtab_and_line sal;
13924 CORE_ADDR pc = next_pc;
13925
13926 if (tp->control.single_step_breakpoints == NULL)
13927 {
13928 std::unique_ptr<breakpoint> b
13932 tp->global_num));
13933
13935 = add_to_breakpoint_chain (std::move (b));
13936 }
13937
13938 sal = find_pc_line (pc, 0);
13939 sal.pc = pc;
13940 sal.section = find_pc_overlay (pc);
13941 sal.explicit_pc = 1;
13942
13943 auto *ss_bp
13944 = (gdb::checked_static_cast<momentary_breakpoint *>
13946 ss_bp->add_location (sal);
13947
13949}
13950
13951/* Insert single step breakpoints according to the current state. */
13952
13953int
13955{
13957 std::vector<CORE_ADDR> next_pcs;
13958
13960
13961 if (!next_pcs.empty ())
13962 {
13965
13966 for (CORE_ADDR pc : next_pcs)
13968
13969 return 1;
13970 }
13971 else
13972 return 0;
13973}
13974
13975/* See breakpoint.h. */
13976
13977int
13979 const address_space *aspace,
13980 CORE_ADDR pc)
13981{
13982 for (bp_location &loc : bp->locations ())
13983 if (loc.inserted
13985 return 1;
13986
13987 return 0;
13988}
13989
13990/* Check whether a software single-step breakpoint is inserted at
13991 PC. */
13992
13993int
13995 CORE_ADDR pc)
13996{
13997 for (breakpoint &bpt : all_breakpoints ())
13998 {
13999 if (bpt.type == bp_single_step
14001 return 1;
14002 }
14003 return 0;
14004}
14005
14006/* Tracepoint-specific operations. */
14007
14008/* Set tracepoint count to NUM. */
14009static void
14011{
14012 tracepoint_count = num;
14014}
14015
14016static void
14017trace_command (const char *arg, int from_tty)
14018{
14022 (locspec.get (), true /* is_tracepoint */);
14023
14025 locspec.get (),
14026 NULL, -1, -1, arg, false, 1 /* parse arg */,
14027 0 /* tempflag */,
14028 bp_tracepoint /* type_wanted */,
14029 0 /* Ignore count */,
14031 ops,
14032 from_tty,
14033 1 /* enabled */,
14034 0 /* internal */, 0);
14035}
14036
14037static void
14038ftrace_command (const char *arg, int from_tty)
14039{
14043 locspec.get (),
14044 NULL, -1, -1, arg, false, 1 /* parse arg */,
14045 0 /* tempflag */,
14046 bp_fast_tracepoint /* type_wanted */,
14047 0 /* Ignore count */,
14050 from_tty,
14051 1 /* enabled */,
14052 0 /* internal */, 0);
14053}
14054
14055/* strace command implementation. Creates a static tracepoint. */
14056
14057static void
14058strace_command (const char *arg, int from_tty)
14059{
14060 const struct breakpoint_ops *ops;
14061 location_spec_up locspec;
14062 enum bptype type;
14063
14064 /* Decide if we are dealing with a static tracepoint marker (`-m'),
14065 or with a normal static tracepoint. */
14066 if (arg && startswith (arg, "-m") && isspace (arg[2]))
14067 {
14069 locspec = new_linespec_location_spec (&arg,
14072 }
14073 else
14074 {
14075 ops = &code_breakpoint_ops;
14076 locspec = string_to_location_spec (&arg, current_language);
14078 }
14079
14081 locspec.get (),
14082 NULL, -1, -1, arg, false, 1 /* parse arg */,
14083 0 /* tempflag */,
14084 type /* type_wanted */,
14085 0 /* Ignore count */,
14087 ops,
14088 from_tty,
14089 1 /* enabled */,
14090 0 /* internal */, 0);
14091}
14092
14093/* Set up a fake reader function that gets command lines from a linked
14094 list that was acquired during tracepoint uploading. */
14095
14096static struct uploaded_tp *this_utp;
14097static int next_cmd;
14098
14099static const char *
14100read_uploaded_action (std::string &buffer)
14101{
14102 char *rslt = nullptr;
14103
14104 if (next_cmd < this_utp->cmd_strings.size ())
14105 {
14106 rslt = this_utp->cmd_strings[next_cmd].get ();
14107 next_cmd++;
14108 }
14109
14110 return rslt;
14111}
14112
14113/* Given information about a tracepoint as recorded on a target (which
14114 can be either a live system or a trace file), attempt to create an
14115 equivalent GDB tracepoint. This is not a reliable process, since
14116 the target does not necessarily have all the information used when
14117 the tracepoint was originally defined. */
14118
14119struct tracepoint *
14121{
14122 const char *addr_str;
14123 char small_buf[100];
14124 struct tracepoint *tp;
14125
14126 if (utp->at_string)
14127 addr_str = utp->at_string.get ();
14128 else
14129 {
14130 /* In the absence of a source location, fall back to raw
14131 address. Since there is no way to confirm that the address
14132 means the same thing as when the trace was started, warn the
14133 user. */
14134 warning (_("Uploaded tracepoint %d has no "
14135 "source location, using raw address"),
14136 utp->number);
14137 xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr));
14138 addr_str = small_buf;
14139 }
14140
14141 /* There's not much we can do with a sequence of bytecodes. */
14142 if (utp->cond && !utp->cond_string)
14143 warning (_("Uploaded tracepoint %d condition "
14144 "has no source form, ignoring it"),
14145 utp->number);
14146
14150 locspec.get (),
14151 utp->cond_string.get (), -1, -1, addr_str,
14152 false /* force_condition */,
14153 0 /* parse cond/thread */,
14154 0 /* tempflag */,
14155 utp->type /* type_wanted */,
14156 0 /* Ignore count */,
14159 0 /* from_tty */,
14160 utp->enabled /* enabled */,
14161 0 /* internal */,
14163 return NULL;
14164
14165 /* Get the tracepoint we just created. */
14167 gdb_assert (tp != NULL);
14168
14169 if (utp->pass > 0)
14170 {
14171 xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass,
14172 tp->number);
14173
14174 trace_pass_command (small_buf, 0);
14175 }
14176
14177 /* If we have uploaded versions of the original commands, set up a
14178 special-purpose "reader" function and call the usual command line
14179 reader, then pass the result to the breakpoint command-setting
14180 function. */
14181 if (!utp->cmd_strings.empty ())
14182 {
14183 counted_command_line cmd_list;
14184
14185 this_utp = utp;
14186 next_cmd = 0;
14187
14188 cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL);
14189
14190 breakpoint_set_commands (tp, std::move (cmd_list));
14191 }
14192 else if (!utp->actions.empty ()
14193 || !utp->step_actions.empty ())
14194 warning (_("Uploaded tracepoint %d actions "
14195 "have no source form, ignoring them"),
14196 utp->number);
14197
14198 /* Copy any status information that might be available. */
14199 tp->hit_count = utp->hit_count;
14201
14202 return tp;
14203}
14204
14205/* Print information on tracepoint number TPNUM_EXP, or all if
14206 omitted. */
14207
14208static void
14209info_tracepoints_command (const char *args, int from_tty)
14210{
14211 struct ui_out *uiout = current_uiout;
14212 int num_printed;
14213
14214 num_printed = breakpoint_1 (args, false, is_tracepoint);
14215
14216 if (num_printed == 0)
14217 {
14218 if (args == NULL || *args == '\0')
14219 uiout->message ("No tracepoints.\n");
14220 else
14221 uiout->message ("No tracepoint matching '%s'.\n", args);
14222 }
14223
14225}
14226
14227/* The 'enable trace' command enables tracepoints.
14228 Not supported by all targets. */
14229static void
14230enable_trace_command (const char *args, int from_tty)
14231{
14232 enable_command (args, from_tty);
14233}
14234
14235/* The 'disable trace' command disables tracepoints.
14236 Not supported by all targets. */
14237static void
14238disable_trace_command (const char *args, int from_tty)
14239{
14240 disable_command (args, from_tty);
14241}
14242
14243/* Remove a tracepoint (or all if no argument). */
14244static void
14245delete_trace_command (const char *arg, int from_tty)
14246{
14247 dont_repeat ();
14248
14249 if (arg == 0)
14250 {
14251 int breaks_to_delete = 0;
14252
14253 /* Delete all breakpoints if no argument.
14254 Do not delete internal or call-dummy breakpoints, these
14255 have to be deleted with an explicit breakpoint number
14256 argument. */
14257 for (breakpoint &tp : all_tracepoints ())
14258 if (is_tracepoint (&tp) && user_breakpoint_p (&tp))
14259 {
14260 breaks_to_delete = 1;
14261 break;
14262 }
14263
14264 /* Ask user only if there are some breakpoints to delete. */
14265 if (!from_tty
14266 || (breaks_to_delete && query (_("Delete all tracepoints? "))))
14267 {
14268 for (breakpoint &b : all_breakpoints_safe ())
14269 if (is_tracepoint (&b) && user_breakpoint_p (&b))
14270 delete_breakpoint (&b);
14271 }
14272 }
14273 else
14275 (arg, [&] (breakpoint *br)
14276 {
14278 });
14279}
14280
14281/* Helper function for trace_pass_command. */
14282
14283static void
14284trace_pass_set_count (struct tracepoint *tp, int count, int from_tty)
14285{
14286 tp->pass_count = count;
14288 if (from_tty)
14289 gdb_printf (_("Setting tracepoint %d's passcount to %d\n"),
14290 tp->number, count);
14291}
14292
14293/* Set passcount for tracepoint.
14294
14295 First command argument is passcount, second is tracepoint number.
14296 If tracepoint number omitted, apply to most recently defined.
14297 Also accepts special argument "all". */
14298
14299static void
14300trace_pass_command (const char *args, int from_tty)
14301{
14302 ULONGEST count;
14303
14304 if (args == 0 || *args == 0)
14305 error (_("passcount command requires an "
14306 "argument (count + optional TP num)"));
14307
14308 count = strtoulst (args, &args, 10); /* Count comes first, then TP num. */
14309
14310 args = skip_spaces (args);
14311 if (*args && strncasecmp (args, "all", 3) == 0)
14312 {
14313 args += 3; /* Skip special argument "all". */
14314 if (*args)
14315 error (_("Junk at end of arguments."));
14316
14317 for (breakpoint &b : all_tracepoints ())
14318 {
14319 tracepoint &t1 = gdb::checked_static_cast<tracepoint &> (b);
14320 trace_pass_set_count (&t1, count, from_tty);
14321 }
14322 }
14323 else if (*args == '\0')
14324 {
14325 tracepoint *t1 = get_tracepoint_by_number (&args, NULL);
14326 if (t1)
14327 trace_pass_set_count (t1, count, from_tty);
14328 }
14329 else
14330 {
14331 number_or_range_parser parser (args);
14332 while (!parser.finished ())
14333 {
14334 tracepoint *t1 = get_tracepoint_by_number (&args, &parser);
14335 if (t1)
14336 trace_pass_set_count (t1, count, from_tty);
14337 }
14338 }
14339}
14340
14341struct tracepoint *
14343{
14344 for (breakpoint &t : all_tracepoints ())
14345 if (t.number == num)
14346 return gdb::checked_static_cast<tracepoint *> (&t);
14347
14348 return NULL;
14349}
14350
14351/* Find the tracepoint with the given target-side number (which may be
14352 different from the tracepoint number after disconnecting and
14353 reconnecting). */
14354
14355struct tracepoint *
14357{
14358 for (breakpoint &b : all_tracepoints ())
14359 {
14360 tracepoint &t = gdb::checked_static_cast<tracepoint &> (b);
14361
14362 if (t.number_on_target == num)
14363 return &t;
14364 }
14365
14366 return NULL;
14367}
14368
14369/* Utility: parse a tracepoint number and look it up in the list.
14370 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
14371 If the argument is missing, the most recent tracepoint
14372 (tracepoint_count) is returned. */
14373
14374struct tracepoint *
14376 number_or_range_parser *parser)
14377{
14378 int tpnum;
14379 const char *instring = arg == NULL ? NULL : *arg;
14380
14381 if (parser != NULL)
14382 {
14383 gdb_assert (!parser->finished ());
14384 tpnum = parser->get_number ();
14385 }
14386 else if (arg == NULL || *arg == NULL || ! **arg)
14387 tpnum = tracepoint_count;
14388 else
14389 tpnum = get_number (arg);
14390
14391 if (tpnum <= 0)
14392 {
14393 if (instring && *instring)
14394 gdb_printf (_("bad tracepoint number at or near '%s'\n"),
14395 instring);
14396 else
14397 gdb_printf (_("No previous tracepoint\n"));
14398 return NULL;
14399 }
14400
14401 for (breakpoint &t : all_tracepoints ())
14402 if (t.number == tpnum)
14403 return gdb::checked_static_cast<tracepoint *> (&t);
14404
14405 gdb_printf ("No tracepoint number %d.\n", tpnum);
14406 return NULL;
14407}
14408
14409void
14411{
14412 if (thread != -1)
14413 {
14415 gdb_printf (fp, " thread %s", print_full_thread_id (thr));
14416 }
14417
14418 if (task != -1)
14419 gdb_printf (fp, " task %d", task);
14420
14421 gdb_printf (fp, "\n");
14422}
14423
14424/* Save information on user settable breakpoints (watchpoints, etc) to
14425 a new script file named FILENAME. If FILTER is non-NULL, call it
14426 on each breakpoint and only include the ones for which it returns
14427 true. */
14428
14429static void
14430save_breakpoints (const char *filename, int from_tty,
14431 bool (*filter) (const struct breakpoint *))
14432{
14433 bool any = false;
14434 int extra_trace_bits = 0;
14435
14436 if (filename == 0 || *filename == 0)
14437 error (_("Argument required (file name in which to save)"));
14438
14439 /* See if we have anything to save. */
14440 for (breakpoint &tp : all_breakpoints ())
14441 {
14442 /* Skip internal and momentary breakpoints. */
14443 if (!user_breakpoint_p (&tp))
14444 continue;
14445
14446 /* If we have a filter, only save the breakpoints it accepts. */
14447 if (filter && !filter (&tp))
14448 continue;
14449
14450 any = true;
14451
14452 if (is_tracepoint (&tp))
14453 {
14454 extra_trace_bits = 1;
14455
14456 /* We can stop searching. */
14457 break;
14458 }
14459 }
14460
14461 if (!any)
14462 {
14463 warning (_("Nothing to save."));
14464 return;
14465 }
14466
14467 gdb::unique_xmalloc_ptr<char> expanded_filename (tilde_expand (filename));
14468
14469 stdio_file fp;
14470
14471 if (!fp.open (expanded_filename.get (), "w"))
14472 error (_("Unable to open file '%s' for saving (%s)"),
14473 expanded_filename.get (), safe_strerror (errno));
14474
14475 if (extra_trace_bits)
14477
14478 for (breakpoint &tp : all_breakpoints ())
14479 {
14480 /* Skip internal and momentary breakpoints. */
14481 if (!user_breakpoint_p (&tp))
14482 continue;
14483
14484 /* If we have a filter, only save the breakpoints it accepts. */
14485 if (filter && !filter (&tp))
14486 continue;
14487
14488 tp.print_recreate (&fp);
14489
14490 /* Note, we can't rely on tp->number for anything, as we can't
14491 assume the recreated breakpoint numbers will match. Use $bpnum
14492 instead. */
14493
14494 if (tp.cond_string)
14495 fp.printf (" condition $bpnum %s\n", tp.cond_string.get ());
14496
14497 if (tp.ignore_count)
14498 fp.printf (" ignore $bpnum %d\n", tp.ignore_count);
14499
14500 if (tp.type != bp_dprintf && tp.commands)
14501 {
14502 fp.puts (" commands\n");
14503
14505 print_command_lines (current_uiout, tp.commands.get (), 2);
14506
14507 fp.puts (" end\n");
14508 }
14509
14510 if (tp.enable_state == bp_disabled)
14511 fp.puts ("disable $bpnum\n");
14512
14513 /* If this is a multi-location breakpoint, check if the locations
14514 should be individually disabled. Watchpoint locations are
14515 special, and not user visible. */
14516 if (!is_watchpoint (&tp) && tp.has_multiple_locations ())
14517 {
14518 int n = 1;
14519
14520 for (bp_location &loc : tp.locations ())
14521 {
14522 if (!loc.enabled)
14523 fp.printf ("disable $bpnum.%d\n", n);
14524
14525 n++;
14526 }
14527 }
14528 }
14529
14530 if (extra_trace_bits && !default_collect.empty ())
14531 fp.printf ("set default-collect %s\n", default_collect.c_str ());
14532
14533 if (from_tty)
14534 gdb_printf (_("Saved to file '%s'.\n"), expanded_filename.get ());
14535}
14536
14537/* The `save breakpoints' command. */
14538
14539static void
14540save_breakpoints_command (const char *args, int from_tty)
14541{
14542 save_breakpoints (args, from_tty, NULL);
14543}
14544
14545/* The `save tracepoints' command. */
14546
14547static void
14548save_tracepoints_command (const char *args, int from_tty)
14549{
14550 save_breakpoints (args, from_tty, is_tracepoint);
14551}
14552
14553
14554/* This help string is used to consolidate all the help string for specifying
14555 locations used by several commands. */
14556
14557#define LOCATION_SPEC_HELP_STRING \
14558"Linespecs are colon-separated lists of location parameters, such as\n\
14559source filename, function name, label name, and line number.\n\
14560Example: To specify the start of a label named \"the_top\" in the\n\
14561function \"fact\" in the file \"factorial.c\", use\n\
14562\"factorial.c:fact:the_top\".\n\
14563\n\
14564Address locations begin with \"*\" and specify an exact address in the\n\
14565program. Example: To specify the fourth byte past the start function\n\
14566\"main\", use \"*main + 4\".\n\
14567\n\
14568Explicit locations are similar to linespecs but use an option/argument\n\
14569syntax to specify location parameters.\n\
14570Example: To specify the start of the label named \"the_top\" in the\n\
14571function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
14572-function fact -label the_top\".\n\
14573\n\
14574By default, a specified function is matched against the program's\n\
14575functions in all scopes. For C++, this means in all namespaces and\n\
14576classes. For Ada, this means in all packages. E.g., in C++,\n\
14577\"func()\" matches \"A::func()\", \"A::B::func()\", etc. The\n\
14578\"-qualified\" flag overrides this behavior, making GDB interpret the\n\
14579specified name as a complete fully-qualified name instead."
14580
14581/* This help string is used for the break, hbreak, tbreak and thbreak
14582 commands. It is defined as a macro to prevent duplication.
14583 COMMAND should be a string constant containing the name of the
14584 command. */
14585
14586#define BREAK_ARGS_HELP(command) \
14587command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM]\n\
14588\t[-force-condition] [if CONDITION]\n\
14589PROBE_MODIFIER shall be present if the command is to be placed in a\n\
14590probe point. Accepted values are `-probe' (for a generic, automatically\n\
14591guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
14592`-probe-dtrace' (for a DTrace probe).\n\
14593LOCATION may be a linespec, address, or explicit location as described\n\
14594below.\n\
14595\n\
14596With no LOCATION, uses current execution address of the selected\n\
14597stack frame. This is useful for breaking on return to a stack frame.\n\
14598\n\
14599THREADNUM is the number from \"info threads\".\n\
14600CONDITION is a boolean expression.\n\
14601\n\
14602With the \"-force-condition\" flag, the condition is defined even when\n\
14603it is invalid for all current locations.\n\
14604\n" LOCATION_SPEC_HELP_STRING "\n\n\
14605Multiple breakpoints at one place are permitted, and useful if their\n\
14606conditions are different.\n\
14607\n\
14608Do \"help breakpoints\" for info on other commands dealing with breakpoints."
14609
14610/* List of subcommands for "catch". */
14612
14613/* List of subcommands for "tcatch". */
14615
14616void
14617add_catch_command (const char *name, const char *docstring,
14620 void *user_data_catch,
14621 void *user_data_tcatch)
14622{
14623 struct cmd_list_element *command;
14624
14625 command = add_cmd (name, class_breakpoint, docstring,
14626 &catch_cmdlist);
14627 command->func = func;
14628 command->set_context (user_data_catch);
14629 set_cmd_completer (command, completer);
14630
14631 command = add_cmd (name, class_breakpoint, docstring,
14633 command->func = func;
14634 command->set_context (user_data_tcatch);
14635 set_cmd_completer (command, completer);
14636}
14637
14638/* False if any of the breakpoint's locations could be a location where
14639 functions have been inlined, true otherwise. */
14640
14641static bool
14643{
14644 /* The shared library event breakpoint is set on the address of a
14645 non-inline function. */
14646 return (b->type == bp_shlib_event);
14647}
14648
14649/* Nonzero if the specified PC cannot be a location where functions
14650 have been inlined. */
14651
14652int
14653pc_at_non_inline_function (const address_space *aspace, CORE_ADDR pc,
14654 const target_waitstatus &ws)
14655{
14656 for (breakpoint &b : all_breakpoints ())
14657 {
14658 if (!is_non_inline_function (&b))
14659 continue;
14660
14661 for (bp_location &bl : b.locations ())
14662 {
14663 if (!bl.shlib_disabled
14664 && bpstat_check_location (&bl, aspace, pc, ws))
14665 return 1;
14666 }
14667 }
14668
14669 return 0;
14670}
14671
14672/* Remove any references to OBJFILE which is going to be freed. */
14673
14674void
14676{
14677 for (bp_location *loc : all_bp_locations ())
14678 if (loc->symtab != NULL && loc->symtab->compunit ()->objfile () == objfile)
14679 loc->symtab = NULL;
14680}
14681
14682/* Chain containing all defined "enable breakpoint" subcommands. */
14683
14684static struct cmd_list_element *enablebreaklist = NULL;
14685
14686/* See breakpoint.h. */
14687
14689
14691void
14693{
14694 struct cmd_list_element *c;
14695
14697 "breakpoint");
14699 "breakpoint");
14701 "breakpoint");
14702
14703 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
14704 before a breakpoint is set. */
14705 breakpoint_count = 0;
14706
14707 tracepoint_count = 0;
14708
14709 add_com ("ignore", class_breakpoint, ignore_command, _("\
14710Set ignore-count of breakpoint number N to COUNT.\n\
14711Usage is `ignore N COUNT'."));
14712
14714 commands_command, _("\
14715Set commands to be executed when the given breakpoints are hit.\n\
14716Give a space-separated breakpoint list as argument after \"commands\".\n\
14717A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
14718(e.g. `5-7').\n\
14719With no argument, the targeted breakpoint is the last one set.\n\
14720The commands themselves follow starting on the next line.\n\
14721Type a line containing \"end\" to indicate the end of them.\n\
14722Give \"silent\" as the first line to make the breakpoint silent;\n\
14723then no output is printed when it is hit, except what the commands print."));
14724
14725 const auto cc_opts = make_condition_command_options_def_group (nullptr);
14726 static std::string condition_command_help
14728Specify breakpoint number N to break only if COND is true.\n\
14729Usage is `condition [OPTION] N COND', where N is an integer and COND\n\
14730is an expression to be evaluated whenever breakpoint N is reached.\n\
14731\n\
14732Options:\n\
14733%OPTIONS%"), cc_opts);
14734
14735 c = add_com ("condition", class_breakpoint, condition_command,
14736 condition_command_help.c_str ());
14738
14739 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
14740Set a temporary breakpoint.\n\
14741Like \"break\" except the breakpoint is only temporary,\n\
14742so it will be deleted when hit. Equivalent to \"break\" followed\n\
14743by using \"enable delete\" on the breakpoint number.\n\
14744\n"
14745BREAK_ARGS_HELP ("tbreak")));
14747
14748 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
14749Set a hardware assisted breakpoint.\n\
14750Like \"break\" except the breakpoint requires hardware support,\n\
14751some target hardware may not have this support.\n\
14752\n"
14753BREAK_ARGS_HELP ("hbreak")));
14755
14756 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
14757Set a temporary hardware assisted breakpoint.\n\
14758Like \"hbreak\" except the breakpoint is only temporary,\n\
14759so it will be deleted when hit.\n\
14760\n"
14761BREAK_ARGS_HELP ("thbreak")));
14763
14764 cmd_list_element *enable_cmd
14766Enable all or some breakpoints.\n\
14767Usage: enable [BREAKPOINTNUM]...\n\
14768Give breakpoint numbers (separated by spaces) as arguments.\n\
14769With no subcommand, breakpoints are enabled until you command otherwise.\n\
14770This is used to cancel the effect of the \"disable\" command.\n\
14771With a subcommand you can enable temporarily."),
14772 &enablelist, 1, &cmdlist);
14773
14774 add_com_alias ("en", enable_cmd, class_breakpoint, 1);
14775
14776 add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
14777Enable all or some breakpoints.\n\
14778Usage: enable breakpoints [BREAKPOINTNUM]...\n\
14779Give breakpoint numbers (separated by spaces) as arguments.\n\
14780This is used to cancel the effect of the \"disable\" command.\n\
14781May be abbreviated to simply \"enable\"."),
14783
14784 add_cmd ("once", no_class, enable_once_command, _("\
14785Enable some breakpoints for one hit.\n\
14786Usage: enable breakpoints once BREAKPOINTNUM...\n\
14787If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
14789
14790 add_cmd ("delete", no_class, enable_delete_command, _("\
14791Enable some breakpoints and delete when hit.\n\
14792Usage: enable breakpoints delete BREAKPOINTNUM...\n\
14793If a breakpoint is hit while enabled in this fashion, it is deleted."),
14795
14796 add_cmd ("count", no_class, enable_count_command, _("\
14797Enable some breakpoints for COUNT hits.\n\
14798Usage: enable breakpoints count COUNT BREAKPOINTNUM...\n\
14799If a breakpoint is hit while enabled in this fashion,\n\
14800the count is decremented; when it reaches zero, the breakpoint is disabled."),
14802
14803 add_cmd ("delete", no_class, enable_delete_command, _("\
14804Enable some breakpoints and delete when hit.\n\
14805Usage: enable delete BREAKPOINTNUM...\n\
14806If a breakpoint is hit while enabled in this fashion, it is deleted."),
14807 &enablelist);
14808
14809 add_cmd ("once", no_class, enable_once_command, _("\
14810Enable some breakpoints for one hit.\n\
14811Usage: enable once BREAKPOINTNUM...\n\
14812If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
14813 &enablelist);
14814
14815 add_cmd ("count", no_class, enable_count_command, _("\
14816Enable some breakpoints for COUNT hits.\n\
14817Usage: enable count COUNT BREAKPOINTNUM...\n\
14818If a breakpoint is hit while enabled in this fashion,\n\
14819the count is decremented; when it reaches zero, the breakpoint is disabled."),
14820 &enablelist);
14821
14822 cmd_list_element *disable_cmd
14824Disable all or some breakpoints.\n\
14825Usage: disable [BREAKPOINTNUM]...\n\
14826Arguments are breakpoint numbers with spaces in between.\n\
14827To disable all breakpoints, give no argument.\n\
14828A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
14829 &disablelist, 1, &cmdlist);
14830 add_com_alias ("dis", disable_cmd, class_breakpoint, 1);
14831 add_com_alias ("disa", disable_cmd, class_breakpoint, 1);
14832
14833 add_cmd ("breakpoints", class_breakpoint, disable_command, _("\
14834Disable all or some breakpoints.\n\
14835Usage: disable breakpoints [BREAKPOINTNUM]...\n\
14836Arguments are breakpoint numbers with spaces in between.\n\
14837To disable all breakpoints, give no argument.\n\
14838A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
14839This command may be abbreviated \"disable\"."),
14840 &disablelist);
14841
14844Delete all or some breakpoints.\n\
14845Usage: delete [BREAKPOINTNUM]...\n\
14846Arguments are breakpoint numbers with spaces in between.\n\
14847To delete all breakpoints, give no argument.\n\
14848\n\
14849Also a prefix command for deletion of other GDB objects."),
14850 &deletelist, 1, &cmdlist);
14853
14854 add_cmd ("breakpoints", class_breakpoint, delete_command, _("\
14855Delete all or some breakpoints or auto-display expressions.\n\
14856Usage: delete breakpoints [BREAKPOINTNUM]...\n\
14857Arguments are breakpoint numbers with spaces in between.\n\
14858To delete all breakpoints, give no argument.\n\
14859This command may be abbreviated \"delete\"."),
14860 &deletelist);
14861
14862 cmd_list_element *clear_cmd
14863 = add_com ("clear", class_breakpoint, clear_command, _("\
14864Clear breakpoint at specified location.\n\
14865Argument may be a linespec, explicit, or address location as described below.\n\
14866\n\
14867With no argument, clears all breakpoints in the line that the selected frame\n\
14868is executing in.\n"
14869"\n" LOCATION_SPEC_HELP_STRING "\n\n\
14870See also the \"delete\" command which clears breakpoints by number."));
14871 add_com_alias ("cl", clear_cmd, class_breakpoint, 1);
14872
14873 cmd_list_element *break_cmd
14874 = add_com ("break", class_breakpoint, break_command, _("\
14875Set breakpoint at specified location.\n"
14876BREAK_ARGS_HELP ("break")));
14878
14879 add_com_alias ("b", break_cmd, class_run, 1);
14880 add_com_alias ("br", break_cmd, class_run, 1);
14881 add_com_alias ("bre", break_cmd, class_run, 1);
14882 add_com_alias ("brea", break_cmd, class_run, 1);
14883
14884 cmd_list_element *info_breakpoints_cmd
14885 = add_info ("breakpoints", info_breakpoints_command, _("\
14886Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
14887The \"Type\" column indicates one of:\n\
14888\tbreakpoint - normal breakpoint\n\
14889\twatchpoint - watchpoint\n\
14890The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
14891the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
14892breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
14893address and file/line number respectively.\n\
14894\n\
14895Convenience variable \"$_\" and default examine address for \"x\"\n\
14896are set to the address of the last breakpoint listed unless the command\n\
14897is prefixed with \"server \".\n\n\
14898Convenience variable \"$bpnum\" contains the number of the last\n\
14899breakpoint set."));
14900
14901 add_info_alias ("b", info_breakpoints_cmd, 1);
14902
14904Status of all breakpoints, or breakpoint number NUMBER.\n\
14905The \"Type\" column indicates one of:\n\
14906\tbreakpoint - normal breakpoint\n\
14907\twatchpoint - watchpoint\n\
14908\tlongjmp - internal breakpoint used to step through longjmp()\n\
14909\tlongjmp resume - internal breakpoint at the target of longjmp()\n\
14910\tuntil - internal breakpoint used by the \"until\" command\n\
14911\tfinish - internal breakpoint used by the \"finish\" command\n\
14912The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
14913the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
14914breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
14915address and file/line number respectively.\n\
14916\n\
14917Convenience variable \"$_\" and default examine address for \"x\"\n\
14918are set to the address of the last breakpoint listed unless the command\n\
14919is prefixed with \"server \".\n\n\
14920Convenience variable \"$bpnum\" contains the number of the last\n\
14921breakpoint set."),
14923
14925Set catchpoints to catch events."),
14927 0/*allow-unknown*/, &cmdlist);
14928
14929 add_basic_prefix_cmd ("tcatch", class_breakpoint, _("\
14930Set temporary catchpoints to catch events."),
14932 0/*allow-unknown*/, &cmdlist);
14933
14934 const auto opts = make_watch_options_def_group (nullptr);
14935
14936 static const std::string watch_help = gdb::option::build_help (_("\
14937Set a watchpoint for EXPRESSION.\n\
14938Usage: watch [-location] EXPRESSION\n\
14939\n\
14940Options:\n\
14941%OPTIONS%\n\
14942\n\
14943A watchpoint stops execution of your program whenever the value of\n\
14944an expression changes."), opts);
14945 c = add_com ("watch", class_breakpoint, watch_command,
14946 watch_help.c_str ());
14948
14949 static const std::string rwatch_help = gdb::option::build_help (_("\
14950Set a read watchpoint for EXPRESSION.\n\
14951Usage: rwatch [-location] EXPRESSION\n\
14952\n\
14953Options:\n\
14954%OPTIONS%\n\
14955\n\
14956A read watchpoint stops execution of your program whenever the value of\n\
14957an expression is read."), opts);
14958 c = add_com ("rwatch", class_breakpoint, rwatch_command,
14959 rwatch_help.c_str ());
14961
14962 static const std::string awatch_help = gdb::option::build_help (_("\
14963Set an access watchpoint for EXPRESSION.\n\
14964Usage: awatch [-location] EXPRESSION\n\
14965\n\
14966Options:\n\
14967%OPTIONS%\n\
14968\n\
14969An access watchpoint stops execution of your program whenever the value\n\
14970of an expression is either read or written."), opts);
14971 c = add_com ("awatch", class_breakpoint, awatch_command,
14972 awatch_help.c_str ());
14974
14975 add_info ("watchpoints", info_watchpoints_command, _("\
14976Status of specified watchpoints (all watchpoints if no argument)."));
14977
14978 /* XXX: cagney/2005-02-23: This should be a boolean, and should
14979 respond to changes - contrary to the description. */
14980 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
14982Set debugger's willingness to use watchpoint hardware."), _("\
14983Show debugger's willingness to use watchpoint hardware."), _("\
14984If zero, gdb will not use hardware for new watchpoints, even if\n\
14985such is available. (However, any hardware watchpoints that were\n\
14986created before setting this to nonzero, will continue to use watchpoint\n\
14987hardware.)"),
14988 NULL,
14990 &setlist, &showlist);
14991
14993
14994 /* Tracepoint manipulation commands. */
14995
14996 cmd_list_element *trace_cmd
14997 = add_com ("trace", class_breakpoint, trace_command, _("\
14998Set a tracepoint at specified location.\n\
14999\n"
15000BREAK_ARGS_HELP ("trace") "\n\
15001Do \"help tracepoints\" for info on other tracepoint commands."));
15003
15004 add_com_alias ("tp", trace_cmd, class_breakpoint, 0);
15005 add_com_alias ("tr", trace_cmd, class_breakpoint, 1);
15006 add_com_alias ("tra", trace_cmd, class_breakpoint, 1);
15007 add_com_alias ("trac", trace_cmd, class_breakpoint, 1);
15008
15009 c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\
15010Set a fast tracepoint at specified location.\n\
15011\n"
15012BREAK_ARGS_HELP ("ftrace") "\n\
15013Do \"help tracepoints\" for info on other tracepoint commands."));
15015
15016 c = add_com ("strace", class_breakpoint, strace_command, _("\
15017Set a static tracepoint at location or marker.\n\
15018\n\
15019strace [LOCATION] [if CONDITION]\n\
15020LOCATION may be a linespec, explicit, or address location (described below) \n\
15021or -m MARKER_ID.\n\n\
15022If a marker id is specified, probe the marker with that name. With\n\
15023no LOCATION, uses current execution address of the selected stack frame.\n\
15024Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
15025This collects arbitrary user data passed in the probe point call to the\n\
15026tracing library. You can inspect it when analyzing the trace buffer,\n\
15027by printing the $_sdata variable like any other convenience variable.\n\
15028\n\
15029CONDITION is a boolean expression.\n\
15031Multiple tracepoints at one place are permitted, and useful if their\n\
15032conditions are different.\n\
15033\n\
15034Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
15035Do \"help tracepoints\" for info on other tracepoint commands."));
15037
15038 cmd_list_element *info_tracepoints_cmd
15039 = add_info ("tracepoints", info_tracepoints_command, _("\
15040Status of specified tracepoints (all tracepoints if no argument).\n\
15041Convenience variable \"$tpnum\" contains the number of the\n\
15042last tracepoint set."));
15043
15044 add_info_alias ("tp", info_tracepoints_cmd, 1);
15045
15046 cmd_list_element *delete_tracepoints_cmd
15047 = add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
15048Delete specified tracepoints.\n\
15049Arguments are tracepoint numbers, separated by spaces.\n\
15050No argument means delete all tracepoints."),
15051 &deletelist);
15052 add_alias_cmd ("tr", delete_tracepoints_cmd, class_trace, 1, &deletelist);
15053
15054 c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
15055Disable specified tracepoints.\n\
15056Arguments are tracepoint numbers, separated by spaces.\n\
15057No argument means disable all tracepoints."),
15058 &disablelist);
15059 deprecate_cmd (c, "disable");
15060
15061 c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\
15062Enable specified tracepoints.\n\
15063Arguments are tracepoint numbers, separated by spaces.\n\
15064No argument means enable all tracepoints."),
15065 &enablelist);
15066 deprecate_cmd (c, "enable");
15067
15068 add_com ("passcount", class_trace, trace_pass_command, _("\
15069Set the passcount for a tracepoint.\n\
15070The trace will end when the tracepoint has been passed 'count' times.\n\
15071Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
15072if TPNUM is omitted, passcount refers to the last tracepoint defined."));
15073
15075 _("Save breakpoint definitions as a script."),
15076 &save_cmdlist,
15077 0/*allow-unknown*/, &cmdlist);
15078
15079 c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\
15080Save current breakpoint definitions as a script.\n\
15081This includes all types of breakpoints (breakpoints, watchpoints,\n\
15082catchpoints, tracepoints). Use the 'source' command in another debug\n\
15083session to restore them."),
15084 &save_cmdlist);
15086
15087 cmd_list_element *save_tracepoints_cmd
15088 = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\
15089Save current tracepoint definitions as a script.\n\
15090Use the 'source' command in another debug session to restore them."),
15091 &save_cmdlist);
15092 set_cmd_completer (save_tracepoints_cmd, filename_completer);
15093
15094 c = add_com_alias ("save-tracepoints", save_tracepoints_cmd, class_trace, 0);
15095 deprecate_cmd (c, "save tracepoints");
15096
15098 _("\
15099Breakpoint specific settings.\n\
15100Configure various breakpoint-specific variables such as\n\
15101pending breakpoint behavior."),
15102 _("\
15103Breakpoint specific settings.\n\
15104Configure various breakpoint-specific variables such as\n\
15105pending breakpoint behavior."),
15107 &setlist, &showlist);
15108
15111Set debugger's behavior regarding pending breakpoints."), _("\
15112Show debugger's behavior regarding pending breakpoints."), _("\
15113If on, an unrecognized breakpoint location will cause gdb to create a\n\
15114pending breakpoint. If off, an unrecognized breakpoint location results in\n\
15115an error. If auto, an unrecognized breakpoint location results in a\n\
15116user-query to see if a pending breakpoint should be created."),
15117 NULL,
15121
15123
15126Set automatic usage of hardware breakpoints."), _("\
15127Show automatic usage of hardware breakpoints."), _("\
15128If set, the debugger will automatically use hardware breakpoints for\n\
15129breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
15130a warning will be emitted for such breakpoints."),
15131 NULL,
15135
15136 add_setshow_boolean_cmd ("always-inserted", class_support,
15138Set mode for inserting breakpoints."), _("\
15139Show mode for inserting breakpoints."), _("\
15140When this mode is on, breakpoints are inserted immediately as soon as\n\
15141they're created, kept inserted even when execution stops, and removed\n\
15142only when the user deletes them. When this mode is off (the default),\n\
15143breakpoints are inserted only when execution continues, and removed\n\
15144when execution stops."),
15145 NULL,
15149
15151 &debug_breakpoint, _("\
15152Set breakpoint location debugging."), _("\
15153Show breakpoint location debugging."), _("\
15154When on, breakpoint location specific debugging is enabled."),
15155 NULL,
15158
15159 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint,
15162Set mode of breakpoint condition evaluation."), _("\
15163Show mode of breakpoint condition evaluation."), _("\
15164When this is set to \"host\", breakpoint conditions will be\n\
15165evaluated on the host's side by GDB. When it is set to \"target\",\n\
15166breakpoint conditions will be downloaded to the target (if the target\n\
15167supports such feature) and conditions will be evaluated on the target's side.\n\
15168If this is set to \"auto\" (default), this will be automatically set to\n\
15169\"target\" if it supports condition evaluation, otherwise it will\n\
15170be set to \"host\"."),
15175
15176 add_com ("break-range", class_breakpoint, break_range_command, _("\
15177Set a breakpoint for an address range.\n\
15178break-range START-LOCATION, END-LOCATION\n\
15179where START-LOCATION and END-LOCATION can be one of the following:\n\
15180 LINENUM, for that line in the current file,\n\
15181 FILE:LINENUM, for that line in that file,\n\
15182 +OFFSET, for that number of lines after the current line\n\
15183 or the start of the range\n\
15184 FUNCTION, for the first line in that function,\n\
15185 FILE:FUNCTION, to distinguish among like-named static functions.\n\
15186 *ADDRESS, for the instruction at that address.\n\
15187\n\
15188The breakpoint will stop execution of the inferior whenever it executes\n\
15189an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
15190range (including START-LOCATION and END-LOCATION)."));
15191
15192 c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\
15193Set a dynamic printf at specified location.\n\
15194dprintf location,format string,arg1,arg2,...\n\
15195location may be a linespec, explicit, or address location.\n"
15198
15199 add_setshow_enum_cmd ("dprintf-style", class_support,
15201Set the style of usage for dynamic printf."), _("\
15202Show the style of usage for dynamic printf."), _("\
15203This setting chooses how GDB will do a dynamic printf.\n\
15204If the value is \"gdb\", then the printing is done by GDB to its own\n\
15205console, as with the \"printf\" command.\n\
15206If the value is \"call\", the print is done by calling a function in your\n\
15207program; by default printf(), but you can choose a different function or\n\
15208output stream by setting dprintf-function and dprintf-channel."),
15210 &setlist, &showlist);
15211
15212 add_setshow_string_cmd ("dprintf-function", class_support,
15213 &dprintf_function, _("\
15214Set the function to use for dynamic printf."), _("\
15215Show the function to use for dynamic printf."), NULL,
15217 &setlist, &showlist);
15218
15219 add_setshow_string_cmd ("dprintf-channel", class_support,
15220 &dprintf_channel, _("\
15221Set the channel to use for dynamic printf."), _("\
15222Show the channel to use for dynamic printf."), NULL,
15224 &setlist, &showlist);
15225
15226 add_setshow_boolean_cmd ("disconnected-dprintf", no_class,
15228Set whether dprintf continues after GDB disconnects."), _("\
15229Show whether dprintf continues after GDB disconnects."), _("\
15230Use this to let dprintf commands continue to hit and produce output\n\
15231even if GDB disconnects or detaches from the target."),
15232 NULL,
15233 NULL,
15234 &setlist, &showlist);
15235
15236 add_com ("agent-printf", class_vars, agent_printf_command, _("\
15237Target agent only formatted printing, like the C \"printf\" function.\n\
15238Usage: agent-printf \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\
15239This supports most C printf format specifications, like %s, %d, etc.\n\
15240This is useful for formatted output in user-defined commands."));
15241
15243
15245 "breakpoint");
15247 "breakpoint");
15249 "breakpoint");
15250}
const char *const name
void xfree(void *)
bool is_ada_exception_catchpoint(breakpoint *bp)
Definition ada-lang.c:12502
int ada_get_task_number(thread_info *thread)
Definition ada-tasks.c:334
int valid_task_id(int)
Definition ada-tasks.c:370
void * xcalloc(size_t number, size_t size)
Definition alloc.c:85
void annotate_breakpoint(int num)
Definition annotate.c:75
void annotate_record(void)
Definition annotate.c:186
void annotate_watchpoint(int num)
Definition annotate.c:89
void annotate_field(int num)
Definition annotate.c:172
void annotate_breakpoints_table(void)
Definition annotate.c:179
void annotate_breakpoints_headers(void)
Definition annotate.c:165
void annotate_breakpoints_table_end(void)
Definition annotate.c:193
struct gdbarch * get_current_arch(void)
Definition arch-utils.c:846
struct gdbarch * target_gdbarch(void)
agent_expr_up gen_eval_for_expr(CORE_ADDR scope, struct expression *expr)
Definition ax-gdb.c:2393
agent_expr_up gen_printf(CORE_ADDR scope, struct gdbarch *gdbarch, CORE_ADDR function, LONGEST channel, const char *format, int fmtlen, int nargs, struct expression **exprs)
Definition ax-gdb.c:2436
std::unique_ptr< agent_expr > agent_expr_up
Definition ax.h:147
constexpr char c2[]
Definition 2.cc:24
const struct blockvector * blockvector_for_pc_sect(CORE_ADDR pc, struct obj_section *section, const struct block **pblock, struct compunit_symtab *cust)
Definition block.c:178
const struct block * block_for_pc(CORE_ADDR pc)
Definition block.c:276
bool find_pc_partial_function(CORE_ADDR pc, const char **name, CORE_ADDR *address, CORE_ADDR *endaddr, const struct block **block)
Definition blockframe.c:373
struct symbol * get_frame_function(frame_info_ptr frame)
Definition blockframe.c:118
frame_info_ptr block_innermost_frame(const struct block *block)
Definition blockframe.c:463
bool is_exception_catchpoint(breakpoint *bp)
static void disable_breakpoints_in_unloaded_shlib(program_space *pspace, so_list *solib)
void enable_breakpoint(struct breakpoint *bpt)
static const char * bp_location_condition_evaluator(const struct bp_location *bl)
static std::vector< symtab_and_line > bkpt_probe_decode_location_spec(struct breakpoint *b, location_spec *locspec, struct program_space *search_pspace)
static const char * translate_condition_evaluation_mode(const char *mode)
Definition breakpoint.c:656
static gdb::option::option_def_group make_condition_command_options_def_group(condition_command_opts *cc_opts)
static bool breakpoint_location_spec_empty_p(const struct breakpoint *b)
void breakpoint_program_space_exit(struct program_space *pspace)
static struct cmd_list_element * tcatch_cmdlist
void breakpoint_re_set(void)
static bool breakpoint_address_match_range(const address_space *aspace1, CORE_ADDR addr1, int len1, const address_space *aspace2, CORE_ADDR addr2)
static bool print_one_breakpoint_location(struct breakpoint *b, struct bp_location *loc, int loc_number, const bp_location **last_loc, int allflag, bool raw_loc)
static void break_command_1(const char *arg, int flag, int from_tty)
#define BP_TEMPFLAG
static void iterate_over_related_breakpoints(struct breakpoint *b, gdb::function_view< void(breakpoint *)> function)
void delete_breakpoint(struct breakpoint *bpt)
static void awatch_command(const char *arg, int from_tty)
static const char * dprintf_style
Definition breakpoint.c:470
static std::unique_ptr< code_breakpoint > new_breakpoint_from_type(struct gdbarch *gdbarch, bptype type, Arg &&... args)
const std::vector< bp_location * > & all_bp_locations()
Definition breakpoint.c:733
breakpoint_up set_momentary_breakpoint_at_pc(struct gdbarch *gdbarch, CORE_ADDR pc, enum bptype type)
static void hbreak_command(const char *arg, int from_tty)
static void create_longjmp_master_breakpoint(void)
static void one_breakpoint_xfer_memory(gdb_byte *readbuf, gdb_byte *writebuf, const gdb_byte *writebuf_org, ULONGEST memaddr, LONGEST len, struct bp_target_info *target_info, struct gdbarch *gdbarch)
static struct uploaded_tp * this_utp
static agent_expr_up parse_cond_to_aexpr(CORE_ADDR scope, struct expression *cond)
static void bp_locations_target_extensions_update(void)
void check_longjmp_breakpoint_for_call_dummy(struct thread_info *tp)
static const gdb::option::option_def condition_command_option_defs[]
static void info_tracepoints_command(const char *args, int from_tty)
static void info_watchpoints_command(const char *args, int from_tty)
static bool unduplicated_should_be_inserted(struct bp_location *bl)
void remove_solib_event_breakpoints_at_next_stop(void)
static void watchpoint_value_print(struct value *val, struct ui_file *stream)
static bool breakpoint_proceeded
Definition breakpoint.c:502
void breakpoint_retire_moribund(void)
void enable_disable_bp_location(bp_location *loc, bool enable)
void breakpoint_init_inferior(enum inf_context context)
static int can_use_hardware_watchpoint(const std::vector< value_ref_ptr > &vals)
static const char * remove_bp_reason_str(remove_bp_reason reason)
Definition breakpoint.c:230
static CORE_ADDR bp_locations_shadow_len_after_address_max
Definition breakpoint.c:811
void breakpoint_set_thread(struct breakpoint *b, int thread)
static void show_pending_break_support(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition breakpoint.c:537
static void save_tracepoints_command(const char *args, int from_tty)
static void show_condition_evaluation_mode(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
struct breakpoint * create_thread_event_breakpoint(struct gdbarch *gdbarch, CORE_ADDR address)
static const char condition_evaluation_host[]
Definition breakpoint.c:634
static bool locations_are_equal(const bp_location_list &a, const bp_location_range &b)
void remove_jit_event_breakpoints(void)
static void strace_command(const char *arg, int from_tty)
int software_breakpoint_inserted_here_p(const address_space *aspace, CORE_ADDR pc)
void breakpoint_set_inferior(struct breakpoint *b, int inferior)
struct breakpoint * get_breakpoint(int num)
Definition breakpoint.c:887
static void mark_breakpoint_modified(struct breakpoint *b)
Definition breakpoint.c:915
static const char * bptype_string(enum bptype type)
void until_break_command(const char *arg, int from_tty, int anywhere)
void bpstat_run_callbacks(bpstat *bs_head)
static struct value * extract_bitfield_from_watchpoint_value(struct watchpoint *w, struct value *val)
static void thbreak_command(const char *arg, int from_tty)
int hardware_watchpoint_inserted_in_range(const address_space *aspace, CORE_ADDR addr, ULONGEST len)
void breakpoint_re_set_thread(struct breakpoint *b)
static bool all_locations_are_pending(struct breakpoint *b, struct program_space *pspace)
static struct cmd_list_element * catch_cmdlist
struct breakpoint * create_solib_event_breakpoint(struct gdbarch *gdbarch, CORE_ADDR address)
bool fix_breakpoint_script_output_globally
bool is_breakpoint(const struct breakpoint *bpt)
static void breakpoint_re_set_one(breakpoint *b)
static void bpstat_remove_bp_location(bpstat *bps, struct breakpoint *bpt)
static struct cmd_list_element * breakpoint_show_cmdlist
Definition breakpoint.c:833
static agent_expr_up parse_cmd_to_aexpr(CORE_ADDR scope, char *cmd)
int remove_breakpoints(void)
static void commands_command(const char *arg, int from_tty)
#define BP_HARDWAREFLAG
static bool is_tracepoint_type(bptype type)
int breakpoints_should_be_inserted_now(void)
Definition breakpoint.c:598
static void strace_marker_create_sals_from_location_spec(location_spec *locspec, struct linespec_result *canonical)
bool bpstat_should_step()
static const char * breakpoint_condition_evaluation_mode(void)
Definition breakpoint.c:672
int detach_breakpoints(ptid_t ptid)
struct breakpoint * clone_momentary_breakpoint(struct breakpoint *orig)
static void enable_disable_breakpoint_location_range(int bp_num, std::pair< int, int > &bp_loc_range, bool enable)
static const char dprintf_style_call[]
Definition breakpoint.c:462
static bool bp_loc_is_permanent(struct bp_location *loc)
static const char condition_evaluation_auto[]
Definition breakpoint.c:633
static int breakpoint_1(const char *bp_num_list, bool show_internal, bool(*filter)(const struct breakpoint *))
int watchpoints_triggered(const target_waitstatus &ws)
static bool watchpoint_locations_match(const struct bp_location *loc1, const struct bp_location *loc2)
int moribund_breakpoint_here_p(const address_space *aspace, CORE_ADDR pc)
void watch_command_wrapper(const char *arg, int from_tty, bool internal)
static void ignore_command(const char *args, int from_tty)
void set_std_terminate_breakpoint(void)
static int bp_location_is_less_than(const bp_location *a, const bp_location *b)
static void create_std_terminate_master_breakpoint(void)
static void show_debug_breakpoint(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition breakpoint.c:589
void add_catch_command(const char *name, const char *docstring, cmd_func_ftype *func, completer_ftype *completer, void *user_data_catch, void *user_data_tcatch)
static int remove_breakpoint_1(struct bp_location *, enum remove_bp_reason)
static struct minimal_symbol msym_not_found
static void build_target_condition_list(struct bp_location *bl)
static bool breakpoint_has_pc(struct breakpoint *b, struct program_space *pspace, CORE_ADDR pc, struct obj_section *section)
static bool has_multiple_locations(int num)
Definition breakpoint.c:900
static void enable_delete_command(const char *args, int from_tty)
#define LOCATION_SPEC_HELP_STRING
static void strace_marker_create_breakpoints_sal(struct gdbarch *gdbarch, struct linespec_result *canonical, gdb::unique_xmalloc_ptr< char > cond_string, gdb::unique_xmalloc_ptr< char > extra_string, enum bptype type_wanted, enum bpdisp disposition, int thread, int task, int inferior, int ignore_count, int from_tty, int enabled, int internal, unsigned flags)
void rwatch_command_wrapper(const char *arg, int from_tty, bool internal)
int bpstat_num(bpstat **bsp, int *num)
static bool bl_address_is_meaningful(bp_location *loc)
static int overlay_events_enabled
Definition breakpoint.c:692
static bool bpstat_check_location(const struct bp_location *bl, const address_space *aspace, CORE_ADDR bp_addr, const target_waitstatus &ws)
int create_breakpoint(struct gdbarch *gdbarch, location_spec *locspec, const char *cond_string, int thread, int inferior, const char *extra_string, bool force_condition, int parse_extra, int tempflag, enum bptype type_wanted, int ignore_count, enum auto_boolean pending_break_support, const struct breakpoint_ops *ops, int from_tty, int enabled, int internal, unsigned flags)
static int find_loc_num_by_location(const bp_location *loc)
static bool watchpoint_in_thread_scope(struct watchpoint *b)
static bool debug_breakpoint
Definition breakpoint.c:580
static void watch_command_1(const char *arg, int accessflag, int from_tty, bool just_location, bool internal)
static std::vector< bp_location * > bp_locations
Definition breakpoint.c:728
static const char * read_uploaded_action(std::string &buffer)
static const char * condition_evaluation_mode
Definition breakpoint.c:648
const char * bpdisp_text(enum bpdisp disp)
Definition breakpoint.c:505
static void tracepoint_probe_create_sals_from_location_spec(location_spec *locspec, struct linespec_result *canonical)
static void watch_maybe_just_location(const char *arg, int accessflag, int from_tty)
void resolve_sal_pc(struct symtab_and_line *sal)
static void disable_trace_command(const char *args, int from_tty)
static const struct breakpoint_ops tracepoint_probe_breakpoint_ops
Definition breakpoint.c:304
static void break_range_command(const char *arg, int from_tty)
const struct breakpoint_ops code_breakpoint_ops
Definition breakpoint.c:290
static void breakpoint_adjustment_warning(CORE_ADDR, CORE_ADDR, int, bool)
static void watch_command(const char *arg, int from_tty)
static const struct breakpoint_ops * breakpoint_ops_for_location_spec_type(enum location_spec_type locspec_type, bool is_tracepoint)
void break_command(const char *arg, int from_tty)
static std::string dprintf_channel
Definition breakpoint.c:487
static bp_loc_type bp_location_from_bp_type(bptype type)
static bool is_non_inline_function(struct breakpoint *b)
void enable_breakpoints_after_startup(void)
static void insert_breakpoint_locations(void)
static bool tracepoint_locations_match(const struct bp_location *loc1, const struct bp_location *loc2)
static void add_dummy_location(struct breakpoint *b, struct program_space *pspace)
bool fix_multi_location_breakpoint_output_globally
static void clear_command(const char *arg, int from_tty)
static void maintenance_info_breakpoints(const char *args, int from_tty)
static void condition_command(const char *arg, int from_tty)
static void set_hit_convenience_vars(int bpnum, int locno)
bool is_watchpoint(const struct breakpoint *bpt)
enum breakpoint_here breakpoint_here_p(const address_space *aspace, CORE_ADDR pc)
static void bpstat_check_breakpoint_conditions(bpstat *bs, thread_info *thread)
void awatch_command_wrapper(const char *arg, int from_tty, bool internal)
extract_bp_kind
enum command_control_type commands_from_control_command(const char *arg, struct command_line *cmd)
struct tracepoint * get_tracepoint_by_number_on_target(int num)
bool bpstat_explains_signal(bpstat *bsp, enum gdb_signal sig)
static thread_info * get_bpstat_thread()
static void commands_command_1(const char *arg, int from_tty, struct command_line *control)
bpstat * bpstat_find_breakpoint(bpstat *bsp, struct breakpoint *breakpoint)
ugll_insert_mode
Definition breakpoint.c:172
@ UGLL_DONT_INSERT
Definition breakpoint.c:188
@ UGLL_INSERT
Definition breakpoint.c:201
@ UGLL_MAY_INSERT
Definition breakpoint.c:192
static bool command_line_is_silent(struct command_line *cmd)
static std::vector< bp_location * > moribund_locations
Definition breakpoint.c:816
void breakpoint_auto_delete(bpstat *bs)
void delete_std_terminate_breakpoint(void)
static void update_global_location_list_nothrow(enum ugll_insert_mode)
void bpstat_clear_actions(void)
static bool create_longjmp_master_breakpoint_names(objfile *objfile)
bool bpstat_causes_stop(bpstat *bs)
static bool create_exception_master_breakpoint_hook(objfile *objfile)
static struct cmd_list_element * enablebreaklist
static void trace_command(const char *arg, int from_tty)
struct command_line * breakpoint_commands(struct breakpoint *b)
Definition breakpoint.c:494
static bool ambiguous_names_p(const bp_location_range &locs)
static const char * bp_condition_evaluator(const breakpoint *b)
static CORE_ADDR bp_locations_placed_address_before_address_max
Definition breakpoint.c:803
void breakpoint_set_silent(struct breakpoint *b, int silent)
breakpoint * install_breakpoint(int internal, std::unique_ptr< breakpoint > &&arg, int update_gll)
static const char dprintf_style_agent[]
Definition breakpoint.c:463
static void mention(const breakpoint *)
static void print_one_breakpoint(breakpoint *b, const bp_location **last_loc, int allflag)
static void invalidate_bp_value_on_memory_change(struct inferior *inferior, CORE_ADDR addr, ssize_t len, const bfd_byte *data)
static void remove_inferior_breakpoints(struct inferior *inf)
static void set_breakpoint_count(int num)
Definition breakpoint.c:846
static void create_overlay_event_breakpoint(void)
static int executing_breakpoint_commands
Definition breakpoint.c:689
cmd_list_element * commands_cmd_element
static void save_breakpoints(const char *filename, int from_tty, bool(*filter)(const struct breakpoint *))
static void show_always_inserted_mode(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition breakpoint.c:572
static bp_locations_at_addr_range all_bp_locations_at_addr(CORE_ADDR addr)
Definition breakpoint.c:792
void disable_breakpoint(struct breakpoint *bpt)
static void notify_breakpoint_deleted(breakpoint *b)
static int hw_watchpoint_used_count_others(struct breakpoint *except, enum bptype type, int *other_type_used)
void bpstat_do_actions(void)
static void force_breakpoint_reinsertion(struct bp_location *bl)
static int hw_breakpoint_used_count(void)
static void set_tracepoint_count(int num)
static bool automatic_hardware_breakpoints
Definition breakpoint.c:551
void remove_breakpoints_inf(inferior *inf)
static bool breakpoint_cond_eval(expression *exp)
static const char * ugll_insert_mode_text(ugll_insert_mode insert_mode)
Definition breakpoint.c:207
void breakpoint_free_objfile(struct objfile *objfile)
static breakpoint * add_to_breakpoint_chain(std::unique_ptr< breakpoint > &&b)
static void watchpoint_del_at_next_stop(struct watchpoint *w)
static struct breakpoint_objfile_data * get_breakpoint_objfile_data(struct objfile *objfile)
static void find_condition_and_thread(const char *tok, CORE_ADDR pc, gdb::unique_xmalloc_ptr< char > *cond_string, int *thread, int *inferior, int *task, gdb::unique_xmalloc_ptr< char > *rest)
void remove_solib_event_breakpoints(void)
int hardware_breakpoint_inserted_here_p(const address_space *aspace, CORE_ADDR pc)
static const char dprintf_style_gdb[]
Definition breakpoint.c:461
static void map_breakpoint_number_range(std::pair< int, int > bp_num_range, gdb::function_view< void(breakpoint *)> function)
static void check_fast_tracepoint_sals(struct gdbarch *gdbarch, gdb::array_view< const symtab_and_line > sals)
static void parse_breakpoint_sals(location_spec *locspec, struct linespec_result *canonical)
static void extract_bp_number_and_location(const std::string &arg, std::pair< int, int > &bp_num_range, std::pair< int, int > &bp_loc_range)
static int wrap_indent_at_field(struct ui_out *uiout, const char *col_name)
static void download_tracepoint_locations(void)
static void set_breakpoint_location_condition(const char *cond_string, bp_location *loc, int bp_num, int loc_num)
int pc_at_non_inline_function(const address_space *aspace, CORE_ADDR pc, const target_waitstatus &ws)
static struct cmd_list_element * breakpoint_set_cmdlist
Definition breakpoint.c:832
static void trace_pass_command(const char *, int)
static void breakpoint_sals_to_pc(std::vector< symtab_and_line > &sals)
static int internal_breakpoint_number
static void create_exception_master_breakpoint(void)
bpstat * bpstat_stop_status_nowatch(const address_space *aspace, CORE_ADDR bp_addr, thread_info *thread, const target_waitstatus &ws)
static bool watchpoint_exp_is_const(const struct expression *exp)
static int hw_watchpoint_use_count(struct breakpoint *)
static void update_watchpoint(struct watchpoint *b, bool reparse)
void bpstat_clear(bpstat **bsp)
static void handle_automatic_hardware_breakpoints(bp_location *bl)
int breakpoint_in_range_p(const address_space *aspace, CORE_ADDR addr, ULONGEST len)
static struct breakpoint * create_internal_breakpoint(struct gdbarch *gdbarch, CORE_ADDR address, enum bptype type)
static void print_breakpoint_location(const breakpoint *b, const bp_location *loc)
static bool create_longjmp_master_breakpoint_probe(objfile *objfile)
void breakpoint_set_task(struct breakpoint *b, int task)
static int can_use_hw_watchpoints
Definition breakpoint.c:518
static void dprintf_command(const char *arg, int from_tty)
static void enable_command(const char *args, int from_tty)
static struct breakpoint * momentary_breakpoint_from_master(struct breakpoint *orig, enum bptype type, int loc_enabled, int thread)
bpstat * build_bpstat_chain(const address_space *aspace, CORE_ADDR bp_addr, const target_waitstatus &ws)
static std::string dprintf_function
Definition breakpoint.c:477
struct breakpoint * create_jit_event_breakpoint(struct gdbarch *gdbarch, CORE_ADDR address)
void disable_breakpoints_before_startup(void)
static void decref_bp_location(struct bp_location **loc)
#define BREAK_ARGS_HELP(command)
static void set_condition_evaluation_mode(const char *args, int from_tty, struct cmd_list_element *c)
Definition breakpoint.c:957
void enable_watchpoints_after_interactive_call_stop(void)
static struct bp_location * find_location_by_number(int bp_num, int loc_num)
void _initialize_breakpoint()
static struct breakpoint * create_solib_event_breakpoint_1(struct gdbarch *gdbarch, CORE_ADDR address, enum ugll_insert_mode insert_mode)
#define internal_error_pure_virtual_called()
static const char condition_evaluation_both[]
Definition breakpoint.c:630
static int remove_breakpoint(struct bp_location *)
void breakpoint_set_commands(struct breakpoint *b, counted_command_line &&commands)
int insert_single_step_breakpoints(struct gdbarch *gdbarch)
static std::vector< symtab_and_line > decode_static_tracepoint_spec(const char **arg_p)
static int extract_bp_num(extract_bp_kind kind, const char *start, int trailer, const char **end_out=NULL)
static void create_breakpoints_sal(struct gdbarch *, struct linespec_result *, gdb::unique_xmalloc_ptr< char >, gdb::unique_xmalloc_ptr< char >, enum bptype, enum bpdisp, int, int, int, int, int, int, int, unsigned)
void notify_breakpoint_modified(breakpoint *b)
struct tracepoint * create_tracepoint_from_upload(struct uploaded_tp *utp)
struct tracepoint * get_tracepoint(int num)
void set_ignore_count(int bptnum, int count, int from_tty)
static void set_breakpoint_location_function(struct bp_location *loc)
bpstat * bpstat_stop_status(const address_space *aspace, CORE_ADDR bp_addr, thread_info *thread, const target_waitstatus &ws, bpstat *stop_chain)
struct cmd_list_element * save_cmdlist
Definition breakpoint.c:834
static const char *const condition_evaluation_enums[]
Definition breakpoint.c:636
#define NUM_LONGJMP_NAMES
static const char *const longjmp_names[]
static bool msym_not_found_p(const struct minimal_symbol *msym)
int breakpoint_has_location_inserted_here(struct breakpoint *bp, const address_space *aspace, CORE_ADDR pc)
int single_step_breakpoint_inserted_here_p(const address_space *aspace, CORE_ADDR pc)
static void info_breakpoints_command(const char *args, int from_tty)
static enum print_stop_action print_bp_stop_message(bpstat *bs)
static void show_can_use_hw_watchpoints(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition breakpoint.c:521
void print_solib_event(bool is_catchpoint)
static const char * condition_evaluation_mode_1
Definition breakpoint.c:644
static bool should_be_inserted(struct bp_location *bl)
static bool bp_location_has_shadow(struct bp_location *bl)
static void build_target_command_list(struct bp_location *bl)
wp_check_result
@ WP_IGNORE
@ WP_VALUE_NOT_CHANGED
@ WP_VALUE_CHANGED
@ WP_DELETED
static bool gdb_evaluates_breakpoint_condition_p(void)
Definition breakpoint.c:681
struct breakpoint * set_longjmp_breakpoint_for_call_dummy(void)
static momentary_breakpoint * new_momentary_breakpoint(struct gdbarch *gdbarch, enum bptype type, Arg &&... args)
static void default_collect_info(void)
static int bpstat_remove_breakpoint_callback(struct thread_info *th, void *data)
static void agent_printf_command(const char *arg, int from_tty)
static bool strace_marker_p(struct breakpoint *b)
void print_num_locno(const bpstat *bs, struct ui_out *uiout)
static void show_automatic_hardware_breakpoints(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition breakpoint.c:553
static void notify_breakpoint_created(breakpoint *b)
int breakpoint_inserted_here_p(const address_space *aspace, CORE_ADDR pc)
static void update_dprintf_command_list(struct breakpoint *b)
bool target_exact_watchpoints
Definition breakpoint.c:695
static enum auto_boolean pending_break_support
Definition breakpoint.c:535
static int tracepoint_count
Definition breakpoint.c:830
static gdb::option::option_def_group make_watch_options_def_group(watch_options *opts)
static void delete_command(const char *arg, int from_tty)
static std::pair< int, int > extract_bp_or_bp_range(extract_bp_kind kind, const std::string &arg, std::string::size_type arg_offset)
static void update_dprintf_commands(const char *args, int from_tty, struct cmd_list_element *c)
void tbreak_command(const char *arg, int from_tty)
std::vector< breakpoint * > static_tracepoints_here(CORE_ADDR addr)
static bool create_exception_master_breakpoint_probe(objfile *objfile)
void clear_breakpoint_hit_counts(void)
Definition breakpoint.c:876
static void enable_disable_bp_num_loc(int bp_num, int loc_num, bool enable)
static const char *const dprintf_style_enums[]
Definition breakpoint.c:464
static void update_global_location_list(enum ugll_insert_mode)
static void ftrace_command(const char *arg, int from_tty)
bpstat * bpstat_copy(bpstat *bs)
static int breakpoint_address_bits(struct breakpoint *b)
int breakpoint_address_match(const address_space *aspace1, CORE_ADDR addr1, const address_space *aspace2, CORE_ADDR addr2)
static bool disconnected_dprintf
Definition breakpoint.c:491
static void remove_threaded_breakpoints(thread_info *tp, gdb::optional< ULONGEST >, int)
void disable_watchpoints_before_interactive_call_start(void)
static const gdb::option::option_def watch_option_defs[]
static int compare_breakpoints(const breakpoint *a, const breakpoint *b)
static void output_thread_groups(struct ui_out *uiout, const char *field_name, const std::vector< int > &inf_nums, int mi_only)
void set_breakpoint_condition(struct breakpoint *b, const char *exp, int from_tty, bool force)
int user_breakpoint_p(struct breakpoint *b)
static int breakpoint_count
Definition breakpoint.c:820
static void set_breakpoint_number(int internal, struct breakpoint *b)
static bool bp_location_inserted_here_p(const struct bp_location *bl, const address_space *aspace, CORE_ADDR pc)
struct breakpoint * create_and_insert_solib_event_breakpoint(struct gdbarch *gdbarch, CORE_ADDR address)
static const char condition_evaluation_target[]
Definition breakpoint.c:635
static void enable_once_command(const char *args, int from_tty)
void breakpoint_xfer_memory(gdb_byte *readbuf, gdb_byte *writebuf, const gdb_byte *writebuf_org, ULONGEST memaddr, LONGEST len)
static wp_check_result watchpoint_check(bpstat *bs)
void disable_breakpoints_in_shlibs(void)
void mark_breakpoints_out(void)
static void enable_disable_command(const char *args, int from_tty, bool enable)
static void delete_trace_command(const char *arg, int from_tty)
void print_breakpoint(breakpoint *b)
static bool need_moribund_for_location_type(const struct bp_location *loc)
void delete_longjmp_breakpoint_at_next_stop(int thread)
int pending_breakpoint_p(struct breakpoint *b)
static void watch_command_completer(struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *)
static void breakpoint_about_to_proceed(void)
bool is_tracepoint(const struct breakpoint *b)
static void enable_trace_command(const char *args, int from_tty)
static void create_breakpoint_sal(struct gdbarch *gdbarch, gdb::array_view< const symtab_and_line > sals, location_spec_up &&locspec, gdb::unique_xmalloc_ptr< char > filter, gdb::unique_xmalloc_ptr< char > cond_string, gdb::unique_xmalloc_ptr< char > extra_string, enum bptype type, enum bpdisp disposition, int thread, int task, int inferior, int ignore_count, int from_tty, int enabled, int internal, unsigned flags, int display_canonical)
static void create_sals_from_location_spec_default(location_spec *locspec, linespec_result *canonical)
static void update_inserted_breakpoint_locations(void)
breakpoint_up set_momentary_breakpoint(struct gdbarch *gdbarch, struct symtab_and_line sal, struct frame_id frame_id, enum bptype type)
static bool bpstat_do_actions_1(bpstat **bsp)
static void handle_jit_event(CORE_ADDR address)
static void disable_breakpoints_in_freed_objfile(struct objfile *objfile)
void insert_breakpoints(void)
static void map_breakpoint_numbers(const char *, gdb::function_view< void(breakpoint *)>)
static const struct breakpoint_ops bkpt_probe_breakpoint_ops
Definition breakpoint.c:297
struct gdbarch * get_sal_arch(struct symtab_and_line sal)
void delete_longjmp_breakpoint(int thread)
void update_breakpoints_after_exec(void)
static int next_cmd
static void disable_command(const char *args, int from_tty)
enum print_stop_action bpstat_print(bpstat *bs, target_waitkind kind)
void update_breakpoint_locations(code_breakpoint *b, struct program_space *filter_pspace, gdb::array_view< const symtab_and_line > sals, gdb::array_view< const symtab_and_line > sals_end)
void set_longjmp_breakpoint(struct thread_info *tp, struct frame_id frame)
int bpstat_locno(const bpstat *bs)
static void trace_pass_set_count(struct tracepoint *tp, int count, int from_tty)
static int prev_breakpoint_count
Definition breakpoint.c:826
static void bkpt_probe_create_sals_from_location_spec(location_spec *locspec, struct linespec_result *canonical)
tracepoint_range all_tracepoints()
Definition breakpoint.c:720
static intrusive_list< breakpoint > breakpoint_chain
Definition breakpoint.c:699
const struct breakpoint_ops * breakpoint_ops_for_location_spec(const location_spec *locspec, bool is_tracepoint)
void disable_overlay_breakpoints(void)
static CORE_ADDR adjust_breakpoint_address(struct gdbarch *gdbarch, CORE_ADDR bpaddr, enum bptype bptype, struct program_space *pspace)
static bool always_inserted_mode
Definition breakpoint.c:569
static bool breakpoint_location_address_match(struct bp_location *bl, const struct address_space *aspace, CORE_ADDR addr)
static bool is_masked_watchpoint(const struct breakpoint *b)
static const registry< objfile >::key< breakpoint_objfile_data > breakpoint_objfile_key
static bool breakpoint_enabled(struct breakpoint *b)
Definition breakpoint.c:838
static void find_condition_and_thread_for_sals(const std::vector< symtab_and_line > &sals, const char *input, gdb::unique_xmalloc_ptr< char > *cond_string, int *thread, int *inferior, int *task, gdb::unique_xmalloc_ptr< char > *rest)
static CORE_ADDR find_breakpoint_range_end(struct symtab_and_line sal)
static struct breakpoint_ops strace_marker_breakpoint_ops
void insert_single_step_breakpoint(struct gdbarch *gdbarch, const address_space *aspace, CORE_ADDR next_pc)
static void swap_insertion(struct bp_location *left, struct bp_location *right)
static int insert_bp_location(struct bp_location *bl, struct ui_file *tmp_error_stream, int *disabled_breaks, int *hw_breakpoint_error, int *hw_bp_error_explained_already)
static struct symtab_and_line update_static_tracepoint(tracepoint *tp, struct symtab_and_line sal)
static int rbreak_start_breakpoint_count
Definition breakpoint.c:855
static void enable_count_command(const char *args, int from_tty)
bool is_catchpoint(struct breakpoint *b)
static void check_no_tracepoint_commands(struct command_line *commands)
struct tracepoint * get_tracepoint_by_number(const char **arg, number_or_range_parser *parser)
breakpoint_safe_range all_breakpoints_safe()
Definition breakpoint.c:712
static bool breakpoint_locations_match(const struct bp_location *loc1, const struct bp_location *loc2, bool sw_hw_bps_match=false)
static void condition_completer(struct cmd_list_element *cmd, completion_tracker &tracker, const char *text, const char *)
static bool is_hardware_watchpoint(const struct breakpoint *bpt)
static void validate_commands_for_breakpoint(struct breakpoint *b, struct command_line *commands)
static void rwatch_command(const char *arg, int from_tty)
void describe_other_breakpoints(struct gdbarch *gdbarch, struct program_space *pspace, CORE_ADDR pc, struct obj_section *section, int thread)
static void save_breakpoints_command(const char *args, int from_tty)
static void enable_breakpoint_disp(struct breakpoint *, enum bpdisp, int count)
static int breakpoint_kind(const struct bp_location *bl, CORE_ADDR *addr)
static bool breakpoint_location_address_range_overlap(struct bp_location *, const address_space *, CORE_ADDR, int)
static void mark_breakpoint_location_modified(struct bp_location *loc)
Definition breakpoint.c:936
void enable_overlay_breakpoints(void)
static void bpstat_check_watchpoint(bpstat *bs)
#define breakpoint_debug_printf(fmt,...)
Definition breakpoint.c:583
breakpoint_range all_breakpoints()
Definition breakpoint.c:704
static void rethrow_on_target_close_error(const gdb_exception &e)
static std::string breakpoint_location_address_str(const bp_location *bl)
Definition breakpoint.c:252
void maybe_print_thread_hit_breakpoint(struct ui_out *uiout)
bpdisp
Definition breakpoint.h:236
@ disp_donttouch
Definition breakpoint.h:241
@ disp_del
Definition breakpoint.h:237
@ disp_disable
Definition breakpoint.h:240
@ disp_del_at_next_stop
Definition breakpoint.h:238
iterator_range< bp_location_iterator > bp_location_range
Definition breakpoint.h:612
bpstat_what_main_action
@ BPSTAT_WHAT_STOP_NOISY
@ BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
@ BPSTAT_WHAT_STOP_SILENT
@ BPSTAT_WHAT_SINGLE
@ BPSTAT_WHAT_SET_LONGJMP_RESUME
@ BPSTAT_WHAT_HP_STEP_RESUME
@ BPSTAT_WHAT_STEP_RESUME
@ BPSTAT_WHAT_KEEP_CHECKING
iterator_range< tracepoint_iterator > tracepoint_range
@ print_it_noop
@ print_it_done
@ print_it_normal
bptype
Definition breakpoint.h:84
@ bp_gnu_ifunc_resolver_return
Definition breakpoint.h:211
@ bp_std_terminate_master
Definition breakpoint.h:177
@ bp_breakpoint
Definition breakpoint.h:86
@ bp_exception_resume
Definition breakpoint.h:109
@ bp_watchpoint
Definition breakpoint.h:91
@ bp_longjmp_call_dummy
Definition breakpoint.h:102
@ bp_thread_event
Definition breakpoint.h:159
@ bp_dprintf
Definition breakpoint.h:195
@ bp_step_resume
Definition breakpoint.h:113
@ bp_longjmp
Definition breakpoint.h:95
@ bp_fast_tracepoint
Definition breakpoint.h:185
@ bp_overlay_event
Definition breakpoint.h:167
@ bp_hardware_breakpoint
Definition breakpoint.h:87
@ bp_exception_master
Definition breakpoint.h:180
@ bp_read_watchpoint
Definition breakpoint.h:93
@ bp_shlib_event
Definition breakpoint.h:149
@ bp_std_terminate
Definition breakpoint.h:139
@ bp_finish
Definition breakpoint.h:90
@ bp_until
Definition breakpoint.h:89
@ bp_catchpoint
Definition breakpoint.h:182
@ bp_access_watchpoint
Definition breakpoint.h:94
@ bp_call_dummy
Definition breakpoint.h:135
@ bp_jit_event
Definition breakpoint.h:198
@ bp_gnu_ifunc_resolver
Definition breakpoint.h:205
@ bp_none
Definition breakpoint.h:85
@ bp_static_marker_tracepoint
Definition breakpoint.h:188
@ bp_hp_step_resume
Definition breakpoint.h:117
@ bp_longjmp_master
Definition breakpoint.h:174
@ bp_longjmp_resume
Definition breakpoint.h:96
@ bp_watchpoint_scope
Definition breakpoint.h:131
@ bp_single_step
Definition breakpoint.h:88
@ bp_hardware_watchpoint
Definition breakpoint.h:92
@ bp_static_tracepoint
Definition breakpoint.h:186
@ bp_exception
Definition breakpoint.h:106
@ bp_tracepoint
Definition breakpoint.h:184
@ CREATE_BREAKPOINT_FLAGS_INSERTED
void delete_breakpoint(struct breakpoint *)
inf_context
@ inf_starting
std::unique_ptr< struct breakpoint, breakpoint_deleter > breakpoint_up
intrusive_list< bp_location > bp_location_list
Definition breakpoint.h:610
@ condition_updated
Definition breakpoint.h:251
@ condition_unchanged
Definition breakpoint.h:249
@ condition_modified
Definition breakpoint.h:250
print_stop_action
Definition breakpoint.h:542
@ PRINT_SRC_AND_LOC
Definition breakpoint.h:548
@ PRINT_NOTHING
Definition breakpoint.h:556
@ PRINT_UNKNOWN
Definition breakpoint.h:544
@ PRINT_SRC_ONLY
Definition breakpoint.h:552
breakpoint_here
@ ordinary_breakpoint_here
@ no_breakpoint_here
@ permanent_breakpoint_here
int breakpoint_address_match(const address_space *aspace1, CORE_ADDR addr1, const address_space *aspace2, CORE_ADDR addr2)
enable_state
Definition breakpoint.h:217
@ bp_disabled
Definition breakpoint.h:218
@ bp_enabled
Definition breakpoint.h:220
@ bp_call_disabled
Definition breakpoint.h:222
remove_bp_reason
Definition breakpoint.h:64
@ REMOVE_BREAKPOINT
Definition breakpoint.h:67
@ DETACH_BREAKPOINT
Definition breakpoint.h:70
bp_loc_type
Definition breakpoint.h:315
@ bp_loc_tracepoint
Definition breakpoint.h:320
@ bp_loc_hardware_breakpoint
Definition breakpoint.h:317
@ bp_loc_other
Definition breakpoint.h:321
@ bp_loc_software_breakpoint
Definition breakpoint.h:316
@ bp_loc_software_watchpoint
Definition breakpoint.h:318
@ bp_loc_hardware_watchpoint
Definition breakpoint.h:319
basic_safe_range< breakpoint_range > breakpoint_safe_range
struct gdbarch * get_sal_arch(struct symtab_and_line sal)
@ STOP_NONE
@ STOP_STD_TERMINATE
@ STOP_STACK_DUMMY
filtered_iterator< breakpoint_iterator, tracepoint_filter > tracepoint_iterator
void update_breakpoint_locations(code_breakpoint *b, struct program_space *filter_pspace, gdb::array_view< const symtab_and_line > sals, gdb::array_view< const symtab_and_line > sals_end)
void describe_other_breakpoints(struct gdbarch *, struct program_space *, CORE_ADDR, struct obj_section *, int)
watchpoint_triggered
Definition breakpoint.h:591
@ watch_triggered_no
Definition breakpoint.h:593
@ watch_triggered_unknown
Definition breakpoint.h:597
@ watch_triggered_yes
Definition breakpoint.h:600
iterator_range< breakpoint_iterator > breakpoint_range
gdb::ref_ptr< bp_location, bp_location_ref_policy > bp_location_ref_ptr
Definition breakpoint.h:537
void maybe_print_thread_hit_breakpoint(struct ui_out *uiout)
const minimal_symbol * msymbol
Definition breakpoint.h:508
expression_up cond
Definition breakpoint.h:354
struct symtab * symtab
Definition breakpoint.h:498
breakpoint * owner
Definition breakpoint.h:345
CORE_ADDR requested_address
Definition breakpoint.h:458
struct gdbarch * gdbarch
Definition breakpoint.h:423
bp_target_info overlay_target_info
Definition breakpoint.h:475
CORE_ADDR address
Definition breakpoint.h:437
const struct symbol * symbol
Definition breakpoint.h:503
bool shlib_disabled
Definition breakpoint.h:386
bool needs_update
Definition breakpoint.h:381
bool disabled_by_cond
Definition breakpoint.h:395
agent_expr_up cond_bytecode
Definition breakpoint.h:359
bp_loc_type loc_type
Definition breakpoint.h:337
bp_location(breakpoint *owner)
std::string to_string() const
obj_section * section
Definition breakpoint.h:450
condition_status condition_changed
Definition breakpoint.h:374
target_hw_bp_type watchpoint_type
Definition breakpoint.h:445
bp_target_info target_info
Definition breakpoint.h:472
const struct objfile * objfile
Definition breakpoint.h:511
bound_probe probe
Definition breakpoint.h:467
program_space * pspace
Definition breakpoint.h:431
ui_file_style style() const
Definition cli-style.c:169
void add_completion(gdb::unique_xmalloc_ptr< char > name, completion_match_for_lcd *match_for_lcd=NULL, const char *text=NULL, const char *word=NULL)
Definition completer.c:1579
void advance_custom_word_point_by(int len)
Definition completer.c:2049
int num
Definition inferior.h:557
struct program_space * pspace
Definition inferior.h:582
const struct block * block() const
Definition expression.h:272
bool finished() const
Definition cli-utils.c:327
Definition probe.h:115
virtual void clear_semaphore(struct objfile *objfile, struct gdbarch *gdbarch)
Definition probe.h:164
virtual void set_semaphore(struct objfile *objfile, struct gdbarch *gdbarch)
Definition probe.h:157
virtual bool can_evaluate_arguments() const =0
friend class regcache
Definition regcache.h:269
const address_space * aspace() const
Definition regcache.h:343
void * get(unsigned key)
Definition registry.h:211
void puts(const char *) override
Definition ui-file.c:329
bool open(const char *name, const char *mode)
Definition ui-file.c:263
const char * c_str() const
Definition ui-file.h:222
std::string release()
Definition ui-file.h:204
static void inferior()
Definition target.c:952
static void ours_for_output()
Definition target.c:1088
void set_thread_fsm(std::unique_ptr< struct thread_fsm > fsm)
Definition gdbthread.h:470
enum thread_state state
Definition gdbthread.h:339
ptid_t ptid
Definition gdbthread.h:259
struct frame_id initiating_frame
Definition gdbthread.h:525
bool executing() const
Definition gdbthread.h:319
struct inferior * inf
Definition gdbthread.h:301
thread_control_state control
Definition gdbthread.h:343
virtual void puts(const char *str)
Definition ui-file.h:76
void printf(const char *,...) ATTRIBUTE_PRINTF(2
Definition ui-file.c:40
ui_out_flags test_flags(ui_out_flags mask)
Definition ui-out.c:804
bool query_table_field(int colno, int *width, int *alignment, const char **col_name)
Definition ui-out.c:853
void field_core_addr(const char *fldname, struct gdbarch *gdbarch, CORE_ADDR address)
Definition ui-out.c:478
void field_string(const char *fldname, const char *string, const ui_file_style &style=ui_file_style())
Definition ui-out.c:511
void field_fmt(const char *fldname, const char *format,...) ATTRIBUTE_PRINTF(3
Definition ui-out.c:525
void field_signed(const char *fldname, LONGEST value)
Definition ui-out.c:437
void field_skip(const char *fldname)
Definition ui-out.c:499
void text(const char *string)
Definition ui-out.c:566
void field_stream(const char *fldname, string_file &stream, const ui_file_style &style=ui_file_style())
Definition ui-out.c:486
void table_header(int width, ui_align align, const std::string &col_name, const std::string &col_hdr)
Definition ui-out.c:363
bool is_mi_like_p() const
Definition ui-out.c:810
void table_body()
Definition ui-out.c:376
void void void wrap_hint(int indent)
Definition ui-out.c:785
void message(const char *format,...) ATTRIBUTE_PRINTF(2
Definition ui-out.c:774
void end(ui_out_type type)
Definition ui-out.c:429
struct cmd_list_element * showlist
Definition cli-cmds.c:127
struct cmd_list_element * deletelist
Definition cli-cmds.c:107
void error_no_arg(const char *why)
Definition cli-cmds.c:206
struct cmd_list_element * cmdlist
Definition cli-cmds.c:87
struct cmd_list_element * setlist
Definition cli-cmds.c:119
struct cmd_list_element * showdebuglist
Definition cli-cmds.c:167
struct cmd_list_element * disablelist
Definition cli-cmds.c:99
struct cmd_list_element * enablelist
Definition cli-cmds.c:95
struct cmd_list_element * maintenanceinfolist
Definition cli-cmds.c:147
struct cmd_list_element * setdebuglist
Definition cli-cmds.c:165
struct cmd_list_element * add_alias_cmd(const char *name, cmd_list_element *target, enum command_class theclass, int abbrev_flag, struct cmd_list_element **list)
Definition cli-decode.c:294
set_show_commands add_setshow_zinteger_cmd(const char *name, enum command_class theclass, int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **list)
Definition cli-decode.c:233
void set_cmd_completer_handle_brkchars(struct cmd_list_element *cmd, completer_handle_brkchars_ftype *func)
Definition cli-decode.c:125
cmd_list_element * add_com_alias(const char *name, cmd_list_element *target, command_class theclass, int abbrev_flag)
set_show_commands add_setshow_string_cmd(const char *name, enum command_class theclass, std::string *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
Definition cli-decode.c:903
void set_cmd_completer(struct cmd_list_element *cmd, completer_ftype *completer)
Definition cli-decode.c:117
struct cmd_list_element * add_com(const char *name, enum command_class theclass, cmd_simple_func_ftype *fun, const char *doc)
set_show_commands add_setshow_enum_cmd(const char *name, enum command_class theclass, const char *const *enumlist, const char **var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
Definition cli-decode.c:688
struct cmd_list_element * deprecate_cmd(struct cmd_list_element *cmd, const char *replacement)
Definition cli-decode.c:280
set_show_commands add_setshow_prefix_cmd(const char *name, command_class theclass, const char *set_doc, const char *show_doc, cmd_list_element **set_subcommands_list, cmd_list_element **show_subcommands_list, cmd_list_element **set_list, cmd_list_element **show_list)
Definition cli-decode.c:428
struct cmd_list_element * add_prefix_cmd(const char *name, enum command_class theclass, cmd_simple_func_ftype *fun, const char *doc, struct cmd_list_element **subcommands, int allow_unknown, struct cmd_list_element **list)
Definition cli-decode.c:357
static cmd_list_element::aliases_list_type delete_cmd(const char *name, cmd_list_element **list, cmd_list_element **prehook, cmd_list_element **prehookee, cmd_list_element **posthook, cmd_list_element **posthookee)
set_show_commands add_setshow_boolean_cmd(const char *name, enum command_class theclass, bool *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
Definition cli-decode.c:809
cmd_list_element * add_info_alias(const char *name, cmd_list_element *target, int abbrev_flag)
set_show_commands add_setshow_auto_boolean_cmd(const char *name, enum command_class theclass, enum auto_boolean *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
Definition cli-decode.c:752
struct cmd_list_element * add_basic_prefix_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **subcommands, int allow_unknown, struct cmd_list_element **list)
Definition cli-decode.c:391
struct cmd_list_element * add_info(const char *name, cmd_simple_func_ftype *fun, const char *doc)
counted_command_line read_command_lines_1(read_next_line_ftype read_next_line_func, int parse_commands, gdb::function_view< void(const char *)> validator)
void execute_control_commands(struct command_line *cmdlines, int from_tty)
Definition cli-script.c:403
counted_command_line read_command_lines(const char *prompt_arg, int from_tty, int parse_commands, gdb::function_view< void(const char *)> validator)
void print_command_lines(struct ui_out *uiout, struct command_line *cmd, unsigned int depth)
Definition cli-script.c:202
enum command_control_type execute_control_command(struct command_line *cmd, int from_tty)
Definition cli-script.c:698
command_control_type
Definition cli-script.h:36
@ while_stepping_control
Definition cli-script.h:46
@ simple_control
Definition cli-script.h:37
std::shared_ptr< command_line > counted_command_line
Definition cli-script.h:67
cli_style_option address_style
cli_style_option function_name_style
cli_style_option file_name_style
cli_style_option metadata_style
int get_number(const char **pp)
Definition cli-utils.c:163
int number_is_in_list(const char *list, int number)
Definition cli-utils.c:348
std::string extract_arg(const char **arg)
Definition cli-utils.c:383
int get_number_trailer(const char **pp, int trailer)
Definition cli-utils.c:81
scoped_restore_tmpl< int > prevent_dont_repeat(void)
Definition top.c:735
void completer_ftype(struct cmd_list_element *, completion_tracker &tracker, const char *text, const char *word)
Definition command.h:511
void dont_repeat()
Definition top.c:696
void cmd_func_ftype(const char *args, int from_tty, cmd_list_element *c)
Definition command.h:499
@ class_maintenance
Definition command.h:65
@ class_breakpoint
Definition command.h:60
@ class_vars
Definition command.h:55
@ class_support
Definition command.h:58
@ class_trace
Definition command.h:61
@ class_run
Definition command.h:54
@ no_class
Definition command.h:53
void expression_completer(struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *word)
Definition completer.c:1092
const char * advance_to_expression_complete_word_point(completion_tracker &tracker, const char *text)
Definition completer.c:422
void location_completer(struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *)
Definition completer.c:927
void filename_completer(struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *word)
Definition completer.c:204
std::string to_string(cooked_index_flag flags)
std::string memory_error_message(enum target_xfer_status err, struct gdbarch *gdbarch, CORE_ADDR memaddr)
Definition corefile.c:163
void set_next_address(struct gdbarch *, CORE_ADDR)
Definition printcmd.c:532
unsigned input_radix
Definition valprint.c:186
int longest_to_int(LONGEST)
Definition valprint.c:1372
auto_boolean
Definition defs.h:247
@ AUTO_BOOLEAN_AUTO
Definition defs.h:250
@ AUTO_BOOLEAN_FALSE
Definition defs.h:249
int print_address_symbolic(struct gdbarch *, CORE_ADDR, struct ui_file *, int, const char *)
Definition printcmd.c:554
language
Definition defs.h:211
@ lval_memory
Definition defs.h:363
@ not_lval
Definition defs.h:361
@ lval_register
Definition defs.h:365
#define QUIT
Definition defs.h:187
void dummy_frame_discard(struct frame_id dummy_id, thread_info *thread)
struct value * parse_and_eval(const char *exp, parser_flags flags)
Definition eval.c:70
struct value * parse_to_comma_and_eval(const char **expp)
Definition eval.c:82
LONGEST parse_and_eval_long(const char *exp)
Definition eval.c:62
void fetch_subexp_value(struct expression *exp, expr::operation *op, struct value **valp, struct value **resultp, std::vector< value_ref_ptr > *val_chain, bool preserve_errors)
Definition eval.c:143
void exception_fprintf(struct ui_file *file, const struct gdb_exception &e, const char *prefix,...)
Definition exceptions.c:116
void exception_print(struct ui_file *file, const struct gdb_exception &e)
Definition exceptions.c:106
std::unique_ptr< expression > expression_up
Definition expression.h:241
@ PARSER_COMMA_TERMINATES
Definition expression.h:298
expression_up parse_exp_1(const char **, CORE_ADDR pc, const struct block *, parser_flags flags, innermost_block_tracker *=nullptr)
Definition parse.c:446
const struct extension_language_defn * get_breakpoint_cond_ext_lang(struct breakpoint *b, enum extension_language skip_lang)
Definition extension.c:583
const char * ext_lang_capitalized_name(const struct extension_language_defn *extlang)
Definition extension.c:215
bool breakpoint_ext_lang_cond_says_stop(struct breakpoint *b)
Definition extension.c:602
@ EXT_LANG_NONE
Definition extension.h:62
const struct frame_id null_frame_id
Definition frame.c:688
enum unwind_stop_reason get_frame_unwind_stop_reason(frame_info_ptr frame)
Definition frame.c:3166
struct program_space * get_frame_program_space(frame_info_ptr frame)
Definition frame.c:2965
void select_frame(frame_info_ptr fi)
Definition frame.c:1927
CORE_ADDR frame_unwind_caller_pc(frame_info_ptr this_frame)
Definition frame.c:1042
CORE_ADDR get_frame_pc(frame_info_ptr frame)
Definition frame.c:2712
struct frame_id get_stack_frame_id(frame_info_ptr next_frame)
Definition frame.c:662
const address_space * get_frame_address_space(frame_info_ptr frame)
Definition frame.c:2982
bool frame_id_p(frame_id l)
Definition frame.c:781
bool frame_id_artificial_p(frame_id l)
Definition frame.c:792
struct gdbarch * get_frame_arch(frame_info_ptr this_frame)
Definition frame.c:3027
struct frame_id frame_unwind_caller_id(frame_info_ptr next_frame)
Definition frame.c:668
frame_info_ptr get_selected_frame(const char *message)
Definition frame.c:1888
frame_info_ptr frame_find_by_id(struct frame_id id)
Definition frame.c:916
frame_info_ptr get_current_frame(void)
Definition frame.c:1670
struct frame_id get_frame_id(frame_info_ptr fi)
Definition frame.c:631
frame_info_ptr get_prev_frame(frame_info_ptr this_frame)
Definition frame.c:2614
struct gdbarch * frame_unwind_caller_arch(frame_info_ptr next_frame)
Definition frame.c:3059
bool demangle
CORE_ADDR gdbarch_adjust_breakpoint_address(struct gdbarch *gdbarch, CORE_ADDR bpaddr)
Definition gdbarch.c:2852
const gdb_byte * gdbarch_breakpoint_from_pc(struct gdbarch *gdbarch, CORE_ADDR *pcptr, int *lenptr)
Definition gdbarch.c:2777
bool gdbarch_adjust_breakpoint_address_p(struct gdbarch *gdbarch)
Definition gdbarch.c:2845
int gdbarch_addr_bit(struct gdbarch *gdbarch)
Definition gdbarch.c:1739
bool gdbarch_program_breakpoint_here_p(struct gdbarch *gdbarch, CORE_ADDR address)
Definition gdbarch.c:5157
std::vector< CORE_ADDR > gdbarch_software_single_step(struct gdbarch *gdbarch, struct regcache *regcache)
Definition gdbarch.c:3295
int gdbarch_stack_frame_destroyed_p(struct gdbarch *gdbarch, CORE_ADDR addr)
Definition gdbarch.c:3438
int gdbarch_has_global_breakpoints(struct gdbarch *gdbarch)
Definition gdbarch.c:4871
int gdbarch_fast_tracepoint_valid_at(struct gdbarch *gdbarch, CORE_ADDR addr, std::string *msg)
Definition gdbarch.c:4905
bool gdbarch_skip_entrypoint_p(struct gdbarch *gdbarch)
Definition gdbarch.c:2736
int gdbarch_breakpoint_kind_from_current_state(struct gdbarch *gdbarch, struct regcache *regcache, CORE_ADDR *pcptr)
Definition gdbarch.c:2828
CORE_ADDR gdbarch_skip_entrypoint(struct gdbarch *gdbarch, CORE_ADDR ip)
Definition gdbarch.c:2743
CORE_ADDR gdbarch_remove_non_address_bits(struct gdbarch *gdbarch, CORE_ADDR pointer)
Definition gdbarch.c:3169
bool gdbarch_get_longjmp_target_p(struct gdbarch *gdbarch)
Definition gdbarch.c:2436
CORE_ADDR gdbarch_convert_from_func_ptr_addr(struct gdbarch *gdbarch, CORE_ADDR addr, struct target_ops *targ)
Definition gdbarch.c:3135
int gdbarch_breakpoint_kind_from_pc(struct gdbarch *gdbarch, CORE_ADDR *pcptr)
Definition gdbarch.c:2794
int thread_count(process_stratum_target *proc_target)
Definition thread.c:605
all_non_exited_threads_range all_non_exited_threads(process_stratum_target *proc_target=nullptr, ptid_t filter_ptid=minus_one_ptid)
Definition gdbthread.h:753
@ THREAD_EXITED
Definition gdbthread.h:79
int valid_global_thread_id(int global_id)
Definition thread.c:621
int show_thread_that_caused_stop(void)
Definition thread.c:1450
struct thread_info * find_thread_global_id(int global_id)
Definition thread.c:539
const char * print_full_thread_id(struct thread_info *thr)
Definition thread.c:1485
struct thread_info * inferior_thread(void)
Definition thread.c:85
struct thread_info * iterate_over_threads(thread_callback_func, void *)
Definition thread.c:584
const char * thread_name(thread_info *thread)
Definition thread.c:2095
bool threads_are_executing(process_stratum_target *targ)
Definition thread.c:925
const char * print_thread_id(struct thread_info *thr)
Definition thread.c:1470
int is_scalar_type_recursive(struct type *t)
Definition gdbtypes.c:3706
struct type * check_typedef(struct type *type)
Definition gdbtypes.c:2966
mach_port_t kern_return_t mach_port_t mach_msg_type_name_t msgportsPoly mach_port_t kern_return_t pid_t pid mach_port_t kern_return_t mach_port_t task mach_port_t kern_return_t int flags
Definition gnu-nat.c:1861
ptid_t inferior_ptid
Definition infcmd.c:74
int number_of_inferiors(void)
Definition inferior.c:487
struct inferior * current_inferior(void)
Definition inferior.c:55
bool valid_global_inferior_id(int id)
Definition inferior.h:856
all_inferiors_range all_inferiors(process_stratum_target *proc_target=nullptr)
Definition inferior.h:821
int thread_is_stepping_over_breakpoint(int thread)
Definition infrun.c:1498
int stepping_past_instruction_at(struct address_space *aspace, CORE_ADDR address)
Definition infrun.c:1486
void clear_proceed_status(int step)
Definition infrun.c:2924
int stepping_past_nonsteppable_watchpoint(void)
Definition infrun.c:1507
int stop_on_solib_events
Definition infrun.c:375
void proceed(CORE_ADDR addr, enum gdb_signal siggnal)
Definition infrun.c:3395
#define INFRUN_SCOPED_DEBUG_ENTER_EXIT
Definition infrun.h:48
#define infrun_debug_printf(fmt,...)
Definition infrun.h:38
void interps_notify_breakpoint_created(breakpoint *b)
Definition interps.c:539
void interps_notify_breakpoint_modified(breakpoint *b)
Definition interps.c:555
struct interp * command_interp(void)
Definition interps.c:247
void interps_notify_breakpoint_deleted(breakpoint *b)
Definition interps.c:547
void jit_event_handler(gdbarch *gdbarch, objfile *jiter)
Definition jit.c:1250
void jit_breakpoint_re_set(void)
Definition jit.c:1230
static void set_language(const char *language)
Definition language.c:140
const struct language_defn * current_language
Definition language.c:82
static const char * range
Definition language.c:96
language_mode
Definition language.h:717
@ language_mode_manual
Definition language.h:718
std::vector< symtab_and_line > decode_line_1(const location_spec *locspec, int flags, struct program_space *search_pspace, struct symtab *default_symtab, int default_line)
Definition linespec.c:3194
void decode_line_full(struct location_spec *locspec, int flags, struct program_space *search_pspace, struct symtab *default_symtab, int default_line, struct linespec_result *canonical, const char *select_mode, const char *filter)
Definition linespec.c:3125
std::vector< symtab_and_line > decode_line_with_current_source(const char *string, int flags)
Definition linespec.c:3211
@ DECODE_LINE_FUNFIRSTLINE
Definition linespec.h:30
@ DECODE_LINE_LIST_MODE
Definition linespec.h:35
location_spec_up new_address_location_spec(CORE_ADDR addr, const char *addr_string, int addr_string_len)
Definition location.c:230
const linespec_location_spec * as_linespec_location_spec(const location_spec *locspec)
Definition location.c:221
location_spec_up string_to_location_spec(const char **stringp, const struct language_defn *language, symbol_name_match_type match_type)
Definition location.c:825
location_spec_up new_probe_location_spec(std::string &&probe)
Definition location.c:249
location_spec_up new_linespec_location_spec(const char **linespec, symbol_name_match_type match_type)
Definition location.c:211
std::unique_ptr< location_spec > location_spec_up
Definition location.h:71
@ LINE_OFFSET_NONE
Definition location.h:32
static location_spec_up new_explicit_location_spec_function(const char *function_name)
Definition location.h:287
location_spec_type
Definition location.h:56
@ LINESPEC_LOCATION_SPEC
Definition location.h:58
@ PROBE_LOCATION_SPEC
Definition location.h:67
static struct type * new_type(char *)
int memory_validate_breakpoint(struct gdbarch *gdbarch, struct bp_target_info *bp_tgt)
Definition mem-break.c:104
struct mem_region * lookup_mem_region(CORE_ADDR addr)
Definition memattr.c:163
@ MEM_RW
Definition memattr.h:26
int mem_ranges_overlap(CORE_ADDR start1, int len1, CORE_ADDR start2, int len2)
Definition memrange.c:25
bp_type
const char * async_reason_lookup(enum async_reply_reason reason)
Definition mi-common.c:50
async_reply_reason
Definition mi-common.h:26
@ EXEC_ASYNC_LOCATION_REACHED
Definition mi-common.h:32
@ EXEC_ASYNC_WATCHPOINT_SCOPE
Definition mi-common.h:33
@ EXEC_ASYNC_BREAKPOINT_HIT
Definition mi-common.h:27
@ EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
Definition mi-common.h:30
@ EXEC_ASYNC_WATCHPOINT_TRIGGER
Definition mi-common.h:28
@ EXEC_ASYNC_SOLIB_EVENT
Definition mi-common.h:39
@ EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
Definition mi-common.h:29
struct bound_minimal_symbol lookup_minimal_symbol(const char *name, const char *sfile, struct objfile *objf)
Definition minsyms.c:363
struct bound_minimal_symbol lookup_minimal_symbol_by_pc(CORE_ADDR pc)
Definition minsyms.c:996
struct bound_minimal_symbol lookup_minimal_symbol_text(const char *name, struct objfile *objf)
Definition minsyms.c:618
Definition ada-exp.h:87
observable< struct inferior *, CORE_ADDR, ssize_t, const bfd_byte * > memory_changed
observable< struct breakpoint * > breakpoint_created
observable< struct objfile * > free_objfile
observable< struct breakpoint * > breakpoint_modified
observable< struct breakpoint * > breakpoint_deleted
observable< struct inferior * > inferior_removed
observable about_to_proceed
observable< thread_info *, gdb::optional< ULONGEST >, bool > thread_exit
observable< struct program_space *, struct so_list * > solib_unloaded
bool process_options(const char **args, process_options_mode mode, gdb::array_view< const option_def_group > options_group)
Definition cli-option.c:627
@ PROCESS_OPTIONS_UNKNOWN_IS_ERROR
Definition cli-option.h:333
@ PROCESS_OPTIONS_UNKNOWN_IS_OPERAND
Definition cli-option.h:337
std::string build_help(const char *help_tmpl, gdb::array_view< const option_def_group > options_group)
Definition cli-option.c:766
void complete_on_all_options(completion_tracker &tracker, gdb::array_view< const option_def_group > options_group)
Definition cli-option.c:170
bool complete_options(completion_tracker &tracker, const char **args, process_options_mode mode, gdb::array_view< const option_def_group > options_group)
Definition cli-option.c:467
Definition aarch64.h:67
@ OBJF_USERLOADED
@ OBJF_SHARED
bool shared_objfile_contains_address_p(struct program_space *pspace, CORE_ADDR address)
Definition objfiles.c:1225
bool is_addr_in_objfile(CORE_ADDR addr, const struct objfile *objfile)
Definition objfiles.c:1206
std::vector< probe * > find_probes_in_objfile(struct objfile *objfile, const char *provider, const char *name)
Definition probe.c:216
std::vector< symtab_and_line > parse_probes(const location_spec *locspec, struct program_space *search_pspace, struct linespec_result *canonical)
Definition probe.c:117
void switch_to_program_space_and_thread(program_space *pspace)
struct program_space * current_program_space
Definition progspace.c:40
void set_current_program_space(struct program_space *pspace)
Definition progspace.c:243
std::vector< struct program_space * > program_spaces
Definition progspace.c:37
static gdbpy_ref field_name(struct type *type, int field)
Definition py-type.c:234
struct regcache * get_current_regcache(void)
Definition regcache.c:429
struct regcache * get_thread_regcache(process_stratum_target *target, ptid_t ptid)
Definition regcache.c:400
void(* func)(remote_target *remote, char *)
enum var_types type
Definition scm-param.c:142
#define enable()
Definition ser-go32.c:239
bool solib_contains_address_p(const struct so_list *const solib, CORE_ADDR address)
Definition solib.c:1175
const char * solib_name_from_address(struct program_space *pspace, CORE_ADDR address)
Definition solib.c:1200
void handle_solib_event(void)
Definition solib.c:1309
const char * symtab_to_fullname(struct symtab *s)
Definition source.c:1234
const char * symtab_to_filename_for_display(struct symtab *symtab)
Definition source.c:1269
struct symtab_and_line get_current_source_symtab_and_line(void)
Definition source.c:239
struct symtab * get_last_displayed_symtab(void)
Definition stack.c:1220
symtab_and_line get_last_displayed_sal()
Definition stack.c:1236
int get_last_displayed_line(void)
Definition stack.c:1228
bool last_displayed_sal_is_valid(void)
Definition stack.c:1196
Definition block.h:109
bool contains(const struct block *a, bool allow_nested=false) const
Definition block.c:68
struct symbol * linkage_function() const
Definition block.c:91
struct objfile * objfile
Definition minsyms.h:54
CORE_ADDR value_address() const
Definition minsyms.h:41
struct minimal_symbol * minsym
Definition minsyms.h:49
struct obj_section * obj_section() const
Definition minsyms.h:58
probe * prob
Definition probe.h:255
struct objfile * objfile
Definition probe.h:258
static void decref(bp_location *loc)
Definition breakpoint.h:526
bp_locations_at_addr_range(CORE_ADDR addr)
Definition breakpoint.c:744
std::vector< bp_location * >::iterator iterator
Definition breakpoint.c:742
iterator begin() const
Definition breakpoint.c:762
std::vector< agent_expr * > conditions
Definition breakpoint.h:290
std::vector< agent_expr * > tcommands
Definition breakpoint.h:294
CORE_ADDR placed_address
Definition breakpoint.h:266
CORE_ADDR reqstd_address
Definition breakpoint.h:269
struct address_space * placed_address_space
Definition breakpoint.h:259
enum stop_stack_kind call_dummy
enum bpstat_what_main_action main_action
value_ref_ptr old_val
bp_location_ref_ptr bp_location_at
bpstat * next
enum bp_print_how print_it
bool stop
counted_command_line commands
bool print
struct breakpoint * breakpoint_at
struct bound_minimal_symbol terminate_msym
std::vector< probe * > exception_probes
struct bound_minimal_symbol overlay_msym
struct bound_minimal_symbol exception_msym
std::vector< probe * > longjmp_probes
struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES]
void(* create_sals_from_location_spec)(location_spec *locspec, struct linespec_result *canonical)
Definition breakpoint.h:572
void(* create_breakpoints_sal)(struct gdbarch *, struct linespec_result *, gdb::unique_xmalloc_ptr< char >, gdb::unique_xmalloc_ptr< char >, enum bptype, enum bpdisp, int, int, int, int, int, int, int, unsigned)
Definition breakpoint.h:582
counted_command_line commands
Definition breakpoint.h:821
virtual int breakpoint_hit(const struct bp_location *bl, const address_space *aspace, CORE_ADDR bp_addr, const target_waitstatus &ws)
breakpoint(struct gdbarch *gdbarch_, enum bptype bptype, bool temp=true, const char *cond_string=nullptr)
int ignore_count
Definition breakpoint.h:813
bp_location_list steal_locations(program_space *pspace)
bp_location_list m_locations
Definition breakpoint.h:907
int enable_count
Definition breakpoint.h:817
virtual void print_recreate(struct ui_file *fp) const
virtual int resources_needed(const struct bp_location *)
bptype type
Definition breakpoint.h:798
virtual ~breakpoint()=0
Definition breakpoint.c:313
location_spec_up locspec
Definition breakpoint.h:832
bp_location_range locations() const
virtual void check_status(struct bpstat *bs)
Definition breakpoint.h:737
gdb::unique_xmalloc_ptr< char > cond_string
Definition breakpoint.h:850
void print_recreate_thread(struct ui_file *fp) const
virtual int insert_location(struct bp_location *)
void clear_locations()
Definition breakpoint.h:652
virtual enum print_stop_action print_it(const bpstat *bs) const
breakpoint * related_breakpoint
Definition breakpoint.h:860
int condition_not_parsed
Definition breakpoint.h:883
bool has_locations() const
Definition breakpoint.h:661
virtual struct bp_location * allocate_location()
gdb::unique_xmalloc_ptr< char > filter
Definition breakpoint.h:836
bp_location & first_loc()
Definition breakpoint.h:683
virtual void re_set()
Definition breakpoint.h:706
void unadd_location(bp_location &loc)
virtual bool print_one(const bp_location **) const
Definition breakpoint.h:754
virtual bool explains_signal(enum gdb_signal)
Definition breakpoint.h:785
bool has_multiple_locations() const
Definition breakpoint.h:674
virtual int remove_location(struct bp_location *, enum remove_bp_reason reason)
virtual void print_one_detail(struct ui_out *) const
Definition breakpoint.h:771
void add_location(bp_location &loc)
virtual void print_mention() const
struct gdbarch * gdbarch
Definition breakpoint.h:843
gdb::unique_xmalloc_ptr< char > extra_string
Definition breakpoint.h:854
bool has_single_location() const
Definition breakpoint.h:665
const bp_location & last_loc() const
Definition breakpoint.h:697
program_space * pspace
Definition breakpoint.h:829
enum enable_state enable_state
Definition breakpoint.h:800
int input_radix
Definition breakpoint.h:847
enum language language
Definition breakpoint.h:845
virtual void after_condition_true(struct bpstat *bs)
Definition breakpoint.h:792
bpdisp disposition
Definition breakpoint.h:802
location_spec_up locspec_range_end
Definition breakpoint.h:840
struct frame_id frame_id
Definition breakpoint.h:824
bool display_canonical
Definition breakpoint.h:810
~catchpoint() override=0
Definition breakpoint.c:321
catchpoint(struct gdbarch *gdbarch, bool temp, const char *cond_string)
cmd_func_ftype * func
Definition cli-decode.h:175
completer_ftype * completer
Definition cli-decode.h:220
void set_context(void *context)
Definition cli-decode.h:103
~code_breakpoint() override=0
Definition breakpoint.c:317
int breakpoint_hit(const struct bp_location *bl, const address_space *aspace, CORE_ADDR bp_addr, const target_waitstatus &ws) override
virtual std::vector< symtab_and_line > decode_location_spec(location_spec *locspec, struct program_space *search_pspace)
bp_location * add_location(const symtab_and_line &sal)
void re_set() override
int insert_location(struct bp_location *) override
std::vector< symtab_and_line > location_spec_to_sals(location_spec *locspec, struct program_space *search_pspace, int *found)
code_breakpoint(struct gdbarch *gdbarch, bptype type, gdb::array_view< const symtab_and_line > sals, location_spec_up &&locspec, gdb::unique_xmalloc_ptr< char > filter, gdb::unique_xmalloc_ptr< char > cond_string, gdb::unique_xmalloc_ptr< char > extra_string, enum bpdisp disposition, int thread, int task, int inferior, int ignore_count, int from_tty, int enabled, unsigned flags, int display_canonical)
int remove_location(struct bp_location *, enum remove_bp_reason reason) override
void say_where() const
counted_command_line body_list_0
Definition cli-script.h:102
counted_command_line body_list_1
Definition cli-script.h:103
struct command_line * next
Definition cli-script.h:86
enum command_control_type control_type
Definition cli-script.h:88
char * line
Definition cli-script.h:87
struct objfile * objfile() const
Definition symtab.h:1788
void after_condition_true(struct bpstat *bs) override
void print_recreate(struct ui_file *fp) const override
int breakpoint_hit(const struct bp_location *bl, const address_space *aspace, CORE_ADDR bp_addr, const target_waitstatus &ws) override
void re_set() override
struct value * evaluate(struct type *expect_type=nullptr, enum noside noside=EVAL_NORMAL)
Definition eval.c:103
expr::operation_up op
Definition expression.h:238
CORE_ADDR stack_addr
Definition frame-id.h:68
std::string to_string() const
Definition frame.c:407
const char * print_name() const
Definition symtab.h:475
struct obj_section * obj_section(const struct objfile *objfile) const
Definition symtab.c:1117
Definition gnu-nat.c:153
enum print_stop_action print_it(const bpstat *bs) const override
void check_status(struct bpstat *bs) override
void re_set() override
void print_mention() const override
internal_breakpoint(struct gdbarch *gdbarch, enum bptype type, CORE_ADDR address)
Definition breakpoint.c:342
enum language lang
virtual gdb::unique_xmalloc_ptr< char > watch_location_expression(struct type *type, CORE_ADDR addr) const
Definition language.c:575
bool special_display
Definition linespec.h:65
std::vector< linespec_sals > lsals
Definition linespec.h:78
bool pre_expanded
Definition linespec.h:71
location_spec_up locspec
Definition linespec.h:75
std::vector< symtab_and_line > sals
Definition linespec.h:49
char * canonical
Definition linespec.h:46
enum location_spec_type type() const
Definition location.h:108
~longjmp_breakpoint() override
enum print_stop_action print_it(const bpstat *bs) const override
int remove_location(struct bp_location *, enum remove_bp_reason reason) override
void print_recreate(struct ui_file *fp) const override
void print_mention() const override
void print_one_detail(struct ui_out *) const override
int resources_needed(const struct bp_location *) override
bool works_in_software_mode() const override
int insert_location(struct bp_location *) override
enum mem_access_mode mode
Definition memattr.h:65
mem_attrib attrib
Definition memattr.h:125
void check_status(struct bpstat *bs) override
void re_set() override
enum print_stop_action print_it(const bpstat *bs) const override
momentary_breakpoint(struct gdbarch *gdbarch_, enum bptype bptype, program_space *pspace_, const struct frame_id &frame_id_, int thread_)
Definition breakpoint.c:370
void print_mention() const override
struct objfile * objfile
Definition objfiles.h:401
struct objfile * separate_debug_objfile_backlink
Definition objfiles.h:830
struct program_space * pspace
Definition objfiles.h:728
struct gdbarch * arch() const
Definition objfiles.h:507
objfile_flags flags
Definition objfiles.h:724
void print_recreate(struct ui_file *fp) const override
void print_mention() const override
enum print_stop_action print_it(const bpstat *bs) const override
int resources_needed(const struct bp_location *) override
objfiles_range objfiles()
Definition progspace.h:209
std::vector< std::string > deleted_solibs
Definition progspace.h:375
std::vector< struct so_list * > added_solibs
Definition progspace.h:371
int executing_startup
Definition progspace.h:349
int breakpoints_not_allowed
Definition progspace.h:353
struct address_space * aspace
Definition progspace.h:339
Definition value.h:90
enum print_stop_action print_it(const bpstat *bs) const override
void print_mention() const override
int resources_needed(const struct bp_location *) override
bool print_one(const bp_location **) const override
ranged_breakpoint(struct gdbarch *gdbarch, const symtab_and_line &sal_start, int length, location_spec_up start_locspec, location_spec_up end_locspec)
Definition breakpoint.c:416
void print_one_detail(struct ui_out *) const override
void print_recreate(struct ui_file *fp) const override
int breakpoint_hit(const struct bp_location *bl, const address_space *aspace, CORE_ADDR bp_addr, const target_waitstatus &ws) override
char so_name[SO_NAME_MAX_PATH_SIZE]
Definition solist.h:56
std::vector< symtab_and_line > decode_location_spec(struct location_spec *locspec, struct program_space *search_pspace) override
const block * value_block() const
Definition symtab.h:1549
symbol()
Definition symtab.h:1237
bool explicit_line
Definition symtab.h:2340
struct obj_section * section
Definition symtab.h:2330
struct objfile * objfile
Definition symtab.h:2350
struct symbol * symbol
Definition symtab.h:2329
probe * prob
Definition symtab.h:2347
struct symtab * symtab
Definition symtab.h:2328
CORE_ADDR pc
Definition symtab.h:2337
struct program_space * pspace
Definition symtab.h:2326
struct minimal_symbol * msymbol
Definition symtab.h:2331
struct compunit_symtab * compunit() const
Definition symtab.h:1677
enum gdb_signal sig
Definition waitstatus.h:414
target_waitkind kind() const
Definition waitstatus.h:345
struct breakpoint * single_step_breakpoints
Definition gdbthread.h:112
void set_finished()
Definition thread-fsm.h:82
std::string static_trace_marker_id
void print_recreate(struct ui_file *fp) const override
long step_count
int number_on_target
ULONGEST traceframe_usage
int breakpoint_hit(const struct bp_location *bl, const address_space *aspace, CORE_ADDR bp_addr, const target_waitstatus &ws) override
int static_trace_marker_id_idx
void print_one_detail(struct ui_out *uiout) const override
void print_mention() const override
type_code code() const
Definition gdbtypes.h:956
ULONGEST length() const
Definition gdbtypes.h:983
int async
Definition ui.h:106
void clean_up(struct thread_info *thread) override
until_break_fsm(struct interp *cmd_interp, int thread, std::vector< breakpoint_up > &&breakpoints)
std::vector< breakpoint_up > breakpoints
bool should_stop(struct thread_info *thread) override
enum async_reply_reason do_async_reply_reason() override
std::vector< gdb::unique_xmalloc_ptr< char[]> > cmd_strings
Definition tracepoint.h:195
gdb::unique_xmalloc_ptr< char[]> cond_string
Definition tracepoint.h:192
enum bptype type
Definition tracepoint.h:173
std::vector< gdb::unique_xmalloc_ptr< char[]> > step_actions
Definition tracepoint.h:186
ULONGEST traceframe_usage
Definition tracepoint.h:201
std::vector< gdb::unique_xmalloc_ptr< char[]> > actions
Definition tracepoint.h:185
ULONGEST addr
Definition tracepoint.h:174
gdb::unique_xmalloc_ptr< char[]> at_string
Definition tracepoint.h:189
gdb::unique_xmalloc_ptr< char[]> cond
Definition tracepoint.h:181
Definition value.h:130
void unpack_bitfield(struct value *dest_val, LONGEST bitpos, LONGEST bitsize, const gdb_byte *valaddr, LONGEST embedded_offset) const
Definition value.c:3215
LONGEST bitsize() const
Definition value.h:193
bool deprecated_modifiable() const
Definition value.h:231
bool lazy() const
Definition value.h:265
static struct value * allocate(struct type *type)
Definition value.c:957
LONGEST bitpos() const
Definition value.h:202
struct type * type() const
Definition value.h:180
LONGEST offset() const
Definition value.h:222
enum lval_type lval() const
Definition value.h:332
CORE_ADDR address
Definition value.h:658
gdb::array_view< const gdb_byte > contents_for_printing()
Definition value.c:1100
ptid_t watchpoint_thread
int insert_location(struct bp_location *) override
int breakpoint_hit(const struct bp_location *bl, const address_space *aspace, CORE_ADDR bp_addr, const target_waitstatus &ws) override
void check_status(struct bpstat *bs) override
struct frame_id watchpoint_frame
int remove_location(struct bp_location *, enum remove_bp_reason reason) override
virtual bool works_in_software_mode() const
void re_set() override
gdb::unique_xmalloc_ptr< char > exp_string
gdb::unique_xmalloc_ptr< char > exp_string_reparse
enum print_stop_action print_it(const bpstat *bs) const override
expression_up exp
CORE_ADDR hw_wp_mask
bool explains_signal(enum gdb_signal) override
expression_up cond_exp
void print_mention() const override
int resources_needed(const struct bp_location *) override
const struct block * exp_valid_block
const struct block * cond_exp_valid_block
void print_recreate(struct ui_file *fp) const override
enum watchpoint_triggered watchpoint_triggered
value_ref_ptr val
struct obj_section * find_pc_overlay(CORE_ADDR pc)
Definition symfile.c:3174
CORE_ADDR overlay_unmapped_address(CORE_ADDR pc, struct obj_section *section)
Definition symfile.c:3108
int section_is_mapped(struct obj_section *osect)
Definition symfile.c:3019
int section_is_overlay(struct obj_section *section)
Definition symfile.c:2983
enum overlay_debugging_state overlay_debugging
Definition symfile.c:2975
@ ovly_auto
Definition symfile.h:296
@ ovly_off
Definition symfile.h:294
bool find_line_pc(struct symtab *symtab, int line, CORE_ADDR *pc)
Definition symtab.c:3472
const char multiple_symbols_all[]
Definition symtab.c:277
bool find_line_pc_range(struct symtab_and_line sal, CORE_ADDR *startptr, CORE_ADDR *endptr)
Definition symtab.c:3499
void skip_prologue_sal(struct symtab_and_line *sal)
Definition symtab.c:3764
struct symtab_and_line find_pc_line(CORE_ADDR pc, int notcurrent)
Definition symtab.c:3295
bool find_line_pc(struct symtab *, int, CORE_ADDR *)
Definition symtab.c:3472
#define gnu_ifunc_resolver_return_stop
Definition symtab.h:2316
struct symbol * find_pc_sect_function(CORE_ADDR, struct obj_section *)
Definition blockframe.c:136
@ mst_data_gnu_ifunc
Definition symtab.h:690
@ mst_file_text
Definition symtab.h:708
@ mst_text
Definition symtab.h:672
@ mst_text_gnu_ifunc
Definition symtab.h:681
struct symtab_and_line find_pc_line(CORE_ADDR, int)
Definition symtab.c:3295
#define gnu_ifunc_resolver_stop
Definition symtab.h:2315
std::vector< static_tracepoint_marker > target_static_tracepoint_markers_by_strid(const char *marker_id)
Definition target.c:783
int target_insert_hw_breakpoint(gdbarch *gdbarch, bp_target_info *bp_tgt)
Definition target.c:565
int target_region_ok_for_hw_watchpoint(CORE_ADDR addr, int len)
Definition target.c:526
int target_remove_hw_breakpoint(gdbarch *gdbarch, bp_target_info *bp_tgt)
Definition target.c:575
bool target_supports_stopped_by_hw_breakpoint()
Definition target.c:498
bool target_can_run_breakpoint_commands()
Definition target.c:290
int target_remove_mask_watchpoint(CORE_ADDR addr, CORE_ADDR mask, enum target_hw_bp_type rw)
Definition target.c:4017
void target_enable_tracepoint(bp_location *loc)
Definition target.c:640
int target_insert_breakpoint(struct gdbarch *gdbarch, struct bp_target_info *bp_tgt)
Definition target.c:2376
bool target_can_download_tracepoint()
Definition target.c:626
int target_insert_watchpoint(CORE_ADDR addr, int len, target_hw_bp_type type, expression *cond)
Definition target.c:543
bool target_static_tracepoint_marker_at(CORE_ADDR addr, static_tracepoint_marker *marker)
Definition target.c:774
int target_can_use_hardware_watchpoint(bptype type, int cnt, int othertype)
Definition target.c:516
bool target_has_execution(inferior *inf)
Definition target.c:201
void target_disable_tracepoint(bp_location *loc)
Definition target.c:646
void target_download_tracepoint(bp_location *location)
Definition target.c:620
bool target_supports_stopped_by_sw_breakpoint()
Definition target.c:484
int target_insert_mask_watchpoint(CORE_ADDR addr, CORE_ADDR mask, enum target_hw_bp_type rw)
Definition target.c:4005
int target_masked_watch_num_registers(CORE_ADDR addr, CORE_ADDR mask)
Definition target.c:4029
bool target_is_non_stop_p()
Definition target.c:4394
int target_remove_breakpoint(struct gdbarch *gdbarch, struct bp_target_info *bp_tgt, enum remove_bp_reason reason)
Definition target.c:2393
bool target_can_accel_watchpoint_condition(CORE_ADDR addr, int len, int type, expression *cond)
Definition target.c:585
int target_ranged_break_num_registers(void)
Definition target.c:4040
bool target_stopped_by_watchpoint()
Definition target.c:470
bool target_supports_evaluation_of_breakpoint_conditions()
Definition target.c:264
bool target_supports_enable_disable_tracepoint()
Definition target.c:248
int target_remove_watchpoint(CORE_ADDR addr, int len, target_hw_bp_type type, expression *cond)
Definition target.c:554
#define target_stopped_data_address(target, addr_p)
Definition target.h:2106
bool may_insert_fast_tracepoints
@ TARGET_XFER_E_IO
Definition target.h:232
bool may_insert_tracepoints
#define target_watchpoint_addr_within_range(target, addr, start, length)
Definition target.h:2111
struct thread_info * parse_thread_id(const char *tidstr, const char **end)
Definition tid-parse.c:54
bool server_command
Definition top.c:173
struct trace_status * current_trace_status(void)
Definition tracepoint.c:175
void save_trace_state_variables(struct ui_file *fp)
Definition tracepoint.c:476
void validate_actionline(const char *line, tracepoint *t)
Definition tracepoint.c:629
std::string default_collect
Definition tracepoint.c:130
static signed_field_s * signed_field(const char *name, LONGEST val, signed_field_s &&tmp={})
Definition ui-out.h:105
static styled_string_s * styled_string(const ui_file_style &style, const char *str, styled_string_s &&tmp={})
Definition ui-out.h:151
@ ui_noalign
Definition ui-out.h:48
@ ui_left
Definition ui-out.h:45
@ fix_multi_location_breakpoint_output
Definition ui-out.h:55
@ fix_breakpoint_script_output
Definition ui-out.h:59
#define current_uiout
Definition ui-out.h:40
static string_field_s * string_field(const char *name, const char *str, string_field_s &&tmp={})
Definition ui-out.h:126
struct ui * current_ui
Definition ui.c:35
#define SWITCH_THRU_ALL_UIS()
Definition ui.h:215
int nquery(const char *ctlstr,...)
Definition utils.c:908
const char * print_core_address(struct gdbarch *gdbarch, CORE_ADDR address)
Definition utils.c:3187
int query(const char *ctlstr,...)
Definition utils.c:943
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
Definition utils.c:3166
void gdb_putc(int c)
Definition utils.c:1862
void fprintf_styled(struct ui_file *stream, const ui_file_style &style, const char *format,...)
Definition utils.c:1898
void gdb_printf(struct ui_file *stream, const char *format,...)
Definition utils.c:1886
#define gdb_stderr
Definition utils.h:187
int value_equal_contents(struct value *arg1, struct value *arg2)
Definition valarith.c:1630
struct value * value_addr(struct value *arg1)
Definition valops.c:1551
void value_print(struct value *val, struct ui_file *stream, const struct value_print_options *options)
Definition valprint.c:1191
void get_user_print_options(struct value_print_options *opts)
Definition valprint.c:135
CORE_ADDR value_as_address(struct value *val)
Definition value.c:2636
void complete_internalvar(completion_tracker &tracker, const char *name)
Definition value.c:1931
struct internalvar * lookup_internalvar(const char *name)
Definition value.c:2001
LONGEST value_as_long(struct value *val)
Definition value.c:2554
void set_internalvar_integer(struct internalvar *var, LONGEST l)
Definition value.c:2232
struct value * value_mark(void)
Definition value.c:1414
void value_free_to_mark(const struct value *mark)
Definition value.c:1437
value_ref_ptr release_value(struct value *val)
Definition value.c:1450
static bool value_true(struct value *val)
Definition value.h:1461
gdb::ref_ptr< struct value, value_ref_policy > value_ref_ptr
Definition value.h:124
target_waitkind
Definition waitstatus.h:30
@ TARGET_WAITKIND_LOADED
Definition waitstatus.h:44
@ TARGET_WAITKIND_STOPPED
Definition waitstatus.h:36
#define nullptr
Definition x86-cpuid.h:28