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"
36 #include "gdbthread.h"
40 #include "gdb-demangle.h"
41 #include "filenames.h"
47 #include "completer.h"
50 #include "cli/cli-script.h"
51 #include "gdb_assert.h"
56 #include "exceptions.h"
62 #include "xml-syscall.h"
63 #include "parser-defs.h"
64 #include "gdb_regex.h"
66 #include "cli/cli-utils.h"
67 #include "continuations.h"
71 #include "dummy-frame.h"
75 /* readline include files */
76 #include "readline/readline.h"
77 #include "readline/history.h"
79 /* readline defines this. */
82 #include "mi/mi-common.h"
83 #include "extension.h"
85 /* Enums for exception-handling support. */
86 enum exception_event_kind
93 /* Prototypes for local functions. */
95 static void enable_delete_command (char *, int);
97 static void enable_once_command (char *, int);
99 static void enable_count_command (char *, int);
101 static void disable_command (char *, int);
103 static void enable_command (char *, int);
105 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *,
109 static void ignore_command (char *, int);
111 static int breakpoint_re_set_one (void *);
113 static void breakpoint_re_set_default (struct breakpoint *);
115 static void create_sals_from_address_default (char **,
116 struct linespec_result *,
120 static void create_breakpoints_sal_default (struct gdbarch *,
121 struct linespec_result *,
122 char *, char *, enum bptype,
123 enum bpdisp, int, int,
125 const struct breakpoint_ops *,
126 int, int, int, unsigned);
128 static void decode_linespec_default (struct breakpoint *, char **,
129 struct symtabs_and_lines *);
131 static void clear_command (char *, int);
133 static void catch_command (char *, int);
135 static int can_use_hardware_watchpoint (struct value *);
137 static void break_command_1 (char *, int, int);
139 static void mention (struct breakpoint *);
141 static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *,
143 const struct breakpoint_ops *);
144 static struct bp_location *add_location_to_breakpoint (struct breakpoint *,
145 const struct symtab_and_line *);
147 /* This function is used in gdbtk sources and thus can not be made
149 struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch,
150 struct symtab_and_line,
152 const struct breakpoint_ops *);
154 static struct breakpoint *
155 momentary_breakpoint_from_master (struct breakpoint *orig,
157 const struct breakpoint_ops *ops,
160 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
162 static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch,
166 static void describe_other_breakpoints (struct gdbarch *,
167 struct program_space *, CORE_ADDR,
168 struct obj_section *, int);
170 static int watchpoint_locations_match (struct bp_location *loc1,
171 struct bp_location *loc2);
173 static int breakpoint_location_address_match (struct bp_location *bl,
174 struct address_space *aspace,
177 static void breakpoints_info (char *, int);
179 static void watchpoints_info (char *, int);
181 static int breakpoint_1 (char *, int,
182 int (*) (const struct breakpoint *));
184 static int breakpoint_cond_eval (void *);
186 static void cleanup_executing_breakpoints (void *);
188 static void commands_command (char *, int);
190 static void condition_command (char *, int);
199 static int remove_breakpoint (struct bp_location *, insertion_state_t);
200 static int remove_breakpoint_1 (struct bp_location *, insertion_state_t);
202 static enum print_stop_action print_bp_stop_message (bpstat bs);
204 static int watchpoint_check (void *);
206 static void maintenance_info_breakpoints (char *, int);
208 static int hw_breakpoint_used_count (void);
210 static int hw_watchpoint_use_count (struct breakpoint *);
212 static int hw_watchpoint_used_count_others (struct breakpoint *except,
214 int *other_type_used);
216 static void hbreak_command (char *, int);
218 static void thbreak_command (char *, int);
220 static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp,
223 static void stop_command (char *arg, int from_tty);
225 static void stopin_command (char *arg, int from_tty);
227 static void stopat_command (char *arg, int from_tty);
229 static void tcatch_command (char *arg, int from_tty);
231 static void detach_single_step_breakpoints (void);
233 static int find_single_step_breakpoint (struct address_space *aspace,
236 static void free_bp_location (struct bp_location *loc);
237 static void incref_bp_location (struct bp_location *loc);
238 static void decref_bp_location (struct bp_location **loc);
240 static struct bp_location *allocate_bp_location (struct breakpoint *bpt);
242 static void update_global_location_list (int);
244 static void update_global_location_list_nothrow (int);
246 static int is_hardware_watchpoint (const struct breakpoint *bpt);
248 static void insert_breakpoint_locations (void);
250 static int syscall_catchpoint_p (struct breakpoint *b);
252 static void tracepoints_info (char *, int);
254 static void delete_trace_command (char *, int);
256 static void enable_trace_command (char *, int);
258 static void disable_trace_command (char *, int);
260 static void trace_pass_command (char *, int);
262 static void set_tracepoint_count (int num);
264 static int is_masked_watchpoint (const struct breakpoint *b);
266 static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address);
268 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
271 static int strace_marker_p (struct breakpoint *b);
273 /* The abstract base class all breakpoint_ops structures inherit
275 struct breakpoint_ops base_breakpoint_ops;
277 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
278 that are implemented on top of software or hardware breakpoints
279 (user breakpoints, internal and momentary breakpoints, etc.). */
280 static struct breakpoint_ops bkpt_base_breakpoint_ops;
282 /* Internal breakpoints class type. */
283 static struct breakpoint_ops internal_breakpoint_ops;
285 /* Momentary breakpoints class type. */
286 static struct breakpoint_ops momentary_breakpoint_ops;
288 /* Momentary breakpoints for bp_longjmp and bp_exception class type. */
289 static struct breakpoint_ops longjmp_breakpoint_ops;
291 /* The breakpoint_ops structure to be used in regular user created
293 struct breakpoint_ops bkpt_breakpoint_ops;
295 /* Breakpoints set on probes. */
296 static struct breakpoint_ops bkpt_probe_breakpoint_ops;
298 /* Dynamic printf class type. */
299 struct breakpoint_ops dprintf_breakpoint_ops;
301 /* One (or perhaps two) breakpoints used for software single
304 static void *single_step_breakpoints[2];
305 static struct gdbarch *single_step_gdbarch[2];
307 /* The style in which to perform a dynamic printf. This is a user
308 option because different output options have different tradeoffs;
309 if GDB does the printing, there is better error handling if there
310 is a problem with any of the arguments, but using an inferior
311 function lets you have special-purpose printers and sending of
312 output to the same place as compiled-in print functions. */
314 static const char dprintf_style_gdb[] = "gdb";
315 static const char dprintf_style_call[] = "call";
316 static const char dprintf_style_agent[] = "agent";
317 static const char *const dprintf_style_enums[] = {
323 static const char *dprintf_style = dprintf_style_gdb;
325 /* The function to use for dynamic printf if the preferred style is to
326 call into the inferior. The value is simply a string that is
327 copied into the command, so it can be anything that GDB can
328 evaluate to a callable address, not necessarily a function name. */
330 static char *dprintf_function = "";
332 /* The channel to use for dynamic printf if the preferred style is to
333 call into the inferior; if a nonempty string, it will be passed to
334 the call as the first argument, with the format string as the
335 second. As with the dprintf function, this can be anything that
336 GDB knows how to evaluate, so in addition to common choices like
337 "stderr", this could be an app-specific expression like
338 "mystreams[curlogger]". */
340 static char *dprintf_channel = "";
342 /* True if dprintf commands should continue to operate even if GDB
344 static int disconnected_dprintf = 1;
346 /* A reference-counted struct command_line. This lets multiple
347 breakpoints share a single command list. */
348 struct counted_command_line
350 /* The reference count. */
353 /* The command list. */
354 struct command_line *commands;
357 struct command_line *
358 breakpoint_commands (struct breakpoint *b)
360 return b->commands ? b->commands->commands : NULL;
363 /* Flag indicating that a command has proceeded the inferior past the
364 current breakpoint. */
366 static int breakpoint_proceeded;
369 bpdisp_text (enum bpdisp disp)
371 /* NOTE: the following values are a part of MI protocol and
372 represent values of 'disp' field returned when inferior stops at
374 static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"};
376 return bpdisps[(int) disp];
379 /* Prototypes for exported functions. */
380 /* If FALSE, gdb will not use hardware support for watchpoints, even
381 if such is available. */
382 static int can_use_hw_watchpoints;
385 show_can_use_hw_watchpoints (struct ui_file *file, int from_tty,
386 struct cmd_list_element *c,
389 fprintf_filtered (file,
390 _("Debugger's willingness to use "
391 "watchpoint hardware is %s.\n"),
395 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
396 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
397 for unrecognized breakpoint locations.
398 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
399 static enum auto_boolean pending_break_support;
401 show_pending_break_support (struct ui_file *file, int from_tty,
402 struct cmd_list_element *c,
405 fprintf_filtered (file,
406 _("Debugger's behavior regarding "
407 "pending breakpoints is %s.\n"),
411 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
412 set with "break" but falling in read-only memory.
413 If 0, gdb will warn about such breakpoints, but won't automatically
414 use hardware breakpoints. */
415 static int automatic_hardware_breakpoints;
417 show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty,
418 struct cmd_list_element *c,
421 fprintf_filtered (file,
422 _("Automatic usage of hardware breakpoints is %s.\n"),
426 /* If on, gdb will keep breakpoints inserted even as inferior is
427 stopped, and immediately insert any new breakpoints. If off, gdb
428 will insert breakpoints into inferior only when resuming it, and
429 will remove breakpoints upon stop. If auto, GDB will behave as ON
430 if in non-stop mode, and as OFF if all-stop mode.*/
432 static enum auto_boolean always_inserted_mode = AUTO_BOOLEAN_AUTO;
435 show_always_inserted_mode (struct ui_file *file, int from_tty,
436 struct cmd_list_element *c, const char *value)
438 if (always_inserted_mode == AUTO_BOOLEAN_AUTO)
439 fprintf_filtered (file,
440 _("Always inserted breakpoint "
441 "mode is %s (currently %s).\n"),
443 breakpoints_always_inserted_mode () ? "on" : "off");
445 fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"),
450 breakpoints_always_inserted_mode (void)
452 return (always_inserted_mode == AUTO_BOOLEAN_TRUE
453 || (always_inserted_mode == AUTO_BOOLEAN_AUTO && non_stop));
456 static const char condition_evaluation_both[] = "host or target";
458 /* Modes for breakpoint condition evaluation. */
459 static const char condition_evaluation_auto[] = "auto";
460 static const char condition_evaluation_host[] = "host";
461 static const char condition_evaluation_target[] = "target";
462 static const char *const condition_evaluation_enums[] = {
463 condition_evaluation_auto,
464 condition_evaluation_host,
465 condition_evaluation_target,
469 /* Global that holds the current mode for breakpoint condition evaluation. */
470 static const char *condition_evaluation_mode_1 = condition_evaluation_auto;
472 /* Global that we use to display information to the user (gets its value from
473 condition_evaluation_mode_1. */
474 static const char *condition_evaluation_mode = condition_evaluation_auto;
476 /* Translate a condition evaluation mode MODE into either "host"
477 or "target". This is used mostly to translate from "auto" to the
478 real setting that is being used. It returns the translated
482 translate_condition_evaluation_mode (const char *mode)
484 if (mode == condition_evaluation_auto)
486 if (target_supports_evaluation_of_breakpoint_conditions ())
487 return condition_evaluation_target;
489 return condition_evaluation_host;
495 /* Discovers what condition_evaluation_auto translates to. */
498 breakpoint_condition_evaluation_mode (void)
500 return translate_condition_evaluation_mode (condition_evaluation_mode);
503 /* Return true if GDB should evaluate breakpoint conditions or false
507 gdb_evaluates_breakpoint_condition_p (void)
509 const char *mode = breakpoint_condition_evaluation_mode ();
511 return (mode == condition_evaluation_host);
514 void _initialize_breakpoint (void);
516 /* Are we executing breakpoint commands? */
517 static int executing_breakpoint_commands;
519 /* Are overlay event breakpoints enabled? */
520 static int overlay_events_enabled;
522 /* See description in breakpoint.h. */
523 int target_exact_watchpoints = 0;
525 /* Walk the following statement or block through all breakpoints.
526 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
527 current breakpoint. */
529 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
531 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
532 for (B = breakpoint_chain; \
533 B ? (TMP=B->next, 1): 0; \
536 /* Similar iterator for the low-level breakpoints. SAFE variant is
537 not provided so update_global_location_list must not be called
538 while executing the block of ALL_BP_LOCATIONS. */
540 #define ALL_BP_LOCATIONS(B,BP_TMP) \
541 for (BP_TMP = bp_location; \
542 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
545 /* Iterates through locations with address ADDRESS for the currently selected
546 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
547 to where the loop should start from.
548 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
549 appropriate location to start with. */
551 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
552 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
553 BP_LOCP_TMP = BP_LOCP_START; \
555 && (BP_LOCP_TMP < bp_location + bp_location_count \
556 && (*BP_LOCP_TMP)->address == ADDRESS); \
559 /* Iterator for tracepoints only. */
561 #define ALL_TRACEPOINTS(B) \
562 for (B = breakpoint_chain; B; B = B->next) \
563 if (is_tracepoint (B))
565 /* Chains of all breakpoints defined. */
567 struct breakpoint *breakpoint_chain;
569 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
571 static struct bp_location **bp_location;
573 /* Number of elements of BP_LOCATION. */
575 static unsigned bp_location_count;
577 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
578 ADDRESS for the current elements of BP_LOCATION which get a valid
579 result from bp_location_has_shadow. You can use it for roughly
580 limiting the subrange of BP_LOCATION to scan for shadow bytes for
581 an address you need to read. */
583 static CORE_ADDR bp_location_placed_address_before_address_max;
585 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
586 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
587 BP_LOCATION which get a valid result from bp_location_has_shadow.
588 You can use it for roughly limiting the subrange of BP_LOCATION to
589 scan for shadow bytes for an address you need to read. */
591 static CORE_ADDR bp_location_shadow_len_after_address_max;
593 /* The locations that no longer correspond to any breakpoint, unlinked
594 from bp_location array, but for which a hit may still be reported
596 VEC(bp_location_p) *moribund_locations = NULL;
598 /* Number of last breakpoint made. */
600 static int breakpoint_count;
602 /* The value of `breakpoint_count' before the last command that
603 created breakpoints. If the last (break-like) command created more
604 than one breakpoint, then the difference between BREAKPOINT_COUNT
605 and PREV_BREAKPOINT_COUNT is more than one. */
606 static int prev_breakpoint_count;
608 /* Number of last tracepoint made. */
610 static int tracepoint_count;
612 static struct cmd_list_element *breakpoint_set_cmdlist;
613 static struct cmd_list_element *breakpoint_show_cmdlist;
614 struct cmd_list_element *save_cmdlist;
616 /* Return whether a breakpoint is an active enabled breakpoint. */
618 breakpoint_enabled (struct breakpoint *b)
620 return (b->enable_state == bp_enabled);
623 /* Set breakpoint count to NUM. */
626 set_breakpoint_count (int num)
628 prev_breakpoint_count = breakpoint_count;
629 breakpoint_count = num;
630 set_internalvar_integer (lookup_internalvar ("bpnum"), num);
633 /* Used by `start_rbreak_breakpoints' below, to record the current
634 breakpoint count before "rbreak" creates any breakpoint. */
635 static int rbreak_start_breakpoint_count;
637 /* Called at the start an "rbreak" command to record the first
641 start_rbreak_breakpoints (void)
643 rbreak_start_breakpoint_count = breakpoint_count;
646 /* Called at the end of an "rbreak" command to record the last
650 end_rbreak_breakpoints (void)
652 prev_breakpoint_count = rbreak_start_breakpoint_count;
655 /* Used in run_command to zero the hit count when a new run starts. */
658 clear_breakpoint_hit_counts (void)
660 struct breakpoint *b;
666 /* Allocate a new counted_command_line with reference count of 1.
667 The new structure owns COMMANDS. */
669 static struct counted_command_line *
670 alloc_counted_command_line (struct command_line *commands)
672 struct counted_command_line *result
673 = xmalloc (sizeof (struct counted_command_line));
676 result->commands = commands;
680 /* Increment reference count. This does nothing if CMD is NULL. */
683 incref_counted_command_line (struct counted_command_line *cmd)
689 /* Decrement reference count. If the reference count reaches 0,
690 destroy the counted_command_line. Sets *CMDP to NULL. This does
691 nothing if *CMDP is NULL. */
694 decref_counted_command_line (struct counted_command_line **cmdp)
698 if (--(*cmdp)->refc == 0)
700 free_command_lines (&(*cmdp)->commands);
707 /* A cleanup function that calls decref_counted_command_line. */
710 do_cleanup_counted_command_line (void *arg)
712 decref_counted_command_line (arg);
715 /* Create a cleanup that calls decref_counted_command_line on the
718 static struct cleanup *
719 make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp)
721 return make_cleanup (do_cleanup_counted_command_line, cmdp);
725 /* Return the breakpoint with the specified number, or NULL
726 if the number does not refer to an existing breakpoint. */
729 get_breakpoint (int num)
731 struct breakpoint *b;
734 if (b->number == num)
742 /* Mark locations as "conditions have changed" in case the target supports
743 evaluating conditions on its side. */
746 mark_breakpoint_modified (struct breakpoint *b)
748 struct bp_location *loc;
750 /* This is only meaningful if the target is
751 evaluating conditions and if the user has
752 opted for condition evaluation on the target's
754 if (gdb_evaluates_breakpoint_condition_p ()
755 || !target_supports_evaluation_of_breakpoint_conditions ())
758 if (!is_breakpoint (b))
761 for (loc = b->loc; loc; loc = loc->next)
762 loc->condition_changed = condition_modified;
765 /* Mark location as "conditions have changed" in case the target supports
766 evaluating conditions on its side. */
769 mark_breakpoint_location_modified (struct bp_location *loc)
771 /* This is only meaningful if the target is
772 evaluating conditions and if the user has
773 opted for condition evaluation on the target's
775 if (gdb_evaluates_breakpoint_condition_p ()
776 || !target_supports_evaluation_of_breakpoint_conditions ())
780 if (!is_breakpoint (loc->owner))
783 loc->condition_changed = condition_modified;
786 /* Sets the condition-evaluation mode using the static global
787 condition_evaluation_mode. */
790 set_condition_evaluation_mode (char *args, int from_tty,
791 struct cmd_list_element *c)
793 const char *old_mode, *new_mode;
795 if ((condition_evaluation_mode_1 == condition_evaluation_target)
796 && !target_supports_evaluation_of_breakpoint_conditions ())
798 condition_evaluation_mode_1 = condition_evaluation_mode;
799 warning (_("Target does not support breakpoint condition evaluation.\n"
800 "Using host evaluation mode instead."));
804 new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1);
805 old_mode = translate_condition_evaluation_mode (condition_evaluation_mode);
807 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
808 settings was "auto". */
809 condition_evaluation_mode = condition_evaluation_mode_1;
811 /* Only update the mode if the user picked a different one. */
812 if (new_mode != old_mode)
814 struct bp_location *loc, **loc_tmp;
815 /* If the user switched to a different evaluation mode, we
816 need to synch the changes with the target as follows:
818 "host" -> "target": Send all (valid) conditions to the target.
819 "target" -> "host": Remove all the conditions from the target.
822 if (new_mode == condition_evaluation_target)
824 /* Mark everything modified and synch conditions with the
826 ALL_BP_LOCATIONS (loc, loc_tmp)
827 mark_breakpoint_location_modified (loc);
831 /* Manually mark non-duplicate locations to synch conditions
832 with the target. We do this to remove all the conditions the
833 target knows about. */
834 ALL_BP_LOCATIONS (loc, loc_tmp)
835 if (is_breakpoint (loc->owner) && loc->inserted)
836 loc->needs_update = 1;
840 update_global_location_list (1);
846 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
847 what "auto" is translating to. */
850 show_condition_evaluation_mode (struct ui_file *file, int from_tty,
851 struct cmd_list_element *c, const char *value)
853 if (condition_evaluation_mode == condition_evaluation_auto)
854 fprintf_filtered (file,
855 _("Breakpoint condition evaluation "
856 "mode is %s (currently %s).\n"),
858 breakpoint_condition_evaluation_mode ());
860 fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"),
864 /* A comparison function for bp_location AP and BP that is used by
865 bsearch. This comparison function only cares about addresses, unlike
866 the more general bp_location_compare function. */
869 bp_location_compare_addrs (const void *ap, const void *bp)
871 struct bp_location *a = *(void **) ap;
872 struct bp_location *b = *(void **) bp;
874 if (a->address == b->address)
877 return ((a->address > b->address) - (a->address < b->address));
880 /* Helper function to skip all bp_locations with addresses
881 less than ADDRESS. It returns the first bp_location that
882 is greater than or equal to ADDRESS. If none is found, just
885 static struct bp_location **
886 get_first_locp_gte_addr (CORE_ADDR address)
888 struct bp_location dummy_loc;
889 struct bp_location *dummy_locp = &dummy_loc;
890 struct bp_location **locp_found = NULL;
892 /* Initialize the dummy location's address field. */
893 memset (&dummy_loc, 0, sizeof (struct bp_location));
894 dummy_loc.address = address;
896 /* Find a close match to the first location at ADDRESS. */
897 locp_found = bsearch (&dummy_locp, bp_location, bp_location_count,
898 sizeof (struct bp_location **),
899 bp_location_compare_addrs);
901 /* Nothing was found, nothing left to do. */
902 if (locp_found == NULL)
905 /* We may have found a location that is at ADDRESS but is not the first in the
906 location's list. Go backwards (if possible) and locate the first one. */
907 while ((locp_found - 1) >= bp_location
908 && (*(locp_found - 1))->address == address)
915 set_breakpoint_condition (struct breakpoint *b, char *exp,
918 xfree (b->cond_string);
919 b->cond_string = NULL;
921 if (is_watchpoint (b))
923 struct watchpoint *w = (struct watchpoint *) b;
930 struct bp_location *loc;
932 for (loc = b->loc; loc; loc = loc->next)
937 /* No need to free the condition agent expression
938 bytecode (if we have one). We will handle this
939 when we go through update_global_location_list. */
946 printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number);
950 const char *arg = exp;
952 /* I don't know if it matters whether this is the string the user
953 typed in or the decompiled expression. */
954 b->cond_string = xstrdup (arg);
955 b->condition_not_parsed = 0;
957 if (is_watchpoint (b))
959 struct watchpoint *w = (struct watchpoint *) b;
961 innermost_block = NULL;
963 w->cond_exp = parse_exp_1 (&arg, 0, 0, 0);
965 error (_("Junk at end of expression"));
966 w->cond_exp_valid_block = innermost_block;
970 struct bp_location *loc;
972 for (loc = b->loc; loc; loc = loc->next)
976 parse_exp_1 (&arg, loc->address,
977 block_for_pc (loc->address), 0);
979 error (_("Junk at end of expression"));
983 mark_breakpoint_modified (b);
985 observer_notify_breakpoint_modified (b);
988 /* Completion for the "condition" command. */
990 static VEC (char_ptr) *
991 condition_completer (struct cmd_list_element *cmd,
992 const char *text, const char *word)
996 text = skip_spaces_const (text);
997 space = skip_to_space_const (text);
1001 struct breakpoint *b;
1002 VEC (char_ptr) *result = NULL;
1006 /* We don't support completion of history indices. */
1007 if (isdigit (text[1]))
1009 return complete_internalvar (&text[1]);
1012 /* We're completing the breakpoint number. */
1013 len = strlen (text);
1019 xsnprintf (number, sizeof (number), "%d", b->number);
1021 if (strncmp (number, text, len) == 0)
1022 VEC_safe_push (char_ptr, result, xstrdup (number));
1028 /* We're completing the expression part. */
1029 text = skip_spaces_const (space);
1030 return expression_completer (cmd, text, word);
1033 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1036 condition_command (char *arg, int from_tty)
1038 struct breakpoint *b;
1043 error_no_arg (_("breakpoint number"));
1046 bnum = get_number (&p);
1048 error (_("Bad breakpoint argument: '%s'"), arg);
1051 if (b->number == bnum)
1053 /* Check if this breakpoint has a "stop" method implemented in an
1054 extension language. This method and conditions entered into GDB
1055 from the CLI are mutually exclusive. */
1056 const struct extension_language_defn *extlang
1057 = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE);
1059 if (extlang != NULL)
1061 error (_("Only one stop condition allowed. There is currently"
1062 " a %s stop condition defined for this breakpoint."),
1063 ext_lang_capitalized_name (extlang));
1065 set_breakpoint_condition (b, p, from_tty);
1067 if (is_breakpoint (b))
1068 update_global_location_list (1);
1073 error (_("No breakpoint number %d."), bnum);
1076 /* Check that COMMAND do not contain commands that are suitable
1077 only for tracepoints and not suitable for ordinary breakpoints.
1078 Throw if any such commands is found. */
1081 check_no_tracepoint_commands (struct command_line *commands)
1083 struct command_line *c;
1085 for (c = commands; c; c = c->next)
1089 if (c->control_type == while_stepping_control)
1090 error (_("The 'while-stepping' command can "
1091 "only be used for tracepoints"));
1093 for (i = 0; i < c->body_count; ++i)
1094 check_no_tracepoint_commands ((c->body_list)[i]);
1096 /* Not that command parsing removes leading whitespace and comment
1097 lines and also empty lines. So, we only need to check for
1098 command directly. */
1099 if (strstr (c->line, "collect ") == c->line)
1100 error (_("The 'collect' command can only be used for tracepoints"));
1102 if (strstr (c->line, "teval ") == c->line)
1103 error (_("The 'teval' command can only be used for tracepoints"));
1107 /* Encapsulate tests for different types of tracepoints. */
1110 is_tracepoint_type (enum bptype type)
1112 return (type == bp_tracepoint
1113 || type == bp_fast_tracepoint
1114 || type == bp_static_tracepoint);
1118 is_tracepoint (const struct breakpoint *b)
1120 return is_tracepoint_type (b->type);
1123 /* A helper function that validates that COMMANDS are valid for a
1124 breakpoint. This function will throw an exception if a problem is
1128 validate_commands_for_breakpoint (struct breakpoint *b,
1129 struct command_line *commands)
1131 if (is_tracepoint (b))
1133 struct tracepoint *t = (struct tracepoint *) b;
1134 struct command_line *c;
1135 struct command_line *while_stepping = 0;
1137 /* Reset the while-stepping step count. The previous commands
1138 might have included a while-stepping action, while the new
1142 /* We need to verify that each top-level element of commands is
1143 valid for tracepoints, that there's at most one
1144 while-stepping element, and that the while-stepping's body
1145 has valid tracing commands excluding nested while-stepping.
1146 We also need to validate the tracepoint action line in the
1147 context of the tracepoint --- validate_actionline actually
1148 has side effects, like setting the tracepoint's
1149 while-stepping STEP_COUNT, in addition to checking if the
1150 collect/teval actions parse and make sense in the
1151 tracepoint's context. */
1152 for (c = commands; c; c = c->next)
1154 if (c->control_type == while_stepping_control)
1156 if (b->type == bp_fast_tracepoint)
1157 error (_("The 'while-stepping' command "
1158 "cannot be used for fast tracepoint"));
1159 else if (b->type == bp_static_tracepoint)
1160 error (_("The 'while-stepping' command "
1161 "cannot be used for static tracepoint"));
1164 error (_("The 'while-stepping' command "
1165 "can be used only once"));
1170 validate_actionline (c->line, b);
1174 struct command_line *c2;
1176 gdb_assert (while_stepping->body_count == 1);
1177 c2 = while_stepping->body_list[0];
1178 for (; c2; c2 = c2->next)
1180 if (c2->control_type == while_stepping_control)
1181 error (_("The 'while-stepping' command cannot be nested"));
1187 check_no_tracepoint_commands (commands);
1191 /* Return a vector of all the static tracepoints set at ADDR. The
1192 caller is responsible for releasing the vector. */
1195 static_tracepoints_here (CORE_ADDR addr)
1197 struct breakpoint *b;
1198 VEC(breakpoint_p) *found = 0;
1199 struct bp_location *loc;
1202 if (b->type == bp_static_tracepoint)
1204 for (loc = b->loc; loc; loc = loc->next)
1205 if (loc->address == addr)
1206 VEC_safe_push(breakpoint_p, found, b);
1212 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1213 validate that only allowed commands are included. */
1216 breakpoint_set_commands (struct breakpoint *b,
1217 struct command_line *commands)
1219 validate_commands_for_breakpoint (b, commands);
1221 decref_counted_command_line (&b->commands);
1222 b->commands = alloc_counted_command_line (commands);
1223 observer_notify_breakpoint_modified (b);
1226 /* Set the internal `silent' flag on the breakpoint. Note that this
1227 is not the same as the "silent" that may appear in the breakpoint's
1231 breakpoint_set_silent (struct breakpoint *b, int silent)
1233 int old_silent = b->silent;
1236 if (old_silent != silent)
1237 observer_notify_breakpoint_modified (b);
1240 /* Set the thread for this breakpoint. If THREAD is -1, make the
1241 breakpoint work for any thread. */
1244 breakpoint_set_thread (struct breakpoint *b, int thread)
1246 int old_thread = b->thread;
1249 if (old_thread != thread)
1250 observer_notify_breakpoint_modified (b);
1253 /* Set the task for this breakpoint. If TASK is 0, make the
1254 breakpoint work for any task. */
1257 breakpoint_set_task (struct breakpoint *b, int task)
1259 int old_task = b->task;
1262 if (old_task != task)
1263 observer_notify_breakpoint_modified (b);
1267 check_tracepoint_command (char *line, void *closure)
1269 struct breakpoint *b = closure;
1271 validate_actionline (line, b);
1274 /* A structure used to pass information through
1275 map_breakpoint_numbers. */
1277 struct commands_info
1279 /* True if the command was typed at a tty. */
1282 /* The breakpoint range spec. */
1285 /* Non-NULL if the body of the commands are being read from this
1286 already-parsed command. */
1287 struct command_line *control;
1289 /* The command lines read from the user, or NULL if they have not
1291 struct counted_command_line *cmd;
1294 /* A callback for map_breakpoint_numbers that sets the commands for
1295 commands_command. */
1298 do_map_commands_command (struct breakpoint *b, void *data)
1300 struct commands_info *info = data;
1302 if (info->cmd == NULL)
1304 struct command_line *l;
1306 if (info->control != NULL)
1307 l = copy_command_lines (info->control->body_list[0]);
1310 struct cleanup *old_chain;
1313 str = xstrprintf (_("Type commands for breakpoint(s) "
1314 "%s, one per line."),
1317 old_chain = make_cleanup (xfree, str);
1319 l = read_command_lines (str,
1322 ? check_tracepoint_command : 0),
1325 do_cleanups (old_chain);
1328 info->cmd = alloc_counted_command_line (l);
1331 /* If a breakpoint was on the list more than once, we don't need to
1333 if (b->commands != info->cmd)
1335 validate_commands_for_breakpoint (b, info->cmd->commands);
1336 incref_counted_command_line (info->cmd);
1337 decref_counted_command_line (&b->commands);
1338 b->commands = info->cmd;
1339 observer_notify_breakpoint_modified (b);
1344 commands_command_1 (char *arg, int from_tty,
1345 struct command_line *control)
1347 struct cleanup *cleanups;
1348 struct commands_info info;
1350 info.from_tty = from_tty;
1351 info.control = control;
1353 /* If we read command lines from the user, then `info' will hold an
1354 extra reference to the commands that we must clean up. */
1355 cleanups = make_cleanup_decref_counted_command_line (&info.cmd);
1357 if (arg == NULL || !*arg)
1359 if (breakpoint_count - prev_breakpoint_count > 1)
1360 arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1,
1362 else if (breakpoint_count > 0)
1363 arg = xstrprintf ("%d", breakpoint_count);
1366 /* So that we don't try to free the incoming non-NULL
1367 argument in the cleanup below. Mapping breakpoint
1368 numbers will fail in this case. */
1373 /* The command loop has some static state, so we need to preserve
1375 arg = xstrdup (arg);
1378 make_cleanup (xfree, arg);
1382 map_breakpoint_numbers (arg, do_map_commands_command, &info);
1384 if (info.cmd == NULL)
1385 error (_("No breakpoints specified."));
1387 do_cleanups (cleanups);
1391 commands_command (char *arg, int from_tty)
1393 commands_command_1 (arg, from_tty, NULL);
1396 /* Like commands_command, but instead of reading the commands from
1397 input stream, takes them from an already parsed command structure.
1399 This is used by cli-script.c to DTRT with breakpoint commands
1400 that are part of if and while bodies. */
1401 enum command_control_type
1402 commands_from_control_command (char *arg, struct command_line *cmd)
1404 commands_command_1 (arg, 0, cmd);
1405 return simple_control;
1408 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1411 bp_location_has_shadow (struct bp_location *bl)
1413 if (bl->loc_type != bp_loc_software_breakpoint)
1417 if (bl->target_info.shadow_len == 0)
1418 /* BL isn't valid, or doesn't shadow memory. */
1423 /* Update BUF, which is LEN bytes read from the target address
1424 MEMADDR, by replacing a memory breakpoint with its shadowed
1427 If READBUF is not NULL, this buffer must not overlap with the of
1428 the breakpoint location's shadow_contents buffer. Otherwise, a
1429 failed assertion internal error will be raised. */
1432 one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf,
1433 const gdb_byte *writebuf_org,
1434 ULONGEST memaddr, LONGEST len,
1435 struct bp_target_info *target_info,
1436 struct gdbarch *gdbarch)
1438 /* Now do full processing of the found relevant range of elements. */
1439 CORE_ADDR bp_addr = 0;
1443 if (!breakpoint_address_match (target_info->placed_address_space, 0,
1444 current_program_space->aspace, 0))
1446 /* The breakpoint is inserted in a different address space. */
1450 /* Addresses and length of the part of the breakpoint that
1452 bp_addr = target_info->placed_address;
1453 bp_size = target_info->shadow_len;
1455 if (bp_addr + bp_size <= memaddr)
1457 /* The breakpoint is entirely before the chunk of memory we are
1462 if (bp_addr >= memaddr + len)
1464 /* The breakpoint is entirely after the chunk of memory we are
1469 /* Offset within shadow_contents. */
1470 if (bp_addr < memaddr)
1472 /* Only copy the second part of the breakpoint. */
1473 bp_size -= memaddr - bp_addr;
1474 bptoffset = memaddr - bp_addr;
1478 if (bp_addr + bp_size > memaddr + len)
1480 /* Only copy the first part of the breakpoint. */
1481 bp_size -= (bp_addr + bp_size) - (memaddr + len);
1484 if (readbuf != NULL)
1486 /* Verify that the readbuf buffer does not overlap with the
1487 shadow_contents buffer. */
1488 gdb_assert (target_info->shadow_contents >= readbuf + len
1489 || readbuf >= (target_info->shadow_contents
1490 + target_info->shadow_len));
1492 /* Update the read buffer with this inserted breakpoint's
1494 memcpy (readbuf + bp_addr - memaddr,
1495 target_info->shadow_contents + bptoffset, bp_size);
1499 const unsigned char *bp;
1500 CORE_ADDR placed_address = target_info->placed_address;
1501 int placed_size = target_info->placed_size;
1503 /* Update the shadow with what we want to write to memory. */
1504 memcpy (target_info->shadow_contents + bptoffset,
1505 writebuf_org + bp_addr - memaddr, bp_size);
1507 /* Determine appropriate breakpoint contents and size for this
1509 bp = gdbarch_breakpoint_from_pc (gdbarch, &placed_address, &placed_size);
1511 /* Update the final write buffer with this inserted
1512 breakpoint's INSN. */
1513 memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size);
1517 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1518 by replacing any memory breakpoints with their shadowed contents.
1520 If READBUF is not NULL, this buffer must not overlap with any of
1521 the breakpoint location's shadow_contents buffers. Otherwise,
1522 a failed assertion internal error will be raised.
1524 The range of shadowed area by each bp_location is:
1525 bl->address - bp_location_placed_address_before_address_max
1526 up to bl->address + bp_location_shadow_len_after_address_max
1527 The range we were requested to resolve shadows for is:
1528 memaddr ... memaddr + len
1529 Thus the safe cutoff boundaries for performance optimization are
1530 memaddr + len <= (bl->address
1531 - bp_location_placed_address_before_address_max)
1533 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1536 breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf,
1537 const gdb_byte *writebuf_org,
1538 ULONGEST memaddr, LONGEST len)
1540 /* Left boundary, right boundary and median element of our binary
1542 unsigned bc_l, bc_r, bc;
1545 /* Find BC_L which is a leftmost element which may affect BUF
1546 content. It is safe to report lower value but a failure to
1547 report higher one. */
1550 bc_r = bp_location_count;
1551 while (bc_l + 1 < bc_r)
1553 struct bp_location *bl;
1555 bc = (bc_l + bc_r) / 2;
1556 bl = bp_location[bc];
1558 /* Check first BL->ADDRESS will not overflow due to the added
1559 constant. Then advance the left boundary only if we are sure
1560 the BC element can in no way affect the BUF content (MEMADDR
1561 to MEMADDR + LEN range).
1563 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1564 offset so that we cannot miss a breakpoint with its shadow
1565 range tail still reaching MEMADDR. */
1567 if ((bl->address + bp_location_shadow_len_after_address_max
1569 && (bl->address + bp_location_shadow_len_after_address_max
1576 /* Due to the binary search above, we need to make sure we pick the
1577 first location that's at BC_L's address. E.g., if there are
1578 multiple locations at the same address, BC_L may end up pointing
1579 at a duplicate location, and miss the "master"/"inserted"
1580 location. Say, given locations L1, L2 and L3 at addresses A and
1583 L1@A, L2@A, L3@B, ...
1585 BC_L could end up pointing at location L2, while the "master"
1586 location could be L1. Since the `loc->inserted' flag is only set
1587 on "master" locations, we'd forget to restore the shadow of L1
1590 && bp_location[bc_l]->address == bp_location[bc_l - 1]->address)
1593 /* Now do full processing of the found relevant range of elements. */
1595 for (bc = bc_l; bc < bp_location_count; bc++)
1597 struct bp_location *bl = bp_location[bc];
1598 CORE_ADDR bp_addr = 0;
1602 /* bp_location array has BL->OWNER always non-NULL. */
1603 if (bl->owner->type == bp_none)
1604 warning (_("reading through apparently deleted breakpoint #%d?"),
1607 /* Performance optimization: any further element can no longer affect BUF
1610 if (bl->address >= bp_location_placed_address_before_address_max
1611 && memaddr + len <= (bl->address
1612 - bp_location_placed_address_before_address_max))
1615 if (!bp_location_has_shadow (bl))
1618 one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org,
1619 memaddr, len, &bl->target_info, bl->gdbarch);
1622 /* Now process single-step breakpoints. These are not found in the
1623 bp_location array. */
1624 for (i = 0; i < 2; i++)
1626 struct bp_target_info *bp_tgt = single_step_breakpoints[i];
1630 struct gdbarch *gdbarch = single_step_gdbarch[i];
1632 one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org,
1633 memaddr, len, bp_tgt, gdbarch);
1640 /* Return true if BPT is either a software breakpoint or a hardware
1644 is_breakpoint (const struct breakpoint *bpt)
1646 return (bpt->type == bp_breakpoint
1647 || bpt->type == bp_hardware_breakpoint
1648 || bpt->type == bp_dprintf);
1651 /* Return true if BPT is of any hardware watchpoint kind. */
1654 is_hardware_watchpoint (const struct breakpoint *bpt)
1656 return (bpt->type == bp_hardware_watchpoint
1657 || bpt->type == bp_read_watchpoint
1658 || bpt->type == bp_access_watchpoint);
1661 /* Return true if BPT is of any watchpoint kind, hardware or
1665 is_watchpoint (const struct breakpoint *bpt)
1667 return (is_hardware_watchpoint (bpt)
1668 || bpt->type == bp_watchpoint);
1671 /* Returns true if the current thread and its running state are safe
1672 to evaluate or update watchpoint B. Watchpoints on local
1673 expressions need to be evaluated in the context of the thread that
1674 was current when the watchpoint was created, and, that thread needs
1675 to be stopped to be able to select the correct frame context.
1676 Watchpoints on global expressions can be evaluated on any thread,
1677 and in any state. It is presently left to the target allowing
1678 memory accesses when threads are running. */
1681 watchpoint_in_thread_scope (struct watchpoint *b)
1683 return (b->base.pspace == current_program_space
1684 && (ptid_equal (b->watchpoint_thread, null_ptid)
1685 || (ptid_equal (inferior_ptid, b->watchpoint_thread)
1686 && !is_executing (inferior_ptid))));
1689 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1690 associated bp_watchpoint_scope breakpoint. */
1693 watchpoint_del_at_next_stop (struct watchpoint *w)
1695 struct breakpoint *b = &w->base;
1697 if (b->related_breakpoint != b)
1699 gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope);
1700 gdb_assert (b->related_breakpoint->related_breakpoint == b);
1701 b->related_breakpoint->disposition = disp_del_at_next_stop;
1702 b->related_breakpoint->related_breakpoint = b->related_breakpoint;
1703 b->related_breakpoint = b;
1705 b->disposition = disp_del_at_next_stop;
1708 /* Assuming that B is a watchpoint:
1709 - Reparse watchpoint expression, if REPARSE is non-zero
1710 - Evaluate expression and store the result in B->val
1711 - Evaluate the condition if there is one, and store the result
1713 - Update the list of values that must be watched in B->loc.
1715 If the watchpoint disposition is disp_del_at_next_stop, then do
1716 nothing. If this is local watchpoint that is out of scope, delete
1719 Even with `set breakpoint always-inserted on' the watchpoints are
1720 removed + inserted on each stop here. Normal breakpoints must
1721 never be removed because they might be missed by a running thread
1722 when debugging in non-stop mode. On the other hand, hardware
1723 watchpoints (is_hardware_watchpoint; processed here) are specific
1724 to each LWP since they are stored in each LWP's hardware debug
1725 registers. Therefore, such LWP must be stopped first in order to
1726 be able to modify its hardware watchpoints.
1728 Hardware watchpoints must be reset exactly once after being
1729 presented to the user. It cannot be done sooner, because it would
1730 reset the data used to present the watchpoint hit to the user. And
1731 it must not be done later because it could display the same single
1732 watchpoint hit during multiple GDB stops. Note that the latter is
1733 relevant only to the hardware watchpoint types bp_read_watchpoint
1734 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1735 not user-visible - its hit is suppressed if the memory content has
1738 The following constraints influence the location where we can reset
1739 hardware watchpoints:
1741 * target_stopped_by_watchpoint and target_stopped_data_address are
1742 called several times when GDB stops.
1745 * Multiple hardware watchpoints can be hit at the same time,
1746 causing GDB to stop. GDB only presents one hardware watchpoint
1747 hit at a time as the reason for stopping, and all the other hits
1748 are presented later, one after the other, each time the user
1749 requests the execution to be resumed. Execution is not resumed
1750 for the threads still having pending hit event stored in
1751 LWP_INFO->STATUS. While the watchpoint is already removed from
1752 the inferior on the first stop the thread hit event is kept being
1753 reported from its cached value by linux_nat_stopped_data_address
1754 until the real thread resume happens after the watchpoint gets
1755 presented and thus its LWP_INFO->STATUS gets reset.
1757 Therefore the hardware watchpoint hit can get safely reset on the
1758 watchpoint removal from inferior. */
1761 update_watchpoint (struct watchpoint *b, int reparse)
1763 int within_current_scope;
1764 struct frame_id saved_frame_id;
1767 /* If this is a local watchpoint, we only want to check if the
1768 watchpoint frame is in scope if the current thread is the thread
1769 that was used to create the watchpoint. */
1770 if (!watchpoint_in_thread_scope (b))
1773 if (b->base.disposition == disp_del_at_next_stop)
1778 /* Determine if the watchpoint is within scope. */
1779 if (b->exp_valid_block == NULL)
1780 within_current_scope = 1;
1783 struct frame_info *fi = get_current_frame ();
1784 struct gdbarch *frame_arch = get_frame_arch (fi);
1785 CORE_ADDR frame_pc = get_frame_pc (fi);
1787 /* If we're in a function epilogue, unwinding may not work
1788 properly, so do not attempt to recreate locations at this
1789 point. See similar comments in watchpoint_check. */
1790 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
1793 /* Save the current frame's ID so we can restore it after
1794 evaluating the watchpoint expression on its own frame. */
1795 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1796 took a frame parameter, so that we didn't have to change the
1799 saved_frame_id = get_frame_id (get_selected_frame (NULL));
1801 fi = frame_find_by_id (b->watchpoint_frame);
1802 within_current_scope = (fi != NULL);
1803 if (within_current_scope)
1807 /* We don't free locations. They are stored in the bp_location array
1808 and update_global_location_list will eventually delete them and
1809 remove breakpoints if needed. */
1812 if (within_current_scope && reparse)
1821 s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string;
1822 b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0);
1823 /* If the meaning of expression itself changed, the old value is
1824 no longer relevant. We don't want to report a watchpoint hit
1825 to the user when the old value and the new value may actually
1826 be completely different objects. */
1827 value_free (b->val);
1831 /* Note that unlike with breakpoints, the watchpoint's condition
1832 expression is stored in the breakpoint object, not in the
1833 locations (re)created below. */
1834 if (b->base.cond_string != NULL)
1836 if (b->cond_exp != NULL)
1838 xfree (b->cond_exp);
1842 s = b->base.cond_string;
1843 b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0);
1847 /* If we failed to parse the expression, for example because
1848 it refers to a global variable in a not-yet-loaded shared library,
1849 don't try to insert watchpoint. We don't automatically delete
1850 such watchpoint, though, since failure to parse expression
1851 is different from out-of-scope watchpoint. */
1852 if (!target_has_execution)
1854 /* Without execution, memory can't change. No use to try and
1855 set watchpoint locations. The watchpoint will be reset when
1856 the target gains execution, through breakpoint_re_set. */
1857 if (!can_use_hw_watchpoints)
1859 if (b->base.ops->works_in_software_mode (&b->base))
1860 b->base.type = bp_watchpoint;
1862 error (_("Can't set read/access watchpoint when "
1863 "hardware watchpoints are disabled."));
1866 else if (within_current_scope && b->exp)
1869 struct value *val_chain, *v, *result, *next;
1870 struct program_space *frame_pspace;
1872 fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain, 0);
1874 /* Avoid setting b->val if it's already set. The meaning of
1875 b->val is 'the last value' user saw, and we should update
1876 it only if we reported that last value to user. As it
1877 happens, the code that reports it updates b->val directly.
1878 We don't keep track of the memory value for masked
1880 if (!b->val_valid && !is_masked_watchpoint (&b->base))
1886 frame_pspace = get_frame_program_space (get_selected_frame (NULL));
1888 /* Look at each value on the value chain. */
1889 for (v = val_chain; v; v = value_next (v))
1891 /* If it's a memory location, and GDB actually needed
1892 its contents to evaluate the expression, then we
1893 must watch it. If the first value returned is
1894 still lazy, that means an error occurred reading it;
1895 watch it anyway in case it becomes readable. */
1896 if (VALUE_LVAL (v) == lval_memory
1897 && (v == val_chain || ! value_lazy (v)))
1899 struct type *vtype = check_typedef (value_type (v));
1901 /* We only watch structs and arrays if user asked
1902 for it explicitly, never if they just happen to
1903 appear in the middle of some value chain. */
1905 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1906 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1910 struct bp_location *loc, **tmp;
1912 addr = value_address (v);
1914 if (b->base.type == bp_read_watchpoint)
1916 else if (b->base.type == bp_access_watchpoint)
1919 loc = allocate_bp_location (&b->base);
1920 for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next))
1923 loc->gdbarch = get_type_arch (value_type (v));
1925 loc->pspace = frame_pspace;
1926 loc->address = addr;
1927 loc->length = TYPE_LENGTH (value_type (v));
1928 loc->watchpoint_type = type;
1933 /* Change the type of breakpoint between hardware assisted or
1934 an ordinary watchpoint depending on the hardware support
1935 and free hardware slots. REPARSE is set when the inferior
1940 enum bp_loc_type loc_type;
1941 struct bp_location *bl;
1943 reg_cnt = can_use_hardware_watchpoint (val_chain);
1947 int i, target_resources_ok, other_type_used;
1950 /* Use an exact watchpoint when there's only one memory region to be
1951 watched, and only one debug register is needed to watch it. */
1952 b->exact = target_exact_watchpoints && reg_cnt == 1;
1954 /* We need to determine how many resources are already
1955 used for all other hardware watchpoints plus this one
1956 to see if we still have enough resources to also fit
1957 this watchpoint in as well. */
1959 /* If this is a software watchpoint, we try to turn it
1960 to a hardware one -- count resources as if B was of
1961 hardware watchpoint type. */
1962 type = b->base.type;
1963 if (type == bp_watchpoint)
1964 type = bp_hardware_watchpoint;
1966 /* This watchpoint may or may not have been placed on
1967 the list yet at this point (it won't be in the list
1968 if we're trying to create it for the first time,
1969 through watch_command), so always account for it
1972 /* Count resources used by all watchpoints except B. */
1973 i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used);
1975 /* Add in the resources needed for B. */
1976 i += hw_watchpoint_use_count (&b->base);
1979 = target_can_use_hardware_watchpoint (type, i, other_type_used);
1980 if (target_resources_ok <= 0)
1982 int sw_mode = b->base.ops->works_in_software_mode (&b->base);
1984 if (target_resources_ok == 0 && !sw_mode)
1985 error (_("Target does not support this type of "
1986 "hardware watchpoint."));
1987 else if (target_resources_ok < 0 && !sw_mode)
1988 error (_("There are not enough available hardware "
1989 "resources for this watchpoint."));
1991 /* Downgrade to software watchpoint. */
1992 b->base.type = bp_watchpoint;
1996 /* If this was a software watchpoint, we've just
1997 found we have enough resources to turn it to a
1998 hardware watchpoint. Otherwise, this is a
2000 b->base.type = type;
2003 else if (!b->base.ops->works_in_software_mode (&b->base))
2005 if (!can_use_hw_watchpoints)
2006 error (_("Can't set read/access watchpoint when "
2007 "hardware watchpoints are disabled."));
2009 error (_("Expression cannot be implemented with "
2010 "read/access watchpoint."));
2013 b->base.type = bp_watchpoint;
2015 loc_type = (b->base.type == bp_watchpoint? bp_loc_other
2016 : bp_loc_hardware_watchpoint);
2017 for (bl = b->base.loc; bl; bl = bl->next)
2018 bl->loc_type = loc_type;
2021 for (v = val_chain; v; v = next)
2023 next = value_next (v);
2028 /* If a software watchpoint is not watching any memory, then the
2029 above left it without any location set up. But,
2030 bpstat_stop_status requires a location to be able to report
2031 stops, so make sure there's at least a dummy one. */
2032 if (b->base.type == bp_watchpoint && b->base.loc == NULL)
2034 struct breakpoint *base = &b->base;
2035 base->loc = allocate_bp_location (base);
2036 base->loc->pspace = frame_pspace;
2037 base->loc->address = -1;
2038 base->loc->length = -1;
2039 base->loc->watchpoint_type = -1;
2042 else if (!within_current_scope)
2044 printf_filtered (_("\
2045 Watchpoint %d deleted because the program has left the block\n\
2046 in which its expression is valid.\n"),
2048 watchpoint_del_at_next_stop (b);
2051 /* Restore the selected frame. */
2053 select_frame (frame_find_by_id (saved_frame_id));
2057 /* Returns 1 iff breakpoint location should be
2058 inserted in the inferior. We don't differentiate the type of BL's owner
2059 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2060 breakpoint_ops is not defined, because in insert_bp_location,
2061 tracepoint's insert_location will not be called. */
2063 should_be_inserted (struct bp_location *bl)
2065 if (bl->owner == NULL || !breakpoint_enabled (bl->owner))
2068 if (bl->owner->disposition == disp_del_at_next_stop)
2071 if (!bl->enabled || bl->shlib_disabled || bl->duplicate)
2074 if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup)
2077 /* This is set for example, when we're attached to the parent of a
2078 vfork, and have detached from the child. The child is running
2079 free, and we expect it to do an exec or exit, at which point the
2080 OS makes the parent schedulable again (and the target reports
2081 that the vfork is done). Until the child is done with the shared
2082 memory region, do not insert breakpoints in the parent, otherwise
2083 the child could still trip on the parent's breakpoints. Since
2084 the parent is blocked anyway, it won't miss any breakpoint. */
2085 if (bl->pspace->breakpoints_not_allowed)
2088 /* Don't insert a breakpoint if we're trying to step past its
2090 if ((bl->loc_type == bp_loc_software_breakpoint
2091 || bl->loc_type == bp_loc_hardware_breakpoint)
2092 && stepping_past_instruction_at (bl->pspace->aspace,
2099 /* Same as should_be_inserted but does the check assuming
2100 that the location is not duplicated. */
2103 unduplicated_should_be_inserted (struct bp_location *bl)
2106 const int save_duplicate = bl->duplicate;
2109 result = should_be_inserted (bl);
2110 bl->duplicate = save_duplicate;
2114 /* Parses a conditional described by an expression COND into an
2115 agent expression bytecode suitable for evaluation
2116 by the bytecode interpreter. Return NULL if there was
2117 any error during parsing. */
2119 static struct agent_expr *
2120 parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond)
2122 struct agent_expr *aexpr = NULL;
2123 volatile struct gdb_exception ex;
2128 /* We don't want to stop processing, so catch any errors
2129 that may show up. */
2130 TRY_CATCH (ex, RETURN_MASK_ERROR)
2132 aexpr = gen_eval_for_expr (scope, cond);
2137 /* If we got here, it means the condition could not be parsed to a valid
2138 bytecode expression and thus can't be evaluated on the target's side.
2139 It's no use iterating through the conditions. */
2143 /* We have a valid agent expression. */
2147 /* Based on location BL, create a list of breakpoint conditions to be
2148 passed on to the target. If we have duplicated locations with different
2149 conditions, we will add such conditions to the list. The idea is that the
2150 target will evaluate the list of conditions and will only notify GDB when
2151 one of them is true. */
2154 build_target_condition_list (struct bp_location *bl)
2156 struct bp_location **locp = NULL, **loc2p;
2157 int null_condition_or_parse_error = 0;
2158 int modified = bl->needs_update;
2159 struct bp_location *loc;
2161 /* Release conditions left over from a previous insert. */
2162 VEC_free (agent_expr_p, bl->target_info.conditions);
2164 /* This is only meaningful if the target is
2165 evaluating conditions and if the user has
2166 opted for condition evaluation on the target's
2168 if (gdb_evaluates_breakpoint_condition_p ()
2169 || !target_supports_evaluation_of_breakpoint_conditions ())
2172 /* Do a first pass to check for locations with no assigned
2173 conditions or conditions that fail to parse to a valid agent expression
2174 bytecode. If any of these happen, then it's no use to send conditions
2175 to the target since this location will always trigger and generate a
2176 response back to GDB. */
2177 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2180 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2184 struct agent_expr *aexpr;
2186 /* Re-parse the conditions since something changed. In that
2187 case we already freed the condition bytecodes (see
2188 force_breakpoint_reinsertion). We just
2189 need to parse the condition to bytecodes again. */
2190 aexpr = parse_cond_to_aexpr (bl->address, loc->cond);
2191 loc->cond_bytecode = aexpr;
2193 /* Check if we managed to parse the conditional expression
2194 correctly. If not, we will not send this condition
2200 /* If we have a NULL bytecode expression, it means something
2201 went wrong or we have a null condition expression. */
2202 if (!loc->cond_bytecode)
2204 null_condition_or_parse_error = 1;
2210 /* If any of these happened, it means we will have to evaluate the conditions
2211 for the location's address on gdb's side. It is no use keeping bytecodes
2212 for all the other duplicate locations, thus we free all of them here.
2214 This is so we have a finer control over which locations' conditions are
2215 being evaluated by GDB or the remote stub. */
2216 if (null_condition_or_parse_error)
2218 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2221 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2223 /* Only go as far as the first NULL bytecode is
2225 if (!loc->cond_bytecode)
2228 free_agent_expr (loc->cond_bytecode);
2229 loc->cond_bytecode = NULL;
2234 /* No NULL conditions or failed bytecode generation. Build a condition list
2235 for this location's address. */
2236 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2240 && is_breakpoint (loc->owner)
2241 && loc->pspace->num == bl->pspace->num
2242 && loc->owner->enable_state == bp_enabled
2244 /* Add the condition to the vector. This will be used later to send the
2245 conditions to the target. */
2246 VEC_safe_push (agent_expr_p, bl->target_info.conditions,
2247 loc->cond_bytecode);
2253 /* Parses a command described by string CMD into an agent expression
2254 bytecode suitable for evaluation by the bytecode interpreter.
2255 Return NULL if there was any error during parsing. */
2257 static struct agent_expr *
2258 parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd)
2260 struct cleanup *old_cleanups = 0;
2261 struct expression *expr, **argvec;
2262 struct agent_expr *aexpr = NULL;
2263 volatile struct gdb_exception ex;
2264 const char *cmdrest;
2265 const char *format_start, *format_end;
2266 struct format_piece *fpieces;
2268 struct gdbarch *gdbarch = get_current_arch ();
2275 if (*cmdrest == ',')
2277 cmdrest = skip_spaces_const (cmdrest);
2279 if (*cmdrest++ != '"')
2280 error (_("No format string following the location"));
2282 format_start = cmdrest;
2284 fpieces = parse_format_string (&cmdrest);
2286 old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces);
2288 format_end = cmdrest;
2290 if (*cmdrest++ != '"')
2291 error (_("Bad format string, non-terminated '\"'."));
2293 cmdrest = skip_spaces_const (cmdrest);
2295 if (!(*cmdrest == ',' || *cmdrest == '\0'))
2296 error (_("Invalid argument syntax"));
2298 if (*cmdrest == ',')
2300 cmdrest = skip_spaces_const (cmdrest);
2302 /* For each argument, make an expression. */
2304 argvec = (struct expression **) alloca (strlen (cmd)
2305 * sizeof (struct expression *));
2308 while (*cmdrest != '\0')
2313 expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1);
2314 argvec[nargs++] = expr;
2316 if (*cmdrest == ',')
2320 /* We don't want to stop processing, so catch any errors
2321 that may show up. */
2322 TRY_CATCH (ex, RETURN_MASK_ERROR)
2324 aexpr = gen_printf (scope, gdbarch, 0, 0,
2325 format_start, format_end - format_start,
2326 fpieces, nargs, argvec);
2329 do_cleanups (old_cleanups);
2333 /* If we got here, it means the command could not be parsed to a valid
2334 bytecode expression and thus can't be evaluated on the target's side.
2335 It's no use iterating through the other commands. */
2339 /* We have a valid agent expression, return it. */
2343 /* Based on location BL, create a list of breakpoint commands to be
2344 passed on to the target. If we have duplicated locations with
2345 different commands, we will add any such to the list. */
2348 build_target_command_list (struct bp_location *bl)
2350 struct bp_location **locp = NULL, **loc2p;
2351 int null_command_or_parse_error = 0;
2352 int modified = bl->needs_update;
2353 struct bp_location *loc;
2355 /* Release commands left over from a previous insert. */
2356 VEC_free (agent_expr_p, bl->target_info.tcommands);
2358 if (!target_can_run_breakpoint_commands ())
2361 /* For now, limit to agent-style dprintf breakpoints. */
2362 if (dprintf_style != dprintf_style_agent)
2365 /* For now, if we have any duplicate location that isn't a dprintf,
2366 don't install the target-side commands, as that would make the
2367 breakpoint not be reported to the core, and we'd lose
2369 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2372 if (is_breakpoint (loc->owner)
2373 && loc->pspace->num == bl->pspace->num
2374 && loc->owner->type != bp_dprintf)
2378 /* Do a first pass to check for locations with no assigned
2379 conditions or conditions that fail to parse to a valid agent expression
2380 bytecode. If any of these happen, then it's no use to send conditions
2381 to the target since this location will always trigger and generate a
2382 response back to GDB. */
2383 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2386 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2390 struct agent_expr *aexpr;
2392 /* Re-parse the commands since something changed. In that
2393 case we already freed the command bytecodes (see
2394 force_breakpoint_reinsertion). We just
2395 need to parse the command to bytecodes again. */
2396 aexpr = parse_cmd_to_aexpr (bl->address,
2397 loc->owner->extra_string);
2398 loc->cmd_bytecode = aexpr;
2404 /* If we have a NULL bytecode expression, it means something
2405 went wrong or we have a null command expression. */
2406 if (!loc->cmd_bytecode)
2408 null_command_or_parse_error = 1;
2414 /* If anything failed, then we're not doing target-side commands,
2416 if (null_command_or_parse_error)
2418 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2421 if (is_breakpoint (loc->owner)
2422 && loc->pspace->num == bl->pspace->num)
2424 /* Only go as far as the first NULL bytecode is
2426 if (loc->cmd_bytecode == NULL)
2429 free_agent_expr (loc->cmd_bytecode);
2430 loc->cmd_bytecode = NULL;
2435 /* No NULL commands or failed bytecode generation. Build a command list
2436 for this location's address. */
2437 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2440 if (loc->owner->extra_string
2441 && is_breakpoint (loc->owner)
2442 && loc->pspace->num == bl->pspace->num
2443 && loc->owner->enable_state == bp_enabled
2445 /* Add the command to the vector. This will be used later
2446 to send the commands to the target. */
2447 VEC_safe_push (agent_expr_p, bl->target_info.tcommands,
2451 bl->target_info.persist = 0;
2452 /* Maybe flag this location as persistent. */
2453 if (bl->owner->type == bp_dprintf && disconnected_dprintf)
2454 bl->target_info.persist = 1;
2457 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2458 location. Any error messages are printed to TMP_ERROR_STREAM; and
2459 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2460 Returns 0 for success, 1 if the bp_location type is not supported or
2463 NOTE drow/2003-09-09: This routine could be broken down to an
2464 object-style method for each breakpoint or catchpoint type. */
2466 insert_bp_location (struct bp_location *bl,
2467 struct ui_file *tmp_error_stream,
2468 int *disabled_breaks,
2469 int *hw_breakpoint_error,
2470 int *hw_bp_error_explained_already)
2472 enum errors bp_err = GDB_NO_ERROR;
2473 const char *bp_err_message = NULL;
2474 volatile struct gdb_exception e;
2476 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
2479 /* Note we don't initialize bl->target_info, as that wipes out
2480 the breakpoint location's shadow_contents if the breakpoint
2481 is still inserted at that location. This in turn breaks
2482 target_read_memory which depends on these buffers when
2483 a memory read is requested at the breakpoint location:
2484 Once the target_info has been wiped, we fail to see that
2485 we have a breakpoint inserted at that address and thus
2486 read the breakpoint instead of returning the data saved in
2487 the breakpoint location's shadow contents. */
2488 bl->target_info.placed_address = bl->address;
2489 bl->target_info.placed_address_space = bl->pspace->aspace;
2490 bl->target_info.length = bl->length;
2492 /* When working with target-side conditions, we must pass all the conditions
2493 for the same breakpoint address down to the target since GDB will not
2494 insert those locations. With a list of breakpoint conditions, the target
2495 can decide when to stop and notify GDB. */
2497 if (is_breakpoint (bl->owner))
2499 build_target_condition_list (bl);
2500 build_target_command_list (bl);
2501 /* Reset the modification marker. */
2502 bl->needs_update = 0;
2505 if (bl->loc_type == bp_loc_software_breakpoint
2506 || bl->loc_type == bp_loc_hardware_breakpoint)
2508 if (bl->owner->type != bp_hardware_breakpoint)
2510 /* If the explicitly specified breakpoint type
2511 is not hardware breakpoint, check the memory map to see
2512 if the breakpoint address is in read only memory or not.
2514 Two important cases are:
2515 - location type is not hardware breakpoint, memory
2516 is readonly. We change the type of the location to
2517 hardware breakpoint.
2518 - location type is hardware breakpoint, memory is
2519 read-write. This means we've previously made the
2520 location hardware one, but then the memory map changed,
2523 When breakpoints are removed, remove_breakpoints will use
2524 location types we've just set here, the only possible
2525 problem is that memory map has changed during running
2526 program, but it's not going to work anyway with current
2528 struct mem_region *mr
2529 = lookup_mem_region (bl->target_info.placed_address);
2533 if (automatic_hardware_breakpoints)
2535 enum bp_loc_type new_type;
2537 if (mr->attrib.mode != MEM_RW)
2538 new_type = bp_loc_hardware_breakpoint;
2540 new_type = bp_loc_software_breakpoint;
2542 if (new_type != bl->loc_type)
2544 static int said = 0;
2546 bl->loc_type = new_type;
2549 fprintf_filtered (gdb_stdout,
2550 _("Note: automatically using "
2551 "hardware breakpoints for "
2552 "read-only addresses.\n"));
2557 else if (bl->loc_type == bp_loc_software_breakpoint
2558 && mr->attrib.mode != MEM_RW)
2559 warning (_("cannot set software breakpoint "
2560 "at readonly address %s"),
2561 paddress (bl->gdbarch, bl->address));
2565 /* First check to see if we have to handle an overlay. */
2566 if (overlay_debugging == ovly_off
2567 || bl->section == NULL
2568 || !(section_is_overlay (bl->section)))
2570 /* No overlay handling: just set the breakpoint. */
2571 TRY_CATCH (e, RETURN_MASK_ALL)
2575 val = bl->owner->ops->insert_location (bl);
2577 bp_err = GENERIC_ERROR;
2582 bp_err_message = e.message;
2587 /* This breakpoint is in an overlay section.
2588 Shall we set a breakpoint at the LMA? */
2589 if (!overlay_events_enabled)
2591 /* Yes -- overlay event support is not active,
2592 so we must try to set a breakpoint at the LMA.
2593 This will not work for a hardware breakpoint. */
2594 if (bl->loc_type == bp_loc_hardware_breakpoint)
2595 warning (_("hardware breakpoint %d not supported in overlay!"),
2599 CORE_ADDR addr = overlay_unmapped_address (bl->address,
2601 /* Set a software (trap) breakpoint at the LMA. */
2602 bl->overlay_target_info = bl->target_info;
2603 bl->overlay_target_info.placed_address = addr;
2605 /* No overlay handling: just set the breakpoint. */
2606 TRY_CATCH (e, RETURN_MASK_ALL)
2610 val = target_insert_breakpoint (bl->gdbarch,
2611 &bl->overlay_target_info);
2613 bp_err = GENERIC_ERROR;
2618 bp_err_message = e.message;
2621 if (bp_err != GDB_NO_ERROR)
2622 fprintf_unfiltered (tmp_error_stream,
2623 "Overlay breakpoint %d "
2624 "failed: in ROM?\n",
2628 /* Shall we set a breakpoint at the VMA? */
2629 if (section_is_mapped (bl->section))
2631 /* Yes. This overlay section is mapped into memory. */
2632 TRY_CATCH (e, RETURN_MASK_ALL)
2636 val = bl->owner->ops->insert_location (bl);
2638 bp_err = GENERIC_ERROR;
2643 bp_err_message = e.message;
2648 /* No. This breakpoint will not be inserted.
2649 No error, but do not mark the bp as 'inserted'. */
2654 if (bp_err != GDB_NO_ERROR)
2656 /* Can't set the breakpoint. */
2658 /* In some cases, we might not be able to insert a
2659 breakpoint in a shared library that has already been
2660 removed, but we have not yet processed the shlib unload
2661 event. Unfortunately, some targets that implement
2662 breakpoint insertion themselves can't tell why the
2663 breakpoint insertion failed (e.g., the remote target
2664 doesn't define error codes), so we must treat generic
2665 errors as memory errors. */
2666 if ((bp_err == GENERIC_ERROR || bp_err == MEMORY_ERROR)
2667 && bl->loc_type == bp_loc_software_breakpoint
2668 && (solib_name_from_address (bl->pspace, bl->address)
2669 || shared_objfile_contains_address_p (bl->pspace,
2672 /* See also: disable_breakpoints_in_shlibs. */
2673 bl->shlib_disabled = 1;
2674 observer_notify_breakpoint_modified (bl->owner);
2675 if (!*disabled_breaks)
2677 fprintf_unfiltered (tmp_error_stream,
2678 "Cannot insert breakpoint %d.\n",
2680 fprintf_unfiltered (tmp_error_stream,
2681 "Temporarily disabling shared "
2682 "library breakpoints:\n");
2684 *disabled_breaks = 1;
2685 fprintf_unfiltered (tmp_error_stream,
2686 "breakpoint #%d\n", bl->owner->number);
2691 if (bl->loc_type == bp_loc_hardware_breakpoint)
2693 *hw_breakpoint_error = 1;
2694 *hw_bp_error_explained_already = bp_err_message != NULL;
2695 fprintf_unfiltered (tmp_error_stream,
2696 "Cannot insert hardware breakpoint %d%s",
2697 bl->owner->number, bp_err_message ? ":" : ".\n");
2698 if (bp_err_message != NULL)
2699 fprintf_unfiltered (tmp_error_stream, "%s.\n", bp_err_message);
2703 if (bp_err_message == NULL)
2706 = memory_error_message (TARGET_XFER_E_IO,
2707 bl->gdbarch, bl->address);
2708 struct cleanup *old_chain = make_cleanup (xfree, message);
2710 fprintf_unfiltered (tmp_error_stream,
2711 "Cannot insert breakpoint %d.\n"
2713 bl->owner->number, message);
2714 do_cleanups (old_chain);
2718 fprintf_unfiltered (tmp_error_stream,
2719 "Cannot insert breakpoint %d: %s\n",
2734 else if (bl->loc_type == bp_loc_hardware_watchpoint
2735 /* NOTE drow/2003-09-08: This state only exists for removing
2736 watchpoints. It's not clear that it's necessary... */
2737 && bl->owner->disposition != disp_del_at_next_stop)
2741 gdb_assert (bl->owner->ops != NULL
2742 && bl->owner->ops->insert_location != NULL);
2744 val = bl->owner->ops->insert_location (bl);
2746 /* If trying to set a read-watchpoint, and it turns out it's not
2747 supported, try emulating one with an access watchpoint. */
2748 if (val == 1 && bl->watchpoint_type == hw_read)
2750 struct bp_location *loc, **loc_temp;
2752 /* But don't try to insert it, if there's already another
2753 hw_access location that would be considered a duplicate
2755 ALL_BP_LOCATIONS (loc, loc_temp)
2757 && loc->watchpoint_type == hw_access
2758 && watchpoint_locations_match (bl, loc))
2762 bl->target_info = loc->target_info;
2763 bl->watchpoint_type = hw_access;
2770 bl->watchpoint_type = hw_access;
2771 val = bl->owner->ops->insert_location (bl);
2774 /* Back to the original value. */
2775 bl->watchpoint_type = hw_read;
2779 bl->inserted = (val == 0);
2782 else if (bl->owner->type == bp_catchpoint)
2786 gdb_assert (bl->owner->ops != NULL
2787 && bl->owner->ops->insert_location != NULL);
2789 val = bl->owner->ops->insert_location (bl);
2792 bl->owner->enable_state = bp_disabled;
2796 Error inserting catchpoint %d: Your system does not support this type\n\
2797 of catchpoint."), bl->owner->number);
2799 warning (_("Error inserting catchpoint %d."), bl->owner->number);
2802 bl->inserted = (val == 0);
2804 /* We've already printed an error message if there was a problem
2805 inserting this catchpoint, and we've disabled the catchpoint,
2806 so just return success. */
2813 /* This function is called when program space PSPACE is about to be
2814 deleted. It takes care of updating breakpoints to not reference
2818 breakpoint_program_space_exit (struct program_space *pspace)
2820 struct breakpoint *b, *b_temp;
2821 struct bp_location *loc, **loc_temp;
2823 /* Remove any breakpoint that was set through this program space. */
2824 ALL_BREAKPOINTS_SAFE (b, b_temp)
2826 if (b->pspace == pspace)
2827 delete_breakpoint (b);
2830 /* Breakpoints set through other program spaces could have locations
2831 bound to PSPACE as well. Remove those. */
2832 ALL_BP_LOCATIONS (loc, loc_temp)
2834 struct bp_location *tmp;
2836 if (loc->pspace == pspace)
2838 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2839 if (loc->owner->loc == loc)
2840 loc->owner->loc = loc->next;
2842 for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next)
2843 if (tmp->next == loc)
2845 tmp->next = loc->next;
2851 /* Now update the global location list to permanently delete the
2852 removed locations above. */
2853 update_global_location_list (0);
2856 /* Make sure all breakpoints are inserted in inferior.
2857 Throws exception on any error.
2858 A breakpoint that is already inserted won't be inserted
2859 again, so calling this function twice is safe. */
2861 insert_breakpoints (void)
2863 struct breakpoint *bpt;
2865 ALL_BREAKPOINTS (bpt)
2866 if (is_hardware_watchpoint (bpt))
2868 struct watchpoint *w = (struct watchpoint *) bpt;
2870 update_watchpoint (w, 0 /* don't reparse. */);
2873 update_global_location_list (1);
2875 /* update_global_location_list does not insert breakpoints when
2876 always_inserted_mode is not enabled. Explicitly insert them
2878 if (!breakpoints_always_inserted_mode ())
2879 insert_breakpoint_locations ();
2882 /* Invoke CALLBACK for each of bp_location. */
2885 iterate_over_bp_locations (walk_bp_location_callback callback)
2887 struct bp_location *loc, **loc_tmp;
2889 ALL_BP_LOCATIONS (loc, loc_tmp)
2891 callback (loc, NULL);
2895 /* This is used when we need to synch breakpoint conditions between GDB and the
2896 target. It is the case with deleting and disabling of breakpoints when using
2897 always-inserted mode. */
2900 update_inserted_breakpoint_locations (void)
2902 struct bp_location *bl, **blp_tmp;
2905 int disabled_breaks = 0;
2906 int hw_breakpoint_error = 0;
2907 int hw_bp_details_reported = 0;
2909 struct ui_file *tmp_error_stream = mem_fileopen ();
2910 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
2912 /* Explicitly mark the warning -- this will only be printed if
2913 there was an error. */
2914 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
2916 save_current_space_and_thread ();
2918 ALL_BP_LOCATIONS (bl, blp_tmp)
2920 /* We only want to update software breakpoints and hardware
2922 if (!is_breakpoint (bl->owner))
2925 /* We only want to update locations that are already inserted
2926 and need updating. This is to avoid unwanted insertion during
2927 deletion of breakpoints. */
2928 if (!bl->inserted || (bl->inserted && !bl->needs_update))
2931 switch_to_program_space_and_thread (bl->pspace);
2933 /* For targets that support global breakpoints, there's no need
2934 to select an inferior to insert breakpoint to. In fact, even
2935 if we aren't attached to any process yet, we should still
2936 insert breakpoints. */
2937 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2938 && ptid_equal (inferior_ptid, null_ptid))
2941 val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
2942 &hw_breakpoint_error, &hw_bp_details_reported);
2949 target_terminal_ours_for_output ();
2950 error_stream (tmp_error_stream);
2953 do_cleanups (cleanups);
2956 /* Used when starting or continuing the program. */
2959 insert_breakpoint_locations (void)
2961 struct breakpoint *bpt;
2962 struct bp_location *bl, **blp_tmp;
2965 int disabled_breaks = 0;
2966 int hw_breakpoint_error = 0;
2967 int hw_bp_error_explained_already = 0;
2969 struct ui_file *tmp_error_stream = mem_fileopen ();
2970 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
2972 /* Explicitly mark the warning -- this will only be printed if
2973 there was an error. */
2974 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
2976 save_current_space_and_thread ();
2978 ALL_BP_LOCATIONS (bl, blp_tmp)
2980 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
2983 /* There is no point inserting thread-specific breakpoints if
2984 the thread no longer exists. ALL_BP_LOCATIONS bp_location
2985 has BL->OWNER always non-NULL. */
2986 if (bl->owner->thread != -1
2987 && !valid_thread_id (bl->owner->thread))
2990 switch_to_program_space_and_thread (bl->pspace);
2992 /* For targets that support global breakpoints, there's no need
2993 to select an inferior to insert breakpoint to. In fact, even
2994 if we aren't attached to any process yet, we should still
2995 insert breakpoints. */
2996 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2997 && ptid_equal (inferior_ptid, null_ptid))
3000 val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
3001 &hw_breakpoint_error, &hw_bp_error_explained_already);
3006 /* If we failed to insert all locations of a watchpoint, remove
3007 them, as half-inserted watchpoint is of limited use. */
3008 ALL_BREAKPOINTS (bpt)
3010 int some_failed = 0;
3011 struct bp_location *loc;
3013 if (!is_hardware_watchpoint (bpt))
3016 if (!breakpoint_enabled (bpt))
3019 if (bpt->disposition == disp_del_at_next_stop)
3022 for (loc = bpt->loc; loc; loc = loc->next)
3023 if (!loc->inserted && should_be_inserted (loc))
3030 for (loc = bpt->loc; loc; loc = loc->next)
3032 remove_breakpoint (loc, mark_uninserted);
3034 hw_breakpoint_error = 1;
3035 fprintf_unfiltered (tmp_error_stream,
3036 "Could not insert hardware watchpoint %d.\n",
3044 /* If a hardware breakpoint or watchpoint was inserted, add a
3045 message about possibly exhausted resources. */
3046 if (hw_breakpoint_error && !hw_bp_error_explained_already)
3048 fprintf_unfiltered (tmp_error_stream,
3049 "Could not insert hardware breakpoints:\n\
3050 You may have requested too many hardware breakpoints/watchpoints.\n");
3052 target_terminal_ours_for_output ();
3053 error_stream (tmp_error_stream);
3056 do_cleanups (cleanups);
3059 /* Used when the program stops.
3060 Returns zero if successful, or non-zero if there was a problem
3061 removing a breakpoint location. */
3064 remove_breakpoints (void)
3066 struct bp_location *bl, **blp_tmp;
3069 ALL_BP_LOCATIONS (bl, blp_tmp)
3071 if (bl->inserted && !is_tracepoint (bl->owner))
3072 val |= remove_breakpoint (bl, mark_uninserted);
3077 /* When a thread exits, remove breakpoints that are related to
3081 remove_threaded_breakpoints (struct thread_info *tp, int silent)
3083 struct breakpoint *b, *b_tmp;
3085 ALL_BREAKPOINTS_SAFE (b, b_tmp)
3087 if (b->thread == tp->num && user_breakpoint_p (b))
3089 b->disposition = disp_del_at_next_stop;
3091 printf_filtered (_("\
3092 Thread-specific breakpoint %d deleted - thread %d no longer in the thread list.\n"),
3093 b->number, tp->num);
3095 /* Hide it from the user. */
3101 /* Remove breakpoints of process PID. */
3104 remove_breakpoints_pid (int pid)
3106 struct bp_location *bl, **blp_tmp;
3108 struct inferior *inf = find_inferior_pid (pid);
3110 ALL_BP_LOCATIONS (bl, blp_tmp)
3112 if (bl->pspace != inf->pspace)
3115 if (bl->owner->type == bp_dprintf)
3120 val = remove_breakpoint (bl, mark_uninserted);
3129 reattach_breakpoints (int pid)
3131 struct cleanup *old_chain;
3132 struct bp_location *bl, **blp_tmp;
3134 struct ui_file *tmp_error_stream;
3135 int dummy1 = 0, dummy2 = 0, dummy3 = 0;
3136 struct inferior *inf;
3137 struct thread_info *tp;
3139 tp = any_live_thread_of_process (pid);
3143 inf = find_inferior_pid (pid);
3144 old_chain = save_inferior_ptid ();
3146 inferior_ptid = tp->ptid;
3148 tmp_error_stream = mem_fileopen ();
3149 make_cleanup_ui_file_delete (tmp_error_stream);
3151 ALL_BP_LOCATIONS (bl, blp_tmp)
3153 if (bl->pspace != inf->pspace)
3159 val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2, &dummy3);
3162 do_cleanups (old_chain);
3167 do_cleanups (old_chain);
3171 static int internal_breakpoint_number = -1;
3173 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3174 If INTERNAL is non-zero, the breakpoint number will be populated
3175 from internal_breakpoint_number and that variable decremented.
3176 Otherwise the breakpoint number will be populated from
3177 breakpoint_count and that value incremented. Internal breakpoints
3178 do not set the internal var bpnum. */
3180 set_breakpoint_number (int internal, struct breakpoint *b)
3183 b->number = internal_breakpoint_number--;
3186 set_breakpoint_count (breakpoint_count + 1);
3187 b->number = breakpoint_count;
3191 static struct breakpoint *
3192 create_internal_breakpoint (struct gdbarch *gdbarch,
3193 CORE_ADDR address, enum bptype type,
3194 const struct breakpoint_ops *ops)
3196 struct symtab_and_line sal;
3197 struct breakpoint *b;
3199 init_sal (&sal); /* Initialize to zeroes. */
3202 sal.section = find_pc_overlay (sal.pc);
3203 sal.pspace = current_program_space;
3205 b = set_raw_breakpoint (gdbarch, sal, type, ops);
3206 b->number = internal_breakpoint_number--;
3207 b->disposition = disp_donttouch;
3212 static const char *const longjmp_names[] =
3214 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3216 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3218 /* Per-objfile data private to breakpoint.c. */
3219 struct breakpoint_objfile_data
3221 /* Minimal symbol for "_ovly_debug_event" (if any). */
3222 struct bound_minimal_symbol overlay_msym;
3224 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3225 struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES];
3227 /* True if we have looked for longjmp probes. */
3228 int longjmp_searched;
3230 /* SystemTap probe points for longjmp (if any). */
3231 VEC (probe_p) *longjmp_probes;
3233 /* Minimal symbol for "std::terminate()" (if any). */
3234 struct bound_minimal_symbol terminate_msym;
3236 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3237 struct bound_minimal_symbol exception_msym;
3239 /* True if we have looked for exception probes. */
3240 int exception_searched;
3242 /* SystemTap probe points for unwinding (if any). */
3243 VEC (probe_p) *exception_probes;
3246 static const struct objfile_data *breakpoint_objfile_key;
3248 /* Minimal symbol not found sentinel. */
3249 static struct minimal_symbol msym_not_found;
3251 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3254 msym_not_found_p (const struct minimal_symbol *msym)
3256 return msym == &msym_not_found;
3259 /* Return per-objfile data needed by breakpoint.c.
3260 Allocate the data if necessary. */
3262 static struct breakpoint_objfile_data *
3263 get_breakpoint_objfile_data (struct objfile *objfile)
3265 struct breakpoint_objfile_data *bp_objfile_data;
3267 bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key);
3268 if (bp_objfile_data == NULL)
3270 bp_objfile_data = obstack_alloc (&objfile->objfile_obstack,
3271 sizeof (*bp_objfile_data));
3273 memset (bp_objfile_data, 0, sizeof (*bp_objfile_data));
3274 set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data);
3276 return bp_objfile_data;
3280 free_breakpoint_probes (struct objfile *obj, void *data)
3282 struct breakpoint_objfile_data *bp_objfile_data = data;
3284 VEC_free (probe_p, bp_objfile_data->longjmp_probes);
3285 VEC_free (probe_p, bp_objfile_data->exception_probes);
3289 create_overlay_event_breakpoint (void)
3291 struct objfile *objfile;
3292 const char *const func_name = "_ovly_debug_event";
3294 ALL_OBJFILES (objfile)
3296 struct breakpoint *b;
3297 struct breakpoint_objfile_data *bp_objfile_data;
3300 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3302 if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym))
3305 if (bp_objfile_data->overlay_msym.minsym == NULL)
3307 struct bound_minimal_symbol m;
3309 m = lookup_minimal_symbol_text (func_name, objfile);
3310 if (m.minsym == NULL)
3312 /* Avoid future lookups in this objfile. */
3313 bp_objfile_data->overlay_msym.minsym = &msym_not_found;
3316 bp_objfile_data->overlay_msym = m;
3319 addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym);
3320 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
3322 &internal_breakpoint_ops);
3323 b->addr_string = xstrdup (func_name);
3325 if (overlay_debugging == ovly_auto)
3327 b->enable_state = bp_enabled;
3328 overlay_events_enabled = 1;
3332 b->enable_state = bp_disabled;
3333 overlay_events_enabled = 0;
3336 update_global_location_list (1);
3340 create_longjmp_master_breakpoint (void)
3342 struct program_space *pspace;
3343 struct cleanup *old_chain;
3345 old_chain = save_current_program_space ();
3347 ALL_PSPACES (pspace)
3349 struct objfile *objfile;
3351 set_current_program_space (pspace);
3353 ALL_OBJFILES (objfile)
3356 struct gdbarch *gdbarch;
3357 struct breakpoint_objfile_data *bp_objfile_data;
3359 gdbarch = get_objfile_arch (objfile);
3361 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3363 if (!bp_objfile_data->longjmp_searched)
3367 ret = find_probes_in_objfile (objfile, "libc", "longjmp");
3370 /* We are only interested in checking one element. */
3371 struct probe *p = VEC_index (probe_p, ret, 0);
3373 if (!can_evaluate_probe_arguments (p))
3375 /* We cannot use the probe interface here, because it does
3376 not know how to evaluate arguments. */
3377 VEC_free (probe_p, ret);
3381 bp_objfile_data->longjmp_probes = ret;
3382 bp_objfile_data->longjmp_searched = 1;
3385 if (bp_objfile_data->longjmp_probes != NULL)
3388 struct probe *probe;
3389 struct gdbarch *gdbarch = get_objfile_arch (objfile);
3392 VEC_iterate (probe_p,
3393 bp_objfile_data->longjmp_probes,
3397 struct breakpoint *b;
3399 b = create_internal_breakpoint (gdbarch,
3400 get_probe_address (probe,
3403 &internal_breakpoint_ops);
3404 b->addr_string = xstrdup ("-probe-stap libc:longjmp");
3405 b->enable_state = bp_disabled;
3411 if (!gdbarch_get_longjmp_target_p (gdbarch))
3414 for (i = 0; i < NUM_LONGJMP_NAMES; i++)
3416 struct breakpoint *b;
3417 const char *func_name;
3420 if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym))
3423 func_name = longjmp_names[i];
3424 if (bp_objfile_data->longjmp_msym[i].minsym == NULL)
3426 struct bound_minimal_symbol m;
3428 m = lookup_minimal_symbol_text (func_name, objfile);
3429 if (m.minsym == NULL)
3431 /* Prevent future lookups in this objfile. */
3432 bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found;
3435 bp_objfile_data->longjmp_msym[i] = m;
3438 addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]);
3439 b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master,
3440 &internal_breakpoint_ops);
3441 b->addr_string = xstrdup (func_name);
3442 b->enable_state = bp_disabled;
3446 update_global_location_list (1);
3448 do_cleanups (old_chain);
3451 /* Create a master std::terminate breakpoint. */
3453 create_std_terminate_master_breakpoint (void)
3455 struct program_space *pspace;
3456 struct cleanup *old_chain;
3457 const char *const func_name = "std::terminate()";
3459 old_chain = save_current_program_space ();
3461 ALL_PSPACES (pspace)
3463 struct objfile *objfile;
3466 set_current_program_space (pspace);
3468 ALL_OBJFILES (objfile)
3470 struct breakpoint *b;
3471 struct breakpoint_objfile_data *bp_objfile_data;
3473 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3475 if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym))
3478 if (bp_objfile_data->terminate_msym.minsym == NULL)
3480 struct bound_minimal_symbol m;
3482 m = lookup_minimal_symbol (func_name, NULL, objfile);
3483 if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text
3484 && MSYMBOL_TYPE (m.minsym) != mst_file_text))
3486 /* Prevent future lookups in this objfile. */
3487 bp_objfile_data->terminate_msym.minsym = &msym_not_found;
3490 bp_objfile_data->terminate_msym = m;
3493 addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym);
3494 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
3495 bp_std_terminate_master,
3496 &internal_breakpoint_ops);
3497 b->addr_string = xstrdup (func_name);
3498 b->enable_state = bp_disabled;
3502 update_global_location_list (1);
3504 do_cleanups (old_chain);
3507 /* Install a master breakpoint on the unwinder's debug hook. */
3510 create_exception_master_breakpoint (void)
3512 struct objfile *objfile;
3513 const char *const func_name = "_Unwind_DebugHook";
3515 ALL_OBJFILES (objfile)
3517 struct breakpoint *b;
3518 struct gdbarch *gdbarch;
3519 struct breakpoint_objfile_data *bp_objfile_data;
3522 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3524 /* We prefer the SystemTap probe point if it exists. */
3525 if (!bp_objfile_data->exception_searched)
3529 ret = find_probes_in_objfile (objfile, "libgcc", "unwind");
3533 /* We are only interested in checking one element. */
3534 struct probe *p = VEC_index (probe_p, ret, 0);
3536 if (!can_evaluate_probe_arguments (p))
3538 /* We cannot use the probe interface here, because it does
3539 not know how to evaluate arguments. */
3540 VEC_free (probe_p, ret);
3544 bp_objfile_data->exception_probes = ret;
3545 bp_objfile_data->exception_searched = 1;
3548 if (bp_objfile_data->exception_probes != NULL)
3550 struct gdbarch *gdbarch = get_objfile_arch (objfile);
3552 struct probe *probe;
3555 VEC_iterate (probe_p,
3556 bp_objfile_data->exception_probes,
3560 struct breakpoint *b;
3562 b = create_internal_breakpoint (gdbarch,
3563 get_probe_address (probe,
3565 bp_exception_master,
3566 &internal_breakpoint_ops);
3567 b->addr_string = xstrdup ("-probe-stap libgcc:unwind");
3568 b->enable_state = bp_disabled;
3574 /* Otherwise, try the hook function. */
3576 if (msym_not_found_p (bp_objfile_data->exception_msym.minsym))
3579 gdbarch = get_objfile_arch (objfile);
3581 if (bp_objfile_data->exception_msym.minsym == NULL)
3583 struct bound_minimal_symbol debug_hook;
3585 debug_hook = lookup_minimal_symbol (func_name, NULL, objfile);
3586 if (debug_hook.minsym == NULL)
3588 bp_objfile_data->exception_msym.minsym = &msym_not_found;
3592 bp_objfile_data->exception_msym = debug_hook;
3595 addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym);
3596 addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
3598 b = create_internal_breakpoint (gdbarch, addr, bp_exception_master,
3599 &internal_breakpoint_ops);
3600 b->addr_string = xstrdup (func_name);
3601 b->enable_state = bp_disabled;
3604 update_global_location_list (1);
3608 update_breakpoints_after_exec (void)
3610 struct breakpoint *b, *b_tmp;
3611 struct bp_location *bploc, **bplocp_tmp;
3613 /* We're about to delete breakpoints from GDB's lists. If the
3614 INSERTED flag is true, GDB will try to lift the breakpoints by
3615 writing the breakpoints' "shadow contents" back into memory. The
3616 "shadow contents" are NOT valid after an exec, so GDB should not
3617 do that. Instead, the target is responsible from marking
3618 breakpoints out as soon as it detects an exec. We don't do that
3619 here instead, because there may be other attempts to delete
3620 breakpoints after detecting an exec and before reaching here. */
3621 ALL_BP_LOCATIONS (bploc, bplocp_tmp)
3622 if (bploc->pspace == current_program_space)
3623 gdb_assert (!bploc->inserted);
3625 ALL_BREAKPOINTS_SAFE (b, b_tmp)
3627 if (b->pspace != current_program_space)
3630 /* Solib breakpoints must be explicitly reset after an exec(). */
3631 if (b->type == bp_shlib_event)
3633 delete_breakpoint (b);
3637 /* JIT breakpoints must be explicitly reset after an exec(). */
3638 if (b->type == bp_jit_event)
3640 delete_breakpoint (b);
3644 /* Thread event breakpoints must be set anew after an exec(),
3645 as must overlay event and longjmp master breakpoints. */
3646 if (b->type == bp_thread_event || b->type == bp_overlay_event
3647 || b->type == bp_longjmp_master || b->type == bp_std_terminate_master
3648 || b->type == bp_exception_master)
3650 delete_breakpoint (b);
3654 /* Step-resume breakpoints are meaningless after an exec(). */
3655 if (b->type == bp_step_resume || b->type == bp_hp_step_resume)
3657 delete_breakpoint (b);
3661 /* Longjmp and longjmp-resume breakpoints are also meaningless
3663 if (b->type == bp_longjmp || b->type == bp_longjmp_resume
3664 || b->type == bp_longjmp_call_dummy
3665 || b->type == bp_exception || b->type == bp_exception_resume)
3667 delete_breakpoint (b);
3671 if (b->type == bp_catchpoint)
3673 /* For now, none of the bp_catchpoint breakpoints need to
3674 do anything at this point. In the future, if some of
3675 the catchpoints need to something, we will need to add
3676 a new method, and call this method from here. */
3680 /* bp_finish is a special case. The only way we ought to be able
3681 to see one of these when an exec() has happened, is if the user
3682 caught a vfork, and then said "finish". Ordinarily a finish just
3683 carries them to the call-site of the current callee, by setting
3684 a temporary bp there and resuming. But in this case, the finish
3685 will carry them entirely through the vfork & exec.
3687 We don't want to allow a bp_finish to remain inserted now. But
3688 we can't safely delete it, 'cause finish_command has a handle to
3689 the bp on a bpstat, and will later want to delete it. There's a
3690 chance (and I've seen it happen) that if we delete the bp_finish
3691 here, that its storage will get reused by the time finish_command
3692 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3693 We really must allow finish_command to delete a bp_finish.
3695 In the absence of a general solution for the "how do we know
3696 it's safe to delete something others may have handles to?"
3697 problem, what we'll do here is just uninsert the bp_finish, and
3698 let finish_command delete it.
3700 (We know the bp_finish is "doomed" in the sense that it's
3701 momentary, and will be deleted as soon as finish_command sees
3702 the inferior stopped. So it doesn't matter that the bp's
3703 address is probably bogus in the new a.out, unlike e.g., the
3704 solib breakpoints.) */
3706 if (b->type == bp_finish)
3711 /* Without a symbolic address, we have little hope of the
3712 pre-exec() address meaning the same thing in the post-exec()
3714 if (b->addr_string == NULL)
3716 delete_breakpoint (b);
3720 /* FIXME what about longjmp breakpoints? Re-create them here? */
3721 create_overlay_event_breakpoint ();
3722 create_longjmp_master_breakpoint ();
3723 create_std_terminate_master_breakpoint ();
3724 create_exception_master_breakpoint ();
3728 detach_breakpoints (ptid_t ptid)
3730 struct bp_location *bl, **blp_tmp;
3732 struct cleanup *old_chain = save_inferior_ptid ();
3733 struct inferior *inf = current_inferior ();
3735 if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid))
3736 error (_("Cannot detach breakpoints of inferior_ptid"));
3738 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3739 inferior_ptid = ptid;
3740 ALL_BP_LOCATIONS (bl, blp_tmp)
3742 if (bl->pspace != inf->pspace)
3745 /* This function must physically remove breakpoints locations
3746 from the specified ptid, without modifying the breakpoint
3747 package's state. Locations of type bp_loc_other are only
3748 maintained at GDB side. So, there is no need to remove
3749 these bp_loc_other locations. Moreover, removing these
3750 would modify the breakpoint package's state. */
3751 if (bl->loc_type == bp_loc_other)
3755 val |= remove_breakpoint_1 (bl, mark_inserted);
3758 /* Detach single-step breakpoints as well. */
3759 detach_single_step_breakpoints ();
3761 do_cleanups (old_chain);
3765 /* Remove the breakpoint location BL from the current address space.
3766 Note that this is used to detach breakpoints from a child fork.
3767 When we get here, the child isn't in the inferior list, and neither
3768 do we have objects to represent its address space --- we should
3769 *not* look at bl->pspace->aspace here. */
3772 remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is)
3776 /* BL is never in moribund_locations by our callers. */
3777 gdb_assert (bl->owner != NULL);
3779 if (bl->owner->enable_state == bp_permanent)
3780 /* Permanent breakpoints cannot be inserted or removed. */
3783 /* The type of none suggests that owner is actually deleted.
3784 This should not ever happen. */
3785 gdb_assert (bl->owner->type != bp_none);
3787 if (bl->loc_type == bp_loc_software_breakpoint
3788 || bl->loc_type == bp_loc_hardware_breakpoint)
3790 /* "Normal" instruction breakpoint: either the standard
3791 trap-instruction bp (bp_breakpoint), or a
3792 bp_hardware_breakpoint. */
3794 /* First check to see if we have to handle an overlay. */
3795 if (overlay_debugging == ovly_off
3796 || bl->section == NULL
3797 || !(section_is_overlay (bl->section)))
3799 /* No overlay handling: just remove the breakpoint. */
3801 /* If we're trying to uninsert a memory breakpoint that we
3802 know is set in a dynamic object that is marked
3803 shlib_disabled, then either the dynamic object was
3804 removed with "remove-symbol-file" or with
3805 "nosharedlibrary". In the former case, we don't know
3806 whether another dynamic object might have loaded over the
3807 breakpoint's address -- the user might well let us know
3808 about it next with add-symbol-file (the whole point of
3809 add-symbol-file is letting the user manually maintain a
3810 list of dynamically loaded objects). If we have the
3811 breakpoint's shadow memory, that is, this is a software
3812 breakpoint managed by GDB, check whether the breakpoint
3813 is still inserted in memory, to avoid overwriting wrong
3814 code with stale saved shadow contents. Note that HW
3815 breakpoints don't have shadow memory, as they're
3816 implemented using a mechanism that is not dependent on
3817 being able to modify the target's memory, and as such
3818 they should always be removed. */
3819 if (bl->shlib_disabled
3820 && bl->target_info.shadow_len != 0
3821 && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info))
3824 val = bl->owner->ops->remove_location (bl);
3828 /* This breakpoint is in an overlay section.
3829 Did we set a breakpoint at the LMA? */
3830 if (!overlay_events_enabled)
3832 /* Yes -- overlay event support is not active, so we
3833 should have set a breakpoint at the LMA. Remove it.
3835 /* Ignore any failures: if the LMA is in ROM, we will
3836 have already warned when we failed to insert it. */
3837 if (bl->loc_type == bp_loc_hardware_breakpoint)
3838 target_remove_hw_breakpoint (bl->gdbarch,
3839 &bl->overlay_target_info);
3841 target_remove_breakpoint (bl->gdbarch,
3842 &bl->overlay_target_info);
3844 /* Did we set a breakpoint at the VMA?
3845 If so, we will have marked the breakpoint 'inserted'. */
3848 /* Yes -- remove it. Previously we did not bother to
3849 remove the breakpoint if the section had been
3850 unmapped, but let's not rely on that being safe. We
3851 don't know what the overlay manager might do. */
3853 /* However, we should remove *software* breakpoints only
3854 if the section is still mapped, or else we overwrite
3855 wrong code with the saved shadow contents. */
3856 if (bl->loc_type == bp_loc_hardware_breakpoint
3857 || section_is_mapped (bl->section))
3858 val = bl->owner->ops->remove_location (bl);
3864 /* No -- not inserted, so no need to remove. No error. */
3869 /* In some cases, we might not be able to remove a breakpoint in
3870 a shared library that has already been removed, but we have
3871 not yet processed the shlib unload event. Similarly for an
3872 unloaded add-symbol-file object - the user might not yet have
3873 had the chance to remove-symbol-file it. shlib_disabled will
3874 be set if the library/object has already been removed, but
3875 the breakpoint hasn't been uninserted yet, e.g., after
3876 "nosharedlibrary" or "remove-symbol-file" with breakpoints
3877 always-inserted mode. */
3879 && (bl->loc_type == bp_loc_software_breakpoint
3880 && (bl->shlib_disabled
3881 || solib_name_from_address (bl->pspace, bl->address)
3882 || shared_objfile_contains_address_p (bl->pspace,
3888 bl->inserted = (is == mark_inserted);
3890 else if (bl->loc_type == bp_loc_hardware_watchpoint)
3892 gdb_assert (bl->owner->ops != NULL
3893 && bl->owner->ops->remove_location != NULL);
3895 bl->inserted = (is == mark_inserted);
3896 bl->owner->ops->remove_location (bl);
3898 /* Failure to remove any of the hardware watchpoints comes here. */
3899 if ((is == mark_uninserted) && (bl->inserted))
3900 warning (_("Could not remove hardware watchpoint %d."),
3903 else if (bl->owner->type == bp_catchpoint
3904 && breakpoint_enabled (bl->owner)
3907 gdb_assert (bl->owner->ops != NULL
3908 && bl->owner->ops->remove_location != NULL);
3910 val = bl->owner->ops->remove_location (bl);
3914 bl->inserted = (is == mark_inserted);
3921 remove_breakpoint (struct bp_location *bl, insertion_state_t is)
3924 struct cleanup *old_chain;
3926 /* BL is never in moribund_locations by our callers. */
3927 gdb_assert (bl->owner != NULL);
3929 if (bl->owner->enable_state == bp_permanent)
3930 /* Permanent breakpoints cannot be inserted or removed. */
3933 /* The type of none suggests that owner is actually deleted.
3934 This should not ever happen. */
3935 gdb_assert (bl->owner->type != bp_none);
3937 old_chain = save_current_space_and_thread ();
3939 switch_to_program_space_and_thread (bl->pspace);
3941 ret = remove_breakpoint_1 (bl, is);
3943 do_cleanups (old_chain);
3947 /* Clear the "inserted" flag in all breakpoints. */
3950 mark_breakpoints_out (void)
3952 struct bp_location *bl, **blp_tmp;
3954 ALL_BP_LOCATIONS (bl, blp_tmp)
3955 if (bl->pspace == current_program_space)
3959 /* Clear the "inserted" flag in all breakpoints and delete any
3960 breakpoints which should go away between runs of the program.
3962 Plus other such housekeeping that has to be done for breakpoints
3965 Note: this function gets called at the end of a run (by
3966 generic_mourn_inferior) and when a run begins (by
3967 init_wait_for_inferior). */
3972 breakpoint_init_inferior (enum inf_context context)
3974 struct breakpoint *b, *b_tmp;
3975 struct bp_location *bl, **blp_tmp;
3977 struct program_space *pspace = current_program_space;
3979 /* If breakpoint locations are shared across processes, then there's
3981 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
3984 ALL_BP_LOCATIONS (bl, blp_tmp)
3986 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3987 if (bl->pspace == pspace
3988 && bl->owner->enable_state != bp_permanent)
3992 ALL_BREAKPOINTS_SAFE (b, b_tmp)
3994 if (b->loc && b->loc->pspace != pspace)
4000 case bp_longjmp_call_dummy:
4002 /* If the call dummy breakpoint is at the entry point it will
4003 cause problems when the inferior is rerun, so we better get
4006 case bp_watchpoint_scope:
4008 /* Also get rid of scope breakpoints. */
4010 case bp_shlib_event:
4012 /* Also remove solib event breakpoints. Their addresses may
4013 have changed since the last time we ran the program.
4014 Actually we may now be debugging against different target;
4015 and so the solib backend that installed this breakpoint may
4016 not be used in by the target. E.g.,
4018 (gdb) file prog-linux
4019 (gdb) run # native linux target
4022 (gdb) file prog-win.exe
4023 (gdb) tar rem :9999 # remote Windows gdbserver.
4026 case bp_step_resume:
4028 /* Also remove step-resume breakpoints. */
4030 delete_breakpoint (b);
4034 case bp_hardware_watchpoint:
4035 case bp_read_watchpoint:
4036 case bp_access_watchpoint:
4038 struct watchpoint *w = (struct watchpoint *) b;
4040 /* Likewise for watchpoints on local expressions. */
4041 if (w->exp_valid_block != NULL)
4042 delete_breakpoint (b);
4043 else if (context == inf_starting)
4045 /* Reset val field to force reread of starting value in
4046 insert_breakpoints. */
4048 value_free (w->val);
4059 /* Get rid of the moribund locations. */
4060 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix)
4061 decref_bp_location (&bl);
4062 VEC_free (bp_location_p, moribund_locations);
4065 /* These functions concern about actual breakpoints inserted in the
4066 target --- to e.g. check if we need to do decr_pc adjustment or if
4067 we need to hop over the bkpt --- so we check for address space
4068 match, not program space. */
4070 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4071 exists at PC. It returns ordinary_breakpoint_here if it's an
4072 ordinary breakpoint, or permanent_breakpoint_here if it's a
4073 permanent breakpoint.
4074 - When continuing from a location with an ordinary breakpoint, we
4075 actually single step once before calling insert_breakpoints.
4076 - When continuing from a location with a permanent breakpoint, we
4077 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4078 the target, to advance the PC past the breakpoint. */
4080 enum breakpoint_here
4081 breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
4083 struct bp_location *bl, **blp_tmp;
4084 int any_breakpoint_here = 0;
4086 ALL_BP_LOCATIONS (bl, blp_tmp)
4088 if (bl->loc_type != bp_loc_software_breakpoint
4089 && bl->loc_type != bp_loc_hardware_breakpoint)
4092 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4093 if ((breakpoint_enabled (bl->owner)
4094 || bl->owner->enable_state == bp_permanent)
4095 && breakpoint_location_address_match (bl, aspace, pc))
4097 if (overlay_debugging
4098 && section_is_overlay (bl->section)
4099 && !section_is_mapped (bl->section))
4100 continue; /* unmapped overlay -- can't be a match */
4101 else if (bl->owner->enable_state == bp_permanent)
4102 return permanent_breakpoint_here;
4104 any_breakpoint_here = 1;
4108 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
4111 /* Return true if there's a moribund breakpoint at PC. */
4114 moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
4116 struct bp_location *loc;
4119 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
4120 if (breakpoint_location_address_match (loc, aspace, pc))
4126 /* Returns non-zero if there's a breakpoint inserted at PC, which is
4127 inserted using regular breakpoint_chain / bp_location array
4128 mechanism. This does not check for single-step breakpoints, which
4129 are inserted and removed using direct target manipulation. */
4132 regular_breakpoint_inserted_here_p (struct address_space *aspace,
4135 struct bp_location *bl, **blp_tmp;
4137 ALL_BP_LOCATIONS (bl, blp_tmp)
4139 if (bl->loc_type != bp_loc_software_breakpoint
4140 && bl->loc_type != bp_loc_hardware_breakpoint)
4144 && breakpoint_location_address_match (bl, aspace, pc))
4146 if (overlay_debugging
4147 && section_is_overlay (bl->section)
4148 && !section_is_mapped (bl->section))
4149 continue; /* unmapped overlay -- can't be a match */
4157 /* Returns non-zero iff there's either regular breakpoint
4158 or a single step breakpoint inserted at PC. */
4161 breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
4163 if (regular_breakpoint_inserted_here_p (aspace, pc))
4166 if (single_step_breakpoint_inserted_here_p (aspace, pc))
4172 /* Ignoring deprecated raw breakpoints, return non-zero iff there is a
4173 software breakpoint inserted at PC. */
4175 static struct bp_location *
4176 find_non_raw_software_breakpoint_inserted_here (struct address_space *aspace,
4179 struct bp_location *bl, **blp_tmp;
4181 ALL_BP_LOCATIONS (bl, blp_tmp)
4183 if (bl->loc_type != bp_loc_software_breakpoint)
4187 && breakpoint_address_match (bl->pspace->aspace, bl->address,
4190 if (overlay_debugging
4191 && section_is_overlay (bl->section)
4192 && !section_is_mapped (bl->section))
4193 continue; /* unmapped overlay -- can't be a match */
4202 /* This function returns non-zero iff there is a software breakpoint
4206 software_breakpoint_inserted_here_p (struct address_space *aspace,
4209 if (find_non_raw_software_breakpoint_inserted_here (aspace, pc) != NULL)
4212 /* Also check for software single-step breakpoints. */
4213 if (single_step_breakpoint_inserted_here_p (aspace, pc))
4220 hardware_watchpoint_inserted_in_range (struct address_space *aspace,
4221 CORE_ADDR addr, ULONGEST len)
4223 struct breakpoint *bpt;
4225 ALL_BREAKPOINTS (bpt)
4227 struct bp_location *loc;
4229 if (bpt->type != bp_hardware_watchpoint
4230 && bpt->type != bp_access_watchpoint)
4233 if (!breakpoint_enabled (bpt))
4236 for (loc = bpt->loc; loc; loc = loc->next)
4237 if (loc->pspace->aspace == aspace && loc->inserted)
4241 /* Check for intersection. */
4242 l = max (loc->address, addr);
4243 h = min (loc->address + loc->length, addr + len);
4251 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
4252 PC is valid for process/thread PTID. */
4255 breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc,
4258 struct bp_location *bl, **blp_tmp;
4259 /* The thread and task IDs associated to PTID, computed lazily. */
4263 ALL_BP_LOCATIONS (bl, blp_tmp)
4265 if (bl->loc_type != bp_loc_software_breakpoint
4266 && bl->loc_type != bp_loc_hardware_breakpoint)
4269 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
4270 if (!breakpoint_enabled (bl->owner)
4271 && bl->owner->enable_state != bp_permanent)
4274 if (!breakpoint_location_address_match (bl, aspace, pc))
4277 if (bl->owner->thread != -1)
4279 /* This is a thread-specific breakpoint. Check that ptid
4280 matches that thread. If thread hasn't been computed yet,
4281 it is now time to do so. */
4283 thread = pid_to_thread_id (ptid);
4284 if (bl->owner->thread != thread)
4288 if (bl->owner->task != 0)
4290 /* This is a task-specific breakpoint. Check that ptid
4291 matches that task. If task hasn't been computed yet,
4292 it is now time to do so. */
4294 task = ada_get_task_number (ptid);
4295 if (bl->owner->task != task)
4299 if (overlay_debugging
4300 && section_is_overlay (bl->section)
4301 && !section_is_mapped (bl->section))
4302 continue; /* unmapped overlay -- can't be a match */
4311 /* bpstat stuff. External routines' interfaces are documented
4315 is_catchpoint (struct breakpoint *ep)
4317 return (ep->type == bp_catchpoint);
4320 /* Frees any storage that is part of a bpstat. Does not walk the
4324 bpstat_free (bpstat bs)
4326 if (bs->old_val != NULL)
4327 value_free (bs->old_val);
4328 decref_counted_command_line (&bs->commands);
4329 decref_bp_location (&bs->bp_location_at);
4333 /* Clear a bpstat so that it says we are not at any breakpoint.
4334 Also free any storage that is part of a bpstat. */
4337 bpstat_clear (bpstat *bsp)
4354 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4355 is part of the bpstat is copied as well. */
4358 bpstat_copy (bpstat bs)
4362 bpstat retval = NULL;
4367 for (; bs != NULL; bs = bs->next)
4369 tmp = (bpstat) xmalloc (sizeof (*tmp));
4370 memcpy (tmp, bs, sizeof (*tmp));
4371 incref_counted_command_line (tmp->commands);
4372 incref_bp_location (tmp->bp_location_at);
4373 if (bs->old_val != NULL)
4375 tmp->old_val = value_copy (bs->old_val);
4376 release_value (tmp->old_val);
4380 /* This is the first thing in the chain. */
4390 /* Find the bpstat associated with this breakpoint. */
4393 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
4398 for (; bsp != NULL; bsp = bsp->next)
4400 if (bsp->breakpoint_at == breakpoint)
4406 /* See breakpoint.h. */
4409 bpstat_explains_signal (bpstat bsp, enum gdb_signal sig)
4411 for (; bsp != NULL; bsp = bsp->next)
4413 if (bsp->breakpoint_at == NULL)
4415 /* A moribund location can never explain a signal other than
4417 if (sig == GDB_SIGNAL_TRAP)
4422 if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at,
4431 /* Put in *NUM the breakpoint number of the first breakpoint we are
4432 stopped at. *BSP upon return is a bpstat which points to the
4433 remaining breakpoints stopped at (but which is not guaranteed to be
4434 good for anything but further calls to bpstat_num).
4436 Return 0 if passed a bpstat which does not indicate any breakpoints.
4437 Return -1 if stopped at a breakpoint that has been deleted since
4439 Return 1 otherwise. */
4442 bpstat_num (bpstat *bsp, int *num)
4444 struct breakpoint *b;
4447 return 0; /* No more breakpoint values */
4449 /* We assume we'll never have several bpstats that correspond to a
4450 single breakpoint -- otherwise, this function might return the
4451 same number more than once and this will look ugly. */
4452 b = (*bsp)->breakpoint_at;
4453 *bsp = (*bsp)->next;
4455 return -1; /* breakpoint that's been deleted since */
4457 *num = b->number; /* We have its number */
4461 /* See breakpoint.h. */
4464 bpstat_clear_actions (void)
4466 struct thread_info *tp;
4469 if (ptid_equal (inferior_ptid, null_ptid))
4472 tp = find_thread_ptid (inferior_ptid);
4476 for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next)
4478 decref_counted_command_line (&bs->commands);
4480 if (bs->old_val != NULL)
4482 value_free (bs->old_val);
4488 /* Called when a command is about to proceed the inferior. */
4491 breakpoint_about_to_proceed (void)
4493 if (!ptid_equal (inferior_ptid, null_ptid))
4495 struct thread_info *tp = inferior_thread ();
4497 /* Allow inferior function calls in breakpoint commands to not
4498 interrupt the command list. When the call finishes
4499 successfully, the inferior will be standing at the same
4500 breakpoint as if nothing happened. */
4501 if (tp->control.in_infcall)
4505 breakpoint_proceeded = 1;
4508 /* Stub for cleaning up our state if we error-out of a breakpoint
4511 cleanup_executing_breakpoints (void *ignore)
4513 executing_breakpoint_commands = 0;
4516 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4517 or its equivalent. */
4520 command_line_is_silent (struct command_line *cmd)
4522 return cmd && (strcmp ("silent", cmd->line) == 0
4523 || (xdb_commands && strcmp ("Q", cmd->line) == 0));
4526 /* Execute all the commands associated with all the breakpoints at
4527 this location. Any of these commands could cause the process to
4528 proceed beyond this point, etc. We look out for such changes by
4529 checking the global "breakpoint_proceeded" after each command.
4531 Returns true if a breakpoint command resumed the inferior. In that
4532 case, it is the caller's responsibility to recall it again with the
4533 bpstat of the current thread. */
4536 bpstat_do_actions_1 (bpstat *bsp)
4539 struct cleanup *old_chain;
4542 /* Avoid endless recursion if a `source' command is contained
4544 if (executing_breakpoint_commands)
4547 executing_breakpoint_commands = 1;
4548 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
4550 prevent_dont_repeat ();
4552 /* This pointer will iterate over the list of bpstat's. */
4555 breakpoint_proceeded = 0;
4556 for (; bs != NULL; bs = bs->next)
4558 struct counted_command_line *ccmd;
4559 struct command_line *cmd;
4560 struct cleanup *this_cmd_tree_chain;
4562 /* Take ownership of the BSP's command tree, if it has one.
4564 The command tree could legitimately contain commands like
4565 'step' and 'next', which call clear_proceed_status, which
4566 frees stop_bpstat's command tree. To make sure this doesn't
4567 free the tree we're executing out from under us, we need to
4568 take ownership of the tree ourselves. Since a given bpstat's
4569 commands are only executed once, we don't need to copy it; we
4570 can clear the pointer in the bpstat, and make sure we free
4571 the tree when we're done. */
4572 ccmd = bs->commands;
4573 bs->commands = NULL;
4574 this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd);
4575 cmd = ccmd ? ccmd->commands : NULL;
4576 if (command_line_is_silent (cmd))
4578 /* The action has been already done by bpstat_stop_status. */
4584 execute_control_command (cmd);
4586 if (breakpoint_proceeded)
4592 /* We can free this command tree now. */
4593 do_cleanups (this_cmd_tree_chain);
4595 if (breakpoint_proceeded)
4597 if (target_can_async_p ())
4598 /* If we are in async mode, then the target might be still
4599 running, not stopped at any breakpoint, so nothing for
4600 us to do here -- just return to the event loop. */
4603 /* In sync mode, when execute_control_command returns
4604 we're already standing on the next breakpoint.
4605 Breakpoint commands for that stop were not run, since
4606 execute_command does not run breakpoint commands --
4607 only command_line_handler does, but that one is not
4608 involved in execution of breakpoint commands. So, we
4609 can now execute breakpoint commands. It should be
4610 noted that making execute_command do bpstat actions is
4611 not an option -- in this case we'll have recursive
4612 invocation of bpstat for each breakpoint with a
4613 command, and can easily blow up GDB stack. Instead, we
4614 return true, which will trigger the caller to recall us
4615 with the new stop_bpstat. */
4620 do_cleanups (old_chain);
4625 bpstat_do_actions (void)
4627 struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup ();
4629 /* Do any commands attached to breakpoint we are stopped at. */
4630 while (!ptid_equal (inferior_ptid, null_ptid)
4631 && target_has_execution
4632 && !is_exited (inferior_ptid)
4633 && !is_executing (inferior_ptid))
4634 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4635 and only return when it is stopped at the next breakpoint, we
4636 keep doing breakpoint actions until it returns false to
4637 indicate the inferior was not resumed. */
4638 if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat))
4641 discard_cleanups (cleanup_if_error);
4644 /* Print out the (old or new) value associated with a watchpoint. */
4647 watchpoint_value_print (struct value *val, struct ui_file *stream)
4650 fprintf_unfiltered (stream, _("<unreadable>"));
4653 struct value_print_options opts;
4654 get_user_print_options (&opts);
4655 value_print (val, stream, &opts);
4659 /* Generic routine for printing messages indicating why we
4660 stopped. The behavior of this function depends on the value
4661 'print_it' in the bpstat structure. Under some circumstances we
4662 may decide not to print anything here and delegate the task to
4665 static enum print_stop_action
4666 print_bp_stop_message (bpstat bs)
4668 switch (bs->print_it)
4671 /* Nothing should be printed for this bpstat entry. */
4672 return PRINT_UNKNOWN;
4676 /* We still want to print the frame, but we already printed the
4677 relevant messages. */
4678 return PRINT_SRC_AND_LOC;
4681 case print_it_normal:
4683 struct breakpoint *b = bs->breakpoint_at;
4685 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4686 which has since been deleted. */
4688 return PRINT_UNKNOWN;
4690 /* Normal case. Call the breakpoint's print_it method. */
4691 return b->ops->print_it (bs);
4696 internal_error (__FILE__, __LINE__,
4697 _("print_bp_stop_message: unrecognized enum value"));
4702 /* A helper function that prints a shared library stopped event. */
4705 print_solib_event (int is_catchpoint)
4708 = !VEC_empty (char_ptr, current_program_space->deleted_solibs);
4710 = !VEC_empty (so_list_ptr, current_program_space->added_solibs);
4714 if (any_added || any_deleted)
4715 ui_out_text (current_uiout,
4716 _("Stopped due to shared library event:\n"));
4718 ui_out_text (current_uiout,
4719 _("Stopped due to shared library event (no "
4720 "libraries added or removed)\n"));
4723 if (ui_out_is_mi_like_p (current_uiout))
4724 ui_out_field_string (current_uiout, "reason",
4725 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT));
4729 struct cleanup *cleanup;
4733 ui_out_text (current_uiout, _(" Inferior unloaded "));
4734 cleanup = make_cleanup_ui_out_list_begin_end (current_uiout,
4737 VEC_iterate (char_ptr, current_program_space->deleted_solibs,
4742 ui_out_text (current_uiout, " ");
4743 ui_out_field_string (current_uiout, "library", name);
4744 ui_out_text (current_uiout, "\n");
4747 do_cleanups (cleanup);
4752 struct so_list *iter;
4754 struct cleanup *cleanup;
4756 ui_out_text (current_uiout, _(" Inferior loaded "));
4757 cleanup = make_cleanup_ui_out_list_begin_end (current_uiout,
4760 VEC_iterate (so_list_ptr, current_program_space->added_solibs,
4765 ui_out_text (current_uiout, " ");
4766 ui_out_field_string (current_uiout, "library", iter->so_name);
4767 ui_out_text (current_uiout, "\n");
4770 do_cleanups (cleanup);
4774 /* Print a message indicating what happened. This is called from
4775 normal_stop(). The input to this routine is the head of the bpstat
4776 list - a list of the eventpoints that caused this stop. KIND is
4777 the target_waitkind for the stopping event. This
4778 routine calls the generic print routine for printing a message
4779 about reasons for stopping. This will print (for example) the
4780 "Breakpoint n," part of the output. The return value of this
4783 PRINT_UNKNOWN: Means we printed nothing.
4784 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4785 code to print the location. An example is
4786 "Breakpoint 1, " which should be followed by
4788 PRINT_SRC_ONLY: Means we printed something, but there is no need
4789 to also print the location part of the message.
4790 An example is the catch/throw messages, which
4791 don't require a location appended to the end.
4792 PRINT_NOTHING: We have done some printing and we don't need any
4793 further info to be printed. */
4795 enum print_stop_action
4796 bpstat_print (bpstat bs, int kind)
4800 /* Maybe another breakpoint in the chain caused us to stop.
4801 (Currently all watchpoints go on the bpstat whether hit or not.
4802 That probably could (should) be changed, provided care is taken
4803 with respect to bpstat_explains_signal). */
4804 for (; bs; bs = bs->next)
4806 val = print_bp_stop_message (bs);
4807 if (val == PRINT_SRC_ONLY
4808 || val == PRINT_SRC_AND_LOC
4809 || val == PRINT_NOTHING)
4813 /* If we had hit a shared library event breakpoint,
4814 print_bp_stop_message would print out this message. If we hit an
4815 OS-level shared library event, do the same thing. */
4816 if (kind == TARGET_WAITKIND_LOADED)
4818 print_solib_event (0);
4819 return PRINT_NOTHING;
4822 /* We reached the end of the chain, or we got a null BS to start
4823 with and nothing was printed. */
4824 return PRINT_UNKNOWN;
4827 /* Evaluate the expression EXP and return 1 if value is zero.
4828 This returns the inverse of the condition because it is called
4829 from catch_errors which returns 0 if an exception happened, and if an
4830 exception happens we want execution to stop.
4831 The argument is a "struct expression *" that has been cast to a
4832 "void *" to make it pass through catch_errors. */
4835 breakpoint_cond_eval (void *exp)
4837 struct value *mark = value_mark ();
4838 int i = !value_true (evaluate_expression ((struct expression *) exp));
4840 value_free_to_mark (mark);
4844 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4847 bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer)
4851 bs = (bpstat) xmalloc (sizeof (*bs));
4853 **bs_link_pointer = bs;
4854 *bs_link_pointer = &bs->next;
4855 bs->breakpoint_at = bl->owner;
4856 bs->bp_location_at = bl;
4857 incref_bp_location (bl);
4858 /* If the condition is false, etc., don't do the commands. */
4859 bs->commands = NULL;
4861 bs->print_it = print_it_normal;
4865 /* The target has stopped with waitstatus WS. Check if any hardware
4866 watchpoints have triggered, according to the target. */
4869 watchpoints_triggered (struct target_waitstatus *ws)
4871 int stopped_by_watchpoint = target_stopped_by_watchpoint ();
4873 struct breakpoint *b;
4875 if (!stopped_by_watchpoint)
4877 /* We were not stopped by a watchpoint. Mark all watchpoints
4878 as not triggered. */
4880 if (is_hardware_watchpoint (b))
4882 struct watchpoint *w = (struct watchpoint *) b;
4884 w->watchpoint_triggered = watch_triggered_no;
4890 if (!target_stopped_data_address (¤t_target, &addr))
4892 /* We were stopped by a watchpoint, but we don't know where.
4893 Mark all watchpoints as unknown. */
4895 if (is_hardware_watchpoint (b))
4897 struct watchpoint *w = (struct watchpoint *) b;
4899 w->watchpoint_triggered = watch_triggered_unknown;
4905 /* The target could report the data address. Mark watchpoints
4906 affected by this data address as triggered, and all others as not
4910 if (is_hardware_watchpoint (b))
4912 struct watchpoint *w = (struct watchpoint *) b;
4913 struct bp_location *loc;
4915 w->watchpoint_triggered = watch_triggered_no;
4916 for (loc = b->loc; loc; loc = loc->next)
4918 if (is_masked_watchpoint (b))
4920 CORE_ADDR newaddr = addr & w->hw_wp_mask;
4921 CORE_ADDR start = loc->address & w->hw_wp_mask;
4923 if (newaddr == start)
4925 w->watchpoint_triggered = watch_triggered_yes;
4929 /* Exact match not required. Within range is sufficient. */
4930 else if (target_watchpoint_addr_within_range (¤t_target,
4934 w->watchpoint_triggered = watch_triggered_yes;
4943 /* Possible return values for watchpoint_check (this can't be an enum
4944 because of check_errors). */
4945 /* The watchpoint has been deleted. */
4946 #define WP_DELETED 1
4947 /* The value has changed. */
4948 #define WP_VALUE_CHANGED 2
4949 /* The value has not changed. */
4950 #define WP_VALUE_NOT_CHANGED 3
4951 /* Ignore this watchpoint, no matter if the value changed or not. */
4954 #define BP_TEMPFLAG 1
4955 #define BP_HARDWAREFLAG 2
4957 /* Evaluate watchpoint condition expression and check if its value
4960 P should be a pointer to struct bpstat, but is defined as a void *
4961 in order for this function to be usable with catch_errors. */
4964 watchpoint_check (void *p)
4966 bpstat bs = (bpstat) p;
4967 struct watchpoint *b;
4968 struct frame_info *fr;
4969 int within_current_scope;
4971 /* BS is built from an existing struct breakpoint. */
4972 gdb_assert (bs->breakpoint_at != NULL);
4973 b = (struct watchpoint *) bs->breakpoint_at;
4975 /* If this is a local watchpoint, we only want to check if the
4976 watchpoint frame is in scope if the current thread is the thread
4977 that was used to create the watchpoint. */
4978 if (!watchpoint_in_thread_scope (b))
4981 if (b->exp_valid_block == NULL)
4982 within_current_scope = 1;
4985 struct frame_info *frame = get_current_frame ();
4986 struct gdbarch *frame_arch = get_frame_arch (frame);
4987 CORE_ADDR frame_pc = get_frame_pc (frame);
4989 /* in_function_epilogue_p() returns a non-zero value if we're
4990 still in the function but the stack frame has already been
4991 invalidated. Since we can't rely on the values of local
4992 variables after the stack has been destroyed, we are treating
4993 the watchpoint in that state as `not changed' without further
4994 checking. Don't mark watchpoints as changed if the current
4995 frame is in an epilogue - even if they are in some other
4996 frame, our view of the stack is likely to be wrong and
4997 frame_find_by_id could error out. */
4998 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
5001 fr = frame_find_by_id (b->watchpoint_frame);
5002 within_current_scope = (fr != NULL);
5004 /* If we've gotten confused in the unwinder, we might have
5005 returned a frame that can't describe this variable. */
5006 if (within_current_scope)
5008 struct symbol *function;
5010 function = get_frame_function (fr);
5011 if (function == NULL
5012 || !contained_in (b->exp_valid_block,
5013 SYMBOL_BLOCK_VALUE (function)))
5014 within_current_scope = 0;
5017 if (within_current_scope)
5018 /* If we end up stopping, the current frame will get selected
5019 in normal_stop. So this call to select_frame won't affect
5024 if (within_current_scope)
5026 /* We use value_{,free_to_}mark because it could be a *long*
5027 time before we return to the command level and call
5028 free_all_values. We can't call free_all_values because we
5029 might be in the middle of evaluating a function call. */
5033 struct value *new_val;
5035 if (is_masked_watchpoint (&b->base))
5036 /* Since we don't know the exact trigger address (from
5037 stopped_data_address), just tell the user we've triggered
5038 a mask watchpoint. */
5039 return WP_VALUE_CHANGED;
5041 mark = value_mark ();
5042 fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL, 0);
5044 /* We use value_equal_contents instead of value_equal because
5045 the latter coerces an array to a pointer, thus comparing just
5046 the address of the array instead of its contents. This is
5047 not what we want. */
5048 if ((b->val != NULL) != (new_val != NULL)
5049 || (b->val != NULL && !value_equal_contents (b->val, new_val)))
5051 if (new_val != NULL)
5053 release_value (new_val);
5054 value_free_to_mark (mark);
5056 bs->old_val = b->val;
5059 return WP_VALUE_CHANGED;
5063 /* Nothing changed. */
5064 value_free_to_mark (mark);
5065 return WP_VALUE_NOT_CHANGED;
5070 struct ui_out *uiout = current_uiout;
5072 /* This seems like the only logical thing to do because
5073 if we temporarily ignored the watchpoint, then when
5074 we reenter the block in which it is valid it contains
5075 garbage (in the case of a function, it may have two
5076 garbage values, one before and one after the prologue).
5077 So we can't even detect the first assignment to it and
5078 watch after that (since the garbage may or may not equal
5079 the first value assigned). */
5080 /* We print all the stop information in
5081 breakpoint_ops->print_it, but in this case, by the time we
5082 call breakpoint_ops->print_it this bp will be deleted
5083 already. So we have no choice but print the information
5085 if (ui_out_is_mi_like_p (uiout))
5087 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
5088 ui_out_text (uiout, "\nWatchpoint ");
5089 ui_out_field_int (uiout, "wpnum", b->base.number);
5091 " deleted because the program has left the block in\n\
5092 which its expression is valid.\n");
5094 /* Make sure the watchpoint's commands aren't executed. */
5095 decref_counted_command_line (&b->base.commands);
5096 watchpoint_del_at_next_stop (b);
5102 /* Return true if it looks like target has stopped due to hitting
5103 breakpoint location BL. This function does not check if we should
5104 stop, only if BL explains the stop. */
5107 bpstat_check_location (const struct bp_location *bl,
5108 struct address_space *aspace, CORE_ADDR bp_addr,
5109 const struct target_waitstatus *ws)
5111 struct breakpoint *b = bl->owner;
5113 /* BL is from an existing breakpoint. */
5114 gdb_assert (b != NULL);
5116 return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws);
5119 /* Determine if the watched values have actually changed, and we
5120 should stop. If not, set BS->stop to 0. */
5123 bpstat_check_watchpoint (bpstat bs)
5125 const struct bp_location *bl;
5126 struct watchpoint *b;
5128 /* BS is built for existing struct breakpoint. */
5129 bl = bs->bp_location_at;
5130 gdb_assert (bl != NULL);
5131 b = (struct watchpoint *) bs->breakpoint_at;
5132 gdb_assert (b != NULL);
5135 int must_check_value = 0;
5137 if (b->base.type == bp_watchpoint)
5138 /* For a software watchpoint, we must always check the
5140 must_check_value = 1;
5141 else if (b->watchpoint_triggered == watch_triggered_yes)
5142 /* We have a hardware watchpoint (read, write, or access)
5143 and the target earlier reported an address watched by
5145 must_check_value = 1;
5146 else if (b->watchpoint_triggered == watch_triggered_unknown
5147 && b->base.type == bp_hardware_watchpoint)
5148 /* We were stopped by a hardware watchpoint, but the target could
5149 not report the data address. We must check the watchpoint's
5150 value. Access and read watchpoints are out of luck; without
5151 a data address, we can't figure it out. */
5152 must_check_value = 1;
5154 if (must_check_value)
5157 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
5159 struct cleanup *cleanups = make_cleanup (xfree, message);
5160 int e = catch_errors (watchpoint_check, bs, message,
5162 do_cleanups (cleanups);
5166 /* We've already printed what needs to be printed. */
5167 bs->print_it = print_it_done;
5171 bs->print_it = print_it_noop;
5174 case WP_VALUE_CHANGED:
5175 if (b->base.type == bp_read_watchpoint)
5177 /* There are two cases to consider here:
5179 1. We're watching the triggered memory for reads.
5180 In that case, trust the target, and always report
5181 the watchpoint hit to the user. Even though
5182 reads don't cause value changes, the value may
5183 have changed since the last time it was read, and
5184 since we're not trapping writes, we will not see
5185 those, and as such we should ignore our notion of
5188 2. We're watching the triggered memory for both
5189 reads and writes. There are two ways this may
5192 2.1. This is a target that can't break on data
5193 reads only, but can break on accesses (reads or
5194 writes), such as e.g., x86. We detect this case
5195 at the time we try to insert read watchpoints.
5197 2.2. Otherwise, the target supports read
5198 watchpoints, but, the user set an access or write
5199 watchpoint watching the same memory as this read
5202 If we're watching memory writes as well as reads,
5203 ignore watchpoint hits when we find that the
5204 value hasn't changed, as reads don't cause
5205 changes. This still gives false positives when
5206 the program writes the same value to memory as
5207 what there was already in memory (we will confuse
5208 it for a read), but it's much better than
5211 int other_write_watchpoint = 0;
5213 if (bl->watchpoint_type == hw_read)
5215 struct breakpoint *other_b;
5217 ALL_BREAKPOINTS (other_b)
5218 if (other_b->type == bp_hardware_watchpoint
5219 || other_b->type == bp_access_watchpoint)
5221 struct watchpoint *other_w =
5222 (struct watchpoint *) other_b;
5224 if (other_w->watchpoint_triggered
5225 == watch_triggered_yes)
5227 other_write_watchpoint = 1;
5233 if (other_write_watchpoint
5234 || bl->watchpoint_type == hw_access)
5236 /* We're watching the same memory for writes,
5237 and the value changed since the last time we
5238 updated it, so this trap must be for a write.
5240 bs->print_it = print_it_noop;
5245 case WP_VALUE_NOT_CHANGED:
5246 if (b->base.type == bp_hardware_watchpoint
5247 || b->base.type == bp_watchpoint)
5249 /* Don't stop: write watchpoints shouldn't fire if
5250 the value hasn't changed. */
5251 bs->print_it = print_it_noop;
5259 /* Error from catch_errors. */
5260 printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number);
5261 watchpoint_del_at_next_stop (b);
5262 /* We've already printed what needs to be printed. */
5263 bs->print_it = print_it_done;
5267 else /* must_check_value == 0 */
5269 /* This is a case where some watchpoint(s) triggered, but
5270 not at the address of this watchpoint, or else no
5271 watchpoint triggered after all. So don't print
5272 anything for this watchpoint. */
5273 bs->print_it = print_it_noop;
5279 /* For breakpoints that are currently marked as telling gdb to stop,
5280 check conditions (condition proper, frame, thread and ignore count)
5281 of breakpoint referred to by BS. If we should not stop for this
5282 breakpoint, set BS->stop to 0. */
5285 bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
5287 const struct bp_location *bl;
5288 struct breakpoint *b;
5289 int value_is_zero = 0;
5290 struct expression *cond;
5292 gdb_assert (bs->stop);
5294 /* BS is built for existing struct breakpoint. */
5295 bl = bs->bp_location_at;
5296 gdb_assert (bl != NULL);
5297 b = bs->breakpoint_at;
5298 gdb_assert (b != NULL);
5300 /* Even if the target evaluated the condition on its end and notified GDB, we
5301 need to do so again since GDB does not know if we stopped due to a
5302 breakpoint or a single step breakpoint. */
5304 if (frame_id_p (b->frame_id)
5305 && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ())))
5311 /* If this is a thread/task-specific breakpoint, don't waste cpu
5312 evaluating the condition if this isn't the specified
5314 if ((b->thread != -1 && b->thread != pid_to_thread_id (ptid))
5315 || (b->task != 0 && b->task != ada_get_task_number (ptid)))
5322 /* Evaluate extension language breakpoints that have a "stop" method
5324 bs->stop = breakpoint_ext_lang_cond_says_stop (b);
5326 if (is_watchpoint (b))
5328 struct watchpoint *w = (struct watchpoint *) b;
5335 if (cond && b->disposition != disp_del_at_next_stop)
5337 int within_current_scope = 1;
5338 struct watchpoint * w;
5340 /* We use value_mark and value_free_to_mark because it could
5341 be a long time before we return to the command level and
5342 call free_all_values. We can't call free_all_values
5343 because we might be in the middle of evaluating a
5345 struct value *mark = value_mark ();
5347 if (is_watchpoint (b))
5348 w = (struct watchpoint *) b;
5352 /* Need to select the frame, with all that implies so that
5353 the conditions will have the right context. Because we
5354 use the frame, we will not see an inlined function's
5355 variables when we arrive at a breakpoint at the start
5356 of the inlined function; the current frame will be the
5358 if (w == NULL || w->cond_exp_valid_block == NULL)
5359 select_frame (get_current_frame ());
5362 struct frame_info *frame;
5364 /* For local watchpoint expressions, which particular
5365 instance of a local is being watched matters, so we
5366 keep track of the frame to evaluate the expression
5367 in. To evaluate the condition however, it doesn't
5368 really matter which instantiation of the function
5369 where the condition makes sense triggers the
5370 watchpoint. This allows an expression like "watch
5371 global if q > 10" set in `func', catch writes to
5372 global on all threads that call `func', or catch
5373 writes on all recursive calls of `func' by a single
5374 thread. We simply always evaluate the condition in
5375 the innermost frame that's executing where it makes
5376 sense to evaluate the condition. It seems
5378 frame = block_innermost_frame (w->cond_exp_valid_block);
5380 select_frame (frame);
5382 within_current_scope = 0;
5384 if (within_current_scope)
5386 = catch_errors (breakpoint_cond_eval, cond,
5387 "Error in testing breakpoint condition:\n",
5391 warning (_("Watchpoint condition cannot be tested "
5392 "in the current scope"));
5393 /* If we failed to set the right context for this
5394 watchpoint, unconditionally report it. */
5397 /* FIXME-someday, should give breakpoint #. */
5398 value_free_to_mark (mark);
5401 if (cond && value_is_zero)
5405 else if (b->ignore_count > 0)
5409 /* Increase the hit count even though we don't stop. */
5411 observer_notify_breakpoint_modified (b);
5416 /* Get a bpstat associated with having just stopped at address
5417 BP_ADDR in thread PTID.
5419 Determine whether we stopped at a breakpoint, etc, or whether we
5420 don't understand this stop. Result is a chain of bpstat's such
5423 if we don't understand the stop, the result is a null pointer.
5425 if we understand why we stopped, the result is not null.
5427 Each element of the chain refers to a particular breakpoint or
5428 watchpoint at which we have stopped. (We may have stopped for
5429 several reasons concurrently.)
5431 Each element of the chain has valid next, breakpoint_at,
5432 commands, FIXME??? fields. */
5435 bpstat_stop_status (struct address_space *aspace,
5436 CORE_ADDR bp_addr, ptid_t ptid,
5437 const struct target_waitstatus *ws)
5439 struct breakpoint *b = NULL;
5440 struct bp_location *bl;
5441 struct bp_location *loc;
5442 /* First item of allocated bpstat's. */
5443 bpstat bs_head = NULL, *bs_link = &bs_head;
5444 /* Pointer to the last thing in the chain currently. */
5447 int need_remove_insert;
5450 /* First, build the bpstat chain with locations that explain a
5451 target stop, while being careful to not set the target running,
5452 as that may invalidate locations (in particular watchpoint
5453 locations are recreated). Resuming will happen here with
5454 breakpoint conditions or watchpoint expressions that include
5455 inferior function calls. */
5459 if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
5462 for (bl = b->loc; bl != NULL; bl = bl->next)
5464 /* For hardware watchpoints, we look only at the first
5465 location. The watchpoint_check function will work on the
5466 entire expression, not the individual locations. For
5467 read watchpoints, the watchpoints_triggered function has
5468 checked all locations already. */
5469 if (b->type == bp_hardware_watchpoint && bl != b->loc)
5472 if (!bl->enabled || bl->shlib_disabled)
5475 if (!bpstat_check_location (bl, aspace, bp_addr, ws))
5478 /* Come here if it's a watchpoint, or if the break address
5481 bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to
5484 /* Assume we stop. Should we find a watchpoint that is not
5485 actually triggered, or if the condition of the breakpoint
5486 evaluates as false, we'll reset 'stop' to 0. */
5490 /* If this is a scope breakpoint, mark the associated
5491 watchpoint as triggered so that we will handle the
5492 out-of-scope event. We'll get to the watchpoint next
5494 if (b->type == bp_watchpoint_scope && b->related_breakpoint != b)
5496 struct watchpoint *w = (struct watchpoint *) b->related_breakpoint;
5498 w->watchpoint_triggered = watch_triggered_yes;
5503 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
5505 if (breakpoint_location_address_match (loc, aspace, bp_addr))
5507 bs = bpstat_alloc (loc, &bs_link);
5508 /* For hits of moribund locations, we should just proceed. */
5511 bs->print_it = print_it_noop;
5515 /* A bit of special processing for shlib breakpoints. We need to
5516 process solib loading here, so that the lists of loaded and
5517 unloaded libraries are correct before we handle "catch load" and
5519 for (bs = bs_head; bs != NULL; bs = bs->next)
5521 if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event)
5523 handle_solib_event ();
5528 /* Now go through the locations that caused the target to stop, and
5529 check whether we're interested in reporting this stop to higher
5530 layers, or whether we should resume the target transparently. */
5534 for (bs = bs_head; bs != NULL; bs = bs->next)
5539 b = bs->breakpoint_at;
5540 b->ops->check_status (bs);
5543 bpstat_check_breakpoint_conditions (bs, ptid);
5548 observer_notify_breakpoint_modified (b);
5550 /* We will stop here. */
5551 if (b->disposition == disp_disable)
5553 --(b->enable_count);
5554 if (b->enable_count <= 0
5555 && b->enable_state != bp_permanent)
5556 b->enable_state = bp_disabled;
5561 bs->commands = b->commands;
5562 incref_counted_command_line (bs->commands);
5563 if (command_line_is_silent (bs->commands
5564 ? bs->commands->commands : NULL))
5567 b->ops->after_condition_true (bs);
5572 /* Print nothing for this entry if we don't stop or don't
5574 if (!bs->stop || !bs->print)
5575 bs->print_it = print_it_noop;
5578 /* If we aren't stopping, the value of some hardware watchpoint may
5579 not have changed, but the intermediate memory locations we are
5580 watching may have. Don't bother if we're stopping; this will get
5582 need_remove_insert = 0;
5583 if (! bpstat_causes_stop (bs_head))
5584 for (bs = bs_head; bs != NULL; bs = bs->next)
5586 && bs->breakpoint_at
5587 && is_hardware_watchpoint (bs->breakpoint_at))
5589 struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at;
5591 update_watchpoint (w, 0 /* don't reparse. */);
5592 need_remove_insert = 1;
5595 if (need_remove_insert)
5596 update_global_location_list (1);
5597 else if (removed_any)
5598 update_global_location_list (0);
5604 handle_jit_event (void)
5606 struct frame_info *frame;
5607 struct gdbarch *gdbarch;
5609 /* Switch terminal for any messages produced by
5610 breakpoint_re_set. */
5611 target_terminal_ours_for_output ();
5613 frame = get_current_frame ();
5614 gdbarch = get_frame_arch (frame);
5616 jit_event_handler (gdbarch);
5618 target_terminal_inferior ();
5621 /* Prepare WHAT final decision for infrun. */
5623 /* Decide what infrun needs to do with this bpstat. */
5626 bpstat_what (bpstat bs_head)
5628 struct bpstat_what retval;
5632 retval.main_action = BPSTAT_WHAT_KEEP_CHECKING;
5633 retval.call_dummy = STOP_NONE;
5634 retval.is_longjmp = 0;
5636 for (bs = bs_head; bs != NULL; bs = bs->next)
5638 /* Extract this BS's action. After processing each BS, we check
5639 if its action overrides all we've seem so far. */
5640 enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING;
5643 if (bs->breakpoint_at == NULL)
5645 /* I suspect this can happen if it was a momentary
5646 breakpoint which has since been deleted. */
5650 bptype = bs->breakpoint_at->type;
5657 case bp_hardware_breakpoint:
5660 case bp_shlib_event:
5664 this_action = BPSTAT_WHAT_STOP_NOISY;
5666 this_action = BPSTAT_WHAT_STOP_SILENT;
5669 this_action = BPSTAT_WHAT_SINGLE;
5672 case bp_hardware_watchpoint:
5673 case bp_read_watchpoint:
5674 case bp_access_watchpoint:
5678 this_action = BPSTAT_WHAT_STOP_NOISY;
5680 this_action = BPSTAT_WHAT_STOP_SILENT;
5684 /* There was a watchpoint, but we're not stopping.
5685 This requires no further action. */
5689 case bp_longjmp_call_dummy:
5691 this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME;
5692 retval.is_longjmp = bptype != bp_exception;
5694 case bp_longjmp_resume:
5695 case bp_exception_resume:
5696 this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME;
5697 retval.is_longjmp = bptype == bp_longjmp_resume;
5699 case bp_step_resume:
5701 this_action = BPSTAT_WHAT_STEP_RESUME;
5704 /* It is for the wrong frame. */
5705 this_action = BPSTAT_WHAT_SINGLE;
5708 case bp_hp_step_resume:
5710 this_action = BPSTAT_WHAT_HP_STEP_RESUME;
5713 /* It is for the wrong frame. */
5714 this_action = BPSTAT_WHAT_SINGLE;
5717 case bp_watchpoint_scope:
5718 case bp_thread_event:
5719 case bp_overlay_event:
5720 case bp_longjmp_master:
5721 case bp_std_terminate_master:
5722 case bp_exception_master:
5723 this_action = BPSTAT_WHAT_SINGLE;
5729 this_action = BPSTAT_WHAT_STOP_NOISY;
5731 this_action = BPSTAT_WHAT_STOP_SILENT;
5735 /* There was a catchpoint, but we're not stopping.
5736 This requires no further action. */
5741 this_action = BPSTAT_WHAT_SINGLE;
5744 /* Make sure the action is stop (silent or noisy),
5745 so infrun.c pops the dummy frame. */
5746 retval.call_dummy = STOP_STACK_DUMMY;
5747 this_action = BPSTAT_WHAT_STOP_SILENT;
5749 case bp_std_terminate:
5750 /* Make sure the action is stop (silent or noisy),
5751 so infrun.c pops the dummy frame. */
5752 retval.call_dummy = STOP_STD_TERMINATE;
5753 this_action = BPSTAT_WHAT_STOP_SILENT;
5756 case bp_fast_tracepoint:
5757 case bp_static_tracepoint:
5758 /* Tracepoint hits should not be reported back to GDB, and
5759 if one got through somehow, it should have been filtered
5761 internal_error (__FILE__, __LINE__,
5762 _("bpstat_what: tracepoint encountered"));
5764 case bp_gnu_ifunc_resolver:
5765 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5766 this_action = BPSTAT_WHAT_SINGLE;
5768 case bp_gnu_ifunc_resolver_return:
5769 /* The breakpoint will be removed, execution will restart from the
5770 PC of the former breakpoint. */
5771 this_action = BPSTAT_WHAT_KEEP_CHECKING;
5776 this_action = BPSTAT_WHAT_STOP_SILENT;
5778 this_action = BPSTAT_WHAT_SINGLE;
5782 internal_error (__FILE__, __LINE__,
5783 _("bpstat_what: unhandled bptype %d"), (int) bptype);
5786 retval.main_action = max (retval.main_action, this_action);
5789 /* These operations may affect the bs->breakpoint_at state so they are
5790 delayed after MAIN_ACTION is decided above. */
5795 fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n");
5797 handle_jit_event ();
5800 for (bs = bs_head; bs != NULL; bs = bs->next)
5802 struct breakpoint *b = bs->breakpoint_at;
5808 case bp_gnu_ifunc_resolver:
5809 gnu_ifunc_resolver_stop (b);
5811 case bp_gnu_ifunc_resolver_return:
5812 gnu_ifunc_resolver_return_stop (b);
5820 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5821 without hardware support). This isn't related to a specific bpstat,
5822 just to things like whether watchpoints are set. */
5825 bpstat_should_step (void)
5827 struct breakpoint *b;
5830 if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL)
5836 bpstat_causes_stop (bpstat bs)
5838 for (; bs != NULL; bs = bs->next)
5847 /* Compute a string of spaces suitable to indent the next line
5848 so it starts at the position corresponding to the table column
5849 named COL_NAME in the currently active table of UIOUT. */
5852 wrap_indent_at_field (struct ui_out *uiout, const char *col_name)
5854 static char wrap_indent[80];
5855 int i, total_width, width, align;
5859 for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++)
5861 if (strcmp (text, col_name) == 0)
5863 gdb_assert (total_width < sizeof wrap_indent);
5864 memset (wrap_indent, ' ', total_width);
5865 wrap_indent[total_width] = 0;
5870 total_width += width + 1;
5876 /* Determine if the locations of this breakpoint will have their conditions
5877 evaluated by the target, host or a mix of both. Returns the following:
5879 "host": Host evals condition.
5880 "host or target": Host or Target evals condition.
5881 "target": Target evals condition.
5885 bp_condition_evaluator (struct breakpoint *b)
5887 struct bp_location *bl;
5888 char host_evals = 0;
5889 char target_evals = 0;
5894 if (!is_breakpoint (b))
5897 if (gdb_evaluates_breakpoint_condition_p ()
5898 || !target_supports_evaluation_of_breakpoint_conditions ())
5899 return condition_evaluation_host;
5901 for (bl = b->loc; bl; bl = bl->next)
5903 if (bl->cond_bytecode)
5909 if (host_evals && target_evals)
5910 return condition_evaluation_both;
5911 else if (target_evals)
5912 return condition_evaluation_target;
5914 return condition_evaluation_host;
5917 /* Determine the breakpoint location's condition evaluator. This is
5918 similar to bp_condition_evaluator, but for locations. */
5921 bp_location_condition_evaluator (struct bp_location *bl)
5923 if (bl && !is_breakpoint (bl->owner))
5926 if (gdb_evaluates_breakpoint_condition_p ()
5927 || !target_supports_evaluation_of_breakpoint_conditions ())
5928 return condition_evaluation_host;
5930 if (bl && bl->cond_bytecode)
5931 return condition_evaluation_target;
5933 return condition_evaluation_host;
5936 /* Print the LOC location out of the list of B->LOC locations. */
5939 print_breakpoint_location (struct breakpoint *b,
5940 struct bp_location *loc)
5942 struct ui_out *uiout = current_uiout;
5943 struct cleanup *old_chain = save_current_program_space ();
5945 if (loc != NULL && loc->shlib_disabled)
5949 set_current_program_space (loc->pspace);
5951 if (b->display_canonical)
5952 ui_out_field_string (uiout, "what", b->addr_string);
5953 else if (loc && loc->symtab)
5956 = find_pc_sect_function (loc->address, loc->section);
5959 ui_out_text (uiout, "in ");
5960 ui_out_field_string (uiout, "func",
5961 SYMBOL_PRINT_NAME (sym));
5962 ui_out_text (uiout, " ");
5963 ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what"));
5964 ui_out_text (uiout, "at ");
5966 ui_out_field_string (uiout, "file",
5967 symtab_to_filename_for_display (loc->symtab));
5968 ui_out_text (uiout, ":");
5970 if (ui_out_is_mi_like_p (uiout))
5971 ui_out_field_string (uiout, "fullname",
5972 symtab_to_fullname (loc->symtab));
5974 ui_out_field_int (uiout, "line", loc->line_number);
5978 struct ui_file *stb = mem_fileopen ();
5979 struct cleanup *stb_chain = make_cleanup_ui_file_delete (stb);
5981 print_address_symbolic (loc->gdbarch, loc->address, stb,
5983 ui_out_field_stream (uiout, "at", stb);
5985 do_cleanups (stb_chain);
5988 ui_out_field_string (uiout, "pending", b->addr_string);
5990 if (loc && is_breakpoint (b)
5991 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
5992 && bp_condition_evaluator (b) == condition_evaluation_both)
5994 ui_out_text (uiout, " (");
5995 ui_out_field_string (uiout, "evaluated-by",
5996 bp_location_condition_evaluator (loc));
5997 ui_out_text (uiout, ")");
6000 do_cleanups (old_chain);
6004 bptype_string (enum bptype type)
6006 struct ep_type_description
6011 static struct ep_type_description bptypes[] =
6013 {bp_none, "?deleted?"},
6014 {bp_breakpoint, "breakpoint"},
6015 {bp_hardware_breakpoint, "hw breakpoint"},
6016 {bp_until, "until"},
6017 {bp_finish, "finish"},
6018 {bp_watchpoint, "watchpoint"},
6019 {bp_hardware_watchpoint, "hw watchpoint"},
6020 {bp_read_watchpoint, "read watchpoint"},
6021 {bp_access_watchpoint, "acc watchpoint"},
6022 {bp_longjmp, "longjmp"},
6023 {bp_longjmp_resume, "longjmp resume"},
6024 {bp_longjmp_call_dummy, "longjmp for call dummy"},
6025 {bp_exception, "exception"},
6026 {bp_exception_resume, "exception resume"},
6027 {bp_step_resume, "step resume"},
6028 {bp_hp_step_resume, "high-priority step resume"},
6029 {bp_watchpoint_scope, "watchpoint scope"},
6030 {bp_call_dummy, "call dummy"},
6031 {bp_std_terminate, "std::terminate"},
6032 {bp_shlib_event, "shlib events"},
6033 {bp_thread_event, "thread events"},
6034 {bp_overlay_event, "overlay events"},
6035 {bp_longjmp_master, "longjmp master"},
6036 {bp_std_terminate_master, "std::terminate master"},
6037 {bp_exception_master, "exception master"},
6038 {bp_catchpoint, "catchpoint"},
6039 {bp_tracepoint, "tracepoint"},
6040 {bp_fast_tracepoint, "fast tracepoint"},
6041 {bp_static_tracepoint, "static tracepoint"},
6042 {bp_dprintf, "dprintf"},
6043 {bp_jit_event, "jit events"},
6044 {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"},
6045 {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"},
6048 if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0])))
6049 || ((int) type != bptypes[(int) type].type))
6050 internal_error (__FILE__, __LINE__,
6051 _("bptypes table does not describe type #%d."),
6054 return bptypes[(int) type].description;
6057 /* For MI, output a field named 'thread-groups' with a list as the value.
6058 For CLI, prefix the list with the string 'inf'. */
6061 output_thread_groups (struct ui_out *uiout,
6062 const char *field_name,
6066 struct cleanup *back_to;
6067 int is_mi = ui_out_is_mi_like_p (uiout);
6071 /* For backward compatibility, don't display inferiors in CLI unless
6072 there are several. Always display them for MI. */
6073 if (!is_mi && mi_only)
6076 back_to = make_cleanup_ui_out_list_begin_end (uiout, field_name);
6078 for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i)
6084 xsnprintf (mi_group, sizeof (mi_group), "i%d", inf);
6085 ui_out_field_string (uiout, NULL, mi_group);
6090 ui_out_text (uiout, " inf ");
6092 ui_out_text (uiout, ", ");
6094 ui_out_text (uiout, plongest (inf));
6098 do_cleanups (back_to);
6101 /* Print B to gdb_stdout. */
6104 print_one_breakpoint_location (struct breakpoint *b,
6105 struct bp_location *loc,
6107 struct bp_location **last_loc,
6110 struct command_line *l;
6111 static char bpenables[] = "nynny";
6113 struct ui_out *uiout = current_uiout;
6114 int header_of_multiple = 0;
6115 int part_of_multiple = (loc != NULL);
6116 struct value_print_options opts;
6118 get_user_print_options (&opts);
6120 gdb_assert (!loc || loc_number != 0);
6121 /* See comment in print_one_breakpoint concerning treatment of
6122 breakpoints with single disabled location. */
6125 && (b->loc->next != NULL || !b->loc->enabled)))
6126 header_of_multiple = 1;
6134 if (part_of_multiple)
6137 formatted = xstrprintf ("%d.%d", b->number, loc_number);
6138 ui_out_field_string (uiout, "number", formatted);
6143 ui_out_field_int (uiout, "number", b->number);
6148 if (part_of_multiple)
6149 ui_out_field_skip (uiout, "type");
6151 ui_out_field_string (uiout, "type", bptype_string (b->type));
6155 if (part_of_multiple)
6156 ui_out_field_skip (uiout, "disp");
6158 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
6163 if (part_of_multiple)
6164 ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n");
6166 ui_out_field_fmt (uiout, "enabled", "%c",
6167 bpenables[(int) b->enable_state]);
6168 ui_out_spaces (uiout, 2);
6172 if (b->ops != NULL && b->ops->print_one != NULL)
6174 /* Although the print_one can possibly print all locations,
6175 calling it here is not likely to get any nice result. So,
6176 make sure there's just one location. */
6177 gdb_assert (b->loc == NULL || b->loc->next == NULL);
6178 b->ops->print_one (b, last_loc);
6184 internal_error (__FILE__, __LINE__,
6185 _("print_one_breakpoint: bp_none encountered\n"));
6189 case bp_hardware_watchpoint:
6190 case bp_read_watchpoint:
6191 case bp_access_watchpoint:
6193 struct watchpoint *w = (struct watchpoint *) b;
6195 /* Field 4, the address, is omitted (which makes the columns
6196 not line up too nicely with the headers, but the effect
6197 is relatively readable). */
6198 if (opts.addressprint)
6199 ui_out_field_skip (uiout, "addr");
6201 ui_out_field_string (uiout, "what", w->exp_string);
6206 case bp_hardware_breakpoint:
6210 case bp_longjmp_resume:
6211 case bp_longjmp_call_dummy:
6213 case bp_exception_resume:
6214 case bp_step_resume:
6215 case bp_hp_step_resume:
6216 case bp_watchpoint_scope:
6218 case bp_std_terminate:
6219 case bp_shlib_event:
6220 case bp_thread_event:
6221 case bp_overlay_event:
6222 case bp_longjmp_master:
6223 case bp_std_terminate_master:
6224 case bp_exception_master:
6226 case bp_fast_tracepoint:
6227 case bp_static_tracepoint:
6230 case bp_gnu_ifunc_resolver:
6231 case bp_gnu_ifunc_resolver_return:
6232 if (opts.addressprint)
6235 if (header_of_multiple)
6236 ui_out_field_string (uiout, "addr", "<MULTIPLE>");
6237 else if (b->loc == NULL || loc->shlib_disabled)
6238 ui_out_field_string (uiout, "addr", "<PENDING>");
6240 ui_out_field_core_addr (uiout, "addr",
6241 loc->gdbarch, loc->address);
6244 if (!header_of_multiple)
6245 print_breakpoint_location (b, loc);
6252 if (loc != NULL && !header_of_multiple)
6254 struct inferior *inf;
6255 VEC(int) *inf_num = NULL;
6260 if (inf->pspace == loc->pspace)
6261 VEC_safe_push (int, inf_num, inf->num);
6264 /* For backward compatibility, don't display inferiors in CLI unless
6265 there are several. Always display for MI. */
6267 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6268 && (number_of_program_spaces () > 1
6269 || number_of_inferiors () > 1)
6270 /* LOC is for existing B, it cannot be in
6271 moribund_locations and thus having NULL OWNER. */
6272 && loc->owner->type != bp_catchpoint))
6274 output_thread_groups (uiout, "thread-groups", inf_num, mi_only);
6275 VEC_free (int, inf_num);
6278 if (!part_of_multiple)
6280 if (b->thread != -1)
6282 /* FIXME: This seems to be redundant and lost here; see the
6283 "stop only in" line a little further down. */
6284 ui_out_text (uiout, " thread ");
6285 ui_out_field_int (uiout, "thread", b->thread);
6287 else if (b->task != 0)
6289 ui_out_text (uiout, " task ");
6290 ui_out_field_int (uiout, "task", b->task);
6294 ui_out_text (uiout, "\n");
6296 if (!part_of_multiple)
6297 b->ops->print_one_detail (b, uiout);
6299 if (part_of_multiple && frame_id_p (b->frame_id))
6302 ui_out_text (uiout, "\tstop only in stack frame at ");
6303 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6305 ui_out_field_core_addr (uiout, "frame",
6306 b->gdbarch, b->frame_id.stack_addr);
6307 ui_out_text (uiout, "\n");
6310 if (!part_of_multiple && b->cond_string)
6313 if (is_tracepoint (b))
6314 ui_out_text (uiout, "\ttrace only if ");
6316 ui_out_text (uiout, "\tstop only if ");
6317 ui_out_field_string (uiout, "cond", b->cond_string);
6319 /* Print whether the target is doing the breakpoint's condition
6320 evaluation. If GDB is doing the evaluation, don't print anything. */
6321 if (is_breakpoint (b)
6322 && breakpoint_condition_evaluation_mode ()
6323 == condition_evaluation_target)
6325 ui_out_text (uiout, " (");
6326 ui_out_field_string (uiout, "evaluated-by",
6327 bp_condition_evaluator (b));
6328 ui_out_text (uiout, " evals)");
6330 ui_out_text (uiout, "\n");
6333 if (!part_of_multiple && b->thread != -1)
6335 /* FIXME should make an annotation for this. */
6336 ui_out_text (uiout, "\tstop only in thread ");
6337 ui_out_field_int (uiout, "thread", b->thread);
6338 ui_out_text (uiout, "\n");
6341 if (!part_of_multiple)
6345 /* FIXME should make an annotation for this. */
6346 if (is_catchpoint (b))
6347 ui_out_text (uiout, "\tcatchpoint");
6348 else if (is_tracepoint (b))
6349 ui_out_text (uiout, "\ttracepoint");
6351 ui_out_text (uiout, "\tbreakpoint");
6352 ui_out_text (uiout, " already hit ");
6353 ui_out_field_int (uiout, "times", b->hit_count);
6354 if (b->hit_count == 1)
6355 ui_out_text (uiout, " time\n");
6357 ui_out_text (uiout, " times\n");
6361 /* Output the count also if it is zero, but only if this is mi. */
6362 if (ui_out_is_mi_like_p (uiout))
6363 ui_out_field_int (uiout, "times", b->hit_count);
6367 if (!part_of_multiple && b->ignore_count)
6370 ui_out_text (uiout, "\tignore next ");
6371 ui_out_field_int (uiout, "ignore", b->ignore_count);
6372 ui_out_text (uiout, " hits\n");
6375 /* Note that an enable count of 1 corresponds to "enable once"
6376 behavior, which is reported by the combination of enablement and
6377 disposition, so we don't need to mention it here. */
6378 if (!part_of_multiple && b->enable_count > 1)
6381 ui_out_text (uiout, "\tdisable after ");
6382 /* Tweak the wording to clarify that ignore and enable counts
6383 are distinct, and have additive effect. */
6384 if (b->ignore_count)
6385 ui_out_text (uiout, "additional ");
6387 ui_out_text (uiout, "next ");
6388 ui_out_field_int (uiout, "enable", b->enable_count);
6389 ui_out_text (uiout, " hits\n");
6392 if (!part_of_multiple && is_tracepoint (b))
6394 struct tracepoint *tp = (struct tracepoint *) b;
6396 if (tp->traceframe_usage)
6398 ui_out_text (uiout, "\ttrace buffer usage ");
6399 ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage);
6400 ui_out_text (uiout, " bytes\n");
6404 l = b->commands ? b->commands->commands : NULL;
6405 if (!part_of_multiple && l)
6407 struct cleanup *script_chain;
6410 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
6411 print_command_lines (uiout, l, 4);
6412 do_cleanups (script_chain);
6415 if (is_tracepoint (b))
6417 struct tracepoint *t = (struct tracepoint *) b;
6419 if (!part_of_multiple && t->pass_count)
6421 annotate_field (10);
6422 ui_out_text (uiout, "\tpass count ");
6423 ui_out_field_int (uiout, "pass", t->pass_count);
6424 ui_out_text (uiout, " \n");
6427 /* Don't display it when tracepoint or tracepoint location is
6429 if (!header_of_multiple && loc != NULL && !loc->shlib_disabled)
6431 annotate_field (11);
6433 if (ui_out_is_mi_like_p (uiout))
6434 ui_out_field_string (uiout, "installed",
6435 loc->inserted ? "y" : "n");
6439 ui_out_text (uiout, "\t");
6441 ui_out_text (uiout, "\tnot ");
6442 ui_out_text (uiout, "installed on target\n");
6447 if (ui_out_is_mi_like_p (uiout) && !part_of_multiple)
6449 if (is_watchpoint (b))
6451 struct watchpoint *w = (struct watchpoint *) b;
6453 ui_out_field_string (uiout, "original-location", w->exp_string);
6455 else if (b->addr_string)
6456 ui_out_field_string (uiout, "original-location", b->addr_string);
6461 print_one_breakpoint (struct breakpoint *b,
6462 struct bp_location **last_loc,
6465 struct cleanup *bkpt_chain;
6466 struct ui_out *uiout = current_uiout;
6468 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
6470 print_one_breakpoint_location (b, NULL, 0, last_loc, allflag);
6471 do_cleanups (bkpt_chain);
6473 /* If this breakpoint has custom print function,
6474 it's already printed. Otherwise, print individual
6475 locations, if any. */
6476 if (b->ops == NULL || b->ops->print_one == NULL)
6478 /* If breakpoint has a single location that is disabled, we
6479 print it as if it had several locations, since otherwise it's
6480 hard to represent "breakpoint enabled, location disabled"
6483 Note that while hardware watchpoints have several locations
6484 internally, that's not a property exposed to user. */
6486 && !is_hardware_watchpoint (b)
6487 && (b->loc->next || !b->loc->enabled))
6489 struct bp_location *loc;
6492 for (loc = b->loc; loc; loc = loc->next, ++n)
6494 struct cleanup *inner2 =
6495 make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
6496 print_one_breakpoint_location (b, loc, n, last_loc, allflag);
6497 do_cleanups (inner2);
6504 breakpoint_address_bits (struct breakpoint *b)
6506 int print_address_bits = 0;
6507 struct bp_location *loc;
6509 for (loc = b->loc; loc; loc = loc->next)
6513 /* Software watchpoints that aren't watching memory don't have
6514 an address to print. */
6515 if (b->type == bp_watchpoint && loc->watchpoint_type == -1)
6518 addr_bit = gdbarch_addr_bit (loc->gdbarch);
6519 if (addr_bit > print_address_bits)
6520 print_address_bits = addr_bit;
6523 return print_address_bits;
6526 struct captured_breakpoint_query_args
6532 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
6534 struct captured_breakpoint_query_args *args = data;
6535 struct breakpoint *b;
6536 struct bp_location *dummy_loc = NULL;
6540 if (args->bnum == b->number)
6542 print_one_breakpoint (b, &dummy_loc, 0);
6550 gdb_breakpoint_query (struct ui_out *uiout, int bnum,
6551 char **error_message)
6553 struct captured_breakpoint_query_args args;
6556 /* For the moment we don't trust print_one_breakpoint() to not throw
6558 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
6559 error_message, RETURN_MASK_ALL) < 0)
6565 /* Return true if this breakpoint was set by the user, false if it is
6566 internal or momentary. */
6569 user_breakpoint_p (struct breakpoint *b)
6571 return b->number > 0;
6574 /* Print information on user settable breakpoint (watchpoint, etc)
6575 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6576 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6577 FILTER is non-NULL, call it on each breakpoint and only include the
6578 ones for which it returns non-zero. Return the total number of
6579 breakpoints listed. */
6582 breakpoint_1 (char *args, int allflag,
6583 int (*filter) (const struct breakpoint *))
6585 struct breakpoint *b;
6586 struct bp_location *last_loc = NULL;
6587 int nr_printable_breakpoints;
6588 struct cleanup *bkpttbl_chain;
6589 struct value_print_options opts;
6590 int print_address_bits = 0;
6591 int print_type_col_width = 14;
6592 struct ui_out *uiout = current_uiout;
6594 get_user_print_options (&opts);
6596 /* Compute the number of rows in the table, as well as the size
6597 required for address fields. */
6598 nr_printable_breakpoints = 0;
6601 /* If we have a filter, only list the breakpoints it accepts. */
6602 if (filter && !filter (b))
6605 /* If we have an "args" string, it is a list of breakpoints to
6606 accept. Skip the others. */
6607 if (args != NULL && *args != '\0')
6609 if (allflag && parse_and_eval_long (args) != b->number)
6611 if (!allflag && !number_is_in_list (args, b->number))
6615 if (allflag || user_breakpoint_p (b))
6617 int addr_bit, type_len;
6619 addr_bit = breakpoint_address_bits (b);
6620 if (addr_bit > print_address_bits)
6621 print_address_bits = addr_bit;
6623 type_len = strlen (bptype_string (b->type));
6624 if (type_len > print_type_col_width)
6625 print_type_col_width = type_len;
6627 nr_printable_breakpoints++;
6631 if (opts.addressprint)
6633 = make_cleanup_ui_out_table_begin_end (uiout, 6,
6634 nr_printable_breakpoints,
6638 = make_cleanup_ui_out_table_begin_end (uiout, 5,
6639 nr_printable_breakpoints,
6642 if (nr_printable_breakpoints > 0)
6643 annotate_breakpoints_headers ();
6644 if (nr_printable_breakpoints > 0)
6646 ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */
6647 if (nr_printable_breakpoints > 0)
6649 ui_out_table_header (uiout, print_type_col_width, ui_left,
6650 "type", "Type"); /* 2 */
6651 if (nr_printable_breakpoints > 0)
6653 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
6654 if (nr_printable_breakpoints > 0)
6656 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
6657 if (opts.addressprint)
6659 if (nr_printable_breakpoints > 0)
6661 if (print_address_bits <= 32)
6662 ui_out_table_header (uiout, 10, ui_left,
6663 "addr", "Address"); /* 5 */
6665 ui_out_table_header (uiout, 18, ui_left,
6666 "addr", "Address"); /* 5 */
6668 if (nr_printable_breakpoints > 0)
6670 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
6671 ui_out_table_body (uiout);
6672 if (nr_printable_breakpoints > 0)
6673 annotate_breakpoints_table ();
6678 /* If we have a filter, only list the breakpoints it accepts. */
6679 if (filter && !filter (b))
6682 /* If we have an "args" string, it is a list of breakpoints to
6683 accept. Skip the others. */
6685 if (args != NULL && *args != '\0')
6687 if (allflag) /* maintenance info breakpoint */
6689 if (parse_and_eval_long (args) != b->number)
6692 else /* all others */
6694 if (!number_is_in_list (args, b->number))
6698 /* We only print out user settable breakpoints unless the
6700 if (allflag || user_breakpoint_p (b))
6701 print_one_breakpoint (b, &last_loc, allflag);
6704 do_cleanups (bkpttbl_chain);
6706 if (nr_printable_breakpoints == 0)
6708 /* If there's a filter, let the caller decide how to report
6712 if (args == NULL || *args == '\0')
6713 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
6715 ui_out_message (uiout, 0,
6716 "No breakpoint or watchpoint matching '%s'.\n",
6722 if (last_loc && !server_command)
6723 set_next_address (last_loc->gdbarch, last_loc->address);
6726 /* FIXME? Should this be moved up so that it is only called when
6727 there have been breakpoints? */
6728 annotate_breakpoints_table_end ();
6730 return nr_printable_breakpoints;
6733 /* Display the value of default-collect in a way that is generally
6734 compatible with the breakpoint list. */
6737 default_collect_info (void)
6739 struct ui_out *uiout = current_uiout;
6741 /* If it has no value (which is frequently the case), say nothing; a
6742 message like "No default-collect." gets in user's face when it's
6744 if (!*default_collect)
6747 /* The following phrase lines up nicely with per-tracepoint collect
6749 ui_out_text (uiout, "default collect ");
6750 ui_out_field_string (uiout, "default-collect", default_collect);
6751 ui_out_text (uiout, " \n");
6755 breakpoints_info (char *args, int from_tty)
6757 breakpoint_1 (args, 0, NULL);
6759 default_collect_info ();
6763 watchpoints_info (char *args, int from_tty)
6765 int num_printed = breakpoint_1 (args, 0, is_watchpoint);
6766 struct ui_out *uiout = current_uiout;
6768 if (num_printed == 0)
6770 if (args == NULL || *args == '\0')
6771 ui_out_message (uiout, 0, "No watchpoints.\n");
6773 ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args);
6778 maintenance_info_breakpoints (char *args, int from_tty)
6780 breakpoint_1 (args, 1, NULL);
6782 default_collect_info ();
6786 breakpoint_has_pc (struct breakpoint *b,
6787 struct program_space *pspace,
6788 CORE_ADDR pc, struct obj_section *section)
6790 struct bp_location *bl = b->loc;
6792 for (; bl; bl = bl->next)
6794 if (bl->pspace == pspace
6795 && bl->address == pc
6796 && (!overlay_debugging || bl->section == section))
6802 /* Print a message describing any user-breakpoints set at PC. This
6803 concerns with logical breakpoints, so we match program spaces, not
6807 describe_other_breakpoints (struct gdbarch *gdbarch,
6808 struct program_space *pspace, CORE_ADDR pc,
6809 struct obj_section *section, int thread)
6812 struct breakpoint *b;
6815 others += (user_breakpoint_p (b)
6816 && breakpoint_has_pc (b, pspace, pc, section));
6820 printf_filtered (_("Note: breakpoint "));
6821 else /* if (others == ???) */
6822 printf_filtered (_("Note: breakpoints "));
6824 if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section))
6827 printf_filtered ("%d", b->number);
6828 if (b->thread == -1 && thread != -1)
6829 printf_filtered (" (all threads)");
6830 else if (b->thread != -1)
6831 printf_filtered (" (thread %d)", b->thread);
6832 printf_filtered ("%s%s ",
6833 ((b->enable_state == bp_disabled
6834 || b->enable_state == bp_call_disabled)
6836 : b->enable_state == bp_permanent
6840 : ((others == 1) ? " and" : ""));
6842 printf_filtered (_("also set at pc "));
6843 fputs_filtered (paddress (gdbarch, pc), gdb_stdout);
6844 printf_filtered (".\n");
6849 /* Return true iff it is meaningful to use the address member of
6850 BPT. For some breakpoint types, the address member is irrelevant
6851 and it makes no sense to attempt to compare it to other addresses
6852 (or use it for any other purpose either).
6854 More specifically, each of the following breakpoint types will
6855 always have a zero valued address and we don't want to mark
6856 breakpoints of any of these types to be a duplicate of an actual
6857 breakpoint at address zero:
6865 breakpoint_address_is_meaningful (struct breakpoint *bpt)
6867 enum bptype type = bpt->type;
6869 return (type != bp_watchpoint && type != bp_catchpoint);
6872 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6873 true if LOC1 and LOC2 represent the same watchpoint location. */
6876 watchpoint_locations_match (struct bp_location *loc1,
6877 struct bp_location *loc2)
6879 struct watchpoint *w1 = (struct watchpoint *) loc1->owner;
6880 struct watchpoint *w2 = (struct watchpoint *) loc2->owner;
6882 /* Both of them must exist. */
6883 gdb_assert (w1 != NULL);
6884 gdb_assert (w2 != NULL);
6886 /* If the target can evaluate the condition expression in hardware,
6887 then we we need to insert both watchpoints even if they are at
6888 the same place. Otherwise the watchpoint will only trigger when
6889 the condition of whichever watchpoint was inserted evaluates to
6890 true, not giving a chance for GDB to check the condition of the
6891 other watchpoint. */
6893 && target_can_accel_watchpoint_condition (loc1->address,
6895 loc1->watchpoint_type,
6898 && target_can_accel_watchpoint_condition (loc2->address,
6900 loc2->watchpoint_type,
6904 /* Note that this checks the owner's type, not the location's. In
6905 case the target does not support read watchpoints, but does
6906 support access watchpoints, we'll have bp_read_watchpoint
6907 watchpoints with hw_access locations. Those should be considered
6908 duplicates of hw_read locations. The hw_read locations will
6909 become hw_access locations later. */
6910 return (loc1->owner->type == loc2->owner->type
6911 && loc1->pspace->aspace == loc2->pspace->aspace
6912 && loc1->address == loc2->address
6913 && loc1->length == loc2->length);
6916 /* See breakpoint.h. */
6919 breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1,
6920 struct address_space *aspace2, CORE_ADDR addr2)
6922 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6923 || aspace1 == aspace2)
6927 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6928 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6929 matches ASPACE2. On targets that have global breakpoints, the address
6930 space doesn't really matter. */
6933 breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1,
6934 int len1, struct address_space *aspace2,
6937 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6938 || aspace1 == aspace2)
6939 && addr2 >= addr1 && addr2 < addr1 + len1);
6942 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6943 a ranged breakpoint. In most targets, a match happens only if ASPACE
6944 matches the breakpoint's address space. On targets that have global
6945 breakpoints, the address space doesn't really matter. */
6948 breakpoint_location_address_match (struct bp_location *bl,
6949 struct address_space *aspace,
6952 return (breakpoint_address_match (bl->pspace->aspace, bl->address,
6955 && breakpoint_address_match_range (bl->pspace->aspace,
6956 bl->address, bl->length,
6960 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6961 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6962 true, otherwise returns false. */
6965 tracepoint_locations_match (struct bp_location *loc1,
6966 struct bp_location *loc2)
6968 if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner))
6969 /* Since tracepoint locations are never duplicated with others', tracepoint
6970 locations at the same address of different tracepoints are regarded as
6971 different locations. */
6972 return (loc1->address == loc2->address && loc1->owner == loc2->owner);
6977 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
6978 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
6979 represent the same location. */
6982 breakpoint_locations_match (struct bp_location *loc1,
6983 struct bp_location *loc2)
6985 int hw_point1, hw_point2;
6987 /* Both of them must not be in moribund_locations. */
6988 gdb_assert (loc1->owner != NULL);
6989 gdb_assert (loc2->owner != NULL);
6991 hw_point1 = is_hardware_watchpoint (loc1->owner);
6992 hw_point2 = is_hardware_watchpoint (loc2->owner);
6994 if (hw_point1 != hw_point2)
6997 return watchpoint_locations_match (loc1, loc2);
6998 else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner))
6999 return tracepoint_locations_match (loc1, loc2);
7001 /* We compare bp_location.length in order to cover ranged breakpoints. */
7002 return (breakpoint_address_match (loc1->pspace->aspace, loc1->address,
7003 loc2->pspace->aspace, loc2->address)
7004 && loc1->length == loc2->length);
7008 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
7009 int bnum, int have_bnum)
7011 /* The longest string possibly returned by hex_string_custom
7012 is 50 chars. These must be at least that big for safety. */
7016 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
7017 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
7019 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7020 bnum, astr1, astr2);
7022 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
7025 /* Adjust a breakpoint's address to account for architectural
7026 constraints on breakpoint placement. Return the adjusted address.
7027 Note: Very few targets require this kind of adjustment. For most
7028 targets, this function is simply the identity function. */
7031 adjust_breakpoint_address (struct gdbarch *gdbarch,
7032 CORE_ADDR bpaddr, enum bptype bptype)
7034 if (!gdbarch_adjust_breakpoint_address_p (gdbarch))
7036 /* Very few targets need any kind of breakpoint adjustment. */
7039 else if (bptype == bp_watchpoint
7040 || bptype == bp_hardware_watchpoint
7041 || bptype == bp_read_watchpoint
7042 || bptype == bp_access_watchpoint
7043 || bptype == bp_catchpoint)
7045 /* Watchpoints and the various bp_catch_* eventpoints should not
7046 have their addresses modified. */
7051 CORE_ADDR adjusted_bpaddr;
7053 /* Some targets have architectural constraints on the placement
7054 of breakpoint instructions. Obtain the adjusted address. */
7055 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr);
7057 /* An adjusted breakpoint address can significantly alter
7058 a user's expectations. Print a warning if an adjustment
7060 if (adjusted_bpaddr != bpaddr)
7061 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
7063 return adjusted_bpaddr;
7068 init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops,
7069 struct breakpoint *owner)
7071 memset (loc, 0, sizeof (*loc));
7073 gdb_assert (ops != NULL);
7078 loc->cond_bytecode = NULL;
7079 loc->shlib_disabled = 0;
7082 switch (owner->type)
7088 case bp_longjmp_resume:
7089 case bp_longjmp_call_dummy:
7091 case bp_exception_resume:
7092 case bp_step_resume:
7093 case bp_hp_step_resume:
7094 case bp_watchpoint_scope:
7096 case bp_std_terminate:
7097 case bp_shlib_event:
7098 case bp_thread_event:
7099 case bp_overlay_event:
7101 case bp_longjmp_master:
7102 case bp_std_terminate_master:
7103 case bp_exception_master:
7104 case bp_gnu_ifunc_resolver:
7105 case bp_gnu_ifunc_resolver_return:
7107 loc->loc_type = bp_loc_software_breakpoint;
7108 mark_breakpoint_location_modified (loc);
7110 case bp_hardware_breakpoint:
7111 loc->loc_type = bp_loc_hardware_breakpoint;
7112 mark_breakpoint_location_modified (loc);
7114 case bp_hardware_watchpoint:
7115 case bp_read_watchpoint:
7116 case bp_access_watchpoint:
7117 loc->loc_type = bp_loc_hardware_watchpoint;
7122 case bp_fast_tracepoint:
7123 case bp_static_tracepoint:
7124 loc->loc_type = bp_loc_other;
7127 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
7133 /* Allocate a struct bp_location. */
7135 static struct bp_location *
7136 allocate_bp_location (struct breakpoint *bpt)
7138 return bpt->ops->allocate_location (bpt);
7142 free_bp_location (struct bp_location *loc)
7144 loc->ops->dtor (loc);
7148 /* Increment reference count. */
7151 incref_bp_location (struct bp_location *bl)
7156 /* Decrement reference count. If the reference count reaches 0,
7157 destroy the bp_location. Sets *BLP to NULL. */
7160 decref_bp_location (struct bp_location **blp)
7162 gdb_assert ((*blp)->refc > 0);
7164 if (--(*blp)->refc == 0)
7165 free_bp_location (*blp);
7169 /* Add breakpoint B at the end of the global breakpoint chain. */
7172 add_to_breakpoint_chain (struct breakpoint *b)
7174 struct breakpoint *b1;
7176 /* Add this breakpoint to the end of the chain so that a list of
7177 breakpoints will come out in order of increasing numbers. */
7179 b1 = breakpoint_chain;
7181 breakpoint_chain = b;
7190 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7193 init_raw_breakpoint_without_location (struct breakpoint *b,
7194 struct gdbarch *gdbarch,
7196 const struct breakpoint_ops *ops)
7198 memset (b, 0, sizeof (*b));
7200 gdb_assert (ops != NULL);
7204 b->gdbarch = gdbarch;
7205 b->language = current_language->la_language;
7206 b->input_radix = input_radix;
7208 b->enable_state = bp_enabled;
7211 b->ignore_count = 0;
7213 b->frame_id = null_frame_id;
7214 b->condition_not_parsed = 0;
7215 b->py_bp_object = NULL;
7216 b->related_breakpoint = b;
7219 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7220 that has type BPTYPE and has no locations as yet. */
7222 static struct breakpoint *
7223 set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
7225 const struct breakpoint_ops *ops)
7227 struct breakpoint *b = XNEW (struct breakpoint);
7229 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
7230 add_to_breakpoint_chain (b);
7234 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7235 resolutions should be made as the user specified the location explicitly
7239 set_breakpoint_location_function (struct bp_location *loc, int explicit_loc)
7241 gdb_assert (loc->owner != NULL);
7243 if (loc->owner->type == bp_breakpoint
7244 || loc->owner->type == bp_hardware_breakpoint
7245 || is_tracepoint (loc->owner))
7248 const char *function_name;
7249 CORE_ADDR func_addr;
7251 find_pc_partial_function_gnu_ifunc (loc->address, &function_name,
7252 &func_addr, NULL, &is_gnu_ifunc);
7254 if (is_gnu_ifunc && !explicit_loc)
7256 struct breakpoint *b = loc->owner;
7258 gdb_assert (loc->pspace == current_program_space);
7259 if (gnu_ifunc_resolve_name (function_name,
7260 &loc->requested_address))
7262 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7263 loc->address = adjust_breakpoint_address (loc->gdbarch,
7264 loc->requested_address,
7267 else if (b->type == bp_breakpoint && b->loc == loc
7268 && loc->next == NULL && b->related_breakpoint == b)
7270 /* Create only the whole new breakpoint of this type but do not
7271 mess more complicated breakpoints with multiple locations. */
7272 b->type = bp_gnu_ifunc_resolver;
7273 /* Remember the resolver's address for use by the return
7275 loc->related_address = func_addr;
7280 loc->function_name = xstrdup (function_name);
7284 /* Attempt to determine architecture of location identified by SAL. */
7286 get_sal_arch (struct symtab_and_line sal)
7289 return get_objfile_arch (sal.section->objfile);
7291 return get_objfile_arch (sal.symtab->objfile);
7296 /* Low level routine for partially initializing a breakpoint of type
7297 BPTYPE. The newly created breakpoint's address, section, source
7298 file name, and line number are provided by SAL.
7300 It is expected that the caller will complete the initialization of
7301 the newly created breakpoint struct as well as output any status
7302 information regarding the creation of a new breakpoint. */
7305 init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch,
7306 struct symtab_and_line sal, enum bptype bptype,
7307 const struct breakpoint_ops *ops)
7309 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
7311 add_location_to_breakpoint (b, &sal);
7313 if (bptype != bp_catchpoint)
7314 gdb_assert (sal.pspace != NULL);
7316 /* Store the program space that was used to set the breakpoint,
7317 except for ordinary breakpoints, which are independent of the
7319 if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint)
7320 b->pspace = sal.pspace;
7323 /* set_raw_breakpoint is a low level routine for allocating and
7324 partially initializing a breakpoint of type BPTYPE. The newly
7325 created breakpoint's address, section, source file name, and line
7326 number are provided by SAL. The newly created and partially
7327 initialized breakpoint is added to the breakpoint chain and
7328 is also returned as the value of this function.
7330 It is expected that the caller will complete the initialization of
7331 the newly created breakpoint struct as well as output any status
7332 information regarding the creation of a new breakpoint. In
7333 particular, set_raw_breakpoint does NOT set the breakpoint
7334 number! Care should be taken to not allow an error to occur
7335 prior to completing the initialization of the breakpoint. If this
7336 should happen, a bogus breakpoint will be left on the chain. */
7339 set_raw_breakpoint (struct gdbarch *gdbarch,
7340 struct symtab_and_line sal, enum bptype bptype,
7341 const struct breakpoint_ops *ops)
7343 struct breakpoint *b = XNEW (struct breakpoint);
7345 init_raw_breakpoint (b, gdbarch, sal, bptype, ops);
7346 add_to_breakpoint_chain (b);
7351 /* Note that the breakpoint object B describes a permanent breakpoint
7352 instruction, hard-wired into the inferior's code. */
7354 make_breakpoint_permanent (struct breakpoint *b)
7356 struct bp_location *bl;
7358 b->enable_state = bp_permanent;
7360 /* By definition, permanent breakpoints are already present in the
7361 code. Mark all locations as inserted. For now,
7362 make_breakpoint_permanent is called in just one place, so it's
7363 hard to say if it's reasonable to have permanent breakpoint with
7364 multiple locations or not, but it's easy to implement. */
7365 for (bl = b->loc; bl; bl = bl->next)
7369 /* Call this routine when stepping and nexting to enable a breakpoint
7370 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7371 initiated the operation. */
7374 set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame)
7376 struct breakpoint *b, *b_tmp;
7377 int thread = tp->num;
7379 /* To avoid having to rescan all objfile symbols at every step,
7380 we maintain a list of continually-inserted but always disabled
7381 longjmp "master" breakpoints. Here, we simply create momentary
7382 clones of those and enable them for the requested thread. */
7383 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7384 if (b->pspace == current_program_space
7385 && (b->type == bp_longjmp_master
7386 || b->type == bp_exception_master))
7388 enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception;
7389 struct breakpoint *clone;
7391 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7392 after their removal. */
7393 clone = momentary_breakpoint_from_master (b, type,
7394 &longjmp_breakpoint_ops, 1);
7395 clone->thread = thread;
7398 tp->initiating_frame = frame;
7401 /* Delete all longjmp breakpoints from THREAD. */
7403 delete_longjmp_breakpoint (int thread)
7405 struct breakpoint *b, *b_tmp;
7407 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7408 if (b->type == bp_longjmp || b->type == bp_exception)
7410 if (b->thread == thread)
7411 delete_breakpoint (b);
7416 delete_longjmp_breakpoint_at_next_stop (int thread)
7418 struct breakpoint *b, *b_tmp;
7420 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7421 if (b->type == bp_longjmp || b->type == bp_exception)
7423 if (b->thread == thread)
7424 b->disposition = disp_del_at_next_stop;
7428 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7429 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7430 pointer to any of them. Return NULL if this system cannot place longjmp
7434 set_longjmp_breakpoint_for_call_dummy (void)
7436 struct breakpoint *b, *retval = NULL;
7439 if (b->pspace == current_program_space && b->type == bp_longjmp_master)
7441 struct breakpoint *new_b;
7443 new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy,
7444 &momentary_breakpoint_ops,
7446 new_b->thread = pid_to_thread_id (inferior_ptid);
7448 /* Link NEW_B into the chain of RETVAL breakpoints. */
7450 gdb_assert (new_b->related_breakpoint == new_b);
7453 new_b->related_breakpoint = retval;
7454 while (retval->related_breakpoint != new_b->related_breakpoint)
7455 retval = retval->related_breakpoint;
7456 retval->related_breakpoint = new_b;
7462 /* Verify all existing dummy frames and their associated breakpoints for
7463 TP. Remove those which can no longer be found in the current frame
7466 You should call this function only at places where it is safe to currently
7467 unwind the whole stack. Failed stack unwind would discard live dummy
7471 check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp)
7473 struct breakpoint *b, *b_tmp;
7475 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7476 if (b->type == bp_longjmp_call_dummy && b->thread == tp->num)
7478 struct breakpoint *dummy_b = b->related_breakpoint;
7480 while (dummy_b != b && dummy_b->type != bp_call_dummy)
7481 dummy_b = dummy_b->related_breakpoint;
7482 if (dummy_b->type != bp_call_dummy
7483 || frame_find_by_id (dummy_b->frame_id) != NULL)
7486 dummy_frame_discard (dummy_b->frame_id, tp->ptid);
7488 while (b->related_breakpoint != b)
7490 if (b_tmp == b->related_breakpoint)
7491 b_tmp = b->related_breakpoint->next;
7492 delete_breakpoint (b->related_breakpoint);
7494 delete_breakpoint (b);
7499 enable_overlay_breakpoints (void)
7501 struct breakpoint *b;
7504 if (b->type == bp_overlay_event)
7506 b->enable_state = bp_enabled;
7507 update_global_location_list (1);
7508 overlay_events_enabled = 1;
7513 disable_overlay_breakpoints (void)
7515 struct breakpoint *b;
7518 if (b->type == bp_overlay_event)
7520 b->enable_state = bp_disabled;
7521 update_global_location_list (0);
7522 overlay_events_enabled = 0;
7526 /* Set an active std::terminate breakpoint for each std::terminate
7527 master breakpoint. */
7529 set_std_terminate_breakpoint (void)
7531 struct breakpoint *b, *b_tmp;
7533 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7534 if (b->pspace == current_program_space
7535 && b->type == bp_std_terminate_master)
7537 momentary_breakpoint_from_master (b, bp_std_terminate,
7538 &momentary_breakpoint_ops, 1);
7542 /* Delete all the std::terminate breakpoints. */
7544 delete_std_terminate_breakpoint (void)
7546 struct breakpoint *b, *b_tmp;
7548 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7549 if (b->type == bp_std_terminate)
7550 delete_breakpoint (b);
7554 create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7556 struct breakpoint *b;
7558 b = create_internal_breakpoint (gdbarch, address, bp_thread_event,
7559 &internal_breakpoint_ops);
7561 b->enable_state = bp_enabled;
7562 /* addr_string has to be used or breakpoint_re_set will delete me. */
7564 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
7566 update_global_location_list_nothrow (1);
7572 remove_thread_event_breakpoints (void)
7574 struct breakpoint *b, *b_tmp;
7576 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7577 if (b->type == bp_thread_event
7578 && b->loc->pspace == current_program_space)
7579 delete_breakpoint (b);
7582 struct lang_and_radix
7588 /* Create a breakpoint for JIT code registration and unregistration. */
7591 create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7593 struct breakpoint *b;
7595 b = create_internal_breakpoint (gdbarch, address, bp_jit_event,
7596 &internal_breakpoint_ops);
7597 update_global_location_list_nothrow (1);
7601 /* Remove JIT code registration and unregistration breakpoint(s). */
7604 remove_jit_event_breakpoints (void)
7606 struct breakpoint *b, *b_tmp;
7608 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7609 if (b->type == bp_jit_event
7610 && b->loc->pspace == current_program_space)
7611 delete_breakpoint (b);
7615 remove_solib_event_breakpoints (void)
7617 struct breakpoint *b, *b_tmp;
7619 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7620 if (b->type == bp_shlib_event
7621 && b->loc->pspace == current_program_space)
7622 delete_breakpoint (b);
7626 create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7628 struct breakpoint *b;
7630 b = create_internal_breakpoint (gdbarch, address, bp_shlib_event,
7631 &internal_breakpoint_ops);
7632 update_global_location_list_nothrow (1);
7636 /* Disable any breakpoints that are on code in shared libraries. Only
7637 apply to enabled breakpoints, disabled ones can just stay disabled. */
7640 disable_breakpoints_in_shlibs (void)
7642 struct bp_location *loc, **locp_tmp;
7644 ALL_BP_LOCATIONS (loc, locp_tmp)
7646 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7647 struct breakpoint *b = loc->owner;
7649 /* We apply the check to all breakpoints, including disabled for
7650 those with loc->duplicate set. This is so that when breakpoint
7651 becomes enabled, or the duplicate is removed, gdb will try to
7652 insert all breakpoints. If we don't set shlib_disabled here,
7653 we'll try to insert those breakpoints and fail. */
7654 if (((b->type == bp_breakpoint)
7655 || (b->type == bp_jit_event)
7656 || (b->type == bp_hardware_breakpoint)
7657 || (is_tracepoint (b)))
7658 && loc->pspace == current_program_space
7659 && !loc->shlib_disabled
7660 && solib_name_from_address (loc->pspace, loc->address)
7663 loc->shlib_disabled = 1;
7668 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7669 notification of unloaded_shlib. Only apply to enabled breakpoints,
7670 disabled ones can just stay disabled. */
7673 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
7675 struct bp_location *loc, **locp_tmp;
7676 int disabled_shlib_breaks = 0;
7678 /* SunOS a.out shared libraries are always mapped, so do not
7679 disable breakpoints; they will only be reported as unloaded
7680 through clear_solib when GDB discards its shared library
7681 list. See clear_solib for more information. */
7682 if (exec_bfd != NULL
7683 && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour)
7686 ALL_BP_LOCATIONS (loc, locp_tmp)
7688 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7689 struct breakpoint *b = loc->owner;
7691 if (solib->pspace == loc->pspace
7692 && !loc->shlib_disabled
7693 && (((b->type == bp_breakpoint
7694 || b->type == bp_jit_event
7695 || b->type == bp_hardware_breakpoint)
7696 && (loc->loc_type == bp_loc_hardware_breakpoint
7697 || loc->loc_type == bp_loc_software_breakpoint))
7698 || is_tracepoint (b))
7699 && solib_contains_address_p (solib, loc->address))
7701 loc->shlib_disabled = 1;
7702 /* At this point, we cannot rely on remove_breakpoint
7703 succeeding so we must mark the breakpoint as not inserted
7704 to prevent future errors occurring in remove_breakpoints. */
7707 /* This may cause duplicate notifications for the same breakpoint. */
7708 observer_notify_breakpoint_modified (b);
7710 if (!disabled_shlib_breaks)
7712 target_terminal_ours_for_output ();
7713 warning (_("Temporarily disabling breakpoints "
7714 "for unloaded shared library \"%s\""),
7717 disabled_shlib_breaks = 1;
7722 /* Disable any breakpoints and tracepoints in OBJFILE upon
7723 notification of free_objfile. Only apply to enabled breakpoints,
7724 disabled ones can just stay disabled. */
7727 disable_breakpoints_in_freed_objfile (struct objfile *objfile)
7729 struct breakpoint *b;
7731 if (objfile == NULL)
7734 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7735 managed by the user with add-symbol-file/remove-symbol-file.
7736 Similarly to how breakpoints in shared libraries are handled in
7737 response to "nosharedlibrary", mark breakpoints in such modules
7738 shlib_disabled so they end up uninserted on the next global
7739 location list update. Shared libraries not loaded by the user
7740 aren't handled here -- they're already handled in
7741 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7742 solib_unloaded observer. We skip objfiles that are not
7743 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7745 if ((objfile->flags & OBJF_SHARED) == 0
7746 || (objfile->flags & OBJF_USERLOADED) == 0)
7751 struct bp_location *loc;
7752 int bp_modified = 0;
7754 if (!is_breakpoint (b) && !is_tracepoint (b))
7757 for (loc = b->loc; loc != NULL; loc = loc->next)
7759 CORE_ADDR loc_addr = loc->address;
7761 if (loc->loc_type != bp_loc_hardware_breakpoint
7762 && loc->loc_type != bp_loc_software_breakpoint)
7765 if (loc->shlib_disabled != 0)
7768 if (objfile->pspace != loc->pspace)
7771 if (loc->loc_type != bp_loc_hardware_breakpoint
7772 && loc->loc_type != bp_loc_software_breakpoint)
7775 if (is_addr_in_objfile (loc_addr, objfile))
7777 loc->shlib_disabled = 1;
7778 /* At this point, we don't know whether the object was
7779 unmapped from the inferior or not, so leave the
7780 inserted flag alone. We'll handle failure to
7781 uninsert quietly, in case the object was indeed
7784 mark_breakpoint_location_modified (loc);
7791 observer_notify_breakpoint_modified (b);
7795 /* FORK & VFORK catchpoints. */
7797 /* An instance of this type is used to represent a fork or vfork
7798 catchpoint. It includes a "struct breakpoint" as a kind of base
7799 class; users downcast to "struct breakpoint *" when needed. A
7800 breakpoint is really of this type iff its ops pointer points to
7801 CATCH_FORK_BREAKPOINT_OPS. */
7803 struct fork_catchpoint
7805 /* The base class. */
7806 struct breakpoint base;
7808 /* Process id of a child process whose forking triggered this
7809 catchpoint. This field is only valid immediately after this
7810 catchpoint has triggered. */
7811 ptid_t forked_inferior_pid;
7814 /* Implement the "insert" breakpoint_ops method for fork
7818 insert_catch_fork (struct bp_location *bl)
7820 return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid));
7823 /* Implement the "remove" breakpoint_ops method for fork
7827 remove_catch_fork (struct bp_location *bl)
7829 return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid));
7832 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7836 breakpoint_hit_catch_fork (const struct bp_location *bl,
7837 struct address_space *aspace, CORE_ADDR bp_addr,
7838 const struct target_waitstatus *ws)
7840 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
7842 if (ws->kind != TARGET_WAITKIND_FORKED)
7845 c->forked_inferior_pid = ws->value.related_pid;
7849 /* Implement the "print_it" breakpoint_ops method for fork
7852 static enum print_stop_action
7853 print_it_catch_fork (bpstat bs)
7855 struct ui_out *uiout = current_uiout;
7856 struct breakpoint *b = bs->breakpoint_at;
7857 struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at;
7859 annotate_catchpoint (b->number);
7860 if (b->disposition == disp_del)
7861 ui_out_text (uiout, "\nTemporary catchpoint ");
7863 ui_out_text (uiout, "\nCatchpoint ");
7864 if (ui_out_is_mi_like_p (uiout))
7866 ui_out_field_string (uiout, "reason",
7867 async_reason_lookup (EXEC_ASYNC_FORK));
7868 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7870 ui_out_field_int (uiout, "bkptno", b->number);
7871 ui_out_text (uiout, " (forked process ");
7872 ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid));
7873 ui_out_text (uiout, "), ");
7874 return PRINT_SRC_AND_LOC;
7877 /* Implement the "print_one" breakpoint_ops method for fork
7881 print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc)
7883 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
7884 struct value_print_options opts;
7885 struct ui_out *uiout = current_uiout;
7887 get_user_print_options (&opts);
7889 /* Field 4, the address, is omitted (which makes the columns not
7890 line up too nicely with the headers, but the effect is relatively
7892 if (opts.addressprint)
7893 ui_out_field_skip (uiout, "addr");
7895 ui_out_text (uiout, "fork");
7896 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
7898 ui_out_text (uiout, ", process ");
7899 ui_out_field_int (uiout, "what",
7900 ptid_get_pid (c->forked_inferior_pid));
7901 ui_out_spaces (uiout, 1);
7904 if (ui_out_is_mi_like_p (uiout))
7905 ui_out_field_string (uiout, "catch-type", "fork");
7908 /* Implement the "print_mention" breakpoint_ops method for fork
7912 print_mention_catch_fork (struct breakpoint *b)
7914 printf_filtered (_("Catchpoint %d (fork)"), b->number);
7917 /* Implement the "print_recreate" breakpoint_ops method for fork
7921 print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp)
7923 fprintf_unfiltered (fp, "catch fork");
7924 print_recreate_thread (b, fp);
7927 /* The breakpoint_ops structure to be used in fork catchpoints. */
7929 static struct breakpoint_ops catch_fork_breakpoint_ops;
7931 /* Implement the "insert" breakpoint_ops method for vfork
7935 insert_catch_vfork (struct bp_location *bl)
7937 return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid));
7940 /* Implement the "remove" breakpoint_ops method for vfork
7944 remove_catch_vfork (struct bp_location *bl)
7946 return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid));
7949 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
7953 breakpoint_hit_catch_vfork (const struct bp_location *bl,
7954 struct address_space *aspace, CORE_ADDR bp_addr,
7955 const struct target_waitstatus *ws)
7957 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
7959 if (ws->kind != TARGET_WAITKIND_VFORKED)
7962 c->forked_inferior_pid = ws->value.related_pid;
7966 /* Implement the "print_it" breakpoint_ops method for vfork
7969 static enum print_stop_action
7970 print_it_catch_vfork (bpstat bs)
7972 struct ui_out *uiout = current_uiout;
7973 struct breakpoint *b = bs->breakpoint_at;
7974 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
7976 annotate_catchpoint (b->number);
7977 if (b->disposition == disp_del)
7978 ui_out_text (uiout, "\nTemporary catchpoint ");
7980 ui_out_text (uiout, "\nCatchpoint ");
7981 if (ui_out_is_mi_like_p (uiout))
7983 ui_out_field_string (uiout, "reason",
7984 async_reason_lookup (EXEC_ASYNC_VFORK));
7985 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7987 ui_out_field_int (uiout, "bkptno", b->number);
7988 ui_out_text (uiout, " (vforked process ");
7989 ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid));
7990 ui_out_text (uiout, "), ");
7991 return PRINT_SRC_AND_LOC;
7994 /* Implement the "print_one" breakpoint_ops method for vfork
7998 print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc)
8000 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
8001 struct value_print_options opts;
8002 struct ui_out *uiout = current_uiout;
8004 get_user_print_options (&opts);
8005 /* Field 4, the address, is omitted (which makes the columns not
8006 line up too nicely with the headers, but the effect is relatively
8008 if (opts.addressprint)
8009 ui_out_field_skip (uiout, "addr");
8011 ui_out_text (uiout, "vfork");
8012 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
8014 ui_out_text (uiout, ", process ");
8015 ui_out_field_int (uiout, "what",
8016 ptid_get_pid (c->forked_inferior_pid));
8017 ui_out_spaces (uiout, 1);
8020 if (ui_out_is_mi_like_p (uiout))
8021 ui_out_field_string (uiout, "catch-type", "vfork");
8024 /* Implement the "print_mention" breakpoint_ops method for vfork
8028 print_mention_catch_vfork (struct breakpoint *b)
8030 printf_filtered (_("Catchpoint %d (vfork)"), b->number);
8033 /* Implement the "print_recreate" breakpoint_ops method for vfork
8037 print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp)
8039 fprintf_unfiltered (fp, "catch vfork");
8040 print_recreate_thread (b, fp);
8043 /* The breakpoint_ops structure to be used in vfork catchpoints. */
8045 static struct breakpoint_ops catch_vfork_breakpoint_ops;
8047 /* An instance of this type is used to represent an solib catchpoint.
8048 It includes a "struct breakpoint" as a kind of base class; users
8049 downcast to "struct breakpoint *" when needed. A breakpoint is
8050 really of this type iff its ops pointer points to
8051 CATCH_SOLIB_BREAKPOINT_OPS. */
8053 struct solib_catchpoint
8055 /* The base class. */
8056 struct breakpoint base;
8058 /* True for "catch load", false for "catch unload". */
8059 unsigned char is_load;
8061 /* Regular expression to match, if any. COMPILED is only valid when
8062 REGEX is non-NULL. */
8068 dtor_catch_solib (struct breakpoint *b)
8070 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8073 regfree (&self->compiled);
8074 xfree (self->regex);
8076 base_breakpoint_ops.dtor (b);
8080 insert_catch_solib (struct bp_location *ignore)
8086 remove_catch_solib (struct bp_location *ignore)
8092 breakpoint_hit_catch_solib (const struct bp_location *bl,
8093 struct address_space *aspace,
8095 const struct target_waitstatus *ws)
8097 struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner;
8098 struct breakpoint *other;
8100 if (ws->kind == TARGET_WAITKIND_LOADED)
8103 ALL_BREAKPOINTS (other)
8105 struct bp_location *other_bl;
8107 if (other == bl->owner)
8110 if (other->type != bp_shlib_event)
8113 if (self->base.pspace != NULL && other->pspace != self->base.pspace)
8116 for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next)
8118 if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws))
8127 check_status_catch_solib (struct bpstats *bs)
8129 struct solib_catchpoint *self
8130 = (struct solib_catchpoint *) bs->breakpoint_at;
8135 struct so_list *iter;
8138 VEC_iterate (so_list_ptr, current_program_space->added_solibs,
8143 || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0)
8152 VEC_iterate (char_ptr, current_program_space->deleted_solibs,
8157 || regexec (&self->compiled, iter, 0, NULL, 0) == 0)
8163 bs->print_it = print_it_noop;
8166 static enum print_stop_action
8167 print_it_catch_solib (bpstat bs)
8169 struct breakpoint *b = bs->breakpoint_at;
8170 struct ui_out *uiout = current_uiout;
8172 annotate_catchpoint (b->number);
8173 if (b->disposition == disp_del)
8174 ui_out_text (uiout, "\nTemporary catchpoint ");
8176 ui_out_text (uiout, "\nCatchpoint ");
8177 ui_out_field_int (uiout, "bkptno", b->number);
8178 ui_out_text (uiout, "\n");
8179 if (ui_out_is_mi_like_p (uiout))
8180 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8181 print_solib_event (1);
8182 return PRINT_SRC_AND_LOC;
8186 print_one_catch_solib (struct breakpoint *b, struct bp_location **locs)
8188 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8189 struct value_print_options opts;
8190 struct ui_out *uiout = current_uiout;
8193 get_user_print_options (&opts);
8194 /* Field 4, the address, is omitted (which makes the columns not
8195 line up too nicely with the headers, but the effect is relatively
8197 if (opts.addressprint)
8200 ui_out_field_skip (uiout, "addr");
8207 msg = xstrprintf (_("load of library matching %s"), self->regex);
8209 msg = xstrdup (_("load of library"));
8214 msg = xstrprintf (_("unload of library matching %s"), self->regex);
8216 msg = xstrdup (_("unload of library"));
8218 ui_out_field_string (uiout, "what", msg);
8221 if (ui_out_is_mi_like_p (uiout))
8222 ui_out_field_string (uiout, "catch-type",
8223 self->is_load ? "load" : "unload");
8227 print_mention_catch_solib (struct breakpoint *b)
8229 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8231 printf_filtered (_("Catchpoint %d (%s)"), b->number,
8232 self->is_load ? "load" : "unload");
8236 print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp)
8238 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8240 fprintf_unfiltered (fp, "%s %s",
8241 b->disposition == disp_del ? "tcatch" : "catch",
8242 self->is_load ? "load" : "unload");
8244 fprintf_unfiltered (fp, " %s", self->regex);
8245 fprintf_unfiltered (fp, "\n");
8248 static struct breakpoint_ops catch_solib_breakpoint_ops;
8250 /* Shared helper function (MI and CLI) for creating and installing
8251 a shared object event catchpoint. If IS_LOAD is non-zero then
8252 the events to be caught are load events, otherwise they are
8253 unload events. If IS_TEMP is non-zero the catchpoint is a
8254 temporary one. If ENABLED is non-zero the catchpoint is
8255 created in an enabled state. */
8258 add_solib_catchpoint (char *arg, int is_load, int is_temp, int enabled)
8260 struct solib_catchpoint *c;
8261 struct gdbarch *gdbarch = get_current_arch ();
8262 struct cleanup *cleanup;
8266 arg = skip_spaces (arg);
8268 c = XCNEW (struct solib_catchpoint);
8269 cleanup = make_cleanup (xfree, c);
8275 errcode = regcomp (&c->compiled, arg, REG_NOSUB);
8278 char *err = get_regcomp_error (errcode, &c->compiled);
8280 make_cleanup (xfree, err);
8281 error (_("Invalid regexp (%s): %s"), err, arg);
8283 c->regex = xstrdup (arg);
8286 c->is_load = is_load;
8287 init_catchpoint (&c->base, gdbarch, is_temp, NULL,
8288 &catch_solib_breakpoint_ops);
8290 c->base.enable_state = enabled ? bp_enabled : bp_disabled;
8292 discard_cleanups (cleanup);
8293 install_breakpoint (0, &c->base, 1);
8296 /* A helper function that does all the work for "catch load" and
8300 catch_load_or_unload (char *arg, int from_tty, int is_load,
8301 struct cmd_list_element *command)
8304 const int enabled = 1;
8306 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
8308 add_solib_catchpoint (arg, is_load, tempflag, enabled);
8312 catch_load_command_1 (char *arg, int from_tty,
8313 struct cmd_list_element *command)
8315 catch_load_or_unload (arg, from_tty, 1, command);
8319 catch_unload_command_1 (char *arg, int from_tty,
8320 struct cmd_list_element *command)
8322 catch_load_or_unload (arg, from_tty, 0, command);
8325 /* An instance of this type is used to represent a syscall catchpoint.
8326 It includes a "struct breakpoint" as a kind of base class; users
8327 downcast to "struct breakpoint *" when needed. A breakpoint is
8328 really of this type iff its ops pointer points to
8329 CATCH_SYSCALL_BREAKPOINT_OPS. */
8331 struct syscall_catchpoint
8333 /* The base class. */
8334 struct breakpoint base;
8336 /* Syscall numbers used for the 'catch syscall' feature. If no
8337 syscall has been specified for filtering, its value is NULL.
8338 Otherwise, it holds a list of all syscalls to be caught. The
8339 list elements are allocated with xmalloc. */
8340 VEC(int) *syscalls_to_be_caught;
8343 /* Implement the "dtor" breakpoint_ops method for syscall
8347 dtor_catch_syscall (struct breakpoint *b)
8349 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
8351 VEC_free (int, c->syscalls_to_be_caught);
8353 base_breakpoint_ops.dtor (b);
8356 static const struct inferior_data *catch_syscall_inferior_data = NULL;
8358 struct catch_syscall_inferior_data
8360 /* We keep a count of the number of times the user has requested a
8361 particular syscall to be tracked, and pass this information to the
8362 target. This lets capable targets implement filtering directly. */
8364 /* Number of times that "any" syscall is requested. */
8365 int any_syscall_count;
8367 /* Count of each system call. */
8368 VEC(int) *syscalls_counts;
8370 /* This counts all syscall catch requests, so we can readily determine
8371 if any catching is necessary. */
8372 int total_syscalls_count;
8375 static struct catch_syscall_inferior_data*
8376 get_catch_syscall_inferior_data (struct inferior *inf)
8378 struct catch_syscall_inferior_data *inf_data;
8380 inf_data = inferior_data (inf, catch_syscall_inferior_data);
8381 if (inf_data == NULL)
8383 inf_data = XCNEW (struct catch_syscall_inferior_data);
8384 set_inferior_data (inf, catch_syscall_inferior_data, inf_data);
8391 catch_syscall_inferior_data_cleanup (struct inferior *inf, void *arg)
8397 /* Implement the "insert" breakpoint_ops method for syscall
8401 insert_catch_syscall (struct bp_location *bl)
8403 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner;
8404 struct inferior *inf = current_inferior ();
8405 struct catch_syscall_inferior_data *inf_data
8406 = get_catch_syscall_inferior_data (inf);
8408 ++inf_data->total_syscalls_count;
8409 if (!c->syscalls_to_be_caught)
8410 ++inf_data->any_syscall_count;
8416 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8421 if (iter >= VEC_length (int, inf_data->syscalls_counts))
8423 int old_size = VEC_length (int, inf_data->syscalls_counts);
8424 uintptr_t vec_addr_offset
8425 = old_size * ((uintptr_t) sizeof (int));
8427 VEC_safe_grow (int, inf_data->syscalls_counts, iter + 1);
8428 vec_addr = ((uintptr_t) VEC_address (int,
8429 inf_data->syscalls_counts)
8431 memset ((void *) vec_addr, 0,
8432 (iter + 1 - old_size) * sizeof (int));
8434 elem = VEC_index (int, inf_data->syscalls_counts, iter);
8435 VEC_replace (int, inf_data->syscalls_counts, iter, ++elem);
8439 return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid),
8440 inf_data->total_syscalls_count != 0,
8441 inf_data->any_syscall_count,
8443 inf_data->syscalls_counts),
8445 inf_data->syscalls_counts));
8448 /* Implement the "remove" breakpoint_ops method for syscall
8452 remove_catch_syscall (struct bp_location *bl)
8454 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner;
8455 struct inferior *inf = current_inferior ();
8456 struct catch_syscall_inferior_data *inf_data
8457 = get_catch_syscall_inferior_data (inf);
8459 --inf_data->total_syscalls_count;
8460 if (!c->syscalls_to_be_caught)
8461 --inf_data->any_syscall_count;
8467 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8471 if (iter >= VEC_length (int, inf_data->syscalls_counts))
8472 /* Shouldn't happen. */
8474 elem = VEC_index (int, inf_data->syscalls_counts, iter);
8475 VEC_replace (int, inf_data->syscalls_counts, iter, --elem);
8479 return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid),
8480 inf_data->total_syscalls_count != 0,
8481 inf_data->any_syscall_count,
8483 inf_data->syscalls_counts),
8485 inf_data->syscalls_counts));
8488 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
8492 breakpoint_hit_catch_syscall (const struct bp_location *bl,
8493 struct address_space *aspace, CORE_ADDR bp_addr,
8494 const struct target_waitstatus *ws)
8496 /* We must check if we are catching specific syscalls in this
8497 breakpoint. If we are, then we must guarantee that the called
8498 syscall is the same syscall we are catching. */
8499 int syscall_number = 0;
8500 const struct syscall_catchpoint *c
8501 = (const struct syscall_catchpoint *) bl->owner;
8503 if (ws->kind != TARGET_WAITKIND_SYSCALL_ENTRY
8504 && ws->kind != TARGET_WAITKIND_SYSCALL_RETURN)
8507 syscall_number = ws->value.syscall_number;
8509 /* Now, checking if the syscall is the same. */
8510 if (c->syscalls_to_be_caught)
8515 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8517 if (syscall_number == iter)
8526 /* Implement the "print_it" breakpoint_ops method for syscall
8529 static enum print_stop_action
8530 print_it_catch_syscall (bpstat bs)
8532 struct ui_out *uiout = current_uiout;
8533 struct breakpoint *b = bs->breakpoint_at;
8534 /* These are needed because we want to know in which state a
8535 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
8536 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
8537 must print "called syscall" or "returned from syscall". */
8539 struct target_waitstatus last;
8542 get_last_target_status (&ptid, &last);
8544 get_syscall_by_number (last.value.syscall_number, &s);
8546 annotate_catchpoint (b->number);
8548 if (b->disposition == disp_del)
8549 ui_out_text (uiout, "\nTemporary catchpoint ");
8551 ui_out_text (uiout, "\nCatchpoint ");
8552 if (ui_out_is_mi_like_p (uiout))
8554 ui_out_field_string (uiout, "reason",
8555 async_reason_lookup (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY
8556 ? EXEC_ASYNC_SYSCALL_ENTRY
8557 : EXEC_ASYNC_SYSCALL_RETURN));
8558 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8560 ui_out_field_int (uiout, "bkptno", b->number);
8562 if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY)
8563 ui_out_text (uiout, " (call to syscall ");
8565 ui_out_text (uiout, " (returned from syscall ");
8567 if (s.name == NULL || ui_out_is_mi_like_p (uiout))
8568 ui_out_field_int (uiout, "syscall-number", last.value.syscall_number);
8570 ui_out_field_string (uiout, "syscall-name", s.name);
8572 ui_out_text (uiout, "), ");
8574 return PRINT_SRC_AND_LOC;
8577 /* Implement the "print_one" breakpoint_ops method for syscall
8581 print_one_catch_syscall (struct breakpoint *b,
8582 struct bp_location **last_loc)
8584 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
8585 struct value_print_options opts;
8586 struct ui_out *uiout = current_uiout;
8588 get_user_print_options (&opts);
8589 /* Field 4, the address, is omitted (which makes the columns not
8590 line up too nicely with the headers, but the effect is relatively
8592 if (opts.addressprint)
8593 ui_out_field_skip (uiout, "addr");
8596 if (c->syscalls_to_be_caught
8597 && VEC_length (int, c->syscalls_to_be_caught) > 1)
8598 ui_out_text (uiout, "syscalls \"");
8600 ui_out_text (uiout, "syscall \"");
8602 if (c->syscalls_to_be_caught)
8605 char *text = xstrprintf ("%s", "");
8608 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8613 get_syscall_by_number (iter, &s);
8616 text = xstrprintf ("%s%s, ", text, s.name);
8618 text = xstrprintf ("%s%d, ", text, iter);
8620 /* We have to xfree the last 'text' (now stored at 'x')
8621 because xstrprintf dynamically allocates new space for it
8625 /* Remove the last comma. */
8626 text[strlen (text) - 2] = '\0';
8627 ui_out_field_string (uiout, "what", text);
8630 ui_out_field_string (uiout, "what", "<any syscall>");
8631 ui_out_text (uiout, "\" ");
8633 if (ui_out_is_mi_like_p (uiout))
8634 ui_out_field_string (uiout, "catch-type", "syscall");
8637 /* Implement the "print_mention" breakpoint_ops method for syscall
8641 print_mention_catch_syscall (struct breakpoint *b)
8643 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
8645 if (c->syscalls_to_be_caught)
8649 if (VEC_length (int, c->syscalls_to_be_caught) > 1)
8650 printf_filtered (_("Catchpoint %d (syscalls"), b->number);
8652 printf_filtered (_("Catchpoint %d (syscall"), b->number);
8655 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8659 get_syscall_by_number (iter, &s);
8662 printf_filtered (" '%s' [%d]", s.name, s.number);
8664 printf_filtered (" %d", s.number);
8666 printf_filtered (")");
8669 printf_filtered (_("Catchpoint %d (any syscall)"),
8673 /* Implement the "print_recreate" breakpoint_ops method for syscall
8677 print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp)
8679 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
8681 fprintf_unfiltered (fp, "catch syscall");
8683 if (c->syscalls_to_be_caught)
8688 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8693 get_syscall_by_number (iter, &s);
8695 fprintf_unfiltered (fp, " %s", s.name);
8697 fprintf_unfiltered (fp, " %d", s.number);
8700 print_recreate_thread (b, fp);
8703 /* The breakpoint_ops structure to be used in syscall catchpoints. */
8705 static struct breakpoint_ops catch_syscall_breakpoint_ops;
8707 /* Returns non-zero if 'b' is a syscall catchpoint. */
8710 syscall_catchpoint_p (struct breakpoint *b)
8712 return (b->ops == &catch_syscall_breakpoint_ops);
8715 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8716 is non-zero, then make the breakpoint temporary. If COND_STRING is
8717 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8718 the breakpoint_ops structure associated to the catchpoint. */
8721 init_catchpoint (struct breakpoint *b,
8722 struct gdbarch *gdbarch, int tempflag,
8724 const struct breakpoint_ops *ops)
8726 struct symtab_and_line sal;
8729 sal.pspace = current_program_space;
8731 init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops);
8733 b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string);
8734 b->disposition = tempflag ? disp_del : disp_donttouch;
8738 install_breakpoint (int internal, struct breakpoint *b, int update_gll)
8740 add_to_breakpoint_chain (b);
8741 set_breakpoint_number (internal, b);
8742 if (is_tracepoint (b))
8743 set_tracepoint_count (breakpoint_count);
8746 observer_notify_breakpoint_created (b);
8749 update_global_location_list (1);
8753 create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch,
8754 int tempflag, char *cond_string,
8755 const struct breakpoint_ops *ops)
8757 struct fork_catchpoint *c = XNEW (struct fork_catchpoint);
8759 init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops);
8761 c->forked_inferior_pid = null_ptid;
8763 install_breakpoint (0, &c->base, 1);
8766 /* Exec catchpoints. */
8768 /* An instance of this type is used to represent an exec catchpoint.
8769 It includes a "struct breakpoint" as a kind of base class; users
8770 downcast to "struct breakpoint *" when needed. A breakpoint is
8771 really of this type iff its ops pointer points to
8772 CATCH_EXEC_BREAKPOINT_OPS. */
8774 struct exec_catchpoint
8776 /* The base class. */
8777 struct breakpoint base;
8779 /* Filename of a program whose exec triggered this catchpoint.
8780 This field is only valid immediately after this catchpoint has
8782 char *exec_pathname;
8785 /* Implement the "dtor" breakpoint_ops method for exec
8789 dtor_catch_exec (struct breakpoint *b)
8791 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8793 xfree (c->exec_pathname);
8795 base_breakpoint_ops.dtor (b);
8799 insert_catch_exec (struct bp_location *bl)
8801 return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid));
8805 remove_catch_exec (struct bp_location *bl)
8807 return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid));
8811 breakpoint_hit_catch_exec (const struct bp_location *bl,
8812 struct address_space *aspace, CORE_ADDR bp_addr,
8813 const struct target_waitstatus *ws)
8815 struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner;
8817 if (ws->kind != TARGET_WAITKIND_EXECD)
8820 c->exec_pathname = xstrdup (ws->value.execd_pathname);
8824 static enum print_stop_action
8825 print_it_catch_exec (bpstat bs)
8827 struct ui_out *uiout = current_uiout;
8828 struct breakpoint *b = bs->breakpoint_at;
8829 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8831 annotate_catchpoint (b->number);
8832 if (b->disposition == disp_del)
8833 ui_out_text (uiout, "\nTemporary catchpoint ");
8835 ui_out_text (uiout, "\nCatchpoint ");
8836 if (ui_out_is_mi_like_p (uiout))
8838 ui_out_field_string (uiout, "reason",
8839 async_reason_lookup (EXEC_ASYNC_EXEC));
8840 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8842 ui_out_field_int (uiout, "bkptno", b->number);
8843 ui_out_text (uiout, " (exec'd ");
8844 ui_out_field_string (uiout, "new-exec", c->exec_pathname);
8845 ui_out_text (uiout, "), ");
8847 return PRINT_SRC_AND_LOC;
8851 print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc)
8853 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8854 struct value_print_options opts;
8855 struct ui_out *uiout = current_uiout;
8857 get_user_print_options (&opts);
8859 /* Field 4, the address, is omitted (which makes the columns
8860 not line up too nicely with the headers, but the effect
8861 is relatively readable). */
8862 if (opts.addressprint)
8863 ui_out_field_skip (uiout, "addr");
8865 ui_out_text (uiout, "exec");
8866 if (c->exec_pathname != NULL)
8868 ui_out_text (uiout, ", program \"");
8869 ui_out_field_string (uiout, "what", c->exec_pathname);
8870 ui_out_text (uiout, "\" ");
8873 if (ui_out_is_mi_like_p (uiout))
8874 ui_out_field_string (uiout, "catch-type", "exec");
8878 print_mention_catch_exec (struct breakpoint *b)
8880 printf_filtered (_("Catchpoint %d (exec)"), b->number);
8883 /* Implement the "print_recreate" breakpoint_ops method for exec
8887 print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp)
8889 fprintf_unfiltered (fp, "catch exec");
8890 print_recreate_thread (b, fp);
8893 static struct breakpoint_ops catch_exec_breakpoint_ops;
8896 create_syscall_event_catchpoint (int tempflag, VEC(int) *filter,
8897 const struct breakpoint_ops *ops)
8899 struct syscall_catchpoint *c;
8900 struct gdbarch *gdbarch = get_current_arch ();
8902 c = XNEW (struct syscall_catchpoint);
8903 init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops);
8904 c->syscalls_to_be_caught = filter;
8906 install_breakpoint (0, &c->base, 1);
8910 hw_breakpoint_used_count (void)
8913 struct breakpoint *b;
8914 struct bp_location *bl;
8918 if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b))
8919 for (bl = b->loc; bl; bl = bl->next)
8921 /* Special types of hardware breakpoints may use more than
8923 i += b->ops->resources_needed (bl);
8930 /* Returns the resources B would use if it were a hardware
8934 hw_watchpoint_use_count (struct breakpoint *b)
8937 struct bp_location *bl;
8939 if (!breakpoint_enabled (b))
8942 for (bl = b->loc; bl; bl = bl->next)
8944 /* Special types of hardware watchpoints may use more than
8946 i += b->ops->resources_needed (bl);
8952 /* Returns the sum the used resources of all hardware watchpoints of
8953 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8954 the sum of the used resources of all hardware watchpoints of other
8955 types _not_ TYPE. */
8958 hw_watchpoint_used_count_others (struct breakpoint *except,
8959 enum bptype type, int *other_type_used)
8962 struct breakpoint *b;
8964 *other_type_used = 0;
8969 if (!breakpoint_enabled (b))
8972 if (b->type == type)
8973 i += hw_watchpoint_use_count (b);
8974 else if (is_hardware_watchpoint (b))
8975 *other_type_used = 1;
8982 disable_watchpoints_before_interactive_call_start (void)
8984 struct breakpoint *b;
8988 if (is_watchpoint (b) && breakpoint_enabled (b))
8990 b->enable_state = bp_call_disabled;
8991 update_global_location_list (0);
8997 enable_watchpoints_after_interactive_call_stop (void)
8999 struct breakpoint *b;
9003 if (is_watchpoint (b) && b->enable_state == bp_call_disabled)
9005 b->enable_state = bp_enabled;
9006 update_global_location_list (1);
9012 disable_breakpoints_before_startup (void)
9014 current_program_space->executing_startup = 1;
9015 update_global_location_list (0);
9019 enable_breakpoints_after_startup (void)
9021 current_program_space->executing_startup = 0;
9022 breakpoint_re_set ();
9026 /* Set a breakpoint that will evaporate an end of command
9027 at address specified by SAL.
9028 Restrict it to frame FRAME if FRAME is nonzero. */
9031 set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal,
9032 struct frame_id frame_id, enum bptype type)
9034 struct breakpoint *b;
9036 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
9038 gdb_assert (!frame_id_artificial_p (frame_id));
9040 b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops);
9041 b->enable_state = bp_enabled;
9042 b->disposition = disp_donttouch;
9043 b->frame_id = frame_id;
9045 /* If we're debugging a multi-threaded program, then we want
9046 momentary breakpoints to be active in only a single thread of
9048 if (in_thread_list (inferior_ptid))
9049 b->thread = pid_to_thread_id (inferior_ptid);
9051 update_global_location_list_nothrow (1);
9056 /* Make a momentary breakpoint based on the master breakpoint ORIG.
9057 The new breakpoint will have type TYPE, use OPS as its
9058 breakpoint_ops, and will set enabled to LOC_ENABLED. */
9060 static struct breakpoint *
9061 momentary_breakpoint_from_master (struct breakpoint *orig,
9063 const struct breakpoint_ops *ops,
9066 struct breakpoint *copy;
9068 copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops);
9069 copy->loc = allocate_bp_location (copy);
9070 set_breakpoint_location_function (copy->loc, 1);
9072 copy->loc->gdbarch = orig->loc->gdbarch;
9073 copy->loc->requested_address = orig->loc->requested_address;
9074 copy->loc->address = orig->loc->address;
9075 copy->loc->section = orig->loc->section;
9076 copy->loc->pspace = orig->loc->pspace;
9077 copy->loc->probe = orig->loc->probe;
9078 copy->loc->line_number = orig->loc->line_number;
9079 copy->loc->symtab = orig->loc->symtab;
9080 copy->loc->enabled = loc_enabled;
9081 copy->frame_id = orig->frame_id;
9082 copy->thread = orig->thread;
9083 copy->pspace = orig->pspace;
9085 copy->enable_state = bp_enabled;
9086 copy->disposition = disp_donttouch;
9087 copy->number = internal_breakpoint_number--;
9089 update_global_location_list_nothrow (0);
9093 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
9097 clone_momentary_breakpoint (struct breakpoint *orig)
9099 /* If there's nothing to clone, then return nothing. */
9103 return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0);
9107 set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc,
9110 struct symtab_and_line sal;
9112 sal = find_pc_line (pc, 0);
9114 sal.section = find_pc_overlay (pc);
9115 sal.explicit_pc = 1;
9117 return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type);
9121 /* Tell the user we have just set a breakpoint B. */
9124 mention (struct breakpoint *b)
9126 b->ops->print_mention (b);
9127 if (ui_out_is_mi_like_p (current_uiout))
9129 printf_filtered ("\n");
9133 static struct bp_location *
9134 add_location_to_breakpoint (struct breakpoint *b,
9135 const struct symtab_and_line *sal)
9137 struct bp_location *loc, **tmp;
9138 CORE_ADDR adjusted_address;
9139 struct gdbarch *loc_gdbarch = get_sal_arch (*sal);
9141 if (loc_gdbarch == NULL)
9142 loc_gdbarch = b->gdbarch;
9144 /* Adjust the breakpoint's address prior to allocating a location.
9145 Once we call allocate_bp_location(), that mostly uninitialized
9146 location will be placed on the location chain. Adjustment of the
9147 breakpoint may cause target_read_memory() to be called and we do
9148 not want its scan of the location chain to find a breakpoint and
9149 location that's only been partially initialized. */
9150 adjusted_address = adjust_breakpoint_address (loc_gdbarch,
9153 /* Sort the locations by their ADDRESS. */
9154 loc = allocate_bp_location (b);
9155 for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address;
9156 tmp = &((*tmp)->next))
9161 loc->requested_address = sal->pc;
9162 loc->address = adjusted_address;
9163 loc->pspace = sal->pspace;
9164 loc->probe.probe = sal->probe;
9165 loc->probe.objfile = sal->objfile;
9166 gdb_assert (loc->pspace != NULL);
9167 loc->section = sal->section;
9168 loc->gdbarch = loc_gdbarch;
9169 loc->line_number = sal->line;
9170 loc->symtab = sal->symtab;
9172 set_breakpoint_location_function (loc,
9173 sal->explicit_pc || sal->explicit_line);
9178 /* Return 1 if LOC is pointing to a permanent breakpoint,
9179 return 0 otherwise. */
9182 bp_loc_is_permanent (struct bp_location *loc)
9186 const gdb_byte *bpoint;
9187 gdb_byte *target_mem;
9188 struct cleanup *cleanup;
9191 gdb_assert (loc != NULL);
9193 addr = loc->address;
9194 bpoint = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len);
9196 /* Software breakpoints unsupported? */
9200 target_mem = alloca (len);
9202 /* Enable the automatic memory restoration from breakpoints while
9203 we read the memory. Otherwise we could say about our temporary
9204 breakpoints they are permanent. */
9205 cleanup = save_current_space_and_thread ();
9207 switch_to_program_space_and_thread (loc->pspace);
9208 make_show_memory_breakpoints_cleanup (0);
9210 if (target_read_memory (loc->address, target_mem, len) == 0
9211 && memcmp (target_mem, bpoint, len) == 0)
9214 do_cleanups (cleanup);
9219 /* Build a command list for the dprintf corresponding to the current
9220 settings of the dprintf style options. */
9223 update_dprintf_command_list (struct breakpoint *b)
9225 char *dprintf_args = b->extra_string;
9226 char *printf_line = NULL;
9231 dprintf_args = skip_spaces (dprintf_args);
9233 /* Allow a comma, as it may have terminated a location, but don't
9235 if (*dprintf_args == ',')
9237 dprintf_args = skip_spaces (dprintf_args);
9239 if (*dprintf_args != '"')
9240 error (_("Bad format string, missing '\"'."));
9242 if (strcmp (dprintf_style, dprintf_style_gdb) == 0)
9243 printf_line = xstrprintf ("printf %s", dprintf_args);
9244 else if (strcmp (dprintf_style, dprintf_style_call) == 0)
9246 if (!dprintf_function)
9247 error (_("No function supplied for dprintf call"));
9249 if (dprintf_channel && strlen (dprintf_channel) > 0)
9250 printf_line = xstrprintf ("call (void) %s (%s,%s)",
9255 printf_line = xstrprintf ("call (void) %s (%s)",
9259 else if (strcmp (dprintf_style, dprintf_style_agent) == 0)
9261 if (target_can_run_breakpoint_commands ())
9262 printf_line = xstrprintf ("agent-printf %s", dprintf_args);
9265 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
9266 printf_line = xstrprintf ("printf %s", dprintf_args);
9270 internal_error (__FILE__, __LINE__,
9271 _("Invalid dprintf style."));
9273 gdb_assert (printf_line != NULL);
9274 /* Manufacture a printf sequence. */
9276 struct command_line *printf_cmd_line
9277 = xmalloc (sizeof (struct command_line));
9279 printf_cmd_line = xmalloc (sizeof (struct command_line));
9280 printf_cmd_line->control_type = simple_control;
9281 printf_cmd_line->body_count = 0;
9282 printf_cmd_line->body_list = NULL;
9283 printf_cmd_line->next = NULL;
9284 printf_cmd_line->line = printf_line;
9286 breakpoint_set_commands (b, printf_cmd_line);
9290 /* Update all dprintf commands, making their command lists reflect
9291 current style settings. */
9294 update_dprintf_commands (char *args, int from_tty,
9295 struct cmd_list_element *c)
9297 struct breakpoint *b;
9301 if (b->type == bp_dprintf)
9302 update_dprintf_command_list (b);
9306 /* Create a breakpoint with SAL as location. Use ADDR_STRING
9307 as textual description of the location, and COND_STRING
9308 as condition expression. */
9311 init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch,
9312 struct symtabs_and_lines sals, char *addr_string,
9313 char *filter, char *cond_string,
9315 enum bptype type, enum bpdisp disposition,
9316 int thread, int task, int ignore_count,
9317 const struct breakpoint_ops *ops, int from_tty,
9318 int enabled, int internal, unsigned flags,
9319 int display_canonical)
9323 if (type == bp_hardware_breakpoint)
9325 int target_resources_ok;
9327 i = hw_breakpoint_used_count ();
9328 target_resources_ok =
9329 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
9331 if (target_resources_ok == 0)
9332 error (_("No hardware breakpoint support in the target."));
9333 else if (target_resources_ok < 0)
9334 error (_("Hardware breakpoints used exceeds limit."));
9337 gdb_assert (sals.nelts > 0);
9339 for (i = 0; i < sals.nelts; ++i)
9341 struct symtab_and_line sal = sals.sals[i];
9342 struct bp_location *loc;
9346 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
9348 loc_gdbarch = gdbarch;
9350 describe_other_breakpoints (loc_gdbarch,
9351 sal.pspace, sal.pc, sal.section, thread);
9356 init_raw_breakpoint (b, gdbarch, sal, type, ops);
9360 b->cond_string = cond_string;
9361 b->extra_string = extra_string;
9362 b->ignore_count = ignore_count;
9363 b->enable_state = enabled ? bp_enabled : bp_disabled;
9364 b->disposition = disposition;
9366 if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
9367 b->loc->inserted = 1;
9369 if (type == bp_static_tracepoint)
9371 struct tracepoint *t = (struct tracepoint *) b;
9372 struct static_tracepoint_marker marker;
9374 if (strace_marker_p (b))
9376 /* We already know the marker exists, otherwise, we
9377 wouldn't see a sal for it. */
9378 char *p = &addr_string[3];
9382 p = skip_spaces (p);
9384 endp = skip_to_space (p);
9386 marker_str = savestring (p, endp - p);
9387 t->static_trace_marker_id = marker_str;
9389 printf_filtered (_("Probed static tracepoint "
9391 t->static_trace_marker_id);
9393 else if (target_static_tracepoint_marker_at (sal.pc, &marker))
9395 t->static_trace_marker_id = xstrdup (marker.str_id);
9396 release_static_tracepoint_marker (&marker);
9398 printf_filtered (_("Probed static tracepoint "
9400 t->static_trace_marker_id);
9403 warning (_("Couldn't determine the static "
9404 "tracepoint marker to probe"));
9411 loc = add_location_to_breakpoint (b, &sal);
9412 if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
9416 if (bp_loc_is_permanent (loc))
9417 make_breakpoint_permanent (b);
9421 const char *arg = b->cond_string;
9423 loc->cond = parse_exp_1 (&arg, loc->address,
9424 block_for_pc (loc->address), 0);
9426 error (_("Garbage '%s' follows condition"), arg);
9429 /* Dynamic printf requires and uses additional arguments on the
9430 command line, otherwise it's an error. */
9431 if (type == bp_dprintf)
9433 if (b->extra_string)
9434 update_dprintf_command_list (b);
9436 error (_("Format string required"));
9438 else if (b->extra_string)
9439 error (_("Garbage '%s' at end of command"), b->extra_string);
9442 b->display_canonical = display_canonical;
9444 b->addr_string = addr_string;
9446 /* addr_string has to be used or breakpoint_re_set will delete
9449 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
9454 create_breakpoint_sal (struct gdbarch *gdbarch,
9455 struct symtabs_and_lines sals, char *addr_string,
9456 char *filter, char *cond_string,
9458 enum bptype type, enum bpdisp disposition,
9459 int thread, int task, int ignore_count,
9460 const struct breakpoint_ops *ops, int from_tty,
9461 int enabled, int internal, unsigned flags,
9462 int display_canonical)
9464 struct breakpoint *b;
9465 struct cleanup *old_chain;
9467 if (is_tracepoint_type (type))
9469 struct tracepoint *t;
9471 t = XCNEW (struct tracepoint);
9475 b = XNEW (struct breakpoint);
9477 old_chain = make_cleanup (xfree, b);
9479 init_breakpoint_sal (b, gdbarch,
9481 filter, cond_string, extra_string,
9483 thread, task, ignore_count,
9485 enabled, internal, flags,
9487 discard_cleanups (old_chain);
9489 install_breakpoint (internal, b, 0);
9492 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9493 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9494 value. COND_STRING, if not NULL, specified the condition to be
9495 used for all breakpoints. Essentially the only case where
9496 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9497 function. In that case, it's still not possible to specify
9498 separate conditions for different overloaded functions, so
9499 we take just a single condition string.
9501 NOTE: If the function succeeds, the caller is expected to cleanup
9502 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9503 array contents). If the function fails (error() is called), the
9504 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9505 COND and SALS arrays and each of those arrays contents. */
9508 create_breakpoints_sal (struct gdbarch *gdbarch,
9509 struct linespec_result *canonical,
9510 char *cond_string, char *extra_string,
9511 enum bptype type, enum bpdisp disposition,
9512 int thread, int task, int ignore_count,
9513 const struct breakpoint_ops *ops, int from_tty,
9514 int enabled, int internal, unsigned flags)
9517 struct linespec_sals *lsal;
9519 if (canonical->pre_expanded)
9520 gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1);
9522 for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i)
9524 /* Note that 'addr_string' can be NULL in the case of a plain
9525 'break', without arguments. */
9526 char *addr_string = (canonical->addr_string
9527 ? xstrdup (canonical->addr_string)
9529 char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL;
9530 struct cleanup *inner = make_cleanup (xfree, addr_string);
9532 make_cleanup (xfree, filter_string);
9533 create_breakpoint_sal (gdbarch, lsal->sals,
9536 cond_string, extra_string,
9538 thread, task, ignore_count, ops,
9539 from_tty, enabled, internal, flags,
9540 canonical->special_display);
9541 discard_cleanups (inner);
9545 /* Parse ADDRESS which is assumed to be a SAL specification possibly
9546 followed by conditionals. On return, SALS contains an array of SAL
9547 addresses found. ADDR_STRING contains a vector of (canonical)
9548 address strings. ADDRESS points to the end of the SAL.
9550 The array and the line spec strings are allocated on the heap, it is
9551 the caller's responsibility to free them. */
9554 parse_breakpoint_sals (char **address,
9555 struct linespec_result *canonical)
9557 /* If no arg given, or if first arg is 'if ', use the default
9559 if ((*address) == NULL
9560 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
9562 /* The last displayed codepoint, if it's valid, is our default breakpoint
9564 if (last_displayed_sal_is_valid ())
9566 struct linespec_sals lsal;
9567 struct symtab_and_line sal;
9570 init_sal (&sal); /* Initialize to zeroes. */
9571 lsal.sals.sals = (struct symtab_and_line *)
9572 xmalloc (sizeof (struct symtab_and_line));
9574 /* Set sal's pspace, pc, symtab, and line to the values
9575 corresponding to the last call to print_frame_info.
9576 Be sure to reinitialize LINE with NOTCURRENT == 0
9577 as the breakpoint line number is inappropriate otherwise.
9578 find_pc_line would adjust PC, re-set it back. */
9579 get_last_displayed_sal (&sal);
9581 sal = find_pc_line (pc, 0);
9583 /* "break" without arguments is equivalent to "break *PC"
9584 where PC is the last displayed codepoint's address. So
9585 make sure to set sal.explicit_pc to prevent GDB from
9586 trying to expand the list of sals to include all other
9587 instances with the same symtab and line. */
9589 sal.explicit_pc = 1;
9591 lsal.sals.sals[0] = sal;
9592 lsal.sals.nelts = 1;
9593 lsal.canonical = NULL;
9595 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
9598 error (_("No default breakpoint address now."));
9602 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
9604 /* Force almost all breakpoints to be in terms of the
9605 current_source_symtab (which is decode_line_1's default).
9606 This should produce the results we want almost all of the
9607 time while leaving default_breakpoint_* alone.
9609 ObjC: However, don't match an Objective-C method name which
9610 may have a '+' or '-' succeeded by a '['. */
9611 if (last_displayed_sal_is_valid ()
9613 || ((strchr ("+-", (*address)[0]) != NULL)
9614 && ((*address)[1] != '['))))
9615 decode_line_full (address, DECODE_LINE_FUNFIRSTLINE,
9616 get_last_displayed_symtab (),
9617 get_last_displayed_line (),
9618 canonical, NULL, NULL);
9620 decode_line_full (address, DECODE_LINE_FUNFIRSTLINE,
9621 cursal.symtab, cursal.line, canonical, NULL, NULL);
9626 /* Convert each SAL into a real PC. Verify that the PC can be
9627 inserted as a breakpoint. If it can't throw an error. */
9630 breakpoint_sals_to_pc (struct symtabs_and_lines *sals)
9634 for (i = 0; i < sals->nelts; i++)
9635 resolve_sal_pc (&sals->sals[i]);
9638 /* Fast tracepoints may have restrictions on valid locations. For
9639 instance, a fast tracepoint using a jump instead of a trap will
9640 likely have to overwrite more bytes than a trap would, and so can
9641 only be placed where the instruction is longer than the jump, or a
9642 multi-instruction sequence does not have a jump into the middle of
9646 check_fast_tracepoint_sals (struct gdbarch *gdbarch,
9647 struct symtabs_and_lines *sals)
9650 struct symtab_and_line *sal;
9652 struct cleanup *old_chain;
9654 for (i = 0; i < sals->nelts; i++)
9656 struct gdbarch *sarch;
9658 sal = &sals->sals[i];
9660 sarch = get_sal_arch (*sal);
9661 /* We fall back to GDBARCH if there is no architecture
9662 associated with SAL. */
9665 rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc,
9667 old_chain = make_cleanup (xfree, msg);
9670 error (_("May not have a fast tracepoint at 0x%s%s"),
9671 paddress (sarch, sal->pc), (msg ? msg : ""));
9673 do_cleanups (old_chain);
9677 /* Issue an invalid thread ID error. */
9679 static void ATTRIBUTE_NORETURN
9680 invalid_thread_id_error (int id)
9682 error (_("Unknown thread %d."), id);
9685 /* Given TOK, a string specification of condition and thread, as
9686 accepted by the 'break' command, extract the condition
9687 string and thread number and set *COND_STRING and *THREAD.
9688 PC identifies the context at which the condition should be parsed.
9689 If no condition is found, *COND_STRING is set to NULL.
9690 If no thread is found, *THREAD is set to -1. */
9693 find_condition_and_thread (const char *tok, CORE_ADDR pc,
9694 char **cond_string, int *thread, int *task,
9697 *cond_string = NULL;
9704 const char *end_tok;
9706 const char *cond_start = NULL;
9707 const char *cond_end = NULL;
9709 tok = skip_spaces_const (tok);
9711 if ((*tok == '"' || *tok == ',') && rest)
9713 *rest = savestring (tok, strlen (tok));
9717 end_tok = skip_to_space_const (tok);
9719 toklen = end_tok - tok;
9721 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
9723 struct expression *expr;
9725 tok = cond_start = end_tok + 1;
9726 expr = parse_exp_1 (&tok, pc, block_for_pc (pc), 0);
9729 *cond_string = savestring (cond_start, cond_end - cond_start);
9731 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
9736 *thread = strtol (tok, &tmptok, 0);
9738 error (_("Junk after thread keyword."));
9739 if (!valid_thread_id (*thread))
9740 invalid_thread_id_error (*thread);
9743 else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0)
9748 *task = strtol (tok, &tmptok, 0);
9750 error (_("Junk after task keyword."));
9751 if (!valid_task_id (*task))
9752 error (_("Unknown task %d."), *task);
9757 *rest = savestring (tok, strlen (tok));
9761 error (_("Junk at end of arguments."));
9765 /* Decode a static tracepoint marker spec. */
9767 static struct symtabs_and_lines
9768 decode_static_tracepoint_spec (char **arg_p)
9770 VEC(static_tracepoint_marker_p) *markers = NULL;
9771 struct symtabs_and_lines sals;
9772 struct cleanup *old_chain;
9773 char *p = &(*arg_p)[3];
9778 p = skip_spaces (p);
9780 endp = skip_to_space (p);
9782 marker_str = savestring (p, endp - p);
9783 old_chain = make_cleanup (xfree, marker_str);
9785 markers = target_static_tracepoint_markers_by_strid (marker_str);
9786 if (VEC_empty(static_tracepoint_marker_p, markers))
9787 error (_("No known static tracepoint marker named %s"), marker_str);
9789 sals.nelts = VEC_length(static_tracepoint_marker_p, markers);
9790 sals.sals = xmalloc (sizeof *sals.sals * sals.nelts);
9792 for (i = 0; i < sals.nelts; i++)
9794 struct static_tracepoint_marker *marker;
9796 marker = VEC_index (static_tracepoint_marker_p, markers, i);
9798 init_sal (&sals.sals[i]);
9800 sals.sals[i] = find_pc_line (marker->address, 0);
9801 sals.sals[i].pc = marker->address;
9803 release_static_tracepoint_marker (marker);
9806 do_cleanups (old_chain);
9812 /* Set a breakpoint. This function is shared between CLI and MI
9813 functions for setting a breakpoint. This function has two major
9814 modes of operations, selected by the PARSE_ARG parameter. If
9815 non-zero, the function will parse ARG, extracting location,
9816 condition, thread and extra string. Otherwise, ARG is just the
9817 breakpoint's location, with condition, thread, and extra string
9818 specified by the COND_STRING, THREAD and EXTRA_STRING parameters.
9819 If INTERNAL is non-zero, the breakpoint number will be allocated
9820 from the internal breakpoint count. Returns true if any breakpoint
9821 was created; false otherwise. */
9824 create_breakpoint (struct gdbarch *gdbarch,
9825 char *arg, char *cond_string,
9826 int thread, char *extra_string,
9828 int tempflag, enum bptype type_wanted,
9830 enum auto_boolean pending_break_support,
9831 const struct breakpoint_ops *ops,
9832 int from_tty, int enabled, int internal,
9835 volatile struct gdb_exception e;
9836 char *copy_arg = NULL;
9837 char *addr_start = arg;
9838 struct linespec_result canonical;
9839 struct cleanup *old_chain;
9840 struct cleanup *bkpt_chain = NULL;
9843 int prev_bkpt_count = breakpoint_count;
9845 gdb_assert (ops != NULL);
9847 init_linespec_result (&canonical);
9849 TRY_CATCH (e, RETURN_MASK_ALL)
9851 ops->create_sals_from_address (&arg, &canonical, type_wanted,
9852 addr_start, ©_arg);
9855 /* If caller is interested in rc value from parse, set value. */
9859 if (VEC_empty (linespec_sals, canonical.sals))
9865 case NOT_FOUND_ERROR:
9867 /* If pending breakpoint support is turned off, throw
9870 if (pending_break_support == AUTO_BOOLEAN_FALSE)
9871 throw_exception (e);
9873 exception_print (gdb_stderr, e);
9875 /* If pending breakpoint support is auto query and the user
9876 selects no, then simply return the error code. */
9877 if (pending_break_support == AUTO_BOOLEAN_AUTO
9878 && !nquery (_("Make %s pending on future shared library load? "),
9879 bptype_string (type_wanted)))
9882 /* At this point, either the user was queried about setting
9883 a pending breakpoint and selected yes, or pending
9884 breakpoint behavior is on and thus a pending breakpoint
9885 is defaulted on behalf of the user. */
9887 struct linespec_sals lsal;
9889 copy_arg = xstrdup (addr_start);
9890 lsal.canonical = xstrdup (copy_arg);
9891 lsal.sals.nelts = 1;
9892 lsal.sals.sals = XNEW (struct symtab_and_line);
9893 init_sal (&lsal.sals.sals[0]);
9895 VEC_safe_push (linespec_sals, canonical.sals, &lsal);
9899 throw_exception (e);
9903 throw_exception (e);
9906 /* Create a chain of things that always need to be cleaned up. */
9907 old_chain = make_cleanup_destroy_linespec_result (&canonical);
9909 /* ----------------------------- SNIP -----------------------------
9910 Anything added to the cleanup chain beyond this point is assumed
9911 to be part of a breakpoint. If the breakpoint create succeeds
9912 then the memory is not reclaimed. */
9913 bkpt_chain = make_cleanup (null_cleanup, 0);
9915 /* Resolve all line numbers to PC's and verify that the addresses
9916 are ok for the target. */
9920 struct linespec_sals *iter;
9922 for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
9923 breakpoint_sals_to_pc (&iter->sals);
9926 /* Fast tracepoints may have additional restrictions on location. */
9927 if (!pending && type_wanted == bp_fast_tracepoint)
9930 struct linespec_sals *iter;
9932 for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
9933 check_fast_tracepoint_sals (gdbarch, &iter->sals);
9936 /* Verify that condition can be parsed, before setting any
9937 breakpoints. Allocate a separate condition expression for each
9944 struct linespec_sals *lsal;
9946 lsal = VEC_index (linespec_sals, canonical.sals, 0);
9948 /* Here we only parse 'arg' to separate condition
9949 from thread number, so parsing in context of first
9950 sal is OK. When setting the breakpoint we'll
9951 re-parse it in context of each sal. */
9953 find_condition_and_thread (arg, lsal->sals.sals[0].pc, &cond_string,
9954 &thread, &task, &rest);
9956 make_cleanup (xfree, cond_string);
9958 make_cleanup (xfree, rest);
9960 extra_string = rest;
9965 error (_("Garbage '%s' at end of location"), arg);
9967 /* Create a private copy of condition string. */
9970 cond_string = xstrdup (cond_string);
9971 make_cleanup (xfree, cond_string);
9973 /* Create a private copy of any extra string. */
9976 extra_string = xstrdup (extra_string);
9977 make_cleanup (xfree, extra_string);
9981 ops->create_breakpoints_sal (gdbarch, &canonical,
9982 cond_string, extra_string, type_wanted,
9983 tempflag ? disp_del : disp_donttouch,
9984 thread, task, ignore_count, ops,
9985 from_tty, enabled, internal, flags);
9989 struct breakpoint *b;
9991 make_cleanup (xfree, copy_arg);
9993 if (is_tracepoint_type (type_wanted))
9995 struct tracepoint *t;
9997 t = XCNEW (struct tracepoint);
10001 b = XNEW (struct breakpoint);
10003 init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops);
10005 b->addr_string = copy_arg;
10007 b->cond_string = NULL;
10010 /* Create a private copy of condition string. */
10013 cond_string = xstrdup (cond_string);
10014 make_cleanup (xfree, cond_string);
10016 b->cond_string = cond_string;
10018 b->extra_string = NULL;
10019 b->ignore_count = ignore_count;
10020 b->disposition = tempflag ? disp_del : disp_donttouch;
10021 b->condition_not_parsed = 1;
10022 b->enable_state = enabled ? bp_enabled : bp_disabled;
10023 if ((type_wanted != bp_breakpoint
10024 && type_wanted != bp_hardware_breakpoint) || thread != -1)
10025 b->pspace = current_program_space;
10027 install_breakpoint (internal, b, 0);
10030 if (VEC_length (linespec_sals, canonical.sals) > 1)
10032 warning (_("Multiple breakpoints were set.\nUse the "
10033 "\"delete\" command to delete unwanted breakpoints."));
10034 prev_breakpoint_count = prev_bkpt_count;
10037 /* That's it. Discard the cleanups for data inserted into the
10039 discard_cleanups (bkpt_chain);
10040 /* But cleanup everything else. */
10041 do_cleanups (old_chain);
10043 /* error call may happen here - have BKPT_CHAIN already discarded. */
10044 update_global_location_list (1);
10049 /* Set a breakpoint.
10050 ARG is a string describing breakpoint address,
10051 condition, and thread.
10052 FLAG specifies if a breakpoint is hardware on,
10053 and if breakpoint is temporary, using BP_HARDWARE_FLAG
10054 and BP_TEMPFLAG. */
10057 break_command_1 (char *arg, int flag, int from_tty)
10059 int tempflag = flag & BP_TEMPFLAG;
10060 enum bptype type_wanted = (flag & BP_HARDWAREFLAG
10061 ? bp_hardware_breakpoint
10063 struct breakpoint_ops *ops;
10064 const char *arg_cp = arg;
10066 /* Matching breakpoints on probes. */
10067 if (arg && probe_linespec_to_ops (&arg_cp) != NULL)
10068 ops = &bkpt_probe_breakpoint_ops;
10070 ops = &bkpt_breakpoint_ops;
10072 create_breakpoint (get_current_arch (),
10074 NULL, 0, NULL, 1 /* parse arg */,
10075 tempflag, type_wanted,
10076 0 /* Ignore count */,
10077 pending_break_support,
10085 /* Helper function for break_command_1 and disassemble_command. */
10088 resolve_sal_pc (struct symtab_and_line *sal)
10092 if (sal->pc == 0 && sal->symtab != NULL)
10094 if (!find_line_pc (sal->symtab, sal->line, &pc))
10095 error (_("No line %d in file \"%s\"."),
10096 sal->line, symtab_to_filename_for_display (sal->symtab));
10099 /* If this SAL corresponds to a breakpoint inserted using a line
10100 number, then skip the function prologue if necessary. */
10101 if (sal->explicit_line)
10102 skip_prologue_sal (sal);
10105 if (sal->section == 0 && sal->symtab != NULL)
10107 const struct blockvector *bv;
10108 const struct block *b;
10109 struct symbol *sym;
10111 bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab);
10114 sym = block_linkage_function (b);
10117 fixup_symbol_section (sym, sal->symtab->objfile);
10118 sal->section = SYMBOL_OBJ_SECTION (sal->symtab->objfile, sym);
10122 /* It really is worthwhile to have the section, so we'll
10123 just have to look harder. This case can be executed
10124 if we have line numbers but no functions (as can
10125 happen in assembly source). */
10127 struct bound_minimal_symbol msym;
10128 struct cleanup *old_chain = save_current_space_and_thread ();
10130 switch_to_program_space_and_thread (sal->pspace);
10132 msym = lookup_minimal_symbol_by_pc (sal->pc);
10134 sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym);
10136 do_cleanups (old_chain);
10143 break_command (char *arg, int from_tty)
10145 break_command_1 (arg, 0, from_tty);
10149 tbreak_command (char *arg, int from_tty)
10151 break_command_1 (arg, BP_TEMPFLAG, from_tty);
10155 hbreak_command (char *arg, int from_tty)
10157 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
10161 thbreak_command (char *arg, int from_tty)
10163 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
10167 stop_command (char *arg, int from_tty)
10169 printf_filtered (_("Specify the type of breakpoint to set.\n\
10170 Usage: stop in <function | address>\n\
10171 stop at <line>\n"));
10175 stopin_command (char *arg, int from_tty)
10179 if (arg == (char *) NULL)
10181 else if (*arg != '*')
10183 char *argptr = arg;
10186 /* Look for a ':'. If this is a line number specification, then
10187 say it is bad, otherwise, it should be an address or
10188 function/method name. */
10189 while (*argptr && !hasColon)
10191 hasColon = (*argptr == ':');
10196 badInput = (*argptr != ':'); /* Not a class::method */
10198 badInput = isdigit (*arg); /* a simple line number */
10202 printf_filtered (_("Usage: stop in <function | address>\n"));
10204 break_command_1 (arg, 0, from_tty);
10208 stopat_command (char *arg, int from_tty)
10212 if (arg == (char *) NULL || *arg == '*') /* no line number */
10216 char *argptr = arg;
10219 /* Look for a ':'. If there is a '::' then get out, otherwise
10220 it is probably a line number. */
10221 while (*argptr && !hasColon)
10223 hasColon = (*argptr == ':');
10228 badInput = (*argptr == ':'); /* we have class::method */
10230 badInput = !isdigit (*arg); /* not a line number */
10234 printf_filtered (_("Usage: stop at <line>\n"));
10236 break_command_1 (arg, 0, from_tty);
10239 /* The dynamic printf command is mostly like a regular breakpoint, but
10240 with a prewired command list consisting of a single output command,
10241 built from extra arguments supplied on the dprintf command
10245 dprintf_command (char *arg, int from_tty)
10247 create_breakpoint (get_current_arch (),
10249 NULL, 0, NULL, 1 /* parse arg */,
10251 0 /* Ignore count */,
10252 pending_break_support,
10253 &dprintf_breakpoint_ops,
10261 agent_printf_command (char *arg, int from_tty)
10263 error (_("May only run agent-printf on the target"));
10266 /* Implement the "breakpoint_hit" breakpoint_ops method for
10267 ranged breakpoints. */
10270 breakpoint_hit_ranged_breakpoint (const struct bp_location *bl,
10271 struct address_space *aspace,
10273 const struct target_waitstatus *ws)
10275 if (ws->kind != TARGET_WAITKIND_STOPPED
10276 || ws->value.sig != GDB_SIGNAL_TRAP)
10279 return breakpoint_address_match_range (bl->pspace->aspace, bl->address,
10280 bl->length, aspace, bp_addr);
10283 /* Implement the "resources_needed" breakpoint_ops method for
10284 ranged breakpoints. */
10287 resources_needed_ranged_breakpoint (const struct bp_location *bl)
10289 return target_ranged_break_num_registers ();
10292 /* Implement the "print_it" breakpoint_ops method for
10293 ranged breakpoints. */
10295 static enum print_stop_action
10296 print_it_ranged_breakpoint (bpstat bs)
10298 struct breakpoint *b = bs->breakpoint_at;
10299 struct bp_location *bl = b->loc;
10300 struct ui_out *uiout = current_uiout;
10302 gdb_assert (b->type == bp_hardware_breakpoint);
10304 /* Ranged breakpoints have only one location. */
10305 gdb_assert (bl && bl->next == NULL);
10307 annotate_breakpoint (b->number);
10308 if (b->disposition == disp_del)
10309 ui_out_text (uiout, "\nTemporary ranged breakpoint ");
10311 ui_out_text (uiout, "\nRanged breakpoint ");
10312 if (ui_out_is_mi_like_p (uiout))
10314 ui_out_field_string (uiout, "reason",
10315 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
10316 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
10318 ui_out_field_int (uiout, "bkptno", b->number);
10319 ui_out_text (uiout, ", ");
10321 return PRINT_SRC_AND_LOC;
10324 /* Implement the "print_one" breakpoint_ops method for
10325 ranged breakpoints. */
10328 print_one_ranged_breakpoint (struct breakpoint *b,
10329 struct bp_location **last_loc)
10331 struct bp_location *bl = b->loc;
10332 struct value_print_options opts;
10333 struct ui_out *uiout = current_uiout;
10335 /* Ranged breakpoints have only one location. */
10336 gdb_assert (bl && bl->next == NULL);
10338 get_user_print_options (&opts);
10340 if (opts.addressprint)
10341 /* We don't print the address range here, it will be printed later
10342 by print_one_detail_ranged_breakpoint. */
10343 ui_out_field_skip (uiout, "addr");
10344 annotate_field (5);
10345 print_breakpoint_location (b, bl);
10349 /* Implement the "print_one_detail" breakpoint_ops method for
10350 ranged breakpoints. */
10353 print_one_detail_ranged_breakpoint (const struct breakpoint *b,
10354 struct ui_out *uiout)
10356 CORE_ADDR address_start, address_end;
10357 struct bp_location *bl = b->loc;
10358 struct ui_file *stb = mem_fileopen ();
10359 struct cleanup *cleanup = make_cleanup_ui_file_delete (stb);
10363 address_start = bl->address;
10364 address_end = address_start + bl->length - 1;
10366 ui_out_text (uiout, "\taddress range: ");
10367 fprintf_unfiltered (stb, "[%s, %s]",
10368 print_core_address (bl->gdbarch, address_start),
10369 print_core_address (bl->gdbarch, address_end));
10370 ui_out_field_stream (uiout, "addr", stb);
10371 ui_out_text (uiout, "\n");
10373 do_cleanups (cleanup);
10376 /* Implement the "print_mention" breakpoint_ops method for
10377 ranged breakpoints. */
10380 print_mention_ranged_breakpoint (struct breakpoint *b)
10382 struct bp_location *bl = b->loc;
10383 struct ui_out *uiout = current_uiout;
10386 gdb_assert (b->type == bp_hardware_breakpoint);
10388 if (ui_out_is_mi_like_p (uiout))
10391 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
10392 b->number, paddress (bl->gdbarch, bl->address),
10393 paddress (bl->gdbarch, bl->address + bl->length - 1));
10396 /* Implement the "print_recreate" breakpoint_ops method for
10397 ranged breakpoints. */
10400 print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp)
10402 fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string,
10403 b->addr_string_range_end);
10404 print_recreate_thread (b, fp);
10407 /* The breakpoint_ops structure to be used in ranged breakpoints. */
10409 static struct breakpoint_ops ranged_breakpoint_ops;
10411 /* Find the address where the end of the breakpoint range should be
10412 placed, given the SAL of the end of the range. This is so that if
10413 the user provides a line number, the end of the range is set to the
10414 last instruction of the given line. */
10417 find_breakpoint_range_end (struct symtab_and_line sal)
10421 /* If the user provided a PC value, use it. Otherwise,
10422 find the address of the end of the given location. */
10423 if (sal.explicit_pc)
10430 ret = find_line_pc_range (sal, &start, &end);
10432 error (_("Could not find location of the end of the range."));
10434 /* find_line_pc_range returns the start of the next line. */
10441 /* Implement the "break-range" CLI command. */
10444 break_range_command (char *arg, int from_tty)
10446 char *arg_start, *addr_string_start, *addr_string_end;
10447 struct linespec_result canonical_start, canonical_end;
10448 int bp_count, can_use_bp, length;
10450 struct breakpoint *b;
10451 struct symtab_and_line sal_start, sal_end;
10452 struct cleanup *cleanup_bkpt;
10453 struct linespec_sals *lsal_start, *lsal_end;
10455 /* We don't support software ranged breakpoints. */
10456 if (target_ranged_break_num_registers () < 0)
10457 error (_("This target does not support hardware ranged breakpoints."));
10459 bp_count = hw_breakpoint_used_count ();
10460 bp_count += target_ranged_break_num_registers ();
10461 can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
10463 if (can_use_bp < 0)
10464 error (_("Hardware breakpoints used exceeds limit."));
10466 arg = skip_spaces (arg);
10467 if (arg == NULL || arg[0] == '\0')
10468 error(_("No address range specified."));
10470 init_linespec_result (&canonical_start);
10473 parse_breakpoint_sals (&arg, &canonical_start);
10475 cleanup_bkpt = make_cleanup_destroy_linespec_result (&canonical_start);
10478 error (_("Too few arguments."));
10479 else if (VEC_empty (linespec_sals, canonical_start.sals))
10480 error (_("Could not find location of the beginning of the range."));
10482 lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0);
10484 if (VEC_length (linespec_sals, canonical_start.sals) > 1
10485 || lsal_start->sals.nelts != 1)
10486 error (_("Cannot create a ranged breakpoint with multiple locations."));
10488 sal_start = lsal_start->sals.sals[0];
10489 addr_string_start = savestring (arg_start, arg - arg_start);
10490 make_cleanup (xfree, addr_string_start);
10492 arg++; /* Skip the comma. */
10493 arg = skip_spaces (arg);
10495 /* Parse the end location. */
10497 init_linespec_result (&canonical_end);
10500 /* We call decode_line_full directly here instead of using
10501 parse_breakpoint_sals because we need to specify the start location's
10502 symtab and line as the default symtab and line for the end of the
10503 range. This makes it possible to have ranges like "foo.c:27, +14",
10504 where +14 means 14 lines from the start location. */
10505 decode_line_full (&arg, DECODE_LINE_FUNFIRSTLINE,
10506 sal_start.symtab, sal_start.line,
10507 &canonical_end, NULL, NULL);
10509 make_cleanup_destroy_linespec_result (&canonical_end);
10511 if (VEC_empty (linespec_sals, canonical_end.sals))
10512 error (_("Could not find location of the end of the range."));
10514 lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0);
10515 if (VEC_length (linespec_sals, canonical_end.sals) > 1
10516 || lsal_end->sals.nelts != 1)
10517 error (_("Cannot create a ranged breakpoint with multiple locations."));
10519 sal_end = lsal_end->sals.sals[0];
10520 addr_string_end = savestring (arg_start, arg - arg_start);
10521 make_cleanup (xfree, addr_string_end);
10523 end = find_breakpoint_range_end (sal_end);
10524 if (sal_start.pc > end)
10525 error (_("Invalid address range, end precedes start."));
10527 length = end - sal_start.pc + 1;
10529 /* Length overflowed. */
10530 error (_("Address range too large."));
10531 else if (length == 1)
10533 /* This range is simple enough to be handled by
10534 the `hbreak' command. */
10535 hbreak_command (addr_string_start, 1);
10537 do_cleanups (cleanup_bkpt);
10542 /* Now set up the breakpoint. */
10543 b = set_raw_breakpoint (get_current_arch (), sal_start,
10544 bp_hardware_breakpoint, &ranged_breakpoint_ops);
10545 set_breakpoint_count (breakpoint_count + 1);
10546 b->number = breakpoint_count;
10547 b->disposition = disp_donttouch;
10548 b->addr_string = xstrdup (addr_string_start);
10549 b->addr_string_range_end = xstrdup (addr_string_end);
10550 b->loc->length = length;
10552 do_cleanups (cleanup_bkpt);
10555 observer_notify_breakpoint_created (b);
10556 update_global_location_list (1);
10559 /* Return non-zero if EXP is verified as constant. Returned zero
10560 means EXP is variable. Also the constant detection may fail for
10561 some constant expressions and in such case still falsely return
10565 watchpoint_exp_is_const (const struct expression *exp)
10567 int i = exp->nelts;
10573 /* We are only interested in the descriptor of each element. */
10574 operator_length (exp, i, &oplenp, &argsp);
10577 switch (exp->elts[i].opcode)
10587 case BINOP_LOGICAL_AND:
10588 case BINOP_LOGICAL_OR:
10589 case BINOP_BITWISE_AND:
10590 case BINOP_BITWISE_IOR:
10591 case BINOP_BITWISE_XOR:
10593 case BINOP_NOTEQUAL:
10621 case OP_OBJC_NSSTRING:
10624 case UNOP_LOGICAL_NOT:
10625 case UNOP_COMPLEMENT:
10630 case UNOP_CAST_TYPE:
10631 case UNOP_REINTERPRET_CAST:
10632 case UNOP_DYNAMIC_CAST:
10633 /* Unary, binary and ternary operators: We have to check
10634 their operands. If they are constant, then so is the
10635 result of that operation. For instance, if A and B are
10636 determined to be constants, then so is "A + B".
10638 UNOP_IND is one exception to the rule above, because the
10639 value of *ADDR is not necessarily a constant, even when
10644 /* Check whether the associated symbol is a constant.
10646 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10647 possible that a buggy compiler could mark a variable as
10648 constant even when it is not, and TYPE_CONST would return
10649 true in this case, while SYMBOL_CLASS wouldn't.
10651 We also have to check for function symbols because they
10652 are always constant. */
10654 struct symbol *s = exp->elts[i + 2].symbol;
10656 if (SYMBOL_CLASS (s) != LOC_BLOCK
10657 && SYMBOL_CLASS (s) != LOC_CONST
10658 && SYMBOL_CLASS (s) != LOC_CONST_BYTES)
10663 /* The default action is to return 0 because we are using
10664 the optimistic approach here: If we don't know something,
10665 then it is not a constant. */
10674 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
10677 dtor_watchpoint (struct breakpoint *self)
10679 struct watchpoint *w = (struct watchpoint *) self;
10681 xfree (w->cond_exp);
10683 xfree (w->exp_string);
10684 xfree (w->exp_string_reparse);
10685 value_free (w->val);
10687 base_breakpoint_ops.dtor (self);
10690 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10693 re_set_watchpoint (struct breakpoint *b)
10695 struct watchpoint *w = (struct watchpoint *) b;
10697 /* Watchpoint can be either on expression using entirely global
10698 variables, or it can be on local variables.
10700 Watchpoints of the first kind are never auto-deleted, and even
10701 persist across program restarts. Since they can use variables
10702 from shared libraries, we need to reparse expression as libraries
10703 are loaded and unloaded.
10705 Watchpoints on local variables can also change meaning as result
10706 of solib event. For example, if a watchpoint uses both a local
10707 and a global variables in expression, it's a local watchpoint,
10708 but unloading of a shared library will make the expression
10709 invalid. This is not a very common use case, but we still
10710 re-evaluate expression, to avoid surprises to the user.
10712 Note that for local watchpoints, we re-evaluate it only if
10713 watchpoints frame id is still valid. If it's not, it means the
10714 watchpoint is out of scope and will be deleted soon. In fact,
10715 I'm not sure we'll ever be called in this case.
10717 If a local watchpoint's frame id is still valid, then
10718 w->exp_valid_block is likewise valid, and we can safely use it.
10720 Don't do anything about disabled watchpoints, since they will be
10721 reevaluated again when enabled. */
10722 update_watchpoint (w, 1 /* reparse */);
10725 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10728 insert_watchpoint (struct bp_location *bl)
10730 struct watchpoint *w = (struct watchpoint *) bl->owner;
10731 int length = w->exact ? 1 : bl->length;
10733 return target_insert_watchpoint (bl->address, length, bl->watchpoint_type,
10737 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10740 remove_watchpoint (struct bp_location *bl)
10742 struct watchpoint *w = (struct watchpoint *) bl->owner;
10743 int length = w->exact ? 1 : bl->length;
10745 return target_remove_watchpoint (bl->address, length, bl->watchpoint_type,
10750 breakpoint_hit_watchpoint (const struct bp_location *bl,
10751 struct address_space *aspace, CORE_ADDR bp_addr,
10752 const struct target_waitstatus *ws)
10754 struct breakpoint *b = bl->owner;
10755 struct watchpoint *w = (struct watchpoint *) b;
10757 /* Continuable hardware watchpoints are treated as non-existent if the
10758 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10759 some data address). Otherwise gdb won't stop on a break instruction
10760 in the code (not from a breakpoint) when a hardware watchpoint has
10761 been defined. Also skip watchpoints which we know did not trigger
10762 (did not match the data address). */
10763 if (is_hardware_watchpoint (b)
10764 && w->watchpoint_triggered == watch_triggered_no)
10771 check_status_watchpoint (bpstat bs)
10773 gdb_assert (is_watchpoint (bs->breakpoint_at));
10775 bpstat_check_watchpoint (bs);
10778 /* Implement the "resources_needed" breakpoint_ops method for
10779 hardware watchpoints. */
10782 resources_needed_watchpoint (const struct bp_location *bl)
10784 struct watchpoint *w = (struct watchpoint *) bl->owner;
10785 int length = w->exact? 1 : bl->length;
10787 return target_region_ok_for_hw_watchpoint (bl->address, length);
10790 /* Implement the "works_in_software_mode" breakpoint_ops method for
10791 hardware watchpoints. */
10794 works_in_software_mode_watchpoint (const struct breakpoint *b)
10796 /* Read and access watchpoints only work with hardware support. */
10797 return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint;
10800 static enum print_stop_action
10801 print_it_watchpoint (bpstat bs)
10803 struct cleanup *old_chain;
10804 struct breakpoint *b;
10805 struct ui_file *stb;
10806 enum print_stop_action result;
10807 struct watchpoint *w;
10808 struct ui_out *uiout = current_uiout;
10810 gdb_assert (bs->bp_location_at != NULL);
10812 b = bs->breakpoint_at;
10813 w = (struct watchpoint *) b;
10815 stb = mem_fileopen ();
10816 old_chain = make_cleanup_ui_file_delete (stb);
10820 case bp_watchpoint:
10821 case bp_hardware_watchpoint:
10822 annotate_watchpoint (b->number);
10823 if (ui_out_is_mi_like_p (uiout))
10824 ui_out_field_string
10826 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
10828 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10829 ui_out_text (uiout, "\nOld value = ");
10830 watchpoint_value_print (bs->old_val, stb);
10831 ui_out_field_stream (uiout, "old", stb);
10832 ui_out_text (uiout, "\nNew value = ");
10833 watchpoint_value_print (w->val, stb);
10834 ui_out_field_stream (uiout, "new", stb);
10835 ui_out_text (uiout, "\n");
10836 /* More than one watchpoint may have been triggered. */
10837 result = PRINT_UNKNOWN;
10840 case bp_read_watchpoint:
10841 if (ui_out_is_mi_like_p (uiout))
10842 ui_out_field_string
10844 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
10846 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10847 ui_out_text (uiout, "\nValue = ");
10848 watchpoint_value_print (w->val, stb);
10849 ui_out_field_stream (uiout, "value", stb);
10850 ui_out_text (uiout, "\n");
10851 result = PRINT_UNKNOWN;
10854 case bp_access_watchpoint:
10855 if (bs->old_val != NULL)
10857 annotate_watchpoint (b->number);
10858 if (ui_out_is_mi_like_p (uiout))
10859 ui_out_field_string
10861 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10863 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10864 ui_out_text (uiout, "\nOld value = ");
10865 watchpoint_value_print (bs->old_val, stb);
10866 ui_out_field_stream (uiout, "old", stb);
10867 ui_out_text (uiout, "\nNew value = ");
10872 if (ui_out_is_mi_like_p (uiout))
10873 ui_out_field_string
10875 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10876 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10877 ui_out_text (uiout, "\nValue = ");
10879 watchpoint_value_print (w->val, stb);
10880 ui_out_field_stream (uiout, "new", stb);
10881 ui_out_text (uiout, "\n");
10882 result = PRINT_UNKNOWN;
10885 result = PRINT_UNKNOWN;
10888 do_cleanups (old_chain);
10892 /* Implement the "print_mention" breakpoint_ops method for hardware
10896 print_mention_watchpoint (struct breakpoint *b)
10898 struct cleanup *ui_out_chain;
10899 struct watchpoint *w = (struct watchpoint *) b;
10900 struct ui_out *uiout = current_uiout;
10904 case bp_watchpoint:
10905 ui_out_text (uiout, "Watchpoint ");
10906 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
10908 case bp_hardware_watchpoint:
10909 ui_out_text (uiout, "Hardware watchpoint ");
10910 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
10912 case bp_read_watchpoint:
10913 ui_out_text (uiout, "Hardware read watchpoint ");
10914 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
10916 case bp_access_watchpoint:
10917 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
10918 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
10921 internal_error (__FILE__, __LINE__,
10922 _("Invalid hardware watchpoint type."));
10925 ui_out_field_int (uiout, "number", b->number);
10926 ui_out_text (uiout, ": ");
10927 ui_out_field_string (uiout, "exp", w->exp_string);
10928 do_cleanups (ui_out_chain);
10931 /* Implement the "print_recreate" breakpoint_ops method for
10935 print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp)
10937 struct watchpoint *w = (struct watchpoint *) b;
10941 case bp_watchpoint:
10942 case bp_hardware_watchpoint:
10943 fprintf_unfiltered (fp, "watch");
10945 case bp_read_watchpoint:
10946 fprintf_unfiltered (fp, "rwatch");
10948 case bp_access_watchpoint:
10949 fprintf_unfiltered (fp, "awatch");
10952 internal_error (__FILE__, __LINE__,
10953 _("Invalid watchpoint type."));
10956 fprintf_unfiltered (fp, " %s", w->exp_string);
10957 print_recreate_thread (b, fp);
10960 /* Implement the "explains_signal" breakpoint_ops method for
10964 explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig)
10966 /* A software watchpoint cannot cause a signal other than
10967 GDB_SIGNAL_TRAP. */
10968 if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP)
10974 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10976 static struct breakpoint_ops watchpoint_breakpoint_ops;
10978 /* Implement the "insert" breakpoint_ops method for
10979 masked hardware watchpoints. */
10982 insert_masked_watchpoint (struct bp_location *bl)
10984 struct watchpoint *w = (struct watchpoint *) bl->owner;
10986 return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask,
10987 bl->watchpoint_type);
10990 /* Implement the "remove" breakpoint_ops method for
10991 masked hardware watchpoints. */
10994 remove_masked_watchpoint (struct bp_location *bl)
10996 struct watchpoint *w = (struct watchpoint *) bl->owner;
10998 return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask,
10999 bl->watchpoint_type);
11002 /* Implement the "resources_needed" breakpoint_ops method for
11003 masked hardware watchpoints. */
11006 resources_needed_masked_watchpoint (const struct bp_location *bl)
11008 struct watchpoint *w = (struct watchpoint *) bl->owner;
11010 return target_masked_watch_num_registers (bl->address, w->hw_wp_mask);
11013 /* Implement the "works_in_software_mode" breakpoint_ops method for
11014 masked hardware watchpoints. */
11017 works_in_software_mode_masked_watchpoint (const struct breakpoint *b)
11022 /* Implement the "print_it" breakpoint_ops method for
11023 masked hardware watchpoints. */
11025 static enum print_stop_action
11026 print_it_masked_watchpoint (bpstat bs)
11028 struct breakpoint *b = bs->breakpoint_at;
11029 struct ui_out *uiout = current_uiout;
11031 /* Masked watchpoints have only one location. */
11032 gdb_assert (b->loc && b->loc->next == NULL);
11036 case bp_hardware_watchpoint:
11037 annotate_watchpoint (b->number);
11038 if (ui_out_is_mi_like_p (uiout))
11039 ui_out_field_string
11041 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
11044 case bp_read_watchpoint:
11045 if (ui_out_is_mi_like_p (uiout))
11046 ui_out_field_string
11048 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
11051 case bp_access_watchpoint:
11052 if (ui_out_is_mi_like_p (uiout))
11053 ui_out_field_string
11055 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
11058 internal_error (__FILE__, __LINE__,
11059 _("Invalid hardware watchpoint type."));
11063 ui_out_text (uiout, _("\n\
11064 Check the underlying instruction at PC for the memory\n\
11065 address and value which triggered this watchpoint.\n"));
11066 ui_out_text (uiout, "\n");
11068 /* More than one watchpoint may have been triggered. */
11069 return PRINT_UNKNOWN;
11072 /* Implement the "print_one_detail" breakpoint_ops method for
11073 masked hardware watchpoints. */
11076 print_one_detail_masked_watchpoint (const struct breakpoint *b,
11077 struct ui_out *uiout)
11079 struct watchpoint *w = (struct watchpoint *) b;
11081 /* Masked watchpoints have only one location. */
11082 gdb_assert (b->loc && b->loc->next == NULL);
11084 ui_out_text (uiout, "\tmask ");
11085 ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask);
11086 ui_out_text (uiout, "\n");
11089 /* Implement the "print_mention" breakpoint_ops method for
11090 masked hardware watchpoints. */
11093 print_mention_masked_watchpoint (struct breakpoint *b)
11095 struct watchpoint *w = (struct watchpoint *) b;
11096 struct ui_out *uiout = current_uiout;
11097 struct cleanup *ui_out_chain;
11101 case bp_hardware_watchpoint:
11102 ui_out_text (uiout, "Masked hardware watchpoint ");
11103 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
11105 case bp_read_watchpoint:
11106 ui_out_text (uiout, "Masked hardware read watchpoint ");
11107 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
11109 case bp_access_watchpoint:
11110 ui_out_text (uiout, "Masked hardware access (read/write) watchpoint ");
11111 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
11114 internal_error (__FILE__, __LINE__,
11115 _("Invalid hardware watchpoint type."));
11118 ui_out_field_int (uiout, "number", b->number);
11119 ui_out_text (uiout, ": ");
11120 ui_out_field_string (uiout, "exp", w->exp_string);
11121 do_cleanups (ui_out_chain);
11124 /* Implement the "print_recreate" breakpoint_ops method for
11125 masked hardware watchpoints. */
11128 print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp)
11130 struct watchpoint *w = (struct watchpoint *) b;
11135 case bp_hardware_watchpoint:
11136 fprintf_unfiltered (fp, "watch");
11138 case bp_read_watchpoint:
11139 fprintf_unfiltered (fp, "rwatch");
11141 case bp_access_watchpoint:
11142 fprintf_unfiltered (fp, "awatch");
11145 internal_error (__FILE__, __LINE__,
11146 _("Invalid hardware watchpoint type."));
11149 sprintf_vma (tmp, w->hw_wp_mask);
11150 fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp);
11151 print_recreate_thread (b, fp);
11154 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
11156 static struct breakpoint_ops masked_watchpoint_breakpoint_ops;
11158 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
11161 is_masked_watchpoint (const struct breakpoint *b)
11163 return b->ops == &masked_watchpoint_breakpoint_ops;
11166 /* accessflag: hw_write: watch write,
11167 hw_read: watch read,
11168 hw_access: watch access (read or write) */
11170 watch_command_1 (const char *arg, int accessflag, int from_tty,
11171 int just_location, int internal)
11173 volatile struct gdb_exception e;
11174 struct breakpoint *b, *scope_breakpoint = NULL;
11175 struct expression *exp;
11176 const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL;
11177 struct value *val, *mark, *result;
11178 struct frame_info *frame;
11179 const char *exp_start = NULL;
11180 const char *exp_end = NULL;
11181 const char *tok, *end_tok;
11183 const char *cond_start = NULL;
11184 const char *cond_end = NULL;
11185 enum bptype bp_type;
11188 /* Flag to indicate whether we are going to use masks for
11189 the hardware watchpoint. */
11191 CORE_ADDR mask = 0;
11192 struct watchpoint *w;
11194 struct cleanup *back_to;
11196 /* Make sure that we actually have parameters to parse. */
11197 if (arg != NULL && arg[0] != '\0')
11199 const char *value_start;
11201 exp_end = arg + strlen (arg);
11203 /* Look for "parameter value" pairs at the end
11204 of the arguments string. */
11205 for (tok = exp_end - 1; tok > arg; tok--)
11207 /* Skip whitespace at the end of the argument list. */
11208 while (tok > arg && (*tok == ' ' || *tok == '\t'))
11211 /* Find the beginning of the last token.
11212 This is the value of the parameter. */
11213 while (tok > arg && (*tok != ' ' && *tok != '\t'))
11215 value_start = tok + 1;
11217 /* Skip whitespace. */
11218 while (tok > arg && (*tok == ' ' || *tok == '\t'))
11223 /* Find the beginning of the second to last token.
11224 This is the parameter itself. */
11225 while (tok > arg && (*tok != ' ' && *tok != '\t'))
11228 toklen = end_tok - tok + 1;
11230 if (toklen == 6 && !strncmp (tok, "thread", 6))
11232 /* At this point we've found a "thread" token, which means
11233 the user is trying to set a watchpoint that triggers
11234 only in a specific thread. */
11238 error(_("You can specify only one thread."));
11240 /* Extract the thread ID from the next token. */
11241 thread = strtol (value_start, &endp, 0);
11243 /* Check if the user provided a valid numeric value for the
11245 if (*endp != ' ' && *endp != '\t' && *endp != '\0')
11246 error (_("Invalid thread ID specification %s."), value_start);
11248 /* Check if the thread actually exists. */
11249 if (!valid_thread_id (thread))
11250 invalid_thread_id_error (thread);
11252 else if (toklen == 4 && !strncmp (tok, "mask", 4))
11254 /* We've found a "mask" token, which means the user wants to
11255 create a hardware watchpoint that is going to have the mask
11257 struct value *mask_value, *mark;
11260 error(_("You can specify only one mask."));
11262 use_mask = just_location = 1;
11264 mark = value_mark ();
11265 mask_value = parse_to_comma_and_eval (&value_start);
11266 mask = value_as_address (mask_value);
11267 value_free_to_mark (mark);
11270 /* We didn't recognize what we found. We should stop here. */
11273 /* Truncate the string and get rid of the "parameter value" pair before
11274 the arguments string is parsed by the parse_exp_1 function. */
11281 /* Parse the rest of the arguments. From here on out, everything
11282 is in terms of a newly allocated string instead of the original
11284 innermost_block = NULL;
11285 expression = savestring (arg, exp_end - arg);
11286 back_to = make_cleanup (xfree, expression);
11287 exp_start = arg = expression;
11288 exp = parse_exp_1 (&arg, 0, 0, 0);
11290 /* Remove trailing whitespace from the expression before saving it.
11291 This makes the eventual display of the expression string a bit
11293 while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t'))
11296 /* Checking if the expression is not constant. */
11297 if (watchpoint_exp_is_const (exp))
11301 len = exp_end - exp_start;
11302 while (len > 0 && isspace (exp_start[len - 1]))
11304 error (_("Cannot watch constant value `%.*s'."), len, exp_start);
11307 exp_valid_block = innermost_block;
11308 mark = value_mark ();
11309 fetch_subexp_value (exp, &pc, &val, &result, NULL, just_location);
11315 exp_valid_block = NULL;
11316 val = value_addr (result);
11317 release_value (val);
11318 value_free_to_mark (mark);
11322 ret = target_masked_watch_num_registers (value_as_address (val),
11325 error (_("This target does not support masked watchpoints."));
11326 else if (ret == -2)
11327 error (_("Invalid mask or memory region."));
11330 else if (val != NULL)
11331 release_value (val);
11333 tok = skip_spaces_const (arg);
11334 end_tok = skip_to_space_const (tok);
11336 toklen = end_tok - tok;
11337 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
11339 struct expression *cond;
11341 innermost_block = NULL;
11342 tok = cond_start = end_tok + 1;
11343 cond = parse_exp_1 (&tok, 0, 0, 0);
11345 /* The watchpoint expression may not be local, but the condition
11346 may still be. E.g.: `watch global if local > 0'. */
11347 cond_exp_valid_block = innermost_block;
11353 error (_("Junk at end of command."));
11355 frame = block_innermost_frame (exp_valid_block);
11357 /* If the expression is "local", then set up a "watchpoint scope"
11358 breakpoint at the point where we've left the scope of the watchpoint
11359 expression. Create the scope breakpoint before the watchpoint, so
11360 that we will encounter it first in bpstat_stop_status. */
11361 if (exp_valid_block && frame)
11363 if (frame_id_p (frame_unwind_caller_id (frame)))
11366 = create_internal_breakpoint (frame_unwind_caller_arch (frame),
11367 frame_unwind_caller_pc (frame),
11368 bp_watchpoint_scope,
11369 &momentary_breakpoint_ops);
11371 scope_breakpoint->enable_state = bp_enabled;
11373 /* Automatically delete the breakpoint when it hits. */
11374 scope_breakpoint->disposition = disp_del;
11376 /* Only break in the proper frame (help with recursion). */
11377 scope_breakpoint->frame_id = frame_unwind_caller_id (frame);
11379 /* Set the address at which we will stop. */
11380 scope_breakpoint->loc->gdbarch
11381 = frame_unwind_caller_arch (frame);
11382 scope_breakpoint->loc->requested_address
11383 = frame_unwind_caller_pc (frame);
11384 scope_breakpoint->loc->address
11385 = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch,
11386 scope_breakpoint->loc->requested_address,
11387 scope_breakpoint->type);
11391 /* Now set up the breakpoint. We create all watchpoints as hardware
11392 watchpoints here even if hardware watchpoints are turned off, a call
11393 to update_watchpoint later in this function will cause the type to
11394 drop back to bp_watchpoint (software watchpoint) if required. */
11396 if (accessflag == hw_read)
11397 bp_type = bp_read_watchpoint;
11398 else if (accessflag == hw_access)
11399 bp_type = bp_access_watchpoint;
11401 bp_type = bp_hardware_watchpoint;
11403 w = XCNEW (struct watchpoint);
11406 init_raw_breakpoint_without_location (b, NULL, bp_type,
11407 &masked_watchpoint_breakpoint_ops);
11409 init_raw_breakpoint_without_location (b, NULL, bp_type,
11410 &watchpoint_breakpoint_ops);
11411 b->thread = thread;
11412 b->disposition = disp_donttouch;
11413 b->pspace = current_program_space;
11415 w->exp_valid_block = exp_valid_block;
11416 w->cond_exp_valid_block = cond_exp_valid_block;
11419 struct type *t = value_type (val);
11420 CORE_ADDR addr = value_as_address (val);
11423 t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t)));
11424 name = type_to_string (t);
11426 w->exp_string_reparse = xstrprintf ("* (%s *) %s", name,
11427 core_addr_to_string (addr));
11430 w->exp_string = xstrprintf ("-location %.*s",
11431 (int) (exp_end - exp_start), exp_start);
11433 /* The above expression is in C. */
11434 b->language = language_c;
11437 w->exp_string = savestring (exp_start, exp_end - exp_start);
11441 w->hw_wp_mask = mask;
11450 b->cond_string = savestring (cond_start, cond_end - cond_start);
11452 b->cond_string = 0;
11456 w->watchpoint_frame = get_frame_id (frame);
11457 w->watchpoint_thread = inferior_ptid;
11461 w->watchpoint_frame = null_frame_id;
11462 w->watchpoint_thread = null_ptid;
11465 if (scope_breakpoint != NULL)
11467 /* The scope breakpoint is related to the watchpoint. We will
11468 need to act on them together. */
11469 b->related_breakpoint = scope_breakpoint;
11470 scope_breakpoint->related_breakpoint = b;
11473 if (!just_location)
11474 value_free_to_mark (mark);
11476 TRY_CATCH (e, RETURN_MASK_ALL)
11478 /* Finally update the new watchpoint. This creates the locations
11479 that should be inserted. */
11480 update_watchpoint (w, 1);
11484 delete_breakpoint (b);
11485 throw_exception (e);
11488 install_breakpoint (internal, b, 1);
11489 do_cleanups (back_to);
11492 /* Return count of debug registers needed to watch the given expression.
11493 If the watchpoint cannot be handled in hardware return zero. */
11496 can_use_hardware_watchpoint (struct value *v)
11498 int found_memory_cnt = 0;
11499 struct value *head = v;
11501 /* Did the user specifically forbid us to use hardware watchpoints? */
11502 if (!can_use_hw_watchpoints)
11505 /* Make sure that the value of the expression depends only upon
11506 memory contents, and values computed from them within GDB. If we
11507 find any register references or function calls, we can't use a
11508 hardware watchpoint.
11510 The idea here is that evaluating an expression generates a series
11511 of values, one holding the value of every subexpression. (The
11512 expression a*b+c has five subexpressions: a, b, a*b, c, and
11513 a*b+c.) GDB's values hold almost enough information to establish
11514 the criteria given above --- they identify memory lvalues,
11515 register lvalues, computed values, etcetera. So we can evaluate
11516 the expression, and then scan the chain of values that leaves
11517 behind to decide whether we can detect any possible change to the
11518 expression's final value using only hardware watchpoints.
11520 However, I don't think that the values returned by inferior
11521 function calls are special in any way. So this function may not
11522 notice that an expression involving an inferior function call
11523 can't be watched with hardware watchpoints. FIXME. */
11524 for (; v; v = value_next (v))
11526 if (VALUE_LVAL (v) == lval_memory)
11528 if (v != head && value_lazy (v))
11529 /* A lazy memory lvalue in the chain is one that GDB never
11530 needed to fetch; we either just used its address (e.g.,
11531 `a' in `a.b') or we never needed it at all (e.g., `a'
11532 in `a,b'). This doesn't apply to HEAD; if that is
11533 lazy then it was not readable, but watch it anyway. */
11537 /* Ahh, memory we actually used! Check if we can cover
11538 it with hardware watchpoints. */
11539 struct type *vtype = check_typedef (value_type (v));
11541 /* We only watch structs and arrays if user asked for it
11542 explicitly, never if they just happen to appear in a
11543 middle of some value chain. */
11545 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
11546 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
11548 CORE_ADDR vaddr = value_address (v);
11552 len = (target_exact_watchpoints
11553 && is_scalar_type_recursive (vtype))?
11554 1 : TYPE_LENGTH (value_type (v));
11556 num_regs = target_region_ok_for_hw_watchpoint (vaddr, len);
11560 found_memory_cnt += num_regs;
11564 else if (VALUE_LVAL (v) != not_lval
11565 && deprecated_value_modifiable (v) == 0)
11566 return 0; /* These are values from the history (e.g., $1). */
11567 else if (VALUE_LVAL (v) == lval_register)
11568 return 0; /* Cannot watch a register with a HW watchpoint. */
11571 /* The expression itself looks suitable for using a hardware
11572 watchpoint, but give the target machine a chance to reject it. */
11573 return found_memory_cnt;
11577 watch_command_wrapper (char *arg, int from_tty, int internal)
11579 watch_command_1 (arg, hw_write, from_tty, 0, internal);
11582 /* A helper function that looks for the "-location" argument and then
11583 calls watch_command_1. */
11586 watch_maybe_just_location (char *arg, int accessflag, int from_tty)
11588 int just_location = 0;
11591 && (check_for_argument (&arg, "-location", sizeof ("-location") - 1)
11592 || check_for_argument (&arg, "-l", sizeof ("-l") - 1)))
11594 arg = skip_spaces (arg);
11598 watch_command_1 (arg, accessflag, from_tty, just_location, 0);
11602 watch_command (char *arg, int from_tty)
11604 watch_maybe_just_location (arg, hw_write, from_tty);
11608 rwatch_command_wrapper (char *arg, int from_tty, int internal)
11610 watch_command_1 (arg, hw_read, from_tty, 0, internal);
11614 rwatch_command (char *arg, int from_tty)
11616 watch_maybe_just_location (arg, hw_read, from_tty);
11620 awatch_command_wrapper (char *arg, int from_tty, int internal)
11622 watch_command_1 (arg, hw_access, from_tty, 0, internal);
11626 awatch_command (char *arg, int from_tty)
11628 watch_maybe_just_location (arg, hw_access, from_tty);
11632 /* Helper routines for the until_command routine in infcmd.c. Here
11633 because it uses the mechanisms of breakpoints. */
11635 struct until_break_command_continuation_args
11637 struct breakpoint *breakpoint;
11638 struct breakpoint *breakpoint2;
11642 /* This function is called by fetch_inferior_event via the
11643 cmd_continuation pointer, to complete the until command. It takes
11644 care of cleaning up the temporary breakpoints set up by the until
11647 until_break_command_continuation (void *arg, int err)
11649 struct until_break_command_continuation_args *a = arg;
11651 delete_breakpoint (a->breakpoint);
11652 if (a->breakpoint2)
11653 delete_breakpoint (a->breakpoint2);
11654 delete_longjmp_breakpoint (a->thread_num);
11658 until_break_command (char *arg, int from_tty, int anywhere)
11660 struct symtabs_and_lines sals;
11661 struct symtab_and_line sal;
11662 struct frame_info *frame;
11663 struct gdbarch *frame_gdbarch;
11664 struct frame_id stack_frame_id;
11665 struct frame_id caller_frame_id;
11666 struct breakpoint *breakpoint;
11667 struct breakpoint *breakpoint2 = NULL;
11668 struct cleanup *old_chain;
11670 struct thread_info *tp;
11672 clear_proceed_status ();
11674 /* Set a breakpoint where the user wants it and at return from
11677 if (last_displayed_sal_is_valid ())
11678 sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE,
11679 get_last_displayed_symtab (),
11680 get_last_displayed_line ());
11682 sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE,
11683 (struct symtab *) NULL, 0);
11685 if (sals.nelts != 1)
11686 error (_("Couldn't get information on specified line."));
11688 sal = sals.sals[0];
11689 xfree (sals.sals); /* malloc'd, so freed. */
11692 error (_("Junk at end of arguments."));
11694 resolve_sal_pc (&sal);
11696 tp = inferior_thread ();
11699 old_chain = make_cleanup (null_cleanup, NULL);
11701 /* Note linespec handling above invalidates the frame chain.
11702 Installing a breakpoint also invalidates the frame chain (as it
11703 may need to switch threads), so do any frame handling before
11706 frame = get_selected_frame (NULL);
11707 frame_gdbarch = get_frame_arch (frame);
11708 stack_frame_id = get_stack_frame_id (frame);
11709 caller_frame_id = frame_unwind_caller_id (frame);
11711 /* Keep within the current frame, or in frames called by the current
11714 if (frame_id_p (caller_frame_id))
11716 struct symtab_and_line sal2;
11718 sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0);
11719 sal2.pc = frame_unwind_caller_pc (frame);
11720 breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame),
11724 make_cleanup_delete_breakpoint (breakpoint2);
11726 set_longjmp_breakpoint (tp, caller_frame_id);
11727 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
11730 /* set_momentary_breakpoint could invalidate FRAME. */
11734 /* If the user told us to continue until a specified location,
11735 we don't specify a frame at which we need to stop. */
11736 breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
11737 null_frame_id, bp_until);
11739 /* Otherwise, specify the selected frame, because we want to stop
11740 only at the very same frame. */
11741 breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
11742 stack_frame_id, bp_until);
11743 make_cleanup_delete_breakpoint (breakpoint);
11745 proceed (-1, GDB_SIGNAL_DEFAULT, 0);
11747 /* If we are running asynchronously, and proceed call above has
11748 actually managed to start the target, arrange for breakpoints to
11749 be deleted when the target stops. Otherwise, we're already
11750 stopped and delete breakpoints via cleanup chain. */
11752 if (target_can_async_p () && is_running (inferior_ptid))
11754 struct until_break_command_continuation_args *args;
11755 args = xmalloc (sizeof (*args));
11757 args->breakpoint = breakpoint;
11758 args->breakpoint2 = breakpoint2;
11759 args->thread_num = thread;
11761 discard_cleanups (old_chain);
11762 add_continuation (inferior_thread (),
11763 until_break_command_continuation, args,
11767 do_cleanups (old_chain);
11770 /* This function attempts to parse an optional "if <cond>" clause
11771 from the arg string. If one is not found, it returns NULL.
11773 Else, it returns a pointer to the condition string. (It does not
11774 attempt to evaluate the string against a particular block.) And,
11775 it updates arg to point to the first character following the parsed
11776 if clause in the arg string. */
11779 ep_parse_optional_if_clause (char **arg)
11783 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
11786 /* Skip the "if" keyword. */
11789 /* Skip any extra leading whitespace, and record the start of the
11790 condition string. */
11791 *arg = skip_spaces (*arg);
11792 cond_string = *arg;
11794 /* Assume that the condition occupies the remainder of the arg
11796 (*arg) += strlen (cond_string);
11798 return cond_string;
11801 /* Commands to deal with catching events, such as signals, exceptions,
11802 process start/exit, etc. */
11806 catch_fork_temporary, catch_vfork_temporary,
11807 catch_fork_permanent, catch_vfork_permanent
11812 catch_fork_command_1 (char *arg, int from_tty,
11813 struct cmd_list_element *command)
11815 struct gdbarch *gdbarch = get_current_arch ();
11816 char *cond_string = NULL;
11817 catch_fork_kind fork_kind;
11820 fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command);
11821 tempflag = (fork_kind == catch_fork_temporary
11822 || fork_kind == catch_vfork_temporary);
11826 arg = skip_spaces (arg);
11828 /* The allowed syntax is:
11830 catch [v]fork if <cond>
11832 First, check if there's an if clause. */
11833 cond_string = ep_parse_optional_if_clause (&arg);
11835 if ((*arg != '\0') && !isspace (*arg))
11836 error (_("Junk at end of arguments."));
11838 /* If this target supports it, create a fork or vfork catchpoint
11839 and enable reporting of such events. */
11842 case catch_fork_temporary:
11843 case catch_fork_permanent:
11844 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
11845 &catch_fork_breakpoint_ops);
11847 case catch_vfork_temporary:
11848 case catch_vfork_permanent:
11849 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
11850 &catch_vfork_breakpoint_ops);
11853 error (_("unsupported or unknown fork kind; cannot catch it"));
11859 catch_exec_command_1 (char *arg, int from_tty,
11860 struct cmd_list_element *command)
11862 struct exec_catchpoint *c;
11863 struct gdbarch *gdbarch = get_current_arch ();
11865 char *cond_string = NULL;
11867 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11871 arg = skip_spaces (arg);
11873 /* The allowed syntax is:
11875 catch exec if <cond>
11877 First, check if there's an if clause. */
11878 cond_string = ep_parse_optional_if_clause (&arg);
11880 if ((*arg != '\0') && !isspace (*arg))
11881 error (_("Junk at end of arguments."));
11883 c = XNEW (struct exec_catchpoint);
11884 init_catchpoint (&c->base, gdbarch, tempflag, cond_string,
11885 &catch_exec_breakpoint_ops);
11886 c->exec_pathname = NULL;
11888 install_breakpoint (0, &c->base, 1);
11892 init_ada_exception_breakpoint (struct breakpoint *b,
11893 struct gdbarch *gdbarch,
11894 struct symtab_and_line sal,
11896 const struct breakpoint_ops *ops,
11903 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
11905 loc_gdbarch = gdbarch;
11907 describe_other_breakpoints (loc_gdbarch,
11908 sal.pspace, sal.pc, sal.section, -1);
11909 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11910 version for exception catchpoints, because two catchpoints
11911 used for different exception names will use the same address.
11912 In this case, a "breakpoint ... also set at..." warning is
11913 unproductive. Besides, the warning phrasing is also a bit
11914 inappropriate, we should use the word catchpoint, and tell
11915 the user what type of catchpoint it is. The above is good
11916 enough for now, though. */
11919 init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops);
11921 b->enable_state = enabled ? bp_enabled : bp_disabled;
11922 b->disposition = tempflag ? disp_del : disp_donttouch;
11923 b->addr_string = addr_string;
11924 b->language = language_ada;
11927 /* Splits the argument using space as delimiter. Returns an xmalloc'd
11928 filter list, or NULL if no filtering is required. */
11930 catch_syscall_split_args (char *arg)
11932 VEC(int) *result = NULL;
11933 struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result);
11935 while (*arg != '\0')
11937 int i, syscall_number;
11939 char cur_name[128];
11942 /* Skip whitespace. */
11943 arg = skip_spaces (arg);
11945 for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i)
11946 cur_name[i] = arg[i];
11947 cur_name[i] = '\0';
11950 /* Check if the user provided a syscall name or a number. */
11951 syscall_number = (int) strtol (cur_name, &endptr, 0);
11952 if (*endptr == '\0')
11953 get_syscall_by_number (syscall_number, &s);
11956 /* We have a name. Let's check if it's valid and convert it
11958 get_syscall_by_name (cur_name, &s);
11960 if (s.number == UNKNOWN_SYSCALL)
11961 /* Here we have to issue an error instead of a warning,
11962 because GDB cannot do anything useful if there's no
11963 syscall number to be caught. */
11964 error (_("Unknown syscall name '%s'."), cur_name);
11967 /* Ok, it's valid. */
11968 VEC_safe_push (int, result, s.number);
11971 discard_cleanups (cleanup);
11975 /* Implement the "catch syscall" command. */
11978 catch_syscall_command_1 (char *arg, int from_tty,
11979 struct cmd_list_element *command)
11984 struct gdbarch *gdbarch = get_current_arch ();
11986 /* Checking if the feature if supported. */
11987 if (gdbarch_get_syscall_number_p (gdbarch) == 0)
11988 error (_("The feature 'catch syscall' is not supported on \
11989 this architecture yet."));
11991 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11993 arg = skip_spaces (arg);
11995 /* We need to do this first "dummy" translation in order
11996 to get the syscall XML file loaded or, most important,
11997 to display a warning to the user if there's no XML file
11998 for his/her architecture. */
11999 get_syscall_by_number (0, &s);
12001 /* The allowed syntax is:
12003 catch syscall <name | number> [<name | number> ... <name | number>]
12005 Let's check if there's a syscall name. */
12008 filter = catch_syscall_split_args (arg);
12012 create_syscall_event_catchpoint (tempflag, filter,
12013 &catch_syscall_breakpoint_ops);
12017 catch_command (char *arg, int from_tty)
12019 error (_("Catch requires an event name."));
12024 tcatch_command (char *arg, int from_tty)
12026 error (_("Catch requires an event name."));
12029 /* A qsort comparison function that sorts breakpoints in order. */
12032 compare_breakpoints (const void *a, const void *b)
12034 const breakpoint_p *ba = a;
12035 uintptr_t ua = (uintptr_t) *ba;
12036 const breakpoint_p *bb = b;
12037 uintptr_t ub = (uintptr_t) *bb;
12039 if ((*ba)->number < (*bb)->number)
12041 else if ((*ba)->number > (*bb)->number)
12044 /* Now sort by address, in case we see, e..g, two breakpoints with
12048 return ua > ub ? 1 : 0;
12051 /* Delete breakpoints by address or line. */
12054 clear_command (char *arg, int from_tty)
12056 struct breakpoint *b, *prev;
12057 VEC(breakpoint_p) *found = 0;
12060 struct symtabs_and_lines sals;
12061 struct symtab_and_line sal;
12063 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
12067 sals = decode_line_with_current_source (arg,
12068 (DECODE_LINE_FUNFIRSTLINE
12069 | DECODE_LINE_LIST_MODE));
12070 make_cleanup (xfree, sals.sals);
12075 sals.sals = (struct symtab_and_line *)
12076 xmalloc (sizeof (struct symtab_and_line));
12077 make_cleanup (xfree, sals.sals);
12078 init_sal (&sal); /* Initialize to zeroes. */
12080 /* Set sal's line, symtab, pc, and pspace to the values
12081 corresponding to the last call to print_frame_info. If the
12082 codepoint is not valid, this will set all the fields to 0. */
12083 get_last_displayed_sal (&sal);
12084 if (sal.symtab == 0)
12085 error (_("No source file specified."));
12087 sals.sals[0] = sal;
12093 /* We don't call resolve_sal_pc here. That's not as bad as it
12094 seems, because all existing breakpoints typically have both
12095 file/line and pc set. So, if clear is given file/line, we can
12096 match this to existing breakpoint without obtaining pc at all.
12098 We only support clearing given the address explicitly
12099 present in breakpoint table. Say, we've set breakpoint
12100 at file:line. There were several PC values for that file:line,
12101 due to optimization, all in one block.
12103 We've picked one PC value. If "clear" is issued with another
12104 PC corresponding to the same file:line, the breakpoint won't
12105 be cleared. We probably can still clear the breakpoint, but
12106 since the other PC value is never presented to user, user
12107 can only find it by guessing, and it does not seem important
12108 to support that. */
12110 /* For each line spec given, delete bps which correspond to it. Do
12111 it in two passes, solely to preserve the current behavior that
12112 from_tty is forced true if we delete more than one
12116 make_cleanup (VEC_cleanup (breakpoint_p), &found);
12117 for (i = 0; i < sals.nelts; i++)
12119 const char *sal_fullname;
12121 /* If exact pc given, clear bpts at that pc.
12122 If line given (pc == 0), clear all bpts on specified line.
12123 If defaulting, clear all bpts on default line
12126 defaulting sal.pc != 0 tests to do
12131 1 0 <can't happen> */
12133 sal = sals.sals[i];
12134 sal_fullname = (sal.symtab == NULL
12135 ? NULL : symtab_to_fullname (sal.symtab));
12137 /* Find all matching breakpoints and add them to 'found'. */
12138 ALL_BREAKPOINTS (b)
12141 /* Are we going to delete b? */
12142 if (b->type != bp_none && !is_watchpoint (b))
12144 struct bp_location *loc = b->loc;
12145 for (; loc; loc = loc->next)
12147 /* If the user specified file:line, don't allow a PC
12148 match. This matches historical gdb behavior. */
12149 int pc_match = (!sal.explicit_line
12151 && (loc->pspace == sal.pspace)
12152 && (loc->address == sal.pc)
12153 && (!section_is_overlay (loc->section)
12154 || loc->section == sal.section));
12155 int line_match = 0;
12157 if ((default_match || sal.explicit_line)
12158 && loc->symtab != NULL
12159 && sal_fullname != NULL
12160 && sal.pspace == loc->pspace
12161 && loc->line_number == sal.line
12162 && filename_cmp (symtab_to_fullname (loc->symtab),
12163 sal_fullname) == 0)
12166 if (pc_match || line_match)
12175 VEC_safe_push(breakpoint_p, found, b);
12179 /* Now go thru the 'found' chain and delete them. */
12180 if (VEC_empty(breakpoint_p, found))
12183 error (_("No breakpoint at %s."), arg);
12185 error (_("No breakpoint at this line."));
12188 /* Remove duplicates from the vec. */
12189 qsort (VEC_address (breakpoint_p, found),
12190 VEC_length (breakpoint_p, found),
12191 sizeof (breakpoint_p),
12192 compare_breakpoints);
12193 prev = VEC_index (breakpoint_p, found, 0);
12194 for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix)
12198 VEC_ordered_remove (breakpoint_p, found, ix);
12203 if (VEC_length(breakpoint_p, found) > 1)
12204 from_tty = 1; /* Always report if deleted more than one. */
12207 if (VEC_length(breakpoint_p, found) == 1)
12208 printf_unfiltered (_("Deleted breakpoint "));
12210 printf_unfiltered (_("Deleted breakpoints "));
12213 for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++)
12216 printf_unfiltered ("%d ", b->number);
12217 delete_breakpoint (b);
12220 putchar_unfiltered ('\n');
12222 do_cleanups (cleanups);
12225 /* Delete breakpoint in BS if they are `delete' breakpoints and
12226 all breakpoints that are marked for deletion, whether hit or not.
12227 This is called after any breakpoint is hit, or after errors. */
12230 breakpoint_auto_delete (bpstat bs)
12232 struct breakpoint *b, *b_tmp;
12234 for (; bs; bs = bs->next)
12235 if (bs->breakpoint_at
12236 && bs->breakpoint_at->disposition == disp_del
12238 delete_breakpoint (bs->breakpoint_at);
12240 ALL_BREAKPOINTS_SAFE (b, b_tmp)
12242 if (b->disposition == disp_del_at_next_stop)
12243 delete_breakpoint (b);
12247 /* A comparison function for bp_location AP and BP being interfaced to
12248 qsort. Sort elements primarily by their ADDRESS (no matter what
12249 does breakpoint_address_is_meaningful say for its OWNER),
12250 secondarily by ordering first bp_permanent OWNERed elements and
12251 terciarily just ensuring the array is sorted stable way despite
12252 qsort being an unstable algorithm. */
12255 bp_location_compare (const void *ap, const void *bp)
12257 struct bp_location *a = *(void **) ap;
12258 struct bp_location *b = *(void **) bp;
12259 /* A and B come from existing breakpoints having non-NULL OWNER. */
12260 int a_perm = a->owner->enable_state == bp_permanent;
12261 int b_perm = b->owner->enable_state == bp_permanent;
12263 if (a->address != b->address)
12264 return (a->address > b->address) - (a->address < b->address);
12266 /* Sort locations at the same address by their pspace number, keeping
12267 locations of the same inferior (in a multi-inferior environment)
12270 if (a->pspace->num != b->pspace->num)
12271 return ((a->pspace->num > b->pspace->num)
12272 - (a->pspace->num < b->pspace->num));
12274 /* Sort permanent breakpoints first. */
12275 if (a_perm != b_perm)
12276 return (a_perm < b_perm) - (a_perm > b_perm);
12278 /* Make the internal GDB representation stable across GDB runs
12279 where A and B memory inside GDB can differ. Breakpoint locations of
12280 the same type at the same address can be sorted in arbitrary order. */
12282 if (a->owner->number != b->owner->number)
12283 return ((a->owner->number > b->owner->number)
12284 - (a->owner->number < b->owner->number));
12286 return (a > b) - (a < b);
12289 /* Set bp_location_placed_address_before_address_max and
12290 bp_location_shadow_len_after_address_max according to the current
12291 content of the bp_location array. */
12294 bp_location_target_extensions_update (void)
12296 struct bp_location *bl, **blp_tmp;
12298 bp_location_placed_address_before_address_max = 0;
12299 bp_location_shadow_len_after_address_max = 0;
12301 ALL_BP_LOCATIONS (bl, blp_tmp)
12303 CORE_ADDR start, end, addr;
12305 if (!bp_location_has_shadow (bl))
12308 start = bl->target_info.placed_address;
12309 end = start + bl->target_info.shadow_len;
12311 gdb_assert (bl->address >= start);
12312 addr = bl->address - start;
12313 if (addr > bp_location_placed_address_before_address_max)
12314 bp_location_placed_address_before_address_max = addr;
12316 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
12318 gdb_assert (bl->address < end);
12319 addr = end - bl->address;
12320 if (addr > bp_location_shadow_len_after_address_max)
12321 bp_location_shadow_len_after_address_max = addr;
12325 /* Download tracepoint locations if they haven't been. */
12328 download_tracepoint_locations (void)
12330 struct breakpoint *b;
12331 struct cleanup *old_chain;
12333 if (!target_can_download_tracepoint ())
12336 old_chain = save_current_space_and_thread ();
12338 ALL_TRACEPOINTS (b)
12340 struct bp_location *bl;
12341 struct tracepoint *t;
12342 int bp_location_downloaded = 0;
12344 if ((b->type == bp_fast_tracepoint
12345 ? !may_insert_fast_tracepoints
12346 : !may_insert_tracepoints))
12349 for (bl = b->loc; bl; bl = bl->next)
12351 /* In tracepoint, locations are _never_ duplicated, so
12352 should_be_inserted is equivalent to
12353 unduplicated_should_be_inserted. */
12354 if (!should_be_inserted (bl) || bl->inserted)
12357 switch_to_program_space_and_thread (bl->pspace);
12359 target_download_tracepoint (bl);
12362 bp_location_downloaded = 1;
12364 t = (struct tracepoint *) b;
12365 t->number_on_target = b->number;
12366 if (bp_location_downloaded)
12367 observer_notify_breakpoint_modified (b);
12370 do_cleanups (old_chain);
12373 /* Swap the insertion/duplication state between two locations. */
12376 swap_insertion (struct bp_location *left, struct bp_location *right)
12378 const int left_inserted = left->inserted;
12379 const int left_duplicate = left->duplicate;
12380 const int left_needs_update = left->needs_update;
12381 const struct bp_target_info left_target_info = left->target_info;
12383 /* Locations of tracepoints can never be duplicated. */
12384 if (is_tracepoint (left->owner))
12385 gdb_assert (!left->duplicate);
12386 if (is_tracepoint (right->owner))
12387 gdb_assert (!right->duplicate);
12389 left->inserted = right->inserted;
12390 left->duplicate = right->duplicate;
12391 left->needs_update = right->needs_update;
12392 left->target_info = right->target_info;
12393 right->inserted = left_inserted;
12394 right->duplicate = left_duplicate;
12395 right->needs_update = left_needs_update;
12396 right->target_info = left_target_info;
12399 /* Force the re-insertion of the locations at ADDRESS. This is called
12400 once a new/deleted/modified duplicate location is found and we are evaluating
12401 conditions on the target's side. Such conditions need to be updated on
12405 force_breakpoint_reinsertion (struct bp_location *bl)
12407 struct bp_location **locp = NULL, **loc2p;
12408 struct bp_location *loc;
12409 CORE_ADDR address = 0;
12412 address = bl->address;
12413 pspace_num = bl->pspace->num;
12415 /* This is only meaningful if the target is
12416 evaluating conditions and if the user has
12417 opted for condition evaluation on the target's
12419 if (gdb_evaluates_breakpoint_condition_p ()
12420 || !target_supports_evaluation_of_breakpoint_conditions ())
12423 /* Flag all breakpoint locations with this address and
12424 the same program space as the location
12425 as "its condition has changed". We need to
12426 update the conditions on the target's side. */
12427 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address)
12431 if (!is_breakpoint (loc->owner)
12432 || pspace_num != loc->pspace->num)
12435 /* Flag the location appropriately. We use a different state to
12436 let everyone know that we already updated the set of locations
12437 with addr bl->address and program space bl->pspace. This is so
12438 we don't have to keep calling these functions just to mark locations
12439 that have already been marked. */
12440 loc->condition_changed = condition_updated;
12442 /* Free the agent expression bytecode as well. We will compute
12444 if (loc->cond_bytecode)
12446 free_agent_expr (loc->cond_bytecode);
12447 loc->cond_bytecode = NULL;
12452 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
12453 into the inferior, only remove already-inserted locations that no
12454 longer should be inserted. Functions that delete a breakpoint or
12455 breakpoints should pass false, so that deleting a breakpoint
12456 doesn't have the side effect of inserting the locations of other
12457 breakpoints that are marked not-inserted, but should_be_inserted
12458 returns true on them.
12460 This behaviour is useful is situations close to tear-down -- e.g.,
12461 after an exec, while the target still has execution, but breakpoint
12462 shadows of the previous executable image should *NOT* be restored
12463 to the new image; or before detaching, where the target still has
12464 execution and wants to delete breakpoints from GDB's lists, and all
12465 breakpoints had already been removed from the inferior. */
12468 update_global_location_list (int should_insert)
12470 struct breakpoint *b;
12471 struct bp_location **locp, *loc;
12472 struct cleanup *cleanups;
12473 /* Last breakpoint location address that was marked for update. */
12474 CORE_ADDR last_addr = 0;
12475 /* Last breakpoint location program space that was marked for update. */
12476 int last_pspace_num = -1;
12478 /* Used in the duplicates detection below. When iterating over all
12479 bp_locations, points to the first bp_location of a given address.
12480 Breakpoints and watchpoints of different types are never
12481 duplicates of each other. Keep one pointer for each type of
12482 breakpoint/watchpoint, so we only need to loop over all locations
12484 struct bp_location *bp_loc_first; /* breakpoint */
12485 struct bp_location *wp_loc_first; /* hardware watchpoint */
12486 struct bp_location *awp_loc_first; /* access watchpoint */
12487 struct bp_location *rwp_loc_first; /* read watchpoint */
12489 /* Saved former bp_location array which we compare against the newly
12490 built bp_location from the current state of ALL_BREAKPOINTS. */
12491 struct bp_location **old_location, **old_locp;
12492 unsigned old_location_count;
12494 old_location = bp_location;
12495 old_location_count = bp_location_count;
12496 bp_location = NULL;
12497 bp_location_count = 0;
12498 cleanups = make_cleanup (xfree, old_location);
12500 ALL_BREAKPOINTS (b)
12501 for (loc = b->loc; loc; loc = loc->next)
12502 bp_location_count++;
12504 bp_location = xmalloc (sizeof (*bp_location) * bp_location_count);
12505 locp = bp_location;
12506 ALL_BREAKPOINTS (b)
12507 for (loc = b->loc; loc; loc = loc->next)
12509 qsort (bp_location, bp_location_count, sizeof (*bp_location),
12510 bp_location_compare);
12512 bp_location_target_extensions_update ();
12514 /* Identify bp_location instances that are no longer present in the
12515 new list, and therefore should be freed. Note that it's not
12516 necessary that those locations should be removed from inferior --
12517 if there's another location at the same address (previously
12518 marked as duplicate), we don't need to remove/insert the
12521 LOCP is kept in sync with OLD_LOCP, each pointing to the current
12522 and former bp_location array state respectively. */
12524 locp = bp_location;
12525 for (old_locp = old_location; old_locp < old_location + old_location_count;
12528 struct bp_location *old_loc = *old_locp;
12529 struct bp_location **loc2p;
12531 /* Tells if 'old_loc' is found among the new locations. If
12532 not, we have to free it. */
12533 int found_object = 0;
12534 /* Tells if the location should remain inserted in the target. */
12535 int keep_in_target = 0;
12538 /* Skip LOCP entries which will definitely never be needed.
12539 Stop either at or being the one matching OLD_LOC. */
12540 while (locp < bp_location + bp_location_count
12541 && (*locp)->address < old_loc->address)
12545 (loc2p < bp_location + bp_location_count
12546 && (*loc2p)->address == old_loc->address);
12549 /* Check if this is a new/duplicated location or a duplicated
12550 location that had its condition modified. If so, we want to send
12551 its condition to the target if evaluation of conditions is taking
12553 if ((*loc2p)->condition_changed == condition_modified
12554 && (last_addr != old_loc->address
12555 || last_pspace_num != old_loc->pspace->num))
12557 force_breakpoint_reinsertion (*loc2p);
12558 last_pspace_num = old_loc->pspace->num;
12561 if (*loc2p == old_loc)
12565 /* We have already handled this address, update it so that we don't
12566 have to go through updates again. */
12567 last_addr = old_loc->address;
12569 /* Target-side condition evaluation: Handle deleted locations. */
12571 force_breakpoint_reinsertion (old_loc);
12573 /* If this location is no longer present, and inserted, look if
12574 there's maybe a new location at the same address. If so,
12575 mark that one inserted, and don't remove this one. This is
12576 needed so that we don't have a time window where a breakpoint
12577 at certain location is not inserted. */
12579 if (old_loc->inserted)
12581 /* If the location is inserted now, we might have to remove
12584 if (found_object && should_be_inserted (old_loc))
12586 /* The location is still present in the location list,
12587 and still should be inserted. Don't do anything. */
12588 keep_in_target = 1;
12592 /* This location still exists, but it won't be kept in the
12593 target since it may have been disabled. We proceed to
12594 remove its target-side condition. */
12596 /* The location is either no longer present, or got
12597 disabled. See if there's another location at the
12598 same address, in which case we don't need to remove
12599 this one from the target. */
12601 /* OLD_LOC comes from existing struct breakpoint. */
12602 if (breakpoint_address_is_meaningful (old_loc->owner))
12605 (loc2p < bp_location + bp_location_count
12606 && (*loc2p)->address == old_loc->address);
12609 struct bp_location *loc2 = *loc2p;
12611 if (breakpoint_locations_match (loc2, old_loc))
12613 /* Read watchpoint locations are switched to
12614 access watchpoints, if the former are not
12615 supported, but the latter are. */
12616 if (is_hardware_watchpoint (old_loc->owner))
12618 gdb_assert (is_hardware_watchpoint (loc2->owner));
12619 loc2->watchpoint_type = old_loc->watchpoint_type;
12622 /* loc2 is a duplicated location. We need to check
12623 if it should be inserted in case it will be
12625 if (loc2 != old_loc
12626 && unduplicated_should_be_inserted (loc2))
12628 swap_insertion (old_loc, loc2);
12629 keep_in_target = 1;
12637 if (!keep_in_target)
12639 if (remove_breakpoint (old_loc, mark_uninserted))
12641 /* This is just about all we can do. We could keep
12642 this location on the global list, and try to
12643 remove it next time, but there's no particular
12644 reason why we will succeed next time.
12646 Note that at this point, old_loc->owner is still
12647 valid, as delete_breakpoint frees the breakpoint
12648 only after calling us. */
12649 printf_filtered (_("warning: Error removing "
12650 "breakpoint %d\n"),
12651 old_loc->owner->number);
12659 if (removed && non_stop
12660 && breakpoint_address_is_meaningful (old_loc->owner)
12661 && !is_hardware_watchpoint (old_loc->owner))
12663 /* This location was removed from the target. In
12664 non-stop mode, a race condition is possible where
12665 we've removed a breakpoint, but stop events for that
12666 breakpoint are already queued and will arrive later.
12667 We apply an heuristic to be able to distinguish such
12668 SIGTRAPs from other random SIGTRAPs: we keep this
12669 breakpoint location for a bit, and will retire it
12670 after we see some number of events. The theory here
12671 is that reporting of events should, "on the average",
12672 be fair, so after a while we'll see events from all
12673 threads that have anything of interest, and no longer
12674 need to keep this breakpoint location around. We
12675 don't hold locations forever so to reduce chances of
12676 mistaking a non-breakpoint SIGTRAP for a breakpoint
12679 The heuristic failing can be disastrous on
12680 decr_pc_after_break targets.
12682 On decr_pc_after_break targets, like e.g., x86-linux,
12683 if we fail to recognize a late breakpoint SIGTRAP,
12684 because events_till_retirement has reached 0 too
12685 soon, we'll fail to do the PC adjustment, and report
12686 a random SIGTRAP to the user. When the user resumes
12687 the inferior, it will most likely immediately crash
12688 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12689 corrupted, because of being resumed e.g., in the
12690 middle of a multi-byte instruction, or skipped a
12691 one-byte instruction. This was actually seen happen
12692 on native x86-linux, and should be less rare on
12693 targets that do not support new thread events, like
12694 remote, due to the heuristic depending on
12697 Mistaking a random SIGTRAP for a breakpoint trap
12698 causes similar symptoms (PC adjustment applied when
12699 it shouldn't), but then again, playing with SIGTRAPs
12700 behind the debugger's back is asking for trouble.
12702 Since hardware watchpoint traps are always
12703 distinguishable from other traps, so we don't need to
12704 apply keep hardware watchpoint moribund locations
12705 around. We simply always ignore hardware watchpoint
12706 traps we can no longer explain. */
12708 old_loc->events_till_retirement = 3 * (thread_count () + 1);
12709 old_loc->owner = NULL;
12711 VEC_safe_push (bp_location_p, moribund_locations, old_loc);
12715 old_loc->owner = NULL;
12716 decref_bp_location (&old_loc);
12721 /* Rescan breakpoints at the same address and section, marking the
12722 first one as "first" and any others as "duplicates". This is so
12723 that the bpt instruction is only inserted once. If we have a
12724 permanent breakpoint at the same place as BPT, make that one the
12725 official one, and the rest as duplicates. Permanent breakpoints
12726 are sorted first for the same address.
12728 Do the same for hardware watchpoints, but also considering the
12729 watchpoint's type (regular/access/read) and length. */
12731 bp_loc_first = NULL;
12732 wp_loc_first = NULL;
12733 awp_loc_first = NULL;
12734 rwp_loc_first = NULL;
12735 ALL_BP_LOCATIONS (loc, locp)
12737 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12739 struct bp_location **loc_first_p;
12742 if (!unduplicated_should_be_inserted (loc)
12743 || !breakpoint_address_is_meaningful (b)
12744 /* Don't detect duplicate for tracepoint locations because they are
12745 never duplicated. See the comments in field `duplicate' of
12746 `struct bp_location'. */
12747 || is_tracepoint (b))
12749 /* Clear the condition modification flag. */
12750 loc->condition_changed = condition_unchanged;
12754 /* Permanent breakpoint should always be inserted. */
12755 if (b->enable_state == bp_permanent && ! loc->inserted)
12756 internal_error (__FILE__, __LINE__,
12757 _("allegedly permanent breakpoint is not "
12758 "actually inserted"));
12760 if (b->type == bp_hardware_watchpoint)
12761 loc_first_p = &wp_loc_first;
12762 else if (b->type == bp_read_watchpoint)
12763 loc_first_p = &rwp_loc_first;
12764 else if (b->type == bp_access_watchpoint)
12765 loc_first_p = &awp_loc_first;
12767 loc_first_p = &bp_loc_first;
12769 if (*loc_first_p == NULL
12770 || (overlay_debugging && loc->section != (*loc_first_p)->section)
12771 || !breakpoint_locations_match (loc, *loc_first_p))
12773 *loc_first_p = loc;
12774 loc->duplicate = 0;
12776 if (is_breakpoint (loc->owner) && loc->condition_changed)
12778 loc->needs_update = 1;
12779 /* Clear the condition modification flag. */
12780 loc->condition_changed = condition_unchanged;
12786 /* This and the above ensure the invariant that the first location
12787 is not duplicated, and is the inserted one.
12788 All following are marked as duplicated, and are not inserted. */
12790 swap_insertion (loc, *loc_first_p);
12791 loc->duplicate = 1;
12793 /* Clear the condition modification flag. */
12794 loc->condition_changed = condition_unchanged;
12796 if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted
12797 && b->enable_state != bp_permanent)
12798 internal_error (__FILE__, __LINE__,
12799 _("another breakpoint was inserted on top of "
12800 "a permanent breakpoint"));
12803 if (breakpoints_always_inserted_mode ()
12804 && (have_live_inferiors ()
12805 || (gdbarch_has_global_breakpoints (target_gdbarch ()))))
12808 insert_breakpoint_locations ();
12811 /* Though should_insert is false, we may need to update conditions
12812 on the target's side if it is evaluating such conditions. We
12813 only update conditions for locations that are marked
12815 update_inserted_breakpoint_locations ();
12820 download_tracepoint_locations ();
12822 do_cleanups (cleanups);
12826 breakpoint_retire_moribund (void)
12828 struct bp_location *loc;
12831 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
12832 if (--(loc->events_till_retirement) == 0)
12834 decref_bp_location (&loc);
12835 VEC_unordered_remove (bp_location_p, moribund_locations, ix);
12841 update_global_location_list_nothrow (int inserting)
12843 volatile struct gdb_exception e;
12845 TRY_CATCH (e, RETURN_MASK_ERROR)
12846 update_global_location_list (inserting);
12849 /* Clear BKP from a BPS. */
12852 bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt)
12856 for (bs = bps; bs; bs = bs->next)
12857 if (bs->breakpoint_at == bpt)
12859 bs->breakpoint_at = NULL;
12860 bs->old_val = NULL;
12861 /* bs->commands will be freed later. */
12865 /* Callback for iterate_over_threads. */
12867 bpstat_remove_breakpoint_callback (struct thread_info *th, void *data)
12869 struct breakpoint *bpt = data;
12871 bpstat_remove_bp_location (th->control.stop_bpstat, bpt);
12875 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12879 say_where (struct breakpoint *b)
12881 struct value_print_options opts;
12883 get_user_print_options (&opts);
12885 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12887 if (b->loc == NULL)
12889 printf_filtered (_(" (%s) pending."), b->addr_string);
12893 if (opts.addressprint || b->loc->symtab == NULL)
12895 printf_filtered (" at ");
12896 fputs_filtered (paddress (b->loc->gdbarch, b->loc->address),
12899 if (b->loc->symtab != NULL)
12901 /* If there is a single location, we can print the location
12903 if (b->loc->next == NULL)
12904 printf_filtered (": file %s, line %d.",
12905 symtab_to_filename_for_display (b->loc->symtab),
12906 b->loc->line_number);
12908 /* This is not ideal, but each location may have a
12909 different file name, and this at least reflects the
12910 real situation somewhat. */
12911 printf_filtered (": %s.", b->addr_string);
12916 struct bp_location *loc = b->loc;
12918 for (; loc; loc = loc->next)
12920 printf_filtered (" (%d locations)", n);
12925 /* Default bp_location_ops methods. */
12928 bp_location_dtor (struct bp_location *self)
12930 xfree (self->cond);
12931 if (self->cond_bytecode)
12932 free_agent_expr (self->cond_bytecode);
12933 xfree (self->function_name);
12935 VEC_free (agent_expr_p, self->target_info.conditions);
12936 VEC_free (agent_expr_p, self->target_info.tcommands);
12939 static const struct bp_location_ops bp_location_ops =
12944 /* Default breakpoint_ops methods all breakpoint_ops ultimately
12948 base_breakpoint_dtor (struct breakpoint *self)
12950 decref_counted_command_line (&self->commands);
12951 xfree (self->cond_string);
12952 xfree (self->extra_string);
12953 xfree (self->addr_string);
12954 xfree (self->filter);
12955 xfree (self->addr_string_range_end);
12958 static struct bp_location *
12959 base_breakpoint_allocate_location (struct breakpoint *self)
12961 struct bp_location *loc;
12963 loc = XNEW (struct bp_location);
12964 init_bp_location (loc, &bp_location_ops, self);
12969 base_breakpoint_re_set (struct breakpoint *b)
12971 /* Nothing to re-set. */
12974 #define internal_error_pure_virtual_called() \
12975 gdb_assert_not_reached ("pure virtual function called")
12978 base_breakpoint_insert_location (struct bp_location *bl)
12980 internal_error_pure_virtual_called ();
12984 base_breakpoint_remove_location (struct bp_location *bl)
12986 internal_error_pure_virtual_called ();
12990 base_breakpoint_breakpoint_hit (const struct bp_location *bl,
12991 struct address_space *aspace,
12993 const struct target_waitstatus *ws)
12995 internal_error_pure_virtual_called ();
12999 base_breakpoint_check_status (bpstat bs)
13004 /* A "works_in_software_mode" breakpoint_ops method that just internal
13008 base_breakpoint_works_in_software_mode (const struct breakpoint *b)
13010 internal_error_pure_virtual_called ();
13013 /* A "resources_needed" breakpoint_ops method that just internal
13017 base_breakpoint_resources_needed (const struct bp_location *bl)
13019 internal_error_pure_virtual_called ();
13022 static enum print_stop_action
13023 base_breakpoint_print_it (bpstat bs)
13025 internal_error_pure_virtual_called ();
13029 base_breakpoint_print_one_detail (const struct breakpoint *self,
13030 struct ui_out *uiout)
13036 base_breakpoint_print_mention (struct breakpoint *b)
13038 internal_error_pure_virtual_called ();
13042 base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp)
13044 internal_error_pure_virtual_called ();
13048 base_breakpoint_create_sals_from_address (char **arg,
13049 struct linespec_result *canonical,
13050 enum bptype type_wanted,
13054 internal_error_pure_virtual_called ();
13058 base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch,
13059 struct linespec_result *c,
13061 char *extra_string,
13062 enum bptype type_wanted,
13063 enum bpdisp disposition,
13065 int task, int ignore_count,
13066 const struct breakpoint_ops *o,
13067 int from_tty, int enabled,
13068 int internal, unsigned flags)
13070 internal_error_pure_virtual_called ();
13074 base_breakpoint_decode_linespec (struct breakpoint *b, char **s,
13075 struct symtabs_and_lines *sals)
13077 internal_error_pure_virtual_called ();
13080 /* The default 'explains_signal' method. */
13083 base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig)
13088 /* The default "after_condition_true" method. */
13091 base_breakpoint_after_condition_true (struct bpstats *bs)
13093 /* Nothing to do. */
13096 struct breakpoint_ops base_breakpoint_ops =
13098 base_breakpoint_dtor,
13099 base_breakpoint_allocate_location,
13100 base_breakpoint_re_set,
13101 base_breakpoint_insert_location,
13102 base_breakpoint_remove_location,
13103 base_breakpoint_breakpoint_hit,
13104 base_breakpoint_check_status,
13105 base_breakpoint_resources_needed,
13106 base_breakpoint_works_in_software_mode,
13107 base_breakpoint_print_it,
13109 base_breakpoint_print_one_detail,
13110 base_breakpoint_print_mention,
13111 base_breakpoint_print_recreate,
13112 base_breakpoint_create_sals_from_address,
13113 base_breakpoint_create_breakpoints_sal,
13114 base_breakpoint_decode_linespec,
13115 base_breakpoint_explains_signal,
13116 base_breakpoint_after_condition_true,
13119 /* Default breakpoint_ops methods. */
13122 bkpt_re_set (struct breakpoint *b)
13124 /* FIXME: is this still reachable? */
13125 if (b->addr_string == NULL)
13127 /* Anything without a string can't be re-set. */
13128 delete_breakpoint (b);
13132 breakpoint_re_set_default (b);
13135 /* Copy SRC's shadow buffer and whatever else we'd set if we actually
13136 inserted DEST, so we can remove it later, in case SRC is removed
13140 bp_target_info_copy_insertion_state (struct bp_target_info *dest,
13141 const struct bp_target_info *src)
13143 dest->shadow_len = src->shadow_len;
13144 memcpy (dest->shadow_contents, src->shadow_contents, src->shadow_len);
13145 dest->placed_size = src->placed_size;
13149 bkpt_insert_location (struct bp_location *bl)
13151 if (bl->loc_type == bp_loc_hardware_breakpoint)
13152 return target_insert_hw_breakpoint (bl->gdbarch,
13156 struct bp_target_info *bp_tgt = &bl->target_info;
13160 /* There is no need to insert a breakpoint if an unconditional
13161 raw/sss breakpoint is already inserted at that location. */
13162 sss_slot = find_single_step_breakpoint (bp_tgt->placed_address_space,
13163 bp_tgt->placed_address);
13166 struct bp_target_info *sss_bp_tgt = single_step_breakpoints[sss_slot];
13168 bp_target_info_copy_insertion_state (bp_tgt, sss_bp_tgt);
13172 return target_insert_breakpoint (bl->gdbarch, bp_tgt);
13177 bkpt_remove_location (struct bp_location *bl)
13179 if (bl->loc_type == bp_loc_hardware_breakpoint)
13180 return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info);
13183 struct bp_target_info *bp_tgt = &bl->target_info;
13184 struct address_space *aspace = bp_tgt->placed_address_space;
13185 CORE_ADDR address = bp_tgt->placed_address;
13187 /* Only remove the breakpoint if there is no raw/sss breakpoint
13188 still inserted at this location. Otherwise, we would be
13189 effectively disabling the raw/sss breakpoint. */
13190 if (single_step_breakpoint_inserted_here_p (aspace, address))
13193 return target_remove_breakpoint (bl->gdbarch, bp_tgt);
13198 bkpt_breakpoint_hit (const struct bp_location *bl,
13199 struct address_space *aspace, CORE_ADDR bp_addr,
13200 const struct target_waitstatus *ws)
13202 if (ws->kind != TARGET_WAITKIND_STOPPED
13203 || ws->value.sig != GDB_SIGNAL_TRAP)
13206 if (!breakpoint_address_match (bl->pspace->aspace, bl->address,
13210 if (overlay_debugging /* unmapped overlay section */
13211 && section_is_overlay (bl->section)
13212 && !section_is_mapped (bl->section))
13219 dprintf_breakpoint_hit (const struct bp_location *bl,
13220 struct address_space *aspace, CORE_ADDR bp_addr,
13221 const struct target_waitstatus *ws)
13223 if (dprintf_style == dprintf_style_agent
13224 && target_can_run_breakpoint_commands ())
13226 /* An agent-style dprintf never causes a stop. If we see a trap
13227 for this address it must be for a breakpoint that happens to
13228 be set at the same address. */
13232 return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws);
13236 bkpt_resources_needed (const struct bp_location *bl)
13238 gdb_assert (bl->owner->type == bp_hardware_breakpoint);
13243 static enum print_stop_action
13244 bkpt_print_it (bpstat bs)
13246 struct breakpoint *b;
13247 const struct bp_location *bl;
13249 struct ui_out *uiout = current_uiout;
13251 gdb_assert (bs->bp_location_at != NULL);
13253 bl = bs->bp_location_at;
13254 b = bs->breakpoint_at;
13256 bp_temp = b->disposition == disp_del;
13257 if (bl->address != bl->requested_address)
13258 breakpoint_adjustment_warning (bl->requested_address,
13261 annotate_breakpoint (b->number);
13263 ui_out_text (uiout, "\nTemporary breakpoint ");
13265 ui_out_text (uiout, "\nBreakpoint ");
13266 if (ui_out_is_mi_like_p (uiout))
13268 ui_out_field_string (uiout, "reason",
13269 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
13270 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
13272 ui_out_field_int (uiout, "bkptno", b->number);
13273 ui_out_text (uiout, ", ");
13275 return PRINT_SRC_AND_LOC;
13279 bkpt_print_mention (struct breakpoint *b)
13281 if (ui_out_is_mi_like_p (current_uiout))
13286 case bp_breakpoint:
13287 case bp_gnu_ifunc_resolver:
13288 if (b->disposition == disp_del)
13289 printf_filtered (_("Temporary breakpoint"));
13291 printf_filtered (_("Breakpoint"));
13292 printf_filtered (_(" %d"), b->number);
13293 if (b->type == bp_gnu_ifunc_resolver)
13294 printf_filtered (_(" at gnu-indirect-function resolver"));
13296 case bp_hardware_breakpoint:
13297 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
13300 printf_filtered (_("Dprintf %d"), b->number);
13308 bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp)
13310 if (tp->type == bp_breakpoint && tp->disposition == disp_del)
13311 fprintf_unfiltered (fp, "tbreak");
13312 else if (tp->type == bp_breakpoint)
13313 fprintf_unfiltered (fp, "break");
13314 else if (tp->type == bp_hardware_breakpoint
13315 && tp->disposition == disp_del)
13316 fprintf_unfiltered (fp, "thbreak");
13317 else if (tp->type == bp_hardware_breakpoint)
13318 fprintf_unfiltered (fp, "hbreak");
13320 internal_error (__FILE__, __LINE__,
13321 _("unhandled breakpoint type %d"), (int) tp->type);
13323 fprintf_unfiltered (fp, " %s", tp->addr_string);
13324 print_recreate_thread (tp, fp);
13328 bkpt_create_sals_from_address (char **arg,
13329 struct linespec_result *canonical,
13330 enum bptype type_wanted,
13331 char *addr_start, char **copy_arg)
13333 create_sals_from_address_default (arg, canonical, type_wanted,
13334 addr_start, copy_arg);
13338 bkpt_create_breakpoints_sal (struct gdbarch *gdbarch,
13339 struct linespec_result *canonical,
13341 char *extra_string,
13342 enum bptype type_wanted,
13343 enum bpdisp disposition,
13345 int task, int ignore_count,
13346 const struct breakpoint_ops *ops,
13347 int from_tty, int enabled,
13348 int internal, unsigned flags)
13350 create_breakpoints_sal_default (gdbarch, canonical,
13351 cond_string, extra_string,
13353 disposition, thread, task,
13354 ignore_count, ops, from_tty,
13355 enabled, internal, flags);
13359 bkpt_decode_linespec (struct breakpoint *b, char **s,
13360 struct symtabs_and_lines *sals)
13362 decode_linespec_default (b, s, sals);
13365 /* Virtual table for internal breakpoints. */
13368 internal_bkpt_re_set (struct breakpoint *b)
13372 /* Delete overlay event and longjmp master breakpoints; they
13373 will be reset later by breakpoint_re_set. */
13374 case bp_overlay_event:
13375 case bp_longjmp_master:
13376 case bp_std_terminate_master:
13377 case bp_exception_master:
13378 delete_breakpoint (b);
13381 /* This breakpoint is special, it's set up when the inferior
13382 starts and we really don't want to touch it. */
13383 case bp_shlib_event:
13385 /* Like bp_shlib_event, this breakpoint type is special. Once
13386 it is set up, we do not want to touch it. */
13387 case bp_thread_event:
13393 internal_bkpt_check_status (bpstat bs)
13395 if (bs->breakpoint_at->type == bp_shlib_event)
13397 /* If requested, stop when the dynamic linker notifies GDB of
13398 events. This allows the user to get control and place
13399 breakpoints in initializer routines for dynamically loaded
13400 objects (among other things). */
13401 bs->stop = stop_on_solib_events;
13402 bs->print = stop_on_solib_events;
13408 static enum print_stop_action
13409 internal_bkpt_print_it (bpstat bs)
13411 struct breakpoint *b;
13413 b = bs->breakpoint_at;
13417 case bp_shlib_event:
13418 /* Did we stop because the user set the stop_on_solib_events
13419 variable? (If so, we report this as a generic, "Stopped due
13420 to shlib event" message.) */
13421 print_solib_event (0);
13424 case bp_thread_event:
13425 /* Not sure how we will get here.
13426 GDB should not stop for these breakpoints. */
13427 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
13430 case bp_overlay_event:
13431 /* By analogy with the thread event, GDB should not stop for these. */
13432 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
13435 case bp_longjmp_master:
13436 /* These should never be enabled. */
13437 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
13440 case bp_std_terminate_master:
13441 /* These should never be enabled. */
13442 printf_filtered (_("std::terminate Master Breakpoint: "
13443 "gdb should not stop!\n"));
13446 case bp_exception_master:
13447 /* These should never be enabled. */
13448 printf_filtered (_("Exception Master Breakpoint: "
13449 "gdb should not stop!\n"));
13453 return PRINT_NOTHING;
13457 internal_bkpt_print_mention (struct breakpoint *b)
13459 /* Nothing to mention. These breakpoints are internal. */
13462 /* Virtual table for momentary breakpoints */
13465 momentary_bkpt_re_set (struct breakpoint *b)
13467 /* Keep temporary breakpoints, which can be encountered when we step
13468 over a dlopen call and solib_add is resetting the breakpoints.
13469 Otherwise these should have been blown away via the cleanup chain
13470 or by breakpoint_init_inferior when we rerun the executable. */
13474 momentary_bkpt_check_status (bpstat bs)
13476 /* Nothing. The point of these breakpoints is causing a stop. */
13479 static enum print_stop_action
13480 momentary_bkpt_print_it (bpstat bs)
13482 struct ui_out *uiout = current_uiout;
13484 if (ui_out_is_mi_like_p (uiout))
13486 struct breakpoint *b = bs->breakpoint_at;
13491 ui_out_field_string
13493 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED));
13497 ui_out_field_string
13499 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED));
13504 return PRINT_UNKNOWN;
13508 momentary_bkpt_print_mention (struct breakpoint *b)
13510 /* Nothing to mention. These breakpoints are internal. */
13513 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
13515 It gets cleared already on the removal of the first one of such placed
13516 breakpoints. This is OK as they get all removed altogether. */
13519 longjmp_bkpt_dtor (struct breakpoint *self)
13521 struct thread_info *tp = find_thread_id (self->thread);
13524 tp->initiating_frame = null_frame_id;
13526 momentary_breakpoint_ops.dtor (self);
13529 /* Specific methods for probe breakpoints. */
13532 bkpt_probe_insert_location (struct bp_location *bl)
13534 int v = bkpt_insert_location (bl);
13538 /* The insertion was successful, now let's set the probe's semaphore
13540 bl->probe.probe->pops->set_semaphore (bl->probe.probe,
13549 bkpt_probe_remove_location (struct bp_location *bl)
13551 /* Let's clear the semaphore before removing the location. */
13552 bl->probe.probe->pops->clear_semaphore (bl->probe.probe,
13556 return bkpt_remove_location (bl);
13560 bkpt_probe_create_sals_from_address (char **arg,
13561 struct linespec_result *canonical,
13562 enum bptype type_wanted,
13563 char *addr_start, char **copy_arg)
13565 struct linespec_sals lsal;
13567 lsal.sals = parse_probes (arg, canonical);
13569 *copy_arg = xstrdup (canonical->addr_string);
13570 lsal.canonical = xstrdup (*copy_arg);
13572 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
13576 bkpt_probe_decode_linespec (struct breakpoint *b, char **s,
13577 struct symtabs_and_lines *sals)
13579 *sals = parse_probes (s, NULL);
13581 error (_("probe not found"));
13584 /* The breakpoint_ops structure to be used in tracepoints. */
13587 tracepoint_re_set (struct breakpoint *b)
13589 breakpoint_re_set_default (b);
13593 tracepoint_breakpoint_hit (const struct bp_location *bl,
13594 struct address_space *aspace, CORE_ADDR bp_addr,
13595 const struct target_waitstatus *ws)
13597 /* By definition, the inferior does not report stops at
13603 tracepoint_print_one_detail (const struct breakpoint *self,
13604 struct ui_out *uiout)
13606 struct tracepoint *tp = (struct tracepoint *) self;
13607 if (tp->static_trace_marker_id)
13609 gdb_assert (self->type == bp_static_tracepoint);
13611 ui_out_text (uiout, "\tmarker id is ");
13612 ui_out_field_string (uiout, "static-tracepoint-marker-string-id",
13613 tp->static_trace_marker_id);
13614 ui_out_text (uiout, "\n");
13619 tracepoint_print_mention (struct breakpoint *b)
13621 if (ui_out_is_mi_like_p (current_uiout))
13626 case bp_tracepoint:
13627 printf_filtered (_("Tracepoint"));
13628 printf_filtered (_(" %d"), b->number);
13630 case bp_fast_tracepoint:
13631 printf_filtered (_("Fast tracepoint"));
13632 printf_filtered (_(" %d"), b->number);
13634 case bp_static_tracepoint:
13635 printf_filtered (_("Static tracepoint"));
13636 printf_filtered (_(" %d"), b->number);
13639 internal_error (__FILE__, __LINE__,
13640 _("unhandled tracepoint type %d"), (int) b->type);
13647 tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp)
13649 struct tracepoint *tp = (struct tracepoint *) self;
13651 if (self->type == bp_fast_tracepoint)
13652 fprintf_unfiltered (fp, "ftrace");
13653 if (self->type == bp_static_tracepoint)
13654 fprintf_unfiltered (fp, "strace");
13655 else if (self->type == bp_tracepoint)
13656 fprintf_unfiltered (fp, "trace");
13658 internal_error (__FILE__, __LINE__,
13659 _("unhandled tracepoint type %d"), (int) self->type);
13661 fprintf_unfiltered (fp, " %s", self->addr_string);
13662 print_recreate_thread (self, fp);
13664 if (tp->pass_count)
13665 fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count);
13669 tracepoint_create_sals_from_address (char **arg,
13670 struct linespec_result *canonical,
13671 enum bptype type_wanted,
13672 char *addr_start, char **copy_arg)
13674 create_sals_from_address_default (arg, canonical, type_wanted,
13675 addr_start, copy_arg);
13679 tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch,
13680 struct linespec_result *canonical,
13682 char *extra_string,
13683 enum bptype type_wanted,
13684 enum bpdisp disposition,
13686 int task, int ignore_count,
13687 const struct breakpoint_ops *ops,
13688 int from_tty, int enabled,
13689 int internal, unsigned flags)
13691 create_breakpoints_sal_default (gdbarch, canonical,
13692 cond_string, extra_string,
13694 disposition, thread, task,
13695 ignore_count, ops, from_tty,
13696 enabled, internal, flags);
13700 tracepoint_decode_linespec (struct breakpoint *b, char **s,
13701 struct symtabs_and_lines *sals)
13703 decode_linespec_default (b, s, sals);
13706 struct breakpoint_ops tracepoint_breakpoint_ops;
13708 /* The breakpoint_ops structure to be use on tracepoints placed in a
13712 tracepoint_probe_create_sals_from_address (char **arg,
13713 struct linespec_result *canonical,
13714 enum bptype type_wanted,
13715 char *addr_start, char **copy_arg)
13717 /* We use the same method for breakpoint on probes. */
13718 bkpt_probe_create_sals_from_address (arg, canonical, type_wanted,
13719 addr_start, copy_arg);
13723 tracepoint_probe_decode_linespec (struct breakpoint *b, char **s,
13724 struct symtabs_and_lines *sals)
13726 /* We use the same method for breakpoint on probes. */
13727 bkpt_probe_decode_linespec (b, s, sals);
13730 static struct breakpoint_ops tracepoint_probe_breakpoint_ops;
13732 /* Dprintf breakpoint_ops methods. */
13735 dprintf_re_set (struct breakpoint *b)
13737 breakpoint_re_set_default (b);
13739 /* This breakpoint could have been pending, and be resolved now, and
13740 if so, we should now have the extra string. If we don't, the
13741 dprintf was malformed when created, but we couldn't tell because
13742 we can't extract the extra string until the location is
13744 if (b->loc != NULL && b->extra_string == NULL)
13745 error (_("Format string required"));
13747 /* 1 - connect to target 1, that can run breakpoint commands.
13748 2 - create a dprintf, which resolves fine.
13749 3 - disconnect from target 1
13750 4 - connect to target 2, that can NOT run breakpoint commands.
13752 After steps #3/#4, you'll want the dprintf command list to
13753 be updated, because target 1 and 2 may well return different
13754 answers for target_can_run_breakpoint_commands().
13755 Given absence of finer grained resetting, we get to do
13756 it all the time. */
13757 if (b->extra_string != NULL)
13758 update_dprintf_command_list (b);
13761 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13764 dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp)
13766 fprintf_unfiltered (fp, "dprintf %s%s", tp->addr_string,
13768 print_recreate_thread (tp, fp);
13771 /* Implement the "after_condition_true" breakpoint_ops method for
13774 dprintf's are implemented with regular commands in their command
13775 list, but we run the commands here instead of before presenting the
13776 stop to the user, as dprintf's don't actually cause a stop. This
13777 also makes it so that the commands of multiple dprintfs at the same
13778 address are all handled. */
13781 dprintf_after_condition_true (struct bpstats *bs)
13783 struct cleanup *old_chain;
13784 struct bpstats tmp_bs = { NULL };
13785 struct bpstats *tmp_bs_p = &tmp_bs;
13787 /* dprintf's never cause a stop. This wasn't set in the
13788 check_status hook instead because that would make the dprintf's
13789 condition not be evaluated. */
13792 /* Run the command list here. Take ownership of it instead of
13793 copying. We never want these commands to run later in
13794 bpstat_do_actions, if a breakpoint that causes a stop happens to
13795 be set at same address as this dprintf, or even if running the
13796 commands here throws. */
13797 tmp_bs.commands = bs->commands;
13798 bs->commands = NULL;
13799 old_chain = make_cleanup_decref_counted_command_line (&tmp_bs.commands);
13801 bpstat_do_actions_1 (&tmp_bs_p);
13803 /* 'tmp_bs.commands' will usually be NULL by now, but
13804 bpstat_do_actions_1 may return early without processing the whole
13806 do_cleanups (old_chain);
13809 /* The breakpoint_ops structure to be used on static tracepoints with
13813 strace_marker_create_sals_from_address (char **arg,
13814 struct linespec_result *canonical,
13815 enum bptype type_wanted,
13816 char *addr_start, char **copy_arg)
13818 struct linespec_sals lsal;
13820 lsal.sals = decode_static_tracepoint_spec (arg);
13822 *copy_arg = savestring (addr_start, *arg - addr_start);
13824 canonical->addr_string = xstrdup (*copy_arg);
13825 lsal.canonical = xstrdup (*copy_arg);
13826 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
13830 strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch,
13831 struct linespec_result *canonical,
13833 char *extra_string,
13834 enum bptype type_wanted,
13835 enum bpdisp disposition,
13837 int task, int ignore_count,
13838 const struct breakpoint_ops *ops,
13839 int from_tty, int enabled,
13840 int internal, unsigned flags)
13843 struct linespec_sals *lsal = VEC_index (linespec_sals,
13844 canonical->sals, 0);
13846 /* If the user is creating a static tracepoint by marker id
13847 (strace -m MARKER_ID), then store the sals index, so that
13848 breakpoint_re_set can try to match up which of the newly
13849 found markers corresponds to this one, and, don't try to
13850 expand multiple locations for each sal, given than SALS
13851 already should contain all sals for MARKER_ID. */
13853 for (i = 0; i < lsal->sals.nelts; ++i)
13855 struct symtabs_and_lines expanded;
13856 struct tracepoint *tp;
13857 struct cleanup *old_chain;
13860 expanded.nelts = 1;
13861 expanded.sals = &lsal->sals.sals[i];
13863 addr_string = xstrdup (canonical->addr_string);
13864 old_chain = make_cleanup (xfree, addr_string);
13866 tp = XCNEW (struct tracepoint);
13867 init_breakpoint_sal (&tp->base, gdbarch, expanded,
13869 cond_string, extra_string,
13870 type_wanted, disposition,
13871 thread, task, ignore_count, ops,
13872 from_tty, enabled, internal, flags,
13873 canonical->special_display);
13874 /* Given that its possible to have multiple markers with
13875 the same string id, if the user is creating a static
13876 tracepoint by marker id ("strace -m MARKER_ID"), then
13877 store the sals index, so that breakpoint_re_set can
13878 try to match up which of the newly found markers
13879 corresponds to this one */
13880 tp->static_trace_marker_id_idx = i;
13882 install_breakpoint (internal, &tp->base, 0);
13884 discard_cleanups (old_chain);
13889 strace_marker_decode_linespec (struct breakpoint *b, char **s,
13890 struct symtabs_and_lines *sals)
13892 struct tracepoint *tp = (struct tracepoint *) b;
13894 *sals = decode_static_tracepoint_spec (s);
13895 if (sals->nelts > tp->static_trace_marker_id_idx)
13897 sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx];
13901 error (_("marker %s not found"), tp->static_trace_marker_id);
13904 static struct breakpoint_ops strace_marker_breakpoint_ops;
13907 strace_marker_p (struct breakpoint *b)
13909 return b->ops == &strace_marker_breakpoint_ops;
13912 /* Delete a breakpoint and clean up all traces of it in the data
13916 delete_breakpoint (struct breakpoint *bpt)
13918 struct breakpoint *b;
13920 gdb_assert (bpt != NULL);
13922 /* Has this bp already been deleted? This can happen because
13923 multiple lists can hold pointers to bp's. bpstat lists are
13926 One example of this happening is a watchpoint's scope bp. When
13927 the scope bp triggers, we notice that the watchpoint is out of
13928 scope, and delete it. We also delete its scope bp. But the
13929 scope bp is marked "auto-deleting", and is already on a bpstat.
13930 That bpstat is then checked for auto-deleting bp's, which are
13933 A real solution to this problem might involve reference counts in
13934 bp's, and/or giving them pointers back to their referencing
13935 bpstat's, and teaching delete_breakpoint to only free a bp's
13936 storage when no more references were extent. A cheaper bandaid
13938 if (bpt->type == bp_none)
13941 /* At least avoid this stale reference until the reference counting
13942 of breakpoints gets resolved. */
13943 if (bpt->related_breakpoint != bpt)
13945 struct breakpoint *related;
13946 struct watchpoint *w;
13948 if (bpt->type == bp_watchpoint_scope)
13949 w = (struct watchpoint *) bpt->related_breakpoint;
13950 else if (bpt->related_breakpoint->type == bp_watchpoint_scope)
13951 w = (struct watchpoint *) bpt;
13955 watchpoint_del_at_next_stop (w);
13957 /* Unlink bpt from the bpt->related_breakpoint ring. */
13958 for (related = bpt; related->related_breakpoint != bpt;
13959 related = related->related_breakpoint);
13960 related->related_breakpoint = bpt->related_breakpoint;
13961 bpt->related_breakpoint = bpt;
13964 /* watch_command_1 creates a watchpoint but only sets its number if
13965 update_watchpoint succeeds in creating its bp_locations. If there's
13966 a problem in that process, we'll be asked to delete the half-created
13967 watchpoint. In that case, don't announce the deletion. */
13969 observer_notify_breakpoint_deleted (bpt);
13971 if (breakpoint_chain == bpt)
13972 breakpoint_chain = bpt->next;
13974 ALL_BREAKPOINTS (b)
13975 if (b->next == bpt)
13977 b->next = bpt->next;
13981 /* Be sure no bpstat's are pointing at the breakpoint after it's
13983 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13984 in all threads for now. Note that we cannot just remove bpstats
13985 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13986 commands are associated with the bpstat; if we remove it here,
13987 then the later call to bpstat_do_actions (&stop_bpstat); in
13988 event-top.c won't do anything, and temporary breakpoints with
13989 commands won't work. */
13991 iterate_over_threads (bpstat_remove_breakpoint_callback, bpt);
13993 /* Now that breakpoint is removed from breakpoint list, update the
13994 global location list. This will remove locations that used to
13995 belong to this breakpoint. Do this before freeing the breakpoint
13996 itself, since remove_breakpoint looks at location's owner. It
13997 might be better design to have location completely
13998 self-contained, but it's not the case now. */
13999 update_global_location_list (0);
14001 bpt->ops->dtor (bpt);
14002 /* On the chance that someone will soon try again to delete this
14003 same bp, we mark it as deleted before freeing its storage. */
14004 bpt->type = bp_none;
14009 do_delete_breakpoint_cleanup (void *b)
14011 delete_breakpoint (b);
14015 make_cleanup_delete_breakpoint (struct breakpoint *b)
14017 return make_cleanup (do_delete_breakpoint_cleanup, b);
14020 /* Iterator function to call a user-provided callback function once
14021 for each of B and its related breakpoints. */
14024 iterate_over_related_breakpoints (struct breakpoint *b,
14025 void (*function) (struct breakpoint *,
14029 struct breakpoint *related;
14034 struct breakpoint *next;
14036 /* FUNCTION may delete RELATED. */
14037 next = related->related_breakpoint;
14039 if (next == related)
14041 /* RELATED is the last ring entry. */
14042 function (related, data);
14044 /* FUNCTION may have deleted it, so we'd never reach back to
14045 B. There's nothing left to do anyway, so just break
14050 function (related, data);
14054 while (related != b);
14058 do_delete_breakpoint (struct breakpoint *b, void *ignore)
14060 delete_breakpoint (b);
14063 /* A callback for map_breakpoint_numbers that calls
14064 delete_breakpoint. */
14067 do_map_delete_breakpoint (struct breakpoint *b, void *ignore)
14069 iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL);
14073 delete_command (char *arg, int from_tty)
14075 struct breakpoint *b, *b_tmp;
14081 int breaks_to_delete = 0;
14083 /* Delete all breakpoints if no argument. Do not delete
14084 internal breakpoints, these have to be deleted with an
14085 explicit breakpoint number argument. */
14086 ALL_BREAKPOINTS (b)
14087 if (user_breakpoint_p (b))
14089 breaks_to_delete = 1;
14093 /* Ask user only if there are some breakpoints to delete. */
14095 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
14097 ALL_BREAKPOINTS_SAFE (b, b_tmp)
14098 if (user_breakpoint_p (b))
14099 delete_breakpoint (b);
14103 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
14107 all_locations_are_pending (struct bp_location *loc)
14109 for (; loc; loc = loc->next)
14110 if (!loc->shlib_disabled
14111 && !loc->pspace->executing_startup)
14116 /* Subroutine of update_breakpoint_locations to simplify it.
14117 Return non-zero if multiple fns in list LOC have the same name.
14118 Null names are ignored. */
14121 ambiguous_names_p (struct bp_location *loc)
14123 struct bp_location *l;
14124 htab_t htab = htab_create_alloc (13, htab_hash_string,
14125 (int (*) (const void *,
14126 const void *)) streq,
14127 NULL, xcalloc, xfree);
14129 for (l = loc; l != NULL; l = l->next)
14132 const char *name = l->function_name;
14134 /* Allow for some names to be NULL, ignore them. */
14138 slot = (const char **) htab_find_slot (htab, (const void *) name,
14140 /* NOTE: We can assume slot != NULL here because xcalloc never
14144 htab_delete (htab);
14150 htab_delete (htab);
14154 /* When symbols change, it probably means the sources changed as well,
14155 and it might mean the static tracepoint markers are no longer at
14156 the same address or line numbers they used to be at last we
14157 checked. Losing your static tracepoints whenever you rebuild is
14158 undesirable. This function tries to resync/rematch gdb static
14159 tracepoints with the markers on the target, for static tracepoints
14160 that have not been set by marker id. Static tracepoint that have
14161 been set by marker id are reset by marker id in breakpoint_re_set.
14164 1) For a tracepoint set at a specific address, look for a marker at
14165 the old PC. If one is found there, assume to be the same marker.
14166 If the name / string id of the marker found is different from the
14167 previous known name, assume that means the user renamed the marker
14168 in the sources, and output a warning.
14170 2) For a tracepoint set at a given line number, look for a marker
14171 at the new address of the old line number. If one is found there,
14172 assume to be the same marker. If the name / string id of the
14173 marker found is different from the previous known name, assume that
14174 means the user renamed the marker in the sources, and output a
14177 3) If a marker is no longer found at the same address or line, it
14178 may mean the marker no longer exists. But it may also just mean
14179 the code changed a bit. Maybe the user added a few lines of code
14180 that made the marker move up or down (in line number terms). Ask
14181 the target for info about the marker with the string id as we knew
14182 it. If found, update line number and address in the matching
14183 static tracepoint. This will get confused if there's more than one
14184 marker with the same ID (possible in UST, although unadvised
14185 precisely because it confuses tools). */
14187 static struct symtab_and_line
14188 update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal)
14190 struct tracepoint *tp = (struct tracepoint *) b;
14191 struct static_tracepoint_marker marker;
14196 find_line_pc (sal.symtab, sal.line, &pc);
14198 if (target_static_tracepoint_marker_at (pc, &marker))
14200 if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0)
14201 warning (_("static tracepoint %d changed probed marker from %s to %s"),
14203 tp->static_trace_marker_id, marker.str_id);
14205 xfree (tp->static_trace_marker_id);
14206 tp->static_trace_marker_id = xstrdup (marker.str_id);
14207 release_static_tracepoint_marker (&marker);
14212 /* Old marker wasn't found on target at lineno. Try looking it up
14214 if (!sal.explicit_pc
14216 && sal.symtab != NULL
14217 && tp->static_trace_marker_id != NULL)
14219 VEC(static_tracepoint_marker_p) *markers;
14222 = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id);
14224 if (!VEC_empty(static_tracepoint_marker_p, markers))
14226 struct symtab_and_line sal2;
14227 struct symbol *sym;
14228 struct static_tracepoint_marker *tpmarker;
14229 struct ui_out *uiout = current_uiout;
14231 tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0);
14233 xfree (tp->static_trace_marker_id);
14234 tp->static_trace_marker_id = xstrdup (tpmarker->str_id);
14236 warning (_("marker for static tracepoint %d (%s) not "
14237 "found at previous line number"),
14238 b->number, tp->static_trace_marker_id);
14242 sal2.pc = tpmarker->address;
14244 sal2 = find_pc_line (tpmarker->address, 0);
14245 sym = find_pc_sect_function (tpmarker->address, NULL);
14246 ui_out_text (uiout, "Now in ");
14249 ui_out_field_string (uiout, "func",
14250 SYMBOL_PRINT_NAME (sym));
14251 ui_out_text (uiout, " at ");
14253 ui_out_field_string (uiout, "file",
14254 symtab_to_filename_for_display (sal2.symtab));
14255 ui_out_text (uiout, ":");
14257 if (ui_out_is_mi_like_p (uiout))
14259 const char *fullname = symtab_to_fullname (sal2.symtab);
14261 ui_out_field_string (uiout, "fullname", fullname);
14264 ui_out_field_int (uiout, "line", sal2.line);
14265 ui_out_text (uiout, "\n");
14267 b->loc->line_number = sal2.line;
14268 b->loc->symtab = sym != NULL ? sal2.symtab : NULL;
14270 xfree (b->addr_string);
14271 b->addr_string = xstrprintf ("%s:%d",
14272 symtab_to_filename_for_display (sal2.symtab),
14273 b->loc->line_number);
14275 /* Might be nice to check if function changed, and warn if
14278 release_static_tracepoint_marker (tpmarker);
14284 /* Returns 1 iff locations A and B are sufficiently same that
14285 we don't need to report breakpoint as changed. */
14288 locations_are_equal (struct bp_location *a, struct bp_location *b)
14292 if (a->address != b->address)
14295 if (a->shlib_disabled != b->shlib_disabled)
14298 if (a->enabled != b->enabled)
14305 if ((a == NULL) != (b == NULL))
14311 /* Create new breakpoint locations for B (a hardware or software breakpoint)
14312 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
14313 a ranged breakpoint. */
14316 update_breakpoint_locations (struct breakpoint *b,
14317 struct symtabs_and_lines sals,
14318 struct symtabs_and_lines sals_end)
14321 struct bp_location *existing_locations = b->loc;
14323 if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1))
14325 /* Ranged breakpoints have only one start location and one end
14327 b->enable_state = bp_disabled;
14328 update_global_location_list (1);
14329 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
14330 "multiple locations found\n"),
14335 /* If there's no new locations, and all existing locations are
14336 pending, don't do anything. This optimizes the common case where
14337 all locations are in the same shared library, that was unloaded.
14338 We'd like to retain the location, so that when the library is
14339 loaded again, we don't loose the enabled/disabled status of the
14340 individual locations. */
14341 if (all_locations_are_pending (existing_locations) && sals.nelts == 0)
14346 for (i = 0; i < sals.nelts; ++i)
14348 struct bp_location *new_loc;
14350 switch_to_program_space_and_thread (sals.sals[i].pspace);
14352 new_loc = add_location_to_breakpoint (b, &(sals.sals[i]));
14354 /* Reparse conditions, they might contain references to the
14356 if (b->cond_string != NULL)
14359 volatile struct gdb_exception e;
14361 s = b->cond_string;
14362 TRY_CATCH (e, RETURN_MASK_ERROR)
14364 new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc,
14365 block_for_pc (sals.sals[i].pc),
14370 warning (_("failed to reevaluate condition "
14371 "for breakpoint %d: %s"),
14372 b->number, e.message);
14373 new_loc->enabled = 0;
14377 if (sals_end.nelts)
14379 CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]);
14381 new_loc->length = end - sals.sals[0].pc + 1;
14385 /* Update locations of permanent breakpoints. */
14386 if (b->enable_state == bp_permanent)
14387 make_breakpoint_permanent (b);
14389 /* If possible, carry over 'disable' status from existing
14392 struct bp_location *e = existing_locations;
14393 /* If there are multiple breakpoints with the same function name,
14394 e.g. for inline functions, comparing function names won't work.
14395 Instead compare pc addresses; this is just a heuristic as things
14396 may have moved, but in practice it gives the correct answer
14397 often enough until a better solution is found. */
14398 int have_ambiguous_names = ambiguous_names_p (b->loc);
14400 for (; e; e = e->next)
14402 if (!e->enabled && e->function_name)
14404 struct bp_location *l = b->loc;
14405 if (have_ambiguous_names)
14407 for (; l; l = l->next)
14408 if (breakpoint_locations_match (e, l))
14416 for (; l; l = l->next)
14417 if (l->function_name
14418 && strcmp (e->function_name, l->function_name) == 0)
14428 if (!locations_are_equal (existing_locations, b->loc))
14429 observer_notify_breakpoint_modified (b);
14431 update_global_location_list (1);
14434 /* Find the SaL locations corresponding to the given ADDR_STRING.
14435 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
14437 static struct symtabs_and_lines
14438 addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found)
14441 struct symtabs_and_lines sals = {0};
14442 volatile struct gdb_exception e;
14444 gdb_assert (b->ops != NULL);
14447 TRY_CATCH (e, RETURN_MASK_ERROR)
14449 b->ops->decode_linespec (b, &s, &sals);
14453 int not_found_and_ok = 0;
14454 /* For pending breakpoints, it's expected that parsing will
14455 fail until the right shared library is loaded. User has
14456 already told to create pending breakpoints and don't need
14457 extra messages. If breakpoint is in bp_shlib_disabled
14458 state, then user already saw the message about that
14459 breakpoint being disabled, and don't want to see more
14461 if (e.error == NOT_FOUND_ERROR
14462 && (b->condition_not_parsed
14463 || (b->loc && b->loc->shlib_disabled)
14464 || (b->loc && b->loc->pspace->executing_startup)
14465 || b->enable_state == bp_disabled))
14466 not_found_and_ok = 1;
14468 if (!not_found_and_ok)
14470 /* We surely don't want to warn about the same breakpoint
14471 10 times. One solution, implemented here, is disable
14472 the breakpoint on error. Another solution would be to
14473 have separate 'warning emitted' flag. Since this
14474 happens only when a binary has changed, I don't know
14475 which approach is better. */
14476 b->enable_state = bp_disabled;
14477 throw_exception (e);
14481 if (e.reason == 0 || e.error != NOT_FOUND_ERROR)
14485 for (i = 0; i < sals.nelts; ++i)
14486 resolve_sal_pc (&sals.sals[i]);
14487 if (b->condition_not_parsed && s && s[0])
14489 char *cond_string, *extra_string;
14492 find_condition_and_thread (s, sals.sals[0].pc,
14493 &cond_string, &thread, &task,
14496 b->cond_string = cond_string;
14497 b->thread = thread;
14500 b->extra_string = extra_string;
14501 b->condition_not_parsed = 0;
14504 if (b->type == bp_static_tracepoint && !strace_marker_p (b))
14505 sals.sals[0] = update_static_tracepoint (b, sals.sals[0]);
14515 /* The default re_set method, for typical hardware or software
14516 breakpoints. Reevaluate the breakpoint and recreate its
14520 breakpoint_re_set_default (struct breakpoint *b)
14523 struct symtabs_and_lines sals, sals_end;
14524 struct symtabs_and_lines expanded = {0};
14525 struct symtabs_and_lines expanded_end = {0};
14527 sals = addr_string_to_sals (b, b->addr_string, &found);
14530 make_cleanup (xfree, sals.sals);
14534 if (b->addr_string_range_end)
14536 sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found);
14539 make_cleanup (xfree, sals_end.sals);
14540 expanded_end = sals_end;
14544 update_breakpoint_locations (b, expanded, expanded_end);
14547 /* Default method for creating SALs from an address string. It basically
14548 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
14551 create_sals_from_address_default (char **arg,
14552 struct linespec_result *canonical,
14553 enum bptype type_wanted,
14554 char *addr_start, char **copy_arg)
14556 parse_breakpoint_sals (arg, canonical);
14559 /* Call create_breakpoints_sal for the given arguments. This is the default
14560 function for the `create_breakpoints_sal' method of
14564 create_breakpoints_sal_default (struct gdbarch *gdbarch,
14565 struct linespec_result *canonical,
14567 char *extra_string,
14568 enum bptype type_wanted,
14569 enum bpdisp disposition,
14571 int task, int ignore_count,
14572 const struct breakpoint_ops *ops,
14573 int from_tty, int enabled,
14574 int internal, unsigned flags)
14576 create_breakpoints_sal (gdbarch, canonical, cond_string,
14578 type_wanted, disposition,
14579 thread, task, ignore_count, ops, from_tty,
14580 enabled, internal, flags);
14583 /* Decode the line represented by S by calling decode_line_full. This is the
14584 default function for the `decode_linespec' method of breakpoint_ops. */
14587 decode_linespec_default (struct breakpoint *b, char **s,
14588 struct symtabs_and_lines *sals)
14590 struct linespec_result canonical;
14592 init_linespec_result (&canonical);
14593 decode_line_full (s, DECODE_LINE_FUNFIRSTLINE,
14594 (struct symtab *) NULL, 0,
14595 &canonical, multiple_symbols_all,
14598 /* We should get 0 or 1 resulting SALs. */
14599 gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2);
14601 if (VEC_length (linespec_sals, canonical.sals) > 0)
14603 struct linespec_sals *lsal;
14605 lsal = VEC_index (linespec_sals, canonical.sals, 0);
14606 *sals = lsal->sals;
14607 /* Arrange it so the destructor does not free the
14609 lsal->sals.sals = NULL;
14612 destroy_linespec_result (&canonical);
14615 /* Prepare the global context for a re-set of breakpoint B. */
14617 static struct cleanup *
14618 prepare_re_set_context (struct breakpoint *b)
14620 struct cleanup *cleanups;
14622 input_radix = b->input_radix;
14623 cleanups = save_current_space_and_thread ();
14624 if (b->pspace != NULL)
14625 switch_to_program_space_and_thread (b->pspace);
14626 set_language (b->language);
14631 /* Reset a breakpoint given it's struct breakpoint * BINT.
14632 The value we return ends up being the return value from catch_errors.
14633 Unused in this case. */
14636 breakpoint_re_set_one (void *bint)
14638 /* Get past catch_errs. */
14639 struct breakpoint *b = (struct breakpoint *) bint;
14640 struct cleanup *cleanups;
14642 cleanups = prepare_re_set_context (b);
14643 b->ops->re_set (b);
14644 do_cleanups (cleanups);
14648 /* Re-set all breakpoints after symbols have been re-loaded. */
14650 breakpoint_re_set (void)
14652 struct breakpoint *b, *b_tmp;
14653 enum language save_language;
14654 int save_input_radix;
14655 struct cleanup *old_chain;
14657 save_language = current_language->la_language;
14658 save_input_radix = input_radix;
14659 old_chain = save_current_program_space ();
14661 ALL_BREAKPOINTS_SAFE (b, b_tmp)
14663 /* Format possible error msg. */
14664 char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
14666 struct cleanup *cleanups = make_cleanup (xfree, message);
14667 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
14668 do_cleanups (cleanups);
14670 set_language (save_language);
14671 input_radix = save_input_radix;
14673 jit_breakpoint_re_set ();
14675 do_cleanups (old_chain);
14677 create_overlay_event_breakpoint ();
14678 create_longjmp_master_breakpoint ();
14679 create_std_terminate_master_breakpoint ();
14680 create_exception_master_breakpoint ();
14683 /* Reset the thread number of this breakpoint:
14685 - If the breakpoint is for all threads, leave it as-is.
14686 - Else, reset it to the current thread for inferior_ptid. */
14688 breakpoint_re_set_thread (struct breakpoint *b)
14690 if (b->thread != -1)
14692 if (in_thread_list (inferior_ptid))
14693 b->thread = pid_to_thread_id (inferior_ptid);
14695 /* We're being called after following a fork. The new fork is
14696 selected as current, and unless this was a vfork will have a
14697 different program space from the original thread. Reset that
14699 b->loc->pspace = current_program_space;
14703 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14704 If from_tty is nonzero, it prints a message to that effect,
14705 which ends with a period (no newline). */
14708 set_ignore_count (int bptnum, int count, int from_tty)
14710 struct breakpoint *b;
14715 ALL_BREAKPOINTS (b)
14716 if (b->number == bptnum)
14718 if (is_tracepoint (b))
14720 if (from_tty && count != 0)
14721 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14726 b->ignore_count = count;
14730 printf_filtered (_("Will stop next time "
14731 "breakpoint %d is reached."),
14733 else if (count == 1)
14734 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14737 printf_filtered (_("Will ignore next %d "
14738 "crossings of breakpoint %d."),
14741 observer_notify_breakpoint_modified (b);
14745 error (_("No breakpoint number %d."), bptnum);
14748 /* Command to set ignore-count of breakpoint N to COUNT. */
14751 ignore_command (char *args, int from_tty)
14757 error_no_arg (_("a breakpoint number"));
14759 num = get_number (&p);
14761 error (_("bad breakpoint number: '%s'"), args);
14763 error (_("Second argument (specified ignore-count) is missing."));
14765 set_ignore_count (num,
14766 longest_to_int (value_as_long (parse_and_eval (p))),
14769 printf_filtered ("\n");
14772 /* Call FUNCTION on each of the breakpoints
14773 whose numbers are given in ARGS. */
14776 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *,
14781 struct breakpoint *b, *tmp;
14783 struct get_number_or_range_state state;
14786 error_no_arg (_("one or more breakpoint numbers"));
14788 init_number_or_range (&state, args);
14790 while (!state.finished)
14792 char *p = state.string;
14796 num = get_number_or_range (&state);
14799 warning (_("bad breakpoint number at or near '%s'"), p);
14803 ALL_BREAKPOINTS_SAFE (b, tmp)
14804 if (b->number == num)
14807 function (b, data);
14811 printf_unfiltered (_("No breakpoint number %d.\n"), num);
14816 static struct bp_location *
14817 find_location_by_number (char *number)
14819 char *dot = strchr (number, '.');
14823 struct breakpoint *b;
14824 struct bp_location *loc;
14829 bp_num = get_number (&p1);
14831 error (_("Bad breakpoint number '%s'"), number);
14833 ALL_BREAKPOINTS (b)
14834 if (b->number == bp_num)
14839 if (!b || b->number != bp_num)
14840 error (_("Bad breakpoint number '%s'"), number);
14843 loc_num = get_number (&p1);
14845 error (_("Bad breakpoint location number '%s'"), number);
14849 for (;loc_num && loc; --loc_num, loc = loc->next)
14852 error (_("Bad breakpoint location number '%s'"), dot+1);
14858 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14859 If from_tty is nonzero, it prints a message to that effect,
14860 which ends with a period (no newline). */
14863 disable_breakpoint (struct breakpoint *bpt)
14865 /* Never disable a watchpoint scope breakpoint; we want to
14866 hit them when we leave scope so we can delete both the
14867 watchpoint and its scope breakpoint at that time. */
14868 if (bpt->type == bp_watchpoint_scope)
14871 /* You can't disable permanent breakpoints. */
14872 if (bpt->enable_state == bp_permanent)
14875 bpt->enable_state = bp_disabled;
14877 /* Mark breakpoint locations modified. */
14878 mark_breakpoint_modified (bpt);
14880 if (target_supports_enable_disable_tracepoint ()
14881 && current_trace_status ()->running && is_tracepoint (bpt))
14883 struct bp_location *location;
14885 for (location = bpt->loc; location; location = location->next)
14886 target_disable_tracepoint (location);
14889 update_global_location_list (0);
14891 observer_notify_breakpoint_modified (bpt);
14894 /* A callback for iterate_over_related_breakpoints. */
14897 do_disable_breakpoint (struct breakpoint *b, void *ignore)
14899 disable_breakpoint (b);
14902 /* A callback for map_breakpoint_numbers that calls
14903 disable_breakpoint. */
14906 do_map_disable_breakpoint (struct breakpoint *b, void *ignore)
14908 iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL);
14912 disable_command (char *args, int from_tty)
14916 struct breakpoint *bpt;
14918 ALL_BREAKPOINTS (bpt)
14919 if (user_breakpoint_p (bpt))
14920 disable_breakpoint (bpt);
14924 char *num = extract_arg (&args);
14928 if (strchr (num, '.'))
14930 struct bp_location *loc = find_location_by_number (num);
14937 mark_breakpoint_location_modified (loc);
14939 if (target_supports_enable_disable_tracepoint ()
14940 && current_trace_status ()->running && loc->owner
14941 && is_tracepoint (loc->owner))
14942 target_disable_tracepoint (loc);
14944 update_global_location_list (0);
14947 map_breakpoint_numbers (num, do_map_disable_breakpoint, NULL);
14948 num = extract_arg (&args);
14954 enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition,
14957 int target_resources_ok;
14959 if (bpt->type == bp_hardware_breakpoint)
14962 i = hw_breakpoint_used_count ();
14963 target_resources_ok =
14964 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
14966 if (target_resources_ok == 0)
14967 error (_("No hardware breakpoint support in the target."));
14968 else if (target_resources_ok < 0)
14969 error (_("Hardware breakpoints used exceeds limit."));
14972 if (is_watchpoint (bpt))
14974 /* Initialize it just to avoid a GCC false warning. */
14975 enum enable_state orig_enable_state = 0;
14976 volatile struct gdb_exception e;
14978 TRY_CATCH (e, RETURN_MASK_ALL)
14980 struct watchpoint *w = (struct watchpoint *) bpt;
14982 orig_enable_state = bpt->enable_state;
14983 bpt->enable_state = bp_enabled;
14984 update_watchpoint (w, 1 /* reparse */);
14988 bpt->enable_state = orig_enable_state;
14989 exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
14995 if (bpt->enable_state != bp_permanent)
14996 bpt->enable_state = bp_enabled;
14998 bpt->enable_state = bp_enabled;
15000 /* Mark breakpoint locations modified. */
15001 mark_breakpoint_modified (bpt);
15003 if (target_supports_enable_disable_tracepoint ()
15004 && current_trace_status ()->running && is_tracepoint (bpt))
15006 struct bp_location *location;
15008 for (location = bpt->loc; location; location = location->next)
15009 target_enable_tracepoint (location);
15012 bpt->disposition = disposition;
15013 bpt->enable_count = count;
15014 update_global_location_list (1);
15016 observer_notify_breakpoint_modified (bpt);
15021 enable_breakpoint (struct breakpoint *bpt)
15023 enable_breakpoint_disp (bpt, bpt->disposition, 0);
15027 do_enable_breakpoint (struct breakpoint *bpt, void *arg)
15029 enable_breakpoint (bpt);
15032 /* A callback for map_breakpoint_numbers that calls
15033 enable_breakpoint. */
15036 do_map_enable_breakpoint (struct breakpoint *b, void *ignore)
15038 iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL);
15041 /* The enable command enables the specified breakpoints (or all defined
15042 breakpoints) so they once again become (or continue to be) effective
15043 in stopping the inferior. */
15046 enable_command (char *args, int from_tty)
15050 struct breakpoint *bpt;
15052 ALL_BREAKPOINTS (bpt)
15053 if (user_breakpoint_p (bpt))
15054 enable_breakpoint (bpt);
15058 char *num = extract_arg (&args);
15062 if (strchr (num, '.'))
15064 struct bp_location *loc = find_location_by_number (num);
15071 mark_breakpoint_location_modified (loc);
15073 if (target_supports_enable_disable_tracepoint ()
15074 && current_trace_status ()->running && loc->owner
15075 && is_tracepoint (loc->owner))
15076 target_enable_tracepoint (loc);
15078 update_global_location_list (1);
15081 map_breakpoint_numbers (num, do_map_enable_breakpoint, NULL);
15082 num = extract_arg (&args);
15087 /* This struct packages up disposition data for application to multiple
15097 do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg)
15099 struct disp_data disp_data = *(struct disp_data *) arg;
15101 enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count);
15105 do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore)
15107 struct disp_data disp = { disp_disable, 1 };
15109 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
15113 enable_once_command (char *args, int from_tty)
15115 map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL);
15119 do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr)
15121 struct disp_data disp = { disp_disable, *(int *) countptr };
15123 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
15127 enable_count_command (char *args, int from_tty)
15129 int count = get_number (&args);
15131 map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count);
15135 do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore)
15137 struct disp_data disp = { disp_del, 1 };
15139 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
15143 enable_delete_command (char *args, int from_tty)
15145 map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL);
15149 set_breakpoint_cmd (char *args, int from_tty)
15154 show_breakpoint_cmd (char *args, int from_tty)
15158 /* Invalidate last known value of any hardware watchpoint if
15159 the memory which that value represents has been written to by
15163 invalidate_bp_value_on_memory_change (struct inferior *inferior,
15164 CORE_ADDR addr, ssize_t len,
15165 const bfd_byte *data)
15167 struct breakpoint *bp;
15169 ALL_BREAKPOINTS (bp)
15170 if (bp->enable_state == bp_enabled
15171 && bp->type == bp_hardware_watchpoint)
15173 struct watchpoint *wp = (struct watchpoint *) bp;
15175 if (wp->val_valid && wp->val)
15177 struct bp_location *loc;
15179 for (loc = bp->loc; loc != NULL; loc = loc->next)
15180 if (loc->loc_type == bp_loc_hardware_watchpoint
15181 && loc->address + loc->length > addr
15182 && addr + len > loc->address)
15184 value_free (wp->val);
15192 /* Create and insert a raw software breakpoint at PC. Return an
15193 identifier, which should be used to remove the breakpoint later.
15194 In general, places which call this should be using something on the
15195 breakpoint chain instead; this function should be eliminated
15199 deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch,
15200 struct address_space *aspace, CORE_ADDR pc)
15202 struct bp_target_info *bp_tgt;
15203 struct bp_location *bl;
15205 bp_tgt = XCNEW (struct bp_target_info);
15207 bp_tgt->placed_address_space = aspace;
15208 bp_tgt->placed_address = pc;
15210 /* If an unconditional non-raw breakpoint is already inserted at
15211 that location, there's no need to insert another. However, with
15212 target-side evaluation of breakpoint conditions, if the
15213 breakpoint that is currently inserted on the target is
15214 conditional, we need to make it unconditional. Note that a
15215 breakpoint with target-side commands is not reported even if
15216 unconditional, so we need to remove the commands from the target
15218 bl = find_non_raw_software_breakpoint_inserted_here (aspace, pc);
15220 && VEC_empty (agent_expr_p, bl->target_info.conditions)
15221 && VEC_empty (agent_expr_p, bl->target_info.tcommands))
15223 bp_target_info_copy_insertion_state (bp_tgt, &bl->target_info);
15227 if (target_insert_breakpoint (gdbarch, bp_tgt) != 0)
15229 /* Could not insert the breakpoint. */
15237 /* Remove a breakpoint BP inserted by
15238 deprecated_insert_raw_breakpoint. */
15241 deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp)
15243 struct bp_target_info *bp_tgt = bp;
15244 struct address_space *aspace = bp_tgt->placed_address_space;
15245 CORE_ADDR address = bp_tgt->placed_address;
15246 struct bp_location *bl;
15249 bl = find_non_raw_software_breakpoint_inserted_here (aspace, address);
15251 /* Only remove the raw breakpoint if there are no other non-raw
15252 breakpoints still inserted at this location. Otherwise, we would
15253 be effectively disabling those breakpoints. */
15255 ret = target_remove_breakpoint (gdbarch, bp_tgt);
15256 else if (!VEC_empty (agent_expr_p, bl->target_info.conditions)
15257 || !VEC_empty (agent_expr_p, bl->target_info.tcommands))
15259 /* The target is evaluating conditions, and when we inserted the
15260 software single-step breakpoint, we had made the breakpoint
15261 unconditional and command-less on the target side. Reinsert
15262 to restore the conditions/commands. */
15263 ret = target_insert_breakpoint (bl->gdbarch, &bl->target_info);
15273 /* Create and insert a breakpoint for software single step. */
15276 insert_single_step_breakpoint (struct gdbarch *gdbarch,
15277 struct address_space *aspace,
15282 if (single_step_breakpoints[0] == NULL)
15284 bpt_p = &single_step_breakpoints[0];
15285 single_step_gdbarch[0] = gdbarch;
15289 gdb_assert (single_step_breakpoints[1] == NULL);
15290 bpt_p = &single_step_breakpoints[1];
15291 single_step_gdbarch[1] = gdbarch;
15294 /* NOTE drow/2006-04-11: A future improvement to this function would
15295 be to only create the breakpoints once, and actually put them on
15296 the breakpoint chain. That would let us use set_raw_breakpoint.
15297 We could adjust the addresses each time they were needed. Doing
15298 this requires corresponding changes elsewhere where single step
15299 breakpoints are handled, however. So, for now, we use this. */
15301 *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc);
15302 if (*bpt_p == NULL)
15303 error (_("Could not insert single-step breakpoint at %s"),
15304 paddress (gdbarch, next_pc));
15307 /* Check if the breakpoints used for software single stepping
15308 were inserted or not. */
15311 single_step_breakpoints_inserted (void)
15313 return (single_step_breakpoints[0] != NULL
15314 || single_step_breakpoints[1] != NULL);
15317 /* Remove and delete any breakpoints used for software single step. */
15320 remove_single_step_breakpoints (void)
15322 gdb_assert (single_step_breakpoints[0] != NULL);
15324 /* See insert_single_step_breakpoint for more about this deprecated
15326 deprecated_remove_raw_breakpoint (single_step_gdbarch[0],
15327 single_step_breakpoints[0]);
15328 single_step_gdbarch[0] = NULL;
15329 single_step_breakpoints[0] = NULL;
15331 if (single_step_breakpoints[1] != NULL)
15333 deprecated_remove_raw_breakpoint (single_step_gdbarch[1],
15334 single_step_breakpoints[1]);
15335 single_step_gdbarch[1] = NULL;
15336 single_step_breakpoints[1] = NULL;
15340 /* Delete software single step breakpoints without removing them from
15341 the inferior. This is intended to be used if the inferior's address
15342 space where they were inserted is already gone, e.g. after exit or
15346 cancel_single_step_breakpoints (void)
15350 for (i = 0; i < 2; i++)
15351 if (single_step_breakpoints[i])
15353 xfree (single_step_breakpoints[i]);
15354 single_step_breakpoints[i] = NULL;
15355 single_step_gdbarch[i] = NULL;
15359 /* Detach software single-step breakpoints from INFERIOR_PTID without
15363 detach_single_step_breakpoints (void)
15367 for (i = 0; i < 2; i++)
15368 if (single_step_breakpoints[i])
15369 target_remove_breakpoint (single_step_gdbarch[i],
15370 single_step_breakpoints[i]);
15373 /* Find the software single-step breakpoint that inserted at PC.
15374 Returns its slot if found, and -1 if not found. */
15377 find_single_step_breakpoint (struct address_space *aspace,
15382 for (i = 0; i < 2; i++)
15384 struct bp_target_info *bp_tgt = single_step_breakpoints[i];
15386 && breakpoint_address_match (bp_tgt->placed_address_space,
15387 bp_tgt->placed_address,
15395 /* Check whether a software single-step breakpoint is inserted at
15399 single_step_breakpoint_inserted_here_p (struct address_space *aspace,
15402 return find_single_step_breakpoint (aspace, pc) >= 0;
15405 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
15406 non-zero otherwise. */
15408 is_syscall_catchpoint_enabled (struct breakpoint *bp)
15410 if (syscall_catchpoint_p (bp)
15411 && bp->enable_state != bp_disabled
15412 && bp->enable_state != bp_call_disabled)
15419 catch_syscall_enabled (void)
15421 struct catch_syscall_inferior_data *inf_data
15422 = get_catch_syscall_inferior_data (current_inferior ());
15424 return inf_data->total_syscalls_count != 0;
15428 catching_syscall_number (int syscall_number)
15430 struct breakpoint *bp;
15432 ALL_BREAKPOINTS (bp)
15433 if (is_syscall_catchpoint_enabled (bp))
15435 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp;
15437 if (c->syscalls_to_be_caught)
15441 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
15443 if (syscall_number == iter)
15453 /* Complete syscall names. Used by "catch syscall". */
15454 static VEC (char_ptr) *
15455 catch_syscall_completer (struct cmd_list_element *cmd,
15456 const char *text, const char *word)
15458 const char **list = get_syscall_names ();
15459 VEC (char_ptr) *retlist
15460 = (list == NULL) ? NULL : complete_on_enum (list, word, word);
15466 /* Tracepoint-specific operations. */
15468 /* Set tracepoint count to NUM. */
15470 set_tracepoint_count (int num)
15472 tracepoint_count = num;
15473 set_internalvar_integer (lookup_internalvar ("tpnum"), num);
15477 trace_command (char *arg, int from_tty)
15479 struct breakpoint_ops *ops;
15480 const char *arg_cp = arg;
15482 if (arg && probe_linespec_to_ops (&arg_cp))
15483 ops = &tracepoint_probe_breakpoint_ops;
15485 ops = &tracepoint_breakpoint_ops;
15487 create_breakpoint (get_current_arch (),
15489 NULL, 0, NULL, 1 /* parse arg */,
15491 bp_tracepoint /* type_wanted */,
15492 0 /* Ignore count */,
15493 pending_break_support,
15497 0 /* internal */, 0);
15501 ftrace_command (char *arg, int from_tty)
15503 create_breakpoint (get_current_arch (),
15505 NULL, 0, NULL, 1 /* parse arg */,
15507 bp_fast_tracepoint /* type_wanted */,
15508 0 /* Ignore count */,
15509 pending_break_support,
15510 &tracepoint_breakpoint_ops,
15513 0 /* internal */, 0);
15516 /* strace command implementation. Creates a static tracepoint. */
15519 strace_command (char *arg, int from_tty)
15521 struct breakpoint_ops *ops;
15523 /* Decide if we are dealing with a static tracepoint marker (`-m'),
15524 or with a normal static tracepoint. */
15525 if (arg && strncmp (arg, "-m", 2) == 0 && isspace (arg[2]))
15526 ops = &strace_marker_breakpoint_ops;
15528 ops = &tracepoint_breakpoint_ops;
15530 create_breakpoint (get_current_arch (),
15532 NULL, 0, NULL, 1 /* parse arg */,
15534 bp_static_tracepoint /* type_wanted */,
15535 0 /* Ignore count */,
15536 pending_break_support,
15540 0 /* internal */, 0);
15543 /* Set up a fake reader function that gets command lines from a linked
15544 list that was acquired during tracepoint uploading. */
15546 static struct uploaded_tp *this_utp;
15547 static int next_cmd;
15550 read_uploaded_action (void)
15554 VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt);
15561 /* Given information about a tracepoint as recorded on a target (which
15562 can be either a live system or a trace file), attempt to create an
15563 equivalent GDB tracepoint. This is not a reliable process, since
15564 the target does not necessarily have all the information used when
15565 the tracepoint was originally defined. */
15567 struct tracepoint *
15568 create_tracepoint_from_upload (struct uploaded_tp *utp)
15570 char *addr_str, small_buf[100];
15571 struct tracepoint *tp;
15573 if (utp->at_string)
15574 addr_str = utp->at_string;
15577 /* In the absence of a source location, fall back to raw
15578 address. Since there is no way to confirm that the address
15579 means the same thing as when the trace was started, warn the
15581 warning (_("Uploaded tracepoint %d has no "
15582 "source location, using raw address"),
15584 xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr));
15585 addr_str = small_buf;
15588 /* There's not much we can do with a sequence of bytecodes. */
15589 if (utp->cond && !utp->cond_string)
15590 warning (_("Uploaded tracepoint %d condition "
15591 "has no source form, ignoring it"),
15594 if (!create_breakpoint (get_current_arch (),
15596 utp->cond_string, -1, NULL,
15597 0 /* parse cond/thread */,
15599 utp->type /* type_wanted */,
15600 0 /* Ignore count */,
15601 pending_break_support,
15602 &tracepoint_breakpoint_ops,
15604 utp->enabled /* enabled */,
15606 CREATE_BREAKPOINT_FLAGS_INSERTED))
15609 /* Get the tracepoint we just created. */
15610 tp = get_tracepoint (tracepoint_count);
15611 gdb_assert (tp != NULL);
15615 xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass,
15618 trace_pass_command (small_buf, 0);
15621 /* If we have uploaded versions of the original commands, set up a
15622 special-purpose "reader" function and call the usual command line
15623 reader, then pass the result to the breakpoint command-setting
15625 if (!VEC_empty (char_ptr, utp->cmd_strings))
15627 struct command_line *cmd_list;
15632 cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL);
15634 breakpoint_set_commands (&tp->base, cmd_list);
15636 else if (!VEC_empty (char_ptr, utp->actions)
15637 || !VEC_empty (char_ptr, utp->step_actions))
15638 warning (_("Uploaded tracepoint %d actions "
15639 "have no source form, ignoring them"),
15642 /* Copy any status information that might be available. */
15643 tp->base.hit_count = utp->hit_count;
15644 tp->traceframe_usage = utp->traceframe_usage;
15649 /* Print information on tracepoint number TPNUM_EXP, or all if
15653 tracepoints_info (char *args, int from_tty)
15655 struct ui_out *uiout = current_uiout;
15658 num_printed = breakpoint_1 (args, 0, is_tracepoint);
15660 if (num_printed == 0)
15662 if (args == NULL || *args == '\0')
15663 ui_out_message (uiout, 0, "No tracepoints.\n");
15665 ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args);
15668 default_collect_info ();
15671 /* The 'enable trace' command enables tracepoints.
15672 Not supported by all targets. */
15674 enable_trace_command (char *args, int from_tty)
15676 enable_command (args, from_tty);
15679 /* The 'disable trace' command disables tracepoints.
15680 Not supported by all targets. */
15682 disable_trace_command (char *args, int from_tty)
15684 disable_command (args, from_tty);
15687 /* Remove a tracepoint (or all if no argument). */
15689 delete_trace_command (char *arg, int from_tty)
15691 struct breakpoint *b, *b_tmp;
15697 int breaks_to_delete = 0;
15699 /* Delete all breakpoints if no argument.
15700 Do not delete internal or call-dummy breakpoints, these
15701 have to be deleted with an explicit breakpoint number
15703 ALL_TRACEPOINTS (b)
15704 if (is_tracepoint (b) && user_breakpoint_p (b))
15706 breaks_to_delete = 1;
15710 /* Ask user only if there are some breakpoints to delete. */
15712 || (breaks_to_delete && query (_("Delete all tracepoints? "))))
15714 ALL_BREAKPOINTS_SAFE (b, b_tmp)
15715 if (is_tracepoint (b) && user_breakpoint_p (b))
15716 delete_breakpoint (b);
15720 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
15723 /* Helper function for trace_pass_command. */
15726 trace_pass_set_count (struct tracepoint *tp, int count, int from_tty)
15728 tp->pass_count = count;
15729 observer_notify_breakpoint_modified (&tp->base);
15731 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15732 tp->base.number, count);
15735 /* Set passcount for tracepoint.
15737 First command argument is passcount, second is tracepoint number.
15738 If tracepoint number omitted, apply to most recently defined.
15739 Also accepts special argument "all". */
15742 trace_pass_command (char *args, int from_tty)
15744 struct tracepoint *t1;
15745 unsigned int count;
15747 if (args == 0 || *args == 0)
15748 error (_("passcount command requires an "
15749 "argument (count + optional TP num)"));
15751 count = strtoul (args, &args, 10); /* Count comes first, then TP num. */
15753 args = skip_spaces (args);
15754 if (*args && strncasecmp (args, "all", 3) == 0)
15756 struct breakpoint *b;
15758 args += 3; /* Skip special argument "all". */
15760 error (_("Junk at end of arguments."));
15762 ALL_TRACEPOINTS (b)
15764 t1 = (struct tracepoint *) b;
15765 trace_pass_set_count (t1, count, from_tty);
15768 else if (*args == '\0')
15770 t1 = get_tracepoint_by_number (&args, NULL);
15772 trace_pass_set_count (t1, count, from_tty);
15776 struct get_number_or_range_state state;
15778 init_number_or_range (&state, args);
15779 while (!state.finished)
15781 t1 = get_tracepoint_by_number (&args, &state);
15783 trace_pass_set_count (t1, count, from_tty);
15788 struct tracepoint *
15789 get_tracepoint (int num)
15791 struct breakpoint *t;
15793 ALL_TRACEPOINTS (t)
15794 if (t->number == num)
15795 return (struct tracepoint *) t;
15800 /* Find the tracepoint with the given target-side number (which may be
15801 different from the tracepoint number after disconnecting and
15804 struct tracepoint *
15805 get_tracepoint_by_number_on_target (int num)
15807 struct breakpoint *b;
15809 ALL_TRACEPOINTS (b)
15811 struct tracepoint *t = (struct tracepoint *) b;
15813 if (t->number_on_target == num)
15820 /* Utility: parse a tracepoint number and look it up in the list.
15821 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15822 If the argument is missing, the most recent tracepoint
15823 (tracepoint_count) is returned. */
15825 struct tracepoint *
15826 get_tracepoint_by_number (char **arg,
15827 struct get_number_or_range_state *state)
15829 struct breakpoint *t;
15831 char *instring = arg == NULL ? NULL : *arg;
15835 gdb_assert (!state->finished);
15836 tpnum = get_number_or_range (state);
15838 else if (arg == NULL || *arg == NULL || ! **arg)
15839 tpnum = tracepoint_count;
15841 tpnum = get_number (arg);
15845 if (instring && *instring)
15846 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15849 printf_filtered (_("No previous tracepoint\n"));
15853 ALL_TRACEPOINTS (t)
15854 if (t->number == tpnum)
15856 return (struct tracepoint *) t;
15859 printf_unfiltered ("No tracepoint number %d.\n", tpnum);
15864 print_recreate_thread (struct breakpoint *b, struct ui_file *fp)
15866 if (b->thread != -1)
15867 fprintf_unfiltered (fp, " thread %d", b->thread);
15870 fprintf_unfiltered (fp, " task %d", b->task);
15872 fprintf_unfiltered (fp, "\n");
15875 /* Save information on user settable breakpoints (watchpoints, etc) to
15876 a new script file named FILENAME. If FILTER is non-NULL, call it
15877 on each breakpoint and only include the ones for which it returns
15881 save_breakpoints (char *filename, int from_tty,
15882 int (*filter) (const struct breakpoint *))
15884 struct breakpoint *tp;
15886 struct cleanup *cleanup;
15887 struct ui_file *fp;
15888 int extra_trace_bits = 0;
15890 if (filename == 0 || *filename == 0)
15891 error (_("Argument required (file name in which to save)"));
15893 /* See if we have anything to save. */
15894 ALL_BREAKPOINTS (tp)
15896 /* Skip internal and momentary breakpoints. */
15897 if (!user_breakpoint_p (tp))
15900 /* If we have a filter, only save the breakpoints it accepts. */
15901 if (filter && !filter (tp))
15906 if (is_tracepoint (tp))
15908 extra_trace_bits = 1;
15910 /* We can stop searching. */
15917 warning (_("Nothing to save."));
15921 filename = tilde_expand (filename);
15922 cleanup = make_cleanup (xfree, filename);
15923 fp = gdb_fopen (filename, "w");
15925 error (_("Unable to open file '%s' for saving (%s)"),
15926 filename, safe_strerror (errno));
15927 make_cleanup_ui_file_delete (fp);
15929 if (extra_trace_bits)
15930 save_trace_state_variables (fp);
15932 ALL_BREAKPOINTS (tp)
15934 /* Skip internal and momentary breakpoints. */
15935 if (!user_breakpoint_p (tp))
15938 /* If we have a filter, only save the breakpoints it accepts. */
15939 if (filter && !filter (tp))
15942 tp->ops->print_recreate (tp, fp);
15944 /* Note, we can't rely on tp->number for anything, as we can't
15945 assume the recreated breakpoint numbers will match. Use $bpnum
15948 if (tp->cond_string)
15949 fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string);
15951 if (tp->ignore_count)
15952 fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count);
15954 if (tp->type != bp_dprintf && tp->commands)
15956 volatile struct gdb_exception ex;
15958 fprintf_unfiltered (fp, " commands\n");
15960 ui_out_redirect (current_uiout, fp);
15961 TRY_CATCH (ex, RETURN_MASK_ALL)
15963 print_command_lines (current_uiout, tp->commands->commands, 2);
15965 ui_out_redirect (current_uiout, NULL);
15968 throw_exception (ex);
15970 fprintf_unfiltered (fp, " end\n");
15973 if (tp->enable_state == bp_disabled)
15974 fprintf_unfiltered (fp, "disable\n");
15976 /* If this is a multi-location breakpoint, check if the locations
15977 should be individually disabled. Watchpoint locations are
15978 special, and not user visible. */
15979 if (!is_watchpoint (tp) && tp->loc && tp->loc->next)
15981 struct bp_location *loc;
15984 for (loc = tp->loc; loc != NULL; loc = loc->next, n++)
15986 fprintf_unfiltered (fp, "disable $bpnum.%d\n", n);
15990 if (extra_trace_bits && *default_collect)
15991 fprintf_unfiltered (fp, "set default-collect %s\n", default_collect);
15994 printf_filtered (_("Saved to file '%s'.\n"), filename);
15995 do_cleanups (cleanup);
15998 /* The `save breakpoints' command. */
16001 save_breakpoints_command (char *args, int from_tty)
16003 save_breakpoints (args, from_tty, NULL);
16006 /* The `save tracepoints' command. */
16009 save_tracepoints_command (char *args, int from_tty)
16011 save_breakpoints (args, from_tty, is_tracepoint);
16014 /* Create a vector of all tracepoints. */
16016 VEC(breakpoint_p) *
16017 all_tracepoints (void)
16019 VEC(breakpoint_p) *tp_vec = 0;
16020 struct breakpoint *tp;
16022 ALL_TRACEPOINTS (tp)
16024 VEC_safe_push (breakpoint_p, tp_vec, tp);
16031 /* This help string is used for the break, hbreak, tbreak and thbreak
16032 commands. It is defined as a macro to prevent duplication.
16033 COMMAND should be a string constant containing the name of the
16035 #define BREAK_ARGS_HELP(command) \
16036 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
16037 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
16038 probe point. Accepted values are `-probe' (for a generic, automatically\n\
16039 guessed probe type) or `-probe-stap' (for a SystemTap probe).\n\
16040 LOCATION may be a line number, function name, or \"*\" and an address.\n\
16041 If a line number is specified, break at start of code for that line.\n\
16042 If a function is specified, break at start of code for that function.\n\
16043 If an address is specified, break at that exact address.\n\
16044 With no LOCATION, uses current execution address of the selected\n\
16045 stack frame. This is useful for breaking on return to a stack frame.\n\
16047 THREADNUM is the number from \"info threads\".\n\
16048 CONDITION is a boolean expression.\n\
16050 Multiple breakpoints at one place are permitted, and useful if their\n\
16051 conditions are different.\n\
16053 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
16055 /* List of subcommands for "catch". */
16056 static struct cmd_list_element *catch_cmdlist;
16058 /* List of subcommands for "tcatch". */
16059 static struct cmd_list_element *tcatch_cmdlist;
16062 add_catch_command (char *name, char *docstring,
16063 cmd_sfunc_ftype *sfunc,
16064 completer_ftype *completer,
16065 void *user_data_catch,
16066 void *user_data_tcatch)
16068 struct cmd_list_element *command;
16070 command = add_cmd (name, class_breakpoint, NULL, docstring,
16072 set_cmd_sfunc (command, sfunc);
16073 set_cmd_context (command, user_data_catch);
16074 set_cmd_completer (command, completer);
16076 command = add_cmd (name, class_breakpoint, NULL, docstring,
16078 set_cmd_sfunc (command, sfunc);
16079 set_cmd_context (command, user_data_tcatch);
16080 set_cmd_completer (command, completer);
16084 clear_syscall_counts (struct inferior *inf)
16086 struct catch_syscall_inferior_data *inf_data
16087 = get_catch_syscall_inferior_data (inf);
16089 inf_data->total_syscalls_count = 0;
16090 inf_data->any_syscall_count = 0;
16091 VEC_free (int, inf_data->syscalls_counts);
16095 save_command (char *arg, int from_tty)
16097 printf_unfiltered (_("\"save\" must be followed by "
16098 "the name of a save subcommand.\n"));
16099 help_list (save_cmdlist, "save ", all_commands, gdb_stdout);
16102 struct breakpoint *
16103 iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *),
16106 struct breakpoint *b, *b_tmp;
16108 ALL_BREAKPOINTS_SAFE (b, b_tmp)
16110 if ((*callback) (b, data))
16117 /* Zero if any of the breakpoint's locations could be a location where
16118 functions have been inlined, nonzero otherwise. */
16121 is_non_inline_function (struct breakpoint *b)
16123 /* The shared library event breakpoint is set on the address of a
16124 non-inline function. */
16125 if (b->type == bp_shlib_event)
16131 /* Nonzero if the specified PC cannot be a location where functions
16132 have been inlined. */
16135 pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc,
16136 const struct target_waitstatus *ws)
16138 struct breakpoint *b;
16139 struct bp_location *bl;
16141 ALL_BREAKPOINTS (b)
16143 if (!is_non_inline_function (b))
16146 for (bl = b->loc; bl != NULL; bl = bl->next)
16148 if (!bl->shlib_disabled
16149 && bpstat_check_location (bl, aspace, pc, ws))
16157 /* Remove any references to OBJFILE which is going to be freed. */
16160 breakpoint_free_objfile (struct objfile *objfile)
16162 struct bp_location **locp, *loc;
16164 ALL_BP_LOCATIONS (loc, locp)
16165 if (loc->symtab != NULL && loc->symtab->objfile == objfile)
16166 loc->symtab = NULL;
16170 initialize_breakpoint_ops (void)
16172 static int initialized = 0;
16174 struct breakpoint_ops *ops;
16180 /* The breakpoint_ops structure to be inherit by all kinds of
16181 breakpoints (real breakpoints, i.e., user "break" breakpoints,
16182 internal and momentary breakpoints, etc.). */
16183 ops = &bkpt_base_breakpoint_ops;
16184 *ops = base_breakpoint_ops;
16185 ops->re_set = bkpt_re_set;
16186 ops->insert_location = bkpt_insert_location;
16187 ops->remove_location = bkpt_remove_location;
16188 ops->breakpoint_hit = bkpt_breakpoint_hit;
16189 ops->create_sals_from_address = bkpt_create_sals_from_address;
16190 ops->create_breakpoints_sal = bkpt_create_breakpoints_sal;
16191 ops->decode_linespec = bkpt_decode_linespec;
16193 /* The breakpoint_ops structure to be used in regular breakpoints. */
16194 ops = &bkpt_breakpoint_ops;
16195 *ops = bkpt_base_breakpoint_ops;
16196 ops->re_set = bkpt_re_set;
16197 ops->resources_needed = bkpt_resources_needed;
16198 ops->print_it = bkpt_print_it;
16199 ops->print_mention = bkpt_print_mention;
16200 ops->print_recreate = bkpt_print_recreate;
16202 /* Ranged breakpoints. */
16203 ops = &ranged_breakpoint_ops;
16204 *ops = bkpt_breakpoint_ops;
16205 ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint;
16206 ops->resources_needed = resources_needed_ranged_breakpoint;
16207 ops->print_it = print_it_ranged_breakpoint;
16208 ops->print_one = print_one_ranged_breakpoint;
16209 ops->print_one_detail = print_one_detail_ranged_breakpoint;
16210 ops->print_mention = print_mention_ranged_breakpoint;
16211 ops->print_recreate = print_recreate_ranged_breakpoint;
16213 /* Internal breakpoints. */
16214 ops = &internal_breakpoint_ops;
16215 *ops = bkpt_base_breakpoint_ops;
16216 ops->re_set = internal_bkpt_re_set;
16217 ops->check_status = internal_bkpt_check_status;
16218 ops->print_it = internal_bkpt_print_it;
16219 ops->print_mention = internal_bkpt_print_mention;
16221 /* Momentary breakpoints. */
16222 ops = &momentary_breakpoint_ops;
16223 *ops = bkpt_base_breakpoint_ops;
16224 ops->re_set = momentary_bkpt_re_set;
16225 ops->check_status = momentary_bkpt_check_status;
16226 ops->print_it = momentary_bkpt_print_it;
16227 ops->print_mention = momentary_bkpt_print_mention;
16229 /* Momentary breakpoints for bp_longjmp and bp_exception. */
16230 ops = &longjmp_breakpoint_ops;
16231 *ops = momentary_breakpoint_ops;
16232 ops->dtor = longjmp_bkpt_dtor;
16234 /* Probe breakpoints. */
16235 ops = &bkpt_probe_breakpoint_ops;
16236 *ops = bkpt_breakpoint_ops;
16237 ops->insert_location = bkpt_probe_insert_location;
16238 ops->remove_location = bkpt_probe_remove_location;
16239 ops->create_sals_from_address = bkpt_probe_create_sals_from_address;
16240 ops->decode_linespec = bkpt_probe_decode_linespec;
16243 ops = &watchpoint_breakpoint_ops;
16244 *ops = base_breakpoint_ops;
16245 ops->dtor = dtor_watchpoint;
16246 ops->re_set = re_set_watchpoint;
16247 ops->insert_location = insert_watchpoint;
16248 ops->remove_location = remove_watchpoint;
16249 ops->breakpoint_hit = breakpoint_hit_watchpoint;
16250 ops->check_status = check_status_watchpoint;
16251 ops->resources_needed = resources_needed_watchpoint;
16252 ops->works_in_software_mode = works_in_software_mode_watchpoint;
16253 ops->print_it = print_it_watchpoint;
16254 ops->print_mention = print_mention_watchpoint;
16255 ops->print_recreate = print_recreate_watchpoint;
16256 ops->explains_signal = explains_signal_watchpoint;
16258 /* Masked watchpoints. */
16259 ops = &masked_watchpoint_breakpoint_ops;
16260 *ops = watchpoint_breakpoint_ops;
16261 ops->insert_location = insert_masked_watchpoint;
16262 ops->remove_location = remove_masked_watchpoint;
16263 ops->resources_needed = resources_needed_masked_watchpoint;
16264 ops->works_in_software_mode = works_in_software_mode_masked_watchpoint;
16265 ops->print_it = print_it_masked_watchpoint;
16266 ops->print_one_detail = print_one_detail_masked_watchpoint;
16267 ops->print_mention = print_mention_masked_watchpoint;
16268 ops->print_recreate = print_recreate_masked_watchpoint;
16271 ops = &tracepoint_breakpoint_ops;
16272 *ops = base_breakpoint_ops;
16273 ops->re_set = tracepoint_re_set;
16274 ops->breakpoint_hit = tracepoint_breakpoint_hit;
16275 ops->print_one_detail = tracepoint_print_one_detail;
16276 ops->print_mention = tracepoint_print_mention;
16277 ops->print_recreate = tracepoint_print_recreate;
16278 ops->create_sals_from_address = tracepoint_create_sals_from_address;
16279 ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal;
16280 ops->decode_linespec = tracepoint_decode_linespec;
16282 /* Probe tracepoints. */
16283 ops = &tracepoint_probe_breakpoint_ops;
16284 *ops = tracepoint_breakpoint_ops;
16285 ops->create_sals_from_address = tracepoint_probe_create_sals_from_address;
16286 ops->decode_linespec = tracepoint_probe_decode_linespec;
16288 /* Static tracepoints with marker (`-m'). */
16289 ops = &strace_marker_breakpoint_ops;
16290 *ops = tracepoint_breakpoint_ops;
16291 ops->create_sals_from_address = strace_marker_create_sals_from_address;
16292 ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal;
16293 ops->decode_linespec = strace_marker_decode_linespec;
16295 /* Fork catchpoints. */
16296 ops = &catch_fork_breakpoint_ops;
16297 *ops = base_breakpoint_ops;
16298 ops->insert_location = insert_catch_fork;
16299 ops->remove_location = remove_catch_fork;
16300 ops->breakpoint_hit = breakpoint_hit_catch_fork;
16301 ops->print_it = print_it_catch_fork;
16302 ops->print_one = print_one_catch_fork;
16303 ops->print_mention = print_mention_catch_fork;
16304 ops->print_recreate = print_recreate_catch_fork;
16306 /* Vfork catchpoints. */
16307 ops = &catch_vfork_breakpoint_ops;
16308 *ops = base_breakpoint_ops;
16309 ops->insert_location = insert_catch_vfork;
16310 ops->remove_location = remove_catch_vfork;
16311 ops->breakpoint_hit = breakpoint_hit_catch_vfork;
16312 ops->print_it = print_it_catch_vfork;
16313 ops->print_one = print_one_catch_vfork;
16314 ops->print_mention = print_mention_catch_vfork;
16315 ops->print_recreate = print_recreate_catch_vfork;
16317 /* Exec catchpoints. */
16318 ops = &catch_exec_breakpoint_ops;
16319 *ops = base_breakpoint_ops;
16320 ops->dtor = dtor_catch_exec;
16321 ops->insert_location = insert_catch_exec;
16322 ops->remove_location = remove_catch_exec;
16323 ops->breakpoint_hit = breakpoint_hit_catch_exec;
16324 ops->print_it = print_it_catch_exec;
16325 ops->print_one = print_one_catch_exec;
16326 ops->print_mention = print_mention_catch_exec;
16327 ops->print_recreate = print_recreate_catch_exec;
16329 /* Syscall catchpoints. */
16330 ops = &catch_syscall_breakpoint_ops;
16331 *ops = base_breakpoint_ops;
16332 ops->dtor = dtor_catch_syscall;
16333 ops->insert_location = insert_catch_syscall;
16334 ops->remove_location = remove_catch_syscall;
16335 ops->breakpoint_hit = breakpoint_hit_catch_syscall;
16336 ops->print_it = print_it_catch_syscall;
16337 ops->print_one = print_one_catch_syscall;
16338 ops->print_mention = print_mention_catch_syscall;
16339 ops->print_recreate = print_recreate_catch_syscall;
16341 /* Solib-related catchpoints. */
16342 ops = &catch_solib_breakpoint_ops;
16343 *ops = base_breakpoint_ops;
16344 ops->dtor = dtor_catch_solib;
16345 ops->insert_location = insert_catch_solib;
16346 ops->remove_location = remove_catch_solib;
16347 ops->breakpoint_hit = breakpoint_hit_catch_solib;
16348 ops->check_status = check_status_catch_solib;
16349 ops->print_it = print_it_catch_solib;
16350 ops->print_one = print_one_catch_solib;
16351 ops->print_mention = print_mention_catch_solib;
16352 ops->print_recreate = print_recreate_catch_solib;
16354 ops = &dprintf_breakpoint_ops;
16355 *ops = bkpt_base_breakpoint_ops;
16356 ops->re_set = dprintf_re_set;
16357 ops->resources_needed = bkpt_resources_needed;
16358 ops->print_it = bkpt_print_it;
16359 ops->print_mention = bkpt_print_mention;
16360 ops->print_recreate = dprintf_print_recreate;
16361 ops->after_condition_true = dprintf_after_condition_true;
16362 ops->breakpoint_hit = dprintf_breakpoint_hit;
16365 /* Chain containing all defined "enable breakpoint" subcommands. */
16367 static struct cmd_list_element *enablebreaklist = NULL;
16370 _initialize_breakpoint (void)
16372 struct cmd_list_element *c;
16374 initialize_breakpoint_ops ();
16376 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
16377 observer_attach_free_objfile (disable_breakpoints_in_freed_objfile);
16378 observer_attach_inferior_exit (clear_syscall_counts);
16379 observer_attach_memory_changed (invalidate_bp_value_on_memory_change);
16381 breakpoint_objfile_key
16382 = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes);
16384 catch_syscall_inferior_data
16385 = register_inferior_data_with_cleanup (NULL,
16386 catch_syscall_inferior_data_cleanup);
16388 breakpoint_chain = 0;
16389 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
16390 before a breakpoint is set. */
16391 breakpoint_count = 0;
16393 tracepoint_count = 0;
16395 add_com ("ignore", class_breakpoint, ignore_command, _("\
16396 Set ignore-count of breakpoint number N to COUNT.\n\
16397 Usage is `ignore N COUNT'."));
16399 add_com_alias ("bc", "ignore", class_breakpoint, 1);
16401 add_com ("commands", class_breakpoint, commands_command, _("\
16402 Set commands to be executed when a breakpoint is hit.\n\
16403 Give breakpoint number as argument after \"commands\".\n\
16404 With no argument, the targeted breakpoint is the last one set.\n\
16405 The commands themselves follow starting on the next line.\n\
16406 Type a line containing \"end\" to indicate the end of them.\n\
16407 Give \"silent\" as the first line to make the breakpoint silent;\n\
16408 then no output is printed when it is hit, except what the commands print."));
16410 c = add_com ("condition", class_breakpoint, condition_command, _("\
16411 Specify breakpoint number N to break only if COND is true.\n\
16412 Usage is `condition N COND', where N is an integer and COND is an\n\
16413 expression to be evaluated whenever breakpoint N is reached."));
16414 set_cmd_completer (c, condition_completer);
16416 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
16417 Set a temporary breakpoint.\n\
16418 Like \"break\" except the breakpoint is only temporary,\n\
16419 so it will be deleted when hit. Equivalent to \"break\" followed\n\
16420 by using \"enable delete\" on the breakpoint number.\n\
16422 BREAK_ARGS_HELP ("tbreak")));
16423 set_cmd_completer (c, location_completer);
16425 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
16426 Set a hardware assisted breakpoint.\n\
16427 Like \"break\" except the breakpoint requires hardware support,\n\
16428 some target hardware may not have this support.\n\
16430 BREAK_ARGS_HELP ("hbreak")));
16431 set_cmd_completer (c, location_completer);
16433 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
16434 Set a temporary hardware assisted breakpoint.\n\
16435 Like \"hbreak\" except the breakpoint is only temporary,\n\
16436 so it will be deleted when hit.\n\
16438 BREAK_ARGS_HELP ("thbreak")));
16439 set_cmd_completer (c, location_completer);
16441 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
16442 Enable some breakpoints.\n\
16443 Give breakpoint numbers (separated by spaces) as arguments.\n\
16444 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16445 This is used to cancel the effect of the \"disable\" command.\n\
16446 With a subcommand you can enable temporarily."),
16447 &enablelist, "enable ", 1, &cmdlist);
16449 add_com ("ab", class_breakpoint, enable_command, _("\
16450 Enable some breakpoints.\n\
16451 Give breakpoint numbers (separated by spaces) as arguments.\n\
16452 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16453 This is used to cancel the effect of the \"disable\" command.\n\
16454 With a subcommand you can enable temporarily."));
16456 add_com_alias ("en", "enable", class_breakpoint, 1);
16458 add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
16459 Enable some breakpoints.\n\
16460 Give breakpoint numbers (separated by spaces) as arguments.\n\
16461 This is used to cancel the effect of the \"disable\" command.\n\
16462 May be abbreviated to simply \"enable\".\n"),
16463 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
16465 add_cmd ("once", no_class, enable_once_command, _("\
16466 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16467 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16470 add_cmd ("delete", no_class, enable_delete_command, _("\
16471 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16472 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16475 add_cmd ("count", no_class, enable_count_command, _("\
16476 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16477 If a breakpoint is hit while enabled in this fashion,\n\
16478 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16481 add_cmd ("delete", no_class, enable_delete_command, _("\
16482 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16483 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16486 add_cmd ("once", no_class, enable_once_command, _("\
16487 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16488 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16491 add_cmd ("count", no_class, enable_count_command, _("\
16492 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16493 If a breakpoint is hit while enabled in this fashion,\n\
16494 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16497 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
16498 Disable some breakpoints.\n\
16499 Arguments are breakpoint numbers with spaces in between.\n\
16500 To disable all breakpoints, give no argument.\n\
16501 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
16502 &disablelist, "disable ", 1, &cmdlist);
16503 add_com_alias ("dis", "disable", class_breakpoint, 1);
16504 add_com_alias ("disa", "disable", class_breakpoint, 1);
16506 add_com ("sb", class_breakpoint, disable_command, _("\
16507 Disable some breakpoints.\n\
16508 Arguments are breakpoint numbers with spaces in between.\n\
16509 To disable all breakpoints, give no argument.\n\
16510 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
16512 add_cmd ("breakpoints", class_alias, disable_command, _("\
16513 Disable some breakpoints.\n\
16514 Arguments are breakpoint numbers with spaces in between.\n\
16515 To disable all breakpoints, give no argument.\n\
16516 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
16517 This command may be abbreviated \"disable\"."),
16520 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
16521 Delete some breakpoints or auto-display expressions.\n\
16522 Arguments are breakpoint numbers with spaces in between.\n\
16523 To delete all breakpoints, give no argument.\n\
16525 Also a prefix command for deletion of other GDB objects.\n\
16526 The \"unset\" command is also an alias for \"delete\"."),
16527 &deletelist, "delete ", 1, &cmdlist);
16528 add_com_alias ("d", "delete", class_breakpoint, 1);
16529 add_com_alias ("del", "delete", class_breakpoint, 1);
16531 add_com ("db", class_breakpoint, delete_command, _("\
16532 Delete some breakpoints.\n\
16533 Arguments are breakpoint numbers with spaces in between.\n\
16534 To delete all breakpoints, give no argument.\n"));
16536 add_cmd ("breakpoints", class_alias, delete_command, _("\
16537 Delete some breakpoints or auto-display expressions.\n\
16538 Arguments are breakpoint numbers with spaces in between.\n\
16539 To delete all breakpoints, give no argument.\n\
16540 This command may be abbreviated \"delete\"."),
16543 add_com ("clear", class_breakpoint, clear_command, _("\
16544 Clear breakpoint at specified line or function.\n\
16545 Argument may be line number, function name, or \"*\" and an address.\n\
16546 If line number is specified, all breakpoints in that line are cleared.\n\
16547 If function is specified, breakpoints at beginning of function are cleared.\n\
16548 If an address is specified, breakpoints at that address are cleared.\n\
16550 With no argument, clears all breakpoints in the line that the selected frame\n\
16551 is executing in.\n\
16553 See also the \"delete\" command which clears breakpoints by number."));
16554 add_com_alias ("cl", "clear", class_breakpoint, 1);
16556 c = add_com ("break", class_breakpoint, break_command, _("\
16557 Set breakpoint at specified line or function.\n"
16558 BREAK_ARGS_HELP ("break")));
16559 set_cmd_completer (c, location_completer);
16561 add_com_alias ("b", "break", class_run, 1);
16562 add_com_alias ("br", "break", class_run, 1);
16563 add_com_alias ("bre", "break", class_run, 1);
16564 add_com_alias ("brea", "break", class_run, 1);
16567 add_com_alias ("ba", "break", class_breakpoint, 1);
16571 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
16572 Break in function/address or break at a line in the current file."),
16573 &stoplist, "stop ", 1, &cmdlist);
16574 add_cmd ("in", class_breakpoint, stopin_command,
16575 _("Break in function or address."), &stoplist);
16576 add_cmd ("at", class_breakpoint, stopat_command,
16577 _("Break at a line in the current file."), &stoplist);
16578 add_com ("status", class_info, breakpoints_info, _("\
16579 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16580 The \"Type\" column indicates one of:\n\
16581 \tbreakpoint - normal breakpoint\n\
16582 \twatchpoint - watchpoint\n\
16583 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16584 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16585 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16586 address and file/line number respectively.\n\
16588 Convenience variable \"$_\" and default examine address for \"x\"\n\
16589 are set to the address of the last breakpoint listed unless the command\n\
16590 is prefixed with \"server \".\n\n\
16591 Convenience variable \"$bpnum\" contains the number of the last\n\
16592 breakpoint set."));
16595 add_info ("breakpoints", breakpoints_info, _("\
16596 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
16597 The \"Type\" column indicates one of:\n\
16598 \tbreakpoint - normal breakpoint\n\
16599 \twatchpoint - watchpoint\n\
16600 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16601 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16602 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16603 address and file/line number respectively.\n\
16605 Convenience variable \"$_\" and default examine address for \"x\"\n\
16606 are set to the address of the last breakpoint listed unless the command\n\
16607 is prefixed with \"server \".\n\n\
16608 Convenience variable \"$bpnum\" contains the number of the last\n\
16609 breakpoint set."));
16611 add_info_alias ("b", "breakpoints", 1);
16614 add_com ("lb", class_breakpoint, breakpoints_info, _("\
16615 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16616 The \"Type\" column indicates one of:\n\
16617 \tbreakpoint - normal breakpoint\n\
16618 \twatchpoint - watchpoint\n\
16619 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16620 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16621 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16622 address and file/line number respectively.\n\
16624 Convenience variable \"$_\" and default examine address for \"x\"\n\
16625 are set to the address of the last breakpoint listed unless the command\n\
16626 is prefixed with \"server \".\n\n\
16627 Convenience variable \"$bpnum\" contains the number of the last\n\
16628 breakpoint set."));
16630 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
16631 Status of all breakpoints, or breakpoint number NUMBER.\n\
16632 The \"Type\" column indicates one of:\n\
16633 \tbreakpoint - normal breakpoint\n\
16634 \twatchpoint - watchpoint\n\
16635 \tlongjmp - internal breakpoint used to step through longjmp()\n\
16636 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
16637 \tuntil - internal breakpoint used by the \"until\" command\n\
16638 \tfinish - internal breakpoint used by the \"finish\" command\n\
16639 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16640 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16641 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16642 address and file/line number respectively.\n\
16644 Convenience variable \"$_\" and default examine address for \"x\"\n\
16645 are set to the address of the last breakpoint listed unless the command\n\
16646 is prefixed with \"server \".\n\n\
16647 Convenience variable \"$bpnum\" contains the number of the last\n\
16649 &maintenanceinfolist);
16651 add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\
16652 Set catchpoints to catch events."),
16653 &catch_cmdlist, "catch ",
16654 0/*allow-unknown*/, &cmdlist);
16656 add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\
16657 Set temporary catchpoints to catch events."),
16658 &tcatch_cmdlist, "tcatch ",
16659 0/*allow-unknown*/, &cmdlist);
16661 add_catch_command ("fork", _("Catch calls to fork."),
16662 catch_fork_command_1,
16664 (void *) (uintptr_t) catch_fork_permanent,
16665 (void *) (uintptr_t) catch_fork_temporary);
16666 add_catch_command ("vfork", _("Catch calls to vfork."),
16667 catch_fork_command_1,
16669 (void *) (uintptr_t) catch_vfork_permanent,
16670 (void *) (uintptr_t) catch_vfork_temporary);
16671 add_catch_command ("exec", _("Catch calls to exec."),
16672 catch_exec_command_1,
16676 add_catch_command ("load", _("Catch loads of shared libraries.\n\
16677 Usage: catch load [REGEX]\n\
16678 If REGEX is given, only stop for libraries matching the regular expression."),
16679 catch_load_command_1,
16683 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
16684 Usage: catch unload [REGEX]\n\
16685 If REGEX is given, only stop for libraries matching the regular expression."),
16686 catch_unload_command_1,
16690 add_catch_command ("syscall", _("\
16691 Catch system calls by their names and/or numbers.\n\
16692 Arguments say which system calls to catch. If no arguments\n\
16693 are given, every system call will be caught.\n\
16694 Arguments, if given, should be one or more system call names\n\
16695 (if your system supports that), or system call numbers."),
16696 catch_syscall_command_1,
16697 catch_syscall_completer,
16701 c = add_com ("watch", class_breakpoint, watch_command, _("\
16702 Set a watchpoint for an expression.\n\
16703 Usage: watch [-l|-location] EXPRESSION\n\
16704 A watchpoint stops execution of your program whenever the value of\n\
16705 an expression changes.\n\
16706 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16707 the memory to which it refers."));
16708 set_cmd_completer (c, expression_completer);
16710 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
16711 Set a read watchpoint for an expression.\n\
16712 Usage: rwatch [-l|-location] EXPRESSION\n\
16713 A watchpoint stops execution of your program whenever the value of\n\
16714 an expression is read.\n\
16715 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16716 the memory to which it refers."));
16717 set_cmd_completer (c, expression_completer);
16719 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
16720 Set a watchpoint for an expression.\n\
16721 Usage: awatch [-l|-location] EXPRESSION\n\
16722 A watchpoint stops execution of your program whenever the value of\n\
16723 an expression is either read or written.\n\
16724 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16725 the memory to which it refers."));
16726 set_cmd_completer (c, expression_completer);
16728 add_info ("watchpoints", watchpoints_info, _("\
16729 Status of specified watchpoints (all watchpoints if no argument)."));
16731 /* XXX: cagney/2005-02-23: This should be a boolean, and should
16732 respond to changes - contrary to the description. */
16733 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
16734 &can_use_hw_watchpoints, _("\
16735 Set debugger's willingness to use watchpoint hardware."), _("\
16736 Show debugger's willingness to use watchpoint hardware."), _("\
16737 If zero, gdb will not use hardware for new watchpoints, even if\n\
16738 such is available. (However, any hardware watchpoints that were\n\
16739 created before setting this to nonzero, will continue to use watchpoint\n\
16742 show_can_use_hw_watchpoints,
16743 &setlist, &showlist);
16745 can_use_hw_watchpoints = 1;
16747 /* Tracepoint manipulation commands. */
16749 c = add_com ("trace", class_breakpoint, trace_command, _("\
16750 Set a tracepoint at specified line or function.\n\
16752 BREAK_ARGS_HELP ("trace") "\n\
16753 Do \"help tracepoints\" for info on other tracepoint commands."));
16754 set_cmd_completer (c, location_completer);
16756 add_com_alias ("tp", "trace", class_alias, 0);
16757 add_com_alias ("tr", "trace", class_alias, 1);
16758 add_com_alias ("tra", "trace", class_alias, 1);
16759 add_com_alias ("trac", "trace", class_alias, 1);
16761 c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\
16762 Set a fast tracepoint at specified line or function.\n\
16764 BREAK_ARGS_HELP ("ftrace") "\n\
16765 Do \"help tracepoints\" for info on other tracepoint commands."));
16766 set_cmd_completer (c, location_completer);
16768 c = add_com ("strace", class_breakpoint, strace_command, _("\
16769 Set a static tracepoint at specified line, function or marker.\n\
16771 strace [LOCATION] [if CONDITION]\n\
16772 LOCATION may be a line number, function name, \"*\" and an address,\n\
16773 or -m MARKER_ID.\n\
16774 If a line number is specified, probe the marker at start of code\n\
16775 for that line. If a function is specified, probe the marker at start\n\
16776 of code for that function. If an address is specified, probe the marker\n\
16777 at that exact address. If a marker id is specified, probe the marker\n\
16778 with that name. With no LOCATION, uses current execution address of\n\
16779 the selected stack frame.\n\
16780 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16781 This collects arbitrary user data passed in the probe point call to the\n\
16782 tracing library. You can inspect it when analyzing the trace buffer,\n\
16783 by printing the $_sdata variable like any other convenience variable.\n\
16785 CONDITION is a boolean expression.\n\
16787 Multiple tracepoints at one place are permitted, and useful if their\n\
16788 conditions are different.\n\
16790 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16791 Do \"help tracepoints\" for info on other tracepoint commands."));
16792 set_cmd_completer (c, location_completer);
16794 add_info ("tracepoints", tracepoints_info, _("\
16795 Status of specified tracepoints (all tracepoints if no argument).\n\
16796 Convenience variable \"$tpnum\" contains the number of the\n\
16797 last tracepoint set."));
16799 add_info_alias ("tp", "tracepoints", 1);
16801 add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
16802 Delete specified tracepoints.\n\
16803 Arguments are tracepoint numbers, separated by spaces.\n\
16804 No argument means delete all tracepoints."),
16806 add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist);
16808 c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
16809 Disable specified tracepoints.\n\
16810 Arguments are tracepoint numbers, separated by spaces.\n\
16811 No argument means disable all tracepoints."),
16813 deprecate_cmd (c, "disable");
16815 c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\
16816 Enable specified tracepoints.\n\
16817 Arguments are tracepoint numbers, separated by spaces.\n\
16818 No argument means enable all tracepoints."),
16820 deprecate_cmd (c, "enable");
16822 add_com ("passcount", class_trace, trace_pass_command, _("\
16823 Set the passcount for a tracepoint.\n\
16824 The trace will end when the tracepoint has been passed 'count' times.\n\
16825 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16826 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16828 add_prefix_cmd ("save", class_breakpoint, save_command,
16829 _("Save breakpoint definitions as a script."),
16830 &save_cmdlist, "save ",
16831 0/*allow-unknown*/, &cmdlist);
16833 c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\
16834 Save current breakpoint definitions as a script.\n\
16835 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16836 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16837 session to restore them."),
16839 set_cmd_completer (c, filename_completer);
16841 c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\
16842 Save current tracepoint definitions as a script.\n\
16843 Use the 'source' command in another debug session to restore them."),
16845 set_cmd_completer (c, filename_completer);
16847 c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0);
16848 deprecate_cmd (c, "save tracepoints");
16850 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
16851 Breakpoint specific settings\n\
16852 Configure various breakpoint-specific variables such as\n\
16853 pending breakpoint behavior"),
16854 &breakpoint_set_cmdlist, "set breakpoint ",
16855 0/*allow-unknown*/, &setlist);
16856 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
16857 Breakpoint specific settings\n\
16858 Configure various breakpoint-specific variables such as\n\
16859 pending breakpoint behavior"),
16860 &breakpoint_show_cmdlist, "show breakpoint ",
16861 0/*allow-unknown*/, &showlist);
16863 add_setshow_auto_boolean_cmd ("pending", no_class,
16864 &pending_break_support, _("\
16865 Set debugger's behavior regarding pending breakpoints."), _("\
16866 Show debugger's behavior regarding pending breakpoints."), _("\
16867 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16868 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16869 an error. If auto, an unrecognized breakpoint location results in a\n\
16870 user-query to see if a pending breakpoint should be created."),
16872 show_pending_break_support,
16873 &breakpoint_set_cmdlist,
16874 &breakpoint_show_cmdlist);
16876 pending_break_support = AUTO_BOOLEAN_AUTO;
16878 add_setshow_boolean_cmd ("auto-hw", no_class,
16879 &automatic_hardware_breakpoints, _("\
16880 Set automatic usage of hardware breakpoints."), _("\
16881 Show automatic usage of hardware breakpoints."), _("\
16882 If set, the debugger will automatically use hardware breakpoints for\n\
16883 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16884 a warning will be emitted for such breakpoints."),
16886 show_automatic_hardware_breakpoints,
16887 &breakpoint_set_cmdlist,
16888 &breakpoint_show_cmdlist);
16890 add_setshow_auto_boolean_cmd ("always-inserted", class_support,
16891 &always_inserted_mode, _("\
16892 Set mode for inserting breakpoints."), _("\
16893 Show mode for inserting breakpoints."), _("\
16894 When this mode is off, breakpoints are inserted in inferior when it is\n\
16895 resumed, and removed when execution stops. When this mode is on,\n\
16896 breakpoints are inserted immediately and removed only when the user\n\
16897 deletes the breakpoint. When this mode is auto (which is the default),\n\
16898 the behaviour depends on the non-stop setting (see help set non-stop).\n\
16899 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
16900 behaves as if always-inserted mode is on; if gdb is controlling the\n\
16901 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
16903 &show_always_inserted_mode,
16904 &breakpoint_set_cmdlist,
16905 &breakpoint_show_cmdlist);
16907 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint,
16908 condition_evaluation_enums,
16909 &condition_evaluation_mode_1, _("\
16910 Set mode of breakpoint condition evaluation."), _("\
16911 Show mode of breakpoint condition evaluation."), _("\
16912 When this is set to \"host\", breakpoint conditions will be\n\
16913 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16914 breakpoint conditions will be downloaded to the target (if the target\n\
16915 supports such feature) and conditions will be evaluated on the target's side.\n\
16916 If this is set to \"auto\" (default), this will be automatically set to\n\
16917 \"target\" if it supports condition evaluation, otherwise it will\n\
16918 be set to \"gdb\""),
16919 &set_condition_evaluation_mode,
16920 &show_condition_evaluation_mode,
16921 &breakpoint_set_cmdlist,
16922 &breakpoint_show_cmdlist);
16924 add_com ("break-range", class_breakpoint, break_range_command, _("\
16925 Set a breakpoint for an address range.\n\
16926 break-range START-LOCATION, END-LOCATION\n\
16927 where START-LOCATION and END-LOCATION can be one of the following:\n\
16928 LINENUM, for that line in the current file,\n\
16929 FILE:LINENUM, for that line in that file,\n\
16930 +OFFSET, for that number of lines after the current line\n\
16931 or the start of the range\n\
16932 FUNCTION, for the first line in that function,\n\
16933 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16934 *ADDRESS, for the instruction at that address.\n\
16936 The breakpoint will stop execution of the inferior whenever it executes\n\
16937 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16938 range (including START-LOCATION and END-LOCATION)."));
16940 c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\
16941 Set a dynamic printf at specified line or function.\n\
16942 dprintf location,format string,arg1,arg2,...\n\
16943 location may be a line number, function name, or \"*\" and an address.\n\
16944 If a line number is specified, break at start of code for that line.\n\
16945 If a function is specified, break at start of code for that function."));
16946 set_cmd_completer (c, location_completer);
16948 add_setshow_enum_cmd ("dprintf-style", class_support,
16949 dprintf_style_enums, &dprintf_style, _("\
16950 Set the style of usage for dynamic printf."), _("\
16951 Show the style of usage for dynamic printf."), _("\
16952 This setting chooses how GDB will do a dynamic printf.\n\
16953 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16954 console, as with the \"printf\" command.\n\
16955 If the value is \"call\", the print is done by calling a function in your\n\
16956 program; by default printf(), but you can choose a different function or\n\
16957 output stream by setting dprintf-function and dprintf-channel."),
16958 update_dprintf_commands, NULL,
16959 &setlist, &showlist);
16961 dprintf_function = xstrdup ("printf");
16962 add_setshow_string_cmd ("dprintf-function", class_support,
16963 &dprintf_function, _("\
16964 Set the function to use for dynamic printf"), _("\
16965 Show the function to use for dynamic printf"), NULL,
16966 update_dprintf_commands, NULL,
16967 &setlist, &showlist);
16969 dprintf_channel = xstrdup ("");
16970 add_setshow_string_cmd ("dprintf-channel", class_support,
16971 &dprintf_channel, _("\
16972 Set the channel to use for dynamic printf"), _("\
16973 Show the channel to use for dynamic printf"), NULL,
16974 update_dprintf_commands, NULL,
16975 &setlist, &showlist);
16977 add_setshow_boolean_cmd ("disconnected-dprintf", no_class,
16978 &disconnected_dprintf, _("\
16979 Set whether dprintf continues after GDB disconnects."), _("\
16980 Show whether dprintf continues after GDB disconnects."), _("\
16981 Use this to let dprintf commands continue to hit and produce output\n\
16982 even if GDB disconnects or detaches from the target."),
16985 &setlist, &showlist);
16987 add_com ("agent-printf", class_vars, agent_printf_command, _("\
16988 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16989 (target agent only) This is useful for formatted output in user-defined commands."));
16991 automatic_hardware_breakpoints = 1;
16993 observer_attach_about_to_proceed (breakpoint_about_to_proceed);
16994 observer_attach_thread_exit (remove_threaded_breakpoints);