1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2013 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
21 #include "arch-utils.h"
26 #include "breakpoint.h"
27 #include "tracepoint.h"
29 #include "expression.h"
35 #include "gdbthread.h"
38 #include "gdb_string.h"
39 #include "gdb-demangle.h"
40 #include "filenames.h"
46 #include "completer.h"
49 #include "cli/cli-script.h"
50 #include "gdb_assert.h"
55 #include "exceptions.h"
61 #include "xml-syscall.h"
62 #include "parser-defs.h"
63 #include "gdb_regex.h"
65 #include "cli/cli-utils.h"
66 #include "continuations.h"
69 #include "gdb_regex.h"
71 #include "dummy-frame.h"
75 /* readline include files */
76 #include "readline/readline.h"
77 #include "readline/history.h"
79 /* readline defines this. */
82 #include "mi/mi-common.h"
83 #include "python/python.h"
85 /* Enums for exception-handling support. */
86 enum exception_event_kind
93 /* Prototypes for local functions. */
95 static void enable_delete_command (char *, int);
97 static void enable_once_command (char *, int);
99 static void enable_count_command (char *, int);
101 static void disable_command (char *, int);
103 static void enable_command (char *, int);
105 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *,
109 static void ignore_command (char *, int);
111 static int breakpoint_re_set_one (void *);
113 static void breakpoint_re_set_default (struct breakpoint *);
115 static void create_sals_from_address_default (char **,
116 struct linespec_result *,
120 static void create_breakpoints_sal_default (struct gdbarch *,
121 struct linespec_result *,
122 struct linespec_sals *,
123 char *, char *, enum bptype,
124 enum bpdisp, int, int,
126 const struct breakpoint_ops *,
127 int, int, int, unsigned);
129 static void decode_linespec_default (struct breakpoint *, char **,
130 struct symtabs_and_lines *);
132 static void clear_command (char *, int);
134 static void catch_command (char *, int);
136 static int can_use_hardware_watchpoint (struct value *);
138 static void break_command_1 (char *, int, int);
140 static void mention (struct breakpoint *);
142 static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *,
144 const struct breakpoint_ops *);
145 static struct bp_location *add_location_to_breakpoint (struct breakpoint *,
146 const struct symtab_and_line *);
148 /* This function is used in gdbtk sources and thus can not be made
150 struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch,
151 struct symtab_and_line,
153 const struct breakpoint_ops *);
155 static struct breakpoint *
156 momentary_breakpoint_from_master (struct breakpoint *orig,
158 const struct breakpoint_ops *ops);
160 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
162 static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch,
166 static void describe_other_breakpoints (struct gdbarch *,
167 struct program_space *, CORE_ADDR,
168 struct obj_section *, int);
170 static int breakpoint_address_match (struct address_space *aspace1,
172 struct address_space *aspace2,
175 static int watchpoint_locations_match (struct bp_location *loc1,
176 struct bp_location *loc2);
178 static int breakpoint_location_address_match (struct bp_location *bl,
179 struct address_space *aspace,
182 static void breakpoints_info (char *, int);
184 static void watchpoints_info (char *, int);
186 static int breakpoint_1 (char *, int,
187 int (*) (const struct breakpoint *));
189 static int breakpoint_cond_eval (void *);
191 static void cleanup_executing_breakpoints (void *);
193 static void commands_command (char *, int);
195 static void condition_command (char *, int);
204 static int remove_breakpoint (struct bp_location *, insertion_state_t);
205 static int remove_breakpoint_1 (struct bp_location *, insertion_state_t);
207 static enum print_stop_action print_bp_stop_message (bpstat bs);
209 static int watchpoint_check (void *);
211 static void maintenance_info_breakpoints (char *, int);
213 static int hw_breakpoint_used_count (void);
215 static int hw_watchpoint_use_count (struct breakpoint *);
217 static int hw_watchpoint_used_count_others (struct breakpoint *except,
219 int *other_type_used);
221 static void hbreak_command (char *, int);
223 static void thbreak_command (char *, int);
225 static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp,
228 static void stop_command (char *arg, int from_tty);
230 static void stopin_command (char *arg, int from_tty);
232 static void stopat_command (char *arg, int from_tty);
234 static char *ep_parse_optional_if_clause (char **arg);
236 static void catch_exception_command_1 (enum exception_event_kind ex_event,
237 char *arg, int tempflag, int from_tty);
239 static void tcatch_command (char *arg, int from_tty);
241 static void detach_single_step_breakpoints (void);
243 static int single_step_breakpoint_inserted_here_p (struct address_space *,
246 static void free_bp_location (struct bp_location *loc);
247 static void incref_bp_location (struct bp_location *loc);
248 static void decref_bp_location (struct bp_location **loc);
250 static struct bp_location *allocate_bp_location (struct breakpoint *bpt);
252 static void update_global_location_list (int);
254 static void update_global_location_list_nothrow (int);
256 static int is_hardware_watchpoint (const struct breakpoint *bpt);
258 static void insert_breakpoint_locations (void);
260 static int syscall_catchpoint_p (struct breakpoint *b);
262 static void tracepoints_info (char *, int);
264 static void delete_trace_command (char *, int);
266 static void enable_trace_command (char *, int);
268 static void disable_trace_command (char *, int);
270 static void trace_pass_command (char *, int);
272 static void set_tracepoint_count (int num);
274 static int is_masked_watchpoint (const struct breakpoint *b);
276 static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address);
278 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
281 static int strace_marker_p (struct breakpoint *b);
283 /* The abstract base class all breakpoint_ops structures inherit
285 struct breakpoint_ops base_breakpoint_ops;
287 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
288 that are implemented on top of software or hardware breakpoints
289 (user breakpoints, internal and momentary breakpoints, etc.). */
290 static struct breakpoint_ops bkpt_base_breakpoint_ops;
292 /* Internal breakpoints class type. */
293 static struct breakpoint_ops internal_breakpoint_ops;
295 /* Momentary breakpoints class type. */
296 static struct breakpoint_ops momentary_breakpoint_ops;
298 /* Momentary breakpoints for bp_longjmp and bp_exception class type. */
299 static struct breakpoint_ops longjmp_breakpoint_ops;
301 /* The breakpoint_ops structure to be used in regular user created
303 struct breakpoint_ops bkpt_breakpoint_ops;
305 /* Breakpoints set on probes. */
306 static struct breakpoint_ops bkpt_probe_breakpoint_ops;
308 /* Dynamic printf class type. */
309 static struct breakpoint_ops dprintf_breakpoint_ops;
311 /* The style in which to perform a dynamic printf. This is a user
312 option because different output options have different tradeoffs;
313 if GDB does the printing, there is better error handling if there
314 is a problem with any of the arguments, but using an inferior
315 function lets you have special-purpose printers and sending of
316 output to the same place as compiled-in print functions. */
318 static const char dprintf_style_gdb[] = "gdb";
319 static const char dprintf_style_call[] = "call";
320 static const char dprintf_style_agent[] = "agent";
321 static const char *const dprintf_style_enums[] = {
327 static const char *dprintf_style = dprintf_style_gdb;
329 /* The function to use for dynamic printf if the preferred style is to
330 call into the inferior. The value is simply a string that is
331 copied into the command, so it can be anything that GDB can
332 evaluate to a callable address, not necessarily a function name. */
334 static char *dprintf_function = "";
336 /* The channel to use for dynamic printf if the preferred style is to
337 call into the inferior; if a nonempty string, it will be passed to
338 the call as the first argument, with the format string as the
339 second. As with the dprintf function, this can be anything that
340 GDB knows how to evaluate, so in addition to common choices like
341 "stderr", this could be an app-specific expression like
342 "mystreams[curlogger]". */
344 static char *dprintf_channel = "";
346 /* True if dprintf commands should continue to operate even if GDB
348 static int disconnected_dprintf = 1;
350 /* A reference-counted struct command_line. This lets multiple
351 breakpoints share a single command list. */
352 struct counted_command_line
354 /* The reference count. */
357 /* The command list. */
358 struct command_line *commands;
361 struct command_line *
362 breakpoint_commands (struct breakpoint *b)
364 return b->commands ? b->commands->commands : NULL;
367 /* Flag indicating that a command has proceeded the inferior past the
368 current breakpoint. */
370 static int breakpoint_proceeded;
373 bpdisp_text (enum bpdisp disp)
375 /* NOTE: the following values are a part of MI protocol and
376 represent values of 'disp' field returned when inferior stops at
378 static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"};
380 return bpdisps[(int) disp];
383 /* Prototypes for exported functions. */
384 /* If FALSE, gdb will not use hardware support for watchpoints, even
385 if such is available. */
386 static int can_use_hw_watchpoints;
389 show_can_use_hw_watchpoints (struct ui_file *file, int from_tty,
390 struct cmd_list_element *c,
393 fprintf_filtered (file,
394 _("Debugger's willingness to use "
395 "watchpoint hardware is %s.\n"),
399 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
400 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
401 for unrecognized breakpoint locations.
402 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
403 static enum auto_boolean pending_break_support;
405 show_pending_break_support (struct ui_file *file, int from_tty,
406 struct cmd_list_element *c,
409 fprintf_filtered (file,
410 _("Debugger's behavior regarding "
411 "pending breakpoints is %s.\n"),
415 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
416 set with "break" but falling in read-only memory.
417 If 0, gdb will warn about such breakpoints, but won't automatically
418 use hardware breakpoints. */
419 static int automatic_hardware_breakpoints;
421 show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty,
422 struct cmd_list_element *c,
425 fprintf_filtered (file,
426 _("Automatic usage of hardware breakpoints is %s.\n"),
430 /* If on, gdb will keep breakpoints inserted even as inferior is
431 stopped, and immediately insert any new breakpoints. If off, gdb
432 will insert breakpoints into inferior only when resuming it, and
433 will remove breakpoints upon stop. If auto, GDB will behave as ON
434 if in non-stop mode, and as OFF if all-stop mode.*/
436 static enum auto_boolean always_inserted_mode = AUTO_BOOLEAN_AUTO;
439 show_always_inserted_mode (struct ui_file *file, int from_tty,
440 struct cmd_list_element *c, const char *value)
442 if (always_inserted_mode == AUTO_BOOLEAN_AUTO)
443 fprintf_filtered (file,
444 _("Always inserted breakpoint "
445 "mode is %s (currently %s).\n"),
447 breakpoints_always_inserted_mode () ? "on" : "off");
449 fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"),
454 breakpoints_always_inserted_mode (void)
456 return (always_inserted_mode == AUTO_BOOLEAN_TRUE
457 || (always_inserted_mode == AUTO_BOOLEAN_AUTO && non_stop));
460 static const char condition_evaluation_both[] = "host or target";
462 /* Modes for breakpoint condition evaluation. */
463 static const char condition_evaluation_auto[] = "auto";
464 static const char condition_evaluation_host[] = "host";
465 static const char condition_evaluation_target[] = "target";
466 static const char *const condition_evaluation_enums[] = {
467 condition_evaluation_auto,
468 condition_evaluation_host,
469 condition_evaluation_target,
473 /* Global that holds the current mode for breakpoint condition evaluation. */
474 static const char *condition_evaluation_mode_1 = condition_evaluation_auto;
476 /* Global that we use to display information to the user (gets its value from
477 condition_evaluation_mode_1. */
478 static const char *condition_evaluation_mode = condition_evaluation_auto;
480 /* Translate a condition evaluation mode MODE into either "host"
481 or "target". This is used mostly to translate from "auto" to the
482 real setting that is being used. It returns the translated
486 translate_condition_evaluation_mode (const char *mode)
488 if (mode == condition_evaluation_auto)
490 if (target_supports_evaluation_of_breakpoint_conditions ())
491 return condition_evaluation_target;
493 return condition_evaluation_host;
499 /* Discovers what condition_evaluation_auto translates to. */
502 breakpoint_condition_evaluation_mode (void)
504 return translate_condition_evaluation_mode (condition_evaluation_mode);
507 /* Return true if GDB should evaluate breakpoint conditions or false
511 gdb_evaluates_breakpoint_condition_p (void)
513 const char *mode = breakpoint_condition_evaluation_mode ();
515 return (mode == condition_evaluation_host);
518 void _initialize_breakpoint (void);
520 /* Are we executing breakpoint commands? */
521 static int executing_breakpoint_commands;
523 /* Are overlay event breakpoints enabled? */
524 static int overlay_events_enabled;
526 /* See description in breakpoint.h. */
527 int target_exact_watchpoints = 0;
529 /* Walk the following statement or block through all breakpoints.
530 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
531 current breakpoint. */
533 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
535 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
536 for (B = breakpoint_chain; \
537 B ? (TMP=B->next, 1): 0; \
540 /* Similar iterator for the low-level breakpoints. SAFE variant is
541 not provided so update_global_location_list must not be called
542 while executing the block of ALL_BP_LOCATIONS. */
544 #define ALL_BP_LOCATIONS(B,BP_TMP) \
545 for (BP_TMP = bp_location; \
546 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
549 /* Iterates through locations with address ADDRESS for the currently selected
550 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
551 to where the loop should start from.
552 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
553 appropriate location to start with. */
555 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
556 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
557 BP_LOCP_TMP = BP_LOCP_START; \
559 && (BP_LOCP_TMP < bp_location + bp_location_count \
560 && (*BP_LOCP_TMP)->address == ADDRESS); \
563 /* Iterator for tracepoints only. */
565 #define ALL_TRACEPOINTS(B) \
566 for (B = breakpoint_chain; B; B = B->next) \
567 if (is_tracepoint (B))
569 /* Chains of all breakpoints defined. */
571 struct breakpoint *breakpoint_chain;
573 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
575 static struct bp_location **bp_location;
577 /* Number of elements of BP_LOCATION. */
579 static unsigned bp_location_count;
581 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
582 ADDRESS for the current elements of BP_LOCATION which get a valid
583 result from bp_location_has_shadow. You can use it for roughly
584 limiting the subrange of BP_LOCATION to scan for shadow bytes for
585 an address you need to read. */
587 static CORE_ADDR bp_location_placed_address_before_address_max;
589 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
590 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
591 BP_LOCATION which get a valid result from bp_location_has_shadow.
592 You can use it for roughly limiting the subrange of BP_LOCATION to
593 scan for shadow bytes for an address you need to read. */
595 static CORE_ADDR bp_location_shadow_len_after_address_max;
597 /* The locations that no longer correspond to any breakpoint, unlinked
598 from bp_location array, but for which a hit may still be reported
600 VEC(bp_location_p) *moribund_locations = NULL;
602 /* Number of last breakpoint made. */
604 static int breakpoint_count;
606 /* The value of `breakpoint_count' before the last command that
607 created breakpoints. If the last (break-like) command created more
608 than one breakpoint, then the difference between BREAKPOINT_COUNT
609 and PREV_BREAKPOINT_COUNT is more than one. */
610 static int prev_breakpoint_count;
612 /* Number of last tracepoint made. */
614 static int tracepoint_count;
616 static struct cmd_list_element *breakpoint_set_cmdlist;
617 static struct cmd_list_element *breakpoint_show_cmdlist;
618 struct cmd_list_element *save_cmdlist;
620 /* Return whether a breakpoint is an active enabled breakpoint. */
622 breakpoint_enabled (struct breakpoint *b)
624 return (b->enable_state == bp_enabled);
627 /* Set breakpoint count to NUM. */
630 set_breakpoint_count (int num)
632 prev_breakpoint_count = breakpoint_count;
633 breakpoint_count = num;
634 set_internalvar_integer (lookup_internalvar ("bpnum"), num);
637 /* Used by `start_rbreak_breakpoints' below, to record the current
638 breakpoint count before "rbreak" creates any breakpoint. */
639 static int rbreak_start_breakpoint_count;
641 /* Called at the start an "rbreak" command to record the first
645 start_rbreak_breakpoints (void)
647 rbreak_start_breakpoint_count = breakpoint_count;
650 /* Called at the end of an "rbreak" command to record the last
654 end_rbreak_breakpoints (void)
656 prev_breakpoint_count = rbreak_start_breakpoint_count;
659 /* Used in run_command to zero the hit count when a new run starts. */
662 clear_breakpoint_hit_counts (void)
664 struct breakpoint *b;
670 /* Allocate a new counted_command_line with reference count of 1.
671 The new structure owns COMMANDS. */
673 static struct counted_command_line *
674 alloc_counted_command_line (struct command_line *commands)
676 struct counted_command_line *result
677 = xmalloc (sizeof (struct counted_command_line));
680 result->commands = commands;
684 /* Increment reference count. This does nothing if CMD is NULL. */
687 incref_counted_command_line (struct counted_command_line *cmd)
693 /* Decrement reference count. If the reference count reaches 0,
694 destroy the counted_command_line. Sets *CMDP to NULL. This does
695 nothing if *CMDP is NULL. */
698 decref_counted_command_line (struct counted_command_line **cmdp)
702 if (--(*cmdp)->refc == 0)
704 free_command_lines (&(*cmdp)->commands);
711 /* A cleanup function that calls decref_counted_command_line. */
714 do_cleanup_counted_command_line (void *arg)
716 decref_counted_command_line (arg);
719 /* Create a cleanup that calls decref_counted_command_line on the
722 static struct cleanup *
723 make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp)
725 return make_cleanup (do_cleanup_counted_command_line, cmdp);
729 /* Return the breakpoint with the specified number, or NULL
730 if the number does not refer to an existing breakpoint. */
733 get_breakpoint (int num)
735 struct breakpoint *b;
738 if (b->number == num)
746 /* Mark locations as "conditions have changed" in case the target supports
747 evaluating conditions on its side. */
750 mark_breakpoint_modified (struct breakpoint *b)
752 struct bp_location *loc;
754 /* This is only meaningful if the target is
755 evaluating conditions and if the user has
756 opted for condition evaluation on the target's
758 if (gdb_evaluates_breakpoint_condition_p ()
759 || !target_supports_evaluation_of_breakpoint_conditions ())
762 if (!is_breakpoint (b))
765 for (loc = b->loc; loc; loc = loc->next)
766 loc->condition_changed = condition_modified;
769 /* Mark location as "conditions have changed" in case the target supports
770 evaluating conditions on its side. */
773 mark_breakpoint_location_modified (struct bp_location *loc)
775 /* This is only meaningful if the target is
776 evaluating conditions and if the user has
777 opted for condition evaluation on the target's
779 if (gdb_evaluates_breakpoint_condition_p ()
780 || !target_supports_evaluation_of_breakpoint_conditions ())
784 if (!is_breakpoint (loc->owner))
787 loc->condition_changed = condition_modified;
790 /* Sets the condition-evaluation mode using the static global
791 condition_evaluation_mode. */
794 set_condition_evaluation_mode (char *args, int from_tty,
795 struct cmd_list_element *c)
797 const char *old_mode, *new_mode;
799 if ((condition_evaluation_mode_1 == condition_evaluation_target)
800 && !target_supports_evaluation_of_breakpoint_conditions ())
802 condition_evaluation_mode_1 = condition_evaluation_mode;
803 warning (_("Target does not support breakpoint condition evaluation.\n"
804 "Using host evaluation mode instead."));
808 new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1);
809 old_mode = translate_condition_evaluation_mode (condition_evaluation_mode);
811 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
812 settings was "auto". */
813 condition_evaluation_mode = condition_evaluation_mode_1;
815 /* Only update the mode if the user picked a different one. */
816 if (new_mode != old_mode)
818 struct bp_location *loc, **loc_tmp;
819 /* If the user switched to a different evaluation mode, we
820 need to synch the changes with the target as follows:
822 "host" -> "target": Send all (valid) conditions to the target.
823 "target" -> "host": Remove all the conditions from the target.
826 if (new_mode == condition_evaluation_target)
828 /* Mark everything modified and synch conditions with the
830 ALL_BP_LOCATIONS (loc, loc_tmp)
831 mark_breakpoint_location_modified (loc);
835 /* Manually mark non-duplicate locations to synch conditions
836 with the target. We do this to remove all the conditions the
837 target knows about. */
838 ALL_BP_LOCATIONS (loc, loc_tmp)
839 if (is_breakpoint (loc->owner) && loc->inserted)
840 loc->needs_update = 1;
844 update_global_location_list (1);
850 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
851 what "auto" is translating to. */
854 show_condition_evaluation_mode (struct ui_file *file, int from_tty,
855 struct cmd_list_element *c, const char *value)
857 if (condition_evaluation_mode == condition_evaluation_auto)
858 fprintf_filtered (file,
859 _("Breakpoint condition evaluation "
860 "mode is %s (currently %s).\n"),
862 breakpoint_condition_evaluation_mode ());
864 fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"),
868 /* A comparison function for bp_location AP and BP that is used by
869 bsearch. This comparison function only cares about addresses, unlike
870 the more general bp_location_compare function. */
873 bp_location_compare_addrs (const void *ap, const void *bp)
875 struct bp_location *a = *(void **) ap;
876 struct bp_location *b = *(void **) bp;
878 if (a->address == b->address)
881 return ((a->address > b->address) - (a->address < b->address));
884 /* Helper function to skip all bp_locations with addresses
885 less than ADDRESS. It returns the first bp_location that
886 is greater than or equal to ADDRESS. If none is found, just
889 static struct bp_location **
890 get_first_locp_gte_addr (CORE_ADDR address)
892 struct bp_location dummy_loc;
893 struct bp_location *dummy_locp = &dummy_loc;
894 struct bp_location **locp_found = NULL;
896 /* Initialize the dummy location's address field. */
897 memset (&dummy_loc, 0, sizeof (struct bp_location));
898 dummy_loc.address = address;
900 /* Find a close match to the first location at ADDRESS. */
901 locp_found = bsearch (&dummy_locp, bp_location, bp_location_count,
902 sizeof (struct bp_location **),
903 bp_location_compare_addrs);
905 /* Nothing was found, nothing left to do. */
906 if (locp_found == NULL)
909 /* We may have found a location that is at ADDRESS but is not the first in the
910 location's list. Go backwards (if possible) and locate the first one. */
911 while ((locp_found - 1) >= bp_location
912 && (*(locp_found - 1))->address == address)
919 set_breakpoint_condition (struct breakpoint *b, char *exp,
922 xfree (b->cond_string);
923 b->cond_string = NULL;
925 if (is_watchpoint (b))
927 struct watchpoint *w = (struct watchpoint *) b;
934 struct bp_location *loc;
936 for (loc = b->loc; loc; loc = loc->next)
941 /* No need to free the condition agent expression
942 bytecode (if we have one). We will handle this
943 when we go through update_global_location_list. */
950 printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number);
954 const char *arg = exp;
956 /* I don't know if it matters whether this is the string the user
957 typed in or the decompiled expression. */
958 b->cond_string = xstrdup (arg);
959 b->condition_not_parsed = 0;
961 if (is_watchpoint (b))
963 struct watchpoint *w = (struct watchpoint *) b;
965 innermost_block = NULL;
967 w->cond_exp = parse_exp_1 (&arg, 0, 0, 0);
969 error (_("Junk at end of expression"));
970 w->cond_exp_valid_block = innermost_block;
974 struct bp_location *loc;
976 for (loc = b->loc; loc; loc = loc->next)
980 parse_exp_1 (&arg, loc->address,
981 block_for_pc (loc->address), 0);
983 error (_("Junk at end of expression"));
987 mark_breakpoint_modified (b);
989 observer_notify_breakpoint_modified (b);
992 /* Completion for the "condition" command. */
994 static VEC (char_ptr) *
995 condition_completer (struct cmd_list_element *cmd,
996 const char *text, const char *word)
1000 text = skip_spaces_const (text);
1001 space = skip_to_space_const (text);
1005 struct breakpoint *b;
1006 VEC (char_ptr) *result = NULL;
1010 /* We don't support completion of history indices. */
1011 if (isdigit (text[1]))
1013 return complete_internalvar (&text[1]);
1016 /* We're completing the breakpoint number. */
1017 len = strlen (text);
1021 int single = b->loc->next == NULL;
1022 struct bp_location *loc;
1025 for (loc = b->loc; loc; loc = loc->next)
1030 xsnprintf (location, sizeof (location), "%d", b->number);
1032 xsnprintf (location, sizeof (location), "%d.%d", b->number,
1035 if (strncmp (location, text, len) == 0)
1036 VEC_safe_push (char_ptr, result, xstrdup (location));
1045 /* We're completing the expression part. */
1046 text = skip_spaces_const (space);
1047 return expression_completer (cmd, text, word);
1050 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1053 condition_command (char *arg, int from_tty)
1055 struct breakpoint *b;
1060 error_no_arg (_("breakpoint number"));
1063 bnum = get_number (&p);
1065 error (_("Bad breakpoint argument: '%s'"), arg);
1068 if (b->number == bnum)
1070 /* Check if this breakpoint has a Python object assigned to
1071 it, and if it has a definition of the "stop"
1072 method. This method and conditions entered into GDB from
1073 the CLI are mutually exclusive. */
1075 && gdbpy_breakpoint_has_py_cond (b->py_bp_object))
1076 error (_("Cannot set a condition where a Python 'stop' "
1077 "method has been defined in the breakpoint."));
1078 set_breakpoint_condition (b, p, from_tty);
1080 if (is_breakpoint (b))
1081 update_global_location_list (1);
1086 error (_("No breakpoint number %d."), bnum);
1089 /* Check that COMMAND do not contain commands that are suitable
1090 only for tracepoints and not suitable for ordinary breakpoints.
1091 Throw if any such commands is found. */
1094 check_no_tracepoint_commands (struct command_line *commands)
1096 struct command_line *c;
1098 for (c = commands; c; c = c->next)
1102 if (c->control_type == while_stepping_control)
1103 error (_("The 'while-stepping' command can "
1104 "only be used for tracepoints"));
1106 for (i = 0; i < c->body_count; ++i)
1107 check_no_tracepoint_commands ((c->body_list)[i]);
1109 /* Not that command parsing removes leading whitespace and comment
1110 lines and also empty lines. So, we only need to check for
1111 command directly. */
1112 if (strstr (c->line, "collect ") == c->line)
1113 error (_("The 'collect' command can only be used for tracepoints"));
1115 if (strstr (c->line, "teval ") == c->line)
1116 error (_("The 'teval' command can only be used for tracepoints"));
1120 /* Encapsulate tests for different types of tracepoints. */
1123 is_tracepoint_type (enum bptype type)
1125 return (type == bp_tracepoint
1126 || type == bp_fast_tracepoint
1127 || type == bp_static_tracepoint);
1131 is_tracepoint (const struct breakpoint *b)
1133 return is_tracepoint_type (b->type);
1136 /* A helper function that validates that COMMANDS are valid for a
1137 breakpoint. This function will throw an exception if a problem is
1141 validate_commands_for_breakpoint (struct breakpoint *b,
1142 struct command_line *commands)
1144 if (is_tracepoint (b))
1146 struct tracepoint *t = (struct tracepoint *) b;
1147 struct command_line *c;
1148 struct command_line *while_stepping = 0;
1150 /* Reset the while-stepping step count. The previous commands
1151 might have included a while-stepping action, while the new
1155 /* We need to verify that each top-level element of commands is
1156 valid for tracepoints, that there's at most one
1157 while-stepping element, and that the while-stepping's body
1158 has valid tracing commands excluding nested while-stepping.
1159 We also need to validate the tracepoint action line in the
1160 context of the tracepoint --- validate_actionline actually
1161 has side effects, like setting the tracepoint's
1162 while-stepping STEP_COUNT, in addition to checking if the
1163 collect/teval actions parse and make sense in the
1164 tracepoint's context. */
1165 for (c = commands; c; c = c->next)
1167 if (c->control_type == while_stepping_control)
1169 if (b->type == bp_fast_tracepoint)
1170 error (_("The 'while-stepping' command "
1171 "cannot be used for fast tracepoint"));
1172 else if (b->type == bp_static_tracepoint)
1173 error (_("The 'while-stepping' command "
1174 "cannot be used for static tracepoint"));
1177 error (_("The 'while-stepping' command "
1178 "can be used only once"));
1183 validate_actionline (c->line, b);
1187 struct command_line *c2;
1189 gdb_assert (while_stepping->body_count == 1);
1190 c2 = while_stepping->body_list[0];
1191 for (; c2; c2 = c2->next)
1193 if (c2->control_type == while_stepping_control)
1194 error (_("The 'while-stepping' command cannot be nested"));
1200 check_no_tracepoint_commands (commands);
1204 /* Return a vector of all the static tracepoints set at ADDR. The
1205 caller is responsible for releasing the vector. */
1208 static_tracepoints_here (CORE_ADDR addr)
1210 struct breakpoint *b;
1211 VEC(breakpoint_p) *found = 0;
1212 struct bp_location *loc;
1215 if (b->type == bp_static_tracepoint)
1217 for (loc = b->loc; loc; loc = loc->next)
1218 if (loc->address == addr)
1219 VEC_safe_push(breakpoint_p, found, b);
1225 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1226 validate that only allowed commands are included. */
1229 breakpoint_set_commands (struct breakpoint *b,
1230 struct command_line *commands)
1232 validate_commands_for_breakpoint (b, commands);
1234 decref_counted_command_line (&b->commands);
1235 b->commands = alloc_counted_command_line (commands);
1236 observer_notify_breakpoint_modified (b);
1239 /* Set the internal `silent' flag on the breakpoint. Note that this
1240 is not the same as the "silent" that may appear in the breakpoint's
1244 breakpoint_set_silent (struct breakpoint *b, int silent)
1246 int old_silent = b->silent;
1249 if (old_silent != silent)
1250 observer_notify_breakpoint_modified (b);
1253 /* Set the thread for this breakpoint. If THREAD is -1, make the
1254 breakpoint work for any thread. */
1257 breakpoint_set_thread (struct breakpoint *b, int thread)
1259 int old_thread = b->thread;
1262 if (old_thread != thread)
1263 observer_notify_breakpoint_modified (b);
1266 /* Set the task for this breakpoint. If TASK is 0, make the
1267 breakpoint work for any task. */
1270 breakpoint_set_task (struct breakpoint *b, int task)
1272 int old_task = b->task;
1275 if (old_task != task)
1276 observer_notify_breakpoint_modified (b);
1280 check_tracepoint_command (char *line, void *closure)
1282 struct breakpoint *b = closure;
1284 validate_actionline (line, b);
1287 /* A structure used to pass information through
1288 map_breakpoint_numbers. */
1290 struct commands_info
1292 /* True if the command was typed at a tty. */
1295 /* The breakpoint range spec. */
1298 /* Non-NULL if the body of the commands are being read from this
1299 already-parsed command. */
1300 struct command_line *control;
1302 /* The command lines read from the user, or NULL if they have not
1304 struct counted_command_line *cmd;
1307 /* A callback for map_breakpoint_numbers that sets the commands for
1308 commands_command. */
1311 do_map_commands_command (struct breakpoint *b, void *data)
1313 struct commands_info *info = data;
1315 if (info->cmd == NULL)
1317 struct command_line *l;
1319 if (info->control != NULL)
1320 l = copy_command_lines (info->control->body_list[0]);
1323 struct cleanup *old_chain;
1326 str = xstrprintf (_("Type commands for breakpoint(s) "
1327 "%s, one per line."),
1330 old_chain = make_cleanup (xfree, str);
1332 l = read_command_lines (str,
1335 ? check_tracepoint_command : 0),
1338 do_cleanups (old_chain);
1341 info->cmd = alloc_counted_command_line (l);
1344 /* If a breakpoint was on the list more than once, we don't need to
1346 if (b->commands != info->cmd)
1348 validate_commands_for_breakpoint (b, info->cmd->commands);
1349 incref_counted_command_line (info->cmd);
1350 decref_counted_command_line (&b->commands);
1351 b->commands = info->cmd;
1352 observer_notify_breakpoint_modified (b);
1357 commands_command_1 (char *arg, int from_tty,
1358 struct command_line *control)
1360 struct cleanup *cleanups;
1361 struct commands_info info;
1363 info.from_tty = from_tty;
1364 info.control = control;
1366 /* If we read command lines from the user, then `info' will hold an
1367 extra reference to the commands that we must clean up. */
1368 cleanups = make_cleanup_decref_counted_command_line (&info.cmd);
1370 if (arg == NULL || !*arg)
1372 if (breakpoint_count - prev_breakpoint_count > 1)
1373 arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1,
1375 else if (breakpoint_count > 0)
1376 arg = xstrprintf ("%d", breakpoint_count);
1379 /* So that we don't try to free the incoming non-NULL
1380 argument in the cleanup below. Mapping breakpoint
1381 numbers will fail in this case. */
1386 /* The command loop has some static state, so we need to preserve
1388 arg = xstrdup (arg);
1391 make_cleanup (xfree, arg);
1395 map_breakpoint_numbers (arg, do_map_commands_command, &info);
1397 if (info.cmd == NULL)
1398 error (_("No breakpoints specified."));
1400 do_cleanups (cleanups);
1404 commands_command (char *arg, int from_tty)
1406 commands_command_1 (arg, from_tty, NULL);
1409 /* Like commands_command, but instead of reading the commands from
1410 input stream, takes them from an already parsed command structure.
1412 This is used by cli-script.c to DTRT with breakpoint commands
1413 that are part of if and while bodies. */
1414 enum command_control_type
1415 commands_from_control_command (char *arg, struct command_line *cmd)
1417 commands_command_1 (arg, 0, cmd);
1418 return simple_control;
1421 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1424 bp_location_has_shadow (struct bp_location *bl)
1426 if (bl->loc_type != bp_loc_software_breakpoint)
1430 if (bl->target_info.shadow_len == 0)
1431 /* BL isn't valid, or doesn't shadow memory. */
1436 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1437 by replacing any memory breakpoints with their shadowed contents.
1439 If READBUF is not NULL, this buffer must not overlap with any of
1440 the breakpoint location's shadow_contents buffers. Otherwise,
1441 a failed assertion internal error will be raised.
1443 The range of shadowed area by each bp_location is:
1444 bl->address - bp_location_placed_address_before_address_max
1445 up to bl->address + bp_location_shadow_len_after_address_max
1446 The range we were requested to resolve shadows for is:
1447 memaddr ... memaddr + len
1448 Thus the safe cutoff boundaries for performance optimization are
1449 memaddr + len <= (bl->address
1450 - bp_location_placed_address_before_address_max)
1452 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1455 breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf,
1456 const gdb_byte *writebuf_org,
1457 ULONGEST memaddr, LONGEST len)
1459 /* Left boundary, right boundary and median element of our binary
1461 unsigned bc_l, bc_r, bc;
1463 /* Find BC_L which is a leftmost element which may affect BUF
1464 content. It is safe to report lower value but a failure to
1465 report higher one. */
1468 bc_r = bp_location_count;
1469 while (bc_l + 1 < bc_r)
1471 struct bp_location *bl;
1473 bc = (bc_l + bc_r) / 2;
1474 bl = bp_location[bc];
1476 /* Check first BL->ADDRESS will not overflow due to the added
1477 constant. Then advance the left boundary only if we are sure
1478 the BC element can in no way affect the BUF content (MEMADDR
1479 to MEMADDR + LEN range).
1481 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1482 offset so that we cannot miss a breakpoint with its shadow
1483 range tail still reaching MEMADDR. */
1485 if ((bl->address + bp_location_shadow_len_after_address_max
1487 && (bl->address + bp_location_shadow_len_after_address_max
1494 /* Due to the binary search above, we need to make sure we pick the
1495 first location that's at BC_L's address. E.g., if there are
1496 multiple locations at the same address, BC_L may end up pointing
1497 at a duplicate location, and miss the "master"/"inserted"
1498 location. Say, given locations L1, L2 and L3 at addresses A and
1501 L1@A, L2@A, L3@B, ...
1503 BC_L could end up pointing at location L2, while the "master"
1504 location could be L1. Since the `loc->inserted' flag is only set
1505 on "master" locations, we'd forget to restore the shadow of L1
1508 && bp_location[bc_l]->address == bp_location[bc_l - 1]->address)
1511 /* Now do full processing of the found relevant range of elements. */
1513 for (bc = bc_l; bc < bp_location_count; bc++)
1515 struct bp_location *bl = bp_location[bc];
1516 CORE_ADDR bp_addr = 0;
1520 /* bp_location array has BL->OWNER always non-NULL. */
1521 if (bl->owner->type == bp_none)
1522 warning (_("reading through apparently deleted breakpoint #%d?"),
1525 /* Performance optimization: any further element can no longer affect BUF
1528 if (bl->address >= bp_location_placed_address_before_address_max
1529 && memaddr + len <= (bl->address
1530 - bp_location_placed_address_before_address_max))
1533 if (!bp_location_has_shadow (bl))
1535 if (!breakpoint_address_match (bl->target_info.placed_address_space, 0,
1536 current_program_space->aspace, 0))
1539 /* Addresses and length of the part of the breakpoint that
1541 bp_addr = bl->target_info.placed_address;
1542 bp_size = bl->target_info.shadow_len;
1544 if (bp_addr + bp_size <= memaddr)
1545 /* The breakpoint is entirely before the chunk of memory we
1549 if (bp_addr >= memaddr + len)
1550 /* The breakpoint is entirely after the chunk of memory we are
1554 /* Offset within shadow_contents. */
1555 if (bp_addr < memaddr)
1557 /* Only copy the second part of the breakpoint. */
1558 bp_size -= memaddr - bp_addr;
1559 bptoffset = memaddr - bp_addr;
1563 if (bp_addr + bp_size > memaddr + len)
1565 /* Only copy the first part of the breakpoint. */
1566 bp_size -= (bp_addr + bp_size) - (memaddr + len);
1569 if (readbuf != NULL)
1571 /* Verify that the readbuf buffer does not overlap with
1572 the shadow_contents buffer. */
1573 gdb_assert (bl->target_info.shadow_contents >= readbuf + len
1574 || readbuf >= (bl->target_info.shadow_contents
1575 + bl->target_info.shadow_len));
1577 /* Update the read buffer with this inserted breakpoint's
1579 memcpy (readbuf + bp_addr - memaddr,
1580 bl->target_info.shadow_contents + bptoffset, bp_size);
1584 struct gdbarch *gdbarch = bl->gdbarch;
1585 const unsigned char *bp;
1586 CORE_ADDR placed_address = bl->target_info.placed_address;
1587 int placed_size = bl->target_info.placed_size;
1589 /* Update the shadow with what we want to write to memory. */
1590 memcpy (bl->target_info.shadow_contents + bptoffset,
1591 writebuf_org + bp_addr - memaddr, bp_size);
1593 /* Determine appropriate breakpoint contents and size for this
1595 bp = gdbarch_breakpoint_from_pc (gdbarch, &placed_address, &placed_size);
1597 /* Update the final write buffer with this inserted
1598 breakpoint's INSN. */
1599 memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size);
1605 /* Return true if BPT is either a software breakpoint or a hardware
1609 is_breakpoint (const struct breakpoint *bpt)
1611 return (bpt->type == bp_breakpoint
1612 || bpt->type == bp_hardware_breakpoint
1613 || bpt->type == bp_dprintf);
1616 /* Return true if BPT is of any hardware watchpoint kind. */
1619 is_hardware_watchpoint (const struct breakpoint *bpt)
1621 return (bpt->type == bp_hardware_watchpoint
1622 || bpt->type == bp_read_watchpoint
1623 || bpt->type == bp_access_watchpoint);
1626 /* Return true if BPT is of any watchpoint kind, hardware or
1630 is_watchpoint (const struct breakpoint *bpt)
1632 return (is_hardware_watchpoint (bpt)
1633 || bpt->type == bp_watchpoint);
1636 /* Returns true if the current thread and its running state are safe
1637 to evaluate or update watchpoint B. Watchpoints on local
1638 expressions need to be evaluated in the context of the thread that
1639 was current when the watchpoint was created, and, that thread needs
1640 to be stopped to be able to select the correct frame context.
1641 Watchpoints on global expressions can be evaluated on any thread,
1642 and in any state. It is presently left to the target allowing
1643 memory accesses when threads are running. */
1646 watchpoint_in_thread_scope (struct watchpoint *b)
1648 return (b->base.pspace == current_program_space
1649 && (ptid_equal (b->watchpoint_thread, null_ptid)
1650 || (ptid_equal (inferior_ptid, b->watchpoint_thread)
1651 && !is_executing (inferior_ptid))));
1654 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1655 associated bp_watchpoint_scope breakpoint. */
1658 watchpoint_del_at_next_stop (struct watchpoint *w)
1660 struct breakpoint *b = &w->base;
1662 if (b->related_breakpoint != b)
1664 gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope);
1665 gdb_assert (b->related_breakpoint->related_breakpoint == b);
1666 b->related_breakpoint->disposition = disp_del_at_next_stop;
1667 b->related_breakpoint->related_breakpoint = b->related_breakpoint;
1668 b->related_breakpoint = b;
1670 b->disposition = disp_del_at_next_stop;
1673 /* Assuming that B is a watchpoint:
1674 - Reparse watchpoint expression, if REPARSE is non-zero
1675 - Evaluate expression and store the result in B->val
1676 - Evaluate the condition if there is one, and store the result
1678 - Update the list of values that must be watched in B->loc.
1680 If the watchpoint disposition is disp_del_at_next_stop, then do
1681 nothing. If this is local watchpoint that is out of scope, delete
1684 Even with `set breakpoint always-inserted on' the watchpoints are
1685 removed + inserted on each stop here. Normal breakpoints must
1686 never be removed because they might be missed by a running thread
1687 when debugging in non-stop mode. On the other hand, hardware
1688 watchpoints (is_hardware_watchpoint; processed here) are specific
1689 to each LWP since they are stored in each LWP's hardware debug
1690 registers. Therefore, such LWP must be stopped first in order to
1691 be able to modify its hardware watchpoints.
1693 Hardware watchpoints must be reset exactly once after being
1694 presented to the user. It cannot be done sooner, because it would
1695 reset the data used to present the watchpoint hit to the user. And
1696 it must not be done later because it could display the same single
1697 watchpoint hit during multiple GDB stops. Note that the latter is
1698 relevant only to the hardware watchpoint types bp_read_watchpoint
1699 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1700 not user-visible - its hit is suppressed if the memory content has
1703 The following constraints influence the location where we can reset
1704 hardware watchpoints:
1706 * target_stopped_by_watchpoint and target_stopped_data_address are
1707 called several times when GDB stops.
1710 * Multiple hardware watchpoints can be hit at the same time,
1711 causing GDB to stop. GDB only presents one hardware watchpoint
1712 hit at a time as the reason for stopping, and all the other hits
1713 are presented later, one after the other, each time the user
1714 requests the execution to be resumed. Execution is not resumed
1715 for the threads still having pending hit event stored in
1716 LWP_INFO->STATUS. While the watchpoint is already removed from
1717 the inferior on the first stop the thread hit event is kept being
1718 reported from its cached value by linux_nat_stopped_data_address
1719 until the real thread resume happens after the watchpoint gets
1720 presented and thus its LWP_INFO->STATUS gets reset.
1722 Therefore the hardware watchpoint hit can get safely reset on the
1723 watchpoint removal from inferior. */
1726 update_watchpoint (struct watchpoint *b, int reparse)
1728 int within_current_scope;
1729 struct frame_id saved_frame_id;
1732 /* If this is a local watchpoint, we only want to check if the
1733 watchpoint frame is in scope if the current thread is the thread
1734 that was used to create the watchpoint. */
1735 if (!watchpoint_in_thread_scope (b))
1738 if (b->base.disposition == disp_del_at_next_stop)
1743 /* Determine if the watchpoint is within scope. */
1744 if (b->exp_valid_block == NULL)
1745 within_current_scope = 1;
1748 struct frame_info *fi = get_current_frame ();
1749 struct gdbarch *frame_arch = get_frame_arch (fi);
1750 CORE_ADDR frame_pc = get_frame_pc (fi);
1752 /* If we're in a function epilogue, unwinding may not work
1753 properly, so do not attempt to recreate locations at this
1754 point. See similar comments in watchpoint_check. */
1755 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
1758 /* Save the current frame's ID so we can restore it after
1759 evaluating the watchpoint expression on its own frame. */
1760 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1761 took a frame parameter, so that we didn't have to change the
1764 saved_frame_id = get_frame_id (get_selected_frame (NULL));
1766 fi = frame_find_by_id (b->watchpoint_frame);
1767 within_current_scope = (fi != NULL);
1768 if (within_current_scope)
1772 /* We don't free locations. They are stored in the bp_location array
1773 and update_global_location_list will eventually delete them and
1774 remove breakpoints if needed. */
1777 if (within_current_scope && reparse)
1786 s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string;
1787 b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0);
1788 /* If the meaning of expression itself changed, the old value is
1789 no longer relevant. We don't want to report a watchpoint hit
1790 to the user when the old value and the new value may actually
1791 be completely different objects. */
1792 value_free (b->val);
1796 /* Note that unlike with breakpoints, the watchpoint's condition
1797 expression is stored in the breakpoint object, not in the
1798 locations (re)created below. */
1799 if (b->base.cond_string != NULL)
1801 if (b->cond_exp != NULL)
1803 xfree (b->cond_exp);
1807 s = b->base.cond_string;
1808 b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0);
1812 /* If we failed to parse the expression, for example because
1813 it refers to a global variable in a not-yet-loaded shared library,
1814 don't try to insert watchpoint. We don't automatically delete
1815 such watchpoint, though, since failure to parse expression
1816 is different from out-of-scope watchpoint. */
1817 if ( !target_has_execution)
1819 /* Without execution, memory can't change. No use to try and
1820 set watchpoint locations. The watchpoint will be reset when
1821 the target gains execution, through breakpoint_re_set. */
1823 else if (within_current_scope && b->exp)
1826 struct value *val_chain, *v, *result, *next;
1827 struct program_space *frame_pspace;
1829 fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain);
1831 /* Avoid setting b->val if it's already set. The meaning of
1832 b->val is 'the last value' user saw, and we should update
1833 it only if we reported that last value to user. As it
1834 happens, the code that reports it updates b->val directly.
1835 We don't keep track of the memory value for masked
1837 if (!b->val_valid && !is_masked_watchpoint (&b->base))
1843 frame_pspace = get_frame_program_space (get_selected_frame (NULL));
1845 /* Look at each value on the value chain. */
1846 for (v = val_chain; v; v = value_next (v))
1848 /* If it's a memory location, and GDB actually needed
1849 its contents to evaluate the expression, then we
1850 must watch it. If the first value returned is
1851 still lazy, that means an error occurred reading it;
1852 watch it anyway in case it becomes readable. */
1853 if (VALUE_LVAL (v) == lval_memory
1854 && (v == val_chain || ! value_lazy (v)))
1856 struct type *vtype = check_typedef (value_type (v));
1858 /* We only watch structs and arrays if user asked
1859 for it explicitly, never if they just happen to
1860 appear in the middle of some value chain. */
1862 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1863 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1867 struct bp_location *loc, **tmp;
1869 addr = value_address (v);
1871 if (b->base.type == bp_read_watchpoint)
1873 else if (b->base.type == bp_access_watchpoint)
1876 loc = allocate_bp_location (&b->base);
1877 for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next))
1880 loc->gdbarch = get_type_arch (value_type (v));
1882 loc->pspace = frame_pspace;
1883 loc->address = addr;
1884 loc->length = TYPE_LENGTH (value_type (v));
1885 loc->watchpoint_type = type;
1890 /* Change the type of breakpoint between hardware assisted or
1891 an ordinary watchpoint depending on the hardware support
1892 and free hardware slots. REPARSE is set when the inferior
1897 enum bp_loc_type loc_type;
1898 struct bp_location *bl;
1900 reg_cnt = can_use_hardware_watchpoint (val_chain);
1904 int i, target_resources_ok, other_type_used;
1907 /* Use an exact watchpoint when there's only one memory region to be
1908 watched, and only one debug register is needed to watch it. */
1909 b->exact = target_exact_watchpoints && reg_cnt == 1;
1911 /* We need to determine how many resources are already
1912 used for all other hardware watchpoints plus this one
1913 to see if we still have enough resources to also fit
1914 this watchpoint in as well. */
1916 /* If this is a software watchpoint, we try to turn it
1917 to a hardware one -- count resources as if B was of
1918 hardware watchpoint type. */
1919 type = b->base.type;
1920 if (type == bp_watchpoint)
1921 type = bp_hardware_watchpoint;
1923 /* This watchpoint may or may not have been placed on
1924 the list yet at this point (it won't be in the list
1925 if we're trying to create it for the first time,
1926 through watch_command), so always account for it
1929 /* Count resources used by all watchpoints except B. */
1930 i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used);
1932 /* Add in the resources needed for B. */
1933 i += hw_watchpoint_use_count (&b->base);
1936 = target_can_use_hardware_watchpoint (type, i, other_type_used);
1937 if (target_resources_ok <= 0)
1939 int sw_mode = b->base.ops->works_in_software_mode (&b->base);
1941 if (target_resources_ok == 0 && !sw_mode)
1942 error (_("Target does not support this type of "
1943 "hardware watchpoint."));
1944 else if (target_resources_ok < 0 && !sw_mode)
1945 error (_("There are not enough available hardware "
1946 "resources for this watchpoint."));
1948 /* Downgrade to software watchpoint. */
1949 b->base.type = bp_watchpoint;
1953 /* If this was a software watchpoint, we've just
1954 found we have enough resources to turn it to a
1955 hardware watchpoint. Otherwise, this is a
1957 b->base.type = type;
1960 else if (!b->base.ops->works_in_software_mode (&b->base))
1961 error (_("Expression cannot be implemented with "
1962 "read/access watchpoint."));
1964 b->base.type = bp_watchpoint;
1966 loc_type = (b->base.type == bp_watchpoint? bp_loc_other
1967 : bp_loc_hardware_watchpoint);
1968 for (bl = b->base.loc; bl; bl = bl->next)
1969 bl->loc_type = loc_type;
1972 for (v = val_chain; v; v = next)
1974 next = value_next (v);
1979 /* If a software watchpoint is not watching any memory, then the
1980 above left it without any location set up. But,
1981 bpstat_stop_status requires a location to be able to report
1982 stops, so make sure there's at least a dummy one. */
1983 if (b->base.type == bp_watchpoint && b->base.loc == NULL)
1985 struct breakpoint *base = &b->base;
1986 base->loc = allocate_bp_location (base);
1987 base->loc->pspace = frame_pspace;
1988 base->loc->address = -1;
1989 base->loc->length = -1;
1990 base->loc->watchpoint_type = -1;
1993 else if (!within_current_scope)
1995 printf_filtered (_("\
1996 Watchpoint %d deleted because the program has left the block\n\
1997 in which its expression is valid.\n"),
1999 watchpoint_del_at_next_stop (b);
2002 /* Restore the selected frame. */
2004 select_frame (frame_find_by_id (saved_frame_id));
2008 /* Returns 1 iff breakpoint location should be
2009 inserted in the inferior. We don't differentiate the type of BL's owner
2010 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2011 breakpoint_ops is not defined, because in insert_bp_location,
2012 tracepoint's insert_location will not be called. */
2014 should_be_inserted (struct bp_location *bl)
2016 if (bl->owner == NULL || !breakpoint_enabled (bl->owner))
2019 if (bl->owner->disposition == disp_del_at_next_stop)
2022 if (!bl->enabled || bl->shlib_disabled || bl->duplicate)
2025 if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup)
2028 /* This is set for example, when we're attached to the parent of a
2029 vfork, and have detached from the child. The child is running
2030 free, and we expect it to do an exec or exit, at which point the
2031 OS makes the parent schedulable again (and the target reports
2032 that the vfork is done). Until the child is done with the shared
2033 memory region, do not insert breakpoints in the parent, otherwise
2034 the child could still trip on the parent's breakpoints. Since
2035 the parent is blocked anyway, it won't miss any breakpoint. */
2036 if (bl->pspace->breakpoints_not_allowed)
2042 /* Same as should_be_inserted but does the check assuming
2043 that the location is not duplicated. */
2046 unduplicated_should_be_inserted (struct bp_location *bl)
2049 const int save_duplicate = bl->duplicate;
2052 result = should_be_inserted (bl);
2053 bl->duplicate = save_duplicate;
2057 /* Parses a conditional described by an expression COND into an
2058 agent expression bytecode suitable for evaluation
2059 by the bytecode interpreter. Return NULL if there was
2060 any error during parsing. */
2062 static struct agent_expr *
2063 parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond)
2065 struct agent_expr *aexpr = NULL;
2066 volatile struct gdb_exception ex;
2071 /* We don't want to stop processing, so catch any errors
2072 that may show up. */
2073 TRY_CATCH (ex, RETURN_MASK_ERROR)
2075 aexpr = gen_eval_for_expr (scope, cond);
2080 /* If we got here, it means the condition could not be parsed to a valid
2081 bytecode expression and thus can't be evaluated on the target's side.
2082 It's no use iterating through the conditions. */
2086 /* We have a valid agent expression. */
2090 /* Based on location BL, create a list of breakpoint conditions to be
2091 passed on to the target. If we have duplicated locations with different
2092 conditions, we will add such conditions to the list. The idea is that the
2093 target will evaluate the list of conditions and will only notify GDB when
2094 one of them is true. */
2097 build_target_condition_list (struct bp_location *bl)
2099 struct bp_location **locp = NULL, **loc2p;
2100 int null_condition_or_parse_error = 0;
2101 int modified = bl->needs_update;
2102 struct bp_location *loc;
2104 /* This is only meaningful if the target is
2105 evaluating conditions and if the user has
2106 opted for condition evaluation on the target's
2108 if (gdb_evaluates_breakpoint_condition_p ()
2109 || !target_supports_evaluation_of_breakpoint_conditions ())
2112 /* Do a first pass to check for locations with no assigned
2113 conditions or conditions that fail to parse to a valid agent expression
2114 bytecode. If any of these happen, then it's no use to send conditions
2115 to the target since this location will always trigger and generate a
2116 response back to GDB. */
2117 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2120 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2124 struct agent_expr *aexpr;
2126 /* Re-parse the conditions since something changed. In that
2127 case we already freed the condition bytecodes (see
2128 force_breakpoint_reinsertion). We just
2129 need to parse the condition to bytecodes again. */
2130 aexpr = parse_cond_to_aexpr (bl->address, loc->cond);
2131 loc->cond_bytecode = aexpr;
2133 /* Check if we managed to parse the conditional expression
2134 correctly. If not, we will not send this condition
2140 /* If we have a NULL bytecode expression, it means something
2141 went wrong or we have a null condition expression. */
2142 if (!loc->cond_bytecode)
2144 null_condition_or_parse_error = 1;
2150 /* If any of these happened, it means we will have to evaluate the conditions
2151 for the location's address on gdb's side. It is no use keeping bytecodes
2152 for all the other duplicate locations, thus we free all of them here.
2154 This is so we have a finer control over which locations' conditions are
2155 being evaluated by GDB or the remote stub. */
2156 if (null_condition_or_parse_error)
2158 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2161 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2163 /* Only go as far as the first NULL bytecode is
2165 if (!loc->cond_bytecode)
2168 free_agent_expr (loc->cond_bytecode);
2169 loc->cond_bytecode = NULL;
2174 /* No NULL conditions or failed bytecode generation. Build a condition list
2175 for this location's address. */
2176 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2180 && is_breakpoint (loc->owner)
2181 && loc->pspace->num == bl->pspace->num
2182 && loc->owner->enable_state == bp_enabled
2184 /* Add the condition to the vector. This will be used later to send the
2185 conditions to the target. */
2186 VEC_safe_push (agent_expr_p, bl->target_info.conditions,
2187 loc->cond_bytecode);
2193 /* Parses a command described by string CMD into an agent expression
2194 bytecode suitable for evaluation by the bytecode interpreter.
2195 Return NULL if there was any error during parsing. */
2197 static struct agent_expr *
2198 parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd)
2200 struct cleanup *old_cleanups = 0;
2201 struct expression *expr, **argvec;
2202 struct agent_expr *aexpr = NULL;
2203 volatile struct gdb_exception ex;
2204 const char *cmdrest;
2205 const char *format_start, *format_end;
2206 struct format_piece *fpieces;
2208 struct gdbarch *gdbarch = get_current_arch ();
2215 if (*cmdrest == ',')
2217 cmdrest = skip_spaces_const (cmdrest);
2219 if (*cmdrest++ != '"')
2220 error (_("No format string following the location"));
2222 format_start = cmdrest;
2224 fpieces = parse_format_string (&cmdrest);
2226 old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces);
2228 format_end = cmdrest;
2230 if (*cmdrest++ != '"')
2231 error (_("Bad format string, non-terminated '\"'."));
2233 cmdrest = skip_spaces_const (cmdrest);
2235 if (!(*cmdrest == ',' || *cmdrest == '\0'))
2236 error (_("Invalid argument syntax"));
2238 if (*cmdrest == ',')
2240 cmdrest = skip_spaces_const (cmdrest);
2242 /* For each argument, make an expression. */
2244 argvec = (struct expression **) alloca (strlen (cmd)
2245 * sizeof (struct expression *));
2248 while (*cmdrest != '\0')
2253 expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1);
2254 argvec[nargs++] = expr;
2256 if (*cmdrest == ',')
2260 /* We don't want to stop processing, so catch any errors
2261 that may show up. */
2262 TRY_CATCH (ex, RETURN_MASK_ERROR)
2264 aexpr = gen_printf (scope, gdbarch, 0, 0,
2265 format_start, format_end - format_start,
2266 fpieces, nargs, argvec);
2271 /* If we got here, it means the command could not be parsed to a valid
2272 bytecode expression and thus can't be evaluated on the target's side.
2273 It's no use iterating through the other commands. */
2277 do_cleanups (old_cleanups);
2279 /* We have a valid agent expression, return it. */
2283 /* Based on location BL, create a list of breakpoint commands to be
2284 passed on to the target. If we have duplicated locations with
2285 different commands, we will add any such to the list. */
2288 build_target_command_list (struct bp_location *bl)
2290 struct bp_location **locp = NULL, **loc2p;
2291 int null_command_or_parse_error = 0;
2292 int modified = bl->needs_update;
2293 struct bp_location *loc;
2295 /* For now, limit to agent-style dprintf breakpoints. */
2296 if (bl->owner->type != bp_dprintf
2297 || strcmp (dprintf_style, dprintf_style_agent) != 0)
2300 if (!target_can_run_breakpoint_commands ())
2303 /* Do a first pass to check for locations with no assigned
2304 conditions or conditions that fail to parse to a valid agent expression
2305 bytecode. If any of these happen, then it's no use to send conditions
2306 to the target since this location will always trigger and generate a
2307 response back to GDB. */
2308 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2311 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2315 struct agent_expr *aexpr;
2317 /* Re-parse the commands since something changed. In that
2318 case we already freed the command bytecodes (see
2319 force_breakpoint_reinsertion). We just
2320 need to parse the command to bytecodes again. */
2321 aexpr = parse_cmd_to_aexpr (bl->address,
2322 loc->owner->extra_string);
2323 loc->cmd_bytecode = aexpr;
2329 /* If we have a NULL bytecode expression, it means something
2330 went wrong or we have a null command expression. */
2331 if (!loc->cmd_bytecode)
2333 null_command_or_parse_error = 1;
2339 /* If anything failed, then we're not doing target-side commands,
2341 if (null_command_or_parse_error)
2343 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2346 if (is_breakpoint (loc->owner)
2347 && loc->pspace->num == bl->pspace->num)
2349 /* Only go as far as the first NULL bytecode is
2351 if (!loc->cond_bytecode)
2354 free_agent_expr (loc->cond_bytecode);
2355 loc->cond_bytecode = NULL;
2360 /* No NULL commands or failed bytecode generation. Build a command list
2361 for this location's address. */
2362 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2365 if (loc->owner->extra_string
2366 && is_breakpoint (loc->owner)
2367 && loc->pspace->num == bl->pspace->num
2368 && loc->owner->enable_state == bp_enabled
2370 /* Add the command to the vector. This will be used later
2371 to send the commands to the target. */
2372 VEC_safe_push (agent_expr_p, bl->target_info.tcommands,
2376 bl->target_info.persist = 0;
2377 /* Maybe flag this location as persistent. */
2378 if (bl->owner->type == bp_dprintf && disconnected_dprintf)
2379 bl->target_info.persist = 1;
2382 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2383 location. Any error messages are printed to TMP_ERROR_STREAM; and
2384 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2385 Returns 0 for success, 1 if the bp_location type is not supported or
2388 NOTE drow/2003-09-09: This routine could be broken down to an
2389 object-style method for each breakpoint or catchpoint type. */
2391 insert_bp_location (struct bp_location *bl,
2392 struct ui_file *tmp_error_stream,
2393 int *disabled_breaks,
2394 int *hw_breakpoint_error,
2395 int *hw_bp_error_explained_already)
2398 char *hw_bp_err_string = NULL;
2399 struct gdb_exception e;
2401 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
2404 /* Note we don't initialize bl->target_info, as that wipes out
2405 the breakpoint location's shadow_contents if the breakpoint
2406 is still inserted at that location. This in turn breaks
2407 target_read_memory which depends on these buffers when
2408 a memory read is requested at the breakpoint location:
2409 Once the target_info has been wiped, we fail to see that
2410 we have a breakpoint inserted at that address and thus
2411 read the breakpoint instead of returning the data saved in
2412 the breakpoint location's shadow contents. */
2413 bl->target_info.placed_address = bl->address;
2414 bl->target_info.placed_address_space = bl->pspace->aspace;
2415 bl->target_info.length = bl->length;
2417 /* When working with target-side conditions, we must pass all the conditions
2418 for the same breakpoint address down to the target since GDB will not
2419 insert those locations. With a list of breakpoint conditions, the target
2420 can decide when to stop and notify GDB. */
2422 if (is_breakpoint (bl->owner))
2424 build_target_condition_list (bl);
2425 build_target_command_list (bl);
2426 /* Reset the modification marker. */
2427 bl->needs_update = 0;
2430 if (bl->loc_type == bp_loc_software_breakpoint
2431 || bl->loc_type == bp_loc_hardware_breakpoint)
2433 if (bl->owner->type != bp_hardware_breakpoint)
2435 /* If the explicitly specified breakpoint type
2436 is not hardware breakpoint, check the memory map to see
2437 if the breakpoint address is in read only memory or not.
2439 Two important cases are:
2440 - location type is not hardware breakpoint, memory
2441 is readonly. We change the type of the location to
2442 hardware breakpoint.
2443 - location type is hardware breakpoint, memory is
2444 read-write. This means we've previously made the
2445 location hardware one, but then the memory map changed,
2448 When breakpoints are removed, remove_breakpoints will use
2449 location types we've just set here, the only possible
2450 problem is that memory map has changed during running
2451 program, but it's not going to work anyway with current
2453 struct mem_region *mr
2454 = lookup_mem_region (bl->target_info.placed_address);
2458 if (automatic_hardware_breakpoints)
2460 enum bp_loc_type new_type;
2462 if (mr->attrib.mode != MEM_RW)
2463 new_type = bp_loc_hardware_breakpoint;
2465 new_type = bp_loc_software_breakpoint;
2467 if (new_type != bl->loc_type)
2469 static int said = 0;
2471 bl->loc_type = new_type;
2474 fprintf_filtered (gdb_stdout,
2475 _("Note: automatically using "
2476 "hardware breakpoints for "
2477 "read-only addresses.\n"));
2482 else if (bl->loc_type == bp_loc_software_breakpoint
2483 && mr->attrib.mode != MEM_RW)
2484 warning (_("cannot set software breakpoint "
2485 "at readonly address %s"),
2486 paddress (bl->gdbarch, bl->address));
2490 /* First check to see if we have to handle an overlay. */
2491 if (overlay_debugging == ovly_off
2492 || bl->section == NULL
2493 || !(section_is_overlay (bl->section)))
2495 /* No overlay handling: just set the breakpoint. */
2496 TRY_CATCH (e, RETURN_MASK_ALL)
2498 val = bl->owner->ops->insert_location (bl);
2503 hw_bp_err_string = (char *) e.message;
2508 /* This breakpoint is in an overlay section.
2509 Shall we set a breakpoint at the LMA? */
2510 if (!overlay_events_enabled)
2512 /* Yes -- overlay event support is not active,
2513 so we must try to set a breakpoint at the LMA.
2514 This will not work for a hardware breakpoint. */
2515 if (bl->loc_type == bp_loc_hardware_breakpoint)
2516 warning (_("hardware breakpoint %d not supported in overlay!"),
2520 CORE_ADDR addr = overlay_unmapped_address (bl->address,
2522 /* Set a software (trap) breakpoint at the LMA. */
2523 bl->overlay_target_info = bl->target_info;
2524 bl->overlay_target_info.placed_address = addr;
2525 val = target_insert_breakpoint (bl->gdbarch,
2526 &bl->overlay_target_info);
2528 fprintf_unfiltered (tmp_error_stream,
2529 "Overlay breakpoint %d "
2530 "failed: in ROM?\n",
2534 /* Shall we set a breakpoint at the VMA? */
2535 if (section_is_mapped (bl->section))
2537 /* Yes. This overlay section is mapped into memory. */
2538 TRY_CATCH (e, RETURN_MASK_ALL)
2540 val = bl->owner->ops->insert_location (bl);
2545 hw_bp_err_string = (char *) e.message;
2550 /* No. This breakpoint will not be inserted.
2551 No error, but do not mark the bp as 'inserted'. */
2558 /* Can't set the breakpoint. */
2559 if (solib_name_from_address (bl->pspace, bl->address))
2561 /* See also: disable_breakpoints_in_shlibs. */
2563 bl->shlib_disabled = 1;
2564 observer_notify_breakpoint_modified (bl->owner);
2565 if (!*disabled_breaks)
2567 fprintf_unfiltered (tmp_error_stream,
2568 "Cannot insert breakpoint %d.\n",
2570 fprintf_unfiltered (tmp_error_stream,
2571 "Temporarily disabling shared "
2572 "library breakpoints:\n");
2574 *disabled_breaks = 1;
2575 fprintf_unfiltered (tmp_error_stream,
2576 "breakpoint #%d\n", bl->owner->number);
2580 if (bl->loc_type == bp_loc_hardware_breakpoint)
2582 *hw_breakpoint_error = 1;
2583 *hw_bp_error_explained_already = hw_bp_err_string != NULL;
2584 fprintf_unfiltered (tmp_error_stream,
2585 "Cannot insert hardware breakpoint %d%s",
2586 bl->owner->number, hw_bp_err_string ? ":" : ".\n");
2587 if (hw_bp_err_string)
2588 fprintf_unfiltered (tmp_error_stream, "%s.\n", hw_bp_err_string);
2592 fprintf_unfiltered (tmp_error_stream,
2593 "Cannot insert breakpoint %d.\n",
2595 fprintf_filtered (tmp_error_stream,
2596 "Error accessing memory address ");
2597 fputs_filtered (paddress (bl->gdbarch, bl->address),
2599 fprintf_filtered (tmp_error_stream, ": %s.\n",
2600 safe_strerror (val));
2611 else if (bl->loc_type == bp_loc_hardware_watchpoint
2612 /* NOTE drow/2003-09-08: This state only exists for removing
2613 watchpoints. It's not clear that it's necessary... */
2614 && bl->owner->disposition != disp_del_at_next_stop)
2616 gdb_assert (bl->owner->ops != NULL
2617 && bl->owner->ops->insert_location != NULL);
2619 val = bl->owner->ops->insert_location (bl);
2621 /* If trying to set a read-watchpoint, and it turns out it's not
2622 supported, try emulating one with an access watchpoint. */
2623 if (val == 1 && bl->watchpoint_type == hw_read)
2625 struct bp_location *loc, **loc_temp;
2627 /* But don't try to insert it, if there's already another
2628 hw_access location that would be considered a duplicate
2630 ALL_BP_LOCATIONS (loc, loc_temp)
2632 && loc->watchpoint_type == hw_access
2633 && watchpoint_locations_match (bl, loc))
2637 bl->target_info = loc->target_info;
2638 bl->watchpoint_type = hw_access;
2645 bl->watchpoint_type = hw_access;
2646 val = bl->owner->ops->insert_location (bl);
2649 /* Back to the original value. */
2650 bl->watchpoint_type = hw_read;
2654 bl->inserted = (val == 0);
2657 else if (bl->owner->type == bp_catchpoint)
2659 gdb_assert (bl->owner->ops != NULL
2660 && bl->owner->ops->insert_location != NULL);
2662 val = bl->owner->ops->insert_location (bl);
2665 bl->owner->enable_state = bp_disabled;
2669 Error inserting catchpoint %d: Your system does not support this type\n\
2670 of catchpoint."), bl->owner->number);
2672 warning (_("Error inserting catchpoint %d."), bl->owner->number);
2675 bl->inserted = (val == 0);
2677 /* We've already printed an error message if there was a problem
2678 inserting this catchpoint, and we've disabled the catchpoint,
2679 so just return success. */
2686 /* This function is called when program space PSPACE is about to be
2687 deleted. It takes care of updating breakpoints to not reference
2691 breakpoint_program_space_exit (struct program_space *pspace)
2693 struct breakpoint *b, *b_temp;
2694 struct bp_location *loc, **loc_temp;
2696 /* Remove any breakpoint that was set through this program space. */
2697 ALL_BREAKPOINTS_SAFE (b, b_temp)
2699 if (b->pspace == pspace)
2700 delete_breakpoint (b);
2703 /* Breakpoints set through other program spaces could have locations
2704 bound to PSPACE as well. Remove those. */
2705 ALL_BP_LOCATIONS (loc, loc_temp)
2707 struct bp_location *tmp;
2709 if (loc->pspace == pspace)
2711 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2712 if (loc->owner->loc == loc)
2713 loc->owner->loc = loc->next;
2715 for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next)
2716 if (tmp->next == loc)
2718 tmp->next = loc->next;
2724 /* Now update the global location list to permanently delete the
2725 removed locations above. */
2726 update_global_location_list (0);
2729 /* Make sure all breakpoints are inserted in inferior.
2730 Throws exception on any error.
2731 A breakpoint that is already inserted won't be inserted
2732 again, so calling this function twice is safe. */
2734 insert_breakpoints (void)
2736 struct breakpoint *bpt;
2738 ALL_BREAKPOINTS (bpt)
2739 if (is_hardware_watchpoint (bpt))
2741 struct watchpoint *w = (struct watchpoint *) bpt;
2743 update_watchpoint (w, 0 /* don't reparse. */);
2746 update_global_location_list (1);
2748 /* update_global_location_list does not insert breakpoints when
2749 always_inserted_mode is not enabled. Explicitly insert them
2751 if (!breakpoints_always_inserted_mode ())
2752 insert_breakpoint_locations ();
2755 /* Invoke CALLBACK for each of bp_location. */
2758 iterate_over_bp_locations (walk_bp_location_callback callback)
2760 struct bp_location *loc, **loc_tmp;
2762 ALL_BP_LOCATIONS (loc, loc_tmp)
2764 callback (loc, NULL);
2768 /* This is used when we need to synch breakpoint conditions between GDB and the
2769 target. It is the case with deleting and disabling of breakpoints when using
2770 always-inserted mode. */
2773 update_inserted_breakpoint_locations (void)
2775 struct bp_location *bl, **blp_tmp;
2778 int disabled_breaks = 0;
2779 int hw_breakpoint_error = 0;
2780 int hw_bp_details_reported = 0;
2782 struct ui_file *tmp_error_stream = mem_fileopen ();
2783 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
2785 /* Explicitly mark the warning -- this will only be printed if
2786 there was an error. */
2787 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
2789 save_current_space_and_thread ();
2791 ALL_BP_LOCATIONS (bl, blp_tmp)
2793 /* We only want to update software breakpoints and hardware
2795 if (!is_breakpoint (bl->owner))
2798 /* We only want to update locations that are already inserted
2799 and need updating. This is to avoid unwanted insertion during
2800 deletion of breakpoints. */
2801 if (!bl->inserted || (bl->inserted && !bl->needs_update))
2804 switch_to_program_space_and_thread (bl->pspace);
2806 /* For targets that support global breakpoints, there's no need
2807 to select an inferior to insert breakpoint to. In fact, even
2808 if we aren't attached to any process yet, we should still
2809 insert breakpoints. */
2810 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2811 && ptid_equal (inferior_ptid, null_ptid))
2814 val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
2815 &hw_breakpoint_error, &hw_bp_details_reported);
2822 target_terminal_ours_for_output ();
2823 error_stream (tmp_error_stream);
2826 do_cleanups (cleanups);
2829 /* Used when starting or continuing the program. */
2832 insert_breakpoint_locations (void)
2834 struct breakpoint *bpt;
2835 struct bp_location *bl, **blp_tmp;
2838 int disabled_breaks = 0;
2839 int hw_breakpoint_error = 0;
2840 int hw_bp_error_explained_already = 0;
2842 struct ui_file *tmp_error_stream = mem_fileopen ();
2843 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
2845 /* Explicitly mark the warning -- this will only be printed if
2846 there was an error. */
2847 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
2849 save_current_space_and_thread ();
2851 ALL_BP_LOCATIONS (bl, blp_tmp)
2853 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
2856 /* There is no point inserting thread-specific breakpoints if
2857 the thread no longer exists. ALL_BP_LOCATIONS bp_location
2858 has BL->OWNER always non-NULL. */
2859 if (bl->owner->thread != -1
2860 && !valid_thread_id (bl->owner->thread))
2863 switch_to_program_space_and_thread (bl->pspace);
2865 /* For targets that support global breakpoints, there's no need
2866 to select an inferior to insert breakpoint to. In fact, even
2867 if we aren't attached to any process yet, we should still
2868 insert breakpoints. */
2869 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2870 && ptid_equal (inferior_ptid, null_ptid))
2873 val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
2874 &hw_breakpoint_error, &hw_bp_error_explained_already);
2879 /* If we failed to insert all locations of a watchpoint, remove
2880 them, as half-inserted watchpoint is of limited use. */
2881 ALL_BREAKPOINTS (bpt)
2883 int some_failed = 0;
2884 struct bp_location *loc;
2886 if (!is_hardware_watchpoint (bpt))
2889 if (!breakpoint_enabled (bpt))
2892 if (bpt->disposition == disp_del_at_next_stop)
2895 for (loc = bpt->loc; loc; loc = loc->next)
2896 if (!loc->inserted && should_be_inserted (loc))
2903 for (loc = bpt->loc; loc; loc = loc->next)
2905 remove_breakpoint (loc, mark_uninserted);
2907 hw_breakpoint_error = 1;
2908 fprintf_unfiltered (tmp_error_stream,
2909 "Could not insert hardware watchpoint %d.\n",
2917 /* If a hardware breakpoint or watchpoint was inserted, add a
2918 message about possibly exhausted resources. */
2919 if (hw_breakpoint_error && !hw_bp_error_explained_already)
2921 fprintf_unfiltered (tmp_error_stream,
2922 "Could not insert hardware breakpoints:\n\
2923 You may have requested too many hardware breakpoints/watchpoints.\n");
2925 target_terminal_ours_for_output ();
2926 error_stream (tmp_error_stream);
2929 do_cleanups (cleanups);
2932 /* Used when the program stops.
2933 Returns zero if successful, or non-zero if there was a problem
2934 removing a breakpoint location. */
2937 remove_breakpoints (void)
2939 struct bp_location *bl, **blp_tmp;
2942 ALL_BP_LOCATIONS (bl, blp_tmp)
2944 if (bl->inserted && !is_tracepoint (bl->owner))
2945 val |= remove_breakpoint (bl, mark_uninserted);
2950 /* Remove breakpoints of process PID. */
2953 remove_breakpoints_pid (int pid)
2955 struct bp_location *bl, **blp_tmp;
2957 struct inferior *inf = find_inferior_pid (pid);
2959 ALL_BP_LOCATIONS (bl, blp_tmp)
2961 if (bl->pspace != inf->pspace)
2964 if (bl->owner->type == bp_dprintf)
2969 val = remove_breakpoint (bl, mark_uninserted);
2978 reattach_breakpoints (int pid)
2980 struct cleanup *old_chain;
2981 struct bp_location *bl, **blp_tmp;
2983 struct ui_file *tmp_error_stream;
2984 int dummy1 = 0, dummy2 = 0, dummy3 = 0;
2985 struct inferior *inf;
2986 struct thread_info *tp;
2988 tp = any_live_thread_of_process (pid);
2992 inf = find_inferior_pid (pid);
2993 old_chain = save_inferior_ptid ();
2995 inferior_ptid = tp->ptid;
2997 tmp_error_stream = mem_fileopen ();
2998 make_cleanup_ui_file_delete (tmp_error_stream);
3000 ALL_BP_LOCATIONS (bl, blp_tmp)
3002 if (bl->pspace != inf->pspace)
3008 val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2, &dummy3);
3011 do_cleanups (old_chain);
3016 do_cleanups (old_chain);
3020 static int internal_breakpoint_number = -1;
3022 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3023 If INTERNAL is non-zero, the breakpoint number will be populated
3024 from internal_breakpoint_number and that variable decremented.
3025 Otherwise the breakpoint number will be populated from
3026 breakpoint_count and that value incremented. Internal breakpoints
3027 do not set the internal var bpnum. */
3029 set_breakpoint_number (int internal, struct breakpoint *b)
3032 b->number = internal_breakpoint_number--;
3035 set_breakpoint_count (breakpoint_count + 1);
3036 b->number = breakpoint_count;
3040 static struct breakpoint *
3041 create_internal_breakpoint (struct gdbarch *gdbarch,
3042 CORE_ADDR address, enum bptype type,
3043 const struct breakpoint_ops *ops)
3045 struct symtab_and_line sal;
3046 struct breakpoint *b;
3048 init_sal (&sal); /* Initialize to zeroes. */
3051 sal.section = find_pc_overlay (sal.pc);
3052 sal.pspace = current_program_space;
3054 b = set_raw_breakpoint (gdbarch, sal, type, ops);
3055 b->number = internal_breakpoint_number--;
3056 b->disposition = disp_donttouch;
3061 static const char *const longjmp_names[] =
3063 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3065 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3067 /* Per-objfile data private to breakpoint.c. */
3068 struct breakpoint_objfile_data
3070 /* Minimal symbol for "_ovly_debug_event" (if any). */
3071 struct minimal_symbol *overlay_msym;
3073 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3074 struct minimal_symbol *longjmp_msym[NUM_LONGJMP_NAMES];
3076 /* True if we have looked for longjmp probes. */
3077 int longjmp_searched;
3079 /* SystemTap probe points for longjmp (if any). */
3080 VEC (probe_p) *longjmp_probes;
3082 /* Minimal symbol for "std::terminate()" (if any). */
3083 struct minimal_symbol *terminate_msym;
3085 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3086 struct minimal_symbol *exception_msym;
3088 /* True if we have looked for exception probes. */
3089 int exception_searched;
3091 /* SystemTap probe points for unwinding (if any). */
3092 VEC (probe_p) *exception_probes;
3095 static const struct objfile_data *breakpoint_objfile_key;
3097 /* Minimal symbol not found sentinel. */
3098 static struct minimal_symbol msym_not_found;
3100 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3103 msym_not_found_p (const struct minimal_symbol *msym)
3105 return msym == &msym_not_found;
3108 /* Return per-objfile data needed by breakpoint.c.
3109 Allocate the data if necessary. */
3111 static struct breakpoint_objfile_data *
3112 get_breakpoint_objfile_data (struct objfile *objfile)
3114 struct breakpoint_objfile_data *bp_objfile_data;
3116 bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key);
3117 if (bp_objfile_data == NULL)
3119 bp_objfile_data = obstack_alloc (&objfile->objfile_obstack,
3120 sizeof (*bp_objfile_data));
3122 memset (bp_objfile_data, 0, sizeof (*bp_objfile_data));
3123 set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data);
3125 return bp_objfile_data;
3129 free_breakpoint_probes (struct objfile *obj, void *data)
3131 struct breakpoint_objfile_data *bp_objfile_data = data;
3133 VEC_free (probe_p, bp_objfile_data->longjmp_probes);
3134 VEC_free (probe_p, bp_objfile_data->exception_probes);
3138 create_overlay_event_breakpoint (void)
3140 struct objfile *objfile;
3141 const char *const func_name = "_ovly_debug_event";
3143 ALL_OBJFILES (objfile)
3145 struct breakpoint *b;
3146 struct breakpoint_objfile_data *bp_objfile_data;
3149 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3151 if (msym_not_found_p (bp_objfile_data->overlay_msym))
3154 if (bp_objfile_data->overlay_msym == NULL)
3156 struct minimal_symbol *m;
3158 m = lookup_minimal_symbol_text (func_name, objfile);
3161 /* Avoid future lookups in this objfile. */
3162 bp_objfile_data->overlay_msym = &msym_not_found;
3165 bp_objfile_data->overlay_msym = m;
3168 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym);
3169 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
3171 &internal_breakpoint_ops);
3172 b->addr_string = xstrdup (func_name);
3174 if (overlay_debugging == ovly_auto)
3176 b->enable_state = bp_enabled;
3177 overlay_events_enabled = 1;
3181 b->enable_state = bp_disabled;
3182 overlay_events_enabled = 0;
3185 update_global_location_list (1);
3189 create_longjmp_master_breakpoint (void)
3191 struct program_space *pspace;
3192 struct cleanup *old_chain;
3194 old_chain = save_current_program_space ();
3196 ALL_PSPACES (pspace)
3198 struct objfile *objfile;
3200 set_current_program_space (pspace);
3202 ALL_OBJFILES (objfile)
3205 struct gdbarch *gdbarch;
3206 struct breakpoint_objfile_data *bp_objfile_data;
3208 gdbarch = get_objfile_arch (objfile);
3209 if (!gdbarch_get_longjmp_target_p (gdbarch))
3212 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3214 if (!bp_objfile_data->longjmp_searched)
3216 bp_objfile_data->longjmp_probes
3217 = find_probes_in_objfile (objfile, "libc", "longjmp");
3218 bp_objfile_data->longjmp_searched = 1;
3221 if (bp_objfile_data->longjmp_probes != NULL)
3224 struct probe *probe;
3225 struct gdbarch *gdbarch = get_objfile_arch (objfile);
3228 VEC_iterate (probe_p,
3229 bp_objfile_data->longjmp_probes,
3233 struct breakpoint *b;
3235 b = create_internal_breakpoint (gdbarch, probe->address,
3237 &internal_breakpoint_ops);
3238 b->addr_string = xstrdup ("-probe-stap libc:longjmp");
3239 b->enable_state = bp_disabled;
3245 for (i = 0; i < NUM_LONGJMP_NAMES; i++)
3247 struct breakpoint *b;
3248 const char *func_name;
3251 if (msym_not_found_p (bp_objfile_data->longjmp_msym[i]))
3254 func_name = longjmp_names[i];
3255 if (bp_objfile_data->longjmp_msym[i] == NULL)
3257 struct minimal_symbol *m;
3259 m = lookup_minimal_symbol_text (func_name, objfile);
3262 /* Prevent future lookups in this objfile. */
3263 bp_objfile_data->longjmp_msym[i] = &msym_not_found;
3266 bp_objfile_data->longjmp_msym[i] = m;
3269 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]);
3270 b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master,
3271 &internal_breakpoint_ops);
3272 b->addr_string = xstrdup (func_name);
3273 b->enable_state = bp_disabled;
3277 update_global_location_list (1);
3279 do_cleanups (old_chain);
3282 /* Create a master std::terminate breakpoint. */
3284 create_std_terminate_master_breakpoint (void)
3286 struct program_space *pspace;
3287 struct cleanup *old_chain;
3288 const char *const func_name = "std::terminate()";
3290 old_chain = save_current_program_space ();
3292 ALL_PSPACES (pspace)
3294 struct objfile *objfile;
3297 set_current_program_space (pspace);
3299 ALL_OBJFILES (objfile)
3301 struct breakpoint *b;
3302 struct breakpoint_objfile_data *bp_objfile_data;
3304 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3306 if (msym_not_found_p (bp_objfile_data->terminate_msym))
3309 if (bp_objfile_data->terminate_msym == NULL)
3311 struct minimal_symbol *m;
3313 m = lookup_minimal_symbol (func_name, NULL, objfile);
3314 if (m == NULL || (MSYMBOL_TYPE (m) != mst_text
3315 && MSYMBOL_TYPE (m) != mst_file_text))
3317 /* Prevent future lookups in this objfile. */
3318 bp_objfile_data->terminate_msym = &msym_not_found;
3321 bp_objfile_data->terminate_msym = m;
3324 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym);
3325 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
3326 bp_std_terminate_master,
3327 &internal_breakpoint_ops);
3328 b->addr_string = xstrdup (func_name);
3329 b->enable_state = bp_disabled;
3333 update_global_location_list (1);
3335 do_cleanups (old_chain);
3338 /* Install a master breakpoint on the unwinder's debug hook. */
3341 create_exception_master_breakpoint (void)
3343 struct objfile *objfile;
3344 const char *const func_name = "_Unwind_DebugHook";
3346 ALL_OBJFILES (objfile)
3348 struct breakpoint *b;
3349 struct gdbarch *gdbarch;
3350 struct breakpoint_objfile_data *bp_objfile_data;
3353 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3355 /* We prefer the SystemTap probe point if it exists. */
3356 if (!bp_objfile_data->exception_searched)
3358 bp_objfile_data->exception_probes
3359 = find_probes_in_objfile (objfile, "libgcc", "unwind");
3360 bp_objfile_data->exception_searched = 1;
3363 if (bp_objfile_data->exception_probes != NULL)
3365 struct gdbarch *gdbarch = get_objfile_arch (objfile);
3367 struct probe *probe;
3370 VEC_iterate (probe_p,
3371 bp_objfile_data->exception_probes,
3375 struct breakpoint *b;
3377 b = create_internal_breakpoint (gdbarch, probe->address,
3378 bp_exception_master,
3379 &internal_breakpoint_ops);
3380 b->addr_string = xstrdup ("-probe-stap libgcc:unwind");
3381 b->enable_state = bp_disabled;
3387 /* Otherwise, try the hook function. */
3389 if (msym_not_found_p (bp_objfile_data->exception_msym))
3392 gdbarch = get_objfile_arch (objfile);
3394 if (bp_objfile_data->exception_msym == NULL)
3396 struct minimal_symbol *debug_hook;
3398 debug_hook = lookup_minimal_symbol (func_name, NULL, objfile);
3399 if (debug_hook == NULL)
3401 bp_objfile_data->exception_msym = &msym_not_found;
3405 bp_objfile_data->exception_msym = debug_hook;
3408 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym);
3409 addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
3411 b = create_internal_breakpoint (gdbarch, addr, bp_exception_master,
3412 &internal_breakpoint_ops);
3413 b->addr_string = xstrdup (func_name);
3414 b->enable_state = bp_disabled;
3417 update_global_location_list (1);
3421 update_breakpoints_after_exec (void)
3423 struct breakpoint *b, *b_tmp;
3424 struct bp_location *bploc, **bplocp_tmp;
3426 /* We're about to delete breakpoints from GDB's lists. If the
3427 INSERTED flag is true, GDB will try to lift the breakpoints by
3428 writing the breakpoints' "shadow contents" back into memory. The
3429 "shadow contents" are NOT valid after an exec, so GDB should not
3430 do that. Instead, the target is responsible from marking
3431 breakpoints out as soon as it detects an exec. We don't do that
3432 here instead, because there may be other attempts to delete
3433 breakpoints after detecting an exec and before reaching here. */
3434 ALL_BP_LOCATIONS (bploc, bplocp_tmp)
3435 if (bploc->pspace == current_program_space)
3436 gdb_assert (!bploc->inserted);
3438 ALL_BREAKPOINTS_SAFE (b, b_tmp)
3440 if (b->pspace != current_program_space)
3443 /* Solib breakpoints must be explicitly reset after an exec(). */
3444 if (b->type == bp_shlib_event)
3446 delete_breakpoint (b);
3450 /* JIT breakpoints must be explicitly reset after an exec(). */
3451 if (b->type == bp_jit_event)
3453 delete_breakpoint (b);
3457 /* Thread event breakpoints must be set anew after an exec(),
3458 as must overlay event and longjmp master breakpoints. */
3459 if (b->type == bp_thread_event || b->type == bp_overlay_event
3460 || b->type == bp_longjmp_master || b->type == bp_std_terminate_master
3461 || b->type == bp_exception_master)
3463 delete_breakpoint (b);
3467 /* Step-resume breakpoints are meaningless after an exec(). */
3468 if (b->type == bp_step_resume || b->type == bp_hp_step_resume)
3470 delete_breakpoint (b);
3474 /* Longjmp and longjmp-resume breakpoints are also meaningless
3476 if (b->type == bp_longjmp || b->type == bp_longjmp_resume
3477 || b->type == bp_longjmp_call_dummy
3478 || b->type == bp_exception || b->type == bp_exception_resume)
3480 delete_breakpoint (b);
3484 if (b->type == bp_catchpoint)
3486 /* For now, none of the bp_catchpoint breakpoints need to
3487 do anything at this point. In the future, if some of
3488 the catchpoints need to something, we will need to add
3489 a new method, and call this method from here. */
3493 /* bp_finish is a special case. The only way we ought to be able
3494 to see one of these when an exec() has happened, is if the user
3495 caught a vfork, and then said "finish". Ordinarily a finish just
3496 carries them to the call-site of the current callee, by setting
3497 a temporary bp there and resuming. But in this case, the finish
3498 will carry them entirely through the vfork & exec.
3500 We don't want to allow a bp_finish to remain inserted now. But
3501 we can't safely delete it, 'cause finish_command has a handle to
3502 the bp on a bpstat, and will later want to delete it. There's a
3503 chance (and I've seen it happen) that if we delete the bp_finish
3504 here, that its storage will get reused by the time finish_command
3505 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3506 We really must allow finish_command to delete a bp_finish.
3508 In the absence of a general solution for the "how do we know
3509 it's safe to delete something others may have handles to?"
3510 problem, what we'll do here is just uninsert the bp_finish, and
3511 let finish_command delete it.
3513 (We know the bp_finish is "doomed" in the sense that it's
3514 momentary, and will be deleted as soon as finish_command sees
3515 the inferior stopped. So it doesn't matter that the bp's
3516 address is probably bogus in the new a.out, unlike e.g., the
3517 solib breakpoints.) */
3519 if (b->type == bp_finish)
3524 /* Without a symbolic address, we have little hope of the
3525 pre-exec() address meaning the same thing in the post-exec()
3527 if (b->addr_string == NULL)
3529 delete_breakpoint (b);
3533 /* FIXME what about longjmp breakpoints? Re-create them here? */
3534 create_overlay_event_breakpoint ();
3535 create_longjmp_master_breakpoint ();
3536 create_std_terminate_master_breakpoint ();
3537 create_exception_master_breakpoint ();
3541 detach_breakpoints (ptid_t ptid)
3543 struct bp_location *bl, **blp_tmp;
3545 struct cleanup *old_chain = save_inferior_ptid ();
3546 struct inferior *inf = current_inferior ();
3548 if (PIDGET (ptid) == PIDGET (inferior_ptid))
3549 error (_("Cannot detach breakpoints of inferior_ptid"));
3551 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3552 inferior_ptid = ptid;
3553 ALL_BP_LOCATIONS (bl, blp_tmp)
3555 if (bl->pspace != inf->pspace)
3559 val |= remove_breakpoint_1 (bl, mark_inserted);
3562 /* Detach single-step breakpoints as well. */
3563 detach_single_step_breakpoints ();
3565 do_cleanups (old_chain);
3569 /* Remove the breakpoint location BL from the current address space.
3570 Note that this is used to detach breakpoints from a child fork.
3571 When we get here, the child isn't in the inferior list, and neither
3572 do we have objects to represent its address space --- we should
3573 *not* look at bl->pspace->aspace here. */
3576 remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is)
3580 /* BL is never in moribund_locations by our callers. */
3581 gdb_assert (bl->owner != NULL);
3583 if (bl->owner->enable_state == bp_permanent)
3584 /* Permanent breakpoints cannot be inserted or removed. */
3587 /* The type of none suggests that owner is actually deleted.
3588 This should not ever happen. */
3589 gdb_assert (bl->owner->type != bp_none);
3591 if (bl->loc_type == bp_loc_software_breakpoint
3592 || bl->loc_type == bp_loc_hardware_breakpoint)
3594 /* "Normal" instruction breakpoint: either the standard
3595 trap-instruction bp (bp_breakpoint), or a
3596 bp_hardware_breakpoint. */
3598 /* First check to see if we have to handle an overlay. */
3599 if (overlay_debugging == ovly_off
3600 || bl->section == NULL
3601 || !(section_is_overlay (bl->section)))
3603 /* No overlay handling: just remove the breakpoint. */
3604 val = bl->owner->ops->remove_location (bl);
3608 /* This breakpoint is in an overlay section.
3609 Did we set a breakpoint at the LMA? */
3610 if (!overlay_events_enabled)
3612 /* Yes -- overlay event support is not active, so we
3613 should have set a breakpoint at the LMA. Remove it.
3615 /* Ignore any failures: if the LMA is in ROM, we will
3616 have already warned when we failed to insert it. */
3617 if (bl->loc_type == bp_loc_hardware_breakpoint)
3618 target_remove_hw_breakpoint (bl->gdbarch,
3619 &bl->overlay_target_info);
3621 target_remove_breakpoint (bl->gdbarch,
3622 &bl->overlay_target_info);
3624 /* Did we set a breakpoint at the VMA?
3625 If so, we will have marked the breakpoint 'inserted'. */
3628 /* Yes -- remove it. Previously we did not bother to
3629 remove the breakpoint if the section had been
3630 unmapped, but let's not rely on that being safe. We
3631 don't know what the overlay manager might do. */
3633 /* However, we should remove *software* breakpoints only
3634 if the section is still mapped, or else we overwrite
3635 wrong code with the saved shadow contents. */
3636 if (bl->loc_type == bp_loc_hardware_breakpoint
3637 || section_is_mapped (bl->section))
3638 val = bl->owner->ops->remove_location (bl);
3644 /* No -- not inserted, so no need to remove. No error. */
3649 /* In some cases, we might not be able to remove a breakpoint
3650 in a shared library that has already been removed, but we
3651 have not yet processed the shlib unload event. */
3652 if (val && solib_name_from_address (bl->pspace, bl->address))
3657 bl->inserted = (is == mark_inserted);
3659 else if (bl->loc_type == bp_loc_hardware_watchpoint)
3661 gdb_assert (bl->owner->ops != NULL
3662 && bl->owner->ops->remove_location != NULL);
3664 bl->inserted = (is == mark_inserted);
3665 bl->owner->ops->remove_location (bl);
3667 /* Failure to remove any of the hardware watchpoints comes here. */
3668 if ((is == mark_uninserted) && (bl->inserted))
3669 warning (_("Could not remove hardware watchpoint %d."),
3672 else if (bl->owner->type == bp_catchpoint
3673 && breakpoint_enabled (bl->owner)
3676 gdb_assert (bl->owner->ops != NULL
3677 && bl->owner->ops->remove_location != NULL);
3679 val = bl->owner->ops->remove_location (bl);
3683 bl->inserted = (is == mark_inserted);
3690 remove_breakpoint (struct bp_location *bl, insertion_state_t is)
3693 struct cleanup *old_chain;
3695 /* BL is never in moribund_locations by our callers. */
3696 gdb_assert (bl->owner != NULL);
3698 if (bl->owner->enable_state == bp_permanent)
3699 /* Permanent breakpoints cannot be inserted or removed. */
3702 /* The type of none suggests that owner is actually deleted.
3703 This should not ever happen. */
3704 gdb_assert (bl->owner->type != bp_none);
3706 old_chain = save_current_space_and_thread ();
3708 switch_to_program_space_and_thread (bl->pspace);
3710 ret = remove_breakpoint_1 (bl, is);
3712 do_cleanups (old_chain);
3716 /* Clear the "inserted" flag in all breakpoints. */
3719 mark_breakpoints_out (void)
3721 struct bp_location *bl, **blp_tmp;
3723 ALL_BP_LOCATIONS (bl, blp_tmp)
3724 if (bl->pspace == current_program_space)
3728 /* Clear the "inserted" flag in all breakpoints and delete any
3729 breakpoints which should go away between runs of the program.
3731 Plus other such housekeeping that has to be done for breakpoints
3734 Note: this function gets called at the end of a run (by
3735 generic_mourn_inferior) and when a run begins (by
3736 init_wait_for_inferior). */
3741 breakpoint_init_inferior (enum inf_context context)
3743 struct breakpoint *b, *b_tmp;
3744 struct bp_location *bl, **blp_tmp;
3746 struct program_space *pspace = current_program_space;
3748 /* If breakpoint locations are shared across processes, then there's
3750 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
3753 ALL_BP_LOCATIONS (bl, blp_tmp)
3755 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3756 if (bl->pspace == pspace
3757 && bl->owner->enable_state != bp_permanent)
3761 ALL_BREAKPOINTS_SAFE (b, b_tmp)
3763 if (b->loc && b->loc->pspace != pspace)
3769 case bp_longjmp_call_dummy:
3771 /* If the call dummy breakpoint is at the entry point it will
3772 cause problems when the inferior is rerun, so we better get
3775 case bp_watchpoint_scope:
3777 /* Also get rid of scope breakpoints. */
3779 case bp_shlib_event:
3781 /* Also remove solib event breakpoints. Their addresses may
3782 have changed since the last time we ran the program.
3783 Actually we may now be debugging against different target;
3784 and so the solib backend that installed this breakpoint may
3785 not be used in by the target. E.g.,
3787 (gdb) file prog-linux
3788 (gdb) run # native linux target
3791 (gdb) file prog-win.exe
3792 (gdb) tar rem :9999 # remote Windows gdbserver.
3795 case bp_step_resume:
3797 /* Also remove step-resume breakpoints. */
3799 delete_breakpoint (b);
3803 case bp_hardware_watchpoint:
3804 case bp_read_watchpoint:
3805 case bp_access_watchpoint:
3807 struct watchpoint *w = (struct watchpoint *) b;
3809 /* Likewise for watchpoints on local expressions. */
3810 if (w->exp_valid_block != NULL)
3811 delete_breakpoint (b);
3812 else if (context == inf_starting)
3814 /* Reset val field to force reread of starting value in
3815 insert_breakpoints. */
3817 value_free (w->val);
3828 /* Get rid of the moribund locations. */
3829 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix)
3830 decref_bp_location (&bl);
3831 VEC_free (bp_location_p, moribund_locations);
3834 /* These functions concern about actual breakpoints inserted in the
3835 target --- to e.g. check if we need to do decr_pc adjustment or if
3836 we need to hop over the bkpt --- so we check for address space
3837 match, not program space. */
3839 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
3840 exists at PC. It returns ordinary_breakpoint_here if it's an
3841 ordinary breakpoint, or permanent_breakpoint_here if it's a
3842 permanent breakpoint.
3843 - When continuing from a location with an ordinary breakpoint, we
3844 actually single step once before calling insert_breakpoints.
3845 - When continuing from a location with a permanent breakpoint, we
3846 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
3847 the target, to advance the PC past the breakpoint. */
3849 enum breakpoint_here
3850 breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
3852 struct bp_location *bl, **blp_tmp;
3853 int any_breakpoint_here = 0;
3855 ALL_BP_LOCATIONS (bl, blp_tmp)
3857 if (bl->loc_type != bp_loc_software_breakpoint
3858 && bl->loc_type != bp_loc_hardware_breakpoint)
3861 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3862 if ((breakpoint_enabled (bl->owner)
3863 || bl->owner->enable_state == bp_permanent)
3864 && breakpoint_location_address_match (bl, aspace, pc))
3866 if (overlay_debugging
3867 && section_is_overlay (bl->section)
3868 && !section_is_mapped (bl->section))
3869 continue; /* unmapped overlay -- can't be a match */
3870 else if (bl->owner->enable_state == bp_permanent)
3871 return permanent_breakpoint_here;
3873 any_breakpoint_here = 1;
3877 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
3880 /* Return true if there's a moribund breakpoint at PC. */
3883 moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
3885 struct bp_location *loc;
3888 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
3889 if (breakpoint_location_address_match (loc, aspace, pc))
3895 /* Returns non-zero if there's a breakpoint inserted at PC, which is
3896 inserted using regular breakpoint_chain / bp_location array
3897 mechanism. This does not check for single-step breakpoints, which
3898 are inserted and removed using direct target manipulation. */
3901 regular_breakpoint_inserted_here_p (struct address_space *aspace,
3904 struct bp_location *bl, **blp_tmp;
3906 ALL_BP_LOCATIONS (bl, blp_tmp)
3908 if (bl->loc_type != bp_loc_software_breakpoint
3909 && bl->loc_type != bp_loc_hardware_breakpoint)
3913 && breakpoint_location_address_match (bl, aspace, pc))
3915 if (overlay_debugging
3916 && section_is_overlay (bl->section)
3917 && !section_is_mapped (bl->section))
3918 continue; /* unmapped overlay -- can't be a match */
3926 /* Returns non-zero iff there's either regular breakpoint
3927 or a single step breakpoint inserted at PC. */
3930 breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
3932 if (regular_breakpoint_inserted_here_p (aspace, pc))
3935 if (single_step_breakpoint_inserted_here_p (aspace, pc))
3941 /* This function returns non-zero iff there is a software breakpoint
3945 software_breakpoint_inserted_here_p (struct address_space *aspace,
3948 struct bp_location *bl, **blp_tmp;
3950 ALL_BP_LOCATIONS (bl, blp_tmp)
3952 if (bl->loc_type != bp_loc_software_breakpoint)
3956 && breakpoint_address_match (bl->pspace->aspace, bl->address,
3959 if (overlay_debugging
3960 && section_is_overlay (bl->section)
3961 && !section_is_mapped (bl->section))
3962 continue; /* unmapped overlay -- can't be a match */
3968 /* Also check for software single-step breakpoints. */
3969 if (single_step_breakpoint_inserted_here_p (aspace, pc))
3976 hardware_watchpoint_inserted_in_range (struct address_space *aspace,
3977 CORE_ADDR addr, ULONGEST len)
3979 struct breakpoint *bpt;
3981 ALL_BREAKPOINTS (bpt)
3983 struct bp_location *loc;
3985 if (bpt->type != bp_hardware_watchpoint
3986 && bpt->type != bp_access_watchpoint)
3989 if (!breakpoint_enabled (bpt))
3992 for (loc = bpt->loc; loc; loc = loc->next)
3993 if (loc->pspace->aspace == aspace && loc->inserted)
3997 /* Check for intersection. */
3998 l = max (loc->address, addr);
3999 h = min (loc->address + loc->length, addr + len);
4007 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
4008 PC is valid for process/thread PTID. */
4011 breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc,
4014 struct bp_location *bl, **blp_tmp;
4015 /* The thread and task IDs associated to PTID, computed lazily. */
4019 ALL_BP_LOCATIONS (bl, blp_tmp)
4021 if (bl->loc_type != bp_loc_software_breakpoint
4022 && bl->loc_type != bp_loc_hardware_breakpoint)
4025 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
4026 if (!breakpoint_enabled (bl->owner)
4027 && bl->owner->enable_state != bp_permanent)
4030 if (!breakpoint_location_address_match (bl, aspace, pc))
4033 if (bl->owner->thread != -1)
4035 /* This is a thread-specific breakpoint. Check that ptid
4036 matches that thread. If thread hasn't been computed yet,
4037 it is now time to do so. */
4039 thread = pid_to_thread_id (ptid);
4040 if (bl->owner->thread != thread)
4044 if (bl->owner->task != 0)
4046 /* This is a task-specific breakpoint. Check that ptid
4047 matches that task. If task hasn't been computed yet,
4048 it is now time to do so. */
4050 task = ada_get_task_number (ptid);
4051 if (bl->owner->task != task)
4055 if (overlay_debugging
4056 && section_is_overlay (bl->section)
4057 && !section_is_mapped (bl->section))
4058 continue; /* unmapped overlay -- can't be a match */
4067 /* bpstat stuff. External routines' interfaces are documented
4071 is_catchpoint (struct breakpoint *ep)
4073 return (ep->type == bp_catchpoint);
4076 /* Frees any storage that is part of a bpstat. Does not walk the
4080 bpstat_free (bpstat bs)
4082 if (bs->old_val != NULL)
4083 value_free (bs->old_val);
4084 decref_counted_command_line (&bs->commands);
4085 decref_bp_location (&bs->bp_location_at);
4089 /* Clear a bpstat so that it says we are not at any breakpoint.
4090 Also free any storage that is part of a bpstat. */
4093 bpstat_clear (bpstat *bsp)
4110 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4111 is part of the bpstat is copied as well. */
4114 bpstat_copy (bpstat bs)
4118 bpstat retval = NULL;
4123 for (; bs != NULL; bs = bs->next)
4125 tmp = (bpstat) xmalloc (sizeof (*tmp));
4126 memcpy (tmp, bs, sizeof (*tmp));
4127 incref_counted_command_line (tmp->commands);
4128 incref_bp_location (tmp->bp_location_at);
4129 if (bs->old_val != NULL)
4131 tmp->old_val = value_copy (bs->old_val);
4132 release_value (tmp->old_val);
4136 /* This is the first thing in the chain. */
4146 /* Find the bpstat associated with this breakpoint. */
4149 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
4154 for (; bsp != NULL; bsp = bsp->next)
4156 if (bsp->breakpoint_at == breakpoint)
4162 /* See breakpoint.h. */
4164 enum bpstat_signal_value
4165 bpstat_explains_signal (bpstat bsp)
4167 enum bpstat_signal_value result = BPSTAT_SIGNAL_NO;
4169 for (; bsp != NULL; bsp = bsp->next)
4171 /* Ensure that, if we ever entered this loop, then we at least
4172 return BPSTAT_SIGNAL_HIDE. */
4173 enum bpstat_signal_value newval = BPSTAT_SIGNAL_HIDE;
4175 if (bsp->breakpoint_at != NULL)
4176 newval = bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at);
4178 if (newval > result)
4185 /* Put in *NUM the breakpoint number of the first breakpoint we are
4186 stopped at. *BSP upon return is a bpstat which points to the
4187 remaining breakpoints stopped at (but which is not guaranteed to be
4188 good for anything but further calls to bpstat_num).
4190 Return 0 if passed a bpstat which does not indicate any breakpoints.
4191 Return -1 if stopped at a breakpoint that has been deleted since
4193 Return 1 otherwise. */
4196 bpstat_num (bpstat *bsp, int *num)
4198 struct breakpoint *b;
4201 return 0; /* No more breakpoint values */
4203 /* We assume we'll never have several bpstats that correspond to a
4204 single breakpoint -- otherwise, this function might return the
4205 same number more than once and this will look ugly. */
4206 b = (*bsp)->breakpoint_at;
4207 *bsp = (*bsp)->next;
4209 return -1; /* breakpoint that's been deleted since */
4211 *num = b->number; /* We have its number */
4215 /* See breakpoint.h. */
4218 bpstat_clear_actions (void)
4220 struct thread_info *tp;
4223 if (ptid_equal (inferior_ptid, null_ptid))
4226 tp = find_thread_ptid (inferior_ptid);
4230 for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next)
4232 decref_counted_command_line (&bs->commands);
4234 if (bs->old_val != NULL)
4236 value_free (bs->old_val);
4242 /* Called when a command is about to proceed the inferior. */
4245 breakpoint_about_to_proceed (void)
4247 if (!ptid_equal (inferior_ptid, null_ptid))
4249 struct thread_info *tp = inferior_thread ();
4251 /* Allow inferior function calls in breakpoint commands to not
4252 interrupt the command list. When the call finishes
4253 successfully, the inferior will be standing at the same
4254 breakpoint as if nothing happened. */
4255 if (tp->control.in_infcall)
4259 breakpoint_proceeded = 1;
4262 /* Stub for cleaning up our state if we error-out of a breakpoint
4265 cleanup_executing_breakpoints (void *ignore)
4267 executing_breakpoint_commands = 0;
4270 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4271 or its equivalent. */
4274 command_line_is_silent (struct command_line *cmd)
4276 return cmd && (strcmp ("silent", cmd->line) == 0
4277 || (xdb_commands && strcmp ("Q", cmd->line) == 0));
4280 /* Execute all the commands associated with all the breakpoints at
4281 this location. Any of these commands could cause the process to
4282 proceed beyond this point, etc. We look out for such changes by
4283 checking the global "breakpoint_proceeded" after each command.
4285 Returns true if a breakpoint command resumed the inferior. In that
4286 case, it is the caller's responsibility to recall it again with the
4287 bpstat of the current thread. */
4290 bpstat_do_actions_1 (bpstat *bsp)
4293 struct cleanup *old_chain;
4296 /* Avoid endless recursion if a `source' command is contained
4298 if (executing_breakpoint_commands)
4301 executing_breakpoint_commands = 1;
4302 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
4304 prevent_dont_repeat ();
4306 /* This pointer will iterate over the list of bpstat's. */
4309 breakpoint_proceeded = 0;
4310 for (; bs != NULL; bs = bs->next)
4312 struct counted_command_line *ccmd;
4313 struct command_line *cmd;
4314 struct cleanup *this_cmd_tree_chain;
4316 /* Take ownership of the BSP's command tree, if it has one.
4318 The command tree could legitimately contain commands like
4319 'step' and 'next', which call clear_proceed_status, which
4320 frees stop_bpstat's command tree. To make sure this doesn't
4321 free the tree we're executing out from under us, we need to
4322 take ownership of the tree ourselves. Since a given bpstat's
4323 commands are only executed once, we don't need to copy it; we
4324 can clear the pointer in the bpstat, and make sure we free
4325 the tree when we're done. */
4326 ccmd = bs->commands;
4327 bs->commands = NULL;
4328 this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd);
4329 cmd = ccmd ? ccmd->commands : NULL;
4330 if (command_line_is_silent (cmd))
4332 /* The action has been already done by bpstat_stop_status. */
4338 execute_control_command (cmd);
4340 if (breakpoint_proceeded)
4346 /* We can free this command tree now. */
4347 do_cleanups (this_cmd_tree_chain);
4349 if (breakpoint_proceeded)
4351 if (target_can_async_p ())
4352 /* If we are in async mode, then the target might be still
4353 running, not stopped at any breakpoint, so nothing for
4354 us to do here -- just return to the event loop. */
4357 /* In sync mode, when execute_control_command returns
4358 we're already standing on the next breakpoint.
4359 Breakpoint commands for that stop were not run, since
4360 execute_command does not run breakpoint commands --
4361 only command_line_handler does, but that one is not
4362 involved in execution of breakpoint commands. So, we
4363 can now execute breakpoint commands. It should be
4364 noted that making execute_command do bpstat actions is
4365 not an option -- in this case we'll have recursive
4366 invocation of bpstat for each breakpoint with a
4367 command, and can easily blow up GDB stack. Instead, we
4368 return true, which will trigger the caller to recall us
4369 with the new stop_bpstat. */
4374 do_cleanups (old_chain);
4379 bpstat_do_actions (void)
4381 struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup ();
4383 /* Do any commands attached to breakpoint we are stopped at. */
4384 while (!ptid_equal (inferior_ptid, null_ptid)
4385 && target_has_execution
4386 && !is_exited (inferior_ptid)
4387 && !is_executing (inferior_ptid))
4388 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4389 and only return when it is stopped at the next breakpoint, we
4390 keep doing breakpoint actions until it returns false to
4391 indicate the inferior was not resumed. */
4392 if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat))
4395 discard_cleanups (cleanup_if_error);
4398 /* Print out the (old or new) value associated with a watchpoint. */
4401 watchpoint_value_print (struct value *val, struct ui_file *stream)
4404 fprintf_unfiltered (stream, _("<unreadable>"));
4407 struct value_print_options opts;
4408 get_user_print_options (&opts);
4409 value_print (val, stream, &opts);
4413 /* Generic routine for printing messages indicating why we
4414 stopped. The behavior of this function depends on the value
4415 'print_it' in the bpstat structure. Under some circumstances we
4416 may decide not to print anything here and delegate the task to
4419 static enum print_stop_action
4420 print_bp_stop_message (bpstat bs)
4422 switch (bs->print_it)
4425 /* Nothing should be printed for this bpstat entry. */
4426 return PRINT_UNKNOWN;
4430 /* We still want to print the frame, but we already printed the
4431 relevant messages. */
4432 return PRINT_SRC_AND_LOC;
4435 case print_it_normal:
4437 struct breakpoint *b = bs->breakpoint_at;
4439 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4440 which has since been deleted. */
4442 return PRINT_UNKNOWN;
4444 /* Normal case. Call the breakpoint's print_it method. */
4445 return b->ops->print_it (bs);
4450 internal_error (__FILE__, __LINE__,
4451 _("print_bp_stop_message: unrecognized enum value"));
4456 /* A helper function that prints a shared library stopped event. */
4459 print_solib_event (int is_catchpoint)
4462 = !VEC_empty (char_ptr, current_program_space->deleted_solibs);
4464 = !VEC_empty (so_list_ptr, current_program_space->added_solibs);
4468 if (any_added || any_deleted)
4469 ui_out_text (current_uiout,
4470 _("Stopped due to shared library event:\n"));
4472 ui_out_text (current_uiout,
4473 _("Stopped due to shared library event (no "
4474 "libraries added or removed)\n"));
4477 if (ui_out_is_mi_like_p (current_uiout))
4478 ui_out_field_string (current_uiout, "reason",
4479 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT));
4483 struct cleanup *cleanup;
4487 ui_out_text (current_uiout, _(" Inferior unloaded "));
4488 cleanup = make_cleanup_ui_out_list_begin_end (current_uiout,
4491 VEC_iterate (char_ptr, current_program_space->deleted_solibs,
4496 ui_out_text (current_uiout, " ");
4497 ui_out_field_string (current_uiout, "library", name);
4498 ui_out_text (current_uiout, "\n");
4501 do_cleanups (cleanup);
4506 struct so_list *iter;
4508 struct cleanup *cleanup;
4510 ui_out_text (current_uiout, _(" Inferior loaded "));
4511 cleanup = make_cleanup_ui_out_list_begin_end (current_uiout,
4514 VEC_iterate (so_list_ptr, current_program_space->added_solibs,
4519 ui_out_text (current_uiout, " ");
4520 ui_out_field_string (current_uiout, "library", iter->so_name);
4521 ui_out_text (current_uiout, "\n");
4524 do_cleanups (cleanup);
4528 /* Print a message indicating what happened. This is called from
4529 normal_stop(). The input to this routine is the head of the bpstat
4530 list - a list of the eventpoints that caused this stop. KIND is
4531 the target_waitkind for the stopping event. This
4532 routine calls the generic print routine for printing a message
4533 about reasons for stopping. This will print (for example) the
4534 "Breakpoint n," part of the output. The return value of this
4537 PRINT_UNKNOWN: Means we printed nothing.
4538 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4539 code to print the location. An example is
4540 "Breakpoint 1, " which should be followed by
4542 PRINT_SRC_ONLY: Means we printed something, but there is no need
4543 to also print the location part of the message.
4544 An example is the catch/throw messages, which
4545 don't require a location appended to the end.
4546 PRINT_NOTHING: We have done some printing and we don't need any
4547 further info to be printed. */
4549 enum print_stop_action
4550 bpstat_print (bpstat bs, int kind)
4554 /* Maybe another breakpoint in the chain caused us to stop.
4555 (Currently all watchpoints go on the bpstat whether hit or not.
4556 That probably could (should) be changed, provided care is taken
4557 with respect to bpstat_explains_signal). */
4558 for (; bs; bs = bs->next)
4560 val = print_bp_stop_message (bs);
4561 if (val == PRINT_SRC_ONLY
4562 || val == PRINT_SRC_AND_LOC
4563 || val == PRINT_NOTHING)
4567 /* If we had hit a shared library event breakpoint,
4568 print_bp_stop_message would print out this message. If we hit an
4569 OS-level shared library event, do the same thing. */
4570 if (kind == TARGET_WAITKIND_LOADED)
4572 print_solib_event (0);
4573 return PRINT_NOTHING;
4576 /* We reached the end of the chain, or we got a null BS to start
4577 with and nothing was printed. */
4578 return PRINT_UNKNOWN;
4581 /* Evaluate the expression EXP and return 1 if value is zero. This is
4582 used inside a catch_errors to evaluate the breakpoint condition.
4583 The argument is a "struct expression *" that has been cast to a
4584 "char *" to make it pass through catch_errors. */
4587 breakpoint_cond_eval (void *exp)
4589 struct value *mark = value_mark ();
4590 int i = !value_true (evaluate_expression ((struct expression *) exp));
4592 value_free_to_mark (mark);
4596 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4599 bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer)
4603 bs = (bpstat) xmalloc (sizeof (*bs));
4605 **bs_link_pointer = bs;
4606 *bs_link_pointer = &bs->next;
4607 bs->breakpoint_at = bl->owner;
4608 bs->bp_location_at = bl;
4609 incref_bp_location (bl);
4610 /* If the condition is false, etc., don't do the commands. */
4611 bs->commands = NULL;
4613 bs->print_it = print_it_normal;
4617 /* The target has stopped with waitstatus WS. Check if any hardware
4618 watchpoints have triggered, according to the target. */
4621 watchpoints_triggered (struct target_waitstatus *ws)
4623 int stopped_by_watchpoint = target_stopped_by_watchpoint ();
4625 struct breakpoint *b;
4627 if (!stopped_by_watchpoint)
4629 /* We were not stopped by a watchpoint. Mark all watchpoints
4630 as not triggered. */
4632 if (is_hardware_watchpoint (b))
4634 struct watchpoint *w = (struct watchpoint *) b;
4636 w->watchpoint_triggered = watch_triggered_no;
4642 if (!target_stopped_data_address (¤t_target, &addr))
4644 /* We were stopped by a watchpoint, but we don't know where.
4645 Mark all watchpoints as unknown. */
4647 if (is_hardware_watchpoint (b))
4649 struct watchpoint *w = (struct watchpoint *) b;
4651 w->watchpoint_triggered = watch_triggered_unknown;
4654 return stopped_by_watchpoint;
4657 /* The target could report the data address. Mark watchpoints
4658 affected by this data address as triggered, and all others as not
4662 if (is_hardware_watchpoint (b))
4664 struct watchpoint *w = (struct watchpoint *) b;
4665 struct bp_location *loc;
4667 w->watchpoint_triggered = watch_triggered_no;
4668 for (loc = b->loc; loc; loc = loc->next)
4670 if (is_masked_watchpoint (b))
4672 CORE_ADDR newaddr = addr & w->hw_wp_mask;
4673 CORE_ADDR start = loc->address & w->hw_wp_mask;
4675 if (newaddr == start)
4677 w->watchpoint_triggered = watch_triggered_yes;
4681 /* Exact match not required. Within range is sufficient. */
4682 else if (target_watchpoint_addr_within_range (¤t_target,
4686 w->watchpoint_triggered = watch_triggered_yes;
4695 /* Possible return values for watchpoint_check (this can't be an enum
4696 because of check_errors). */
4697 /* The watchpoint has been deleted. */
4698 #define WP_DELETED 1
4699 /* The value has changed. */
4700 #define WP_VALUE_CHANGED 2
4701 /* The value has not changed. */
4702 #define WP_VALUE_NOT_CHANGED 3
4703 /* Ignore this watchpoint, no matter if the value changed or not. */
4706 #define BP_TEMPFLAG 1
4707 #define BP_HARDWAREFLAG 2
4709 /* Evaluate watchpoint condition expression and check if its value
4712 P should be a pointer to struct bpstat, but is defined as a void *
4713 in order for this function to be usable with catch_errors. */
4716 watchpoint_check (void *p)
4718 bpstat bs = (bpstat) p;
4719 struct watchpoint *b;
4720 struct frame_info *fr;
4721 int within_current_scope;
4723 /* BS is built from an existing struct breakpoint. */
4724 gdb_assert (bs->breakpoint_at != NULL);
4725 b = (struct watchpoint *) bs->breakpoint_at;
4727 /* If this is a local watchpoint, we only want to check if the
4728 watchpoint frame is in scope if the current thread is the thread
4729 that was used to create the watchpoint. */
4730 if (!watchpoint_in_thread_scope (b))
4733 if (b->exp_valid_block == NULL)
4734 within_current_scope = 1;
4737 struct frame_info *frame = get_current_frame ();
4738 struct gdbarch *frame_arch = get_frame_arch (frame);
4739 CORE_ADDR frame_pc = get_frame_pc (frame);
4741 /* in_function_epilogue_p() returns a non-zero value if we're
4742 still in the function but the stack frame has already been
4743 invalidated. Since we can't rely on the values of local
4744 variables after the stack has been destroyed, we are treating
4745 the watchpoint in that state as `not changed' without further
4746 checking. Don't mark watchpoints as changed if the current
4747 frame is in an epilogue - even if they are in some other
4748 frame, our view of the stack is likely to be wrong and
4749 frame_find_by_id could error out. */
4750 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
4753 fr = frame_find_by_id (b->watchpoint_frame);
4754 within_current_scope = (fr != NULL);
4756 /* If we've gotten confused in the unwinder, we might have
4757 returned a frame that can't describe this variable. */
4758 if (within_current_scope)
4760 struct symbol *function;
4762 function = get_frame_function (fr);
4763 if (function == NULL
4764 || !contained_in (b->exp_valid_block,
4765 SYMBOL_BLOCK_VALUE (function)))
4766 within_current_scope = 0;
4769 if (within_current_scope)
4770 /* If we end up stopping, the current frame will get selected
4771 in normal_stop. So this call to select_frame won't affect
4776 if (within_current_scope)
4778 /* We use value_{,free_to_}mark because it could be a *long*
4779 time before we return to the command level and call
4780 free_all_values. We can't call free_all_values because we
4781 might be in the middle of evaluating a function call. */
4785 struct value *new_val;
4787 if (is_masked_watchpoint (&b->base))
4788 /* Since we don't know the exact trigger address (from
4789 stopped_data_address), just tell the user we've triggered
4790 a mask watchpoint. */
4791 return WP_VALUE_CHANGED;
4793 mark = value_mark ();
4794 fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL);
4796 /* We use value_equal_contents instead of value_equal because
4797 the latter coerces an array to a pointer, thus comparing just
4798 the address of the array instead of its contents. This is
4799 not what we want. */
4800 if ((b->val != NULL) != (new_val != NULL)
4801 || (b->val != NULL && !value_equal_contents (b->val, new_val)))
4803 if (new_val != NULL)
4805 release_value (new_val);
4806 value_free_to_mark (mark);
4808 bs->old_val = b->val;
4811 return WP_VALUE_CHANGED;
4815 /* Nothing changed. */
4816 value_free_to_mark (mark);
4817 return WP_VALUE_NOT_CHANGED;
4822 struct ui_out *uiout = current_uiout;
4824 /* This seems like the only logical thing to do because
4825 if we temporarily ignored the watchpoint, then when
4826 we reenter the block in which it is valid it contains
4827 garbage (in the case of a function, it may have two
4828 garbage values, one before and one after the prologue).
4829 So we can't even detect the first assignment to it and
4830 watch after that (since the garbage may or may not equal
4831 the first value assigned). */
4832 /* We print all the stop information in
4833 breakpoint_ops->print_it, but in this case, by the time we
4834 call breakpoint_ops->print_it this bp will be deleted
4835 already. So we have no choice but print the information
4837 if (ui_out_is_mi_like_p (uiout))
4839 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
4840 ui_out_text (uiout, "\nWatchpoint ");
4841 ui_out_field_int (uiout, "wpnum", b->base.number);
4843 " deleted because the program has left the block in\n\
4844 which its expression is valid.\n");
4846 /* Make sure the watchpoint's commands aren't executed. */
4847 decref_counted_command_line (&b->base.commands);
4848 watchpoint_del_at_next_stop (b);
4854 /* Return true if it looks like target has stopped due to hitting
4855 breakpoint location BL. This function does not check if we should
4856 stop, only if BL explains the stop. */
4859 bpstat_check_location (const struct bp_location *bl,
4860 struct address_space *aspace, CORE_ADDR bp_addr,
4861 const struct target_waitstatus *ws)
4863 struct breakpoint *b = bl->owner;
4865 /* BL is from an existing breakpoint. */
4866 gdb_assert (b != NULL);
4868 return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws);
4871 /* Determine if the watched values have actually changed, and we
4872 should stop. If not, set BS->stop to 0. */
4875 bpstat_check_watchpoint (bpstat bs)
4877 const struct bp_location *bl;
4878 struct watchpoint *b;
4880 /* BS is built for existing struct breakpoint. */
4881 bl = bs->bp_location_at;
4882 gdb_assert (bl != NULL);
4883 b = (struct watchpoint *) bs->breakpoint_at;
4884 gdb_assert (b != NULL);
4887 int must_check_value = 0;
4889 if (b->base.type == bp_watchpoint)
4890 /* For a software watchpoint, we must always check the
4892 must_check_value = 1;
4893 else if (b->watchpoint_triggered == watch_triggered_yes)
4894 /* We have a hardware watchpoint (read, write, or access)
4895 and the target earlier reported an address watched by
4897 must_check_value = 1;
4898 else if (b->watchpoint_triggered == watch_triggered_unknown
4899 && b->base.type == bp_hardware_watchpoint)
4900 /* We were stopped by a hardware watchpoint, but the target could
4901 not report the data address. We must check the watchpoint's
4902 value. Access and read watchpoints are out of luck; without
4903 a data address, we can't figure it out. */
4904 must_check_value = 1;
4906 if (must_check_value)
4909 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
4911 struct cleanup *cleanups = make_cleanup (xfree, message);
4912 int e = catch_errors (watchpoint_check, bs, message,
4914 do_cleanups (cleanups);
4918 /* We've already printed what needs to be printed. */
4919 bs->print_it = print_it_done;
4923 bs->print_it = print_it_noop;
4926 case WP_VALUE_CHANGED:
4927 if (b->base.type == bp_read_watchpoint)
4929 /* There are two cases to consider here:
4931 1. We're watching the triggered memory for reads.
4932 In that case, trust the target, and always report
4933 the watchpoint hit to the user. Even though
4934 reads don't cause value changes, the value may
4935 have changed since the last time it was read, and
4936 since we're not trapping writes, we will not see
4937 those, and as such we should ignore our notion of
4940 2. We're watching the triggered memory for both
4941 reads and writes. There are two ways this may
4944 2.1. This is a target that can't break on data
4945 reads only, but can break on accesses (reads or
4946 writes), such as e.g., x86. We detect this case
4947 at the time we try to insert read watchpoints.
4949 2.2. Otherwise, the target supports read
4950 watchpoints, but, the user set an access or write
4951 watchpoint watching the same memory as this read
4954 If we're watching memory writes as well as reads,
4955 ignore watchpoint hits when we find that the
4956 value hasn't changed, as reads don't cause
4957 changes. This still gives false positives when
4958 the program writes the same value to memory as
4959 what there was already in memory (we will confuse
4960 it for a read), but it's much better than
4963 int other_write_watchpoint = 0;
4965 if (bl->watchpoint_type == hw_read)
4967 struct breakpoint *other_b;
4969 ALL_BREAKPOINTS (other_b)
4970 if (other_b->type == bp_hardware_watchpoint
4971 || other_b->type == bp_access_watchpoint)
4973 struct watchpoint *other_w =
4974 (struct watchpoint *) other_b;
4976 if (other_w->watchpoint_triggered
4977 == watch_triggered_yes)
4979 other_write_watchpoint = 1;
4985 if (other_write_watchpoint
4986 || bl->watchpoint_type == hw_access)
4988 /* We're watching the same memory for writes,
4989 and the value changed since the last time we
4990 updated it, so this trap must be for a write.
4992 bs->print_it = print_it_noop;
4997 case WP_VALUE_NOT_CHANGED:
4998 if (b->base.type == bp_hardware_watchpoint
4999 || b->base.type == bp_watchpoint)
5001 /* Don't stop: write watchpoints shouldn't fire if
5002 the value hasn't changed. */
5003 bs->print_it = print_it_noop;
5011 /* Error from catch_errors. */
5012 printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number);
5013 watchpoint_del_at_next_stop (b);
5014 /* We've already printed what needs to be printed. */
5015 bs->print_it = print_it_done;
5019 else /* must_check_value == 0 */
5021 /* This is a case where some watchpoint(s) triggered, but
5022 not at the address of this watchpoint, or else no
5023 watchpoint triggered after all. So don't print
5024 anything for this watchpoint. */
5025 bs->print_it = print_it_noop;
5032 /* Check conditions (condition proper, frame, thread and ignore count)
5033 of breakpoint referred to by BS. If we should not stop for this
5034 breakpoint, set BS->stop to 0. */
5037 bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
5039 int thread_id = pid_to_thread_id (ptid);
5040 const struct bp_location *bl;
5041 struct breakpoint *b;
5043 /* BS is built for existing struct breakpoint. */
5044 bl = bs->bp_location_at;
5045 gdb_assert (bl != NULL);
5046 b = bs->breakpoint_at;
5047 gdb_assert (b != NULL);
5049 /* Even if the target evaluated the condition on its end and notified GDB, we
5050 need to do so again since GDB does not know if we stopped due to a
5051 breakpoint or a single step breakpoint. */
5053 if (frame_id_p (b->frame_id)
5054 && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ())))
5058 int value_is_zero = 0;
5059 struct expression *cond;
5061 /* Evaluate Python breakpoints that have a "stop"
5062 method implemented. */
5063 if (b->py_bp_object)
5064 bs->stop = gdbpy_should_stop (b->py_bp_object);
5066 if (is_watchpoint (b))
5068 struct watchpoint *w = (struct watchpoint *) b;
5075 if (cond && b->disposition != disp_del_at_next_stop)
5077 int within_current_scope = 1;
5078 struct watchpoint * w;
5080 /* We use value_mark and value_free_to_mark because it could
5081 be a long time before we return to the command level and
5082 call free_all_values. We can't call free_all_values
5083 because we might be in the middle of evaluating a
5085 struct value *mark = value_mark ();
5087 if (is_watchpoint (b))
5088 w = (struct watchpoint *) b;
5092 /* Need to select the frame, with all that implies so that
5093 the conditions will have the right context. Because we
5094 use the frame, we will not see an inlined function's
5095 variables when we arrive at a breakpoint at the start
5096 of the inlined function; the current frame will be the
5098 if (w == NULL || w->cond_exp_valid_block == NULL)
5099 select_frame (get_current_frame ());
5102 struct frame_info *frame;
5104 /* For local watchpoint expressions, which particular
5105 instance of a local is being watched matters, so we
5106 keep track of the frame to evaluate the expression
5107 in. To evaluate the condition however, it doesn't
5108 really matter which instantiation of the function
5109 where the condition makes sense triggers the
5110 watchpoint. This allows an expression like "watch
5111 global if q > 10" set in `func', catch writes to
5112 global on all threads that call `func', or catch
5113 writes on all recursive calls of `func' by a single
5114 thread. We simply always evaluate the condition in
5115 the innermost frame that's executing where it makes
5116 sense to evaluate the condition. It seems
5118 frame = block_innermost_frame (w->cond_exp_valid_block);
5120 select_frame (frame);
5122 within_current_scope = 0;
5124 if (within_current_scope)
5126 = catch_errors (breakpoint_cond_eval, cond,
5127 "Error in testing breakpoint condition:\n",
5131 warning (_("Watchpoint condition cannot be tested "
5132 "in the current scope"));
5133 /* If we failed to set the right context for this
5134 watchpoint, unconditionally report it. */
5137 /* FIXME-someday, should give breakpoint #. */
5138 value_free_to_mark (mark);
5141 if (cond && value_is_zero)
5145 else if (b->thread != -1 && b->thread != thread_id)
5149 else if (b->ignore_count > 0)
5153 /* Increase the hit count even though we don't stop. */
5155 observer_notify_breakpoint_modified (b);
5161 /* Get a bpstat associated with having just stopped at address
5162 BP_ADDR in thread PTID.
5164 Determine whether we stopped at a breakpoint, etc, or whether we
5165 don't understand this stop. Result is a chain of bpstat's such
5168 if we don't understand the stop, the result is a null pointer.
5170 if we understand why we stopped, the result is not null.
5172 Each element of the chain refers to a particular breakpoint or
5173 watchpoint at which we have stopped. (We may have stopped for
5174 several reasons concurrently.)
5176 Each element of the chain has valid next, breakpoint_at,
5177 commands, FIXME??? fields. */
5180 bpstat_stop_status (struct address_space *aspace,
5181 CORE_ADDR bp_addr, ptid_t ptid,
5182 const struct target_waitstatus *ws)
5184 struct breakpoint *b = NULL;
5185 struct bp_location *bl;
5186 struct bp_location *loc;
5187 /* First item of allocated bpstat's. */
5188 bpstat bs_head = NULL, *bs_link = &bs_head;
5189 /* Pointer to the last thing in the chain currently. */
5192 int need_remove_insert;
5195 /* First, build the bpstat chain with locations that explain a
5196 target stop, while being careful to not set the target running,
5197 as that may invalidate locations (in particular watchpoint
5198 locations are recreated). Resuming will happen here with
5199 breakpoint conditions or watchpoint expressions that include
5200 inferior function calls. */
5204 if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
5207 for (bl = b->loc; bl != NULL; bl = bl->next)
5209 /* For hardware watchpoints, we look only at the first
5210 location. The watchpoint_check function will work on the
5211 entire expression, not the individual locations. For
5212 read watchpoints, the watchpoints_triggered function has
5213 checked all locations already. */
5214 if (b->type == bp_hardware_watchpoint && bl != b->loc)
5217 if (!bl->enabled || bl->shlib_disabled)
5220 if (!bpstat_check_location (bl, aspace, bp_addr, ws))
5223 /* Come here if it's a watchpoint, or if the break address
5226 bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to
5229 /* Assume we stop. Should we find a watchpoint that is not
5230 actually triggered, or if the condition of the breakpoint
5231 evaluates as false, we'll reset 'stop' to 0. */
5235 /* If this is a scope breakpoint, mark the associated
5236 watchpoint as triggered so that we will handle the
5237 out-of-scope event. We'll get to the watchpoint next
5239 if (b->type == bp_watchpoint_scope && b->related_breakpoint != b)
5241 struct watchpoint *w = (struct watchpoint *) b->related_breakpoint;
5243 w->watchpoint_triggered = watch_triggered_yes;
5248 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
5250 if (breakpoint_location_address_match (loc, aspace, bp_addr))
5252 bs = bpstat_alloc (loc, &bs_link);
5253 /* For hits of moribund locations, we should just proceed. */
5256 bs->print_it = print_it_noop;
5260 /* A bit of special processing for shlib breakpoints. We need to
5261 process solib loading here, so that the lists of loaded and
5262 unloaded libraries are correct before we handle "catch load" and
5264 for (bs = bs_head; bs != NULL; bs = bs->next)
5266 if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event)
5268 handle_solib_event ();
5273 /* Now go through the locations that caused the target to stop, and
5274 check whether we're interested in reporting this stop to higher
5275 layers, or whether we should resume the target transparently. */
5279 for (bs = bs_head; bs != NULL; bs = bs->next)
5284 b = bs->breakpoint_at;
5285 b->ops->check_status (bs);
5288 bpstat_check_breakpoint_conditions (bs, ptid);
5293 observer_notify_breakpoint_modified (b);
5295 /* We will stop here. */
5296 if (b->disposition == disp_disable)
5298 --(b->enable_count);
5299 if (b->enable_count <= 0
5300 && b->enable_state != bp_permanent)
5301 b->enable_state = bp_disabled;
5306 bs->commands = b->commands;
5307 incref_counted_command_line (bs->commands);
5308 if (command_line_is_silent (bs->commands
5309 ? bs->commands->commands : NULL))
5315 /* Print nothing for this entry if we don't stop or don't
5317 if (!bs->stop || !bs->print)
5318 bs->print_it = print_it_noop;
5321 /* If we aren't stopping, the value of some hardware watchpoint may
5322 not have changed, but the intermediate memory locations we are
5323 watching may have. Don't bother if we're stopping; this will get
5325 need_remove_insert = 0;
5326 if (! bpstat_causes_stop (bs_head))
5327 for (bs = bs_head; bs != NULL; bs = bs->next)
5329 && bs->breakpoint_at
5330 && is_hardware_watchpoint (bs->breakpoint_at))
5332 struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at;
5334 update_watchpoint (w, 0 /* don't reparse. */);
5335 need_remove_insert = 1;
5338 if (need_remove_insert)
5339 update_global_location_list (1);
5340 else if (removed_any)
5341 update_global_location_list (0);
5347 handle_jit_event (void)
5349 struct frame_info *frame;
5350 struct gdbarch *gdbarch;
5352 /* Switch terminal for any messages produced by
5353 breakpoint_re_set. */
5354 target_terminal_ours_for_output ();
5356 frame = get_current_frame ();
5357 gdbarch = get_frame_arch (frame);
5359 jit_event_handler (gdbarch);
5361 target_terminal_inferior ();
5364 /* Handle an solib event by calling solib_add. */
5367 handle_solib_event (void)
5369 clear_program_space_solib_cache (current_inferior ()->pspace);
5371 /* Check for any newly added shared libraries if we're supposed to
5372 be adding them automatically. Switch terminal for any messages
5373 produced by breakpoint_re_set. */
5374 target_terminal_ours_for_output ();
5376 SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add);
5378 solib_add (NULL, 0, ¤t_target, auto_solib_add);
5380 target_terminal_inferior ();
5383 /* Prepare WHAT final decision for infrun. */
5385 /* Decide what infrun needs to do with this bpstat. */
5388 bpstat_what (bpstat bs_head)
5390 struct bpstat_what retval;
5394 retval.main_action = BPSTAT_WHAT_KEEP_CHECKING;
5395 retval.call_dummy = STOP_NONE;
5396 retval.is_longjmp = 0;
5398 for (bs = bs_head; bs != NULL; bs = bs->next)
5400 /* Extract this BS's action. After processing each BS, we check
5401 if its action overrides all we've seem so far. */
5402 enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING;
5405 if (bs->breakpoint_at == NULL)
5407 /* I suspect this can happen if it was a momentary
5408 breakpoint which has since been deleted. */
5412 bptype = bs->breakpoint_at->type;
5419 case bp_hardware_breakpoint:
5422 case bp_shlib_event:
5426 this_action = BPSTAT_WHAT_STOP_NOISY;
5428 this_action = BPSTAT_WHAT_STOP_SILENT;
5431 this_action = BPSTAT_WHAT_SINGLE;
5434 case bp_hardware_watchpoint:
5435 case bp_read_watchpoint:
5436 case bp_access_watchpoint:
5440 this_action = BPSTAT_WHAT_STOP_NOISY;
5442 this_action = BPSTAT_WHAT_STOP_SILENT;
5446 /* There was a watchpoint, but we're not stopping.
5447 This requires no further action. */
5451 case bp_longjmp_call_dummy:
5453 this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME;
5454 retval.is_longjmp = bptype != bp_exception;
5456 case bp_longjmp_resume:
5457 case bp_exception_resume:
5458 this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME;
5459 retval.is_longjmp = bptype == bp_longjmp_resume;
5461 case bp_step_resume:
5463 this_action = BPSTAT_WHAT_STEP_RESUME;
5466 /* It is for the wrong frame. */
5467 this_action = BPSTAT_WHAT_SINGLE;
5470 case bp_hp_step_resume:
5472 this_action = BPSTAT_WHAT_HP_STEP_RESUME;
5475 /* It is for the wrong frame. */
5476 this_action = BPSTAT_WHAT_SINGLE;
5479 case bp_watchpoint_scope:
5480 case bp_thread_event:
5481 case bp_overlay_event:
5482 case bp_longjmp_master:
5483 case bp_std_terminate_master:
5484 case bp_exception_master:
5485 this_action = BPSTAT_WHAT_SINGLE;
5491 this_action = BPSTAT_WHAT_STOP_NOISY;
5493 this_action = BPSTAT_WHAT_STOP_SILENT;
5497 /* There was a catchpoint, but we're not stopping.
5498 This requires no further action. */
5503 this_action = BPSTAT_WHAT_SINGLE;
5506 /* Make sure the action is stop (silent or noisy),
5507 so infrun.c pops the dummy frame. */
5508 retval.call_dummy = STOP_STACK_DUMMY;
5509 this_action = BPSTAT_WHAT_STOP_SILENT;
5511 case bp_std_terminate:
5512 /* Make sure the action is stop (silent or noisy),
5513 so infrun.c pops the dummy frame. */
5514 retval.call_dummy = STOP_STD_TERMINATE;
5515 this_action = BPSTAT_WHAT_STOP_SILENT;
5518 case bp_fast_tracepoint:
5519 case bp_static_tracepoint:
5520 /* Tracepoint hits should not be reported back to GDB, and
5521 if one got through somehow, it should have been filtered
5523 internal_error (__FILE__, __LINE__,
5524 _("bpstat_what: tracepoint encountered"));
5526 case bp_gnu_ifunc_resolver:
5527 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5528 this_action = BPSTAT_WHAT_SINGLE;
5530 case bp_gnu_ifunc_resolver_return:
5531 /* The breakpoint will be removed, execution will restart from the
5532 PC of the former breakpoint. */
5533 this_action = BPSTAT_WHAT_KEEP_CHECKING;
5537 this_action = BPSTAT_WHAT_STOP_SILENT;
5541 internal_error (__FILE__, __LINE__,
5542 _("bpstat_what: unhandled bptype %d"), (int) bptype);
5545 retval.main_action = max (retval.main_action, this_action);
5548 /* These operations may affect the bs->breakpoint_at state so they are
5549 delayed after MAIN_ACTION is decided above. */
5554 fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n");
5556 handle_jit_event ();
5559 for (bs = bs_head; bs != NULL; bs = bs->next)
5561 struct breakpoint *b = bs->breakpoint_at;
5567 case bp_gnu_ifunc_resolver:
5568 gnu_ifunc_resolver_stop (b);
5570 case bp_gnu_ifunc_resolver_return:
5571 gnu_ifunc_resolver_return_stop (b);
5579 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5580 without hardware support). This isn't related to a specific bpstat,
5581 just to things like whether watchpoints are set. */
5584 bpstat_should_step (void)
5586 struct breakpoint *b;
5589 if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL)
5595 bpstat_causes_stop (bpstat bs)
5597 for (; bs != NULL; bs = bs->next)
5606 /* Compute a string of spaces suitable to indent the next line
5607 so it starts at the position corresponding to the table column
5608 named COL_NAME in the currently active table of UIOUT. */
5611 wrap_indent_at_field (struct ui_out *uiout, const char *col_name)
5613 static char wrap_indent[80];
5614 int i, total_width, width, align;
5618 for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++)
5620 if (strcmp (text, col_name) == 0)
5622 gdb_assert (total_width < sizeof wrap_indent);
5623 memset (wrap_indent, ' ', total_width);
5624 wrap_indent[total_width] = 0;
5629 total_width += width + 1;
5635 /* Determine if the locations of this breakpoint will have their conditions
5636 evaluated by the target, host or a mix of both. Returns the following:
5638 "host": Host evals condition.
5639 "host or target": Host or Target evals condition.
5640 "target": Target evals condition.
5644 bp_condition_evaluator (struct breakpoint *b)
5646 struct bp_location *bl;
5647 char host_evals = 0;
5648 char target_evals = 0;
5653 if (!is_breakpoint (b))
5656 if (gdb_evaluates_breakpoint_condition_p ()
5657 || !target_supports_evaluation_of_breakpoint_conditions ())
5658 return condition_evaluation_host;
5660 for (bl = b->loc; bl; bl = bl->next)
5662 if (bl->cond_bytecode)
5668 if (host_evals && target_evals)
5669 return condition_evaluation_both;
5670 else if (target_evals)
5671 return condition_evaluation_target;
5673 return condition_evaluation_host;
5676 /* Determine the breakpoint location's condition evaluator. This is
5677 similar to bp_condition_evaluator, but for locations. */
5680 bp_location_condition_evaluator (struct bp_location *bl)
5682 if (bl && !is_breakpoint (bl->owner))
5685 if (gdb_evaluates_breakpoint_condition_p ()
5686 || !target_supports_evaluation_of_breakpoint_conditions ())
5687 return condition_evaluation_host;
5689 if (bl && bl->cond_bytecode)
5690 return condition_evaluation_target;
5692 return condition_evaluation_host;
5695 /* Print the LOC location out of the list of B->LOC locations. */
5698 print_breakpoint_location (struct breakpoint *b,
5699 struct bp_location *loc)
5701 struct ui_out *uiout = current_uiout;
5702 struct cleanup *old_chain = save_current_program_space ();
5704 if (loc != NULL && loc->shlib_disabled)
5708 set_current_program_space (loc->pspace);
5710 if (b->display_canonical)
5711 ui_out_field_string (uiout, "what", b->addr_string);
5712 else if (loc && loc->symtab)
5715 = find_pc_sect_function (loc->address, loc->section);
5718 ui_out_text (uiout, "in ");
5719 ui_out_field_string (uiout, "func",
5720 SYMBOL_PRINT_NAME (sym));
5721 ui_out_text (uiout, " ");
5722 ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what"));
5723 ui_out_text (uiout, "at ");
5725 ui_out_field_string (uiout, "file",
5726 symtab_to_filename_for_display (loc->symtab));
5727 ui_out_text (uiout, ":");
5729 if (ui_out_is_mi_like_p (uiout))
5730 ui_out_field_string (uiout, "fullname",
5731 symtab_to_fullname (loc->symtab));
5733 ui_out_field_int (uiout, "line", loc->line_number);
5737 struct ui_file *stb = mem_fileopen ();
5738 struct cleanup *stb_chain = make_cleanup_ui_file_delete (stb);
5740 print_address_symbolic (loc->gdbarch, loc->address, stb,
5742 ui_out_field_stream (uiout, "at", stb);
5744 do_cleanups (stb_chain);
5747 ui_out_field_string (uiout, "pending", b->addr_string);
5749 if (loc && is_breakpoint (b)
5750 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
5751 && bp_condition_evaluator (b) == condition_evaluation_both)
5753 ui_out_text (uiout, " (");
5754 ui_out_field_string (uiout, "evaluated-by",
5755 bp_location_condition_evaluator (loc));
5756 ui_out_text (uiout, ")");
5759 do_cleanups (old_chain);
5763 bptype_string (enum bptype type)
5765 struct ep_type_description
5770 static struct ep_type_description bptypes[] =
5772 {bp_none, "?deleted?"},
5773 {bp_breakpoint, "breakpoint"},
5774 {bp_hardware_breakpoint, "hw breakpoint"},
5775 {bp_until, "until"},
5776 {bp_finish, "finish"},
5777 {bp_watchpoint, "watchpoint"},
5778 {bp_hardware_watchpoint, "hw watchpoint"},
5779 {bp_read_watchpoint, "read watchpoint"},
5780 {bp_access_watchpoint, "acc watchpoint"},
5781 {bp_longjmp, "longjmp"},
5782 {bp_longjmp_resume, "longjmp resume"},
5783 {bp_longjmp_call_dummy, "longjmp for call dummy"},
5784 {bp_exception, "exception"},
5785 {bp_exception_resume, "exception resume"},
5786 {bp_step_resume, "step resume"},
5787 {bp_hp_step_resume, "high-priority step resume"},
5788 {bp_watchpoint_scope, "watchpoint scope"},
5789 {bp_call_dummy, "call dummy"},
5790 {bp_std_terminate, "std::terminate"},
5791 {bp_shlib_event, "shlib events"},
5792 {bp_thread_event, "thread events"},
5793 {bp_overlay_event, "overlay events"},
5794 {bp_longjmp_master, "longjmp master"},
5795 {bp_std_terminate_master, "std::terminate master"},
5796 {bp_exception_master, "exception master"},
5797 {bp_catchpoint, "catchpoint"},
5798 {bp_tracepoint, "tracepoint"},
5799 {bp_fast_tracepoint, "fast tracepoint"},
5800 {bp_static_tracepoint, "static tracepoint"},
5801 {bp_dprintf, "dprintf"},
5802 {bp_jit_event, "jit events"},
5803 {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"},
5804 {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"},
5807 if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0])))
5808 || ((int) type != bptypes[(int) type].type))
5809 internal_error (__FILE__, __LINE__,
5810 _("bptypes table does not describe type #%d."),
5813 return bptypes[(int) type].description;
5818 /* For MI, output a field named 'thread-groups' with a list as the value.
5819 For CLI, prefix the list with the string 'inf'. */
5822 output_thread_groups (struct ui_out *uiout,
5823 const char *field_name,
5827 struct cleanup *back_to = make_cleanup_ui_out_list_begin_end (uiout,
5829 int is_mi = ui_out_is_mi_like_p (uiout);
5833 /* For backward compatibility, don't display inferiors in CLI unless
5834 there are several. Always display them for MI. */
5835 if (!is_mi && mi_only)
5838 for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i)
5844 xsnprintf (mi_group, sizeof (mi_group), "i%d", inf);
5845 ui_out_field_string (uiout, NULL, mi_group);
5850 ui_out_text (uiout, " inf ");
5852 ui_out_text (uiout, ", ");
5854 ui_out_text (uiout, plongest (inf));
5858 do_cleanups (back_to);
5861 /* Print B to gdb_stdout. */
5864 print_one_breakpoint_location (struct breakpoint *b,
5865 struct bp_location *loc,
5867 struct bp_location **last_loc,
5870 struct command_line *l;
5871 static char bpenables[] = "nynny";
5873 struct ui_out *uiout = current_uiout;
5874 int header_of_multiple = 0;
5875 int part_of_multiple = (loc != NULL);
5876 struct value_print_options opts;
5878 get_user_print_options (&opts);
5880 gdb_assert (!loc || loc_number != 0);
5881 /* See comment in print_one_breakpoint concerning treatment of
5882 breakpoints with single disabled location. */
5885 && (b->loc->next != NULL || !b->loc->enabled)))
5886 header_of_multiple = 1;
5894 if (part_of_multiple)
5897 formatted = xstrprintf ("%d.%d", b->number, loc_number);
5898 ui_out_field_string (uiout, "number", formatted);
5903 ui_out_field_int (uiout, "number", b->number);
5908 if (part_of_multiple)
5909 ui_out_field_skip (uiout, "type");
5911 ui_out_field_string (uiout, "type", bptype_string (b->type));
5915 if (part_of_multiple)
5916 ui_out_field_skip (uiout, "disp");
5918 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
5923 if (part_of_multiple)
5924 ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n");
5926 ui_out_field_fmt (uiout, "enabled", "%c",
5927 bpenables[(int) b->enable_state]);
5928 ui_out_spaces (uiout, 2);
5932 if (b->ops != NULL && b->ops->print_one != NULL)
5934 /* Although the print_one can possibly print all locations,
5935 calling it here is not likely to get any nice result. So,
5936 make sure there's just one location. */
5937 gdb_assert (b->loc == NULL || b->loc->next == NULL);
5938 b->ops->print_one (b, last_loc);
5944 internal_error (__FILE__, __LINE__,
5945 _("print_one_breakpoint: bp_none encountered\n"));
5949 case bp_hardware_watchpoint:
5950 case bp_read_watchpoint:
5951 case bp_access_watchpoint:
5953 struct watchpoint *w = (struct watchpoint *) b;
5955 /* Field 4, the address, is omitted (which makes the columns
5956 not line up too nicely with the headers, but the effect
5957 is relatively readable). */
5958 if (opts.addressprint)
5959 ui_out_field_skip (uiout, "addr");
5961 ui_out_field_string (uiout, "what", w->exp_string);
5966 case bp_hardware_breakpoint:
5970 case bp_longjmp_resume:
5971 case bp_longjmp_call_dummy:
5973 case bp_exception_resume:
5974 case bp_step_resume:
5975 case bp_hp_step_resume:
5976 case bp_watchpoint_scope:
5978 case bp_std_terminate:
5979 case bp_shlib_event:
5980 case bp_thread_event:
5981 case bp_overlay_event:
5982 case bp_longjmp_master:
5983 case bp_std_terminate_master:
5984 case bp_exception_master:
5986 case bp_fast_tracepoint:
5987 case bp_static_tracepoint:
5990 case bp_gnu_ifunc_resolver:
5991 case bp_gnu_ifunc_resolver_return:
5992 if (opts.addressprint)
5995 if (header_of_multiple)
5996 ui_out_field_string (uiout, "addr", "<MULTIPLE>");
5997 else if (b->loc == NULL || loc->shlib_disabled)
5998 ui_out_field_string (uiout, "addr", "<PENDING>");
6000 ui_out_field_core_addr (uiout, "addr",
6001 loc->gdbarch, loc->address);
6004 if (!header_of_multiple)
6005 print_breakpoint_location (b, loc);
6012 if (loc != NULL && !header_of_multiple)
6014 struct inferior *inf;
6015 VEC(int) *inf_num = NULL;
6020 if (inf->pspace == loc->pspace)
6021 VEC_safe_push (int, inf_num, inf->num);
6024 /* For backward compatibility, don't display inferiors in CLI unless
6025 there are several. Always display for MI. */
6027 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6028 && (number_of_program_spaces () > 1
6029 || number_of_inferiors () > 1)
6030 /* LOC is for existing B, it cannot be in
6031 moribund_locations and thus having NULL OWNER. */
6032 && loc->owner->type != bp_catchpoint))
6034 output_thread_groups (uiout, "thread-groups", inf_num, mi_only);
6035 VEC_free (int, inf_num);
6038 if (!part_of_multiple)
6040 if (b->thread != -1)
6042 /* FIXME: This seems to be redundant and lost here; see the
6043 "stop only in" line a little further down. */
6044 ui_out_text (uiout, " thread ");
6045 ui_out_field_int (uiout, "thread", b->thread);
6047 else if (b->task != 0)
6049 ui_out_text (uiout, " task ");
6050 ui_out_field_int (uiout, "task", b->task);
6054 ui_out_text (uiout, "\n");
6056 if (!part_of_multiple)
6057 b->ops->print_one_detail (b, uiout);
6059 if (part_of_multiple && frame_id_p (b->frame_id))
6062 ui_out_text (uiout, "\tstop only in stack frame at ");
6063 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6065 ui_out_field_core_addr (uiout, "frame",
6066 b->gdbarch, b->frame_id.stack_addr);
6067 ui_out_text (uiout, "\n");
6070 if (!part_of_multiple && b->cond_string)
6073 if (is_tracepoint (b))
6074 ui_out_text (uiout, "\ttrace only if ");
6076 ui_out_text (uiout, "\tstop only if ");
6077 ui_out_field_string (uiout, "cond", b->cond_string);
6079 /* Print whether the target is doing the breakpoint's condition
6080 evaluation. If GDB is doing the evaluation, don't print anything. */
6081 if (is_breakpoint (b)
6082 && breakpoint_condition_evaluation_mode ()
6083 == condition_evaluation_target)
6085 ui_out_text (uiout, " (");
6086 ui_out_field_string (uiout, "evaluated-by",
6087 bp_condition_evaluator (b));
6088 ui_out_text (uiout, " evals)");
6090 ui_out_text (uiout, "\n");
6093 if (!part_of_multiple && b->thread != -1)
6095 /* FIXME should make an annotation for this. */
6096 ui_out_text (uiout, "\tstop only in thread ");
6097 ui_out_field_int (uiout, "thread", b->thread);
6098 ui_out_text (uiout, "\n");
6101 if (!part_of_multiple)
6105 /* FIXME should make an annotation for this. */
6106 if (is_catchpoint (b))
6107 ui_out_text (uiout, "\tcatchpoint");
6108 else if (is_tracepoint (b))
6109 ui_out_text (uiout, "\ttracepoint");
6111 ui_out_text (uiout, "\tbreakpoint");
6112 ui_out_text (uiout, " already hit ");
6113 ui_out_field_int (uiout, "times", b->hit_count);
6114 if (b->hit_count == 1)
6115 ui_out_text (uiout, " time\n");
6117 ui_out_text (uiout, " times\n");
6121 /* Output the count also if it is zero, but only if this is mi. */
6122 if (ui_out_is_mi_like_p (uiout))
6123 ui_out_field_int (uiout, "times", b->hit_count);
6127 if (!part_of_multiple && b->ignore_count)
6130 ui_out_text (uiout, "\tignore next ");
6131 ui_out_field_int (uiout, "ignore", b->ignore_count);
6132 ui_out_text (uiout, " hits\n");
6135 /* Note that an enable count of 1 corresponds to "enable once"
6136 behavior, which is reported by the combination of enablement and
6137 disposition, so we don't need to mention it here. */
6138 if (!part_of_multiple && b->enable_count > 1)
6141 ui_out_text (uiout, "\tdisable after ");
6142 /* Tweak the wording to clarify that ignore and enable counts
6143 are distinct, and have additive effect. */
6144 if (b->ignore_count)
6145 ui_out_text (uiout, "additional ");
6147 ui_out_text (uiout, "next ");
6148 ui_out_field_int (uiout, "enable", b->enable_count);
6149 ui_out_text (uiout, " hits\n");
6152 if (!part_of_multiple && is_tracepoint (b))
6154 struct tracepoint *tp = (struct tracepoint *) b;
6156 if (tp->traceframe_usage)
6158 ui_out_text (uiout, "\ttrace buffer usage ");
6159 ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage);
6160 ui_out_text (uiout, " bytes\n");
6164 l = b->commands ? b->commands->commands : NULL;
6165 if (!part_of_multiple && l)
6167 struct cleanup *script_chain;
6170 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
6171 print_command_lines (uiout, l, 4);
6172 do_cleanups (script_chain);
6175 if (is_tracepoint (b))
6177 struct tracepoint *t = (struct tracepoint *) b;
6179 if (!part_of_multiple && t->pass_count)
6181 annotate_field (10);
6182 ui_out_text (uiout, "\tpass count ");
6183 ui_out_field_int (uiout, "pass", t->pass_count);
6184 ui_out_text (uiout, " \n");
6187 /* Don't display it when tracepoint or tracepoint location is
6189 if (!header_of_multiple && loc != NULL && !loc->shlib_disabled)
6191 annotate_field (11);
6193 if (ui_out_is_mi_like_p (uiout))
6194 ui_out_field_string (uiout, "installed",
6195 loc->inserted ? "y" : "n");
6199 ui_out_text (uiout, "\t");
6201 ui_out_text (uiout, "\tnot ");
6202 ui_out_text (uiout, "installed on target\n");
6207 if (ui_out_is_mi_like_p (uiout) && !part_of_multiple)
6209 if (is_watchpoint (b))
6211 struct watchpoint *w = (struct watchpoint *) b;
6213 ui_out_field_string (uiout, "original-location", w->exp_string);
6215 else if (b->addr_string)
6216 ui_out_field_string (uiout, "original-location", b->addr_string);
6221 print_one_breakpoint (struct breakpoint *b,
6222 struct bp_location **last_loc,
6225 struct cleanup *bkpt_chain;
6226 struct ui_out *uiout = current_uiout;
6228 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
6230 print_one_breakpoint_location (b, NULL, 0, last_loc, allflag);
6231 do_cleanups (bkpt_chain);
6233 /* If this breakpoint has custom print function,
6234 it's already printed. Otherwise, print individual
6235 locations, if any. */
6236 if (b->ops == NULL || b->ops->print_one == NULL)
6238 /* If breakpoint has a single location that is disabled, we
6239 print it as if it had several locations, since otherwise it's
6240 hard to represent "breakpoint enabled, location disabled"
6243 Note that while hardware watchpoints have several locations
6244 internally, that's not a property exposed to user. */
6246 && !is_hardware_watchpoint (b)
6247 && (b->loc->next || !b->loc->enabled))
6249 struct bp_location *loc;
6252 for (loc = b->loc; loc; loc = loc->next, ++n)
6254 struct cleanup *inner2 =
6255 make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
6256 print_one_breakpoint_location (b, loc, n, last_loc, allflag);
6257 do_cleanups (inner2);
6264 breakpoint_address_bits (struct breakpoint *b)
6266 int print_address_bits = 0;
6267 struct bp_location *loc;
6269 for (loc = b->loc; loc; loc = loc->next)
6273 /* Software watchpoints that aren't watching memory don't have
6274 an address to print. */
6275 if (b->type == bp_watchpoint && loc->watchpoint_type == -1)
6278 addr_bit = gdbarch_addr_bit (loc->gdbarch);
6279 if (addr_bit > print_address_bits)
6280 print_address_bits = addr_bit;
6283 return print_address_bits;
6286 struct captured_breakpoint_query_args
6292 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
6294 struct captured_breakpoint_query_args *args = data;
6295 struct breakpoint *b;
6296 struct bp_location *dummy_loc = NULL;
6300 if (args->bnum == b->number)
6302 print_one_breakpoint (b, &dummy_loc, 0);
6310 gdb_breakpoint_query (struct ui_out *uiout, int bnum,
6311 char **error_message)
6313 struct captured_breakpoint_query_args args;
6316 /* For the moment we don't trust print_one_breakpoint() to not throw
6318 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
6319 error_message, RETURN_MASK_ALL) < 0)
6325 /* Return true if this breakpoint was set by the user, false if it is
6326 internal or momentary. */
6329 user_breakpoint_p (struct breakpoint *b)
6331 return b->number > 0;
6334 /* Print information on user settable breakpoint (watchpoint, etc)
6335 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6336 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6337 FILTER is non-NULL, call it on each breakpoint and only include the
6338 ones for which it returns non-zero. Return the total number of
6339 breakpoints listed. */
6342 breakpoint_1 (char *args, int allflag,
6343 int (*filter) (const struct breakpoint *))
6345 struct breakpoint *b;
6346 struct bp_location *last_loc = NULL;
6347 int nr_printable_breakpoints;
6348 struct cleanup *bkpttbl_chain;
6349 struct value_print_options opts;
6350 int print_address_bits = 0;
6351 int print_type_col_width = 14;
6352 struct ui_out *uiout = current_uiout;
6354 get_user_print_options (&opts);
6356 /* Compute the number of rows in the table, as well as the size
6357 required for address fields. */
6358 nr_printable_breakpoints = 0;
6361 /* If we have a filter, only list the breakpoints it accepts. */
6362 if (filter && !filter (b))
6365 /* If we have an "args" string, it is a list of breakpoints to
6366 accept. Skip the others. */
6367 if (args != NULL && *args != '\0')
6369 if (allflag && parse_and_eval_long (args) != b->number)
6371 if (!allflag && !number_is_in_list (args, b->number))
6375 if (allflag || user_breakpoint_p (b))
6377 int addr_bit, type_len;
6379 addr_bit = breakpoint_address_bits (b);
6380 if (addr_bit > print_address_bits)
6381 print_address_bits = addr_bit;
6383 type_len = strlen (bptype_string (b->type));
6384 if (type_len > print_type_col_width)
6385 print_type_col_width = type_len;
6387 nr_printable_breakpoints++;
6391 if (opts.addressprint)
6393 = make_cleanup_ui_out_table_begin_end (uiout, 6,
6394 nr_printable_breakpoints,
6398 = make_cleanup_ui_out_table_begin_end (uiout, 5,
6399 nr_printable_breakpoints,
6402 if (nr_printable_breakpoints > 0)
6403 annotate_breakpoints_headers ();
6404 if (nr_printable_breakpoints > 0)
6406 ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */
6407 if (nr_printable_breakpoints > 0)
6409 ui_out_table_header (uiout, print_type_col_width, ui_left,
6410 "type", "Type"); /* 2 */
6411 if (nr_printable_breakpoints > 0)
6413 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
6414 if (nr_printable_breakpoints > 0)
6416 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
6417 if (opts.addressprint)
6419 if (nr_printable_breakpoints > 0)
6421 if (print_address_bits <= 32)
6422 ui_out_table_header (uiout, 10, ui_left,
6423 "addr", "Address"); /* 5 */
6425 ui_out_table_header (uiout, 18, ui_left,
6426 "addr", "Address"); /* 5 */
6428 if (nr_printable_breakpoints > 0)
6430 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
6431 ui_out_table_body (uiout);
6432 if (nr_printable_breakpoints > 0)
6433 annotate_breakpoints_table ();
6438 /* If we have a filter, only list the breakpoints it accepts. */
6439 if (filter && !filter (b))
6442 /* If we have an "args" string, it is a list of breakpoints to
6443 accept. Skip the others. */
6445 if (args != NULL && *args != '\0')
6447 if (allflag) /* maintenance info breakpoint */
6449 if (parse_and_eval_long (args) != b->number)
6452 else /* all others */
6454 if (!number_is_in_list (args, b->number))
6458 /* We only print out user settable breakpoints unless the
6460 if (allflag || user_breakpoint_p (b))
6461 print_one_breakpoint (b, &last_loc, allflag);
6464 do_cleanups (bkpttbl_chain);
6466 if (nr_printable_breakpoints == 0)
6468 /* If there's a filter, let the caller decide how to report
6472 if (args == NULL || *args == '\0')
6473 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
6475 ui_out_message (uiout, 0,
6476 "No breakpoint or watchpoint matching '%s'.\n",
6482 if (last_loc && !server_command)
6483 set_next_address (last_loc->gdbarch, last_loc->address);
6486 /* FIXME? Should this be moved up so that it is only called when
6487 there have been breakpoints? */
6488 annotate_breakpoints_table_end ();
6490 return nr_printable_breakpoints;
6493 /* Display the value of default-collect in a way that is generally
6494 compatible with the breakpoint list. */
6497 default_collect_info (void)
6499 struct ui_out *uiout = current_uiout;
6501 /* If it has no value (which is frequently the case), say nothing; a
6502 message like "No default-collect." gets in user's face when it's
6504 if (!*default_collect)
6507 /* The following phrase lines up nicely with per-tracepoint collect
6509 ui_out_text (uiout, "default collect ");
6510 ui_out_field_string (uiout, "default-collect", default_collect);
6511 ui_out_text (uiout, " \n");
6515 breakpoints_info (char *args, int from_tty)
6517 breakpoint_1 (args, 0, NULL);
6519 default_collect_info ();
6523 watchpoints_info (char *args, int from_tty)
6525 int num_printed = breakpoint_1 (args, 0, is_watchpoint);
6526 struct ui_out *uiout = current_uiout;
6528 if (num_printed == 0)
6530 if (args == NULL || *args == '\0')
6531 ui_out_message (uiout, 0, "No watchpoints.\n");
6533 ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args);
6538 maintenance_info_breakpoints (char *args, int from_tty)
6540 breakpoint_1 (args, 1, NULL);
6542 default_collect_info ();
6546 breakpoint_has_pc (struct breakpoint *b,
6547 struct program_space *pspace,
6548 CORE_ADDR pc, struct obj_section *section)
6550 struct bp_location *bl = b->loc;
6552 for (; bl; bl = bl->next)
6554 if (bl->pspace == pspace
6555 && bl->address == pc
6556 && (!overlay_debugging || bl->section == section))
6562 /* Print a message describing any user-breakpoints set at PC. This
6563 concerns with logical breakpoints, so we match program spaces, not
6567 describe_other_breakpoints (struct gdbarch *gdbarch,
6568 struct program_space *pspace, CORE_ADDR pc,
6569 struct obj_section *section, int thread)
6572 struct breakpoint *b;
6575 others += (user_breakpoint_p (b)
6576 && breakpoint_has_pc (b, pspace, pc, section));
6580 printf_filtered (_("Note: breakpoint "));
6581 else /* if (others == ???) */
6582 printf_filtered (_("Note: breakpoints "));
6584 if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section))
6587 printf_filtered ("%d", b->number);
6588 if (b->thread == -1 && thread != -1)
6589 printf_filtered (" (all threads)");
6590 else if (b->thread != -1)
6591 printf_filtered (" (thread %d)", b->thread);
6592 printf_filtered ("%s%s ",
6593 ((b->enable_state == bp_disabled
6594 || b->enable_state == bp_call_disabled)
6596 : b->enable_state == bp_permanent
6600 : ((others == 1) ? " and" : ""));
6602 printf_filtered (_("also set at pc "));
6603 fputs_filtered (paddress (gdbarch, pc), gdb_stdout);
6604 printf_filtered (".\n");
6609 /* Return true iff it is meaningful to use the address member of
6610 BPT. For some breakpoint types, the address member is irrelevant
6611 and it makes no sense to attempt to compare it to other addresses
6612 (or use it for any other purpose either).
6614 More specifically, each of the following breakpoint types will
6615 always have a zero valued address and we don't want to mark
6616 breakpoints of any of these types to be a duplicate of an actual
6617 breakpoint at address zero:
6625 breakpoint_address_is_meaningful (struct breakpoint *bpt)
6627 enum bptype type = bpt->type;
6629 return (type != bp_watchpoint && type != bp_catchpoint);
6632 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6633 true if LOC1 and LOC2 represent the same watchpoint location. */
6636 watchpoint_locations_match (struct bp_location *loc1,
6637 struct bp_location *loc2)
6639 struct watchpoint *w1 = (struct watchpoint *) loc1->owner;
6640 struct watchpoint *w2 = (struct watchpoint *) loc2->owner;
6642 /* Both of them must exist. */
6643 gdb_assert (w1 != NULL);
6644 gdb_assert (w2 != NULL);
6646 /* If the target can evaluate the condition expression in hardware,
6647 then we we need to insert both watchpoints even if they are at
6648 the same place. Otherwise the watchpoint will only trigger when
6649 the condition of whichever watchpoint was inserted evaluates to
6650 true, not giving a chance for GDB to check the condition of the
6651 other watchpoint. */
6653 && target_can_accel_watchpoint_condition (loc1->address,
6655 loc1->watchpoint_type,
6658 && target_can_accel_watchpoint_condition (loc2->address,
6660 loc2->watchpoint_type,
6664 /* Note that this checks the owner's type, not the location's. In
6665 case the target does not support read watchpoints, but does
6666 support access watchpoints, we'll have bp_read_watchpoint
6667 watchpoints with hw_access locations. Those should be considered
6668 duplicates of hw_read locations. The hw_read locations will
6669 become hw_access locations later. */
6670 return (loc1->owner->type == loc2->owner->type
6671 && loc1->pspace->aspace == loc2->pspace->aspace
6672 && loc1->address == loc2->address
6673 && loc1->length == loc2->length);
6676 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
6677 same breakpoint location. In most targets, this can only be true
6678 if ASPACE1 matches ASPACE2. On targets that have global
6679 breakpoints, the address space doesn't really matter. */
6682 breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1,
6683 struct address_space *aspace2, CORE_ADDR addr2)
6685 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6686 || aspace1 == aspace2)
6690 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6691 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6692 matches ASPACE2. On targets that have global breakpoints, the address
6693 space doesn't really matter. */
6696 breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1,
6697 int len1, struct address_space *aspace2,
6700 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6701 || aspace1 == aspace2)
6702 && addr2 >= addr1 && addr2 < addr1 + len1);
6705 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6706 a ranged breakpoint. In most targets, a match happens only if ASPACE
6707 matches the breakpoint's address space. On targets that have global
6708 breakpoints, the address space doesn't really matter. */
6711 breakpoint_location_address_match (struct bp_location *bl,
6712 struct address_space *aspace,
6715 return (breakpoint_address_match (bl->pspace->aspace, bl->address,
6718 && breakpoint_address_match_range (bl->pspace->aspace,
6719 bl->address, bl->length,
6723 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6724 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6725 true, otherwise returns false. */
6728 tracepoint_locations_match (struct bp_location *loc1,
6729 struct bp_location *loc2)
6731 if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner))
6732 /* Since tracepoint locations are never duplicated with others', tracepoint
6733 locations at the same address of different tracepoints are regarded as
6734 different locations. */
6735 return (loc1->address == loc2->address && loc1->owner == loc2->owner);
6740 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
6741 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
6742 represent the same location. */
6745 breakpoint_locations_match (struct bp_location *loc1,
6746 struct bp_location *loc2)
6748 int hw_point1, hw_point2;
6750 /* Both of them must not be in moribund_locations. */
6751 gdb_assert (loc1->owner != NULL);
6752 gdb_assert (loc2->owner != NULL);
6754 hw_point1 = is_hardware_watchpoint (loc1->owner);
6755 hw_point2 = is_hardware_watchpoint (loc2->owner);
6757 if (hw_point1 != hw_point2)
6760 return watchpoint_locations_match (loc1, loc2);
6761 else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner))
6762 return tracepoint_locations_match (loc1, loc2);
6764 /* We compare bp_location.length in order to cover ranged breakpoints. */
6765 return (breakpoint_address_match (loc1->pspace->aspace, loc1->address,
6766 loc2->pspace->aspace, loc2->address)
6767 && loc1->length == loc2->length);
6771 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
6772 int bnum, int have_bnum)
6774 /* The longest string possibly returned by hex_string_custom
6775 is 50 chars. These must be at least that big for safety. */
6779 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
6780 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
6782 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
6783 bnum, astr1, astr2);
6785 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
6788 /* Adjust a breakpoint's address to account for architectural
6789 constraints on breakpoint placement. Return the adjusted address.
6790 Note: Very few targets require this kind of adjustment. For most
6791 targets, this function is simply the identity function. */
6794 adjust_breakpoint_address (struct gdbarch *gdbarch,
6795 CORE_ADDR bpaddr, enum bptype bptype)
6797 if (!gdbarch_adjust_breakpoint_address_p (gdbarch))
6799 /* Very few targets need any kind of breakpoint adjustment. */
6802 else if (bptype == bp_watchpoint
6803 || bptype == bp_hardware_watchpoint
6804 || bptype == bp_read_watchpoint
6805 || bptype == bp_access_watchpoint
6806 || bptype == bp_catchpoint)
6808 /* Watchpoints and the various bp_catch_* eventpoints should not
6809 have their addresses modified. */
6814 CORE_ADDR adjusted_bpaddr;
6816 /* Some targets have architectural constraints on the placement
6817 of breakpoint instructions. Obtain the adjusted address. */
6818 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr);
6820 /* An adjusted breakpoint address can significantly alter
6821 a user's expectations. Print a warning if an adjustment
6823 if (adjusted_bpaddr != bpaddr)
6824 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
6826 return adjusted_bpaddr;
6831 init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops,
6832 struct breakpoint *owner)
6834 memset (loc, 0, sizeof (*loc));
6836 gdb_assert (ops != NULL);
6841 loc->cond_bytecode = NULL;
6842 loc->shlib_disabled = 0;
6845 switch (owner->type)
6851 case bp_longjmp_resume:
6852 case bp_longjmp_call_dummy:
6854 case bp_exception_resume:
6855 case bp_step_resume:
6856 case bp_hp_step_resume:
6857 case bp_watchpoint_scope:
6859 case bp_std_terminate:
6860 case bp_shlib_event:
6861 case bp_thread_event:
6862 case bp_overlay_event:
6864 case bp_longjmp_master:
6865 case bp_std_terminate_master:
6866 case bp_exception_master:
6867 case bp_gnu_ifunc_resolver:
6868 case bp_gnu_ifunc_resolver_return:
6870 loc->loc_type = bp_loc_software_breakpoint;
6871 mark_breakpoint_location_modified (loc);
6873 case bp_hardware_breakpoint:
6874 loc->loc_type = bp_loc_hardware_breakpoint;
6875 mark_breakpoint_location_modified (loc);
6877 case bp_hardware_watchpoint:
6878 case bp_read_watchpoint:
6879 case bp_access_watchpoint:
6880 loc->loc_type = bp_loc_hardware_watchpoint;
6885 case bp_fast_tracepoint:
6886 case bp_static_tracepoint:
6887 loc->loc_type = bp_loc_other;
6890 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
6896 /* Allocate a struct bp_location. */
6898 static struct bp_location *
6899 allocate_bp_location (struct breakpoint *bpt)
6901 return bpt->ops->allocate_location (bpt);
6905 free_bp_location (struct bp_location *loc)
6907 loc->ops->dtor (loc);
6911 /* Increment reference count. */
6914 incref_bp_location (struct bp_location *bl)
6919 /* Decrement reference count. If the reference count reaches 0,
6920 destroy the bp_location. Sets *BLP to NULL. */
6923 decref_bp_location (struct bp_location **blp)
6925 gdb_assert ((*blp)->refc > 0);
6927 if (--(*blp)->refc == 0)
6928 free_bp_location (*blp);
6932 /* Add breakpoint B at the end of the global breakpoint chain. */
6935 add_to_breakpoint_chain (struct breakpoint *b)
6937 struct breakpoint *b1;
6939 /* Add this breakpoint to the end of the chain so that a list of
6940 breakpoints will come out in order of increasing numbers. */
6942 b1 = breakpoint_chain;
6944 breakpoint_chain = b;
6953 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
6956 init_raw_breakpoint_without_location (struct breakpoint *b,
6957 struct gdbarch *gdbarch,
6959 const struct breakpoint_ops *ops)
6961 memset (b, 0, sizeof (*b));
6963 gdb_assert (ops != NULL);
6967 b->gdbarch = gdbarch;
6968 b->language = current_language->la_language;
6969 b->input_radix = input_radix;
6971 b->enable_state = bp_enabled;
6974 b->ignore_count = 0;
6976 b->frame_id = null_frame_id;
6977 b->condition_not_parsed = 0;
6978 b->py_bp_object = NULL;
6979 b->related_breakpoint = b;
6982 /* Helper to set_raw_breakpoint below. Creates a breakpoint
6983 that has type BPTYPE and has no locations as yet. */
6985 static struct breakpoint *
6986 set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
6988 const struct breakpoint_ops *ops)
6990 struct breakpoint *b = XNEW (struct breakpoint);
6992 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
6993 add_to_breakpoint_chain (b);
6997 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
6998 resolutions should be made as the user specified the location explicitly
7002 set_breakpoint_location_function (struct bp_location *loc, int explicit_loc)
7004 gdb_assert (loc->owner != NULL);
7006 if (loc->owner->type == bp_breakpoint
7007 || loc->owner->type == bp_hardware_breakpoint
7008 || is_tracepoint (loc->owner))
7011 const char *function_name;
7012 CORE_ADDR func_addr;
7014 find_pc_partial_function_gnu_ifunc (loc->address, &function_name,
7015 &func_addr, NULL, &is_gnu_ifunc);
7017 if (is_gnu_ifunc && !explicit_loc)
7019 struct breakpoint *b = loc->owner;
7021 gdb_assert (loc->pspace == current_program_space);
7022 if (gnu_ifunc_resolve_name (function_name,
7023 &loc->requested_address))
7025 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7026 loc->address = adjust_breakpoint_address (loc->gdbarch,
7027 loc->requested_address,
7030 else if (b->type == bp_breakpoint && b->loc == loc
7031 && loc->next == NULL && b->related_breakpoint == b)
7033 /* Create only the whole new breakpoint of this type but do not
7034 mess more complicated breakpoints with multiple locations. */
7035 b->type = bp_gnu_ifunc_resolver;
7036 /* Remember the resolver's address for use by the return
7038 loc->related_address = func_addr;
7043 loc->function_name = xstrdup (function_name);
7047 /* Attempt to determine architecture of location identified by SAL. */
7049 get_sal_arch (struct symtab_and_line sal)
7052 return get_objfile_arch (sal.section->objfile);
7054 return get_objfile_arch (sal.symtab->objfile);
7059 /* Low level routine for partially initializing a breakpoint of type
7060 BPTYPE. The newly created breakpoint's address, section, source
7061 file name, and line number are provided by SAL.
7063 It is expected that the caller will complete the initialization of
7064 the newly created breakpoint struct as well as output any status
7065 information regarding the creation of a new breakpoint. */
7068 init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch,
7069 struct symtab_and_line sal, enum bptype bptype,
7070 const struct breakpoint_ops *ops)
7072 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
7074 add_location_to_breakpoint (b, &sal);
7076 if (bptype != bp_catchpoint)
7077 gdb_assert (sal.pspace != NULL);
7079 /* Store the program space that was used to set the breakpoint,
7080 except for ordinary breakpoints, which are independent of the
7082 if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint)
7083 b->pspace = sal.pspace;
7086 /* set_raw_breakpoint is a low level routine for allocating and
7087 partially initializing a breakpoint of type BPTYPE. The newly
7088 created breakpoint's address, section, source file name, and line
7089 number are provided by SAL. The newly created and partially
7090 initialized breakpoint is added to the breakpoint chain and
7091 is also returned as the value of this function.
7093 It is expected that the caller will complete the initialization of
7094 the newly created breakpoint struct as well as output any status
7095 information regarding the creation of a new breakpoint. In
7096 particular, set_raw_breakpoint does NOT set the breakpoint
7097 number! Care should be taken to not allow an error to occur
7098 prior to completing the initialization of the breakpoint. If this
7099 should happen, a bogus breakpoint will be left on the chain. */
7102 set_raw_breakpoint (struct gdbarch *gdbarch,
7103 struct symtab_and_line sal, enum bptype bptype,
7104 const struct breakpoint_ops *ops)
7106 struct breakpoint *b = XNEW (struct breakpoint);
7108 init_raw_breakpoint (b, gdbarch, sal, bptype, ops);
7109 add_to_breakpoint_chain (b);
7114 /* Note that the breakpoint object B describes a permanent breakpoint
7115 instruction, hard-wired into the inferior's code. */
7117 make_breakpoint_permanent (struct breakpoint *b)
7119 struct bp_location *bl;
7121 b->enable_state = bp_permanent;
7123 /* By definition, permanent breakpoints are already present in the
7124 code. Mark all locations as inserted. For now,
7125 make_breakpoint_permanent is called in just one place, so it's
7126 hard to say if it's reasonable to have permanent breakpoint with
7127 multiple locations or not, but it's easy to implement. */
7128 for (bl = b->loc; bl; bl = bl->next)
7132 /* Call this routine when stepping and nexting to enable a breakpoint
7133 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7134 initiated the operation. */
7137 set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame)
7139 struct breakpoint *b, *b_tmp;
7140 int thread = tp->num;
7142 /* To avoid having to rescan all objfile symbols at every step,
7143 we maintain a list of continually-inserted but always disabled
7144 longjmp "master" breakpoints. Here, we simply create momentary
7145 clones of those and enable them for the requested thread. */
7146 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7147 if (b->pspace == current_program_space
7148 && (b->type == bp_longjmp_master
7149 || b->type == bp_exception_master))
7151 enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception;
7152 struct breakpoint *clone;
7154 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7155 after their removal. */
7156 clone = momentary_breakpoint_from_master (b, type,
7157 &longjmp_breakpoint_ops);
7158 clone->thread = thread;
7161 tp->initiating_frame = frame;
7164 /* Delete all longjmp breakpoints from THREAD. */
7166 delete_longjmp_breakpoint (int thread)
7168 struct breakpoint *b, *b_tmp;
7170 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7171 if (b->type == bp_longjmp || b->type == bp_exception)
7173 if (b->thread == thread)
7174 delete_breakpoint (b);
7179 delete_longjmp_breakpoint_at_next_stop (int thread)
7181 struct breakpoint *b, *b_tmp;
7183 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7184 if (b->type == bp_longjmp || b->type == bp_exception)
7186 if (b->thread == thread)
7187 b->disposition = disp_del_at_next_stop;
7191 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7192 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7193 pointer to any of them. Return NULL if this system cannot place longjmp
7197 set_longjmp_breakpoint_for_call_dummy (void)
7199 struct breakpoint *b, *retval = NULL;
7202 if (b->pspace == current_program_space && b->type == bp_longjmp_master)
7204 struct breakpoint *new_b;
7206 new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy,
7207 &momentary_breakpoint_ops);
7208 new_b->thread = pid_to_thread_id (inferior_ptid);
7210 /* Link NEW_B into the chain of RETVAL breakpoints. */
7212 gdb_assert (new_b->related_breakpoint == new_b);
7215 new_b->related_breakpoint = retval;
7216 while (retval->related_breakpoint != new_b->related_breakpoint)
7217 retval = retval->related_breakpoint;
7218 retval->related_breakpoint = new_b;
7224 /* Verify all existing dummy frames and their associated breakpoints for
7225 THREAD. Remove those which can no longer be found in the current frame
7228 You should call this function only at places where it is safe to currently
7229 unwind the whole stack. Failed stack unwind would discard live dummy
7233 check_longjmp_breakpoint_for_call_dummy (int thread)
7235 struct breakpoint *b, *b_tmp;
7237 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7238 if (b->type == bp_longjmp_call_dummy && b->thread == thread)
7240 struct breakpoint *dummy_b = b->related_breakpoint;
7242 while (dummy_b != b && dummy_b->type != bp_call_dummy)
7243 dummy_b = dummy_b->related_breakpoint;
7244 if (dummy_b->type != bp_call_dummy
7245 || frame_find_by_id (dummy_b->frame_id) != NULL)
7248 dummy_frame_discard (dummy_b->frame_id);
7250 while (b->related_breakpoint != b)
7252 if (b_tmp == b->related_breakpoint)
7253 b_tmp = b->related_breakpoint->next;
7254 delete_breakpoint (b->related_breakpoint);
7256 delete_breakpoint (b);
7261 enable_overlay_breakpoints (void)
7263 struct breakpoint *b;
7266 if (b->type == bp_overlay_event)
7268 b->enable_state = bp_enabled;
7269 update_global_location_list (1);
7270 overlay_events_enabled = 1;
7275 disable_overlay_breakpoints (void)
7277 struct breakpoint *b;
7280 if (b->type == bp_overlay_event)
7282 b->enable_state = bp_disabled;
7283 update_global_location_list (0);
7284 overlay_events_enabled = 0;
7288 /* Set an active std::terminate breakpoint for each std::terminate
7289 master breakpoint. */
7291 set_std_terminate_breakpoint (void)
7293 struct breakpoint *b, *b_tmp;
7295 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7296 if (b->pspace == current_program_space
7297 && b->type == bp_std_terminate_master)
7299 momentary_breakpoint_from_master (b, bp_std_terminate,
7300 &momentary_breakpoint_ops);
7304 /* Delete all the std::terminate breakpoints. */
7306 delete_std_terminate_breakpoint (void)
7308 struct breakpoint *b, *b_tmp;
7310 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7311 if (b->type == bp_std_terminate)
7312 delete_breakpoint (b);
7316 create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7318 struct breakpoint *b;
7320 b = create_internal_breakpoint (gdbarch, address, bp_thread_event,
7321 &internal_breakpoint_ops);
7323 b->enable_state = bp_enabled;
7324 /* addr_string has to be used or breakpoint_re_set will delete me. */
7326 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
7328 update_global_location_list_nothrow (1);
7334 remove_thread_event_breakpoints (void)
7336 struct breakpoint *b, *b_tmp;
7338 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7339 if (b->type == bp_thread_event
7340 && b->loc->pspace == current_program_space)
7341 delete_breakpoint (b);
7344 struct lang_and_radix
7350 /* Create a breakpoint for JIT code registration and unregistration. */
7353 create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7355 struct breakpoint *b;
7357 b = create_internal_breakpoint (gdbarch, address, bp_jit_event,
7358 &internal_breakpoint_ops);
7359 update_global_location_list_nothrow (1);
7363 /* Remove JIT code registration and unregistration breakpoint(s). */
7366 remove_jit_event_breakpoints (void)
7368 struct breakpoint *b, *b_tmp;
7370 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7371 if (b->type == bp_jit_event
7372 && b->loc->pspace == current_program_space)
7373 delete_breakpoint (b);
7377 remove_solib_event_breakpoints (void)
7379 struct breakpoint *b, *b_tmp;
7381 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7382 if (b->type == bp_shlib_event
7383 && b->loc->pspace == current_program_space)
7384 delete_breakpoint (b);
7388 create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7390 struct breakpoint *b;
7392 b = create_internal_breakpoint (gdbarch, address, bp_shlib_event,
7393 &internal_breakpoint_ops);
7394 update_global_location_list_nothrow (1);
7398 /* Disable any breakpoints that are on code in shared libraries. Only
7399 apply to enabled breakpoints, disabled ones can just stay disabled. */
7402 disable_breakpoints_in_shlibs (void)
7404 struct bp_location *loc, **locp_tmp;
7406 ALL_BP_LOCATIONS (loc, locp_tmp)
7408 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7409 struct breakpoint *b = loc->owner;
7411 /* We apply the check to all breakpoints, including disabled for
7412 those with loc->duplicate set. This is so that when breakpoint
7413 becomes enabled, or the duplicate is removed, gdb will try to
7414 insert all breakpoints. If we don't set shlib_disabled here,
7415 we'll try to insert those breakpoints and fail. */
7416 if (((b->type == bp_breakpoint)
7417 || (b->type == bp_jit_event)
7418 || (b->type == bp_hardware_breakpoint)
7419 || (is_tracepoint (b)))
7420 && loc->pspace == current_program_space
7421 && !loc->shlib_disabled
7423 && PC_SOLIB (loc->address)
7425 && solib_name_from_address (loc->pspace, loc->address)
7429 loc->shlib_disabled = 1;
7434 /* Disable any breakpoints and tracepoints that are in an unloaded shared
7435 library. Only apply to enabled breakpoints, disabled ones can just stay
7439 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
7441 struct bp_location *loc, **locp_tmp;
7442 int disabled_shlib_breaks = 0;
7444 /* SunOS a.out shared libraries are always mapped, so do not
7445 disable breakpoints; they will only be reported as unloaded
7446 through clear_solib when GDB discards its shared library
7447 list. See clear_solib for more information. */
7448 if (exec_bfd != NULL
7449 && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour)
7452 ALL_BP_LOCATIONS (loc, locp_tmp)
7454 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7455 struct breakpoint *b = loc->owner;
7457 if (solib->pspace == loc->pspace
7458 && !loc->shlib_disabled
7459 && (((b->type == bp_breakpoint
7460 || b->type == bp_jit_event
7461 || b->type == bp_hardware_breakpoint)
7462 && (loc->loc_type == bp_loc_hardware_breakpoint
7463 || loc->loc_type == bp_loc_software_breakpoint))
7464 || is_tracepoint (b))
7465 && solib_contains_address_p (solib, loc->address))
7467 loc->shlib_disabled = 1;
7468 /* At this point, we cannot rely on remove_breakpoint
7469 succeeding so we must mark the breakpoint as not inserted
7470 to prevent future errors occurring in remove_breakpoints. */
7473 /* This may cause duplicate notifications for the same breakpoint. */
7474 observer_notify_breakpoint_modified (b);
7476 if (!disabled_shlib_breaks)
7478 target_terminal_ours_for_output ();
7479 warning (_("Temporarily disabling breakpoints "
7480 "for unloaded shared library \"%s\""),
7483 disabled_shlib_breaks = 1;
7488 /* FORK & VFORK catchpoints. */
7490 /* An instance of this type is used to represent a fork or vfork
7491 catchpoint. It includes a "struct breakpoint" as a kind of base
7492 class; users downcast to "struct breakpoint *" when needed. A
7493 breakpoint is really of this type iff its ops pointer points to
7494 CATCH_FORK_BREAKPOINT_OPS. */
7496 struct fork_catchpoint
7498 /* The base class. */
7499 struct breakpoint base;
7501 /* Process id of a child process whose forking triggered this
7502 catchpoint. This field is only valid immediately after this
7503 catchpoint has triggered. */
7504 ptid_t forked_inferior_pid;
7507 /* Implement the "insert" breakpoint_ops method for fork
7511 insert_catch_fork (struct bp_location *bl)
7513 return target_insert_fork_catchpoint (PIDGET (inferior_ptid));
7516 /* Implement the "remove" breakpoint_ops method for fork
7520 remove_catch_fork (struct bp_location *bl)
7522 return target_remove_fork_catchpoint (PIDGET (inferior_ptid));
7525 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7529 breakpoint_hit_catch_fork (const struct bp_location *bl,
7530 struct address_space *aspace, CORE_ADDR bp_addr,
7531 const struct target_waitstatus *ws)
7533 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
7535 if (ws->kind != TARGET_WAITKIND_FORKED)
7538 c->forked_inferior_pid = ws->value.related_pid;
7542 /* Implement the "print_it" breakpoint_ops method for fork
7545 static enum print_stop_action
7546 print_it_catch_fork (bpstat bs)
7548 struct ui_out *uiout = current_uiout;
7549 struct breakpoint *b = bs->breakpoint_at;
7550 struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at;
7552 annotate_catchpoint (b->number);
7553 if (b->disposition == disp_del)
7554 ui_out_text (uiout, "\nTemporary catchpoint ");
7556 ui_out_text (uiout, "\nCatchpoint ");
7557 if (ui_out_is_mi_like_p (uiout))
7559 ui_out_field_string (uiout, "reason",
7560 async_reason_lookup (EXEC_ASYNC_FORK));
7561 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7563 ui_out_field_int (uiout, "bkptno", b->number);
7564 ui_out_text (uiout, " (forked process ");
7565 ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid));
7566 ui_out_text (uiout, "), ");
7567 return PRINT_SRC_AND_LOC;
7570 /* Implement the "print_one" breakpoint_ops method for fork
7574 print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc)
7576 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
7577 struct value_print_options opts;
7578 struct ui_out *uiout = current_uiout;
7580 get_user_print_options (&opts);
7582 /* Field 4, the address, is omitted (which makes the columns not
7583 line up too nicely with the headers, but the effect is relatively
7585 if (opts.addressprint)
7586 ui_out_field_skip (uiout, "addr");
7588 ui_out_text (uiout, "fork");
7589 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
7591 ui_out_text (uiout, ", process ");
7592 ui_out_field_int (uiout, "what",
7593 ptid_get_pid (c->forked_inferior_pid));
7594 ui_out_spaces (uiout, 1);
7597 if (ui_out_is_mi_like_p (uiout))
7598 ui_out_field_string (uiout, "catch-type", "fork");
7601 /* Implement the "print_mention" breakpoint_ops method for fork
7605 print_mention_catch_fork (struct breakpoint *b)
7607 printf_filtered (_("Catchpoint %d (fork)"), b->number);
7610 /* Implement the "print_recreate" breakpoint_ops method for fork
7614 print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp)
7616 fprintf_unfiltered (fp, "catch fork");
7617 print_recreate_thread (b, fp);
7620 /* The breakpoint_ops structure to be used in fork catchpoints. */
7622 static struct breakpoint_ops catch_fork_breakpoint_ops;
7624 /* Implement the "insert" breakpoint_ops method for vfork
7628 insert_catch_vfork (struct bp_location *bl)
7630 return target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
7633 /* Implement the "remove" breakpoint_ops method for vfork
7637 remove_catch_vfork (struct bp_location *bl)
7639 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
7642 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
7646 breakpoint_hit_catch_vfork (const struct bp_location *bl,
7647 struct address_space *aspace, CORE_ADDR bp_addr,
7648 const struct target_waitstatus *ws)
7650 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
7652 if (ws->kind != TARGET_WAITKIND_VFORKED)
7655 c->forked_inferior_pid = ws->value.related_pid;
7659 /* Implement the "print_it" breakpoint_ops method for vfork
7662 static enum print_stop_action
7663 print_it_catch_vfork (bpstat bs)
7665 struct ui_out *uiout = current_uiout;
7666 struct breakpoint *b = bs->breakpoint_at;
7667 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
7669 annotate_catchpoint (b->number);
7670 if (b->disposition == disp_del)
7671 ui_out_text (uiout, "\nTemporary catchpoint ");
7673 ui_out_text (uiout, "\nCatchpoint ");
7674 if (ui_out_is_mi_like_p (uiout))
7676 ui_out_field_string (uiout, "reason",
7677 async_reason_lookup (EXEC_ASYNC_VFORK));
7678 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7680 ui_out_field_int (uiout, "bkptno", b->number);
7681 ui_out_text (uiout, " (vforked process ");
7682 ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid));
7683 ui_out_text (uiout, "), ");
7684 return PRINT_SRC_AND_LOC;
7687 /* Implement the "print_one" breakpoint_ops method for vfork
7691 print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc)
7693 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
7694 struct value_print_options opts;
7695 struct ui_out *uiout = current_uiout;
7697 get_user_print_options (&opts);
7698 /* Field 4, the address, is omitted (which makes the columns not
7699 line up too nicely with the headers, but the effect is relatively
7701 if (opts.addressprint)
7702 ui_out_field_skip (uiout, "addr");
7704 ui_out_text (uiout, "vfork");
7705 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
7707 ui_out_text (uiout, ", process ");
7708 ui_out_field_int (uiout, "what",
7709 ptid_get_pid (c->forked_inferior_pid));
7710 ui_out_spaces (uiout, 1);
7713 if (ui_out_is_mi_like_p (uiout))
7714 ui_out_field_string (uiout, "catch-type", "vfork");
7717 /* Implement the "print_mention" breakpoint_ops method for vfork
7721 print_mention_catch_vfork (struct breakpoint *b)
7723 printf_filtered (_("Catchpoint %d (vfork)"), b->number);
7726 /* Implement the "print_recreate" breakpoint_ops method for vfork
7730 print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp)
7732 fprintf_unfiltered (fp, "catch vfork");
7733 print_recreate_thread (b, fp);
7736 /* The breakpoint_ops structure to be used in vfork catchpoints. */
7738 static struct breakpoint_ops catch_vfork_breakpoint_ops;
7740 /* An instance of this type is used to represent an solib catchpoint.
7741 It includes a "struct breakpoint" as a kind of base class; users
7742 downcast to "struct breakpoint *" when needed. A breakpoint is
7743 really of this type iff its ops pointer points to
7744 CATCH_SOLIB_BREAKPOINT_OPS. */
7746 struct solib_catchpoint
7748 /* The base class. */
7749 struct breakpoint base;
7751 /* True for "catch load", false for "catch unload". */
7752 unsigned char is_load;
7754 /* Regular expression to match, if any. COMPILED is only valid when
7755 REGEX is non-NULL. */
7761 dtor_catch_solib (struct breakpoint *b)
7763 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
7766 regfree (&self->compiled);
7767 xfree (self->regex);
7769 base_breakpoint_ops.dtor (b);
7773 insert_catch_solib (struct bp_location *ignore)
7779 remove_catch_solib (struct bp_location *ignore)
7785 breakpoint_hit_catch_solib (const struct bp_location *bl,
7786 struct address_space *aspace,
7788 const struct target_waitstatus *ws)
7790 struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner;
7791 struct breakpoint *other;
7793 if (ws->kind == TARGET_WAITKIND_LOADED)
7796 ALL_BREAKPOINTS (other)
7798 struct bp_location *other_bl;
7800 if (other == bl->owner)
7803 if (other->type != bp_shlib_event)
7806 if (self->base.pspace != NULL && other->pspace != self->base.pspace)
7809 for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next)
7811 if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws))
7820 check_status_catch_solib (struct bpstats *bs)
7822 struct solib_catchpoint *self
7823 = (struct solib_catchpoint *) bs->breakpoint_at;
7828 struct so_list *iter;
7831 VEC_iterate (so_list_ptr, current_program_space->added_solibs,
7836 || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0)
7845 VEC_iterate (char_ptr, current_program_space->deleted_solibs,
7850 || regexec (&self->compiled, iter, 0, NULL, 0) == 0)
7856 bs->print_it = print_it_noop;
7859 static enum print_stop_action
7860 print_it_catch_solib (bpstat bs)
7862 struct breakpoint *b = bs->breakpoint_at;
7863 struct ui_out *uiout = current_uiout;
7865 annotate_catchpoint (b->number);
7866 if (b->disposition == disp_del)
7867 ui_out_text (uiout, "\nTemporary catchpoint ");
7869 ui_out_text (uiout, "\nCatchpoint ");
7870 ui_out_field_int (uiout, "bkptno", b->number);
7871 ui_out_text (uiout, "\n");
7872 if (ui_out_is_mi_like_p (uiout))
7873 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7874 print_solib_event (1);
7875 return PRINT_SRC_AND_LOC;
7879 print_one_catch_solib (struct breakpoint *b, struct bp_location **locs)
7881 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
7882 struct value_print_options opts;
7883 struct ui_out *uiout = current_uiout;
7886 get_user_print_options (&opts);
7887 /* Field 4, the address, is omitted (which makes the columns not
7888 line up too nicely with the headers, but the effect is relatively
7890 if (opts.addressprint)
7893 ui_out_field_skip (uiout, "addr");
7900 msg = xstrprintf (_("load of library matching %s"), self->regex);
7902 msg = xstrdup (_("load of library"));
7907 msg = xstrprintf (_("unload of library matching %s"), self->regex);
7909 msg = xstrdup (_("unload of library"));
7911 ui_out_field_string (uiout, "what", msg);
7914 if (ui_out_is_mi_like_p (uiout))
7915 ui_out_field_string (uiout, "catch-type",
7916 self->is_load ? "load" : "unload");
7920 print_mention_catch_solib (struct breakpoint *b)
7922 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
7924 printf_filtered (_("Catchpoint %d (%s)"), b->number,
7925 self->is_load ? "load" : "unload");
7929 print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp)
7931 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
7933 fprintf_unfiltered (fp, "%s %s",
7934 b->disposition == disp_del ? "tcatch" : "catch",
7935 self->is_load ? "load" : "unload");
7937 fprintf_unfiltered (fp, " %s", self->regex);
7938 fprintf_unfiltered (fp, "\n");
7941 static struct breakpoint_ops catch_solib_breakpoint_ops;
7943 /* Shared helper function (MI and CLI) for creating and installing
7944 a shared object event catchpoint. If IS_LOAD is non-zero then
7945 the events to be caught are load events, otherwise they are
7946 unload events. If IS_TEMP is non-zero the catchpoint is a
7947 temporary one. If ENABLED is non-zero the catchpoint is
7948 created in an enabled state. */
7951 add_solib_catchpoint (char *arg, int is_load, int is_temp, int enabled)
7953 struct solib_catchpoint *c;
7954 struct gdbarch *gdbarch = get_current_arch ();
7955 struct cleanup *cleanup;
7959 arg = skip_spaces (arg);
7961 c = XCNEW (struct solib_catchpoint);
7962 cleanup = make_cleanup (xfree, c);
7968 errcode = regcomp (&c->compiled, arg, REG_NOSUB);
7971 char *err = get_regcomp_error (errcode, &c->compiled);
7973 make_cleanup (xfree, err);
7974 error (_("Invalid regexp (%s): %s"), err, arg);
7976 c->regex = xstrdup (arg);
7979 c->is_load = is_load;
7980 init_catchpoint (&c->base, gdbarch, is_temp, NULL,
7981 &catch_solib_breakpoint_ops);
7983 c->base.enable_state = enabled ? bp_enabled : bp_disabled;
7985 discard_cleanups (cleanup);
7986 install_breakpoint (0, &c->base, 1);
7989 /* A helper function that does all the work for "catch load" and
7993 catch_load_or_unload (char *arg, int from_tty, int is_load,
7994 struct cmd_list_element *command)
7997 const int enabled = 1;
7999 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
8001 add_solib_catchpoint (arg, is_load, tempflag, enabled);
8005 catch_load_command_1 (char *arg, int from_tty,
8006 struct cmd_list_element *command)
8008 catch_load_or_unload (arg, from_tty, 1, command);
8012 catch_unload_command_1 (char *arg, int from_tty,
8013 struct cmd_list_element *command)
8015 catch_load_or_unload (arg, from_tty, 0, command);
8018 /* An instance of this type is used to represent a syscall catchpoint.
8019 It includes a "struct breakpoint" as a kind of base class; users
8020 downcast to "struct breakpoint *" when needed. A breakpoint is
8021 really of this type iff its ops pointer points to
8022 CATCH_SYSCALL_BREAKPOINT_OPS. */
8024 struct syscall_catchpoint
8026 /* The base class. */
8027 struct breakpoint base;
8029 /* Syscall numbers used for the 'catch syscall' feature. If no
8030 syscall has been specified for filtering, its value is NULL.
8031 Otherwise, it holds a list of all syscalls to be caught. The
8032 list elements are allocated with xmalloc. */
8033 VEC(int) *syscalls_to_be_caught;
8036 /* Implement the "dtor" breakpoint_ops method for syscall
8040 dtor_catch_syscall (struct breakpoint *b)
8042 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
8044 VEC_free (int, c->syscalls_to_be_caught);
8046 base_breakpoint_ops.dtor (b);
8049 static const struct inferior_data *catch_syscall_inferior_data = NULL;
8051 struct catch_syscall_inferior_data
8053 /* We keep a count of the number of times the user has requested a
8054 particular syscall to be tracked, and pass this information to the
8055 target. This lets capable targets implement filtering directly. */
8057 /* Number of times that "any" syscall is requested. */
8058 int any_syscall_count;
8060 /* Count of each system call. */
8061 VEC(int) *syscalls_counts;
8063 /* This counts all syscall catch requests, so we can readily determine
8064 if any catching is necessary. */
8065 int total_syscalls_count;
8068 static struct catch_syscall_inferior_data*
8069 get_catch_syscall_inferior_data (struct inferior *inf)
8071 struct catch_syscall_inferior_data *inf_data;
8073 inf_data = inferior_data (inf, catch_syscall_inferior_data);
8074 if (inf_data == NULL)
8076 inf_data = XZALLOC (struct catch_syscall_inferior_data);
8077 set_inferior_data (inf, catch_syscall_inferior_data, inf_data);
8084 catch_syscall_inferior_data_cleanup (struct inferior *inf, void *arg)
8090 /* Implement the "insert" breakpoint_ops method for syscall
8094 insert_catch_syscall (struct bp_location *bl)
8096 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner;
8097 struct inferior *inf = current_inferior ();
8098 struct catch_syscall_inferior_data *inf_data
8099 = get_catch_syscall_inferior_data (inf);
8101 ++inf_data->total_syscalls_count;
8102 if (!c->syscalls_to_be_caught)
8103 ++inf_data->any_syscall_count;
8109 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8114 if (iter >= VEC_length (int, inf_data->syscalls_counts))
8116 int old_size = VEC_length (int, inf_data->syscalls_counts);
8117 uintptr_t vec_addr_offset
8118 = old_size * ((uintptr_t) sizeof (int));
8120 VEC_safe_grow (int, inf_data->syscalls_counts, iter + 1);
8121 vec_addr = ((uintptr_t) VEC_address (int,
8122 inf_data->syscalls_counts)
8124 memset ((void *) vec_addr, 0,
8125 (iter + 1 - old_size) * sizeof (int));
8127 elem = VEC_index (int, inf_data->syscalls_counts, iter);
8128 VEC_replace (int, inf_data->syscalls_counts, iter, ++elem);
8132 return target_set_syscall_catchpoint (PIDGET (inferior_ptid),
8133 inf_data->total_syscalls_count != 0,
8134 inf_data->any_syscall_count,
8136 inf_data->syscalls_counts),
8138 inf_data->syscalls_counts));
8141 /* Implement the "remove" breakpoint_ops method for syscall
8145 remove_catch_syscall (struct bp_location *bl)
8147 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner;
8148 struct inferior *inf = current_inferior ();
8149 struct catch_syscall_inferior_data *inf_data
8150 = get_catch_syscall_inferior_data (inf);
8152 --inf_data->total_syscalls_count;
8153 if (!c->syscalls_to_be_caught)
8154 --inf_data->any_syscall_count;
8160 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8164 if (iter >= VEC_length (int, inf_data->syscalls_counts))
8165 /* Shouldn't happen. */
8167 elem = VEC_index (int, inf_data->syscalls_counts, iter);
8168 VEC_replace (int, inf_data->syscalls_counts, iter, --elem);
8172 return target_set_syscall_catchpoint (PIDGET (inferior_ptid),
8173 inf_data->total_syscalls_count != 0,
8174 inf_data->any_syscall_count,
8176 inf_data->syscalls_counts),
8178 inf_data->syscalls_counts));
8181 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
8185 breakpoint_hit_catch_syscall (const struct bp_location *bl,
8186 struct address_space *aspace, CORE_ADDR bp_addr,
8187 const struct target_waitstatus *ws)
8189 /* We must check if we are catching specific syscalls in this
8190 breakpoint. If we are, then we must guarantee that the called
8191 syscall is the same syscall we are catching. */
8192 int syscall_number = 0;
8193 const struct syscall_catchpoint *c
8194 = (const struct syscall_catchpoint *) bl->owner;
8196 if (ws->kind != TARGET_WAITKIND_SYSCALL_ENTRY
8197 && ws->kind != TARGET_WAITKIND_SYSCALL_RETURN)
8200 syscall_number = ws->value.syscall_number;
8202 /* Now, checking if the syscall is the same. */
8203 if (c->syscalls_to_be_caught)
8208 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8210 if (syscall_number == iter)
8220 /* Implement the "print_it" breakpoint_ops method for syscall
8223 static enum print_stop_action
8224 print_it_catch_syscall (bpstat bs)
8226 struct ui_out *uiout = current_uiout;
8227 struct breakpoint *b = bs->breakpoint_at;
8228 /* These are needed because we want to know in which state a
8229 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
8230 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
8231 must print "called syscall" or "returned from syscall". */
8233 struct target_waitstatus last;
8236 get_last_target_status (&ptid, &last);
8238 get_syscall_by_number (last.value.syscall_number, &s);
8240 annotate_catchpoint (b->number);
8242 if (b->disposition == disp_del)
8243 ui_out_text (uiout, "\nTemporary catchpoint ");
8245 ui_out_text (uiout, "\nCatchpoint ");
8246 if (ui_out_is_mi_like_p (uiout))
8248 ui_out_field_string (uiout, "reason",
8249 async_reason_lookup (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY
8250 ? EXEC_ASYNC_SYSCALL_ENTRY
8251 : EXEC_ASYNC_SYSCALL_RETURN));
8252 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8254 ui_out_field_int (uiout, "bkptno", b->number);
8256 if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY)
8257 ui_out_text (uiout, " (call to syscall ");
8259 ui_out_text (uiout, " (returned from syscall ");
8261 if (s.name == NULL || ui_out_is_mi_like_p (uiout))
8262 ui_out_field_int (uiout, "syscall-number", last.value.syscall_number);
8264 ui_out_field_string (uiout, "syscall-name", s.name);
8266 ui_out_text (uiout, "), ");
8268 return PRINT_SRC_AND_LOC;
8271 /* Implement the "print_one" breakpoint_ops method for syscall
8275 print_one_catch_syscall (struct breakpoint *b,
8276 struct bp_location **last_loc)
8278 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
8279 struct value_print_options opts;
8280 struct ui_out *uiout = current_uiout;
8282 get_user_print_options (&opts);
8283 /* Field 4, the address, is omitted (which makes the columns not
8284 line up too nicely with the headers, but the effect is relatively
8286 if (opts.addressprint)
8287 ui_out_field_skip (uiout, "addr");
8290 if (c->syscalls_to_be_caught
8291 && VEC_length (int, c->syscalls_to_be_caught) > 1)
8292 ui_out_text (uiout, "syscalls \"");
8294 ui_out_text (uiout, "syscall \"");
8296 if (c->syscalls_to_be_caught)
8299 char *text = xstrprintf ("%s", "");
8302 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8307 get_syscall_by_number (iter, &s);
8310 text = xstrprintf ("%s%s, ", text, s.name);
8312 text = xstrprintf ("%s%d, ", text, iter);
8314 /* We have to xfree the last 'text' (now stored at 'x')
8315 because xstrprintf dynamically allocates new space for it
8319 /* Remove the last comma. */
8320 text[strlen (text) - 2] = '\0';
8321 ui_out_field_string (uiout, "what", text);
8324 ui_out_field_string (uiout, "what", "<any syscall>");
8325 ui_out_text (uiout, "\" ");
8327 if (ui_out_is_mi_like_p (uiout))
8328 ui_out_field_string (uiout, "catch-type", "syscall");
8331 /* Implement the "print_mention" breakpoint_ops method for syscall
8335 print_mention_catch_syscall (struct breakpoint *b)
8337 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
8339 if (c->syscalls_to_be_caught)
8343 if (VEC_length (int, c->syscalls_to_be_caught) > 1)
8344 printf_filtered (_("Catchpoint %d (syscalls"), b->number);
8346 printf_filtered (_("Catchpoint %d (syscall"), b->number);
8349 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8353 get_syscall_by_number (iter, &s);
8356 printf_filtered (" '%s' [%d]", s.name, s.number);
8358 printf_filtered (" %d", s.number);
8360 printf_filtered (")");
8363 printf_filtered (_("Catchpoint %d (any syscall)"),
8367 /* Implement the "print_recreate" breakpoint_ops method for syscall
8371 print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp)
8373 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
8375 fprintf_unfiltered (fp, "catch syscall");
8377 if (c->syscalls_to_be_caught)
8382 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8387 get_syscall_by_number (iter, &s);
8389 fprintf_unfiltered (fp, " %s", s.name);
8391 fprintf_unfiltered (fp, " %d", s.number);
8394 print_recreate_thread (b, fp);
8397 /* The breakpoint_ops structure to be used in syscall catchpoints. */
8399 static struct breakpoint_ops catch_syscall_breakpoint_ops;
8401 /* Returns non-zero if 'b' is a syscall catchpoint. */
8404 syscall_catchpoint_p (struct breakpoint *b)
8406 return (b->ops == &catch_syscall_breakpoint_ops);
8409 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8410 is non-zero, then make the breakpoint temporary. If COND_STRING is
8411 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8412 the breakpoint_ops structure associated to the catchpoint. */
8415 init_catchpoint (struct breakpoint *b,
8416 struct gdbarch *gdbarch, int tempflag,
8418 const struct breakpoint_ops *ops)
8420 struct symtab_and_line sal;
8423 sal.pspace = current_program_space;
8425 init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops);
8427 b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string);
8428 b->disposition = tempflag ? disp_del : disp_donttouch;
8432 install_breakpoint (int internal, struct breakpoint *b, int update_gll)
8434 add_to_breakpoint_chain (b);
8435 set_breakpoint_number (internal, b);
8436 if (is_tracepoint (b))
8437 set_tracepoint_count (breakpoint_count);
8440 observer_notify_breakpoint_created (b);
8443 update_global_location_list (1);
8447 create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch,
8448 int tempflag, char *cond_string,
8449 const struct breakpoint_ops *ops)
8451 struct fork_catchpoint *c = XNEW (struct fork_catchpoint);
8453 init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops);
8455 c->forked_inferior_pid = null_ptid;
8457 install_breakpoint (0, &c->base, 1);
8460 /* Exec catchpoints. */
8462 /* An instance of this type is used to represent an exec catchpoint.
8463 It includes a "struct breakpoint" as a kind of base class; users
8464 downcast to "struct breakpoint *" when needed. A breakpoint is
8465 really of this type iff its ops pointer points to
8466 CATCH_EXEC_BREAKPOINT_OPS. */
8468 struct exec_catchpoint
8470 /* The base class. */
8471 struct breakpoint base;
8473 /* Filename of a program whose exec triggered this catchpoint.
8474 This field is only valid immediately after this catchpoint has
8476 char *exec_pathname;
8479 /* Implement the "dtor" breakpoint_ops method for exec
8483 dtor_catch_exec (struct breakpoint *b)
8485 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8487 xfree (c->exec_pathname);
8489 base_breakpoint_ops.dtor (b);
8493 insert_catch_exec (struct bp_location *bl)
8495 return target_insert_exec_catchpoint (PIDGET (inferior_ptid));
8499 remove_catch_exec (struct bp_location *bl)
8501 return target_remove_exec_catchpoint (PIDGET (inferior_ptid));
8505 breakpoint_hit_catch_exec (const struct bp_location *bl,
8506 struct address_space *aspace, CORE_ADDR bp_addr,
8507 const struct target_waitstatus *ws)
8509 struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner;
8511 if (ws->kind != TARGET_WAITKIND_EXECD)
8514 c->exec_pathname = xstrdup (ws->value.execd_pathname);
8518 static enum print_stop_action
8519 print_it_catch_exec (bpstat bs)
8521 struct ui_out *uiout = current_uiout;
8522 struct breakpoint *b = bs->breakpoint_at;
8523 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8525 annotate_catchpoint (b->number);
8526 if (b->disposition == disp_del)
8527 ui_out_text (uiout, "\nTemporary catchpoint ");
8529 ui_out_text (uiout, "\nCatchpoint ");
8530 if (ui_out_is_mi_like_p (uiout))
8532 ui_out_field_string (uiout, "reason",
8533 async_reason_lookup (EXEC_ASYNC_EXEC));
8534 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8536 ui_out_field_int (uiout, "bkptno", b->number);
8537 ui_out_text (uiout, " (exec'd ");
8538 ui_out_field_string (uiout, "new-exec", c->exec_pathname);
8539 ui_out_text (uiout, "), ");
8541 return PRINT_SRC_AND_LOC;
8545 print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc)
8547 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8548 struct value_print_options opts;
8549 struct ui_out *uiout = current_uiout;
8551 get_user_print_options (&opts);
8553 /* Field 4, the address, is omitted (which makes the columns
8554 not line up too nicely with the headers, but the effect
8555 is relatively readable). */
8556 if (opts.addressprint)
8557 ui_out_field_skip (uiout, "addr");
8559 ui_out_text (uiout, "exec");
8560 if (c->exec_pathname != NULL)
8562 ui_out_text (uiout, ", program \"");
8563 ui_out_field_string (uiout, "what", c->exec_pathname);
8564 ui_out_text (uiout, "\" ");
8567 if (ui_out_is_mi_like_p (uiout))
8568 ui_out_field_string (uiout, "catch-type", "exec");
8572 print_mention_catch_exec (struct breakpoint *b)
8574 printf_filtered (_("Catchpoint %d (exec)"), b->number);
8577 /* Implement the "print_recreate" breakpoint_ops method for exec
8581 print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp)
8583 fprintf_unfiltered (fp, "catch exec");
8584 print_recreate_thread (b, fp);
8587 static struct breakpoint_ops catch_exec_breakpoint_ops;
8590 create_syscall_event_catchpoint (int tempflag, VEC(int) *filter,
8591 const struct breakpoint_ops *ops)
8593 struct syscall_catchpoint *c;
8594 struct gdbarch *gdbarch = get_current_arch ();
8596 c = XNEW (struct syscall_catchpoint);
8597 init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops);
8598 c->syscalls_to_be_caught = filter;
8600 install_breakpoint (0, &c->base, 1);
8604 hw_breakpoint_used_count (void)
8607 struct breakpoint *b;
8608 struct bp_location *bl;
8612 if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b))
8613 for (bl = b->loc; bl; bl = bl->next)
8615 /* Special types of hardware breakpoints may use more than
8617 i += b->ops->resources_needed (bl);
8624 /* Returns the resources B would use if it were a hardware
8628 hw_watchpoint_use_count (struct breakpoint *b)
8631 struct bp_location *bl;
8633 if (!breakpoint_enabled (b))
8636 for (bl = b->loc; bl; bl = bl->next)
8638 /* Special types of hardware watchpoints may use more than
8640 i += b->ops->resources_needed (bl);
8646 /* Returns the sum the used resources of all hardware watchpoints of
8647 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8648 the sum of the used resources of all hardware watchpoints of other
8649 types _not_ TYPE. */
8652 hw_watchpoint_used_count_others (struct breakpoint *except,
8653 enum bptype type, int *other_type_used)
8656 struct breakpoint *b;
8658 *other_type_used = 0;
8663 if (!breakpoint_enabled (b))
8666 if (b->type == type)
8667 i += hw_watchpoint_use_count (b);
8668 else if (is_hardware_watchpoint (b))
8669 *other_type_used = 1;
8676 disable_watchpoints_before_interactive_call_start (void)
8678 struct breakpoint *b;
8682 if (is_watchpoint (b) && breakpoint_enabled (b))
8684 b->enable_state = bp_call_disabled;
8685 update_global_location_list (0);
8691 enable_watchpoints_after_interactive_call_stop (void)
8693 struct breakpoint *b;
8697 if (is_watchpoint (b) && b->enable_state == bp_call_disabled)
8699 b->enable_state = bp_enabled;
8700 update_global_location_list (1);
8706 disable_breakpoints_before_startup (void)
8708 current_program_space->executing_startup = 1;
8709 update_global_location_list (0);
8713 enable_breakpoints_after_startup (void)
8715 current_program_space->executing_startup = 0;
8716 breakpoint_re_set ();
8720 /* Set a breakpoint that will evaporate an end of command
8721 at address specified by SAL.
8722 Restrict it to frame FRAME if FRAME is nonzero. */
8725 set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal,
8726 struct frame_id frame_id, enum bptype type)
8728 struct breakpoint *b;
8730 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8732 gdb_assert (!frame_id_artificial_p (frame_id));
8734 b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops);
8735 b->enable_state = bp_enabled;
8736 b->disposition = disp_donttouch;
8737 b->frame_id = frame_id;
8739 /* If we're debugging a multi-threaded program, then we want
8740 momentary breakpoints to be active in only a single thread of
8742 if (in_thread_list (inferior_ptid))
8743 b->thread = pid_to_thread_id (inferior_ptid);
8745 update_global_location_list_nothrow (1);
8750 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8751 The new breakpoint will have type TYPE, and use OPS as it
8754 static struct breakpoint *
8755 momentary_breakpoint_from_master (struct breakpoint *orig,
8757 const struct breakpoint_ops *ops)
8759 struct breakpoint *copy;
8761 copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops);
8762 copy->loc = allocate_bp_location (copy);
8763 set_breakpoint_location_function (copy->loc, 1);
8765 copy->loc->gdbarch = orig->loc->gdbarch;
8766 copy->loc->requested_address = orig->loc->requested_address;
8767 copy->loc->address = orig->loc->address;
8768 copy->loc->section = orig->loc->section;
8769 copy->loc->pspace = orig->loc->pspace;
8770 copy->loc->probe = orig->loc->probe;
8771 copy->loc->line_number = orig->loc->line_number;
8772 copy->loc->symtab = orig->loc->symtab;
8773 copy->frame_id = orig->frame_id;
8774 copy->thread = orig->thread;
8775 copy->pspace = orig->pspace;
8777 copy->enable_state = bp_enabled;
8778 copy->disposition = disp_donttouch;
8779 copy->number = internal_breakpoint_number--;
8781 update_global_location_list_nothrow (0);
8785 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8789 clone_momentary_breakpoint (struct breakpoint *orig)
8791 /* If there's nothing to clone, then return nothing. */
8795 return momentary_breakpoint_from_master (orig, orig->type, orig->ops);
8799 set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc,
8802 struct symtab_and_line sal;
8804 sal = find_pc_line (pc, 0);
8806 sal.section = find_pc_overlay (pc);
8807 sal.explicit_pc = 1;
8809 return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type);
8813 /* Tell the user we have just set a breakpoint B. */
8816 mention (struct breakpoint *b)
8818 b->ops->print_mention (b);
8819 if (ui_out_is_mi_like_p (current_uiout))
8821 printf_filtered ("\n");
8825 static struct bp_location *
8826 add_location_to_breakpoint (struct breakpoint *b,
8827 const struct symtab_and_line *sal)
8829 struct bp_location *loc, **tmp;
8830 CORE_ADDR adjusted_address;
8831 struct gdbarch *loc_gdbarch = get_sal_arch (*sal);
8833 if (loc_gdbarch == NULL)
8834 loc_gdbarch = b->gdbarch;
8836 /* Adjust the breakpoint's address prior to allocating a location.
8837 Once we call allocate_bp_location(), that mostly uninitialized
8838 location will be placed on the location chain. Adjustment of the
8839 breakpoint may cause target_read_memory() to be called and we do
8840 not want its scan of the location chain to find a breakpoint and
8841 location that's only been partially initialized. */
8842 adjusted_address = adjust_breakpoint_address (loc_gdbarch,
8845 /* Sort the locations by their ADDRESS. */
8846 loc = allocate_bp_location (b);
8847 for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address;
8848 tmp = &((*tmp)->next))
8853 loc->requested_address = sal->pc;
8854 loc->address = adjusted_address;
8855 loc->pspace = sal->pspace;
8856 loc->probe = sal->probe;
8857 gdb_assert (loc->pspace != NULL);
8858 loc->section = sal->section;
8859 loc->gdbarch = loc_gdbarch;
8860 loc->line_number = sal->line;
8861 loc->symtab = sal->symtab;
8863 set_breakpoint_location_function (loc,
8864 sal->explicit_pc || sal->explicit_line);
8869 /* Return 1 if LOC is pointing to a permanent breakpoint,
8870 return 0 otherwise. */
8873 bp_loc_is_permanent (struct bp_location *loc)
8877 const gdb_byte *bpoint;
8878 gdb_byte *target_mem;
8879 struct cleanup *cleanup;
8882 gdb_assert (loc != NULL);
8884 addr = loc->address;
8885 bpoint = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len);
8887 /* Software breakpoints unsupported? */
8891 target_mem = alloca (len);
8893 /* Enable the automatic memory restoration from breakpoints while
8894 we read the memory. Otherwise we could say about our temporary
8895 breakpoints they are permanent. */
8896 cleanup = save_current_space_and_thread ();
8898 switch_to_program_space_and_thread (loc->pspace);
8899 make_show_memory_breakpoints_cleanup (0);
8901 if (target_read_memory (loc->address, target_mem, len) == 0
8902 && memcmp (target_mem, bpoint, len) == 0)
8905 do_cleanups (cleanup);
8910 /* Build a command list for the dprintf corresponding to the current
8911 settings of the dprintf style options. */
8914 update_dprintf_command_list (struct breakpoint *b)
8916 char *dprintf_args = b->extra_string;
8917 char *printf_line = NULL;
8922 dprintf_args = skip_spaces (dprintf_args);
8924 /* Allow a comma, as it may have terminated a location, but don't
8926 if (*dprintf_args == ',')
8928 dprintf_args = skip_spaces (dprintf_args);
8930 if (*dprintf_args != '"')
8931 error (_("Bad format string, missing '\"'."));
8933 if (strcmp (dprintf_style, dprintf_style_gdb) == 0)
8934 printf_line = xstrprintf ("printf %s", dprintf_args);
8935 else if (strcmp (dprintf_style, dprintf_style_call) == 0)
8937 if (!dprintf_function)
8938 error (_("No function supplied for dprintf call"));
8940 if (dprintf_channel && strlen (dprintf_channel) > 0)
8941 printf_line = xstrprintf ("call (void) %s (%s,%s)",
8946 printf_line = xstrprintf ("call (void) %s (%s)",
8950 else if (strcmp (dprintf_style, dprintf_style_agent) == 0)
8952 if (target_can_run_breakpoint_commands ())
8953 printf_line = xstrprintf ("agent-printf %s", dprintf_args);
8956 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
8957 printf_line = xstrprintf ("printf %s", dprintf_args);
8961 internal_error (__FILE__, __LINE__,
8962 _("Invalid dprintf style."));
8964 gdb_assert (printf_line != NULL);
8965 /* Manufacture a printf/continue sequence. */
8967 struct command_line *printf_cmd_line, *cont_cmd_line = NULL;
8969 if (strcmp (dprintf_style, dprintf_style_agent) != 0)
8971 cont_cmd_line = xmalloc (sizeof (struct command_line));
8972 cont_cmd_line->control_type = simple_control;
8973 cont_cmd_line->body_count = 0;
8974 cont_cmd_line->body_list = NULL;
8975 cont_cmd_line->next = NULL;
8976 cont_cmd_line->line = xstrdup ("continue");
8979 printf_cmd_line = xmalloc (sizeof (struct command_line));
8980 printf_cmd_line->control_type = simple_control;
8981 printf_cmd_line->body_count = 0;
8982 printf_cmd_line->body_list = NULL;
8983 printf_cmd_line->next = cont_cmd_line;
8984 printf_cmd_line->line = printf_line;
8986 breakpoint_set_commands (b, printf_cmd_line);
8990 /* Update all dprintf commands, making their command lists reflect
8991 current style settings. */
8994 update_dprintf_commands (char *args, int from_tty,
8995 struct cmd_list_element *c)
8997 struct breakpoint *b;
9001 if (b->type == bp_dprintf)
9002 update_dprintf_command_list (b);
9006 /* Create a breakpoint with SAL as location. Use ADDR_STRING
9007 as textual description of the location, and COND_STRING
9008 as condition expression. */
9011 init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch,
9012 struct symtabs_and_lines sals, char *addr_string,
9013 char *filter, char *cond_string,
9015 enum bptype type, enum bpdisp disposition,
9016 int thread, int task, int ignore_count,
9017 const struct breakpoint_ops *ops, int from_tty,
9018 int enabled, int internal, unsigned flags,
9019 int display_canonical)
9023 if (type == bp_hardware_breakpoint)
9025 int target_resources_ok;
9027 i = hw_breakpoint_used_count ();
9028 target_resources_ok =
9029 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
9031 if (target_resources_ok == 0)
9032 error (_("No hardware breakpoint support in the target."));
9033 else if (target_resources_ok < 0)
9034 error (_("Hardware breakpoints used exceeds limit."));
9037 gdb_assert (sals.nelts > 0);
9039 for (i = 0; i < sals.nelts; ++i)
9041 struct symtab_and_line sal = sals.sals[i];
9042 struct bp_location *loc;
9046 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
9048 loc_gdbarch = gdbarch;
9050 describe_other_breakpoints (loc_gdbarch,
9051 sal.pspace, sal.pc, sal.section, thread);
9056 init_raw_breakpoint (b, gdbarch, sal, type, ops);
9060 b->cond_string = cond_string;
9061 b->extra_string = extra_string;
9062 b->ignore_count = ignore_count;
9063 b->enable_state = enabled ? bp_enabled : bp_disabled;
9064 b->disposition = disposition;
9066 if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
9067 b->loc->inserted = 1;
9069 if (type == bp_static_tracepoint)
9071 struct tracepoint *t = (struct tracepoint *) b;
9072 struct static_tracepoint_marker marker;
9074 if (strace_marker_p (b))
9076 /* We already know the marker exists, otherwise, we
9077 wouldn't see a sal for it. */
9078 char *p = &addr_string[3];
9082 p = skip_spaces (p);
9084 endp = skip_to_space (p);
9086 marker_str = savestring (p, endp - p);
9087 t->static_trace_marker_id = marker_str;
9089 printf_filtered (_("Probed static tracepoint "
9091 t->static_trace_marker_id);
9093 else if (target_static_tracepoint_marker_at (sal.pc, &marker))
9095 t->static_trace_marker_id = xstrdup (marker.str_id);
9096 release_static_tracepoint_marker (&marker);
9098 printf_filtered (_("Probed static tracepoint "
9100 t->static_trace_marker_id);
9103 warning (_("Couldn't determine the static "
9104 "tracepoint marker to probe"));
9111 loc = add_location_to_breakpoint (b, &sal);
9112 if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
9116 if (bp_loc_is_permanent (loc))
9117 make_breakpoint_permanent (b);
9121 const char *arg = b->cond_string;
9123 loc->cond = parse_exp_1 (&arg, loc->address,
9124 block_for_pc (loc->address), 0);
9126 error (_("Garbage '%s' follows condition"), arg);
9129 /* Dynamic printf requires and uses additional arguments on the
9130 command line, otherwise it's an error. */
9131 if (type == bp_dprintf)
9133 if (b->extra_string)
9134 update_dprintf_command_list (b);
9136 error (_("Format string required"));
9138 else if (b->extra_string)
9139 error (_("Garbage '%s' at end of command"), b->extra_string);
9142 b->display_canonical = display_canonical;
9144 b->addr_string = addr_string;
9146 /* addr_string has to be used or breakpoint_re_set will delete
9149 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
9154 create_breakpoint_sal (struct gdbarch *gdbarch,
9155 struct symtabs_and_lines sals, char *addr_string,
9156 char *filter, char *cond_string,
9158 enum bptype type, enum bpdisp disposition,
9159 int thread, int task, int ignore_count,
9160 const struct breakpoint_ops *ops, int from_tty,
9161 int enabled, int internal, unsigned flags,
9162 int display_canonical)
9164 struct breakpoint *b;
9165 struct cleanup *old_chain;
9167 if (is_tracepoint_type (type))
9169 struct tracepoint *t;
9171 t = XCNEW (struct tracepoint);
9175 b = XNEW (struct breakpoint);
9177 old_chain = make_cleanup (xfree, b);
9179 init_breakpoint_sal (b, gdbarch,
9181 filter, cond_string, extra_string,
9183 thread, task, ignore_count,
9185 enabled, internal, flags,
9187 discard_cleanups (old_chain);
9189 install_breakpoint (internal, b, 0);
9192 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9193 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9194 value. COND_STRING, if not NULL, specified the condition to be
9195 used for all breakpoints. Essentially the only case where
9196 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9197 function. In that case, it's still not possible to specify
9198 separate conditions for different overloaded functions, so
9199 we take just a single condition string.
9201 NOTE: If the function succeeds, the caller is expected to cleanup
9202 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9203 array contents). If the function fails (error() is called), the
9204 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9205 COND and SALS arrays and each of those arrays contents. */
9208 create_breakpoints_sal (struct gdbarch *gdbarch,
9209 struct linespec_result *canonical,
9210 char *cond_string, char *extra_string,
9211 enum bptype type, enum bpdisp disposition,
9212 int thread, int task, int ignore_count,
9213 const struct breakpoint_ops *ops, int from_tty,
9214 int enabled, int internal, unsigned flags)
9217 struct linespec_sals *lsal;
9219 if (canonical->pre_expanded)
9220 gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1);
9222 for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i)
9224 /* Note that 'addr_string' can be NULL in the case of a plain
9225 'break', without arguments. */
9226 char *addr_string = (canonical->addr_string
9227 ? xstrdup (canonical->addr_string)
9229 char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL;
9230 struct cleanup *inner = make_cleanup (xfree, addr_string);
9232 make_cleanup (xfree, filter_string);
9233 create_breakpoint_sal (gdbarch, lsal->sals,
9236 cond_string, extra_string,
9238 thread, task, ignore_count, ops,
9239 from_tty, enabled, internal, flags,
9240 canonical->special_display);
9241 discard_cleanups (inner);
9245 /* Parse ADDRESS which is assumed to be a SAL specification possibly
9246 followed by conditionals. On return, SALS contains an array of SAL
9247 addresses found. ADDR_STRING contains a vector of (canonical)
9248 address strings. ADDRESS points to the end of the SAL.
9250 The array and the line spec strings are allocated on the heap, it is
9251 the caller's responsibility to free them. */
9254 parse_breakpoint_sals (char **address,
9255 struct linespec_result *canonical)
9257 /* If no arg given, or if first arg is 'if ', use the default
9259 if ((*address) == NULL
9260 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
9262 /* The last displayed codepoint, if it's valid, is our default breakpoint
9264 if (last_displayed_sal_is_valid ())
9266 struct linespec_sals lsal;
9267 struct symtab_and_line sal;
9270 init_sal (&sal); /* Initialize to zeroes. */
9271 lsal.sals.sals = (struct symtab_and_line *)
9272 xmalloc (sizeof (struct symtab_and_line));
9274 /* Set sal's pspace, pc, symtab, and line to the values
9275 corresponding to the last call to print_frame_info.
9276 Be sure to reinitialize LINE with NOTCURRENT == 0
9277 as the breakpoint line number is inappropriate otherwise.
9278 find_pc_line would adjust PC, re-set it back. */
9279 get_last_displayed_sal (&sal);
9281 sal = find_pc_line (pc, 0);
9283 /* "break" without arguments is equivalent to "break *PC"
9284 where PC is the last displayed codepoint's address. So
9285 make sure to set sal.explicit_pc to prevent GDB from
9286 trying to expand the list of sals to include all other
9287 instances with the same symtab and line. */
9289 sal.explicit_pc = 1;
9291 lsal.sals.sals[0] = sal;
9292 lsal.sals.nelts = 1;
9293 lsal.canonical = NULL;
9295 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
9298 error (_("No default breakpoint address now."));
9302 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
9304 /* Force almost all breakpoints to be in terms of the
9305 current_source_symtab (which is decode_line_1's default).
9306 This should produce the results we want almost all of the
9307 time while leaving default_breakpoint_* alone.
9309 ObjC: However, don't match an Objective-C method name which
9310 may have a '+' or '-' succeeded by a '['. */
9311 if (last_displayed_sal_is_valid ()
9313 || ((strchr ("+-", (*address)[0]) != NULL)
9314 && ((*address)[1] != '['))))
9315 decode_line_full (address, DECODE_LINE_FUNFIRSTLINE,
9316 get_last_displayed_symtab (),
9317 get_last_displayed_line (),
9318 canonical, NULL, NULL);
9320 decode_line_full (address, DECODE_LINE_FUNFIRSTLINE,
9321 cursal.symtab, cursal.line, canonical, NULL, NULL);
9326 /* Convert each SAL into a real PC. Verify that the PC can be
9327 inserted as a breakpoint. If it can't throw an error. */
9330 breakpoint_sals_to_pc (struct symtabs_and_lines *sals)
9334 for (i = 0; i < sals->nelts; i++)
9335 resolve_sal_pc (&sals->sals[i]);
9338 /* Fast tracepoints may have restrictions on valid locations. For
9339 instance, a fast tracepoint using a jump instead of a trap will
9340 likely have to overwrite more bytes than a trap would, and so can
9341 only be placed where the instruction is longer than the jump, or a
9342 multi-instruction sequence does not have a jump into the middle of
9346 check_fast_tracepoint_sals (struct gdbarch *gdbarch,
9347 struct symtabs_and_lines *sals)
9350 struct symtab_and_line *sal;
9352 struct cleanup *old_chain;
9354 for (i = 0; i < sals->nelts; i++)
9356 struct gdbarch *sarch;
9358 sal = &sals->sals[i];
9360 sarch = get_sal_arch (*sal);
9361 /* We fall back to GDBARCH if there is no architecture
9362 associated with SAL. */
9365 rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc,
9367 old_chain = make_cleanup (xfree, msg);
9370 error (_("May not have a fast tracepoint at 0x%s%s"),
9371 paddress (sarch, sal->pc), (msg ? msg : ""));
9373 do_cleanups (old_chain);
9377 /* Issue an invalid thread ID error. */
9379 static void ATTRIBUTE_NORETURN
9380 invalid_thread_id_error (int id)
9382 error (_("Unknown thread %d."), id);
9385 /* Given TOK, a string specification of condition and thread, as
9386 accepted by the 'break' command, extract the condition
9387 string and thread number and set *COND_STRING and *THREAD.
9388 PC identifies the context at which the condition should be parsed.
9389 If no condition is found, *COND_STRING is set to NULL.
9390 If no thread is found, *THREAD is set to -1. */
9393 find_condition_and_thread (const char *tok, CORE_ADDR pc,
9394 char **cond_string, int *thread, int *task,
9397 *cond_string = NULL;
9404 const char *end_tok;
9406 const char *cond_start = NULL;
9407 const char *cond_end = NULL;
9409 tok = skip_spaces_const (tok);
9411 if ((*tok == '"' || *tok == ',') && rest)
9413 *rest = savestring (tok, strlen (tok));
9417 end_tok = skip_to_space_const (tok);
9419 toklen = end_tok - tok;
9421 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
9423 struct expression *expr;
9425 tok = cond_start = end_tok + 1;
9426 expr = parse_exp_1 (&tok, pc, block_for_pc (pc), 0);
9429 *cond_string = savestring (cond_start, cond_end - cond_start);
9431 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
9436 *thread = strtol (tok, &tmptok, 0);
9438 error (_("Junk after thread keyword."));
9439 if (!valid_thread_id (*thread))
9440 invalid_thread_id_error (*thread);
9443 else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0)
9448 *task = strtol (tok, &tmptok, 0);
9450 error (_("Junk after task keyword."));
9451 if (!valid_task_id (*task))
9452 error (_("Unknown task %d."), *task);
9457 *rest = savestring (tok, strlen (tok));
9461 error (_("Junk at end of arguments."));
9465 /* Decode a static tracepoint marker spec. */
9467 static struct symtabs_and_lines
9468 decode_static_tracepoint_spec (char **arg_p)
9470 VEC(static_tracepoint_marker_p) *markers = NULL;
9471 struct symtabs_and_lines sals;
9472 struct cleanup *old_chain;
9473 char *p = &(*arg_p)[3];
9478 p = skip_spaces (p);
9480 endp = skip_to_space (p);
9482 marker_str = savestring (p, endp - p);
9483 old_chain = make_cleanup (xfree, marker_str);
9485 markers = target_static_tracepoint_markers_by_strid (marker_str);
9486 if (VEC_empty(static_tracepoint_marker_p, markers))
9487 error (_("No known static tracepoint marker named %s"), marker_str);
9489 sals.nelts = VEC_length(static_tracepoint_marker_p, markers);
9490 sals.sals = xmalloc (sizeof *sals.sals * sals.nelts);
9492 for (i = 0; i < sals.nelts; i++)
9494 struct static_tracepoint_marker *marker;
9496 marker = VEC_index (static_tracepoint_marker_p, markers, i);
9498 init_sal (&sals.sals[i]);
9500 sals.sals[i] = find_pc_line (marker->address, 0);
9501 sals.sals[i].pc = marker->address;
9503 release_static_tracepoint_marker (marker);
9506 do_cleanups (old_chain);
9512 /* Set a breakpoint. This function is shared between CLI and MI
9513 functions for setting a breakpoint. This function has two major
9514 modes of operations, selected by the PARSE_ARG parameter. If
9515 non-zero, the function will parse ARG, extracting location,
9516 condition, thread and extra string. Otherwise, ARG is just the
9517 breakpoint's location, with condition, thread, and extra string
9518 specified by the COND_STRING, THREAD and EXTRA_STRING parameters.
9519 If INTERNAL is non-zero, the breakpoint number will be allocated
9520 from the internal breakpoint count. Returns true if any breakpoint
9521 was created; false otherwise. */
9524 create_breakpoint (struct gdbarch *gdbarch,
9525 char *arg, char *cond_string,
9526 int thread, char *extra_string,
9528 int tempflag, enum bptype type_wanted,
9530 enum auto_boolean pending_break_support,
9531 const struct breakpoint_ops *ops,
9532 int from_tty, int enabled, int internal,
9535 volatile struct gdb_exception e;
9536 char *copy_arg = NULL;
9537 char *addr_start = arg;
9538 struct linespec_result canonical;
9539 struct cleanup *old_chain;
9540 struct cleanup *bkpt_chain = NULL;
9543 int prev_bkpt_count = breakpoint_count;
9545 gdb_assert (ops != NULL);
9547 init_linespec_result (&canonical);
9549 TRY_CATCH (e, RETURN_MASK_ALL)
9551 ops->create_sals_from_address (&arg, &canonical, type_wanted,
9552 addr_start, ©_arg);
9555 /* If caller is interested in rc value from parse, set value. */
9559 if (VEC_empty (linespec_sals, canonical.sals))
9565 case NOT_FOUND_ERROR:
9567 /* If pending breakpoint support is turned off, throw
9570 if (pending_break_support == AUTO_BOOLEAN_FALSE)
9571 throw_exception (e);
9573 exception_print (gdb_stderr, e);
9575 /* If pending breakpoint support is auto query and the user
9576 selects no, then simply return the error code. */
9577 if (pending_break_support == AUTO_BOOLEAN_AUTO
9578 && !nquery (_("Make %s pending on future shared library load? "),
9579 bptype_string (type_wanted)))
9582 /* At this point, either the user was queried about setting
9583 a pending breakpoint and selected yes, or pending
9584 breakpoint behavior is on and thus a pending breakpoint
9585 is defaulted on behalf of the user. */
9587 struct linespec_sals lsal;
9589 copy_arg = xstrdup (addr_start);
9590 lsal.canonical = xstrdup (copy_arg);
9591 lsal.sals.nelts = 1;
9592 lsal.sals.sals = XNEW (struct symtab_and_line);
9593 init_sal (&lsal.sals.sals[0]);
9595 VEC_safe_push (linespec_sals, canonical.sals, &lsal);
9599 throw_exception (e);
9603 throw_exception (e);
9606 /* Create a chain of things that always need to be cleaned up. */
9607 old_chain = make_cleanup_destroy_linespec_result (&canonical);
9609 /* ----------------------------- SNIP -----------------------------
9610 Anything added to the cleanup chain beyond this point is assumed
9611 to be part of a breakpoint. If the breakpoint create succeeds
9612 then the memory is not reclaimed. */
9613 bkpt_chain = make_cleanup (null_cleanup, 0);
9615 /* Resolve all line numbers to PC's and verify that the addresses
9616 are ok for the target. */
9620 struct linespec_sals *iter;
9622 for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
9623 breakpoint_sals_to_pc (&iter->sals);
9626 /* Fast tracepoints may have additional restrictions on location. */
9627 if (!pending && type_wanted == bp_fast_tracepoint)
9630 struct linespec_sals *iter;
9632 for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
9633 check_fast_tracepoint_sals (gdbarch, &iter->sals);
9636 /* Verify that condition can be parsed, before setting any
9637 breakpoints. Allocate a separate condition expression for each
9641 struct linespec_sals *lsal;
9643 lsal = VEC_index (linespec_sals, canonical.sals, 0);
9648 /* Here we only parse 'arg' to separate condition
9649 from thread number, so parsing in context of first
9650 sal is OK. When setting the breakpoint we'll
9651 re-parse it in context of each sal. */
9653 find_condition_and_thread (arg, lsal->sals.sals[0].pc, &cond_string,
9654 &thread, &task, &rest);
9656 make_cleanup (xfree, cond_string);
9658 make_cleanup (xfree, rest);
9660 extra_string = rest;
9665 error (_("Garbage '%s' at end of location"), arg);
9667 /* Create a private copy of condition string. */
9670 cond_string = xstrdup (cond_string);
9671 make_cleanup (xfree, cond_string);
9673 /* Create a private copy of any extra string. */
9676 extra_string = xstrdup (extra_string);
9677 make_cleanup (xfree, extra_string);
9681 ops->create_breakpoints_sal (gdbarch, &canonical, lsal,
9682 cond_string, extra_string, type_wanted,
9683 tempflag ? disp_del : disp_donttouch,
9684 thread, task, ignore_count, ops,
9685 from_tty, enabled, internal, flags);
9689 struct breakpoint *b;
9691 make_cleanup (xfree, copy_arg);
9693 if (is_tracepoint_type (type_wanted))
9695 struct tracepoint *t;
9697 t = XCNEW (struct tracepoint);
9701 b = XNEW (struct breakpoint);
9703 init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops);
9705 b->addr_string = copy_arg;
9707 b->cond_string = NULL;
9710 /* Create a private copy of condition string. */
9713 cond_string = xstrdup (cond_string);
9714 make_cleanup (xfree, cond_string);
9716 b->cond_string = cond_string;
9718 b->extra_string = NULL;
9719 b->ignore_count = ignore_count;
9720 b->disposition = tempflag ? disp_del : disp_donttouch;
9721 b->condition_not_parsed = 1;
9722 b->enable_state = enabled ? bp_enabled : bp_disabled;
9723 if ((type_wanted != bp_breakpoint
9724 && type_wanted != bp_hardware_breakpoint) || thread != -1)
9725 b->pspace = current_program_space;
9727 install_breakpoint (internal, b, 0);
9730 if (VEC_length (linespec_sals, canonical.sals) > 1)
9732 warning (_("Multiple breakpoints were set.\nUse the "
9733 "\"delete\" command to delete unwanted breakpoints."));
9734 prev_breakpoint_count = prev_bkpt_count;
9737 /* That's it. Discard the cleanups for data inserted into the
9739 discard_cleanups (bkpt_chain);
9740 /* But cleanup everything else. */
9741 do_cleanups (old_chain);
9743 /* error call may happen here - have BKPT_CHAIN already discarded. */
9744 update_global_location_list (1);
9749 /* Set a breakpoint.
9750 ARG is a string describing breakpoint address,
9751 condition, and thread.
9752 FLAG specifies if a breakpoint is hardware on,
9753 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9757 break_command_1 (char *arg, int flag, int from_tty)
9759 int tempflag = flag & BP_TEMPFLAG;
9760 enum bptype type_wanted = (flag & BP_HARDWAREFLAG
9761 ? bp_hardware_breakpoint
9763 struct breakpoint_ops *ops;
9764 const char *arg_cp = arg;
9766 /* Matching breakpoints on probes. */
9767 if (arg && probe_linespec_to_ops (&arg_cp) != NULL)
9768 ops = &bkpt_probe_breakpoint_ops;
9770 ops = &bkpt_breakpoint_ops;
9772 create_breakpoint (get_current_arch (),
9774 NULL, 0, NULL, 1 /* parse arg */,
9775 tempflag, type_wanted,
9776 0 /* Ignore count */,
9777 pending_break_support,
9785 /* Helper function for break_command_1 and disassemble_command. */
9788 resolve_sal_pc (struct symtab_and_line *sal)
9792 if (sal->pc == 0 && sal->symtab != NULL)
9794 if (!find_line_pc (sal->symtab, sal->line, &pc))
9795 error (_("No line %d in file \"%s\"."),
9796 sal->line, symtab_to_filename_for_display (sal->symtab));
9799 /* If this SAL corresponds to a breakpoint inserted using a line
9800 number, then skip the function prologue if necessary. */
9801 if (sal->explicit_line)
9802 skip_prologue_sal (sal);
9805 if (sal->section == 0 && sal->symtab != NULL)
9807 struct blockvector *bv;
9811 bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab);
9814 sym = block_linkage_function (b);
9817 fixup_symbol_section (sym, sal->symtab->objfile);
9818 sal->section = SYMBOL_OBJ_SECTION (sal->symtab->objfile, sym);
9822 /* It really is worthwhile to have the section, so we'll
9823 just have to look harder. This case can be executed
9824 if we have line numbers but no functions (as can
9825 happen in assembly source). */
9827 struct bound_minimal_symbol msym;
9828 struct cleanup *old_chain = save_current_space_and_thread ();
9830 switch_to_program_space_and_thread (sal->pspace);
9832 msym = lookup_minimal_symbol_by_pc (sal->pc);
9834 sal->section = SYMBOL_OBJ_SECTION (msym.objfile, msym.minsym);
9836 do_cleanups (old_chain);
9843 break_command (char *arg, int from_tty)
9845 break_command_1 (arg, 0, from_tty);
9849 tbreak_command (char *arg, int from_tty)
9851 break_command_1 (arg, BP_TEMPFLAG, from_tty);
9855 hbreak_command (char *arg, int from_tty)
9857 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
9861 thbreak_command (char *arg, int from_tty)
9863 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
9867 stop_command (char *arg, int from_tty)
9869 printf_filtered (_("Specify the type of breakpoint to set.\n\
9870 Usage: stop in <function | address>\n\
9871 stop at <line>\n"));
9875 stopin_command (char *arg, int from_tty)
9879 if (arg == (char *) NULL)
9881 else if (*arg != '*')
9886 /* Look for a ':'. If this is a line number specification, then
9887 say it is bad, otherwise, it should be an address or
9888 function/method name. */
9889 while (*argptr && !hasColon)
9891 hasColon = (*argptr == ':');
9896 badInput = (*argptr != ':'); /* Not a class::method */
9898 badInput = isdigit (*arg); /* a simple line number */
9902 printf_filtered (_("Usage: stop in <function | address>\n"));
9904 break_command_1 (arg, 0, from_tty);
9908 stopat_command (char *arg, int from_tty)
9912 if (arg == (char *) NULL || *arg == '*') /* no line number */
9919 /* Look for a ':'. If there is a '::' then get out, otherwise
9920 it is probably a line number. */
9921 while (*argptr && !hasColon)
9923 hasColon = (*argptr == ':');
9928 badInput = (*argptr == ':'); /* we have class::method */
9930 badInput = !isdigit (*arg); /* not a line number */
9934 printf_filtered (_("Usage: stop at <line>\n"));
9936 break_command_1 (arg, 0, from_tty);
9939 /* The dynamic printf command is mostly like a regular breakpoint, but
9940 with a prewired command list consisting of a single output command,
9941 built from extra arguments supplied on the dprintf command
9945 dprintf_command (char *arg, int from_tty)
9947 create_breakpoint (get_current_arch (),
9949 NULL, 0, NULL, 1 /* parse arg */,
9951 0 /* Ignore count */,
9952 pending_break_support,
9953 &dprintf_breakpoint_ops,
9961 agent_printf_command (char *arg, int from_tty)
9963 error (_("May only run agent-printf on the target"));
9966 /* Implement the "breakpoint_hit" breakpoint_ops method for
9967 ranged breakpoints. */
9970 breakpoint_hit_ranged_breakpoint (const struct bp_location *bl,
9971 struct address_space *aspace,
9973 const struct target_waitstatus *ws)
9975 if (ws->kind != TARGET_WAITKIND_STOPPED
9976 || ws->value.sig != GDB_SIGNAL_TRAP)
9979 return breakpoint_address_match_range (bl->pspace->aspace, bl->address,
9980 bl->length, aspace, bp_addr);
9983 /* Implement the "resources_needed" breakpoint_ops method for
9984 ranged breakpoints. */
9987 resources_needed_ranged_breakpoint (const struct bp_location *bl)
9989 return target_ranged_break_num_registers ();
9992 /* Implement the "print_it" breakpoint_ops method for
9993 ranged breakpoints. */
9995 static enum print_stop_action
9996 print_it_ranged_breakpoint (bpstat bs)
9998 struct breakpoint *b = bs->breakpoint_at;
9999 struct bp_location *bl = b->loc;
10000 struct ui_out *uiout = current_uiout;
10002 gdb_assert (b->type == bp_hardware_breakpoint);
10004 /* Ranged breakpoints have only one location. */
10005 gdb_assert (bl && bl->next == NULL);
10007 annotate_breakpoint (b->number);
10008 if (b->disposition == disp_del)
10009 ui_out_text (uiout, "\nTemporary ranged breakpoint ");
10011 ui_out_text (uiout, "\nRanged breakpoint ");
10012 if (ui_out_is_mi_like_p (uiout))
10014 ui_out_field_string (uiout, "reason",
10015 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
10016 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
10018 ui_out_field_int (uiout, "bkptno", b->number);
10019 ui_out_text (uiout, ", ");
10021 return PRINT_SRC_AND_LOC;
10024 /* Implement the "print_one" breakpoint_ops method for
10025 ranged breakpoints. */
10028 print_one_ranged_breakpoint (struct breakpoint *b,
10029 struct bp_location **last_loc)
10031 struct bp_location *bl = b->loc;
10032 struct value_print_options opts;
10033 struct ui_out *uiout = current_uiout;
10035 /* Ranged breakpoints have only one location. */
10036 gdb_assert (bl && bl->next == NULL);
10038 get_user_print_options (&opts);
10040 if (opts.addressprint)
10041 /* We don't print the address range here, it will be printed later
10042 by print_one_detail_ranged_breakpoint. */
10043 ui_out_field_skip (uiout, "addr");
10044 annotate_field (5);
10045 print_breakpoint_location (b, bl);
10049 /* Implement the "print_one_detail" breakpoint_ops method for
10050 ranged breakpoints. */
10053 print_one_detail_ranged_breakpoint (const struct breakpoint *b,
10054 struct ui_out *uiout)
10056 CORE_ADDR address_start, address_end;
10057 struct bp_location *bl = b->loc;
10058 struct ui_file *stb = mem_fileopen ();
10059 struct cleanup *cleanup = make_cleanup_ui_file_delete (stb);
10063 address_start = bl->address;
10064 address_end = address_start + bl->length - 1;
10066 ui_out_text (uiout, "\taddress range: ");
10067 fprintf_unfiltered (stb, "[%s, %s]",
10068 print_core_address (bl->gdbarch, address_start),
10069 print_core_address (bl->gdbarch, address_end));
10070 ui_out_field_stream (uiout, "addr", stb);
10071 ui_out_text (uiout, "\n");
10073 do_cleanups (cleanup);
10076 /* Implement the "print_mention" breakpoint_ops method for
10077 ranged breakpoints. */
10080 print_mention_ranged_breakpoint (struct breakpoint *b)
10082 struct bp_location *bl = b->loc;
10083 struct ui_out *uiout = current_uiout;
10086 gdb_assert (b->type == bp_hardware_breakpoint);
10088 if (ui_out_is_mi_like_p (uiout))
10091 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
10092 b->number, paddress (bl->gdbarch, bl->address),
10093 paddress (bl->gdbarch, bl->address + bl->length - 1));
10096 /* Implement the "print_recreate" breakpoint_ops method for
10097 ranged breakpoints. */
10100 print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp)
10102 fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string,
10103 b->addr_string_range_end);
10104 print_recreate_thread (b, fp);
10107 /* The breakpoint_ops structure to be used in ranged breakpoints. */
10109 static struct breakpoint_ops ranged_breakpoint_ops;
10111 /* Find the address where the end of the breakpoint range should be
10112 placed, given the SAL of the end of the range. This is so that if
10113 the user provides a line number, the end of the range is set to the
10114 last instruction of the given line. */
10117 find_breakpoint_range_end (struct symtab_and_line sal)
10121 /* If the user provided a PC value, use it. Otherwise,
10122 find the address of the end of the given location. */
10123 if (sal.explicit_pc)
10130 ret = find_line_pc_range (sal, &start, &end);
10132 error (_("Could not find location of the end of the range."));
10134 /* find_line_pc_range returns the start of the next line. */
10141 /* Implement the "break-range" CLI command. */
10144 break_range_command (char *arg, int from_tty)
10146 char *arg_start, *addr_string_start, *addr_string_end;
10147 struct linespec_result canonical_start, canonical_end;
10148 int bp_count, can_use_bp, length;
10150 struct breakpoint *b;
10151 struct symtab_and_line sal_start, sal_end;
10152 struct cleanup *cleanup_bkpt;
10153 struct linespec_sals *lsal_start, *lsal_end;
10155 /* We don't support software ranged breakpoints. */
10156 if (target_ranged_break_num_registers () < 0)
10157 error (_("This target does not support hardware ranged breakpoints."));
10159 bp_count = hw_breakpoint_used_count ();
10160 bp_count += target_ranged_break_num_registers ();
10161 can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
10163 if (can_use_bp < 0)
10164 error (_("Hardware breakpoints used exceeds limit."));
10166 arg = skip_spaces (arg);
10167 if (arg == NULL || arg[0] == '\0')
10168 error(_("No address range specified."));
10170 init_linespec_result (&canonical_start);
10173 parse_breakpoint_sals (&arg, &canonical_start);
10175 cleanup_bkpt = make_cleanup_destroy_linespec_result (&canonical_start);
10178 error (_("Too few arguments."));
10179 else if (VEC_empty (linespec_sals, canonical_start.sals))
10180 error (_("Could not find location of the beginning of the range."));
10182 lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0);
10184 if (VEC_length (linespec_sals, canonical_start.sals) > 1
10185 || lsal_start->sals.nelts != 1)
10186 error (_("Cannot create a ranged breakpoint with multiple locations."));
10188 sal_start = lsal_start->sals.sals[0];
10189 addr_string_start = savestring (arg_start, arg - arg_start);
10190 make_cleanup (xfree, addr_string_start);
10192 arg++; /* Skip the comma. */
10193 arg = skip_spaces (arg);
10195 /* Parse the end location. */
10197 init_linespec_result (&canonical_end);
10200 /* We call decode_line_full directly here instead of using
10201 parse_breakpoint_sals because we need to specify the start location's
10202 symtab and line as the default symtab and line for the end of the
10203 range. This makes it possible to have ranges like "foo.c:27, +14",
10204 where +14 means 14 lines from the start location. */
10205 decode_line_full (&arg, DECODE_LINE_FUNFIRSTLINE,
10206 sal_start.symtab, sal_start.line,
10207 &canonical_end, NULL, NULL);
10209 make_cleanup_destroy_linespec_result (&canonical_end);
10211 if (VEC_empty (linespec_sals, canonical_end.sals))
10212 error (_("Could not find location of the end of the range."));
10214 lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0);
10215 if (VEC_length (linespec_sals, canonical_end.sals) > 1
10216 || lsal_end->sals.nelts != 1)
10217 error (_("Cannot create a ranged breakpoint with multiple locations."));
10219 sal_end = lsal_end->sals.sals[0];
10220 addr_string_end = savestring (arg_start, arg - arg_start);
10221 make_cleanup (xfree, addr_string_end);
10223 end = find_breakpoint_range_end (sal_end);
10224 if (sal_start.pc > end)
10225 error (_("Invalid address range, end precedes start."));
10227 length = end - sal_start.pc + 1;
10229 /* Length overflowed. */
10230 error (_("Address range too large."));
10231 else if (length == 1)
10233 /* This range is simple enough to be handled by
10234 the `hbreak' command. */
10235 hbreak_command (addr_string_start, 1);
10237 do_cleanups (cleanup_bkpt);
10242 /* Now set up the breakpoint. */
10243 b = set_raw_breakpoint (get_current_arch (), sal_start,
10244 bp_hardware_breakpoint, &ranged_breakpoint_ops);
10245 set_breakpoint_count (breakpoint_count + 1);
10246 b->number = breakpoint_count;
10247 b->disposition = disp_donttouch;
10248 b->addr_string = xstrdup (addr_string_start);
10249 b->addr_string_range_end = xstrdup (addr_string_end);
10250 b->loc->length = length;
10252 do_cleanups (cleanup_bkpt);
10255 observer_notify_breakpoint_created (b);
10256 update_global_location_list (1);
10259 /* Return non-zero if EXP is verified as constant. Returned zero
10260 means EXP is variable. Also the constant detection may fail for
10261 some constant expressions and in such case still falsely return
10265 watchpoint_exp_is_const (const struct expression *exp)
10267 int i = exp->nelts;
10273 /* We are only interested in the descriptor of each element. */
10274 operator_length (exp, i, &oplenp, &argsp);
10277 switch (exp->elts[i].opcode)
10287 case BINOP_LOGICAL_AND:
10288 case BINOP_LOGICAL_OR:
10289 case BINOP_BITWISE_AND:
10290 case BINOP_BITWISE_IOR:
10291 case BINOP_BITWISE_XOR:
10293 case BINOP_NOTEQUAL:
10322 case OP_OBJC_NSSTRING:
10325 case UNOP_LOGICAL_NOT:
10326 case UNOP_COMPLEMENT:
10331 case UNOP_CAST_TYPE:
10332 case UNOP_REINTERPRET_CAST:
10333 case UNOP_DYNAMIC_CAST:
10334 /* Unary, binary and ternary operators: We have to check
10335 their operands. If they are constant, then so is the
10336 result of that operation. For instance, if A and B are
10337 determined to be constants, then so is "A + B".
10339 UNOP_IND is one exception to the rule above, because the
10340 value of *ADDR is not necessarily a constant, even when
10345 /* Check whether the associated symbol is a constant.
10347 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10348 possible that a buggy compiler could mark a variable as
10349 constant even when it is not, and TYPE_CONST would return
10350 true in this case, while SYMBOL_CLASS wouldn't.
10352 We also have to check for function symbols because they
10353 are always constant. */
10355 struct symbol *s = exp->elts[i + 2].symbol;
10357 if (SYMBOL_CLASS (s) != LOC_BLOCK
10358 && SYMBOL_CLASS (s) != LOC_CONST
10359 && SYMBOL_CLASS (s) != LOC_CONST_BYTES)
10364 /* The default action is to return 0 because we are using
10365 the optimistic approach here: If we don't know something,
10366 then it is not a constant. */
10375 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
10378 dtor_watchpoint (struct breakpoint *self)
10380 struct watchpoint *w = (struct watchpoint *) self;
10382 xfree (w->cond_exp);
10384 xfree (w->exp_string);
10385 xfree (w->exp_string_reparse);
10386 value_free (w->val);
10388 base_breakpoint_ops.dtor (self);
10391 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10394 re_set_watchpoint (struct breakpoint *b)
10396 struct watchpoint *w = (struct watchpoint *) b;
10398 /* Watchpoint can be either on expression using entirely global
10399 variables, or it can be on local variables.
10401 Watchpoints of the first kind are never auto-deleted, and even
10402 persist across program restarts. Since they can use variables
10403 from shared libraries, we need to reparse expression as libraries
10404 are loaded and unloaded.
10406 Watchpoints on local variables can also change meaning as result
10407 of solib event. For example, if a watchpoint uses both a local
10408 and a global variables in expression, it's a local watchpoint,
10409 but unloading of a shared library will make the expression
10410 invalid. This is not a very common use case, but we still
10411 re-evaluate expression, to avoid surprises to the user.
10413 Note that for local watchpoints, we re-evaluate it only if
10414 watchpoints frame id is still valid. If it's not, it means the
10415 watchpoint is out of scope and will be deleted soon. In fact,
10416 I'm not sure we'll ever be called in this case.
10418 If a local watchpoint's frame id is still valid, then
10419 w->exp_valid_block is likewise valid, and we can safely use it.
10421 Don't do anything about disabled watchpoints, since they will be
10422 reevaluated again when enabled. */
10423 update_watchpoint (w, 1 /* reparse */);
10426 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10429 insert_watchpoint (struct bp_location *bl)
10431 struct watchpoint *w = (struct watchpoint *) bl->owner;
10432 int length = w->exact ? 1 : bl->length;
10434 return target_insert_watchpoint (bl->address, length, bl->watchpoint_type,
10438 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10441 remove_watchpoint (struct bp_location *bl)
10443 struct watchpoint *w = (struct watchpoint *) bl->owner;
10444 int length = w->exact ? 1 : bl->length;
10446 return target_remove_watchpoint (bl->address, length, bl->watchpoint_type,
10451 breakpoint_hit_watchpoint (const struct bp_location *bl,
10452 struct address_space *aspace, CORE_ADDR bp_addr,
10453 const struct target_waitstatus *ws)
10455 struct breakpoint *b = bl->owner;
10456 struct watchpoint *w = (struct watchpoint *) b;
10458 /* Continuable hardware watchpoints are treated as non-existent if the
10459 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10460 some data address). Otherwise gdb won't stop on a break instruction
10461 in the code (not from a breakpoint) when a hardware watchpoint has
10462 been defined. Also skip watchpoints which we know did not trigger
10463 (did not match the data address). */
10464 if (is_hardware_watchpoint (b)
10465 && w->watchpoint_triggered == watch_triggered_no)
10472 check_status_watchpoint (bpstat bs)
10474 gdb_assert (is_watchpoint (bs->breakpoint_at));
10476 bpstat_check_watchpoint (bs);
10479 /* Implement the "resources_needed" breakpoint_ops method for
10480 hardware watchpoints. */
10483 resources_needed_watchpoint (const struct bp_location *bl)
10485 struct watchpoint *w = (struct watchpoint *) bl->owner;
10486 int length = w->exact? 1 : bl->length;
10488 return target_region_ok_for_hw_watchpoint (bl->address, length);
10491 /* Implement the "works_in_software_mode" breakpoint_ops method for
10492 hardware watchpoints. */
10495 works_in_software_mode_watchpoint (const struct breakpoint *b)
10497 /* Read and access watchpoints only work with hardware support. */
10498 return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint;
10501 static enum print_stop_action
10502 print_it_watchpoint (bpstat bs)
10504 struct cleanup *old_chain;
10505 struct breakpoint *b;
10506 struct ui_file *stb;
10507 enum print_stop_action result;
10508 struct watchpoint *w;
10509 struct ui_out *uiout = current_uiout;
10511 gdb_assert (bs->bp_location_at != NULL);
10513 b = bs->breakpoint_at;
10514 w = (struct watchpoint *) b;
10516 stb = mem_fileopen ();
10517 old_chain = make_cleanup_ui_file_delete (stb);
10521 case bp_watchpoint:
10522 case bp_hardware_watchpoint:
10523 annotate_watchpoint (b->number);
10524 if (ui_out_is_mi_like_p (uiout))
10525 ui_out_field_string
10527 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
10529 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10530 ui_out_text (uiout, "\nOld value = ");
10531 watchpoint_value_print (bs->old_val, stb);
10532 ui_out_field_stream (uiout, "old", stb);
10533 ui_out_text (uiout, "\nNew value = ");
10534 watchpoint_value_print (w->val, stb);
10535 ui_out_field_stream (uiout, "new", stb);
10536 ui_out_text (uiout, "\n");
10537 /* More than one watchpoint may have been triggered. */
10538 result = PRINT_UNKNOWN;
10541 case bp_read_watchpoint:
10542 if (ui_out_is_mi_like_p (uiout))
10543 ui_out_field_string
10545 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
10547 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10548 ui_out_text (uiout, "\nValue = ");
10549 watchpoint_value_print (w->val, stb);
10550 ui_out_field_stream (uiout, "value", stb);
10551 ui_out_text (uiout, "\n");
10552 result = PRINT_UNKNOWN;
10555 case bp_access_watchpoint:
10556 if (bs->old_val != NULL)
10558 annotate_watchpoint (b->number);
10559 if (ui_out_is_mi_like_p (uiout))
10560 ui_out_field_string
10562 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10564 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10565 ui_out_text (uiout, "\nOld value = ");
10566 watchpoint_value_print (bs->old_val, stb);
10567 ui_out_field_stream (uiout, "old", stb);
10568 ui_out_text (uiout, "\nNew value = ");
10573 if (ui_out_is_mi_like_p (uiout))
10574 ui_out_field_string
10576 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10577 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10578 ui_out_text (uiout, "\nValue = ");
10580 watchpoint_value_print (w->val, stb);
10581 ui_out_field_stream (uiout, "new", stb);
10582 ui_out_text (uiout, "\n");
10583 result = PRINT_UNKNOWN;
10586 result = PRINT_UNKNOWN;
10589 do_cleanups (old_chain);
10593 /* Implement the "print_mention" breakpoint_ops method for hardware
10597 print_mention_watchpoint (struct breakpoint *b)
10599 struct cleanup *ui_out_chain;
10600 struct watchpoint *w = (struct watchpoint *) b;
10601 struct ui_out *uiout = current_uiout;
10605 case bp_watchpoint:
10606 ui_out_text (uiout, "Watchpoint ");
10607 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
10609 case bp_hardware_watchpoint:
10610 ui_out_text (uiout, "Hardware watchpoint ");
10611 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
10613 case bp_read_watchpoint:
10614 ui_out_text (uiout, "Hardware read watchpoint ");
10615 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
10617 case bp_access_watchpoint:
10618 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
10619 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
10622 internal_error (__FILE__, __LINE__,
10623 _("Invalid hardware watchpoint type."));
10626 ui_out_field_int (uiout, "number", b->number);
10627 ui_out_text (uiout, ": ");
10628 ui_out_field_string (uiout, "exp", w->exp_string);
10629 do_cleanups (ui_out_chain);
10632 /* Implement the "print_recreate" breakpoint_ops method for
10636 print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp)
10638 struct watchpoint *w = (struct watchpoint *) b;
10642 case bp_watchpoint:
10643 case bp_hardware_watchpoint:
10644 fprintf_unfiltered (fp, "watch");
10646 case bp_read_watchpoint:
10647 fprintf_unfiltered (fp, "rwatch");
10649 case bp_access_watchpoint:
10650 fprintf_unfiltered (fp, "awatch");
10653 internal_error (__FILE__, __LINE__,
10654 _("Invalid watchpoint type."));
10657 fprintf_unfiltered (fp, " %s", w->exp_string);
10658 print_recreate_thread (b, fp);
10661 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10663 static struct breakpoint_ops watchpoint_breakpoint_ops;
10665 /* Implement the "insert" breakpoint_ops method for
10666 masked hardware watchpoints. */
10669 insert_masked_watchpoint (struct bp_location *bl)
10671 struct watchpoint *w = (struct watchpoint *) bl->owner;
10673 return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask,
10674 bl->watchpoint_type);
10677 /* Implement the "remove" breakpoint_ops method for
10678 masked hardware watchpoints. */
10681 remove_masked_watchpoint (struct bp_location *bl)
10683 struct watchpoint *w = (struct watchpoint *) bl->owner;
10685 return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask,
10686 bl->watchpoint_type);
10689 /* Implement the "resources_needed" breakpoint_ops method for
10690 masked hardware watchpoints. */
10693 resources_needed_masked_watchpoint (const struct bp_location *bl)
10695 struct watchpoint *w = (struct watchpoint *) bl->owner;
10697 return target_masked_watch_num_registers (bl->address, w->hw_wp_mask);
10700 /* Implement the "works_in_software_mode" breakpoint_ops method for
10701 masked hardware watchpoints. */
10704 works_in_software_mode_masked_watchpoint (const struct breakpoint *b)
10709 /* Implement the "print_it" breakpoint_ops method for
10710 masked hardware watchpoints. */
10712 static enum print_stop_action
10713 print_it_masked_watchpoint (bpstat bs)
10715 struct breakpoint *b = bs->breakpoint_at;
10716 struct ui_out *uiout = current_uiout;
10718 /* Masked watchpoints have only one location. */
10719 gdb_assert (b->loc && b->loc->next == NULL);
10723 case bp_hardware_watchpoint:
10724 annotate_watchpoint (b->number);
10725 if (ui_out_is_mi_like_p (uiout))
10726 ui_out_field_string
10728 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
10731 case bp_read_watchpoint:
10732 if (ui_out_is_mi_like_p (uiout))
10733 ui_out_field_string
10735 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
10738 case bp_access_watchpoint:
10739 if (ui_out_is_mi_like_p (uiout))
10740 ui_out_field_string
10742 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10745 internal_error (__FILE__, __LINE__,
10746 _("Invalid hardware watchpoint type."));
10750 ui_out_text (uiout, _("\n\
10751 Check the underlying instruction at PC for the memory\n\
10752 address and value which triggered this watchpoint.\n"));
10753 ui_out_text (uiout, "\n");
10755 /* More than one watchpoint may have been triggered. */
10756 return PRINT_UNKNOWN;
10759 /* Implement the "print_one_detail" breakpoint_ops method for
10760 masked hardware watchpoints. */
10763 print_one_detail_masked_watchpoint (const struct breakpoint *b,
10764 struct ui_out *uiout)
10766 struct watchpoint *w = (struct watchpoint *) b;
10768 /* Masked watchpoints have only one location. */
10769 gdb_assert (b->loc && b->loc->next == NULL);
10771 ui_out_text (uiout, "\tmask ");
10772 ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask);
10773 ui_out_text (uiout, "\n");
10776 /* Implement the "print_mention" breakpoint_ops method for
10777 masked hardware watchpoints. */
10780 print_mention_masked_watchpoint (struct breakpoint *b)
10782 struct watchpoint *w = (struct watchpoint *) b;
10783 struct ui_out *uiout = current_uiout;
10784 struct cleanup *ui_out_chain;
10788 case bp_hardware_watchpoint:
10789 ui_out_text (uiout, "Masked hardware watchpoint ");
10790 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
10792 case bp_read_watchpoint:
10793 ui_out_text (uiout, "Masked hardware read watchpoint ");
10794 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
10796 case bp_access_watchpoint:
10797 ui_out_text (uiout, "Masked hardware access (read/write) watchpoint ");
10798 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
10801 internal_error (__FILE__, __LINE__,
10802 _("Invalid hardware watchpoint type."));
10805 ui_out_field_int (uiout, "number", b->number);
10806 ui_out_text (uiout, ": ");
10807 ui_out_field_string (uiout, "exp", w->exp_string);
10808 do_cleanups (ui_out_chain);
10811 /* Implement the "print_recreate" breakpoint_ops method for
10812 masked hardware watchpoints. */
10815 print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp)
10817 struct watchpoint *w = (struct watchpoint *) b;
10822 case bp_hardware_watchpoint:
10823 fprintf_unfiltered (fp, "watch");
10825 case bp_read_watchpoint:
10826 fprintf_unfiltered (fp, "rwatch");
10828 case bp_access_watchpoint:
10829 fprintf_unfiltered (fp, "awatch");
10832 internal_error (__FILE__, __LINE__,
10833 _("Invalid hardware watchpoint type."));
10836 sprintf_vma (tmp, w->hw_wp_mask);
10837 fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp);
10838 print_recreate_thread (b, fp);
10841 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10843 static struct breakpoint_ops masked_watchpoint_breakpoint_ops;
10845 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10848 is_masked_watchpoint (const struct breakpoint *b)
10850 return b->ops == &masked_watchpoint_breakpoint_ops;
10853 /* accessflag: hw_write: watch write,
10854 hw_read: watch read,
10855 hw_access: watch access (read or write) */
10857 watch_command_1 (const char *arg, int accessflag, int from_tty,
10858 int just_location, int internal)
10860 volatile struct gdb_exception e;
10861 struct breakpoint *b, *scope_breakpoint = NULL;
10862 struct expression *exp;
10863 const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL;
10864 struct value *val, *mark, *result;
10865 struct frame_info *frame;
10866 const char *exp_start = NULL;
10867 const char *exp_end = NULL;
10868 const char *tok, *end_tok;
10870 const char *cond_start = NULL;
10871 const char *cond_end = NULL;
10872 enum bptype bp_type;
10875 /* Flag to indicate whether we are going to use masks for
10876 the hardware watchpoint. */
10878 CORE_ADDR mask = 0;
10879 struct watchpoint *w;
10881 struct cleanup *back_to;
10883 /* Make sure that we actually have parameters to parse. */
10884 if (arg != NULL && arg[0] != '\0')
10886 const char *value_start;
10888 exp_end = arg + strlen (arg);
10890 /* Look for "parameter value" pairs at the end
10891 of the arguments string. */
10892 for (tok = exp_end - 1; tok > arg; tok--)
10894 /* Skip whitespace at the end of the argument list. */
10895 while (tok > arg && (*tok == ' ' || *tok == '\t'))
10898 /* Find the beginning of the last token.
10899 This is the value of the parameter. */
10900 while (tok > arg && (*tok != ' ' && *tok != '\t'))
10902 value_start = tok + 1;
10904 /* Skip whitespace. */
10905 while (tok > arg && (*tok == ' ' || *tok == '\t'))
10910 /* Find the beginning of the second to last token.
10911 This is the parameter itself. */
10912 while (tok > arg && (*tok != ' ' && *tok != '\t'))
10915 toklen = end_tok - tok + 1;
10917 if (toklen == 6 && !strncmp (tok, "thread", 6))
10919 /* At this point we've found a "thread" token, which means
10920 the user is trying to set a watchpoint that triggers
10921 only in a specific thread. */
10925 error(_("You can specify only one thread."));
10927 /* Extract the thread ID from the next token. */
10928 thread = strtol (value_start, &endp, 0);
10930 /* Check if the user provided a valid numeric value for the
10932 if (*endp != ' ' && *endp != '\t' && *endp != '\0')
10933 error (_("Invalid thread ID specification %s."), value_start);
10935 /* Check if the thread actually exists. */
10936 if (!valid_thread_id (thread))
10937 invalid_thread_id_error (thread);
10939 else if (toklen == 4 && !strncmp (tok, "mask", 4))
10941 /* We've found a "mask" token, which means the user wants to
10942 create a hardware watchpoint that is going to have the mask
10944 struct value *mask_value, *mark;
10947 error(_("You can specify only one mask."));
10949 use_mask = just_location = 1;
10951 mark = value_mark ();
10952 mask_value = parse_to_comma_and_eval (&value_start);
10953 mask = value_as_address (mask_value);
10954 value_free_to_mark (mark);
10957 /* We didn't recognize what we found. We should stop here. */
10960 /* Truncate the string and get rid of the "parameter value" pair before
10961 the arguments string is parsed by the parse_exp_1 function. */
10968 /* Parse the rest of the arguments. From here on out, everything
10969 is in terms of a newly allocated string instead of the original
10971 innermost_block = NULL;
10972 expression = savestring (arg, exp_end - arg);
10973 back_to = make_cleanup (xfree, expression);
10974 exp_start = arg = expression;
10975 exp = parse_exp_1 (&arg, 0, 0, 0);
10977 /* Remove trailing whitespace from the expression before saving it.
10978 This makes the eventual display of the expression string a bit
10980 while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t'))
10983 /* Checking if the expression is not constant. */
10984 if (watchpoint_exp_is_const (exp))
10988 len = exp_end - exp_start;
10989 while (len > 0 && isspace (exp_start[len - 1]))
10991 error (_("Cannot watch constant value `%.*s'."), len, exp_start);
10994 exp_valid_block = innermost_block;
10995 mark = value_mark ();
10996 fetch_subexp_value (exp, &pc, &val, &result, NULL);
11002 exp_valid_block = NULL;
11003 val = value_addr (result);
11004 release_value (val);
11005 value_free_to_mark (mark);
11009 ret = target_masked_watch_num_registers (value_as_address (val),
11012 error (_("This target does not support masked watchpoints."));
11013 else if (ret == -2)
11014 error (_("Invalid mask or memory region."));
11017 else if (val != NULL)
11018 release_value (val);
11020 tok = skip_spaces_const (arg);
11021 end_tok = skip_to_space_const (tok);
11023 toklen = end_tok - tok;
11024 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
11026 struct expression *cond;
11028 innermost_block = NULL;
11029 tok = cond_start = end_tok + 1;
11030 cond = parse_exp_1 (&tok, 0, 0, 0);
11032 /* The watchpoint expression may not be local, but the condition
11033 may still be. E.g.: `watch global if local > 0'. */
11034 cond_exp_valid_block = innermost_block;
11040 error (_("Junk at end of command."));
11042 if (accessflag == hw_read)
11043 bp_type = bp_read_watchpoint;
11044 else if (accessflag == hw_access)
11045 bp_type = bp_access_watchpoint;
11047 bp_type = bp_hardware_watchpoint;
11049 frame = block_innermost_frame (exp_valid_block);
11051 /* If the expression is "local", then set up a "watchpoint scope"
11052 breakpoint at the point where we've left the scope of the watchpoint
11053 expression. Create the scope breakpoint before the watchpoint, so
11054 that we will encounter it first in bpstat_stop_status. */
11055 if (exp_valid_block && frame)
11057 if (frame_id_p (frame_unwind_caller_id (frame)))
11060 = create_internal_breakpoint (frame_unwind_caller_arch (frame),
11061 frame_unwind_caller_pc (frame),
11062 bp_watchpoint_scope,
11063 &momentary_breakpoint_ops);
11065 scope_breakpoint->enable_state = bp_enabled;
11067 /* Automatically delete the breakpoint when it hits. */
11068 scope_breakpoint->disposition = disp_del;
11070 /* Only break in the proper frame (help with recursion). */
11071 scope_breakpoint->frame_id = frame_unwind_caller_id (frame);
11073 /* Set the address at which we will stop. */
11074 scope_breakpoint->loc->gdbarch
11075 = frame_unwind_caller_arch (frame);
11076 scope_breakpoint->loc->requested_address
11077 = frame_unwind_caller_pc (frame);
11078 scope_breakpoint->loc->address
11079 = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch,
11080 scope_breakpoint->loc->requested_address,
11081 scope_breakpoint->type);
11085 /* Now set up the breakpoint. */
11087 w = XCNEW (struct watchpoint);
11090 init_raw_breakpoint_without_location (b, NULL, bp_type,
11091 &masked_watchpoint_breakpoint_ops);
11093 init_raw_breakpoint_without_location (b, NULL, bp_type,
11094 &watchpoint_breakpoint_ops);
11095 b->thread = thread;
11096 b->disposition = disp_donttouch;
11097 b->pspace = current_program_space;
11099 w->exp_valid_block = exp_valid_block;
11100 w->cond_exp_valid_block = cond_exp_valid_block;
11103 struct type *t = value_type (val);
11104 CORE_ADDR addr = value_as_address (val);
11107 t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t)));
11108 name = type_to_string (t);
11110 w->exp_string_reparse = xstrprintf ("* (%s *) %s", name,
11111 core_addr_to_string (addr));
11114 w->exp_string = xstrprintf ("-location %.*s",
11115 (int) (exp_end - exp_start), exp_start);
11117 /* The above expression is in C. */
11118 b->language = language_c;
11121 w->exp_string = savestring (exp_start, exp_end - exp_start);
11125 w->hw_wp_mask = mask;
11134 b->cond_string = savestring (cond_start, cond_end - cond_start);
11136 b->cond_string = 0;
11140 w->watchpoint_frame = get_frame_id (frame);
11141 w->watchpoint_thread = inferior_ptid;
11145 w->watchpoint_frame = null_frame_id;
11146 w->watchpoint_thread = null_ptid;
11149 if (scope_breakpoint != NULL)
11151 /* The scope breakpoint is related to the watchpoint. We will
11152 need to act on them together. */
11153 b->related_breakpoint = scope_breakpoint;
11154 scope_breakpoint->related_breakpoint = b;
11157 if (!just_location)
11158 value_free_to_mark (mark);
11160 TRY_CATCH (e, RETURN_MASK_ALL)
11162 /* Finally update the new watchpoint. This creates the locations
11163 that should be inserted. */
11164 update_watchpoint (w, 1);
11168 delete_breakpoint (b);
11169 throw_exception (e);
11172 install_breakpoint (internal, b, 1);
11173 do_cleanups (back_to);
11176 /* Return count of debug registers needed to watch the given expression.
11177 If the watchpoint cannot be handled in hardware return zero. */
11180 can_use_hardware_watchpoint (struct value *v)
11182 int found_memory_cnt = 0;
11183 struct value *head = v;
11185 /* Did the user specifically forbid us to use hardware watchpoints? */
11186 if (!can_use_hw_watchpoints)
11189 /* Make sure that the value of the expression depends only upon
11190 memory contents, and values computed from them within GDB. If we
11191 find any register references or function calls, we can't use a
11192 hardware watchpoint.
11194 The idea here is that evaluating an expression generates a series
11195 of values, one holding the value of every subexpression. (The
11196 expression a*b+c has five subexpressions: a, b, a*b, c, and
11197 a*b+c.) GDB's values hold almost enough information to establish
11198 the criteria given above --- they identify memory lvalues,
11199 register lvalues, computed values, etcetera. So we can evaluate
11200 the expression, and then scan the chain of values that leaves
11201 behind to decide whether we can detect any possible change to the
11202 expression's final value using only hardware watchpoints.
11204 However, I don't think that the values returned by inferior
11205 function calls are special in any way. So this function may not
11206 notice that an expression involving an inferior function call
11207 can't be watched with hardware watchpoints. FIXME. */
11208 for (; v; v = value_next (v))
11210 if (VALUE_LVAL (v) == lval_memory)
11212 if (v != head && value_lazy (v))
11213 /* A lazy memory lvalue in the chain is one that GDB never
11214 needed to fetch; we either just used its address (e.g.,
11215 `a' in `a.b') or we never needed it at all (e.g., `a'
11216 in `a,b'). This doesn't apply to HEAD; if that is
11217 lazy then it was not readable, but watch it anyway. */
11221 /* Ahh, memory we actually used! Check if we can cover
11222 it with hardware watchpoints. */
11223 struct type *vtype = check_typedef (value_type (v));
11225 /* We only watch structs and arrays if user asked for it
11226 explicitly, never if they just happen to appear in a
11227 middle of some value chain. */
11229 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
11230 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
11232 CORE_ADDR vaddr = value_address (v);
11236 len = (target_exact_watchpoints
11237 && is_scalar_type_recursive (vtype))?
11238 1 : TYPE_LENGTH (value_type (v));
11240 num_regs = target_region_ok_for_hw_watchpoint (vaddr, len);
11244 found_memory_cnt += num_regs;
11248 else if (VALUE_LVAL (v) != not_lval
11249 && deprecated_value_modifiable (v) == 0)
11250 return 0; /* These are values from the history (e.g., $1). */
11251 else if (VALUE_LVAL (v) == lval_register)
11252 return 0; /* Cannot watch a register with a HW watchpoint. */
11255 /* The expression itself looks suitable for using a hardware
11256 watchpoint, but give the target machine a chance to reject it. */
11257 return found_memory_cnt;
11261 watch_command_wrapper (char *arg, int from_tty, int internal)
11263 watch_command_1 (arg, hw_write, from_tty, 0, internal);
11266 /* A helper function that looks for the "-location" argument and then
11267 calls watch_command_1. */
11270 watch_maybe_just_location (char *arg, int accessflag, int from_tty)
11272 int just_location = 0;
11275 && (check_for_argument (&arg, "-location", sizeof ("-location") - 1)
11276 || check_for_argument (&arg, "-l", sizeof ("-l") - 1)))
11278 arg = skip_spaces (arg);
11282 watch_command_1 (arg, accessflag, from_tty, just_location, 0);
11286 watch_command (char *arg, int from_tty)
11288 watch_maybe_just_location (arg, hw_write, from_tty);
11292 rwatch_command_wrapper (char *arg, int from_tty, int internal)
11294 watch_command_1 (arg, hw_read, from_tty, 0, internal);
11298 rwatch_command (char *arg, int from_tty)
11300 watch_maybe_just_location (arg, hw_read, from_tty);
11304 awatch_command_wrapper (char *arg, int from_tty, int internal)
11306 watch_command_1 (arg, hw_access, from_tty, 0, internal);
11310 awatch_command (char *arg, int from_tty)
11312 watch_maybe_just_location (arg, hw_access, from_tty);
11316 /* Helper routines for the until_command routine in infcmd.c. Here
11317 because it uses the mechanisms of breakpoints. */
11319 struct until_break_command_continuation_args
11321 struct breakpoint *breakpoint;
11322 struct breakpoint *breakpoint2;
11326 /* This function is called by fetch_inferior_event via the
11327 cmd_continuation pointer, to complete the until command. It takes
11328 care of cleaning up the temporary breakpoints set up by the until
11331 until_break_command_continuation (void *arg, int err)
11333 struct until_break_command_continuation_args *a = arg;
11335 delete_breakpoint (a->breakpoint);
11336 if (a->breakpoint2)
11337 delete_breakpoint (a->breakpoint2);
11338 delete_longjmp_breakpoint (a->thread_num);
11342 until_break_command (char *arg, int from_tty, int anywhere)
11344 struct symtabs_and_lines sals;
11345 struct symtab_and_line sal;
11346 struct frame_info *frame;
11347 struct gdbarch *frame_gdbarch;
11348 struct frame_id stack_frame_id;
11349 struct frame_id caller_frame_id;
11350 struct breakpoint *breakpoint;
11351 struct breakpoint *breakpoint2 = NULL;
11352 struct cleanup *old_chain;
11354 struct thread_info *tp;
11356 clear_proceed_status ();
11358 /* Set a breakpoint where the user wants it and at return from
11361 if (last_displayed_sal_is_valid ())
11362 sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE,
11363 get_last_displayed_symtab (),
11364 get_last_displayed_line ());
11366 sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE,
11367 (struct symtab *) NULL, 0);
11369 if (sals.nelts != 1)
11370 error (_("Couldn't get information on specified line."));
11372 sal = sals.sals[0];
11373 xfree (sals.sals); /* malloc'd, so freed. */
11376 error (_("Junk at end of arguments."));
11378 resolve_sal_pc (&sal);
11380 tp = inferior_thread ();
11383 old_chain = make_cleanup (null_cleanup, NULL);
11385 /* Note linespec handling above invalidates the frame chain.
11386 Installing a breakpoint also invalidates the frame chain (as it
11387 may need to switch threads), so do any frame handling before
11390 frame = get_selected_frame (NULL);
11391 frame_gdbarch = get_frame_arch (frame);
11392 stack_frame_id = get_stack_frame_id (frame);
11393 caller_frame_id = frame_unwind_caller_id (frame);
11395 /* Keep within the current frame, or in frames called by the current
11398 if (frame_id_p (caller_frame_id))
11400 struct symtab_and_line sal2;
11402 sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0);
11403 sal2.pc = frame_unwind_caller_pc (frame);
11404 breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame),
11408 make_cleanup_delete_breakpoint (breakpoint2);
11410 set_longjmp_breakpoint (tp, caller_frame_id);
11411 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
11414 /* set_momentary_breakpoint could invalidate FRAME. */
11418 /* If the user told us to continue until a specified location,
11419 we don't specify a frame at which we need to stop. */
11420 breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
11421 null_frame_id, bp_until);
11423 /* Otherwise, specify the selected frame, because we want to stop
11424 only at the very same frame. */
11425 breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
11426 stack_frame_id, bp_until);
11427 make_cleanup_delete_breakpoint (breakpoint);
11429 proceed (-1, GDB_SIGNAL_DEFAULT, 0);
11431 /* If we are running asynchronously, and proceed call above has
11432 actually managed to start the target, arrange for breakpoints to
11433 be deleted when the target stops. Otherwise, we're already
11434 stopped and delete breakpoints via cleanup chain. */
11436 if (target_can_async_p () && is_running (inferior_ptid))
11438 struct until_break_command_continuation_args *args;
11439 args = xmalloc (sizeof (*args));
11441 args->breakpoint = breakpoint;
11442 args->breakpoint2 = breakpoint2;
11443 args->thread_num = thread;
11445 discard_cleanups (old_chain);
11446 add_continuation (inferior_thread (),
11447 until_break_command_continuation, args,
11451 do_cleanups (old_chain);
11454 /* This function attempts to parse an optional "if <cond>" clause
11455 from the arg string. If one is not found, it returns NULL.
11457 Else, it returns a pointer to the condition string. (It does not
11458 attempt to evaluate the string against a particular block.) And,
11459 it updates arg to point to the first character following the parsed
11460 if clause in the arg string. */
11463 ep_parse_optional_if_clause (char **arg)
11467 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
11470 /* Skip the "if" keyword. */
11473 /* Skip any extra leading whitespace, and record the start of the
11474 condition string. */
11475 *arg = skip_spaces (*arg);
11476 cond_string = *arg;
11478 /* Assume that the condition occupies the remainder of the arg
11480 (*arg) += strlen (cond_string);
11482 return cond_string;
11485 /* Commands to deal with catching events, such as signals, exceptions,
11486 process start/exit, etc. */
11490 catch_fork_temporary, catch_vfork_temporary,
11491 catch_fork_permanent, catch_vfork_permanent
11496 catch_fork_command_1 (char *arg, int from_tty,
11497 struct cmd_list_element *command)
11499 struct gdbarch *gdbarch = get_current_arch ();
11500 char *cond_string = NULL;
11501 catch_fork_kind fork_kind;
11504 fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command);
11505 tempflag = (fork_kind == catch_fork_temporary
11506 || fork_kind == catch_vfork_temporary);
11510 arg = skip_spaces (arg);
11512 /* The allowed syntax is:
11514 catch [v]fork if <cond>
11516 First, check if there's an if clause. */
11517 cond_string = ep_parse_optional_if_clause (&arg);
11519 if ((*arg != '\0') && !isspace (*arg))
11520 error (_("Junk at end of arguments."));
11522 /* If this target supports it, create a fork or vfork catchpoint
11523 and enable reporting of such events. */
11526 case catch_fork_temporary:
11527 case catch_fork_permanent:
11528 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
11529 &catch_fork_breakpoint_ops);
11531 case catch_vfork_temporary:
11532 case catch_vfork_permanent:
11533 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
11534 &catch_vfork_breakpoint_ops);
11537 error (_("unsupported or unknown fork kind; cannot catch it"));
11543 catch_exec_command_1 (char *arg, int from_tty,
11544 struct cmd_list_element *command)
11546 struct exec_catchpoint *c;
11547 struct gdbarch *gdbarch = get_current_arch ();
11549 char *cond_string = NULL;
11551 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11555 arg = skip_spaces (arg);
11557 /* The allowed syntax is:
11559 catch exec if <cond>
11561 First, check if there's an if clause. */
11562 cond_string = ep_parse_optional_if_clause (&arg);
11564 if ((*arg != '\0') && !isspace (*arg))
11565 error (_("Junk at end of arguments."));
11567 c = XNEW (struct exec_catchpoint);
11568 init_catchpoint (&c->base, gdbarch, tempflag, cond_string,
11569 &catch_exec_breakpoint_ops);
11570 c->exec_pathname = NULL;
11572 install_breakpoint (0, &c->base, 1);
11575 /* A helper function that returns a value indicating the kind of the
11576 exception catchpoint B. */
11578 static enum exception_event_kind
11579 classify_exception_breakpoint (struct breakpoint *b)
11581 if (strstr (b->addr_string, "catch") != NULL)
11582 return EX_EVENT_CATCH;
11583 else if (strstr (b->addr_string, "rethrow") != NULL)
11584 return EX_EVENT_RETHROW;
11586 return EX_EVENT_THROW;
11589 static enum print_stop_action
11590 print_it_exception_catchpoint (bpstat bs)
11592 struct ui_out *uiout = current_uiout;
11593 struct breakpoint *b = bs->breakpoint_at;
11595 enum exception_event_kind kind = classify_exception_breakpoint (b);
11597 annotate_catchpoint (b->number);
11599 if (b->loc->address != b->loc->requested_address)
11600 breakpoint_adjustment_warning (b->loc->requested_address,
11603 bp_temp = b->disposition == disp_del;
11604 ui_out_text (uiout,
11605 bp_temp ? "Temporary catchpoint "
11607 if (!ui_out_is_mi_like_p (uiout))
11608 ui_out_field_int (uiout, "bkptno", b->number);
11609 ui_out_text (uiout,
11610 (kind == EX_EVENT_THROW ? " (exception thrown), "
11611 : (kind == EX_EVENT_CATCH ? " (exception caught), "
11612 : " (exception rethrown), ")));
11613 if (ui_out_is_mi_like_p (uiout))
11615 ui_out_field_string (uiout, "reason",
11616 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
11617 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
11618 ui_out_field_int (uiout, "bkptno", b->number);
11620 return PRINT_SRC_AND_LOC;
11624 print_one_exception_catchpoint (struct breakpoint *b,
11625 struct bp_location **last_loc)
11627 struct value_print_options opts;
11628 struct ui_out *uiout = current_uiout;
11629 enum exception_event_kind kind = classify_exception_breakpoint (b);
11631 get_user_print_options (&opts);
11632 if (opts.addressprint)
11634 annotate_field (4);
11635 if (b->loc == NULL || b->loc->shlib_disabled)
11636 ui_out_field_string (uiout, "addr", "<PENDING>");
11638 ui_out_field_core_addr (uiout, "addr",
11639 b->loc->gdbarch, b->loc->address);
11641 annotate_field (5);
11643 *last_loc = b->loc;
11647 case EX_EVENT_THROW:
11648 ui_out_field_string (uiout, "what", "exception throw");
11649 if (ui_out_is_mi_like_p (uiout))
11650 ui_out_field_string (uiout, "catch-type", "throw");
11653 case EX_EVENT_RETHROW:
11654 ui_out_field_string (uiout, "what", "exception rethrow");
11655 if (ui_out_is_mi_like_p (uiout))
11656 ui_out_field_string (uiout, "catch-type", "rethrow");
11659 case EX_EVENT_CATCH:
11660 ui_out_field_string (uiout, "what", "exception catch");
11661 if (ui_out_is_mi_like_p (uiout))
11662 ui_out_field_string (uiout, "catch-type", "catch");
11668 print_mention_exception_catchpoint (struct breakpoint *b)
11670 struct ui_out *uiout = current_uiout;
11672 enum exception_event_kind kind = classify_exception_breakpoint (b);
11674 bp_temp = b->disposition == disp_del;
11675 ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ")
11676 : _("Catchpoint "));
11677 ui_out_field_int (uiout, "bkptno", b->number);
11678 ui_out_text (uiout, (kind == EX_EVENT_THROW ? _(" (throw)")
11679 : (kind == EX_EVENT_CATCH ? _(" (catch)")
11680 : _(" (rethrow)"))));
11683 /* Implement the "print_recreate" breakpoint_ops method for throw and
11684 catch catchpoints. */
11687 print_recreate_exception_catchpoint (struct breakpoint *b,
11688 struct ui_file *fp)
11691 enum exception_event_kind kind = classify_exception_breakpoint (b);
11693 bp_temp = b->disposition == disp_del;
11694 fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch ");
11697 case EX_EVENT_THROW:
11698 fprintf_unfiltered (fp, "throw");
11700 case EX_EVENT_CATCH:
11701 fprintf_unfiltered (fp, "catch");
11703 case EX_EVENT_RETHROW:
11704 fprintf_unfiltered (fp, "rethrow");
11707 print_recreate_thread (b, fp);
11710 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops;
11713 handle_gnu_v3_exceptions (int tempflag, char *cond_string,
11714 enum exception_event_kind ex_event, int from_tty)
11716 char *trigger_func_name;
11718 if (ex_event == EX_EVENT_CATCH)
11719 trigger_func_name = "__cxa_begin_catch";
11720 else if (ex_event == EX_EVENT_RETHROW)
11721 trigger_func_name = "__cxa_rethrow";
11724 gdb_assert (ex_event == EX_EVENT_THROW);
11725 trigger_func_name = "__cxa_throw";
11728 create_breakpoint (get_current_arch (),
11729 trigger_func_name, cond_string, -1, NULL,
11730 0 /* condition and thread are valid. */,
11731 tempflag, bp_breakpoint,
11733 AUTO_BOOLEAN_TRUE /* pending */,
11734 &gnu_v3_exception_catchpoint_ops, from_tty,
11742 /* Deal with "catch catch" and "catch throw" commands. */
11745 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
11746 int tempflag, int from_tty)
11748 char *cond_string = NULL;
11752 arg = skip_spaces (arg);
11754 cond_string = ep_parse_optional_if_clause (&arg);
11756 if ((*arg != '\0') && !isspace (*arg))
11757 error (_("Junk at end of arguments."));
11759 if (ex_event != EX_EVENT_THROW
11760 && ex_event != EX_EVENT_CATCH
11761 && ex_event != EX_EVENT_RETHROW)
11762 error (_("Unsupported or unknown exception event; cannot catch it"));
11764 if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
11767 warning (_("Unsupported with this platform/compiler combination."));
11770 /* Implementation of "catch catch" command. */
11773 catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command)
11775 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11777 catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty);
11780 /* Implementation of "catch throw" command. */
11783 catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command)
11785 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11787 catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty);
11790 /* Implementation of "catch rethrow" command. */
11793 catch_rethrow_command (char *arg, int from_tty,
11794 struct cmd_list_element *command)
11796 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11798 catch_exception_command_1 (EX_EVENT_RETHROW, arg, tempflag, from_tty);
11802 init_ada_exception_breakpoint (struct breakpoint *b,
11803 struct gdbarch *gdbarch,
11804 struct symtab_and_line sal,
11806 const struct breakpoint_ops *ops,
11812 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
11814 loc_gdbarch = gdbarch;
11816 describe_other_breakpoints (loc_gdbarch,
11817 sal.pspace, sal.pc, sal.section, -1);
11818 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11819 version for exception catchpoints, because two catchpoints
11820 used for different exception names will use the same address.
11821 In this case, a "breakpoint ... also set at..." warning is
11822 unproductive. Besides, the warning phrasing is also a bit
11823 inappropriate, we should use the word catchpoint, and tell
11824 the user what type of catchpoint it is. The above is good
11825 enough for now, though. */
11828 init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops);
11830 b->enable_state = bp_enabled;
11831 b->disposition = tempflag ? disp_del : disp_donttouch;
11832 b->addr_string = addr_string;
11833 b->language = language_ada;
11836 /* Splits the argument using space as delimiter. Returns an xmalloc'd
11837 filter list, or NULL if no filtering is required. */
11839 catch_syscall_split_args (char *arg)
11841 VEC(int) *result = NULL;
11842 struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result);
11844 while (*arg != '\0')
11846 int i, syscall_number;
11848 char cur_name[128];
11851 /* Skip whitespace. */
11852 arg = skip_spaces (arg);
11854 for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i)
11855 cur_name[i] = arg[i];
11856 cur_name[i] = '\0';
11859 /* Check if the user provided a syscall name or a number. */
11860 syscall_number = (int) strtol (cur_name, &endptr, 0);
11861 if (*endptr == '\0')
11862 get_syscall_by_number (syscall_number, &s);
11865 /* We have a name. Let's check if it's valid and convert it
11867 get_syscall_by_name (cur_name, &s);
11869 if (s.number == UNKNOWN_SYSCALL)
11870 /* Here we have to issue an error instead of a warning,
11871 because GDB cannot do anything useful if there's no
11872 syscall number to be caught. */
11873 error (_("Unknown syscall name '%s'."), cur_name);
11876 /* Ok, it's valid. */
11877 VEC_safe_push (int, result, s.number);
11880 discard_cleanups (cleanup);
11884 /* Implement the "catch syscall" command. */
11887 catch_syscall_command_1 (char *arg, int from_tty,
11888 struct cmd_list_element *command)
11893 struct gdbarch *gdbarch = get_current_arch ();
11895 /* Checking if the feature if supported. */
11896 if (gdbarch_get_syscall_number_p (gdbarch) == 0)
11897 error (_("The feature 'catch syscall' is not supported on \
11898 this architecture yet."));
11900 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11902 arg = skip_spaces (arg);
11904 /* We need to do this first "dummy" translation in order
11905 to get the syscall XML file loaded or, most important,
11906 to display a warning to the user if there's no XML file
11907 for his/her architecture. */
11908 get_syscall_by_number (0, &s);
11910 /* The allowed syntax is:
11912 catch syscall <name | number> [<name | number> ... <name | number>]
11914 Let's check if there's a syscall name. */
11917 filter = catch_syscall_split_args (arg);
11921 create_syscall_event_catchpoint (tempflag, filter,
11922 &catch_syscall_breakpoint_ops);
11926 catch_command (char *arg, int from_tty)
11928 error (_("Catch requires an event name."));
11933 tcatch_command (char *arg, int from_tty)
11935 error (_("Catch requires an event name."));
11938 /* A qsort comparison function that sorts breakpoints in order. */
11941 compare_breakpoints (const void *a, const void *b)
11943 const breakpoint_p *ba = a;
11944 uintptr_t ua = (uintptr_t) *ba;
11945 const breakpoint_p *bb = b;
11946 uintptr_t ub = (uintptr_t) *bb;
11948 if ((*ba)->number < (*bb)->number)
11950 else if ((*ba)->number > (*bb)->number)
11953 /* Now sort by address, in case we see, e..g, two breakpoints with
11957 return ua > ub ? 1 : 0;
11960 /* Delete breakpoints by address or line. */
11963 clear_command (char *arg, int from_tty)
11965 struct breakpoint *b, *prev;
11966 VEC(breakpoint_p) *found = 0;
11969 struct symtabs_and_lines sals;
11970 struct symtab_and_line sal;
11972 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
11976 sals = decode_line_with_current_source (arg,
11977 (DECODE_LINE_FUNFIRSTLINE
11978 | DECODE_LINE_LIST_MODE));
11979 make_cleanup (xfree, sals.sals);
11984 sals.sals = (struct symtab_and_line *)
11985 xmalloc (sizeof (struct symtab_and_line));
11986 make_cleanup (xfree, sals.sals);
11987 init_sal (&sal); /* Initialize to zeroes. */
11989 /* Set sal's line, symtab, pc, and pspace to the values
11990 corresponding to the last call to print_frame_info. If the
11991 codepoint is not valid, this will set all the fields to 0. */
11992 get_last_displayed_sal (&sal);
11993 if (sal.symtab == 0)
11994 error (_("No source file specified."));
11996 sals.sals[0] = sal;
12002 /* We don't call resolve_sal_pc here. That's not as bad as it
12003 seems, because all existing breakpoints typically have both
12004 file/line and pc set. So, if clear is given file/line, we can
12005 match this to existing breakpoint without obtaining pc at all.
12007 We only support clearing given the address explicitly
12008 present in breakpoint table. Say, we've set breakpoint
12009 at file:line. There were several PC values for that file:line,
12010 due to optimization, all in one block.
12012 We've picked one PC value. If "clear" is issued with another
12013 PC corresponding to the same file:line, the breakpoint won't
12014 be cleared. We probably can still clear the breakpoint, but
12015 since the other PC value is never presented to user, user
12016 can only find it by guessing, and it does not seem important
12017 to support that. */
12019 /* For each line spec given, delete bps which correspond to it. Do
12020 it in two passes, solely to preserve the current behavior that
12021 from_tty is forced true if we delete more than one
12025 make_cleanup (VEC_cleanup (breakpoint_p), &found);
12026 for (i = 0; i < sals.nelts; i++)
12028 const char *sal_fullname;
12030 /* If exact pc given, clear bpts at that pc.
12031 If line given (pc == 0), clear all bpts on specified line.
12032 If defaulting, clear all bpts on default line
12035 defaulting sal.pc != 0 tests to do
12040 1 0 <can't happen> */
12042 sal = sals.sals[i];
12043 sal_fullname = (sal.symtab == NULL
12044 ? NULL : symtab_to_fullname (sal.symtab));
12046 /* Find all matching breakpoints and add them to 'found'. */
12047 ALL_BREAKPOINTS (b)
12050 /* Are we going to delete b? */
12051 if (b->type != bp_none && !is_watchpoint (b))
12053 struct bp_location *loc = b->loc;
12054 for (; loc; loc = loc->next)
12056 /* If the user specified file:line, don't allow a PC
12057 match. This matches historical gdb behavior. */
12058 int pc_match = (!sal.explicit_line
12060 && (loc->pspace == sal.pspace)
12061 && (loc->address == sal.pc)
12062 && (!section_is_overlay (loc->section)
12063 || loc->section == sal.section));
12064 int line_match = 0;
12066 if ((default_match || sal.explicit_line)
12067 && loc->symtab != NULL
12068 && sal_fullname != NULL
12069 && sal.pspace == loc->pspace
12070 && loc->line_number == sal.line
12071 && filename_cmp (symtab_to_fullname (loc->symtab),
12072 sal_fullname) == 0)
12075 if (pc_match || line_match)
12084 VEC_safe_push(breakpoint_p, found, b);
12088 /* Now go thru the 'found' chain and delete them. */
12089 if (VEC_empty(breakpoint_p, found))
12092 error (_("No breakpoint at %s."), arg);
12094 error (_("No breakpoint at this line."));
12097 /* Remove duplicates from the vec. */
12098 qsort (VEC_address (breakpoint_p, found),
12099 VEC_length (breakpoint_p, found),
12100 sizeof (breakpoint_p),
12101 compare_breakpoints);
12102 prev = VEC_index (breakpoint_p, found, 0);
12103 for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix)
12107 VEC_ordered_remove (breakpoint_p, found, ix);
12112 if (VEC_length(breakpoint_p, found) > 1)
12113 from_tty = 1; /* Always report if deleted more than one. */
12116 if (VEC_length(breakpoint_p, found) == 1)
12117 printf_unfiltered (_("Deleted breakpoint "));
12119 printf_unfiltered (_("Deleted breakpoints "));
12122 for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++)
12125 printf_unfiltered ("%d ", b->number);
12126 delete_breakpoint (b);
12129 putchar_unfiltered ('\n');
12131 do_cleanups (cleanups);
12134 /* Delete breakpoint in BS if they are `delete' breakpoints and
12135 all breakpoints that are marked for deletion, whether hit or not.
12136 This is called after any breakpoint is hit, or after errors. */
12139 breakpoint_auto_delete (bpstat bs)
12141 struct breakpoint *b, *b_tmp;
12143 for (; bs; bs = bs->next)
12144 if (bs->breakpoint_at
12145 && bs->breakpoint_at->disposition == disp_del
12147 delete_breakpoint (bs->breakpoint_at);
12149 ALL_BREAKPOINTS_SAFE (b, b_tmp)
12151 if (b->disposition == disp_del_at_next_stop)
12152 delete_breakpoint (b);
12156 /* A comparison function for bp_location AP and BP being interfaced to
12157 qsort. Sort elements primarily by their ADDRESS (no matter what
12158 does breakpoint_address_is_meaningful say for its OWNER),
12159 secondarily by ordering first bp_permanent OWNERed elements and
12160 terciarily just ensuring the array is sorted stable way despite
12161 qsort being an unstable algorithm. */
12164 bp_location_compare (const void *ap, const void *bp)
12166 struct bp_location *a = *(void **) ap;
12167 struct bp_location *b = *(void **) bp;
12168 /* A and B come from existing breakpoints having non-NULL OWNER. */
12169 int a_perm = a->owner->enable_state == bp_permanent;
12170 int b_perm = b->owner->enable_state == bp_permanent;
12172 if (a->address != b->address)
12173 return (a->address > b->address) - (a->address < b->address);
12175 /* Sort locations at the same address by their pspace number, keeping
12176 locations of the same inferior (in a multi-inferior environment)
12179 if (a->pspace->num != b->pspace->num)
12180 return ((a->pspace->num > b->pspace->num)
12181 - (a->pspace->num < b->pspace->num));
12183 /* Sort permanent breakpoints first. */
12184 if (a_perm != b_perm)
12185 return (a_perm < b_perm) - (a_perm > b_perm);
12187 /* Make the internal GDB representation stable across GDB runs
12188 where A and B memory inside GDB can differ. Breakpoint locations of
12189 the same type at the same address can be sorted in arbitrary order. */
12191 if (a->owner->number != b->owner->number)
12192 return ((a->owner->number > b->owner->number)
12193 - (a->owner->number < b->owner->number));
12195 return (a > b) - (a < b);
12198 /* Set bp_location_placed_address_before_address_max and
12199 bp_location_shadow_len_after_address_max according to the current
12200 content of the bp_location array. */
12203 bp_location_target_extensions_update (void)
12205 struct bp_location *bl, **blp_tmp;
12207 bp_location_placed_address_before_address_max = 0;
12208 bp_location_shadow_len_after_address_max = 0;
12210 ALL_BP_LOCATIONS (bl, blp_tmp)
12212 CORE_ADDR start, end, addr;
12214 if (!bp_location_has_shadow (bl))
12217 start = bl->target_info.placed_address;
12218 end = start + bl->target_info.shadow_len;
12220 gdb_assert (bl->address >= start);
12221 addr = bl->address - start;
12222 if (addr > bp_location_placed_address_before_address_max)
12223 bp_location_placed_address_before_address_max = addr;
12225 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
12227 gdb_assert (bl->address < end);
12228 addr = end - bl->address;
12229 if (addr > bp_location_shadow_len_after_address_max)
12230 bp_location_shadow_len_after_address_max = addr;
12234 /* Download tracepoint locations if they haven't been. */
12237 download_tracepoint_locations (void)
12239 struct breakpoint *b;
12240 struct cleanup *old_chain;
12242 if (!target_can_download_tracepoint ())
12245 old_chain = save_current_space_and_thread ();
12247 ALL_TRACEPOINTS (b)
12249 struct bp_location *bl;
12250 struct tracepoint *t;
12251 int bp_location_downloaded = 0;
12253 if ((b->type == bp_fast_tracepoint
12254 ? !may_insert_fast_tracepoints
12255 : !may_insert_tracepoints))
12258 for (bl = b->loc; bl; bl = bl->next)
12260 /* In tracepoint, locations are _never_ duplicated, so
12261 should_be_inserted is equivalent to
12262 unduplicated_should_be_inserted. */
12263 if (!should_be_inserted (bl) || bl->inserted)
12266 switch_to_program_space_and_thread (bl->pspace);
12268 target_download_tracepoint (bl);
12271 bp_location_downloaded = 1;
12273 t = (struct tracepoint *) b;
12274 t->number_on_target = b->number;
12275 if (bp_location_downloaded)
12276 observer_notify_breakpoint_modified (b);
12279 do_cleanups (old_chain);
12282 /* Swap the insertion/duplication state between two locations. */
12285 swap_insertion (struct bp_location *left, struct bp_location *right)
12287 const int left_inserted = left->inserted;
12288 const int left_duplicate = left->duplicate;
12289 const int left_needs_update = left->needs_update;
12290 const struct bp_target_info left_target_info = left->target_info;
12292 /* Locations of tracepoints can never be duplicated. */
12293 if (is_tracepoint (left->owner))
12294 gdb_assert (!left->duplicate);
12295 if (is_tracepoint (right->owner))
12296 gdb_assert (!right->duplicate);
12298 left->inserted = right->inserted;
12299 left->duplicate = right->duplicate;
12300 left->needs_update = right->needs_update;
12301 left->target_info = right->target_info;
12302 right->inserted = left_inserted;
12303 right->duplicate = left_duplicate;
12304 right->needs_update = left_needs_update;
12305 right->target_info = left_target_info;
12308 /* Force the re-insertion of the locations at ADDRESS. This is called
12309 once a new/deleted/modified duplicate location is found and we are evaluating
12310 conditions on the target's side. Such conditions need to be updated on
12314 force_breakpoint_reinsertion (struct bp_location *bl)
12316 struct bp_location **locp = NULL, **loc2p;
12317 struct bp_location *loc;
12318 CORE_ADDR address = 0;
12321 address = bl->address;
12322 pspace_num = bl->pspace->num;
12324 /* This is only meaningful if the target is
12325 evaluating conditions and if the user has
12326 opted for condition evaluation on the target's
12328 if (gdb_evaluates_breakpoint_condition_p ()
12329 || !target_supports_evaluation_of_breakpoint_conditions ())
12332 /* Flag all breakpoint locations with this address and
12333 the same program space as the location
12334 as "its condition has changed". We need to
12335 update the conditions on the target's side. */
12336 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address)
12340 if (!is_breakpoint (loc->owner)
12341 || pspace_num != loc->pspace->num)
12344 /* Flag the location appropriately. We use a different state to
12345 let everyone know that we already updated the set of locations
12346 with addr bl->address and program space bl->pspace. This is so
12347 we don't have to keep calling these functions just to mark locations
12348 that have already been marked. */
12349 loc->condition_changed = condition_updated;
12351 /* Free the agent expression bytecode as well. We will compute
12353 if (loc->cond_bytecode)
12355 free_agent_expr (loc->cond_bytecode);
12356 loc->cond_bytecode = NULL;
12361 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
12362 into the inferior, only remove already-inserted locations that no
12363 longer should be inserted. Functions that delete a breakpoint or
12364 breakpoints should pass false, so that deleting a breakpoint
12365 doesn't have the side effect of inserting the locations of other
12366 breakpoints that are marked not-inserted, but should_be_inserted
12367 returns true on them.
12369 This behaviour is useful is situations close to tear-down -- e.g.,
12370 after an exec, while the target still has execution, but breakpoint
12371 shadows of the previous executable image should *NOT* be restored
12372 to the new image; or before detaching, where the target still has
12373 execution and wants to delete breakpoints from GDB's lists, and all
12374 breakpoints had already been removed from the inferior. */
12377 update_global_location_list (int should_insert)
12379 struct breakpoint *b;
12380 struct bp_location **locp, *loc;
12381 struct cleanup *cleanups;
12382 /* Last breakpoint location address that was marked for update. */
12383 CORE_ADDR last_addr = 0;
12384 /* Last breakpoint location program space that was marked for update. */
12385 int last_pspace_num = -1;
12387 /* Used in the duplicates detection below. When iterating over all
12388 bp_locations, points to the first bp_location of a given address.
12389 Breakpoints and watchpoints of different types are never
12390 duplicates of each other. Keep one pointer for each type of
12391 breakpoint/watchpoint, so we only need to loop over all locations
12393 struct bp_location *bp_loc_first; /* breakpoint */
12394 struct bp_location *wp_loc_first; /* hardware watchpoint */
12395 struct bp_location *awp_loc_first; /* access watchpoint */
12396 struct bp_location *rwp_loc_first; /* read watchpoint */
12398 /* Saved former bp_location array which we compare against the newly
12399 built bp_location from the current state of ALL_BREAKPOINTS. */
12400 struct bp_location **old_location, **old_locp;
12401 unsigned old_location_count;
12403 old_location = bp_location;
12404 old_location_count = bp_location_count;
12405 bp_location = NULL;
12406 bp_location_count = 0;
12407 cleanups = make_cleanup (xfree, old_location);
12409 ALL_BREAKPOINTS (b)
12410 for (loc = b->loc; loc; loc = loc->next)
12411 bp_location_count++;
12413 bp_location = xmalloc (sizeof (*bp_location) * bp_location_count);
12414 locp = bp_location;
12415 ALL_BREAKPOINTS (b)
12416 for (loc = b->loc; loc; loc = loc->next)
12418 qsort (bp_location, bp_location_count, sizeof (*bp_location),
12419 bp_location_compare);
12421 bp_location_target_extensions_update ();
12423 /* Identify bp_location instances that are no longer present in the
12424 new list, and therefore should be freed. Note that it's not
12425 necessary that those locations should be removed from inferior --
12426 if there's another location at the same address (previously
12427 marked as duplicate), we don't need to remove/insert the
12430 LOCP is kept in sync with OLD_LOCP, each pointing to the current
12431 and former bp_location array state respectively. */
12433 locp = bp_location;
12434 for (old_locp = old_location; old_locp < old_location + old_location_count;
12437 struct bp_location *old_loc = *old_locp;
12438 struct bp_location **loc2p;
12440 /* Tells if 'old_loc' is found among the new locations. If
12441 not, we have to free it. */
12442 int found_object = 0;
12443 /* Tells if the location should remain inserted in the target. */
12444 int keep_in_target = 0;
12447 /* Skip LOCP entries which will definitely never be needed.
12448 Stop either at or being the one matching OLD_LOC. */
12449 while (locp < bp_location + bp_location_count
12450 && (*locp)->address < old_loc->address)
12454 (loc2p < bp_location + bp_location_count
12455 && (*loc2p)->address == old_loc->address);
12458 /* Check if this is a new/duplicated location or a duplicated
12459 location that had its condition modified. If so, we want to send
12460 its condition to the target if evaluation of conditions is taking
12462 if ((*loc2p)->condition_changed == condition_modified
12463 && (last_addr != old_loc->address
12464 || last_pspace_num != old_loc->pspace->num))
12466 force_breakpoint_reinsertion (*loc2p);
12467 last_pspace_num = old_loc->pspace->num;
12470 if (*loc2p == old_loc)
12474 /* We have already handled this address, update it so that we don't
12475 have to go through updates again. */
12476 last_addr = old_loc->address;
12478 /* Target-side condition evaluation: Handle deleted locations. */
12480 force_breakpoint_reinsertion (old_loc);
12482 /* If this location is no longer present, and inserted, look if
12483 there's maybe a new location at the same address. If so,
12484 mark that one inserted, and don't remove this one. This is
12485 needed so that we don't have a time window where a breakpoint
12486 at certain location is not inserted. */
12488 if (old_loc->inserted)
12490 /* If the location is inserted now, we might have to remove
12493 if (found_object && should_be_inserted (old_loc))
12495 /* The location is still present in the location list,
12496 and still should be inserted. Don't do anything. */
12497 keep_in_target = 1;
12501 /* This location still exists, but it won't be kept in the
12502 target since it may have been disabled. We proceed to
12503 remove its target-side condition. */
12505 /* The location is either no longer present, or got
12506 disabled. See if there's another location at the
12507 same address, in which case we don't need to remove
12508 this one from the target. */
12510 /* OLD_LOC comes from existing struct breakpoint. */
12511 if (breakpoint_address_is_meaningful (old_loc->owner))
12514 (loc2p < bp_location + bp_location_count
12515 && (*loc2p)->address == old_loc->address);
12518 struct bp_location *loc2 = *loc2p;
12520 if (breakpoint_locations_match (loc2, old_loc))
12522 /* Read watchpoint locations are switched to
12523 access watchpoints, if the former are not
12524 supported, but the latter are. */
12525 if (is_hardware_watchpoint (old_loc->owner))
12527 gdb_assert (is_hardware_watchpoint (loc2->owner));
12528 loc2->watchpoint_type = old_loc->watchpoint_type;
12531 /* loc2 is a duplicated location. We need to check
12532 if it should be inserted in case it will be
12534 if (loc2 != old_loc
12535 && unduplicated_should_be_inserted (loc2))
12537 swap_insertion (old_loc, loc2);
12538 keep_in_target = 1;
12546 if (!keep_in_target)
12548 if (remove_breakpoint (old_loc, mark_uninserted))
12550 /* This is just about all we can do. We could keep
12551 this location on the global list, and try to
12552 remove it next time, but there's no particular
12553 reason why we will succeed next time.
12555 Note that at this point, old_loc->owner is still
12556 valid, as delete_breakpoint frees the breakpoint
12557 only after calling us. */
12558 printf_filtered (_("warning: Error removing "
12559 "breakpoint %d\n"),
12560 old_loc->owner->number);
12568 if (removed && non_stop
12569 && breakpoint_address_is_meaningful (old_loc->owner)
12570 && !is_hardware_watchpoint (old_loc->owner))
12572 /* This location was removed from the target. In
12573 non-stop mode, a race condition is possible where
12574 we've removed a breakpoint, but stop events for that
12575 breakpoint are already queued and will arrive later.
12576 We apply an heuristic to be able to distinguish such
12577 SIGTRAPs from other random SIGTRAPs: we keep this
12578 breakpoint location for a bit, and will retire it
12579 after we see some number of events. The theory here
12580 is that reporting of events should, "on the average",
12581 be fair, so after a while we'll see events from all
12582 threads that have anything of interest, and no longer
12583 need to keep this breakpoint location around. We
12584 don't hold locations forever so to reduce chances of
12585 mistaking a non-breakpoint SIGTRAP for a breakpoint
12588 The heuristic failing can be disastrous on
12589 decr_pc_after_break targets.
12591 On decr_pc_after_break targets, like e.g., x86-linux,
12592 if we fail to recognize a late breakpoint SIGTRAP,
12593 because events_till_retirement has reached 0 too
12594 soon, we'll fail to do the PC adjustment, and report
12595 a random SIGTRAP to the user. When the user resumes
12596 the inferior, it will most likely immediately crash
12597 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12598 corrupted, because of being resumed e.g., in the
12599 middle of a multi-byte instruction, or skipped a
12600 one-byte instruction. This was actually seen happen
12601 on native x86-linux, and should be less rare on
12602 targets that do not support new thread events, like
12603 remote, due to the heuristic depending on
12606 Mistaking a random SIGTRAP for a breakpoint trap
12607 causes similar symptoms (PC adjustment applied when
12608 it shouldn't), but then again, playing with SIGTRAPs
12609 behind the debugger's back is asking for trouble.
12611 Since hardware watchpoint traps are always
12612 distinguishable from other traps, so we don't need to
12613 apply keep hardware watchpoint moribund locations
12614 around. We simply always ignore hardware watchpoint
12615 traps we can no longer explain. */
12617 old_loc->events_till_retirement = 3 * (thread_count () + 1);
12618 old_loc->owner = NULL;
12620 VEC_safe_push (bp_location_p, moribund_locations, old_loc);
12624 old_loc->owner = NULL;
12625 decref_bp_location (&old_loc);
12630 /* Rescan breakpoints at the same address and section, marking the
12631 first one as "first" and any others as "duplicates". This is so
12632 that the bpt instruction is only inserted once. If we have a
12633 permanent breakpoint at the same place as BPT, make that one the
12634 official one, and the rest as duplicates. Permanent breakpoints
12635 are sorted first for the same address.
12637 Do the same for hardware watchpoints, but also considering the
12638 watchpoint's type (regular/access/read) and length. */
12640 bp_loc_first = NULL;
12641 wp_loc_first = NULL;
12642 awp_loc_first = NULL;
12643 rwp_loc_first = NULL;
12644 ALL_BP_LOCATIONS (loc, locp)
12646 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12648 struct bp_location **loc_first_p;
12651 if (!unduplicated_should_be_inserted (loc)
12652 || !breakpoint_address_is_meaningful (b)
12653 /* Don't detect duplicate for tracepoint locations because they are
12654 never duplicated. See the comments in field `duplicate' of
12655 `struct bp_location'. */
12656 || is_tracepoint (b))
12658 /* Clear the condition modification flag. */
12659 loc->condition_changed = condition_unchanged;
12663 /* Permanent breakpoint should always be inserted. */
12664 if (b->enable_state == bp_permanent && ! loc->inserted)
12665 internal_error (__FILE__, __LINE__,
12666 _("allegedly permanent breakpoint is not "
12667 "actually inserted"));
12669 if (b->type == bp_hardware_watchpoint)
12670 loc_first_p = &wp_loc_first;
12671 else if (b->type == bp_read_watchpoint)
12672 loc_first_p = &rwp_loc_first;
12673 else if (b->type == bp_access_watchpoint)
12674 loc_first_p = &awp_loc_first;
12676 loc_first_p = &bp_loc_first;
12678 if (*loc_first_p == NULL
12679 || (overlay_debugging && loc->section != (*loc_first_p)->section)
12680 || !breakpoint_locations_match (loc, *loc_first_p))
12682 *loc_first_p = loc;
12683 loc->duplicate = 0;
12685 if (is_breakpoint (loc->owner) && loc->condition_changed)
12687 loc->needs_update = 1;
12688 /* Clear the condition modification flag. */
12689 loc->condition_changed = condition_unchanged;
12695 /* This and the above ensure the invariant that the first location
12696 is not duplicated, and is the inserted one.
12697 All following are marked as duplicated, and are not inserted. */
12699 swap_insertion (loc, *loc_first_p);
12700 loc->duplicate = 1;
12702 /* Clear the condition modification flag. */
12703 loc->condition_changed = condition_unchanged;
12705 if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted
12706 && b->enable_state != bp_permanent)
12707 internal_error (__FILE__, __LINE__,
12708 _("another breakpoint was inserted on top of "
12709 "a permanent breakpoint"));
12712 if (breakpoints_always_inserted_mode ()
12713 && (have_live_inferiors ()
12714 || (gdbarch_has_global_breakpoints (target_gdbarch ()))))
12717 insert_breakpoint_locations ();
12720 /* Though should_insert is false, we may need to update conditions
12721 on the target's side if it is evaluating such conditions. We
12722 only update conditions for locations that are marked
12724 update_inserted_breakpoint_locations ();
12729 download_tracepoint_locations ();
12731 do_cleanups (cleanups);
12735 breakpoint_retire_moribund (void)
12737 struct bp_location *loc;
12740 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
12741 if (--(loc->events_till_retirement) == 0)
12743 decref_bp_location (&loc);
12744 VEC_unordered_remove (bp_location_p, moribund_locations, ix);
12750 update_global_location_list_nothrow (int inserting)
12752 volatile struct gdb_exception e;
12754 TRY_CATCH (e, RETURN_MASK_ERROR)
12755 update_global_location_list (inserting);
12758 /* Clear BKP from a BPS. */
12761 bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt)
12765 for (bs = bps; bs; bs = bs->next)
12766 if (bs->breakpoint_at == bpt)
12768 bs->breakpoint_at = NULL;
12769 bs->old_val = NULL;
12770 /* bs->commands will be freed later. */
12774 /* Callback for iterate_over_threads. */
12776 bpstat_remove_breakpoint_callback (struct thread_info *th, void *data)
12778 struct breakpoint *bpt = data;
12780 bpstat_remove_bp_location (th->control.stop_bpstat, bpt);
12784 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12788 say_where (struct breakpoint *b)
12790 struct value_print_options opts;
12792 get_user_print_options (&opts);
12794 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12796 if (b->loc == NULL)
12798 printf_filtered (_(" (%s) pending."), b->addr_string);
12802 if (opts.addressprint || b->loc->symtab == NULL)
12804 printf_filtered (" at ");
12805 fputs_filtered (paddress (b->loc->gdbarch, b->loc->address),
12808 if (b->loc->symtab != NULL)
12810 /* If there is a single location, we can print the location
12812 if (b->loc->next == NULL)
12813 printf_filtered (": file %s, line %d.",
12814 symtab_to_filename_for_display (b->loc->symtab),
12815 b->loc->line_number);
12817 /* This is not ideal, but each location may have a
12818 different file name, and this at least reflects the
12819 real situation somewhat. */
12820 printf_filtered (": %s.", b->addr_string);
12825 struct bp_location *loc = b->loc;
12827 for (; loc; loc = loc->next)
12829 printf_filtered (" (%d locations)", n);
12834 /* Default bp_location_ops methods. */
12837 bp_location_dtor (struct bp_location *self)
12839 xfree (self->cond);
12840 if (self->cond_bytecode)
12841 free_agent_expr (self->cond_bytecode);
12842 xfree (self->function_name);
12845 static const struct bp_location_ops bp_location_ops =
12850 /* Default breakpoint_ops methods all breakpoint_ops ultimately
12854 base_breakpoint_dtor (struct breakpoint *self)
12856 decref_counted_command_line (&self->commands);
12857 xfree (self->cond_string);
12858 xfree (self->extra_string);
12859 xfree (self->addr_string);
12860 xfree (self->filter);
12861 xfree (self->addr_string_range_end);
12864 static struct bp_location *
12865 base_breakpoint_allocate_location (struct breakpoint *self)
12867 struct bp_location *loc;
12869 loc = XNEW (struct bp_location);
12870 init_bp_location (loc, &bp_location_ops, self);
12875 base_breakpoint_re_set (struct breakpoint *b)
12877 /* Nothing to re-set. */
12880 #define internal_error_pure_virtual_called() \
12881 gdb_assert_not_reached ("pure virtual function called")
12884 base_breakpoint_insert_location (struct bp_location *bl)
12886 internal_error_pure_virtual_called ();
12890 base_breakpoint_remove_location (struct bp_location *bl)
12892 internal_error_pure_virtual_called ();
12896 base_breakpoint_breakpoint_hit (const struct bp_location *bl,
12897 struct address_space *aspace,
12899 const struct target_waitstatus *ws)
12901 internal_error_pure_virtual_called ();
12905 base_breakpoint_check_status (bpstat bs)
12910 /* A "works_in_software_mode" breakpoint_ops method that just internal
12914 base_breakpoint_works_in_software_mode (const struct breakpoint *b)
12916 internal_error_pure_virtual_called ();
12919 /* A "resources_needed" breakpoint_ops method that just internal
12923 base_breakpoint_resources_needed (const struct bp_location *bl)
12925 internal_error_pure_virtual_called ();
12928 static enum print_stop_action
12929 base_breakpoint_print_it (bpstat bs)
12931 internal_error_pure_virtual_called ();
12935 base_breakpoint_print_one_detail (const struct breakpoint *self,
12936 struct ui_out *uiout)
12942 base_breakpoint_print_mention (struct breakpoint *b)
12944 internal_error_pure_virtual_called ();
12948 base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp)
12950 internal_error_pure_virtual_called ();
12954 base_breakpoint_create_sals_from_address (char **arg,
12955 struct linespec_result *canonical,
12956 enum bptype type_wanted,
12960 internal_error_pure_virtual_called ();
12964 base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch,
12965 struct linespec_result *c,
12966 struct linespec_sals *lsal,
12968 char *extra_string,
12969 enum bptype type_wanted,
12970 enum bpdisp disposition,
12972 int task, int ignore_count,
12973 const struct breakpoint_ops *o,
12974 int from_tty, int enabled,
12975 int internal, unsigned flags)
12977 internal_error_pure_virtual_called ();
12981 base_breakpoint_decode_linespec (struct breakpoint *b, char **s,
12982 struct symtabs_and_lines *sals)
12984 internal_error_pure_virtual_called ();
12987 /* The default 'explains_signal' method. */
12989 static enum bpstat_signal_value
12990 base_breakpoint_explains_signal (struct breakpoint *b)
12992 return BPSTAT_SIGNAL_HIDE;
12995 struct breakpoint_ops base_breakpoint_ops =
12997 base_breakpoint_dtor,
12998 base_breakpoint_allocate_location,
12999 base_breakpoint_re_set,
13000 base_breakpoint_insert_location,
13001 base_breakpoint_remove_location,
13002 base_breakpoint_breakpoint_hit,
13003 base_breakpoint_check_status,
13004 base_breakpoint_resources_needed,
13005 base_breakpoint_works_in_software_mode,
13006 base_breakpoint_print_it,
13008 base_breakpoint_print_one_detail,
13009 base_breakpoint_print_mention,
13010 base_breakpoint_print_recreate,
13011 base_breakpoint_create_sals_from_address,
13012 base_breakpoint_create_breakpoints_sal,
13013 base_breakpoint_decode_linespec,
13014 base_breakpoint_explains_signal
13017 /* Default breakpoint_ops methods. */
13020 bkpt_re_set (struct breakpoint *b)
13022 /* FIXME: is this still reachable? */
13023 if (b->addr_string == NULL)
13025 /* Anything without a string can't be re-set. */
13026 delete_breakpoint (b);
13030 breakpoint_re_set_default (b);
13034 bkpt_insert_location (struct bp_location *bl)
13036 if (bl->loc_type == bp_loc_hardware_breakpoint)
13037 return target_insert_hw_breakpoint (bl->gdbarch,
13040 return target_insert_breakpoint (bl->gdbarch,
13045 bkpt_remove_location (struct bp_location *bl)
13047 if (bl->loc_type == bp_loc_hardware_breakpoint)
13048 return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info);
13050 return target_remove_breakpoint (bl->gdbarch, &bl->target_info);
13054 bkpt_breakpoint_hit (const struct bp_location *bl,
13055 struct address_space *aspace, CORE_ADDR bp_addr,
13056 const struct target_waitstatus *ws)
13058 if (ws->kind != TARGET_WAITKIND_STOPPED
13059 || ws->value.sig != GDB_SIGNAL_TRAP)
13062 if (!breakpoint_address_match (bl->pspace->aspace, bl->address,
13066 if (overlay_debugging /* unmapped overlay section */
13067 && section_is_overlay (bl->section)
13068 && !section_is_mapped (bl->section))
13075 bkpt_resources_needed (const struct bp_location *bl)
13077 gdb_assert (bl->owner->type == bp_hardware_breakpoint);
13082 static enum print_stop_action
13083 bkpt_print_it (bpstat bs)
13085 struct breakpoint *b;
13086 const struct bp_location *bl;
13088 struct ui_out *uiout = current_uiout;
13090 gdb_assert (bs->bp_location_at != NULL);
13092 bl = bs->bp_location_at;
13093 b = bs->breakpoint_at;
13095 bp_temp = b->disposition == disp_del;
13096 if (bl->address != bl->requested_address)
13097 breakpoint_adjustment_warning (bl->requested_address,
13100 annotate_breakpoint (b->number);
13102 ui_out_text (uiout, "\nTemporary breakpoint ");
13104 ui_out_text (uiout, "\nBreakpoint ");
13105 if (ui_out_is_mi_like_p (uiout))
13107 ui_out_field_string (uiout, "reason",
13108 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
13109 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
13111 ui_out_field_int (uiout, "bkptno", b->number);
13112 ui_out_text (uiout, ", ");
13114 return PRINT_SRC_AND_LOC;
13118 bkpt_print_mention (struct breakpoint *b)
13120 if (ui_out_is_mi_like_p (current_uiout))
13125 case bp_breakpoint:
13126 case bp_gnu_ifunc_resolver:
13127 if (b->disposition == disp_del)
13128 printf_filtered (_("Temporary breakpoint"));
13130 printf_filtered (_("Breakpoint"));
13131 printf_filtered (_(" %d"), b->number);
13132 if (b->type == bp_gnu_ifunc_resolver)
13133 printf_filtered (_(" at gnu-indirect-function resolver"));
13135 case bp_hardware_breakpoint:
13136 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
13139 printf_filtered (_("Dprintf %d"), b->number);
13147 bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp)
13149 if (tp->type == bp_breakpoint && tp->disposition == disp_del)
13150 fprintf_unfiltered (fp, "tbreak");
13151 else if (tp->type == bp_breakpoint)
13152 fprintf_unfiltered (fp, "break");
13153 else if (tp->type == bp_hardware_breakpoint
13154 && tp->disposition == disp_del)
13155 fprintf_unfiltered (fp, "thbreak");
13156 else if (tp->type == bp_hardware_breakpoint)
13157 fprintf_unfiltered (fp, "hbreak");
13159 internal_error (__FILE__, __LINE__,
13160 _("unhandled breakpoint type %d"), (int) tp->type);
13162 fprintf_unfiltered (fp, " %s", tp->addr_string);
13163 print_recreate_thread (tp, fp);
13167 bkpt_create_sals_from_address (char **arg,
13168 struct linespec_result *canonical,
13169 enum bptype type_wanted,
13170 char *addr_start, char **copy_arg)
13172 create_sals_from_address_default (arg, canonical, type_wanted,
13173 addr_start, copy_arg);
13177 bkpt_create_breakpoints_sal (struct gdbarch *gdbarch,
13178 struct linespec_result *canonical,
13179 struct linespec_sals *lsal,
13181 char *extra_string,
13182 enum bptype type_wanted,
13183 enum bpdisp disposition,
13185 int task, int ignore_count,
13186 const struct breakpoint_ops *ops,
13187 int from_tty, int enabled,
13188 int internal, unsigned flags)
13190 create_breakpoints_sal_default (gdbarch, canonical, lsal,
13191 cond_string, extra_string,
13193 disposition, thread, task,
13194 ignore_count, ops, from_tty,
13195 enabled, internal, flags);
13199 bkpt_decode_linespec (struct breakpoint *b, char **s,
13200 struct symtabs_and_lines *sals)
13202 decode_linespec_default (b, s, sals);
13205 /* Virtual table for internal breakpoints. */
13208 internal_bkpt_re_set (struct breakpoint *b)
13212 /* Delete overlay event and longjmp master breakpoints; they
13213 will be reset later by breakpoint_re_set. */
13214 case bp_overlay_event:
13215 case bp_longjmp_master:
13216 case bp_std_terminate_master:
13217 case bp_exception_master:
13218 delete_breakpoint (b);
13221 /* This breakpoint is special, it's set up when the inferior
13222 starts and we really don't want to touch it. */
13223 case bp_shlib_event:
13225 /* Like bp_shlib_event, this breakpoint type is special. Once
13226 it is set up, we do not want to touch it. */
13227 case bp_thread_event:
13233 internal_bkpt_check_status (bpstat bs)
13235 if (bs->breakpoint_at->type == bp_shlib_event)
13237 /* If requested, stop when the dynamic linker notifies GDB of
13238 events. This allows the user to get control and place
13239 breakpoints in initializer routines for dynamically loaded
13240 objects (among other things). */
13241 bs->stop = stop_on_solib_events;
13242 bs->print = stop_on_solib_events;
13248 static enum print_stop_action
13249 internal_bkpt_print_it (bpstat bs)
13251 struct breakpoint *b;
13253 b = bs->breakpoint_at;
13257 case bp_shlib_event:
13258 /* Did we stop because the user set the stop_on_solib_events
13259 variable? (If so, we report this as a generic, "Stopped due
13260 to shlib event" message.) */
13261 print_solib_event (0);
13264 case bp_thread_event:
13265 /* Not sure how we will get here.
13266 GDB should not stop for these breakpoints. */
13267 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
13270 case bp_overlay_event:
13271 /* By analogy with the thread event, GDB should not stop for these. */
13272 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
13275 case bp_longjmp_master:
13276 /* These should never be enabled. */
13277 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
13280 case bp_std_terminate_master:
13281 /* These should never be enabled. */
13282 printf_filtered (_("std::terminate Master Breakpoint: "
13283 "gdb should not stop!\n"));
13286 case bp_exception_master:
13287 /* These should never be enabled. */
13288 printf_filtered (_("Exception Master Breakpoint: "
13289 "gdb should not stop!\n"));
13293 return PRINT_NOTHING;
13297 internal_bkpt_print_mention (struct breakpoint *b)
13299 /* Nothing to mention. These breakpoints are internal. */
13302 /* Virtual table for momentary breakpoints */
13305 momentary_bkpt_re_set (struct breakpoint *b)
13307 /* Keep temporary breakpoints, which can be encountered when we step
13308 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
13309 Otherwise these should have been blown away via the cleanup chain
13310 or by breakpoint_init_inferior when we rerun the executable. */
13314 momentary_bkpt_check_status (bpstat bs)
13316 /* Nothing. The point of these breakpoints is causing a stop. */
13319 static enum print_stop_action
13320 momentary_bkpt_print_it (bpstat bs)
13322 struct ui_out *uiout = current_uiout;
13324 if (ui_out_is_mi_like_p (uiout))
13326 struct breakpoint *b = bs->breakpoint_at;
13331 ui_out_field_string
13333 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED));
13337 ui_out_field_string
13339 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED));
13344 return PRINT_UNKNOWN;
13348 momentary_bkpt_print_mention (struct breakpoint *b)
13350 /* Nothing to mention. These breakpoints are internal. */
13353 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
13355 It gets cleared already on the removal of the first one of such placed
13356 breakpoints. This is OK as they get all removed altogether. */
13359 longjmp_bkpt_dtor (struct breakpoint *self)
13361 struct thread_info *tp = find_thread_id (self->thread);
13364 tp->initiating_frame = null_frame_id;
13366 momentary_breakpoint_ops.dtor (self);
13369 /* Specific methods for probe breakpoints. */
13372 bkpt_probe_insert_location (struct bp_location *bl)
13374 int v = bkpt_insert_location (bl);
13378 /* The insertion was successful, now let's set the probe's semaphore
13380 bl->probe->pops->set_semaphore (bl->probe, bl->gdbarch);
13387 bkpt_probe_remove_location (struct bp_location *bl)
13389 /* Let's clear the semaphore before removing the location. */
13390 bl->probe->pops->clear_semaphore (bl->probe, bl->gdbarch);
13392 return bkpt_remove_location (bl);
13396 bkpt_probe_create_sals_from_address (char **arg,
13397 struct linespec_result *canonical,
13398 enum bptype type_wanted,
13399 char *addr_start, char **copy_arg)
13401 struct linespec_sals lsal;
13403 lsal.sals = parse_probes (arg, canonical);
13405 *copy_arg = xstrdup (canonical->addr_string);
13406 lsal.canonical = xstrdup (*copy_arg);
13408 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
13412 bkpt_probe_decode_linespec (struct breakpoint *b, char **s,
13413 struct symtabs_and_lines *sals)
13415 *sals = parse_probes (s, NULL);
13417 error (_("probe not found"));
13420 /* The breakpoint_ops structure to be used in tracepoints. */
13423 tracepoint_re_set (struct breakpoint *b)
13425 breakpoint_re_set_default (b);
13429 tracepoint_breakpoint_hit (const struct bp_location *bl,
13430 struct address_space *aspace, CORE_ADDR bp_addr,
13431 const struct target_waitstatus *ws)
13433 /* By definition, the inferior does not report stops at
13439 tracepoint_print_one_detail (const struct breakpoint *self,
13440 struct ui_out *uiout)
13442 struct tracepoint *tp = (struct tracepoint *) self;
13443 if (tp->static_trace_marker_id)
13445 gdb_assert (self->type == bp_static_tracepoint);
13447 ui_out_text (uiout, "\tmarker id is ");
13448 ui_out_field_string (uiout, "static-tracepoint-marker-string-id",
13449 tp->static_trace_marker_id);
13450 ui_out_text (uiout, "\n");
13455 tracepoint_print_mention (struct breakpoint *b)
13457 if (ui_out_is_mi_like_p (current_uiout))
13462 case bp_tracepoint:
13463 printf_filtered (_("Tracepoint"));
13464 printf_filtered (_(" %d"), b->number);
13466 case bp_fast_tracepoint:
13467 printf_filtered (_("Fast tracepoint"));
13468 printf_filtered (_(" %d"), b->number);
13470 case bp_static_tracepoint:
13471 printf_filtered (_("Static tracepoint"));
13472 printf_filtered (_(" %d"), b->number);
13475 internal_error (__FILE__, __LINE__,
13476 _("unhandled tracepoint type %d"), (int) b->type);
13483 tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp)
13485 struct tracepoint *tp = (struct tracepoint *) self;
13487 if (self->type == bp_fast_tracepoint)
13488 fprintf_unfiltered (fp, "ftrace");
13489 if (self->type == bp_static_tracepoint)
13490 fprintf_unfiltered (fp, "strace");
13491 else if (self->type == bp_tracepoint)
13492 fprintf_unfiltered (fp, "trace");
13494 internal_error (__FILE__, __LINE__,
13495 _("unhandled tracepoint type %d"), (int) self->type);
13497 fprintf_unfiltered (fp, " %s", self->addr_string);
13498 print_recreate_thread (self, fp);
13500 if (tp->pass_count)
13501 fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count);
13505 tracepoint_create_sals_from_address (char **arg,
13506 struct linespec_result *canonical,
13507 enum bptype type_wanted,
13508 char *addr_start, char **copy_arg)
13510 create_sals_from_address_default (arg, canonical, type_wanted,
13511 addr_start, copy_arg);
13515 tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch,
13516 struct linespec_result *canonical,
13517 struct linespec_sals *lsal,
13519 char *extra_string,
13520 enum bptype type_wanted,
13521 enum bpdisp disposition,
13523 int task, int ignore_count,
13524 const struct breakpoint_ops *ops,
13525 int from_tty, int enabled,
13526 int internal, unsigned flags)
13528 create_breakpoints_sal_default (gdbarch, canonical, lsal,
13529 cond_string, extra_string,
13531 disposition, thread, task,
13532 ignore_count, ops, from_tty,
13533 enabled, internal, flags);
13537 tracepoint_decode_linespec (struct breakpoint *b, char **s,
13538 struct symtabs_and_lines *sals)
13540 decode_linespec_default (b, s, sals);
13543 struct breakpoint_ops tracepoint_breakpoint_ops;
13545 /* The breakpoint_ops structure to be use on tracepoints placed in a
13549 tracepoint_probe_create_sals_from_address (char **arg,
13550 struct linespec_result *canonical,
13551 enum bptype type_wanted,
13552 char *addr_start, char **copy_arg)
13554 /* We use the same method for breakpoint on probes. */
13555 bkpt_probe_create_sals_from_address (arg, canonical, type_wanted,
13556 addr_start, copy_arg);
13560 tracepoint_probe_decode_linespec (struct breakpoint *b, char **s,
13561 struct symtabs_and_lines *sals)
13563 /* We use the same method for breakpoint on probes. */
13564 bkpt_probe_decode_linespec (b, s, sals);
13567 static struct breakpoint_ops tracepoint_probe_breakpoint_ops;
13569 /* Dprintf breakpoint_ops methods. */
13572 dprintf_re_set (struct breakpoint *b)
13574 breakpoint_re_set_default (b);
13576 /* This breakpoint could have been pending, and be resolved now, and
13577 if so, we should now have the extra string. If we don't, the
13578 dprintf was malformed when created, but we couldn't tell because
13579 we can't extract the extra string until the location is
13581 if (b->loc != NULL && b->extra_string == NULL)
13582 error (_("Format string required"));
13584 /* 1 - connect to target 1, that can run breakpoint commands.
13585 2 - create a dprintf, which resolves fine.
13586 3 - disconnect from target 1
13587 4 - connect to target 2, that can NOT run breakpoint commands.
13589 After steps #3/#4, you'll want the dprintf command list to
13590 be updated, because target 1 and 2 may well return different
13591 answers for target_can_run_breakpoint_commands().
13592 Given absence of finer grained resetting, we get to do
13593 it all the time. */
13594 if (b->extra_string != NULL)
13595 update_dprintf_command_list (b);
13598 /* The breakpoint_ops structure to be used on static tracepoints with
13602 strace_marker_create_sals_from_address (char **arg,
13603 struct linespec_result *canonical,
13604 enum bptype type_wanted,
13605 char *addr_start, char **copy_arg)
13607 struct linespec_sals lsal;
13609 lsal.sals = decode_static_tracepoint_spec (arg);
13611 *copy_arg = savestring (addr_start, *arg - addr_start);
13613 canonical->addr_string = xstrdup (*copy_arg);
13614 lsal.canonical = xstrdup (*copy_arg);
13615 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
13619 strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch,
13620 struct linespec_result *canonical,
13621 struct linespec_sals *lsal,
13623 char *extra_string,
13624 enum bptype type_wanted,
13625 enum bpdisp disposition,
13627 int task, int ignore_count,
13628 const struct breakpoint_ops *ops,
13629 int from_tty, int enabled,
13630 int internal, unsigned flags)
13634 /* If the user is creating a static tracepoint by marker id
13635 (strace -m MARKER_ID), then store the sals index, so that
13636 breakpoint_re_set can try to match up which of the newly
13637 found markers corresponds to this one, and, don't try to
13638 expand multiple locations for each sal, given than SALS
13639 already should contain all sals for MARKER_ID. */
13641 for (i = 0; i < lsal->sals.nelts; ++i)
13643 struct symtabs_and_lines expanded;
13644 struct tracepoint *tp;
13645 struct cleanup *old_chain;
13648 expanded.nelts = 1;
13649 expanded.sals = &lsal->sals.sals[i];
13651 addr_string = xstrdup (canonical->addr_string);
13652 old_chain = make_cleanup (xfree, addr_string);
13654 tp = XCNEW (struct tracepoint);
13655 init_breakpoint_sal (&tp->base, gdbarch, expanded,
13657 cond_string, extra_string,
13658 type_wanted, disposition,
13659 thread, task, ignore_count, ops,
13660 from_tty, enabled, internal, flags,
13661 canonical->special_display);
13662 /* Given that its possible to have multiple markers with
13663 the same string id, if the user is creating a static
13664 tracepoint by marker id ("strace -m MARKER_ID"), then
13665 store the sals index, so that breakpoint_re_set can
13666 try to match up which of the newly found markers
13667 corresponds to this one */
13668 tp->static_trace_marker_id_idx = i;
13670 install_breakpoint (internal, &tp->base, 0);
13672 discard_cleanups (old_chain);
13677 strace_marker_decode_linespec (struct breakpoint *b, char **s,
13678 struct symtabs_and_lines *sals)
13680 struct tracepoint *tp = (struct tracepoint *) b;
13682 *sals = decode_static_tracepoint_spec (s);
13683 if (sals->nelts > tp->static_trace_marker_id_idx)
13685 sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx];
13689 error (_("marker %s not found"), tp->static_trace_marker_id);
13692 static struct breakpoint_ops strace_marker_breakpoint_ops;
13695 strace_marker_p (struct breakpoint *b)
13697 return b->ops == &strace_marker_breakpoint_ops;
13700 /* Delete a breakpoint and clean up all traces of it in the data
13704 delete_breakpoint (struct breakpoint *bpt)
13706 struct breakpoint *b;
13708 gdb_assert (bpt != NULL);
13710 /* Has this bp already been deleted? This can happen because
13711 multiple lists can hold pointers to bp's. bpstat lists are
13714 One example of this happening is a watchpoint's scope bp. When
13715 the scope bp triggers, we notice that the watchpoint is out of
13716 scope, and delete it. We also delete its scope bp. But the
13717 scope bp is marked "auto-deleting", and is already on a bpstat.
13718 That bpstat is then checked for auto-deleting bp's, which are
13721 A real solution to this problem might involve reference counts in
13722 bp's, and/or giving them pointers back to their referencing
13723 bpstat's, and teaching delete_breakpoint to only free a bp's
13724 storage when no more references were extent. A cheaper bandaid
13726 if (bpt->type == bp_none)
13729 /* At least avoid this stale reference until the reference counting
13730 of breakpoints gets resolved. */
13731 if (bpt->related_breakpoint != bpt)
13733 struct breakpoint *related;
13734 struct watchpoint *w;
13736 if (bpt->type == bp_watchpoint_scope)
13737 w = (struct watchpoint *) bpt->related_breakpoint;
13738 else if (bpt->related_breakpoint->type == bp_watchpoint_scope)
13739 w = (struct watchpoint *) bpt;
13743 watchpoint_del_at_next_stop (w);
13745 /* Unlink bpt from the bpt->related_breakpoint ring. */
13746 for (related = bpt; related->related_breakpoint != bpt;
13747 related = related->related_breakpoint);
13748 related->related_breakpoint = bpt->related_breakpoint;
13749 bpt->related_breakpoint = bpt;
13752 /* watch_command_1 creates a watchpoint but only sets its number if
13753 update_watchpoint succeeds in creating its bp_locations. If there's
13754 a problem in that process, we'll be asked to delete the half-created
13755 watchpoint. In that case, don't announce the deletion. */
13757 observer_notify_breakpoint_deleted (bpt);
13759 if (breakpoint_chain == bpt)
13760 breakpoint_chain = bpt->next;
13762 ALL_BREAKPOINTS (b)
13763 if (b->next == bpt)
13765 b->next = bpt->next;
13769 /* Be sure no bpstat's are pointing at the breakpoint after it's
13771 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13772 in all threads for now. Note that we cannot just remove bpstats
13773 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13774 commands are associated with the bpstat; if we remove it here,
13775 then the later call to bpstat_do_actions (&stop_bpstat); in
13776 event-top.c won't do anything, and temporary breakpoints with
13777 commands won't work. */
13779 iterate_over_threads (bpstat_remove_breakpoint_callback, bpt);
13781 /* Now that breakpoint is removed from breakpoint list, update the
13782 global location list. This will remove locations that used to
13783 belong to this breakpoint. Do this before freeing the breakpoint
13784 itself, since remove_breakpoint looks at location's owner. It
13785 might be better design to have location completely
13786 self-contained, but it's not the case now. */
13787 update_global_location_list (0);
13789 bpt->ops->dtor (bpt);
13790 /* On the chance that someone will soon try again to delete this
13791 same bp, we mark it as deleted before freeing its storage. */
13792 bpt->type = bp_none;
13797 do_delete_breakpoint_cleanup (void *b)
13799 delete_breakpoint (b);
13803 make_cleanup_delete_breakpoint (struct breakpoint *b)
13805 return make_cleanup (do_delete_breakpoint_cleanup, b);
13808 /* Iterator function to call a user-provided callback function once
13809 for each of B and its related breakpoints. */
13812 iterate_over_related_breakpoints (struct breakpoint *b,
13813 void (*function) (struct breakpoint *,
13817 struct breakpoint *related;
13822 struct breakpoint *next;
13824 /* FUNCTION may delete RELATED. */
13825 next = related->related_breakpoint;
13827 if (next == related)
13829 /* RELATED is the last ring entry. */
13830 function (related, data);
13832 /* FUNCTION may have deleted it, so we'd never reach back to
13833 B. There's nothing left to do anyway, so just break
13838 function (related, data);
13842 while (related != b);
13846 do_delete_breakpoint (struct breakpoint *b, void *ignore)
13848 delete_breakpoint (b);
13851 /* A callback for map_breakpoint_numbers that calls
13852 delete_breakpoint. */
13855 do_map_delete_breakpoint (struct breakpoint *b, void *ignore)
13857 iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL);
13861 delete_command (char *arg, int from_tty)
13863 struct breakpoint *b, *b_tmp;
13869 int breaks_to_delete = 0;
13871 /* Delete all breakpoints if no argument. Do not delete
13872 internal breakpoints, these have to be deleted with an
13873 explicit breakpoint number argument. */
13874 ALL_BREAKPOINTS (b)
13875 if (user_breakpoint_p (b))
13877 breaks_to_delete = 1;
13881 /* Ask user only if there are some breakpoints to delete. */
13883 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
13885 ALL_BREAKPOINTS_SAFE (b, b_tmp)
13886 if (user_breakpoint_p (b))
13887 delete_breakpoint (b);
13891 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
13895 all_locations_are_pending (struct bp_location *loc)
13897 for (; loc; loc = loc->next)
13898 if (!loc->shlib_disabled
13899 && !loc->pspace->executing_startup)
13904 /* Subroutine of update_breakpoint_locations to simplify it.
13905 Return non-zero if multiple fns in list LOC have the same name.
13906 Null names are ignored. */
13909 ambiguous_names_p (struct bp_location *loc)
13911 struct bp_location *l;
13912 htab_t htab = htab_create_alloc (13, htab_hash_string,
13913 (int (*) (const void *,
13914 const void *)) streq,
13915 NULL, xcalloc, xfree);
13917 for (l = loc; l != NULL; l = l->next)
13920 const char *name = l->function_name;
13922 /* Allow for some names to be NULL, ignore them. */
13926 slot = (const char **) htab_find_slot (htab, (const void *) name,
13928 /* NOTE: We can assume slot != NULL here because xcalloc never
13932 htab_delete (htab);
13938 htab_delete (htab);
13942 /* When symbols change, it probably means the sources changed as well,
13943 and it might mean the static tracepoint markers are no longer at
13944 the same address or line numbers they used to be at last we
13945 checked. Losing your static tracepoints whenever you rebuild is
13946 undesirable. This function tries to resync/rematch gdb static
13947 tracepoints with the markers on the target, for static tracepoints
13948 that have not been set by marker id. Static tracepoint that have
13949 been set by marker id are reset by marker id in breakpoint_re_set.
13952 1) For a tracepoint set at a specific address, look for a marker at
13953 the old PC. If one is found there, assume to be the same marker.
13954 If the name / string id of the marker found is different from the
13955 previous known name, assume that means the user renamed the marker
13956 in the sources, and output a warning.
13958 2) For a tracepoint set at a given line number, look for a marker
13959 at the new address of the old line number. If one is found there,
13960 assume to be the same marker. If the name / string id of the
13961 marker found is different from the previous known name, assume that
13962 means the user renamed the marker in the sources, and output a
13965 3) If a marker is no longer found at the same address or line, it
13966 may mean the marker no longer exists. But it may also just mean
13967 the code changed a bit. Maybe the user added a few lines of code
13968 that made the marker move up or down (in line number terms). Ask
13969 the target for info about the marker with the string id as we knew
13970 it. If found, update line number and address in the matching
13971 static tracepoint. This will get confused if there's more than one
13972 marker with the same ID (possible in UST, although unadvised
13973 precisely because it confuses tools). */
13975 static struct symtab_and_line
13976 update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal)
13978 struct tracepoint *tp = (struct tracepoint *) b;
13979 struct static_tracepoint_marker marker;
13984 find_line_pc (sal.symtab, sal.line, &pc);
13986 if (target_static_tracepoint_marker_at (pc, &marker))
13988 if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0)
13989 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13991 tp->static_trace_marker_id, marker.str_id);
13993 xfree (tp->static_trace_marker_id);
13994 tp->static_trace_marker_id = xstrdup (marker.str_id);
13995 release_static_tracepoint_marker (&marker);
14000 /* Old marker wasn't found on target at lineno. Try looking it up
14002 if (!sal.explicit_pc
14004 && sal.symtab != NULL
14005 && tp->static_trace_marker_id != NULL)
14007 VEC(static_tracepoint_marker_p) *markers;
14010 = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id);
14012 if (!VEC_empty(static_tracepoint_marker_p, markers))
14014 struct symtab_and_line sal2;
14015 struct symbol *sym;
14016 struct static_tracepoint_marker *tpmarker;
14017 struct ui_out *uiout = current_uiout;
14019 tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0);
14021 xfree (tp->static_trace_marker_id);
14022 tp->static_trace_marker_id = xstrdup (tpmarker->str_id);
14024 warning (_("marker for static tracepoint %d (%s) not "
14025 "found at previous line number"),
14026 b->number, tp->static_trace_marker_id);
14030 sal2.pc = tpmarker->address;
14032 sal2 = find_pc_line (tpmarker->address, 0);
14033 sym = find_pc_sect_function (tpmarker->address, NULL);
14034 ui_out_text (uiout, "Now in ");
14037 ui_out_field_string (uiout, "func",
14038 SYMBOL_PRINT_NAME (sym));
14039 ui_out_text (uiout, " at ");
14041 ui_out_field_string (uiout, "file",
14042 symtab_to_filename_for_display (sal2.symtab));
14043 ui_out_text (uiout, ":");
14045 if (ui_out_is_mi_like_p (uiout))
14047 const char *fullname = symtab_to_fullname (sal2.symtab);
14049 ui_out_field_string (uiout, "fullname", fullname);
14052 ui_out_field_int (uiout, "line", sal2.line);
14053 ui_out_text (uiout, "\n");
14055 b->loc->line_number = sal2.line;
14056 b->loc->symtab = sym != NULL ? sal2.symtab : NULL;
14058 xfree (b->addr_string);
14059 b->addr_string = xstrprintf ("%s:%d",
14060 symtab_to_filename_for_display (sal2.symtab),
14061 b->loc->line_number);
14063 /* Might be nice to check if function changed, and warn if
14066 release_static_tracepoint_marker (tpmarker);
14072 /* Returns 1 iff locations A and B are sufficiently same that
14073 we don't need to report breakpoint as changed. */
14076 locations_are_equal (struct bp_location *a, struct bp_location *b)
14080 if (a->address != b->address)
14083 if (a->shlib_disabled != b->shlib_disabled)
14086 if (a->enabled != b->enabled)
14093 if ((a == NULL) != (b == NULL))
14099 /* Create new breakpoint locations for B (a hardware or software breakpoint)
14100 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
14101 a ranged breakpoint. */
14104 update_breakpoint_locations (struct breakpoint *b,
14105 struct symtabs_and_lines sals,
14106 struct symtabs_and_lines sals_end)
14109 struct bp_location *existing_locations = b->loc;
14111 if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1))
14113 /* Ranged breakpoints have only one start location and one end
14115 b->enable_state = bp_disabled;
14116 update_global_location_list (1);
14117 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
14118 "multiple locations found\n"),
14123 /* If there's no new locations, and all existing locations are
14124 pending, don't do anything. This optimizes the common case where
14125 all locations are in the same shared library, that was unloaded.
14126 We'd like to retain the location, so that when the library is
14127 loaded again, we don't loose the enabled/disabled status of the
14128 individual locations. */
14129 if (all_locations_are_pending (existing_locations) && sals.nelts == 0)
14134 for (i = 0; i < sals.nelts; ++i)
14136 struct bp_location *new_loc;
14138 switch_to_program_space_and_thread (sals.sals[i].pspace);
14140 new_loc = add_location_to_breakpoint (b, &(sals.sals[i]));
14142 /* Reparse conditions, they might contain references to the
14144 if (b->cond_string != NULL)
14147 volatile struct gdb_exception e;
14149 s = b->cond_string;
14150 TRY_CATCH (e, RETURN_MASK_ERROR)
14152 new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc,
14153 block_for_pc (sals.sals[i].pc),
14158 warning (_("failed to reevaluate condition "
14159 "for breakpoint %d: %s"),
14160 b->number, e.message);
14161 new_loc->enabled = 0;
14165 if (sals_end.nelts)
14167 CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]);
14169 new_loc->length = end - sals.sals[0].pc + 1;
14173 /* Update locations of permanent breakpoints. */
14174 if (b->enable_state == bp_permanent)
14175 make_breakpoint_permanent (b);
14177 /* If possible, carry over 'disable' status from existing
14180 struct bp_location *e = existing_locations;
14181 /* If there are multiple breakpoints with the same function name,
14182 e.g. for inline functions, comparing function names won't work.
14183 Instead compare pc addresses; this is just a heuristic as things
14184 may have moved, but in practice it gives the correct answer
14185 often enough until a better solution is found. */
14186 int have_ambiguous_names = ambiguous_names_p (b->loc);
14188 for (; e; e = e->next)
14190 if (!e->enabled && e->function_name)
14192 struct bp_location *l = b->loc;
14193 if (have_ambiguous_names)
14195 for (; l; l = l->next)
14196 if (breakpoint_locations_match (e, l))
14204 for (; l; l = l->next)
14205 if (l->function_name
14206 && strcmp (e->function_name, l->function_name) == 0)
14216 if (!locations_are_equal (existing_locations, b->loc))
14217 observer_notify_breakpoint_modified (b);
14219 update_global_location_list (1);
14222 /* Find the SaL locations corresponding to the given ADDR_STRING.
14223 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
14225 static struct symtabs_and_lines
14226 addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found)
14229 struct symtabs_and_lines sals = {0};
14230 volatile struct gdb_exception e;
14232 gdb_assert (b->ops != NULL);
14235 TRY_CATCH (e, RETURN_MASK_ERROR)
14237 b->ops->decode_linespec (b, &s, &sals);
14241 int not_found_and_ok = 0;
14242 /* For pending breakpoints, it's expected that parsing will
14243 fail until the right shared library is loaded. User has
14244 already told to create pending breakpoints and don't need
14245 extra messages. If breakpoint is in bp_shlib_disabled
14246 state, then user already saw the message about that
14247 breakpoint being disabled, and don't want to see more
14249 if (e.error == NOT_FOUND_ERROR
14250 && (b->condition_not_parsed
14251 || (b->loc && b->loc->shlib_disabled)
14252 || (b->loc && b->loc->pspace->executing_startup)
14253 || b->enable_state == bp_disabled))
14254 not_found_and_ok = 1;
14256 if (!not_found_and_ok)
14258 /* We surely don't want to warn about the same breakpoint
14259 10 times. One solution, implemented here, is disable
14260 the breakpoint on error. Another solution would be to
14261 have separate 'warning emitted' flag. Since this
14262 happens only when a binary has changed, I don't know
14263 which approach is better. */
14264 b->enable_state = bp_disabled;
14265 throw_exception (e);
14269 if (e.reason == 0 || e.error != NOT_FOUND_ERROR)
14273 for (i = 0; i < sals.nelts; ++i)
14274 resolve_sal_pc (&sals.sals[i]);
14275 if (b->condition_not_parsed && s && s[0])
14277 char *cond_string, *extra_string;
14280 find_condition_and_thread (s, sals.sals[0].pc,
14281 &cond_string, &thread, &task,
14284 b->cond_string = cond_string;
14285 b->thread = thread;
14288 b->extra_string = extra_string;
14289 b->condition_not_parsed = 0;
14292 if (b->type == bp_static_tracepoint && !strace_marker_p (b))
14293 sals.sals[0] = update_static_tracepoint (b, sals.sals[0]);
14303 /* The default re_set method, for typical hardware or software
14304 breakpoints. Reevaluate the breakpoint and recreate its
14308 breakpoint_re_set_default (struct breakpoint *b)
14311 struct symtabs_and_lines sals, sals_end;
14312 struct symtabs_and_lines expanded = {0};
14313 struct symtabs_and_lines expanded_end = {0};
14315 sals = addr_string_to_sals (b, b->addr_string, &found);
14318 make_cleanup (xfree, sals.sals);
14322 if (b->addr_string_range_end)
14324 sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found);
14327 make_cleanup (xfree, sals_end.sals);
14328 expanded_end = sals_end;
14332 update_breakpoint_locations (b, expanded, expanded_end);
14335 /* Default method for creating SALs from an address string. It basically
14336 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
14339 create_sals_from_address_default (char **arg,
14340 struct linespec_result *canonical,
14341 enum bptype type_wanted,
14342 char *addr_start, char **copy_arg)
14344 parse_breakpoint_sals (arg, canonical);
14347 /* Call create_breakpoints_sal for the given arguments. This is the default
14348 function for the `create_breakpoints_sal' method of
14352 create_breakpoints_sal_default (struct gdbarch *gdbarch,
14353 struct linespec_result *canonical,
14354 struct linespec_sals *lsal,
14356 char *extra_string,
14357 enum bptype type_wanted,
14358 enum bpdisp disposition,
14360 int task, int ignore_count,
14361 const struct breakpoint_ops *ops,
14362 int from_tty, int enabled,
14363 int internal, unsigned flags)
14365 create_breakpoints_sal (gdbarch, canonical, cond_string,
14367 type_wanted, disposition,
14368 thread, task, ignore_count, ops, from_tty,
14369 enabled, internal, flags);
14372 /* Decode the line represented by S by calling decode_line_full. This is the
14373 default function for the `decode_linespec' method of breakpoint_ops. */
14376 decode_linespec_default (struct breakpoint *b, char **s,
14377 struct symtabs_and_lines *sals)
14379 struct linespec_result canonical;
14381 init_linespec_result (&canonical);
14382 decode_line_full (s, DECODE_LINE_FUNFIRSTLINE,
14383 (struct symtab *) NULL, 0,
14384 &canonical, multiple_symbols_all,
14387 /* We should get 0 or 1 resulting SALs. */
14388 gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2);
14390 if (VEC_length (linespec_sals, canonical.sals) > 0)
14392 struct linespec_sals *lsal;
14394 lsal = VEC_index (linespec_sals, canonical.sals, 0);
14395 *sals = lsal->sals;
14396 /* Arrange it so the destructor does not free the
14398 lsal->sals.sals = NULL;
14401 destroy_linespec_result (&canonical);
14404 /* Prepare the global context for a re-set of breakpoint B. */
14406 static struct cleanup *
14407 prepare_re_set_context (struct breakpoint *b)
14409 struct cleanup *cleanups;
14411 input_radix = b->input_radix;
14412 cleanups = save_current_space_and_thread ();
14413 if (b->pspace != NULL)
14414 switch_to_program_space_and_thread (b->pspace);
14415 set_language (b->language);
14420 /* Reset a breakpoint given it's struct breakpoint * BINT.
14421 The value we return ends up being the return value from catch_errors.
14422 Unused in this case. */
14425 breakpoint_re_set_one (void *bint)
14427 /* Get past catch_errs. */
14428 struct breakpoint *b = (struct breakpoint *) bint;
14429 struct cleanup *cleanups;
14431 cleanups = prepare_re_set_context (b);
14432 b->ops->re_set (b);
14433 do_cleanups (cleanups);
14437 /* Re-set all breakpoints after symbols have been re-loaded. */
14439 breakpoint_re_set (void)
14441 struct breakpoint *b, *b_tmp;
14442 enum language save_language;
14443 int save_input_radix;
14444 struct cleanup *old_chain;
14446 save_language = current_language->la_language;
14447 save_input_radix = input_radix;
14448 old_chain = save_current_program_space ();
14450 ALL_BREAKPOINTS_SAFE (b, b_tmp)
14452 /* Format possible error msg. */
14453 char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
14455 struct cleanup *cleanups = make_cleanup (xfree, message);
14456 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
14457 do_cleanups (cleanups);
14459 set_language (save_language);
14460 input_radix = save_input_radix;
14462 jit_breakpoint_re_set ();
14464 do_cleanups (old_chain);
14466 create_overlay_event_breakpoint ();
14467 create_longjmp_master_breakpoint ();
14468 create_std_terminate_master_breakpoint ();
14469 create_exception_master_breakpoint ();
14472 /* Reset the thread number of this breakpoint:
14474 - If the breakpoint is for all threads, leave it as-is.
14475 - Else, reset it to the current thread for inferior_ptid. */
14477 breakpoint_re_set_thread (struct breakpoint *b)
14479 if (b->thread != -1)
14481 if (in_thread_list (inferior_ptid))
14482 b->thread = pid_to_thread_id (inferior_ptid);
14484 /* We're being called after following a fork. The new fork is
14485 selected as current, and unless this was a vfork will have a
14486 different program space from the original thread. Reset that
14488 b->loc->pspace = current_program_space;
14492 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14493 If from_tty is nonzero, it prints a message to that effect,
14494 which ends with a period (no newline). */
14497 set_ignore_count (int bptnum, int count, int from_tty)
14499 struct breakpoint *b;
14504 ALL_BREAKPOINTS (b)
14505 if (b->number == bptnum)
14507 if (is_tracepoint (b))
14509 if (from_tty && count != 0)
14510 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14515 b->ignore_count = count;
14519 printf_filtered (_("Will stop next time "
14520 "breakpoint %d is reached."),
14522 else if (count == 1)
14523 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14526 printf_filtered (_("Will ignore next %d "
14527 "crossings of breakpoint %d."),
14530 observer_notify_breakpoint_modified (b);
14534 error (_("No breakpoint number %d."), bptnum);
14537 /* Command to set ignore-count of breakpoint N to COUNT. */
14540 ignore_command (char *args, int from_tty)
14546 error_no_arg (_("a breakpoint number"));
14548 num = get_number (&p);
14550 error (_("bad breakpoint number: '%s'"), args);
14552 error (_("Second argument (specified ignore-count) is missing."));
14554 set_ignore_count (num,
14555 longest_to_int (value_as_long (parse_and_eval (p))),
14558 printf_filtered ("\n");
14561 /* Call FUNCTION on each of the breakpoints
14562 whose numbers are given in ARGS. */
14565 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *,
14570 struct breakpoint *b, *tmp;
14572 struct get_number_or_range_state state;
14575 error_no_arg (_("one or more breakpoint numbers"));
14577 init_number_or_range (&state, args);
14579 while (!state.finished)
14581 char *p = state.string;
14585 num = get_number_or_range (&state);
14588 warning (_("bad breakpoint number at or near '%s'"), p);
14592 ALL_BREAKPOINTS_SAFE (b, tmp)
14593 if (b->number == num)
14596 function (b, data);
14600 printf_unfiltered (_("No breakpoint number %d.\n"), num);
14605 static struct bp_location *
14606 find_location_by_number (char *number)
14608 char *dot = strchr (number, '.');
14612 struct breakpoint *b;
14613 struct bp_location *loc;
14618 bp_num = get_number (&p1);
14620 error (_("Bad breakpoint number '%s'"), number);
14622 ALL_BREAKPOINTS (b)
14623 if (b->number == bp_num)
14628 if (!b || b->number != bp_num)
14629 error (_("Bad breakpoint number '%s'"), number);
14632 loc_num = get_number (&p1);
14634 error (_("Bad breakpoint location number '%s'"), number);
14638 for (;loc_num && loc; --loc_num, loc = loc->next)
14641 error (_("Bad breakpoint location number '%s'"), dot+1);
14647 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14648 If from_tty is nonzero, it prints a message to that effect,
14649 which ends with a period (no newline). */
14652 disable_breakpoint (struct breakpoint *bpt)
14654 /* Never disable a watchpoint scope breakpoint; we want to
14655 hit them when we leave scope so we can delete both the
14656 watchpoint and its scope breakpoint at that time. */
14657 if (bpt->type == bp_watchpoint_scope)
14660 /* You can't disable permanent breakpoints. */
14661 if (bpt->enable_state == bp_permanent)
14664 bpt->enable_state = bp_disabled;
14666 /* Mark breakpoint locations modified. */
14667 mark_breakpoint_modified (bpt);
14669 if (target_supports_enable_disable_tracepoint ()
14670 && current_trace_status ()->running && is_tracepoint (bpt))
14672 struct bp_location *location;
14674 for (location = bpt->loc; location; location = location->next)
14675 target_disable_tracepoint (location);
14678 update_global_location_list (0);
14680 observer_notify_breakpoint_modified (bpt);
14683 /* A callback for iterate_over_related_breakpoints. */
14686 do_disable_breakpoint (struct breakpoint *b, void *ignore)
14688 disable_breakpoint (b);
14691 /* A callback for map_breakpoint_numbers that calls
14692 disable_breakpoint. */
14695 do_map_disable_breakpoint (struct breakpoint *b, void *ignore)
14697 iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL);
14701 disable_command (char *args, int from_tty)
14705 struct breakpoint *bpt;
14707 ALL_BREAKPOINTS (bpt)
14708 if (user_breakpoint_p (bpt))
14709 disable_breakpoint (bpt);
14711 else if (strchr (args, '.'))
14713 struct bp_location *loc = find_location_by_number (args);
14719 mark_breakpoint_location_modified (loc);
14721 if (target_supports_enable_disable_tracepoint ()
14722 && current_trace_status ()->running && loc->owner
14723 && is_tracepoint (loc->owner))
14724 target_disable_tracepoint (loc);
14726 update_global_location_list (0);
14729 map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL);
14733 enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition,
14736 int target_resources_ok;
14738 if (bpt->type == bp_hardware_breakpoint)
14741 i = hw_breakpoint_used_count ();
14742 target_resources_ok =
14743 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
14745 if (target_resources_ok == 0)
14746 error (_("No hardware breakpoint support in the target."));
14747 else if (target_resources_ok < 0)
14748 error (_("Hardware breakpoints used exceeds limit."));
14751 if (is_watchpoint (bpt))
14753 /* Initialize it just to avoid a GCC false warning. */
14754 enum enable_state orig_enable_state = 0;
14755 volatile struct gdb_exception e;
14757 TRY_CATCH (e, RETURN_MASK_ALL)
14759 struct watchpoint *w = (struct watchpoint *) bpt;
14761 orig_enable_state = bpt->enable_state;
14762 bpt->enable_state = bp_enabled;
14763 update_watchpoint (w, 1 /* reparse */);
14767 bpt->enable_state = orig_enable_state;
14768 exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
14774 if (bpt->enable_state != bp_permanent)
14775 bpt->enable_state = bp_enabled;
14777 bpt->enable_state = bp_enabled;
14779 /* Mark breakpoint locations modified. */
14780 mark_breakpoint_modified (bpt);
14782 if (target_supports_enable_disable_tracepoint ()
14783 && current_trace_status ()->running && is_tracepoint (bpt))
14785 struct bp_location *location;
14787 for (location = bpt->loc; location; location = location->next)
14788 target_enable_tracepoint (location);
14791 bpt->disposition = disposition;
14792 bpt->enable_count = count;
14793 update_global_location_list (1);
14795 observer_notify_breakpoint_modified (bpt);
14800 enable_breakpoint (struct breakpoint *bpt)
14802 enable_breakpoint_disp (bpt, bpt->disposition, 0);
14806 do_enable_breakpoint (struct breakpoint *bpt, void *arg)
14808 enable_breakpoint (bpt);
14811 /* A callback for map_breakpoint_numbers that calls
14812 enable_breakpoint. */
14815 do_map_enable_breakpoint (struct breakpoint *b, void *ignore)
14817 iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL);
14820 /* The enable command enables the specified breakpoints (or all defined
14821 breakpoints) so they once again become (or continue to be) effective
14822 in stopping the inferior. */
14825 enable_command (char *args, int from_tty)
14829 struct breakpoint *bpt;
14831 ALL_BREAKPOINTS (bpt)
14832 if (user_breakpoint_p (bpt))
14833 enable_breakpoint (bpt);
14835 else if (strchr (args, '.'))
14837 struct bp_location *loc = find_location_by_number (args);
14843 mark_breakpoint_location_modified (loc);
14845 if (target_supports_enable_disable_tracepoint ()
14846 && current_trace_status ()->running && loc->owner
14847 && is_tracepoint (loc->owner))
14848 target_enable_tracepoint (loc);
14850 update_global_location_list (1);
14853 map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL);
14856 /* This struct packages up disposition data for application to multiple
14866 do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg)
14868 struct disp_data disp_data = *(struct disp_data *) arg;
14870 enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count);
14874 do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore)
14876 struct disp_data disp = { disp_disable, 1 };
14878 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
14882 enable_once_command (char *args, int from_tty)
14884 map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL);
14888 do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr)
14890 struct disp_data disp = { disp_disable, *(int *) countptr };
14892 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
14896 enable_count_command (char *args, int from_tty)
14898 int count = get_number (&args);
14900 map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count);
14904 do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore)
14906 struct disp_data disp = { disp_del, 1 };
14908 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
14912 enable_delete_command (char *args, int from_tty)
14914 map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL);
14918 set_breakpoint_cmd (char *args, int from_tty)
14923 show_breakpoint_cmd (char *args, int from_tty)
14927 /* Invalidate last known value of any hardware watchpoint if
14928 the memory which that value represents has been written to by
14932 invalidate_bp_value_on_memory_change (struct inferior *inferior,
14933 CORE_ADDR addr, ssize_t len,
14934 const bfd_byte *data)
14936 struct breakpoint *bp;
14938 ALL_BREAKPOINTS (bp)
14939 if (bp->enable_state == bp_enabled
14940 && bp->type == bp_hardware_watchpoint)
14942 struct watchpoint *wp = (struct watchpoint *) bp;
14944 if (wp->val_valid && wp->val)
14946 struct bp_location *loc;
14948 for (loc = bp->loc; loc != NULL; loc = loc->next)
14949 if (loc->loc_type == bp_loc_hardware_watchpoint
14950 && loc->address + loc->length > addr
14951 && addr + len > loc->address)
14953 value_free (wp->val);
14961 /* Create and insert a raw software breakpoint at PC. Return an
14962 identifier, which should be used to remove the breakpoint later.
14963 In general, places which call this should be using something on the
14964 breakpoint chain instead; this function should be eliminated
14968 deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch,
14969 struct address_space *aspace, CORE_ADDR pc)
14971 struct bp_target_info *bp_tgt;
14973 bp_tgt = XZALLOC (struct bp_target_info);
14975 bp_tgt->placed_address_space = aspace;
14976 bp_tgt->placed_address = pc;
14978 if (target_insert_breakpoint (gdbarch, bp_tgt) != 0)
14980 /* Could not insert the breakpoint. */
14988 /* Remove a breakpoint BP inserted by
14989 deprecated_insert_raw_breakpoint. */
14992 deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp)
14994 struct bp_target_info *bp_tgt = bp;
14997 ret = target_remove_breakpoint (gdbarch, bp_tgt);
15003 /* One (or perhaps two) breakpoints used for software single
15006 static void *single_step_breakpoints[2];
15007 static struct gdbarch *single_step_gdbarch[2];
15009 /* Create and insert a breakpoint for software single step. */
15012 insert_single_step_breakpoint (struct gdbarch *gdbarch,
15013 struct address_space *aspace,
15018 if (single_step_breakpoints[0] == NULL)
15020 bpt_p = &single_step_breakpoints[0];
15021 single_step_gdbarch[0] = gdbarch;
15025 gdb_assert (single_step_breakpoints[1] == NULL);
15026 bpt_p = &single_step_breakpoints[1];
15027 single_step_gdbarch[1] = gdbarch;
15030 /* NOTE drow/2006-04-11: A future improvement to this function would
15031 be to only create the breakpoints once, and actually put them on
15032 the breakpoint chain. That would let us use set_raw_breakpoint.
15033 We could adjust the addresses each time they were needed. Doing
15034 this requires corresponding changes elsewhere where single step
15035 breakpoints are handled, however. So, for now, we use this. */
15037 *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc);
15038 if (*bpt_p == NULL)
15039 error (_("Could not insert single-step breakpoint at %s"),
15040 paddress (gdbarch, next_pc));
15043 /* Check if the breakpoints used for software single stepping
15044 were inserted or not. */
15047 single_step_breakpoints_inserted (void)
15049 return (single_step_breakpoints[0] != NULL
15050 || single_step_breakpoints[1] != NULL);
15053 /* Remove and delete any breakpoints used for software single step. */
15056 remove_single_step_breakpoints (void)
15058 gdb_assert (single_step_breakpoints[0] != NULL);
15060 /* See insert_single_step_breakpoint for more about this deprecated
15062 deprecated_remove_raw_breakpoint (single_step_gdbarch[0],
15063 single_step_breakpoints[0]);
15064 single_step_gdbarch[0] = NULL;
15065 single_step_breakpoints[0] = NULL;
15067 if (single_step_breakpoints[1] != NULL)
15069 deprecated_remove_raw_breakpoint (single_step_gdbarch[1],
15070 single_step_breakpoints[1]);
15071 single_step_gdbarch[1] = NULL;
15072 single_step_breakpoints[1] = NULL;
15076 /* Delete software single step breakpoints without removing them from
15077 the inferior. This is intended to be used if the inferior's address
15078 space where they were inserted is already gone, e.g. after exit or
15082 cancel_single_step_breakpoints (void)
15086 for (i = 0; i < 2; i++)
15087 if (single_step_breakpoints[i])
15089 xfree (single_step_breakpoints[i]);
15090 single_step_breakpoints[i] = NULL;
15091 single_step_gdbarch[i] = NULL;
15095 /* Detach software single-step breakpoints from INFERIOR_PTID without
15099 detach_single_step_breakpoints (void)
15103 for (i = 0; i < 2; i++)
15104 if (single_step_breakpoints[i])
15105 target_remove_breakpoint (single_step_gdbarch[i],
15106 single_step_breakpoints[i]);
15109 /* Check whether a software single-step breakpoint is inserted at
15113 single_step_breakpoint_inserted_here_p (struct address_space *aspace,
15118 for (i = 0; i < 2; i++)
15120 struct bp_target_info *bp_tgt = single_step_breakpoints[i];
15122 && breakpoint_address_match (bp_tgt->placed_address_space,
15123 bp_tgt->placed_address,
15131 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
15132 non-zero otherwise. */
15134 is_syscall_catchpoint_enabled (struct breakpoint *bp)
15136 if (syscall_catchpoint_p (bp)
15137 && bp->enable_state != bp_disabled
15138 && bp->enable_state != bp_call_disabled)
15145 catch_syscall_enabled (void)
15147 struct catch_syscall_inferior_data *inf_data
15148 = get_catch_syscall_inferior_data (current_inferior ());
15150 return inf_data->total_syscalls_count != 0;
15154 catching_syscall_number (int syscall_number)
15156 struct breakpoint *bp;
15158 ALL_BREAKPOINTS (bp)
15159 if (is_syscall_catchpoint_enabled (bp))
15161 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp;
15163 if (c->syscalls_to_be_caught)
15167 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
15169 if (syscall_number == iter)
15179 /* Complete syscall names. Used by "catch syscall". */
15180 static VEC (char_ptr) *
15181 catch_syscall_completer (struct cmd_list_element *cmd,
15182 const char *text, const char *word)
15184 const char **list = get_syscall_names ();
15185 VEC (char_ptr) *retlist
15186 = (list == NULL) ? NULL : complete_on_enum (list, word, word);
15192 /* Tracepoint-specific operations. */
15194 /* Set tracepoint count to NUM. */
15196 set_tracepoint_count (int num)
15198 tracepoint_count = num;
15199 set_internalvar_integer (lookup_internalvar ("tpnum"), num);
15203 trace_command (char *arg, int from_tty)
15205 struct breakpoint_ops *ops;
15206 const char *arg_cp = arg;
15208 if (arg && probe_linespec_to_ops (&arg_cp))
15209 ops = &tracepoint_probe_breakpoint_ops;
15211 ops = &tracepoint_breakpoint_ops;
15213 create_breakpoint (get_current_arch (),
15215 NULL, 0, NULL, 1 /* parse arg */,
15217 bp_tracepoint /* type_wanted */,
15218 0 /* Ignore count */,
15219 pending_break_support,
15223 0 /* internal */, 0);
15227 ftrace_command (char *arg, int from_tty)
15229 create_breakpoint (get_current_arch (),
15231 NULL, 0, NULL, 1 /* parse arg */,
15233 bp_fast_tracepoint /* type_wanted */,
15234 0 /* Ignore count */,
15235 pending_break_support,
15236 &tracepoint_breakpoint_ops,
15239 0 /* internal */, 0);
15242 /* strace command implementation. Creates a static tracepoint. */
15245 strace_command (char *arg, int from_tty)
15247 struct breakpoint_ops *ops;
15249 /* Decide if we are dealing with a static tracepoint marker (`-m'),
15250 or with a normal static tracepoint. */
15251 if (arg && strncmp (arg, "-m", 2) == 0 && isspace (arg[2]))
15252 ops = &strace_marker_breakpoint_ops;
15254 ops = &tracepoint_breakpoint_ops;
15256 create_breakpoint (get_current_arch (),
15258 NULL, 0, NULL, 1 /* parse arg */,
15260 bp_static_tracepoint /* type_wanted */,
15261 0 /* Ignore count */,
15262 pending_break_support,
15266 0 /* internal */, 0);
15269 /* Set up a fake reader function that gets command lines from a linked
15270 list that was acquired during tracepoint uploading. */
15272 static struct uploaded_tp *this_utp;
15273 static int next_cmd;
15276 read_uploaded_action (void)
15280 VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt);
15287 /* Given information about a tracepoint as recorded on a target (which
15288 can be either a live system or a trace file), attempt to create an
15289 equivalent GDB tracepoint. This is not a reliable process, since
15290 the target does not necessarily have all the information used when
15291 the tracepoint was originally defined. */
15293 struct tracepoint *
15294 create_tracepoint_from_upload (struct uploaded_tp *utp)
15296 char *addr_str, small_buf[100];
15297 struct tracepoint *tp;
15299 if (utp->at_string)
15300 addr_str = utp->at_string;
15303 /* In the absence of a source location, fall back to raw
15304 address. Since there is no way to confirm that the address
15305 means the same thing as when the trace was started, warn the
15307 warning (_("Uploaded tracepoint %d has no "
15308 "source location, using raw address"),
15310 xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr));
15311 addr_str = small_buf;
15314 /* There's not much we can do with a sequence of bytecodes. */
15315 if (utp->cond && !utp->cond_string)
15316 warning (_("Uploaded tracepoint %d condition "
15317 "has no source form, ignoring it"),
15320 if (!create_breakpoint (get_current_arch (),
15322 utp->cond_string, -1, NULL,
15323 0 /* parse cond/thread */,
15325 utp->type /* type_wanted */,
15326 0 /* Ignore count */,
15327 pending_break_support,
15328 &tracepoint_breakpoint_ops,
15330 utp->enabled /* enabled */,
15332 CREATE_BREAKPOINT_FLAGS_INSERTED))
15335 /* Get the tracepoint we just created. */
15336 tp = get_tracepoint (tracepoint_count);
15337 gdb_assert (tp != NULL);
15341 xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass,
15344 trace_pass_command (small_buf, 0);
15347 /* If we have uploaded versions of the original commands, set up a
15348 special-purpose "reader" function and call the usual command line
15349 reader, then pass the result to the breakpoint command-setting
15351 if (!VEC_empty (char_ptr, utp->cmd_strings))
15353 struct command_line *cmd_list;
15358 cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL);
15360 breakpoint_set_commands (&tp->base, cmd_list);
15362 else if (!VEC_empty (char_ptr, utp->actions)
15363 || !VEC_empty (char_ptr, utp->step_actions))
15364 warning (_("Uploaded tracepoint %d actions "
15365 "have no source form, ignoring them"),
15368 /* Copy any status information that might be available. */
15369 tp->base.hit_count = utp->hit_count;
15370 tp->traceframe_usage = utp->traceframe_usage;
15375 /* Print information on tracepoint number TPNUM_EXP, or all if
15379 tracepoints_info (char *args, int from_tty)
15381 struct ui_out *uiout = current_uiout;
15384 num_printed = breakpoint_1 (args, 0, is_tracepoint);
15386 if (num_printed == 0)
15388 if (args == NULL || *args == '\0')
15389 ui_out_message (uiout, 0, "No tracepoints.\n");
15391 ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args);
15394 default_collect_info ();
15397 /* The 'enable trace' command enables tracepoints.
15398 Not supported by all targets. */
15400 enable_trace_command (char *args, int from_tty)
15402 enable_command (args, from_tty);
15405 /* The 'disable trace' command disables tracepoints.
15406 Not supported by all targets. */
15408 disable_trace_command (char *args, int from_tty)
15410 disable_command (args, from_tty);
15413 /* Remove a tracepoint (or all if no argument). */
15415 delete_trace_command (char *arg, int from_tty)
15417 struct breakpoint *b, *b_tmp;
15423 int breaks_to_delete = 0;
15425 /* Delete all breakpoints if no argument.
15426 Do not delete internal or call-dummy breakpoints, these
15427 have to be deleted with an explicit breakpoint number
15429 ALL_TRACEPOINTS (b)
15430 if (is_tracepoint (b) && user_breakpoint_p (b))
15432 breaks_to_delete = 1;
15436 /* Ask user only if there are some breakpoints to delete. */
15438 || (breaks_to_delete && query (_("Delete all tracepoints? "))))
15440 ALL_BREAKPOINTS_SAFE (b, b_tmp)
15441 if (is_tracepoint (b) && user_breakpoint_p (b))
15442 delete_breakpoint (b);
15446 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
15449 /* Helper function for trace_pass_command. */
15452 trace_pass_set_count (struct tracepoint *tp, int count, int from_tty)
15454 tp->pass_count = count;
15455 observer_notify_breakpoint_modified (&tp->base);
15457 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15458 tp->base.number, count);
15461 /* Set passcount for tracepoint.
15463 First command argument is passcount, second is tracepoint number.
15464 If tracepoint number omitted, apply to most recently defined.
15465 Also accepts special argument "all". */
15468 trace_pass_command (char *args, int from_tty)
15470 struct tracepoint *t1;
15471 unsigned int count;
15473 if (args == 0 || *args == 0)
15474 error (_("passcount command requires an "
15475 "argument (count + optional TP num)"));
15477 count = strtoul (args, &args, 10); /* Count comes first, then TP num. */
15479 args = skip_spaces (args);
15480 if (*args && strncasecmp (args, "all", 3) == 0)
15482 struct breakpoint *b;
15484 args += 3; /* Skip special argument "all". */
15486 error (_("Junk at end of arguments."));
15488 ALL_TRACEPOINTS (b)
15490 t1 = (struct tracepoint *) b;
15491 trace_pass_set_count (t1, count, from_tty);
15494 else if (*args == '\0')
15496 t1 = get_tracepoint_by_number (&args, NULL, 1);
15498 trace_pass_set_count (t1, count, from_tty);
15502 struct get_number_or_range_state state;
15504 init_number_or_range (&state, args);
15505 while (!state.finished)
15507 t1 = get_tracepoint_by_number (&args, &state, 1);
15509 trace_pass_set_count (t1, count, from_tty);
15514 struct tracepoint *
15515 get_tracepoint (int num)
15517 struct breakpoint *t;
15519 ALL_TRACEPOINTS (t)
15520 if (t->number == num)
15521 return (struct tracepoint *) t;
15526 /* Find the tracepoint with the given target-side number (which may be
15527 different from the tracepoint number after disconnecting and
15530 struct tracepoint *
15531 get_tracepoint_by_number_on_target (int num)
15533 struct breakpoint *b;
15535 ALL_TRACEPOINTS (b)
15537 struct tracepoint *t = (struct tracepoint *) b;
15539 if (t->number_on_target == num)
15546 /* Utility: parse a tracepoint number and look it up in the list.
15547 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15548 If OPTIONAL_P is true, then if the argument is missing, the most
15549 recent tracepoint (tracepoint_count) is returned. */
15550 struct tracepoint *
15551 get_tracepoint_by_number (char **arg,
15552 struct get_number_or_range_state *state,
15555 struct breakpoint *t;
15557 char *instring = arg == NULL ? NULL : *arg;
15561 gdb_assert (!state->finished);
15562 tpnum = get_number_or_range (state);
15564 else if (arg == NULL || *arg == NULL || ! **arg)
15567 tpnum = tracepoint_count;
15569 error_no_arg (_("tracepoint number"));
15572 tpnum = get_number (arg);
15576 if (instring && *instring)
15577 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15580 printf_filtered (_("Tracepoint argument missing "
15581 "and no previous tracepoint\n"));
15585 ALL_TRACEPOINTS (t)
15586 if (t->number == tpnum)
15588 return (struct tracepoint *) t;
15591 printf_unfiltered ("No tracepoint number %d.\n", tpnum);
15596 print_recreate_thread (struct breakpoint *b, struct ui_file *fp)
15598 if (b->thread != -1)
15599 fprintf_unfiltered (fp, " thread %d", b->thread);
15602 fprintf_unfiltered (fp, " task %d", b->task);
15604 fprintf_unfiltered (fp, "\n");
15607 /* Save information on user settable breakpoints (watchpoints, etc) to
15608 a new script file named FILENAME. If FILTER is non-NULL, call it
15609 on each breakpoint and only include the ones for which it returns
15613 save_breakpoints (char *filename, int from_tty,
15614 int (*filter) (const struct breakpoint *))
15616 struct breakpoint *tp;
15619 struct cleanup *cleanup;
15620 struct ui_file *fp;
15621 int extra_trace_bits = 0;
15623 if (filename == 0 || *filename == 0)
15624 error (_("Argument required (file name in which to save)"));
15626 /* See if we have anything to save. */
15627 ALL_BREAKPOINTS (tp)
15629 /* Skip internal and momentary breakpoints. */
15630 if (!user_breakpoint_p (tp))
15633 /* If we have a filter, only save the breakpoints it accepts. */
15634 if (filter && !filter (tp))
15639 if (is_tracepoint (tp))
15641 extra_trace_bits = 1;
15643 /* We can stop searching. */
15650 warning (_("Nothing to save."));
15654 pathname = tilde_expand (filename);
15655 cleanup = make_cleanup (xfree, pathname);
15656 fp = gdb_fopen (pathname, "w");
15658 error (_("Unable to open file '%s' for saving (%s)"),
15659 filename, safe_strerror (errno));
15660 make_cleanup_ui_file_delete (fp);
15662 if (extra_trace_bits)
15663 save_trace_state_variables (fp);
15665 ALL_BREAKPOINTS (tp)
15667 /* Skip internal and momentary breakpoints. */
15668 if (!user_breakpoint_p (tp))
15671 /* If we have a filter, only save the breakpoints it accepts. */
15672 if (filter && !filter (tp))
15675 tp->ops->print_recreate (tp, fp);
15677 /* Note, we can't rely on tp->number for anything, as we can't
15678 assume the recreated breakpoint numbers will match. Use $bpnum
15681 if (tp->cond_string)
15682 fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string);
15684 if (tp->ignore_count)
15685 fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count);
15689 volatile struct gdb_exception ex;
15691 fprintf_unfiltered (fp, " commands\n");
15693 ui_out_redirect (current_uiout, fp);
15694 TRY_CATCH (ex, RETURN_MASK_ALL)
15696 print_command_lines (current_uiout, tp->commands->commands, 2);
15698 ui_out_redirect (current_uiout, NULL);
15701 throw_exception (ex);
15703 fprintf_unfiltered (fp, " end\n");
15706 if (tp->enable_state == bp_disabled)
15707 fprintf_unfiltered (fp, "disable\n");
15709 /* If this is a multi-location breakpoint, check if the locations
15710 should be individually disabled. Watchpoint locations are
15711 special, and not user visible. */
15712 if (!is_watchpoint (tp) && tp->loc && tp->loc->next)
15714 struct bp_location *loc;
15717 for (loc = tp->loc; loc != NULL; loc = loc->next, n++)
15719 fprintf_unfiltered (fp, "disable $bpnum.%d\n", n);
15723 if (extra_trace_bits && *default_collect)
15724 fprintf_unfiltered (fp, "set default-collect %s\n", default_collect);
15726 do_cleanups (cleanup);
15728 printf_filtered (_("Saved to file '%s'.\n"), filename);
15731 /* The `save breakpoints' command. */
15734 save_breakpoints_command (char *args, int from_tty)
15736 save_breakpoints (args, from_tty, NULL);
15739 /* The `save tracepoints' command. */
15742 save_tracepoints_command (char *args, int from_tty)
15744 save_breakpoints (args, from_tty, is_tracepoint);
15747 /* Create a vector of all tracepoints. */
15749 VEC(breakpoint_p) *
15750 all_tracepoints (void)
15752 VEC(breakpoint_p) *tp_vec = 0;
15753 struct breakpoint *tp;
15755 ALL_TRACEPOINTS (tp)
15757 VEC_safe_push (breakpoint_p, tp_vec, tp);
15764 /* This help string is used for the break, hbreak, tbreak and thbreak
15765 commands. It is defined as a macro to prevent duplication.
15766 COMMAND should be a string constant containing the name of the
15768 #define BREAK_ARGS_HELP(command) \
15769 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15770 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15771 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15772 guessed probe type) or `-probe-stap' (for a SystemTap probe).\n\
15773 LOCATION may be a line number, function name, or \"*\" and an address.\n\
15774 If a line number is specified, break at start of code for that line.\n\
15775 If a function is specified, break at start of code for that function.\n\
15776 If an address is specified, break at that exact address.\n\
15777 With no LOCATION, uses current execution address of the selected\n\
15778 stack frame. This is useful for breaking on return to a stack frame.\n\
15780 THREADNUM is the number from \"info threads\".\n\
15781 CONDITION is a boolean expression.\n\
15783 Multiple breakpoints at one place are permitted, and useful if their\n\
15784 conditions are different.\n\
15786 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15788 /* List of subcommands for "catch". */
15789 static struct cmd_list_element *catch_cmdlist;
15791 /* List of subcommands for "tcatch". */
15792 static struct cmd_list_element *tcatch_cmdlist;
15795 add_catch_command (char *name, char *docstring,
15796 void (*sfunc) (char *args, int from_tty,
15797 struct cmd_list_element *command),
15798 completer_ftype *completer,
15799 void *user_data_catch,
15800 void *user_data_tcatch)
15802 struct cmd_list_element *command;
15804 command = add_cmd (name, class_breakpoint, NULL, docstring,
15806 set_cmd_sfunc (command, sfunc);
15807 set_cmd_context (command, user_data_catch);
15808 set_cmd_completer (command, completer);
15810 command = add_cmd (name, class_breakpoint, NULL, docstring,
15812 set_cmd_sfunc (command, sfunc);
15813 set_cmd_context (command, user_data_tcatch);
15814 set_cmd_completer (command, completer);
15818 clear_syscall_counts (struct inferior *inf)
15820 struct catch_syscall_inferior_data *inf_data
15821 = get_catch_syscall_inferior_data (inf);
15823 inf_data->total_syscalls_count = 0;
15824 inf_data->any_syscall_count = 0;
15825 VEC_free (int, inf_data->syscalls_counts);
15829 save_command (char *arg, int from_tty)
15831 printf_unfiltered (_("\"save\" must be followed by "
15832 "the name of a save subcommand.\n"));
15833 help_list (save_cmdlist, "save ", -1, gdb_stdout);
15836 struct breakpoint *
15837 iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *),
15840 struct breakpoint *b, *b_tmp;
15842 ALL_BREAKPOINTS_SAFE (b, b_tmp)
15844 if ((*callback) (b, data))
15851 /* Zero if any of the breakpoint's locations could be a location where
15852 functions have been inlined, nonzero otherwise. */
15855 is_non_inline_function (struct breakpoint *b)
15857 /* The shared library event breakpoint is set on the address of a
15858 non-inline function. */
15859 if (b->type == bp_shlib_event)
15865 /* Nonzero if the specified PC cannot be a location where functions
15866 have been inlined. */
15869 pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc,
15870 const struct target_waitstatus *ws)
15872 struct breakpoint *b;
15873 struct bp_location *bl;
15875 ALL_BREAKPOINTS (b)
15877 if (!is_non_inline_function (b))
15880 for (bl = b->loc; bl != NULL; bl = bl->next)
15882 if (!bl->shlib_disabled
15883 && bpstat_check_location (bl, aspace, pc, ws))
15891 /* Remove any references to OBJFILE which is going to be freed. */
15894 breakpoint_free_objfile (struct objfile *objfile)
15896 struct bp_location **locp, *loc;
15898 ALL_BP_LOCATIONS (loc, locp)
15899 if (loc->symtab != NULL && loc->symtab->objfile == objfile)
15900 loc->symtab = NULL;
15904 initialize_breakpoint_ops (void)
15906 static int initialized = 0;
15908 struct breakpoint_ops *ops;
15914 /* The breakpoint_ops structure to be inherit by all kinds of
15915 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15916 internal and momentary breakpoints, etc.). */
15917 ops = &bkpt_base_breakpoint_ops;
15918 *ops = base_breakpoint_ops;
15919 ops->re_set = bkpt_re_set;
15920 ops->insert_location = bkpt_insert_location;
15921 ops->remove_location = bkpt_remove_location;
15922 ops->breakpoint_hit = bkpt_breakpoint_hit;
15923 ops->create_sals_from_address = bkpt_create_sals_from_address;
15924 ops->create_breakpoints_sal = bkpt_create_breakpoints_sal;
15925 ops->decode_linespec = bkpt_decode_linespec;
15927 /* The breakpoint_ops structure to be used in regular breakpoints. */
15928 ops = &bkpt_breakpoint_ops;
15929 *ops = bkpt_base_breakpoint_ops;
15930 ops->re_set = bkpt_re_set;
15931 ops->resources_needed = bkpt_resources_needed;
15932 ops->print_it = bkpt_print_it;
15933 ops->print_mention = bkpt_print_mention;
15934 ops->print_recreate = bkpt_print_recreate;
15936 /* Ranged breakpoints. */
15937 ops = &ranged_breakpoint_ops;
15938 *ops = bkpt_breakpoint_ops;
15939 ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint;
15940 ops->resources_needed = resources_needed_ranged_breakpoint;
15941 ops->print_it = print_it_ranged_breakpoint;
15942 ops->print_one = print_one_ranged_breakpoint;
15943 ops->print_one_detail = print_one_detail_ranged_breakpoint;
15944 ops->print_mention = print_mention_ranged_breakpoint;
15945 ops->print_recreate = print_recreate_ranged_breakpoint;
15947 /* Internal breakpoints. */
15948 ops = &internal_breakpoint_ops;
15949 *ops = bkpt_base_breakpoint_ops;
15950 ops->re_set = internal_bkpt_re_set;
15951 ops->check_status = internal_bkpt_check_status;
15952 ops->print_it = internal_bkpt_print_it;
15953 ops->print_mention = internal_bkpt_print_mention;
15955 /* Momentary breakpoints. */
15956 ops = &momentary_breakpoint_ops;
15957 *ops = bkpt_base_breakpoint_ops;
15958 ops->re_set = momentary_bkpt_re_set;
15959 ops->check_status = momentary_bkpt_check_status;
15960 ops->print_it = momentary_bkpt_print_it;
15961 ops->print_mention = momentary_bkpt_print_mention;
15963 /* Momentary breakpoints for bp_longjmp and bp_exception. */
15964 ops = &longjmp_breakpoint_ops;
15965 *ops = momentary_breakpoint_ops;
15966 ops->dtor = longjmp_bkpt_dtor;
15968 /* Probe breakpoints. */
15969 ops = &bkpt_probe_breakpoint_ops;
15970 *ops = bkpt_breakpoint_ops;
15971 ops->insert_location = bkpt_probe_insert_location;
15972 ops->remove_location = bkpt_probe_remove_location;
15973 ops->create_sals_from_address = bkpt_probe_create_sals_from_address;
15974 ops->decode_linespec = bkpt_probe_decode_linespec;
15976 /* GNU v3 exception catchpoints. */
15977 ops = &gnu_v3_exception_catchpoint_ops;
15978 *ops = bkpt_breakpoint_ops;
15979 ops->print_it = print_it_exception_catchpoint;
15980 ops->print_one = print_one_exception_catchpoint;
15981 ops->print_mention = print_mention_exception_catchpoint;
15982 ops->print_recreate = print_recreate_exception_catchpoint;
15985 ops = &watchpoint_breakpoint_ops;
15986 *ops = base_breakpoint_ops;
15987 ops->dtor = dtor_watchpoint;
15988 ops->re_set = re_set_watchpoint;
15989 ops->insert_location = insert_watchpoint;
15990 ops->remove_location = remove_watchpoint;
15991 ops->breakpoint_hit = breakpoint_hit_watchpoint;
15992 ops->check_status = check_status_watchpoint;
15993 ops->resources_needed = resources_needed_watchpoint;
15994 ops->works_in_software_mode = works_in_software_mode_watchpoint;
15995 ops->print_it = print_it_watchpoint;
15996 ops->print_mention = print_mention_watchpoint;
15997 ops->print_recreate = print_recreate_watchpoint;
15999 /* Masked watchpoints. */
16000 ops = &masked_watchpoint_breakpoint_ops;
16001 *ops = watchpoint_breakpoint_ops;
16002 ops->insert_location = insert_masked_watchpoint;
16003 ops->remove_location = remove_masked_watchpoint;
16004 ops->resources_needed = resources_needed_masked_watchpoint;
16005 ops->works_in_software_mode = works_in_software_mode_masked_watchpoint;
16006 ops->print_it = print_it_masked_watchpoint;
16007 ops->print_one_detail = print_one_detail_masked_watchpoint;
16008 ops->print_mention = print_mention_masked_watchpoint;
16009 ops->print_recreate = print_recreate_masked_watchpoint;
16012 ops = &tracepoint_breakpoint_ops;
16013 *ops = base_breakpoint_ops;
16014 ops->re_set = tracepoint_re_set;
16015 ops->breakpoint_hit = tracepoint_breakpoint_hit;
16016 ops->print_one_detail = tracepoint_print_one_detail;
16017 ops->print_mention = tracepoint_print_mention;
16018 ops->print_recreate = tracepoint_print_recreate;
16019 ops->create_sals_from_address = tracepoint_create_sals_from_address;
16020 ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal;
16021 ops->decode_linespec = tracepoint_decode_linespec;
16023 /* Probe tracepoints. */
16024 ops = &tracepoint_probe_breakpoint_ops;
16025 *ops = tracepoint_breakpoint_ops;
16026 ops->create_sals_from_address = tracepoint_probe_create_sals_from_address;
16027 ops->decode_linespec = tracepoint_probe_decode_linespec;
16029 /* Static tracepoints with marker (`-m'). */
16030 ops = &strace_marker_breakpoint_ops;
16031 *ops = tracepoint_breakpoint_ops;
16032 ops->create_sals_from_address = strace_marker_create_sals_from_address;
16033 ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal;
16034 ops->decode_linespec = strace_marker_decode_linespec;
16036 /* Fork catchpoints. */
16037 ops = &catch_fork_breakpoint_ops;
16038 *ops = base_breakpoint_ops;
16039 ops->insert_location = insert_catch_fork;
16040 ops->remove_location = remove_catch_fork;
16041 ops->breakpoint_hit = breakpoint_hit_catch_fork;
16042 ops->print_it = print_it_catch_fork;
16043 ops->print_one = print_one_catch_fork;
16044 ops->print_mention = print_mention_catch_fork;
16045 ops->print_recreate = print_recreate_catch_fork;
16047 /* Vfork catchpoints. */
16048 ops = &catch_vfork_breakpoint_ops;
16049 *ops = base_breakpoint_ops;
16050 ops->insert_location = insert_catch_vfork;
16051 ops->remove_location = remove_catch_vfork;
16052 ops->breakpoint_hit = breakpoint_hit_catch_vfork;
16053 ops->print_it = print_it_catch_vfork;
16054 ops->print_one = print_one_catch_vfork;
16055 ops->print_mention = print_mention_catch_vfork;
16056 ops->print_recreate = print_recreate_catch_vfork;
16058 /* Exec catchpoints. */
16059 ops = &catch_exec_breakpoint_ops;
16060 *ops = base_breakpoint_ops;
16061 ops->dtor = dtor_catch_exec;
16062 ops->insert_location = insert_catch_exec;
16063 ops->remove_location = remove_catch_exec;
16064 ops->breakpoint_hit = breakpoint_hit_catch_exec;
16065 ops->print_it = print_it_catch_exec;
16066 ops->print_one = print_one_catch_exec;
16067 ops->print_mention = print_mention_catch_exec;
16068 ops->print_recreate = print_recreate_catch_exec;
16070 /* Syscall catchpoints. */
16071 ops = &catch_syscall_breakpoint_ops;
16072 *ops = base_breakpoint_ops;
16073 ops->dtor = dtor_catch_syscall;
16074 ops->insert_location = insert_catch_syscall;
16075 ops->remove_location = remove_catch_syscall;
16076 ops->breakpoint_hit = breakpoint_hit_catch_syscall;
16077 ops->print_it = print_it_catch_syscall;
16078 ops->print_one = print_one_catch_syscall;
16079 ops->print_mention = print_mention_catch_syscall;
16080 ops->print_recreate = print_recreate_catch_syscall;
16082 /* Solib-related catchpoints. */
16083 ops = &catch_solib_breakpoint_ops;
16084 *ops = base_breakpoint_ops;
16085 ops->dtor = dtor_catch_solib;
16086 ops->insert_location = insert_catch_solib;
16087 ops->remove_location = remove_catch_solib;
16088 ops->breakpoint_hit = breakpoint_hit_catch_solib;
16089 ops->check_status = check_status_catch_solib;
16090 ops->print_it = print_it_catch_solib;
16091 ops->print_one = print_one_catch_solib;
16092 ops->print_mention = print_mention_catch_solib;
16093 ops->print_recreate = print_recreate_catch_solib;
16095 ops = &dprintf_breakpoint_ops;
16096 *ops = bkpt_base_breakpoint_ops;
16097 ops->re_set = dprintf_re_set;
16098 ops->resources_needed = bkpt_resources_needed;
16099 ops->print_it = bkpt_print_it;
16100 ops->print_mention = bkpt_print_mention;
16101 ops->print_recreate = bkpt_print_recreate;
16104 /* Chain containing all defined "enable breakpoint" subcommands. */
16106 static struct cmd_list_element *enablebreaklist = NULL;
16109 _initialize_breakpoint (void)
16111 struct cmd_list_element *c;
16113 initialize_breakpoint_ops ();
16115 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
16116 observer_attach_inferior_exit (clear_syscall_counts);
16117 observer_attach_memory_changed (invalidate_bp_value_on_memory_change);
16119 breakpoint_objfile_key
16120 = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes);
16122 catch_syscall_inferior_data
16123 = register_inferior_data_with_cleanup (NULL,
16124 catch_syscall_inferior_data_cleanup);
16126 breakpoint_chain = 0;
16127 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
16128 before a breakpoint is set. */
16129 breakpoint_count = 0;
16131 tracepoint_count = 0;
16133 add_com ("ignore", class_breakpoint, ignore_command, _("\
16134 Set ignore-count of breakpoint number N to COUNT.\n\
16135 Usage is `ignore N COUNT'."));
16137 add_com_alias ("bc", "ignore", class_breakpoint, 1);
16139 add_com ("commands", class_breakpoint, commands_command, _("\
16140 Set commands to be executed when a breakpoint is hit.\n\
16141 Give breakpoint number as argument after \"commands\".\n\
16142 With no argument, the targeted breakpoint is the last one set.\n\
16143 The commands themselves follow starting on the next line.\n\
16144 Type a line containing \"end\" to indicate the end of them.\n\
16145 Give \"silent\" as the first line to make the breakpoint silent;\n\
16146 then no output is printed when it is hit, except what the commands print."));
16148 c = add_com ("condition", class_breakpoint, condition_command, _("\
16149 Specify breakpoint number N to break only if COND is true.\n\
16150 Usage is `condition N COND', where N is an integer and COND is an\n\
16151 expression to be evaluated whenever breakpoint N is reached."));
16152 set_cmd_completer (c, condition_completer);
16154 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
16155 Set a temporary breakpoint.\n\
16156 Like \"break\" except the breakpoint is only temporary,\n\
16157 so it will be deleted when hit. Equivalent to \"break\" followed\n\
16158 by using \"enable delete\" on the breakpoint number.\n\
16160 BREAK_ARGS_HELP ("tbreak")));
16161 set_cmd_completer (c, location_completer);
16163 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
16164 Set a hardware assisted breakpoint.\n\
16165 Like \"break\" except the breakpoint requires hardware support,\n\
16166 some target hardware may not have this support.\n\
16168 BREAK_ARGS_HELP ("hbreak")));
16169 set_cmd_completer (c, location_completer);
16171 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
16172 Set a temporary hardware assisted breakpoint.\n\
16173 Like \"hbreak\" except the breakpoint is only temporary,\n\
16174 so it will be deleted when hit.\n\
16176 BREAK_ARGS_HELP ("thbreak")));
16177 set_cmd_completer (c, location_completer);
16179 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
16180 Enable some breakpoints.\n\
16181 Give breakpoint numbers (separated by spaces) as arguments.\n\
16182 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16183 This is used to cancel the effect of the \"disable\" command.\n\
16184 With a subcommand you can enable temporarily."),
16185 &enablelist, "enable ", 1, &cmdlist);
16187 add_com ("ab", class_breakpoint, enable_command, _("\
16188 Enable some breakpoints.\n\
16189 Give breakpoint numbers (separated by spaces) as arguments.\n\
16190 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16191 This is used to cancel the effect of the \"disable\" command.\n\
16192 With a subcommand you can enable temporarily."));
16194 add_com_alias ("en", "enable", class_breakpoint, 1);
16196 add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
16197 Enable some breakpoints.\n\
16198 Give breakpoint numbers (separated by spaces) as arguments.\n\
16199 This is used to cancel the effect of the \"disable\" command.\n\
16200 May be abbreviated to simply \"enable\".\n"),
16201 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
16203 add_cmd ("once", no_class, enable_once_command, _("\
16204 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16205 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16208 add_cmd ("delete", no_class, enable_delete_command, _("\
16209 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16210 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16213 add_cmd ("count", no_class, enable_count_command, _("\
16214 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16215 If a breakpoint is hit while enabled in this fashion,\n\
16216 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16219 add_cmd ("delete", no_class, enable_delete_command, _("\
16220 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16221 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16224 add_cmd ("once", no_class, enable_once_command, _("\
16225 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16226 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16229 add_cmd ("count", no_class, enable_count_command, _("\
16230 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16231 If a breakpoint is hit while enabled in this fashion,\n\
16232 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16235 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
16236 Disable some breakpoints.\n\
16237 Arguments are breakpoint numbers with spaces in between.\n\
16238 To disable all breakpoints, give no argument.\n\
16239 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
16240 &disablelist, "disable ", 1, &cmdlist);
16241 add_com_alias ("dis", "disable", class_breakpoint, 1);
16242 add_com_alias ("disa", "disable", class_breakpoint, 1);
16244 add_com ("sb", class_breakpoint, disable_command, _("\
16245 Disable some breakpoints.\n\
16246 Arguments are breakpoint numbers with spaces in between.\n\
16247 To disable all breakpoints, give no argument.\n\
16248 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
16250 add_cmd ("breakpoints", class_alias, disable_command, _("\
16251 Disable some breakpoints.\n\
16252 Arguments are breakpoint numbers with spaces in between.\n\
16253 To disable all breakpoints, give no argument.\n\
16254 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
16255 This command may be abbreviated \"disable\"."),
16258 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
16259 Delete some breakpoints or auto-display expressions.\n\
16260 Arguments are breakpoint numbers with spaces in between.\n\
16261 To delete all breakpoints, give no argument.\n\
16263 Also a prefix command for deletion of other GDB objects.\n\
16264 The \"unset\" command is also an alias for \"delete\"."),
16265 &deletelist, "delete ", 1, &cmdlist);
16266 add_com_alias ("d", "delete", class_breakpoint, 1);
16267 add_com_alias ("del", "delete", class_breakpoint, 1);
16269 add_com ("db", class_breakpoint, delete_command, _("\
16270 Delete some breakpoints.\n\
16271 Arguments are breakpoint numbers with spaces in between.\n\
16272 To delete all breakpoints, give no argument.\n"));
16274 add_cmd ("breakpoints", class_alias, delete_command, _("\
16275 Delete some breakpoints or auto-display expressions.\n\
16276 Arguments are breakpoint numbers with spaces in between.\n\
16277 To delete all breakpoints, give no argument.\n\
16278 This command may be abbreviated \"delete\"."),
16281 add_com ("clear", class_breakpoint, clear_command, _("\
16282 Clear breakpoint at specified line or function.\n\
16283 Argument may be line number, function name, or \"*\" and an address.\n\
16284 If line number is specified, all breakpoints in that line are cleared.\n\
16285 If function is specified, breakpoints at beginning of function are cleared.\n\
16286 If an address is specified, breakpoints at that address are cleared.\n\
16288 With no argument, clears all breakpoints in the line that the selected frame\n\
16289 is executing in.\n\
16291 See also the \"delete\" command which clears breakpoints by number."));
16292 add_com_alias ("cl", "clear", class_breakpoint, 1);
16294 c = add_com ("break", class_breakpoint, break_command, _("\
16295 Set breakpoint at specified line or function.\n"
16296 BREAK_ARGS_HELP ("break")));
16297 set_cmd_completer (c, location_completer);
16299 add_com_alias ("b", "break", class_run, 1);
16300 add_com_alias ("br", "break", class_run, 1);
16301 add_com_alias ("bre", "break", class_run, 1);
16302 add_com_alias ("brea", "break", class_run, 1);
16305 add_com_alias ("ba", "break", class_breakpoint, 1);
16309 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
16310 Break in function/address or break at a line in the current file."),
16311 &stoplist, "stop ", 1, &cmdlist);
16312 add_cmd ("in", class_breakpoint, stopin_command,
16313 _("Break in function or address."), &stoplist);
16314 add_cmd ("at", class_breakpoint, stopat_command,
16315 _("Break at a line in the current file."), &stoplist);
16316 add_com ("status", class_info, breakpoints_info, _("\
16317 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16318 The \"Type\" column indicates one of:\n\
16319 \tbreakpoint - normal breakpoint\n\
16320 \twatchpoint - watchpoint\n\
16321 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16322 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16323 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16324 address and file/line number respectively.\n\
16326 Convenience variable \"$_\" and default examine address for \"x\"\n\
16327 are set to the address of the last breakpoint listed unless the command\n\
16328 is prefixed with \"server \".\n\n\
16329 Convenience variable \"$bpnum\" contains the number of the last\n\
16330 breakpoint set."));
16333 add_info ("breakpoints", breakpoints_info, _("\
16334 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
16335 The \"Type\" column indicates one of:\n\
16336 \tbreakpoint - normal breakpoint\n\
16337 \twatchpoint - watchpoint\n\
16338 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16339 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16340 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16341 address and file/line number respectively.\n\
16343 Convenience variable \"$_\" and default examine address for \"x\"\n\
16344 are set to the address of the last breakpoint listed unless the command\n\
16345 is prefixed with \"server \".\n\n\
16346 Convenience variable \"$bpnum\" contains the number of the last\n\
16347 breakpoint set."));
16349 add_info_alias ("b", "breakpoints", 1);
16352 add_com ("lb", class_breakpoint, breakpoints_info, _("\
16353 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16354 The \"Type\" column indicates one of:\n\
16355 \tbreakpoint - normal breakpoint\n\
16356 \twatchpoint - watchpoint\n\
16357 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16358 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16359 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16360 address and file/line number respectively.\n\
16362 Convenience variable \"$_\" and default examine address for \"x\"\n\
16363 are set to the address of the last breakpoint listed unless the command\n\
16364 is prefixed with \"server \".\n\n\
16365 Convenience variable \"$bpnum\" contains the number of the last\n\
16366 breakpoint set."));
16368 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
16369 Status of all breakpoints, or breakpoint number NUMBER.\n\
16370 The \"Type\" column indicates one of:\n\
16371 \tbreakpoint - normal breakpoint\n\
16372 \twatchpoint - watchpoint\n\
16373 \tlongjmp - internal breakpoint used to step through longjmp()\n\
16374 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
16375 \tuntil - internal breakpoint used by the \"until\" command\n\
16376 \tfinish - internal breakpoint used by the \"finish\" command\n\
16377 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16378 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16379 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16380 address and file/line number respectively.\n\
16382 Convenience variable \"$_\" and default examine address for \"x\"\n\
16383 are set to the address of the last breakpoint listed unless the command\n\
16384 is prefixed with \"server \".\n\n\
16385 Convenience variable \"$bpnum\" contains the number of the last\n\
16387 &maintenanceinfolist);
16389 add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\
16390 Set catchpoints to catch events."),
16391 &catch_cmdlist, "catch ",
16392 0/*allow-unknown*/, &cmdlist);
16394 add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\
16395 Set temporary catchpoints to catch events."),
16396 &tcatch_cmdlist, "tcatch ",
16397 0/*allow-unknown*/, &cmdlist);
16399 /* Add catch and tcatch sub-commands. */
16400 add_catch_command ("catch", _("\
16401 Catch an exception, when caught."),
16402 catch_catch_command,
16406 add_catch_command ("throw", _("\
16407 Catch an exception, when thrown."),
16408 catch_throw_command,
16412 add_catch_command ("rethrow", _("\
16413 Catch an exception, when rethrown."),
16414 catch_rethrow_command,
16418 add_catch_command ("fork", _("Catch calls to fork."),
16419 catch_fork_command_1,
16421 (void *) (uintptr_t) catch_fork_permanent,
16422 (void *) (uintptr_t) catch_fork_temporary);
16423 add_catch_command ("vfork", _("Catch calls to vfork."),
16424 catch_fork_command_1,
16426 (void *) (uintptr_t) catch_vfork_permanent,
16427 (void *) (uintptr_t) catch_vfork_temporary);
16428 add_catch_command ("exec", _("Catch calls to exec."),
16429 catch_exec_command_1,
16433 add_catch_command ("load", _("Catch loads of shared libraries.\n\
16434 Usage: catch load [REGEX]\n\
16435 If REGEX is given, only stop for libraries matching the regular expression."),
16436 catch_load_command_1,
16440 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
16441 Usage: catch unload [REGEX]\n\
16442 If REGEX is given, only stop for libraries matching the regular expression."),
16443 catch_unload_command_1,
16447 add_catch_command ("syscall", _("\
16448 Catch system calls by their names and/or numbers.\n\
16449 Arguments say which system calls to catch. If no arguments\n\
16450 are given, every system call will be caught.\n\
16451 Arguments, if given, should be one or more system call names\n\
16452 (if your system supports that), or system call numbers."),
16453 catch_syscall_command_1,
16454 catch_syscall_completer,
16458 c = add_com ("watch", class_breakpoint, watch_command, _("\
16459 Set a watchpoint for an expression.\n\
16460 Usage: watch [-l|-location] EXPRESSION\n\
16461 A watchpoint stops execution of your program whenever the value of\n\
16462 an expression changes.\n\
16463 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16464 the memory to which it refers."));
16465 set_cmd_completer (c, expression_completer);
16467 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
16468 Set a read watchpoint for an expression.\n\
16469 Usage: rwatch [-l|-location] EXPRESSION\n\
16470 A watchpoint stops execution of your program whenever the value of\n\
16471 an expression is read.\n\
16472 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16473 the memory to which it refers."));
16474 set_cmd_completer (c, expression_completer);
16476 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
16477 Set a watchpoint for an expression.\n\
16478 Usage: awatch [-l|-location] EXPRESSION\n\
16479 A watchpoint stops execution of your program whenever the value of\n\
16480 an expression is either read or written.\n\
16481 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16482 the memory to which it refers."));
16483 set_cmd_completer (c, expression_completer);
16485 add_info ("watchpoints", watchpoints_info, _("\
16486 Status of specified watchpoints (all watchpoints if no argument)."));
16488 /* XXX: cagney/2005-02-23: This should be a boolean, and should
16489 respond to changes - contrary to the description. */
16490 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
16491 &can_use_hw_watchpoints, _("\
16492 Set debugger's willingness to use watchpoint hardware."), _("\
16493 Show debugger's willingness to use watchpoint hardware."), _("\
16494 If zero, gdb will not use hardware for new watchpoints, even if\n\
16495 such is available. (However, any hardware watchpoints that were\n\
16496 created before setting this to nonzero, will continue to use watchpoint\n\
16499 show_can_use_hw_watchpoints,
16500 &setlist, &showlist);
16502 can_use_hw_watchpoints = 1;
16504 /* Tracepoint manipulation commands. */
16506 c = add_com ("trace", class_breakpoint, trace_command, _("\
16507 Set a tracepoint at specified line or function.\n\
16509 BREAK_ARGS_HELP ("trace") "\n\
16510 Do \"help tracepoints\" for info on other tracepoint commands."));
16511 set_cmd_completer (c, location_completer);
16513 add_com_alias ("tp", "trace", class_alias, 0);
16514 add_com_alias ("tr", "trace", class_alias, 1);
16515 add_com_alias ("tra", "trace", class_alias, 1);
16516 add_com_alias ("trac", "trace", class_alias, 1);
16518 c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\
16519 Set a fast tracepoint at specified line or function.\n\
16521 BREAK_ARGS_HELP ("ftrace") "\n\
16522 Do \"help tracepoints\" for info on other tracepoint commands."));
16523 set_cmd_completer (c, location_completer);
16525 c = add_com ("strace", class_breakpoint, strace_command, _("\
16526 Set a static tracepoint at specified line, function or marker.\n\
16528 strace [LOCATION] [if CONDITION]\n\
16529 LOCATION may be a line number, function name, \"*\" and an address,\n\
16530 or -m MARKER_ID.\n\
16531 If a line number is specified, probe the marker at start of code\n\
16532 for that line. If a function is specified, probe the marker at start\n\
16533 of code for that function. If an address is specified, probe the marker\n\
16534 at that exact address. If a marker id is specified, probe the marker\n\
16535 with that name. With no LOCATION, uses current execution address of\n\
16536 the selected stack frame.\n\
16537 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16538 This collects arbitrary user data passed in the probe point call to the\n\
16539 tracing library. You can inspect it when analyzing the trace buffer,\n\
16540 by printing the $_sdata variable like any other convenience variable.\n\
16542 CONDITION is a boolean expression.\n\
16544 Multiple tracepoints at one place are permitted, and useful if their\n\
16545 conditions are different.\n\
16547 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16548 Do \"help tracepoints\" for info on other tracepoint commands."));
16549 set_cmd_completer (c, location_completer);
16551 add_info ("tracepoints", tracepoints_info, _("\
16552 Status of specified tracepoints (all tracepoints if no argument).\n\
16553 Convenience variable \"$tpnum\" contains the number of the\n\
16554 last tracepoint set."));
16556 add_info_alias ("tp", "tracepoints", 1);
16558 add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
16559 Delete specified tracepoints.\n\
16560 Arguments are tracepoint numbers, separated by spaces.\n\
16561 No argument means delete all tracepoints."),
16563 add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist);
16565 c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
16566 Disable specified tracepoints.\n\
16567 Arguments are tracepoint numbers, separated by spaces.\n\
16568 No argument means disable all tracepoints."),
16570 deprecate_cmd (c, "disable");
16572 c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\
16573 Enable specified tracepoints.\n\
16574 Arguments are tracepoint numbers, separated by spaces.\n\
16575 No argument means enable all tracepoints."),
16577 deprecate_cmd (c, "enable");
16579 add_com ("passcount", class_trace, trace_pass_command, _("\
16580 Set the passcount for a tracepoint.\n\
16581 The trace will end when the tracepoint has been passed 'count' times.\n\
16582 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16583 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16585 add_prefix_cmd ("save", class_breakpoint, save_command,
16586 _("Save breakpoint definitions as a script."),
16587 &save_cmdlist, "save ",
16588 0/*allow-unknown*/, &cmdlist);
16590 c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\
16591 Save current breakpoint definitions as a script.\n\
16592 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16593 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16594 session to restore them."),
16596 set_cmd_completer (c, filename_completer);
16598 c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\
16599 Save current tracepoint definitions as a script.\n\
16600 Use the 'source' command in another debug session to restore them."),
16602 set_cmd_completer (c, filename_completer);
16604 c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0);
16605 deprecate_cmd (c, "save tracepoints");
16607 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
16608 Breakpoint specific settings\n\
16609 Configure various breakpoint-specific variables such as\n\
16610 pending breakpoint behavior"),
16611 &breakpoint_set_cmdlist, "set breakpoint ",
16612 0/*allow-unknown*/, &setlist);
16613 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
16614 Breakpoint specific settings\n\
16615 Configure various breakpoint-specific variables such as\n\
16616 pending breakpoint behavior"),
16617 &breakpoint_show_cmdlist, "show breakpoint ",
16618 0/*allow-unknown*/, &showlist);
16620 add_setshow_auto_boolean_cmd ("pending", no_class,
16621 &pending_break_support, _("\
16622 Set debugger's behavior regarding pending breakpoints."), _("\
16623 Show debugger's behavior regarding pending breakpoints."), _("\
16624 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16625 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16626 an error. If auto, an unrecognized breakpoint location results in a\n\
16627 user-query to see if a pending breakpoint should be created."),
16629 show_pending_break_support,
16630 &breakpoint_set_cmdlist,
16631 &breakpoint_show_cmdlist);
16633 pending_break_support = AUTO_BOOLEAN_AUTO;
16635 add_setshow_boolean_cmd ("auto-hw", no_class,
16636 &automatic_hardware_breakpoints, _("\
16637 Set automatic usage of hardware breakpoints."), _("\
16638 Show automatic usage of hardware breakpoints."), _("\
16639 If set, the debugger will automatically use hardware breakpoints for\n\
16640 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16641 a warning will be emitted for such breakpoints."),
16643 show_automatic_hardware_breakpoints,
16644 &breakpoint_set_cmdlist,
16645 &breakpoint_show_cmdlist);
16647 add_setshow_auto_boolean_cmd ("always-inserted", class_support,
16648 &always_inserted_mode, _("\
16649 Set mode for inserting breakpoints."), _("\
16650 Show mode for inserting breakpoints."), _("\
16651 When this mode is off, breakpoints are inserted in inferior when it is\n\
16652 resumed, and removed when execution stops. When this mode is on,\n\
16653 breakpoints are inserted immediately and removed only when the user\n\
16654 deletes the breakpoint. When this mode is auto (which is the default),\n\
16655 the behaviour depends on the non-stop setting (see help set non-stop).\n\
16656 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
16657 behaves as if always-inserted mode is on; if gdb is controlling the\n\
16658 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
16660 &show_always_inserted_mode,
16661 &breakpoint_set_cmdlist,
16662 &breakpoint_show_cmdlist);
16664 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint,
16665 condition_evaluation_enums,
16666 &condition_evaluation_mode_1, _("\
16667 Set mode of breakpoint condition evaluation."), _("\
16668 Show mode of breakpoint condition evaluation."), _("\
16669 When this is set to \"host\", breakpoint conditions will be\n\
16670 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16671 breakpoint conditions will be downloaded to the target (if the target\n\
16672 supports such feature) and conditions will be evaluated on the target's side.\n\
16673 If this is set to \"auto\" (default), this will be automatically set to\n\
16674 \"target\" if it supports condition evaluation, otherwise it will\n\
16675 be set to \"gdb\""),
16676 &set_condition_evaluation_mode,
16677 &show_condition_evaluation_mode,
16678 &breakpoint_set_cmdlist,
16679 &breakpoint_show_cmdlist);
16681 add_com ("break-range", class_breakpoint, break_range_command, _("\
16682 Set a breakpoint for an address range.\n\
16683 break-range START-LOCATION, END-LOCATION\n\
16684 where START-LOCATION and END-LOCATION can be one of the following:\n\
16685 LINENUM, for that line in the current file,\n\
16686 FILE:LINENUM, for that line in that file,\n\
16687 +OFFSET, for that number of lines after the current line\n\
16688 or the start of the range\n\
16689 FUNCTION, for the first line in that function,\n\
16690 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16691 *ADDRESS, for the instruction at that address.\n\
16693 The breakpoint will stop execution of the inferior whenever it executes\n\
16694 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16695 range (including START-LOCATION and END-LOCATION)."));
16697 c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\
16698 Set a dynamic printf at specified line or function.\n\
16699 dprintf location,format string,arg1,arg2,...\n\
16700 location may be a line number, function name, or \"*\" and an address.\n\
16701 If a line number is specified, break at start of code for that line.\n\
16702 If a function is specified, break at start of code for that function.\n\
16704 set_cmd_completer (c, location_completer);
16706 add_setshow_enum_cmd ("dprintf-style", class_support,
16707 dprintf_style_enums, &dprintf_style, _("\
16708 Set the style of usage for dynamic printf."), _("\
16709 Show the style of usage for dynamic printf."), _("\
16710 This setting chooses how GDB will do a dynamic printf.\n\
16711 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16712 console, as with the \"printf\" command.\n\
16713 If the value is \"call\", the print is done by calling a function in your\n\
16714 program; by default printf(), but you can choose a different function or\n\
16715 output stream by setting dprintf-function and dprintf-channel."),
16716 update_dprintf_commands, NULL,
16717 &setlist, &showlist);
16719 dprintf_function = xstrdup ("printf");
16720 add_setshow_string_cmd ("dprintf-function", class_support,
16721 &dprintf_function, _("\
16722 Set the function to use for dynamic printf"), _("\
16723 Show the function to use for dynamic printf"), NULL,
16724 update_dprintf_commands, NULL,
16725 &setlist, &showlist);
16727 dprintf_channel = xstrdup ("");
16728 add_setshow_string_cmd ("dprintf-channel", class_support,
16729 &dprintf_channel, _("\
16730 Set the channel to use for dynamic printf"), _("\
16731 Show the channel to use for dynamic printf"), NULL,
16732 update_dprintf_commands, NULL,
16733 &setlist, &showlist);
16735 add_setshow_boolean_cmd ("disconnected-dprintf", no_class,
16736 &disconnected_dprintf, _("\
16737 Set whether dprintf continues after GDB disconnects."), _("\
16738 Show whether dprintf continues after GDB disconnects."), _("\
16739 Use this to let dprintf commands continue to hit and produce output\n\
16740 even if GDB disconnects or detaches from the target."),
16743 &setlist, &showlist);
16745 add_com ("agent-printf", class_vars, agent_printf_command, _("\
16746 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16747 (target agent only) This is useful for formatted output in user-defined commands."));
16749 automatic_hardware_breakpoints = 1;
16751 observer_attach_about_to_proceed (breakpoint_about_to_proceed);