1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2014 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"
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"
70 #include "dummy-frame.h"
74 /* readline include files */
75 #include "readline/readline.h"
76 #include "readline/history.h"
78 /* readline defines this. */
81 #include "mi/mi-common.h"
82 #include "python/python.h"
84 /* Enums for exception-handling support. */
85 enum exception_event_kind
92 /* Prototypes for local functions. */
94 static void enable_delete_command (char *, int);
96 static void enable_once_command (char *, int);
98 static void enable_count_command (char *, int);
100 static void disable_command (char *, int);
102 static void enable_command (char *, int);
104 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *,
108 static void ignore_command (char *, int);
110 static int breakpoint_re_set_one (void *);
112 static void breakpoint_re_set_default (struct breakpoint *);
114 static void create_sals_from_address_default (char **,
115 struct linespec_result *,
119 static void create_breakpoints_sal_default (struct gdbarch *,
120 struct linespec_result *,
121 char *, char *, enum bptype,
122 enum bpdisp, int, int,
124 const struct breakpoint_ops *,
125 int, int, int, unsigned);
127 static void decode_linespec_default (struct breakpoint *, char **,
128 struct symtabs_and_lines *);
130 static void clear_command (char *, int);
132 static void catch_command (char *, int);
134 static int can_use_hardware_watchpoint (struct value *);
136 static void break_command_1 (char *, int, int);
138 static void mention (struct breakpoint *);
140 static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *,
142 const struct breakpoint_ops *);
143 static struct bp_location *add_location_to_breakpoint (struct breakpoint *,
144 const struct symtab_and_line *);
146 /* This function is used in gdbtk sources and thus can not be made
148 struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch,
149 struct symtab_and_line,
151 const struct breakpoint_ops *);
153 static struct breakpoint *
154 momentary_breakpoint_from_master (struct breakpoint *orig,
156 const struct breakpoint_ops *ops);
158 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
160 static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch,
164 static void describe_other_breakpoints (struct gdbarch *,
165 struct program_space *, CORE_ADDR,
166 struct obj_section *, int);
168 static int breakpoint_address_match (struct address_space *aspace1,
170 struct address_space *aspace2,
173 static int watchpoint_locations_match (struct bp_location *loc1,
174 struct bp_location *loc2);
176 static int breakpoint_location_address_match (struct bp_location *bl,
177 struct address_space *aspace,
180 static void breakpoints_info (char *, int);
182 static void watchpoints_info (char *, int);
184 static int breakpoint_1 (char *, int,
185 int (*) (const struct breakpoint *));
187 static int breakpoint_cond_eval (void *);
189 static void cleanup_executing_breakpoints (void *);
191 static void commands_command (char *, int);
193 static void condition_command (char *, int);
202 static int remove_breakpoint (struct bp_location *, insertion_state_t);
203 static int remove_breakpoint_1 (struct bp_location *, insertion_state_t);
205 static enum print_stop_action print_bp_stop_message (bpstat bs);
207 static int watchpoint_check (void *);
209 static void maintenance_info_breakpoints (char *, int);
211 static int hw_breakpoint_used_count (void);
213 static int hw_watchpoint_use_count (struct breakpoint *);
215 static int hw_watchpoint_used_count_others (struct breakpoint *except,
217 int *other_type_used);
219 static void hbreak_command (char *, int);
221 static void thbreak_command (char *, int);
223 static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp,
226 static void stop_command (char *arg, int from_tty);
228 static void stopin_command (char *arg, int from_tty);
230 static void stopat_command (char *arg, int from_tty);
232 static void tcatch_command (char *arg, int from_tty);
234 static void detach_single_step_breakpoints (void);
236 static int single_step_breakpoint_inserted_here_p (struct address_space *,
239 static void free_bp_location (struct bp_location *loc);
240 static void incref_bp_location (struct bp_location *loc);
241 static void decref_bp_location (struct bp_location **loc);
243 static struct bp_location *allocate_bp_location (struct breakpoint *bpt);
245 static void update_global_location_list (int);
247 static void update_global_location_list_nothrow (int);
249 static int is_hardware_watchpoint (const struct breakpoint *bpt);
251 static void insert_breakpoint_locations (void);
253 static int syscall_catchpoint_p (struct breakpoint *b);
255 static void tracepoints_info (char *, int);
257 static void delete_trace_command (char *, int);
259 static void enable_trace_command (char *, int);
261 static void disable_trace_command (char *, int);
263 static void trace_pass_command (char *, int);
265 static void set_tracepoint_count (int num);
267 static int is_masked_watchpoint (const struct breakpoint *b);
269 static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address);
271 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
274 static int strace_marker_p (struct breakpoint *b);
276 /* The abstract base class all breakpoint_ops structures inherit
278 struct breakpoint_ops base_breakpoint_ops;
280 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
281 that are implemented on top of software or hardware breakpoints
282 (user breakpoints, internal and momentary breakpoints, etc.). */
283 static struct breakpoint_ops bkpt_base_breakpoint_ops;
285 /* Internal breakpoints class type. */
286 static struct breakpoint_ops internal_breakpoint_ops;
288 /* Momentary breakpoints class type. */
289 static struct breakpoint_ops momentary_breakpoint_ops;
291 /* Momentary breakpoints for bp_longjmp and bp_exception class type. */
292 static struct breakpoint_ops longjmp_breakpoint_ops;
294 /* The breakpoint_ops structure to be used in regular user created
296 struct breakpoint_ops bkpt_breakpoint_ops;
298 /* Breakpoints set on probes. */
299 static struct breakpoint_ops bkpt_probe_breakpoint_ops;
301 /* Dynamic printf class type. */
302 struct breakpoint_ops dprintf_breakpoint_ops;
304 /* The style in which to perform a dynamic printf. This is a user
305 option because different output options have different tradeoffs;
306 if GDB does the printing, there is better error handling if there
307 is a problem with any of the arguments, but using an inferior
308 function lets you have special-purpose printers and sending of
309 output to the same place as compiled-in print functions. */
311 static const char dprintf_style_gdb[] = "gdb";
312 static const char dprintf_style_call[] = "call";
313 static const char dprintf_style_agent[] = "agent";
314 static const char *const dprintf_style_enums[] = {
320 static const char *dprintf_style = dprintf_style_gdb;
322 /* The function to use for dynamic printf if the preferred style is to
323 call into the inferior. The value is simply a string that is
324 copied into the command, so it can be anything that GDB can
325 evaluate to a callable address, not necessarily a function name. */
327 static char *dprintf_function = "";
329 /* The channel to use for dynamic printf if the preferred style is to
330 call into the inferior; if a nonempty string, it will be passed to
331 the call as the first argument, with the format string as the
332 second. As with the dprintf function, this can be anything that
333 GDB knows how to evaluate, so in addition to common choices like
334 "stderr", this could be an app-specific expression like
335 "mystreams[curlogger]". */
337 static char *dprintf_channel = "";
339 /* True if dprintf commands should continue to operate even if GDB
341 static int disconnected_dprintf = 1;
343 /* A reference-counted struct command_line. This lets multiple
344 breakpoints share a single command list. */
345 struct counted_command_line
347 /* The reference count. */
350 /* The command list. */
351 struct command_line *commands;
354 struct command_line *
355 breakpoint_commands (struct breakpoint *b)
357 return b->commands ? b->commands->commands : NULL;
360 /* Flag indicating that a command has proceeded the inferior past the
361 current breakpoint. */
363 static int breakpoint_proceeded;
366 bpdisp_text (enum bpdisp disp)
368 /* NOTE: the following values are a part of MI protocol and
369 represent values of 'disp' field returned when inferior stops at
371 static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"};
373 return bpdisps[(int) disp];
376 /* Prototypes for exported functions. */
377 /* If FALSE, gdb will not use hardware support for watchpoints, even
378 if such is available. */
379 static int can_use_hw_watchpoints;
382 show_can_use_hw_watchpoints (struct ui_file *file, int from_tty,
383 struct cmd_list_element *c,
386 fprintf_filtered (file,
387 _("Debugger's willingness to use "
388 "watchpoint hardware is %s.\n"),
392 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
393 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
394 for unrecognized breakpoint locations.
395 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
396 static enum auto_boolean pending_break_support;
398 show_pending_break_support (struct ui_file *file, int from_tty,
399 struct cmd_list_element *c,
402 fprintf_filtered (file,
403 _("Debugger's behavior regarding "
404 "pending breakpoints is %s.\n"),
408 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
409 set with "break" but falling in read-only memory.
410 If 0, gdb will warn about such breakpoints, but won't automatically
411 use hardware breakpoints. */
412 static int automatic_hardware_breakpoints;
414 show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty,
415 struct cmd_list_element *c,
418 fprintf_filtered (file,
419 _("Automatic usage of hardware breakpoints is %s.\n"),
423 /* If on, gdb will keep breakpoints inserted even as inferior is
424 stopped, and immediately insert any new breakpoints. If off, gdb
425 will insert breakpoints into inferior only when resuming it, and
426 will remove breakpoints upon stop. If auto, GDB will behave as ON
427 if in non-stop mode, and as OFF if all-stop mode.*/
429 static enum auto_boolean always_inserted_mode = AUTO_BOOLEAN_AUTO;
432 show_always_inserted_mode (struct ui_file *file, int from_tty,
433 struct cmd_list_element *c, const char *value)
435 if (always_inserted_mode == AUTO_BOOLEAN_AUTO)
436 fprintf_filtered (file,
437 _("Always inserted breakpoint "
438 "mode is %s (currently %s).\n"),
440 breakpoints_always_inserted_mode () ? "on" : "off");
442 fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"),
447 breakpoints_always_inserted_mode (void)
449 return (always_inserted_mode == AUTO_BOOLEAN_TRUE
450 || (always_inserted_mode == AUTO_BOOLEAN_AUTO && non_stop));
453 static const char condition_evaluation_both[] = "host or target";
455 /* Modes for breakpoint condition evaluation. */
456 static const char condition_evaluation_auto[] = "auto";
457 static const char condition_evaluation_host[] = "host";
458 static const char condition_evaluation_target[] = "target";
459 static const char *const condition_evaluation_enums[] = {
460 condition_evaluation_auto,
461 condition_evaluation_host,
462 condition_evaluation_target,
466 /* Global that holds the current mode for breakpoint condition evaluation. */
467 static const char *condition_evaluation_mode_1 = condition_evaluation_auto;
469 /* Global that we use to display information to the user (gets its value from
470 condition_evaluation_mode_1. */
471 static const char *condition_evaluation_mode = condition_evaluation_auto;
473 /* Translate a condition evaluation mode MODE into either "host"
474 or "target". This is used mostly to translate from "auto" to the
475 real setting that is being used. It returns the translated
479 translate_condition_evaluation_mode (const char *mode)
481 if (mode == condition_evaluation_auto)
483 if (target_supports_evaluation_of_breakpoint_conditions ())
484 return condition_evaluation_target;
486 return condition_evaluation_host;
492 /* Discovers what condition_evaluation_auto translates to. */
495 breakpoint_condition_evaluation_mode (void)
497 return translate_condition_evaluation_mode (condition_evaluation_mode);
500 /* Return true if GDB should evaluate breakpoint conditions or false
504 gdb_evaluates_breakpoint_condition_p (void)
506 const char *mode = breakpoint_condition_evaluation_mode ();
508 return (mode == condition_evaluation_host);
511 void _initialize_breakpoint (void);
513 /* Are we executing breakpoint commands? */
514 static int executing_breakpoint_commands;
516 /* Are overlay event breakpoints enabled? */
517 static int overlay_events_enabled;
519 /* See description in breakpoint.h. */
520 int target_exact_watchpoints = 0;
522 /* Walk the following statement or block through all breakpoints.
523 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
524 current breakpoint. */
526 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
528 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
529 for (B = breakpoint_chain; \
530 B ? (TMP=B->next, 1): 0; \
533 /* Similar iterator for the low-level breakpoints. SAFE variant is
534 not provided so update_global_location_list must not be called
535 while executing the block of ALL_BP_LOCATIONS. */
537 #define ALL_BP_LOCATIONS(B,BP_TMP) \
538 for (BP_TMP = bp_location; \
539 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
542 /* Iterates through locations with address ADDRESS for the currently selected
543 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
544 to where the loop should start from.
545 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
546 appropriate location to start with. */
548 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
549 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
550 BP_LOCP_TMP = BP_LOCP_START; \
552 && (BP_LOCP_TMP < bp_location + bp_location_count \
553 && (*BP_LOCP_TMP)->address == ADDRESS); \
556 /* Iterator for tracepoints only. */
558 #define ALL_TRACEPOINTS(B) \
559 for (B = breakpoint_chain; B; B = B->next) \
560 if (is_tracepoint (B))
562 /* Chains of all breakpoints defined. */
564 struct breakpoint *breakpoint_chain;
566 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
568 static struct bp_location **bp_location;
570 /* Number of elements of BP_LOCATION. */
572 static unsigned bp_location_count;
574 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
575 ADDRESS for the current elements of BP_LOCATION which get a valid
576 result from bp_location_has_shadow. You can use it for roughly
577 limiting the subrange of BP_LOCATION to scan for shadow bytes for
578 an address you need to read. */
580 static CORE_ADDR bp_location_placed_address_before_address_max;
582 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
583 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
584 BP_LOCATION which get a valid result from bp_location_has_shadow.
585 You can use it for roughly limiting the subrange of BP_LOCATION to
586 scan for shadow bytes for an address you need to read. */
588 static CORE_ADDR bp_location_shadow_len_after_address_max;
590 /* The locations that no longer correspond to any breakpoint, unlinked
591 from bp_location array, but for which a hit may still be reported
593 VEC(bp_location_p) *moribund_locations = NULL;
595 /* Number of last breakpoint made. */
597 static int breakpoint_count;
599 /* The value of `breakpoint_count' before the last command that
600 created breakpoints. If the last (break-like) command created more
601 than one breakpoint, then the difference between BREAKPOINT_COUNT
602 and PREV_BREAKPOINT_COUNT is more than one. */
603 static int prev_breakpoint_count;
605 /* Number of last tracepoint made. */
607 static int tracepoint_count;
609 static struct cmd_list_element *breakpoint_set_cmdlist;
610 static struct cmd_list_element *breakpoint_show_cmdlist;
611 struct cmd_list_element *save_cmdlist;
613 /* Return whether a breakpoint is an active enabled breakpoint. */
615 breakpoint_enabled (struct breakpoint *b)
617 return (b->enable_state == bp_enabled);
620 /* Set breakpoint count to NUM. */
623 set_breakpoint_count (int num)
625 prev_breakpoint_count = breakpoint_count;
626 breakpoint_count = num;
627 set_internalvar_integer (lookup_internalvar ("bpnum"), num);
630 /* Used by `start_rbreak_breakpoints' below, to record the current
631 breakpoint count before "rbreak" creates any breakpoint. */
632 static int rbreak_start_breakpoint_count;
634 /* Called at the start an "rbreak" command to record the first
638 start_rbreak_breakpoints (void)
640 rbreak_start_breakpoint_count = breakpoint_count;
643 /* Called at the end of an "rbreak" command to record the last
647 end_rbreak_breakpoints (void)
649 prev_breakpoint_count = rbreak_start_breakpoint_count;
652 /* Used in run_command to zero the hit count when a new run starts. */
655 clear_breakpoint_hit_counts (void)
657 struct breakpoint *b;
663 /* Allocate a new counted_command_line with reference count of 1.
664 The new structure owns COMMANDS. */
666 static struct counted_command_line *
667 alloc_counted_command_line (struct command_line *commands)
669 struct counted_command_line *result
670 = xmalloc (sizeof (struct counted_command_line));
673 result->commands = commands;
677 /* Increment reference count. This does nothing if CMD is NULL. */
680 incref_counted_command_line (struct counted_command_line *cmd)
686 /* Decrement reference count. If the reference count reaches 0,
687 destroy the counted_command_line. Sets *CMDP to NULL. This does
688 nothing if *CMDP is NULL. */
691 decref_counted_command_line (struct counted_command_line **cmdp)
695 if (--(*cmdp)->refc == 0)
697 free_command_lines (&(*cmdp)->commands);
704 /* A cleanup function that calls decref_counted_command_line. */
707 do_cleanup_counted_command_line (void *arg)
709 decref_counted_command_line (arg);
712 /* Create a cleanup that calls decref_counted_command_line on the
715 static struct cleanup *
716 make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp)
718 return make_cleanup (do_cleanup_counted_command_line, cmdp);
722 /* Return the breakpoint with the specified number, or NULL
723 if the number does not refer to an existing breakpoint. */
726 get_breakpoint (int num)
728 struct breakpoint *b;
731 if (b->number == num)
739 /* Mark locations as "conditions have changed" in case the target supports
740 evaluating conditions on its side. */
743 mark_breakpoint_modified (struct breakpoint *b)
745 struct bp_location *loc;
747 /* This is only meaningful if the target is
748 evaluating conditions and if the user has
749 opted for condition evaluation on the target's
751 if (gdb_evaluates_breakpoint_condition_p ()
752 || !target_supports_evaluation_of_breakpoint_conditions ())
755 if (!is_breakpoint (b))
758 for (loc = b->loc; loc; loc = loc->next)
759 loc->condition_changed = condition_modified;
762 /* Mark location as "conditions have changed" in case the target supports
763 evaluating conditions on its side. */
766 mark_breakpoint_location_modified (struct bp_location *loc)
768 /* This is only meaningful if the target is
769 evaluating conditions and if the user has
770 opted for condition evaluation on the target's
772 if (gdb_evaluates_breakpoint_condition_p ()
773 || !target_supports_evaluation_of_breakpoint_conditions ())
777 if (!is_breakpoint (loc->owner))
780 loc->condition_changed = condition_modified;
783 /* Sets the condition-evaluation mode using the static global
784 condition_evaluation_mode. */
787 set_condition_evaluation_mode (char *args, int from_tty,
788 struct cmd_list_element *c)
790 const char *old_mode, *new_mode;
792 if ((condition_evaluation_mode_1 == condition_evaluation_target)
793 && !target_supports_evaluation_of_breakpoint_conditions ())
795 condition_evaluation_mode_1 = condition_evaluation_mode;
796 warning (_("Target does not support breakpoint condition evaluation.\n"
797 "Using host evaluation mode instead."));
801 new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1);
802 old_mode = translate_condition_evaluation_mode (condition_evaluation_mode);
804 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
805 settings was "auto". */
806 condition_evaluation_mode = condition_evaluation_mode_1;
808 /* Only update the mode if the user picked a different one. */
809 if (new_mode != old_mode)
811 struct bp_location *loc, **loc_tmp;
812 /* If the user switched to a different evaluation mode, we
813 need to synch the changes with the target as follows:
815 "host" -> "target": Send all (valid) conditions to the target.
816 "target" -> "host": Remove all the conditions from the target.
819 if (new_mode == condition_evaluation_target)
821 /* Mark everything modified and synch conditions with the
823 ALL_BP_LOCATIONS (loc, loc_tmp)
824 mark_breakpoint_location_modified (loc);
828 /* Manually mark non-duplicate locations to synch conditions
829 with the target. We do this to remove all the conditions the
830 target knows about. */
831 ALL_BP_LOCATIONS (loc, loc_tmp)
832 if (is_breakpoint (loc->owner) && loc->inserted)
833 loc->needs_update = 1;
837 update_global_location_list (1);
843 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
844 what "auto" is translating to. */
847 show_condition_evaluation_mode (struct ui_file *file, int from_tty,
848 struct cmd_list_element *c, const char *value)
850 if (condition_evaluation_mode == condition_evaluation_auto)
851 fprintf_filtered (file,
852 _("Breakpoint condition evaluation "
853 "mode is %s (currently %s).\n"),
855 breakpoint_condition_evaluation_mode ());
857 fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"),
861 /* A comparison function for bp_location AP and BP that is used by
862 bsearch. This comparison function only cares about addresses, unlike
863 the more general bp_location_compare function. */
866 bp_location_compare_addrs (const void *ap, const void *bp)
868 struct bp_location *a = *(void **) ap;
869 struct bp_location *b = *(void **) bp;
871 if (a->address == b->address)
874 return ((a->address > b->address) - (a->address < b->address));
877 /* Helper function to skip all bp_locations with addresses
878 less than ADDRESS. It returns the first bp_location that
879 is greater than or equal to ADDRESS. If none is found, just
882 static struct bp_location **
883 get_first_locp_gte_addr (CORE_ADDR address)
885 struct bp_location dummy_loc;
886 struct bp_location *dummy_locp = &dummy_loc;
887 struct bp_location **locp_found = NULL;
889 /* Initialize the dummy location's address field. */
890 memset (&dummy_loc, 0, sizeof (struct bp_location));
891 dummy_loc.address = address;
893 /* Find a close match to the first location at ADDRESS. */
894 locp_found = bsearch (&dummy_locp, bp_location, bp_location_count,
895 sizeof (struct bp_location **),
896 bp_location_compare_addrs);
898 /* Nothing was found, nothing left to do. */
899 if (locp_found == NULL)
902 /* We may have found a location that is at ADDRESS but is not the first in the
903 location's list. Go backwards (if possible) and locate the first one. */
904 while ((locp_found - 1) >= bp_location
905 && (*(locp_found - 1))->address == address)
912 set_breakpoint_condition (struct breakpoint *b, char *exp,
915 xfree (b->cond_string);
916 b->cond_string = NULL;
918 if (is_watchpoint (b))
920 struct watchpoint *w = (struct watchpoint *) b;
927 struct bp_location *loc;
929 for (loc = b->loc; loc; loc = loc->next)
934 /* No need to free the condition agent expression
935 bytecode (if we have one). We will handle this
936 when we go through update_global_location_list. */
943 printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number);
947 const char *arg = exp;
949 /* I don't know if it matters whether this is the string the user
950 typed in or the decompiled expression. */
951 b->cond_string = xstrdup (arg);
952 b->condition_not_parsed = 0;
954 if (is_watchpoint (b))
956 struct watchpoint *w = (struct watchpoint *) b;
958 innermost_block = NULL;
960 w->cond_exp = parse_exp_1 (&arg, 0, 0, 0);
962 error (_("Junk at end of expression"));
963 w->cond_exp_valid_block = innermost_block;
967 struct bp_location *loc;
969 for (loc = b->loc; loc; loc = loc->next)
973 parse_exp_1 (&arg, loc->address,
974 block_for_pc (loc->address), 0);
976 error (_("Junk at end of expression"));
980 mark_breakpoint_modified (b);
982 observer_notify_breakpoint_modified (b);
985 /* Completion for the "condition" command. */
987 static VEC (char_ptr) *
988 condition_completer (struct cmd_list_element *cmd,
989 const char *text, const char *word)
993 text = skip_spaces_const (text);
994 space = skip_to_space_const (text);
998 struct breakpoint *b;
999 VEC (char_ptr) *result = NULL;
1003 /* We don't support completion of history indices. */
1004 if (isdigit (text[1]))
1006 return complete_internalvar (&text[1]);
1009 /* We're completing the breakpoint number. */
1010 len = strlen (text);
1016 xsnprintf (number, sizeof (number), "%d", b->number);
1018 if (strncmp (number, text, len) == 0)
1019 VEC_safe_push (char_ptr, result, xstrdup (number));
1025 /* We're completing the expression part. */
1026 text = skip_spaces_const (space);
1027 return expression_completer (cmd, text, word);
1030 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1033 condition_command (char *arg, int from_tty)
1035 struct breakpoint *b;
1040 error_no_arg (_("breakpoint number"));
1043 bnum = get_number (&p);
1045 error (_("Bad breakpoint argument: '%s'"), arg);
1048 if (b->number == bnum)
1050 /* Check if this breakpoint has a Python object assigned to
1051 it, and if it has a definition of the "stop"
1052 method. This method and conditions entered into GDB from
1053 the CLI are mutually exclusive. */
1055 && gdbpy_breakpoint_has_py_cond (b->py_bp_object))
1056 error (_("Cannot set a condition where a Python 'stop' "
1057 "method has been defined in the breakpoint."));
1058 set_breakpoint_condition (b, p, from_tty);
1060 if (is_breakpoint (b))
1061 update_global_location_list (1);
1066 error (_("No breakpoint number %d."), bnum);
1069 /* Check that COMMAND do not contain commands that are suitable
1070 only for tracepoints and not suitable for ordinary breakpoints.
1071 Throw if any such commands is found. */
1074 check_no_tracepoint_commands (struct command_line *commands)
1076 struct command_line *c;
1078 for (c = commands; c; c = c->next)
1082 if (c->control_type == while_stepping_control)
1083 error (_("The 'while-stepping' command can "
1084 "only be used for tracepoints"));
1086 for (i = 0; i < c->body_count; ++i)
1087 check_no_tracepoint_commands ((c->body_list)[i]);
1089 /* Not that command parsing removes leading whitespace and comment
1090 lines and also empty lines. So, we only need to check for
1091 command directly. */
1092 if (strstr (c->line, "collect ") == c->line)
1093 error (_("The 'collect' command can only be used for tracepoints"));
1095 if (strstr (c->line, "teval ") == c->line)
1096 error (_("The 'teval' command can only be used for tracepoints"));
1100 /* Encapsulate tests for different types of tracepoints. */
1103 is_tracepoint_type (enum bptype type)
1105 return (type == bp_tracepoint
1106 || type == bp_fast_tracepoint
1107 || type == bp_static_tracepoint);
1111 is_tracepoint (const struct breakpoint *b)
1113 return is_tracepoint_type (b->type);
1116 /* A helper function that validates that COMMANDS are valid for a
1117 breakpoint. This function will throw an exception if a problem is
1121 validate_commands_for_breakpoint (struct breakpoint *b,
1122 struct command_line *commands)
1124 if (is_tracepoint (b))
1126 struct tracepoint *t = (struct tracepoint *) b;
1127 struct command_line *c;
1128 struct command_line *while_stepping = 0;
1130 /* Reset the while-stepping step count. The previous commands
1131 might have included a while-stepping action, while the new
1135 /* We need to verify that each top-level element of commands is
1136 valid for tracepoints, that there's at most one
1137 while-stepping element, and that the while-stepping's body
1138 has valid tracing commands excluding nested while-stepping.
1139 We also need to validate the tracepoint action line in the
1140 context of the tracepoint --- validate_actionline actually
1141 has side effects, like setting the tracepoint's
1142 while-stepping STEP_COUNT, in addition to checking if the
1143 collect/teval actions parse and make sense in the
1144 tracepoint's context. */
1145 for (c = commands; c; c = c->next)
1147 if (c->control_type == while_stepping_control)
1149 if (b->type == bp_fast_tracepoint)
1150 error (_("The 'while-stepping' command "
1151 "cannot be used for fast tracepoint"));
1152 else if (b->type == bp_static_tracepoint)
1153 error (_("The 'while-stepping' command "
1154 "cannot be used for static tracepoint"));
1157 error (_("The 'while-stepping' command "
1158 "can be used only once"));
1163 validate_actionline (c->line, b);
1167 struct command_line *c2;
1169 gdb_assert (while_stepping->body_count == 1);
1170 c2 = while_stepping->body_list[0];
1171 for (; c2; c2 = c2->next)
1173 if (c2->control_type == while_stepping_control)
1174 error (_("The 'while-stepping' command cannot be nested"));
1180 check_no_tracepoint_commands (commands);
1184 /* Return a vector of all the static tracepoints set at ADDR. The
1185 caller is responsible for releasing the vector. */
1188 static_tracepoints_here (CORE_ADDR addr)
1190 struct breakpoint *b;
1191 VEC(breakpoint_p) *found = 0;
1192 struct bp_location *loc;
1195 if (b->type == bp_static_tracepoint)
1197 for (loc = b->loc; loc; loc = loc->next)
1198 if (loc->address == addr)
1199 VEC_safe_push(breakpoint_p, found, b);
1205 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1206 validate that only allowed commands are included. */
1209 breakpoint_set_commands (struct breakpoint *b,
1210 struct command_line *commands)
1212 validate_commands_for_breakpoint (b, commands);
1214 decref_counted_command_line (&b->commands);
1215 b->commands = alloc_counted_command_line (commands);
1216 observer_notify_breakpoint_modified (b);
1219 /* Set the internal `silent' flag on the breakpoint. Note that this
1220 is not the same as the "silent" that may appear in the breakpoint's
1224 breakpoint_set_silent (struct breakpoint *b, int silent)
1226 int old_silent = b->silent;
1229 if (old_silent != silent)
1230 observer_notify_breakpoint_modified (b);
1233 /* Set the thread for this breakpoint. If THREAD is -1, make the
1234 breakpoint work for any thread. */
1237 breakpoint_set_thread (struct breakpoint *b, int thread)
1239 int old_thread = b->thread;
1242 if (old_thread != thread)
1243 observer_notify_breakpoint_modified (b);
1246 /* Set the task for this breakpoint. If TASK is 0, make the
1247 breakpoint work for any task. */
1250 breakpoint_set_task (struct breakpoint *b, int task)
1252 int old_task = b->task;
1255 if (old_task != task)
1256 observer_notify_breakpoint_modified (b);
1260 check_tracepoint_command (char *line, void *closure)
1262 struct breakpoint *b = closure;
1264 validate_actionline (line, b);
1267 /* A structure used to pass information through
1268 map_breakpoint_numbers. */
1270 struct commands_info
1272 /* True if the command was typed at a tty. */
1275 /* The breakpoint range spec. */
1278 /* Non-NULL if the body of the commands are being read from this
1279 already-parsed command. */
1280 struct command_line *control;
1282 /* The command lines read from the user, or NULL if they have not
1284 struct counted_command_line *cmd;
1287 /* A callback for map_breakpoint_numbers that sets the commands for
1288 commands_command. */
1291 do_map_commands_command (struct breakpoint *b, void *data)
1293 struct commands_info *info = data;
1295 if (info->cmd == NULL)
1297 struct command_line *l;
1299 if (info->control != NULL)
1300 l = copy_command_lines (info->control->body_list[0]);
1303 struct cleanup *old_chain;
1306 str = xstrprintf (_("Type commands for breakpoint(s) "
1307 "%s, one per line."),
1310 old_chain = make_cleanup (xfree, str);
1312 l = read_command_lines (str,
1315 ? check_tracepoint_command : 0),
1318 do_cleanups (old_chain);
1321 info->cmd = alloc_counted_command_line (l);
1324 /* If a breakpoint was on the list more than once, we don't need to
1326 if (b->commands != info->cmd)
1328 validate_commands_for_breakpoint (b, info->cmd->commands);
1329 incref_counted_command_line (info->cmd);
1330 decref_counted_command_line (&b->commands);
1331 b->commands = info->cmd;
1332 observer_notify_breakpoint_modified (b);
1337 commands_command_1 (char *arg, int from_tty,
1338 struct command_line *control)
1340 struct cleanup *cleanups;
1341 struct commands_info info;
1343 info.from_tty = from_tty;
1344 info.control = control;
1346 /* If we read command lines from the user, then `info' will hold an
1347 extra reference to the commands that we must clean up. */
1348 cleanups = make_cleanup_decref_counted_command_line (&info.cmd);
1350 if (arg == NULL || !*arg)
1352 if (breakpoint_count - prev_breakpoint_count > 1)
1353 arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1,
1355 else if (breakpoint_count > 0)
1356 arg = xstrprintf ("%d", breakpoint_count);
1359 /* So that we don't try to free the incoming non-NULL
1360 argument in the cleanup below. Mapping breakpoint
1361 numbers will fail in this case. */
1366 /* The command loop has some static state, so we need to preserve
1368 arg = xstrdup (arg);
1371 make_cleanup (xfree, arg);
1375 map_breakpoint_numbers (arg, do_map_commands_command, &info);
1377 if (info.cmd == NULL)
1378 error (_("No breakpoints specified."));
1380 do_cleanups (cleanups);
1384 commands_command (char *arg, int from_tty)
1386 commands_command_1 (arg, from_tty, NULL);
1389 /* Like commands_command, but instead of reading the commands from
1390 input stream, takes them from an already parsed command structure.
1392 This is used by cli-script.c to DTRT with breakpoint commands
1393 that are part of if and while bodies. */
1394 enum command_control_type
1395 commands_from_control_command (char *arg, struct command_line *cmd)
1397 commands_command_1 (arg, 0, cmd);
1398 return simple_control;
1401 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1404 bp_location_has_shadow (struct bp_location *bl)
1406 if (bl->loc_type != bp_loc_software_breakpoint)
1410 if (bl->target_info.shadow_len == 0)
1411 /* BL isn't valid, or doesn't shadow memory. */
1416 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1417 by replacing any memory breakpoints with their shadowed contents.
1419 If READBUF is not NULL, this buffer must not overlap with any of
1420 the breakpoint location's shadow_contents buffers. Otherwise,
1421 a failed assertion internal error will be raised.
1423 The range of shadowed area by each bp_location is:
1424 bl->address - bp_location_placed_address_before_address_max
1425 up to bl->address + bp_location_shadow_len_after_address_max
1426 The range we were requested to resolve shadows for is:
1427 memaddr ... memaddr + len
1428 Thus the safe cutoff boundaries for performance optimization are
1429 memaddr + len <= (bl->address
1430 - bp_location_placed_address_before_address_max)
1432 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1435 breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf,
1436 const gdb_byte *writebuf_org,
1437 ULONGEST memaddr, LONGEST len)
1439 /* Left boundary, right boundary and median element of our binary
1441 unsigned bc_l, bc_r, bc;
1443 /* Find BC_L which is a leftmost element which may affect BUF
1444 content. It is safe to report lower value but a failure to
1445 report higher one. */
1448 bc_r = bp_location_count;
1449 while (bc_l + 1 < bc_r)
1451 struct bp_location *bl;
1453 bc = (bc_l + bc_r) / 2;
1454 bl = bp_location[bc];
1456 /* Check first BL->ADDRESS will not overflow due to the added
1457 constant. Then advance the left boundary only if we are sure
1458 the BC element can in no way affect the BUF content (MEMADDR
1459 to MEMADDR + LEN range).
1461 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1462 offset so that we cannot miss a breakpoint with its shadow
1463 range tail still reaching MEMADDR. */
1465 if ((bl->address + bp_location_shadow_len_after_address_max
1467 && (bl->address + bp_location_shadow_len_after_address_max
1474 /* Due to the binary search above, we need to make sure we pick the
1475 first location that's at BC_L's address. E.g., if there are
1476 multiple locations at the same address, BC_L may end up pointing
1477 at a duplicate location, and miss the "master"/"inserted"
1478 location. Say, given locations L1, L2 and L3 at addresses A and
1481 L1@A, L2@A, L3@B, ...
1483 BC_L could end up pointing at location L2, while the "master"
1484 location could be L1. Since the `loc->inserted' flag is only set
1485 on "master" locations, we'd forget to restore the shadow of L1
1488 && bp_location[bc_l]->address == bp_location[bc_l - 1]->address)
1491 /* Now do full processing of the found relevant range of elements. */
1493 for (bc = bc_l; bc < bp_location_count; bc++)
1495 struct bp_location *bl = bp_location[bc];
1496 CORE_ADDR bp_addr = 0;
1500 /* bp_location array has BL->OWNER always non-NULL. */
1501 if (bl->owner->type == bp_none)
1502 warning (_("reading through apparently deleted breakpoint #%d?"),
1505 /* Performance optimization: any further element can no longer affect BUF
1508 if (bl->address >= bp_location_placed_address_before_address_max
1509 && memaddr + len <= (bl->address
1510 - bp_location_placed_address_before_address_max))
1513 if (!bp_location_has_shadow (bl))
1515 if (!breakpoint_address_match (bl->target_info.placed_address_space, 0,
1516 current_program_space->aspace, 0))
1519 /* Addresses and length of the part of the breakpoint that
1521 bp_addr = bl->target_info.placed_address;
1522 bp_size = bl->target_info.shadow_len;
1524 if (bp_addr + bp_size <= memaddr)
1525 /* The breakpoint is entirely before the chunk of memory we
1529 if (bp_addr >= memaddr + len)
1530 /* The breakpoint is entirely after the chunk of memory we are
1534 /* Offset within shadow_contents. */
1535 if (bp_addr < memaddr)
1537 /* Only copy the second part of the breakpoint. */
1538 bp_size -= memaddr - bp_addr;
1539 bptoffset = memaddr - bp_addr;
1543 if (bp_addr + bp_size > memaddr + len)
1545 /* Only copy the first part of the breakpoint. */
1546 bp_size -= (bp_addr + bp_size) - (memaddr + len);
1549 if (readbuf != NULL)
1551 /* Verify that the readbuf buffer does not overlap with
1552 the shadow_contents buffer. */
1553 gdb_assert (bl->target_info.shadow_contents >= readbuf + len
1554 || readbuf >= (bl->target_info.shadow_contents
1555 + bl->target_info.shadow_len));
1557 /* Update the read buffer with this inserted breakpoint's
1559 memcpy (readbuf + bp_addr - memaddr,
1560 bl->target_info.shadow_contents + bptoffset, bp_size);
1564 struct gdbarch *gdbarch = bl->gdbarch;
1565 const unsigned char *bp;
1566 CORE_ADDR placed_address = bl->target_info.placed_address;
1567 int placed_size = bl->target_info.placed_size;
1569 /* Update the shadow with what we want to write to memory. */
1570 memcpy (bl->target_info.shadow_contents + bptoffset,
1571 writebuf_org + bp_addr - memaddr, bp_size);
1573 /* Determine appropriate breakpoint contents and size for this
1575 bp = gdbarch_breakpoint_from_pc (gdbarch, &placed_address, &placed_size);
1577 /* Update the final write buffer with this inserted
1578 breakpoint's INSN. */
1579 memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size);
1585 /* Return true if BPT is either a software breakpoint or a hardware
1589 is_breakpoint (const struct breakpoint *bpt)
1591 return (bpt->type == bp_breakpoint
1592 || bpt->type == bp_hardware_breakpoint
1593 || bpt->type == bp_dprintf);
1596 /* Return true if BPT is of any hardware watchpoint kind. */
1599 is_hardware_watchpoint (const struct breakpoint *bpt)
1601 return (bpt->type == bp_hardware_watchpoint
1602 || bpt->type == bp_read_watchpoint
1603 || bpt->type == bp_access_watchpoint);
1606 /* Return true if BPT is of any watchpoint kind, hardware or
1610 is_watchpoint (const struct breakpoint *bpt)
1612 return (is_hardware_watchpoint (bpt)
1613 || bpt->type == bp_watchpoint);
1616 /* Returns true if the current thread and its running state are safe
1617 to evaluate or update watchpoint B. Watchpoints on local
1618 expressions need to be evaluated in the context of the thread that
1619 was current when the watchpoint was created, and, that thread needs
1620 to be stopped to be able to select the correct frame context.
1621 Watchpoints on global expressions can be evaluated on any thread,
1622 and in any state. It is presently left to the target allowing
1623 memory accesses when threads are running. */
1626 watchpoint_in_thread_scope (struct watchpoint *b)
1628 return (b->base.pspace == current_program_space
1629 && (ptid_equal (b->watchpoint_thread, null_ptid)
1630 || (ptid_equal (inferior_ptid, b->watchpoint_thread)
1631 && !is_executing (inferior_ptid))));
1634 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1635 associated bp_watchpoint_scope breakpoint. */
1638 watchpoint_del_at_next_stop (struct watchpoint *w)
1640 struct breakpoint *b = &w->base;
1642 if (b->related_breakpoint != b)
1644 gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope);
1645 gdb_assert (b->related_breakpoint->related_breakpoint == b);
1646 b->related_breakpoint->disposition = disp_del_at_next_stop;
1647 b->related_breakpoint->related_breakpoint = b->related_breakpoint;
1648 b->related_breakpoint = b;
1650 b->disposition = disp_del_at_next_stop;
1653 /* Assuming that B is a watchpoint:
1654 - Reparse watchpoint expression, if REPARSE is non-zero
1655 - Evaluate expression and store the result in B->val
1656 - Evaluate the condition if there is one, and store the result
1658 - Update the list of values that must be watched in B->loc.
1660 If the watchpoint disposition is disp_del_at_next_stop, then do
1661 nothing. If this is local watchpoint that is out of scope, delete
1664 Even with `set breakpoint always-inserted on' the watchpoints are
1665 removed + inserted on each stop here. Normal breakpoints must
1666 never be removed because they might be missed by a running thread
1667 when debugging in non-stop mode. On the other hand, hardware
1668 watchpoints (is_hardware_watchpoint; processed here) are specific
1669 to each LWP since they are stored in each LWP's hardware debug
1670 registers. Therefore, such LWP must be stopped first in order to
1671 be able to modify its hardware watchpoints.
1673 Hardware watchpoints must be reset exactly once after being
1674 presented to the user. It cannot be done sooner, because it would
1675 reset the data used to present the watchpoint hit to the user. And
1676 it must not be done later because it could display the same single
1677 watchpoint hit during multiple GDB stops. Note that the latter is
1678 relevant only to the hardware watchpoint types bp_read_watchpoint
1679 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1680 not user-visible - its hit is suppressed if the memory content has
1683 The following constraints influence the location where we can reset
1684 hardware watchpoints:
1686 * target_stopped_by_watchpoint and target_stopped_data_address are
1687 called several times when GDB stops.
1690 * Multiple hardware watchpoints can be hit at the same time,
1691 causing GDB to stop. GDB only presents one hardware watchpoint
1692 hit at a time as the reason for stopping, and all the other hits
1693 are presented later, one after the other, each time the user
1694 requests the execution to be resumed. Execution is not resumed
1695 for the threads still having pending hit event stored in
1696 LWP_INFO->STATUS. While the watchpoint is already removed from
1697 the inferior on the first stop the thread hit event is kept being
1698 reported from its cached value by linux_nat_stopped_data_address
1699 until the real thread resume happens after the watchpoint gets
1700 presented and thus its LWP_INFO->STATUS gets reset.
1702 Therefore the hardware watchpoint hit can get safely reset on the
1703 watchpoint removal from inferior. */
1706 update_watchpoint (struct watchpoint *b, int reparse)
1708 int within_current_scope;
1709 struct frame_id saved_frame_id;
1712 /* If this is a local watchpoint, we only want to check if the
1713 watchpoint frame is in scope if the current thread is the thread
1714 that was used to create the watchpoint. */
1715 if (!watchpoint_in_thread_scope (b))
1718 if (b->base.disposition == disp_del_at_next_stop)
1723 /* Determine if the watchpoint is within scope. */
1724 if (b->exp_valid_block == NULL)
1725 within_current_scope = 1;
1728 struct frame_info *fi = get_current_frame ();
1729 struct gdbarch *frame_arch = get_frame_arch (fi);
1730 CORE_ADDR frame_pc = get_frame_pc (fi);
1732 /* If we're in a function epilogue, unwinding may not work
1733 properly, so do not attempt to recreate locations at this
1734 point. See similar comments in watchpoint_check. */
1735 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
1738 /* Save the current frame's ID so we can restore it after
1739 evaluating the watchpoint expression on its own frame. */
1740 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1741 took a frame parameter, so that we didn't have to change the
1744 saved_frame_id = get_frame_id (get_selected_frame (NULL));
1746 fi = frame_find_by_id (b->watchpoint_frame);
1747 within_current_scope = (fi != NULL);
1748 if (within_current_scope)
1752 /* We don't free locations. They are stored in the bp_location array
1753 and update_global_location_list will eventually delete them and
1754 remove breakpoints if needed. */
1757 if (within_current_scope && reparse)
1766 s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string;
1767 b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0);
1768 /* If the meaning of expression itself changed, the old value is
1769 no longer relevant. We don't want to report a watchpoint hit
1770 to the user when the old value and the new value may actually
1771 be completely different objects. */
1772 value_free (b->val);
1776 /* Note that unlike with breakpoints, the watchpoint's condition
1777 expression is stored in the breakpoint object, not in the
1778 locations (re)created below. */
1779 if (b->base.cond_string != NULL)
1781 if (b->cond_exp != NULL)
1783 xfree (b->cond_exp);
1787 s = b->base.cond_string;
1788 b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0);
1792 /* If we failed to parse the expression, for example because
1793 it refers to a global variable in a not-yet-loaded shared library,
1794 don't try to insert watchpoint. We don't automatically delete
1795 such watchpoint, though, since failure to parse expression
1796 is different from out-of-scope watchpoint. */
1797 if (!target_has_execution)
1799 /* Without execution, memory can't change. No use to try and
1800 set watchpoint locations. The watchpoint will be reset when
1801 the target gains execution, through breakpoint_re_set. */
1802 if (!can_use_hw_watchpoints)
1804 if (b->base.ops->works_in_software_mode (&b->base))
1805 b->base.type = bp_watchpoint;
1807 error (_("Can't set read/access watchpoint when "
1808 "hardware watchpoints are disabled."));
1811 else if (within_current_scope && b->exp)
1814 struct value *val_chain, *v, *result, *next;
1815 struct program_space *frame_pspace;
1817 fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain, 0);
1819 /* Avoid setting b->val if it's already set. The meaning of
1820 b->val is 'the last value' user saw, and we should update
1821 it only if we reported that last value to user. As it
1822 happens, the code that reports it updates b->val directly.
1823 We don't keep track of the memory value for masked
1825 if (!b->val_valid && !is_masked_watchpoint (&b->base))
1831 frame_pspace = get_frame_program_space (get_selected_frame (NULL));
1833 /* Look at each value on the value chain. */
1834 for (v = val_chain; v; v = value_next (v))
1836 /* If it's a memory location, and GDB actually needed
1837 its contents to evaluate the expression, then we
1838 must watch it. If the first value returned is
1839 still lazy, that means an error occurred reading it;
1840 watch it anyway in case it becomes readable. */
1841 if (VALUE_LVAL (v) == lval_memory
1842 && (v == val_chain || ! value_lazy (v)))
1844 struct type *vtype = check_typedef (value_type (v));
1846 /* We only watch structs and arrays if user asked
1847 for it explicitly, never if they just happen to
1848 appear in the middle of some value chain. */
1850 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1851 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1855 struct bp_location *loc, **tmp;
1857 addr = value_address (v);
1859 if (b->base.type == bp_read_watchpoint)
1861 else if (b->base.type == bp_access_watchpoint)
1864 loc = allocate_bp_location (&b->base);
1865 for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next))
1868 loc->gdbarch = get_type_arch (value_type (v));
1870 loc->pspace = frame_pspace;
1871 loc->address = addr;
1872 loc->length = TYPE_LENGTH (value_type (v));
1873 loc->watchpoint_type = type;
1878 /* Change the type of breakpoint between hardware assisted or
1879 an ordinary watchpoint depending on the hardware support
1880 and free hardware slots. REPARSE is set when the inferior
1885 enum bp_loc_type loc_type;
1886 struct bp_location *bl;
1888 reg_cnt = can_use_hardware_watchpoint (val_chain);
1892 int i, target_resources_ok, other_type_used;
1895 /* Use an exact watchpoint when there's only one memory region to be
1896 watched, and only one debug register is needed to watch it. */
1897 b->exact = target_exact_watchpoints && reg_cnt == 1;
1899 /* We need to determine how many resources are already
1900 used for all other hardware watchpoints plus this one
1901 to see if we still have enough resources to also fit
1902 this watchpoint in as well. */
1904 /* If this is a software watchpoint, we try to turn it
1905 to a hardware one -- count resources as if B was of
1906 hardware watchpoint type. */
1907 type = b->base.type;
1908 if (type == bp_watchpoint)
1909 type = bp_hardware_watchpoint;
1911 /* This watchpoint may or may not have been placed on
1912 the list yet at this point (it won't be in the list
1913 if we're trying to create it for the first time,
1914 through watch_command), so always account for it
1917 /* Count resources used by all watchpoints except B. */
1918 i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used);
1920 /* Add in the resources needed for B. */
1921 i += hw_watchpoint_use_count (&b->base);
1924 = target_can_use_hardware_watchpoint (type, i, other_type_used);
1925 if (target_resources_ok <= 0)
1927 int sw_mode = b->base.ops->works_in_software_mode (&b->base);
1929 if (target_resources_ok == 0 && !sw_mode)
1930 error (_("Target does not support this type of "
1931 "hardware watchpoint."));
1932 else if (target_resources_ok < 0 && !sw_mode)
1933 error (_("There are not enough available hardware "
1934 "resources for this watchpoint."));
1936 /* Downgrade to software watchpoint. */
1937 b->base.type = bp_watchpoint;
1941 /* If this was a software watchpoint, we've just
1942 found we have enough resources to turn it to a
1943 hardware watchpoint. Otherwise, this is a
1945 b->base.type = type;
1948 else if (!b->base.ops->works_in_software_mode (&b->base))
1950 if (!can_use_hw_watchpoints)
1951 error (_("Can't set read/access watchpoint when "
1952 "hardware watchpoints are disabled."));
1954 error (_("Expression cannot be implemented with "
1955 "read/access watchpoint."));
1958 b->base.type = bp_watchpoint;
1960 loc_type = (b->base.type == bp_watchpoint? bp_loc_other
1961 : bp_loc_hardware_watchpoint);
1962 for (bl = b->base.loc; bl; bl = bl->next)
1963 bl->loc_type = loc_type;
1966 for (v = val_chain; v; v = next)
1968 next = value_next (v);
1973 /* If a software watchpoint is not watching any memory, then the
1974 above left it without any location set up. But,
1975 bpstat_stop_status requires a location to be able to report
1976 stops, so make sure there's at least a dummy one. */
1977 if (b->base.type == bp_watchpoint && b->base.loc == NULL)
1979 struct breakpoint *base = &b->base;
1980 base->loc = allocate_bp_location (base);
1981 base->loc->pspace = frame_pspace;
1982 base->loc->address = -1;
1983 base->loc->length = -1;
1984 base->loc->watchpoint_type = -1;
1987 else if (!within_current_scope)
1989 printf_filtered (_("\
1990 Watchpoint %d deleted because the program has left the block\n\
1991 in which its expression is valid.\n"),
1993 watchpoint_del_at_next_stop (b);
1996 /* Restore the selected frame. */
1998 select_frame (frame_find_by_id (saved_frame_id));
2002 /* Returns 1 iff breakpoint location should be
2003 inserted in the inferior. We don't differentiate the type of BL's owner
2004 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2005 breakpoint_ops is not defined, because in insert_bp_location,
2006 tracepoint's insert_location will not be called. */
2008 should_be_inserted (struct bp_location *bl)
2010 if (bl->owner == NULL || !breakpoint_enabled (bl->owner))
2013 if (bl->owner->disposition == disp_del_at_next_stop)
2016 if (!bl->enabled || bl->shlib_disabled || bl->duplicate)
2019 if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup)
2022 /* This is set for example, when we're attached to the parent of a
2023 vfork, and have detached from the child. The child is running
2024 free, and we expect it to do an exec or exit, at which point the
2025 OS makes the parent schedulable again (and the target reports
2026 that the vfork is done). Until the child is done with the shared
2027 memory region, do not insert breakpoints in the parent, otherwise
2028 the child could still trip on the parent's breakpoints. Since
2029 the parent is blocked anyway, it won't miss any breakpoint. */
2030 if (bl->pspace->breakpoints_not_allowed)
2036 /* Same as should_be_inserted but does the check assuming
2037 that the location is not duplicated. */
2040 unduplicated_should_be_inserted (struct bp_location *bl)
2043 const int save_duplicate = bl->duplicate;
2046 result = should_be_inserted (bl);
2047 bl->duplicate = save_duplicate;
2051 /* Parses a conditional described by an expression COND into an
2052 agent expression bytecode suitable for evaluation
2053 by the bytecode interpreter. Return NULL if there was
2054 any error during parsing. */
2056 static struct agent_expr *
2057 parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond)
2059 struct agent_expr *aexpr = NULL;
2060 volatile struct gdb_exception ex;
2065 /* We don't want to stop processing, so catch any errors
2066 that may show up. */
2067 TRY_CATCH (ex, RETURN_MASK_ERROR)
2069 aexpr = gen_eval_for_expr (scope, cond);
2074 /* If we got here, it means the condition could not be parsed to a valid
2075 bytecode expression and thus can't be evaluated on the target's side.
2076 It's no use iterating through the conditions. */
2080 /* We have a valid agent expression. */
2084 /* Based on location BL, create a list of breakpoint conditions to be
2085 passed on to the target. If we have duplicated locations with different
2086 conditions, we will add such conditions to the list. The idea is that the
2087 target will evaluate the list of conditions and will only notify GDB when
2088 one of them is true. */
2091 build_target_condition_list (struct bp_location *bl)
2093 struct bp_location **locp = NULL, **loc2p;
2094 int null_condition_or_parse_error = 0;
2095 int modified = bl->needs_update;
2096 struct bp_location *loc;
2098 /* Release conditions left over from a previous insert. */
2099 VEC_free (agent_expr_p, bl->target_info.conditions);
2101 /* This is only meaningful if the target is
2102 evaluating conditions and if the user has
2103 opted for condition evaluation on the target's
2105 if (gdb_evaluates_breakpoint_condition_p ()
2106 || !target_supports_evaluation_of_breakpoint_conditions ())
2109 /* Do a first pass to check for locations with no assigned
2110 conditions or conditions that fail to parse to a valid agent expression
2111 bytecode. If any of these happen, then it's no use to send conditions
2112 to the target since this location will always trigger and generate a
2113 response back to GDB. */
2114 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2117 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2121 struct agent_expr *aexpr;
2123 /* Re-parse the conditions since something changed. In that
2124 case we already freed the condition bytecodes (see
2125 force_breakpoint_reinsertion). We just
2126 need to parse the condition to bytecodes again. */
2127 aexpr = parse_cond_to_aexpr (bl->address, loc->cond);
2128 loc->cond_bytecode = aexpr;
2130 /* Check if we managed to parse the conditional expression
2131 correctly. If not, we will not send this condition
2137 /* If we have a NULL bytecode expression, it means something
2138 went wrong or we have a null condition expression. */
2139 if (!loc->cond_bytecode)
2141 null_condition_or_parse_error = 1;
2147 /* If any of these happened, it means we will have to evaluate the conditions
2148 for the location's address on gdb's side. It is no use keeping bytecodes
2149 for all the other duplicate locations, thus we free all of them here.
2151 This is so we have a finer control over which locations' conditions are
2152 being evaluated by GDB or the remote stub. */
2153 if (null_condition_or_parse_error)
2155 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2158 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2160 /* Only go as far as the first NULL bytecode is
2162 if (!loc->cond_bytecode)
2165 free_agent_expr (loc->cond_bytecode);
2166 loc->cond_bytecode = NULL;
2171 /* No NULL conditions or failed bytecode generation. Build a condition list
2172 for this location's address. */
2173 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2177 && is_breakpoint (loc->owner)
2178 && loc->pspace->num == bl->pspace->num
2179 && loc->owner->enable_state == bp_enabled
2181 /* Add the condition to the vector. This will be used later to send the
2182 conditions to the target. */
2183 VEC_safe_push (agent_expr_p, bl->target_info.conditions,
2184 loc->cond_bytecode);
2190 /* Parses a command described by string CMD into an agent expression
2191 bytecode suitable for evaluation by the bytecode interpreter.
2192 Return NULL if there was any error during parsing. */
2194 static struct agent_expr *
2195 parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd)
2197 struct cleanup *old_cleanups = 0;
2198 struct expression *expr, **argvec;
2199 struct agent_expr *aexpr = NULL;
2200 volatile struct gdb_exception ex;
2201 const char *cmdrest;
2202 const char *format_start, *format_end;
2203 struct format_piece *fpieces;
2205 struct gdbarch *gdbarch = get_current_arch ();
2212 if (*cmdrest == ',')
2214 cmdrest = skip_spaces_const (cmdrest);
2216 if (*cmdrest++ != '"')
2217 error (_("No format string following the location"));
2219 format_start = cmdrest;
2221 fpieces = parse_format_string (&cmdrest);
2223 old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces);
2225 format_end = cmdrest;
2227 if (*cmdrest++ != '"')
2228 error (_("Bad format string, non-terminated '\"'."));
2230 cmdrest = skip_spaces_const (cmdrest);
2232 if (!(*cmdrest == ',' || *cmdrest == '\0'))
2233 error (_("Invalid argument syntax"));
2235 if (*cmdrest == ',')
2237 cmdrest = skip_spaces_const (cmdrest);
2239 /* For each argument, make an expression. */
2241 argvec = (struct expression **) alloca (strlen (cmd)
2242 * sizeof (struct expression *));
2245 while (*cmdrest != '\0')
2250 expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1);
2251 argvec[nargs++] = expr;
2253 if (*cmdrest == ',')
2257 /* We don't want to stop processing, so catch any errors
2258 that may show up. */
2259 TRY_CATCH (ex, RETURN_MASK_ERROR)
2261 aexpr = gen_printf (scope, gdbarch, 0, 0,
2262 format_start, format_end - format_start,
2263 fpieces, nargs, argvec);
2266 do_cleanups (old_cleanups);
2270 /* If we got here, it means the command could not be parsed to a valid
2271 bytecode expression and thus can't be evaluated on the target's side.
2272 It's no use iterating through the other commands. */
2276 /* We have a valid agent expression, return it. */
2280 /* Based on location BL, create a list of breakpoint commands to be
2281 passed on to the target. If we have duplicated locations with
2282 different commands, we will add any such to the list. */
2285 build_target_command_list (struct bp_location *bl)
2287 struct bp_location **locp = NULL, **loc2p;
2288 int null_command_or_parse_error = 0;
2289 int modified = bl->needs_update;
2290 struct bp_location *loc;
2292 /* Release commands left over from a previous insert. */
2293 VEC_free (agent_expr_p, bl->target_info.tcommands);
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->cmd_bytecode == NULL)
2354 free_agent_expr (loc->cmd_bytecode);
2355 loc->cmd_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)
2397 enum errors bp_err = GDB_NO_ERROR;
2398 const char *bp_err_message = NULL;
2399 volatile 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)
2500 val = bl->owner->ops->insert_location (bl);
2502 bp_err = GENERIC_ERROR;
2507 bp_err_message = e.message;
2512 /* This breakpoint is in an overlay section.
2513 Shall we set a breakpoint at the LMA? */
2514 if (!overlay_events_enabled)
2516 /* Yes -- overlay event support is not active,
2517 so we must try to set a breakpoint at the LMA.
2518 This will not work for a hardware breakpoint. */
2519 if (bl->loc_type == bp_loc_hardware_breakpoint)
2520 warning (_("hardware breakpoint %d not supported in overlay!"),
2524 CORE_ADDR addr = overlay_unmapped_address (bl->address,
2526 /* Set a software (trap) breakpoint at the LMA. */
2527 bl->overlay_target_info = bl->target_info;
2528 bl->overlay_target_info.placed_address = addr;
2530 /* No overlay handling: just set the breakpoint. */
2531 TRY_CATCH (e, RETURN_MASK_ALL)
2535 val = target_insert_breakpoint (bl->gdbarch,
2536 &bl->overlay_target_info);
2538 bp_err = GENERIC_ERROR;
2543 bp_err_message = e.message;
2546 if (bp_err != GDB_NO_ERROR)
2547 fprintf_unfiltered (tmp_error_stream,
2548 "Overlay breakpoint %d "
2549 "failed: in ROM?\n",
2553 /* Shall we set a breakpoint at the VMA? */
2554 if (section_is_mapped (bl->section))
2556 /* Yes. This overlay section is mapped into memory. */
2557 TRY_CATCH (e, RETURN_MASK_ALL)
2561 val = bl->owner->ops->insert_location (bl);
2563 bp_err = GENERIC_ERROR;
2568 bp_err_message = e.message;
2573 /* No. This breakpoint will not be inserted.
2574 No error, but do not mark the bp as 'inserted'. */
2579 if (bp_err != GDB_NO_ERROR)
2581 /* Can't set the breakpoint. */
2583 /* In some cases, we might not be able to insert a
2584 breakpoint in a shared library that has already been
2585 removed, but we have not yet processed the shlib unload
2586 event. Unfortunately, some targets that implement
2587 breakpoint insertion themselves (necessary if this is a
2588 HW breakpoint, but SW breakpoints likewise) can't tell
2589 why the breakpoint insertion failed (e.g., the remote
2590 target doesn't define error codes), so we must treat
2591 generic errors as memory errors. */
2592 if ((bp_err == GENERIC_ERROR || bp_err == MEMORY_ERROR)
2593 && solib_name_from_address (bl->pspace, bl->address))
2595 /* See also: disable_breakpoints_in_shlibs. */
2596 bl->shlib_disabled = 1;
2597 observer_notify_breakpoint_modified (bl->owner);
2598 if (!*disabled_breaks)
2600 fprintf_unfiltered (tmp_error_stream,
2601 "Cannot insert breakpoint %d.\n",
2603 fprintf_unfiltered (tmp_error_stream,
2604 "Temporarily disabling shared "
2605 "library breakpoints:\n");
2607 *disabled_breaks = 1;
2608 fprintf_unfiltered (tmp_error_stream,
2609 "breakpoint #%d\n", bl->owner->number);
2614 if (bl->loc_type == bp_loc_hardware_breakpoint)
2616 *hw_breakpoint_error = 1;
2617 *hw_bp_error_explained_already = bp_err_message != NULL;
2618 fprintf_unfiltered (tmp_error_stream,
2619 "Cannot insert hardware breakpoint %d%s",
2620 bl->owner->number, bp_err_message ? ":" : ".\n");
2621 if (bp_err_message != NULL)
2622 fprintf_unfiltered (tmp_error_stream, "%s.\n", bp_err_message);
2626 if (bp_err_message == NULL)
2629 = memory_error_message (TARGET_XFER_E_IO,
2630 bl->gdbarch, bl->address);
2631 struct cleanup *old_chain = make_cleanup (xfree, message);
2633 fprintf_unfiltered (tmp_error_stream,
2634 "Cannot insert breakpoint %d.\n"
2636 bl->owner->number, message);
2637 do_cleanups (old_chain);
2641 fprintf_unfiltered (tmp_error_stream,
2642 "Cannot insert breakpoint %d: %s\n",
2657 else if (bl->loc_type == bp_loc_hardware_watchpoint
2658 /* NOTE drow/2003-09-08: This state only exists for removing
2659 watchpoints. It's not clear that it's necessary... */
2660 && bl->owner->disposition != disp_del_at_next_stop)
2664 gdb_assert (bl->owner->ops != NULL
2665 && bl->owner->ops->insert_location != NULL);
2667 val = bl->owner->ops->insert_location (bl);
2669 /* If trying to set a read-watchpoint, and it turns out it's not
2670 supported, try emulating one with an access watchpoint. */
2671 if (val == 1 && bl->watchpoint_type == hw_read)
2673 struct bp_location *loc, **loc_temp;
2675 /* But don't try to insert it, if there's already another
2676 hw_access location that would be considered a duplicate
2678 ALL_BP_LOCATIONS (loc, loc_temp)
2680 && loc->watchpoint_type == hw_access
2681 && watchpoint_locations_match (bl, loc))
2685 bl->target_info = loc->target_info;
2686 bl->watchpoint_type = hw_access;
2693 bl->watchpoint_type = hw_access;
2694 val = bl->owner->ops->insert_location (bl);
2697 /* Back to the original value. */
2698 bl->watchpoint_type = hw_read;
2702 bl->inserted = (val == 0);
2705 else if (bl->owner->type == bp_catchpoint)
2709 gdb_assert (bl->owner->ops != NULL
2710 && bl->owner->ops->insert_location != NULL);
2712 val = bl->owner->ops->insert_location (bl);
2715 bl->owner->enable_state = bp_disabled;
2719 Error inserting catchpoint %d: Your system does not support this type\n\
2720 of catchpoint."), bl->owner->number);
2722 warning (_("Error inserting catchpoint %d."), bl->owner->number);
2725 bl->inserted = (val == 0);
2727 /* We've already printed an error message if there was a problem
2728 inserting this catchpoint, and we've disabled the catchpoint,
2729 so just return success. */
2736 /* This function is called when program space PSPACE is about to be
2737 deleted. It takes care of updating breakpoints to not reference
2741 breakpoint_program_space_exit (struct program_space *pspace)
2743 struct breakpoint *b, *b_temp;
2744 struct bp_location *loc, **loc_temp;
2746 /* Remove any breakpoint that was set through this program space. */
2747 ALL_BREAKPOINTS_SAFE (b, b_temp)
2749 if (b->pspace == pspace)
2750 delete_breakpoint (b);
2753 /* Breakpoints set through other program spaces could have locations
2754 bound to PSPACE as well. Remove those. */
2755 ALL_BP_LOCATIONS (loc, loc_temp)
2757 struct bp_location *tmp;
2759 if (loc->pspace == pspace)
2761 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2762 if (loc->owner->loc == loc)
2763 loc->owner->loc = loc->next;
2765 for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next)
2766 if (tmp->next == loc)
2768 tmp->next = loc->next;
2774 /* Now update the global location list to permanently delete the
2775 removed locations above. */
2776 update_global_location_list (0);
2779 /* Make sure all breakpoints are inserted in inferior.
2780 Throws exception on any error.
2781 A breakpoint that is already inserted won't be inserted
2782 again, so calling this function twice is safe. */
2784 insert_breakpoints (void)
2786 struct breakpoint *bpt;
2788 ALL_BREAKPOINTS (bpt)
2789 if (is_hardware_watchpoint (bpt))
2791 struct watchpoint *w = (struct watchpoint *) bpt;
2793 update_watchpoint (w, 0 /* don't reparse. */);
2796 update_global_location_list (1);
2798 /* update_global_location_list does not insert breakpoints when
2799 always_inserted_mode is not enabled. Explicitly insert them
2801 if (!breakpoints_always_inserted_mode ())
2802 insert_breakpoint_locations ();
2805 /* Invoke CALLBACK for each of bp_location. */
2808 iterate_over_bp_locations (walk_bp_location_callback callback)
2810 struct bp_location *loc, **loc_tmp;
2812 ALL_BP_LOCATIONS (loc, loc_tmp)
2814 callback (loc, NULL);
2818 /* This is used when we need to synch breakpoint conditions between GDB and the
2819 target. It is the case with deleting and disabling of breakpoints when using
2820 always-inserted mode. */
2823 update_inserted_breakpoint_locations (void)
2825 struct bp_location *bl, **blp_tmp;
2828 int disabled_breaks = 0;
2829 int hw_breakpoint_error = 0;
2830 int hw_bp_details_reported = 0;
2832 struct ui_file *tmp_error_stream = mem_fileopen ();
2833 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
2835 /* Explicitly mark the warning -- this will only be printed if
2836 there was an error. */
2837 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
2839 save_current_space_and_thread ();
2841 ALL_BP_LOCATIONS (bl, blp_tmp)
2843 /* We only want to update software breakpoints and hardware
2845 if (!is_breakpoint (bl->owner))
2848 /* We only want to update locations that are already inserted
2849 and need updating. This is to avoid unwanted insertion during
2850 deletion of breakpoints. */
2851 if (!bl->inserted || (bl->inserted && !bl->needs_update))
2854 switch_to_program_space_and_thread (bl->pspace);
2856 /* For targets that support global breakpoints, there's no need
2857 to select an inferior to insert breakpoint to. In fact, even
2858 if we aren't attached to any process yet, we should still
2859 insert breakpoints. */
2860 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2861 && ptid_equal (inferior_ptid, null_ptid))
2864 val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
2865 &hw_breakpoint_error, &hw_bp_details_reported);
2872 target_terminal_ours_for_output ();
2873 error_stream (tmp_error_stream);
2876 do_cleanups (cleanups);
2879 /* Used when starting or continuing the program. */
2882 insert_breakpoint_locations (void)
2884 struct breakpoint *bpt;
2885 struct bp_location *bl, **blp_tmp;
2888 int disabled_breaks = 0;
2889 int hw_breakpoint_error = 0;
2890 int hw_bp_error_explained_already = 0;
2892 struct ui_file *tmp_error_stream = mem_fileopen ();
2893 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
2895 /* Explicitly mark the warning -- this will only be printed if
2896 there was an error. */
2897 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
2899 save_current_space_and_thread ();
2901 ALL_BP_LOCATIONS (bl, blp_tmp)
2903 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
2906 /* There is no point inserting thread-specific breakpoints if
2907 the thread no longer exists. ALL_BP_LOCATIONS bp_location
2908 has BL->OWNER always non-NULL. */
2909 if (bl->owner->thread != -1
2910 && !valid_thread_id (bl->owner->thread))
2913 switch_to_program_space_and_thread (bl->pspace);
2915 /* For targets that support global breakpoints, there's no need
2916 to select an inferior to insert breakpoint to. In fact, even
2917 if we aren't attached to any process yet, we should still
2918 insert breakpoints. */
2919 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2920 && ptid_equal (inferior_ptid, null_ptid))
2923 val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
2924 &hw_breakpoint_error, &hw_bp_error_explained_already);
2929 /* If we failed to insert all locations of a watchpoint, remove
2930 them, as half-inserted watchpoint is of limited use. */
2931 ALL_BREAKPOINTS (bpt)
2933 int some_failed = 0;
2934 struct bp_location *loc;
2936 if (!is_hardware_watchpoint (bpt))
2939 if (!breakpoint_enabled (bpt))
2942 if (bpt->disposition == disp_del_at_next_stop)
2945 for (loc = bpt->loc; loc; loc = loc->next)
2946 if (!loc->inserted && should_be_inserted (loc))
2953 for (loc = bpt->loc; loc; loc = loc->next)
2955 remove_breakpoint (loc, mark_uninserted);
2957 hw_breakpoint_error = 1;
2958 fprintf_unfiltered (tmp_error_stream,
2959 "Could not insert hardware watchpoint %d.\n",
2967 /* If a hardware breakpoint or watchpoint was inserted, add a
2968 message about possibly exhausted resources. */
2969 if (hw_breakpoint_error && !hw_bp_error_explained_already)
2971 fprintf_unfiltered (tmp_error_stream,
2972 "Could not insert hardware breakpoints:\n\
2973 You may have requested too many hardware breakpoints/watchpoints.\n");
2975 target_terminal_ours_for_output ();
2976 error_stream (tmp_error_stream);
2979 do_cleanups (cleanups);
2982 /* Used when the program stops.
2983 Returns zero if successful, or non-zero if there was a problem
2984 removing a breakpoint location. */
2987 remove_breakpoints (void)
2989 struct bp_location *bl, **blp_tmp;
2992 ALL_BP_LOCATIONS (bl, blp_tmp)
2994 if (bl->inserted && !is_tracepoint (bl->owner))
2995 val |= remove_breakpoint (bl, mark_uninserted);
3000 /* When a thread exits, remove breakpoints that are related to
3004 remove_threaded_breakpoints (struct thread_info *tp, int silent)
3006 struct breakpoint *b, *b_tmp;
3008 ALL_BREAKPOINTS_SAFE (b, b_tmp)
3010 if (b->thread == tp->num && user_breakpoint_p (b))
3012 b->disposition = disp_del_at_next_stop;
3014 printf_filtered (_("\
3015 Thread-specific breakpoint %d deleted - thread %d no longer in the thread list.\n"),
3016 b->number, tp->num);
3018 /* Hide it from the user. */
3024 /* Remove breakpoints of process PID. */
3027 remove_breakpoints_pid (int pid)
3029 struct bp_location *bl, **blp_tmp;
3031 struct inferior *inf = find_inferior_pid (pid);
3033 ALL_BP_LOCATIONS (bl, blp_tmp)
3035 if (bl->pspace != inf->pspace)
3038 if (bl->owner->type == bp_dprintf)
3043 val = remove_breakpoint (bl, mark_uninserted);
3052 reattach_breakpoints (int pid)
3054 struct cleanup *old_chain;
3055 struct bp_location *bl, **blp_tmp;
3057 struct ui_file *tmp_error_stream;
3058 int dummy1 = 0, dummy2 = 0, dummy3 = 0;
3059 struct inferior *inf;
3060 struct thread_info *tp;
3062 tp = any_live_thread_of_process (pid);
3066 inf = find_inferior_pid (pid);
3067 old_chain = save_inferior_ptid ();
3069 inferior_ptid = tp->ptid;
3071 tmp_error_stream = mem_fileopen ();
3072 make_cleanup_ui_file_delete (tmp_error_stream);
3074 ALL_BP_LOCATIONS (bl, blp_tmp)
3076 if (bl->pspace != inf->pspace)
3082 val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2, &dummy3);
3085 do_cleanups (old_chain);
3090 do_cleanups (old_chain);
3094 static int internal_breakpoint_number = -1;
3096 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3097 If INTERNAL is non-zero, the breakpoint number will be populated
3098 from internal_breakpoint_number and that variable decremented.
3099 Otherwise the breakpoint number will be populated from
3100 breakpoint_count and that value incremented. Internal breakpoints
3101 do not set the internal var bpnum. */
3103 set_breakpoint_number (int internal, struct breakpoint *b)
3106 b->number = internal_breakpoint_number--;
3109 set_breakpoint_count (breakpoint_count + 1);
3110 b->number = breakpoint_count;
3114 static struct breakpoint *
3115 create_internal_breakpoint (struct gdbarch *gdbarch,
3116 CORE_ADDR address, enum bptype type,
3117 const struct breakpoint_ops *ops)
3119 struct symtab_and_line sal;
3120 struct breakpoint *b;
3122 init_sal (&sal); /* Initialize to zeroes. */
3125 sal.section = find_pc_overlay (sal.pc);
3126 sal.pspace = current_program_space;
3128 b = set_raw_breakpoint (gdbarch, sal, type, ops);
3129 b->number = internal_breakpoint_number--;
3130 b->disposition = disp_donttouch;
3135 static const char *const longjmp_names[] =
3137 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3139 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3141 /* Per-objfile data private to breakpoint.c. */
3142 struct breakpoint_objfile_data
3144 /* Minimal symbol for "_ovly_debug_event" (if any). */
3145 struct minimal_symbol *overlay_msym;
3147 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3148 struct minimal_symbol *longjmp_msym[NUM_LONGJMP_NAMES];
3150 /* True if we have looked for longjmp probes. */
3151 int longjmp_searched;
3153 /* SystemTap probe points for longjmp (if any). */
3154 VEC (probe_p) *longjmp_probes;
3156 /* Minimal symbol for "std::terminate()" (if any). */
3157 struct minimal_symbol *terminate_msym;
3159 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3160 struct minimal_symbol *exception_msym;
3162 /* True if we have looked for exception probes. */
3163 int exception_searched;
3165 /* SystemTap probe points for unwinding (if any). */
3166 VEC (probe_p) *exception_probes;
3169 static const struct objfile_data *breakpoint_objfile_key;
3171 /* Minimal symbol not found sentinel. */
3172 static struct minimal_symbol msym_not_found;
3174 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3177 msym_not_found_p (const struct minimal_symbol *msym)
3179 return msym == &msym_not_found;
3182 /* Return per-objfile data needed by breakpoint.c.
3183 Allocate the data if necessary. */
3185 static struct breakpoint_objfile_data *
3186 get_breakpoint_objfile_data (struct objfile *objfile)
3188 struct breakpoint_objfile_data *bp_objfile_data;
3190 bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key);
3191 if (bp_objfile_data == NULL)
3193 bp_objfile_data = obstack_alloc (&objfile->objfile_obstack,
3194 sizeof (*bp_objfile_data));
3196 memset (bp_objfile_data, 0, sizeof (*bp_objfile_data));
3197 set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data);
3199 return bp_objfile_data;
3203 free_breakpoint_probes (struct objfile *obj, void *data)
3205 struct breakpoint_objfile_data *bp_objfile_data = data;
3207 VEC_free (probe_p, bp_objfile_data->longjmp_probes);
3208 VEC_free (probe_p, bp_objfile_data->exception_probes);
3212 create_overlay_event_breakpoint (void)
3214 struct objfile *objfile;
3215 const char *const func_name = "_ovly_debug_event";
3217 ALL_OBJFILES (objfile)
3219 struct breakpoint *b;
3220 struct breakpoint_objfile_data *bp_objfile_data;
3223 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3225 if (msym_not_found_p (bp_objfile_data->overlay_msym))
3228 if (bp_objfile_data->overlay_msym == NULL)
3230 struct minimal_symbol *m;
3232 m = lookup_minimal_symbol_text (func_name, objfile);
3235 /* Avoid future lookups in this objfile. */
3236 bp_objfile_data->overlay_msym = &msym_not_found;
3239 bp_objfile_data->overlay_msym = m;
3242 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym);
3243 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
3245 &internal_breakpoint_ops);
3246 b->addr_string = xstrdup (func_name);
3248 if (overlay_debugging == ovly_auto)
3250 b->enable_state = bp_enabled;
3251 overlay_events_enabled = 1;
3255 b->enable_state = bp_disabled;
3256 overlay_events_enabled = 0;
3259 update_global_location_list (1);
3263 create_longjmp_master_breakpoint (void)
3265 struct program_space *pspace;
3266 struct cleanup *old_chain;
3268 old_chain = save_current_program_space ();
3270 ALL_PSPACES (pspace)
3272 struct objfile *objfile;
3274 set_current_program_space (pspace);
3276 ALL_OBJFILES (objfile)
3279 struct gdbarch *gdbarch;
3280 struct breakpoint_objfile_data *bp_objfile_data;
3282 gdbarch = get_objfile_arch (objfile);
3284 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3286 if (!bp_objfile_data->longjmp_searched)
3290 ret = find_probes_in_objfile (objfile, "libc", "longjmp");
3293 /* We are only interested in checking one element. */
3294 struct probe *p = VEC_index (probe_p, ret, 0);
3296 if (!can_evaluate_probe_arguments (p))
3298 /* We cannot use the probe interface here, because it does
3299 not know how to evaluate arguments. */
3300 VEC_free (probe_p, ret);
3304 bp_objfile_data->longjmp_probes = ret;
3305 bp_objfile_data->longjmp_searched = 1;
3308 if (bp_objfile_data->longjmp_probes != NULL)
3311 struct probe *probe;
3312 struct gdbarch *gdbarch = get_objfile_arch (objfile);
3315 VEC_iterate (probe_p,
3316 bp_objfile_data->longjmp_probes,
3320 struct breakpoint *b;
3322 b = create_internal_breakpoint (gdbarch, probe->address,
3324 &internal_breakpoint_ops);
3325 b->addr_string = xstrdup ("-probe-stap libc:longjmp");
3326 b->enable_state = bp_disabled;
3332 if (!gdbarch_get_longjmp_target_p (gdbarch))
3335 for (i = 0; i < NUM_LONGJMP_NAMES; i++)
3337 struct breakpoint *b;
3338 const char *func_name;
3341 if (msym_not_found_p (bp_objfile_data->longjmp_msym[i]))
3344 func_name = longjmp_names[i];
3345 if (bp_objfile_data->longjmp_msym[i] == NULL)
3347 struct minimal_symbol *m;
3349 m = lookup_minimal_symbol_text (func_name, objfile);
3352 /* Prevent future lookups in this objfile. */
3353 bp_objfile_data->longjmp_msym[i] = &msym_not_found;
3356 bp_objfile_data->longjmp_msym[i] = m;
3359 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]);
3360 b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master,
3361 &internal_breakpoint_ops);
3362 b->addr_string = xstrdup (func_name);
3363 b->enable_state = bp_disabled;
3367 update_global_location_list (1);
3369 do_cleanups (old_chain);
3372 /* Create a master std::terminate breakpoint. */
3374 create_std_terminate_master_breakpoint (void)
3376 struct program_space *pspace;
3377 struct cleanup *old_chain;
3378 const char *const func_name = "std::terminate()";
3380 old_chain = save_current_program_space ();
3382 ALL_PSPACES (pspace)
3384 struct objfile *objfile;
3387 set_current_program_space (pspace);
3389 ALL_OBJFILES (objfile)
3391 struct breakpoint *b;
3392 struct breakpoint_objfile_data *bp_objfile_data;
3394 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3396 if (msym_not_found_p (bp_objfile_data->terminate_msym))
3399 if (bp_objfile_data->terminate_msym == NULL)
3401 struct minimal_symbol *m;
3403 m = lookup_minimal_symbol (func_name, NULL, objfile);
3404 if (m == NULL || (MSYMBOL_TYPE (m) != mst_text
3405 && MSYMBOL_TYPE (m) != mst_file_text))
3407 /* Prevent future lookups in this objfile. */
3408 bp_objfile_data->terminate_msym = &msym_not_found;
3411 bp_objfile_data->terminate_msym = m;
3414 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym);
3415 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
3416 bp_std_terminate_master,
3417 &internal_breakpoint_ops);
3418 b->addr_string = xstrdup (func_name);
3419 b->enable_state = bp_disabled;
3423 update_global_location_list (1);
3425 do_cleanups (old_chain);
3428 /* Install a master breakpoint on the unwinder's debug hook. */
3431 create_exception_master_breakpoint (void)
3433 struct objfile *objfile;
3434 const char *const func_name = "_Unwind_DebugHook";
3436 ALL_OBJFILES (objfile)
3438 struct breakpoint *b;
3439 struct gdbarch *gdbarch;
3440 struct breakpoint_objfile_data *bp_objfile_data;
3443 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3445 /* We prefer the SystemTap probe point if it exists. */
3446 if (!bp_objfile_data->exception_searched)
3450 ret = find_probes_in_objfile (objfile, "libgcc", "unwind");
3454 /* We are only interested in checking one element. */
3455 struct probe *p = VEC_index (probe_p, ret, 0);
3457 if (!can_evaluate_probe_arguments (p))
3459 /* We cannot use the probe interface here, because it does
3460 not know how to evaluate arguments. */
3461 VEC_free (probe_p, ret);
3465 bp_objfile_data->exception_probes = ret;
3466 bp_objfile_data->exception_searched = 1;
3469 if (bp_objfile_data->exception_probes != NULL)
3471 struct gdbarch *gdbarch = get_objfile_arch (objfile);
3473 struct probe *probe;
3476 VEC_iterate (probe_p,
3477 bp_objfile_data->exception_probes,
3481 struct breakpoint *b;
3483 b = create_internal_breakpoint (gdbarch, probe->address,
3484 bp_exception_master,
3485 &internal_breakpoint_ops);
3486 b->addr_string = xstrdup ("-probe-stap libgcc:unwind");
3487 b->enable_state = bp_disabled;
3493 /* Otherwise, try the hook function. */
3495 if (msym_not_found_p (bp_objfile_data->exception_msym))
3498 gdbarch = get_objfile_arch (objfile);
3500 if (bp_objfile_data->exception_msym == NULL)
3502 struct minimal_symbol *debug_hook;
3504 debug_hook = lookup_minimal_symbol (func_name, NULL, objfile);
3505 if (debug_hook == NULL)
3507 bp_objfile_data->exception_msym = &msym_not_found;
3511 bp_objfile_data->exception_msym = debug_hook;
3514 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym);
3515 addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
3517 b = create_internal_breakpoint (gdbarch, addr, bp_exception_master,
3518 &internal_breakpoint_ops);
3519 b->addr_string = xstrdup (func_name);
3520 b->enable_state = bp_disabled;
3523 update_global_location_list (1);
3527 update_breakpoints_after_exec (void)
3529 struct breakpoint *b, *b_tmp;
3530 struct bp_location *bploc, **bplocp_tmp;
3532 /* We're about to delete breakpoints from GDB's lists. If the
3533 INSERTED flag is true, GDB will try to lift the breakpoints by
3534 writing the breakpoints' "shadow contents" back into memory. The
3535 "shadow contents" are NOT valid after an exec, so GDB should not
3536 do that. Instead, the target is responsible from marking
3537 breakpoints out as soon as it detects an exec. We don't do that
3538 here instead, because there may be other attempts to delete
3539 breakpoints after detecting an exec and before reaching here. */
3540 ALL_BP_LOCATIONS (bploc, bplocp_tmp)
3541 if (bploc->pspace == current_program_space)
3542 gdb_assert (!bploc->inserted);
3544 ALL_BREAKPOINTS_SAFE (b, b_tmp)
3546 if (b->pspace != current_program_space)
3549 /* Solib breakpoints must be explicitly reset after an exec(). */
3550 if (b->type == bp_shlib_event)
3552 delete_breakpoint (b);
3556 /* JIT breakpoints must be explicitly reset after an exec(). */
3557 if (b->type == bp_jit_event)
3559 delete_breakpoint (b);
3563 /* Thread event breakpoints must be set anew after an exec(),
3564 as must overlay event and longjmp master breakpoints. */
3565 if (b->type == bp_thread_event || b->type == bp_overlay_event
3566 || b->type == bp_longjmp_master || b->type == bp_std_terminate_master
3567 || b->type == bp_exception_master)
3569 delete_breakpoint (b);
3573 /* Step-resume breakpoints are meaningless after an exec(). */
3574 if (b->type == bp_step_resume || b->type == bp_hp_step_resume)
3576 delete_breakpoint (b);
3580 /* Longjmp and longjmp-resume breakpoints are also meaningless
3582 if (b->type == bp_longjmp || b->type == bp_longjmp_resume
3583 || b->type == bp_longjmp_call_dummy
3584 || b->type == bp_exception || b->type == bp_exception_resume)
3586 delete_breakpoint (b);
3590 if (b->type == bp_catchpoint)
3592 /* For now, none of the bp_catchpoint breakpoints need to
3593 do anything at this point. In the future, if some of
3594 the catchpoints need to something, we will need to add
3595 a new method, and call this method from here. */
3599 /* bp_finish is a special case. The only way we ought to be able
3600 to see one of these when an exec() has happened, is if the user
3601 caught a vfork, and then said "finish". Ordinarily a finish just
3602 carries them to the call-site of the current callee, by setting
3603 a temporary bp there and resuming. But in this case, the finish
3604 will carry them entirely through the vfork & exec.
3606 We don't want to allow a bp_finish to remain inserted now. But
3607 we can't safely delete it, 'cause finish_command has a handle to
3608 the bp on a bpstat, and will later want to delete it. There's a
3609 chance (and I've seen it happen) that if we delete the bp_finish
3610 here, that its storage will get reused by the time finish_command
3611 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3612 We really must allow finish_command to delete a bp_finish.
3614 In the absence of a general solution for the "how do we know
3615 it's safe to delete something others may have handles to?"
3616 problem, what we'll do here is just uninsert the bp_finish, and
3617 let finish_command delete it.
3619 (We know the bp_finish is "doomed" in the sense that it's
3620 momentary, and will be deleted as soon as finish_command sees
3621 the inferior stopped. So it doesn't matter that the bp's
3622 address is probably bogus in the new a.out, unlike e.g., the
3623 solib breakpoints.) */
3625 if (b->type == bp_finish)
3630 /* Without a symbolic address, we have little hope of the
3631 pre-exec() address meaning the same thing in the post-exec()
3633 if (b->addr_string == NULL)
3635 delete_breakpoint (b);
3639 /* FIXME what about longjmp breakpoints? Re-create them here? */
3640 create_overlay_event_breakpoint ();
3641 create_longjmp_master_breakpoint ();
3642 create_std_terminate_master_breakpoint ();
3643 create_exception_master_breakpoint ();
3647 detach_breakpoints (ptid_t ptid)
3649 struct bp_location *bl, **blp_tmp;
3651 struct cleanup *old_chain = save_inferior_ptid ();
3652 struct inferior *inf = current_inferior ();
3654 if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid))
3655 error (_("Cannot detach breakpoints of inferior_ptid"));
3657 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3658 inferior_ptid = ptid;
3659 ALL_BP_LOCATIONS (bl, blp_tmp)
3661 if (bl->pspace != inf->pspace)
3664 /* This function must physically remove breakpoints locations
3665 from the specified ptid, without modifying the breakpoint
3666 package's state. Locations of type bp_loc_other are only
3667 maintained at GDB side. So, there is no need to remove
3668 these bp_loc_other locations. Moreover, removing these
3669 would modify the breakpoint package's state. */
3670 if (bl->loc_type == bp_loc_other)
3674 val |= remove_breakpoint_1 (bl, mark_inserted);
3677 /* Detach single-step breakpoints as well. */
3678 detach_single_step_breakpoints ();
3680 do_cleanups (old_chain);
3684 /* Remove the breakpoint location BL from the current address space.
3685 Note that this is used to detach breakpoints from a child fork.
3686 When we get here, the child isn't in the inferior list, and neither
3687 do we have objects to represent its address space --- we should
3688 *not* look at bl->pspace->aspace here. */
3691 remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is)
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 if (bl->loc_type == bp_loc_software_breakpoint
3707 || bl->loc_type == bp_loc_hardware_breakpoint)
3709 /* "Normal" instruction breakpoint: either the standard
3710 trap-instruction bp (bp_breakpoint), or a
3711 bp_hardware_breakpoint. */
3713 /* First check to see if we have to handle an overlay. */
3714 if (overlay_debugging == ovly_off
3715 || bl->section == NULL
3716 || !(section_is_overlay (bl->section)))
3718 /* No overlay handling: just remove the breakpoint. */
3719 val = bl->owner->ops->remove_location (bl);
3723 /* This breakpoint is in an overlay section.
3724 Did we set a breakpoint at the LMA? */
3725 if (!overlay_events_enabled)
3727 /* Yes -- overlay event support is not active, so we
3728 should have set a breakpoint at the LMA. Remove it.
3730 /* Ignore any failures: if the LMA is in ROM, we will
3731 have already warned when we failed to insert it. */
3732 if (bl->loc_type == bp_loc_hardware_breakpoint)
3733 target_remove_hw_breakpoint (bl->gdbarch,
3734 &bl->overlay_target_info);
3736 target_remove_breakpoint (bl->gdbarch,
3737 &bl->overlay_target_info);
3739 /* Did we set a breakpoint at the VMA?
3740 If so, we will have marked the breakpoint 'inserted'. */
3743 /* Yes -- remove it. Previously we did not bother to
3744 remove the breakpoint if the section had been
3745 unmapped, but let's not rely on that being safe. We
3746 don't know what the overlay manager might do. */
3748 /* However, we should remove *software* breakpoints only
3749 if the section is still mapped, or else we overwrite
3750 wrong code with the saved shadow contents. */
3751 if (bl->loc_type == bp_loc_hardware_breakpoint
3752 || section_is_mapped (bl->section))
3753 val = bl->owner->ops->remove_location (bl);
3759 /* No -- not inserted, so no need to remove. No error. */
3764 /* In some cases, we might not be able to remove a breakpoint
3765 in a shared library that has already been removed, but we
3766 have not yet processed the shlib unload event. */
3767 if (val && solib_name_from_address (bl->pspace, bl->address))
3772 bl->inserted = (is == mark_inserted);
3774 else if (bl->loc_type == bp_loc_hardware_watchpoint)
3776 gdb_assert (bl->owner->ops != NULL
3777 && bl->owner->ops->remove_location != NULL);
3779 bl->inserted = (is == mark_inserted);
3780 bl->owner->ops->remove_location (bl);
3782 /* Failure to remove any of the hardware watchpoints comes here. */
3783 if ((is == mark_uninserted) && (bl->inserted))
3784 warning (_("Could not remove hardware watchpoint %d."),
3787 else if (bl->owner->type == bp_catchpoint
3788 && breakpoint_enabled (bl->owner)
3791 gdb_assert (bl->owner->ops != NULL
3792 && bl->owner->ops->remove_location != NULL);
3794 val = bl->owner->ops->remove_location (bl);
3798 bl->inserted = (is == mark_inserted);
3805 remove_breakpoint (struct bp_location *bl, insertion_state_t is)
3808 struct cleanup *old_chain;
3810 /* BL is never in moribund_locations by our callers. */
3811 gdb_assert (bl->owner != NULL);
3813 if (bl->owner->enable_state == bp_permanent)
3814 /* Permanent breakpoints cannot be inserted or removed. */
3817 /* The type of none suggests that owner is actually deleted.
3818 This should not ever happen. */
3819 gdb_assert (bl->owner->type != bp_none);
3821 old_chain = save_current_space_and_thread ();
3823 switch_to_program_space_and_thread (bl->pspace);
3825 ret = remove_breakpoint_1 (bl, is);
3827 do_cleanups (old_chain);
3831 /* Clear the "inserted" flag in all breakpoints. */
3834 mark_breakpoints_out (void)
3836 struct bp_location *bl, **blp_tmp;
3838 ALL_BP_LOCATIONS (bl, blp_tmp)
3839 if (bl->pspace == current_program_space)
3843 /* Clear the "inserted" flag in all breakpoints and delete any
3844 breakpoints which should go away between runs of the program.
3846 Plus other such housekeeping that has to be done for breakpoints
3849 Note: this function gets called at the end of a run (by
3850 generic_mourn_inferior) and when a run begins (by
3851 init_wait_for_inferior). */
3856 breakpoint_init_inferior (enum inf_context context)
3858 struct breakpoint *b, *b_tmp;
3859 struct bp_location *bl, **blp_tmp;
3861 struct program_space *pspace = current_program_space;
3863 /* If breakpoint locations are shared across processes, then there's
3865 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
3868 ALL_BP_LOCATIONS (bl, blp_tmp)
3870 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3871 if (bl->pspace == pspace
3872 && bl->owner->enable_state != bp_permanent)
3876 ALL_BREAKPOINTS_SAFE (b, b_tmp)
3878 if (b->loc && b->loc->pspace != pspace)
3884 case bp_longjmp_call_dummy:
3886 /* If the call dummy breakpoint is at the entry point it will
3887 cause problems when the inferior is rerun, so we better get
3890 case bp_watchpoint_scope:
3892 /* Also get rid of scope breakpoints. */
3894 case bp_shlib_event:
3896 /* Also remove solib event breakpoints. Their addresses may
3897 have changed since the last time we ran the program.
3898 Actually we may now be debugging against different target;
3899 and so the solib backend that installed this breakpoint may
3900 not be used in by the target. E.g.,
3902 (gdb) file prog-linux
3903 (gdb) run # native linux target
3906 (gdb) file prog-win.exe
3907 (gdb) tar rem :9999 # remote Windows gdbserver.
3910 case bp_step_resume:
3912 /* Also remove step-resume breakpoints. */
3914 delete_breakpoint (b);
3918 case bp_hardware_watchpoint:
3919 case bp_read_watchpoint:
3920 case bp_access_watchpoint:
3922 struct watchpoint *w = (struct watchpoint *) b;
3924 /* Likewise for watchpoints on local expressions. */
3925 if (w->exp_valid_block != NULL)
3926 delete_breakpoint (b);
3927 else if (context == inf_starting)
3929 /* Reset val field to force reread of starting value in
3930 insert_breakpoints. */
3932 value_free (w->val);
3943 /* Get rid of the moribund locations. */
3944 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix)
3945 decref_bp_location (&bl);
3946 VEC_free (bp_location_p, moribund_locations);
3949 /* These functions concern about actual breakpoints inserted in the
3950 target --- to e.g. check if we need to do decr_pc adjustment or if
3951 we need to hop over the bkpt --- so we check for address space
3952 match, not program space. */
3954 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
3955 exists at PC. It returns ordinary_breakpoint_here if it's an
3956 ordinary breakpoint, or permanent_breakpoint_here if it's a
3957 permanent breakpoint.
3958 - When continuing from a location with an ordinary breakpoint, we
3959 actually single step once before calling insert_breakpoints.
3960 - When continuing from a location with a permanent breakpoint, we
3961 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
3962 the target, to advance the PC past the breakpoint. */
3964 enum breakpoint_here
3965 breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
3967 struct bp_location *bl, **blp_tmp;
3968 int any_breakpoint_here = 0;
3970 ALL_BP_LOCATIONS (bl, blp_tmp)
3972 if (bl->loc_type != bp_loc_software_breakpoint
3973 && bl->loc_type != bp_loc_hardware_breakpoint)
3976 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3977 if ((breakpoint_enabled (bl->owner)
3978 || bl->owner->enable_state == bp_permanent)
3979 && breakpoint_location_address_match (bl, aspace, pc))
3981 if (overlay_debugging
3982 && section_is_overlay (bl->section)
3983 && !section_is_mapped (bl->section))
3984 continue; /* unmapped overlay -- can't be a match */
3985 else if (bl->owner->enable_state == bp_permanent)
3986 return permanent_breakpoint_here;
3988 any_breakpoint_here = 1;
3992 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
3995 /* Return true if there's a moribund breakpoint at PC. */
3998 moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
4000 struct bp_location *loc;
4003 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
4004 if (breakpoint_location_address_match (loc, aspace, pc))
4010 /* Returns non-zero if there's a breakpoint inserted at PC, which is
4011 inserted using regular breakpoint_chain / bp_location array
4012 mechanism. This does not check for single-step breakpoints, which
4013 are inserted and removed using direct target manipulation. */
4016 regular_breakpoint_inserted_here_p (struct address_space *aspace,
4019 struct bp_location *bl, **blp_tmp;
4021 ALL_BP_LOCATIONS (bl, blp_tmp)
4023 if (bl->loc_type != bp_loc_software_breakpoint
4024 && bl->loc_type != bp_loc_hardware_breakpoint)
4028 && breakpoint_location_address_match (bl, aspace, pc))
4030 if (overlay_debugging
4031 && section_is_overlay (bl->section)
4032 && !section_is_mapped (bl->section))
4033 continue; /* unmapped overlay -- can't be a match */
4041 /* Returns non-zero iff there's either regular breakpoint
4042 or a single step breakpoint inserted at PC. */
4045 breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
4047 if (regular_breakpoint_inserted_here_p (aspace, pc))
4050 if (single_step_breakpoint_inserted_here_p (aspace, pc))
4056 /* This function returns non-zero iff there is a software breakpoint
4060 software_breakpoint_inserted_here_p (struct address_space *aspace,
4063 struct bp_location *bl, **blp_tmp;
4065 ALL_BP_LOCATIONS (bl, blp_tmp)
4067 if (bl->loc_type != bp_loc_software_breakpoint)
4071 && breakpoint_address_match (bl->pspace->aspace, bl->address,
4074 if (overlay_debugging
4075 && section_is_overlay (bl->section)
4076 && !section_is_mapped (bl->section))
4077 continue; /* unmapped overlay -- can't be a match */
4083 /* Also check for software single-step breakpoints. */
4084 if (single_step_breakpoint_inserted_here_p (aspace, pc))
4091 hardware_watchpoint_inserted_in_range (struct address_space *aspace,
4092 CORE_ADDR addr, ULONGEST len)
4094 struct breakpoint *bpt;
4096 ALL_BREAKPOINTS (bpt)
4098 struct bp_location *loc;
4100 if (bpt->type != bp_hardware_watchpoint
4101 && bpt->type != bp_access_watchpoint)
4104 if (!breakpoint_enabled (bpt))
4107 for (loc = bpt->loc; loc; loc = loc->next)
4108 if (loc->pspace->aspace == aspace && loc->inserted)
4112 /* Check for intersection. */
4113 l = max (loc->address, addr);
4114 h = min (loc->address + loc->length, addr + len);
4122 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
4123 PC is valid for process/thread PTID. */
4126 breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc,
4129 struct bp_location *bl, **blp_tmp;
4130 /* The thread and task IDs associated to PTID, computed lazily. */
4134 ALL_BP_LOCATIONS (bl, blp_tmp)
4136 if (bl->loc_type != bp_loc_software_breakpoint
4137 && bl->loc_type != bp_loc_hardware_breakpoint)
4140 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
4141 if (!breakpoint_enabled (bl->owner)
4142 && bl->owner->enable_state != bp_permanent)
4145 if (!breakpoint_location_address_match (bl, aspace, pc))
4148 if (bl->owner->thread != -1)
4150 /* This is a thread-specific breakpoint. Check that ptid
4151 matches that thread. If thread hasn't been computed yet,
4152 it is now time to do so. */
4154 thread = pid_to_thread_id (ptid);
4155 if (bl->owner->thread != thread)
4159 if (bl->owner->task != 0)
4161 /* This is a task-specific breakpoint. Check that ptid
4162 matches that task. If task hasn't been computed yet,
4163 it is now time to do so. */
4165 task = ada_get_task_number (ptid);
4166 if (bl->owner->task != task)
4170 if (overlay_debugging
4171 && section_is_overlay (bl->section)
4172 && !section_is_mapped (bl->section))
4173 continue; /* unmapped overlay -- can't be a match */
4182 /* bpstat stuff. External routines' interfaces are documented
4186 is_catchpoint (struct breakpoint *ep)
4188 return (ep->type == bp_catchpoint);
4191 /* Frees any storage that is part of a bpstat. Does not walk the
4195 bpstat_free (bpstat bs)
4197 if (bs->old_val != NULL)
4198 value_free (bs->old_val);
4199 decref_counted_command_line (&bs->commands);
4200 decref_bp_location (&bs->bp_location_at);
4204 /* Clear a bpstat so that it says we are not at any breakpoint.
4205 Also free any storage that is part of a bpstat. */
4208 bpstat_clear (bpstat *bsp)
4225 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4226 is part of the bpstat is copied as well. */
4229 bpstat_copy (bpstat bs)
4233 bpstat retval = NULL;
4238 for (; bs != NULL; bs = bs->next)
4240 tmp = (bpstat) xmalloc (sizeof (*tmp));
4241 memcpy (tmp, bs, sizeof (*tmp));
4242 incref_counted_command_line (tmp->commands);
4243 incref_bp_location (tmp->bp_location_at);
4244 if (bs->old_val != NULL)
4246 tmp->old_val = value_copy (bs->old_val);
4247 release_value (tmp->old_val);
4251 /* This is the first thing in the chain. */
4261 /* Find the bpstat associated with this breakpoint. */
4264 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
4269 for (; bsp != NULL; bsp = bsp->next)
4271 if (bsp->breakpoint_at == breakpoint)
4277 /* See breakpoint.h. */
4280 bpstat_explains_signal (bpstat bsp, enum gdb_signal sig)
4282 for (; bsp != NULL; bsp = bsp->next)
4284 if (bsp->breakpoint_at == NULL)
4286 /* A moribund location can never explain a signal other than
4288 if (sig == GDB_SIGNAL_TRAP)
4293 if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at,
4302 /* Put in *NUM the breakpoint number of the first breakpoint we are
4303 stopped at. *BSP upon return is a bpstat which points to the
4304 remaining breakpoints stopped at (but which is not guaranteed to be
4305 good for anything but further calls to bpstat_num).
4307 Return 0 if passed a bpstat which does not indicate any breakpoints.
4308 Return -1 if stopped at a breakpoint that has been deleted since
4310 Return 1 otherwise. */
4313 bpstat_num (bpstat *bsp, int *num)
4315 struct breakpoint *b;
4318 return 0; /* No more breakpoint values */
4320 /* We assume we'll never have several bpstats that correspond to a
4321 single breakpoint -- otherwise, this function might return the
4322 same number more than once and this will look ugly. */
4323 b = (*bsp)->breakpoint_at;
4324 *bsp = (*bsp)->next;
4326 return -1; /* breakpoint that's been deleted since */
4328 *num = b->number; /* We have its number */
4332 /* See breakpoint.h. */
4335 bpstat_clear_actions (void)
4337 struct thread_info *tp;
4340 if (ptid_equal (inferior_ptid, null_ptid))
4343 tp = find_thread_ptid (inferior_ptid);
4347 for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next)
4349 decref_counted_command_line (&bs->commands);
4351 if (bs->old_val != NULL)
4353 value_free (bs->old_val);
4359 /* Called when a command is about to proceed the inferior. */
4362 breakpoint_about_to_proceed (void)
4364 if (!ptid_equal (inferior_ptid, null_ptid))
4366 struct thread_info *tp = inferior_thread ();
4368 /* Allow inferior function calls in breakpoint commands to not
4369 interrupt the command list. When the call finishes
4370 successfully, the inferior will be standing at the same
4371 breakpoint as if nothing happened. */
4372 if (tp->control.in_infcall)
4376 breakpoint_proceeded = 1;
4379 /* Stub for cleaning up our state if we error-out of a breakpoint
4382 cleanup_executing_breakpoints (void *ignore)
4384 executing_breakpoint_commands = 0;
4387 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4388 or its equivalent. */
4391 command_line_is_silent (struct command_line *cmd)
4393 return cmd && (strcmp ("silent", cmd->line) == 0
4394 || (xdb_commands && strcmp ("Q", cmd->line) == 0));
4397 /* Execute all the commands associated with all the breakpoints at
4398 this location. Any of these commands could cause the process to
4399 proceed beyond this point, etc. We look out for such changes by
4400 checking the global "breakpoint_proceeded" after each command.
4402 Returns true if a breakpoint command resumed the inferior. In that
4403 case, it is the caller's responsibility to recall it again with the
4404 bpstat of the current thread. */
4407 bpstat_do_actions_1 (bpstat *bsp)
4410 struct cleanup *old_chain;
4413 /* Avoid endless recursion if a `source' command is contained
4415 if (executing_breakpoint_commands)
4418 executing_breakpoint_commands = 1;
4419 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
4421 prevent_dont_repeat ();
4423 /* This pointer will iterate over the list of bpstat's. */
4426 breakpoint_proceeded = 0;
4427 for (; bs != NULL; bs = bs->next)
4429 struct counted_command_line *ccmd;
4430 struct command_line *cmd;
4431 struct cleanup *this_cmd_tree_chain;
4433 /* Take ownership of the BSP's command tree, if it has one.
4435 The command tree could legitimately contain commands like
4436 'step' and 'next', which call clear_proceed_status, which
4437 frees stop_bpstat's command tree. To make sure this doesn't
4438 free the tree we're executing out from under us, we need to
4439 take ownership of the tree ourselves. Since a given bpstat's
4440 commands are only executed once, we don't need to copy it; we
4441 can clear the pointer in the bpstat, and make sure we free
4442 the tree when we're done. */
4443 ccmd = bs->commands;
4444 bs->commands = NULL;
4445 this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd);
4446 cmd = ccmd ? ccmd->commands : NULL;
4447 if (command_line_is_silent (cmd))
4449 /* The action has been already done by bpstat_stop_status. */
4455 execute_control_command (cmd);
4457 if (breakpoint_proceeded)
4463 /* We can free this command tree now. */
4464 do_cleanups (this_cmd_tree_chain);
4466 if (breakpoint_proceeded)
4468 if (target_can_async_p ())
4469 /* If we are in async mode, then the target might be still
4470 running, not stopped at any breakpoint, so nothing for
4471 us to do here -- just return to the event loop. */
4474 /* In sync mode, when execute_control_command returns
4475 we're already standing on the next breakpoint.
4476 Breakpoint commands for that stop were not run, since
4477 execute_command does not run breakpoint commands --
4478 only command_line_handler does, but that one is not
4479 involved in execution of breakpoint commands. So, we
4480 can now execute breakpoint commands. It should be
4481 noted that making execute_command do bpstat actions is
4482 not an option -- in this case we'll have recursive
4483 invocation of bpstat for each breakpoint with a
4484 command, and can easily blow up GDB stack. Instead, we
4485 return true, which will trigger the caller to recall us
4486 with the new stop_bpstat. */
4491 do_cleanups (old_chain);
4496 bpstat_do_actions (void)
4498 struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup ();
4500 /* Do any commands attached to breakpoint we are stopped at. */
4501 while (!ptid_equal (inferior_ptid, null_ptid)
4502 && target_has_execution
4503 && !is_exited (inferior_ptid)
4504 && !is_executing (inferior_ptid))
4505 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4506 and only return when it is stopped at the next breakpoint, we
4507 keep doing breakpoint actions until it returns false to
4508 indicate the inferior was not resumed. */
4509 if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat))
4512 discard_cleanups (cleanup_if_error);
4515 /* Print out the (old or new) value associated with a watchpoint. */
4518 watchpoint_value_print (struct value *val, struct ui_file *stream)
4521 fprintf_unfiltered (stream, _("<unreadable>"));
4524 struct value_print_options opts;
4525 get_user_print_options (&opts);
4526 value_print (val, stream, &opts);
4530 /* Generic routine for printing messages indicating why we
4531 stopped. The behavior of this function depends on the value
4532 'print_it' in the bpstat structure. Under some circumstances we
4533 may decide not to print anything here and delegate the task to
4536 static enum print_stop_action
4537 print_bp_stop_message (bpstat bs)
4539 switch (bs->print_it)
4542 /* Nothing should be printed for this bpstat entry. */
4543 return PRINT_UNKNOWN;
4547 /* We still want to print the frame, but we already printed the
4548 relevant messages. */
4549 return PRINT_SRC_AND_LOC;
4552 case print_it_normal:
4554 struct breakpoint *b = bs->breakpoint_at;
4556 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4557 which has since been deleted. */
4559 return PRINT_UNKNOWN;
4561 /* Normal case. Call the breakpoint's print_it method. */
4562 return b->ops->print_it (bs);
4567 internal_error (__FILE__, __LINE__,
4568 _("print_bp_stop_message: unrecognized enum value"));
4573 /* A helper function that prints a shared library stopped event. */
4576 print_solib_event (int is_catchpoint)
4579 = !VEC_empty (char_ptr, current_program_space->deleted_solibs);
4581 = !VEC_empty (so_list_ptr, current_program_space->added_solibs);
4585 if (any_added || any_deleted)
4586 ui_out_text (current_uiout,
4587 _("Stopped due to shared library event:\n"));
4589 ui_out_text (current_uiout,
4590 _("Stopped due to shared library event (no "
4591 "libraries added or removed)\n"));
4594 if (ui_out_is_mi_like_p (current_uiout))
4595 ui_out_field_string (current_uiout, "reason",
4596 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT));
4600 struct cleanup *cleanup;
4604 ui_out_text (current_uiout, _(" Inferior unloaded "));
4605 cleanup = make_cleanup_ui_out_list_begin_end (current_uiout,
4608 VEC_iterate (char_ptr, current_program_space->deleted_solibs,
4613 ui_out_text (current_uiout, " ");
4614 ui_out_field_string (current_uiout, "library", name);
4615 ui_out_text (current_uiout, "\n");
4618 do_cleanups (cleanup);
4623 struct so_list *iter;
4625 struct cleanup *cleanup;
4627 ui_out_text (current_uiout, _(" Inferior loaded "));
4628 cleanup = make_cleanup_ui_out_list_begin_end (current_uiout,
4631 VEC_iterate (so_list_ptr, current_program_space->added_solibs,
4636 ui_out_text (current_uiout, " ");
4637 ui_out_field_string (current_uiout, "library", iter->so_name);
4638 ui_out_text (current_uiout, "\n");
4641 do_cleanups (cleanup);
4645 /* Print a message indicating what happened. This is called from
4646 normal_stop(). The input to this routine is the head of the bpstat
4647 list - a list of the eventpoints that caused this stop. KIND is
4648 the target_waitkind for the stopping event. This
4649 routine calls the generic print routine for printing a message
4650 about reasons for stopping. This will print (for example) the
4651 "Breakpoint n," part of the output. The return value of this
4654 PRINT_UNKNOWN: Means we printed nothing.
4655 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4656 code to print the location. An example is
4657 "Breakpoint 1, " which should be followed by
4659 PRINT_SRC_ONLY: Means we printed something, but there is no need
4660 to also print the location part of the message.
4661 An example is the catch/throw messages, which
4662 don't require a location appended to the end.
4663 PRINT_NOTHING: We have done some printing and we don't need any
4664 further info to be printed. */
4666 enum print_stop_action
4667 bpstat_print (bpstat bs, int kind)
4671 /* Maybe another breakpoint in the chain caused us to stop.
4672 (Currently all watchpoints go on the bpstat whether hit or not.
4673 That probably could (should) be changed, provided care is taken
4674 with respect to bpstat_explains_signal). */
4675 for (; bs; bs = bs->next)
4677 val = print_bp_stop_message (bs);
4678 if (val == PRINT_SRC_ONLY
4679 || val == PRINT_SRC_AND_LOC
4680 || val == PRINT_NOTHING)
4684 /* If we had hit a shared library event breakpoint,
4685 print_bp_stop_message would print out this message. If we hit an
4686 OS-level shared library event, do the same thing. */
4687 if (kind == TARGET_WAITKIND_LOADED)
4689 print_solib_event (0);
4690 return PRINT_NOTHING;
4693 /* We reached the end of the chain, or we got a null BS to start
4694 with and nothing was printed. */
4695 return PRINT_UNKNOWN;
4698 /* Evaluate the expression EXP and return 1 if value is zero.
4699 This returns the inverse of the condition because it is called
4700 from catch_errors which returns 0 if an exception happened, and if an
4701 exception happens we want execution to stop.
4702 The argument is a "struct expression *" that has been cast to a
4703 "void *" to make it pass through catch_errors. */
4706 breakpoint_cond_eval (void *exp)
4708 struct value *mark = value_mark ();
4709 int i = !value_true (evaluate_expression ((struct expression *) exp));
4711 value_free_to_mark (mark);
4715 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4718 bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer)
4722 bs = (bpstat) xmalloc (sizeof (*bs));
4724 **bs_link_pointer = bs;
4725 *bs_link_pointer = &bs->next;
4726 bs->breakpoint_at = bl->owner;
4727 bs->bp_location_at = bl;
4728 incref_bp_location (bl);
4729 /* If the condition is false, etc., don't do the commands. */
4730 bs->commands = NULL;
4732 bs->print_it = print_it_normal;
4736 /* The target has stopped with waitstatus WS. Check if any hardware
4737 watchpoints have triggered, according to the target. */
4740 watchpoints_triggered (struct target_waitstatus *ws)
4742 int stopped_by_watchpoint = target_stopped_by_watchpoint ();
4744 struct breakpoint *b;
4746 if (!stopped_by_watchpoint)
4748 /* We were not stopped by a watchpoint. Mark all watchpoints
4749 as not triggered. */
4751 if (is_hardware_watchpoint (b))
4753 struct watchpoint *w = (struct watchpoint *) b;
4755 w->watchpoint_triggered = watch_triggered_no;
4761 if (!target_stopped_data_address (¤t_target, &addr))
4763 /* We were stopped by a watchpoint, but we don't know where.
4764 Mark all watchpoints as unknown. */
4766 if (is_hardware_watchpoint (b))
4768 struct watchpoint *w = (struct watchpoint *) b;
4770 w->watchpoint_triggered = watch_triggered_unknown;
4776 /* The target could report the data address. Mark watchpoints
4777 affected by this data address as triggered, and all others as not
4781 if (is_hardware_watchpoint (b))
4783 struct watchpoint *w = (struct watchpoint *) b;
4784 struct bp_location *loc;
4786 w->watchpoint_triggered = watch_triggered_no;
4787 for (loc = b->loc; loc; loc = loc->next)
4789 if (is_masked_watchpoint (b))
4791 CORE_ADDR newaddr = addr & w->hw_wp_mask;
4792 CORE_ADDR start = loc->address & w->hw_wp_mask;
4794 if (newaddr == start)
4796 w->watchpoint_triggered = watch_triggered_yes;
4800 /* Exact match not required. Within range is sufficient. */
4801 else if (target_watchpoint_addr_within_range (¤t_target,
4805 w->watchpoint_triggered = watch_triggered_yes;
4814 /* Possible return values for watchpoint_check (this can't be an enum
4815 because of check_errors). */
4816 /* The watchpoint has been deleted. */
4817 #define WP_DELETED 1
4818 /* The value has changed. */
4819 #define WP_VALUE_CHANGED 2
4820 /* The value has not changed. */
4821 #define WP_VALUE_NOT_CHANGED 3
4822 /* Ignore this watchpoint, no matter if the value changed or not. */
4825 #define BP_TEMPFLAG 1
4826 #define BP_HARDWAREFLAG 2
4828 /* Evaluate watchpoint condition expression and check if its value
4831 P should be a pointer to struct bpstat, but is defined as a void *
4832 in order for this function to be usable with catch_errors. */
4835 watchpoint_check (void *p)
4837 bpstat bs = (bpstat) p;
4838 struct watchpoint *b;
4839 struct frame_info *fr;
4840 int within_current_scope;
4842 /* BS is built from an existing struct breakpoint. */
4843 gdb_assert (bs->breakpoint_at != NULL);
4844 b = (struct watchpoint *) bs->breakpoint_at;
4846 /* If this is a local watchpoint, we only want to check if the
4847 watchpoint frame is in scope if the current thread is the thread
4848 that was used to create the watchpoint. */
4849 if (!watchpoint_in_thread_scope (b))
4852 if (b->exp_valid_block == NULL)
4853 within_current_scope = 1;
4856 struct frame_info *frame = get_current_frame ();
4857 struct gdbarch *frame_arch = get_frame_arch (frame);
4858 CORE_ADDR frame_pc = get_frame_pc (frame);
4860 /* in_function_epilogue_p() returns a non-zero value if we're
4861 still in the function but the stack frame has already been
4862 invalidated. Since we can't rely on the values of local
4863 variables after the stack has been destroyed, we are treating
4864 the watchpoint in that state as `not changed' without further
4865 checking. Don't mark watchpoints as changed if the current
4866 frame is in an epilogue - even if they are in some other
4867 frame, our view of the stack is likely to be wrong and
4868 frame_find_by_id could error out. */
4869 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
4872 fr = frame_find_by_id (b->watchpoint_frame);
4873 within_current_scope = (fr != NULL);
4875 /* If we've gotten confused in the unwinder, we might have
4876 returned a frame that can't describe this variable. */
4877 if (within_current_scope)
4879 struct symbol *function;
4881 function = get_frame_function (fr);
4882 if (function == NULL
4883 || !contained_in (b->exp_valid_block,
4884 SYMBOL_BLOCK_VALUE (function)))
4885 within_current_scope = 0;
4888 if (within_current_scope)
4889 /* If we end up stopping, the current frame will get selected
4890 in normal_stop. So this call to select_frame won't affect
4895 if (within_current_scope)
4897 /* We use value_{,free_to_}mark because it could be a *long*
4898 time before we return to the command level and call
4899 free_all_values. We can't call free_all_values because we
4900 might be in the middle of evaluating a function call. */
4904 struct value *new_val;
4906 if (is_masked_watchpoint (&b->base))
4907 /* Since we don't know the exact trigger address (from
4908 stopped_data_address), just tell the user we've triggered
4909 a mask watchpoint. */
4910 return WP_VALUE_CHANGED;
4912 mark = value_mark ();
4913 fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL, 0);
4915 /* We use value_equal_contents instead of value_equal because
4916 the latter coerces an array to a pointer, thus comparing just
4917 the address of the array instead of its contents. This is
4918 not what we want. */
4919 if ((b->val != NULL) != (new_val != NULL)
4920 || (b->val != NULL && !value_equal_contents (b->val, new_val)))
4922 if (new_val != NULL)
4924 release_value (new_val);
4925 value_free_to_mark (mark);
4927 bs->old_val = b->val;
4930 return WP_VALUE_CHANGED;
4934 /* Nothing changed. */
4935 value_free_to_mark (mark);
4936 return WP_VALUE_NOT_CHANGED;
4941 struct ui_out *uiout = current_uiout;
4943 /* This seems like the only logical thing to do because
4944 if we temporarily ignored the watchpoint, then when
4945 we reenter the block in which it is valid it contains
4946 garbage (in the case of a function, it may have two
4947 garbage values, one before and one after the prologue).
4948 So we can't even detect the first assignment to it and
4949 watch after that (since the garbage may or may not equal
4950 the first value assigned). */
4951 /* We print all the stop information in
4952 breakpoint_ops->print_it, but in this case, by the time we
4953 call breakpoint_ops->print_it this bp will be deleted
4954 already. So we have no choice but print the information
4956 if (ui_out_is_mi_like_p (uiout))
4958 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
4959 ui_out_text (uiout, "\nWatchpoint ");
4960 ui_out_field_int (uiout, "wpnum", b->base.number);
4962 " deleted because the program has left the block in\n\
4963 which its expression is valid.\n");
4965 /* Make sure the watchpoint's commands aren't executed. */
4966 decref_counted_command_line (&b->base.commands);
4967 watchpoint_del_at_next_stop (b);
4973 /* Return true if it looks like target has stopped due to hitting
4974 breakpoint location BL. This function does not check if we should
4975 stop, only if BL explains the stop. */
4978 bpstat_check_location (const struct bp_location *bl,
4979 struct address_space *aspace, CORE_ADDR bp_addr,
4980 const struct target_waitstatus *ws)
4982 struct breakpoint *b = bl->owner;
4984 /* BL is from an existing breakpoint. */
4985 gdb_assert (b != NULL);
4987 return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws);
4990 /* Determine if the watched values have actually changed, and we
4991 should stop. If not, set BS->stop to 0. */
4994 bpstat_check_watchpoint (bpstat bs)
4996 const struct bp_location *bl;
4997 struct watchpoint *b;
4999 /* BS is built for existing struct breakpoint. */
5000 bl = bs->bp_location_at;
5001 gdb_assert (bl != NULL);
5002 b = (struct watchpoint *) bs->breakpoint_at;
5003 gdb_assert (b != NULL);
5006 int must_check_value = 0;
5008 if (b->base.type == bp_watchpoint)
5009 /* For a software watchpoint, we must always check the
5011 must_check_value = 1;
5012 else if (b->watchpoint_triggered == watch_triggered_yes)
5013 /* We have a hardware watchpoint (read, write, or access)
5014 and the target earlier reported an address watched by
5016 must_check_value = 1;
5017 else if (b->watchpoint_triggered == watch_triggered_unknown
5018 && b->base.type == bp_hardware_watchpoint)
5019 /* We were stopped by a hardware watchpoint, but the target could
5020 not report the data address. We must check the watchpoint's
5021 value. Access and read watchpoints are out of luck; without
5022 a data address, we can't figure it out. */
5023 must_check_value = 1;
5025 if (must_check_value)
5028 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
5030 struct cleanup *cleanups = make_cleanup (xfree, message);
5031 int e = catch_errors (watchpoint_check, bs, message,
5033 do_cleanups (cleanups);
5037 /* We've already printed what needs to be printed. */
5038 bs->print_it = print_it_done;
5042 bs->print_it = print_it_noop;
5045 case WP_VALUE_CHANGED:
5046 if (b->base.type == bp_read_watchpoint)
5048 /* There are two cases to consider here:
5050 1. We're watching the triggered memory for reads.
5051 In that case, trust the target, and always report
5052 the watchpoint hit to the user. Even though
5053 reads don't cause value changes, the value may
5054 have changed since the last time it was read, and
5055 since we're not trapping writes, we will not see
5056 those, and as such we should ignore our notion of
5059 2. We're watching the triggered memory for both
5060 reads and writes. There are two ways this may
5063 2.1. This is a target that can't break on data
5064 reads only, but can break on accesses (reads or
5065 writes), such as e.g., x86. We detect this case
5066 at the time we try to insert read watchpoints.
5068 2.2. Otherwise, the target supports read
5069 watchpoints, but, the user set an access or write
5070 watchpoint watching the same memory as this read
5073 If we're watching memory writes as well as reads,
5074 ignore watchpoint hits when we find that the
5075 value hasn't changed, as reads don't cause
5076 changes. This still gives false positives when
5077 the program writes the same value to memory as
5078 what there was already in memory (we will confuse
5079 it for a read), but it's much better than
5082 int other_write_watchpoint = 0;
5084 if (bl->watchpoint_type == hw_read)
5086 struct breakpoint *other_b;
5088 ALL_BREAKPOINTS (other_b)
5089 if (other_b->type == bp_hardware_watchpoint
5090 || other_b->type == bp_access_watchpoint)
5092 struct watchpoint *other_w =
5093 (struct watchpoint *) other_b;
5095 if (other_w->watchpoint_triggered
5096 == watch_triggered_yes)
5098 other_write_watchpoint = 1;
5104 if (other_write_watchpoint
5105 || bl->watchpoint_type == hw_access)
5107 /* We're watching the same memory for writes,
5108 and the value changed since the last time we
5109 updated it, so this trap must be for a write.
5111 bs->print_it = print_it_noop;
5116 case WP_VALUE_NOT_CHANGED:
5117 if (b->base.type == bp_hardware_watchpoint
5118 || b->base.type == bp_watchpoint)
5120 /* Don't stop: write watchpoints shouldn't fire if
5121 the value hasn't changed. */
5122 bs->print_it = print_it_noop;
5130 /* Error from catch_errors. */
5131 printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number);
5132 watchpoint_del_at_next_stop (b);
5133 /* We've already printed what needs to be printed. */
5134 bs->print_it = print_it_done;
5138 else /* must_check_value == 0 */
5140 /* This is a case where some watchpoint(s) triggered, but
5141 not at the address of this watchpoint, or else no
5142 watchpoint triggered after all. So don't print
5143 anything for this watchpoint. */
5144 bs->print_it = print_it_noop;
5150 /* For breakpoints that are currently marked as telling gdb to stop,
5151 check conditions (condition proper, frame, thread and ignore count)
5152 of breakpoint referred to by BS. If we should not stop for this
5153 breakpoint, set BS->stop to 0. */
5156 bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
5158 int thread_id = pid_to_thread_id (ptid);
5159 const struct bp_location *bl;
5160 struct breakpoint *b;
5161 int value_is_zero = 0;
5162 struct expression *cond;
5164 gdb_assert (bs->stop);
5166 /* BS is built for existing struct breakpoint. */
5167 bl = bs->bp_location_at;
5168 gdb_assert (bl != NULL);
5169 b = bs->breakpoint_at;
5170 gdb_assert (b != NULL);
5172 /* Even if the target evaluated the condition on its end and notified GDB, we
5173 need to do so again since GDB does not know if we stopped due to a
5174 breakpoint or a single step breakpoint. */
5176 if (frame_id_p (b->frame_id)
5177 && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ())))
5183 /* If this is a thread-specific breakpoint, don't waste cpu evaluating the
5184 condition if this isn't the specified thread. */
5185 if (b->thread != -1 && b->thread != thread_id)
5191 /* Evaluate Python breakpoints that have a "stop" method implemented. */
5192 if (b->py_bp_object)
5193 bs->stop = gdbpy_should_stop (b->py_bp_object);
5195 if (is_watchpoint (b))
5197 struct watchpoint *w = (struct watchpoint *) b;
5204 if (cond && b->disposition != disp_del_at_next_stop)
5206 int within_current_scope = 1;
5207 struct watchpoint * w;
5209 /* We use value_mark and value_free_to_mark because it could
5210 be a long time before we return to the command level and
5211 call free_all_values. We can't call free_all_values
5212 because we might be in the middle of evaluating a
5214 struct value *mark = value_mark ();
5216 if (is_watchpoint (b))
5217 w = (struct watchpoint *) b;
5221 /* Need to select the frame, with all that implies so that
5222 the conditions will have the right context. Because we
5223 use the frame, we will not see an inlined function's
5224 variables when we arrive at a breakpoint at the start
5225 of the inlined function; the current frame will be the
5227 if (w == NULL || w->cond_exp_valid_block == NULL)
5228 select_frame (get_current_frame ());
5231 struct frame_info *frame;
5233 /* For local watchpoint expressions, which particular
5234 instance of a local is being watched matters, so we
5235 keep track of the frame to evaluate the expression
5236 in. To evaluate the condition however, it doesn't
5237 really matter which instantiation of the function
5238 where the condition makes sense triggers the
5239 watchpoint. This allows an expression like "watch
5240 global if q > 10" set in `func', catch writes to
5241 global on all threads that call `func', or catch
5242 writes on all recursive calls of `func' by a single
5243 thread. We simply always evaluate the condition in
5244 the innermost frame that's executing where it makes
5245 sense to evaluate the condition. It seems
5247 frame = block_innermost_frame (w->cond_exp_valid_block);
5249 select_frame (frame);
5251 within_current_scope = 0;
5253 if (within_current_scope)
5255 = catch_errors (breakpoint_cond_eval, cond,
5256 "Error in testing breakpoint condition:\n",
5260 warning (_("Watchpoint condition cannot be tested "
5261 "in the current scope"));
5262 /* If we failed to set the right context for this
5263 watchpoint, unconditionally report it. */
5266 /* FIXME-someday, should give breakpoint #. */
5267 value_free_to_mark (mark);
5270 if (cond && value_is_zero)
5274 else if (b->ignore_count > 0)
5278 /* Increase the hit count even though we don't stop. */
5280 observer_notify_breakpoint_modified (b);
5285 /* Get a bpstat associated with having just stopped at address
5286 BP_ADDR in thread PTID.
5288 Determine whether we stopped at a breakpoint, etc, or whether we
5289 don't understand this stop. Result is a chain of bpstat's such
5292 if we don't understand the stop, the result is a null pointer.
5294 if we understand why we stopped, the result is not null.
5296 Each element of the chain refers to a particular breakpoint or
5297 watchpoint at which we have stopped. (We may have stopped for
5298 several reasons concurrently.)
5300 Each element of the chain has valid next, breakpoint_at,
5301 commands, FIXME??? fields. */
5304 bpstat_stop_status (struct address_space *aspace,
5305 CORE_ADDR bp_addr, ptid_t ptid,
5306 const struct target_waitstatus *ws)
5308 struct breakpoint *b = NULL;
5309 struct bp_location *bl;
5310 struct bp_location *loc;
5311 /* First item of allocated bpstat's. */
5312 bpstat bs_head = NULL, *bs_link = &bs_head;
5313 /* Pointer to the last thing in the chain currently. */
5316 int need_remove_insert;
5319 /* First, build the bpstat chain with locations that explain a
5320 target stop, while being careful to not set the target running,
5321 as that may invalidate locations (in particular watchpoint
5322 locations are recreated). Resuming will happen here with
5323 breakpoint conditions or watchpoint expressions that include
5324 inferior function calls. */
5328 if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
5331 for (bl = b->loc; bl != NULL; bl = bl->next)
5333 /* For hardware watchpoints, we look only at the first
5334 location. The watchpoint_check function will work on the
5335 entire expression, not the individual locations. For
5336 read watchpoints, the watchpoints_triggered function has
5337 checked all locations already. */
5338 if (b->type == bp_hardware_watchpoint && bl != b->loc)
5341 if (!bl->enabled || bl->shlib_disabled)
5344 if (!bpstat_check_location (bl, aspace, bp_addr, ws))
5347 /* Come here if it's a watchpoint, or if the break address
5350 bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to
5353 /* Assume we stop. Should we find a watchpoint that is not
5354 actually triggered, or if the condition of the breakpoint
5355 evaluates as false, we'll reset 'stop' to 0. */
5359 /* If this is a scope breakpoint, mark the associated
5360 watchpoint as triggered so that we will handle the
5361 out-of-scope event. We'll get to the watchpoint next
5363 if (b->type == bp_watchpoint_scope && b->related_breakpoint != b)
5365 struct watchpoint *w = (struct watchpoint *) b->related_breakpoint;
5367 w->watchpoint_triggered = watch_triggered_yes;
5372 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
5374 if (breakpoint_location_address_match (loc, aspace, bp_addr))
5376 bs = bpstat_alloc (loc, &bs_link);
5377 /* For hits of moribund locations, we should just proceed. */
5380 bs->print_it = print_it_noop;
5384 /* A bit of special processing for shlib breakpoints. We need to
5385 process solib loading here, so that the lists of loaded and
5386 unloaded libraries are correct before we handle "catch load" and
5388 for (bs = bs_head; bs != NULL; bs = bs->next)
5390 if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event)
5392 handle_solib_event ();
5397 /* Now go through the locations that caused the target to stop, and
5398 check whether we're interested in reporting this stop to higher
5399 layers, or whether we should resume the target transparently. */
5403 for (bs = bs_head; bs != NULL; bs = bs->next)
5408 b = bs->breakpoint_at;
5409 b->ops->check_status (bs);
5412 bpstat_check_breakpoint_conditions (bs, ptid);
5417 observer_notify_breakpoint_modified (b);
5419 /* We will stop here. */
5420 if (b->disposition == disp_disable)
5422 --(b->enable_count);
5423 if (b->enable_count <= 0
5424 && b->enable_state != bp_permanent)
5425 b->enable_state = bp_disabled;
5430 bs->commands = b->commands;
5431 incref_counted_command_line (bs->commands);
5432 if (command_line_is_silent (bs->commands
5433 ? bs->commands->commands : NULL))
5436 b->ops->after_condition_true (bs);
5441 /* Print nothing for this entry if we don't stop or don't
5443 if (!bs->stop || !bs->print)
5444 bs->print_it = print_it_noop;
5447 /* If we aren't stopping, the value of some hardware watchpoint may
5448 not have changed, but the intermediate memory locations we are
5449 watching may have. Don't bother if we're stopping; this will get
5451 need_remove_insert = 0;
5452 if (! bpstat_causes_stop (bs_head))
5453 for (bs = bs_head; bs != NULL; bs = bs->next)
5455 && bs->breakpoint_at
5456 && is_hardware_watchpoint (bs->breakpoint_at))
5458 struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at;
5460 update_watchpoint (w, 0 /* don't reparse. */);
5461 need_remove_insert = 1;
5464 if (need_remove_insert)
5465 update_global_location_list (1);
5466 else if (removed_any)
5467 update_global_location_list (0);
5473 handle_jit_event (void)
5475 struct frame_info *frame;
5476 struct gdbarch *gdbarch;
5478 /* Switch terminal for any messages produced by
5479 breakpoint_re_set. */
5480 target_terminal_ours_for_output ();
5482 frame = get_current_frame ();
5483 gdbarch = get_frame_arch (frame);
5485 jit_event_handler (gdbarch);
5487 target_terminal_inferior ();
5490 /* Prepare WHAT final decision for infrun. */
5492 /* Decide what infrun needs to do with this bpstat. */
5495 bpstat_what (bpstat bs_head)
5497 struct bpstat_what retval;
5501 retval.main_action = BPSTAT_WHAT_KEEP_CHECKING;
5502 retval.call_dummy = STOP_NONE;
5503 retval.is_longjmp = 0;
5505 for (bs = bs_head; bs != NULL; bs = bs->next)
5507 /* Extract this BS's action. After processing each BS, we check
5508 if its action overrides all we've seem so far. */
5509 enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING;
5512 if (bs->breakpoint_at == NULL)
5514 /* I suspect this can happen if it was a momentary
5515 breakpoint which has since been deleted. */
5519 bptype = bs->breakpoint_at->type;
5526 case bp_hardware_breakpoint:
5529 case bp_shlib_event:
5533 this_action = BPSTAT_WHAT_STOP_NOISY;
5535 this_action = BPSTAT_WHAT_STOP_SILENT;
5538 this_action = BPSTAT_WHAT_SINGLE;
5541 case bp_hardware_watchpoint:
5542 case bp_read_watchpoint:
5543 case bp_access_watchpoint:
5547 this_action = BPSTAT_WHAT_STOP_NOISY;
5549 this_action = BPSTAT_WHAT_STOP_SILENT;
5553 /* There was a watchpoint, but we're not stopping.
5554 This requires no further action. */
5558 case bp_longjmp_call_dummy:
5560 this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME;
5561 retval.is_longjmp = bptype != bp_exception;
5563 case bp_longjmp_resume:
5564 case bp_exception_resume:
5565 this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME;
5566 retval.is_longjmp = bptype == bp_longjmp_resume;
5568 case bp_step_resume:
5570 this_action = BPSTAT_WHAT_STEP_RESUME;
5573 /* It is for the wrong frame. */
5574 this_action = BPSTAT_WHAT_SINGLE;
5577 case bp_hp_step_resume:
5579 this_action = BPSTAT_WHAT_HP_STEP_RESUME;
5582 /* It is for the wrong frame. */
5583 this_action = BPSTAT_WHAT_SINGLE;
5586 case bp_watchpoint_scope:
5587 case bp_thread_event:
5588 case bp_overlay_event:
5589 case bp_longjmp_master:
5590 case bp_std_terminate_master:
5591 case bp_exception_master:
5592 this_action = BPSTAT_WHAT_SINGLE;
5598 this_action = BPSTAT_WHAT_STOP_NOISY;
5600 this_action = BPSTAT_WHAT_STOP_SILENT;
5604 /* There was a catchpoint, but we're not stopping.
5605 This requires no further action. */
5610 this_action = BPSTAT_WHAT_SINGLE;
5613 /* Make sure the action is stop (silent or noisy),
5614 so infrun.c pops the dummy frame. */
5615 retval.call_dummy = STOP_STACK_DUMMY;
5616 this_action = BPSTAT_WHAT_STOP_SILENT;
5618 case bp_std_terminate:
5619 /* Make sure the action is stop (silent or noisy),
5620 so infrun.c pops the dummy frame. */
5621 retval.call_dummy = STOP_STD_TERMINATE;
5622 this_action = BPSTAT_WHAT_STOP_SILENT;
5625 case bp_fast_tracepoint:
5626 case bp_static_tracepoint:
5627 /* Tracepoint hits should not be reported back to GDB, and
5628 if one got through somehow, it should have been filtered
5630 internal_error (__FILE__, __LINE__,
5631 _("bpstat_what: tracepoint encountered"));
5633 case bp_gnu_ifunc_resolver:
5634 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5635 this_action = BPSTAT_WHAT_SINGLE;
5637 case bp_gnu_ifunc_resolver_return:
5638 /* The breakpoint will be removed, execution will restart from the
5639 PC of the former breakpoint. */
5640 this_action = BPSTAT_WHAT_KEEP_CHECKING;
5645 this_action = BPSTAT_WHAT_STOP_SILENT;
5647 this_action = BPSTAT_WHAT_SINGLE;
5651 internal_error (__FILE__, __LINE__,
5652 _("bpstat_what: unhandled bptype %d"), (int) bptype);
5655 retval.main_action = max (retval.main_action, this_action);
5658 /* These operations may affect the bs->breakpoint_at state so they are
5659 delayed after MAIN_ACTION is decided above. */
5664 fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n");
5666 handle_jit_event ();
5669 for (bs = bs_head; bs != NULL; bs = bs->next)
5671 struct breakpoint *b = bs->breakpoint_at;
5677 case bp_gnu_ifunc_resolver:
5678 gnu_ifunc_resolver_stop (b);
5680 case bp_gnu_ifunc_resolver_return:
5681 gnu_ifunc_resolver_return_stop (b);
5689 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5690 without hardware support). This isn't related to a specific bpstat,
5691 just to things like whether watchpoints are set. */
5694 bpstat_should_step (void)
5696 struct breakpoint *b;
5699 if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL)
5705 bpstat_causes_stop (bpstat bs)
5707 for (; bs != NULL; bs = bs->next)
5716 /* Compute a string of spaces suitable to indent the next line
5717 so it starts at the position corresponding to the table column
5718 named COL_NAME in the currently active table of UIOUT. */
5721 wrap_indent_at_field (struct ui_out *uiout, const char *col_name)
5723 static char wrap_indent[80];
5724 int i, total_width, width, align;
5728 for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++)
5730 if (strcmp (text, col_name) == 0)
5732 gdb_assert (total_width < sizeof wrap_indent);
5733 memset (wrap_indent, ' ', total_width);
5734 wrap_indent[total_width] = 0;
5739 total_width += width + 1;
5745 /* Determine if the locations of this breakpoint will have their conditions
5746 evaluated by the target, host or a mix of both. Returns the following:
5748 "host": Host evals condition.
5749 "host or target": Host or Target evals condition.
5750 "target": Target evals condition.
5754 bp_condition_evaluator (struct breakpoint *b)
5756 struct bp_location *bl;
5757 char host_evals = 0;
5758 char target_evals = 0;
5763 if (!is_breakpoint (b))
5766 if (gdb_evaluates_breakpoint_condition_p ()
5767 || !target_supports_evaluation_of_breakpoint_conditions ())
5768 return condition_evaluation_host;
5770 for (bl = b->loc; bl; bl = bl->next)
5772 if (bl->cond_bytecode)
5778 if (host_evals && target_evals)
5779 return condition_evaluation_both;
5780 else if (target_evals)
5781 return condition_evaluation_target;
5783 return condition_evaluation_host;
5786 /* Determine the breakpoint location's condition evaluator. This is
5787 similar to bp_condition_evaluator, but for locations. */
5790 bp_location_condition_evaluator (struct bp_location *bl)
5792 if (bl && !is_breakpoint (bl->owner))
5795 if (gdb_evaluates_breakpoint_condition_p ()
5796 || !target_supports_evaluation_of_breakpoint_conditions ())
5797 return condition_evaluation_host;
5799 if (bl && bl->cond_bytecode)
5800 return condition_evaluation_target;
5802 return condition_evaluation_host;
5805 /* Print the LOC location out of the list of B->LOC locations. */
5808 print_breakpoint_location (struct breakpoint *b,
5809 struct bp_location *loc)
5811 struct ui_out *uiout = current_uiout;
5812 struct cleanup *old_chain = save_current_program_space ();
5814 if (loc != NULL && loc->shlib_disabled)
5818 set_current_program_space (loc->pspace);
5820 if (b->display_canonical)
5821 ui_out_field_string (uiout, "what", b->addr_string);
5822 else if (loc && loc->symtab)
5825 = find_pc_sect_function (loc->address, loc->section);
5828 ui_out_text (uiout, "in ");
5829 ui_out_field_string (uiout, "func",
5830 SYMBOL_PRINT_NAME (sym));
5831 ui_out_text (uiout, " ");
5832 ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what"));
5833 ui_out_text (uiout, "at ");
5835 ui_out_field_string (uiout, "file",
5836 symtab_to_filename_for_display (loc->symtab));
5837 ui_out_text (uiout, ":");
5839 if (ui_out_is_mi_like_p (uiout))
5840 ui_out_field_string (uiout, "fullname",
5841 symtab_to_fullname (loc->symtab));
5843 ui_out_field_int (uiout, "line", loc->line_number);
5847 struct ui_file *stb = mem_fileopen ();
5848 struct cleanup *stb_chain = make_cleanup_ui_file_delete (stb);
5850 print_address_symbolic (loc->gdbarch, loc->address, stb,
5852 ui_out_field_stream (uiout, "at", stb);
5854 do_cleanups (stb_chain);
5857 ui_out_field_string (uiout, "pending", b->addr_string);
5859 if (loc && is_breakpoint (b)
5860 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
5861 && bp_condition_evaluator (b) == condition_evaluation_both)
5863 ui_out_text (uiout, " (");
5864 ui_out_field_string (uiout, "evaluated-by",
5865 bp_location_condition_evaluator (loc));
5866 ui_out_text (uiout, ")");
5869 do_cleanups (old_chain);
5873 bptype_string (enum bptype type)
5875 struct ep_type_description
5880 static struct ep_type_description bptypes[] =
5882 {bp_none, "?deleted?"},
5883 {bp_breakpoint, "breakpoint"},
5884 {bp_hardware_breakpoint, "hw breakpoint"},
5885 {bp_until, "until"},
5886 {bp_finish, "finish"},
5887 {bp_watchpoint, "watchpoint"},
5888 {bp_hardware_watchpoint, "hw watchpoint"},
5889 {bp_read_watchpoint, "read watchpoint"},
5890 {bp_access_watchpoint, "acc watchpoint"},
5891 {bp_longjmp, "longjmp"},
5892 {bp_longjmp_resume, "longjmp resume"},
5893 {bp_longjmp_call_dummy, "longjmp for call dummy"},
5894 {bp_exception, "exception"},
5895 {bp_exception_resume, "exception resume"},
5896 {bp_step_resume, "step resume"},
5897 {bp_hp_step_resume, "high-priority step resume"},
5898 {bp_watchpoint_scope, "watchpoint scope"},
5899 {bp_call_dummy, "call dummy"},
5900 {bp_std_terminate, "std::terminate"},
5901 {bp_shlib_event, "shlib events"},
5902 {bp_thread_event, "thread events"},
5903 {bp_overlay_event, "overlay events"},
5904 {bp_longjmp_master, "longjmp master"},
5905 {bp_std_terminate_master, "std::terminate master"},
5906 {bp_exception_master, "exception master"},
5907 {bp_catchpoint, "catchpoint"},
5908 {bp_tracepoint, "tracepoint"},
5909 {bp_fast_tracepoint, "fast tracepoint"},
5910 {bp_static_tracepoint, "static tracepoint"},
5911 {bp_dprintf, "dprintf"},
5912 {bp_jit_event, "jit events"},
5913 {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"},
5914 {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"},
5917 if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0])))
5918 || ((int) type != bptypes[(int) type].type))
5919 internal_error (__FILE__, __LINE__,
5920 _("bptypes table does not describe type #%d."),
5923 return bptypes[(int) type].description;
5926 /* For MI, output a field named 'thread-groups' with a list as the value.
5927 For CLI, prefix the list with the string 'inf'. */
5930 output_thread_groups (struct ui_out *uiout,
5931 const char *field_name,
5935 struct cleanup *back_to;
5936 int is_mi = ui_out_is_mi_like_p (uiout);
5940 /* For backward compatibility, don't display inferiors in CLI unless
5941 there are several. Always display them for MI. */
5942 if (!is_mi && mi_only)
5945 back_to = make_cleanup_ui_out_list_begin_end (uiout, field_name);
5947 for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i)
5953 xsnprintf (mi_group, sizeof (mi_group), "i%d", inf);
5954 ui_out_field_string (uiout, NULL, mi_group);
5959 ui_out_text (uiout, " inf ");
5961 ui_out_text (uiout, ", ");
5963 ui_out_text (uiout, plongest (inf));
5967 do_cleanups (back_to);
5970 /* Print B to gdb_stdout. */
5973 print_one_breakpoint_location (struct breakpoint *b,
5974 struct bp_location *loc,
5976 struct bp_location **last_loc,
5979 struct command_line *l;
5980 static char bpenables[] = "nynny";
5982 struct ui_out *uiout = current_uiout;
5983 int header_of_multiple = 0;
5984 int part_of_multiple = (loc != NULL);
5985 struct value_print_options opts;
5987 get_user_print_options (&opts);
5989 gdb_assert (!loc || loc_number != 0);
5990 /* See comment in print_one_breakpoint concerning treatment of
5991 breakpoints with single disabled location. */
5994 && (b->loc->next != NULL || !b->loc->enabled)))
5995 header_of_multiple = 1;
6003 if (part_of_multiple)
6006 formatted = xstrprintf ("%d.%d", b->number, loc_number);
6007 ui_out_field_string (uiout, "number", formatted);
6012 ui_out_field_int (uiout, "number", b->number);
6017 if (part_of_multiple)
6018 ui_out_field_skip (uiout, "type");
6020 ui_out_field_string (uiout, "type", bptype_string (b->type));
6024 if (part_of_multiple)
6025 ui_out_field_skip (uiout, "disp");
6027 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
6032 if (part_of_multiple)
6033 ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n");
6035 ui_out_field_fmt (uiout, "enabled", "%c",
6036 bpenables[(int) b->enable_state]);
6037 ui_out_spaces (uiout, 2);
6041 if (b->ops != NULL && b->ops->print_one != NULL)
6043 /* Although the print_one can possibly print all locations,
6044 calling it here is not likely to get any nice result. So,
6045 make sure there's just one location. */
6046 gdb_assert (b->loc == NULL || b->loc->next == NULL);
6047 b->ops->print_one (b, last_loc);
6053 internal_error (__FILE__, __LINE__,
6054 _("print_one_breakpoint: bp_none encountered\n"));
6058 case bp_hardware_watchpoint:
6059 case bp_read_watchpoint:
6060 case bp_access_watchpoint:
6062 struct watchpoint *w = (struct watchpoint *) b;
6064 /* Field 4, the address, is omitted (which makes the columns
6065 not line up too nicely with the headers, but the effect
6066 is relatively readable). */
6067 if (opts.addressprint)
6068 ui_out_field_skip (uiout, "addr");
6070 ui_out_field_string (uiout, "what", w->exp_string);
6075 case bp_hardware_breakpoint:
6079 case bp_longjmp_resume:
6080 case bp_longjmp_call_dummy:
6082 case bp_exception_resume:
6083 case bp_step_resume:
6084 case bp_hp_step_resume:
6085 case bp_watchpoint_scope:
6087 case bp_std_terminate:
6088 case bp_shlib_event:
6089 case bp_thread_event:
6090 case bp_overlay_event:
6091 case bp_longjmp_master:
6092 case bp_std_terminate_master:
6093 case bp_exception_master:
6095 case bp_fast_tracepoint:
6096 case bp_static_tracepoint:
6099 case bp_gnu_ifunc_resolver:
6100 case bp_gnu_ifunc_resolver_return:
6101 if (opts.addressprint)
6104 if (header_of_multiple)
6105 ui_out_field_string (uiout, "addr", "<MULTIPLE>");
6106 else if (b->loc == NULL || loc->shlib_disabled)
6107 ui_out_field_string (uiout, "addr", "<PENDING>");
6109 ui_out_field_core_addr (uiout, "addr",
6110 loc->gdbarch, loc->address);
6113 if (!header_of_multiple)
6114 print_breakpoint_location (b, loc);
6121 if (loc != NULL && !header_of_multiple)
6123 struct inferior *inf;
6124 VEC(int) *inf_num = NULL;
6129 if (inf->pspace == loc->pspace)
6130 VEC_safe_push (int, inf_num, inf->num);
6133 /* For backward compatibility, don't display inferiors in CLI unless
6134 there are several. Always display for MI. */
6136 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6137 && (number_of_program_spaces () > 1
6138 || number_of_inferiors () > 1)
6139 /* LOC is for existing B, it cannot be in
6140 moribund_locations and thus having NULL OWNER. */
6141 && loc->owner->type != bp_catchpoint))
6143 output_thread_groups (uiout, "thread-groups", inf_num, mi_only);
6144 VEC_free (int, inf_num);
6147 if (!part_of_multiple)
6149 if (b->thread != -1)
6151 /* FIXME: This seems to be redundant and lost here; see the
6152 "stop only in" line a little further down. */
6153 ui_out_text (uiout, " thread ");
6154 ui_out_field_int (uiout, "thread", b->thread);
6156 else if (b->task != 0)
6158 ui_out_text (uiout, " task ");
6159 ui_out_field_int (uiout, "task", b->task);
6163 ui_out_text (uiout, "\n");
6165 if (!part_of_multiple)
6166 b->ops->print_one_detail (b, uiout);
6168 if (part_of_multiple && frame_id_p (b->frame_id))
6171 ui_out_text (uiout, "\tstop only in stack frame at ");
6172 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6174 ui_out_field_core_addr (uiout, "frame",
6175 b->gdbarch, b->frame_id.stack_addr);
6176 ui_out_text (uiout, "\n");
6179 if (!part_of_multiple && b->cond_string)
6182 if (is_tracepoint (b))
6183 ui_out_text (uiout, "\ttrace only if ");
6185 ui_out_text (uiout, "\tstop only if ");
6186 ui_out_field_string (uiout, "cond", b->cond_string);
6188 /* Print whether the target is doing the breakpoint's condition
6189 evaluation. If GDB is doing the evaluation, don't print anything. */
6190 if (is_breakpoint (b)
6191 && breakpoint_condition_evaluation_mode ()
6192 == condition_evaluation_target)
6194 ui_out_text (uiout, " (");
6195 ui_out_field_string (uiout, "evaluated-by",
6196 bp_condition_evaluator (b));
6197 ui_out_text (uiout, " evals)");
6199 ui_out_text (uiout, "\n");
6202 if (!part_of_multiple && b->thread != -1)
6204 /* FIXME should make an annotation for this. */
6205 ui_out_text (uiout, "\tstop only in thread ");
6206 ui_out_field_int (uiout, "thread", b->thread);
6207 ui_out_text (uiout, "\n");
6210 if (!part_of_multiple)
6214 /* FIXME should make an annotation for this. */
6215 if (is_catchpoint (b))
6216 ui_out_text (uiout, "\tcatchpoint");
6217 else if (is_tracepoint (b))
6218 ui_out_text (uiout, "\ttracepoint");
6220 ui_out_text (uiout, "\tbreakpoint");
6221 ui_out_text (uiout, " already hit ");
6222 ui_out_field_int (uiout, "times", b->hit_count);
6223 if (b->hit_count == 1)
6224 ui_out_text (uiout, " time\n");
6226 ui_out_text (uiout, " times\n");
6230 /* Output the count also if it is zero, but only if this is mi. */
6231 if (ui_out_is_mi_like_p (uiout))
6232 ui_out_field_int (uiout, "times", b->hit_count);
6236 if (!part_of_multiple && b->ignore_count)
6239 ui_out_text (uiout, "\tignore next ");
6240 ui_out_field_int (uiout, "ignore", b->ignore_count);
6241 ui_out_text (uiout, " hits\n");
6244 /* Note that an enable count of 1 corresponds to "enable once"
6245 behavior, which is reported by the combination of enablement and
6246 disposition, so we don't need to mention it here. */
6247 if (!part_of_multiple && b->enable_count > 1)
6250 ui_out_text (uiout, "\tdisable after ");
6251 /* Tweak the wording to clarify that ignore and enable counts
6252 are distinct, and have additive effect. */
6253 if (b->ignore_count)
6254 ui_out_text (uiout, "additional ");
6256 ui_out_text (uiout, "next ");
6257 ui_out_field_int (uiout, "enable", b->enable_count);
6258 ui_out_text (uiout, " hits\n");
6261 if (!part_of_multiple && is_tracepoint (b))
6263 struct tracepoint *tp = (struct tracepoint *) b;
6265 if (tp->traceframe_usage)
6267 ui_out_text (uiout, "\ttrace buffer usage ");
6268 ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage);
6269 ui_out_text (uiout, " bytes\n");
6273 l = b->commands ? b->commands->commands : NULL;
6274 if (!part_of_multiple && l)
6276 struct cleanup *script_chain;
6279 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
6280 print_command_lines (uiout, l, 4);
6281 do_cleanups (script_chain);
6284 if (is_tracepoint (b))
6286 struct tracepoint *t = (struct tracepoint *) b;
6288 if (!part_of_multiple && t->pass_count)
6290 annotate_field (10);
6291 ui_out_text (uiout, "\tpass count ");
6292 ui_out_field_int (uiout, "pass", t->pass_count);
6293 ui_out_text (uiout, " \n");
6296 /* Don't display it when tracepoint or tracepoint location is
6298 if (!header_of_multiple && loc != NULL && !loc->shlib_disabled)
6300 annotate_field (11);
6302 if (ui_out_is_mi_like_p (uiout))
6303 ui_out_field_string (uiout, "installed",
6304 loc->inserted ? "y" : "n");
6308 ui_out_text (uiout, "\t");
6310 ui_out_text (uiout, "\tnot ");
6311 ui_out_text (uiout, "installed on target\n");
6316 if (ui_out_is_mi_like_p (uiout) && !part_of_multiple)
6318 if (is_watchpoint (b))
6320 struct watchpoint *w = (struct watchpoint *) b;
6322 ui_out_field_string (uiout, "original-location", w->exp_string);
6324 else if (b->addr_string)
6325 ui_out_field_string (uiout, "original-location", b->addr_string);
6330 print_one_breakpoint (struct breakpoint *b,
6331 struct bp_location **last_loc,
6334 struct cleanup *bkpt_chain;
6335 struct ui_out *uiout = current_uiout;
6337 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
6339 print_one_breakpoint_location (b, NULL, 0, last_loc, allflag);
6340 do_cleanups (bkpt_chain);
6342 /* If this breakpoint has custom print function,
6343 it's already printed. Otherwise, print individual
6344 locations, if any. */
6345 if (b->ops == NULL || b->ops->print_one == NULL)
6347 /* If breakpoint has a single location that is disabled, we
6348 print it as if it had several locations, since otherwise it's
6349 hard to represent "breakpoint enabled, location disabled"
6352 Note that while hardware watchpoints have several locations
6353 internally, that's not a property exposed to user. */
6355 && !is_hardware_watchpoint (b)
6356 && (b->loc->next || !b->loc->enabled))
6358 struct bp_location *loc;
6361 for (loc = b->loc; loc; loc = loc->next, ++n)
6363 struct cleanup *inner2 =
6364 make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
6365 print_one_breakpoint_location (b, loc, n, last_loc, allflag);
6366 do_cleanups (inner2);
6373 breakpoint_address_bits (struct breakpoint *b)
6375 int print_address_bits = 0;
6376 struct bp_location *loc;
6378 for (loc = b->loc; loc; loc = loc->next)
6382 /* Software watchpoints that aren't watching memory don't have
6383 an address to print. */
6384 if (b->type == bp_watchpoint && loc->watchpoint_type == -1)
6387 addr_bit = gdbarch_addr_bit (loc->gdbarch);
6388 if (addr_bit > print_address_bits)
6389 print_address_bits = addr_bit;
6392 return print_address_bits;
6395 struct captured_breakpoint_query_args
6401 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
6403 struct captured_breakpoint_query_args *args = data;
6404 struct breakpoint *b;
6405 struct bp_location *dummy_loc = NULL;
6409 if (args->bnum == b->number)
6411 print_one_breakpoint (b, &dummy_loc, 0);
6419 gdb_breakpoint_query (struct ui_out *uiout, int bnum,
6420 char **error_message)
6422 struct captured_breakpoint_query_args args;
6425 /* For the moment we don't trust print_one_breakpoint() to not throw
6427 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
6428 error_message, RETURN_MASK_ALL) < 0)
6434 /* Return true if this breakpoint was set by the user, false if it is
6435 internal or momentary. */
6438 user_breakpoint_p (struct breakpoint *b)
6440 return b->number > 0;
6443 /* Print information on user settable breakpoint (watchpoint, etc)
6444 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6445 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6446 FILTER is non-NULL, call it on each breakpoint and only include the
6447 ones for which it returns non-zero. Return the total number of
6448 breakpoints listed. */
6451 breakpoint_1 (char *args, int allflag,
6452 int (*filter) (const struct breakpoint *))
6454 struct breakpoint *b;
6455 struct bp_location *last_loc = NULL;
6456 int nr_printable_breakpoints;
6457 struct cleanup *bkpttbl_chain;
6458 struct value_print_options opts;
6459 int print_address_bits = 0;
6460 int print_type_col_width = 14;
6461 struct ui_out *uiout = current_uiout;
6463 get_user_print_options (&opts);
6465 /* Compute the number of rows in the table, as well as the size
6466 required for address fields. */
6467 nr_printable_breakpoints = 0;
6470 /* If we have a filter, only list the breakpoints it accepts. */
6471 if (filter && !filter (b))
6474 /* If we have an "args" string, it is a list of breakpoints to
6475 accept. Skip the others. */
6476 if (args != NULL && *args != '\0')
6478 if (allflag && parse_and_eval_long (args) != b->number)
6480 if (!allflag && !number_is_in_list (args, b->number))
6484 if (allflag || user_breakpoint_p (b))
6486 int addr_bit, type_len;
6488 addr_bit = breakpoint_address_bits (b);
6489 if (addr_bit > print_address_bits)
6490 print_address_bits = addr_bit;
6492 type_len = strlen (bptype_string (b->type));
6493 if (type_len > print_type_col_width)
6494 print_type_col_width = type_len;
6496 nr_printable_breakpoints++;
6500 if (opts.addressprint)
6502 = make_cleanup_ui_out_table_begin_end (uiout, 6,
6503 nr_printable_breakpoints,
6507 = make_cleanup_ui_out_table_begin_end (uiout, 5,
6508 nr_printable_breakpoints,
6511 if (nr_printable_breakpoints > 0)
6512 annotate_breakpoints_headers ();
6513 if (nr_printable_breakpoints > 0)
6515 ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */
6516 if (nr_printable_breakpoints > 0)
6518 ui_out_table_header (uiout, print_type_col_width, ui_left,
6519 "type", "Type"); /* 2 */
6520 if (nr_printable_breakpoints > 0)
6522 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
6523 if (nr_printable_breakpoints > 0)
6525 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
6526 if (opts.addressprint)
6528 if (nr_printable_breakpoints > 0)
6530 if (print_address_bits <= 32)
6531 ui_out_table_header (uiout, 10, ui_left,
6532 "addr", "Address"); /* 5 */
6534 ui_out_table_header (uiout, 18, ui_left,
6535 "addr", "Address"); /* 5 */
6537 if (nr_printable_breakpoints > 0)
6539 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
6540 ui_out_table_body (uiout);
6541 if (nr_printable_breakpoints > 0)
6542 annotate_breakpoints_table ();
6547 /* If we have a filter, only list the breakpoints it accepts. */
6548 if (filter && !filter (b))
6551 /* If we have an "args" string, it is a list of breakpoints to
6552 accept. Skip the others. */
6554 if (args != NULL && *args != '\0')
6556 if (allflag) /* maintenance info breakpoint */
6558 if (parse_and_eval_long (args) != b->number)
6561 else /* all others */
6563 if (!number_is_in_list (args, b->number))
6567 /* We only print out user settable breakpoints unless the
6569 if (allflag || user_breakpoint_p (b))
6570 print_one_breakpoint (b, &last_loc, allflag);
6573 do_cleanups (bkpttbl_chain);
6575 if (nr_printable_breakpoints == 0)
6577 /* If there's a filter, let the caller decide how to report
6581 if (args == NULL || *args == '\0')
6582 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
6584 ui_out_message (uiout, 0,
6585 "No breakpoint or watchpoint matching '%s'.\n",
6591 if (last_loc && !server_command)
6592 set_next_address (last_loc->gdbarch, last_loc->address);
6595 /* FIXME? Should this be moved up so that it is only called when
6596 there have been breakpoints? */
6597 annotate_breakpoints_table_end ();
6599 return nr_printable_breakpoints;
6602 /* Display the value of default-collect in a way that is generally
6603 compatible with the breakpoint list. */
6606 default_collect_info (void)
6608 struct ui_out *uiout = current_uiout;
6610 /* If it has no value (which is frequently the case), say nothing; a
6611 message like "No default-collect." gets in user's face when it's
6613 if (!*default_collect)
6616 /* The following phrase lines up nicely with per-tracepoint collect
6618 ui_out_text (uiout, "default collect ");
6619 ui_out_field_string (uiout, "default-collect", default_collect);
6620 ui_out_text (uiout, " \n");
6624 breakpoints_info (char *args, int from_tty)
6626 breakpoint_1 (args, 0, NULL);
6628 default_collect_info ();
6632 watchpoints_info (char *args, int from_tty)
6634 int num_printed = breakpoint_1 (args, 0, is_watchpoint);
6635 struct ui_out *uiout = current_uiout;
6637 if (num_printed == 0)
6639 if (args == NULL || *args == '\0')
6640 ui_out_message (uiout, 0, "No watchpoints.\n");
6642 ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args);
6647 maintenance_info_breakpoints (char *args, int from_tty)
6649 breakpoint_1 (args, 1, NULL);
6651 default_collect_info ();
6655 breakpoint_has_pc (struct breakpoint *b,
6656 struct program_space *pspace,
6657 CORE_ADDR pc, struct obj_section *section)
6659 struct bp_location *bl = b->loc;
6661 for (; bl; bl = bl->next)
6663 if (bl->pspace == pspace
6664 && bl->address == pc
6665 && (!overlay_debugging || bl->section == section))
6671 /* Print a message describing any user-breakpoints set at PC. This
6672 concerns with logical breakpoints, so we match program spaces, not
6676 describe_other_breakpoints (struct gdbarch *gdbarch,
6677 struct program_space *pspace, CORE_ADDR pc,
6678 struct obj_section *section, int thread)
6681 struct breakpoint *b;
6684 others += (user_breakpoint_p (b)
6685 && breakpoint_has_pc (b, pspace, pc, section));
6689 printf_filtered (_("Note: breakpoint "));
6690 else /* if (others == ???) */
6691 printf_filtered (_("Note: breakpoints "));
6693 if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section))
6696 printf_filtered ("%d", b->number);
6697 if (b->thread == -1 && thread != -1)
6698 printf_filtered (" (all threads)");
6699 else if (b->thread != -1)
6700 printf_filtered (" (thread %d)", b->thread);
6701 printf_filtered ("%s%s ",
6702 ((b->enable_state == bp_disabled
6703 || b->enable_state == bp_call_disabled)
6705 : b->enable_state == bp_permanent
6709 : ((others == 1) ? " and" : ""));
6711 printf_filtered (_("also set at pc "));
6712 fputs_filtered (paddress (gdbarch, pc), gdb_stdout);
6713 printf_filtered (".\n");
6718 /* Return true iff it is meaningful to use the address member of
6719 BPT. For some breakpoint types, the address member is irrelevant
6720 and it makes no sense to attempt to compare it to other addresses
6721 (or use it for any other purpose either).
6723 More specifically, each of the following breakpoint types will
6724 always have a zero valued address and we don't want to mark
6725 breakpoints of any of these types to be a duplicate of an actual
6726 breakpoint at address zero:
6734 breakpoint_address_is_meaningful (struct breakpoint *bpt)
6736 enum bptype type = bpt->type;
6738 return (type != bp_watchpoint && type != bp_catchpoint);
6741 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6742 true if LOC1 and LOC2 represent the same watchpoint location. */
6745 watchpoint_locations_match (struct bp_location *loc1,
6746 struct bp_location *loc2)
6748 struct watchpoint *w1 = (struct watchpoint *) loc1->owner;
6749 struct watchpoint *w2 = (struct watchpoint *) loc2->owner;
6751 /* Both of them must exist. */
6752 gdb_assert (w1 != NULL);
6753 gdb_assert (w2 != NULL);
6755 /* If the target can evaluate the condition expression in hardware,
6756 then we we need to insert both watchpoints even if they are at
6757 the same place. Otherwise the watchpoint will only trigger when
6758 the condition of whichever watchpoint was inserted evaluates to
6759 true, not giving a chance for GDB to check the condition of the
6760 other watchpoint. */
6762 && target_can_accel_watchpoint_condition (loc1->address,
6764 loc1->watchpoint_type,
6767 && target_can_accel_watchpoint_condition (loc2->address,
6769 loc2->watchpoint_type,
6773 /* Note that this checks the owner's type, not the location's. In
6774 case the target does not support read watchpoints, but does
6775 support access watchpoints, we'll have bp_read_watchpoint
6776 watchpoints with hw_access locations. Those should be considered
6777 duplicates of hw_read locations. The hw_read locations will
6778 become hw_access locations later. */
6779 return (loc1->owner->type == loc2->owner->type
6780 && loc1->pspace->aspace == loc2->pspace->aspace
6781 && loc1->address == loc2->address
6782 && loc1->length == loc2->length);
6785 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
6786 same breakpoint location. In most targets, this can only be true
6787 if ASPACE1 matches ASPACE2. On targets that have global
6788 breakpoints, the address space doesn't really matter. */
6791 breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1,
6792 struct address_space *aspace2, CORE_ADDR addr2)
6794 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6795 || aspace1 == aspace2)
6799 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6800 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6801 matches ASPACE2. On targets that have global breakpoints, the address
6802 space doesn't really matter. */
6805 breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1,
6806 int len1, struct address_space *aspace2,
6809 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6810 || aspace1 == aspace2)
6811 && addr2 >= addr1 && addr2 < addr1 + len1);
6814 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6815 a ranged breakpoint. In most targets, a match happens only if ASPACE
6816 matches the breakpoint's address space. On targets that have global
6817 breakpoints, the address space doesn't really matter. */
6820 breakpoint_location_address_match (struct bp_location *bl,
6821 struct address_space *aspace,
6824 return (breakpoint_address_match (bl->pspace->aspace, bl->address,
6827 && breakpoint_address_match_range (bl->pspace->aspace,
6828 bl->address, bl->length,
6832 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6833 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6834 true, otherwise returns false. */
6837 tracepoint_locations_match (struct bp_location *loc1,
6838 struct bp_location *loc2)
6840 if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner))
6841 /* Since tracepoint locations are never duplicated with others', tracepoint
6842 locations at the same address of different tracepoints are regarded as
6843 different locations. */
6844 return (loc1->address == loc2->address && loc1->owner == loc2->owner);
6849 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
6850 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
6851 represent the same location. */
6854 breakpoint_locations_match (struct bp_location *loc1,
6855 struct bp_location *loc2)
6857 int hw_point1, hw_point2;
6859 /* Both of them must not be in moribund_locations. */
6860 gdb_assert (loc1->owner != NULL);
6861 gdb_assert (loc2->owner != NULL);
6863 hw_point1 = is_hardware_watchpoint (loc1->owner);
6864 hw_point2 = is_hardware_watchpoint (loc2->owner);
6866 if (hw_point1 != hw_point2)
6869 return watchpoint_locations_match (loc1, loc2);
6870 else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner))
6871 return tracepoint_locations_match (loc1, loc2);
6873 /* We compare bp_location.length in order to cover ranged breakpoints. */
6874 return (breakpoint_address_match (loc1->pspace->aspace, loc1->address,
6875 loc2->pspace->aspace, loc2->address)
6876 && loc1->length == loc2->length);
6880 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
6881 int bnum, int have_bnum)
6883 /* The longest string possibly returned by hex_string_custom
6884 is 50 chars. These must be at least that big for safety. */
6888 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
6889 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
6891 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
6892 bnum, astr1, astr2);
6894 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
6897 /* Adjust a breakpoint's address to account for architectural
6898 constraints on breakpoint placement. Return the adjusted address.
6899 Note: Very few targets require this kind of adjustment. For most
6900 targets, this function is simply the identity function. */
6903 adjust_breakpoint_address (struct gdbarch *gdbarch,
6904 CORE_ADDR bpaddr, enum bptype bptype)
6906 if (!gdbarch_adjust_breakpoint_address_p (gdbarch))
6908 /* Very few targets need any kind of breakpoint adjustment. */
6911 else if (bptype == bp_watchpoint
6912 || bptype == bp_hardware_watchpoint
6913 || bptype == bp_read_watchpoint
6914 || bptype == bp_access_watchpoint
6915 || bptype == bp_catchpoint)
6917 /* Watchpoints and the various bp_catch_* eventpoints should not
6918 have their addresses modified. */
6923 CORE_ADDR adjusted_bpaddr;
6925 /* Some targets have architectural constraints on the placement
6926 of breakpoint instructions. Obtain the adjusted address. */
6927 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr);
6929 /* An adjusted breakpoint address can significantly alter
6930 a user's expectations. Print a warning if an adjustment
6932 if (adjusted_bpaddr != bpaddr)
6933 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
6935 return adjusted_bpaddr;
6940 init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops,
6941 struct breakpoint *owner)
6943 memset (loc, 0, sizeof (*loc));
6945 gdb_assert (ops != NULL);
6950 loc->cond_bytecode = NULL;
6951 loc->shlib_disabled = 0;
6954 switch (owner->type)
6960 case bp_longjmp_resume:
6961 case bp_longjmp_call_dummy:
6963 case bp_exception_resume:
6964 case bp_step_resume:
6965 case bp_hp_step_resume:
6966 case bp_watchpoint_scope:
6968 case bp_std_terminate:
6969 case bp_shlib_event:
6970 case bp_thread_event:
6971 case bp_overlay_event:
6973 case bp_longjmp_master:
6974 case bp_std_terminate_master:
6975 case bp_exception_master:
6976 case bp_gnu_ifunc_resolver:
6977 case bp_gnu_ifunc_resolver_return:
6979 loc->loc_type = bp_loc_software_breakpoint;
6980 mark_breakpoint_location_modified (loc);
6982 case bp_hardware_breakpoint:
6983 loc->loc_type = bp_loc_hardware_breakpoint;
6984 mark_breakpoint_location_modified (loc);
6986 case bp_hardware_watchpoint:
6987 case bp_read_watchpoint:
6988 case bp_access_watchpoint:
6989 loc->loc_type = bp_loc_hardware_watchpoint;
6994 case bp_fast_tracepoint:
6995 case bp_static_tracepoint:
6996 loc->loc_type = bp_loc_other;
6999 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
7005 /* Allocate a struct bp_location. */
7007 static struct bp_location *
7008 allocate_bp_location (struct breakpoint *bpt)
7010 return bpt->ops->allocate_location (bpt);
7014 free_bp_location (struct bp_location *loc)
7016 loc->ops->dtor (loc);
7020 /* Increment reference count. */
7023 incref_bp_location (struct bp_location *bl)
7028 /* Decrement reference count. If the reference count reaches 0,
7029 destroy the bp_location. Sets *BLP to NULL. */
7032 decref_bp_location (struct bp_location **blp)
7034 gdb_assert ((*blp)->refc > 0);
7036 if (--(*blp)->refc == 0)
7037 free_bp_location (*blp);
7041 /* Add breakpoint B at the end of the global breakpoint chain. */
7044 add_to_breakpoint_chain (struct breakpoint *b)
7046 struct breakpoint *b1;
7048 /* Add this breakpoint to the end of the chain so that a list of
7049 breakpoints will come out in order of increasing numbers. */
7051 b1 = breakpoint_chain;
7053 breakpoint_chain = b;
7062 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7065 init_raw_breakpoint_without_location (struct breakpoint *b,
7066 struct gdbarch *gdbarch,
7068 const struct breakpoint_ops *ops)
7070 memset (b, 0, sizeof (*b));
7072 gdb_assert (ops != NULL);
7076 b->gdbarch = gdbarch;
7077 b->language = current_language->la_language;
7078 b->input_radix = input_radix;
7080 b->enable_state = bp_enabled;
7083 b->ignore_count = 0;
7085 b->frame_id = null_frame_id;
7086 b->condition_not_parsed = 0;
7087 b->py_bp_object = NULL;
7088 b->related_breakpoint = b;
7091 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7092 that has type BPTYPE and has no locations as yet. */
7094 static struct breakpoint *
7095 set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
7097 const struct breakpoint_ops *ops)
7099 struct breakpoint *b = XNEW (struct breakpoint);
7101 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
7102 add_to_breakpoint_chain (b);
7106 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7107 resolutions should be made as the user specified the location explicitly
7111 set_breakpoint_location_function (struct bp_location *loc, int explicit_loc)
7113 gdb_assert (loc->owner != NULL);
7115 if (loc->owner->type == bp_breakpoint
7116 || loc->owner->type == bp_hardware_breakpoint
7117 || is_tracepoint (loc->owner))
7120 const char *function_name;
7121 CORE_ADDR func_addr;
7123 find_pc_partial_function_gnu_ifunc (loc->address, &function_name,
7124 &func_addr, NULL, &is_gnu_ifunc);
7126 if (is_gnu_ifunc && !explicit_loc)
7128 struct breakpoint *b = loc->owner;
7130 gdb_assert (loc->pspace == current_program_space);
7131 if (gnu_ifunc_resolve_name (function_name,
7132 &loc->requested_address))
7134 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7135 loc->address = adjust_breakpoint_address (loc->gdbarch,
7136 loc->requested_address,
7139 else if (b->type == bp_breakpoint && b->loc == loc
7140 && loc->next == NULL && b->related_breakpoint == b)
7142 /* Create only the whole new breakpoint of this type but do not
7143 mess more complicated breakpoints with multiple locations. */
7144 b->type = bp_gnu_ifunc_resolver;
7145 /* Remember the resolver's address for use by the return
7147 loc->related_address = func_addr;
7152 loc->function_name = xstrdup (function_name);
7156 /* Attempt to determine architecture of location identified by SAL. */
7158 get_sal_arch (struct symtab_and_line sal)
7161 return get_objfile_arch (sal.section->objfile);
7163 return get_objfile_arch (sal.symtab->objfile);
7168 /* Low level routine for partially initializing a breakpoint of type
7169 BPTYPE. The newly created breakpoint's address, section, source
7170 file name, and line number are provided by SAL.
7172 It is expected that the caller will complete the initialization of
7173 the newly created breakpoint struct as well as output any status
7174 information regarding the creation of a new breakpoint. */
7177 init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch,
7178 struct symtab_and_line sal, enum bptype bptype,
7179 const struct breakpoint_ops *ops)
7181 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
7183 add_location_to_breakpoint (b, &sal);
7185 if (bptype != bp_catchpoint)
7186 gdb_assert (sal.pspace != NULL);
7188 /* Store the program space that was used to set the breakpoint,
7189 except for ordinary breakpoints, which are independent of the
7191 if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint)
7192 b->pspace = sal.pspace;
7195 /* set_raw_breakpoint is a low level routine for allocating and
7196 partially initializing a breakpoint of type BPTYPE. The newly
7197 created breakpoint's address, section, source file name, and line
7198 number are provided by SAL. The newly created and partially
7199 initialized breakpoint is added to the breakpoint chain and
7200 is also returned as the value of this function.
7202 It is expected that the caller will complete the initialization of
7203 the newly created breakpoint struct as well as output any status
7204 information regarding the creation of a new breakpoint. In
7205 particular, set_raw_breakpoint does NOT set the breakpoint
7206 number! Care should be taken to not allow an error to occur
7207 prior to completing the initialization of the breakpoint. If this
7208 should happen, a bogus breakpoint will be left on the chain. */
7211 set_raw_breakpoint (struct gdbarch *gdbarch,
7212 struct symtab_and_line sal, enum bptype bptype,
7213 const struct breakpoint_ops *ops)
7215 struct breakpoint *b = XNEW (struct breakpoint);
7217 init_raw_breakpoint (b, gdbarch, sal, bptype, ops);
7218 add_to_breakpoint_chain (b);
7223 /* Note that the breakpoint object B describes a permanent breakpoint
7224 instruction, hard-wired into the inferior's code. */
7226 make_breakpoint_permanent (struct breakpoint *b)
7228 struct bp_location *bl;
7230 b->enable_state = bp_permanent;
7232 /* By definition, permanent breakpoints are already present in the
7233 code. Mark all locations as inserted. For now,
7234 make_breakpoint_permanent is called in just one place, so it's
7235 hard to say if it's reasonable to have permanent breakpoint with
7236 multiple locations or not, but it's easy to implement. */
7237 for (bl = b->loc; bl; bl = bl->next)
7241 /* Call this routine when stepping and nexting to enable a breakpoint
7242 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7243 initiated the operation. */
7246 set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame)
7248 struct breakpoint *b, *b_tmp;
7249 int thread = tp->num;
7251 /* To avoid having to rescan all objfile symbols at every step,
7252 we maintain a list of continually-inserted but always disabled
7253 longjmp "master" breakpoints. Here, we simply create momentary
7254 clones of those and enable them for the requested thread. */
7255 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7256 if (b->pspace == current_program_space
7257 && (b->type == bp_longjmp_master
7258 || b->type == bp_exception_master))
7260 enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception;
7261 struct breakpoint *clone;
7263 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7264 after their removal. */
7265 clone = momentary_breakpoint_from_master (b, type,
7266 &longjmp_breakpoint_ops);
7267 clone->thread = thread;
7270 tp->initiating_frame = frame;
7273 /* Delete all longjmp breakpoints from THREAD. */
7275 delete_longjmp_breakpoint (int thread)
7277 struct breakpoint *b, *b_tmp;
7279 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7280 if (b->type == bp_longjmp || b->type == bp_exception)
7282 if (b->thread == thread)
7283 delete_breakpoint (b);
7288 delete_longjmp_breakpoint_at_next_stop (int thread)
7290 struct breakpoint *b, *b_tmp;
7292 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7293 if (b->type == bp_longjmp || b->type == bp_exception)
7295 if (b->thread == thread)
7296 b->disposition = disp_del_at_next_stop;
7300 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7301 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7302 pointer to any of them. Return NULL if this system cannot place longjmp
7306 set_longjmp_breakpoint_for_call_dummy (void)
7308 struct breakpoint *b, *retval = NULL;
7311 if (b->pspace == current_program_space && b->type == bp_longjmp_master)
7313 struct breakpoint *new_b;
7315 new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy,
7316 &momentary_breakpoint_ops);
7317 new_b->thread = pid_to_thread_id (inferior_ptid);
7319 /* Link NEW_B into the chain of RETVAL breakpoints. */
7321 gdb_assert (new_b->related_breakpoint == new_b);
7324 new_b->related_breakpoint = retval;
7325 while (retval->related_breakpoint != new_b->related_breakpoint)
7326 retval = retval->related_breakpoint;
7327 retval->related_breakpoint = new_b;
7333 /* Verify all existing dummy frames and their associated breakpoints for
7334 THREAD. Remove those which can no longer be found in the current frame
7337 You should call this function only at places where it is safe to currently
7338 unwind the whole stack. Failed stack unwind would discard live dummy
7342 check_longjmp_breakpoint_for_call_dummy (int thread)
7344 struct breakpoint *b, *b_tmp;
7346 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7347 if (b->type == bp_longjmp_call_dummy && b->thread == thread)
7349 struct breakpoint *dummy_b = b->related_breakpoint;
7351 while (dummy_b != b && dummy_b->type != bp_call_dummy)
7352 dummy_b = dummy_b->related_breakpoint;
7353 if (dummy_b->type != bp_call_dummy
7354 || frame_find_by_id (dummy_b->frame_id) != NULL)
7357 dummy_frame_discard (dummy_b->frame_id);
7359 while (b->related_breakpoint != b)
7361 if (b_tmp == b->related_breakpoint)
7362 b_tmp = b->related_breakpoint->next;
7363 delete_breakpoint (b->related_breakpoint);
7365 delete_breakpoint (b);
7370 enable_overlay_breakpoints (void)
7372 struct breakpoint *b;
7375 if (b->type == bp_overlay_event)
7377 b->enable_state = bp_enabled;
7378 update_global_location_list (1);
7379 overlay_events_enabled = 1;
7384 disable_overlay_breakpoints (void)
7386 struct breakpoint *b;
7389 if (b->type == bp_overlay_event)
7391 b->enable_state = bp_disabled;
7392 update_global_location_list (0);
7393 overlay_events_enabled = 0;
7397 /* Set an active std::terminate breakpoint for each std::terminate
7398 master breakpoint. */
7400 set_std_terminate_breakpoint (void)
7402 struct breakpoint *b, *b_tmp;
7404 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7405 if (b->pspace == current_program_space
7406 && b->type == bp_std_terminate_master)
7408 momentary_breakpoint_from_master (b, bp_std_terminate,
7409 &momentary_breakpoint_ops);
7413 /* Delete all the std::terminate breakpoints. */
7415 delete_std_terminate_breakpoint (void)
7417 struct breakpoint *b, *b_tmp;
7419 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7420 if (b->type == bp_std_terminate)
7421 delete_breakpoint (b);
7425 create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7427 struct breakpoint *b;
7429 b = create_internal_breakpoint (gdbarch, address, bp_thread_event,
7430 &internal_breakpoint_ops);
7432 b->enable_state = bp_enabled;
7433 /* addr_string has to be used or breakpoint_re_set will delete me. */
7435 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
7437 update_global_location_list_nothrow (1);
7443 remove_thread_event_breakpoints (void)
7445 struct breakpoint *b, *b_tmp;
7447 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7448 if (b->type == bp_thread_event
7449 && b->loc->pspace == current_program_space)
7450 delete_breakpoint (b);
7453 struct lang_and_radix
7459 /* Create a breakpoint for JIT code registration and unregistration. */
7462 create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7464 struct breakpoint *b;
7466 b = create_internal_breakpoint (gdbarch, address, bp_jit_event,
7467 &internal_breakpoint_ops);
7468 update_global_location_list_nothrow (1);
7472 /* Remove JIT code registration and unregistration breakpoint(s). */
7475 remove_jit_event_breakpoints (void)
7477 struct breakpoint *b, *b_tmp;
7479 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7480 if (b->type == bp_jit_event
7481 && b->loc->pspace == current_program_space)
7482 delete_breakpoint (b);
7486 remove_solib_event_breakpoints (void)
7488 struct breakpoint *b, *b_tmp;
7490 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7491 if (b->type == bp_shlib_event
7492 && b->loc->pspace == current_program_space)
7493 delete_breakpoint (b);
7497 create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7499 struct breakpoint *b;
7501 b = create_internal_breakpoint (gdbarch, address, bp_shlib_event,
7502 &internal_breakpoint_ops);
7503 update_global_location_list_nothrow (1);
7507 /* Disable any breakpoints that are on code in shared libraries. Only
7508 apply to enabled breakpoints, disabled ones can just stay disabled. */
7511 disable_breakpoints_in_shlibs (void)
7513 struct bp_location *loc, **locp_tmp;
7515 ALL_BP_LOCATIONS (loc, locp_tmp)
7517 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7518 struct breakpoint *b = loc->owner;
7520 /* We apply the check to all breakpoints, including disabled for
7521 those with loc->duplicate set. This is so that when breakpoint
7522 becomes enabled, or the duplicate is removed, gdb will try to
7523 insert all breakpoints. If we don't set shlib_disabled here,
7524 we'll try to insert those breakpoints and fail. */
7525 if (((b->type == bp_breakpoint)
7526 || (b->type == bp_jit_event)
7527 || (b->type == bp_hardware_breakpoint)
7528 || (is_tracepoint (b)))
7529 && loc->pspace == current_program_space
7530 && !loc->shlib_disabled
7531 && solib_name_from_address (loc->pspace, loc->address)
7534 loc->shlib_disabled = 1;
7539 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7540 notification of unloaded_shlib. Only apply to enabled breakpoints,
7541 disabled ones can just stay disabled. */
7544 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
7546 struct bp_location *loc, **locp_tmp;
7547 int disabled_shlib_breaks = 0;
7549 /* SunOS a.out shared libraries are always mapped, so do not
7550 disable breakpoints; they will only be reported as unloaded
7551 through clear_solib when GDB discards its shared library
7552 list. See clear_solib for more information. */
7553 if (exec_bfd != NULL
7554 && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour)
7557 ALL_BP_LOCATIONS (loc, locp_tmp)
7559 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7560 struct breakpoint *b = loc->owner;
7562 if (solib->pspace == loc->pspace
7563 && !loc->shlib_disabled
7564 && (((b->type == bp_breakpoint
7565 || b->type == bp_jit_event
7566 || b->type == bp_hardware_breakpoint)
7567 && (loc->loc_type == bp_loc_hardware_breakpoint
7568 || loc->loc_type == bp_loc_software_breakpoint))
7569 || is_tracepoint (b))
7570 && solib_contains_address_p (solib, loc->address))
7572 loc->shlib_disabled = 1;
7573 /* At this point, we cannot rely on remove_breakpoint
7574 succeeding so we must mark the breakpoint as not inserted
7575 to prevent future errors occurring in remove_breakpoints. */
7578 /* This may cause duplicate notifications for the same breakpoint. */
7579 observer_notify_breakpoint_modified (b);
7581 if (!disabled_shlib_breaks)
7583 target_terminal_ours_for_output ();
7584 warning (_("Temporarily disabling breakpoints "
7585 "for unloaded shared library \"%s\""),
7588 disabled_shlib_breaks = 1;
7593 /* Disable any breakpoints and tracepoints in OBJFILE upon
7594 notification of free_objfile. Only apply to enabled breakpoints,
7595 disabled ones can just stay disabled. */
7598 disable_breakpoints_in_freed_objfile (struct objfile *objfile)
7600 struct breakpoint *b;
7602 if (objfile == NULL)
7605 /* If the file is a shared library not loaded by the user then
7606 solib_unloaded was notified and disable_breakpoints_in_unloaded_shlib
7607 was called. In that case there is no need to take action again. */
7608 if ((objfile->flags & OBJF_SHARED) && !(objfile->flags & OBJF_USERLOADED))
7613 struct bp_location *loc;
7614 int bp_modified = 0;
7616 if (!is_breakpoint (b) && !is_tracepoint (b))
7619 for (loc = b->loc; loc != NULL; loc = loc->next)
7621 CORE_ADDR loc_addr = loc->address;
7623 if (loc->loc_type != bp_loc_hardware_breakpoint
7624 && loc->loc_type != bp_loc_software_breakpoint)
7627 if (loc->shlib_disabled != 0)
7630 if (objfile->pspace != loc->pspace)
7633 if (loc->loc_type != bp_loc_hardware_breakpoint
7634 && loc->loc_type != bp_loc_software_breakpoint)
7637 if (is_addr_in_objfile (loc_addr, objfile))
7639 loc->shlib_disabled = 1;
7642 mark_breakpoint_location_modified (loc);
7649 observer_notify_breakpoint_modified (b);
7653 /* FORK & VFORK catchpoints. */
7655 /* An instance of this type is used to represent a fork or vfork
7656 catchpoint. It includes a "struct breakpoint" as a kind of base
7657 class; users downcast to "struct breakpoint *" when needed. A
7658 breakpoint is really of this type iff its ops pointer points to
7659 CATCH_FORK_BREAKPOINT_OPS. */
7661 struct fork_catchpoint
7663 /* The base class. */
7664 struct breakpoint base;
7666 /* Process id of a child process whose forking triggered this
7667 catchpoint. This field is only valid immediately after this
7668 catchpoint has triggered. */
7669 ptid_t forked_inferior_pid;
7672 /* Implement the "insert" breakpoint_ops method for fork
7676 insert_catch_fork (struct bp_location *bl)
7678 return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid));
7681 /* Implement the "remove" breakpoint_ops method for fork
7685 remove_catch_fork (struct bp_location *bl)
7687 return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid));
7690 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7694 breakpoint_hit_catch_fork (const struct bp_location *bl,
7695 struct address_space *aspace, CORE_ADDR bp_addr,
7696 const struct target_waitstatus *ws)
7698 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
7700 if (ws->kind != TARGET_WAITKIND_FORKED)
7703 c->forked_inferior_pid = ws->value.related_pid;
7707 /* Implement the "print_it" breakpoint_ops method for fork
7710 static enum print_stop_action
7711 print_it_catch_fork (bpstat bs)
7713 struct ui_out *uiout = current_uiout;
7714 struct breakpoint *b = bs->breakpoint_at;
7715 struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at;
7717 annotate_catchpoint (b->number);
7718 if (b->disposition == disp_del)
7719 ui_out_text (uiout, "\nTemporary catchpoint ");
7721 ui_out_text (uiout, "\nCatchpoint ");
7722 if (ui_out_is_mi_like_p (uiout))
7724 ui_out_field_string (uiout, "reason",
7725 async_reason_lookup (EXEC_ASYNC_FORK));
7726 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7728 ui_out_field_int (uiout, "bkptno", b->number);
7729 ui_out_text (uiout, " (forked process ");
7730 ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid));
7731 ui_out_text (uiout, "), ");
7732 return PRINT_SRC_AND_LOC;
7735 /* Implement the "print_one" breakpoint_ops method for fork
7739 print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc)
7741 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
7742 struct value_print_options opts;
7743 struct ui_out *uiout = current_uiout;
7745 get_user_print_options (&opts);
7747 /* Field 4, the address, is omitted (which makes the columns not
7748 line up too nicely with the headers, but the effect is relatively
7750 if (opts.addressprint)
7751 ui_out_field_skip (uiout, "addr");
7753 ui_out_text (uiout, "fork");
7754 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
7756 ui_out_text (uiout, ", process ");
7757 ui_out_field_int (uiout, "what",
7758 ptid_get_pid (c->forked_inferior_pid));
7759 ui_out_spaces (uiout, 1);
7762 if (ui_out_is_mi_like_p (uiout))
7763 ui_out_field_string (uiout, "catch-type", "fork");
7766 /* Implement the "print_mention" breakpoint_ops method for fork
7770 print_mention_catch_fork (struct breakpoint *b)
7772 printf_filtered (_("Catchpoint %d (fork)"), b->number);
7775 /* Implement the "print_recreate" breakpoint_ops method for fork
7779 print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp)
7781 fprintf_unfiltered (fp, "catch fork");
7782 print_recreate_thread (b, fp);
7785 /* The breakpoint_ops structure to be used in fork catchpoints. */
7787 static struct breakpoint_ops catch_fork_breakpoint_ops;
7789 /* Implement the "insert" breakpoint_ops method for vfork
7793 insert_catch_vfork (struct bp_location *bl)
7795 return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid));
7798 /* Implement the "remove" breakpoint_ops method for vfork
7802 remove_catch_vfork (struct bp_location *bl)
7804 return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid));
7807 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
7811 breakpoint_hit_catch_vfork (const struct bp_location *bl,
7812 struct address_space *aspace, CORE_ADDR bp_addr,
7813 const struct target_waitstatus *ws)
7815 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
7817 if (ws->kind != TARGET_WAITKIND_VFORKED)
7820 c->forked_inferior_pid = ws->value.related_pid;
7824 /* Implement the "print_it" breakpoint_ops method for vfork
7827 static enum print_stop_action
7828 print_it_catch_vfork (bpstat bs)
7830 struct ui_out *uiout = current_uiout;
7831 struct breakpoint *b = bs->breakpoint_at;
7832 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
7834 annotate_catchpoint (b->number);
7835 if (b->disposition == disp_del)
7836 ui_out_text (uiout, "\nTemporary catchpoint ");
7838 ui_out_text (uiout, "\nCatchpoint ");
7839 if (ui_out_is_mi_like_p (uiout))
7841 ui_out_field_string (uiout, "reason",
7842 async_reason_lookup (EXEC_ASYNC_VFORK));
7843 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7845 ui_out_field_int (uiout, "bkptno", b->number);
7846 ui_out_text (uiout, " (vforked process ");
7847 ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid));
7848 ui_out_text (uiout, "), ");
7849 return PRINT_SRC_AND_LOC;
7852 /* Implement the "print_one" breakpoint_ops method for vfork
7856 print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc)
7858 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
7859 struct value_print_options opts;
7860 struct ui_out *uiout = current_uiout;
7862 get_user_print_options (&opts);
7863 /* Field 4, the address, is omitted (which makes the columns not
7864 line up too nicely with the headers, but the effect is relatively
7866 if (opts.addressprint)
7867 ui_out_field_skip (uiout, "addr");
7869 ui_out_text (uiout, "vfork");
7870 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
7872 ui_out_text (uiout, ", process ");
7873 ui_out_field_int (uiout, "what",
7874 ptid_get_pid (c->forked_inferior_pid));
7875 ui_out_spaces (uiout, 1);
7878 if (ui_out_is_mi_like_p (uiout))
7879 ui_out_field_string (uiout, "catch-type", "vfork");
7882 /* Implement the "print_mention" breakpoint_ops method for vfork
7886 print_mention_catch_vfork (struct breakpoint *b)
7888 printf_filtered (_("Catchpoint %d (vfork)"), b->number);
7891 /* Implement the "print_recreate" breakpoint_ops method for vfork
7895 print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp)
7897 fprintf_unfiltered (fp, "catch vfork");
7898 print_recreate_thread (b, fp);
7901 /* The breakpoint_ops structure to be used in vfork catchpoints. */
7903 static struct breakpoint_ops catch_vfork_breakpoint_ops;
7905 /* An instance of this type is used to represent an solib catchpoint.
7906 It includes a "struct breakpoint" as a kind of base class; users
7907 downcast to "struct breakpoint *" when needed. A breakpoint is
7908 really of this type iff its ops pointer points to
7909 CATCH_SOLIB_BREAKPOINT_OPS. */
7911 struct solib_catchpoint
7913 /* The base class. */
7914 struct breakpoint base;
7916 /* True for "catch load", false for "catch unload". */
7917 unsigned char is_load;
7919 /* Regular expression to match, if any. COMPILED is only valid when
7920 REGEX is non-NULL. */
7926 dtor_catch_solib (struct breakpoint *b)
7928 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
7931 regfree (&self->compiled);
7932 xfree (self->regex);
7934 base_breakpoint_ops.dtor (b);
7938 insert_catch_solib (struct bp_location *ignore)
7944 remove_catch_solib (struct bp_location *ignore)
7950 breakpoint_hit_catch_solib (const struct bp_location *bl,
7951 struct address_space *aspace,
7953 const struct target_waitstatus *ws)
7955 struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner;
7956 struct breakpoint *other;
7958 if (ws->kind == TARGET_WAITKIND_LOADED)
7961 ALL_BREAKPOINTS (other)
7963 struct bp_location *other_bl;
7965 if (other == bl->owner)
7968 if (other->type != bp_shlib_event)
7971 if (self->base.pspace != NULL && other->pspace != self->base.pspace)
7974 for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next)
7976 if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws))
7985 check_status_catch_solib (struct bpstats *bs)
7987 struct solib_catchpoint *self
7988 = (struct solib_catchpoint *) bs->breakpoint_at;
7993 struct so_list *iter;
7996 VEC_iterate (so_list_ptr, current_program_space->added_solibs,
8001 || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0)
8010 VEC_iterate (char_ptr, current_program_space->deleted_solibs,
8015 || regexec (&self->compiled, iter, 0, NULL, 0) == 0)
8021 bs->print_it = print_it_noop;
8024 static enum print_stop_action
8025 print_it_catch_solib (bpstat bs)
8027 struct breakpoint *b = bs->breakpoint_at;
8028 struct ui_out *uiout = current_uiout;
8030 annotate_catchpoint (b->number);
8031 if (b->disposition == disp_del)
8032 ui_out_text (uiout, "\nTemporary catchpoint ");
8034 ui_out_text (uiout, "\nCatchpoint ");
8035 ui_out_field_int (uiout, "bkptno", b->number);
8036 ui_out_text (uiout, "\n");
8037 if (ui_out_is_mi_like_p (uiout))
8038 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8039 print_solib_event (1);
8040 return PRINT_SRC_AND_LOC;
8044 print_one_catch_solib (struct breakpoint *b, struct bp_location **locs)
8046 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8047 struct value_print_options opts;
8048 struct ui_out *uiout = current_uiout;
8051 get_user_print_options (&opts);
8052 /* Field 4, the address, is omitted (which makes the columns not
8053 line up too nicely with the headers, but the effect is relatively
8055 if (opts.addressprint)
8058 ui_out_field_skip (uiout, "addr");
8065 msg = xstrprintf (_("load of library matching %s"), self->regex);
8067 msg = xstrdup (_("load of library"));
8072 msg = xstrprintf (_("unload of library matching %s"), self->regex);
8074 msg = xstrdup (_("unload of library"));
8076 ui_out_field_string (uiout, "what", msg);
8079 if (ui_out_is_mi_like_p (uiout))
8080 ui_out_field_string (uiout, "catch-type",
8081 self->is_load ? "load" : "unload");
8085 print_mention_catch_solib (struct breakpoint *b)
8087 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8089 printf_filtered (_("Catchpoint %d (%s)"), b->number,
8090 self->is_load ? "load" : "unload");
8094 print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp)
8096 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8098 fprintf_unfiltered (fp, "%s %s",
8099 b->disposition == disp_del ? "tcatch" : "catch",
8100 self->is_load ? "load" : "unload");
8102 fprintf_unfiltered (fp, " %s", self->regex);
8103 fprintf_unfiltered (fp, "\n");
8106 static struct breakpoint_ops catch_solib_breakpoint_ops;
8108 /* Shared helper function (MI and CLI) for creating and installing
8109 a shared object event catchpoint. If IS_LOAD is non-zero then
8110 the events to be caught are load events, otherwise they are
8111 unload events. If IS_TEMP is non-zero the catchpoint is a
8112 temporary one. If ENABLED is non-zero the catchpoint is
8113 created in an enabled state. */
8116 add_solib_catchpoint (char *arg, int is_load, int is_temp, int enabled)
8118 struct solib_catchpoint *c;
8119 struct gdbarch *gdbarch = get_current_arch ();
8120 struct cleanup *cleanup;
8124 arg = skip_spaces (arg);
8126 c = XCNEW (struct solib_catchpoint);
8127 cleanup = make_cleanup (xfree, c);
8133 errcode = regcomp (&c->compiled, arg, REG_NOSUB);
8136 char *err = get_regcomp_error (errcode, &c->compiled);
8138 make_cleanup (xfree, err);
8139 error (_("Invalid regexp (%s): %s"), err, arg);
8141 c->regex = xstrdup (arg);
8144 c->is_load = is_load;
8145 init_catchpoint (&c->base, gdbarch, is_temp, NULL,
8146 &catch_solib_breakpoint_ops);
8148 c->base.enable_state = enabled ? bp_enabled : bp_disabled;
8150 discard_cleanups (cleanup);
8151 install_breakpoint (0, &c->base, 1);
8154 /* A helper function that does all the work for "catch load" and
8158 catch_load_or_unload (char *arg, int from_tty, int is_load,
8159 struct cmd_list_element *command)
8162 const int enabled = 1;
8164 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
8166 add_solib_catchpoint (arg, is_load, tempflag, enabled);
8170 catch_load_command_1 (char *arg, int from_tty,
8171 struct cmd_list_element *command)
8173 catch_load_or_unload (arg, from_tty, 1, command);
8177 catch_unload_command_1 (char *arg, int from_tty,
8178 struct cmd_list_element *command)
8180 catch_load_or_unload (arg, from_tty, 0, command);
8183 /* An instance of this type is used to represent a syscall catchpoint.
8184 It includes a "struct breakpoint" as a kind of base class; users
8185 downcast to "struct breakpoint *" when needed. A breakpoint is
8186 really of this type iff its ops pointer points to
8187 CATCH_SYSCALL_BREAKPOINT_OPS. */
8189 struct syscall_catchpoint
8191 /* The base class. */
8192 struct breakpoint base;
8194 /* Syscall numbers used for the 'catch syscall' feature. If no
8195 syscall has been specified for filtering, its value is NULL.
8196 Otherwise, it holds a list of all syscalls to be caught. The
8197 list elements are allocated with xmalloc. */
8198 VEC(int) *syscalls_to_be_caught;
8201 /* Implement the "dtor" breakpoint_ops method for syscall
8205 dtor_catch_syscall (struct breakpoint *b)
8207 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
8209 VEC_free (int, c->syscalls_to_be_caught);
8211 base_breakpoint_ops.dtor (b);
8214 static const struct inferior_data *catch_syscall_inferior_data = NULL;
8216 struct catch_syscall_inferior_data
8218 /* We keep a count of the number of times the user has requested a
8219 particular syscall to be tracked, and pass this information to the
8220 target. This lets capable targets implement filtering directly. */
8222 /* Number of times that "any" syscall is requested. */
8223 int any_syscall_count;
8225 /* Count of each system call. */
8226 VEC(int) *syscalls_counts;
8228 /* This counts all syscall catch requests, so we can readily determine
8229 if any catching is necessary. */
8230 int total_syscalls_count;
8233 static struct catch_syscall_inferior_data*
8234 get_catch_syscall_inferior_data (struct inferior *inf)
8236 struct catch_syscall_inferior_data *inf_data;
8238 inf_data = inferior_data (inf, catch_syscall_inferior_data);
8239 if (inf_data == NULL)
8241 inf_data = XCNEW (struct catch_syscall_inferior_data);
8242 set_inferior_data (inf, catch_syscall_inferior_data, inf_data);
8249 catch_syscall_inferior_data_cleanup (struct inferior *inf, void *arg)
8255 /* Implement the "insert" breakpoint_ops method for syscall
8259 insert_catch_syscall (struct bp_location *bl)
8261 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner;
8262 struct inferior *inf = current_inferior ();
8263 struct catch_syscall_inferior_data *inf_data
8264 = get_catch_syscall_inferior_data (inf);
8266 ++inf_data->total_syscalls_count;
8267 if (!c->syscalls_to_be_caught)
8268 ++inf_data->any_syscall_count;
8274 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8279 if (iter >= VEC_length (int, inf_data->syscalls_counts))
8281 int old_size = VEC_length (int, inf_data->syscalls_counts);
8282 uintptr_t vec_addr_offset
8283 = old_size * ((uintptr_t) sizeof (int));
8285 VEC_safe_grow (int, inf_data->syscalls_counts, iter + 1);
8286 vec_addr = ((uintptr_t) VEC_address (int,
8287 inf_data->syscalls_counts)
8289 memset ((void *) vec_addr, 0,
8290 (iter + 1 - old_size) * sizeof (int));
8292 elem = VEC_index (int, inf_data->syscalls_counts, iter);
8293 VEC_replace (int, inf_data->syscalls_counts, iter, ++elem);
8297 return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid),
8298 inf_data->total_syscalls_count != 0,
8299 inf_data->any_syscall_count,
8301 inf_data->syscalls_counts),
8303 inf_data->syscalls_counts));
8306 /* Implement the "remove" breakpoint_ops method for syscall
8310 remove_catch_syscall (struct bp_location *bl)
8312 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner;
8313 struct inferior *inf = current_inferior ();
8314 struct catch_syscall_inferior_data *inf_data
8315 = get_catch_syscall_inferior_data (inf);
8317 --inf_data->total_syscalls_count;
8318 if (!c->syscalls_to_be_caught)
8319 --inf_data->any_syscall_count;
8325 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8329 if (iter >= VEC_length (int, inf_data->syscalls_counts))
8330 /* Shouldn't happen. */
8332 elem = VEC_index (int, inf_data->syscalls_counts, iter);
8333 VEC_replace (int, inf_data->syscalls_counts, iter, --elem);
8337 return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid),
8338 inf_data->total_syscalls_count != 0,
8339 inf_data->any_syscall_count,
8341 inf_data->syscalls_counts),
8343 inf_data->syscalls_counts));
8346 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
8350 breakpoint_hit_catch_syscall (const struct bp_location *bl,
8351 struct address_space *aspace, CORE_ADDR bp_addr,
8352 const struct target_waitstatus *ws)
8354 /* We must check if we are catching specific syscalls in this
8355 breakpoint. If we are, then we must guarantee that the called
8356 syscall is the same syscall we are catching. */
8357 int syscall_number = 0;
8358 const struct syscall_catchpoint *c
8359 = (const struct syscall_catchpoint *) bl->owner;
8361 if (ws->kind != TARGET_WAITKIND_SYSCALL_ENTRY
8362 && ws->kind != TARGET_WAITKIND_SYSCALL_RETURN)
8365 syscall_number = ws->value.syscall_number;
8367 /* Now, checking if the syscall is the same. */
8368 if (c->syscalls_to_be_caught)
8373 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8375 if (syscall_number == iter)
8384 /* Implement the "print_it" breakpoint_ops method for syscall
8387 static enum print_stop_action
8388 print_it_catch_syscall (bpstat bs)
8390 struct ui_out *uiout = current_uiout;
8391 struct breakpoint *b = bs->breakpoint_at;
8392 /* These are needed because we want to know in which state a
8393 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
8394 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
8395 must print "called syscall" or "returned from syscall". */
8397 struct target_waitstatus last;
8400 get_last_target_status (&ptid, &last);
8402 get_syscall_by_number (last.value.syscall_number, &s);
8404 annotate_catchpoint (b->number);
8406 if (b->disposition == disp_del)
8407 ui_out_text (uiout, "\nTemporary catchpoint ");
8409 ui_out_text (uiout, "\nCatchpoint ");
8410 if (ui_out_is_mi_like_p (uiout))
8412 ui_out_field_string (uiout, "reason",
8413 async_reason_lookup (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY
8414 ? EXEC_ASYNC_SYSCALL_ENTRY
8415 : EXEC_ASYNC_SYSCALL_RETURN));
8416 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8418 ui_out_field_int (uiout, "bkptno", b->number);
8420 if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY)
8421 ui_out_text (uiout, " (call to syscall ");
8423 ui_out_text (uiout, " (returned from syscall ");
8425 if (s.name == NULL || ui_out_is_mi_like_p (uiout))
8426 ui_out_field_int (uiout, "syscall-number", last.value.syscall_number);
8428 ui_out_field_string (uiout, "syscall-name", s.name);
8430 ui_out_text (uiout, "), ");
8432 return PRINT_SRC_AND_LOC;
8435 /* Implement the "print_one" breakpoint_ops method for syscall
8439 print_one_catch_syscall (struct breakpoint *b,
8440 struct bp_location **last_loc)
8442 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
8443 struct value_print_options opts;
8444 struct ui_out *uiout = current_uiout;
8446 get_user_print_options (&opts);
8447 /* Field 4, the address, is omitted (which makes the columns not
8448 line up too nicely with the headers, but the effect is relatively
8450 if (opts.addressprint)
8451 ui_out_field_skip (uiout, "addr");
8454 if (c->syscalls_to_be_caught
8455 && VEC_length (int, c->syscalls_to_be_caught) > 1)
8456 ui_out_text (uiout, "syscalls \"");
8458 ui_out_text (uiout, "syscall \"");
8460 if (c->syscalls_to_be_caught)
8463 char *text = xstrprintf ("%s", "");
8466 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8471 get_syscall_by_number (iter, &s);
8474 text = xstrprintf ("%s%s, ", text, s.name);
8476 text = xstrprintf ("%s%d, ", text, iter);
8478 /* We have to xfree the last 'text' (now stored at 'x')
8479 because xstrprintf dynamically allocates new space for it
8483 /* Remove the last comma. */
8484 text[strlen (text) - 2] = '\0';
8485 ui_out_field_string (uiout, "what", text);
8488 ui_out_field_string (uiout, "what", "<any syscall>");
8489 ui_out_text (uiout, "\" ");
8491 if (ui_out_is_mi_like_p (uiout))
8492 ui_out_field_string (uiout, "catch-type", "syscall");
8495 /* Implement the "print_mention" breakpoint_ops method for syscall
8499 print_mention_catch_syscall (struct breakpoint *b)
8501 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
8503 if (c->syscalls_to_be_caught)
8507 if (VEC_length (int, c->syscalls_to_be_caught) > 1)
8508 printf_filtered (_("Catchpoint %d (syscalls"), b->number);
8510 printf_filtered (_("Catchpoint %d (syscall"), b->number);
8513 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8517 get_syscall_by_number (iter, &s);
8520 printf_filtered (" '%s' [%d]", s.name, s.number);
8522 printf_filtered (" %d", s.number);
8524 printf_filtered (")");
8527 printf_filtered (_("Catchpoint %d (any syscall)"),
8531 /* Implement the "print_recreate" breakpoint_ops method for syscall
8535 print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp)
8537 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
8539 fprintf_unfiltered (fp, "catch syscall");
8541 if (c->syscalls_to_be_caught)
8546 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8551 get_syscall_by_number (iter, &s);
8553 fprintf_unfiltered (fp, " %s", s.name);
8555 fprintf_unfiltered (fp, " %d", s.number);
8558 print_recreate_thread (b, fp);
8561 /* The breakpoint_ops structure to be used in syscall catchpoints. */
8563 static struct breakpoint_ops catch_syscall_breakpoint_ops;
8565 /* Returns non-zero if 'b' is a syscall catchpoint. */
8568 syscall_catchpoint_p (struct breakpoint *b)
8570 return (b->ops == &catch_syscall_breakpoint_ops);
8573 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8574 is non-zero, then make the breakpoint temporary. If COND_STRING is
8575 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8576 the breakpoint_ops structure associated to the catchpoint. */
8579 init_catchpoint (struct breakpoint *b,
8580 struct gdbarch *gdbarch, int tempflag,
8582 const struct breakpoint_ops *ops)
8584 struct symtab_and_line sal;
8587 sal.pspace = current_program_space;
8589 init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops);
8591 b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string);
8592 b->disposition = tempflag ? disp_del : disp_donttouch;
8596 install_breakpoint (int internal, struct breakpoint *b, int update_gll)
8598 add_to_breakpoint_chain (b);
8599 set_breakpoint_number (internal, b);
8600 if (is_tracepoint (b))
8601 set_tracepoint_count (breakpoint_count);
8604 observer_notify_breakpoint_created (b);
8607 update_global_location_list (1);
8611 create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch,
8612 int tempflag, char *cond_string,
8613 const struct breakpoint_ops *ops)
8615 struct fork_catchpoint *c = XNEW (struct fork_catchpoint);
8617 init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops);
8619 c->forked_inferior_pid = null_ptid;
8621 install_breakpoint (0, &c->base, 1);
8624 /* Exec catchpoints. */
8626 /* An instance of this type is used to represent an exec catchpoint.
8627 It includes a "struct breakpoint" as a kind of base class; users
8628 downcast to "struct breakpoint *" when needed. A breakpoint is
8629 really of this type iff its ops pointer points to
8630 CATCH_EXEC_BREAKPOINT_OPS. */
8632 struct exec_catchpoint
8634 /* The base class. */
8635 struct breakpoint base;
8637 /* Filename of a program whose exec triggered this catchpoint.
8638 This field is only valid immediately after this catchpoint has
8640 char *exec_pathname;
8643 /* Implement the "dtor" breakpoint_ops method for exec
8647 dtor_catch_exec (struct breakpoint *b)
8649 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8651 xfree (c->exec_pathname);
8653 base_breakpoint_ops.dtor (b);
8657 insert_catch_exec (struct bp_location *bl)
8659 return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid));
8663 remove_catch_exec (struct bp_location *bl)
8665 return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid));
8669 breakpoint_hit_catch_exec (const struct bp_location *bl,
8670 struct address_space *aspace, CORE_ADDR bp_addr,
8671 const struct target_waitstatus *ws)
8673 struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner;
8675 if (ws->kind != TARGET_WAITKIND_EXECD)
8678 c->exec_pathname = xstrdup (ws->value.execd_pathname);
8682 static enum print_stop_action
8683 print_it_catch_exec (bpstat bs)
8685 struct ui_out *uiout = current_uiout;
8686 struct breakpoint *b = bs->breakpoint_at;
8687 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8689 annotate_catchpoint (b->number);
8690 if (b->disposition == disp_del)
8691 ui_out_text (uiout, "\nTemporary catchpoint ");
8693 ui_out_text (uiout, "\nCatchpoint ");
8694 if (ui_out_is_mi_like_p (uiout))
8696 ui_out_field_string (uiout, "reason",
8697 async_reason_lookup (EXEC_ASYNC_EXEC));
8698 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8700 ui_out_field_int (uiout, "bkptno", b->number);
8701 ui_out_text (uiout, " (exec'd ");
8702 ui_out_field_string (uiout, "new-exec", c->exec_pathname);
8703 ui_out_text (uiout, "), ");
8705 return PRINT_SRC_AND_LOC;
8709 print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc)
8711 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8712 struct value_print_options opts;
8713 struct ui_out *uiout = current_uiout;
8715 get_user_print_options (&opts);
8717 /* Field 4, the address, is omitted (which makes the columns
8718 not line up too nicely with the headers, but the effect
8719 is relatively readable). */
8720 if (opts.addressprint)
8721 ui_out_field_skip (uiout, "addr");
8723 ui_out_text (uiout, "exec");
8724 if (c->exec_pathname != NULL)
8726 ui_out_text (uiout, ", program \"");
8727 ui_out_field_string (uiout, "what", c->exec_pathname);
8728 ui_out_text (uiout, "\" ");
8731 if (ui_out_is_mi_like_p (uiout))
8732 ui_out_field_string (uiout, "catch-type", "exec");
8736 print_mention_catch_exec (struct breakpoint *b)
8738 printf_filtered (_("Catchpoint %d (exec)"), b->number);
8741 /* Implement the "print_recreate" breakpoint_ops method for exec
8745 print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp)
8747 fprintf_unfiltered (fp, "catch exec");
8748 print_recreate_thread (b, fp);
8751 static struct breakpoint_ops catch_exec_breakpoint_ops;
8754 create_syscall_event_catchpoint (int tempflag, VEC(int) *filter,
8755 const struct breakpoint_ops *ops)
8757 struct syscall_catchpoint *c;
8758 struct gdbarch *gdbarch = get_current_arch ();
8760 c = XNEW (struct syscall_catchpoint);
8761 init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops);
8762 c->syscalls_to_be_caught = filter;
8764 install_breakpoint (0, &c->base, 1);
8768 hw_breakpoint_used_count (void)
8771 struct breakpoint *b;
8772 struct bp_location *bl;
8776 if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b))
8777 for (bl = b->loc; bl; bl = bl->next)
8779 /* Special types of hardware breakpoints may use more than
8781 i += b->ops->resources_needed (bl);
8788 /* Returns the resources B would use if it were a hardware
8792 hw_watchpoint_use_count (struct breakpoint *b)
8795 struct bp_location *bl;
8797 if (!breakpoint_enabled (b))
8800 for (bl = b->loc; bl; bl = bl->next)
8802 /* Special types of hardware watchpoints may use more than
8804 i += b->ops->resources_needed (bl);
8810 /* Returns the sum the used resources of all hardware watchpoints of
8811 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8812 the sum of the used resources of all hardware watchpoints of other
8813 types _not_ TYPE. */
8816 hw_watchpoint_used_count_others (struct breakpoint *except,
8817 enum bptype type, int *other_type_used)
8820 struct breakpoint *b;
8822 *other_type_used = 0;
8827 if (!breakpoint_enabled (b))
8830 if (b->type == type)
8831 i += hw_watchpoint_use_count (b);
8832 else if (is_hardware_watchpoint (b))
8833 *other_type_used = 1;
8840 disable_watchpoints_before_interactive_call_start (void)
8842 struct breakpoint *b;
8846 if (is_watchpoint (b) && breakpoint_enabled (b))
8848 b->enable_state = bp_call_disabled;
8849 update_global_location_list (0);
8855 enable_watchpoints_after_interactive_call_stop (void)
8857 struct breakpoint *b;
8861 if (is_watchpoint (b) && b->enable_state == bp_call_disabled)
8863 b->enable_state = bp_enabled;
8864 update_global_location_list (1);
8870 disable_breakpoints_before_startup (void)
8872 current_program_space->executing_startup = 1;
8873 update_global_location_list (0);
8877 enable_breakpoints_after_startup (void)
8879 current_program_space->executing_startup = 0;
8880 breakpoint_re_set ();
8884 /* Set a breakpoint that will evaporate an end of command
8885 at address specified by SAL.
8886 Restrict it to frame FRAME if FRAME is nonzero. */
8889 set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal,
8890 struct frame_id frame_id, enum bptype type)
8892 struct breakpoint *b;
8894 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8896 gdb_assert (!frame_id_artificial_p (frame_id));
8898 b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops);
8899 b->enable_state = bp_enabled;
8900 b->disposition = disp_donttouch;
8901 b->frame_id = frame_id;
8903 /* If we're debugging a multi-threaded program, then we want
8904 momentary breakpoints to be active in only a single thread of
8906 if (in_thread_list (inferior_ptid))
8907 b->thread = pid_to_thread_id (inferior_ptid);
8909 update_global_location_list_nothrow (1);
8914 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8915 The new breakpoint will have type TYPE, and use OPS as it
8918 static struct breakpoint *
8919 momentary_breakpoint_from_master (struct breakpoint *orig,
8921 const struct breakpoint_ops *ops)
8923 struct breakpoint *copy;
8925 copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops);
8926 copy->loc = allocate_bp_location (copy);
8927 set_breakpoint_location_function (copy->loc, 1);
8929 copy->loc->gdbarch = orig->loc->gdbarch;
8930 copy->loc->requested_address = orig->loc->requested_address;
8931 copy->loc->address = orig->loc->address;
8932 copy->loc->section = orig->loc->section;
8933 copy->loc->pspace = orig->loc->pspace;
8934 copy->loc->probe = orig->loc->probe;
8935 copy->loc->line_number = orig->loc->line_number;
8936 copy->loc->symtab = orig->loc->symtab;
8937 copy->frame_id = orig->frame_id;
8938 copy->thread = orig->thread;
8939 copy->pspace = orig->pspace;
8941 copy->enable_state = bp_enabled;
8942 copy->disposition = disp_donttouch;
8943 copy->number = internal_breakpoint_number--;
8945 update_global_location_list_nothrow (0);
8949 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8953 clone_momentary_breakpoint (struct breakpoint *orig)
8955 /* If there's nothing to clone, then return nothing. */
8959 return momentary_breakpoint_from_master (orig, orig->type, orig->ops);
8963 set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc,
8966 struct symtab_and_line sal;
8968 sal = find_pc_line (pc, 0);
8970 sal.section = find_pc_overlay (pc);
8971 sal.explicit_pc = 1;
8973 return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type);
8977 /* Tell the user we have just set a breakpoint B. */
8980 mention (struct breakpoint *b)
8982 b->ops->print_mention (b);
8983 if (ui_out_is_mi_like_p (current_uiout))
8985 printf_filtered ("\n");
8989 static struct bp_location *
8990 add_location_to_breakpoint (struct breakpoint *b,
8991 const struct symtab_and_line *sal)
8993 struct bp_location *loc, **tmp;
8994 CORE_ADDR adjusted_address;
8995 struct gdbarch *loc_gdbarch = get_sal_arch (*sal);
8997 if (loc_gdbarch == NULL)
8998 loc_gdbarch = b->gdbarch;
9000 /* Adjust the breakpoint's address prior to allocating a location.
9001 Once we call allocate_bp_location(), that mostly uninitialized
9002 location will be placed on the location chain. Adjustment of the
9003 breakpoint may cause target_read_memory() to be called and we do
9004 not want its scan of the location chain to find a breakpoint and
9005 location that's only been partially initialized. */
9006 adjusted_address = adjust_breakpoint_address (loc_gdbarch,
9009 /* Sort the locations by their ADDRESS. */
9010 loc = allocate_bp_location (b);
9011 for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address;
9012 tmp = &((*tmp)->next))
9017 loc->requested_address = sal->pc;
9018 loc->address = adjusted_address;
9019 loc->pspace = sal->pspace;
9020 loc->probe = sal->probe;
9021 gdb_assert (loc->pspace != NULL);
9022 loc->section = sal->section;
9023 loc->gdbarch = loc_gdbarch;
9024 loc->line_number = sal->line;
9025 loc->symtab = sal->symtab;
9027 set_breakpoint_location_function (loc,
9028 sal->explicit_pc || sal->explicit_line);
9033 /* Return 1 if LOC is pointing to a permanent breakpoint,
9034 return 0 otherwise. */
9037 bp_loc_is_permanent (struct bp_location *loc)
9041 const gdb_byte *bpoint;
9042 gdb_byte *target_mem;
9043 struct cleanup *cleanup;
9046 gdb_assert (loc != NULL);
9048 addr = loc->address;
9049 bpoint = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len);
9051 /* Software breakpoints unsupported? */
9055 target_mem = alloca (len);
9057 /* Enable the automatic memory restoration from breakpoints while
9058 we read the memory. Otherwise we could say about our temporary
9059 breakpoints they are permanent. */
9060 cleanup = save_current_space_and_thread ();
9062 switch_to_program_space_and_thread (loc->pspace);
9063 make_show_memory_breakpoints_cleanup (0);
9065 if (target_read_memory (loc->address, target_mem, len) == 0
9066 && memcmp (target_mem, bpoint, len) == 0)
9069 do_cleanups (cleanup);
9074 /* Build a command list for the dprintf corresponding to the current
9075 settings of the dprintf style options. */
9078 update_dprintf_command_list (struct breakpoint *b)
9080 char *dprintf_args = b->extra_string;
9081 char *printf_line = NULL;
9086 dprintf_args = skip_spaces (dprintf_args);
9088 /* Allow a comma, as it may have terminated a location, but don't
9090 if (*dprintf_args == ',')
9092 dprintf_args = skip_spaces (dprintf_args);
9094 if (*dprintf_args != '"')
9095 error (_("Bad format string, missing '\"'."));
9097 if (strcmp (dprintf_style, dprintf_style_gdb) == 0)
9098 printf_line = xstrprintf ("printf %s", dprintf_args);
9099 else if (strcmp (dprintf_style, dprintf_style_call) == 0)
9101 if (!dprintf_function)
9102 error (_("No function supplied for dprintf call"));
9104 if (dprintf_channel && strlen (dprintf_channel) > 0)
9105 printf_line = xstrprintf ("call (void) %s (%s,%s)",
9110 printf_line = xstrprintf ("call (void) %s (%s)",
9114 else if (strcmp (dprintf_style, dprintf_style_agent) == 0)
9116 if (target_can_run_breakpoint_commands ())
9117 printf_line = xstrprintf ("agent-printf %s", dprintf_args);
9120 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
9121 printf_line = xstrprintf ("printf %s", dprintf_args);
9125 internal_error (__FILE__, __LINE__,
9126 _("Invalid dprintf style."));
9128 gdb_assert (printf_line != NULL);
9129 /* Manufacture a printf sequence. */
9131 struct command_line *printf_cmd_line
9132 = xmalloc (sizeof (struct command_line));
9134 printf_cmd_line = xmalloc (sizeof (struct command_line));
9135 printf_cmd_line->control_type = simple_control;
9136 printf_cmd_line->body_count = 0;
9137 printf_cmd_line->body_list = NULL;
9138 printf_cmd_line->next = NULL;
9139 printf_cmd_line->line = printf_line;
9141 breakpoint_set_commands (b, printf_cmd_line);
9145 /* Update all dprintf commands, making their command lists reflect
9146 current style settings. */
9149 update_dprintf_commands (char *args, int from_tty,
9150 struct cmd_list_element *c)
9152 struct breakpoint *b;
9156 if (b->type == bp_dprintf)
9157 update_dprintf_command_list (b);
9161 /* Create a breakpoint with SAL as location. Use ADDR_STRING
9162 as textual description of the location, and COND_STRING
9163 as condition expression. */
9166 init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch,
9167 struct symtabs_and_lines sals, char *addr_string,
9168 char *filter, char *cond_string,
9170 enum bptype type, enum bpdisp disposition,
9171 int thread, int task, int ignore_count,
9172 const struct breakpoint_ops *ops, int from_tty,
9173 int enabled, int internal, unsigned flags,
9174 int display_canonical)
9178 if (type == bp_hardware_breakpoint)
9180 int target_resources_ok;
9182 i = hw_breakpoint_used_count ();
9183 target_resources_ok =
9184 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
9186 if (target_resources_ok == 0)
9187 error (_("No hardware breakpoint support in the target."));
9188 else if (target_resources_ok < 0)
9189 error (_("Hardware breakpoints used exceeds limit."));
9192 gdb_assert (sals.nelts > 0);
9194 for (i = 0; i < sals.nelts; ++i)
9196 struct symtab_and_line sal = sals.sals[i];
9197 struct bp_location *loc;
9201 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
9203 loc_gdbarch = gdbarch;
9205 describe_other_breakpoints (loc_gdbarch,
9206 sal.pspace, sal.pc, sal.section, thread);
9211 init_raw_breakpoint (b, gdbarch, sal, type, ops);
9215 b->cond_string = cond_string;
9216 b->extra_string = extra_string;
9217 b->ignore_count = ignore_count;
9218 b->enable_state = enabled ? bp_enabled : bp_disabled;
9219 b->disposition = disposition;
9221 if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
9222 b->loc->inserted = 1;
9224 if (type == bp_static_tracepoint)
9226 struct tracepoint *t = (struct tracepoint *) b;
9227 struct static_tracepoint_marker marker;
9229 if (strace_marker_p (b))
9231 /* We already know the marker exists, otherwise, we
9232 wouldn't see a sal for it. */
9233 char *p = &addr_string[3];
9237 p = skip_spaces (p);
9239 endp = skip_to_space (p);
9241 marker_str = savestring (p, endp - p);
9242 t->static_trace_marker_id = marker_str;
9244 printf_filtered (_("Probed static tracepoint "
9246 t->static_trace_marker_id);
9248 else if (target_static_tracepoint_marker_at (sal.pc, &marker))
9250 t->static_trace_marker_id = xstrdup (marker.str_id);
9251 release_static_tracepoint_marker (&marker);
9253 printf_filtered (_("Probed static tracepoint "
9255 t->static_trace_marker_id);
9258 warning (_("Couldn't determine the static "
9259 "tracepoint marker to probe"));
9266 loc = add_location_to_breakpoint (b, &sal);
9267 if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
9271 if (bp_loc_is_permanent (loc))
9272 make_breakpoint_permanent (b);
9276 const char *arg = b->cond_string;
9278 loc->cond = parse_exp_1 (&arg, loc->address,
9279 block_for_pc (loc->address), 0);
9281 error (_("Garbage '%s' follows condition"), arg);
9284 /* Dynamic printf requires and uses additional arguments on the
9285 command line, otherwise it's an error. */
9286 if (type == bp_dprintf)
9288 if (b->extra_string)
9289 update_dprintf_command_list (b);
9291 error (_("Format string required"));
9293 else if (b->extra_string)
9294 error (_("Garbage '%s' at end of command"), b->extra_string);
9297 b->display_canonical = display_canonical;
9299 b->addr_string = addr_string;
9301 /* addr_string has to be used or breakpoint_re_set will delete
9304 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
9309 create_breakpoint_sal (struct gdbarch *gdbarch,
9310 struct symtabs_and_lines sals, char *addr_string,
9311 char *filter, char *cond_string,
9313 enum bptype type, enum bpdisp disposition,
9314 int thread, int task, int ignore_count,
9315 const struct breakpoint_ops *ops, int from_tty,
9316 int enabled, int internal, unsigned flags,
9317 int display_canonical)
9319 struct breakpoint *b;
9320 struct cleanup *old_chain;
9322 if (is_tracepoint_type (type))
9324 struct tracepoint *t;
9326 t = XCNEW (struct tracepoint);
9330 b = XNEW (struct breakpoint);
9332 old_chain = make_cleanup (xfree, b);
9334 init_breakpoint_sal (b, gdbarch,
9336 filter, cond_string, extra_string,
9338 thread, task, ignore_count,
9340 enabled, internal, flags,
9342 discard_cleanups (old_chain);
9344 install_breakpoint (internal, b, 0);
9347 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9348 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9349 value. COND_STRING, if not NULL, specified the condition to be
9350 used for all breakpoints. Essentially the only case where
9351 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9352 function. In that case, it's still not possible to specify
9353 separate conditions for different overloaded functions, so
9354 we take just a single condition string.
9356 NOTE: If the function succeeds, the caller is expected to cleanup
9357 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9358 array contents). If the function fails (error() is called), the
9359 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9360 COND and SALS arrays and each of those arrays contents. */
9363 create_breakpoints_sal (struct gdbarch *gdbarch,
9364 struct linespec_result *canonical,
9365 char *cond_string, char *extra_string,
9366 enum bptype type, enum bpdisp disposition,
9367 int thread, int task, int ignore_count,
9368 const struct breakpoint_ops *ops, int from_tty,
9369 int enabled, int internal, unsigned flags)
9372 struct linespec_sals *lsal;
9374 if (canonical->pre_expanded)
9375 gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1);
9377 for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i)
9379 /* Note that 'addr_string' can be NULL in the case of a plain
9380 'break', without arguments. */
9381 char *addr_string = (canonical->addr_string
9382 ? xstrdup (canonical->addr_string)
9384 char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL;
9385 struct cleanup *inner = make_cleanup (xfree, addr_string);
9387 make_cleanup (xfree, filter_string);
9388 create_breakpoint_sal (gdbarch, lsal->sals,
9391 cond_string, extra_string,
9393 thread, task, ignore_count, ops,
9394 from_tty, enabled, internal, flags,
9395 canonical->special_display);
9396 discard_cleanups (inner);
9400 /* Parse ADDRESS which is assumed to be a SAL specification possibly
9401 followed by conditionals. On return, SALS contains an array of SAL
9402 addresses found. ADDR_STRING contains a vector of (canonical)
9403 address strings. ADDRESS points to the end of the SAL.
9405 The array and the line spec strings are allocated on the heap, it is
9406 the caller's responsibility to free them. */
9409 parse_breakpoint_sals (char **address,
9410 struct linespec_result *canonical)
9412 /* If no arg given, or if first arg is 'if ', use the default
9414 if ((*address) == NULL
9415 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
9417 /* The last displayed codepoint, if it's valid, is our default breakpoint
9419 if (last_displayed_sal_is_valid ())
9421 struct linespec_sals lsal;
9422 struct symtab_and_line sal;
9425 init_sal (&sal); /* Initialize to zeroes. */
9426 lsal.sals.sals = (struct symtab_and_line *)
9427 xmalloc (sizeof (struct symtab_and_line));
9429 /* Set sal's pspace, pc, symtab, and line to the values
9430 corresponding to the last call to print_frame_info.
9431 Be sure to reinitialize LINE with NOTCURRENT == 0
9432 as the breakpoint line number is inappropriate otherwise.
9433 find_pc_line would adjust PC, re-set it back. */
9434 get_last_displayed_sal (&sal);
9436 sal = find_pc_line (pc, 0);
9438 /* "break" without arguments is equivalent to "break *PC"
9439 where PC is the last displayed codepoint's address. So
9440 make sure to set sal.explicit_pc to prevent GDB from
9441 trying to expand the list of sals to include all other
9442 instances with the same symtab and line. */
9444 sal.explicit_pc = 1;
9446 lsal.sals.sals[0] = sal;
9447 lsal.sals.nelts = 1;
9448 lsal.canonical = NULL;
9450 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
9453 error (_("No default breakpoint address now."));
9457 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
9459 /* Force almost all breakpoints to be in terms of the
9460 current_source_symtab (which is decode_line_1's default).
9461 This should produce the results we want almost all of the
9462 time while leaving default_breakpoint_* alone.
9464 ObjC: However, don't match an Objective-C method name which
9465 may have a '+' or '-' succeeded by a '['. */
9466 if (last_displayed_sal_is_valid ()
9468 || ((strchr ("+-", (*address)[0]) != NULL)
9469 && ((*address)[1] != '['))))
9470 decode_line_full (address, DECODE_LINE_FUNFIRSTLINE,
9471 get_last_displayed_symtab (),
9472 get_last_displayed_line (),
9473 canonical, NULL, NULL);
9475 decode_line_full (address, DECODE_LINE_FUNFIRSTLINE,
9476 cursal.symtab, cursal.line, canonical, NULL, NULL);
9481 /* Convert each SAL into a real PC. Verify that the PC can be
9482 inserted as a breakpoint. If it can't throw an error. */
9485 breakpoint_sals_to_pc (struct symtabs_and_lines *sals)
9489 for (i = 0; i < sals->nelts; i++)
9490 resolve_sal_pc (&sals->sals[i]);
9493 /* Fast tracepoints may have restrictions on valid locations. For
9494 instance, a fast tracepoint using a jump instead of a trap will
9495 likely have to overwrite more bytes than a trap would, and so can
9496 only be placed where the instruction is longer than the jump, or a
9497 multi-instruction sequence does not have a jump into the middle of
9501 check_fast_tracepoint_sals (struct gdbarch *gdbarch,
9502 struct symtabs_and_lines *sals)
9505 struct symtab_and_line *sal;
9507 struct cleanup *old_chain;
9509 for (i = 0; i < sals->nelts; i++)
9511 struct gdbarch *sarch;
9513 sal = &sals->sals[i];
9515 sarch = get_sal_arch (*sal);
9516 /* We fall back to GDBARCH if there is no architecture
9517 associated with SAL. */
9520 rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc,
9522 old_chain = make_cleanup (xfree, msg);
9525 error (_("May not have a fast tracepoint at 0x%s%s"),
9526 paddress (sarch, sal->pc), (msg ? msg : ""));
9528 do_cleanups (old_chain);
9532 /* Issue an invalid thread ID error. */
9534 static void ATTRIBUTE_NORETURN
9535 invalid_thread_id_error (int id)
9537 error (_("Unknown thread %d."), id);
9540 /* Given TOK, a string specification of condition and thread, as
9541 accepted by the 'break' command, extract the condition
9542 string and thread number and set *COND_STRING and *THREAD.
9543 PC identifies the context at which the condition should be parsed.
9544 If no condition is found, *COND_STRING is set to NULL.
9545 If no thread is found, *THREAD is set to -1. */
9548 find_condition_and_thread (const char *tok, CORE_ADDR pc,
9549 char **cond_string, int *thread, int *task,
9552 *cond_string = NULL;
9559 const char *end_tok;
9561 const char *cond_start = NULL;
9562 const char *cond_end = NULL;
9564 tok = skip_spaces_const (tok);
9566 if ((*tok == '"' || *tok == ',') && rest)
9568 *rest = savestring (tok, strlen (tok));
9572 end_tok = skip_to_space_const (tok);
9574 toklen = end_tok - tok;
9576 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
9578 struct expression *expr;
9580 tok = cond_start = end_tok + 1;
9581 expr = parse_exp_1 (&tok, pc, block_for_pc (pc), 0);
9584 *cond_string = savestring (cond_start, cond_end - cond_start);
9586 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
9591 *thread = strtol (tok, &tmptok, 0);
9593 error (_("Junk after thread keyword."));
9594 if (!valid_thread_id (*thread))
9595 invalid_thread_id_error (*thread);
9598 else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0)
9603 *task = strtol (tok, &tmptok, 0);
9605 error (_("Junk after task keyword."));
9606 if (!valid_task_id (*task))
9607 error (_("Unknown task %d."), *task);
9612 *rest = savestring (tok, strlen (tok));
9616 error (_("Junk at end of arguments."));
9620 /* Decode a static tracepoint marker spec. */
9622 static struct symtabs_and_lines
9623 decode_static_tracepoint_spec (char **arg_p)
9625 VEC(static_tracepoint_marker_p) *markers = NULL;
9626 struct symtabs_and_lines sals;
9627 struct cleanup *old_chain;
9628 char *p = &(*arg_p)[3];
9633 p = skip_spaces (p);
9635 endp = skip_to_space (p);
9637 marker_str = savestring (p, endp - p);
9638 old_chain = make_cleanup (xfree, marker_str);
9640 markers = target_static_tracepoint_markers_by_strid (marker_str);
9641 if (VEC_empty(static_tracepoint_marker_p, markers))
9642 error (_("No known static tracepoint marker named %s"), marker_str);
9644 sals.nelts = VEC_length(static_tracepoint_marker_p, markers);
9645 sals.sals = xmalloc (sizeof *sals.sals * sals.nelts);
9647 for (i = 0; i < sals.nelts; i++)
9649 struct static_tracepoint_marker *marker;
9651 marker = VEC_index (static_tracepoint_marker_p, markers, i);
9653 init_sal (&sals.sals[i]);
9655 sals.sals[i] = find_pc_line (marker->address, 0);
9656 sals.sals[i].pc = marker->address;
9658 release_static_tracepoint_marker (marker);
9661 do_cleanups (old_chain);
9667 /* Set a breakpoint. This function is shared between CLI and MI
9668 functions for setting a breakpoint. This function has two major
9669 modes of operations, selected by the PARSE_ARG parameter. If
9670 non-zero, the function will parse ARG, extracting location,
9671 condition, thread and extra string. Otherwise, ARG is just the
9672 breakpoint's location, with condition, thread, and extra string
9673 specified by the COND_STRING, THREAD and EXTRA_STRING parameters.
9674 If INTERNAL is non-zero, the breakpoint number will be allocated
9675 from the internal breakpoint count. Returns true if any breakpoint
9676 was created; false otherwise. */
9679 create_breakpoint (struct gdbarch *gdbarch,
9680 char *arg, char *cond_string,
9681 int thread, char *extra_string,
9683 int tempflag, enum bptype type_wanted,
9685 enum auto_boolean pending_break_support,
9686 const struct breakpoint_ops *ops,
9687 int from_tty, int enabled, int internal,
9690 volatile struct gdb_exception e;
9691 char *copy_arg = NULL;
9692 char *addr_start = arg;
9693 struct linespec_result canonical;
9694 struct cleanup *old_chain;
9695 struct cleanup *bkpt_chain = NULL;
9698 int prev_bkpt_count = breakpoint_count;
9700 gdb_assert (ops != NULL);
9702 init_linespec_result (&canonical);
9704 TRY_CATCH (e, RETURN_MASK_ALL)
9706 ops->create_sals_from_address (&arg, &canonical, type_wanted,
9707 addr_start, ©_arg);
9710 /* If caller is interested in rc value from parse, set value. */
9714 if (VEC_empty (linespec_sals, canonical.sals))
9720 case NOT_FOUND_ERROR:
9722 /* If pending breakpoint support is turned off, throw
9725 if (pending_break_support == AUTO_BOOLEAN_FALSE)
9726 throw_exception (e);
9728 exception_print (gdb_stderr, e);
9730 /* If pending breakpoint support is auto query and the user
9731 selects no, then simply return the error code. */
9732 if (pending_break_support == AUTO_BOOLEAN_AUTO
9733 && !nquery (_("Make %s pending on future shared library load? "),
9734 bptype_string (type_wanted)))
9737 /* At this point, either the user was queried about setting
9738 a pending breakpoint and selected yes, or pending
9739 breakpoint behavior is on and thus a pending breakpoint
9740 is defaulted on behalf of the user. */
9742 struct linespec_sals lsal;
9744 copy_arg = xstrdup (addr_start);
9745 lsal.canonical = xstrdup (copy_arg);
9746 lsal.sals.nelts = 1;
9747 lsal.sals.sals = XNEW (struct symtab_and_line);
9748 init_sal (&lsal.sals.sals[0]);
9750 VEC_safe_push (linespec_sals, canonical.sals, &lsal);
9754 throw_exception (e);
9758 throw_exception (e);
9761 /* Create a chain of things that always need to be cleaned up. */
9762 old_chain = make_cleanup_destroy_linespec_result (&canonical);
9764 /* ----------------------------- SNIP -----------------------------
9765 Anything added to the cleanup chain beyond this point is assumed
9766 to be part of a breakpoint. If the breakpoint create succeeds
9767 then the memory is not reclaimed. */
9768 bkpt_chain = make_cleanup (null_cleanup, 0);
9770 /* Resolve all line numbers to PC's and verify that the addresses
9771 are ok for the target. */
9775 struct linespec_sals *iter;
9777 for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
9778 breakpoint_sals_to_pc (&iter->sals);
9781 /* Fast tracepoints may have additional restrictions on location. */
9782 if (!pending && type_wanted == bp_fast_tracepoint)
9785 struct linespec_sals *iter;
9787 for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
9788 check_fast_tracepoint_sals (gdbarch, &iter->sals);
9791 /* Verify that condition can be parsed, before setting any
9792 breakpoints. Allocate a separate condition expression for each
9799 struct linespec_sals *lsal;
9801 lsal = VEC_index (linespec_sals, canonical.sals, 0);
9803 /* Here we only parse 'arg' to separate condition
9804 from thread number, so parsing in context of first
9805 sal is OK. When setting the breakpoint we'll
9806 re-parse it in context of each sal. */
9808 find_condition_and_thread (arg, lsal->sals.sals[0].pc, &cond_string,
9809 &thread, &task, &rest);
9811 make_cleanup (xfree, cond_string);
9813 make_cleanup (xfree, rest);
9815 extra_string = rest;
9820 error (_("Garbage '%s' at end of location"), arg);
9822 /* Create a private copy of condition string. */
9825 cond_string = xstrdup (cond_string);
9826 make_cleanup (xfree, cond_string);
9828 /* Create a private copy of any extra string. */
9831 extra_string = xstrdup (extra_string);
9832 make_cleanup (xfree, extra_string);
9836 ops->create_breakpoints_sal (gdbarch, &canonical,
9837 cond_string, extra_string, type_wanted,
9838 tempflag ? disp_del : disp_donttouch,
9839 thread, task, ignore_count, ops,
9840 from_tty, enabled, internal, flags);
9844 struct breakpoint *b;
9846 make_cleanup (xfree, copy_arg);
9848 if (is_tracepoint_type (type_wanted))
9850 struct tracepoint *t;
9852 t = XCNEW (struct tracepoint);
9856 b = XNEW (struct breakpoint);
9858 init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops);
9860 b->addr_string = copy_arg;
9862 b->cond_string = NULL;
9865 /* Create a private copy of condition string. */
9868 cond_string = xstrdup (cond_string);
9869 make_cleanup (xfree, cond_string);
9871 b->cond_string = cond_string;
9873 b->extra_string = NULL;
9874 b->ignore_count = ignore_count;
9875 b->disposition = tempflag ? disp_del : disp_donttouch;
9876 b->condition_not_parsed = 1;
9877 b->enable_state = enabled ? bp_enabled : bp_disabled;
9878 if ((type_wanted != bp_breakpoint
9879 && type_wanted != bp_hardware_breakpoint) || thread != -1)
9880 b->pspace = current_program_space;
9882 install_breakpoint (internal, b, 0);
9885 if (VEC_length (linespec_sals, canonical.sals) > 1)
9887 warning (_("Multiple breakpoints were set.\nUse the "
9888 "\"delete\" command to delete unwanted breakpoints."));
9889 prev_breakpoint_count = prev_bkpt_count;
9892 /* That's it. Discard the cleanups for data inserted into the
9894 discard_cleanups (bkpt_chain);
9895 /* But cleanup everything else. */
9896 do_cleanups (old_chain);
9898 /* error call may happen here - have BKPT_CHAIN already discarded. */
9899 update_global_location_list (1);
9904 /* Set a breakpoint.
9905 ARG is a string describing breakpoint address,
9906 condition, and thread.
9907 FLAG specifies if a breakpoint is hardware on,
9908 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9912 break_command_1 (char *arg, int flag, int from_tty)
9914 int tempflag = flag & BP_TEMPFLAG;
9915 enum bptype type_wanted = (flag & BP_HARDWAREFLAG
9916 ? bp_hardware_breakpoint
9918 struct breakpoint_ops *ops;
9919 const char *arg_cp = arg;
9921 /* Matching breakpoints on probes. */
9922 if (arg && probe_linespec_to_ops (&arg_cp) != NULL)
9923 ops = &bkpt_probe_breakpoint_ops;
9925 ops = &bkpt_breakpoint_ops;
9927 create_breakpoint (get_current_arch (),
9929 NULL, 0, NULL, 1 /* parse arg */,
9930 tempflag, type_wanted,
9931 0 /* Ignore count */,
9932 pending_break_support,
9940 /* Helper function for break_command_1 and disassemble_command. */
9943 resolve_sal_pc (struct symtab_and_line *sal)
9947 if (sal->pc == 0 && sal->symtab != NULL)
9949 if (!find_line_pc (sal->symtab, sal->line, &pc))
9950 error (_("No line %d in file \"%s\"."),
9951 sal->line, symtab_to_filename_for_display (sal->symtab));
9954 /* If this SAL corresponds to a breakpoint inserted using a line
9955 number, then skip the function prologue if necessary. */
9956 if (sal->explicit_line)
9957 skip_prologue_sal (sal);
9960 if (sal->section == 0 && sal->symtab != NULL)
9962 struct blockvector *bv;
9966 bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab);
9969 sym = block_linkage_function (b);
9972 fixup_symbol_section (sym, sal->symtab->objfile);
9973 sal->section = SYMBOL_OBJ_SECTION (sal->symtab->objfile, sym);
9977 /* It really is worthwhile to have the section, so we'll
9978 just have to look harder. This case can be executed
9979 if we have line numbers but no functions (as can
9980 happen in assembly source). */
9982 struct bound_minimal_symbol msym;
9983 struct cleanup *old_chain = save_current_space_and_thread ();
9985 switch_to_program_space_and_thread (sal->pspace);
9987 msym = lookup_minimal_symbol_by_pc (sal->pc);
9989 sal->section = SYMBOL_OBJ_SECTION (msym.objfile, msym.minsym);
9991 do_cleanups (old_chain);
9998 break_command (char *arg, int from_tty)
10000 break_command_1 (arg, 0, from_tty);
10004 tbreak_command (char *arg, int from_tty)
10006 break_command_1 (arg, BP_TEMPFLAG, from_tty);
10010 hbreak_command (char *arg, int from_tty)
10012 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
10016 thbreak_command (char *arg, int from_tty)
10018 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
10022 stop_command (char *arg, int from_tty)
10024 printf_filtered (_("Specify the type of breakpoint to set.\n\
10025 Usage: stop in <function | address>\n\
10026 stop at <line>\n"));
10030 stopin_command (char *arg, int from_tty)
10034 if (arg == (char *) NULL)
10036 else if (*arg != '*')
10038 char *argptr = arg;
10041 /* Look for a ':'. If this is a line number specification, then
10042 say it is bad, otherwise, it should be an address or
10043 function/method name. */
10044 while (*argptr && !hasColon)
10046 hasColon = (*argptr == ':');
10051 badInput = (*argptr != ':'); /* Not a class::method */
10053 badInput = isdigit (*arg); /* a simple line number */
10057 printf_filtered (_("Usage: stop in <function | address>\n"));
10059 break_command_1 (arg, 0, from_tty);
10063 stopat_command (char *arg, int from_tty)
10067 if (arg == (char *) NULL || *arg == '*') /* no line number */
10071 char *argptr = arg;
10074 /* Look for a ':'. If there is a '::' then get out, otherwise
10075 it is probably a line number. */
10076 while (*argptr && !hasColon)
10078 hasColon = (*argptr == ':');
10083 badInput = (*argptr == ':'); /* we have class::method */
10085 badInput = !isdigit (*arg); /* not a line number */
10089 printf_filtered (_("Usage: stop at <line>\n"));
10091 break_command_1 (arg, 0, from_tty);
10094 /* The dynamic printf command is mostly like a regular breakpoint, but
10095 with a prewired command list consisting of a single output command,
10096 built from extra arguments supplied on the dprintf command
10100 dprintf_command (char *arg, int from_tty)
10102 create_breakpoint (get_current_arch (),
10104 NULL, 0, NULL, 1 /* parse arg */,
10106 0 /* Ignore count */,
10107 pending_break_support,
10108 &dprintf_breakpoint_ops,
10116 agent_printf_command (char *arg, int from_tty)
10118 error (_("May only run agent-printf on the target"));
10121 /* Implement the "breakpoint_hit" breakpoint_ops method for
10122 ranged breakpoints. */
10125 breakpoint_hit_ranged_breakpoint (const struct bp_location *bl,
10126 struct address_space *aspace,
10128 const struct target_waitstatus *ws)
10130 if (ws->kind != TARGET_WAITKIND_STOPPED
10131 || ws->value.sig != GDB_SIGNAL_TRAP)
10134 return breakpoint_address_match_range (bl->pspace->aspace, bl->address,
10135 bl->length, aspace, bp_addr);
10138 /* Implement the "resources_needed" breakpoint_ops method for
10139 ranged breakpoints. */
10142 resources_needed_ranged_breakpoint (const struct bp_location *bl)
10144 return target_ranged_break_num_registers ();
10147 /* Implement the "print_it" breakpoint_ops method for
10148 ranged breakpoints. */
10150 static enum print_stop_action
10151 print_it_ranged_breakpoint (bpstat bs)
10153 struct breakpoint *b = bs->breakpoint_at;
10154 struct bp_location *bl = b->loc;
10155 struct ui_out *uiout = current_uiout;
10157 gdb_assert (b->type == bp_hardware_breakpoint);
10159 /* Ranged breakpoints have only one location. */
10160 gdb_assert (bl && bl->next == NULL);
10162 annotate_breakpoint (b->number);
10163 if (b->disposition == disp_del)
10164 ui_out_text (uiout, "\nTemporary ranged breakpoint ");
10166 ui_out_text (uiout, "\nRanged breakpoint ");
10167 if (ui_out_is_mi_like_p (uiout))
10169 ui_out_field_string (uiout, "reason",
10170 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
10171 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
10173 ui_out_field_int (uiout, "bkptno", b->number);
10174 ui_out_text (uiout, ", ");
10176 return PRINT_SRC_AND_LOC;
10179 /* Implement the "print_one" breakpoint_ops method for
10180 ranged breakpoints. */
10183 print_one_ranged_breakpoint (struct breakpoint *b,
10184 struct bp_location **last_loc)
10186 struct bp_location *bl = b->loc;
10187 struct value_print_options opts;
10188 struct ui_out *uiout = current_uiout;
10190 /* Ranged breakpoints have only one location. */
10191 gdb_assert (bl && bl->next == NULL);
10193 get_user_print_options (&opts);
10195 if (opts.addressprint)
10196 /* We don't print the address range here, it will be printed later
10197 by print_one_detail_ranged_breakpoint. */
10198 ui_out_field_skip (uiout, "addr");
10199 annotate_field (5);
10200 print_breakpoint_location (b, bl);
10204 /* Implement the "print_one_detail" breakpoint_ops method for
10205 ranged breakpoints. */
10208 print_one_detail_ranged_breakpoint (const struct breakpoint *b,
10209 struct ui_out *uiout)
10211 CORE_ADDR address_start, address_end;
10212 struct bp_location *bl = b->loc;
10213 struct ui_file *stb = mem_fileopen ();
10214 struct cleanup *cleanup = make_cleanup_ui_file_delete (stb);
10218 address_start = bl->address;
10219 address_end = address_start + bl->length - 1;
10221 ui_out_text (uiout, "\taddress range: ");
10222 fprintf_unfiltered (stb, "[%s, %s]",
10223 print_core_address (bl->gdbarch, address_start),
10224 print_core_address (bl->gdbarch, address_end));
10225 ui_out_field_stream (uiout, "addr", stb);
10226 ui_out_text (uiout, "\n");
10228 do_cleanups (cleanup);
10231 /* Implement the "print_mention" breakpoint_ops method for
10232 ranged breakpoints. */
10235 print_mention_ranged_breakpoint (struct breakpoint *b)
10237 struct bp_location *bl = b->loc;
10238 struct ui_out *uiout = current_uiout;
10241 gdb_assert (b->type == bp_hardware_breakpoint);
10243 if (ui_out_is_mi_like_p (uiout))
10246 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
10247 b->number, paddress (bl->gdbarch, bl->address),
10248 paddress (bl->gdbarch, bl->address + bl->length - 1));
10251 /* Implement the "print_recreate" breakpoint_ops method for
10252 ranged breakpoints. */
10255 print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp)
10257 fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string,
10258 b->addr_string_range_end);
10259 print_recreate_thread (b, fp);
10262 /* The breakpoint_ops structure to be used in ranged breakpoints. */
10264 static struct breakpoint_ops ranged_breakpoint_ops;
10266 /* Find the address where the end of the breakpoint range should be
10267 placed, given the SAL of the end of the range. This is so that if
10268 the user provides a line number, the end of the range is set to the
10269 last instruction of the given line. */
10272 find_breakpoint_range_end (struct symtab_and_line sal)
10276 /* If the user provided a PC value, use it. Otherwise,
10277 find the address of the end of the given location. */
10278 if (sal.explicit_pc)
10285 ret = find_line_pc_range (sal, &start, &end);
10287 error (_("Could not find location of the end of the range."));
10289 /* find_line_pc_range returns the start of the next line. */
10296 /* Implement the "break-range" CLI command. */
10299 break_range_command (char *arg, int from_tty)
10301 char *arg_start, *addr_string_start, *addr_string_end;
10302 struct linespec_result canonical_start, canonical_end;
10303 int bp_count, can_use_bp, length;
10305 struct breakpoint *b;
10306 struct symtab_and_line sal_start, sal_end;
10307 struct cleanup *cleanup_bkpt;
10308 struct linespec_sals *lsal_start, *lsal_end;
10310 /* We don't support software ranged breakpoints. */
10311 if (target_ranged_break_num_registers () < 0)
10312 error (_("This target does not support hardware ranged breakpoints."));
10314 bp_count = hw_breakpoint_used_count ();
10315 bp_count += target_ranged_break_num_registers ();
10316 can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
10318 if (can_use_bp < 0)
10319 error (_("Hardware breakpoints used exceeds limit."));
10321 arg = skip_spaces (arg);
10322 if (arg == NULL || arg[0] == '\0')
10323 error(_("No address range specified."));
10325 init_linespec_result (&canonical_start);
10328 parse_breakpoint_sals (&arg, &canonical_start);
10330 cleanup_bkpt = make_cleanup_destroy_linespec_result (&canonical_start);
10333 error (_("Too few arguments."));
10334 else if (VEC_empty (linespec_sals, canonical_start.sals))
10335 error (_("Could not find location of the beginning of the range."));
10337 lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0);
10339 if (VEC_length (linespec_sals, canonical_start.sals) > 1
10340 || lsal_start->sals.nelts != 1)
10341 error (_("Cannot create a ranged breakpoint with multiple locations."));
10343 sal_start = lsal_start->sals.sals[0];
10344 addr_string_start = savestring (arg_start, arg - arg_start);
10345 make_cleanup (xfree, addr_string_start);
10347 arg++; /* Skip the comma. */
10348 arg = skip_spaces (arg);
10350 /* Parse the end location. */
10352 init_linespec_result (&canonical_end);
10355 /* We call decode_line_full directly here instead of using
10356 parse_breakpoint_sals because we need to specify the start location's
10357 symtab and line as the default symtab and line for the end of the
10358 range. This makes it possible to have ranges like "foo.c:27, +14",
10359 where +14 means 14 lines from the start location. */
10360 decode_line_full (&arg, DECODE_LINE_FUNFIRSTLINE,
10361 sal_start.symtab, sal_start.line,
10362 &canonical_end, NULL, NULL);
10364 make_cleanup_destroy_linespec_result (&canonical_end);
10366 if (VEC_empty (linespec_sals, canonical_end.sals))
10367 error (_("Could not find location of the end of the range."));
10369 lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0);
10370 if (VEC_length (linespec_sals, canonical_end.sals) > 1
10371 || lsal_end->sals.nelts != 1)
10372 error (_("Cannot create a ranged breakpoint with multiple locations."));
10374 sal_end = lsal_end->sals.sals[0];
10375 addr_string_end = savestring (arg_start, arg - arg_start);
10376 make_cleanup (xfree, addr_string_end);
10378 end = find_breakpoint_range_end (sal_end);
10379 if (sal_start.pc > end)
10380 error (_("Invalid address range, end precedes start."));
10382 length = end - sal_start.pc + 1;
10384 /* Length overflowed. */
10385 error (_("Address range too large."));
10386 else if (length == 1)
10388 /* This range is simple enough to be handled by
10389 the `hbreak' command. */
10390 hbreak_command (addr_string_start, 1);
10392 do_cleanups (cleanup_bkpt);
10397 /* Now set up the breakpoint. */
10398 b = set_raw_breakpoint (get_current_arch (), sal_start,
10399 bp_hardware_breakpoint, &ranged_breakpoint_ops);
10400 set_breakpoint_count (breakpoint_count + 1);
10401 b->number = breakpoint_count;
10402 b->disposition = disp_donttouch;
10403 b->addr_string = xstrdup (addr_string_start);
10404 b->addr_string_range_end = xstrdup (addr_string_end);
10405 b->loc->length = length;
10407 do_cleanups (cleanup_bkpt);
10410 observer_notify_breakpoint_created (b);
10411 update_global_location_list (1);
10414 /* Return non-zero if EXP is verified as constant. Returned zero
10415 means EXP is variable. Also the constant detection may fail for
10416 some constant expressions and in such case still falsely return
10420 watchpoint_exp_is_const (const struct expression *exp)
10422 int i = exp->nelts;
10428 /* We are only interested in the descriptor of each element. */
10429 operator_length (exp, i, &oplenp, &argsp);
10432 switch (exp->elts[i].opcode)
10442 case BINOP_LOGICAL_AND:
10443 case BINOP_LOGICAL_OR:
10444 case BINOP_BITWISE_AND:
10445 case BINOP_BITWISE_IOR:
10446 case BINOP_BITWISE_XOR:
10448 case BINOP_NOTEQUAL:
10477 case OP_OBJC_NSSTRING:
10480 case UNOP_LOGICAL_NOT:
10481 case UNOP_COMPLEMENT:
10486 case UNOP_CAST_TYPE:
10487 case UNOP_REINTERPRET_CAST:
10488 case UNOP_DYNAMIC_CAST:
10489 /* Unary, binary and ternary operators: We have to check
10490 their operands. If they are constant, then so is the
10491 result of that operation. For instance, if A and B are
10492 determined to be constants, then so is "A + B".
10494 UNOP_IND is one exception to the rule above, because the
10495 value of *ADDR is not necessarily a constant, even when
10500 /* Check whether the associated symbol is a constant.
10502 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10503 possible that a buggy compiler could mark a variable as
10504 constant even when it is not, and TYPE_CONST would return
10505 true in this case, while SYMBOL_CLASS wouldn't.
10507 We also have to check for function symbols because they
10508 are always constant. */
10510 struct symbol *s = exp->elts[i + 2].symbol;
10512 if (SYMBOL_CLASS (s) != LOC_BLOCK
10513 && SYMBOL_CLASS (s) != LOC_CONST
10514 && SYMBOL_CLASS (s) != LOC_CONST_BYTES)
10519 /* The default action is to return 0 because we are using
10520 the optimistic approach here: If we don't know something,
10521 then it is not a constant. */
10530 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
10533 dtor_watchpoint (struct breakpoint *self)
10535 struct watchpoint *w = (struct watchpoint *) self;
10537 xfree (w->cond_exp);
10539 xfree (w->exp_string);
10540 xfree (w->exp_string_reparse);
10541 value_free (w->val);
10543 base_breakpoint_ops.dtor (self);
10546 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10549 re_set_watchpoint (struct breakpoint *b)
10551 struct watchpoint *w = (struct watchpoint *) b;
10553 /* Watchpoint can be either on expression using entirely global
10554 variables, or it can be on local variables.
10556 Watchpoints of the first kind are never auto-deleted, and even
10557 persist across program restarts. Since they can use variables
10558 from shared libraries, we need to reparse expression as libraries
10559 are loaded and unloaded.
10561 Watchpoints on local variables can also change meaning as result
10562 of solib event. For example, if a watchpoint uses both a local
10563 and a global variables in expression, it's a local watchpoint,
10564 but unloading of a shared library will make the expression
10565 invalid. This is not a very common use case, but we still
10566 re-evaluate expression, to avoid surprises to the user.
10568 Note that for local watchpoints, we re-evaluate it only if
10569 watchpoints frame id is still valid. If it's not, it means the
10570 watchpoint is out of scope and will be deleted soon. In fact,
10571 I'm not sure we'll ever be called in this case.
10573 If a local watchpoint's frame id is still valid, then
10574 w->exp_valid_block is likewise valid, and we can safely use it.
10576 Don't do anything about disabled watchpoints, since they will be
10577 reevaluated again when enabled. */
10578 update_watchpoint (w, 1 /* reparse */);
10581 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10584 insert_watchpoint (struct bp_location *bl)
10586 struct watchpoint *w = (struct watchpoint *) bl->owner;
10587 int length = w->exact ? 1 : bl->length;
10589 return target_insert_watchpoint (bl->address, length, bl->watchpoint_type,
10593 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10596 remove_watchpoint (struct bp_location *bl)
10598 struct watchpoint *w = (struct watchpoint *) bl->owner;
10599 int length = w->exact ? 1 : bl->length;
10601 return target_remove_watchpoint (bl->address, length, bl->watchpoint_type,
10606 breakpoint_hit_watchpoint (const struct bp_location *bl,
10607 struct address_space *aspace, CORE_ADDR bp_addr,
10608 const struct target_waitstatus *ws)
10610 struct breakpoint *b = bl->owner;
10611 struct watchpoint *w = (struct watchpoint *) b;
10613 /* Continuable hardware watchpoints are treated as non-existent if the
10614 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10615 some data address). Otherwise gdb won't stop on a break instruction
10616 in the code (not from a breakpoint) when a hardware watchpoint has
10617 been defined. Also skip watchpoints which we know did not trigger
10618 (did not match the data address). */
10619 if (is_hardware_watchpoint (b)
10620 && w->watchpoint_triggered == watch_triggered_no)
10627 check_status_watchpoint (bpstat bs)
10629 gdb_assert (is_watchpoint (bs->breakpoint_at));
10631 bpstat_check_watchpoint (bs);
10634 /* Implement the "resources_needed" breakpoint_ops method for
10635 hardware watchpoints. */
10638 resources_needed_watchpoint (const struct bp_location *bl)
10640 struct watchpoint *w = (struct watchpoint *) bl->owner;
10641 int length = w->exact? 1 : bl->length;
10643 return target_region_ok_for_hw_watchpoint (bl->address, length);
10646 /* Implement the "works_in_software_mode" breakpoint_ops method for
10647 hardware watchpoints. */
10650 works_in_software_mode_watchpoint (const struct breakpoint *b)
10652 /* Read and access watchpoints only work with hardware support. */
10653 return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint;
10656 static enum print_stop_action
10657 print_it_watchpoint (bpstat bs)
10659 struct cleanup *old_chain;
10660 struct breakpoint *b;
10661 struct ui_file *stb;
10662 enum print_stop_action result;
10663 struct watchpoint *w;
10664 struct ui_out *uiout = current_uiout;
10666 gdb_assert (bs->bp_location_at != NULL);
10668 b = bs->breakpoint_at;
10669 w = (struct watchpoint *) b;
10671 stb = mem_fileopen ();
10672 old_chain = make_cleanup_ui_file_delete (stb);
10676 case bp_watchpoint:
10677 case bp_hardware_watchpoint:
10678 annotate_watchpoint (b->number);
10679 if (ui_out_is_mi_like_p (uiout))
10680 ui_out_field_string
10682 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
10684 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10685 ui_out_text (uiout, "\nOld value = ");
10686 watchpoint_value_print (bs->old_val, stb);
10687 ui_out_field_stream (uiout, "old", stb);
10688 ui_out_text (uiout, "\nNew value = ");
10689 watchpoint_value_print (w->val, stb);
10690 ui_out_field_stream (uiout, "new", stb);
10691 ui_out_text (uiout, "\n");
10692 /* More than one watchpoint may have been triggered. */
10693 result = PRINT_UNKNOWN;
10696 case bp_read_watchpoint:
10697 if (ui_out_is_mi_like_p (uiout))
10698 ui_out_field_string
10700 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
10702 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10703 ui_out_text (uiout, "\nValue = ");
10704 watchpoint_value_print (w->val, stb);
10705 ui_out_field_stream (uiout, "value", stb);
10706 ui_out_text (uiout, "\n");
10707 result = PRINT_UNKNOWN;
10710 case bp_access_watchpoint:
10711 if (bs->old_val != NULL)
10713 annotate_watchpoint (b->number);
10714 if (ui_out_is_mi_like_p (uiout))
10715 ui_out_field_string
10717 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10719 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10720 ui_out_text (uiout, "\nOld value = ");
10721 watchpoint_value_print (bs->old_val, stb);
10722 ui_out_field_stream (uiout, "old", stb);
10723 ui_out_text (uiout, "\nNew value = ");
10728 if (ui_out_is_mi_like_p (uiout))
10729 ui_out_field_string
10731 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10732 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10733 ui_out_text (uiout, "\nValue = ");
10735 watchpoint_value_print (w->val, stb);
10736 ui_out_field_stream (uiout, "new", stb);
10737 ui_out_text (uiout, "\n");
10738 result = PRINT_UNKNOWN;
10741 result = PRINT_UNKNOWN;
10744 do_cleanups (old_chain);
10748 /* Implement the "print_mention" breakpoint_ops method for hardware
10752 print_mention_watchpoint (struct breakpoint *b)
10754 struct cleanup *ui_out_chain;
10755 struct watchpoint *w = (struct watchpoint *) b;
10756 struct ui_out *uiout = current_uiout;
10760 case bp_watchpoint:
10761 ui_out_text (uiout, "Watchpoint ");
10762 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
10764 case bp_hardware_watchpoint:
10765 ui_out_text (uiout, "Hardware watchpoint ");
10766 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
10768 case bp_read_watchpoint:
10769 ui_out_text (uiout, "Hardware read watchpoint ");
10770 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
10772 case bp_access_watchpoint:
10773 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
10774 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
10777 internal_error (__FILE__, __LINE__,
10778 _("Invalid hardware watchpoint type."));
10781 ui_out_field_int (uiout, "number", b->number);
10782 ui_out_text (uiout, ": ");
10783 ui_out_field_string (uiout, "exp", w->exp_string);
10784 do_cleanups (ui_out_chain);
10787 /* Implement the "print_recreate" breakpoint_ops method for
10791 print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp)
10793 struct watchpoint *w = (struct watchpoint *) b;
10797 case bp_watchpoint:
10798 case bp_hardware_watchpoint:
10799 fprintf_unfiltered (fp, "watch");
10801 case bp_read_watchpoint:
10802 fprintf_unfiltered (fp, "rwatch");
10804 case bp_access_watchpoint:
10805 fprintf_unfiltered (fp, "awatch");
10808 internal_error (__FILE__, __LINE__,
10809 _("Invalid watchpoint type."));
10812 fprintf_unfiltered (fp, " %s", w->exp_string);
10813 print_recreate_thread (b, fp);
10816 /* Implement the "explains_signal" breakpoint_ops method for
10820 explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig)
10822 /* A software watchpoint cannot cause a signal other than
10823 GDB_SIGNAL_TRAP. */
10824 if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP)
10830 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10832 static struct breakpoint_ops watchpoint_breakpoint_ops;
10834 /* Implement the "insert" breakpoint_ops method for
10835 masked hardware watchpoints. */
10838 insert_masked_watchpoint (struct bp_location *bl)
10840 struct watchpoint *w = (struct watchpoint *) bl->owner;
10842 return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask,
10843 bl->watchpoint_type);
10846 /* Implement the "remove" breakpoint_ops method for
10847 masked hardware watchpoints. */
10850 remove_masked_watchpoint (struct bp_location *bl)
10852 struct watchpoint *w = (struct watchpoint *) bl->owner;
10854 return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask,
10855 bl->watchpoint_type);
10858 /* Implement the "resources_needed" breakpoint_ops method for
10859 masked hardware watchpoints. */
10862 resources_needed_masked_watchpoint (const struct bp_location *bl)
10864 struct watchpoint *w = (struct watchpoint *) bl->owner;
10866 return target_masked_watch_num_registers (bl->address, w->hw_wp_mask);
10869 /* Implement the "works_in_software_mode" breakpoint_ops method for
10870 masked hardware watchpoints. */
10873 works_in_software_mode_masked_watchpoint (const struct breakpoint *b)
10878 /* Implement the "print_it" breakpoint_ops method for
10879 masked hardware watchpoints. */
10881 static enum print_stop_action
10882 print_it_masked_watchpoint (bpstat bs)
10884 struct breakpoint *b = bs->breakpoint_at;
10885 struct ui_out *uiout = current_uiout;
10887 /* Masked watchpoints have only one location. */
10888 gdb_assert (b->loc && b->loc->next == NULL);
10892 case bp_hardware_watchpoint:
10893 annotate_watchpoint (b->number);
10894 if (ui_out_is_mi_like_p (uiout))
10895 ui_out_field_string
10897 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
10900 case bp_read_watchpoint:
10901 if (ui_out_is_mi_like_p (uiout))
10902 ui_out_field_string
10904 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
10907 case bp_access_watchpoint:
10908 if (ui_out_is_mi_like_p (uiout))
10909 ui_out_field_string
10911 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10914 internal_error (__FILE__, __LINE__,
10915 _("Invalid hardware watchpoint type."));
10919 ui_out_text (uiout, _("\n\
10920 Check the underlying instruction at PC for the memory\n\
10921 address and value which triggered this watchpoint.\n"));
10922 ui_out_text (uiout, "\n");
10924 /* More than one watchpoint may have been triggered. */
10925 return PRINT_UNKNOWN;
10928 /* Implement the "print_one_detail" breakpoint_ops method for
10929 masked hardware watchpoints. */
10932 print_one_detail_masked_watchpoint (const struct breakpoint *b,
10933 struct ui_out *uiout)
10935 struct watchpoint *w = (struct watchpoint *) b;
10937 /* Masked watchpoints have only one location. */
10938 gdb_assert (b->loc && b->loc->next == NULL);
10940 ui_out_text (uiout, "\tmask ");
10941 ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask);
10942 ui_out_text (uiout, "\n");
10945 /* Implement the "print_mention" breakpoint_ops method for
10946 masked hardware watchpoints. */
10949 print_mention_masked_watchpoint (struct breakpoint *b)
10951 struct watchpoint *w = (struct watchpoint *) b;
10952 struct ui_out *uiout = current_uiout;
10953 struct cleanup *ui_out_chain;
10957 case bp_hardware_watchpoint:
10958 ui_out_text (uiout, "Masked hardware watchpoint ");
10959 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
10961 case bp_read_watchpoint:
10962 ui_out_text (uiout, "Masked hardware read watchpoint ");
10963 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
10965 case bp_access_watchpoint:
10966 ui_out_text (uiout, "Masked hardware access (read/write) watchpoint ");
10967 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
10970 internal_error (__FILE__, __LINE__,
10971 _("Invalid hardware watchpoint type."));
10974 ui_out_field_int (uiout, "number", b->number);
10975 ui_out_text (uiout, ": ");
10976 ui_out_field_string (uiout, "exp", w->exp_string);
10977 do_cleanups (ui_out_chain);
10980 /* Implement the "print_recreate" breakpoint_ops method for
10981 masked hardware watchpoints. */
10984 print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp)
10986 struct watchpoint *w = (struct watchpoint *) b;
10991 case bp_hardware_watchpoint:
10992 fprintf_unfiltered (fp, "watch");
10994 case bp_read_watchpoint:
10995 fprintf_unfiltered (fp, "rwatch");
10997 case bp_access_watchpoint:
10998 fprintf_unfiltered (fp, "awatch");
11001 internal_error (__FILE__, __LINE__,
11002 _("Invalid hardware watchpoint type."));
11005 sprintf_vma (tmp, w->hw_wp_mask);
11006 fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp);
11007 print_recreate_thread (b, fp);
11010 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
11012 static struct breakpoint_ops masked_watchpoint_breakpoint_ops;
11014 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
11017 is_masked_watchpoint (const struct breakpoint *b)
11019 return b->ops == &masked_watchpoint_breakpoint_ops;
11022 /* accessflag: hw_write: watch write,
11023 hw_read: watch read,
11024 hw_access: watch access (read or write) */
11026 watch_command_1 (const char *arg, int accessflag, int from_tty,
11027 int just_location, int internal)
11029 volatile struct gdb_exception e;
11030 struct breakpoint *b, *scope_breakpoint = NULL;
11031 struct expression *exp;
11032 const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL;
11033 struct value *val, *mark, *result;
11034 struct frame_info *frame;
11035 const char *exp_start = NULL;
11036 const char *exp_end = NULL;
11037 const char *tok, *end_tok;
11039 const char *cond_start = NULL;
11040 const char *cond_end = NULL;
11041 enum bptype bp_type;
11044 /* Flag to indicate whether we are going to use masks for
11045 the hardware watchpoint. */
11047 CORE_ADDR mask = 0;
11048 struct watchpoint *w;
11050 struct cleanup *back_to;
11052 /* Make sure that we actually have parameters to parse. */
11053 if (arg != NULL && arg[0] != '\0')
11055 const char *value_start;
11057 exp_end = arg + strlen (arg);
11059 /* Look for "parameter value" pairs at the end
11060 of the arguments string. */
11061 for (tok = exp_end - 1; tok > arg; tok--)
11063 /* Skip whitespace at the end of the argument list. */
11064 while (tok > arg && (*tok == ' ' || *tok == '\t'))
11067 /* Find the beginning of the last token.
11068 This is the value of the parameter. */
11069 while (tok > arg && (*tok != ' ' && *tok != '\t'))
11071 value_start = tok + 1;
11073 /* Skip whitespace. */
11074 while (tok > arg && (*tok == ' ' || *tok == '\t'))
11079 /* Find the beginning of the second to last token.
11080 This is the parameter itself. */
11081 while (tok > arg && (*tok != ' ' && *tok != '\t'))
11084 toklen = end_tok - tok + 1;
11086 if (toklen == 6 && !strncmp (tok, "thread", 6))
11088 /* At this point we've found a "thread" token, which means
11089 the user is trying to set a watchpoint that triggers
11090 only in a specific thread. */
11094 error(_("You can specify only one thread."));
11096 /* Extract the thread ID from the next token. */
11097 thread = strtol (value_start, &endp, 0);
11099 /* Check if the user provided a valid numeric value for the
11101 if (*endp != ' ' && *endp != '\t' && *endp != '\0')
11102 error (_("Invalid thread ID specification %s."), value_start);
11104 /* Check if the thread actually exists. */
11105 if (!valid_thread_id (thread))
11106 invalid_thread_id_error (thread);
11108 else if (toklen == 4 && !strncmp (tok, "mask", 4))
11110 /* We've found a "mask" token, which means the user wants to
11111 create a hardware watchpoint that is going to have the mask
11113 struct value *mask_value, *mark;
11116 error(_("You can specify only one mask."));
11118 use_mask = just_location = 1;
11120 mark = value_mark ();
11121 mask_value = parse_to_comma_and_eval (&value_start);
11122 mask = value_as_address (mask_value);
11123 value_free_to_mark (mark);
11126 /* We didn't recognize what we found. We should stop here. */
11129 /* Truncate the string and get rid of the "parameter value" pair before
11130 the arguments string is parsed by the parse_exp_1 function. */
11137 /* Parse the rest of the arguments. From here on out, everything
11138 is in terms of a newly allocated string instead of the original
11140 innermost_block = NULL;
11141 expression = savestring (arg, exp_end - arg);
11142 back_to = make_cleanup (xfree, expression);
11143 exp_start = arg = expression;
11144 exp = parse_exp_1 (&arg, 0, 0, 0);
11146 /* Remove trailing whitespace from the expression before saving it.
11147 This makes the eventual display of the expression string a bit
11149 while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t'))
11152 /* Checking if the expression is not constant. */
11153 if (watchpoint_exp_is_const (exp))
11157 len = exp_end - exp_start;
11158 while (len > 0 && isspace (exp_start[len - 1]))
11160 error (_("Cannot watch constant value `%.*s'."), len, exp_start);
11163 exp_valid_block = innermost_block;
11164 mark = value_mark ();
11165 fetch_subexp_value (exp, &pc, &val, &result, NULL, just_location);
11171 exp_valid_block = NULL;
11172 val = value_addr (result);
11173 release_value (val);
11174 value_free_to_mark (mark);
11178 ret = target_masked_watch_num_registers (value_as_address (val),
11181 error (_("This target does not support masked watchpoints."));
11182 else if (ret == -2)
11183 error (_("Invalid mask or memory region."));
11186 else if (val != NULL)
11187 release_value (val);
11189 tok = skip_spaces_const (arg);
11190 end_tok = skip_to_space_const (tok);
11192 toklen = end_tok - tok;
11193 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
11195 struct expression *cond;
11197 innermost_block = NULL;
11198 tok = cond_start = end_tok + 1;
11199 cond = parse_exp_1 (&tok, 0, 0, 0);
11201 /* The watchpoint expression may not be local, but the condition
11202 may still be. E.g.: `watch global if local > 0'. */
11203 cond_exp_valid_block = innermost_block;
11209 error (_("Junk at end of command."));
11211 frame = block_innermost_frame (exp_valid_block);
11213 /* If the expression is "local", then set up a "watchpoint scope"
11214 breakpoint at the point where we've left the scope of the watchpoint
11215 expression. Create the scope breakpoint before the watchpoint, so
11216 that we will encounter it first in bpstat_stop_status. */
11217 if (exp_valid_block && frame)
11219 if (frame_id_p (frame_unwind_caller_id (frame)))
11222 = create_internal_breakpoint (frame_unwind_caller_arch (frame),
11223 frame_unwind_caller_pc (frame),
11224 bp_watchpoint_scope,
11225 &momentary_breakpoint_ops);
11227 scope_breakpoint->enable_state = bp_enabled;
11229 /* Automatically delete the breakpoint when it hits. */
11230 scope_breakpoint->disposition = disp_del;
11232 /* Only break in the proper frame (help with recursion). */
11233 scope_breakpoint->frame_id = frame_unwind_caller_id (frame);
11235 /* Set the address at which we will stop. */
11236 scope_breakpoint->loc->gdbarch
11237 = frame_unwind_caller_arch (frame);
11238 scope_breakpoint->loc->requested_address
11239 = frame_unwind_caller_pc (frame);
11240 scope_breakpoint->loc->address
11241 = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch,
11242 scope_breakpoint->loc->requested_address,
11243 scope_breakpoint->type);
11247 /* Now set up the breakpoint. We create all watchpoints as hardware
11248 watchpoints here even if hardware watchpoints are turned off, a call
11249 to update_watchpoint later in this function will cause the type to
11250 drop back to bp_watchpoint (software watchpoint) if required. */
11252 if (accessflag == hw_read)
11253 bp_type = bp_read_watchpoint;
11254 else if (accessflag == hw_access)
11255 bp_type = bp_access_watchpoint;
11257 bp_type = bp_hardware_watchpoint;
11259 w = XCNEW (struct watchpoint);
11262 init_raw_breakpoint_without_location (b, NULL, bp_type,
11263 &masked_watchpoint_breakpoint_ops);
11265 init_raw_breakpoint_without_location (b, NULL, bp_type,
11266 &watchpoint_breakpoint_ops);
11267 b->thread = thread;
11268 b->disposition = disp_donttouch;
11269 b->pspace = current_program_space;
11271 w->exp_valid_block = exp_valid_block;
11272 w->cond_exp_valid_block = cond_exp_valid_block;
11275 struct type *t = value_type (val);
11276 CORE_ADDR addr = value_as_address (val);
11279 t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t)));
11280 name = type_to_string (t);
11282 w->exp_string_reparse = xstrprintf ("* (%s *) %s", name,
11283 core_addr_to_string (addr));
11286 w->exp_string = xstrprintf ("-location %.*s",
11287 (int) (exp_end - exp_start), exp_start);
11289 /* The above expression is in C. */
11290 b->language = language_c;
11293 w->exp_string = savestring (exp_start, exp_end - exp_start);
11297 w->hw_wp_mask = mask;
11306 b->cond_string = savestring (cond_start, cond_end - cond_start);
11308 b->cond_string = 0;
11312 w->watchpoint_frame = get_frame_id (frame);
11313 w->watchpoint_thread = inferior_ptid;
11317 w->watchpoint_frame = null_frame_id;
11318 w->watchpoint_thread = null_ptid;
11321 if (scope_breakpoint != NULL)
11323 /* The scope breakpoint is related to the watchpoint. We will
11324 need to act on them together. */
11325 b->related_breakpoint = scope_breakpoint;
11326 scope_breakpoint->related_breakpoint = b;
11329 if (!just_location)
11330 value_free_to_mark (mark);
11332 TRY_CATCH (e, RETURN_MASK_ALL)
11334 /* Finally update the new watchpoint. This creates the locations
11335 that should be inserted. */
11336 update_watchpoint (w, 1);
11340 delete_breakpoint (b);
11341 throw_exception (e);
11344 install_breakpoint (internal, b, 1);
11345 do_cleanups (back_to);
11348 /* Return count of debug registers needed to watch the given expression.
11349 If the watchpoint cannot be handled in hardware return zero. */
11352 can_use_hardware_watchpoint (struct value *v)
11354 int found_memory_cnt = 0;
11355 struct value *head = v;
11357 /* Did the user specifically forbid us to use hardware watchpoints? */
11358 if (!can_use_hw_watchpoints)
11361 /* Make sure that the value of the expression depends only upon
11362 memory contents, and values computed from them within GDB. If we
11363 find any register references or function calls, we can't use a
11364 hardware watchpoint.
11366 The idea here is that evaluating an expression generates a series
11367 of values, one holding the value of every subexpression. (The
11368 expression a*b+c has five subexpressions: a, b, a*b, c, and
11369 a*b+c.) GDB's values hold almost enough information to establish
11370 the criteria given above --- they identify memory lvalues,
11371 register lvalues, computed values, etcetera. So we can evaluate
11372 the expression, and then scan the chain of values that leaves
11373 behind to decide whether we can detect any possible change to the
11374 expression's final value using only hardware watchpoints.
11376 However, I don't think that the values returned by inferior
11377 function calls are special in any way. So this function may not
11378 notice that an expression involving an inferior function call
11379 can't be watched with hardware watchpoints. FIXME. */
11380 for (; v; v = value_next (v))
11382 if (VALUE_LVAL (v) == lval_memory)
11384 if (v != head && value_lazy (v))
11385 /* A lazy memory lvalue in the chain is one that GDB never
11386 needed to fetch; we either just used its address (e.g.,
11387 `a' in `a.b') or we never needed it at all (e.g., `a'
11388 in `a,b'). This doesn't apply to HEAD; if that is
11389 lazy then it was not readable, but watch it anyway. */
11393 /* Ahh, memory we actually used! Check if we can cover
11394 it with hardware watchpoints. */
11395 struct type *vtype = check_typedef (value_type (v));
11397 /* We only watch structs and arrays if user asked for it
11398 explicitly, never if they just happen to appear in a
11399 middle of some value chain. */
11401 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
11402 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
11404 CORE_ADDR vaddr = value_address (v);
11408 len = (target_exact_watchpoints
11409 && is_scalar_type_recursive (vtype))?
11410 1 : TYPE_LENGTH (value_type (v));
11412 num_regs = target_region_ok_for_hw_watchpoint (vaddr, len);
11416 found_memory_cnt += num_regs;
11420 else if (VALUE_LVAL (v) != not_lval
11421 && deprecated_value_modifiable (v) == 0)
11422 return 0; /* These are values from the history (e.g., $1). */
11423 else if (VALUE_LVAL (v) == lval_register)
11424 return 0; /* Cannot watch a register with a HW watchpoint. */
11427 /* The expression itself looks suitable for using a hardware
11428 watchpoint, but give the target machine a chance to reject it. */
11429 return found_memory_cnt;
11433 watch_command_wrapper (char *arg, int from_tty, int internal)
11435 watch_command_1 (arg, hw_write, from_tty, 0, internal);
11438 /* A helper function that looks for the "-location" argument and then
11439 calls watch_command_1. */
11442 watch_maybe_just_location (char *arg, int accessflag, int from_tty)
11444 int just_location = 0;
11447 && (check_for_argument (&arg, "-location", sizeof ("-location") - 1)
11448 || check_for_argument (&arg, "-l", sizeof ("-l") - 1)))
11450 arg = skip_spaces (arg);
11454 watch_command_1 (arg, accessflag, from_tty, just_location, 0);
11458 watch_command (char *arg, int from_tty)
11460 watch_maybe_just_location (arg, hw_write, from_tty);
11464 rwatch_command_wrapper (char *arg, int from_tty, int internal)
11466 watch_command_1 (arg, hw_read, from_tty, 0, internal);
11470 rwatch_command (char *arg, int from_tty)
11472 watch_maybe_just_location (arg, hw_read, from_tty);
11476 awatch_command_wrapper (char *arg, int from_tty, int internal)
11478 watch_command_1 (arg, hw_access, from_tty, 0, internal);
11482 awatch_command (char *arg, int from_tty)
11484 watch_maybe_just_location (arg, hw_access, from_tty);
11488 /* Helper routines for the until_command routine in infcmd.c. Here
11489 because it uses the mechanisms of breakpoints. */
11491 struct until_break_command_continuation_args
11493 struct breakpoint *breakpoint;
11494 struct breakpoint *breakpoint2;
11498 /* This function is called by fetch_inferior_event via the
11499 cmd_continuation pointer, to complete the until command. It takes
11500 care of cleaning up the temporary breakpoints set up by the until
11503 until_break_command_continuation (void *arg, int err)
11505 struct until_break_command_continuation_args *a = arg;
11507 delete_breakpoint (a->breakpoint);
11508 if (a->breakpoint2)
11509 delete_breakpoint (a->breakpoint2);
11510 delete_longjmp_breakpoint (a->thread_num);
11514 until_break_command (char *arg, int from_tty, int anywhere)
11516 struct symtabs_and_lines sals;
11517 struct symtab_and_line sal;
11518 struct frame_info *frame;
11519 struct gdbarch *frame_gdbarch;
11520 struct frame_id stack_frame_id;
11521 struct frame_id caller_frame_id;
11522 struct breakpoint *breakpoint;
11523 struct breakpoint *breakpoint2 = NULL;
11524 struct cleanup *old_chain;
11526 struct thread_info *tp;
11528 clear_proceed_status ();
11530 /* Set a breakpoint where the user wants it and at return from
11533 if (last_displayed_sal_is_valid ())
11534 sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE,
11535 get_last_displayed_symtab (),
11536 get_last_displayed_line ());
11538 sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE,
11539 (struct symtab *) NULL, 0);
11541 if (sals.nelts != 1)
11542 error (_("Couldn't get information on specified line."));
11544 sal = sals.sals[0];
11545 xfree (sals.sals); /* malloc'd, so freed. */
11548 error (_("Junk at end of arguments."));
11550 resolve_sal_pc (&sal);
11552 tp = inferior_thread ();
11555 old_chain = make_cleanup (null_cleanup, NULL);
11557 /* Note linespec handling above invalidates the frame chain.
11558 Installing a breakpoint also invalidates the frame chain (as it
11559 may need to switch threads), so do any frame handling before
11562 frame = get_selected_frame (NULL);
11563 frame_gdbarch = get_frame_arch (frame);
11564 stack_frame_id = get_stack_frame_id (frame);
11565 caller_frame_id = frame_unwind_caller_id (frame);
11567 /* Keep within the current frame, or in frames called by the current
11570 if (frame_id_p (caller_frame_id))
11572 struct symtab_and_line sal2;
11574 sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0);
11575 sal2.pc = frame_unwind_caller_pc (frame);
11576 breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame),
11580 make_cleanup_delete_breakpoint (breakpoint2);
11582 set_longjmp_breakpoint (tp, caller_frame_id);
11583 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
11586 /* set_momentary_breakpoint could invalidate FRAME. */
11590 /* If the user told us to continue until a specified location,
11591 we don't specify a frame at which we need to stop. */
11592 breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
11593 null_frame_id, bp_until);
11595 /* Otherwise, specify the selected frame, because we want to stop
11596 only at the very same frame. */
11597 breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
11598 stack_frame_id, bp_until);
11599 make_cleanup_delete_breakpoint (breakpoint);
11601 proceed (-1, GDB_SIGNAL_DEFAULT, 0);
11603 /* If we are running asynchronously, and proceed call above has
11604 actually managed to start the target, arrange for breakpoints to
11605 be deleted when the target stops. Otherwise, we're already
11606 stopped and delete breakpoints via cleanup chain. */
11608 if (target_can_async_p () && is_running (inferior_ptid))
11610 struct until_break_command_continuation_args *args;
11611 args = xmalloc (sizeof (*args));
11613 args->breakpoint = breakpoint;
11614 args->breakpoint2 = breakpoint2;
11615 args->thread_num = thread;
11617 discard_cleanups (old_chain);
11618 add_continuation (inferior_thread (),
11619 until_break_command_continuation, args,
11623 do_cleanups (old_chain);
11626 /* This function attempts to parse an optional "if <cond>" clause
11627 from the arg string. If one is not found, it returns NULL.
11629 Else, it returns a pointer to the condition string. (It does not
11630 attempt to evaluate the string against a particular block.) And,
11631 it updates arg to point to the first character following the parsed
11632 if clause in the arg string. */
11635 ep_parse_optional_if_clause (char **arg)
11639 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
11642 /* Skip the "if" keyword. */
11645 /* Skip any extra leading whitespace, and record the start of the
11646 condition string. */
11647 *arg = skip_spaces (*arg);
11648 cond_string = *arg;
11650 /* Assume that the condition occupies the remainder of the arg
11652 (*arg) += strlen (cond_string);
11654 return cond_string;
11657 /* Commands to deal with catching events, such as signals, exceptions,
11658 process start/exit, etc. */
11662 catch_fork_temporary, catch_vfork_temporary,
11663 catch_fork_permanent, catch_vfork_permanent
11668 catch_fork_command_1 (char *arg, int from_tty,
11669 struct cmd_list_element *command)
11671 struct gdbarch *gdbarch = get_current_arch ();
11672 char *cond_string = NULL;
11673 catch_fork_kind fork_kind;
11676 fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command);
11677 tempflag = (fork_kind == catch_fork_temporary
11678 || fork_kind == catch_vfork_temporary);
11682 arg = skip_spaces (arg);
11684 /* The allowed syntax is:
11686 catch [v]fork if <cond>
11688 First, check if there's an if clause. */
11689 cond_string = ep_parse_optional_if_clause (&arg);
11691 if ((*arg != '\0') && !isspace (*arg))
11692 error (_("Junk at end of arguments."));
11694 /* If this target supports it, create a fork or vfork catchpoint
11695 and enable reporting of such events. */
11698 case catch_fork_temporary:
11699 case catch_fork_permanent:
11700 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
11701 &catch_fork_breakpoint_ops);
11703 case catch_vfork_temporary:
11704 case catch_vfork_permanent:
11705 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
11706 &catch_vfork_breakpoint_ops);
11709 error (_("unsupported or unknown fork kind; cannot catch it"));
11715 catch_exec_command_1 (char *arg, int from_tty,
11716 struct cmd_list_element *command)
11718 struct exec_catchpoint *c;
11719 struct gdbarch *gdbarch = get_current_arch ();
11721 char *cond_string = NULL;
11723 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11727 arg = skip_spaces (arg);
11729 /* The allowed syntax is:
11731 catch exec if <cond>
11733 First, check if there's an if clause. */
11734 cond_string = ep_parse_optional_if_clause (&arg);
11736 if ((*arg != '\0') && !isspace (*arg))
11737 error (_("Junk at end of arguments."));
11739 c = XNEW (struct exec_catchpoint);
11740 init_catchpoint (&c->base, gdbarch, tempflag, cond_string,
11741 &catch_exec_breakpoint_ops);
11742 c->exec_pathname = NULL;
11744 install_breakpoint (0, &c->base, 1);
11748 init_ada_exception_breakpoint (struct breakpoint *b,
11749 struct gdbarch *gdbarch,
11750 struct symtab_and_line sal,
11752 const struct breakpoint_ops *ops,
11759 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
11761 loc_gdbarch = gdbarch;
11763 describe_other_breakpoints (loc_gdbarch,
11764 sal.pspace, sal.pc, sal.section, -1);
11765 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11766 version for exception catchpoints, because two catchpoints
11767 used for different exception names will use the same address.
11768 In this case, a "breakpoint ... also set at..." warning is
11769 unproductive. Besides, the warning phrasing is also a bit
11770 inappropriate, we should use the word catchpoint, and tell
11771 the user what type of catchpoint it is. The above is good
11772 enough for now, though. */
11775 init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops);
11777 b->enable_state = enabled ? bp_enabled : bp_disabled;
11778 b->disposition = tempflag ? disp_del : disp_donttouch;
11779 b->addr_string = addr_string;
11780 b->language = language_ada;
11783 /* Splits the argument using space as delimiter. Returns an xmalloc'd
11784 filter list, or NULL if no filtering is required. */
11786 catch_syscall_split_args (char *arg)
11788 VEC(int) *result = NULL;
11789 struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result);
11791 while (*arg != '\0')
11793 int i, syscall_number;
11795 char cur_name[128];
11798 /* Skip whitespace. */
11799 arg = skip_spaces (arg);
11801 for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i)
11802 cur_name[i] = arg[i];
11803 cur_name[i] = '\0';
11806 /* Check if the user provided a syscall name or a number. */
11807 syscall_number = (int) strtol (cur_name, &endptr, 0);
11808 if (*endptr == '\0')
11809 get_syscall_by_number (syscall_number, &s);
11812 /* We have a name. Let's check if it's valid and convert it
11814 get_syscall_by_name (cur_name, &s);
11816 if (s.number == UNKNOWN_SYSCALL)
11817 /* Here we have to issue an error instead of a warning,
11818 because GDB cannot do anything useful if there's no
11819 syscall number to be caught. */
11820 error (_("Unknown syscall name '%s'."), cur_name);
11823 /* Ok, it's valid. */
11824 VEC_safe_push (int, result, s.number);
11827 discard_cleanups (cleanup);
11831 /* Implement the "catch syscall" command. */
11834 catch_syscall_command_1 (char *arg, int from_tty,
11835 struct cmd_list_element *command)
11840 struct gdbarch *gdbarch = get_current_arch ();
11842 /* Checking if the feature if supported. */
11843 if (gdbarch_get_syscall_number_p (gdbarch) == 0)
11844 error (_("The feature 'catch syscall' is not supported on \
11845 this architecture yet."));
11847 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11849 arg = skip_spaces (arg);
11851 /* We need to do this first "dummy" translation in order
11852 to get the syscall XML file loaded or, most important,
11853 to display a warning to the user if there's no XML file
11854 for his/her architecture. */
11855 get_syscall_by_number (0, &s);
11857 /* The allowed syntax is:
11859 catch syscall <name | number> [<name | number> ... <name | number>]
11861 Let's check if there's a syscall name. */
11864 filter = catch_syscall_split_args (arg);
11868 create_syscall_event_catchpoint (tempflag, filter,
11869 &catch_syscall_breakpoint_ops);
11873 catch_command (char *arg, int from_tty)
11875 error (_("Catch requires an event name."));
11880 tcatch_command (char *arg, int from_tty)
11882 error (_("Catch requires an event name."));
11885 /* A qsort comparison function that sorts breakpoints in order. */
11888 compare_breakpoints (const void *a, const void *b)
11890 const breakpoint_p *ba = a;
11891 uintptr_t ua = (uintptr_t) *ba;
11892 const breakpoint_p *bb = b;
11893 uintptr_t ub = (uintptr_t) *bb;
11895 if ((*ba)->number < (*bb)->number)
11897 else if ((*ba)->number > (*bb)->number)
11900 /* Now sort by address, in case we see, e..g, two breakpoints with
11904 return ua > ub ? 1 : 0;
11907 /* Delete breakpoints by address or line. */
11910 clear_command (char *arg, int from_tty)
11912 struct breakpoint *b, *prev;
11913 VEC(breakpoint_p) *found = 0;
11916 struct symtabs_and_lines sals;
11917 struct symtab_and_line sal;
11919 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
11923 sals = decode_line_with_current_source (arg,
11924 (DECODE_LINE_FUNFIRSTLINE
11925 | DECODE_LINE_LIST_MODE));
11926 make_cleanup (xfree, sals.sals);
11931 sals.sals = (struct symtab_and_line *)
11932 xmalloc (sizeof (struct symtab_and_line));
11933 make_cleanup (xfree, sals.sals);
11934 init_sal (&sal); /* Initialize to zeroes. */
11936 /* Set sal's line, symtab, pc, and pspace to the values
11937 corresponding to the last call to print_frame_info. If the
11938 codepoint is not valid, this will set all the fields to 0. */
11939 get_last_displayed_sal (&sal);
11940 if (sal.symtab == 0)
11941 error (_("No source file specified."));
11943 sals.sals[0] = sal;
11949 /* We don't call resolve_sal_pc here. That's not as bad as it
11950 seems, because all existing breakpoints typically have both
11951 file/line and pc set. So, if clear is given file/line, we can
11952 match this to existing breakpoint without obtaining pc at all.
11954 We only support clearing given the address explicitly
11955 present in breakpoint table. Say, we've set breakpoint
11956 at file:line. There were several PC values for that file:line,
11957 due to optimization, all in one block.
11959 We've picked one PC value. If "clear" is issued with another
11960 PC corresponding to the same file:line, the breakpoint won't
11961 be cleared. We probably can still clear the breakpoint, but
11962 since the other PC value is never presented to user, user
11963 can only find it by guessing, and it does not seem important
11964 to support that. */
11966 /* For each line spec given, delete bps which correspond to it. Do
11967 it in two passes, solely to preserve the current behavior that
11968 from_tty is forced true if we delete more than one
11972 make_cleanup (VEC_cleanup (breakpoint_p), &found);
11973 for (i = 0; i < sals.nelts; i++)
11975 const char *sal_fullname;
11977 /* If exact pc given, clear bpts at that pc.
11978 If line given (pc == 0), clear all bpts on specified line.
11979 If defaulting, clear all bpts on default line
11982 defaulting sal.pc != 0 tests to do
11987 1 0 <can't happen> */
11989 sal = sals.sals[i];
11990 sal_fullname = (sal.symtab == NULL
11991 ? NULL : symtab_to_fullname (sal.symtab));
11993 /* Find all matching breakpoints and add them to 'found'. */
11994 ALL_BREAKPOINTS (b)
11997 /* Are we going to delete b? */
11998 if (b->type != bp_none && !is_watchpoint (b))
12000 struct bp_location *loc = b->loc;
12001 for (; loc; loc = loc->next)
12003 /* If the user specified file:line, don't allow a PC
12004 match. This matches historical gdb behavior. */
12005 int pc_match = (!sal.explicit_line
12007 && (loc->pspace == sal.pspace)
12008 && (loc->address == sal.pc)
12009 && (!section_is_overlay (loc->section)
12010 || loc->section == sal.section));
12011 int line_match = 0;
12013 if ((default_match || sal.explicit_line)
12014 && loc->symtab != NULL
12015 && sal_fullname != NULL
12016 && sal.pspace == loc->pspace
12017 && loc->line_number == sal.line
12018 && filename_cmp (symtab_to_fullname (loc->symtab),
12019 sal_fullname) == 0)
12022 if (pc_match || line_match)
12031 VEC_safe_push(breakpoint_p, found, b);
12035 /* Now go thru the 'found' chain and delete them. */
12036 if (VEC_empty(breakpoint_p, found))
12039 error (_("No breakpoint at %s."), arg);
12041 error (_("No breakpoint at this line."));
12044 /* Remove duplicates from the vec. */
12045 qsort (VEC_address (breakpoint_p, found),
12046 VEC_length (breakpoint_p, found),
12047 sizeof (breakpoint_p),
12048 compare_breakpoints);
12049 prev = VEC_index (breakpoint_p, found, 0);
12050 for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix)
12054 VEC_ordered_remove (breakpoint_p, found, ix);
12059 if (VEC_length(breakpoint_p, found) > 1)
12060 from_tty = 1; /* Always report if deleted more than one. */
12063 if (VEC_length(breakpoint_p, found) == 1)
12064 printf_unfiltered (_("Deleted breakpoint "));
12066 printf_unfiltered (_("Deleted breakpoints "));
12069 for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++)
12072 printf_unfiltered ("%d ", b->number);
12073 delete_breakpoint (b);
12076 putchar_unfiltered ('\n');
12078 do_cleanups (cleanups);
12081 /* Delete breakpoint in BS if they are `delete' breakpoints and
12082 all breakpoints that are marked for deletion, whether hit or not.
12083 This is called after any breakpoint is hit, or after errors. */
12086 breakpoint_auto_delete (bpstat bs)
12088 struct breakpoint *b, *b_tmp;
12090 for (; bs; bs = bs->next)
12091 if (bs->breakpoint_at
12092 && bs->breakpoint_at->disposition == disp_del
12094 delete_breakpoint (bs->breakpoint_at);
12096 ALL_BREAKPOINTS_SAFE (b, b_tmp)
12098 if (b->disposition == disp_del_at_next_stop)
12099 delete_breakpoint (b);
12103 /* A comparison function for bp_location AP and BP being interfaced to
12104 qsort. Sort elements primarily by their ADDRESS (no matter what
12105 does breakpoint_address_is_meaningful say for its OWNER),
12106 secondarily by ordering first bp_permanent OWNERed elements and
12107 terciarily just ensuring the array is sorted stable way despite
12108 qsort being an unstable algorithm. */
12111 bp_location_compare (const void *ap, const void *bp)
12113 struct bp_location *a = *(void **) ap;
12114 struct bp_location *b = *(void **) bp;
12115 /* A and B come from existing breakpoints having non-NULL OWNER. */
12116 int a_perm = a->owner->enable_state == bp_permanent;
12117 int b_perm = b->owner->enable_state == bp_permanent;
12119 if (a->address != b->address)
12120 return (a->address > b->address) - (a->address < b->address);
12122 /* Sort locations at the same address by their pspace number, keeping
12123 locations of the same inferior (in a multi-inferior environment)
12126 if (a->pspace->num != b->pspace->num)
12127 return ((a->pspace->num > b->pspace->num)
12128 - (a->pspace->num < b->pspace->num));
12130 /* Sort permanent breakpoints first. */
12131 if (a_perm != b_perm)
12132 return (a_perm < b_perm) - (a_perm > b_perm);
12134 /* Make the internal GDB representation stable across GDB runs
12135 where A and B memory inside GDB can differ. Breakpoint locations of
12136 the same type at the same address can be sorted in arbitrary order. */
12138 if (a->owner->number != b->owner->number)
12139 return ((a->owner->number > b->owner->number)
12140 - (a->owner->number < b->owner->number));
12142 return (a > b) - (a < b);
12145 /* Set bp_location_placed_address_before_address_max and
12146 bp_location_shadow_len_after_address_max according to the current
12147 content of the bp_location array. */
12150 bp_location_target_extensions_update (void)
12152 struct bp_location *bl, **blp_tmp;
12154 bp_location_placed_address_before_address_max = 0;
12155 bp_location_shadow_len_after_address_max = 0;
12157 ALL_BP_LOCATIONS (bl, blp_tmp)
12159 CORE_ADDR start, end, addr;
12161 if (!bp_location_has_shadow (bl))
12164 start = bl->target_info.placed_address;
12165 end = start + bl->target_info.shadow_len;
12167 gdb_assert (bl->address >= start);
12168 addr = bl->address - start;
12169 if (addr > bp_location_placed_address_before_address_max)
12170 bp_location_placed_address_before_address_max = addr;
12172 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
12174 gdb_assert (bl->address < end);
12175 addr = end - bl->address;
12176 if (addr > bp_location_shadow_len_after_address_max)
12177 bp_location_shadow_len_after_address_max = addr;
12181 /* Download tracepoint locations if they haven't been. */
12184 download_tracepoint_locations (void)
12186 struct breakpoint *b;
12187 struct cleanup *old_chain;
12189 if (!target_can_download_tracepoint ())
12192 old_chain = save_current_space_and_thread ();
12194 ALL_TRACEPOINTS (b)
12196 struct bp_location *bl;
12197 struct tracepoint *t;
12198 int bp_location_downloaded = 0;
12200 if ((b->type == bp_fast_tracepoint
12201 ? !may_insert_fast_tracepoints
12202 : !may_insert_tracepoints))
12205 for (bl = b->loc; bl; bl = bl->next)
12207 /* In tracepoint, locations are _never_ duplicated, so
12208 should_be_inserted is equivalent to
12209 unduplicated_should_be_inserted. */
12210 if (!should_be_inserted (bl) || bl->inserted)
12213 switch_to_program_space_and_thread (bl->pspace);
12215 target_download_tracepoint (bl);
12218 bp_location_downloaded = 1;
12220 t = (struct tracepoint *) b;
12221 t->number_on_target = b->number;
12222 if (bp_location_downloaded)
12223 observer_notify_breakpoint_modified (b);
12226 do_cleanups (old_chain);
12229 /* Swap the insertion/duplication state between two locations. */
12232 swap_insertion (struct bp_location *left, struct bp_location *right)
12234 const int left_inserted = left->inserted;
12235 const int left_duplicate = left->duplicate;
12236 const int left_needs_update = left->needs_update;
12237 const struct bp_target_info left_target_info = left->target_info;
12239 /* Locations of tracepoints can never be duplicated. */
12240 if (is_tracepoint (left->owner))
12241 gdb_assert (!left->duplicate);
12242 if (is_tracepoint (right->owner))
12243 gdb_assert (!right->duplicate);
12245 left->inserted = right->inserted;
12246 left->duplicate = right->duplicate;
12247 left->needs_update = right->needs_update;
12248 left->target_info = right->target_info;
12249 right->inserted = left_inserted;
12250 right->duplicate = left_duplicate;
12251 right->needs_update = left_needs_update;
12252 right->target_info = left_target_info;
12255 /* Force the re-insertion of the locations at ADDRESS. This is called
12256 once a new/deleted/modified duplicate location is found and we are evaluating
12257 conditions on the target's side. Such conditions need to be updated on
12261 force_breakpoint_reinsertion (struct bp_location *bl)
12263 struct bp_location **locp = NULL, **loc2p;
12264 struct bp_location *loc;
12265 CORE_ADDR address = 0;
12268 address = bl->address;
12269 pspace_num = bl->pspace->num;
12271 /* This is only meaningful if the target is
12272 evaluating conditions and if the user has
12273 opted for condition evaluation on the target's
12275 if (gdb_evaluates_breakpoint_condition_p ()
12276 || !target_supports_evaluation_of_breakpoint_conditions ())
12279 /* Flag all breakpoint locations with this address and
12280 the same program space as the location
12281 as "its condition has changed". We need to
12282 update the conditions on the target's side. */
12283 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address)
12287 if (!is_breakpoint (loc->owner)
12288 || pspace_num != loc->pspace->num)
12291 /* Flag the location appropriately. We use a different state to
12292 let everyone know that we already updated the set of locations
12293 with addr bl->address and program space bl->pspace. This is so
12294 we don't have to keep calling these functions just to mark locations
12295 that have already been marked. */
12296 loc->condition_changed = condition_updated;
12298 /* Free the agent expression bytecode as well. We will compute
12300 if (loc->cond_bytecode)
12302 free_agent_expr (loc->cond_bytecode);
12303 loc->cond_bytecode = NULL;
12308 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
12309 into the inferior, only remove already-inserted locations that no
12310 longer should be inserted. Functions that delete a breakpoint or
12311 breakpoints should pass false, so that deleting a breakpoint
12312 doesn't have the side effect of inserting the locations of other
12313 breakpoints that are marked not-inserted, but should_be_inserted
12314 returns true on them.
12316 This behaviour is useful is situations close to tear-down -- e.g.,
12317 after an exec, while the target still has execution, but breakpoint
12318 shadows of the previous executable image should *NOT* be restored
12319 to the new image; or before detaching, where the target still has
12320 execution and wants to delete breakpoints from GDB's lists, and all
12321 breakpoints had already been removed from the inferior. */
12324 update_global_location_list (int should_insert)
12326 struct breakpoint *b;
12327 struct bp_location **locp, *loc;
12328 struct cleanup *cleanups;
12329 /* Last breakpoint location address that was marked for update. */
12330 CORE_ADDR last_addr = 0;
12331 /* Last breakpoint location program space that was marked for update. */
12332 int last_pspace_num = -1;
12334 /* Used in the duplicates detection below. When iterating over all
12335 bp_locations, points to the first bp_location of a given address.
12336 Breakpoints and watchpoints of different types are never
12337 duplicates of each other. Keep one pointer for each type of
12338 breakpoint/watchpoint, so we only need to loop over all locations
12340 struct bp_location *bp_loc_first; /* breakpoint */
12341 struct bp_location *wp_loc_first; /* hardware watchpoint */
12342 struct bp_location *awp_loc_first; /* access watchpoint */
12343 struct bp_location *rwp_loc_first; /* read watchpoint */
12345 /* Saved former bp_location array which we compare against the newly
12346 built bp_location from the current state of ALL_BREAKPOINTS. */
12347 struct bp_location **old_location, **old_locp;
12348 unsigned old_location_count;
12350 old_location = bp_location;
12351 old_location_count = bp_location_count;
12352 bp_location = NULL;
12353 bp_location_count = 0;
12354 cleanups = make_cleanup (xfree, old_location);
12356 ALL_BREAKPOINTS (b)
12357 for (loc = b->loc; loc; loc = loc->next)
12358 bp_location_count++;
12360 bp_location = xmalloc (sizeof (*bp_location) * bp_location_count);
12361 locp = bp_location;
12362 ALL_BREAKPOINTS (b)
12363 for (loc = b->loc; loc; loc = loc->next)
12365 qsort (bp_location, bp_location_count, sizeof (*bp_location),
12366 bp_location_compare);
12368 bp_location_target_extensions_update ();
12370 /* Identify bp_location instances that are no longer present in the
12371 new list, and therefore should be freed. Note that it's not
12372 necessary that those locations should be removed from inferior --
12373 if there's another location at the same address (previously
12374 marked as duplicate), we don't need to remove/insert the
12377 LOCP is kept in sync with OLD_LOCP, each pointing to the current
12378 and former bp_location array state respectively. */
12380 locp = bp_location;
12381 for (old_locp = old_location; old_locp < old_location + old_location_count;
12384 struct bp_location *old_loc = *old_locp;
12385 struct bp_location **loc2p;
12387 /* Tells if 'old_loc' is found among the new locations. If
12388 not, we have to free it. */
12389 int found_object = 0;
12390 /* Tells if the location should remain inserted in the target. */
12391 int keep_in_target = 0;
12394 /* Skip LOCP entries which will definitely never be needed.
12395 Stop either at or being the one matching OLD_LOC. */
12396 while (locp < bp_location + bp_location_count
12397 && (*locp)->address < old_loc->address)
12401 (loc2p < bp_location + bp_location_count
12402 && (*loc2p)->address == old_loc->address);
12405 /* Check if this is a new/duplicated location or a duplicated
12406 location that had its condition modified. If so, we want to send
12407 its condition to the target if evaluation of conditions is taking
12409 if ((*loc2p)->condition_changed == condition_modified
12410 && (last_addr != old_loc->address
12411 || last_pspace_num != old_loc->pspace->num))
12413 force_breakpoint_reinsertion (*loc2p);
12414 last_pspace_num = old_loc->pspace->num;
12417 if (*loc2p == old_loc)
12421 /* We have already handled this address, update it so that we don't
12422 have to go through updates again. */
12423 last_addr = old_loc->address;
12425 /* Target-side condition evaluation: Handle deleted locations. */
12427 force_breakpoint_reinsertion (old_loc);
12429 /* If this location is no longer present, and inserted, look if
12430 there's maybe a new location at the same address. If so,
12431 mark that one inserted, and don't remove this one. This is
12432 needed so that we don't have a time window where a breakpoint
12433 at certain location is not inserted. */
12435 if (old_loc->inserted)
12437 /* If the location is inserted now, we might have to remove
12440 if (found_object && should_be_inserted (old_loc))
12442 /* The location is still present in the location list,
12443 and still should be inserted. Don't do anything. */
12444 keep_in_target = 1;
12448 /* This location still exists, but it won't be kept in the
12449 target since it may have been disabled. We proceed to
12450 remove its target-side condition. */
12452 /* The location is either no longer present, or got
12453 disabled. See if there's another location at the
12454 same address, in which case we don't need to remove
12455 this one from the target. */
12457 /* OLD_LOC comes from existing struct breakpoint. */
12458 if (breakpoint_address_is_meaningful (old_loc->owner))
12461 (loc2p < bp_location + bp_location_count
12462 && (*loc2p)->address == old_loc->address);
12465 struct bp_location *loc2 = *loc2p;
12467 if (breakpoint_locations_match (loc2, old_loc))
12469 /* Read watchpoint locations are switched to
12470 access watchpoints, if the former are not
12471 supported, but the latter are. */
12472 if (is_hardware_watchpoint (old_loc->owner))
12474 gdb_assert (is_hardware_watchpoint (loc2->owner));
12475 loc2->watchpoint_type = old_loc->watchpoint_type;
12478 /* loc2 is a duplicated location. We need to check
12479 if it should be inserted in case it will be
12481 if (loc2 != old_loc
12482 && unduplicated_should_be_inserted (loc2))
12484 swap_insertion (old_loc, loc2);
12485 keep_in_target = 1;
12493 if (!keep_in_target)
12495 if (remove_breakpoint (old_loc, mark_uninserted))
12497 /* This is just about all we can do. We could keep
12498 this location on the global list, and try to
12499 remove it next time, but there's no particular
12500 reason why we will succeed next time.
12502 Note that at this point, old_loc->owner is still
12503 valid, as delete_breakpoint frees the breakpoint
12504 only after calling us. */
12505 printf_filtered (_("warning: Error removing "
12506 "breakpoint %d\n"),
12507 old_loc->owner->number);
12515 if (removed && non_stop
12516 && breakpoint_address_is_meaningful (old_loc->owner)
12517 && !is_hardware_watchpoint (old_loc->owner))
12519 /* This location was removed from the target. In
12520 non-stop mode, a race condition is possible where
12521 we've removed a breakpoint, but stop events for that
12522 breakpoint are already queued and will arrive later.
12523 We apply an heuristic to be able to distinguish such
12524 SIGTRAPs from other random SIGTRAPs: we keep this
12525 breakpoint location for a bit, and will retire it
12526 after we see some number of events. The theory here
12527 is that reporting of events should, "on the average",
12528 be fair, so after a while we'll see events from all
12529 threads that have anything of interest, and no longer
12530 need to keep this breakpoint location around. We
12531 don't hold locations forever so to reduce chances of
12532 mistaking a non-breakpoint SIGTRAP for a breakpoint
12535 The heuristic failing can be disastrous on
12536 decr_pc_after_break targets.
12538 On decr_pc_after_break targets, like e.g., x86-linux,
12539 if we fail to recognize a late breakpoint SIGTRAP,
12540 because events_till_retirement has reached 0 too
12541 soon, we'll fail to do the PC adjustment, and report
12542 a random SIGTRAP to the user. When the user resumes
12543 the inferior, it will most likely immediately crash
12544 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12545 corrupted, because of being resumed e.g., in the
12546 middle of a multi-byte instruction, or skipped a
12547 one-byte instruction. This was actually seen happen
12548 on native x86-linux, and should be less rare on
12549 targets that do not support new thread events, like
12550 remote, due to the heuristic depending on
12553 Mistaking a random SIGTRAP for a breakpoint trap
12554 causes similar symptoms (PC adjustment applied when
12555 it shouldn't), but then again, playing with SIGTRAPs
12556 behind the debugger's back is asking for trouble.
12558 Since hardware watchpoint traps are always
12559 distinguishable from other traps, so we don't need to
12560 apply keep hardware watchpoint moribund locations
12561 around. We simply always ignore hardware watchpoint
12562 traps we can no longer explain. */
12564 old_loc->events_till_retirement = 3 * (thread_count () + 1);
12565 old_loc->owner = NULL;
12567 VEC_safe_push (bp_location_p, moribund_locations, old_loc);
12571 old_loc->owner = NULL;
12572 decref_bp_location (&old_loc);
12577 /* Rescan breakpoints at the same address and section, marking the
12578 first one as "first" and any others as "duplicates". This is so
12579 that the bpt instruction is only inserted once. If we have a
12580 permanent breakpoint at the same place as BPT, make that one the
12581 official one, and the rest as duplicates. Permanent breakpoints
12582 are sorted first for the same address.
12584 Do the same for hardware watchpoints, but also considering the
12585 watchpoint's type (regular/access/read) and length. */
12587 bp_loc_first = NULL;
12588 wp_loc_first = NULL;
12589 awp_loc_first = NULL;
12590 rwp_loc_first = NULL;
12591 ALL_BP_LOCATIONS (loc, locp)
12593 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12595 struct bp_location **loc_first_p;
12598 if (!unduplicated_should_be_inserted (loc)
12599 || !breakpoint_address_is_meaningful (b)
12600 /* Don't detect duplicate for tracepoint locations because they are
12601 never duplicated. See the comments in field `duplicate' of
12602 `struct bp_location'. */
12603 || is_tracepoint (b))
12605 /* Clear the condition modification flag. */
12606 loc->condition_changed = condition_unchanged;
12610 /* Permanent breakpoint should always be inserted. */
12611 if (b->enable_state == bp_permanent && ! loc->inserted)
12612 internal_error (__FILE__, __LINE__,
12613 _("allegedly permanent breakpoint is not "
12614 "actually inserted"));
12616 if (b->type == bp_hardware_watchpoint)
12617 loc_first_p = &wp_loc_first;
12618 else if (b->type == bp_read_watchpoint)
12619 loc_first_p = &rwp_loc_first;
12620 else if (b->type == bp_access_watchpoint)
12621 loc_first_p = &awp_loc_first;
12623 loc_first_p = &bp_loc_first;
12625 if (*loc_first_p == NULL
12626 || (overlay_debugging && loc->section != (*loc_first_p)->section)
12627 || !breakpoint_locations_match (loc, *loc_first_p))
12629 *loc_first_p = loc;
12630 loc->duplicate = 0;
12632 if (is_breakpoint (loc->owner) && loc->condition_changed)
12634 loc->needs_update = 1;
12635 /* Clear the condition modification flag. */
12636 loc->condition_changed = condition_unchanged;
12642 /* This and the above ensure the invariant that the first location
12643 is not duplicated, and is the inserted one.
12644 All following are marked as duplicated, and are not inserted. */
12646 swap_insertion (loc, *loc_first_p);
12647 loc->duplicate = 1;
12649 /* Clear the condition modification flag. */
12650 loc->condition_changed = condition_unchanged;
12652 if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted
12653 && b->enable_state != bp_permanent)
12654 internal_error (__FILE__, __LINE__,
12655 _("another breakpoint was inserted on top of "
12656 "a permanent breakpoint"));
12659 if (breakpoints_always_inserted_mode ()
12660 && (have_live_inferiors ()
12661 || (gdbarch_has_global_breakpoints (target_gdbarch ()))))
12664 insert_breakpoint_locations ();
12667 /* Though should_insert is false, we may need to update conditions
12668 on the target's side if it is evaluating such conditions. We
12669 only update conditions for locations that are marked
12671 update_inserted_breakpoint_locations ();
12676 download_tracepoint_locations ();
12678 do_cleanups (cleanups);
12682 breakpoint_retire_moribund (void)
12684 struct bp_location *loc;
12687 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
12688 if (--(loc->events_till_retirement) == 0)
12690 decref_bp_location (&loc);
12691 VEC_unordered_remove (bp_location_p, moribund_locations, ix);
12697 update_global_location_list_nothrow (int inserting)
12699 volatile struct gdb_exception e;
12701 TRY_CATCH (e, RETURN_MASK_ERROR)
12702 update_global_location_list (inserting);
12705 /* Clear BKP from a BPS. */
12708 bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt)
12712 for (bs = bps; bs; bs = bs->next)
12713 if (bs->breakpoint_at == bpt)
12715 bs->breakpoint_at = NULL;
12716 bs->old_val = NULL;
12717 /* bs->commands will be freed later. */
12721 /* Callback for iterate_over_threads. */
12723 bpstat_remove_breakpoint_callback (struct thread_info *th, void *data)
12725 struct breakpoint *bpt = data;
12727 bpstat_remove_bp_location (th->control.stop_bpstat, bpt);
12731 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12735 say_where (struct breakpoint *b)
12737 struct value_print_options opts;
12739 get_user_print_options (&opts);
12741 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12743 if (b->loc == NULL)
12745 printf_filtered (_(" (%s) pending."), b->addr_string);
12749 if (opts.addressprint || b->loc->symtab == NULL)
12751 printf_filtered (" at ");
12752 fputs_filtered (paddress (b->loc->gdbarch, b->loc->address),
12755 if (b->loc->symtab != NULL)
12757 /* If there is a single location, we can print the location
12759 if (b->loc->next == NULL)
12760 printf_filtered (": file %s, line %d.",
12761 symtab_to_filename_for_display (b->loc->symtab),
12762 b->loc->line_number);
12764 /* This is not ideal, but each location may have a
12765 different file name, and this at least reflects the
12766 real situation somewhat. */
12767 printf_filtered (": %s.", b->addr_string);
12772 struct bp_location *loc = b->loc;
12774 for (; loc; loc = loc->next)
12776 printf_filtered (" (%d locations)", n);
12781 /* Default bp_location_ops methods. */
12784 bp_location_dtor (struct bp_location *self)
12786 xfree (self->cond);
12787 if (self->cond_bytecode)
12788 free_agent_expr (self->cond_bytecode);
12789 xfree (self->function_name);
12791 VEC_free (agent_expr_p, self->target_info.conditions);
12792 VEC_free (agent_expr_p, self->target_info.tcommands);
12795 static const struct bp_location_ops bp_location_ops =
12800 /* Default breakpoint_ops methods all breakpoint_ops ultimately
12804 base_breakpoint_dtor (struct breakpoint *self)
12806 decref_counted_command_line (&self->commands);
12807 xfree (self->cond_string);
12808 xfree (self->extra_string);
12809 xfree (self->addr_string);
12810 xfree (self->filter);
12811 xfree (self->addr_string_range_end);
12814 static struct bp_location *
12815 base_breakpoint_allocate_location (struct breakpoint *self)
12817 struct bp_location *loc;
12819 loc = XNEW (struct bp_location);
12820 init_bp_location (loc, &bp_location_ops, self);
12825 base_breakpoint_re_set (struct breakpoint *b)
12827 /* Nothing to re-set. */
12830 #define internal_error_pure_virtual_called() \
12831 gdb_assert_not_reached ("pure virtual function called")
12834 base_breakpoint_insert_location (struct bp_location *bl)
12836 internal_error_pure_virtual_called ();
12840 base_breakpoint_remove_location (struct bp_location *bl)
12842 internal_error_pure_virtual_called ();
12846 base_breakpoint_breakpoint_hit (const struct bp_location *bl,
12847 struct address_space *aspace,
12849 const struct target_waitstatus *ws)
12851 internal_error_pure_virtual_called ();
12855 base_breakpoint_check_status (bpstat bs)
12860 /* A "works_in_software_mode" breakpoint_ops method that just internal
12864 base_breakpoint_works_in_software_mode (const struct breakpoint *b)
12866 internal_error_pure_virtual_called ();
12869 /* A "resources_needed" breakpoint_ops method that just internal
12873 base_breakpoint_resources_needed (const struct bp_location *bl)
12875 internal_error_pure_virtual_called ();
12878 static enum print_stop_action
12879 base_breakpoint_print_it (bpstat bs)
12881 internal_error_pure_virtual_called ();
12885 base_breakpoint_print_one_detail (const struct breakpoint *self,
12886 struct ui_out *uiout)
12892 base_breakpoint_print_mention (struct breakpoint *b)
12894 internal_error_pure_virtual_called ();
12898 base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp)
12900 internal_error_pure_virtual_called ();
12904 base_breakpoint_create_sals_from_address (char **arg,
12905 struct linespec_result *canonical,
12906 enum bptype type_wanted,
12910 internal_error_pure_virtual_called ();
12914 base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch,
12915 struct linespec_result *c,
12917 char *extra_string,
12918 enum bptype type_wanted,
12919 enum bpdisp disposition,
12921 int task, int ignore_count,
12922 const struct breakpoint_ops *o,
12923 int from_tty, int enabled,
12924 int internal, unsigned flags)
12926 internal_error_pure_virtual_called ();
12930 base_breakpoint_decode_linespec (struct breakpoint *b, char **s,
12931 struct symtabs_and_lines *sals)
12933 internal_error_pure_virtual_called ();
12936 /* The default 'explains_signal' method. */
12939 base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig)
12944 /* The default "after_condition_true" method. */
12947 base_breakpoint_after_condition_true (struct bpstats *bs)
12949 /* Nothing to do. */
12952 struct breakpoint_ops base_breakpoint_ops =
12954 base_breakpoint_dtor,
12955 base_breakpoint_allocate_location,
12956 base_breakpoint_re_set,
12957 base_breakpoint_insert_location,
12958 base_breakpoint_remove_location,
12959 base_breakpoint_breakpoint_hit,
12960 base_breakpoint_check_status,
12961 base_breakpoint_resources_needed,
12962 base_breakpoint_works_in_software_mode,
12963 base_breakpoint_print_it,
12965 base_breakpoint_print_one_detail,
12966 base_breakpoint_print_mention,
12967 base_breakpoint_print_recreate,
12968 base_breakpoint_create_sals_from_address,
12969 base_breakpoint_create_breakpoints_sal,
12970 base_breakpoint_decode_linespec,
12971 base_breakpoint_explains_signal,
12972 base_breakpoint_after_condition_true,
12975 /* Default breakpoint_ops methods. */
12978 bkpt_re_set (struct breakpoint *b)
12980 /* FIXME: is this still reachable? */
12981 if (b->addr_string == NULL)
12983 /* Anything without a string can't be re-set. */
12984 delete_breakpoint (b);
12988 breakpoint_re_set_default (b);
12992 bkpt_insert_location (struct bp_location *bl)
12994 if (bl->loc_type == bp_loc_hardware_breakpoint)
12995 return target_insert_hw_breakpoint (bl->gdbarch,
12998 return target_insert_breakpoint (bl->gdbarch,
13003 bkpt_remove_location (struct bp_location *bl)
13005 if (bl->loc_type == bp_loc_hardware_breakpoint)
13006 return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info);
13008 return target_remove_breakpoint (bl->gdbarch, &bl->target_info);
13012 bkpt_breakpoint_hit (const struct bp_location *bl,
13013 struct address_space *aspace, CORE_ADDR bp_addr,
13014 const struct target_waitstatus *ws)
13016 if (ws->kind != TARGET_WAITKIND_STOPPED
13017 || ws->value.sig != GDB_SIGNAL_TRAP)
13020 if (!breakpoint_address_match (bl->pspace->aspace, bl->address,
13024 if (overlay_debugging /* unmapped overlay section */
13025 && section_is_overlay (bl->section)
13026 && !section_is_mapped (bl->section))
13033 bkpt_resources_needed (const struct bp_location *bl)
13035 gdb_assert (bl->owner->type == bp_hardware_breakpoint);
13040 static enum print_stop_action
13041 bkpt_print_it (bpstat bs)
13043 struct breakpoint *b;
13044 const struct bp_location *bl;
13046 struct ui_out *uiout = current_uiout;
13048 gdb_assert (bs->bp_location_at != NULL);
13050 bl = bs->bp_location_at;
13051 b = bs->breakpoint_at;
13053 bp_temp = b->disposition == disp_del;
13054 if (bl->address != bl->requested_address)
13055 breakpoint_adjustment_warning (bl->requested_address,
13058 annotate_breakpoint (b->number);
13060 ui_out_text (uiout, "\nTemporary breakpoint ");
13062 ui_out_text (uiout, "\nBreakpoint ");
13063 if (ui_out_is_mi_like_p (uiout))
13065 ui_out_field_string (uiout, "reason",
13066 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
13067 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
13069 ui_out_field_int (uiout, "bkptno", b->number);
13070 ui_out_text (uiout, ", ");
13072 return PRINT_SRC_AND_LOC;
13076 bkpt_print_mention (struct breakpoint *b)
13078 if (ui_out_is_mi_like_p (current_uiout))
13083 case bp_breakpoint:
13084 case bp_gnu_ifunc_resolver:
13085 if (b->disposition == disp_del)
13086 printf_filtered (_("Temporary breakpoint"));
13088 printf_filtered (_("Breakpoint"));
13089 printf_filtered (_(" %d"), b->number);
13090 if (b->type == bp_gnu_ifunc_resolver)
13091 printf_filtered (_(" at gnu-indirect-function resolver"));
13093 case bp_hardware_breakpoint:
13094 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
13097 printf_filtered (_("Dprintf %d"), b->number);
13105 bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp)
13107 if (tp->type == bp_breakpoint && tp->disposition == disp_del)
13108 fprintf_unfiltered (fp, "tbreak");
13109 else if (tp->type == bp_breakpoint)
13110 fprintf_unfiltered (fp, "break");
13111 else if (tp->type == bp_hardware_breakpoint
13112 && tp->disposition == disp_del)
13113 fprintf_unfiltered (fp, "thbreak");
13114 else if (tp->type == bp_hardware_breakpoint)
13115 fprintf_unfiltered (fp, "hbreak");
13117 internal_error (__FILE__, __LINE__,
13118 _("unhandled breakpoint type %d"), (int) tp->type);
13120 fprintf_unfiltered (fp, " %s", tp->addr_string);
13121 print_recreate_thread (tp, fp);
13125 bkpt_create_sals_from_address (char **arg,
13126 struct linespec_result *canonical,
13127 enum bptype type_wanted,
13128 char *addr_start, char **copy_arg)
13130 create_sals_from_address_default (arg, canonical, type_wanted,
13131 addr_start, copy_arg);
13135 bkpt_create_breakpoints_sal (struct gdbarch *gdbarch,
13136 struct linespec_result *canonical,
13138 char *extra_string,
13139 enum bptype type_wanted,
13140 enum bpdisp disposition,
13142 int task, int ignore_count,
13143 const struct breakpoint_ops *ops,
13144 int from_tty, int enabled,
13145 int internal, unsigned flags)
13147 create_breakpoints_sal_default (gdbarch, canonical,
13148 cond_string, extra_string,
13150 disposition, thread, task,
13151 ignore_count, ops, from_tty,
13152 enabled, internal, flags);
13156 bkpt_decode_linespec (struct breakpoint *b, char **s,
13157 struct symtabs_and_lines *sals)
13159 decode_linespec_default (b, s, sals);
13162 /* Virtual table for internal breakpoints. */
13165 internal_bkpt_re_set (struct breakpoint *b)
13169 /* Delete overlay event and longjmp master breakpoints; they
13170 will be reset later by breakpoint_re_set. */
13171 case bp_overlay_event:
13172 case bp_longjmp_master:
13173 case bp_std_terminate_master:
13174 case bp_exception_master:
13175 delete_breakpoint (b);
13178 /* This breakpoint is special, it's set up when the inferior
13179 starts and we really don't want to touch it. */
13180 case bp_shlib_event:
13182 /* Like bp_shlib_event, this breakpoint type is special. Once
13183 it is set up, we do not want to touch it. */
13184 case bp_thread_event:
13190 internal_bkpt_check_status (bpstat bs)
13192 if (bs->breakpoint_at->type == bp_shlib_event)
13194 /* If requested, stop when the dynamic linker notifies GDB of
13195 events. This allows the user to get control and place
13196 breakpoints in initializer routines for dynamically loaded
13197 objects (among other things). */
13198 bs->stop = stop_on_solib_events;
13199 bs->print = stop_on_solib_events;
13205 static enum print_stop_action
13206 internal_bkpt_print_it (bpstat bs)
13208 struct breakpoint *b;
13210 b = bs->breakpoint_at;
13214 case bp_shlib_event:
13215 /* Did we stop because the user set the stop_on_solib_events
13216 variable? (If so, we report this as a generic, "Stopped due
13217 to shlib event" message.) */
13218 print_solib_event (0);
13221 case bp_thread_event:
13222 /* Not sure how we will get here.
13223 GDB should not stop for these breakpoints. */
13224 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
13227 case bp_overlay_event:
13228 /* By analogy with the thread event, GDB should not stop for these. */
13229 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
13232 case bp_longjmp_master:
13233 /* These should never be enabled. */
13234 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
13237 case bp_std_terminate_master:
13238 /* These should never be enabled. */
13239 printf_filtered (_("std::terminate Master Breakpoint: "
13240 "gdb should not stop!\n"));
13243 case bp_exception_master:
13244 /* These should never be enabled. */
13245 printf_filtered (_("Exception Master Breakpoint: "
13246 "gdb should not stop!\n"));
13250 return PRINT_NOTHING;
13254 internal_bkpt_print_mention (struct breakpoint *b)
13256 /* Nothing to mention. These breakpoints are internal. */
13259 /* Virtual table for momentary breakpoints */
13262 momentary_bkpt_re_set (struct breakpoint *b)
13264 /* Keep temporary breakpoints, which can be encountered when we step
13265 over a dlopen call and solib_add is resetting the breakpoints.
13266 Otherwise these should have been blown away via the cleanup chain
13267 or by breakpoint_init_inferior when we rerun the executable. */
13271 momentary_bkpt_check_status (bpstat bs)
13273 /* Nothing. The point of these breakpoints is causing a stop. */
13276 static enum print_stop_action
13277 momentary_bkpt_print_it (bpstat bs)
13279 struct ui_out *uiout = current_uiout;
13281 if (ui_out_is_mi_like_p (uiout))
13283 struct breakpoint *b = bs->breakpoint_at;
13288 ui_out_field_string
13290 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED));
13294 ui_out_field_string
13296 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED));
13301 return PRINT_UNKNOWN;
13305 momentary_bkpt_print_mention (struct breakpoint *b)
13307 /* Nothing to mention. These breakpoints are internal. */
13310 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
13312 It gets cleared already on the removal of the first one of such placed
13313 breakpoints. This is OK as they get all removed altogether. */
13316 longjmp_bkpt_dtor (struct breakpoint *self)
13318 struct thread_info *tp = find_thread_id (self->thread);
13321 tp->initiating_frame = null_frame_id;
13323 momentary_breakpoint_ops.dtor (self);
13326 /* Specific methods for probe breakpoints. */
13329 bkpt_probe_insert_location (struct bp_location *bl)
13331 int v = bkpt_insert_location (bl);
13335 /* The insertion was successful, now let's set the probe's semaphore
13337 bl->probe->pops->set_semaphore (bl->probe, bl->gdbarch);
13344 bkpt_probe_remove_location (struct bp_location *bl)
13346 /* Let's clear the semaphore before removing the location. */
13347 bl->probe->pops->clear_semaphore (bl->probe, bl->gdbarch);
13349 return bkpt_remove_location (bl);
13353 bkpt_probe_create_sals_from_address (char **arg,
13354 struct linespec_result *canonical,
13355 enum bptype type_wanted,
13356 char *addr_start, char **copy_arg)
13358 struct linespec_sals lsal;
13360 lsal.sals = parse_probes (arg, canonical);
13362 *copy_arg = xstrdup (canonical->addr_string);
13363 lsal.canonical = xstrdup (*copy_arg);
13365 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
13369 bkpt_probe_decode_linespec (struct breakpoint *b, char **s,
13370 struct symtabs_and_lines *sals)
13372 *sals = parse_probes (s, NULL);
13374 error (_("probe not found"));
13377 /* The breakpoint_ops structure to be used in tracepoints. */
13380 tracepoint_re_set (struct breakpoint *b)
13382 breakpoint_re_set_default (b);
13386 tracepoint_breakpoint_hit (const struct bp_location *bl,
13387 struct address_space *aspace, CORE_ADDR bp_addr,
13388 const struct target_waitstatus *ws)
13390 /* By definition, the inferior does not report stops at
13396 tracepoint_print_one_detail (const struct breakpoint *self,
13397 struct ui_out *uiout)
13399 struct tracepoint *tp = (struct tracepoint *) self;
13400 if (tp->static_trace_marker_id)
13402 gdb_assert (self->type == bp_static_tracepoint);
13404 ui_out_text (uiout, "\tmarker id is ");
13405 ui_out_field_string (uiout, "static-tracepoint-marker-string-id",
13406 tp->static_trace_marker_id);
13407 ui_out_text (uiout, "\n");
13412 tracepoint_print_mention (struct breakpoint *b)
13414 if (ui_out_is_mi_like_p (current_uiout))
13419 case bp_tracepoint:
13420 printf_filtered (_("Tracepoint"));
13421 printf_filtered (_(" %d"), b->number);
13423 case bp_fast_tracepoint:
13424 printf_filtered (_("Fast tracepoint"));
13425 printf_filtered (_(" %d"), b->number);
13427 case bp_static_tracepoint:
13428 printf_filtered (_("Static tracepoint"));
13429 printf_filtered (_(" %d"), b->number);
13432 internal_error (__FILE__, __LINE__,
13433 _("unhandled tracepoint type %d"), (int) b->type);
13440 tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp)
13442 struct tracepoint *tp = (struct tracepoint *) self;
13444 if (self->type == bp_fast_tracepoint)
13445 fprintf_unfiltered (fp, "ftrace");
13446 if (self->type == bp_static_tracepoint)
13447 fprintf_unfiltered (fp, "strace");
13448 else if (self->type == bp_tracepoint)
13449 fprintf_unfiltered (fp, "trace");
13451 internal_error (__FILE__, __LINE__,
13452 _("unhandled tracepoint type %d"), (int) self->type);
13454 fprintf_unfiltered (fp, " %s", self->addr_string);
13455 print_recreate_thread (self, fp);
13457 if (tp->pass_count)
13458 fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count);
13462 tracepoint_create_sals_from_address (char **arg,
13463 struct linespec_result *canonical,
13464 enum bptype type_wanted,
13465 char *addr_start, char **copy_arg)
13467 create_sals_from_address_default (arg, canonical, type_wanted,
13468 addr_start, copy_arg);
13472 tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch,
13473 struct linespec_result *canonical,
13475 char *extra_string,
13476 enum bptype type_wanted,
13477 enum bpdisp disposition,
13479 int task, int ignore_count,
13480 const struct breakpoint_ops *ops,
13481 int from_tty, int enabled,
13482 int internal, unsigned flags)
13484 create_breakpoints_sal_default (gdbarch, canonical,
13485 cond_string, extra_string,
13487 disposition, thread, task,
13488 ignore_count, ops, from_tty,
13489 enabled, internal, flags);
13493 tracepoint_decode_linespec (struct breakpoint *b, char **s,
13494 struct symtabs_and_lines *sals)
13496 decode_linespec_default (b, s, sals);
13499 struct breakpoint_ops tracepoint_breakpoint_ops;
13501 /* The breakpoint_ops structure to be use on tracepoints placed in a
13505 tracepoint_probe_create_sals_from_address (char **arg,
13506 struct linespec_result *canonical,
13507 enum bptype type_wanted,
13508 char *addr_start, char **copy_arg)
13510 /* We use the same method for breakpoint on probes. */
13511 bkpt_probe_create_sals_from_address (arg, canonical, type_wanted,
13512 addr_start, copy_arg);
13516 tracepoint_probe_decode_linespec (struct breakpoint *b, char **s,
13517 struct symtabs_and_lines *sals)
13519 /* We use the same method for breakpoint on probes. */
13520 bkpt_probe_decode_linespec (b, s, sals);
13523 static struct breakpoint_ops tracepoint_probe_breakpoint_ops;
13525 /* Dprintf breakpoint_ops methods. */
13528 dprintf_re_set (struct breakpoint *b)
13530 breakpoint_re_set_default (b);
13532 /* This breakpoint could have been pending, and be resolved now, and
13533 if so, we should now have the extra string. If we don't, the
13534 dprintf was malformed when created, but we couldn't tell because
13535 we can't extract the extra string until the location is
13537 if (b->loc != NULL && b->extra_string == NULL)
13538 error (_("Format string required"));
13540 /* 1 - connect to target 1, that can run breakpoint commands.
13541 2 - create a dprintf, which resolves fine.
13542 3 - disconnect from target 1
13543 4 - connect to target 2, that can NOT run breakpoint commands.
13545 After steps #3/#4, you'll want the dprintf command list to
13546 be updated, because target 1 and 2 may well return different
13547 answers for target_can_run_breakpoint_commands().
13548 Given absence of finer grained resetting, we get to do
13549 it all the time. */
13550 if (b->extra_string != NULL)
13551 update_dprintf_command_list (b);
13554 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13557 dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp)
13559 fprintf_unfiltered (fp, "dprintf %s%s", tp->addr_string,
13561 print_recreate_thread (tp, fp);
13564 /* Implement the "after_condition_true" breakpoint_ops method for
13567 dprintf's are implemented with regular commands in their command
13568 list, but we run the commands here instead of before presenting the
13569 stop to the user, as dprintf's don't actually cause a stop. This
13570 also makes it so that the commands of multiple dprintfs at the same
13571 address are all handled. */
13574 dprintf_after_condition_true (struct bpstats *bs)
13576 struct cleanup *old_chain;
13577 struct bpstats tmp_bs = { NULL };
13578 struct bpstats *tmp_bs_p = &tmp_bs;
13580 /* dprintf's never cause a stop. This wasn't set in the
13581 check_status hook instead because that would make the dprintf's
13582 condition not be evaluated. */
13585 /* Run the command list here. Take ownership of it instead of
13586 copying. We never want these commands to run later in
13587 bpstat_do_actions, if a breakpoint that causes a stop happens to
13588 be set at same address as this dprintf, or even if running the
13589 commands here throws. */
13590 tmp_bs.commands = bs->commands;
13591 bs->commands = NULL;
13592 old_chain = make_cleanup_decref_counted_command_line (&tmp_bs.commands);
13594 bpstat_do_actions_1 (&tmp_bs_p);
13596 /* 'tmp_bs.commands' will usually be NULL by now, but
13597 bpstat_do_actions_1 may return early without processing the whole
13599 do_cleanups (old_chain);
13602 /* The breakpoint_ops structure to be used on static tracepoints with
13606 strace_marker_create_sals_from_address (char **arg,
13607 struct linespec_result *canonical,
13608 enum bptype type_wanted,
13609 char *addr_start, char **copy_arg)
13611 struct linespec_sals lsal;
13613 lsal.sals = decode_static_tracepoint_spec (arg);
13615 *copy_arg = savestring (addr_start, *arg - addr_start);
13617 canonical->addr_string = xstrdup (*copy_arg);
13618 lsal.canonical = xstrdup (*copy_arg);
13619 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
13623 strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch,
13624 struct linespec_result *canonical,
13626 char *extra_string,
13627 enum bptype type_wanted,
13628 enum bpdisp disposition,
13630 int task, int ignore_count,
13631 const struct breakpoint_ops *ops,
13632 int from_tty, int enabled,
13633 int internal, unsigned flags)
13636 struct linespec_sals *lsal = VEC_index (linespec_sals,
13637 canonical->sals, 0);
13639 /* If the user is creating a static tracepoint by marker id
13640 (strace -m MARKER_ID), then store the sals index, so that
13641 breakpoint_re_set can try to match up which of the newly
13642 found markers corresponds to this one, and, don't try to
13643 expand multiple locations for each sal, given than SALS
13644 already should contain all sals for MARKER_ID. */
13646 for (i = 0; i < lsal->sals.nelts; ++i)
13648 struct symtabs_and_lines expanded;
13649 struct tracepoint *tp;
13650 struct cleanup *old_chain;
13653 expanded.nelts = 1;
13654 expanded.sals = &lsal->sals.sals[i];
13656 addr_string = xstrdup (canonical->addr_string);
13657 old_chain = make_cleanup (xfree, addr_string);
13659 tp = XCNEW (struct tracepoint);
13660 init_breakpoint_sal (&tp->base, gdbarch, expanded,
13662 cond_string, extra_string,
13663 type_wanted, disposition,
13664 thread, task, ignore_count, ops,
13665 from_tty, enabled, internal, flags,
13666 canonical->special_display);
13667 /* Given that its possible to have multiple markers with
13668 the same string id, if the user is creating a static
13669 tracepoint by marker id ("strace -m MARKER_ID"), then
13670 store the sals index, so that breakpoint_re_set can
13671 try to match up which of the newly found markers
13672 corresponds to this one */
13673 tp->static_trace_marker_id_idx = i;
13675 install_breakpoint (internal, &tp->base, 0);
13677 discard_cleanups (old_chain);
13682 strace_marker_decode_linespec (struct breakpoint *b, char **s,
13683 struct symtabs_and_lines *sals)
13685 struct tracepoint *tp = (struct tracepoint *) b;
13687 *sals = decode_static_tracepoint_spec (s);
13688 if (sals->nelts > tp->static_trace_marker_id_idx)
13690 sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx];
13694 error (_("marker %s not found"), tp->static_trace_marker_id);
13697 static struct breakpoint_ops strace_marker_breakpoint_ops;
13700 strace_marker_p (struct breakpoint *b)
13702 return b->ops == &strace_marker_breakpoint_ops;
13705 /* Delete a breakpoint and clean up all traces of it in the data
13709 delete_breakpoint (struct breakpoint *bpt)
13711 struct breakpoint *b;
13713 gdb_assert (bpt != NULL);
13715 /* Has this bp already been deleted? This can happen because
13716 multiple lists can hold pointers to bp's. bpstat lists are
13719 One example of this happening is a watchpoint's scope bp. When
13720 the scope bp triggers, we notice that the watchpoint is out of
13721 scope, and delete it. We also delete its scope bp. But the
13722 scope bp is marked "auto-deleting", and is already on a bpstat.
13723 That bpstat is then checked for auto-deleting bp's, which are
13726 A real solution to this problem might involve reference counts in
13727 bp's, and/or giving them pointers back to their referencing
13728 bpstat's, and teaching delete_breakpoint to only free a bp's
13729 storage when no more references were extent. A cheaper bandaid
13731 if (bpt->type == bp_none)
13734 /* At least avoid this stale reference until the reference counting
13735 of breakpoints gets resolved. */
13736 if (bpt->related_breakpoint != bpt)
13738 struct breakpoint *related;
13739 struct watchpoint *w;
13741 if (bpt->type == bp_watchpoint_scope)
13742 w = (struct watchpoint *) bpt->related_breakpoint;
13743 else if (bpt->related_breakpoint->type == bp_watchpoint_scope)
13744 w = (struct watchpoint *) bpt;
13748 watchpoint_del_at_next_stop (w);
13750 /* Unlink bpt from the bpt->related_breakpoint ring. */
13751 for (related = bpt; related->related_breakpoint != bpt;
13752 related = related->related_breakpoint);
13753 related->related_breakpoint = bpt->related_breakpoint;
13754 bpt->related_breakpoint = bpt;
13757 /* watch_command_1 creates a watchpoint but only sets its number if
13758 update_watchpoint succeeds in creating its bp_locations. If there's
13759 a problem in that process, we'll be asked to delete the half-created
13760 watchpoint. In that case, don't announce the deletion. */
13762 observer_notify_breakpoint_deleted (bpt);
13764 if (breakpoint_chain == bpt)
13765 breakpoint_chain = bpt->next;
13767 ALL_BREAKPOINTS (b)
13768 if (b->next == bpt)
13770 b->next = bpt->next;
13774 /* Be sure no bpstat's are pointing at the breakpoint after it's
13776 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13777 in all threads for now. Note that we cannot just remove bpstats
13778 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13779 commands are associated with the bpstat; if we remove it here,
13780 then the later call to bpstat_do_actions (&stop_bpstat); in
13781 event-top.c won't do anything, and temporary breakpoints with
13782 commands won't work. */
13784 iterate_over_threads (bpstat_remove_breakpoint_callback, bpt);
13786 /* Now that breakpoint is removed from breakpoint list, update the
13787 global location list. This will remove locations that used to
13788 belong to this breakpoint. Do this before freeing the breakpoint
13789 itself, since remove_breakpoint looks at location's owner. It
13790 might be better design to have location completely
13791 self-contained, but it's not the case now. */
13792 update_global_location_list (0);
13794 bpt->ops->dtor (bpt);
13795 /* On the chance that someone will soon try again to delete this
13796 same bp, we mark it as deleted before freeing its storage. */
13797 bpt->type = bp_none;
13802 do_delete_breakpoint_cleanup (void *b)
13804 delete_breakpoint (b);
13808 make_cleanup_delete_breakpoint (struct breakpoint *b)
13810 return make_cleanup (do_delete_breakpoint_cleanup, b);
13813 /* Iterator function to call a user-provided callback function once
13814 for each of B and its related breakpoints. */
13817 iterate_over_related_breakpoints (struct breakpoint *b,
13818 void (*function) (struct breakpoint *,
13822 struct breakpoint *related;
13827 struct breakpoint *next;
13829 /* FUNCTION may delete RELATED. */
13830 next = related->related_breakpoint;
13832 if (next == related)
13834 /* RELATED is the last ring entry. */
13835 function (related, data);
13837 /* FUNCTION may have deleted it, so we'd never reach back to
13838 B. There's nothing left to do anyway, so just break
13843 function (related, data);
13847 while (related != b);
13851 do_delete_breakpoint (struct breakpoint *b, void *ignore)
13853 delete_breakpoint (b);
13856 /* A callback for map_breakpoint_numbers that calls
13857 delete_breakpoint. */
13860 do_map_delete_breakpoint (struct breakpoint *b, void *ignore)
13862 iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL);
13866 delete_command (char *arg, int from_tty)
13868 struct breakpoint *b, *b_tmp;
13874 int breaks_to_delete = 0;
13876 /* Delete all breakpoints if no argument. Do not delete
13877 internal breakpoints, these have to be deleted with an
13878 explicit breakpoint number argument. */
13879 ALL_BREAKPOINTS (b)
13880 if (user_breakpoint_p (b))
13882 breaks_to_delete = 1;
13886 /* Ask user only if there are some breakpoints to delete. */
13888 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
13890 ALL_BREAKPOINTS_SAFE (b, b_tmp)
13891 if (user_breakpoint_p (b))
13892 delete_breakpoint (b);
13896 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
13900 all_locations_are_pending (struct bp_location *loc)
13902 for (; loc; loc = loc->next)
13903 if (!loc->shlib_disabled
13904 && !loc->pspace->executing_startup)
13909 /* Subroutine of update_breakpoint_locations to simplify it.
13910 Return non-zero if multiple fns in list LOC have the same name.
13911 Null names are ignored. */
13914 ambiguous_names_p (struct bp_location *loc)
13916 struct bp_location *l;
13917 htab_t htab = htab_create_alloc (13, htab_hash_string,
13918 (int (*) (const void *,
13919 const void *)) streq,
13920 NULL, xcalloc, xfree);
13922 for (l = loc; l != NULL; l = l->next)
13925 const char *name = l->function_name;
13927 /* Allow for some names to be NULL, ignore them. */
13931 slot = (const char **) htab_find_slot (htab, (const void *) name,
13933 /* NOTE: We can assume slot != NULL here because xcalloc never
13937 htab_delete (htab);
13943 htab_delete (htab);
13947 /* When symbols change, it probably means the sources changed as well,
13948 and it might mean the static tracepoint markers are no longer at
13949 the same address or line numbers they used to be at last we
13950 checked. Losing your static tracepoints whenever you rebuild is
13951 undesirable. This function tries to resync/rematch gdb static
13952 tracepoints with the markers on the target, for static tracepoints
13953 that have not been set by marker id. Static tracepoint that have
13954 been set by marker id are reset by marker id in breakpoint_re_set.
13957 1) For a tracepoint set at a specific address, look for a marker at
13958 the old PC. If one is found there, assume to be the same marker.
13959 If the name / string id of the marker found is different from the
13960 previous known name, assume that means the user renamed the marker
13961 in the sources, and output a warning.
13963 2) For a tracepoint set at a given line number, look for a marker
13964 at the new address of the old line number. If one is found there,
13965 assume to be the same marker. If the name / string id of the
13966 marker found is different from the previous known name, assume that
13967 means the user renamed the marker in the sources, and output a
13970 3) If a marker is no longer found at the same address or line, it
13971 may mean the marker no longer exists. But it may also just mean
13972 the code changed a bit. Maybe the user added a few lines of code
13973 that made the marker move up or down (in line number terms). Ask
13974 the target for info about the marker with the string id as we knew
13975 it. If found, update line number and address in the matching
13976 static tracepoint. This will get confused if there's more than one
13977 marker with the same ID (possible in UST, although unadvised
13978 precisely because it confuses tools). */
13980 static struct symtab_and_line
13981 update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal)
13983 struct tracepoint *tp = (struct tracepoint *) b;
13984 struct static_tracepoint_marker marker;
13989 find_line_pc (sal.symtab, sal.line, &pc);
13991 if (target_static_tracepoint_marker_at (pc, &marker))
13993 if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0)
13994 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13996 tp->static_trace_marker_id, marker.str_id);
13998 xfree (tp->static_trace_marker_id);
13999 tp->static_trace_marker_id = xstrdup (marker.str_id);
14000 release_static_tracepoint_marker (&marker);
14005 /* Old marker wasn't found on target at lineno. Try looking it up
14007 if (!sal.explicit_pc
14009 && sal.symtab != NULL
14010 && tp->static_trace_marker_id != NULL)
14012 VEC(static_tracepoint_marker_p) *markers;
14015 = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id);
14017 if (!VEC_empty(static_tracepoint_marker_p, markers))
14019 struct symtab_and_line sal2;
14020 struct symbol *sym;
14021 struct static_tracepoint_marker *tpmarker;
14022 struct ui_out *uiout = current_uiout;
14024 tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0);
14026 xfree (tp->static_trace_marker_id);
14027 tp->static_trace_marker_id = xstrdup (tpmarker->str_id);
14029 warning (_("marker for static tracepoint %d (%s) not "
14030 "found at previous line number"),
14031 b->number, tp->static_trace_marker_id);
14035 sal2.pc = tpmarker->address;
14037 sal2 = find_pc_line (tpmarker->address, 0);
14038 sym = find_pc_sect_function (tpmarker->address, NULL);
14039 ui_out_text (uiout, "Now in ");
14042 ui_out_field_string (uiout, "func",
14043 SYMBOL_PRINT_NAME (sym));
14044 ui_out_text (uiout, " at ");
14046 ui_out_field_string (uiout, "file",
14047 symtab_to_filename_for_display (sal2.symtab));
14048 ui_out_text (uiout, ":");
14050 if (ui_out_is_mi_like_p (uiout))
14052 const char *fullname = symtab_to_fullname (sal2.symtab);
14054 ui_out_field_string (uiout, "fullname", fullname);
14057 ui_out_field_int (uiout, "line", sal2.line);
14058 ui_out_text (uiout, "\n");
14060 b->loc->line_number = sal2.line;
14061 b->loc->symtab = sym != NULL ? sal2.symtab : NULL;
14063 xfree (b->addr_string);
14064 b->addr_string = xstrprintf ("%s:%d",
14065 symtab_to_filename_for_display (sal2.symtab),
14066 b->loc->line_number);
14068 /* Might be nice to check if function changed, and warn if
14071 release_static_tracepoint_marker (tpmarker);
14077 /* Returns 1 iff locations A and B are sufficiently same that
14078 we don't need to report breakpoint as changed. */
14081 locations_are_equal (struct bp_location *a, struct bp_location *b)
14085 if (a->address != b->address)
14088 if (a->shlib_disabled != b->shlib_disabled)
14091 if (a->enabled != b->enabled)
14098 if ((a == NULL) != (b == NULL))
14104 /* Create new breakpoint locations for B (a hardware or software breakpoint)
14105 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
14106 a ranged breakpoint. */
14109 update_breakpoint_locations (struct breakpoint *b,
14110 struct symtabs_and_lines sals,
14111 struct symtabs_and_lines sals_end)
14114 struct bp_location *existing_locations = b->loc;
14116 if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1))
14118 /* Ranged breakpoints have only one start location and one end
14120 b->enable_state = bp_disabled;
14121 update_global_location_list (1);
14122 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
14123 "multiple locations found\n"),
14128 /* If there's no new locations, and all existing locations are
14129 pending, don't do anything. This optimizes the common case where
14130 all locations are in the same shared library, that was unloaded.
14131 We'd like to retain the location, so that when the library is
14132 loaded again, we don't loose the enabled/disabled status of the
14133 individual locations. */
14134 if (all_locations_are_pending (existing_locations) && sals.nelts == 0)
14139 for (i = 0; i < sals.nelts; ++i)
14141 struct bp_location *new_loc;
14143 switch_to_program_space_and_thread (sals.sals[i].pspace);
14145 new_loc = add_location_to_breakpoint (b, &(sals.sals[i]));
14147 /* Reparse conditions, they might contain references to the
14149 if (b->cond_string != NULL)
14152 volatile struct gdb_exception e;
14154 s = b->cond_string;
14155 TRY_CATCH (e, RETURN_MASK_ERROR)
14157 new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc,
14158 block_for_pc (sals.sals[i].pc),
14163 warning (_("failed to reevaluate condition "
14164 "for breakpoint %d: %s"),
14165 b->number, e.message);
14166 new_loc->enabled = 0;
14170 if (sals_end.nelts)
14172 CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]);
14174 new_loc->length = end - sals.sals[0].pc + 1;
14178 /* Update locations of permanent breakpoints. */
14179 if (b->enable_state == bp_permanent)
14180 make_breakpoint_permanent (b);
14182 /* If possible, carry over 'disable' status from existing
14185 struct bp_location *e = existing_locations;
14186 /* If there are multiple breakpoints with the same function name,
14187 e.g. for inline functions, comparing function names won't work.
14188 Instead compare pc addresses; this is just a heuristic as things
14189 may have moved, but in practice it gives the correct answer
14190 often enough until a better solution is found. */
14191 int have_ambiguous_names = ambiguous_names_p (b->loc);
14193 for (; e; e = e->next)
14195 if (!e->enabled && e->function_name)
14197 struct bp_location *l = b->loc;
14198 if (have_ambiguous_names)
14200 for (; l; l = l->next)
14201 if (breakpoint_locations_match (e, l))
14209 for (; l; l = l->next)
14210 if (l->function_name
14211 && strcmp (e->function_name, l->function_name) == 0)
14221 if (!locations_are_equal (existing_locations, b->loc))
14222 observer_notify_breakpoint_modified (b);
14224 update_global_location_list (1);
14227 /* Find the SaL locations corresponding to the given ADDR_STRING.
14228 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
14230 static struct symtabs_and_lines
14231 addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found)
14234 struct symtabs_and_lines sals = {0};
14235 volatile struct gdb_exception e;
14237 gdb_assert (b->ops != NULL);
14240 TRY_CATCH (e, RETURN_MASK_ERROR)
14242 b->ops->decode_linespec (b, &s, &sals);
14246 int not_found_and_ok = 0;
14247 /* For pending breakpoints, it's expected that parsing will
14248 fail until the right shared library is loaded. User has
14249 already told to create pending breakpoints and don't need
14250 extra messages. If breakpoint is in bp_shlib_disabled
14251 state, then user already saw the message about that
14252 breakpoint being disabled, and don't want to see more
14254 if (e.error == NOT_FOUND_ERROR
14255 && (b->condition_not_parsed
14256 || (b->loc && b->loc->shlib_disabled)
14257 || (b->loc && b->loc->pspace->executing_startup)
14258 || b->enable_state == bp_disabled))
14259 not_found_and_ok = 1;
14261 if (!not_found_and_ok)
14263 /* We surely don't want to warn about the same breakpoint
14264 10 times. One solution, implemented here, is disable
14265 the breakpoint on error. Another solution would be to
14266 have separate 'warning emitted' flag. Since this
14267 happens only when a binary has changed, I don't know
14268 which approach is better. */
14269 b->enable_state = bp_disabled;
14270 throw_exception (e);
14274 if (e.reason == 0 || e.error != NOT_FOUND_ERROR)
14278 for (i = 0; i < sals.nelts; ++i)
14279 resolve_sal_pc (&sals.sals[i]);
14280 if (b->condition_not_parsed && s && s[0])
14282 char *cond_string, *extra_string;
14285 find_condition_and_thread (s, sals.sals[0].pc,
14286 &cond_string, &thread, &task,
14289 b->cond_string = cond_string;
14290 b->thread = thread;
14293 b->extra_string = extra_string;
14294 b->condition_not_parsed = 0;
14297 if (b->type == bp_static_tracepoint && !strace_marker_p (b))
14298 sals.sals[0] = update_static_tracepoint (b, sals.sals[0]);
14308 /* The default re_set method, for typical hardware or software
14309 breakpoints. Reevaluate the breakpoint and recreate its
14313 breakpoint_re_set_default (struct breakpoint *b)
14316 struct symtabs_and_lines sals, sals_end;
14317 struct symtabs_and_lines expanded = {0};
14318 struct symtabs_and_lines expanded_end = {0};
14320 sals = addr_string_to_sals (b, b->addr_string, &found);
14323 make_cleanup (xfree, sals.sals);
14327 if (b->addr_string_range_end)
14329 sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found);
14332 make_cleanup (xfree, sals_end.sals);
14333 expanded_end = sals_end;
14337 update_breakpoint_locations (b, expanded, expanded_end);
14340 /* Default method for creating SALs from an address string. It basically
14341 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
14344 create_sals_from_address_default (char **arg,
14345 struct linespec_result *canonical,
14346 enum bptype type_wanted,
14347 char *addr_start, char **copy_arg)
14349 parse_breakpoint_sals (arg, canonical);
14352 /* Call create_breakpoints_sal for the given arguments. This is the default
14353 function for the `create_breakpoints_sal' method of
14357 create_breakpoints_sal_default (struct gdbarch *gdbarch,
14358 struct linespec_result *canonical,
14360 char *extra_string,
14361 enum bptype type_wanted,
14362 enum bpdisp disposition,
14364 int task, int ignore_count,
14365 const struct breakpoint_ops *ops,
14366 int from_tty, int enabled,
14367 int internal, unsigned flags)
14369 create_breakpoints_sal (gdbarch, canonical, cond_string,
14371 type_wanted, disposition,
14372 thread, task, ignore_count, ops, from_tty,
14373 enabled, internal, flags);
14376 /* Decode the line represented by S by calling decode_line_full. This is the
14377 default function for the `decode_linespec' method of breakpoint_ops. */
14380 decode_linespec_default (struct breakpoint *b, char **s,
14381 struct symtabs_and_lines *sals)
14383 struct linespec_result canonical;
14385 init_linespec_result (&canonical);
14386 decode_line_full (s, DECODE_LINE_FUNFIRSTLINE,
14387 (struct symtab *) NULL, 0,
14388 &canonical, multiple_symbols_all,
14391 /* We should get 0 or 1 resulting SALs. */
14392 gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2);
14394 if (VEC_length (linespec_sals, canonical.sals) > 0)
14396 struct linespec_sals *lsal;
14398 lsal = VEC_index (linespec_sals, canonical.sals, 0);
14399 *sals = lsal->sals;
14400 /* Arrange it so the destructor does not free the
14402 lsal->sals.sals = NULL;
14405 destroy_linespec_result (&canonical);
14408 /* Prepare the global context for a re-set of breakpoint B. */
14410 static struct cleanup *
14411 prepare_re_set_context (struct breakpoint *b)
14413 struct cleanup *cleanups;
14415 input_radix = b->input_radix;
14416 cleanups = save_current_space_and_thread ();
14417 if (b->pspace != NULL)
14418 switch_to_program_space_and_thread (b->pspace);
14419 set_language (b->language);
14424 /* Reset a breakpoint given it's struct breakpoint * BINT.
14425 The value we return ends up being the return value from catch_errors.
14426 Unused in this case. */
14429 breakpoint_re_set_one (void *bint)
14431 /* Get past catch_errs. */
14432 struct breakpoint *b = (struct breakpoint *) bint;
14433 struct cleanup *cleanups;
14435 cleanups = prepare_re_set_context (b);
14436 b->ops->re_set (b);
14437 do_cleanups (cleanups);
14441 /* Re-set all breakpoints after symbols have been re-loaded. */
14443 breakpoint_re_set (void)
14445 struct breakpoint *b, *b_tmp;
14446 enum language save_language;
14447 int save_input_radix;
14448 struct cleanup *old_chain;
14450 save_language = current_language->la_language;
14451 save_input_radix = input_radix;
14452 old_chain = save_current_program_space ();
14454 ALL_BREAKPOINTS_SAFE (b, b_tmp)
14456 /* Format possible error msg. */
14457 char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
14459 struct cleanup *cleanups = make_cleanup (xfree, message);
14460 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
14461 do_cleanups (cleanups);
14463 set_language (save_language);
14464 input_radix = save_input_radix;
14466 jit_breakpoint_re_set ();
14468 do_cleanups (old_chain);
14470 create_overlay_event_breakpoint ();
14471 create_longjmp_master_breakpoint ();
14472 create_std_terminate_master_breakpoint ();
14473 create_exception_master_breakpoint ();
14476 /* Reset the thread number of this breakpoint:
14478 - If the breakpoint is for all threads, leave it as-is.
14479 - Else, reset it to the current thread for inferior_ptid. */
14481 breakpoint_re_set_thread (struct breakpoint *b)
14483 if (b->thread != -1)
14485 if (in_thread_list (inferior_ptid))
14486 b->thread = pid_to_thread_id (inferior_ptid);
14488 /* We're being called after following a fork. The new fork is
14489 selected as current, and unless this was a vfork will have a
14490 different program space from the original thread. Reset that
14492 b->loc->pspace = current_program_space;
14496 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14497 If from_tty is nonzero, it prints a message to that effect,
14498 which ends with a period (no newline). */
14501 set_ignore_count (int bptnum, int count, int from_tty)
14503 struct breakpoint *b;
14508 ALL_BREAKPOINTS (b)
14509 if (b->number == bptnum)
14511 if (is_tracepoint (b))
14513 if (from_tty && count != 0)
14514 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14519 b->ignore_count = count;
14523 printf_filtered (_("Will stop next time "
14524 "breakpoint %d is reached."),
14526 else if (count == 1)
14527 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14530 printf_filtered (_("Will ignore next %d "
14531 "crossings of breakpoint %d."),
14534 observer_notify_breakpoint_modified (b);
14538 error (_("No breakpoint number %d."), bptnum);
14541 /* Command to set ignore-count of breakpoint N to COUNT. */
14544 ignore_command (char *args, int from_tty)
14550 error_no_arg (_("a breakpoint number"));
14552 num = get_number (&p);
14554 error (_("bad breakpoint number: '%s'"), args);
14556 error (_("Second argument (specified ignore-count) is missing."));
14558 set_ignore_count (num,
14559 longest_to_int (value_as_long (parse_and_eval (p))),
14562 printf_filtered ("\n");
14565 /* Call FUNCTION on each of the breakpoints
14566 whose numbers are given in ARGS. */
14569 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *,
14574 struct breakpoint *b, *tmp;
14576 struct get_number_or_range_state state;
14579 error_no_arg (_("one or more breakpoint numbers"));
14581 init_number_or_range (&state, args);
14583 while (!state.finished)
14585 char *p = state.string;
14589 num = get_number_or_range (&state);
14592 warning (_("bad breakpoint number at or near '%s'"), p);
14596 ALL_BREAKPOINTS_SAFE (b, tmp)
14597 if (b->number == num)
14600 function (b, data);
14604 printf_unfiltered (_("No breakpoint number %d.\n"), num);
14609 static struct bp_location *
14610 find_location_by_number (char *number)
14612 char *dot = strchr (number, '.');
14616 struct breakpoint *b;
14617 struct bp_location *loc;
14622 bp_num = get_number (&p1);
14624 error (_("Bad breakpoint number '%s'"), number);
14626 ALL_BREAKPOINTS (b)
14627 if (b->number == bp_num)
14632 if (!b || b->number != bp_num)
14633 error (_("Bad breakpoint number '%s'"), number);
14636 loc_num = get_number (&p1);
14638 error (_("Bad breakpoint location number '%s'"), number);
14642 for (;loc_num && loc; --loc_num, loc = loc->next)
14645 error (_("Bad breakpoint location number '%s'"), dot+1);
14651 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14652 If from_tty is nonzero, it prints a message to that effect,
14653 which ends with a period (no newline). */
14656 disable_breakpoint (struct breakpoint *bpt)
14658 /* Never disable a watchpoint scope breakpoint; we want to
14659 hit them when we leave scope so we can delete both the
14660 watchpoint and its scope breakpoint at that time. */
14661 if (bpt->type == bp_watchpoint_scope)
14664 /* You can't disable permanent breakpoints. */
14665 if (bpt->enable_state == bp_permanent)
14668 bpt->enable_state = bp_disabled;
14670 /* Mark breakpoint locations modified. */
14671 mark_breakpoint_modified (bpt);
14673 if (target_supports_enable_disable_tracepoint ()
14674 && current_trace_status ()->running && is_tracepoint (bpt))
14676 struct bp_location *location;
14678 for (location = bpt->loc; location; location = location->next)
14679 target_disable_tracepoint (location);
14682 update_global_location_list (0);
14684 observer_notify_breakpoint_modified (bpt);
14687 /* A callback for iterate_over_related_breakpoints. */
14690 do_disable_breakpoint (struct breakpoint *b, void *ignore)
14692 disable_breakpoint (b);
14695 /* A callback for map_breakpoint_numbers that calls
14696 disable_breakpoint. */
14699 do_map_disable_breakpoint (struct breakpoint *b, void *ignore)
14701 iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL);
14705 disable_command (char *args, int from_tty)
14709 struct breakpoint *bpt;
14711 ALL_BREAKPOINTS (bpt)
14712 if (user_breakpoint_p (bpt))
14713 disable_breakpoint (bpt);
14717 char *num = extract_arg (&args);
14721 if (strchr (num, '.'))
14723 struct bp_location *loc = find_location_by_number (num);
14730 mark_breakpoint_location_modified (loc);
14732 if (target_supports_enable_disable_tracepoint ()
14733 && current_trace_status ()->running && loc->owner
14734 && is_tracepoint (loc->owner))
14735 target_disable_tracepoint (loc);
14737 update_global_location_list (0);
14740 map_breakpoint_numbers (num, do_map_disable_breakpoint, NULL);
14741 num = extract_arg (&args);
14747 enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition,
14750 int target_resources_ok;
14752 if (bpt->type == bp_hardware_breakpoint)
14755 i = hw_breakpoint_used_count ();
14756 target_resources_ok =
14757 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
14759 if (target_resources_ok == 0)
14760 error (_("No hardware breakpoint support in the target."));
14761 else if (target_resources_ok < 0)
14762 error (_("Hardware breakpoints used exceeds limit."));
14765 if (is_watchpoint (bpt))
14767 /* Initialize it just to avoid a GCC false warning. */
14768 enum enable_state orig_enable_state = 0;
14769 volatile struct gdb_exception e;
14771 TRY_CATCH (e, RETURN_MASK_ALL)
14773 struct watchpoint *w = (struct watchpoint *) bpt;
14775 orig_enable_state = bpt->enable_state;
14776 bpt->enable_state = bp_enabled;
14777 update_watchpoint (w, 1 /* reparse */);
14781 bpt->enable_state = orig_enable_state;
14782 exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
14788 if (bpt->enable_state != bp_permanent)
14789 bpt->enable_state = bp_enabled;
14791 bpt->enable_state = bp_enabled;
14793 /* Mark breakpoint locations modified. */
14794 mark_breakpoint_modified (bpt);
14796 if (target_supports_enable_disable_tracepoint ()
14797 && current_trace_status ()->running && is_tracepoint (bpt))
14799 struct bp_location *location;
14801 for (location = bpt->loc; location; location = location->next)
14802 target_enable_tracepoint (location);
14805 bpt->disposition = disposition;
14806 bpt->enable_count = count;
14807 update_global_location_list (1);
14809 observer_notify_breakpoint_modified (bpt);
14814 enable_breakpoint (struct breakpoint *bpt)
14816 enable_breakpoint_disp (bpt, bpt->disposition, 0);
14820 do_enable_breakpoint (struct breakpoint *bpt, void *arg)
14822 enable_breakpoint (bpt);
14825 /* A callback for map_breakpoint_numbers that calls
14826 enable_breakpoint. */
14829 do_map_enable_breakpoint (struct breakpoint *b, void *ignore)
14831 iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL);
14834 /* The enable command enables the specified breakpoints (or all defined
14835 breakpoints) so they once again become (or continue to be) effective
14836 in stopping the inferior. */
14839 enable_command (char *args, int from_tty)
14843 struct breakpoint *bpt;
14845 ALL_BREAKPOINTS (bpt)
14846 if (user_breakpoint_p (bpt))
14847 enable_breakpoint (bpt);
14851 char *num = extract_arg (&args);
14855 if (strchr (num, '.'))
14857 struct bp_location *loc = find_location_by_number (num);
14864 mark_breakpoint_location_modified (loc);
14866 if (target_supports_enable_disable_tracepoint ()
14867 && current_trace_status ()->running && loc->owner
14868 && is_tracepoint (loc->owner))
14869 target_enable_tracepoint (loc);
14871 update_global_location_list (1);
14874 map_breakpoint_numbers (num, do_map_enable_breakpoint, NULL);
14875 num = extract_arg (&args);
14880 /* This struct packages up disposition data for application to multiple
14890 do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg)
14892 struct disp_data disp_data = *(struct disp_data *) arg;
14894 enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count);
14898 do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore)
14900 struct disp_data disp = { disp_disable, 1 };
14902 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
14906 enable_once_command (char *args, int from_tty)
14908 map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL);
14912 do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr)
14914 struct disp_data disp = { disp_disable, *(int *) countptr };
14916 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
14920 enable_count_command (char *args, int from_tty)
14922 int count = get_number (&args);
14924 map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count);
14928 do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore)
14930 struct disp_data disp = { disp_del, 1 };
14932 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
14936 enable_delete_command (char *args, int from_tty)
14938 map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL);
14942 set_breakpoint_cmd (char *args, int from_tty)
14947 show_breakpoint_cmd (char *args, int from_tty)
14951 /* Invalidate last known value of any hardware watchpoint if
14952 the memory which that value represents has been written to by
14956 invalidate_bp_value_on_memory_change (struct inferior *inferior,
14957 CORE_ADDR addr, ssize_t len,
14958 const bfd_byte *data)
14960 struct breakpoint *bp;
14962 ALL_BREAKPOINTS (bp)
14963 if (bp->enable_state == bp_enabled
14964 && bp->type == bp_hardware_watchpoint)
14966 struct watchpoint *wp = (struct watchpoint *) bp;
14968 if (wp->val_valid && wp->val)
14970 struct bp_location *loc;
14972 for (loc = bp->loc; loc != NULL; loc = loc->next)
14973 if (loc->loc_type == bp_loc_hardware_watchpoint
14974 && loc->address + loc->length > addr
14975 && addr + len > loc->address)
14977 value_free (wp->val);
14985 /* Create and insert a raw software breakpoint at PC. Return an
14986 identifier, which should be used to remove the breakpoint later.
14987 In general, places which call this should be using something on the
14988 breakpoint chain instead; this function should be eliminated
14992 deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch,
14993 struct address_space *aspace, CORE_ADDR pc)
14995 struct bp_target_info *bp_tgt;
14997 bp_tgt = XCNEW (struct bp_target_info);
14999 bp_tgt->placed_address_space = aspace;
15000 bp_tgt->placed_address = pc;
15002 if (target_insert_breakpoint (gdbarch, bp_tgt) != 0)
15004 /* Could not insert the breakpoint. */
15012 /* Remove a breakpoint BP inserted by
15013 deprecated_insert_raw_breakpoint. */
15016 deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp)
15018 struct bp_target_info *bp_tgt = bp;
15021 ret = target_remove_breakpoint (gdbarch, bp_tgt);
15027 /* One (or perhaps two) breakpoints used for software single
15030 static void *single_step_breakpoints[2];
15031 static struct gdbarch *single_step_gdbarch[2];
15033 /* Create and insert a breakpoint for software single step. */
15036 insert_single_step_breakpoint (struct gdbarch *gdbarch,
15037 struct address_space *aspace,
15042 if (single_step_breakpoints[0] == NULL)
15044 bpt_p = &single_step_breakpoints[0];
15045 single_step_gdbarch[0] = gdbarch;
15049 gdb_assert (single_step_breakpoints[1] == NULL);
15050 bpt_p = &single_step_breakpoints[1];
15051 single_step_gdbarch[1] = gdbarch;
15054 /* NOTE drow/2006-04-11: A future improvement to this function would
15055 be to only create the breakpoints once, and actually put them on
15056 the breakpoint chain. That would let us use set_raw_breakpoint.
15057 We could adjust the addresses each time they were needed. Doing
15058 this requires corresponding changes elsewhere where single step
15059 breakpoints are handled, however. So, for now, we use this. */
15061 *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc);
15062 if (*bpt_p == NULL)
15063 error (_("Could not insert single-step breakpoint at %s"),
15064 paddress (gdbarch, next_pc));
15067 /* Check if the breakpoints used for software single stepping
15068 were inserted or not. */
15071 single_step_breakpoints_inserted (void)
15073 return (single_step_breakpoints[0] != NULL
15074 || single_step_breakpoints[1] != NULL);
15077 /* Remove and delete any breakpoints used for software single step. */
15080 remove_single_step_breakpoints (void)
15082 gdb_assert (single_step_breakpoints[0] != NULL);
15084 /* See insert_single_step_breakpoint for more about this deprecated
15086 deprecated_remove_raw_breakpoint (single_step_gdbarch[0],
15087 single_step_breakpoints[0]);
15088 single_step_gdbarch[0] = NULL;
15089 single_step_breakpoints[0] = NULL;
15091 if (single_step_breakpoints[1] != NULL)
15093 deprecated_remove_raw_breakpoint (single_step_gdbarch[1],
15094 single_step_breakpoints[1]);
15095 single_step_gdbarch[1] = NULL;
15096 single_step_breakpoints[1] = NULL;
15100 /* Delete software single step breakpoints without removing them from
15101 the inferior. This is intended to be used if the inferior's address
15102 space where they were inserted is already gone, e.g. after exit or
15106 cancel_single_step_breakpoints (void)
15110 for (i = 0; i < 2; i++)
15111 if (single_step_breakpoints[i])
15113 xfree (single_step_breakpoints[i]);
15114 single_step_breakpoints[i] = NULL;
15115 single_step_gdbarch[i] = NULL;
15119 /* Detach software single-step breakpoints from INFERIOR_PTID without
15123 detach_single_step_breakpoints (void)
15127 for (i = 0; i < 2; i++)
15128 if (single_step_breakpoints[i])
15129 target_remove_breakpoint (single_step_gdbarch[i],
15130 single_step_breakpoints[i]);
15133 /* Check whether a software single-step breakpoint is inserted at
15137 single_step_breakpoint_inserted_here_p (struct address_space *aspace,
15142 for (i = 0; i < 2; i++)
15144 struct bp_target_info *bp_tgt = single_step_breakpoints[i];
15146 && breakpoint_address_match (bp_tgt->placed_address_space,
15147 bp_tgt->placed_address,
15155 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
15156 non-zero otherwise. */
15158 is_syscall_catchpoint_enabled (struct breakpoint *bp)
15160 if (syscall_catchpoint_p (bp)
15161 && bp->enable_state != bp_disabled
15162 && bp->enable_state != bp_call_disabled)
15169 catch_syscall_enabled (void)
15171 struct catch_syscall_inferior_data *inf_data
15172 = get_catch_syscall_inferior_data (current_inferior ());
15174 return inf_data->total_syscalls_count != 0;
15178 catching_syscall_number (int syscall_number)
15180 struct breakpoint *bp;
15182 ALL_BREAKPOINTS (bp)
15183 if (is_syscall_catchpoint_enabled (bp))
15185 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp;
15187 if (c->syscalls_to_be_caught)
15191 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
15193 if (syscall_number == iter)
15203 /* Complete syscall names. Used by "catch syscall". */
15204 static VEC (char_ptr) *
15205 catch_syscall_completer (struct cmd_list_element *cmd,
15206 const char *text, const char *word)
15208 const char **list = get_syscall_names ();
15209 VEC (char_ptr) *retlist
15210 = (list == NULL) ? NULL : complete_on_enum (list, word, word);
15216 /* Tracepoint-specific operations. */
15218 /* Set tracepoint count to NUM. */
15220 set_tracepoint_count (int num)
15222 tracepoint_count = num;
15223 set_internalvar_integer (lookup_internalvar ("tpnum"), num);
15227 trace_command (char *arg, int from_tty)
15229 struct breakpoint_ops *ops;
15230 const char *arg_cp = arg;
15232 if (arg && probe_linespec_to_ops (&arg_cp))
15233 ops = &tracepoint_probe_breakpoint_ops;
15235 ops = &tracepoint_breakpoint_ops;
15237 create_breakpoint (get_current_arch (),
15239 NULL, 0, NULL, 1 /* parse arg */,
15241 bp_tracepoint /* type_wanted */,
15242 0 /* Ignore count */,
15243 pending_break_support,
15247 0 /* internal */, 0);
15251 ftrace_command (char *arg, int from_tty)
15253 create_breakpoint (get_current_arch (),
15255 NULL, 0, NULL, 1 /* parse arg */,
15257 bp_fast_tracepoint /* type_wanted */,
15258 0 /* Ignore count */,
15259 pending_break_support,
15260 &tracepoint_breakpoint_ops,
15263 0 /* internal */, 0);
15266 /* strace command implementation. Creates a static tracepoint. */
15269 strace_command (char *arg, int from_tty)
15271 struct breakpoint_ops *ops;
15273 /* Decide if we are dealing with a static tracepoint marker (`-m'),
15274 or with a normal static tracepoint. */
15275 if (arg && strncmp (arg, "-m", 2) == 0 && isspace (arg[2]))
15276 ops = &strace_marker_breakpoint_ops;
15278 ops = &tracepoint_breakpoint_ops;
15280 create_breakpoint (get_current_arch (),
15282 NULL, 0, NULL, 1 /* parse arg */,
15284 bp_static_tracepoint /* type_wanted */,
15285 0 /* Ignore count */,
15286 pending_break_support,
15290 0 /* internal */, 0);
15293 /* Set up a fake reader function that gets command lines from a linked
15294 list that was acquired during tracepoint uploading. */
15296 static struct uploaded_tp *this_utp;
15297 static int next_cmd;
15300 read_uploaded_action (void)
15304 VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt);
15311 /* Given information about a tracepoint as recorded on a target (which
15312 can be either a live system or a trace file), attempt to create an
15313 equivalent GDB tracepoint. This is not a reliable process, since
15314 the target does not necessarily have all the information used when
15315 the tracepoint was originally defined. */
15317 struct tracepoint *
15318 create_tracepoint_from_upload (struct uploaded_tp *utp)
15320 char *addr_str, small_buf[100];
15321 struct tracepoint *tp;
15323 if (utp->at_string)
15324 addr_str = utp->at_string;
15327 /* In the absence of a source location, fall back to raw
15328 address. Since there is no way to confirm that the address
15329 means the same thing as when the trace was started, warn the
15331 warning (_("Uploaded tracepoint %d has no "
15332 "source location, using raw address"),
15334 xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr));
15335 addr_str = small_buf;
15338 /* There's not much we can do with a sequence of bytecodes. */
15339 if (utp->cond && !utp->cond_string)
15340 warning (_("Uploaded tracepoint %d condition "
15341 "has no source form, ignoring it"),
15344 if (!create_breakpoint (get_current_arch (),
15346 utp->cond_string, -1, NULL,
15347 0 /* parse cond/thread */,
15349 utp->type /* type_wanted */,
15350 0 /* Ignore count */,
15351 pending_break_support,
15352 &tracepoint_breakpoint_ops,
15354 utp->enabled /* enabled */,
15356 CREATE_BREAKPOINT_FLAGS_INSERTED))
15359 /* Get the tracepoint we just created. */
15360 tp = get_tracepoint (tracepoint_count);
15361 gdb_assert (tp != NULL);
15365 xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass,
15368 trace_pass_command (small_buf, 0);
15371 /* If we have uploaded versions of the original commands, set up a
15372 special-purpose "reader" function and call the usual command line
15373 reader, then pass the result to the breakpoint command-setting
15375 if (!VEC_empty (char_ptr, utp->cmd_strings))
15377 struct command_line *cmd_list;
15382 cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL);
15384 breakpoint_set_commands (&tp->base, cmd_list);
15386 else if (!VEC_empty (char_ptr, utp->actions)
15387 || !VEC_empty (char_ptr, utp->step_actions))
15388 warning (_("Uploaded tracepoint %d actions "
15389 "have no source form, ignoring them"),
15392 /* Copy any status information that might be available. */
15393 tp->base.hit_count = utp->hit_count;
15394 tp->traceframe_usage = utp->traceframe_usage;
15399 /* Print information on tracepoint number TPNUM_EXP, or all if
15403 tracepoints_info (char *args, int from_tty)
15405 struct ui_out *uiout = current_uiout;
15408 num_printed = breakpoint_1 (args, 0, is_tracepoint);
15410 if (num_printed == 0)
15412 if (args == NULL || *args == '\0')
15413 ui_out_message (uiout, 0, "No tracepoints.\n");
15415 ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args);
15418 default_collect_info ();
15421 /* The 'enable trace' command enables tracepoints.
15422 Not supported by all targets. */
15424 enable_trace_command (char *args, int from_tty)
15426 enable_command (args, from_tty);
15429 /* The 'disable trace' command disables tracepoints.
15430 Not supported by all targets. */
15432 disable_trace_command (char *args, int from_tty)
15434 disable_command (args, from_tty);
15437 /* Remove a tracepoint (or all if no argument). */
15439 delete_trace_command (char *arg, int from_tty)
15441 struct breakpoint *b, *b_tmp;
15447 int breaks_to_delete = 0;
15449 /* Delete all breakpoints if no argument.
15450 Do not delete internal or call-dummy breakpoints, these
15451 have to be deleted with an explicit breakpoint number
15453 ALL_TRACEPOINTS (b)
15454 if (is_tracepoint (b) && user_breakpoint_p (b))
15456 breaks_to_delete = 1;
15460 /* Ask user only if there are some breakpoints to delete. */
15462 || (breaks_to_delete && query (_("Delete all tracepoints? "))))
15464 ALL_BREAKPOINTS_SAFE (b, b_tmp)
15465 if (is_tracepoint (b) && user_breakpoint_p (b))
15466 delete_breakpoint (b);
15470 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
15473 /* Helper function for trace_pass_command. */
15476 trace_pass_set_count (struct tracepoint *tp, int count, int from_tty)
15478 tp->pass_count = count;
15479 observer_notify_breakpoint_modified (&tp->base);
15481 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15482 tp->base.number, count);
15485 /* Set passcount for tracepoint.
15487 First command argument is passcount, second is tracepoint number.
15488 If tracepoint number omitted, apply to most recently defined.
15489 Also accepts special argument "all". */
15492 trace_pass_command (char *args, int from_tty)
15494 struct tracepoint *t1;
15495 unsigned int count;
15497 if (args == 0 || *args == 0)
15498 error (_("passcount command requires an "
15499 "argument (count + optional TP num)"));
15501 count = strtoul (args, &args, 10); /* Count comes first, then TP num. */
15503 args = skip_spaces (args);
15504 if (*args && strncasecmp (args, "all", 3) == 0)
15506 struct breakpoint *b;
15508 args += 3; /* Skip special argument "all". */
15510 error (_("Junk at end of arguments."));
15512 ALL_TRACEPOINTS (b)
15514 t1 = (struct tracepoint *) b;
15515 trace_pass_set_count (t1, count, from_tty);
15518 else if (*args == '\0')
15520 t1 = get_tracepoint_by_number (&args, NULL, 1);
15522 trace_pass_set_count (t1, count, from_tty);
15526 struct get_number_or_range_state state;
15528 init_number_or_range (&state, args);
15529 while (!state.finished)
15531 t1 = get_tracepoint_by_number (&args, &state, 1);
15533 trace_pass_set_count (t1, count, from_tty);
15538 struct tracepoint *
15539 get_tracepoint (int num)
15541 struct breakpoint *t;
15543 ALL_TRACEPOINTS (t)
15544 if (t->number == num)
15545 return (struct tracepoint *) t;
15550 /* Find the tracepoint with the given target-side number (which may be
15551 different from the tracepoint number after disconnecting and
15554 struct tracepoint *
15555 get_tracepoint_by_number_on_target (int num)
15557 struct breakpoint *b;
15559 ALL_TRACEPOINTS (b)
15561 struct tracepoint *t = (struct tracepoint *) b;
15563 if (t->number_on_target == num)
15570 /* Utility: parse a tracepoint number and look it up in the list.
15571 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15572 If OPTIONAL_P is true, then if the argument is missing, the most
15573 recent tracepoint (tracepoint_count) is returned. */
15574 struct tracepoint *
15575 get_tracepoint_by_number (char **arg,
15576 struct get_number_or_range_state *state,
15579 struct breakpoint *t;
15581 char *instring = arg == NULL ? NULL : *arg;
15585 gdb_assert (!state->finished);
15586 tpnum = get_number_or_range (state);
15588 else if (arg == NULL || *arg == NULL || ! **arg)
15591 tpnum = tracepoint_count;
15593 error_no_arg (_("tracepoint number"));
15596 tpnum = get_number (arg);
15600 if (instring && *instring)
15601 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15604 printf_filtered (_("Tracepoint argument missing "
15605 "and no previous tracepoint\n"));
15609 ALL_TRACEPOINTS (t)
15610 if (t->number == tpnum)
15612 return (struct tracepoint *) t;
15615 printf_unfiltered ("No tracepoint number %d.\n", tpnum);
15620 print_recreate_thread (struct breakpoint *b, struct ui_file *fp)
15622 if (b->thread != -1)
15623 fprintf_unfiltered (fp, " thread %d", b->thread);
15626 fprintf_unfiltered (fp, " task %d", b->task);
15628 fprintf_unfiltered (fp, "\n");
15631 /* Save information on user settable breakpoints (watchpoints, etc) to
15632 a new script file named FILENAME. If FILTER is non-NULL, call it
15633 on each breakpoint and only include the ones for which it returns
15637 save_breakpoints (char *filename, int from_tty,
15638 int (*filter) (const struct breakpoint *))
15640 struct breakpoint *tp;
15642 struct cleanup *cleanup;
15643 struct ui_file *fp;
15644 int extra_trace_bits = 0;
15646 if (filename == 0 || *filename == 0)
15647 error (_("Argument required (file name in which to save)"));
15649 /* See if we have anything to save. */
15650 ALL_BREAKPOINTS (tp)
15652 /* Skip internal and momentary breakpoints. */
15653 if (!user_breakpoint_p (tp))
15656 /* If we have a filter, only save the breakpoints it accepts. */
15657 if (filter && !filter (tp))
15662 if (is_tracepoint (tp))
15664 extra_trace_bits = 1;
15666 /* We can stop searching. */
15673 warning (_("Nothing to save."));
15677 filename = tilde_expand (filename);
15678 cleanup = make_cleanup (xfree, filename);
15679 fp = gdb_fopen (filename, "w");
15681 error (_("Unable to open file '%s' for saving (%s)"),
15682 filename, safe_strerror (errno));
15683 make_cleanup_ui_file_delete (fp);
15685 if (extra_trace_bits)
15686 save_trace_state_variables (fp);
15688 ALL_BREAKPOINTS (tp)
15690 /* Skip internal and momentary breakpoints. */
15691 if (!user_breakpoint_p (tp))
15694 /* If we have a filter, only save the breakpoints it accepts. */
15695 if (filter && !filter (tp))
15698 tp->ops->print_recreate (tp, fp);
15700 /* Note, we can't rely on tp->number for anything, as we can't
15701 assume the recreated breakpoint numbers will match. Use $bpnum
15704 if (tp->cond_string)
15705 fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string);
15707 if (tp->ignore_count)
15708 fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count);
15710 if (tp->type != bp_dprintf && tp->commands)
15712 volatile struct gdb_exception ex;
15714 fprintf_unfiltered (fp, " commands\n");
15716 ui_out_redirect (current_uiout, fp);
15717 TRY_CATCH (ex, RETURN_MASK_ALL)
15719 print_command_lines (current_uiout, tp->commands->commands, 2);
15721 ui_out_redirect (current_uiout, NULL);
15724 throw_exception (ex);
15726 fprintf_unfiltered (fp, " end\n");
15729 if (tp->enable_state == bp_disabled)
15730 fprintf_unfiltered (fp, "disable\n");
15732 /* If this is a multi-location breakpoint, check if the locations
15733 should be individually disabled. Watchpoint locations are
15734 special, and not user visible. */
15735 if (!is_watchpoint (tp) && tp->loc && tp->loc->next)
15737 struct bp_location *loc;
15740 for (loc = tp->loc; loc != NULL; loc = loc->next, n++)
15742 fprintf_unfiltered (fp, "disable $bpnum.%d\n", n);
15746 if (extra_trace_bits && *default_collect)
15747 fprintf_unfiltered (fp, "set default-collect %s\n", default_collect);
15750 printf_filtered (_("Saved to file '%s'.\n"), filename);
15751 do_cleanups (cleanup);
15754 /* The `save breakpoints' command. */
15757 save_breakpoints_command (char *args, int from_tty)
15759 save_breakpoints (args, from_tty, NULL);
15762 /* The `save tracepoints' command. */
15765 save_tracepoints_command (char *args, int from_tty)
15767 save_breakpoints (args, from_tty, is_tracepoint);
15770 /* Create a vector of all tracepoints. */
15772 VEC(breakpoint_p) *
15773 all_tracepoints (void)
15775 VEC(breakpoint_p) *tp_vec = 0;
15776 struct breakpoint *tp;
15778 ALL_TRACEPOINTS (tp)
15780 VEC_safe_push (breakpoint_p, tp_vec, tp);
15787 /* This help string is used for the break, hbreak, tbreak and thbreak
15788 commands. It is defined as a macro to prevent duplication.
15789 COMMAND should be a string constant containing the name of the
15791 #define BREAK_ARGS_HELP(command) \
15792 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15793 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15794 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15795 guessed probe type) or `-probe-stap' (for a SystemTap probe).\n\
15796 LOCATION may be a line number, function name, or \"*\" and an address.\n\
15797 If a line number is specified, break at start of code for that line.\n\
15798 If a function is specified, break at start of code for that function.\n\
15799 If an address is specified, break at that exact address.\n\
15800 With no LOCATION, uses current execution address of the selected\n\
15801 stack frame. This is useful for breaking on return to a stack frame.\n\
15803 THREADNUM is the number from \"info threads\".\n\
15804 CONDITION is a boolean expression.\n\
15806 Multiple breakpoints at one place are permitted, and useful if their\n\
15807 conditions are different.\n\
15809 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15811 /* List of subcommands for "catch". */
15812 static struct cmd_list_element *catch_cmdlist;
15814 /* List of subcommands for "tcatch". */
15815 static struct cmd_list_element *tcatch_cmdlist;
15818 add_catch_command (char *name, char *docstring,
15819 void (*sfunc) (char *args, int from_tty,
15820 struct cmd_list_element *command),
15821 completer_ftype *completer,
15822 void *user_data_catch,
15823 void *user_data_tcatch)
15825 struct cmd_list_element *command;
15827 command = add_cmd (name, class_breakpoint, NULL, docstring,
15829 set_cmd_sfunc (command, sfunc);
15830 set_cmd_context (command, user_data_catch);
15831 set_cmd_completer (command, completer);
15833 command = add_cmd (name, class_breakpoint, NULL, docstring,
15835 set_cmd_sfunc (command, sfunc);
15836 set_cmd_context (command, user_data_tcatch);
15837 set_cmd_completer (command, completer);
15841 clear_syscall_counts (struct inferior *inf)
15843 struct catch_syscall_inferior_data *inf_data
15844 = get_catch_syscall_inferior_data (inf);
15846 inf_data->total_syscalls_count = 0;
15847 inf_data->any_syscall_count = 0;
15848 VEC_free (int, inf_data->syscalls_counts);
15852 save_command (char *arg, int from_tty)
15854 printf_unfiltered (_("\"save\" must be followed by "
15855 "the name of a save subcommand.\n"));
15856 help_list (save_cmdlist, "save ", -1, gdb_stdout);
15859 struct breakpoint *
15860 iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *),
15863 struct breakpoint *b, *b_tmp;
15865 ALL_BREAKPOINTS_SAFE (b, b_tmp)
15867 if ((*callback) (b, data))
15874 /* Zero if any of the breakpoint's locations could be a location where
15875 functions have been inlined, nonzero otherwise. */
15878 is_non_inline_function (struct breakpoint *b)
15880 /* The shared library event breakpoint is set on the address of a
15881 non-inline function. */
15882 if (b->type == bp_shlib_event)
15888 /* Nonzero if the specified PC cannot be a location where functions
15889 have been inlined. */
15892 pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc,
15893 const struct target_waitstatus *ws)
15895 struct breakpoint *b;
15896 struct bp_location *bl;
15898 ALL_BREAKPOINTS (b)
15900 if (!is_non_inline_function (b))
15903 for (bl = b->loc; bl != NULL; bl = bl->next)
15905 if (!bl->shlib_disabled
15906 && bpstat_check_location (bl, aspace, pc, ws))
15914 /* Remove any references to OBJFILE which is going to be freed. */
15917 breakpoint_free_objfile (struct objfile *objfile)
15919 struct bp_location **locp, *loc;
15921 ALL_BP_LOCATIONS (loc, locp)
15922 if (loc->symtab != NULL && loc->symtab->objfile == objfile)
15923 loc->symtab = NULL;
15927 initialize_breakpoint_ops (void)
15929 static int initialized = 0;
15931 struct breakpoint_ops *ops;
15937 /* The breakpoint_ops structure to be inherit by all kinds of
15938 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15939 internal and momentary breakpoints, etc.). */
15940 ops = &bkpt_base_breakpoint_ops;
15941 *ops = base_breakpoint_ops;
15942 ops->re_set = bkpt_re_set;
15943 ops->insert_location = bkpt_insert_location;
15944 ops->remove_location = bkpt_remove_location;
15945 ops->breakpoint_hit = bkpt_breakpoint_hit;
15946 ops->create_sals_from_address = bkpt_create_sals_from_address;
15947 ops->create_breakpoints_sal = bkpt_create_breakpoints_sal;
15948 ops->decode_linespec = bkpt_decode_linespec;
15950 /* The breakpoint_ops structure to be used in regular breakpoints. */
15951 ops = &bkpt_breakpoint_ops;
15952 *ops = bkpt_base_breakpoint_ops;
15953 ops->re_set = bkpt_re_set;
15954 ops->resources_needed = bkpt_resources_needed;
15955 ops->print_it = bkpt_print_it;
15956 ops->print_mention = bkpt_print_mention;
15957 ops->print_recreate = bkpt_print_recreate;
15959 /* Ranged breakpoints. */
15960 ops = &ranged_breakpoint_ops;
15961 *ops = bkpt_breakpoint_ops;
15962 ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint;
15963 ops->resources_needed = resources_needed_ranged_breakpoint;
15964 ops->print_it = print_it_ranged_breakpoint;
15965 ops->print_one = print_one_ranged_breakpoint;
15966 ops->print_one_detail = print_one_detail_ranged_breakpoint;
15967 ops->print_mention = print_mention_ranged_breakpoint;
15968 ops->print_recreate = print_recreate_ranged_breakpoint;
15970 /* Internal breakpoints. */
15971 ops = &internal_breakpoint_ops;
15972 *ops = bkpt_base_breakpoint_ops;
15973 ops->re_set = internal_bkpt_re_set;
15974 ops->check_status = internal_bkpt_check_status;
15975 ops->print_it = internal_bkpt_print_it;
15976 ops->print_mention = internal_bkpt_print_mention;
15978 /* Momentary breakpoints. */
15979 ops = &momentary_breakpoint_ops;
15980 *ops = bkpt_base_breakpoint_ops;
15981 ops->re_set = momentary_bkpt_re_set;
15982 ops->check_status = momentary_bkpt_check_status;
15983 ops->print_it = momentary_bkpt_print_it;
15984 ops->print_mention = momentary_bkpt_print_mention;
15986 /* Momentary breakpoints for bp_longjmp and bp_exception. */
15987 ops = &longjmp_breakpoint_ops;
15988 *ops = momentary_breakpoint_ops;
15989 ops->dtor = longjmp_bkpt_dtor;
15991 /* Probe breakpoints. */
15992 ops = &bkpt_probe_breakpoint_ops;
15993 *ops = bkpt_breakpoint_ops;
15994 ops->insert_location = bkpt_probe_insert_location;
15995 ops->remove_location = bkpt_probe_remove_location;
15996 ops->create_sals_from_address = bkpt_probe_create_sals_from_address;
15997 ops->decode_linespec = bkpt_probe_decode_linespec;
16000 ops = &watchpoint_breakpoint_ops;
16001 *ops = base_breakpoint_ops;
16002 ops->dtor = dtor_watchpoint;
16003 ops->re_set = re_set_watchpoint;
16004 ops->insert_location = insert_watchpoint;
16005 ops->remove_location = remove_watchpoint;
16006 ops->breakpoint_hit = breakpoint_hit_watchpoint;
16007 ops->check_status = check_status_watchpoint;
16008 ops->resources_needed = resources_needed_watchpoint;
16009 ops->works_in_software_mode = works_in_software_mode_watchpoint;
16010 ops->print_it = print_it_watchpoint;
16011 ops->print_mention = print_mention_watchpoint;
16012 ops->print_recreate = print_recreate_watchpoint;
16013 ops->explains_signal = explains_signal_watchpoint;
16015 /* Masked watchpoints. */
16016 ops = &masked_watchpoint_breakpoint_ops;
16017 *ops = watchpoint_breakpoint_ops;
16018 ops->insert_location = insert_masked_watchpoint;
16019 ops->remove_location = remove_masked_watchpoint;
16020 ops->resources_needed = resources_needed_masked_watchpoint;
16021 ops->works_in_software_mode = works_in_software_mode_masked_watchpoint;
16022 ops->print_it = print_it_masked_watchpoint;
16023 ops->print_one_detail = print_one_detail_masked_watchpoint;
16024 ops->print_mention = print_mention_masked_watchpoint;
16025 ops->print_recreate = print_recreate_masked_watchpoint;
16028 ops = &tracepoint_breakpoint_ops;
16029 *ops = base_breakpoint_ops;
16030 ops->re_set = tracepoint_re_set;
16031 ops->breakpoint_hit = tracepoint_breakpoint_hit;
16032 ops->print_one_detail = tracepoint_print_one_detail;
16033 ops->print_mention = tracepoint_print_mention;
16034 ops->print_recreate = tracepoint_print_recreate;
16035 ops->create_sals_from_address = tracepoint_create_sals_from_address;
16036 ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal;
16037 ops->decode_linespec = tracepoint_decode_linespec;
16039 /* Probe tracepoints. */
16040 ops = &tracepoint_probe_breakpoint_ops;
16041 *ops = tracepoint_breakpoint_ops;
16042 ops->create_sals_from_address = tracepoint_probe_create_sals_from_address;
16043 ops->decode_linespec = tracepoint_probe_decode_linespec;
16045 /* Static tracepoints with marker (`-m'). */
16046 ops = &strace_marker_breakpoint_ops;
16047 *ops = tracepoint_breakpoint_ops;
16048 ops->create_sals_from_address = strace_marker_create_sals_from_address;
16049 ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal;
16050 ops->decode_linespec = strace_marker_decode_linespec;
16052 /* Fork catchpoints. */
16053 ops = &catch_fork_breakpoint_ops;
16054 *ops = base_breakpoint_ops;
16055 ops->insert_location = insert_catch_fork;
16056 ops->remove_location = remove_catch_fork;
16057 ops->breakpoint_hit = breakpoint_hit_catch_fork;
16058 ops->print_it = print_it_catch_fork;
16059 ops->print_one = print_one_catch_fork;
16060 ops->print_mention = print_mention_catch_fork;
16061 ops->print_recreate = print_recreate_catch_fork;
16063 /* Vfork catchpoints. */
16064 ops = &catch_vfork_breakpoint_ops;
16065 *ops = base_breakpoint_ops;
16066 ops->insert_location = insert_catch_vfork;
16067 ops->remove_location = remove_catch_vfork;
16068 ops->breakpoint_hit = breakpoint_hit_catch_vfork;
16069 ops->print_it = print_it_catch_vfork;
16070 ops->print_one = print_one_catch_vfork;
16071 ops->print_mention = print_mention_catch_vfork;
16072 ops->print_recreate = print_recreate_catch_vfork;
16074 /* Exec catchpoints. */
16075 ops = &catch_exec_breakpoint_ops;
16076 *ops = base_breakpoint_ops;
16077 ops->dtor = dtor_catch_exec;
16078 ops->insert_location = insert_catch_exec;
16079 ops->remove_location = remove_catch_exec;
16080 ops->breakpoint_hit = breakpoint_hit_catch_exec;
16081 ops->print_it = print_it_catch_exec;
16082 ops->print_one = print_one_catch_exec;
16083 ops->print_mention = print_mention_catch_exec;
16084 ops->print_recreate = print_recreate_catch_exec;
16086 /* Syscall catchpoints. */
16087 ops = &catch_syscall_breakpoint_ops;
16088 *ops = base_breakpoint_ops;
16089 ops->dtor = dtor_catch_syscall;
16090 ops->insert_location = insert_catch_syscall;
16091 ops->remove_location = remove_catch_syscall;
16092 ops->breakpoint_hit = breakpoint_hit_catch_syscall;
16093 ops->print_it = print_it_catch_syscall;
16094 ops->print_one = print_one_catch_syscall;
16095 ops->print_mention = print_mention_catch_syscall;
16096 ops->print_recreate = print_recreate_catch_syscall;
16098 /* Solib-related catchpoints. */
16099 ops = &catch_solib_breakpoint_ops;
16100 *ops = base_breakpoint_ops;
16101 ops->dtor = dtor_catch_solib;
16102 ops->insert_location = insert_catch_solib;
16103 ops->remove_location = remove_catch_solib;
16104 ops->breakpoint_hit = breakpoint_hit_catch_solib;
16105 ops->check_status = check_status_catch_solib;
16106 ops->print_it = print_it_catch_solib;
16107 ops->print_one = print_one_catch_solib;
16108 ops->print_mention = print_mention_catch_solib;
16109 ops->print_recreate = print_recreate_catch_solib;
16111 ops = &dprintf_breakpoint_ops;
16112 *ops = bkpt_base_breakpoint_ops;
16113 ops->re_set = dprintf_re_set;
16114 ops->resources_needed = bkpt_resources_needed;
16115 ops->print_it = bkpt_print_it;
16116 ops->print_mention = bkpt_print_mention;
16117 ops->print_recreate = dprintf_print_recreate;
16118 ops->after_condition_true = dprintf_after_condition_true;
16121 /* Chain containing all defined "enable breakpoint" subcommands. */
16123 static struct cmd_list_element *enablebreaklist = NULL;
16126 _initialize_breakpoint (void)
16128 struct cmd_list_element *c;
16130 initialize_breakpoint_ops ();
16132 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
16133 observer_attach_free_objfile (disable_breakpoints_in_freed_objfile);
16134 observer_attach_inferior_exit (clear_syscall_counts);
16135 observer_attach_memory_changed (invalidate_bp_value_on_memory_change);
16137 breakpoint_objfile_key
16138 = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes);
16140 catch_syscall_inferior_data
16141 = register_inferior_data_with_cleanup (NULL,
16142 catch_syscall_inferior_data_cleanup);
16144 breakpoint_chain = 0;
16145 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
16146 before a breakpoint is set. */
16147 breakpoint_count = 0;
16149 tracepoint_count = 0;
16151 add_com ("ignore", class_breakpoint, ignore_command, _("\
16152 Set ignore-count of breakpoint number N to COUNT.\n\
16153 Usage is `ignore N COUNT'."));
16155 add_com_alias ("bc", "ignore", class_breakpoint, 1);
16157 add_com ("commands", class_breakpoint, commands_command, _("\
16158 Set commands to be executed when a breakpoint is hit.\n\
16159 Give breakpoint number as argument after \"commands\".\n\
16160 With no argument, the targeted breakpoint is the last one set.\n\
16161 The commands themselves follow starting on the next line.\n\
16162 Type a line containing \"end\" to indicate the end of them.\n\
16163 Give \"silent\" as the first line to make the breakpoint silent;\n\
16164 then no output is printed when it is hit, except what the commands print."));
16166 c = add_com ("condition", class_breakpoint, condition_command, _("\
16167 Specify breakpoint number N to break only if COND is true.\n\
16168 Usage is `condition N COND', where N is an integer and COND is an\n\
16169 expression to be evaluated whenever breakpoint N is reached."));
16170 set_cmd_completer (c, condition_completer);
16172 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
16173 Set a temporary breakpoint.\n\
16174 Like \"break\" except the breakpoint is only temporary,\n\
16175 so it will be deleted when hit. Equivalent to \"break\" followed\n\
16176 by using \"enable delete\" on the breakpoint number.\n\
16178 BREAK_ARGS_HELP ("tbreak")));
16179 set_cmd_completer (c, location_completer);
16181 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
16182 Set a hardware assisted breakpoint.\n\
16183 Like \"break\" except the breakpoint requires hardware support,\n\
16184 some target hardware may not have this support.\n\
16186 BREAK_ARGS_HELP ("hbreak")));
16187 set_cmd_completer (c, location_completer);
16189 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
16190 Set a temporary hardware assisted breakpoint.\n\
16191 Like \"hbreak\" except the breakpoint is only temporary,\n\
16192 so it will be deleted when hit.\n\
16194 BREAK_ARGS_HELP ("thbreak")));
16195 set_cmd_completer (c, location_completer);
16197 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
16198 Enable some breakpoints.\n\
16199 Give breakpoint numbers (separated by spaces) as arguments.\n\
16200 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16201 This is used to cancel the effect of the \"disable\" command.\n\
16202 With a subcommand you can enable temporarily."),
16203 &enablelist, "enable ", 1, &cmdlist);
16205 add_com ("ab", class_breakpoint, enable_command, _("\
16206 Enable some breakpoints.\n\
16207 Give breakpoint numbers (separated by spaces) as arguments.\n\
16208 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16209 This is used to cancel the effect of the \"disable\" command.\n\
16210 With a subcommand you can enable temporarily."));
16212 add_com_alias ("en", "enable", class_breakpoint, 1);
16214 add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
16215 Enable some breakpoints.\n\
16216 Give breakpoint numbers (separated by spaces) as arguments.\n\
16217 This is used to cancel the effect of the \"disable\" command.\n\
16218 May be abbreviated to simply \"enable\".\n"),
16219 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
16221 add_cmd ("once", no_class, enable_once_command, _("\
16222 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16223 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16226 add_cmd ("delete", no_class, enable_delete_command, _("\
16227 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16228 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16231 add_cmd ("count", no_class, enable_count_command, _("\
16232 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16233 If a breakpoint is hit while enabled in this fashion,\n\
16234 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16237 add_cmd ("delete", no_class, enable_delete_command, _("\
16238 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16239 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16242 add_cmd ("once", no_class, enable_once_command, _("\
16243 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16244 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16247 add_cmd ("count", no_class, enable_count_command, _("\
16248 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16249 If a breakpoint is hit while enabled in this fashion,\n\
16250 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16253 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
16254 Disable some breakpoints.\n\
16255 Arguments are breakpoint numbers with spaces in between.\n\
16256 To disable all breakpoints, give no argument.\n\
16257 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
16258 &disablelist, "disable ", 1, &cmdlist);
16259 add_com_alias ("dis", "disable", class_breakpoint, 1);
16260 add_com_alias ("disa", "disable", class_breakpoint, 1);
16262 add_com ("sb", class_breakpoint, disable_command, _("\
16263 Disable some breakpoints.\n\
16264 Arguments are breakpoint numbers with spaces in between.\n\
16265 To disable all breakpoints, give no argument.\n\
16266 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
16268 add_cmd ("breakpoints", class_alias, disable_command, _("\
16269 Disable some breakpoints.\n\
16270 Arguments are breakpoint numbers with spaces in between.\n\
16271 To disable all breakpoints, give no argument.\n\
16272 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
16273 This command may be abbreviated \"disable\"."),
16276 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
16277 Delete some breakpoints or auto-display expressions.\n\
16278 Arguments are breakpoint numbers with spaces in between.\n\
16279 To delete all breakpoints, give no argument.\n\
16281 Also a prefix command for deletion of other GDB objects.\n\
16282 The \"unset\" command is also an alias for \"delete\"."),
16283 &deletelist, "delete ", 1, &cmdlist);
16284 add_com_alias ("d", "delete", class_breakpoint, 1);
16285 add_com_alias ("del", "delete", class_breakpoint, 1);
16287 add_com ("db", class_breakpoint, delete_command, _("\
16288 Delete some breakpoints.\n\
16289 Arguments are breakpoint numbers with spaces in between.\n\
16290 To delete all breakpoints, give no argument.\n"));
16292 add_cmd ("breakpoints", class_alias, delete_command, _("\
16293 Delete some breakpoints or auto-display expressions.\n\
16294 Arguments are breakpoint numbers with spaces in between.\n\
16295 To delete all breakpoints, give no argument.\n\
16296 This command may be abbreviated \"delete\"."),
16299 add_com ("clear", class_breakpoint, clear_command, _("\
16300 Clear breakpoint at specified line or function.\n\
16301 Argument may be line number, function name, or \"*\" and an address.\n\
16302 If line number is specified, all breakpoints in that line are cleared.\n\
16303 If function is specified, breakpoints at beginning of function are cleared.\n\
16304 If an address is specified, breakpoints at that address are cleared.\n\
16306 With no argument, clears all breakpoints in the line that the selected frame\n\
16307 is executing in.\n\
16309 See also the \"delete\" command which clears breakpoints by number."));
16310 add_com_alias ("cl", "clear", class_breakpoint, 1);
16312 c = add_com ("break", class_breakpoint, break_command, _("\
16313 Set breakpoint at specified line or function.\n"
16314 BREAK_ARGS_HELP ("break")));
16315 set_cmd_completer (c, location_completer);
16317 add_com_alias ("b", "break", class_run, 1);
16318 add_com_alias ("br", "break", class_run, 1);
16319 add_com_alias ("bre", "break", class_run, 1);
16320 add_com_alias ("brea", "break", class_run, 1);
16323 add_com_alias ("ba", "break", class_breakpoint, 1);
16327 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
16328 Break in function/address or break at a line in the current file."),
16329 &stoplist, "stop ", 1, &cmdlist);
16330 add_cmd ("in", class_breakpoint, stopin_command,
16331 _("Break in function or address."), &stoplist);
16332 add_cmd ("at", class_breakpoint, stopat_command,
16333 _("Break at a line in the current file."), &stoplist);
16334 add_com ("status", class_info, breakpoints_info, _("\
16335 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16336 The \"Type\" column indicates one of:\n\
16337 \tbreakpoint - normal breakpoint\n\
16338 \twatchpoint - watchpoint\n\
16339 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16340 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16341 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16342 address and file/line number respectively.\n\
16344 Convenience variable \"$_\" and default examine address for \"x\"\n\
16345 are set to the address of the last breakpoint listed unless the command\n\
16346 is prefixed with \"server \".\n\n\
16347 Convenience variable \"$bpnum\" contains the number of the last\n\
16348 breakpoint set."));
16351 add_info ("breakpoints", breakpoints_info, _("\
16352 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
16353 The \"Type\" column indicates one of:\n\
16354 \tbreakpoint - normal breakpoint\n\
16355 \twatchpoint - watchpoint\n\
16356 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16357 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16358 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16359 address and file/line number respectively.\n\
16361 Convenience variable \"$_\" and default examine address for \"x\"\n\
16362 are set to the address of the last breakpoint listed unless the command\n\
16363 is prefixed with \"server \".\n\n\
16364 Convenience variable \"$bpnum\" contains the number of the last\n\
16365 breakpoint set."));
16367 add_info_alias ("b", "breakpoints", 1);
16370 add_com ("lb", class_breakpoint, breakpoints_info, _("\
16371 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16372 The \"Type\" column indicates one of:\n\
16373 \tbreakpoint - normal breakpoint\n\
16374 \twatchpoint - watchpoint\n\
16375 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16376 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16377 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16378 address and file/line number respectively.\n\
16380 Convenience variable \"$_\" and default examine address for \"x\"\n\
16381 are set to the address of the last breakpoint listed unless the command\n\
16382 is prefixed with \"server \".\n\n\
16383 Convenience variable \"$bpnum\" contains the number of the last\n\
16384 breakpoint set."));
16386 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
16387 Status of all breakpoints, or breakpoint number NUMBER.\n\
16388 The \"Type\" column indicates one of:\n\
16389 \tbreakpoint - normal breakpoint\n\
16390 \twatchpoint - watchpoint\n\
16391 \tlongjmp - internal breakpoint used to step through longjmp()\n\
16392 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
16393 \tuntil - internal breakpoint used by the \"until\" command\n\
16394 \tfinish - internal breakpoint used by the \"finish\" command\n\
16395 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16396 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16397 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16398 address and file/line number respectively.\n\
16400 Convenience variable \"$_\" and default examine address for \"x\"\n\
16401 are set to the address of the last breakpoint listed unless the command\n\
16402 is prefixed with \"server \".\n\n\
16403 Convenience variable \"$bpnum\" contains the number of the last\n\
16405 &maintenanceinfolist);
16407 add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\
16408 Set catchpoints to catch events."),
16409 &catch_cmdlist, "catch ",
16410 0/*allow-unknown*/, &cmdlist);
16412 add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\
16413 Set temporary catchpoints to catch events."),
16414 &tcatch_cmdlist, "tcatch ",
16415 0/*allow-unknown*/, &cmdlist);
16417 add_catch_command ("fork", _("Catch calls to fork."),
16418 catch_fork_command_1,
16420 (void *) (uintptr_t) catch_fork_permanent,
16421 (void *) (uintptr_t) catch_fork_temporary);
16422 add_catch_command ("vfork", _("Catch calls to vfork."),
16423 catch_fork_command_1,
16425 (void *) (uintptr_t) catch_vfork_permanent,
16426 (void *) (uintptr_t) catch_vfork_temporary);
16427 add_catch_command ("exec", _("Catch calls to exec."),
16428 catch_exec_command_1,
16432 add_catch_command ("load", _("Catch loads of shared libraries.\n\
16433 Usage: catch load [REGEX]\n\
16434 If REGEX is given, only stop for libraries matching the regular expression."),
16435 catch_load_command_1,
16439 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
16440 Usage: catch unload [REGEX]\n\
16441 If REGEX is given, only stop for libraries matching the regular expression."),
16442 catch_unload_command_1,
16446 add_catch_command ("syscall", _("\
16447 Catch system calls by their names and/or numbers.\n\
16448 Arguments say which system calls to catch. If no arguments\n\
16449 are given, every system call will be caught.\n\
16450 Arguments, if given, should be one or more system call names\n\
16451 (if your system supports that), or system call numbers."),
16452 catch_syscall_command_1,
16453 catch_syscall_completer,
16457 c = add_com ("watch", class_breakpoint, watch_command, _("\
16458 Set a watchpoint for an expression.\n\
16459 Usage: watch [-l|-location] EXPRESSION\n\
16460 A watchpoint stops execution of your program whenever the value of\n\
16461 an expression changes.\n\
16462 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16463 the memory to which it refers."));
16464 set_cmd_completer (c, expression_completer);
16466 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
16467 Set a read watchpoint for an expression.\n\
16468 Usage: rwatch [-l|-location] EXPRESSION\n\
16469 A watchpoint stops execution of your program whenever the value of\n\
16470 an expression is read.\n\
16471 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16472 the memory to which it refers."));
16473 set_cmd_completer (c, expression_completer);
16475 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
16476 Set a watchpoint for an expression.\n\
16477 Usage: awatch [-l|-location] EXPRESSION\n\
16478 A watchpoint stops execution of your program whenever the value of\n\
16479 an expression is either read or written.\n\
16480 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16481 the memory to which it refers."));
16482 set_cmd_completer (c, expression_completer);
16484 add_info ("watchpoints", watchpoints_info, _("\
16485 Status of specified watchpoints (all watchpoints if no argument)."));
16487 /* XXX: cagney/2005-02-23: This should be a boolean, and should
16488 respond to changes - contrary to the description. */
16489 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
16490 &can_use_hw_watchpoints, _("\
16491 Set debugger's willingness to use watchpoint hardware."), _("\
16492 Show debugger's willingness to use watchpoint hardware."), _("\
16493 If zero, gdb will not use hardware for new watchpoints, even if\n\
16494 such is available. (However, any hardware watchpoints that were\n\
16495 created before setting this to nonzero, will continue to use watchpoint\n\
16498 show_can_use_hw_watchpoints,
16499 &setlist, &showlist);
16501 can_use_hw_watchpoints = 1;
16503 /* Tracepoint manipulation commands. */
16505 c = add_com ("trace", class_breakpoint, trace_command, _("\
16506 Set a tracepoint at specified line or function.\n\
16508 BREAK_ARGS_HELP ("trace") "\n\
16509 Do \"help tracepoints\" for info on other tracepoint commands."));
16510 set_cmd_completer (c, location_completer);
16512 add_com_alias ("tp", "trace", class_alias, 0);
16513 add_com_alias ("tr", "trace", class_alias, 1);
16514 add_com_alias ("tra", "trace", class_alias, 1);
16515 add_com_alias ("trac", "trace", class_alias, 1);
16517 c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\
16518 Set a fast tracepoint at specified line or function.\n\
16520 BREAK_ARGS_HELP ("ftrace") "\n\
16521 Do \"help tracepoints\" for info on other tracepoint commands."));
16522 set_cmd_completer (c, location_completer);
16524 c = add_com ("strace", class_breakpoint, strace_command, _("\
16525 Set a static tracepoint at specified line, function or marker.\n\
16527 strace [LOCATION] [if CONDITION]\n\
16528 LOCATION may be a line number, function name, \"*\" and an address,\n\
16529 or -m MARKER_ID.\n\
16530 If a line number is specified, probe the marker at start of code\n\
16531 for that line. If a function is specified, probe the marker at start\n\
16532 of code for that function. If an address is specified, probe the marker\n\
16533 at that exact address. If a marker id is specified, probe the marker\n\
16534 with that name. With no LOCATION, uses current execution address of\n\
16535 the selected stack frame.\n\
16536 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16537 This collects arbitrary user data passed in the probe point call to the\n\
16538 tracing library. You can inspect it when analyzing the trace buffer,\n\
16539 by printing the $_sdata variable like any other convenience variable.\n\
16541 CONDITION is a boolean expression.\n\
16543 Multiple tracepoints at one place are permitted, and useful if their\n\
16544 conditions are different.\n\
16546 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16547 Do \"help tracepoints\" for info on other tracepoint commands."));
16548 set_cmd_completer (c, location_completer);
16550 add_info ("tracepoints", tracepoints_info, _("\
16551 Status of specified tracepoints (all tracepoints if no argument).\n\
16552 Convenience variable \"$tpnum\" contains the number of the\n\
16553 last tracepoint set."));
16555 add_info_alias ("tp", "tracepoints", 1);
16557 add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
16558 Delete specified tracepoints.\n\
16559 Arguments are tracepoint numbers, separated by spaces.\n\
16560 No argument means delete all tracepoints."),
16562 add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist);
16564 c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
16565 Disable specified tracepoints.\n\
16566 Arguments are tracepoint numbers, separated by spaces.\n\
16567 No argument means disable all tracepoints."),
16569 deprecate_cmd (c, "disable");
16571 c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\
16572 Enable specified tracepoints.\n\
16573 Arguments are tracepoint numbers, separated by spaces.\n\
16574 No argument means enable all tracepoints."),
16576 deprecate_cmd (c, "enable");
16578 add_com ("passcount", class_trace, trace_pass_command, _("\
16579 Set the passcount for a tracepoint.\n\
16580 The trace will end when the tracepoint has been passed 'count' times.\n\
16581 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16582 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16584 add_prefix_cmd ("save", class_breakpoint, save_command,
16585 _("Save breakpoint definitions as a script."),
16586 &save_cmdlist, "save ",
16587 0/*allow-unknown*/, &cmdlist);
16589 c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\
16590 Save current breakpoint definitions as a script.\n\
16591 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16592 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16593 session to restore them."),
16595 set_cmd_completer (c, filename_completer);
16597 c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\
16598 Save current tracepoint definitions as a script.\n\
16599 Use the 'source' command in another debug session to restore them."),
16601 set_cmd_completer (c, filename_completer);
16603 c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0);
16604 deprecate_cmd (c, "save tracepoints");
16606 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
16607 Breakpoint specific settings\n\
16608 Configure various breakpoint-specific variables such as\n\
16609 pending breakpoint behavior"),
16610 &breakpoint_set_cmdlist, "set breakpoint ",
16611 0/*allow-unknown*/, &setlist);
16612 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
16613 Breakpoint specific settings\n\
16614 Configure various breakpoint-specific variables such as\n\
16615 pending breakpoint behavior"),
16616 &breakpoint_show_cmdlist, "show breakpoint ",
16617 0/*allow-unknown*/, &showlist);
16619 add_setshow_auto_boolean_cmd ("pending", no_class,
16620 &pending_break_support, _("\
16621 Set debugger's behavior regarding pending breakpoints."), _("\
16622 Show debugger's behavior regarding pending breakpoints."), _("\
16623 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16624 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16625 an error. If auto, an unrecognized breakpoint location results in a\n\
16626 user-query to see if a pending breakpoint should be created."),
16628 show_pending_break_support,
16629 &breakpoint_set_cmdlist,
16630 &breakpoint_show_cmdlist);
16632 pending_break_support = AUTO_BOOLEAN_AUTO;
16634 add_setshow_boolean_cmd ("auto-hw", no_class,
16635 &automatic_hardware_breakpoints, _("\
16636 Set automatic usage of hardware breakpoints."), _("\
16637 Show automatic usage of hardware breakpoints."), _("\
16638 If set, the debugger will automatically use hardware breakpoints for\n\
16639 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16640 a warning will be emitted for such breakpoints."),
16642 show_automatic_hardware_breakpoints,
16643 &breakpoint_set_cmdlist,
16644 &breakpoint_show_cmdlist);
16646 add_setshow_auto_boolean_cmd ("always-inserted", class_support,
16647 &always_inserted_mode, _("\
16648 Set mode for inserting breakpoints."), _("\
16649 Show mode for inserting breakpoints."), _("\
16650 When this mode is off, breakpoints are inserted in inferior when it is\n\
16651 resumed, and removed when execution stops. When this mode is on,\n\
16652 breakpoints are inserted immediately and removed only when the user\n\
16653 deletes the breakpoint. When this mode is auto (which is the default),\n\
16654 the behaviour depends on the non-stop setting (see help set non-stop).\n\
16655 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
16656 behaves as if always-inserted mode is on; if gdb is controlling the\n\
16657 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
16659 &show_always_inserted_mode,
16660 &breakpoint_set_cmdlist,
16661 &breakpoint_show_cmdlist);
16663 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint,
16664 condition_evaluation_enums,
16665 &condition_evaluation_mode_1, _("\
16666 Set mode of breakpoint condition evaluation."), _("\
16667 Show mode of breakpoint condition evaluation."), _("\
16668 When this is set to \"host\", breakpoint conditions will be\n\
16669 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16670 breakpoint conditions will be downloaded to the target (if the target\n\
16671 supports such feature) and conditions will be evaluated on the target's side.\n\
16672 If this is set to \"auto\" (default), this will be automatically set to\n\
16673 \"target\" if it supports condition evaluation, otherwise it will\n\
16674 be set to \"gdb\""),
16675 &set_condition_evaluation_mode,
16676 &show_condition_evaluation_mode,
16677 &breakpoint_set_cmdlist,
16678 &breakpoint_show_cmdlist);
16680 add_com ("break-range", class_breakpoint, break_range_command, _("\
16681 Set a breakpoint for an address range.\n\
16682 break-range START-LOCATION, END-LOCATION\n\
16683 where START-LOCATION and END-LOCATION can be one of the following:\n\
16684 LINENUM, for that line in the current file,\n\
16685 FILE:LINENUM, for that line in that file,\n\
16686 +OFFSET, for that number of lines after the current line\n\
16687 or the start of the range\n\
16688 FUNCTION, for the first line in that function,\n\
16689 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16690 *ADDRESS, for the instruction at that address.\n\
16692 The breakpoint will stop execution of the inferior whenever it executes\n\
16693 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16694 range (including START-LOCATION and END-LOCATION)."));
16696 c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\
16697 Set a dynamic printf at specified line or function.\n\
16698 dprintf location,format string,arg1,arg2,...\n\
16699 location may be a line number, function name, or \"*\" and an address.\n\
16700 If a line number is specified, break at start of code for that line.\n\
16701 If a function is specified, break at start of code for that function."));
16702 set_cmd_completer (c, location_completer);
16704 add_setshow_enum_cmd ("dprintf-style", class_support,
16705 dprintf_style_enums, &dprintf_style, _("\
16706 Set the style of usage for dynamic printf."), _("\
16707 Show the style of usage for dynamic printf."), _("\
16708 This setting chooses how GDB will do a dynamic printf.\n\
16709 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16710 console, as with the \"printf\" command.\n\
16711 If the value is \"call\", the print is done by calling a function in your\n\
16712 program; by default printf(), but you can choose a different function or\n\
16713 output stream by setting dprintf-function and dprintf-channel."),
16714 update_dprintf_commands, NULL,
16715 &setlist, &showlist);
16717 dprintf_function = xstrdup ("printf");
16718 add_setshow_string_cmd ("dprintf-function", class_support,
16719 &dprintf_function, _("\
16720 Set the function to use for dynamic printf"), _("\
16721 Show the function to use for dynamic printf"), NULL,
16722 update_dprintf_commands, NULL,
16723 &setlist, &showlist);
16725 dprintf_channel = xstrdup ("");
16726 add_setshow_string_cmd ("dprintf-channel", class_support,
16727 &dprintf_channel, _("\
16728 Set the channel to use for dynamic printf"), _("\
16729 Show the channel to use for dynamic printf"), NULL,
16730 update_dprintf_commands, NULL,
16731 &setlist, &showlist);
16733 add_setshow_boolean_cmd ("disconnected-dprintf", no_class,
16734 &disconnected_dprintf, _("\
16735 Set whether dprintf continues after GDB disconnects."), _("\
16736 Show whether dprintf continues after GDB disconnects."), _("\
16737 Use this to let dprintf commands continue to hit and produce output\n\
16738 even if GDB disconnects or detaches from the target."),
16741 &setlist, &showlist);
16743 add_com ("agent-printf", class_vars, agent_printf_command, _("\
16744 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16745 (target agent only) This is useful for formatted output in user-defined commands."));
16747 automatic_hardware_breakpoints = 1;
16749 observer_attach_about_to_proceed (breakpoint_about_to_proceed);
16750 observer_attach_thread_exit (remove_threaded_breakpoints);