1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2012 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "arch-utils.h"
26 #include "breakpoint.h"
27 #include "tracepoint.h"
29 #include "expression.h"
35 #include "gdbthread.h"
38 #include "gdb_string.h"
39 #include "gdb-demangle.h"
40 #include "filenames.h"
46 #include "completer.h"
49 #include "cli/cli-script.h"
50 #include "gdb_assert.h"
55 #include "exceptions.h"
61 #include "xml-syscall.h"
62 #include "parser-defs.h"
63 #include "cli/cli-utils.h"
64 #include "continuations.h"
68 #include "gdb_regex.h"
71 /* readline include files */
72 #include "readline/readline.h"
73 #include "readline/history.h"
75 /* readline defines this. */
78 #include "mi/mi-common.h"
79 #include "python/python.h"
81 /* Prototypes for local functions. */
83 static void enable_delete_command (char *, int);
85 static void enable_once_command (char *, int);
87 static void enable_count_command (char *, int);
89 static void disable_command (char *, int);
91 static void enable_command (char *, int);
93 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *,
97 static void ignore_command (char *, int);
99 static int breakpoint_re_set_one (void *);
101 static void breakpoint_re_set_default (struct breakpoint *);
103 static void create_sals_from_address_default (char **,
104 struct linespec_result *,
108 static void create_breakpoints_sal_default (struct gdbarch *,
109 struct linespec_result *,
110 struct linespec_sals *,
112 enum bpdisp, int, int,
114 const struct breakpoint_ops *,
117 static void decode_linespec_default (struct breakpoint *, char **,
118 struct symtabs_and_lines *);
120 static void clear_command (char *, int);
122 static void catch_command (char *, int);
124 static int can_use_hardware_watchpoint (struct value *);
126 static void break_command_1 (char *, int, int);
128 static void mention (struct breakpoint *);
130 static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *,
132 const struct breakpoint_ops *);
133 static struct bp_location *add_location_to_breakpoint (struct breakpoint *,
134 const struct symtab_and_line *);
136 /* This function is used in gdbtk sources and thus can not be made
138 struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch,
139 struct symtab_and_line,
141 const struct breakpoint_ops *);
143 static struct breakpoint *
144 momentary_breakpoint_from_master (struct breakpoint *orig,
146 const struct breakpoint_ops *ops);
148 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
150 static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch,
154 static void describe_other_breakpoints (struct gdbarch *,
155 struct program_space *, CORE_ADDR,
156 struct obj_section *, int);
158 static int breakpoint_address_match (struct address_space *aspace1,
160 struct address_space *aspace2,
163 static int watchpoint_locations_match (struct bp_location *loc1,
164 struct bp_location *loc2);
166 static int breakpoint_location_address_match (struct bp_location *bl,
167 struct address_space *aspace,
170 static void breakpoints_info (char *, int);
172 static void watchpoints_info (char *, int);
174 static int breakpoint_1 (char *, int,
175 int (*) (const struct breakpoint *));
177 static int breakpoint_cond_eval (void *);
179 static void cleanup_executing_breakpoints (void *);
181 static void commands_command (char *, int);
183 static void condition_command (char *, int);
192 static int remove_breakpoint (struct bp_location *, insertion_state_t);
193 static int remove_breakpoint_1 (struct bp_location *, insertion_state_t);
195 static enum print_stop_action print_bp_stop_message (bpstat bs);
197 static int watchpoint_check (void *);
199 static void maintenance_info_breakpoints (char *, int);
201 static int hw_breakpoint_used_count (void);
203 static int hw_watchpoint_use_count (struct breakpoint *);
205 static int hw_watchpoint_used_count_others (struct breakpoint *except,
207 int *other_type_used);
209 static void hbreak_command (char *, int);
211 static void thbreak_command (char *, int);
213 static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp,
216 static void stop_command (char *arg, int from_tty);
218 static void stopin_command (char *arg, int from_tty);
220 static void stopat_command (char *arg, int from_tty);
222 static char *ep_parse_optional_if_clause (char **arg);
224 static void catch_exception_command_1 (enum exception_event_kind ex_event,
225 char *arg, int tempflag, int from_tty);
227 static void tcatch_command (char *arg, int from_tty);
229 static void detach_single_step_breakpoints (void);
231 static int single_step_breakpoint_inserted_here_p (struct address_space *,
234 static void free_bp_location (struct bp_location *loc);
235 static void incref_bp_location (struct bp_location *loc);
236 static void decref_bp_location (struct bp_location **loc);
238 static struct bp_location *allocate_bp_location (struct breakpoint *bpt);
240 static void update_global_location_list (int);
242 static void update_global_location_list_nothrow (int);
244 static int is_hardware_watchpoint (const struct breakpoint *bpt);
246 static void insert_breakpoint_locations (void);
248 static int syscall_catchpoint_p (struct breakpoint *b);
250 static void tracepoints_info (char *, int);
252 static void delete_trace_command (char *, int);
254 static void enable_trace_command (char *, int);
256 static void disable_trace_command (char *, int);
258 static void trace_pass_command (char *, int);
260 static int is_masked_watchpoint (const struct breakpoint *b);
262 static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address);
264 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
267 static int strace_marker_p (struct breakpoint *b);
269 static void init_catchpoint (struct breakpoint *b,
270 struct gdbarch *gdbarch, int tempflag,
272 const struct breakpoint_ops *ops);
274 /* The abstract base class all breakpoint_ops structures inherit
276 static struct breakpoint_ops base_breakpoint_ops;
278 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
279 that are implemented on top of software or hardware breakpoints
280 (user breakpoints, internal and momentary breakpoints, etc.). */
281 static struct breakpoint_ops bkpt_base_breakpoint_ops;
283 /* Internal breakpoints class type. */
284 static struct breakpoint_ops internal_breakpoint_ops;
286 /* Momentary breakpoints class type. */
287 static struct breakpoint_ops momentary_breakpoint_ops;
289 /* The breakpoint_ops structure to be used in regular user created
291 struct breakpoint_ops bkpt_breakpoint_ops;
293 /* A reference-counted struct command_line. This lets multiple
294 breakpoints share a single command list. */
295 struct counted_command_line
297 /* The reference count. */
300 /* The command list. */
301 struct command_line *commands;
304 struct command_line *
305 breakpoint_commands (struct breakpoint *b)
307 return b->commands ? b->commands->commands : NULL;
310 /* Flag indicating that a command has proceeded the inferior past the
311 current breakpoint. */
313 static int breakpoint_proceeded;
316 bpdisp_text (enum bpdisp disp)
318 /* NOTE: the following values are a part of MI protocol and
319 represent values of 'disp' field returned when inferior stops at
321 static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"};
323 return bpdisps[(int) disp];
326 /* Prototypes for exported functions. */
327 /* If FALSE, gdb will not use hardware support for watchpoints, even
328 if such is available. */
329 static int can_use_hw_watchpoints;
332 show_can_use_hw_watchpoints (struct ui_file *file, int from_tty,
333 struct cmd_list_element *c,
336 fprintf_filtered (file,
337 _("Debugger's willingness to use "
338 "watchpoint hardware is %s.\n"),
342 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
343 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
344 for unrecognized breakpoint locations.
345 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
346 static enum auto_boolean pending_break_support;
348 show_pending_break_support (struct ui_file *file, int from_tty,
349 struct cmd_list_element *c,
352 fprintf_filtered (file,
353 _("Debugger's behavior regarding "
354 "pending breakpoints is %s.\n"),
358 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
359 set with "break" but falling in read-only memory.
360 If 0, gdb will warn about such breakpoints, but won't automatically
361 use hardware breakpoints. */
362 static int automatic_hardware_breakpoints;
364 show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty,
365 struct cmd_list_element *c,
368 fprintf_filtered (file,
369 _("Automatic usage of hardware breakpoints is %s.\n"),
373 /* If on, gdb will keep breakpoints inserted even as inferior is
374 stopped, and immediately insert any new breakpoints. If off, gdb
375 will insert breakpoints into inferior only when resuming it, and
376 will remove breakpoints upon stop. If auto, GDB will behave as ON
377 if in non-stop mode, and as OFF if all-stop mode.*/
379 static const char always_inserted_auto[] = "auto";
380 static const char always_inserted_on[] = "on";
381 static const char always_inserted_off[] = "off";
382 static const char *const always_inserted_enums[] = {
383 always_inserted_auto,
388 static const char *always_inserted_mode = always_inserted_auto;
390 show_always_inserted_mode (struct ui_file *file, int from_tty,
391 struct cmd_list_element *c, const char *value)
393 if (always_inserted_mode == always_inserted_auto)
394 fprintf_filtered (file,
395 _("Always inserted breakpoint "
396 "mode is %s (currently %s).\n"),
398 breakpoints_always_inserted_mode () ? "on" : "off");
400 fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"),
405 breakpoints_always_inserted_mode (void)
407 return ((always_inserted_mode == always_inserted_on
408 || (always_inserted_mode == always_inserted_auto && non_stop))
412 static const char condition_evaluation_both[] = "host or target";
414 /* Modes for breakpoint condition evaluation. */
415 static const char condition_evaluation_auto[] = "auto";
416 static const char condition_evaluation_host[] = "host";
417 static const char condition_evaluation_target[] = "target";
418 static const char *const condition_evaluation_enums[] = {
419 condition_evaluation_auto,
420 condition_evaluation_host,
421 condition_evaluation_target,
425 /* Global that holds the current mode for breakpoint condition evaluation. */
426 static const char *condition_evaluation_mode_1 = condition_evaluation_auto;
428 /* Global that we use to display information to the user (gets its value from
429 condition_evaluation_mode_1. */
430 static const char *condition_evaluation_mode = condition_evaluation_auto;
432 /* Translate a condition evaluation mode MODE into either "host"
433 or "target". This is used mostly to translate from "auto" to the
434 real setting that is being used. It returns the translated
438 translate_condition_evaluation_mode (const char *mode)
440 if (mode == condition_evaluation_auto)
442 if (target_supports_evaluation_of_breakpoint_conditions ())
443 return condition_evaluation_target;
445 return condition_evaluation_host;
451 /* Discovers what condition_evaluation_auto translates to. */
454 breakpoint_condition_evaluation_mode (void)
456 return translate_condition_evaluation_mode (condition_evaluation_mode);
459 /* Return true if GDB should evaluate breakpoint conditions or false
463 gdb_evaluates_breakpoint_condition_p (void)
465 const char *mode = breakpoint_condition_evaluation_mode ();
467 return (mode == condition_evaluation_host);
470 void _initialize_breakpoint (void);
472 /* Are we executing breakpoint commands? */
473 static int executing_breakpoint_commands;
475 /* Are overlay event breakpoints enabled? */
476 static int overlay_events_enabled;
478 /* See description in breakpoint.h. */
479 int target_exact_watchpoints = 0;
481 /* Walk the following statement or block through all breakpoints.
482 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
483 current breakpoint. */
485 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
487 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
488 for (B = breakpoint_chain; \
489 B ? (TMP=B->next, 1): 0; \
492 /* Similar iterator for the low-level breakpoints. SAFE variant is
493 not provided so update_global_location_list must not be called
494 while executing the block of ALL_BP_LOCATIONS. */
496 #define ALL_BP_LOCATIONS(B,BP_TMP) \
497 for (BP_TMP = bp_location; \
498 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
501 /* Iterates through locations with address ADDRESS for the currently selected
502 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
503 to where the loop should start from.
504 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
505 appropriate location to start with. */
507 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
508 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
509 BP_LOCP_TMP = BP_LOCP_START; \
511 && (BP_LOCP_TMP < bp_location + bp_location_count \
512 && (*BP_LOCP_TMP)->address == ADDRESS); \
515 /* Iterator for tracepoints only. */
517 #define ALL_TRACEPOINTS(B) \
518 for (B = breakpoint_chain; B; B = B->next) \
519 if (is_tracepoint (B))
521 /* Chains of all breakpoints defined. */
523 struct breakpoint *breakpoint_chain;
525 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
527 static struct bp_location **bp_location;
529 /* Number of elements of BP_LOCATION. */
531 static unsigned bp_location_count;
533 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
534 ADDRESS for the current elements of BP_LOCATION which get a valid
535 result from bp_location_has_shadow. You can use it for roughly
536 limiting the subrange of BP_LOCATION to scan for shadow bytes for
537 an address you need to read. */
539 static CORE_ADDR bp_location_placed_address_before_address_max;
541 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
542 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
543 BP_LOCATION which get a valid result from bp_location_has_shadow.
544 You can use it for roughly limiting the subrange of BP_LOCATION to
545 scan for shadow bytes for an address you need to read. */
547 static CORE_ADDR bp_location_shadow_len_after_address_max;
549 /* The locations that no longer correspond to any breakpoint, unlinked
550 from bp_location array, but for which a hit may still be reported
552 VEC(bp_location_p) *moribund_locations = NULL;
554 /* Number of last breakpoint made. */
556 static int breakpoint_count;
558 /* The value of `breakpoint_count' before the last command that
559 created breakpoints. If the last (break-like) command created more
560 than one breakpoint, then the difference between BREAKPOINT_COUNT
561 and PREV_BREAKPOINT_COUNT is more than one. */
562 static int prev_breakpoint_count;
564 /* Number of last tracepoint made. */
566 static int tracepoint_count;
568 static struct cmd_list_element *breakpoint_set_cmdlist;
569 static struct cmd_list_element *breakpoint_show_cmdlist;
570 struct cmd_list_element *save_cmdlist;
572 /* Return whether a breakpoint is an active enabled breakpoint. */
574 breakpoint_enabled (struct breakpoint *b)
576 return (b->enable_state == bp_enabled);
579 /* Set breakpoint count to NUM. */
582 set_breakpoint_count (int num)
584 prev_breakpoint_count = breakpoint_count;
585 breakpoint_count = num;
586 set_internalvar_integer (lookup_internalvar ("bpnum"), num);
589 /* Used by `start_rbreak_breakpoints' below, to record the current
590 breakpoint count before "rbreak" creates any breakpoint. */
591 static int rbreak_start_breakpoint_count;
593 /* Called at the start an "rbreak" command to record the first
597 start_rbreak_breakpoints (void)
599 rbreak_start_breakpoint_count = breakpoint_count;
602 /* Called at the end of an "rbreak" command to record the last
606 end_rbreak_breakpoints (void)
608 prev_breakpoint_count = rbreak_start_breakpoint_count;
611 /* Used in run_command to zero the hit count when a new run starts. */
614 clear_breakpoint_hit_counts (void)
616 struct breakpoint *b;
622 /* Allocate a new counted_command_line with reference count of 1.
623 The new structure owns COMMANDS. */
625 static struct counted_command_line *
626 alloc_counted_command_line (struct command_line *commands)
628 struct counted_command_line *result
629 = xmalloc (sizeof (struct counted_command_line));
632 result->commands = commands;
636 /* Increment reference count. This does nothing if CMD is NULL. */
639 incref_counted_command_line (struct counted_command_line *cmd)
645 /* Decrement reference count. If the reference count reaches 0,
646 destroy the counted_command_line. Sets *CMDP to NULL. This does
647 nothing if *CMDP is NULL. */
650 decref_counted_command_line (struct counted_command_line **cmdp)
654 if (--(*cmdp)->refc == 0)
656 free_command_lines (&(*cmdp)->commands);
663 /* A cleanup function that calls decref_counted_command_line. */
666 do_cleanup_counted_command_line (void *arg)
668 decref_counted_command_line (arg);
671 /* Create a cleanup that calls decref_counted_command_line on the
674 static struct cleanup *
675 make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp)
677 return make_cleanup (do_cleanup_counted_command_line, cmdp);
681 /* Return the breakpoint with the specified number, or NULL
682 if the number does not refer to an existing breakpoint. */
685 get_breakpoint (int num)
687 struct breakpoint *b;
690 if (b->number == num)
698 /* Mark locations as "conditions have changed" in case the target supports
699 evaluating conditions on its side. */
702 mark_breakpoint_modified (struct breakpoint *b)
704 struct bp_location *loc;
706 /* This is only meaningful if the target is
707 evaluating conditions and if the user has
708 opted for condition evaluation on the target's
710 if (gdb_evaluates_breakpoint_condition_p ()
711 || !target_supports_evaluation_of_breakpoint_conditions ())
714 if (!is_breakpoint (b))
717 for (loc = b->loc; loc; loc = loc->next)
718 loc->condition_changed = condition_modified;
721 /* Mark location as "conditions have changed" in case the target supports
722 evaluating conditions on its side. */
725 mark_breakpoint_location_modified (struct bp_location *loc)
727 /* This is only meaningful if the target is
728 evaluating conditions and if the user has
729 opted for condition evaluation on the target's
731 if (gdb_evaluates_breakpoint_condition_p ()
732 || !target_supports_evaluation_of_breakpoint_conditions ())
736 if (!is_breakpoint (loc->owner))
739 loc->condition_changed = condition_modified;
742 /* Sets the condition-evaluation mode using the static global
743 condition_evaluation_mode. */
746 set_condition_evaluation_mode (char *args, int from_tty,
747 struct cmd_list_element *c)
749 struct breakpoint *b;
750 const char *old_mode, *new_mode;
752 if ((condition_evaluation_mode_1 == condition_evaluation_target)
753 && !target_supports_evaluation_of_breakpoint_conditions ())
755 condition_evaluation_mode_1 = condition_evaluation_mode;
756 warning (_("Target does not support breakpoint condition evaluation.\n"
757 "Using host evaluation mode instead."));
761 new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1);
762 old_mode = translate_condition_evaluation_mode (condition_evaluation_mode);
764 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
765 settings was "auto". */
766 condition_evaluation_mode = condition_evaluation_mode_1;
768 /* Only update the mode if the user picked a different one. */
769 if (new_mode != old_mode)
771 struct bp_location *loc, **loc_tmp;
772 /* If the user switched to a different evaluation mode, we
773 need to synch the changes with the target as follows:
775 "host" -> "target": Send all (valid) conditions to the target.
776 "target" -> "host": Remove all the conditions from the target.
779 if (new_mode == condition_evaluation_target)
781 /* Mark everything modified and synch conditions with the
783 ALL_BP_LOCATIONS (loc, loc_tmp)
784 mark_breakpoint_location_modified (loc);
788 /* Manually mark non-duplicate locations to synch conditions
789 with the target. We do this to remove all the conditions the
790 target knows about. */
791 ALL_BP_LOCATIONS (loc, loc_tmp)
792 if (is_breakpoint (loc->owner) && loc->inserted)
793 loc->needs_update = 1;
797 update_global_location_list (1);
803 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
804 what "auto" is translating to. */
807 show_condition_evaluation_mode (struct ui_file *file, int from_tty,
808 struct cmd_list_element *c, const char *value)
810 if (condition_evaluation_mode == condition_evaluation_auto)
811 fprintf_filtered (file,
812 _("Breakpoint condition evaluation "
813 "mode is %s (currently %s).\n"),
815 breakpoint_condition_evaluation_mode ());
817 fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"),
821 /* A comparison function for bp_location AP and BP that is used by
822 bsearch. This comparison function only cares about addresses, unlike
823 the more general bp_location_compare function. */
826 bp_location_compare_addrs (const void *ap, const void *bp)
828 struct bp_location *a = *(void **) ap;
829 struct bp_location *b = *(void **) bp;
831 if (a->address == b->address)
834 return ((a->address > b->address) - (a->address < b->address));
837 /* Helper function to skip all bp_locations with addresses
838 less than ADDRESS. It returns the first bp_location that
839 is greater than or equal to ADDRESS. If none is found, just
842 static struct bp_location **
843 get_first_locp_gte_addr (CORE_ADDR address)
845 struct bp_location dummy_loc;
846 struct bp_location *dummy_locp = &dummy_loc;
847 struct bp_location **locp_found = NULL;
849 /* Initialize the dummy location's address field. */
850 memset (&dummy_loc, 0, sizeof (struct bp_location));
851 dummy_loc.address = address;
853 /* Find a close match to the first location at ADDRESS. */
854 locp_found = bsearch (&dummy_locp, bp_location, bp_location_count,
855 sizeof (struct bp_location **),
856 bp_location_compare_addrs);
858 /* Nothing was found, nothing left to do. */
859 if (locp_found == NULL)
862 /* We may have found a location that is at ADDRESS but is not the first in the
863 location's list. Go backwards (if possible) and locate the first one. */
864 while ((locp_found - 1) >= bp_location
865 && (*(locp_found - 1))->address == address)
872 set_breakpoint_condition (struct breakpoint *b, char *exp,
875 xfree (b->cond_string);
876 b->cond_string = NULL;
878 if (is_watchpoint (b))
880 struct watchpoint *w = (struct watchpoint *) b;
887 struct bp_location *loc;
889 for (loc = b->loc; loc; loc = loc->next)
894 /* No need to free the condition agent expression
895 bytecode (if we have one). We will handle this
896 when we go through update_global_location_list. */
903 printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number);
909 /* I don't know if it matters whether this is the string the user
910 typed in or the decompiled expression. */
911 b->cond_string = xstrdup (arg);
912 b->condition_not_parsed = 0;
914 if (is_watchpoint (b))
916 struct watchpoint *w = (struct watchpoint *) b;
918 innermost_block = NULL;
920 w->cond_exp = parse_exp_1 (&arg, 0, 0);
922 error (_("Junk at end of expression"));
923 w->cond_exp_valid_block = innermost_block;
927 struct bp_location *loc;
929 for (loc = b->loc; loc; loc = loc->next)
933 parse_exp_1 (&arg, block_for_pc (loc->address), 0);
935 error (_("Junk at end of expression"));
939 mark_breakpoint_modified (b);
941 breakpoints_changed ();
942 observer_notify_breakpoint_modified (b);
945 /* condition N EXP -- set break condition of breakpoint N to EXP. */
948 condition_command (char *arg, int from_tty)
950 struct breakpoint *b;
955 error_no_arg (_("breakpoint number"));
958 bnum = get_number (&p);
960 error (_("Bad breakpoint argument: '%s'"), arg);
963 if (b->number == bnum)
965 /* Check if this breakpoint has a Python object assigned to
966 it, and if it has a definition of the "stop"
967 method. This method and conditions entered into GDB from
968 the CLI are mutually exclusive. */
970 && gdbpy_breakpoint_has_py_cond (b->py_bp_object))
971 error (_("Cannot set a condition where a Python 'stop' "
972 "method has been defined in the breakpoint."));
973 set_breakpoint_condition (b, p, from_tty);
975 if (is_breakpoint (b))
976 update_global_location_list (1);
981 error (_("No breakpoint number %d."), bnum);
984 /* Check that COMMAND do not contain commands that are suitable
985 only for tracepoints and not suitable for ordinary breakpoints.
986 Throw if any such commands is found. */
989 check_no_tracepoint_commands (struct command_line *commands)
991 struct command_line *c;
993 for (c = commands; c; c = c->next)
997 if (c->control_type == while_stepping_control)
998 error (_("The 'while-stepping' command can "
999 "only be used for tracepoints"));
1001 for (i = 0; i < c->body_count; ++i)
1002 check_no_tracepoint_commands ((c->body_list)[i]);
1004 /* Not that command parsing removes leading whitespace and comment
1005 lines and also empty lines. So, we only need to check for
1006 command directly. */
1007 if (strstr (c->line, "collect ") == c->line)
1008 error (_("The 'collect' command can only be used for tracepoints"));
1010 if (strstr (c->line, "teval ") == c->line)
1011 error (_("The 'teval' command can only be used for tracepoints"));
1015 /* Encapsulate tests for different types of tracepoints. */
1018 is_tracepoint_type (enum bptype type)
1020 return (type == bp_tracepoint
1021 || type == bp_fast_tracepoint
1022 || type == bp_static_tracepoint);
1026 is_tracepoint (const struct breakpoint *b)
1028 return is_tracepoint_type (b->type);
1031 /* A helper function that validates that COMMANDS are valid for a
1032 breakpoint. This function will throw an exception if a problem is
1036 validate_commands_for_breakpoint (struct breakpoint *b,
1037 struct command_line *commands)
1039 if (is_tracepoint (b))
1041 /* We need to verify that each top-level element of commands is
1042 valid for tracepoints, that there's at most one
1043 while-stepping element, and that while-stepping's body has
1044 valid tracing commands excluding nested while-stepping. */
1045 struct command_line *c;
1046 struct command_line *while_stepping = 0;
1047 for (c = commands; c; c = c->next)
1049 if (c->control_type == while_stepping_control)
1051 if (b->type == bp_fast_tracepoint)
1052 error (_("The 'while-stepping' command "
1053 "cannot be used for fast tracepoint"));
1054 else if (b->type == bp_static_tracepoint)
1055 error (_("The 'while-stepping' command "
1056 "cannot be used for static tracepoint"));
1059 error (_("The 'while-stepping' command "
1060 "can be used only once"));
1067 struct command_line *c2;
1069 gdb_assert (while_stepping->body_count == 1);
1070 c2 = while_stepping->body_list[0];
1071 for (; c2; c2 = c2->next)
1073 if (c2->control_type == while_stepping_control)
1074 error (_("The 'while-stepping' command cannot be nested"));
1080 check_no_tracepoint_commands (commands);
1084 /* Return a vector of all the static tracepoints set at ADDR. The
1085 caller is responsible for releasing the vector. */
1088 static_tracepoints_here (CORE_ADDR addr)
1090 struct breakpoint *b;
1091 VEC(breakpoint_p) *found = 0;
1092 struct bp_location *loc;
1095 if (b->type == bp_static_tracepoint)
1097 for (loc = b->loc; loc; loc = loc->next)
1098 if (loc->address == addr)
1099 VEC_safe_push(breakpoint_p, found, b);
1105 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1106 validate that only allowed commands are included. */
1109 breakpoint_set_commands (struct breakpoint *b,
1110 struct command_line *commands)
1112 validate_commands_for_breakpoint (b, commands);
1114 decref_counted_command_line (&b->commands);
1115 b->commands = alloc_counted_command_line (commands);
1116 breakpoints_changed ();
1117 observer_notify_breakpoint_modified (b);
1120 /* Set the internal `silent' flag on the breakpoint. Note that this
1121 is not the same as the "silent" that may appear in the breakpoint's
1125 breakpoint_set_silent (struct breakpoint *b, int silent)
1127 int old_silent = b->silent;
1130 if (old_silent != silent)
1131 observer_notify_breakpoint_modified (b);
1134 /* Set the thread for this breakpoint. If THREAD is -1, make the
1135 breakpoint work for any thread. */
1138 breakpoint_set_thread (struct breakpoint *b, int thread)
1140 int old_thread = b->thread;
1143 if (old_thread != thread)
1144 observer_notify_breakpoint_modified (b);
1147 /* Set the task for this breakpoint. If TASK is 0, make the
1148 breakpoint work for any task. */
1151 breakpoint_set_task (struct breakpoint *b, int task)
1153 int old_task = b->task;
1156 if (old_task != task)
1157 observer_notify_breakpoint_modified (b);
1161 check_tracepoint_command (char *line, void *closure)
1163 struct breakpoint *b = closure;
1165 validate_actionline (&line, b);
1168 /* A structure used to pass information through
1169 map_breakpoint_numbers. */
1171 struct commands_info
1173 /* True if the command was typed at a tty. */
1176 /* The breakpoint range spec. */
1179 /* Non-NULL if the body of the commands are being read from this
1180 already-parsed command. */
1181 struct command_line *control;
1183 /* The command lines read from the user, or NULL if they have not
1185 struct counted_command_line *cmd;
1188 /* A callback for map_breakpoint_numbers that sets the commands for
1189 commands_command. */
1192 do_map_commands_command (struct breakpoint *b, void *data)
1194 struct commands_info *info = data;
1196 if (info->cmd == NULL)
1198 struct command_line *l;
1200 if (info->control != NULL)
1201 l = copy_command_lines (info->control->body_list[0]);
1204 struct cleanup *old_chain;
1207 str = xstrprintf (_("Type commands for breakpoint(s) "
1208 "%s, one per line."),
1211 old_chain = make_cleanup (xfree, str);
1213 l = read_command_lines (str,
1216 ? check_tracepoint_command : 0),
1219 do_cleanups (old_chain);
1222 info->cmd = alloc_counted_command_line (l);
1225 /* If a breakpoint was on the list more than once, we don't need to
1227 if (b->commands != info->cmd)
1229 validate_commands_for_breakpoint (b, info->cmd->commands);
1230 incref_counted_command_line (info->cmd);
1231 decref_counted_command_line (&b->commands);
1232 b->commands = info->cmd;
1233 breakpoints_changed ();
1234 observer_notify_breakpoint_modified (b);
1239 commands_command_1 (char *arg, int from_tty,
1240 struct command_line *control)
1242 struct cleanup *cleanups;
1243 struct commands_info info;
1245 info.from_tty = from_tty;
1246 info.control = control;
1248 /* If we read command lines from the user, then `info' will hold an
1249 extra reference to the commands that we must clean up. */
1250 cleanups = make_cleanup_decref_counted_command_line (&info.cmd);
1252 if (arg == NULL || !*arg)
1254 if (breakpoint_count - prev_breakpoint_count > 1)
1255 arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1,
1257 else if (breakpoint_count > 0)
1258 arg = xstrprintf ("%d", breakpoint_count);
1261 /* So that we don't try to free the incoming non-NULL
1262 argument in the cleanup below. Mapping breakpoint
1263 numbers will fail in this case. */
1268 /* The command loop has some static state, so we need to preserve
1270 arg = xstrdup (arg);
1273 make_cleanup (xfree, arg);
1277 map_breakpoint_numbers (arg, do_map_commands_command, &info);
1279 if (info.cmd == NULL)
1280 error (_("No breakpoints specified."));
1282 do_cleanups (cleanups);
1286 commands_command (char *arg, int from_tty)
1288 commands_command_1 (arg, from_tty, NULL);
1291 /* Like commands_command, but instead of reading the commands from
1292 input stream, takes them from an already parsed command structure.
1294 This is used by cli-script.c to DTRT with breakpoint commands
1295 that are part of if and while bodies. */
1296 enum command_control_type
1297 commands_from_control_command (char *arg, struct command_line *cmd)
1299 commands_command_1 (arg, 0, cmd);
1300 return simple_control;
1303 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1306 bp_location_has_shadow (struct bp_location *bl)
1308 if (bl->loc_type != bp_loc_software_breakpoint)
1312 if (bl->target_info.shadow_len == 0)
1313 /* BL isn't valid, or doesn't shadow memory. */
1318 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1319 by replacing any memory breakpoints with their shadowed contents.
1321 The range of shadowed area by each bp_location is:
1322 bl->address - bp_location_placed_address_before_address_max
1323 up to bl->address + bp_location_shadow_len_after_address_max
1324 The range we were requested to resolve shadows for is:
1325 memaddr ... memaddr + len
1326 Thus the safe cutoff boundaries for performance optimization are
1327 memaddr + len <= (bl->address
1328 - bp_location_placed_address_before_address_max)
1330 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1333 breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf,
1334 const gdb_byte *writebuf_org,
1335 ULONGEST memaddr, LONGEST len)
1337 /* Left boundary, right boundary and median element of our binary
1339 unsigned bc_l, bc_r, bc;
1341 /* Find BC_L which is a leftmost element which may affect BUF
1342 content. It is safe to report lower value but a failure to
1343 report higher one. */
1346 bc_r = bp_location_count;
1347 while (bc_l + 1 < bc_r)
1349 struct bp_location *bl;
1351 bc = (bc_l + bc_r) / 2;
1352 bl = bp_location[bc];
1354 /* Check first BL->ADDRESS will not overflow due to the added
1355 constant. Then advance the left boundary only if we are sure
1356 the BC element can in no way affect the BUF content (MEMADDR
1357 to MEMADDR + LEN range).
1359 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1360 offset so that we cannot miss a breakpoint with its shadow
1361 range tail still reaching MEMADDR. */
1363 if ((bl->address + bp_location_shadow_len_after_address_max
1365 && (bl->address + bp_location_shadow_len_after_address_max
1372 /* Due to the binary search above, we need to make sure we pick the
1373 first location that's at BC_L's address. E.g., if there are
1374 multiple locations at the same address, BC_L may end up pointing
1375 at a duplicate location, and miss the "master"/"inserted"
1376 location. Say, given locations L1, L2 and L3 at addresses A and
1379 L1@A, L2@A, L3@B, ...
1381 BC_L could end up pointing at location L2, while the "master"
1382 location could be L1. Since the `loc->inserted' flag is only set
1383 on "master" locations, we'd forget to restore the shadow of L1
1386 && bp_location[bc_l]->address == bp_location[bc_l - 1]->address)
1389 /* Now do full processing of the found relevant range of elements. */
1391 for (bc = bc_l; bc < bp_location_count; bc++)
1393 struct bp_location *bl = bp_location[bc];
1394 CORE_ADDR bp_addr = 0;
1398 /* bp_location array has BL->OWNER always non-NULL. */
1399 if (bl->owner->type == bp_none)
1400 warning (_("reading through apparently deleted breakpoint #%d?"),
1403 /* Performance optimization: any further element can no longer affect BUF
1406 if (bl->address >= bp_location_placed_address_before_address_max
1407 && memaddr + len <= (bl->address
1408 - bp_location_placed_address_before_address_max))
1411 if (!bp_location_has_shadow (bl))
1413 if (!breakpoint_address_match (bl->target_info.placed_address_space, 0,
1414 current_program_space->aspace, 0))
1417 /* Addresses and length of the part of the breakpoint that
1419 bp_addr = bl->target_info.placed_address;
1420 bp_size = bl->target_info.shadow_len;
1422 if (bp_addr + bp_size <= memaddr)
1423 /* The breakpoint is entirely before the chunk of memory we
1427 if (bp_addr >= memaddr + len)
1428 /* The breakpoint is entirely after the chunk of memory we are
1432 /* Offset within shadow_contents. */
1433 if (bp_addr < memaddr)
1435 /* Only copy the second part of the breakpoint. */
1436 bp_size -= memaddr - bp_addr;
1437 bptoffset = memaddr - bp_addr;
1441 if (bp_addr + bp_size > memaddr + len)
1443 /* Only copy the first part of the breakpoint. */
1444 bp_size -= (bp_addr + bp_size) - (memaddr + len);
1447 if (readbuf != NULL)
1449 /* Update the read buffer with this inserted breakpoint's
1451 memcpy (readbuf + bp_addr - memaddr,
1452 bl->target_info.shadow_contents + bptoffset, bp_size);
1456 struct gdbarch *gdbarch = bl->gdbarch;
1457 const unsigned char *bp;
1458 CORE_ADDR placed_address = bl->target_info.placed_address;
1459 unsigned placed_size = bl->target_info.placed_size;
1461 /* Update the shadow with what we want to write to memory. */
1462 memcpy (bl->target_info.shadow_contents + bptoffset,
1463 writebuf_org + bp_addr - memaddr, bp_size);
1465 /* Determine appropriate breakpoint contents and size for this
1467 bp = gdbarch_breakpoint_from_pc (gdbarch, &placed_address, &placed_size);
1469 /* Update the final write buffer with this inserted
1470 breakpoint's INSN. */
1471 memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size);
1477 /* Return true if BPT is either a software breakpoint or a hardware
1481 is_breakpoint (const struct breakpoint *bpt)
1483 return (bpt->type == bp_breakpoint
1484 || bpt->type == bp_hardware_breakpoint);
1487 /* Return true if BPT is of any hardware watchpoint kind. */
1490 is_hardware_watchpoint (const struct breakpoint *bpt)
1492 return (bpt->type == bp_hardware_watchpoint
1493 || bpt->type == bp_read_watchpoint
1494 || bpt->type == bp_access_watchpoint);
1497 /* Return true if BPT is of any watchpoint kind, hardware or
1501 is_watchpoint (const struct breakpoint *bpt)
1503 return (is_hardware_watchpoint (bpt)
1504 || bpt->type == bp_watchpoint);
1507 /* Returns true if the current thread and its running state are safe
1508 to evaluate or update watchpoint B. Watchpoints on local
1509 expressions need to be evaluated in the context of the thread that
1510 was current when the watchpoint was created, and, that thread needs
1511 to be stopped to be able to select the correct frame context.
1512 Watchpoints on global expressions can be evaluated on any thread,
1513 and in any state. It is presently left to the target allowing
1514 memory accesses when threads are running. */
1517 watchpoint_in_thread_scope (struct watchpoint *b)
1519 return (b->base.pspace == current_program_space
1520 && (ptid_equal (b->watchpoint_thread, null_ptid)
1521 || (ptid_equal (inferior_ptid, b->watchpoint_thread)
1522 && !is_executing (inferior_ptid))));
1525 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1526 associated bp_watchpoint_scope breakpoint. */
1529 watchpoint_del_at_next_stop (struct watchpoint *w)
1531 struct breakpoint *b = &w->base;
1533 if (b->related_breakpoint != b)
1535 gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope);
1536 gdb_assert (b->related_breakpoint->related_breakpoint == b);
1537 b->related_breakpoint->disposition = disp_del_at_next_stop;
1538 b->related_breakpoint->related_breakpoint = b->related_breakpoint;
1539 b->related_breakpoint = b;
1541 b->disposition = disp_del_at_next_stop;
1544 /* Assuming that B is a watchpoint:
1545 - Reparse watchpoint expression, if REPARSE is non-zero
1546 - Evaluate expression and store the result in B->val
1547 - Evaluate the condition if there is one, and store the result
1549 - Update the list of values that must be watched in B->loc.
1551 If the watchpoint disposition is disp_del_at_next_stop, then do
1552 nothing. If this is local watchpoint that is out of scope, delete
1555 Even with `set breakpoint always-inserted on' the watchpoints are
1556 removed + inserted on each stop here. Normal breakpoints must
1557 never be removed because they might be missed by a running thread
1558 when debugging in non-stop mode. On the other hand, hardware
1559 watchpoints (is_hardware_watchpoint; processed here) are specific
1560 to each LWP since they are stored in each LWP's hardware debug
1561 registers. Therefore, such LWP must be stopped first in order to
1562 be able to modify its hardware watchpoints.
1564 Hardware watchpoints must be reset exactly once after being
1565 presented to the user. It cannot be done sooner, because it would
1566 reset the data used to present the watchpoint hit to the user. And
1567 it must not be done later because it could display the same single
1568 watchpoint hit during multiple GDB stops. Note that the latter is
1569 relevant only to the hardware watchpoint types bp_read_watchpoint
1570 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1571 not user-visible - its hit is suppressed if the memory content has
1574 The following constraints influence the location where we can reset
1575 hardware watchpoints:
1577 * target_stopped_by_watchpoint and target_stopped_data_address are
1578 called several times when GDB stops.
1581 * Multiple hardware watchpoints can be hit at the same time,
1582 causing GDB to stop. GDB only presents one hardware watchpoint
1583 hit at a time as the reason for stopping, and all the other hits
1584 are presented later, one after the other, each time the user
1585 requests the execution to be resumed. Execution is not resumed
1586 for the threads still having pending hit event stored in
1587 LWP_INFO->STATUS. While the watchpoint is already removed from
1588 the inferior on the first stop the thread hit event is kept being
1589 reported from its cached value by linux_nat_stopped_data_address
1590 until the real thread resume happens after the watchpoint gets
1591 presented and thus its LWP_INFO->STATUS gets reset.
1593 Therefore the hardware watchpoint hit can get safely reset on the
1594 watchpoint removal from inferior. */
1597 update_watchpoint (struct watchpoint *b, int reparse)
1599 int within_current_scope;
1600 struct frame_id saved_frame_id;
1603 /* If this is a local watchpoint, we only want to check if the
1604 watchpoint frame is in scope if the current thread is the thread
1605 that was used to create the watchpoint. */
1606 if (!watchpoint_in_thread_scope (b))
1609 if (b->base.disposition == disp_del_at_next_stop)
1614 /* Determine if the watchpoint is within scope. */
1615 if (b->exp_valid_block == NULL)
1616 within_current_scope = 1;
1619 struct frame_info *fi = get_current_frame ();
1620 struct gdbarch *frame_arch = get_frame_arch (fi);
1621 CORE_ADDR frame_pc = get_frame_pc (fi);
1623 /* If we're in a function epilogue, unwinding may not work
1624 properly, so do not attempt to recreate locations at this
1625 point. See similar comments in watchpoint_check. */
1626 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
1629 /* Save the current frame's ID so we can restore it after
1630 evaluating the watchpoint expression on its own frame. */
1631 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1632 took a frame parameter, so that we didn't have to change the
1635 saved_frame_id = get_frame_id (get_selected_frame (NULL));
1637 fi = frame_find_by_id (b->watchpoint_frame);
1638 within_current_scope = (fi != NULL);
1639 if (within_current_scope)
1643 /* We don't free locations. They are stored in the bp_location array
1644 and update_global_location_list will eventually delete them and
1645 remove breakpoints if needed. */
1648 if (within_current_scope && reparse)
1657 s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string;
1658 b->exp = parse_exp_1 (&s, b->exp_valid_block, 0);
1659 /* If the meaning of expression itself changed, the old value is
1660 no longer relevant. We don't want to report a watchpoint hit
1661 to the user when the old value and the new value may actually
1662 be completely different objects. */
1663 value_free (b->val);
1667 /* Note that unlike with breakpoints, the watchpoint's condition
1668 expression is stored in the breakpoint object, not in the
1669 locations (re)created below. */
1670 if (b->base.cond_string != NULL)
1672 if (b->cond_exp != NULL)
1674 xfree (b->cond_exp);
1678 s = b->base.cond_string;
1679 b->cond_exp = parse_exp_1 (&s, b->cond_exp_valid_block, 0);
1683 /* If we failed to parse the expression, for example because
1684 it refers to a global variable in a not-yet-loaded shared library,
1685 don't try to insert watchpoint. We don't automatically delete
1686 such watchpoint, though, since failure to parse expression
1687 is different from out-of-scope watchpoint. */
1688 if ( !target_has_execution)
1690 /* Without execution, memory can't change. No use to try and
1691 set watchpoint locations. The watchpoint will be reset when
1692 the target gains execution, through breakpoint_re_set. */
1694 else if (within_current_scope && b->exp)
1697 struct value *val_chain, *v, *result, *next;
1698 struct program_space *frame_pspace;
1700 fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain);
1702 /* Avoid setting b->val if it's already set. The meaning of
1703 b->val is 'the last value' user saw, and we should update
1704 it only if we reported that last value to user. As it
1705 happens, the code that reports it updates b->val directly.
1706 We don't keep track of the memory value for masked
1708 if (!b->val_valid && !is_masked_watchpoint (&b->base))
1714 frame_pspace = get_frame_program_space (get_selected_frame (NULL));
1716 /* Look at each value on the value chain. */
1717 for (v = val_chain; v; v = value_next (v))
1719 /* If it's a memory location, and GDB actually needed
1720 its contents to evaluate the expression, then we
1721 must watch it. If the first value returned is
1722 still lazy, that means an error occurred reading it;
1723 watch it anyway in case it becomes readable. */
1724 if (VALUE_LVAL (v) == lval_memory
1725 && (v == val_chain || ! value_lazy (v)))
1727 struct type *vtype = check_typedef (value_type (v));
1729 /* We only watch structs and arrays if user asked
1730 for it explicitly, never if they just happen to
1731 appear in the middle of some value chain. */
1733 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1734 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1738 struct bp_location *loc, **tmp;
1740 addr = value_address (v);
1741 len = TYPE_LENGTH (value_type (v));
1743 if (b->base.type == bp_read_watchpoint)
1745 else if (b->base.type == bp_access_watchpoint)
1748 loc = allocate_bp_location (&b->base);
1749 for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next))
1752 loc->gdbarch = get_type_arch (value_type (v));
1754 loc->pspace = frame_pspace;
1755 loc->address = addr;
1757 loc->watchpoint_type = type;
1762 /* Change the type of breakpoint between hardware assisted or
1763 an ordinary watchpoint depending on the hardware support
1764 and free hardware slots. REPARSE is set when the inferior
1769 enum bp_loc_type loc_type;
1770 struct bp_location *bl;
1772 reg_cnt = can_use_hardware_watchpoint (val_chain);
1776 int i, target_resources_ok, other_type_used;
1779 /* Use an exact watchpoint when there's only one memory region to be
1780 watched, and only one debug register is needed to watch it. */
1781 b->exact = target_exact_watchpoints && reg_cnt == 1;
1783 /* We need to determine how many resources are already
1784 used for all other hardware watchpoints plus this one
1785 to see if we still have enough resources to also fit
1786 this watchpoint in as well. */
1788 /* If this is a software watchpoint, we try to turn it
1789 to a hardware one -- count resources as if B was of
1790 hardware watchpoint type. */
1791 type = b->base.type;
1792 if (type == bp_watchpoint)
1793 type = bp_hardware_watchpoint;
1795 /* This watchpoint may or may not have been placed on
1796 the list yet at this point (it won't be in the list
1797 if we're trying to create it for the first time,
1798 through watch_command), so always account for it
1801 /* Count resources used by all watchpoints except B. */
1802 i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used);
1804 /* Add in the resources needed for B. */
1805 i += hw_watchpoint_use_count (&b->base);
1808 = target_can_use_hardware_watchpoint (type, i, other_type_used);
1809 if (target_resources_ok <= 0)
1811 int sw_mode = b->base.ops->works_in_software_mode (&b->base);
1813 if (target_resources_ok == 0 && !sw_mode)
1814 error (_("Target does not support this type of "
1815 "hardware watchpoint."));
1816 else if (target_resources_ok < 0 && !sw_mode)
1817 error (_("There are not enough available hardware "
1818 "resources for this watchpoint."));
1820 /* Downgrade to software watchpoint. */
1821 b->base.type = bp_watchpoint;
1825 /* If this was a software watchpoint, we've just
1826 found we have enough resources to turn it to a
1827 hardware watchpoint. Otherwise, this is a
1829 b->base.type = type;
1832 else if (!b->base.ops->works_in_software_mode (&b->base))
1833 error (_("Expression cannot be implemented with "
1834 "read/access watchpoint."));
1836 b->base.type = bp_watchpoint;
1838 loc_type = (b->base.type == bp_watchpoint? bp_loc_other
1839 : bp_loc_hardware_watchpoint);
1840 for (bl = b->base.loc; bl; bl = bl->next)
1841 bl->loc_type = loc_type;
1844 for (v = val_chain; v; v = next)
1846 next = value_next (v);
1851 /* If a software watchpoint is not watching any memory, then the
1852 above left it without any location set up. But,
1853 bpstat_stop_status requires a location to be able to report
1854 stops, so make sure there's at least a dummy one. */
1855 if (b->base.type == bp_watchpoint && b->base.loc == NULL)
1857 struct breakpoint *base = &b->base;
1858 base->loc = allocate_bp_location (base);
1859 base->loc->pspace = frame_pspace;
1860 base->loc->address = -1;
1861 base->loc->length = -1;
1862 base->loc->watchpoint_type = -1;
1865 else if (!within_current_scope)
1867 printf_filtered (_("\
1868 Watchpoint %d deleted because the program has left the block\n\
1869 in which its expression is valid.\n"),
1871 watchpoint_del_at_next_stop (b);
1874 /* Restore the selected frame. */
1876 select_frame (frame_find_by_id (saved_frame_id));
1880 /* Returns 1 iff breakpoint location should be
1881 inserted in the inferior. We don't differentiate the type of BL's owner
1882 (breakpoint vs. tracepoint), although insert_location in tracepoint's
1883 breakpoint_ops is not defined, because in insert_bp_location,
1884 tracepoint's insert_location will not be called. */
1886 should_be_inserted (struct bp_location *bl)
1888 if (bl->owner == NULL || !breakpoint_enabled (bl->owner))
1891 if (bl->owner->disposition == disp_del_at_next_stop)
1894 if (!bl->enabled || bl->shlib_disabled || bl->duplicate)
1897 if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup)
1900 /* This is set for example, when we're attached to the parent of a
1901 vfork, and have detached from the child. The child is running
1902 free, and we expect it to do an exec or exit, at which point the
1903 OS makes the parent schedulable again (and the target reports
1904 that the vfork is done). Until the child is done with the shared
1905 memory region, do not insert breakpoints in the parent, otherwise
1906 the child could still trip on the parent's breakpoints. Since
1907 the parent is blocked anyway, it won't miss any breakpoint. */
1908 if (bl->pspace->breakpoints_not_allowed)
1914 /* Same as should_be_inserted but does the check assuming
1915 that the location is not duplicated. */
1918 unduplicated_should_be_inserted (struct bp_location *bl)
1921 const int save_duplicate = bl->duplicate;
1924 result = should_be_inserted (bl);
1925 bl->duplicate = save_duplicate;
1929 /* Parses a conditional described by an expression COND into an
1930 agent expression bytecode suitable for evaluation
1931 by the bytecode interpreter. Return NULL if there was
1932 any error during parsing. */
1934 static struct agent_expr *
1935 parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond)
1937 struct agent_expr *aexpr = NULL;
1938 struct cleanup *old_chain = NULL;
1939 volatile struct gdb_exception ex;
1944 /* We don't want to stop processing, so catch any errors
1945 that may show up. */
1946 TRY_CATCH (ex, RETURN_MASK_ERROR)
1948 aexpr = gen_eval_for_expr (scope, cond);
1953 /* If we got here, it means the condition could not be parsed to a valid
1954 bytecode expression and thus can't be evaluated on the target's side.
1955 It's no use iterating through the conditions. */
1959 /* We have a valid agent expression. */
1963 /* Based on location BL, create a list of breakpoint conditions to be
1964 passed on to the target. If we have duplicated locations with different
1965 conditions, we will add such conditions to the list. The idea is that the
1966 target will evaluate the list of conditions and will only notify GDB when
1967 one of them is true. */
1970 build_target_condition_list (struct bp_location *bl)
1972 struct bp_location **locp = NULL, **loc2p;
1973 int null_condition_or_parse_error = 0;
1974 int modified = bl->needs_update;
1975 struct bp_location *loc;
1977 /* This is only meaningful if the target is
1978 evaluating conditions and if the user has
1979 opted for condition evaluation on the target's
1981 if (gdb_evaluates_breakpoint_condition_p ()
1982 || !target_supports_evaluation_of_breakpoint_conditions ())
1985 /* Do a first pass to check for locations with no assigned
1986 conditions or conditions that fail to parse to a valid agent expression
1987 bytecode. If any of these happen, then it's no use to send conditions
1988 to the target since this location will always trigger and generate a
1989 response back to GDB. */
1990 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
1993 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
1997 struct agent_expr *aexpr;
1999 /* Re-parse the conditions since something changed. In that
2000 case we already freed the condition bytecodes (see
2001 force_breakpoint_reinsertion). We just
2002 need to parse the condition to bytecodes again. */
2003 aexpr = parse_cond_to_aexpr (bl->address, loc->cond);
2004 loc->cond_bytecode = aexpr;
2006 /* Check if we managed to parse the conditional expression
2007 correctly. If not, we will not send this condition
2013 /* If we have a NULL bytecode expression, it means something
2014 went wrong or we have a null condition expression. */
2015 if (!loc->cond_bytecode)
2017 null_condition_or_parse_error = 1;
2023 /* If any of these happened, it means we will have to evaluate the conditions
2024 for the location's address on gdb's side. It is no use keeping bytecodes
2025 for all the other duplicate locations, thus we free all of them here.
2027 This is so we have a finer control over which locations' conditions are
2028 being evaluated by GDB or the remote stub. */
2029 if (null_condition_or_parse_error)
2031 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2034 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2036 /* Only go as far as the first NULL bytecode is
2038 if (!loc->cond_bytecode)
2041 free_agent_expr (loc->cond_bytecode);
2042 loc->cond_bytecode = NULL;
2047 /* No NULL conditions or failed bytecode generation. Build a condition list
2048 for this location's address. */
2049 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2053 && is_breakpoint (loc->owner)
2054 && loc->pspace->num == bl->pspace->num
2055 && loc->owner->enable_state == bp_enabled
2057 /* Add the condition to the vector. This will be used later to send the
2058 conditions to the target. */
2059 VEC_safe_push (agent_expr_p, bl->target_info.conditions,
2060 loc->cond_bytecode);
2066 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2067 location. Any error messages are printed to TMP_ERROR_STREAM; and
2068 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2069 Returns 0 for success, 1 if the bp_location type is not supported or
2072 NOTE drow/2003-09-09: This routine could be broken down to an
2073 object-style method for each breakpoint or catchpoint type. */
2075 insert_bp_location (struct bp_location *bl,
2076 struct ui_file *tmp_error_stream,
2077 int *disabled_breaks,
2078 int *hw_breakpoint_error)
2082 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
2085 /* Initialize the target-specific information. */
2086 memset (&bl->target_info, 0, sizeof (bl->target_info));
2087 bl->target_info.placed_address = bl->address;
2088 bl->target_info.placed_address_space = bl->pspace->aspace;
2089 bl->target_info.length = bl->length;
2091 /* When working with target-side conditions, we must pass all the conditions
2092 for the same breakpoint address down to the target since GDB will not
2093 insert those locations. With a list of breakpoint conditions, the target
2094 can decide when to stop and notify GDB. */
2096 if (is_breakpoint (bl->owner))
2098 build_target_condition_list (bl);
2099 /* Reset the condition modification marker. */
2100 bl->needs_update = 0;
2103 if (bl->loc_type == bp_loc_software_breakpoint
2104 || bl->loc_type == bp_loc_hardware_breakpoint)
2106 if (bl->owner->type != bp_hardware_breakpoint)
2108 /* If the explicitly specified breakpoint type
2109 is not hardware breakpoint, check the memory map to see
2110 if the breakpoint address is in read only memory or not.
2112 Two important cases are:
2113 - location type is not hardware breakpoint, memory
2114 is readonly. We change the type of the location to
2115 hardware breakpoint.
2116 - location type is hardware breakpoint, memory is
2117 read-write. This means we've previously made the
2118 location hardware one, but then the memory map changed,
2121 When breakpoints are removed, remove_breakpoints will use
2122 location types we've just set here, the only possible
2123 problem is that memory map has changed during running
2124 program, but it's not going to work anyway with current
2126 struct mem_region *mr
2127 = lookup_mem_region (bl->target_info.placed_address);
2131 if (automatic_hardware_breakpoints)
2133 enum bp_loc_type new_type;
2135 if (mr->attrib.mode != MEM_RW)
2136 new_type = bp_loc_hardware_breakpoint;
2138 new_type = bp_loc_software_breakpoint;
2140 if (new_type != bl->loc_type)
2142 static int said = 0;
2144 bl->loc_type = new_type;
2147 fprintf_filtered (gdb_stdout,
2148 _("Note: automatically using "
2149 "hardware breakpoints for "
2150 "read-only addresses.\n"));
2155 else if (bl->loc_type == bp_loc_software_breakpoint
2156 && mr->attrib.mode != MEM_RW)
2157 warning (_("cannot set software breakpoint "
2158 "at readonly address %s"),
2159 paddress (bl->gdbarch, bl->address));
2163 /* First check to see if we have to handle an overlay. */
2164 if (overlay_debugging == ovly_off
2165 || bl->section == NULL
2166 || !(section_is_overlay (bl->section)))
2168 /* No overlay handling: just set the breakpoint. */
2170 val = bl->owner->ops->insert_location (bl);
2174 /* This breakpoint is in an overlay section.
2175 Shall we set a breakpoint at the LMA? */
2176 if (!overlay_events_enabled)
2178 /* Yes -- overlay event support is not active,
2179 so we must try to set a breakpoint at the LMA.
2180 This will not work for a hardware breakpoint. */
2181 if (bl->loc_type == bp_loc_hardware_breakpoint)
2182 warning (_("hardware breakpoint %d not supported in overlay!"),
2186 CORE_ADDR addr = overlay_unmapped_address (bl->address,
2188 /* Set a software (trap) breakpoint at the LMA. */
2189 bl->overlay_target_info = bl->target_info;
2190 bl->overlay_target_info.placed_address = addr;
2191 val = target_insert_breakpoint (bl->gdbarch,
2192 &bl->overlay_target_info);
2194 fprintf_unfiltered (tmp_error_stream,
2195 "Overlay breakpoint %d "
2196 "failed: in ROM?\n",
2200 /* Shall we set a breakpoint at the VMA? */
2201 if (section_is_mapped (bl->section))
2203 /* Yes. This overlay section is mapped into memory. */
2204 val = bl->owner->ops->insert_location (bl);
2208 /* No. This breakpoint will not be inserted.
2209 No error, but do not mark the bp as 'inserted'. */
2216 /* Can't set the breakpoint. */
2217 if (solib_name_from_address (bl->pspace, bl->address))
2219 /* See also: disable_breakpoints_in_shlibs. */
2221 bl->shlib_disabled = 1;
2222 observer_notify_breakpoint_modified (bl->owner);
2223 if (!*disabled_breaks)
2225 fprintf_unfiltered (tmp_error_stream,
2226 "Cannot insert breakpoint %d.\n",
2228 fprintf_unfiltered (tmp_error_stream,
2229 "Temporarily disabling shared "
2230 "library breakpoints:\n");
2232 *disabled_breaks = 1;
2233 fprintf_unfiltered (tmp_error_stream,
2234 "breakpoint #%d\n", bl->owner->number);
2238 if (bl->loc_type == bp_loc_hardware_breakpoint)
2240 *hw_breakpoint_error = 1;
2241 fprintf_unfiltered (tmp_error_stream,
2242 "Cannot insert hardware "
2248 fprintf_unfiltered (tmp_error_stream,
2249 "Cannot insert breakpoint %d.\n",
2251 fprintf_filtered (tmp_error_stream,
2252 "Error accessing memory address ");
2253 fputs_filtered (paddress (bl->gdbarch, bl->address),
2255 fprintf_filtered (tmp_error_stream, ": %s.\n",
2256 safe_strerror (val));
2267 else if (bl->loc_type == bp_loc_hardware_watchpoint
2268 /* NOTE drow/2003-09-08: This state only exists for removing
2269 watchpoints. It's not clear that it's necessary... */
2270 && bl->owner->disposition != disp_del_at_next_stop)
2272 gdb_assert (bl->owner->ops != NULL
2273 && bl->owner->ops->insert_location != NULL);
2275 val = bl->owner->ops->insert_location (bl);
2277 /* If trying to set a read-watchpoint, and it turns out it's not
2278 supported, try emulating one with an access watchpoint. */
2279 if (val == 1 && bl->watchpoint_type == hw_read)
2281 struct bp_location *loc, **loc_temp;
2283 /* But don't try to insert it, if there's already another
2284 hw_access location that would be considered a duplicate
2286 ALL_BP_LOCATIONS (loc, loc_temp)
2288 && loc->watchpoint_type == hw_access
2289 && watchpoint_locations_match (bl, loc))
2293 bl->target_info = loc->target_info;
2294 bl->watchpoint_type = hw_access;
2301 bl->watchpoint_type = hw_access;
2302 val = bl->owner->ops->insert_location (bl);
2305 /* Back to the original value. */
2306 bl->watchpoint_type = hw_read;
2310 bl->inserted = (val == 0);
2313 else if (bl->owner->type == bp_catchpoint)
2315 gdb_assert (bl->owner->ops != NULL
2316 && bl->owner->ops->insert_location != NULL);
2318 val = bl->owner->ops->insert_location (bl);
2321 bl->owner->enable_state = bp_disabled;
2325 Error inserting catchpoint %d: Your system does not support this type\n\
2326 of catchpoint."), bl->owner->number);
2328 warning (_("Error inserting catchpoint %d."), bl->owner->number);
2331 bl->inserted = (val == 0);
2333 /* We've already printed an error message if there was a problem
2334 inserting this catchpoint, and we've disabled the catchpoint,
2335 so just return success. */
2342 /* This function is called when program space PSPACE is about to be
2343 deleted. It takes care of updating breakpoints to not reference
2347 breakpoint_program_space_exit (struct program_space *pspace)
2349 struct breakpoint *b, *b_temp;
2350 struct bp_location *loc, **loc_temp;
2352 /* Remove any breakpoint that was set through this program space. */
2353 ALL_BREAKPOINTS_SAFE (b, b_temp)
2355 if (b->pspace == pspace)
2356 delete_breakpoint (b);
2359 /* Breakpoints set through other program spaces could have locations
2360 bound to PSPACE as well. Remove those. */
2361 ALL_BP_LOCATIONS (loc, loc_temp)
2363 struct bp_location *tmp;
2365 if (loc->pspace == pspace)
2367 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2368 if (loc->owner->loc == loc)
2369 loc->owner->loc = loc->next;
2371 for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next)
2372 if (tmp->next == loc)
2374 tmp->next = loc->next;
2380 /* Now update the global location list to permanently delete the
2381 removed locations above. */
2382 update_global_location_list (0);
2385 /* Make sure all breakpoints are inserted in inferior.
2386 Throws exception on any error.
2387 A breakpoint that is already inserted won't be inserted
2388 again, so calling this function twice is safe. */
2390 insert_breakpoints (void)
2392 struct breakpoint *bpt;
2394 ALL_BREAKPOINTS (bpt)
2395 if (is_hardware_watchpoint (bpt))
2397 struct watchpoint *w = (struct watchpoint *) bpt;
2399 update_watchpoint (w, 0 /* don't reparse. */);
2402 update_global_location_list (1);
2404 /* update_global_location_list does not insert breakpoints when
2405 always_inserted_mode is not enabled. Explicitly insert them
2407 if (!breakpoints_always_inserted_mode ())
2408 insert_breakpoint_locations ();
2411 /* This is used when we need to synch breakpoint conditions between GDB and the
2412 target. It is the case with deleting and disabling of breakpoints when using
2413 always-inserted mode. */
2416 update_inserted_breakpoint_locations (void)
2418 struct bp_location *bl, **blp_tmp;
2421 int disabled_breaks = 0;
2422 int hw_breakpoint_error = 0;
2424 struct ui_file *tmp_error_stream = mem_fileopen ();
2425 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
2427 /* Explicitly mark the warning -- this will only be printed if
2428 there was an error. */
2429 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
2431 save_current_space_and_thread ();
2433 ALL_BP_LOCATIONS (bl, blp_tmp)
2435 /* We only want to update software breakpoints and hardware
2437 if (!is_breakpoint (bl->owner))
2440 /* We only want to update locations that are already inserted
2441 and need updating. This is to avoid unwanted insertion during
2442 deletion of breakpoints. */
2443 if (!bl->inserted || (bl->inserted && !bl->needs_update))
2446 switch_to_program_space_and_thread (bl->pspace);
2448 /* For targets that support global breakpoints, there's no need
2449 to select an inferior to insert breakpoint to. In fact, even
2450 if we aren't attached to any process yet, we should still
2451 insert breakpoints. */
2452 if (!gdbarch_has_global_breakpoints (target_gdbarch)
2453 && ptid_equal (inferior_ptid, null_ptid))
2456 val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
2457 &hw_breakpoint_error);
2464 target_terminal_ours_for_output ();
2465 error_stream (tmp_error_stream);
2468 do_cleanups (cleanups);
2471 /* Used when starting or continuing the program. */
2474 insert_breakpoint_locations (void)
2476 struct breakpoint *bpt;
2477 struct bp_location *bl, **blp_tmp;
2480 int disabled_breaks = 0;
2481 int hw_breakpoint_error = 0;
2483 struct ui_file *tmp_error_stream = mem_fileopen ();
2484 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
2486 /* Explicitly mark the warning -- this will only be printed if
2487 there was an error. */
2488 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
2490 save_current_space_and_thread ();
2492 ALL_BP_LOCATIONS (bl, blp_tmp)
2494 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
2497 /* There is no point inserting thread-specific breakpoints if
2498 the thread no longer exists. ALL_BP_LOCATIONS bp_location
2499 has BL->OWNER always non-NULL. */
2500 if (bl->owner->thread != -1
2501 && !valid_thread_id (bl->owner->thread))
2504 switch_to_program_space_and_thread (bl->pspace);
2506 /* For targets that support global breakpoints, there's no need
2507 to select an inferior to insert breakpoint to. In fact, even
2508 if we aren't attached to any process yet, we should still
2509 insert breakpoints. */
2510 if (!gdbarch_has_global_breakpoints (target_gdbarch)
2511 && ptid_equal (inferior_ptid, null_ptid))
2514 val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
2515 &hw_breakpoint_error);
2520 /* If we failed to insert all locations of a watchpoint, remove
2521 them, as half-inserted watchpoint is of limited use. */
2522 ALL_BREAKPOINTS (bpt)
2524 int some_failed = 0;
2525 struct bp_location *loc;
2527 if (!is_hardware_watchpoint (bpt))
2530 if (!breakpoint_enabled (bpt))
2533 if (bpt->disposition == disp_del_at_next_stop)
2536 for (loc = bpt->loc; loc; loc = loc->next)
2537 if (!loc->inserted && should_be_inserted (loc))
2544 for (loc = bpt->loc; loc; loc = loc->next)
2546 remove_breakpoint (loc, mark_uninserted);
2548 hw_breakpoint_error = 1;
2549 fprintf_unfiltered (tmp_error_stream,
2550 "Could not insert hardware watchpoint %d.\n",
2558 /* If a hardware breakpoint or watchpoint was inserted, add a
2559 message about possibly exhausted resources. */
2560 if (hw_breakpoint_error)
2562 fprintf_unfiltered (tmp_error_stream,
2563 "Could not insert hardware breakpoints:\n\
2564 You may have requested too many hardware breakpoints/watchpoints.\n");
2566 target_terminal_ours_for_output ();
2567 error_stream (tmp_error_stream);
2570 do_cleanups (cleanups);
2573 /* Used when the program stops.
2574 Returns zero if successful, or non-zero if there was a problem
2575 removing a breakpoint location. */
2578 remove_breakpoints (void)
2580 struct bp_location *bl, **blp_tmp;
2583 ALL_BP_LOCATIONS (bl, blp_tmp)
2585 if (bl->inserted && !is_tracepoint (bl->owner))
2586 val |= remove_breakpoint (bl, mark_uninserted);
2591 /* Remove breakpoints of process PID. */
2594 remove_breakpoints_pid (int pid)
2596 struct bp_location *bl, **blp_tmp;
2598 struct inferior *inf = find_inferior_pid (pid);
2600 ALL_BP_LOCATIONS (bl, blp_tmp)
2602 if (bl->pspace != inf->pspace)
2607 val = remove_breakpoint (bl, mark_uninserted);
2616 reattach_breakpoints (int pid)
2618 struct cleanup *old_chain;
2619 struct bp_location *bl, **blp_tmp;
2621 struct ui_file *tmp_error_stream;
2622 int dummy1 = 0, dummy2 = 0;
2623 struct inferior *inf;
2624 struct thread_info *tp;
2626 tp = any_live_thread_of_process (pid);
2630 inf = find_inferior_pid (pid);
2631 old_chain = save_inferior_ptid ();
2633 inferior_ptid = tp->ptid;
2635 tmp_error_stream = mem_fileopen ();
2636 make_cleanup_ui_file_delete (tmp_error_stream);
2638 ALL_BP_LOCATIONS (bl, blp_tmp)
2640 if (bl->pspace != inf->pspace)
2646 val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2);
2649 do_cleanups (old_chain);
2654 do_cleanups (old_chain);
2658 static int internal_breakpoint_number = -1;
2660 /* Set the breakpoint number of B, depending on the value of INTERNAL.
2661 If INTERNAL is non-zero, the breakpoint number will be populated
2662 from internal_breakpoint_number and that variable decremented.
2663 Otherwise the breakpoint number will be populated from
2664 breakpoint_count and that value incremented. Internal breakpoints
2665 do not set the internal var bpnum. */
2667 set_breakpoint_number (int internal, struct breakpoint *b)
2670 b->number = internal_breakpoint_number--;
2673 set_breakpoint_count (breakpoint_count + 1);
2674 b->number = breakpoint_count;
2678 static struct breakpoint *
2679 create_internal_breakpoint (struct gdbarch *gdbarch,
2680 CORE_ADDR address, enum bptype type,
2681 const struct breakpoint_ops *ops)
2683 struct symtab_and_line sal;
2684 struct breakpoint *b;
2686 init_sal (&sal); /* Initialize to zeroes. */
2689 sal.section = find_pc_overlay (sal.pc);
2690 sal.pspace = current_program_space;
2692 b = set_raw_breakpoint (gdbarch, sal, type, ops);
2693 b->number = internal_breakpoint_number--;
2694 b->disposition = disp_donttouch;
2699 static const char *const longjmp_names[] =
2701 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
2703 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
2705 /* Per-objfile data private to breakpoint.c. */
2706 struct breakpoint_objfile_data
2708 /* Minimal symbol for "_ovly_debug_event" (if any). */
2709 struct minimal_symbol *overlay_msym;
2711 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
2712 struct minimal_symbol *longjmp_msym[NUM_LONGJMP_NAMES];
2714 /* Minimal symbol for "std::terminate()" (if any). */
2715 struct minimal_symbol *terminate_msym;
2717 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
2718 struct minimal_symbol *exception_msym;
2721 static const struct objfile_data *breakpoint_objfile_key;
2723 /* Minimal symbol not found sentinel. */
2724 static struct minimal_symbol msym_not_found;
2726 /* Returns TRUE if MSYM point to the "not found" sentinel. */
2729 msym_not_found_p (const struct minimal_symbol *msym)
2731 return msym == &msym_not_found;
2734 /* Return per-objfile data needed by breakpoint.c.
2735 Allocate the data if necessary. */
2737 static struct breakpoint_objfile_data *
2738 get_breakpoint_objfile_data (struct objfile *objfile)
2740 struct breakpoint_objfile_data *bp_objfile_data;
2742 bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key);
2743 if (bp_objfile_data == NULL)
2745 bp_objfile_data = obstack_alloc (&objfile->objfile_obstack,
2746 sizeof (*bp_objfile_data));
2748 memset (bp_objfile_data, 0, sizeof (*bp_objfile_data));
2749 set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data);
2751 return bp_objfile_data;
2755 create_overlay_event_breakpoint (void)
2757 struct objfile *objfile;
2758 const char *const func_name = "_ovly_debug_event";
2760 ALL_OBJFILES (objfile)
2762 struct breakpoint *b;
2763 struct breakpoint_objfile_data *bp_objfile_data;
2766 bp_objfile_data = get_breakpoint_objfile_data (objfile);
2768 if (msym_not_found_p (bp_objfile_data->overlay_msym))
2771 if (bp_objfile_data->overlay_msym == NULL)
2773 struct minimal_symbol *m;
2775 m = lookup_minimal_symbol_text (func_name, objfile);
2778 /* Avoid future lookups in this objfile. */
2779 bp_objfile_data->overlay_msym = &msym_not_found;
2782 bp_objfile_data->overlay_msym = m;
2785 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym);
2786 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
2788 &internal_breakpoint_ops);
2789 b->addr_string = xstrdup (func_name);
2791 if (overlay_debugging == ovly_auto)
2793 b->enable_state = bp_enabled;
2794 overlay_events_enabled = 1;
2798 b->enable_state = bp_disabled;
2799 overlay_events_enabled = 0;
2802 update_global_location_list (1);
2806 create_longjmp_master_breakpoint (void)
2808 struct program_space *pspace;
2809 struct cleanup *old_chain;
2811 old_chain = save_current_program_space ();
2813 ALL_PSPACES (pspace)
2815 struct objfile *objfile;
2817 set_current_program_space (pspace);
2819 ALL_OBJFILES (objfile)
2822 struct gdbarch *gdbarch;
2823 struct breakpoint_objfile_data *bp_objfile_data;
2825 gdbarch = get_objfile_arch (objfile);
2826 if (!gdbarch_get_longjmp_target_p (gdbarch))
2829 bp_objfile_data = get_breakpoint_objfile_data (objfile);
2831 for (i = 0; i < NUM_LONGJMP_NAMES; i++)
2833 struct breakpoint *b;
2834 const char *func_name;
2837 if (msym_not_found_p (bp_objfile_data->longjmp_msym[i]))
2840 func_name = longjmp_names[i];
2841 if (bp_objfile_data->longjmp_msym[i] == NULL)
2843 struct minimal_symbol *m;
2845 m = lookup_minimal_symbol_text (func_name, objfile);
2848 /* Prevent future lookups in this objfile. */
2849 bp_objfile_data->longjmp_msym[i] = &msym_not_found;
2852 bp_objfile_data->longjmp_msym[i] = m;
2855 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]);
2856 b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master,
2857 &internal_breakpoint_ops);
2858 b->addr_string = xstrdup (func_name);
2859 b->enable_state = bp_disabled;
2863 update_global_location_list (1);
2865 do_cleanups (old_chain);
2868 /* Create a master std::terminate breakpoint. */
2870 create_std_terminate_master_breakpoint (void)
2872 struct program_space *pspace;
2873 struct cleanup *old_chain;
2874 const char *const func_name = "std::terminate()";
2876 old_chain = save_current_program_space ();
2878 ALL_PSPACES (pspace)
2880 struct objfile *objfile;
2883 set_current_program_space (pspace);
2885 ALL_OBJFILES (objfile)
2887 struct breakpoint *b;
2888 struct breakpoint_objfile_data *bp_objfile_data;
2890 bp_objfile_data = get_breakpoint_objfile_data (objfile);
2892 if (msym_not_found_p (bp_objfile_data->terminate_msym))
2895 if (bp_objfile_data->terminate_msym == NULL)
2897 struct minimal_symbol *m;
2899 m = lookup_minimal_symbol (func_name, NULL, objfile);
2900 if (m == NULL || (MSYMBOL_TYPE (m) != mst_text
2901 && MSYMBOL_TYPE (m) != mst_file_text))
2903 /* Prevent future lookups in this objfile. */
2904 bp_objfile_data->terminate_msym = &msym_not_found;
2907 bp_objfile_data->terminate_msym = m;
2910 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym);
2911 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
2912 bp_std_terminate_master,
2913 &internal_breakpoint_ops);
2914 b->addr_string = xstrdup (func_name);
2915 b->enable_state = bp_disabled;
2919 update_global_location_list (1);
2921 do_cleanups (old_chain);
2924 /* Install a master breakpoint on the unwinder's debug hook. */
2927 create_exception_master_breakpoint (void)
2929 struct objfile *objfile;
2930 const char *const func_name = "_Unwind_DebugHook";
2932 ALL_OBJFILES (objfile)
2934 struct breakpoint *b;
2935 struct gdbarch *gdbarch;
2936 struct breakpoint_objfile_data *bp_objfile_data;
2939 bp_objfile_data = get_breakpoint_objfile_data (objfile);
2941 if (msym_not_found_p (bp_objfile_data->exception_msym))
2944 gdbarch = get_objfile_arch (objfile);
2946 if (bp_objfile_data->exception_msym == NULL)
2948 struct minimal_symbol *debug_hook;
2950 debug_hook = lookup_minimal_symbol (func_name, NULL, objfile);
2951 if (debug_hook == NULL)
2953 bp_objfile_data->exception_msym = &msym_not_found;
2957 bp_objfile_data->exception_msym = debug_hook;
2960 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym);
2961 addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
2963 b = create_internal_breakpoint (gdbarch, addr, bp_exception_master,
2964 &internal_breakpoint_ops);
2965 b->addr_string = xstrdup (func_name);
2966 b->enable_state = bp_disabled;
2969 update_global_location_list (1);
2973 update_breakpoints_after_exec (void)
2975 struct breakpoint *b, *b_tmp;
2976 struct bp_location *bploc, **bplocp_tmp;
2978 /* We're about to delete breakpoints from GDB's lists. If the
2979 INSERTED flag is true, GDB will try to lift the breakpoints by
2980 writing the breakpoints' "shadow contents" back into memory. The
2981 "shadow contents" are NOT valid after an exec, so GDB should not
2982 do that. Instead, the target is responsible from marking
2983 breakpoints out as soon as it detects an exec. We don't do that
2984 here instead, because there may be other attempts to delete
2985 breakpoints after detecting an exec and before reaching here. */
2986 ALL_BP_LOCATIONS (bploc, bplocp_tmp)
2987 if (bploc->pspace == current_program_space)
2988 gdb_assert (!bploc->inserted);
2990 ALL_BREAKPOINTS_SAFE (b, b_tmp)
2992 if (b->pspace != current_program_space)
2995 /* Solib breakpoints must be explicitly reset after an exec(). */
2996 if (b->type == bp_shlib_event)
2998 delete_breakpoint (b);
3002 /* JIT breakpoints must be explicitly reset after an exec(). */
3003 if (b->type == bp_jit_event)
3005 delete_breakpoint (b);
3009 /* Thread event breakpoints must be set anew after an exec(),
3010 as must overlay event and longjmp master breakpoints. */
3011 if (b->type == bp_thread_event || b->type == bp_overlay_event
3012 || b->type == bp_longjmp_master || b->type == bp_std_terminate_master
3013 || b->type == bp_exception_master)
3015 delete_breakpoint (b);
3019 /* Step-resume breakpoints are meaningless after an exec(). */
3020 if (b->type == bp_step_resume || b->type == bp_hp_step_resume)
3022 delete_breakpoint (b);
3026 /* Longjmp and longjmp-resume breakpoints are also meaningless
3028 if (b->type == bp_longjmp || b->type == bp_longjmp_resume
3029 || b->type == bp_exception || b->type == bp_exception_resume)
3031 delete_breakpoint (b);
3035 if (b->type == bp_catchpoint)
3037 /* For now, none of the bp_catchpoint breakpoints need to
3038 do anything at this point. In the future, if some of
3039 the catchpoints need to something, we will need to add
3040 a new method, and call this method from here. */
3044 /* bp_finish is a special case. The only way we ought to be able
3045 to see one of these when an exec() has happened, is if the user
3046 caught a vfork, and then said "finish". Ordinarily a finish just
3047 carries them to the call-site of the current callee, by setting
3048 a temporary bp there and resuming. But in this case, the finish
3049 will carry them entirely through the vfork & exec.
3051 We don't want to allow a bp_finish to remain inserted now. But
3052 we can't safely delete it, 'cause finish_command has a handle to
3053 the bp on a bpstat, and will later want to delete it. There's a
3054 chance (and I've seen it happen) that if we delete the bp_finish
3055 here, that its storage will get reused by the time finish_command
3056 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3057 We really must allow finish_command to delete a bp_finish.
3059 In the absence of a general solution for the "how do we know
3060 it's safe to delete something others may have handles to?"
3061 problem, what we'll do here is just uninsert the bp_finish, and
3062 let finish_command delete it.
3064 (We know the bp_finish is "doomed" in the sense that it's
3065 momentary, and will be deleted as soon as finish_command sees
3066 the inferior stopped. So it doesn't matter that the bp's
3067 address is probably bogus in the new a.out, unlike e.g., the
3068 solib breakpoints.) */
3070 if (b->type == bp_finish)
3075 /* Without a symbolic address, we have little hope of the
3076 pre-exec() address meaning the same thing in the post-exec()
3078 if (b->addr_string == NULL)
3080 delete_breakpoint (b);
3084 /* FIXME what about longjmp breakpoints? Re-create them here? */
3085 create_overlay_event_breakpoint ();
3086 create_longjmp_master_breakpoint ();
3087 create_std_terminate_master_breakpoint ();
3088 create_exception_master_breakpoint ();
3092 detach_breakpoints (int pid)
3094 struct bp_location *bl, **blp_tmp;
3096 struct cleanup *old_chain = save_inferior_ptid ();
3097 struct inferior *inf = current_inferior ();
3099 if (pid == PIDGET (inferior_ptid))
3100 error (_("Cannot detach breakpoints of inferior_ptid"));
3102 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3103 inferior_ptid = pid_to_ptid (pid);
3104 ALL_BP_LOCATIONS (bl, blp_tmp)
3106 if (bl->pspace != inf->pspace)
3110 val |= remove_breakpoint_1 (bl, mark_inserted);
3113 /* Detach single-step breakpoints as well. */
3114 detach_single_step_breakpoints ();
3116 do_cleanups (old_chain);
3120 /* Remove the breakpoint location BL from the current address space.
3121 Note that this is used to detach breakpoints from a child fork.
3122 When we get here, the child isn't in the inferior list, and neither
3123 do we have objects to represent its address space --- we should
3124 *not* look at bl->pspace->aspace here. */
3127 remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is)
3131 /* BL is never in moribund_locations by our callers. */
3132 gdb_assert (bl->owner != NULL);
3134 if (bl->owner->enable_state == bp_permanent)
3135 /* Permanent breakpoints cannot be inserted or removed. */
3138 /* The type of none suggests that owner is actually deleted.
3139 This should not ever happen. */
3140 gdb_assert (bl->owner->type != bp_none);
3142 if (bl->loc_type == bp_loc_software_breakpoint
3143 || bl->loc_type == bp_loc_hardware_breakpoint)
3145 /* "Normal" instruction breakpoint: either the standard
3146 trap-instruction bp (bp_breakpoint), or a
3147 bp_hardware_breakpoint. */
3149 /* First check to see if we have to handle an overlay. */
3150 if (overlay_debugging == ovly_off
3151 || bl->section == NULL
3152 || !(section_is_overlay (bl->section)))
3154 /* No overlay handling: just remove the breakpoint. */
3155 val = bl->owner->ops->remove_location (bl);
3159 /* This breakpoint is in an overlay section.
3160 Did we set a breakpoint at the LMA? */
3161 if (!overlay_events_enabled)
3163 /* Yes -- overlay event support is not active, so we
3164 should have set a breakpoint at the LMA. Remove it.
3166 /* Ignore any failures: if the LMA is in ROM, we will
3167 have already warned when we failed to insert it. */
3168 if (bl->loc_type == bp_loc_hardware_breakpoint)
3169 target_remove_hw_breakpoint (bl->gdbarch,
3170 &bl->overlay_target_info);
3172 target_remove_breakpoint (bl->gdbarch,
3173 &bl->overlay_target_info);
3175 /* Did we set a breakpoint at the VMA?
3176 If so, we will have marked the breakpoint 'inserted'. */
3179 /* Yes -- remove it. Previously we did not bother to
3180 remove the breakpoint if the section had been
3181 unmapped, but let's not rely on that being safe. We
3182 don't know what the overlay manager might do. */
3184 /* However, we should remove *software* breakpoints only
3185 if the section is still mapped, or else we overwrite
3186 wrong code with the saved shadow contents. */
3187 if (bl->loc_type == bp_loc_hardware_breakpoint
3188 || section_is_mapped (bl->section))
3189 val = bl->owner->ops->remove_location (bl);
3195 /* No -- not inserted, so no need to remove. No error. */
3200 /* In some cases, we might not be able to remove a breakpoint
3201 in a shared library that has already been removed, but we
3202 have not yet processed the shlib unload event. */
3203 if (val && solib_name_from_address (bl->pspace, bl->address))
3208 bl->inserted = (is == mark_inserted);
3210 else if (bl->loc_type == bp_loc_hardware_watchpoint)
3212 gdb_assert (bl->owner->ops != NULL
3213 && bl->owner->ops->remove_location != NULL);
3215 bl->inserted = (is == mark_inserted);
3216 bl->owner->ops->remove_location (bl);
3218 /* Failure to remove any of the hardware watchpoints comes here. */
3219 if ((is == mark_uninserted) && (bl->inserted))
3220 warning (_("Could not remove hardware watchpoint %d."),
3223 else if (bl->owner->type == bp_catchpoint
3224 && breakpoint_enabled (bl->owner)
3227 gdb_assert (bl->owner->ops != NULL
3228 && bl->owner->ops->remove_location != NULL);
3230 val = bl->owner->ops->remove_location (bl);
3234 bl->inserted = (is == mark_inserted);
3241 remove_breakpoint (struct bp_location *bl, insertion_state_t is)
3244 struct cleanup *old_chain;
3246 /* BL is never in moribund_locations by our callers. */
3247 gdb_assert (bl->owner != NULL);
3249 if (bl->owner->enable_state == bp_permanent)
3250 /* Permanent breakpoints cannot be inserted or removed. */
3253 /* The type of none suggests that owner is actually deleted.
3254 This should not ever happen. */
3255 gdb_assert (bl->owner->type != bp_none);
3257 old_chain = save_current_space_and_thread ();
3259 switch_to_program_space_and_thread (bl->pspace);
3261 ret = remove_breakpoint_1 (bl, is);
3263 do_cleanups (old_chain);
3267 /* Clear the "inserted" flag in all breakpoints. */
3270 mark_breakpoints_out (void)
3272 struct bp_location *bl, **blp_tmp;
3274 ALL_BP_LOCATIONS (bl, blp_tmp)
3275 if (bl->pspace == current_program_space)
3279 /* Clear the "inserted" flag in all breakpoints and delete any
3280 breakpoints which should go away between runs of the program.
3282 Plus other such housekeeping that has to be done for breakpoints
3285 Note: this function gets called at the end of a run (by
3286 generic_mourn_inferior) and when a run begins (by
3287 init_wait_for_inferior). */
3292 breakpoint_init_inferior (enum inf_context context)
3294 struct breakpoint *b, *b_tmp;
3295 struct bp_location *bl, **blp_tmp;
3297 struct program_space *pspace = current_program_space;
3299 /* If breakpoint locations are shared across processes, then there's
3301 if (gdbarch_has_global_breakpoints (target_gdbarch))
3304 ALL_BP_LOCATIONS (bl, blp_tmp)
3306 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3307 if (bl->pspace == pspace
3308 && bl->owner->enable_state != bp_permanent)
3312 ALL_BREAKPOINTS_SAFE (b, b_tmp)
3314 if (b->loc && b->loc->pspace != pspace)
3321 /* If the call dummy breakpoint is at the entry point it will
3322 cause problems when the inferior is rerun, so we better get
3325 case bp_watchpoint_scope:
3327 /* Also get rid of scope breakpoints. */
3329 case bp_shlib_event:
3331 /* Also remove solib event breakpoints. Their addresses may
3332 have changed since the last time we ran the program.
3333 Actually we may now be debugging against different target;
3334 and so the solib backend that installed this breakpoint may
3335 not be used in by the target. E.g.,
3337 (gdb) file prog-linux
3338 (gdb) run # native linux target
3341 (gdb) file prog-win.exe
3342 (gdb) tar rem :9999 # remote Windows gdbserver.
3345 case bp_step_resume:
3347 /* Also remove step-resume breakpoints. */
3349 delete_breakpoint (b);
3353 case bp_hardware_watchpoint:
3354 case bp_read_watchpoint:
3355 case bp_access_watchpoint:
3357 struct watchpoint *w = (struct watchpoint *) b;
3359 /* Likewise for watchpoints on local expressions. */
3360 if (w->exp_valid_block != NULL)
3361 delete_breakpoint (b);
3362 else if (context == inf_starting)
3364 /* Reset val field to force reread of starting value in
3365 insert_breakpoints. */
3367 value_free (w->val);
3378 /* Get rid of the moribund locations. */
3379 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix)
3380 decref_bp_location (&bl);
3381 VEC_free (bp_location_p, moribund_locations);
3384 /* These functions concern about actual breakpoints inserted in the
3385 target --- to e.g. check if we need to do decr_pc adjustment or if
3386 we need to hop over the bkpt --- so we check for address space
3387 match, not program space. */
3389 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
3390 exists at PC. It returns ordinary_breakpoint_here if it's an
3391 ordinary breakpoint, or permanent_breakpoint_here if it's a
3392 permanent breakpoint.
3393 - When continuing from a location with an ordinary breakpoint, we
3394 actually single step once before calling insert_breakpoints.
3395 - When continuing from a location with a permanent breakpoint, we
3396 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
3397 the target, to advance the PC past the breakpoint. */
3399 enum breakpoint_here
3400 breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
3402 struct bp_location *bl, **blp_tmp;
3403 int any_breakpoint_here = 0;
3405 ALL_BP_LOCATIONS (bl, blp_tmp)
3407 if (bl->loc_type != bp_loc_software_breakpoint
3408 && bl->loc_type != bp_loc_hardware_breakpoint)
3411 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3412 if ((breakpoint_enabled (bl->owner)
3413 || bl->owner->enable_state == bp_permanent)
3414 && breakpoint_location_address_match (bl, aspace, pc))
3416 if (overlay_debugging
3417 && section_is_overlay (bl->section)
3418 && !section_is_mapped (bl->section))
3419 continue; /* unmapped overlay -- can't be a match */
3420 else if (bl->owner->enable_state == bp_permanent)
3421 return permanent_breakpoint_here;
3423 any_breakpoint_here = 1;
3427 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
3430 /* Return true if there's a moribund breakpoint at PC. */
3433 moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
3435 struct bp_location *loc;
3438 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
3439 if (breakpoint_location_address_match (loc, aspace, pc))
3445 /* Returns non-zero if there's a breakpoint inserted at PC, which is
3446 inserted using regular breakpoint_chain / bp_location array
3447 mechanism. This does not check for single-step breakpoints, which
3448 are inserted and removed using direct target manipulation. */
3451 regular_breakpoint_inserted_here_p (struct address_space *aspace,
3454 struct bp_location *bl, **blp_tmp;
3456 ALL_BP_LOCATIONS (bl, blp_tmp)
3458 if (bl->loc_type != bp_loc_software_breakpoint
3459 && bl->loc_type != bp_loc_hardware_breakpoint)
3463 && breakpoint_location_address_match (bl, aspace, pc))
3465 if (overlay_debugging
3466 && section_is_overlay (bl->section)
3467 && !section_is_mapped (bl->section))
3468 continue; /* unmapped overlay -- can't be a match */
3476 /* Returns non-zero iff there's either regular breakpoint
3477 or a single step breakpoint inserted at PC. */
3480 breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
3482 if (regular_breakpoint_inserted_here_p (aspace, pc))
3485 if (single_step_breakpoint_inserted_here_p (aspace, pc))
3491 /* This function returns non-zero iff there is a software breakpoint
3495 software_breakpoint_inserted_here_p (struct address_space *aspace,
3498 struct bp_location *bl, **blp_tmp;
3500 ALL_BP_LOCATIONS (bl, blp_tmp)
3502 if (bl->loc_type != bp_loc_software_breakpoint)
3506 && breakpoint_address_match (bl->pspace->aspace, bl->address,
3509 if (overlay_debugging
3510 && section_is_overlay (bl->section)
3511 && !section_is_mapped (bl->section))
3512 continue; /* unmapped overlay -- can't be a match */
3518 /* Also check for software single-step breakpoints. */
3519 if (single_step_breakpoint_inserted_here_p (aspace, pc))
3526 hardware_watchpoint_inserted_in_range (struct address_space *aspace,
3527 CORE_ADDR addr, ULONGEST len)
3529 struct breakpoint *bpt;
3531 ALL_BREAKPOINTS (bpt)
3533 struct bp_location *loc;
3535 if (bpt->type != bp_hardware_watchpoint
3536 && bpt->type != bp_access_watchpoint)
3539 if (!breakpoint_enabled (bpt))
3542 for (loc = bpt->loc; loc; loc = loc->next)
3543 if (loc->pspace->aspace == aspace && loc->inserted)
3547 /* Check for intersection. */
3548 l = max (loc->address, addr);
3549 h = min (loc->address + loc->length, addr + len);
3557 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
3558 PC is valid for process/thread PTID. */
3561 breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc,
3564 struct bp_location *bl, **blp_tmp;
3565 /* The thread and task IDs associated to PTID, computed lazily. */
3569 ALL_BP_LOCATIONS (bl, blp_tmp)
3571 if (bl->loc_type != bp_loc_software_breakpoint
3572 && bl->loc_type != bp_loc_hardware_breakpoint)
3575 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
3576 if (!breakpoint_enabled (bl->owner)
3577 && bl->owner->enable_state != bp_permanent)
3580 if (!breakpoint_location_address_match (bl, aspace, pc))
3583 if (bl->owner->thread != -1)
3585 /* This is a thread-specific breakpoint. Check that ptid
3586 matches that thread. If thread hasn't been computed yet,
3587 it is now time to do so. */
3589 thread = pid_to_thread_id (ptid);
3590 if (bl->owner->thread != thread)
3594 if (bl->owner->task != 0)
3596 /* This is a task-specific breakpoint. Check that ptid
3597 matches that task. If task hasn't been computed yet,
3598 it is now time to do so. */
3600 task = ada_get_task_number (ptid);
3601 if (bl->owner->task != task)
3605 if (overlay_debugging
3606 && section_is_overlay (bl->section)
3607 && !section_is_mapped (bl->section))
3608 continue; /* unmapped overlay -- can't be a match */
3617 /* bpstat stuff. External routines' interfaces are documented
3621 ep_is_catchpoint (struct breakpoint *ep)
3623 return (ep->type == bp_catchpoint);
3626 /* Frees any storage that is part of a bpstat. Does not walk the
3630 bpstat_free (bpstat bs)
3632 if (bs->old_val != NULL)
3633 value_free (bs->old_val);
3634 decref_counted_command_line (&bs->commands);
3635 decref_bp_location (&bs->bp_location_at);
3639 /* Clear a bpstat so that it says we are not at any breakpoint.
3640 Also free any storage that is part of a bpstat. */
3643 bpstat_clear (bpstat *bsp)
3660 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
3661 is part of the bpstat is copied as well. */
3664 bpstat_copy (bpstat bs)
3668 bpstat retval = NULL;
3673 for (; bs != NULL; bs = bs->next)
3675 tmp = (bpstat) xmalloc (sizeof (*tmp));
3676 memcpy (tmp, bs, sizeof (*tmp));
3677 incref_counted_command_line (tmp->commands);
3678 incref_bp_location (tmp->bp_location_at);
3679 if (bs->old_val != NULL)
3681 tmp->old_val = value_copy (bs->old_val);
3682 release_value (tmp->old_val);
3686 /* This is the first thing in the chain. */
3696 /* Find the bpstat associated with this breakpoint. */
3699 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
3704 for (; bsp != NULL; bsp = bsp->next)
3706 if (bsp->breakpoint_at == breakpoint)
3712 /* Put in *NUM the breakpoint number of the first breakpoint we are
3713 stopped at. *BSP upon return is a bpstat which points to the
3714 remaining breakpoints stopped at (but which is not guaranteed to be
3715 good for anything but further calls to bpstat_num).
3717 Return 0 if passed a bpstat which does not indicate any breakpoints.
3718 Return -1 if stopped at a breakpoint that has been deleted since
3720 Return 1 otherwise. */
3723 bpstat_num (bpstat *bsp, int *num)
3725 struct breakpoint *b;
3728 return 0; /* No more breakpoint values */
3730 /* We assume we'll never have several bpstats that correspond to a
3731 single breakpoint -- otherwise, this function might return the
3732 same number more than once and this will look ugly. */
3733 b = (*bsp)->breakpoint_at;
3734 *bsp = (*bsp)->next;
3736 return -1; /* breakpoint that's been deleted since */
3738 *num = b->number; /* We have its number */
3742 /* See breakpoint.h. */
3745 bpstat_clear_actions (void)
3747 struct thread_info *tp;
3750 if (ptid_equal (inferior_ptid, null_ptid))
3753 tp = find_thread_ptid (inferior_ptid);
3757 for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next)
3759 decref_counted_command_line (&bs->commands);
3761 if (bs->old_val != NULL)
3763 value_free (bs->old_val);
3769 /* Called when a command is about to proceed the inferior. */
3772 breakpoint_about_to_proceed (void)
3774 if (!ptid_equal (inferior_ptid, null_ptid))
3776 struct thread_info *tp = inferior_thread ();
3778 /* Allow inferior function calls in breakpoint commands to not
3779 interrupt the command list. When the call finishes
3780 successfully, the inferior will be standing at the same
3781 breakpoint as if nothing happened. */
3782 if (tp->control.in_infcall)
3786 breakpoint_proceeded = 1;
3789 /* Stub for cleaning up our state if we error-out of a breakpoint
3792 cleanup_executing_breakpoints (void *ignore)
3794 executing_breakpoint_commands = 0;
3797 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
3798 or its equivalent. */
3801 command_line_is_silent (struct command_line *cmd)
3803 return cmd && (strcmp ("silent", cmd->line) == 0
3804 || (xdb_commands && strcmp ("Q", cmd->line) == 0));
3807 /* Execute all the commands associated with all the breakpoints at
3808 this location. Any of these commands could cause the process to
3809 proceed beyond this point, etc. We look out for such changes by
3810 checking the global "breakpoint_proceeded" after each command.
3812 Returns true if a breakpoint command resumed the inferior. In that
3813 case, it is the caller's responsibility to recall it again with the
3814 bpstat of the current thread. */
3817 bpstat_do_actions_1 (bpstat *bsp)
3820 struct cleanup *old_chain;
3823 /* Avoid endless recursion if a `source' command is contained
3825 if (executing_breakpoint_commands)
3828 executing_breakpoint_commands = 1;
3829 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
3831 prevent_dont_repeat ();
3833 /* This pointer will iterate over the list of bpstat's. */
3836 breakpoint_proceeded = 0;
3837 for (; bs != NULL; bs = bs->next)
3839 struct counted_command_line *ccmd;
3840 struct command_line *cmd;
3841 struct cleanup *this_cmd_tree_chain;
3843 /* Take ownership of the BSP's command tree, if it has one.
3845 The command tree could legitimately contain commands like
3846 'step' and 'next', which call clear_proceed_status, which
3847 frees stop_bpstat's command tree. To make sure this doesn't
3848 free the tree we're executing out from under us, we need to
3849 take ownership of the tree ourselves. Since a given bpstat's
3850 commands are only executed once, we don't need to copy it; we
3851 can clear the pointer in the bpstat, and make sure we free
3852 the tree when we're done. */
3853 ccmd = bs->commands;
3854 bs->commands = NULL;
3855 this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd);
3856 cmd = ccmd ? ccmd->commands : NULL;
3857 if (command_line_is_silent (cmd))
3859 /* The action has been already done by bpstat_stop_status. */
3865 execute_control_command (cmd);
3867 if (breakpoint_proceeded)
3873 /* We can free this command tree now. */
3874 do_cleanups (this_cmd_tree_chain);
3876 if (breakpoint_proceeded)
3878 if (target_can_async_p ())
3879 /* If we are in async mode, then the target might be still
3880 running, not stopped at any breakpoint, so nothing for
3881 us to do here -- just return to the event loop. */
3884 /* In sync mode, when execute_control_command returns
3885 we're already standing on the next breakpoint.
3886 Breakpoint commands for that stop were not run, since
3887 execute_command does not run breakpoint commands --
3888 only command_line_handler does, but that one is not
3889 involved in execution of breakpoint commands. So, we
3890 can now execute breakpoint commands. It should be
3891 noted that making execute_command do bpstat actions is
3892 not an option -- in this case we'll have recursive
3893 invocation of bpstat for each breakpoint with a
3894 command, and can easily blow up GDB stack. Instead, we
3895 return true, which will trigger the caller to recall us
3896 with the new stop_bpstat. */
3901 do_cleanups (old_chain);
3906 bpstat_do_actions (void)
3908 struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup ();
3910 /* Do any commands attached to breakpoint we are stopped at. */
3911 while (!ptid_equal (inferior_ptid, null_ptid)
3912 && target_has_execution
3913 && !is_exited (inferior_ptid)
3914 && !is_executing (inferior_ptid))
3915 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3916 and only return when it is stopped at the next breakpoint, we
3917 keep doing breakpoint actions until it returns false to
3918 indicate the inferior was not resumed. */
3919 if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat))
3922 discard_cleanups (cleanup_if_error);
3925 /* Print out the (old or new) value associated with a watchpoint. */
3928 watchpoint_value_print (struct value *val, struct ui_file *stream)
3931 fprintf_unfiltered (stream, _("<unreadable>"));
3934 struct value_print_options opts;
3935 get_user_print_options (&opts);
3936 value_print (val, stream, &opts);
3940 /* Generic routine for printing messages indicating why we
3941 stopped. The behavior of this function depends on the value
3942 'print_it' in the bpstat structure. Under some circumstances we
3943 may decide not to print anything here and delegate the task to
3946 static enum print_stop_action
3947 print_bp_stop_message (bpstat bs)
3949 switch (bs->print_it)
3952 /* Nothing should be printed for this bpstat entry. */
3953 return PRINT_UNKNOWN;
3957 /* We still want to print the frame, but we already printed the
3958 relevant messages. */
3959 return PRINT_SRC_AND_LOC;
3962 case print_it_normal:
3964 struct breakpoint *b = bs->breakpoint_at;
3966 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3967 which has since been deleted. */
3969 return PRINT_UNKNOWN;
3971 /* Normal case. Call the breakpoint's print_it method. */
3972 return b->ops->print_it (bs);
3977 internal_error (__FILE__, __LINE__,
3978 _("print_bp_stop_message: unrecognized enum value"));
3983 /* A helper function that prints a shared library stopped event. */
3986 print_solib_event (int is_catchpoint)
3989 = !VEC_empty (char_ptr, current_program_space->deleted_solibs);
3991 = !VEC_empty (so_list_ptr, current_program_space->added_solibs);
3995 if (any_added || any_deleted)
3996 ui_out_text (current_uiout,
3997 _("Stopped due to shared library event:\n"));
3999 ui_out_text (current_uiout,
4000 _("Stopped due to shared library event (no "
4001 "libraries added or removed)\n"));
4004 if (ui_out_is_mi_like_p (current_uiout))
4005 ui_out_field_string (current_uiout, "reason",
4006 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT));
4010 struct cleanup *cleanup;
4014 ui_out_text (current_uiout, _(" Inferior unloaded "));
4015 cleanup = make_cleanup_ui_out_list_begin_end (current_uiout,
4018 VEC_iterate (char_ptr, current_program_space->deleted_solibs,
4023 ui_out_text (current_uiout, " ");
4024 ui_out_field_string (current_uiout, "library", name);
4025 ui_out_text (current_uiout, "\n");
4028 do_cleanups (cleanup);
4033 struct so_list *iter;
4035 struct cleanup *cleanup;
4037 ui_out_text (current_uiout, _(" Inferior loaded "));
4038 cleanup = make_cleanup_ui_out_list_begin_end (current_uiout,
4041 VEC_iterate (so_list_ptr, current_program_space->added_solibs,
4046 ui_out_text (current_uiout, " ");
4047 ui_out_field_string (current_uiout, "library", iter->so_name);
4048 ui_out_text (current_uiout, "\n");
4051 do_cleanups (cleanup);
4055 /* Print a message indicating what happened. This is called from
4056 normal_stop(). The input to this routine is the head of the bpstat
4057 list - a list of the eventpoints that caused this stop. KIND is
4058 the target_waitkind for the stopping event. This
4059 routine calls the generic print routine for printing a message
4060 about reasons for stopping. This will print (for example) the
4061 "Breakpoint n," part of the output. The return value of this
4064 PRINT_UNKNOWN: Means we printed nothing.
4065 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4066 code to print the location. An example is
4067 "Breakpoint 1, " which should be followed by
4069 PRINT_SRC_ONLY: Means we printed something, but there is no need
4070 to also print the location part of the message.
4071 An example is the catch/throw messages, which
4072 don't require a location appended to the end.
4073 PRINT_NOTHING: We have done some printing and we don't need any
4074 further info to be printed. */
4076 enum print_stop_action
4077 bpstat_print (bpstat bs, int kind)
4081 /* Maybe another breakpoint in the chain caused us to stop.
4082 (Currently all watchpoints go on the bpstat whether hit or not.
4083 That probably could (should) be changed, provided care is taken
4084 with respect to bpstat_explains_signal). */
4085 for (; bs; bs = bs->next)
4087 val = print_bp_stop_message (bs);
4088 if (val == PRINT_SRC_ONLY
4089 || val == PRINT_SRC_AND_LOC
4090 || val == PRINT_NOTHING)
4094 /* If we had hit a shared library event breakpoint,
4095 print_bp_stop_message would print out this message. If we hit an
4096 OS-level shared library event, do the same thing. */
4097 if (kind == TARGET_WAITKIND_LOADED)
4099 print_solib_event (0);
4100 return PRINT_NOTHING;
4103 /* We reached the end of the chain, or we got a null BS to start
4104 with and nothing was printed. */
4105 return PRINT_UNKNOWN;
4108 /* Evaluate the expression EXP and return 1 if value is zero. This is
4109 used inside a catch_errors to evaluate the breakpoint condition.
4110 The argument is a "struct expression *" that has been cast to a
4111 "char *" to make it pass through catch_errors. */
4114 breakpoint_cond_eval (void *exp)
4116 struct value *mark = value_mark ();
4117 int i = !value_true (evaluate_expression ((struct expression *) exp));
4119 value_free_to_mark (mark);
4123 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4126 bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer)
4130 bs = (bpstat) xmalloc (sizeof (*bs));
4132 **bs_link_pointer = bs;
4133 *bs_link_pointer = &bs->next;
4134 bs->breakpoint_at = bl->owner;
4135 bs->bp_location_at = bl;
4136 incref_bp_location (bl);
4137 /* If the condition is false, etc., don't do the commands. */
4138 bs->commands = NULL;
4140 bs->print_it = print_it_normal;
4144 /* The target has stopped with waitstatus WS. Check if any hardware
4145 watchpoints have triggered, according to the target. */
4148 watchpoints_triggered (struct target_waitstatus *ws)
4150 int stopped_by_watchpoint = target_stopped_by_watchpoint ();
4152 struct breakpoint *b;
4154 if (!stopped_by_watchpoint)
4156 /* We were not stopped by a watchpoint. Mark all watchpoints
4157 as not triggered. */
4159 if (is_hardware_watchpoint (b))
4161 struct watchpoint *w = (struct watchpoint *) b;
4163 w->watchpoint_triggered = watch_triggered_no;
4169 if (!target_stopped_data_address (¤t_target, &addr))
4171 /* We were stopped by a watchpoint, but we don't know where.
4172 Mark all watchpoints as unknown. */
4174 if (is_hardware_watchpoint (b))
4176 struct watchpoint *w = (struct watchpoint *) b;
4178 w->watchpoint_triggered = watch_triggered_unknown;
4181 return stopped_by_watchpoint;
4184 /* The target could report the data address. Mark watchpoints
4185 affected by this data address as triggered, and all others as not
4189 if (is_hardware_watchpoint (b))
4191 struct watchpoint *w = (struct watchpoint *) b;
4192 struct bp_location *loc;
4194 w->watchpoint_triggered = watch_triggered_no;
4195 for (loc = b->loc; loc; loc = loc->next)
4197 if (is_masked_watchpoint (b))
4199 CORE_ADDR newaddr = addr & w->hw_wp_mask;
4200 CORE_ADDR start = loc->address & w->hw_wp_mask;
4202 if (newaddr == start)
4204 w->watchpoint_triggered = watch_triggered_yes;
4208 /* Exact match not required. Within range is sufficient. */
4209 else if (target_watchpoint_addr_within_range (¤t_target,
4213 w->watchpoint_triggered = watch_triggered_yes;
4222 /* Possible return values for watchpoint_check (this can't be an enum
4223 because of check_errors). */
4224 /* The watchpoint has been deleted. */
4225 #define WP_DELETED 1
4226 /* The value has changed. */
4227 #define WP_VALUE_CHANGED 2
4228 /* The value has not changed. */
4229 #define WP_VALUE_NOT_CHANGED 3
4230 /* Ignore this watchpoint, no matter if the value changed or not. */
4233 #define BP_TEMPFLAG 1
4234 #define BP_HARDWAREFLAG 2
4236 /* Evaluate watchpoint condition expression and check if its value
4239 P should be a pointer to struct bpstat, but is defined as a void *
4240 in order for this function to be usable with catch_errors. */
4243 watchpoint_check (void *p)
4245 bpstat bs = (bpstat) p;
4246 struct watchpoint *b;
4247 struct frame_info *fr;
4248 int within_current_scope;
4250 /* BS is built from an existing struct breakpoint. */
4251 gdb_assert (bs->breakpoint_at != NULL);
4252 b = (struct watchpoint *) bs->breakpoint_at;
4254 /* If this is a local watchpoint, we only want to check if the
4255 watchpoint frame is in scope if the current thread is the thread
4256 that was used to create the watchpoint. */
4257 if (!watchpoint_in_thread_scope (b))
4260 if (b->exp_valid_block == NULL)
4261 within_current_scope = 1;
4264 struct frame_info *frame = get_current_frame ();
4265 struct gdbarch *frame_arch = get_frame_arch (frame);
4266 CORE_ADDR frame_pc = get_frame_pc (frame);
4268 /* in_function_epilogue_p() returns a non-zero value if we're
4269 still in the function but the stack frame has already been
4270 invalidated. Since we can't rely on the values of local
4271 variables after the stack has been destroyed, we are treating
4272 the watchpoint in that state as `not changed' without further
4273 checking. Don't mark watchpoints as changed if the current
4274 frame is in an epilogue - even if they are in some other
4275 frame, our view of the stack is likely to be wrong and
4276 frame_find_by_id could error out. */
4277 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
4280 fr = frame_find_by_id (b->watchpoint_frame);
4281 within_current_scope = (fr != NULL);
4283 /* If we've gotten confused in the unwinder, we might have
4284 returned a frame that can't describe this variable. */
4285 if (within_current_scope)
4287 struct symbol *function;
4289 function = get_frame_function (fr);
4290 if (function == NULL
4291 || !contained_in (b->exp_valid_block,
4292 SYMBOL_BLOCK_VALUE (function)))
4293 within_current_scope = 0;
4296 if (within_current_scope)
4297 /* If we end up stopping, the current frame will get selected
4298 in normal_stop. So this call to select_frame won't affect
4303 if (within_current_scope)
4305 /* We use value_{,free_to_}mark because it could be a *long*
4306 time before we return to the command level and call
4307 free_all_values. We can't call free_all_values because we
4308 might be in the middle of evaluating a function call. */
4312 struct value *new_val;
4314 if (is_masked_watchpoint (&b->base))
4315 /* Since we don't know the exact trigger address (from
4316 stopped_data_address), just tell the user we've triggered
4317 a mask watchpoint. */
4318 return WP_VALUE_CHANGED;
4320 mark = value_mark ();
4321 fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL);
4323 /* We use value_equal_contents instead of value_equal because
4324 the latter coerces an array to a pointer, thus comparing just
4325 the address of the array instead of its contents. This is
4326 not what we want. */
4327 if ((b->val != NULL) != (new_val != NULL)
4328 || (b->val != NULL && !value_equal_contents (b->val, new_val)))
4330 if (new_val != NULL)
4332 release_value (new_val);
4333 value_free_to_mark (mark);
4335 bs->old_val = b->val;
4338 return WP_VALUE_CHANGED;
4342 /* Nothing changed. */
4343 value_free_to_mark (mark);
4344 return WP_VALUE_NOT_CHANGED;
4349 struct ui_out *uiout = current_uiout;
4351 /* This seems like the only logical thing to do because
4352 if we temporarily ignored the watchpoint, then when
4353 we reenter the block in which it is valid it contains
4354 garbage (in the case of a function, it may have two
4355 garbage values, one before and one after the prologue).
4356 So we can't even detect the first assignment to it and
4357 watch after that (since the garbage may or may not equal
4358 the first value assigned). */
4359 /* We print all the stop information in
4360 breakpoint_ops->print_it, but in this case, by the time we
4361 call breakpoint_ops->print_it this bp will be deleted
4362 already. So we have no choice but print the information
4364 if (ui_out_is_mi_like_p (uiout))
4366 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
4367 ui_out_text (uiout, "\nWatchpoint ");
4368 ui_out_field_int (uiout, "wpnum", b->base.number);
4370 " deleted because the program has left the block in\n\
4371 which its expression is valid.\n");
4373 /* Make sure the watchpoint's commands aren't executed. */
4374 decref_counted_command_line (&b->base.commands);
4375 watchpoint_del_at_next_stop (b);
4381 /* Return true if it looks like target has stopped due to hitting
4382 breakpoint location BL. This function does not check if we should
4383 stop, only if BL explains the stop. */
4386 bpstat_check_location (const struct bp_location *bl,
4387 struct address_space *aspace, CORE_ADDR bp_addr,
4388 const struct target_waitstatus *ws)
4390 struct breakpoint *b = bl->owner;
4392 /* BL is from an existing breakpoint. */
4393 gdb_assert (b != NULL);
4395 return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws);
4398 /* Determine if the watched values have actually changed, and we
4399 should stop. If not, set BS->stop to 0. */
4402 bpstat_check_watchpoint (bpstat bs)
4404 const struct bp_location *bl;
4405 struct watchpoint *b;
4407 /* BS is built for existing struct breakpoint. */
4408 bl = bs->bp_location_at;
4409 gdb_assert (bl != NULL);
4410 b = (struct watchpoint *) bs->breakpoint_at;
4411 gdb_assert (b != NULL);
4414 int must_check_value = 0;
4416 if (b->base.type == bp_watchpoint)
4417 /* For a software watchpoint, we must always check the
4419 must_check_value = 1;
4420 else if (b->watchpoint_triggered == watch_triggered_yes)
4421 /* We have a hardware watchpoint (read, write, or access)
4422 and the target earlier reported an address watched by
4424 must_check_value = 1;
4425 else if (b->watchpoint_triggered == watch_triggered_unknown
4426 && b->base.type == bp_hardware_watchpoint)
4427 /* We were stopped by a hardware watchpoint, but the target could
4428 not report the data address. We must check the watchpoint's
4429 value. Access and read watchpoints are out of luck; without
4430 a data address, we can't figure it out. */
4431 must_check_value = 1;
4433 if (must_check_value)
4436 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
4438 struct cleanup *cleanups = make_cleanup (xfree, message);
4439 int e = catch_errors (watchpoint_check, bs, message,
4441 do_cleanups (cleanups);
4445 /* We've already printed what needs to be printed. */
4446 bs->print_it = print_it_done;
4450 bs->print_it = print_it_noop;
4453 case WP_VALUE_CHANGED:
4454 if (b->base.type == bp_read_watchpoint)
4456 /* There are two cases to consider here:
4458 1. We're watching the triggered memory for reads.
4459 In that case, trust the target, and always report
4460 the watchpoint hit to the user. Even though
4461 reads don't cause value changes, the value may
4462 have changed since the last time it was read, and
4463 since we're not trapping writes, we will not see
4464 those, and as such we should ignore our notion of
4467 2. We're watching the triggered memory for both
4468 reads and writes. There are two ways this may
4471 2.1. This is a target that can't break on data
4472 reads only, but can break on accesses (reads or
4473 writes), such as e.g., x86. We detect this case
4474 at the time we try to insert read watchpoints.
4476 2.2. Otherwise, the target supports read
4477 watchpoints, but, the user set an access or write
4478 watchpoint watching the same memory as this read
4481 If we're watching memory writes as well as reads,
4482 ignore watchpoint hits when we find that the
4483 value hasn't changed, as reads don't cause
4484 changes. This still gives false positives when
4485 the program writes the same value to memory as
4486 what there was already in memory (we will confuse
4487 it for a read), but it's much better than
4490 int other_write_watchpoint = 0;
4492 if (bl->watchpoint_type == hw_read)
4494 struct breakpoint *other_b;
4496 ALL_BREAKPOINTS (other_b)
4497 if (other_b->type == bp_hardware_watchpoint
4498 || other_b->type == bp_access_watchpoint)
4500 struct watchpoint *other_w =
4501 (struct watchpoint *) other_b;
4503 if (other_w->watchpoint_triggered
4504 == watch_triggered_yes)
4506 other_write_watchpoint = 1;
4512 if (other_write_watchpoint
4513 || bl->watchpoint_type == hw_access)
4515 /* We're watching the same memory for writes,
4516 and the value changed since the last time we
4517 updated it, so this trap must be for a write.
4519 bs->print_it = print_it_noop;
4524 case WP_VALUE_NOT_CHANGED:
4525 if (b->base.type == bp_hardware_watchpoint
4526 || b->base.type == bp_watchpoint)
4528 /* Don't stop: write watchpoints shouldn't fire if
4529 the value hasn't changed. */
4530 bs->print_it = print_it_noop;
4538 /* Error from catch_errors. */
4539 printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number);
4540 watchpoint_del_at_next_stop (b);
4541 /* We've already printed what needs to be printed. */
4542 bs->print_it = print_it_done;
4546 else /* must_check_value == 0 */
4548 /* This is a case where some watchpoint(s) triggered, but
4549 not at the address of this watchpoint, or else no
4550 watchpoint triggered after all. So don't print
4551 anything for this watchpoint. */
4552 bs->print_it = print_it_noop;
4559 /* Check conditions (condition proper, frame, thread and ignore count)
4560 of breakpoint referred to by BS. If we should not stop for this
4561 breakpoint, set BS->stop to 0. */
4564 bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
4566 int thread_id = pid_to_thread_id (ptid);
4567 const struct bp_location *bl;
4568 struct breakpoint *b;
4570 /* BS is built for existing struct breakpoint. */
4571 bl = bs->bp_location_at;
4572 gdb_assert (bl != NULL);
4573 b = bs->breakpoint_at;
4574 gdb_assert (b != NULL);
4576 /* Even if the target evaluated the condition on its end and notified GDB, we
4577 need to do so again since GDB does not know if we stopped due to a
4578 breakpoint or a single step breakpoint. */
4580 if (frame_id_p (b->frame_id)
4581 && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ())))
4585 int value_is_zero = 0;
4586 struct expression *cond;
4588 /* Evaluate Python breakpoints that have a "stop"
4589 method implemented. */
4590 if (b->py_bp_object)
4591 bs->stop = gdbpy_should_stop (b->py_bp_object);
4593 if (is_watchpoint (b))
4595 struct watchpoint *w = (struct watchpoint *) b;
4602 if (cond && b->disposition != disp_del_at_next_stop)
4604 int within_current_scope = 1;
4605 struct watchpoint * w;
4607 /* We use value_mark and value_free_to_mark because it could
4608 be a long time before we return to the command level and
4609 call free_all_values. We can't call free_all_values
4610 because we might be in the middle of evaluating a
4612 struct value *mark = value_mark ();
4614 if (is_watchpoint (b))
4615 w = (struct watchpoint *) b;
4619 /* Need to select the frame, with all that implies so that
4620 the conditions will have the right context. Because we
4621 use the frame, we will not see an inlined function's
4622 variables when we arrive at a breakpoint at the start
4623 of the inlined function; the current frame will be the
4625 if (w == NULL || w->cond_exp_valid_block == NULL)
4626 select_frame (get_current_frame ());
4629 struct frame_info *frame;
4631 /* For local watchpoint expressions, which particular
4632 instance of a local is being watched matters, so we
4633 keep track of the frame to evaluate the expression
4634 in. To evaluate the condition however, it doesn't
4635 really matter which instantiation of the function
4636 where the condition makes sense triggers the
4637 watchpoint. This allows an expression like "watch
4638 global if q > 10" set in `func', catch writes to
4639 global on all threads that call `func', or catch
4640 writes on all recursive calls of `func' by a single
4641 thread. We simply always evaluate the condition in
4642 the innermost frame that's executing where it makes
4643 sense to evaluate the condition. It seems
4645 frame = block_innermost_frame (w->cond_exp_valid_block);
4647 select_frame (frame);
4649 within_current_scope = 0;
4651 if (within_current_scope)
4653 = catch_errors (breakpoint_cond_eval, cond,
4654 "Error in testing breakpoint condition:\n",
4658 warning (_("Watchpoint condition cannot be tested "
4659 "in the current scope"));
4660 /* If we failed to set the right context for this
4661 watchpoint, unconditionally report it. */
4664 /* FIXME-someday, should give breakpoint #. */
4665 value_free_to_mark (mark);
4668 if (cond && value_is_zero)
4672 else if (b->thread != -1 && b->thread != thread_id)
4676 else if (b->ignore_count > 0)
4679 annotate_ignore_count_change ();
4681 /* Increase the hit count even though we don't stop. */
4683 observer_notify_breakpoint_modified (b);
4689 /* Get a bpstat associated with having just stopped at address
4690 BP_ADDR in thread PTID.
4692 Determine whether we stopped at a breakpoint, etc, or whether we
4693 don't understand this stop. Result is a chain of bpstat's such
4696 if we don't understand the stop, the result is a null pointer.
4698 if we understand why we stopped, the result is not null.
4700 Each element of the chain refers to a particular breakpoint or
4701 watchpoint at which we have stopped. (We may have stopped for
4702 several reasons concurrently.)
4704 Each element of the chain has valid next, breakpoint_at,
4705 commands, FIXME??? fields. */
4708 bpstat_stop_status (struct address_space *aspace,
4709 CORE_ADDR bp_addr, ptid_t ptid,
4710 const struct target_waitstatus *ws)
4712 struct breakpoint *b = NULL;
4713 struct bp_location *bl;
4714 struct bp_location *loc;
4715 /* First item of allocated bpstat's. */
4716 bpstat bs_head = NULL, *bs_link = &bs_head;
4717 /* Pointer to the last thing in the chain currently. */
4720 int need_remove_insert;
4723 /* First, build the bpstat chain with locations that explain a
4724 target stop, while being careful to not set the target running,
4725 as that may invalidate locations (in particular watchpoint
4726 locations are recreated). Resuming will happen here with
4727 breakpoint conditions or watchpoint expressions that include
4728 inferior function calls. */
4732 if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
4735 for (bl = b->loc; bl != NULL; bl = bl->next)
4737 /* For hardware watchpoints, we look only at the first
4738 location. The watchpoint_check function will work on the
4739 entire expression, not the individual locations. For
4740 read watchpoints, the watchpoints_triggered function has
4741 checked all locations already. */
4742 if (b->type == bp_hardware_watchpoint && bl != b->loc)
4745 if (bl->shlib_disabled)
4748 if (!bpstat_check_location (bl, aspace, bp_addr, ws))
4751 /* Come here if it's a watchpoint, or if the break address
4754 bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to
4757 /* Assume we stop. Should we find a watchpoint that is not
4758 actually triggered, or if the condition of the breakpoint
4759 evaluates as false, we'll reset 'stop' to 0. */
4763 /* If this is a scope breakpoint, mark the associated
4764 watchpoint as triggered so that we will handle the
4765 out-of-scope event. We'll get to the watchpoint next
4767 if (b->type == bp_watchpoint_scope && b->related_breakpoint != b)
4769 struct watchpoint *w = (struct watchpoint *) b->related_breakpoint;
4771 w->watchpoint_triggered = watch_triggered_yes;
4776 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
4778 if (breakpoint_location_address_match (loc, aspace, bp_addr))
4780 bs = bpstat_alloc (loc, &bs_link);
4781 /* For hits of moribund locations, we should just proceed. */
4784 bs->print_it = print_it_noop;
4788 /* A bit of special processing for shlib breakpoints. We need to
4789 process solib loading here, so that the lists of loaded and
4790 unloaded libraries are correct before we handle "catch load" and
4792 for (bs = bs_head; bs != NULL; bs = bs->next)
4794 if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event)
4796 handle_solib_event ();
4801 /* Now go through the locations that caused the target to stop, and
4802 check whether we're interested in reporting this stop to higher
4803 layers, or whether we should resume the target transparently. */
4807 for (bs = bs_head; bs != NULL; bs = bs->next)
4812 b = bs->breakpoint_at;
4813 b->ops->check_status (bs);
4816 bpstat_check_breakpoint_conditions (bs, ptid);
4821 observer_notify_breakpoint_modified (b);
4823 /* We will stop here. */
4824 if (b->disposition == disp_disable)
4826 --(b->enable_count);
4827 if (b->enable_count <= 0
4828 && b->enable_state != bp_permanent)
4829 b->enable_state = bp_disabled;
4834 bs->commands = b->commands;
4835 incref_counted_command_line (bs->commands);
4836 if (command_line_is_silent (bs->commands
4837 ? bs->commands->commands : NULL))
4843 /* Print nothing for this entry if we don't stop or don't
4845 if (!bs->stop || !bs->print)
4846 bs->print_it = print_it_noop;
4849 /* If we aren't stopping, the value of some hardware watchpoint may
4850 not have changed, but the intermediate memory locations we are
4851 watching may have. Don't bother if we're stopping; this will get
4853 need_remove_insert = 0;
4854 if (! bpstat_causes_stop (bs_head))
4855 for (bs = bs_head; bs != NULL; bs = bs->next)
4857 && bs->breakpoint_at
4858 && is_hardware_watchpoint (bs->breakpoint_at))
4860 struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at;
4862 update_watchpoint (w, 0 /* don't reparse. */);
4863 need_remove_insert = 1;
4866 if (need_remove_insert)
4867 update_global_location_list (1);
4868 else if (removed_any)
4869 update_global_location_list (0);
4875 handle_jit_event (void)
4877 struct frame_info *frame;
4878 struct gdbarch *gdbarch;
4880 /* Switch terminal for any messages produced by
4881 breakpoint_re_set. */
4882 target_terminal_ours_for_output ();
4884 frame = get_current_frame ();
4885 gdbarch = get_frame_arch (frame);
4887 jit_event_handler (gdbarch);
4889 target_terminal_inferior ();
4892 /* Handle an solib event by calling solib_add. */
4895 handle_solib_event (void)
4897 clear_program_space_solib_cache (current_inferior ()->pspace);
4899 /* Check for any newly added shared libraries if we're supposed to
4900 be adding them automatically. Switch terminal for any messages
4901 produced by breakpoint_re_set. */
4902 target_terminal_ours_for_output ();
4904 SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add);
4906 solib_add (NULL, 0, ¤t_target, auto_solib_add);
4908 target_terminal_inferior ();
4911 /* Prepare WHAT final decision for infrun. */
4913 /* Decide what infrun needs to do with this bpstat. */
4916 bpstat_what (bpstat bs_head)
4918 struct bpstat_what retval;
4922 retval.main_action = BPSTAT_WHAT_KEEP_CHECKING;
4923 retval.call_dummy = STOP_NONE;
4924 retval.is_longjmp = 0;
4926 for (bs = bs_head; bs != NULL; bs = bs->next)
4928 /* Extract this BS's action. After processing each BS, we check
4929 if its action overrides all we've seem so far. */
4930 enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING;
4933 if (bs->breakpoint_at == NULL)
4935 /* I suspect this can happen if it was a momentary
4936 breakpoint which has since been deleted. */
4940 bptype = bs->breakpoint_at->type;
4947 case bp_hardware_breakpoint:
4950 case bp_shlib_event:
4954 this_action = BPSTAT_WHAT_STOP_NOISY;
4956 this_action = BPSTAT_WHAT_STOP_SILENT;
4959 this_action = BPSTAT_WHAT_SINGLE;
4962 case bp_hardware_watchpoint:
4963 case bp_read_watchpoint:
4964 case bp_access_watchpoint:
4968 this_action = BPSTAT_WHAT_STOP_NOISY;
4970 this_action = BPSTAT_WHAT_STOP_SILENT;
4974 /* There was a watchpoint, but we're not stopping.
4975 This requires no further action. */
4980 this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME;
4981 retval.is_longjmp = bptype == bp_longjmp;
4983 case bp_longjmp_resume:
4984 case bp_exception_resume:
4985 this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME;
4986 retval.is_longjmp = bptype == bp_longjmp_resume;
4988 case bp_step_resume:
4990 this_action = BPSTAT_WHAT_STEP_RESUME;
4993 /* It is for the wrong frame. */
4994 this_action = BPSTAT_WHAT_SINGLE;
4997 case bp_hp_step_resume:
4999 this_action = BPSTAT_WHAT_HP_STEP_RESUME;
5002 /* It is for the wrong frame. */
5003 this_action = BPSTAT_WHAT_SINGLE;
5006 case bp_watchpoint_scope:
5007 case bp_thread_event:
5008 case bp_overlay_event:
5009 case bp_longjmp_master:
5010 case bp_std_terminate_master:
5011 case bp_exception_master:
5012 this_action = BPSTAT_WHAT_SINGLE;
5018 this_action = BPSTAT_WHAT_STOP_NOISY;
5020 this_action = BPSTAT_WHAT_STOP_SILENT;
5024 /* There was a catchpoint, but we're not stopping.
5025 This requires no further action. */
5030 this_action = BPSTAT_WHAT_SINGLE;
5033 /* Make sure the action is stop (silent or noisy),
5034 so infrun.c pops the dummy frame. */
5035 retval.call_dummy = STOP_STACK_DUMMY;
5036 this_action = BPSTAT_WHAT_STOP_SILENT;
5038 case bp_std_terminate:
5039 /* Make sure the action is stop (silent or noisy),
5040 so infrun.c pops the dummy frame. */
5041 retval.call_dummy = STOP_STD_TERMINATE;
5042 this_action = BPSTAT_WHAT_STOP_SILENT;
5045 case bp_fast_tracepoint:
5046 case bp_static_tracepoint:
5047 /* Tracepoint hits should not be reported back to GDB, and
5048 if one got through somehow, it should have been filtered
5050 internal_error (__FILE__, __LINE__,
5051 _("bpstat_what: tracepoint encountered"));
5053 case bp_gnu_ifunc_resolver:
5054 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5055 this_action = BPSTAT_WHAT_SINGLE;
5057 case bp_gnu_ifunc_resolver_return:
5058 /* The breakpoint will be removed, execution will restart from the
5059 PC of the former breakpoint. */
5060 this_action = BPSTAT_WHAT_KEEP_CHECKING;
5063 internal_error (__FILE__, __LINE__,
5064 _("bpstat_what: unhandled bptype %d"), (int) bptype);
5067 retval.main_action = max (retval.main_action, this_action);
5070 /* These operations may affect the bs->breakpoint_at state so they are
5071 delayed after MAIN_ACTION is decided above. */
5076 fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n");
5078 handle_jit_event ();
5081 for (bs = bs_head; bs != NULL; bs = bs->next)
5083 struct breakpoint *b = bs->breakpoint_at;
5089 case bp_gnu_ifunc_resolver:
5090 gnu_ifunc_resolver_stop (b);
5092 case bp_gnu_ifunc_resolver_return:
5093 gnu_ifunc_resolver_return_stop (b);
5101 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5102 without hardware support). This isn't related to a specific bpstat,
5103 just to things like whether watchpoints are set. */
5106 bpstat_should_step (void)
5108 struct breakpoint *b;
5111 if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL)
5117 bpstat_causes_stop (bpstat bs)
5119 for (; bs != NULL; bs = bs->next)
5128 /* Compute a string of spaces suitable to indent the next line
5129 so it starts at the position corresponding to the table column
5130 named COL_NAME in the currently active table of UIOUT. */
5133 wrap_indent_at_field (struct ui_out *uiout, const char *col_name)
5135 static char wrap_indent[80];
5136 int i, total_width, width, align;
5140 for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++)
5142 if (strcmp (text, col_name) == 0)
5144 gdb_assert (total_width < sizeof wrap_indent);
5145 memset (wrap_indent, ' ', total_width);
5146 wrap_indent[total_width] = 0;
5151 total_width += width + 1;
5157 /* Determine if the locations of this breakpoint will have their conditions
5158 evaluated by the target, host or a mix of both. Returns the following:
5160 "host": Host evals condition.
5161 "host or target": Host or Target evals condition.
5162 "target": Target evals condition.
5166 bp_condition_evaluator (struct breakpoint *b)
5168 struct bp_location *bl;
5169 char host_evals = 0;
5170 char target_evals = 0;
5175 if (!is_breakpoint (b))
5178 if (gdb_evaluates_breakpoint_condition_p ()
5179 || !target_supports_evaluation_of_breakpoint_conditions ())
5180 return condition_evaluation_host;
5182 for (bl = b->loc; bl; bl = bl->next)
5184 if (bl->cond_bytecode)
5190 if (host_evals && target_evals)
5191 return condition_evaluation_both;
5192 else if (target_evals)
5193 return condition_evaluation_target;
5195 return condition_evaluation_host;
5198 /* Determine the breakpoint location's condition evaluator. This is
5199 similar to bp_condition_evaluator, but for locations. */
5202 bp_location_condition_evaluator (struct bp_location *bl)
5204 if (bl && !is_breakpoint (bl->owner))
5207 if (gdb_evaluates_breakpoint_condition_p ()
5208 || !target_supports_evaluation_of_breakpoint_conditions ())
5209 return condition_evaluation_host;
5211 if (bl && bl->cond_bytecode)
5212 return condition_evaluation_target;
5214 return condition_evaluation_host;
5217 /* Print the LOC location out of the list of B->LOC locations. */
5220 print_breakpoint_location (struct breakpoint *b,
5221 struct bp_location *loc)
5223 struct ui_out *uiout = current_uiout;
5224 struct cleanup *old_chain = save_current_program_space ();
5226 if (loc != NULL && loc->shlib_disabled)
5230 set_current_program_space (loc->pspace);
5232 if (b->display_canonical)
5233 ui_out_field_string (uiout, "what", b->addr_string);
5234 else if (loc && loc->source_file)
5237 = find_pc_sect_function (loc->address, loc->section);
5240 ui_out_text (uiout, "in ");
5241 ui_out_field_string (uiout, "func",
5242 SYMBOL_PRINT_NAME (sym));
5243 ui_out_text (uiout, " ");
5244 ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what"));
5245 ui_out_text (uiout, "at ");
5247 ui_out_field_string (uiout, "file", loc->source_file);
5248 ui_out_text (uiout, ":");
5250 if (ui_out_is_mi_like_p (uiout))
5252 struct symtab_and_line sal = find_pc_line (loc->address, 0);
5253 char *fullname = symtab_to_fullname (sal.symtab);
5256 ui_out_field_string (uiout, "fullname", fullname);
5259 ui_out_field_int (uiout, "line", loc->line_number);
5263 struct ui_stream *stb = ui_out_stream_new (uiout);
5264 struct cleanup *stb_chain = make_cleanup_ui_out_stream_delete (stb);
5266 print_address_symbolic (loc->gdbarch, loc->address, stb->stream,
5268 ui_out_field_stream (uiout, "at", stb);
5270 do_cleanups (stb_chain);
5273 ui_out_field_string (uiout, "pending", b->addr_string);
5275 if (loc && is_breakpoint (b)
5276 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
5277 && bp_condition_evaluator (b) == condition_evaluation_both)
5279 ui_out_text (uiout, " (");
5280 ui_out_field_string (uiout, "evaluated-by",
5281 bp_location_condition_evaluator (loc));
5282 ui_out_text (uiout, ")");
5285 do_cleanups (old_chain);
5289 bptype_string (enum bptype type)
5291 struct ep_type_description
5296 static struct ep_type_description bptypes[] =
5298 {bp_none, "?deleted?"},
5299 {bp_breakpoint, "breakpoint"},
5300 {bp_hardware_breakpoint, "hw breakpoint"},
5301 {bp_until, "until"},
5302 {bp_finish, "finish"},
5303 {bp_watchpoint, "watchpoint"},
5304 {bp_hardware_watchpoint, "hw watchpoint"},
5305 {bp_read_watchpoint, "read watchpoint"},
5306 {bp_access_watchpoint, "acc watchpoint"},
5307 {bp_longjmp, "longjmp"},
5308 {bp_longjmp_resume, "longjmp resume"},
5309 {bp_exception, "exception"},
5310 {bp_exception_resume, "exception resume"},
5311 {bp_step_resume, "step resume"},
5312 {bp_hp_step_resume, "high-priority step resume"},
5313 {bp_watchpoint_scope, "watchpoint scope"},
5314 {bp_call_dummy, "call dummy"},
5315 {bp_std_terminate, "std::terminate"},
5316 {bp_shlib_event, "shlib events"},
5317 {bp_thread_event, "thread events"},
5318 {bp_overlay_event, "overlay events"},
5319 {bp_longjmp_master, "longjmp master"},
5320 {bp_std_terminate_master, "std::terminate master"},
5321 {bp_exception_master, "exception master"},
5322 {bp_catchpoint, "catchpoint"},
5323 {bp_tracepoint, "tracepoint"},
5324 {bp_fast_tracepoint, "fast tracepoint"},
5325 {bp_static_tracepoint, "static tracepoint"},
5326 {bp_jit_event, "jit events"},
5327 {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"},
5328 {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"},
5331 if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0])))
5332 || ((int) type != bptypes[(int) type].type))
5333 internal_error (__FILE__, __LINE__,
5334 _("bptypes table does not describe type #%d."),
5337 return bptypes[(int) type].description;
5340 /* Print B to gdb_stdout. */
5343 print_one_breakpoint_location (struct breakpoint *b,
5344 struct bp_location *loc,
5346 struct bp_location **last_loc,
5349 struct command_line *l;
5350 static char bpenables[] = "nynny";
5352 struct ui_out *uiout = current_uiout;
5353 int header_of_multiple = 0;
5354 int part_of_multiple = (loc != NULL);
5355 struct value_print_options opts;
5357 get_user_print_options (&opts);
5359 gdb_assert (!loc || loc_number != 0);
5360 /* See comment in print_one_breakpoint concerning treatment of
5361 breakpoints with single disabled location. */
5364 && (b->loc->next != NULL || !b->loc->enabled)))
5365 header_of_multiple = 1;
5373 if (part_of_multiple)
5376 formatted = xstrprintf ("%d.%d", b->number, loc_number);
5377 ui_out_field_string (uiout, "number", formatted);
5382 ui_out_field_int (uiout, "number", b->number);
5387 if (part_of_multiple)
5388 ui_out_field_skip (uiout, "type");
5390 ui_out_field_string (uiout, "type", bptype_string (b->type));
5394 if (part_of_multiple)
5395 ui_out_field_skip (uiout, "disp");
5397 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
5402 if (part_of_multiple)
5403 ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n");
5405 ui_out_field_fmt (uiout, "enabled", "%c",
5406 bpenables[(int) b->enable_state]);
5407 ui_out_spaces (uiout, 2);
5411 if (b->ops != NULL && b->ops->print_one != NULL)
5413 /* Although the print_one can possibly print all locations,
5414 calling it here is not likely to get any nice result. So,
5415 make sure there's just one location. */
5416 gdb_assert (b->loc == NULL || b->loc->next == NULL);
5417 b->ops->print_one (b, last_loc);
5423 internal_error (__FILE__, __LINE__,
5424 _("print_one_breakpoint: bp_none encountered\n"));
5428 case bp_hardware_watchpoint:
5429 case bp_read_watchpoint:
5430 case bp_access_watchpoint:
5432 struct watchpoint *w = (struct watchpoint *) b;
5434 /* Field 4, the address, is omitted (which makes the columns
5435 not line up too nicely with the headers, but the effect
5436 is relatively readable). */
5437 if (opts.addressprint)
5438 ui_out_field_skip (uiout, "addr");
5440 ui_out_field_string (uiout, "what", w->exp_string);
5445 case bp_hardware_breakpoint:
5449 case bp_longjmp_resume:
5451 case bp_exception_resume:
5452 case bp_step_resume:
5453 case bp_hp_step_resume:
5454 case bp_watchpoint_scope:
5456 case bp_std_terminate:
5457 case bp_shlib_event:
5458 case bp_thread_event:
5459 case bp_overlay_event:
5460 case bp_longjmp_master:
5461 case bp_std_terminate_master:
5462 case bp_exception_master:
5464 case bp_fast_tracepoint:
5465 case bp_static_tracepoint:
5467 case bp_gnu_ifunc_resolver:
5468 case bp_gnu_ifunc_resolver_return:
5469 if (opts.addressprint)
5472 if (header_of_multiple)
5473 ui_out_field_string (uiout, "addr", "<MULTIPLE>");
5474 else if (b->loc == NULL || loc->shlib_disabled)
5475 ui_out_field_string (uiout, "addr", "<PENDING>");
5477 ui_out_field_core_addr (uiout, "addr",
5478 loc->gdbarch, loc->address);
5481 if (!header_of_multiple)
5482 print_breakpoint_location (b, loc);
5489 /* For backward compatibility, don't display inferiors unless there
5492 && !header_of_multiple
5494 || (!gdbarch_has_global_breakpoints (target_gdbarch)
5495 && (number_of_program_spaces () > 1
5496 || number_of_inferiors () > 1)
5497 /* LOC is for existing B, it cannot be in
5498 moribund_locations and thus having NULL OWNER. */
5499 && loc->owner->type != bp_catchpoint)))
5501 struct inferior *inf;
5504 for (inf = inferior_list; inf != NULL; inf = inf->next)
5506 if (inf->pspace == loc->pspace)
5511 ui_out_text (uiout, " inf ");
5514 ui_out_text (uiout, ", ");
5515 ui_out_text (uiout, plongest (inf->num));
5520 if (!part_of_multiple)
5522 if (b->thread != -1)
5524 /* FIXME: This seems to be redundant and lost here; see the
5525 "stop only in" line a little further down. */
5526 ui_out_text (uiout, " thread ");
5527 ui_out_field_int (uiout, "thread", b->thread);
5529 else if (b->task != 0)
5531 ui_out_text (uiout, " task ");
5532 ui_out_field_int (uiout, "task", b->task);
5536 ui_out_text (uiout, "\n");
5538 if (!part_of_multiple)
5539 b->ops->print_one_detail (b, uiout);
5541 if (part_of_multiple && frame_id_p (b->frame_id))
5544 ui_out_text (uiout, "\tstop only in stack frame at ");
5545 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
5547 ui_out_field_core_addr (uiout, "frame",
5548 b->gdbarch, b->frame_id.stack_addr);
5549 ui_out_text (uiout, "\n");
5552 if (!part_of_multiple && b->cond_string)
5555 if (is_tracepoint (b))
5556 ui_out_text (uiout, "\ttrace only if ");
5558 ui_out_text (uiout, "\tstop only if ");
5559 ui_out_field_string (uiout, "cond", b->cond_string);
5561 /* Print whether the target is doing the breakpoint's condition
5562 evaluation. If GDB is doing the evaluation, don't print anything. */
5563 if (is_breakpoint (b)
5564 && breakpoint_condition_evaluation_mode ()
5565 == condition_evaluation_target)
5567 ui_out_text (uiout, " (");
5568 ui_out_field_string (uiout, "evaluated-by",
5569 bp_condition_evaluator (b));
5570 ui_out_text (uiout, " evals)");
5572 ui_out_text (uiout, "\n");
5575 if (!part_of_multiple && b->thread != -1)
5577 /* FIXME should make an annotation for this. */
5578 ui_out_text (uiout, "\tstop only in thread ");
5579 ui_out_field_int (uiout, "thread", b->thread);
5580 ui_out_text (uiout, "\n");
5583 if (!part_of_multiple && b->hit_count)
5585 /* FIXME should make an annotation for this. */
5586 if (ep_is_catchpoint (b))
5587 ui_out_text (uiout, "\tcatchpoint");
5588 else if (is_tracepoint (b))
5589 ui_out_text (uiout, "\ttracepoint");
5591 ui_out_text (uiout, "\tbreakpoint");
5592 ui_out_text (uiout, " already hit ");
5593 ui_out_field_int (uiout, "times", b->hit_count);
5594 if (b->hit_count == 1)
5595 ui_out_text (uiout, " time\n");
5597 ui_out_text (uiout, " times\n");
5600 /* Output the count also if it is zero, but only if this is mi.
5601 FIXME: Should have a better test for this. */
5602 if (ui_out_is_mi_like_p (uiout))
5603 if (!part_of_multiple && b->hit_count == 0)
5604 ui_out_field_int (uiout, "times", b->hit_count);
5606 if (!part_of_multiple && b->ignore_count)
5609 ui_out_text (uiout, "\tignore next ");
5610 ui_out_field_int (uiout, "ignore", b->ignore_count);
5611 ui_out_text (uiout, " hits\n");
5614 /* Note that an enable count of 1 corresponds to "enable once"
5615 behavior, which is reported by the combination of enablement and
5616 disposition, so we don't need to mention it here. */
5617 if (!part_of_multiple && b->enable_count > 1)
5620 ui_out_text (uiout, "\tdisable after ");
5621 /* Tweak the wording to clarify that ignore and enable counts
5622 are distinct, and have additive effect. */
5623 if (b->ignore_count)
5624 ui_out_text (uiout, "additional ");
5626 ui_out_text (uiout, "next ");
5627 ui_out_field_int (uiout, "enable", b->enable_count);
5628 ui_out_text (uiout, " hits\n");
5631 if (!part_of_multiple && is_tracepoint (b))
5633 struct tracepoint *tp = (struct tracepoint *) b;
5635 if (tp->traceframe_usage)
5637 ui_out_text (uiout, "\ttrace buffer usage ");
5638 ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage);
5639 ui_out_text (uiout, " bytes\n");
5643 l = b->commands ? b->commands->commands : NULL;
5644 if (!part_of_multiple && l)
5646 struct cleanup *script_chain;
5649 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
5650 print_command_lines (uiout, l, 4);
5651 do_cleanups (script_chain);
5654 if (is_tracepoint (b))
5656 struct tracepoint *t = (struct tracepoint *) b;
5658 if (!part_of_multiple && t->pass_count)
5660 annotate_field (10);
5661 ui_out_text (uiout, "\tpass count ");
5662 ui_out_field_int (uiout, "pass", t->pass_count);
5663 ui_out_text (uiout, " \n");
5667 if (ui_out_is_mi_like_p (uiout) && !part_of_multiple)
5669 if (is_watchpoint (b))
5671 struct watchpoint *w = (struct watchpoint *) b;
5673 ui_out_field_string (uiout, "original-location", w->exp_string);
5675 else if (b->addr_string)
5676 ui_out_field_string (uiout, "original-location", b->addr_string);
5681 print_one_breakpoint (struct breakpoint *b,
5682 struct bp_location **last_loc,
5685 struct cleanup *bkpt_chain;
5686 struct ui_out *uiout = current_uiout;
5688 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
5690 print_one_breakpoint_location (b, NULL, 0, last_loc, allflag);
5691 do_cleanups (bkpt_chain);
5693 /* If this breakpoint has custom print function,
5694 it's already printed. Otherwise, print individual
5695 locations, if any. */
5696 if (b->ops == NULL || b->ops->print_one == NULL)
5698 /* If breakpoint has a single location that is disabled, we
5699 print it as if it had several locations, since otherwise it's
5700 hard to represent "breakpoint enabled, location disabled"
5703 Note that while hardware watchpoints have several locations
5704 internally, that's not a property exposed to user. */
5706 && !is_hardware_watchpoint (b)
5707 && (b->loc->next || !b->loc->enabled))
5709 struct bp_location *loc;
5712 for (loc = b->loc; loc; loc = loc->next, ++n)
5714 struct cleanup *inner2 =
5715 make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
5716 print_one_breakpoint_location (b, loc, n, last_loc, allflag);
5717 do_cleanups (inner2);
5724 breakpoint_address_bits (struct breakpoint *b)
5726 int print_address_bits = 0;
5727 struct bp_location *loc;
5729 for (loc = b->loc; loc; loc = loc->next)
5733 /* Software watchpoints that aren't watching memory don't have
5734 an address to print. */
5735 if (b->type == bp_watchpoint && loc->watchpoint_type == -1)
5738 addr_bit = gdbarch_addr_bit (loc->gdbarch);
5739 if (addr_bit > print_address_bits)
5740 print_address_bits = addr_bit;
5743 return print_address_bits;
5746 struct captured_breakpoint_query_args
5752 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
5754 struct captured_breakpoint_query_args *args = data;
5755 struct breakpoint *b;
5756 struct bp_location *dummy_loc = NULL;
5760 if (args->bnum == b->number)
5762 print_one_breakpoint (b, &dummy_loc, 0);
5770 gdb_breakpoint_query (struct ui_out *uiout, int bnum,
5771 char **error_message)
5773 struct captured_breakpoint_query_args args;
5776 /* For the moment we don't trust print_one_breakpoint() to not throw
5778 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
5779 error_message, RETURN_MASK_ALL) < 0)
5785 /* Return true if this breakpoint was set by the user, false if it is
5786 internal or momentary. */
5789 user_breakpoint_p (struct breakpoint *b)
5791 return b->number > 0;
5794 /* Print information on user settable breakpoint (watchpoint, etc)
5795 number BNUM. If BNUM is -1 print all user-settable breakpoints.
5796 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
5797 FILTER is non-NULL, call it on each breakpoint and only include the
5798 ones for which it returns non-zero. Return the total number of
5799 breakpoints listed. */
5802 breakpoint_1 (char *args, int allflag,
5803 int (*filter) (const struct breakpoint *))
5805 struct breakpoint *b;
5806 struct bp_location *last_loc = NULL;
5807 int nr_printable_breakpoints;
5808 struct cleanup *bkpttbl_chain;
5809 struct value_print_options opts;
5810 int print_address_bits = 0;
5811 int print_type_col_width = 14;
5812 struct ui_out *uiout = current_uiout;
5814 get_user_print_options (&opts);
5816 /* Compute the number of rows in the table, as well as the size
5817 required for address fields. */
5818 nr_printable_breakpoints = 0;
5821 /* If we have a filter, only list the breakpoints it accepts. */
5822 if (filter && !filter (b))
5825 /* If we have an "args" string, it is a list of breakpoints to
5826 accept. Skip the others. */
5827 if (args != NULL && *args != '\0')
5829 if (allflag && parse_and_eval_long (args) != b->number)
5831 if (!allflag && !number_is_in_list (args, b->number))
5835 if (allflag || user_breakpoint_p (b))
5837 int addr_bit, type_len;
5839 addr_bit = breakpoint_address_bits (b);
5840 if (addr_bit > print_address_bits)
5841 print_address_bits = addr_bit;
5843 type_len = strlen (bptype_string (b->type));
5844 if (type_len > print_type_col_width)
5845 print_type_col_width = type_len;
5847 nr_printable_breakpoints++;
5851 if (opts.addressprint)
5853 = make_cleanup_ui_out_table_begin_end (uiout, 6,
5854 nr_printable_breakpoints,
5858 = make_cleanup_ui_out_table_begin_end (uiout, 5,
5859 nr_printable_breakpoints,
5862 if (nr_printable_breakpoints > 0)
5863 annotate_breakpoints_headers ();
5864 if (nr_printable_breakpoints > 0)
5866 ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */
5867 if (nr_printable_breakpoints > 0)
5869 ui_out_table_header (uiout, print_type_col_width, ui_left,
5870 "type", "Type"); /* 2 */
5871 if (nr_printable_breakpoints > 0)
5873 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
5874 if (nr_printable_breakpoints > 0)
5876 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
5877 if (opts.addressprint)
5879 if (nr_printable_breakpoints > 0)
5881 if (print_address_bits <= 32)
5882 ui_out_table_header (uiout, 10, ui_left,
5883 "addr", "Address"); /* 5 */
5885 ui_out_table_header (uiout, 18, ui_left,
5886 "addr", "Address"); /* 5 */
5888 if (nr_printable_breakpoints > 0)
5890 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
5891 ui_out_table_body (uiout);
5892 if (nr_printable_breakpoints > 0)
5893 annotate_breakpoints_table ();
5898 /* If we have a filter, only list the breakpoints it accepts. */
5899 if (filter && !filter (b))
5902 /* If we have an "args" string, it is a list of breakpoints to
5903 accept. Skip the others. */
5905 if (args != NULL && *args != '\0')
5907 if (allflag) /* maintenance info breakpoint */
5909 if (parse_and_eval_long (args) != b->number)
5912 else /* all others */
5914 if (!number_is_in_list (args, b->number))
5918 /* We only print out user settable breakpoints unless the
5920 if (allflag || user_breakpoint_p (b))
5921 print_one_breakpoint (b, &last_loc, allflag);
5924 do_cleanups (bkpttbl_chain);
5926 if (nr_printable_breakpoints == 0)
5928 /* If there's a filter, let the caller decide how to report
5932 if (args == NULL || *args == '\0')
5933 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
5935 ui_out_message (uiout, 0,
5936 "No breakpoint or watchpoint matching '%s'.\n",
5942 if (last_loc && !server_command)
5943 set_next_address (last_loc->gdbarch, last_loc->address);
5946 /* FIXME? Should this be moved up so that it is only called when
5947 there have been breakpoints? */
5948 annotate_breakpoints_table_end ();
5950 return nr_printable_breakpoints;
5953 /* Display the value of default-collect in a way that is generally
5954 compatible with the breakpoint list. */
5957 default_collect_info (void)
5959 struct ui_out *uiout = current_uiout;
5961 /* If it has no value (which is frequently the case), say nothing; a
5962 message like "No default-collect." gets in user's face when it's
5964 if (!*default_collect)
5967 /* The following phrase lines up nicely with per-tracepoint collect
5969 ui_out_text (uiout, "default collect ");
5970 ui_out_field_string (uiout, "default-collect", default_collect);
5971 ui_out_text (uiout, " \n");
5975 breakpoints_info (char *args, int from_tty)
5977 breakpoint_1 (args, 0, NULL);
5979 default_collect_info ();
5983 watchpoints_info (char *args, int from_tty)
5985 int num_printed = breakpoint_1 (args, 0, is_watchpoint);
5986 struct ui_out *uiout = current_uiout;
5988 if (num_printed == 0)
5990 if (args == NULL || *args == '\0')
5991 ui_out_message (uiout, 0, "No watchpoints.\n");
5993 ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args);
5998 maintenance_info_breakpoints (char *args, int from_tty)
6000 breakpoint_1 (args, 1, NULL);
6002 default_collect_info ();
6006 breakpoint_has_pc (struct breakpoint *b,
6007 struct program_space *pspace,
6008 CORE_ADDR pc, struct obj_section *section)
6010 struct bp_location *bl = b->loc;
6012 for (; bl; bl = bl->next)
6014 if (bl->pspace == pspace
6015 && bl->address == pc
6016 && (!overlay_debugging || bl->section == section))
6022 /* Print a message describing any user-breakpoints set at PC. This
6023 concerns with logical breakpoints, so we match program spaces, not
6027 describe_other_breakpoints (struct gdbarch *gdbarch,
6028 struct program_space *pspace, CORE_ADDR pc,
6029 struct obj_section *section, int thread)
6032 struct breakpoint *b;
6035 others += (user_breakpoint_p (b)
6036 && breakpoint_has_pc (b, pspace, pc, section));
6040 printf_filtered (_("Note: breakpoint "));
6041 else /* if (others == ???) */
6042 printf_filtered (_("Note: breakpoints "));
6044 if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section))
6047 printf_filtered ("%d", b->number);
6048 if (b->thread == -1 && thread != -1)
6049 printf_filtered (" (all threads)");
6050 else if (b->thread != -1)
6051 printf_filtered (" (thread %d)", b->thread);
6052 printf_filtered ("%s%s ",
6053 ((b->enable_state == bp_disabled
6054 || b->enable_state == bp_call_disabled)
6056 : b->enable_state == bp_permanent
6060 : ((others == 1) ? " and" : ""));
6062 printf_filtered (_("also set at pc "));
6063 fputs_filtered (paddress (gdbarch, pc), gdb_stdout);
6064 printf_filtered (".\n");
6069 /* Return true iff it is meaningful to use the address member of
6070 BPT. For some breakpoint types, the address member is irrelevant
6071 and it makes no sense to attempt to compare it to other addresses
6072 (or use it for any other purpose either).
6074 More specifically, each of the following breakpoint types will
6075 always have a zero valued address and we don't want to mark
6076 breakpoints of any of these types to be a duplicate of an actual
6077 breakpoint at address zero:
6085 breakpoint_address_is_meaningful (struct breakpoint *bpt)
6087 enum bptype type = bpt->type;
6089 return (type != bp_watchpoint && type != bp_catchpoint);
6092 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6093 true if LOC1 and LOC2 represent the same watchpoint location. */
6096 watchpoint_locations_match (struct bp_location *loc1,
6097 struct bp_location *loc2)
6099 struct watchpoint *w1 = (struct watchpoint *) loc1->owner;
6100 struct watchpoint *w2 = (struct watchpoint *) loc2->owner;
6102 /* Both of them must exist. */
6103 gdb_assert (w1 != NULL);
6104 gdb_assert (w2 != NULL);
6106 /* If the target can evaluate the condition expression in hardware,
6107 then we we need to insert both watchpoints even if they are at
6108 the same place. Otherwise the watchpoint will only trigger when
6109 the condition of whichever watchpoint was inserted evaluates to
6110 true, not giving a chance for GDB to check the condition of the
6111 other watchpoint. */
6113 && target_can_accel_watchpoint_condition (loc1->address,
6115 loc1->watchpoint_type,
6118 && target_can_accel_watchpoint_condition (loc2->address,
6120 loc2->watchpoint_type,
6124 /* Note that this checks the owner's type, not the location's. In
6125 case the target does not support read watchpoints, but does
6126 support access watchpoints, we'll have bp_read_watchpoint
6127 watchpoints with hw_access locations. Those should be considered
6128 duplicates of hw_read locations. The hw_read locations will
6129 become hw_access locations later. */
6130 return (loc1->owner->type == loc2->owner->type
6131 && loc1->pspace->aspace == loc2->pspace->aspace
6132 && loc1->address == loc2->address
6133 && loc1->length == loc2->length);
6136 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
6137 same breakpoint location. In most targets, this can only be true
6138 if ASPACE1 matches ASPACE2. On targets that have global
6139 breakpoints, the address space doesn't really matter. */
6142 breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1,
6143 struct address_space *aspace2, CORE_ADDR addr2)
6145 return ((gdbarch_has_global_breakpoints (target_gdbarch)
6146 || aspace1 == aspace2)
6150 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6151 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6152 matches ASPACE2. On targets that have global breakpoints, the address
6153 space doesn't really matter. */
6156 breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1,
6157 int len1, struct address_space *aspace2,
6160 return ((gdbarch_has_global_breakpoints (target_gdbarch)
6161 || aspace1 == aspace2)
6162 && addr2 >= addr1 && addr2 < addr1 + len1);
6165 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6166 a ranged breakpoint. In most targets, a match happens only if ASPACE
6167 matches the breakpoint's address space. On targets that have global
6168 breakpoints, the address space doesn't really matter. */
6171 breakpoint_location_address_match (struct bp_location *bl,
6172 struct address_space *aspace,
6175 return (breakpoint_address_match (bl->pspace->aspace, bl->address,
6178 && breakpoint_address_match_range (bl->pspace->aspace,
6179 bl->address, bl->length,
6183 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6184 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6185 true, otherwise returns false. */
6188 tracepoint_locations_match (struct bp_location *loc1,
6189 struct bp_location *loc2)
6191 if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner))
6192 /* Since tracepoint locations are never duplicated with others', tracepoint
6193 locations at the same address of different tracepoints are regarded as
6194 different locations. */
6195 return (loc1->address == loc2->address && loc1->owner == loc2->owner);
6200 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
6201 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
6202 represent the same location. */
6205 breakpoint_locations_match (struct bp_location *loc1,
6206 struct bp_location *loc2)
6208 int hw_point1, hw_point2;
6210 /* Both of them must not be in moribund_locations. */
6211 gdb_assert (loc1->owner != NULL);
6212 gdb_assert (loc2->owner != NULL);
6214 hw_point1 = is_hardware_watchpoint (loc1->owner);
6215 hw_point2 = is_hardware_watchpoint (loc2->owner);
6217 if (hw_point1 != hw_point2)
6220 return watchpoint_locations_match (loc1, loc2);
6221 else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner))
6222 return tracepoint_locations_match (loc1, loc2);
6224 /* We compare bp_location.length in order to cover ranged breakpoints. */
6225 return (breakpoint_address_match (loc1->pspace->aspace, loc1->address,
6226 loc2->pspace->aspace, loc2->address)
6227 && loc1->length == loc2->length);
6231 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
6232 int bnum, int have_bnum)
6234 /* The longest string possibly returned by hex_string_custom
6235 is 50 chars. These must be at least that big for safety. */
6239 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
6240 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
6242 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
6243 bnum, astr1, astr2);
6245 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
6248 /* Adjust a breakpoint's address to account for architectural
6249 constraints on breakpoint placement. Return the adjusted address.
6250 Note: Very few targets require this kind of adjustment. For most
6251 targets, this function is simply the identity function. */
6254 adjust_breakpoint_address (struct gdbarch *gdbarch,
6255 CORE_ADDR bpaddr, enum bptype bptype)
6257 if (!gdbarch_adjust_breakpoint_address_p (gdbarch))
6259 /* Very few targets need any kind of breakpoint adjustment. */
6262 else if (bptype == bp_watchpoint
6263 || bptype == bp_hardware_watchpoint
6264 || bptype == bp_read_watchpoint
6265 || bptype == bp_access_watchpoint
6266 || bptype == bp_catchpoint)
6268 /* Watchpoints and the various bp_catch_* eventpoints should not
6269 have their addresses modified. */
6274 CORE_ADDR adjusted_bpaddr;
6276 /* Some targets have architectural constraints on the placement
6277 of breakpoint instructions. Obtain the adjusted address. */
6278 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr);
6280 /* An adjusted breakpoint address can significantly alter
6281 a user's expectations. Print a warning if an adjustment
6283 if (adjusted_bpaddr != bpaddr)
6284 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
6286 return adjusted_bpaddr;
6291 init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops,
6292 struct breakpoint *owner)
6294 memset (loc, 0, sizeof (*loc));
6296 gdb_assert (ops != NULL);
6301 loc->cond_bytecode = NULL;
6302 loc->shlib_disabled = 0;
6305 switch (owner->type)
6311 case bp_longjmp_resume:
6313 case bp_exception_resume:
6314 case bp_step_resume:
6315 case bp_hp_step_resume:
6316 case bp_watchpoint_scope:
6318 case bp_std_terminate:
6319 case bp_shlib_event:
6320 case bp_thread_event:
6321 case bp_overlay_event:
6323 case bp_longjmp_master:
6324 case bp_std_terminate_master:
6325 case bp_exception_master:
6326 case bp_gnu_ifunc_resolver:
6327 case bp_gnu_ifunc_resolver_return:
6328 loc->loc_type = bp_loc_software_breakpoint;
6329 mark_breakpoint_location_modified (loc);
6331 case bp_hardware_breakpoint:
6332 loc->loc_type = bp_loc_hardware_breakpoint;
6333 mark_breakpoint_location_modified (loc);
6335 case bp_hardware_watchpoint:
6336 case bp_read_watchpoint:
6337 case bp_access_watchpoint:
6338 loc->loc_type = bp_loc_hardware_watchpoint;
6343 case bp_fast_tracepoint:
6344 case bp_static_tracepoint:
6345 loc->loc_type = bp_loc_other;
6348 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
6354 /* Allocate a struct bp_location. */
6356 static struct bp_location *
6357 allocate_bp_location (struct breakpoint *bpt)
6359 return bpt->ops->allocate_location (bpt);
6363 free_bp_location (struct bp_location *loc)
6365 loc->ops->dtor (loc);
6369 /* Increment reference count. */
6372 incref_bp_location (struct bp_location *bl)
6377 /* Decrement reference count. If the reference count reaches 0,
6378 destroy the bp_location. Sets *BLP to NULL. */
6381 decref_bp_location (struct bp_location **blp)
6383 gdb_assert ((*blp)->refc > 0);
6385 if (--(*blp)->refc == 0)
6386 free_bp_location (*blp);
6390 /* Add breakpoint B at the end of the global breakpoint chain. */
6393 add_to_breakpoint_chain (struct breakpoint *b)
6395 struct breakpoint *b1;
6397 /* Add this breakpoint to the end of the chain so that a list of
6398 breakpoints will come out in order of increasing numbers. */
6400 b1 = breakpoint_chain;
6402 breakpoint_chain = b;
6411 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
6414 init_raw_breakpoint_without_location (struct breakpoint *b,
6415 struct gdbarch *gdbarch,
6417 const struct breakpoint_ops *ops)
6419 memset (b, 0, sizeof (*b));
6421 gdb_assert (ops != NULL);
6425 b->gdbarch = gdbarch;
6426 b->language = current_language->la_language;
6427 b->input_radix = input_radix;
6429 b->enable_state = bp_enabled;
6432 b->ignore_count = 0;
6434 b->frame_id = null_frame_id;
6435 b->condition_not_parsed = 0;
6436 b->py_bp_object = NULL;
6437 b->related_breakpoint = b;
6440 /* Helper to set_raw_breakpoint below. Creates a breakpoint
6441 that has type BPTYPE and has no locations as yet. */
6443 static struct breakpoint *
6444 set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
6446 const struct breakpoint_ops *ops)
6448 struct breakpoint *b = XNEW (struct breakpoint);
6450 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
6451 add_to_breakpoint_chain (b);
6455 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
6456 resolutions should be made as the user specified the location explicitly
6460 set_breakpoint_location_function (struct bp_location *loc, int explicit_loc)
6462 gdb_assert (loc->owner != NULL);
6464 if (loc->owner->type == bp_breakpoint
6465 || loc->owner->type == bp_hardware_breakpoint
6466 || is_tracepoint (loc->owner))
6469 const char *function_name;
6471 find_pc_partial_function_gnu_ifunc (loc->address, &function_name,
6472 NULL, NULL, &is_gnu_ifunc);
6474 if (is_gnu_ifunc && !explicit_loc)
6476 struct breakpoint *b = loc->owner;
6478 gdb_assert (loc->pspace == current_program_space);
6479 if (gnu_ifunc_resolve_name (function_name,
6480 &loc->requested_address))
6482 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
6483 loc->address = adjust_breakpoint_address (loc->gdbarch,
6484 loc->requested_address,
6487 else if (b->type == bp_breakpoint && b->loc == loc
6488 && loc->next == NULL && b->related_breakpoint == b)
6490 /* Create only the whole new breakpoint of this type but do not
6491 mess more complicated breakpoints with multiple locations. */
6492 b->type = bp_gnu_ifunc_resolver;
6497 loc->function_name = xstrdup (function_name);
6501 /* Attempt to determine architecture of location identified by SAL. */
6503 get_sal_arch (struct symtab_and_line sal)
6506 return get_objfile_arch (sal.section->objfile);
6508 return get_objfile_arch (sal.symtab->objfile);
6513 /* Low level routine for partially initializing a breakpoint of type
6514 BPTYPE. The newly created breakpoint's address, section, source
6515 file name, and line number are provided by SAL.
6517 It is expected that the caller will complete the initialization of
6518 the newly created breakpoint struct as well as output any status
6519 information regarding the creation of a new breakpoint. */
6522 init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch,
6523 struct symtab_and_line sal, enum bptype bptype,
6524 const struct breakpoint_ops *ops)
6526 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
6528 add_location_to_breakpoint (b, &sal);
6530 if (bptype != bp_catchpoint)
6531 gdb_assert (sal.pspace != NULL);
6533 /* Store the program space that was used to set the breakpoint,
6534 except for ordinary breakpoints, which are independent of the
6536 if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint)
6537 b->pspace = sal.pspace;
6539 breakpoints_changed ();
6542 /* set_raw_breakpoint is a low level routine for allocating and
6543 partially initializing a breakpoint of type BPTYPE. The newly
6544 created breakpoint's address, section, source file name, and line
6545 number are provided by SAL. The newly created and partially
6546 initialized breakpoint is added to the breakpoint chain and
6547 is also returned as the value of this function.
6549 It is expected that the caller will complete the initialization of
6550 the newly created breakpoint struct as well as output any status
6551 information regarding the creation of a new breakpoint. In
6552 particular, set_raw_breakpoint does NOT set the breakpoint
6553 number! Care should be taken to not allow an error to occur
6554 prior to completing the initialization of the breakpoint. If this
6555 should happen, a bogus breakpoint will be left on the chain. */
6558 set_raw_breakpoint (struct gdbarch *gdbarch,
6559 struct symtab_and_line sal, enum bptype bptype,
6560 const struct breakpoint_ops *ops)
6562 struct breakpoint *b = XNEW (struct breakpoint);
6564 init_raw_breakpoint (b, gdbarch, sal, bptype, ops);
6565 add_to_breakpoint_chain (b);
6570 /* Note that the breakpoint object B describes a permanent breakpoint
6571 instruction, hard-wired into the inferior's code. */
6573 make_breakpoint_permanent (struct breakpoint *b)
6575 struct bp_location *bl;
6577 b->enable_state = bp_permanent;
6579 /* By definition, permanent breakpoints are already present in the
6580 code. Mark all locations as inserted. For now,
6581 make_breakpoint_permanent is called in just one place, so it's
6582 hard to say if it's reasonable to have permanent breakpoint with
6583 multiple locations or not, but it's easy to implement. */
6584 for (bl = b->loc; bl; bl = bl->next)
6588 /* Call this routine when stepping and nexting to enable a breakpoint
6589 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
6590 initiated the operation. */
6593 set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame)
6595 struct breakpoint *b, *b_tmp;
6596 int thread = tp->num;
6598 /* To avoid having to rescan all objfile symbols at every step,
6599 we maintain a list of continually-inserted but always disabled
6600 longjmp "master" breakpoints. Here, we simply create momentary
6601 clones of those and enable them for the requested thread. */
6602 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6603 if (b->pspace == current_program_space
6604 && (b->type == bp_longjmp_master
6605 || b->type == bp_exception_master))
6607 enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception;
6608 struct breakpoint *clone;
6610 clone = momentary_breakpoint_from_master (b, type,
6611 &momentary_breakpoint_ops);
6612 clone->thread = thread;
6615 tp->initiating_frame = frame;
6618 /* Delete all longjmp breakpoints from THREAD. */
6620 delete_longjmp_breakpoint (int thread)
6622 struct breakpoint *b, *b_tmp;
6624 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6625 if (b->type == bp_longjmp || b->type == bp_exception)
6627 if (b->thread == thread)
6628 delete_breakpoint (b);
6633 delete_longjmp_breakpoint_at_next_stop (int thread)
6635 struct breakpoint *b, *b_tmp;
6637 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6638 if (b->type == bp_longjmp || b->type == bp_exception)
6640 if (b->thread == thread)
6641 b->disposition = disp_del_at_next_stop;
6646 enable_overlay_breakpoints (void)
6648 struct breakpoint *b;
6651 if (b->type == bp_overlay_event)
6653 b->enable_state = bp_enabled;
6654 update_global_location_list (1);
6655 overlay_events_enabled = 1;
6660 disable_overlay_breakpoints (void)
6662 struct breakpoint *b;
6665 if (b->type == bp_overlay_event)
6667 b->enable_state = bp_disabled;
6668 update_global_location_list (0);
6669 overlay_events_enabled = 0;
6673 /* Set an active std::terminate breakpoint for each std::terminate
6674 master breakpoint. */
6676 set_std_terminate_breakpoint (void)
6678 struct breakpoint *b, *b_tmp;
6680 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6681 if (b->pspace == current_program_space
6682 && b->type == bp_std_terminate_master)
6684 momentary_breakpoint_from_master (b, bp_std_terminate,
6685 &momentary_breakpoint_ops);
6689 /* Delete all the std::terminate breakpoints. */
6691 delete_std_terminate_breakpoint (void)
6693 struct breakpoint *b, *b_tmp;
6695 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6696 if (b->type == bp_std_terminate)
6697 delete_breakpoint (b);
6701 create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
6703 struct breakpoint *b;
6705 b = create_internal_breakpoint (gdbarch, address, bp_thread_event,
6706 &internal_breakpoint_ops);
6708 b->enable_state = bp_enabled;
6709 /* addr_string has to be used or breakpoint_re_set will delete me. */
6711 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
6713 update_global_location_list_nothrow (1);
6719 remove_thread_event_breakpoints (void)
6721 struct breakpoint *b, *b_tmp;
6723 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6724 if (b->type == bp_thread_event
6725 && b->loc->pspace == current_program_space)
6726 delete_breakpoint (b);
6729 struct lang_and_radix
6735 /* Create a breakpoint for JIT code registration and unregistration. */
6738 create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
6740 struct breakpoint *b;
6742 b = create_internal_breakpoint (gdbarch, address, bp_jit_event,
6743 &internal_breakpoint_ops);
6744 update_global_location_list_nothrow (1);
6748 /* Remove JIT code registration and unregistration breakpoint(s). */
6751 remove_jit_event_breakpoints (void)
6753 struct breakpoint *b, *b_tmp;
6755 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6756 if (b->type == bp_jit_event
6757 && b->loc->pspace == current_program_space)
6758 delete_breakpoint (b);
6762 remove_solib_event_breakpoints (void)
6764 struct breakpoint *b, *b_tmp;
6766 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6767 if (b->type == bp_shlib_event
6768 && b->loc->pspace == current_program_space)
6769 delete_breakpoint (b);
6773 create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
6775 struct breakpoint *b;
6777 b = create_internal_breakpoint (gdbarch, address, bp_shlib_event,
6778 &internal_breakpoint_ops);
6779 update_global_location_list_nothrow (1);
6783 /* Disable any breakpoints that are on code in shared libraries. Only
6784 apply to enabled breakpoints, disabled ones can just stay disabled. */
6787 disable_breakpoints_in_shlibs (void)
6789 struct bp_location *loc, **locp_tmp;
6791 ALL_BP_LOCATIONS (loc, locp_tmp)
6793 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6794 struct breakpoint *b = loc->owner;
6796 /* We apply the check to all breakpoints, including disabled for
6797 those with loc->duplicate set. This is so that when breakpoint
6798 becomes enabled, or the duplicate is removed, gdb will try to
6799 insert all breakpoints. If we don't set shlib_disabled here,
6800 we'll try to insert those breakpoints and fail. */
6801 if (((b->type == bp_breakpoint)
6802 || (b->type == bp_jit_event)
6803 || (b->type == bp_hardware_breakpoint)
6804 || (is_tracepoint (b)))
6805 && loc->pspace == current_program_space
6806 && !loc->shlib_disabled
6808 && PC_SOLIB (loc->address)
6810 && solib_name_from_address (loc->pspace, loc->address)
6814 loc->shlib_disabled = 1;
6819 /* Disable any breakpoints and tracepoints that are in an unloaded shared
6820 library. Only apply to enabled breakpoints, disabled ones can just stay
6824 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
6826 struct bp_location *loc, **locp_tmp;
6827 int disabled_shlib_breaks = 0;
6829 /* SunOS a.out shared libraries are always mapped, so do not
6830 disable breakpoints; they will only be reported as unloaded
6831 through clear_solib when GDB discards its shared library
6832 list. See clear_solib for more information. */
6833 if (exec_bfd != NULL
6834 && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour)
6837 ALL_BP_LOCATIONS (loc, locp_tmp)
6839 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6840 struct breakpoint *b = loc->owner;
6842 if (solib->pspace == loc->pspace
6843 && !loc->shlib_disabled
6844 && (((b->type == bp_breakpoint
6845 || b->type == bp_jit_event
6846 || b->type == bp_hardware_breakpoint)
6847 && (loc->loc_type == bp_loc_hardware_breakpoint
6848 || loc->loc_type == bp_loc_software_breakpoint))
6849 || is_tracepoint (b))
6850 && solib_contains_address_p (solib, loc->address))
6852 loc->shlib_disabled = 1;
6853 /* At this point, we cannot rely on remove_breakpoint
6854 succeeding so we must mark the breakpoint as not inserted
6855 to prevent future errors occurring in remove_breakpoints. */
6858 /* This may cause duplicate notifications for the same breakpoint. */
6859 observer_notify_breakpoint_modified (b);
6861 if (!disabled_shlib_breaks)
6863 target_terminal_ours_for_output ();
6864 warning (_("Temporarily disabling breakpoints "
6865 "for unloaded shared library \"%s\""),
6868 disabled_shlib_breaks = 1;
6873 /* FORK & VFORK catchpoints. */
6875 /* An instance of this type is used to represent a fork or vfork
6876 catchpoint. It includes a "struct breakpoint" as a kind of base
6877 class; users downcast to "struct breakpoint *" when needed. A
6878 breakpoint is really of this type iff its ops pointer points to
6879 CATCH_FORK_BREAKPOINT_OPS. */
6881 struct fork_catchpoint
6883 /* The base class. */
6884 struct breakpoint base;
6886 /* Process id of a child process whose forking triggered this
6887 catchpoint. This field is only valid immediately after this
6888 catchpoint has triggered. */
6889 ptid_t forked_inferior_pid;
6892 /* Implement the "insert" breakpoint_ops method for fork
6896 insert_catch_fork (struct bp_location *bl)
6898 return target_insert_fork_catchpoint (PIDGET (inferior_ptid));
6901 /* Implement the "remove" breakpoint_ops method for fork
6905 remove_catch_fork (struct bp_location *bl)
6907 return target_remove_fork_catchpoint (PIDGET (inferior_ptid));
6910 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
6914 breakpoint_hit_catch_fork (const struct bp_location *bl,
6915 struct address_space *aspace, CORE_ADDR bp_addr,
6916 const struct target_waitstatus *ws)
6918 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
6920 if (ws->kind != TARGET_WAITKIND_FORKED)
6923 c->forked_inferior_pid = ws->value.related_pid;
6927 /* Implement the "print_it" breakpoint_ops method for fork
6930 static enum print_stop_action
6931 print_it_catch_fork (bpstat bs)
6933 struct ui_out *uiout = current_uiout;
6934 struct breakpoint *b = bs->breakpoint_at;
6935 struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at;
6937 annotate_catchpoint (b->number);
6938 if (b->disposition == disp_del)
6939 ui_out_text (uiout, "\nTemporary catchpoint ");
6941 ui_out_text (uiout, "\nCatchpoint ");
6942 if (ui_out_is_mi_like_p (uiout))
6944 ui_out_field_string (uiout, "reason",
6945 async_reason_lookup (EXEC_ASYNC_FORK));
6946 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
6948 ui_out_field_int (uiout, "bkptno", b->number);
6949 ui_out_text (uiout, " (forked process ");
6950 ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid));
6951 ui_out_text (uiout, "), ");
6952 return PRINT_SRC_AND_LOC;
6955 /* Implement the "print_one" breakpoint_ops method for fork
6959 print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc)
6961 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
6962 struct value_print_options opts;
6963 struct ui_out *uiout = current_uiout;
6965 get_user_print_options (&opts);
6967 /* Field 4, the address, is omitted (which makes the columns not
6968 line up too nicely with the headers, but the effect is relatively
6970 if (opts.addressprint)
6971 ui_out_field_skip (uiout, "addr");
6973 ui_out_text (uiout, "fork");
6974 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
6976 ui_out_text (uiout, ", process ");
6977 ui_out_field_int (uiout, "what",
6978 ptid_get_pid (c->forked_inferior_pid));
6979 ui_out_spaces (uiout, 1);
6983 /* Implement the "print_mention" breakpoint_ops method for fork
6987 print_mention_catch_fork (struct breakpoint *b)
6989 printf_filtered (_("Catchpoint %d (fork)"), b->number);
6992 /* Implement the "print_recreate" breakpoint_ops method for fork
6996 print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp)
6998 fprintf_unfiltered (fp, "catch fork");
6999 print_recreate_thread (b, fp);
7002 /* The breakpoint_ops structure to be used in fork catchpoints. */
7004 static struct breakpoint_ops catch_fork_breakpoint_ops;
7006 /* Implement the "insert" breakpoint_ops method for vfork
7010 insert_catch_vfork (struct bp_location *bl)
7012 return target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
7015 /* Implement the "remove" breakpoint_ops method for vfork
7019 remove_catch_vfork (struct bp_location *bl)
7021 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
7024 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
7028 breakpoint_hit_catch_vfork (const struct bp_location *bl,
7029 struct address_space *aspace, CORE_ADDR bp_addr,
7030 const struct target_waitstatus *ws)
7032 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
7034 if (ws->kind != TARGET_WAITKIND_VFORKED)
7037 c->forked_inferior_pid = ws->value.related_pid;
7041 /* Implement the "print_it" breakpoint_ops method for vfork
7044 static enum print_stop_action
7045 print_it_catch_vfork (bpstat bs)
7047 struct ui_out *uiout = current_uiout;
7048 struct breakpoint *b = bs->breakpoint_at;
7049 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
7051 annotate_catchpoint (b->number);
7052 if (b->disposition == disp_del)
7053 ui_out_text (uiout, "\nTemporary catchpoint ");
7055 ui_out_text (uiout, "\nCatchpoint ");
7056 if (ui_out_is_mi_like_p (uiout))
7058 ui_out_field_string (uiout, "reason",
7059 async_reason_lookup (EXEC_ASYNC_VFORK));
7060 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7062 ui_out_field_int (uiout, "bkptno", b->number);
7063 ui_out_text (uiout, " (vforked process ");
7064 ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid));
7065 ui_out_text (uiout, "), ");
7066 return PRINT_SRC_AND_LOC;
7069 /* Implement the "print_one" breakpoint_ops method for vfork
7073 print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc)
7075 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
7076 struct value_print_options opts;
7077 struct ui_out *uiout = current_uiout;
7079 get_user_print_options (&opts);
7080 /* Field 4, the address, is omitted (which makes the columns not
7081 line up too nicely with the headers, but the effect is relatively
7083 if (opts.addressprint)
7084 ui_out_field_skip (uiout, "addr");
7086 ui_out_text (uiout, "vfork");
7087 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
7089 ui_out_text (uiout, ", process ");
7090 ui_out_field_int (uiout, "what",
7091 ptid_get_pid (c->forked_inferior_pid));
7092 ui_out_spaces (uiout, 1);
7096 /* Implement the "print_mention" breakpoint_ops method for vfork
7100 print_mention_catch_vfork (struct breakpoint *b)
7102 printf_filtered (_("Catchpoint %d (vfork)"), b->number);
7105 /* Implement the "print_recreate" breakpoint_ops method for vfork
7109 print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp)
7111 fprintf_unfiltered (fp, "catch vfork");
7112 print_recreate_thread (b, fp);
7115 /* The breakpoint_ops structure to be used in vfork catchpoints. */
7117 static struct breakpoint_ops catch_vfork_breakpoint_ops;
7119 /* An instance of this type is used to represent an solib catchpoint.
7120 It includes a "struct breakpoint" as a kind of base class; users
7121 downcast to "struct breakpoint *" when needed. A breakpoint is
7122 really of this type iff its ops pointer points to
7123 CATCH_SOLIB_BREAKPOINT_OPS. */
7125 struct solib_catchpoint
7127 /* The base class. */
7128 struct breakpoint base;
7130 /* True for "catch load", false for "catch unload". */
7131 unsigned char is_load;
7133 /* Regular expression to match, if any. COMPILED is only valid when
7134 REGEX is non-NULL. */
7140 dtor_catch_solib (struct breakpoint *b)
7142 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
7145 regfree (&self->compiled);
7146 xfree (self->regex);
7148 base_breakpoint_ops.dtor (b);
7152 insert_catch_solib (struct bp_location *ignore)
7158 remove_catch_solib (struct bp_location *ignore)
7164 breakpoint_hit_catch_solib (const struct bp_location *bl,
7165 struct address_space *aspace,
7167 const struct target_waitstatus *ws)
7169 struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner;
7170 struct breakpoint *other;
7172 if (ws->kind == TARGET_WAITKIND_LOADED)
7175 ALL_BREAKPOINTS (other)
7177 struct bp_location *other_bl;
7179 if (other == bl->owner)
7182 if (other->type != bp_shlib_event)
7185 if (self->base.pspace != NULL && other->pspace != self->base.pspace)
7188 for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next)
7190 if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws))
7199 check_status_catch_solib (struct bpstats *bs)
7201 struct solib_catchpoint *self
7202 = (struct solib_catchpoint *) bs->breakpoint_at;
7207 struct so_list *iter;
7210 VEC_iterate (so_list_ptr, current_program_space->added_solibs,
7215 || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0)
7224 VEC_iterate (char_ptr, current_program_space->deleted_solibs,
7229 || regexec (&self->compiled, iter, 0, NULL, 0) == 0)
7235 bs->print_it = print_it_noop;
7238 static enum print_stop_action
7239 print_it_catch_solib (bpstat bs)
7241 struct breakpoint *b = bs->breakpoint_at;
7242 struct ui_out *uiout = current_uiout;
7244 annotate_catchpoint (b->number);
7245 if (b->disposition == disp_del)
7246 ui_out_text (uiout, "\nTemporary catchpoint ");
7248 ui_out_text (uiout, "\nCatchpoint ");
7249 ui_out_field_int (uiout, "bkptno", b->number);
7250 ui_out_text (uiout, "\n");
7251 if (ui_out_is_mi_like_p (uiout))
7252 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7253 print_solib_event (1);
7254 return PRINT_SRC_AND_LOC;
7258 print_one_catch_solib (struct breakpoint *b, struct bp_location **locs)
7260 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
7261 struct value_print_options opts;
7262 struct ui_out *uiout = current_uiout;
7265 get_user_print_options (&opts);
7266 /* Field 4, the address, is omitted (which makes the columns not
7267 line up too nicely with the headers, but the effect is relatively
7269 if (opts.addressprint)
7272 ui_out_field_skip (uiout, "addr");
7279 msg = xstrprintf (_("load of library matching %s"), self->regex);
7281 msg = xstrdup (_("load of library"));
7286 msg = xstrprintf (_("unload of library matching %s"), self->regex);
7288 msg = xstrdup (_("unload of library"));
7290 ui_out_field_string (uiout, "what", msg);
7295 print_mention_catch_solib (struct breakpoint *b)
7297 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
7299 printf_filtered (_("Catchpoint %d (%s)"), b->number,
7300 self->is_load ? "load" : "unload");
7304 print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp)
7306 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
7308 fprintf_unfiltered (fp, "%s %s",
7309 b->disposition == disp_del ? "tcatch" : "catch",
7310 self->is_load ? "load" : "unload");
7312 fprintf_unfiltered (fp, " %s", self->regex);
7313 fprintf_unfiltered (fp, "\n");
7316 static struct breakpoint_ops catch_solib_breakpoint_ops;
7318 /* A helper function that does all the work for "catch load" and
7322 catch_load_or_unload (char *arg, int from_tty, int is_load,
7323 struct cmd_list_element *command)
7325 struct solib_catchpoint *c;
7326 struct gdbarch *gdbarch = get_current_arch ();
7329 struct cleanup *cleanup;
7331 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
7335 arg = skip_spaces (arg);
7337 c = XCNEW (struct solib_catchpoint);
7338 cleanup = make_cleanup (xfree, c);
7344 errcode = regcomp (&c->compiled, arg, REG_NOSUB);
7347 char *err = get_regcomp_error (errcode, &c->compiled);
7349 make_cleanup (xfree, err);
7350 error (_("Invalid regexp (%s): %s"), err, arg);
7352 c->regex = xstrdup (arg);
7355 c->is_load = is_load;
7356 init_catchpoint (&c->base, gdbarch, tempflag, NULL,
7357 &catch_solib_breakpoint_ops);
7359 discard_cleanups (cleanup);
7360 install_breakpoint (0, &c->base, 1);
7364 catch_load_command_1 (char *arg, int from_tty,
7365 struct cmd_list_element *command)
7367 catch_load_or_unload (arg, from_tty, 1, command);
7371 catch_unload_command_1 (char *arg, int from_tty,
7372 struct cmd_list_element *command)
7374 catch_load_or_unload (arg, from_tty, 0, command);
7377 /* An instance of this type is used to represent a syscall catchpoint.
7378 It includes a "struct breakpoint" as a kind of base class; users
7379 downcast to "struct breakpoint *" when needed. A breakpoint is
7380 really of this type iff its ops pointer points to
7381 CATCH_SYSCALL_BREAKPOINT_OPS. */
7383 struct syscall_catchpoint
7385 /* The base class. */
7386 struct breakpoint base;
7388 /* Syscall numbers used for the 'catch syscall' feature. If no
7389 syscall has been specified for filtering, its value is NULL.
7390 Otherwise, it holds a list of all syscalls to be caught. The
7391 list elements are allocated with xmalloc. */
7392 VEC(int) *syscalls_to_be_caught;
7395 /* Implement the "dtor" breakpoint_ops method for syscall
7399 dtor_catch_syscall (struct breakpoint *b)
7401 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
7403 VEC_free (int, c->syscalls_to_be_caught);
7405 base_breakpoint_ops.dtor (b);
7408 /* Implement the "insert" breakpoint_ops method for syscall
7412 insert_catch_syscall (struct bp_location *bl)
7414 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner;
7415 struct inferior *inf = current_inferior ();
7417 ++inf->total_syscalls_count;
7418 if (!c->syscalls_to_be_caught)
7419 ++inf->any_syscall_count;
7425 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
7430 if (iter >= VEC_length (int, inf->syscalls_counts))
7432 int old_size = VEC_length (int, inf->syscalls_counts);
7433 uintptr_t vec_addr_offset
7434 = old_size * ((uintptr_t) sizeof (int));
7436 VEC_safe_grow (int, inf->syscalls_counts, iter + 1);
7437 vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) +
7439 memset ((void *) vec_addr, 0,
7440 (iter + 1 - old_size) * sizeof (int));
7442 elem = VEC_index (int, inf->syscalls_counts, iter);
7443 VEC_replace (int, inf->syscalls_counts, iter, ++elem);
7447 return target_set_syscall_catchpoint (PIDGET (inferior_ptid),
7448 inf->total_syscalls_count != 0,
7449 inf->any_syscall_count,
7450 VEC_length (int, inf->syscalls_counts),
7451 VEC_address (int, inf->syscalls_counts));
7454 /* Implement the "remove" breakpoint_ops method for syscall
7458 remove_catch_syscall (struct bp_location *bl)
7460 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner;
7461 struct inferior *inf = current_inferior ();
7463 --inf->total_syscalls_count;
7464 if (!c->syscalls_to_be_caught)
7465 --inf->any_syscall_count;
7471 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
7475 if (iter >= VEC_length (int, inf->syscalls_counts))
7476 /* Shouldn't happen. */
7478 elem = VEC_index (int, inf->syscalls_counts, iter);
7479 VEC_replace (int, inf->syscalls_counts, iter, --elem);
7483 return target_set_syscall_catchpoint (PIDGET (inferior_ptid),
7484 inf->total_syscalls_count != 0,
7485 inf->any_syscall_count,
7486 VEC_length (int, inf->syscalls_counts),
7488 inf->syscalls_counts));
7491 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
7495 breakpoint_hit_catch_syscall (const struct bp_location *bl,
7496 struct address_space *aspace, CORE_ADDR bp_addr,
7497 const struct target_waitstatus *ws)
7499 /* We must check if we are catching specific syscalls in this
7500 breakpoint. If we are, then we must guarantee that the called
7501 syscall is the same syscall we are catching. */
7502 int syscall_number = 0;
7503 const struct syscall_catchpoint *c
7504 = (const struct syscall_catchpoint *) bl->owner;
7506 if (ws->kind != TARGET_WAITKIND_SYSCALL_ENTRY
7507 && ws->kind != TARGET_WAITKIND_SYSCALL_RETURN)
7510 syscall_number = ws->value.syscall_number;
7512 /* Now, checking if the syscall is the same. */
7513 if (c->syscalls_to_be_caught)
7518 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
7520 if (syscall_number == iter)
7530 /* Implement the "print_it" breakpoint_ops method for syscall
7533 static enum print_stop_action
7534 print_it_catch_syscall (bpstat bs)
7536 struct ui_out *uiout = current_uiout;
7537 struct breakpoint *b = bs->breakpoint_at;
7538 /* These are needed because we want to know in which state a
7539 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
7540 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
7541 must print "called syscall" or "returned from syscall". */
7543 struct target_waitstatus last;
7547 get_last_target_status (&ptid, &last);
7549 get_syscall_by_number (last.value.syscall_number, &s);
7551 annotate_catchpoint (b->number);
7553 if (b->disposition == disp_del)
7554 ui_out_text (uiout, "\nTemporary catchpoint ");
7556 ui_out_text (uiout, "\nCatchpoint ");
7557 if (ui_out_is_mi_like_p (uiout))
7559 ui_out_field_string (uiout, "reason",
7560 async_reason_lookup (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY
7561 ? EXEC_ASYNC_SYSCALL_ENTRY
7562 : EXEC_ASYNC_SYSCALL_RETURN));
7563 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7565 ui_out_field_int (uiout, "bkptno", b->number);
7567 if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY)
7568 ui_out_text (uiout, " (call to syscall ");
7570 ui_out_text (uiout, " (returned from syscall ");
7572 if (s.name == NULL || ui_out_is_mi_like_p (uiout))
7573 ui_out_field_int (uiout, "syscall-number", last.value.syscall_number);
7575 ui_out_field_string (uiout, "syscall-name", s.name);
7577 ui_out_text (uiout, "), ");
7579 return PRINT_SRC_AND_LOC;
7582 /* Implement the "print_one" breakpoint_ops method for syscall
7586 print_one_catch_syscall (struct breakpoint *b,
7587 struct bp_location **last_loc)
7589 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
7590 struct value_print_options opts;
7591 struct ui_out *uiout = current_uiout;
7593 get_user_print_options (&opts);
7594 /* Field 4, the address, is omitted (which makes the columns not
7595 line up too nicely with the headers, but the effect is relatively
7597 if (opts.addressprint)
7598 ui_out_field_skip (uiout, "addr");
7601 if (c->syscalls_to_be_caught
7602 && VEC_length (int, c->syscalls_to_be_caught) > 1)
7603 ui_out_text (uiout, "syscalls \"");
7605 ui_out_text (uiout, "syscall \"");
7607 if (c->syscalls_to_be_caught)
7610 char *text = xstrprintf ("%s", "");
7613 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
7618 get_syscall_by_number (iter, &s);
7621 text = xstrprintf ("%s%s, ", text, s.name);
7623 text = xstrprintf ("%s%d, ", text, iter);
7625 /* We have to xfree the last 'text' (now stored at 'x')
7626 because xstrprintf dynamically allocates new space for it
7630 /* Remove the last comma. */
7631 text[strlen (text) - 2] = '\0';
7632 ui_out_field_string (uiout, "what", text);
7635 ui_out_field_string (uiout, "what", "<any syscall>");
7636 ui_out_text (uiout, "\" ");
7639 /* Implement the "print_mention" breakpoint_ops method for syscall
7643 print_mention_catch_syscall (struct breakpoint *b)
7645 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
7647 if (c->syscalls_to_be_caught)
7651 if (VEC_length (int, c->syscalls_to_be_caught) > 1)
7652 printf_filtered (_("Catchpoint %d (syscalls"), b->number);
7654 printf_filtered (_("Catchpoint %d (syscall"), b->number);
7657 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
7661 get_syscall_by_number (iter, &s);
7664 printf_filtered (" '%s' [%d]", s.name, s.number);
7666 printf_filtered (" %d", s.number);
7668 printf_filtered (")");
7671 printf_filtered (_("Catchpoint %d (any syscall)"),
7675 /* Implement the "print_recreate" breakpoint_ops method for syscall
7679 print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp)
7681 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
7683 fprintf_unfiltered (fp, "catch syscall");
7685 if (c->syscalls_to_be_caught)
7690 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
7695 get_syscall_by_number (iter, &s);
7697 fprintf_unfiltered (fp, " %s", s.name);
7699 fprintf_unfiltered (fp, " %d", s.number);
7702 print_recreate_thread (b, fp);
7705 /* The breakpoint_ops structure to be used in syscall catchpoints. */
7707 static struct breakpoint_ops catch_syscall_breakpoint_ops;
7709 /* Returns non-zero if 'b' is a syscall catchpoint. */
7712 syscall_catchpoint_p (struct breakpoint *b)
7714 return (b->ops == &catch_syscall_breakpoint_ops);
7717 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
7718 is non-zero, then make the breakpoint temporary. If COND_STRING is
7719 not NULL, then store it in the breakpoint. OPS, if not NULL, is
7720 the breakpoint_ops structure associated to the catchpoint. */
7723 init_catchpoint (struct breakpoint *b,
7724 struct gdbarch *gdbarch, int tempflag,
7726 const struct breakpoint_ops *ops)
7728 struct symtab_and_line sal;
7731 sal.pspace = current_program_space;
7733 init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops);
7735 b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string);
7736 b->disposition = tempflag ? disp_del : disp_donttouch;
7740 install_breakpoint (int internal, struct breakpoint *b, int update_gll)
7742 add_to_breakpoint_chain (b);
7743 set_breakpoint_number (internal, b);
7746 observer_notify_breakpoint_created (b);
7749 update_global_location_list (1);
7753 create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch,
7754 int tempflag, char *cond_string,
7755 const struct breakpoint_ops *ops)
7757 struct fork_catchpoint *c = XNEW (struct fork_catchpoint);
7759 init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops);
7761 c->forked_inferior_pid = null_ptid;
7763 install_breakpoint (0, &c->base, 1);
7766 /* Exec catchpoints. */
7768 /* An instance of this type is used to represent an exec catchpoint.
7769 It includes a "struct breakpoint" as a kind of base class; users
7770 downcast to "struct breakpoint *" when needed. A breakpoint is
7771 really of this type iff its ops pointer points to
7772 CATCH_EXEC_BREAKPOINT_OPS. */
7774 struct exec_catchpoint
7776 /* The base class. */
7777 struct breakpoint base;
7779 /* Filename of a program whose exec triggered this catchpoint.
7780 This field is only valid immediately after this catchpoint has
7782 char *exec_pathname;
7785 /* Implement the "dtor" breakpoint_ops method for exec
7789 dtor_catch_exec (struct breakpoint *b)
7791 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
7793 xfree (c->exec_pathname);
7795 base_breakpoint_ops.dtor (b);
7799 insert_catch_exec (struct bp_location *bl)
7801 return target_insert_exec_catchpoint (PIDGET (inferior_ptid));
7805 remove_catch_exec (struct bp_location *bl)
7807 return target_remove_exec_catchpoint (PIDGET (inferior_ptid));
7811 breakpoint_hit_catch_exec (const struct bp_location *bl,
7812 struct address_space *aspace, CORE_ADDR bp_addr,
7813 const struct target_waitstatus *ws)
7815 struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner;
7817 if (ws->kind != TARGET_WAITKIND_EXECD)
7820 c->exec_pathname = xstrdup (ws->value.execd_pathname);
7824 static enum print_stop_action
7825 print_it_catch_exec (bpstat bs)
7827 struct ui_out *uiout = current_uiout;
7828 struct breakpoint *b = bs->breakpoint_at;
7829 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
7831 annotate_catchpoint (b->number);
7832 if (b->disposition == disp_del)
7833 ui_out_text (uiout, "\nTemporary catchpoint ");
7835 ui_out_text (uiout, "\nCatchpoint ");
7836 if (ui_out_is_mi_like_p (uiout))
7838 ui_out_field_string (uiout, "reason",
7839 async_reason_lookup (EXEC_ASYNC_EXEC));
7840 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7842 ui_out_field_int (uiout, "bkptno", b->number);
7843 ui_out_text (uiout, " (exec'd ");
7844 ui_out_field_string (uiout, "new-exec", c->exec_pathname);
7845 ui_out_text (uiout, "), ");
7847 return PRINT_SRC_AND_LOC;
7851 print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc)
7853 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
7854 struct value_print_options opts;
7855 struct ui_out *uiout = current_uiout;
7857 get_user_print_options (&opts);
7859 /* Field 4, the address, is omitted (which makes the columns
7860 not line up too nicely with the headers, but the effect
7861 is relatively readable). */
7862 if (opts.addressprint)
7863 ui_out_field_skip (uiout, "addr");
7865 ui_out_text (uiout, "exec");
7866 if (c->exec_pathname != NULL)
7868 ui_out_text (uiout, ", program \"");
7869 ui_out_field_string (uiout, "what", c->exec_pathname);
7870 ui_out_text (uiout, "\" ");
7875 print_mention_catch_exec (struct breakpoint *b)
7877 printf_filtered (_("Catchpoint %d (exec)"), b->number);
7880 /* Implement the "print_recreate" breakpoint_ops method for exec
7884 print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp)
7886 fprintf_unfiltered (fp, "catch exec");
7887 print_recreate_thread (b, fp);
7890 static struct breakpoint_ops catch_exec_breakpoint_ops;
7893 create_syscall_event_catchpoint (int tempflag, VEC(int) *filter,
7894 const struct breakpoint_ops *ops)
7896 struct syscall_catchpoint *c;
7897 struct gdbarch *gdbarch = get_current_arch ();
7899 c = XNEW (struct syscall_catchpoint);
7900 init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops);
7901 c->syscalls_to_be_caught = filter;
7903 install_breakpoint (0, &c->base, 1);
7907 hw_breakpoint_used_count (void)
7910 struct breakpoint *b;
7911 struct bp_location *bl;
7915 if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b))
7916 for (bl = b->loc; bl; bl = bl->next)
7918 /* Special types of hardware breakpoints may use more than
7920 i += b->ops->resources_needed (bl);
7927 /* Returns the resources B would use if it were a hardware
7931 hw_watchpoint_use_count (struct breakpoint *b)
7934 struct bp_location *bl;
7936 if (!breakpoint_enabled (b))
7939 for (bl = b->loc; bl; bl = bl->next)
7941 /* Special types of hardware watchpoints may use more than
7943 i += b->ops->resources_needed (bl);
7949 /* Returns the sum the used resources of all hardware watchpoints of
7950 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
7951 the sum of the used resources of all hardware watchpoints of other
7952 types _not_ TYPE. */
7955 hw_watchpoint_used_count_others (struct breakpoint *except,
7956 enum bptype type, int *other_type_used)
7959 struct breakpoint *b;
7961 *other_type_used = 0;
7966 if (!breakpoint_enabled (b))
7969 if (b->type == type)
7970 i += hw_watchpoint_use_count (b);
7971 else if (is_hardware_watchpoint (b))
7972 *other_type_used = 1;
7979 disable_watchpoints_before_interactive_call_start (void)
7981 struct breakpoint *b;
7985 if (is_watchpoint (b) && breakpoint_enabled (b))
7987 b->enable_state = bp_call_disabled;
7988 update_global_location_list (0);
7994 enable_watchpoints_after_interactive_call_stop (void)
7996 struct breakpoint *b;
8000 if (is_watchpoint (b) && b->enable_state == bp_call_disabled)
8002 b->enable_state = bp_enabled;
8003 update_global_location_list (1);
8009 disable_breakpoints_before_startup (void)
8011 current_program_space->executing_startup = 1;
8012 update_global_location_list (0);
8016 enable_breakpoints_after_startup (void)
8018 current_program_space->executing_startup = 0;
8019 breakpoint_re_set ();
8023 /* Set a breakpoint that will evaporate an end of command
8024 at address specified by SAL.
8025 Restrict it to frame FRAME if FRAME is nonzero. */
8028 set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal,
8029 struct frame_id frame_id, enum bptype type)
8031 struct breakpoint *b;
8033 /* If FRAME_ID is valid, it should be a real frame, not an inlined
8035 gdb_assert (!frame_id_inlined_p (frame_id));
8037 b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops);
8038 b->enable_state = bp_enabled;
8039 b->disposition = disp_donttouch;
8040 b->frame_id = frame_id;
8042 /* If we're debugging a multi-threaded program, then we want
8043 momentary breakpoints to be active in only a single thread of
8045 if (in_thread_list (inferior_ptid))
8046 b->thread = pid_to_thread_id (inferior_ptid);
8048 update_global_location_list_nothrow (1);
8053 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8054 The new breakpoint will have type TYPE, and use OPS as it
8057 static struct breakpoint *
8058 momentary_breakpoint_from_master (struct breakpoint *orig,
8060 const struct breakpoint_ops *ops)
8062 struct breakpoint *copy;
8064 copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops);
8065 copy->loc = allocate_bp_location (copy);
8066 set_breakpoint_location_function (copy->loc, 1);
8068 copy->loc->gdbarch = orig->loc->gdbarch;
8069 copy->loc->requested_address = orig->loc->requested_address;
8070 copy->loc->address = orig->loc->address;
8071 copy->loc->section = orig->loc->section;
8072 copy->loc->pspace = orig->loc->pspace;
8074 if (orig->loc->source_file != NULL)
8075 copy->loc->source_file = xstrdup (orig->loc->source_file);
8077 copy->loc->line_number = orig->loc->line_number;
8078 copy->frame_id = orig->frame_id;
8079 copy->thread = orig->thread;
8080 copy->pspace = orig->pspace;
8082 copy->enable_state = bp_enabled;
8083 copy->disposition = disp_donttouch;
8084 copy->number = internal_breakpoint_number--;
8086 update_global_location_list_nothrow (0);
8090 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8094 clone_momentary_breakpoint (struct breakpoint *orig)
8096 /* If there's nothing to clone, then return nothing. */
8100 return momentary_breakpoint_from_master (orig, orig->type, orig->ops);
8104 set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc,
8107 struct symtab_and_line sal;
8109 sal = find_pc_line (pc, 0);
8111 sal.section = find_pc_overlay (pc);
8112 sal.explicit_pc = 1;
8114 return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type);
8118 /* Tell the user we have just set a breakpoint B. */
8121 mention (struct breakpoint *b)
8123 b->ops->print_mention (b);
8124 if (ui_out_is_mi_like_p (current_uiout))
8126 printf_filtered ("\n");
8130 static struct bp_location *
8131 add_location_to_breakpoint (struct breakpoint *b,
8132 const struct symtab_and_line *sal)
8134 struct bp_location *loc, **tmp;
8135 CORE_ADDR adjusted_address;
8136 struct gdbarch *loc_gdbarch = get_sal_arch (*sal);
8138 if (loc_gdbarch == NULL)
8139 loc_gdbarch = b->gdbarch;
8141 /* Adjust the breakpoint's address prior to allocating a location.
8142 Once we call allocate_bp_location(), that mostly uninitialized
8143 location will be placed on the location chain. Adjustment of the
8144 breakpoint may cause target_read_memory() to be called and we do
8145 not want its scan of the location chain to find a breakpoint and
8146 location that's only been partially initialized. */
8147 adjusted_address = adjust_breakpoint_address (loc_gdbarch,
8150 loc = allocate_bp_location (b);
8151 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
8155 loc->requested_address = sal->pc;
8156 loc->address = adjusted_address;
8157 loc->pspace = sal->pspace;
8158 gdb_assert (loc->pspace != NULL);
8159 loc->section = sal->section;
8160 loc->gdbarch = loc_gdbarch;
8162 if (sal->symtab != NULL)
8163 loc->source_file = xstrdup (sal->symtab->filename);
8164 loc->line_number = sal->line;
8166 set_breakpoint_location_function (loc,
8167 sal->explicit_pc || sal->explicit_line);
8172 /* Return 1 if LOC is pointing to a permanent breakpoint,
8173 return 0 otherwise. */
8176 bp_loc_is_permanent (struct bp_location *loc)
8180 const gdb_byte *bpoint;
8181 gdb_byte *target_mem;
8182 struct cleanup *cleanup;
8185 gdb_assert (loc != NULL);
8187 addr = loc->address;
8188 bpoint = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len);
8190 /* Software breakpoints unsupported? */
8194 target_mem = alloca (len);
8196 /* Enable the automatic memory restoration from breakpoints while
8197 we read the memory. Otherwise we could say about our temporary
8198 breakpoints they are permanent. */
8199 cleanup = save_current_space_and_thread ();
8201 switch_to_program_space_and_thread (loc->pspace);
8202 make_show_memory_breakpoints_cleanup (0);
8204 if (target_read_memory (loc->address, target_mem, len) == 0
8205 && memcmp (target_mem, bpoint, len) == 0)
8208 do_cleanups (cleanup);
8215 /* Create a breakpoint with SAL as location. Use ADDR_STRING
8216 as textual description of the location, and COND_STRING
8217 as condition expression. */
8220 init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch,
8221 struct symtabs_and_lines sals, char *addr_string,
8222 char *filter, char *cond_string,
8223 enum bptype type, enum bpdisp disposition,
8224 int thread, int task, int ignore_count,
8225 const struct breakpoint_ops *ops, int from_tty,
8226 int enabled, int internal, int display_canonical)
8230 if (type == bp_hardware_breakpoint)
8232 int target_resources_ok;
8234 i = hw_breakpoint_used_count ();
8235 target_resources_ok =
8236 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
8238 if (target_resources_ok == 0)
8239 error (_("No hardware breakpoint support in the target."));
8240 else if (target_resources_ok < 0)
8241 error (_("Hardware breakpoints used exceeds limit."));
8244 gdb_assert (sals.nelts > 0);
8246 for (i = 0; i < sals.nelts; ++i)
8248 struct symtab_and_line sal = sals.sals[i];
8249 struct bp_location *loc;
8253 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
8255 loc_gdbarch = gdbarch;
8257 describe_other_breakpoints (loc_gdbarch,
8258 sal.pspace, sal.pc, sal.section, thread);
8263 init_raw_breakpoint (b, gdbarch, sal, type, ops);
8267 b->cond_string = cond_string;
8268 b->ignore_count = ignore_count;
8269 b->enable_state = enabled ? bp_enabled : bp_disabled;
8270 b->disposition = disposition;
8272 if (type == bp_static_tracepoint)
8274 struct tracepoint *t = (struct tracepoint *) b;
8275 struct static_tracepoint_marker marker;
8277 if (strace_marker_p (b))
8279 /* We already know the marker exists, otherwise, we
8280 wouldn't see a sal for it. */
8281 char *p = &addr_string[3];
8285 p = skip_spaces (p);
8287 endp = skip_to_space (p);
8289 marker_str = savestring (p, endp - p);
8290 t->static_trace_marker_id = marker_str;
8292 printf_filtered (_("Probed static tracepoint "
8294 t->static_trace_marker_id);
8296 else if (target_static_tracepoint_marker_at (sal.pc, &marker))
8298 t->static_trace_marker_id = xstrdup (marker.str_id);
8299 release_static_tracepoint_marker (&marker);
8301 printf_filtered (_("Probed static tracepoint "
8303 t->static_trace_marker_id);
8306 warning (_("Couldn't determine the static "
8307 "tracepoint marker to probe"));
8314 loc = add_location_to_breakpoint (b, &sal);
8317 if (bp_loc_is_permanent (loc))
8318 make_breakpoint_permanent (b);
8322 char *arg = b->cond_string;
8323 loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0);
8325 error (_("Garbage %s follows condition"), arg);
8329 b->display_canonical = display_canonical;
8331 b->addr_string = addr_string;
8333 /* addr_string has to be used or breakpoint_re_set will delete
8336 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
8341 create_breakpoint_sal (struct gdbarch *gdbarch,
8342 struct symtabs_and_lines sals, char *addr_string,
8343 char *filter, char *cond_string,
8344 enum bptype type, enum bpdisp disposition,
8345 int thread, int task, int ignore_count,
8346 const struct breakpoint_ops *ops, int from_tty,
8347 int enabled, int internal, int display_canonical)
8349 struct breakpoint *b;
8350 struct cleanup *old_chain;
8352 if (is_tracepoint_type (type))
8354 struct tracepoint *t;
8356 t = XCNEW (struct tracepoint);
8360 b = XNEW (struct breakpoint);
8362 old_chain = make_cleanup (xfree, b);
8364 init_breakpoint_sal (b, gdbarch,
8366 filter, cond_string,
8368 thread, task, ignore_count,
8370 enabled, internal, display_canonical);
8371 discard_cleanups (old_chain);
8373 install_breakpoint (internal, b, 0);
8376 /* Add SALS.nelts breakpoints to the breakpoint table. For each
8377 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
8378 value. COND_STRING, if not NULL, specified the condition to be
8379 used for all breakpoints. Essentially the only case where
8380 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
8381 function. In that case, it's still not possible to specify
8382 separate conditions for different overloaded functions, so
8383 we take just a single condition string.
8385 NOTE: If the function succeeds, the caller is expected to cleanup
8386 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
8387 array contents). If the function fails (error() is called), the
8388 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
8389 COND and SALS arrays and each of those arrays contents. */
8392 create_breakpoints_sal (struct gdbarch *gdbarch,
8393 struct linespec_result *canonical,
8395 enum bptype type, enum bpdisp disposition,
8396 int thread, int task, int ignore_count,
8397 const struct breakpoint_ops *ops, int from_tty,
8398 int enabled, int internal)
8401 struct linespec_sals *lsal;
8403 if (canonical->pre_expanded)
8404 gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1);
8406 for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i)
8408 /* Note that 'addr_string' can be NULL in the case of a plain
8409 'break', without arguments. */
8410 char *addr_string = (canonical->addr_string
8411 ? xstrdup (canonical->addr_string)
8413 char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL;
8414 struct cleanup *inner = make_cleanup (xfree, addr_string);
8416 make_cleanup (xfree, filter_string);
8417 create_breakpoint_sal (gdbarch, lsal->sals,
8420 cond_string, type, disposition,
8421 thread, task, ignore_count, ops,
8422 from_tty, enabled, internal,
8423 canonical->special_display);
8424 discard_cleanups (inner);
8428 /* Parse ADDRESS which is assumed to be a SAL specification possibly
8429 followed by conditionals. On return, SALS contains an array of SAL
8430 addresses found. ADDR_STRING contains a vector of (canonical)
8431 address strings. ADDRESS points to the end of the SAL.
8433 The array and the line spec strings are allocated on the heap, it is
8434 the caller's responsibility to free them. */
8437 parse_breakpoint_sals (char **address,
8438 struct linespec_result *canonical)
8440 char *addr_start = *address;
8442 /* If no arg given, or if first arg is 'if ', use the default
8444 if ((*address) == NULL
8445 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
8447 /* The last displayed codepoint, if it's valid, is our default breakpoint
8449 if (last_displayed_sal_is_valid ())
8451 struct linespec_sals lsal;
8452 struct symtab_and_line sal;
8454 init_sal (&sal); /* Initialize to zeroes. */
8455 lsal.sals.sals = (struct symtab_and_line *)
8456 xmalloc (sizeof (struct symtab_and_line));
8458 /* Set sal's pspace, pc, symtab, and line to the values
8459 corresponding to the last call to print_frame_info. */
8460 get_last_displayed_sal (&sal);
8461 sal.section = find_pc_overlay (sal.pc);
8463 /* "break" without arguments is equivalent to "break *PC"
8464 where PC is the last displayed codepoint's address. So
8465 make sure to set sal.explicit_pc to prevent GDB from
8466 trying to expand the list of sals to include all other
8467 instances with the same symtab and line. */
8468 sal.explicit_pc = 1;
8470 lsal.sals.sals[0] = sal;
8471 lsal.sals.nelts = 1;
8472 lsal.canonical = NULL;
8474 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
8477 error (_("No default breakpoint address now."));
8481 /* Force almost all breakpoints to be in terms of the
8482 current_source_symtab (which is decode_line_1's default).
8483 This should produce the results we want almost all of the
8484 time while leaving default_breakpoint_* alone. */
8485 if (last_displayed_sal_is_valid ())
8486 decode_line_full (address, DECODE_LINE_FUNFIRSTLINE,
8487 get_last_displayed_symtab (),
8488 get_last_displayed_line (),
8489 canonical, NULL, NULL);
8491 decode_line_full (address, DECODE_LINE_FUNFIRSTLINE,
8492 (struct symtab *) NULL, 0,
8493 canonical, NULL, NULL);
8498 /* Convert each SAL into a real PC. Verify that the PC can be
8499 inserted as a breakpoint. If it can't throw an error. */
8502 breakpoint_sals_to_pc (struct symtabs_and_lines *sals)
8506 for (i = 0; i < sals->nelts; i++)
8507 resolve_sal_pc (&sals->sals[i]);
8510 /* Fast tracepoints may have restrictions on valid locations. For
8511 instance, a fast tracepoint using a jump instead of a trap will
8512 likely have to overwrite more bytes than a trap would, and so can
8513 only be placed where the instruction is longer than the jump, or a
8514 multi-instruction sequence does not have a jump into the middle of
8518 check_fast_tracepoint_sals (struct gdbarch *gdbarch,
8519 struct symtabs_and_lines *sals)
8522 struct symtab_and_line *sal;
8524 struct cleanup *old_chain;
8526 for (i = 0; i < sals->nelts; i++)
8528 struct gdbarch *sarch;
8530 sal = &sals->sals[i];
8532 sarch = get_sal_arch (*sal);
8533 /* We fall back to GDBARCH if there is no architecture
8534 associated with SAL. */
8537 rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc,
8539 old_chain = make_cleanup (xfree, msg);
8542 error (_("May not have a fast tracepoint at 0x%s%s"),
8543 paddress (sarch, sal->pc), (msg ? msg : ""));
8545 do_cleanups (old_chain);
8549 /* Given TOK, a string specification of condition and thread, as
8550 accepted by the 'break' command, extract the condition
8551 string and thread number and set *COND_STRING and *THREAD.
8552 PC identifies the context at which the condition should be parsed.
8553 If no condition is found, *COND_STRING is set to NULL.
8554 If no thread is found, *THREAD is set to -1. */
8556 find_condition_and_thread (char *tok, CORE_ADDR pc,
8557 char **cond_string, int *thread, int *task)
8559 *cond_string = NULL;
8565 char *cond_start = NULL;
8566 char *cond_end = NULL;
8568 tok = skip_spaces (tok);
8570 end_tok = skip_to_space (tok);
8572 toklen = end_tok - tok;
8574 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
8576 struct expression *expr;
8578 tok = cond_start = end_tok + 1;
8579 expr = parse_exp_1 (&tok, block_for_pc (pc), 0);
8582 *cond_string = savestring (cond_start,
8583 cond_end - cond_start);
8585 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
8591 *thread = strtol (tok, &tok, 0);
8593 error (_("Junk after thread keyword."));
8594 if (!valid_thread_id (*thread))
8595 error (_("Unknown thread %d."), *thread);
8597 else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0)
8603 *task = strtol (tok, &tok, 0);
8605 error (_("Junk after task keyword."));
8606 if (!valid_task_id (*task))
8607 error (_("Unknown task %d."), *task);
8610 error (_("Junk at end of arguments."));
8614 /* Decode a static tracepoint marker spec. */
8616 static struct symtabs_and_lines
8617 decode_static_tracepoint_spec (char **arg_p)
8619 VEC(static_tracepoint_marker_p) *markers = NULL;
8620 struct symtabs_and_lines sals;
8621 struct symtab_and_line sal;
8623 struct cleanup *old_chain;
8624 char *p = &(*arg_p)[3];
8629 p = skip_spaces (p);
8631 endp = skip_to_space (p);
8633 marker_str = savestring (p, endp - p);
8634 old_chain = make_cleanup (xfree, marker_str);
8636 markers = target_static_tracepoint_markers_by_strid (marker_str);
8637 if (VEC_empty(static_tracepoint_marker_p, markers))
8638 error (_("No known static tracepoint marker named %s"), marker_str);
8640 sals.nelts = VEC_length(static_tracepoint_marker_p, markers);
8641 sals.sals = xmalloc (sizeof *sals.sals * sals.nelts);
8643 for (i = 0; i < sals.nelts; i++)
8645 struct static_tracepoint_marker *marker;
8647 marker = VEC_index (static_tracepoint_marker_p, markers, i);
8649 init_sal (&sals.sals[i]);
8651 sals.sals[i] = find_pc_line (marker->address, 0);
8652 sals.sals[i].pc = marker->address;
8654 release_static_tracepoint_marker (marker);
8657 do_cleanups (old_chain);
8663 /* Set a breakpoint. This function is shared between CLI and MI
8664 functions for setting a breakpoint. This function has two major
8665 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
8666 parameter. If non-zero, the function will parse arg, extracting
8667 breakpoint location, address and thread. Otherwise, ARG is just
8668 the location of breakpoint, with condition and thread specified by
8669 the COND_STRING and THREAD parameters. If INTERNAL is non-zero,
8670 the breakpoint number will be allocated from the internal
8671 breakpoint count. Returns true if any breakpoint was created;
8675 create_breakpoint (struct gdbarch *gdbarch,
8676 char *arg, char *cond_string, int thread,
8677 int parse_condition_and_thread,
8678 int tempflag, enum bptype type_wanted,
8680 enum auto_boolean pending_break_support,
8681 const struct breakpoint_ops *ops,
8682 int from_tty, int enabled, int internal)
8684 volatile struct gdb_exception e;
8685 char *copy_arg = NULL;
8686 char *addr_start = arg;
8687 struct linespec_result canonical;
8688 struct cleanup *old_chain;
8689 struct cleanup *bkpt_chain = NULL;
8693 int prev_bkpt_count = breakpoint_count;
8695 gdb_assert (ops != NULL);
8697 init_linespec_result (&canonical);
8699 TRY_CATCH (e, RETURN_MASK_ALL)
8701 ops->create_sals_from_address (&arg, &canonical, type_wanted,
8702 addr_start, ©_arg);
8705 /* If caller is interested in rc value from parse, set value. */
8709 if (VEC_empty (linespec_sals, canonical.sals))
8715 case NOT_FOUND_ERROR:
8717 /* If pending breakpoint support is turned off, throw
8720 if (pending_break_support == AUTO_BOOLEAN_FALSE)
8721 throw_exception (e);
8723 exception_print (gdb_stderr, e);
8725 /* If pending breakpoint support is auto query and the user
8726 selects no, then simply return the error code. */
8727 if (pending_break_support == AUTO_BOOLEAN_AUTO
8728 && !nquery (_("Make %s pending on future shared library load? "),
8729 bptype_string (type_wanted)))
8732 /* At this point, either the user was queried about setting
8733 a pending breakpoint and selected yes, or pending
8734 breakpoint behavior is on and thus a pending breakpoint
8735 is defaulted on behalf of the user. */
8737 struct linespec_sals lsal;
8739 copy_arg = xstrdup (addr_start);
8740 lsal.canonical = xstrdup (copy_arg);
8741 lsal.sals.nelts = 1;
8742 lsal.sals.sals = XNEW (struct symtab_and_line);
8743 init_sal (&lsal.sals.sals[0]);
8745 VEC_safe_push (linespec_sals, canonical.sals, &lsal);
8749 throw_exception (e);
8753 throw_exception (e);
8756 /* Create a chain of things that always need to be cleaned up. */
8757 old_chain = make_cleanup_destroy_linespec_result (&canonical);
8759 /* ----------------------------- SNIP -----------------------------
8760 Anything added to the cleanup chain beyond this point is assumed
8761 to be part of a breakpoint. If the breakpoint create succeeds
8762 then the memory is not reclaimed. */
8763 bkpt_chain = make_cleanup (null_cleanup, 0);
8765 /* Resolve all line numbers to PC's and verify that the addresses
8766 are ok for the target. */
8770 struct linespec_sals *iter;
8772 for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
8773 breakpoint_sals_to_pc (&iter->sals);
8776 /* Fast tracepoints may have additional restrictions on location. */
8777 if (!pending && type_wanted == bp_fast_tracepoint)
8780 struct linespec_sals *iter;
8782 for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
8783 check_fast_tracepoint_sals (gdbarch, &iter->sals);
8786 /* Verify that condition can be parsed, before setting any
8787 breakpoints. Allocate a separate condition expression for each
8791 struct linespec_sals *lsal;
8793 lsal = VEC_index (linespec_sals, canonical.sals, 0);
8795 if (parse_condition_and_thread)
8797 /* Here we only parse 'arg' to separate condition
8798 from thread number, so parsing in context of first
8799 sal is OK. When setting the breakpoint we'll
8800 re-parse it in context of each sal. */
8803 find_condition_and_thread (arg, lsal->sals.sals[0].pc, &cond_string,
8806 make_cleanup (xfree, cond_string);
8810 /* Create a private copy of condition string. */
8813 cond_string = xstrdup (cond_string);
8814 make_cleanup (xfree, cond_string);
8818 ops->create_breakpoints_sal (gdbarch, &canonical, lsal,
8819 cond_string, type_wanted,
8820 tempflag ? disp_del : disp_donttouch,
8821 thread, task, ignore_count, ops,
8822 from_tty, enabled, internal);
8826 struct breakpoint *b;
8828 make_cleanup (xfree, copy_arg);
8830 if (is_tracepoint_type (type_wanted))
8832 struct tracepoint *t;
8834 t = XCNEW (struct tracepoint);
8838 b = XNEW (struct breakpoint);
8840 init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops);
8842 b->addr_string = copy_arg;
8843 b->cond_string = NULL;
8844 b->ignore_count = ignore_count;
8845 b->disposition = tempflag ? disp_del : disp_donttouch;
8846 b->condition_not_parsed = 1;
8847 b->enable_state = enabled ? bp_enabled : bp_disabled;
8848 if ((type_wanted != bp_breakpoint
8849 && type_wanted != bp_hardware_breakpoint) || thread != -1)
8850 b->pspace = current_program_space;
8852 install_breakpoint (internal, b, 0);
8855 if (VEC_length (linespec_sals, canonical.sals) > 1)
8857 warning (_("Multiple breakpoints were set.\nUse the "
8858 "\"delete\" command to delete unwanted breakpoints."));
8859 prev_breakpoint_count = prev_bkpt_count;
8862 /* That's it. Discard the cleanups for data inserted into the
8864 discard_cleanups (bkpt_chain);
8865 /* But cleanup everything else. */
8866 do_cleanups (old_chain);
8868 /* error call may happen here - have BKPT_CHAIN already discarded. */
8869 update_global_location_list (1);
8874 /* Set a breakpoint.
8875 ARG is a string describing breakpoint address,
8876 condition, and thread.
8877 FLAG specifies if a breakpoint is hardware on,
8878 and if breakpoint is temporary, using BP_HARDWARE_FLAG
8882 break_command_1 (char *arg, int flag, int from_tty)
8884 int tempflag = flag & BP_TEMPFLAG;
8885 enum bptype type_wanted = (flag & BP_HARDWAREFLAG
8886 ? bp_hardware_breakpoint
8889 create_breakpoint (get_current_arch (),
8891 NULL, 0, 1 /* parse arg */,
8892 tempflag, type_wanted,
8893 0 /* Ignore count */,
8894 pending_break_support,
8895 &bkpt_breakpoint_ops,
8901 /* Helper function for break_command_1 and disassemble_command. */
8904 resolve_sal_pc (struct symtab_and_line *sal)
8908 if (sal->pc == 0 && sal->symtab != NULL)
8910 if (!find_line_pc (sal->symtab, sal->line, &pc))
8911 error (_("No line %d in file \"%s\"."),
8912 sal->line, sal->symtab->filename);
8915 /* If this SAL corresponds to a breakpoint inserted using a line
8916 number, then skip the function prologue if necessary. */
8917 if (sal->explicit_line)
8918 skip_prologue_sal (sal);
8921 if (sal->section == 0 && sal->symtab != NULL)
8923 struct blockvector *bv;
8927 bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab);
8930 sym = block_linkage_function (b);
8933 fixup_symbol_section (sym, sal->symtab->objfile);
8934 sal->section = SYMBOL_OBJ_SECTION (sym);
8938 /* It really is worthwhile to have the section, so we'll
8939 just have to look harder. This case can be executed
8940 if we have line numbers but no functions (as can
8941 happen in assembly source). */
8943 struct minimal_symbol *msym;
8944 struct cleanup *old_chain = save_current_space_and_thread ();
8946 switch_to_program_space_and_thread (sal->pspace);
8948 msym = lookup_minimal_symbol_by_pc (sal->pc);
8950 sal->section = SYMBOL_OBJ_SECTION (msym);
8952 do_cleanups (old_chain);
8959 break_command (char *arg, int from_tty)
8961 break_command_1 (arg, 0, from_tty);
8965 tbreak_command (char *arg, int from_tty)
8967 break_command_1 (arg, BP_TEMPFLAG, from_tty);
8971 hbreak_command (char *arg, int from_tty)
8973 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
8977 thbreak_command (char *arg, int from_tty)
8979 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
8983 stop_command (char *arg, int from_tty)
8985 printf_filtered (_("Specify the type of breakpoint to set.\n\
8986 Usage: stop in <function | address>\n\
8987 stop at <line>\n"));
8991 stopin_command (char *arg, int from_tty)
8995 if (arg == (char *) NULL)
8997 else if (*arg != '*')
9002 /* Look for a ':'. If this is a line number specification, then
9003 say it is bad, otherwise, it should be an address or
9004 function/method name. */
9005 while (*argptr && !hasColon)
9007 hasColon = (*argptr == ':');
9012 badInput = (*argptr != ':'); /* Not a class::method */
9014 badInput = isdigit (*arg); /* a simple line number */
9018 printf_filtered (_("Usage: stop in <function | address>\n"));
9020 break_command_1 (arg, 0, from_tty);
9024 stopat_command (char *arg, int from_tty)
9028 if (arg == (char *) NULL || *arg == '*') /* no line number */
9035 /* Look for a ':'. If there is a '::' then get out, otherwise
9036 it is probably a line number. */
9037 while (*argptr && !hasColon)
9039 hasColon = (*argptr == ':');
9044 badInput = (*argptr == ':'); /* we have class::method */
9046 badInput = !isdigit (*arg); /* not a line number */
9050 printf_filtered (_("Usage: stop at <line>\n"));
9052 break_command_1 (arg, 0, from_tty);
9055 /* Implement the "breakpoint_hit" breakpoint_ops method for
9056 ranged breakpoints. */
9059 breakpoint_hit_ranged_breakpoint (const struct bp_location *bl,
9060 struct address_space *aspace,
9062 const struct target_waitstatus *ws)
9064 if (ws->kind != TARGET_WAITKIND_STOPPED
9065 || ws->value.sig != TARGET_SIGNAL_TRAP)
9068 return breakpoint_address_match_range (bl->pspace->aspace, bl->address,
9069 bl->length, aspace, bp_addr);
9072 /* Implement the "resources_needed" breakpoint_ops method for
9073 ranged breakpoints. */
9076 resources_needed_ranged_breakpoint (const struct bp_location *bl)
9078 return target_ranged_break_num_registers ();
9081 /* Implement the "print_it" breakpoint_ops method for
9082 ranged breakpoints. */
9084 static enum print_stop_action
9085 print_it_ranged_breakpoint (bpstat bs)
9087 struct breakpoint *b = bs->breakpoint_at;
9088 struct bp_location *bl = b->loc;
9089 struct ui_out *uiout = current_uiout;
9091 gdb_assert (b->type == bp_hardware_breakpoint);
9093 /* Ranged breakpoints have only one location. */
9094 gdb_assert (bl && bl->next == NULL);
9096 annotate_breakpoint (b->number);
9097 if (b->disposition == disp_del)
9098 ui_out_text (uiout, "\nTemporary ranged breakpoint ");
9100 ui_out_text (uiout, "\nRanged breakpoint ");
9101 if (ui_out_is_mi_like_p (uiout))
9103 ui_out_field_string (uiout, "reason",
9104 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
9105 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
9107 ui_out_field_int (uiout, "bkptno", b->number);
9108 ui_out_text (uiout, ", ");
9110 return PRINT_SRC_AND_LOC;
9113 /* Implement the "print_one" breakpoint_ops method for
9114 ranged breakpoints. */
9117 print_one_ranged_breakpoint (struct breakpoint *b,
9118 struct bp_location **last_loc)
9120 struct bp_location *bl = b->loc;
9121 struct value_print_options opts;
9122 struct ui_out *uiout = current_uiout;
9124 /* Ranged breakpoints have only one location. */
9125 gdb_assert (bl && bl->next == NULL);
9127 get_user_print_options (&opts);
9129 if (opts.addressprint)
9130 /* We don't print the address range here, it will be printed later
9131 by print_one_detail_ranged_breakpoint. */
9132 ui_out_field_skip (uiout, "addr");
9134 print_breakpoint_location (b, bl);
9138 /* Implement the "print_one_detail" breakpoint_ops method for
9139 ranged breakpoints. */
9142 print_one_detail_ranged_breakpoint (const struct breakpoint *b,
9143 struct ui_out *uiout)
9145 CORE_ADDR address_start, address_end;
9146 struct bp_location *bl = b->loc;
9147 struct ui_stream *stb = ui_out_stream_new (uiout);
9148 struct cleanup *cleanup = make_cleanup_ui_out_stream_delete (stb);
9152 address_start = bl->address;
9153 address_end = address_start + bl->length - 1;
9155 ui_out_text (uiout, "\taddress range: ");
9156 fprintf_unfiltered (stb->stream, "[%s, %s]",
9157 print_core_address (bl->gdbarch, address_start),
9158 print_core_address (bl->gdbarch, address_end));
9159 ui_out_field_stream (uiout, "addr", stb);
9160 ui_out_text (uiout, "\n");
9162 do_cleanups (cleanup);
9165 /* Implement the "print_mention" breakpoint_ops method for
9166 ranged breakpoints. */
9169 print_mention_ranged_breakpoint (struct breakpoint *b)
9171 struct bp_location *bl = b->loc;
9172 struct ui_out *uiout = current_uiout;
9175 gdb_assert (b->type == bp_hardware_breakpoint);
9177 if (ui_out_is_mi_like_p (uiout))
9180 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
9181 b->number, paddress (bl->gdbarch, bl->address),
9182 paddress (bl->gdbarch, bl->address + bl->length - 1));
9185 /* Implement the "print_recreate" breakpoint_ops method for
9186 ranged breakpoints. */
9189 print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp)
9191 fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string,
9192 b->addr_string_range_end);
9193 print_recreate_thread (b, fp);
9196 /* The breakpoint_ops structure to be used in ranged breakpoints. */
9198 static struct breakpoint_ops ranged_breakpoint_ops;
9200 /* Find the address where the end of the breakpoint range should be
9201 placed, given the SAL of the end of the range. This is so that if
9202 the user provides a line number, the end of the range is set to the
9203 last instruction of the given line. */
9206 find_breakpoint_range_end (struct symtab_and_line sal)
9210 /* If the user provided a PC value, use it. Otherwise,
9211 find the address of the end of the given location. */
9212 if (sal.explicit_pc)
9219 ret = find_line_pc_range (sal, &start, &end);
9221 error (_("Could not find location of the end of the range."));
9223 /* find_line_pc_range returns the start of the next line. */
9230 /* Implement the "break-range" CLI command. */
9233 break_range_command (char *arg, int from_tty)
9235 char *arg_start, *addr_string_start, *addr_string_end;
9236 struct linespec_result canonical_start, canonical_end;
9237 int bp_count, can_use_bp, length;
9239 struct breakpoint *b;
9240 struct symtab_and_line sal_start, sal_end;
9241 struct cleanup *cleanup_bkpt;
9242 struct linespec_sals *lsal_start, *lsal_end;
9244 /* We don't support software ranged breakpoints. */
9245 if (target_ranged_break_num_registers () < 0)
9246 error (_("This target does not support hardware ranged breakpoints."));
9248 bp_count = hw_breakpoint_used_count ();
9249 bp_count += target_ranged_break_num_registers ();
9250 can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
9253 error (_("Hardware breakpoints used exceeds limit."));
9255 arg = skip_spaces (arg);
9256 if (arg == NULL || arg[0] == '\0')
9257 error(_("No address range specified."));
9259 init_linespec_result (&canonical_start);
9262 parse_breakpoint_sals (&arg, &canonical_start);
9264 cleanup_bkpt = make_cleanup_destroy_linespec_result (&canonical_start);
9267 error (_("Too few arguments."));
9268 else if (VEC_empty (linespec_sals, canonical_start.sals))
9269 error (_("Could not find location of the beginning of the range."));
9271 lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0);
9273 if (VEC_length (linespec_sals, canonical_start.sals) > 1
9274 || lsal_start->sals.nelts != 1)
9275 error (_("Cannot create a ranged breakpoint with multiple locations."));
9277 sal_start = lsal_start->sals.sals[0];
9278 addr_string_start = savestring (arg_start, arg - arg_start);
9279 make_cleanup (xfree, addr_string_start);
9281 arg++; /* Skip the comma. */
9282 arg = skip_spaces (arg);
9284 /* Parse the end location. */
9286 init_linespec_result (&canonical_end);
9289 /* We call decode_line_full directly here instead of using
9290 parse_breakpoint_sals because we need to specify the start location's
9291 symtab and line as the default symtab and line for the end of the
9292 range. This makes it possible to have ranges like "foo.c:27, +14",
9293 where +14 means 14 lines from the start location. */
9294 decode_line_full (&arg, DECODE_LINE_FUNFIRSTLINE,
9295 sal_start.symtab, sal_start.line,
9296 &canonical_end, NULL, NULL);
9298 make_cleanup_destroy_linespec_result (&canonical_end);
9300 if (VEC_empty (linespec_sals, canonical_end.sals))
9301 error (_("Could not find location of the end of the range."));
9303 lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0);
9304 if (VEC_length (linespec_sals, canonical_end.sals) > 1
9305 || lsal_end->sals.nelts != 1)
9306 error (_("Cannot create a ranged breakpoint with multiple locations."));
9308 sal_end = lsal_end->sals.sals[0];
9309 addr_string_end = savestring (arg_start, arg - arg_start);
9310 make_cleanup (xfree, addr_string_end);
9312 end = find_breakpoint_range_end (sal_end);
9313 if (sal_start.pc > end)
9314 error (_("Invalid address range, end precedes start."));
9316 length = end - sal_start.pc + 1;
9318 /* Length overflowed. */
9319 error (_("Address range too large."));
9320 else if (length == 1)
9322 /* This range is simple enough to be handled by
9323 the `hbreak' command. */
9324 hbreak_command (addr_string_start, 1);
9326 do_cleanups (cleanup_bkpt);
9331 /* Now set up the breakpoint. */
9332 b = set_raw_breakpoint (get_current_arch (), sal_start,
9333 bp_hardware_breakpoint, &ranged_breakpoint_ops);
9334 set_breakpoint_count (breakpoint_count + 1);
9335 b->number = breakpoint_count;
9336 b->disposition = disp_donttouch;
9337 b->addr_string = xstrdup (addr_string_start);
9338 b->addr_string_range_end = xstrdup (addr_string_end);
9339 b->loc->length = length;
9341 do_cleanups (cleanup_bkpt);
9344 observer_notify_breakpoint_created (b);
9345 update_global_location_list (1);
9348 /* Return non-zero if EXP is verified as constant. Returned zero
9349 means EXP is variable. Also the constant detection may fail for
9350 some constant expressions and in such case still falsely return
9354 watchpoint_exp_is_const (const struct expression *exp)
9362 /* We are only interested in the descriptor of each element. */
9363 operator_length (exp, i, &oplenp, &argsp);
9366 switch (exp->elts[i].opcode)
9376 case BINOP_LOGICAL_AND:
9377 case BINOP_LOGICAL_OR:
9378 case BINOP_BITWISE_AND:
9379 case BINOP_BITWISE_IOR:
9380 case BINOP_BITWISE_XOR:
9382 case BINOP_NOTEQUAL:
9398 case TERNOP_SLICE_COUNT:
9410 case OP_OBJC_NSSTRING:
9413 case UNOP_LOGICAL_NOT:
9414 case UNOP_COMPLEMENT:
9418 /* Unary, binary and ternary operators: We have to check
9419 their operands. If they are constant, then so is the
9420 result of that operation. For instance, if A and B are
9421 determined to be constants, then so is "A + B".
9423 UNOP_IND is one exception to the rule above, because the
9424 value of *ADDR is not necessarily a constant, even when
9429 /* Check whether the associated symbol is a constant.
9431 We use SYMBOL_CLASS rather than TYPE_CONST because it's
9432 possible that a buggy compiler could mark a variable as
9433 constant even when it is not, and TYPE_CONST would return
9434 true in this case, while SYMBOL_CLASS wouldn't.
9436 We also have to check for function symbols because they
9437 are always constant. */
9439 struct symbol *s = exp->elts[i + 2].symbol;
9441 if (SYMBOL_CLASS (s) != LOC_BLOCK
9442 && SYMBOL_CLASS (s) != LOC_CONST
9443 && SYMBOL_CLASS (s) != LOC_CONST_BYTES)
9448 /* The default action is to return 0 because we are using
9449 the optimistic approach here: If we don't know something,
9450 then it is not a constant. */
9459 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
9462 dtor_watchpoint (struct breakpoint *self)
9464 struct watchpoint *w = (struct watchpoint *) self;
9466 xfree (w->cond_exp);
9468 xfree (w->exp_string);
9469 xfree (w->exp_string_reparse);
9470 value_free (w->val);
9472 base_breakpoint_ops.dtor (self);
9475 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
9478 re_set_watchpoint (struct breakpoint *b)
9480 struct watchpoint *w = (struct watchpoint *) b;
9482 /* Watchpoint can be either on expression using entirely global
9483 variables, or it can be on local variables.
9485 Watchpoints of the first kind are never auto-deleted, and even
9486 persist across program restarts. Since they can use variables
9487 from shared libraries, we need to reparse expression as libraries
9488 are loaded and unloaded.
9490 Watchpoints on local variables can also change meaning as result
9491 of solib event. For example, if a watchpoint uses both a local
9492 and a global variables in expression, it's a local watchpoint,
9493 but unloading of a shared library will make the expression
9494 invalid. This is not a very common use case, but we still
9495 re-evaluate expression, to avoid surprises to the user.
9497 Note that for local watchpoints, we re-evaluate it only if
9498 watchpoints frame id is still valid. If it's not, it means the
9499 watchpoint is out of scope and will be deleted soon. In fact,
9500 I'm not sure we'll ever be called in this case.
9502 If a local watchpoint's frame id is still valid, then
9503 w->exp_valid_block is likewise valid, and we can safely use it.
9505 Don't do anything about disabled watchpoints, since they will be
9506 reevaluated again when enabled. */
9507 update_watchpoint (w, 1 /* reparse */);
9510 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
9513 insert_watchpoint (struct bp_location *bl)
9515 struct watchpoint *w = (struct watchpoint *) bl->owner;
9516 int length = w->exact ? 1 : bl->length;
9518 return target_insert_watchpoint (bl->address, length, bl->watchpoint_type,
9522 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
9525 remove_watchpoint (struct bp_location *bl)
9527 struct watchpoint *w = (struct watchpoint *) bl->owner;
9528 int length = w->exact ? 1 : bl->length;
9530 return target_remove_watchpoint (bl->address, length, bl->watchpoint_type,
9535 breakpoint_hit_watchpoint (const struct bp_location *bl,
9536 struct address_space *aspace, CORE_ADDR bp_addr,
9537 const struct target_waitstatus *ws)
9539 struct breakpoint *b = bl->owner;
9540 struct watchpoint *w = (struct watchpoint *) b;
9542 /* Continuable hardware watchpoints are treated as non-existent if the
9543 reason we stopped wasn't a hardware watchpoint (we didn't stop on
9544 some data address). Otherwise gdb won't stop on a break instruction
9545 in the code (not from a breakpoint) when a hardware watchpoint has
9546 been defined. Also skip watchpoints which we know did not trigger
9547 (did not match the data address). */
9548 if (is_hardware_watchpoint (b)
9549 && w->watchpoint_triggered == watch_triggered_no)
9556 check_status_watchpoint (bpstat bs)
9558 gdb_assert (is_watchpoint (bs->breakpoint_at));
9560 bpstat_check_watchpoint (bs);
9563 /* Implement the "resources_needed" breakpoint_ops method for
9564 hardware watchpoints. */
9567 resources_needed_watchpoint (const struct bp_location *bl)
9569 struct watchpoint *w = (struct watchpoint *) bl->owner;
9570 int length = w->exact? 1 : bl->length;
9572 return target_region_ok_for_hw_watchpoint (bl->address, length);
9575 /* Implement the "works_in_software_mode" breakpoint_ops method for
9576 hardware watchpoints. */
9579 works_in_software_mode_watchpoint (const struct breakpoint *b)
9581 /* Read and access watchpoints only work with hardware support. */
9582 return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint;
9585 static enum print_stop_action
9586 print_it_watchpoint (bpstat bs)
9588 struct cleanup *old_chain;
9589 struct breakpoint *b;
9590 const struct bp_location *bl;
9591 struct ui_stream *stb;
9592 enum print_stop_action result;
9593 struct watchpoint *w;
9594 struct ui_out *uiout = current_uiout;
9596 gdb_assert (bs->bp_location_at != NULL);
9598 bl = bs->bp_location_at;
9599 b = bs->breakpoint_at;
9600 w = (struct watchpoint *) b;
9602 stb = ui_out_stream_new (uiout);
9603 old_chain = make_cleanup_ui_out_stream_delete (stb);
9608 case bp_hardware_watchpoint:
9609 annotate_watchpoint (b->number);
9610 if (ui_out_is_mi_like_p (uiout))
9613 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
9615 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
9616 ui_out_text (uiout, "\nOld value = ");
9617 watchpoint_value_print (bs->old_val, stb->stream);
9618 ui_out_field_stream (uiout, "old", stb);
9619 ui_out_text (uiout, "\nNew value = ");
9620 watchpoint_value_print (w->val, stb->stream);
9621 ui_out_field_stream (uiout, "new", stb);
9622 ui_out_text (uiout, "\n");
9623 /* More than one watchpoint may have been triggered. */
9624 result = PRINT_UNKNOWN;
9627 case bp_read_watchpoint:
9628 if (ui_out_is_mi_like_p (uiout))
9631 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
9633 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
9634 ui_out_text (uiout, "\nValue = ");
9635 watchpoint_value_print (w->val, stb->stream);
9636 ui_out_field_stream (uiout, "value", stb);
9637 ui_out_text (uiout, "\n");
9638 result = PRINT_UNKNOWN;
9641 case bp_access_watchpoint:
9642 if (bs->old_val != NULL)
9644 annotate_watchpoint (b->number);
9645 if (ui_out_is_mi_like_p (uiout))
9648 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
9650 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
9651 ui_out_text (uiout, "\nOld value = ");
9652 watchpoint_value_print (bs->old_val, stb->stream);
9653 ui_out_field_stream (uiout, "old", stb);
9654 ui_out_text (uiout, "\nNew value = ");
9659 if (ui_out_is_mi_like_p (uiout))
9662 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
9663 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
9664 ui_out_text (uiout, "\nValue = ");
9666 watchpoint_value_print (w->val, stb->stream);
9667 ui_out_field_stream (uiout, "new", stb);
9668 ui_out_text (uiout, "\n");
9669 result = PRINT_UNKNOWN;
9672 result = PRINT_UNKNOWN;
9675 do_cleanups (old_chain);
9679 /* Implement the "print_mention" breakpoint_ops method for hardware
9683 print_mention_watchpoint (struct breakpoint *b)
9685 struct cleanup *ui_out_chain;
9686 struct watchpoint *w = (struct watchpoint *) b;
9687 struct ui_out *uiout = current_uiout;
9692 ui_out_text (uiout, "Watchpoint ");
9693 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
9695 case bp_hardware_watchpoint:
9696 ui_out_text (uiout, "Hardware watchpoint ");
9697 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
9699 case bp_read_watchpoint:
9700 ui_out_text (uiout, "Hardware read watchpoint ");
9701 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
9703 case bp_access_watchpoint:
9704 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
9705 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
9708 internal_error (__FILE__, __LINE__,
9709 _("Invalid hardware watchpoint type."));
9712 ui_out_field_int (uiout, "number", b->number);
9713 ui_out_text (uiout, ": ");
9714 ui_out_field_string (uiout, "exp", w->exp_string);
9715 do_cleanups (ui_out_chain);
9718 /* Implement the "print_recreate" breakpoint_ops method for
9722 print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp)
9724 struct watchpoint *w = (struct watchpoint *) b;
9729 case bp_hardware_watchpoint:
9730 fprintf_unfiltered (fp, "watch");
9732 case bp_read_watchpoint:
9733 fprintf_unfiltered (fp, "rwatch");
9735 case bp_access_watchpoint:
9736 fprintf_unfiltered (fp, "awatch");
9739 internal_error (__FILE__, __LINE__,
9740 _("Invalid watchpoint type."));
9743 fprintf_unfiltered (fp, " %s", w->exp_string);
9744 print_recreate_thread (b, fp);
9747 /* The breakpoint_ops structure to be used in hardware watchpoints. */
9749 static struct breakpoint_ops watchpoint_breakpoint_ops;
9751 /* Implement the "insert" breakpoint_ops method for
9752 masked hardware watchpoints. */
9755 insert_masked_watchpoint (struct bp_location *bl)
9757 struct watchpoint *w = (struct watchpoint *) bl->owner;
9759 return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask,
9760 bl->watchpoint_type);
9763 /* Implement the "remove" breakpoint_ops method for
9764 masked hardware watchpoints. */
9767 remove_masked_watchpoint (struct bp_location *bl)
9769 struct watchpoint *w = (struct watchpoint *) bl->owner;
9771 return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask,
9772 bl->watchpoint_type);
9775 /* Implement the "resources_needed" breakpoint_ops method for
9776 masked hardware watchpoints. */
9779 resources_needed_masked_watchpoint (const struct bp_location *bl)
9781 struct watchpoint *w = (struct watchpoint *) bl->owner;
9783 return target_masked_watch_num_registers (bl->address, w->hw_wp_mask);
9786 /* Implement the "works_in_software_mode" breakpoint_ops method for
9787 masked hardware watchpoints. */
9790 works_in_software_mode_masked_watchpoint (const struct breakpoint *b)
9795 /* Implement the "print_it" breakpoint_ops method for
9796 masked hardware watchpoints. */
9798 static enum print_stop_action
9799 print_it_masked_watchpoint (bpstat bs)
9801 struct breakpoint *b = bs->breakpoint_at;
9802 struct ui_out *uiout = current_uiout;
9804 /* Masked watchpoints have only one location. */
9805 gdb_assert (b->loc && b->loc->next == NULL);
9809 case bp_hardware_watchpoint:
9810 annotate_watchpoint (b->number);
9811 if (ui_out_is_mi_like_p (uiout))
9814 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
9817 case bp_read_watchpoint:
9818 if (ui_out_is_mi_like_p (uiout))
9821 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
9824 case bp_access_watchpoint:
9825 if (ui_out_is_mi_like_p (uiout))
9828 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
9831 internal_error (__FILE__, __LINE__,
9832 _("Invalid hardware watchpoint type."));
9836 ui_out_text (uiout, _("\n\
9837 Check the underlying instruction at PC for the memory\n\
9838 address and value which triggered this watchpoint.\n"));
9839 ui_out_text (uiout, "\n");
9841 /* More than one watchpoint may have been triggered. */
9842 return PRINT_UNKNOWN;
9845 /* Implement the "print_one_detail" breakpoint_ops method for
9846 masked hardware watchpoints. */
9849 print_one_detail_masked_watchpoint (const struct breakpoint *b,
9850 struct ui_out *uiout)
9852 struct watchpoint *w = (struct watchpoint *) b;
9854 /* Masked watchpoints have only one location. */
9855 gdb_assert (b->loc && b->loc->next == NULL);
9857 ui_out_text (uiout, "\tmask ");
9858 ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask);
9859 ui_out_text (uiout, "\n");
9862 /* Implement the "print_mention" breakpoint_ops method for
9863 masked hardware watchpoints. */
9866 print_mention_masked_watchpoint (struct breakpoint *b)
9868 struct watchpoint *w = (struct watchpoint *) b;
9869 struct ui_out *uiout = current_uiout;
9870 struct cleanup *ui_out_chain;
9874 case bp_hardware_watchpoint:
9875 ui_out_text (uiout, "Masked hardware watchpoint ");
9876 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
9878 case bp_read_watchpoint:
9879 ui_out_text (uiout, "Masked hardware read watchpoint ");
9880 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
9882 case bp_access_watchpoint:
9883 ui_out_text (uiout, "Masked hardware access (read/write) watchpoint ");
9884 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
9887 internal_error (__FILE__, __LINE__,
9888 _("Invalid hardware watchpoint type."));
9891 ui_out_field_int (uiout, "number", b->number);
9892 ui_out_text (uiout, ": ");
9893 ui_out_field_string (uiout, "exp", w->exp_string);
9894 do_cleanups (ui_out_chain);
9897 /* Implement the "print_recreate" breakpoint_ops method for
9898 masked hardware watchpoints. */
9901 print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp)
9903 struct watchpoint *w = (struct watchpoint *) b;
9908 case bp_hardware_watchpoint:
9909 fprintf_unfiltered (fp, "watch");
9911 case bp_read_watchpoint:
9912 fprintf_unfiltered (fp, "rwatch");
9914 case bp_access_watchpoint:
9915 fprintf_unfiltered (fp, "awatch");
9918 internal_error (__FILE__, __LINE__,
9919 _("Invalid hardware watchpoint type."));
9922 sprintf_vma (tmp, w->hw_wp_mask);
9923 fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp);
9924 print_recreate_thread (b, fp);
9927 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
9929 static struct breakpoint_ops masked_watchpoint_breakpoint_ops;
9931 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
9934 is_masked_watchpoint (const struct breakpoint *b)
9936 return b->ops == &masked_watchpoint_breakpoint_ops;
9939 /* accessflag: hw_write: watch write,
9940 hw_read: watch read,
9941 hw_access: watch access (read or write) */
9943 watch_command_1 (char *arg, int accessflag, int from_tty,
9944 int just_location, int internal)
9946 volatile struct gdb_exception e;
9947 struct breakpoint *b, *scope_breakpoint = NULL;
9948 struct expression *exp;
9949 struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL;
9950 struct value *val, *mark, *result;
9951 struct frame_info *frame;
9952 char *exp_start = NULL;
9953 char *exp_end = NULL;
9954 char *tok, *end_tok;
9956 char *cond_start = NULL;
9957 char *cond_end = NULL;
9958 enum bptype bp_type;
9961 /* Flag to indicate whether we are going to use masks for
9962 the hardware watchpoint. */
9965 struct watchpoint *w;
9967 /* Make sure that we actually have parameters to parse. */
9968 if (arg != NULL && arg[0] != '\0')
9972 /* Look for "parameter value" pairs at the end
9973 of the arguments string. */
9974 for (tok = arg + strlen (arg) - 1; tok > arg; tok--)
9976 /* Skip whitespace at the end of the argument list. */
9977 while (tok > arg && (*tok == ' ' || *tok == '\t'))
9980 /* Find the beginning of the last token.
9981 This is the value of the parameter. */
9982 while (tok > arg && (*tok != ' ' && *tok != '\t'))
9984 value_start = tok + 1;
9986 /* Skip whitespace. */
9987 while (tok > arg && (*tok == ' ' || *tok == '\t'))
9992 /* Find the beginning of the second to last token.
9993 This is the parameter itself. */
9994 while (tok > arg && (*tok != ' ' && *tok != '\t'))
9997 toklen = end_tok - tok + 1;
9999 if (toklen == 6 && !strncmp (tok, "thread", 6))
10001 /* At this point we've found a "thread" token, which means
10002 the user is trying to set a watchpoint that triggers
10003 only in a specific thread. */
10007 error(_("You can specify only one thread."));
10009 /* Extract the thread ID from the next token. */
10010 thread = strtol (value_start, &endp, 0);
10012 /* Check if the user provided a valid numeric value for the
10014 if (*endp != ' ' && *endp != '\t' && *endp != '\0')
10015 error (_("Invalid thread ID specification %s."), value_start);
10017 /* Check if the thread actually exists. */
10018 if (!valid_thread_id (thread))
10019 error (_("Unknown thread %d."), thread);
10021 else if (toklen == 4 && !strncmp (tok, "mask", 4))
10023 /* We've found a "mask" token, which means the user wants to
10024 create a hardware watchpoint that is going to have the mask
10026 struct value *mask_value, *mark;
10029 error(_("You can specify only one mask."));
10031 use_mask = just_location = 1;
10033 mark = value_mark ();
10034 mask_value = parse_to_comma_and_eval (&value_start);
10035 mask = value_as_address (mask_value);
10036 value_free_to_mark (mark);
10039 /* We didn't recognize what we found. We should stop here. */
10042 /* Truncate the string and get rid of the "parameter value" pair before
10043 the arguments string is parsed by the parse_exp_1 function. */
10048 /* Parse the rest of the arguments. */
10049 innermost_block = NULL;
10051 exp = parse_exp_1 (&arg, 0, 0);
10053 /* Remove trailing whitespace from the expression before saving it.
10054 This makes the eventual display of the expression string a bit
10056 while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t'))
10059 /* Checking if the expression is not constant. */
10060 if (watchpoint_exp_is_const (exp))
10064 len = exp_end - exp_start;
10065 while (len > 0 && isspace (exp_start[len - 1]))
10067 error (_("Cannot watch constant value `%.*s'."), len, exp_start);
10070 exp_valid_block = innermost_block;
10071 mark = value_mark ();
10072 fetch_subexp_value (exp, &pc, &val, &result, NULL);
10078 exp_valid_block = NULL;
10079 val = value_addr (result);
10080 release_value (val);
10081 value_free_to_mark (mark);
10085 ret = target_masked_watch_num_registers (value_as_address (val),
10088 error (_("This target does not support masked watchpoints."));
10089 else if (ret == -2)
10090 error (_("Invalid mask or memory region."));
10093 else if (val != NULL)
10094 release_value (val);
10096 tok = skip_spaces (arg);
10097 end_tok = skip_to_space (tok);
10099 toklen = end_tok - tok;
10100 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
10102 struct expression *cond;
10104 innermost_block = NULL;
10105 tok = cond_start = end_tok + 1;
10106 cond = parse_exp_1 (&tok, 0, 0);
10108 /* The watchpoint expression may not be local, but the condition
10109 may still be. E.g.: `watch global if local > 0'. */
10110 cond_exp_valid_block = innermost_block;
10116 error (_("Junk at end of command."));
10118 if (accessflag == hw_read)
10119 bp_type = bp_read_watchpoint;
10120 else if (accessflag == hw_access)
10121 bp_type = bp_access_watchpoint;
10123 bp_type = bp_hardware_watchpoint;
10125 frame = block_innermost_frame (exp_valid_block);
10127 /* If the expression is "local", then set up a "watchpoint scope"
10128 breakpoint at the point where we've left the scope of the watchpoint
10129 expression. Create the scope breakpoint before the watchpoint, so
10130 that we will encounter it first in bpstat_stop_status. */
10131 if (exp_valid_block && frame)
10133 if (frame_id_p (frame_unwind_caller_id (frame)))
10136 = create_internal_breakpoint (frame_unwind_caller_arch (frame),
10137 frame_unwind_caller_pc (frame),
10138 bp_watchpoint_scope,
10139 &momentary_breakpoint_ops);
10141 scope_breakpoint->enable_state = bp_enabled;
10143 /* Automatically delete the breakpoint when it hits. */
10144 scope_breakpoint->disposition = disp_del;
10146 /* Only break in the proper frame (help with recursion). */
10147 scope_breakpoint->frame_id = frame_unwind_caller_id (frame);
10149 /* Set the address at which we will stop. */
10150 scope_breakpoint->loc->gdbarch
10151 = frame_unwind_caller_arch (frame);
10152 scope_breakpoint->loc->requested_address
10153 = frame_unwind_caller_pc (frame);
10154 scope_breakpoint->loc->address
10155 = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch,
10156 scope_breakpoint->loc->requested_address,
10157 scope_breakpoint->type);
10161 /* Now set up the breakpoint. */
10163 w = XCNEW (struct watchpoint);
10166 init_raw_breakpoint_without_location (b, NULL, bp_type,
10167 &masked_watchpoint_breakpoint_ops);
10169 init_raw_breakpoint_without_location (b, NULL, bp_type,
10170 &watchpoint_breakpoint_ops);
10171 b->thread = thread;
10172 b->disposition = disp_donttouch;
10173 b->pspace = current_program_space;
10175 w->exp_valid_block = exp_valid_block;
10176 w->cond_exp_valid_block = cond_exp_valid_block;
10179 struct type *t = value_type (val);
10180 CORE_ADDR addr = value_as_address (val);
10183 t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t)));
10184 name = type_to_string (t);
10186 w->exp_string_reparse = xstrprintf ("* (%s *) %s", name,
10187 core_addr_to_string (addr));
10190 w->exp_string = xstrprintf ("-location %.*s",
10191 (int) (exp_end - exp_start), exp_start);
10193 /* The above expression is in C. */
10194 b->language = language_c;
10197 w->exp_string = savestring (exp_start, exp_end - exp_start);
10201 w->hw_wp_mask = mask;
10210 b->cond_string = savestring (cond_start, cond_end - cond_start);
10212 b->cond_string = 0;
10216 w->watchpoint_frame = get_frame_id (frame);
10217 w->watchpoint_thread = inferior_ptid;
10221 w->watchpoint_frame = null_frame_id;
10222 w->watchpoint_thread = null_ptid;
10225 if (scope_breakpoint != NULL)
10227 /* The scope breakpoint is related to the watchpoint. We will
10228 need to act on them together. */
10229 b->related_breakpoint = scope_breakpoint;
10230 scope_breakpoint->related_breakpoint = b;
10233 if (!just_location)
10234 value_free_to_mark (mark);
10236 TRY_CATCH (e, RETURN_MASK_ALL)
10238 /* Finally update the new watchpoint. This creates the locations
10239 that should be inserted. */
10240 update_watchpoint (w, 1);
10244 delete_breakpoint (b);
10245 throw_exception (e);
10248 install_breakpoint (internal, b, 1);
10251 /* Return count of debug registers needed to watch the given expression.
10252 If the watchpoint cannot be handled in hardware return zero. */
10255 can_use_hardware_watchpoint (struct value *v)
10257 int found_memory_cnt = 0;
10258 struct value *head = v;
10260 /* Did the user specifically forbid us to use hardware watchpoints? */
10261 if (!can_use_hw_watchpoints)
10264 /* Make sure that the value of the expression depends only upon
10265 memory contents, and values computed from them within GDB. If we
10266 find any register references or function calls, we can't use a
10267 hardware watchpoint.
10269 The idea here is that evaluating an expression generates a series
10270 of values, one holding the value of every subexpression. (The
10271 expression a*b+c has five subexpressions: a, b, a*b, c, and
10272 a*b+c.) GDB's values hold almost enough information to establish
10273 the criteria given above --- they identify memory lvalues,
10274 register lvalues, computed values, etcetera. So we can evaluate
10275 the expression, and then scan the chain of values that leaves
10276 behind to decide whether we can detect any possible change to the
10277 expression's final value using only hardware watchpoints.
10279 However, I don't think that the values returned by inferior
10280 function calls are special in any way. So this function may not
10281 notice that an expression involving an inferior function call
10282 can't be watched with hardware watchpoints. FIXME. */
10283 for (; v; v = value_next (v))
10285 if (VALUE_LVAL (v) == lval_memory)
10287 if (v != head && value_lazy (v))
10288 /* A lazy memory lvalue in the chain is one that GDB never
10289 needed to fetch; we either just used its address (e.g.,
10290 `a' in `a.b') or we never needed it at all (e.g., `a'
10291 in `a,b'). This doesn't apply to HEAD; if that is
10292 lazy then it was not readable, but watch it anyway. */
10296 /* Ahh, memory we actually used! Check if we can cover
10297 it with hardware watchpoints. */
10298 struct type *vtype = check_typedef (value_type (v));
10300 /* We only watch structs and arrays if user asked for it
10301 explicitly, never if they just happen to appear in a
10302 middle of some value chain. */
10304 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
10305 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
10307 CORE_ADDR vaddr = value_address (v);
10311 len = (target_exact_watchpoints
10312 && is_scalar_type_recursive (vtype))?
10313 1 : TYPE_LENGTH (value_type (v));
10315 num_regs = target_region_ok_for_hw_watchpoint (vaddr, len);
10319 found_memory_cnt += num_regs;
10323 else if (VALUE_LVAL (v) != not_lval
10324 && deprecated_value_modifiable (v) == 0)
10325 return 0; /* These are values from the history (e.g., $1). */
10326 else if (VALUE_LVAL (v) == lval_register)
10327 return 0; /* Cannot watch a register with a HW watchpoint. */
10330 /* The expression itself looks suitable for using a hardware
10331 watchpoint, but give the target machine a chance to reject it. */
10332 return found_memory_cnt;
10336 watch_command_wrapper (char *arg, int from_tty, int internal)
10338 watch_command_1 (arg, hw_write, from_tty, 0, internal);
10341 /* A helper function that looks for an argument at the start of a
10342 string. The argument must also either be at the end of the string,
10343 or be followed by whitespace. Returns 1 if it finds the argument,
10344 0 otherwise. If the argument is found, it updates *STR. */
10347 check_for_argument (char **str, char *arg, int arg_len)
10349 if (strncmp (*str, arg, arg_len) == 0
10350 && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len])))
10358 /* A helper function that looks for the "-location" argument and then
10359 calls watch_command_1. */
10362 watch_maybe_just_location (char *arg, int accessflag, int from_tty)
10364 int just_location = 0;
10367 && (check_for_argument (&arg, "-location", sizeof ("-location") - 1)
10368 || check_for_argument (&arg, "-l", sizeof ("-l") - 1)))
10370 arg = skip_spaces (arg);
10374 watch_command_1 (arg, accessflag, from_tty, just_location, 0);
10378 watch_command (char *arg, int from_tty)
10380 watch_maybe_just_location (arg, hw_write, from_tty);
10384 rwatch_command_wrapper (char *arg, int from_tty, int internal)
10386 watch_command_1 (arg, hw_read, from_tty, 0, internal);
10390 rwatch_command (char *arg, int from_tty)
10392 watch_maybe_just_location (arg, hw_read, from_tty);
10396 awatch_command_wrapper (char *arg, int from_tty, int internal)
10398 watch_command_1 (arg, hw_access, from_tty, 0, internal);
10402 awatch_command (char *arg, int from_tty)
10404 watch_maybe_just_location (arg, hw_access, from_tty);
10408 /* Helper routines for the until_command routine in infcmd.c. Here
10409 because it uses the mechanisms of breakpoints. */
10411 struct until_break_command_continuation_args
10413 struct breakpoint *breakpoint;
10414 struct breakpoint *breakpoint2;
10418 /* This function is called by fetch_inferior_event via the
10419 cmd_continuation pointer, to complete the until command. It takes
10420 care of cleaning up the temporary breakpoints set up by the until
10423 until_break_command_continuation (void *arg, int err)
10425 struct until_break_command_continuation_args *a = arg;
10427 delete_breakpoint (a->breakpoint);
10428 if (a->breakpoint2)
10429 delete_breakpoint (a->breakpoint2);
10430 delete_longjmp_breakpoint (a->thread_num);
10434 until_break_command (char *arg, int from_tty, int anywhere)
10436 struct symtabs_and_lines sals;
10437 struct symtab_and_line sal;
10438 struct frame_info *frame = get_selected_frame (NULL);
10439 struct gdbarch *frame_gdbarch = get_frame_arch (frame);
10440 struct frame_id stack_frame_id = get_stack_frame_id (frame);
10441 struct frame_id caller_frame_id = frame_unwind_caller_id (frame);
10442 struct breakpoint *breakpoint;
10443 struct breakpoint *breakpoint2 = NULL;
10444 struct cleanup *old_chain;
10446 struct thread_info *tp;
10448 clear_proceed_status ();
10450 /* Set a breakpoint where the user wants it and at return from
10453 if (last_displayed_sal_is_valid ())
10454 sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE,
10455 get_last_displayed_symtab (),
10456 get_last_displayed_line ());
10458 sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE,
10459 (struct symtab *) NULL, 0);
10461 if (sals.nelts != 1)
10462 error (_("Couldn't get information on specified line."));
10464 sal = sals.sals[0];
10465 xfree (sals.sals); /* malloc'd, so freed. */
10468 error (_("Junk at end of arguments."));
10470 resolve_sal_pc (&sal);
10472 tp = inferior_thread ();
10475 old_chain = make_cleanup (null_cleanup, NULL);
10477 /* Installing a breakpoint invalidates the frame chain (as it may
10478 need to switch threads), so do any frame handling first. */
10480 /* Keep within the current frame, or in frames called by the current
10483 if (frame_id_p (caller_frame_id))
10485 struct symtab_and_line sal2;
10487 sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0);
10488 sal2.pc = frame_unwind_caller_pc (frame);
10489 breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame),
10493 make_cleanup_delete_breakpoint (breakpoint2);
10495 set_longjmp_breakpoint (tp, caller_frame_id);
10496 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
10499 /* set_momentary_breakpoint could invalidate FRAME. */
10503 /* If the user told us to continue until a specified location,
10504 we don't specify a frame at which we need to stop. */
10505 breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
10506 null_frame_id, bp_until);
10508 /* Otherwise, specify the selected frame, because we want to stop
10509 only at the very same frame. */
10510 breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
10511 stack_frame_id, bp_until);
10512 make_cleanup_delete_breakpoint (breakpoint);
10514 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
10516 /* If we are running asynchronously, and proceed call above has
10517 actually managed to start the target, arrange for breakpoints to
10518 be deleted when the target stops. Otherwise, we're already
10519 stopped and delete breakpoints via cleanup chain. */
10521 if (target_can_async_p () && is_running (inferior_ptid))
10523 struct until_break_command_continuation_args *args;
10524 args = xmalloc (sizeof (*args));
10526 args->breakpoint = breakpoint;
10527 args->breakpoint2 = breakpoint2;
10528 args->thread_num = thread;
10530 discard_cleanups (old_chain);
10531 add_continuation (inferior_thread (),
10532 until_break_command_continuation, args,
10536 do_cleanups (old_chain);
10539 /* This function attempts to parse an optional "if <cond>" clause
10540 from the arg string. If one is not found, it returns NULL.
10542 Else, it returns a pointer to the condition string. (It does not
10543 attempt to evaluate the string against a particular block.) And,
10544 it updates arg to point to the first character following the parsed
10545 if clause in the arg string. */
10548 ep_parse_optional_if_clause (char **arg)
10552 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
10555 /* Skip the "if" keyword. */
10558 /* Skip any extra leading whitespace, and record the start of the
10559 condition string. */
10560 *arg = skip_spaces (*arg);
10561 cond_string = *arg;
10563 /* Assume that the condition occupies the remainder of the arg
10565 (*arg) += strlen (cond_string);
10567 return cond_string;
10570 /* Commands to deal with catching events, such as signals, exceptions,
10571 process start/exit, etc. */
10575 catch_fork_temporary, catch_vfork_temporary,
10576 catch_fork_permanent, catch_vfork_permanent
10581 catch_fork_command_1 (char *arg, int from_tty,
10582 struct cmd_list_element *command)
10584 struct gdbarch *gdbarch = get_current_arch ();
10585 char *cond_string = NULL;
10586 catch_fork_kind fork_kind;
10589 fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command);
10590 tempflag = (fork_kind == catch_fork_temporary
10591 || fork_kind == catch_vfork_temporary);
10595 arg = skip_spaces (arg);
10597 /* The allowed syntax is:
10599 catch [v]fork if <cond>
10601 First, check if there's an if clause. */
10602 cond_string = ep_parse_optional_if_clause (&arg);
10604 if ((*arg != '\0') && !isspace (*arg))
10605 error (_("Junk at end of arguments."));
10607 /* If this target supports it, create a fork or vfork catchpoint
10608 and enable reporting of such events. */
10611 case catch_fork_temporary:
10612 case catch_fork_permanent:
10613 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
10614 &catch_fork_breakpoint_ops);
10616 case catch_vfork_temporary:
10617 case catch_vfork_permanent:
10618 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
10619 &catch_vfork_breakpoint_ops);
10622 error (_("unsupported or unknown fork kind; cannot catch it"));
10628 catch_exec_command_1 (char *arg, int from_tty,
10629 struct cmd_list_element *command)
10631 struct exec_catchpoint *c;
10632 struct gdbarch *gdbarch = get_current_arch ();
10634 char *cond_string = NULL;
10636 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
10640 arg = skip_spaces (arg);
10642 /* The allowed syntax is:
10644 catch exec if <cond>
10646 First, check if there's an if clause. */
10647 cond_string = ep_parse_optional_if_clause (&arg);
10649 if ((*arg != '\0') && !isspace (*arg))
10650 error (_("Junk at end of arguments."));
10652 c = XNEW (struct exec_catchpoint);
10653 init_catchpoint (&c->base, gdbarch, tempflag, cond_string,
10654 &catch_exec_breakpoint_ops);
10655 c->exec_pathname = NULL;
10657 install_breakpoint (0, &c->base, 1);
10660 static enum print_stop_action
10661 print_it_exception_catchpoint (bpstat bs)
10663 struct ui_out *uiout = current_uiout;
10664 struct breakpoint *b = bs->breakpoint_at;
10665 int bp_temp, bp_throw;
10667 annotate_catchpoint (b->number);
10669 bp_throw = strstr (b->addr_string, "throw") != NULL;
10670 if (b->loc->address != b->loc->requested_address)
10671 breakpoint_adjustment_warning (b->loc->requested_address,
10674 bp_temp = b->disposition == disp_del;
10675 ui_out_text (uiout,
10676 bp_temp ? "Temporary catchpoint "
10678 if (!ui_out_is_mi_like_p (uiout))
10679 ui_out_field_int (uiout, "bkptno", b->number);
10680 ui_out_text (uiout,
10681 bp_throw ? " (exception thrown), "
10682 : " (exception caught), ");
10683 if (ui_out_is_mi_like_p (uiout))
10685 ui_out_field_string (uiout, "reason",
10686 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
10687 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
10688 ui_out_field_int (uiout, "bkptno", b->number);
10690 return PRINT_SRC_AND_LOC;
10694 print_one_exception_catchpoint (struct breakpoint *b,
10695 struct bp_location **last_loc)
10697 struct value_print_options opts;
10698 struct ui_out *uiout = current_uiout;
10700 get_user_print_options (&opts);
10701 if (opts.addressprint)
10703 annotate_field (4);
10704 if (b->loc == NULL || b->loc->shlib_disabled)
10705 ui_out_field_string (uiout, "addr", "<PENDING>");
10707 ui_out_field_core_addr (uiout, "addr",
10708 b->loc->gdbarch, b->loc->address);
10710 annotate_field (5);
10712 *last_loc = b->loc;
10713 if (strstr (b->addr_string, "throw") != NULL)
10714 ui_out_field_string (uiout, "what", "exception throw");
10716 ui_out_field_string (uiout, "what", "exception catch");
10720 print_mention_exception_catchpoint (struct breakpoint *b)
10722 struct ui_out *uiout = current_uiout;
10726 bp_temp = b->disposition == disp_del;
10727 bp_throw = strstr (b->addr_string, "throw") != NULL;
10728 ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ")
10729 : _("Catchpoint "));
10730 ui_out_field_int (uiout, "bkptno", b->number);
10731 ui_out_text (uiout, bp_throw ? _(" (throw)")
10735 /* Implement the "print_recreate" breakpoint_ops method for throw and
10736 catch catchpoints. */
10739 print_recreate_exception_catchpoint (struct breakpoint *b,
10740 struct ui_file *fp)
10745 bp_temp = b->disposition == disp_del;
10746 bp_throw = strstr (b->addr_string, "throw") != NULL;
10747 fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch ");
10748 fprintf_unfiltered (fp, bp_throw ? "throw" : "catch");
10749 print_recreate_thread (b, fp);
10752 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops;
10755 handle_gnu_v3_exceptions (int tempflag, char *cond_string,
10756 enum exception_event_kind ex_event, int from_tty)
10758 char *trigger_func_name;
10760 if (ex_event == EX_EVENT_CATCH)
10761 trigger_func_name = "__cxa_begin_catch";
10763 trigger_func_name = "__cxa_throw";
10765 create_breakpoint (get_current_arch (),
10766 trigger_func_name, cond_string, -1,
10767 0 /* condition and thread are valid. */,
10768 tempflag, bp_breakpoint,
10770 AUTO_BOOLEAN_TRUE /* pending */,
10771 &gnu_v3_exception_catchpoint_ops, from_tty,
10778 /* Deal with "catch catch" and "catch throw" commands. */
10781 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
10782 int tempflag, int from_tty)
10784 char *cond_string = NULL;
10788 arg = skip_spaces (arg);
10790 cond_string = ep_parse_optional_if_clause (&arg);
10792 if ((*arg != '\0') && !isspace (*arg))
10793 error (_("Junk at end of arguments."));
10795 if (ex_event != EX_EVENT_THROW
10796 && ex_event != EX_EVENT_CATCH)
10797 error (_("Unsupported or unknown exception event; cannot catch it"));
10799 if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
10802 warning (_("Unsupported with this platform/compiler combination."));
10805 /* Implementation of "catch catch" command. */
10808 catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command)
10810 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
10812 catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty);
10815 /* Implementation of "catch throw" command. */
10818 catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command)
10820 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
10822 catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty);
10826 init_ada_exception_breakpoint (struct breakpoint *b,
10827 struct gdbarch *gdbarch,
10828 struct symtab_and_line sal,
10830 const struct breakpoint_ops *ops,
10836 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
10838 loc_gdbarch = gdbarch;
10840 describe_other_breakpoints (loc_gdbarch,
10841 sal.pspace, sal.pc, sal.section, -1);
10842 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
10843 version for exception catchpoints, because two catchpoints
10844 used for different exception names will use the same address.
10845 In this case, a "breakpoint ... also set at..." warning is
10846 unproductive. Besides, the warning phrasing is also a bit
10847 inappropriate, we should use the word catchpoint, and tell
10848 the user what type of catchpoint it is. The above is good
10849 enough for now, though. */
10852 init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops);
10854 b->enable_state = bp_enabled;
10855 b->disposition = tempflag ? disp_del : disp_donttouch;
10856 b->addr_string = addr_string;
10857 b->language = language_ada;
10860 /* Splits the argument using space as delimiter. Returns an xmalloc'd
10861 filter list, or NULL if no filtering is required. */
10863 catch_syscall_split_args (char *arg)
10865 VEC(int) *result = NULL;
10866 struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result);
10868 while (*arg != '\0')
10870 int i, syscall_number;
10872 char cur_name[128];
10875 /* Skip whitespace. */
10876 while (isspace (*arg))
10879 for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i)
10880 cur_name[i] = arg[i];
10881 cur_name[i] = '\0';
10884 /* Check if the user provided a syscall name or a number. */
10885 syscall_number = (int) strtol (cur_name, &endptr, 0);
10886 if (*endptr == '\0')
10887 get_syscall_by_number (syscall_number, &s);
10890 /* We have a name. Let's check if it's valid and convert it
10892 get_syscall_by_name (cur_name, &s);
10894 if (s.number == UNKNOWN_SYSCALL)
10895 /* Here we have to issue an error instead of a warning,
10896 because GDB cannot do anything useful if there's no
10897 syscall number to be caught. */
10898 error (_("Unknown syscall name '%s'."), cur_name);
10901 /* Ok, it's valid. */
10902 VEC_safe_push (int, result, s.number);
10905 discard_cleanups (cleanup);
10909 /* Implement the "catch syscall" command. */
10912 catch_syscall_command_1 (char *arg, int from_tty,
10913 struct cmd_list_element *command)
10918 struct gdbarch *gdbarch = get_current_arch ();
10920 /* Checking if the feature if supported. */
10921 if (gdbarch_get_syscall_number_p (gdbarch) == 0)
10922 error (_("The feature 'catch syscall' is not supported on \
10923 this architecture yet."));
10925 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
10927 arg = skip_spaces (arg);
10929 /* We need to do this first "dummy" translation in order
10930 to get the syscall XML file loaded or, most important,
10931 to display a warning to the user if there's no XML file
10932 for his/her architecture. */
10933 get_syscall_by_number (0, &s);
10935 /* The allowed syntax is:
10937 catch syscall <name | number> [<name | number> ... <name | number>]
10939 Let's check if there's a syscall name. */
10942 filter = catch_syscall_split_args (arg);
10946 create_syscall_event_catchpoint (tempflag, filter,
10947 &catch_syscall_breakpoint_ops);
10951 catch_command (char *arg, int from_tty)
10953 error (_("Catch requires an event name."));
10958 tcatch_command (char *arg, int from_tty)
10960 error (_("Catch requires an event name."));
10963 /* A qsort comparison function that sorts breakpoints in order. */
10966 compare_breakpoints (const void *a, const void *b)
10968 const breakpoint_p *ba = a;
10969 uintptr_t ua = (uintptr_t) *ba;
10970 const breakpoint_p *bb = b;
10971 uintptr_t ub = (uintptr_t) *bb;
10973 if ((*ba)->number < (*bb)->number)
10975 else if ((*ba)->number > (*bb)->number)
10978 /* Now sort by address, in case we see, e..g, two breakpoints with
10982 return ub > ub ? 1 : 0;
10985 /* Delete breakpoints by address or line. */
10988 clear_command (char *arg, int from_tty)
10990 struct breakpoint *b, *prev;
10991 VEC(breakpoint_p) *found = 0;
10994 struct symtabs_and_lines sals;
10995 struct symtab_and_line sal;
10997 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
11001 sals = decode_line_spec (arg, (DECODE_LINE_FUNFIRSTLINE
11002 | DECODE_LINE_LIST_MODE));
11007 sals.sals = (struct symtab_and_line *)
11008 xmalloc (sizeof (struct symtab_and_line));
11009 make_cleanup (xfree, sals.sals);
11010 init_sal (&sal); /* Initialize to zeroes. */
11012 /* Set sal's line, symtab, pc, and pspace to the values
11013 corresponding to the last call to print_frame_info. If the
11014 codepoint is not valid, this will set all the fields to 0. */
11015 get_last_displayed_sal (&sal);
11016 if (sal.symtab == 0)
11017 error (_("No source file specified."));
11019 sals.sals[0] = sal;
11025 /* We don't call resolve_sal_pc here. That's not as bad as it
11026 seems, because all existing breakpoints typically have both
11027 file/line and pc set. So, if clear is given file/line, we can
11028 match this to existing breakpoint without obtaining pc at all.
11030 We only support clearing given the address explicitly
11031 present in breakpoint table. Say, we've set breakpoint
11032 at file:line. There were several PC values for that file:line,
11033 due to optimization, all in one block.
11035 We've picked one PC value. If "clear" is issued with another
11036 PC corresponding to the same file:line, the breakpoint won't
11037 be cleared. We probably can still clear the breakpoint, but
11038 since the other PC value is never presented to user, user
11039 can only find it by guessing, and it does not seem important
11040 to support that. */
11042 /* For each line spec given, delete bps which correspond to it. Do
11043 it in two passes, solely to preserve the current behavior that
11044 from_tty is forced true if we delete more than one
11048 make_cleanup (VEC_cleanup (breakpoint_p), &found);
11049 for (i = 0; i < sals.nelts; i++)
11051 int is_abs, sal_name_len;
11053 /* If exact pc given, clear bpts at that pc.
11054 If line given (pc == 0), clear all bpts on specified line.
11055 If defaulting, clear all bpts on default line
11058 defaulting sal.pc != 0 tests to do
11063 1 0 <can't happen> */
11065 sal = sals.sals[i];
11066 is_abs = sal.symtab == NULL ? 1 : IS_ABSOLUTE_PATH (sal.symtab->filename);
11067 sal_name_len = is_abs ? 0 : strlen (sal.symtab->filename);
11069 /* Find all matching breakpoints and add them to 'found'. */
11070 ALL_BREAKPOINTS (b)
11073 /* Are we going to delete b? */
11074 if (b->type != bp_none && !is_watchpoint (b))
11076 struct bp_location *loc = b->loc;
11077 for (; loc; loc = loc->next)
11079 /* If the user specified file:line, don't allow a PC
11080 match. This matches historical gdb behavior. */
11081 int pc_match = (!sal.explicit_line
11083 && (loc->pspace == sal.pspace)
11084 && (loc->address == sal.pc)
11085 && (!section_is_overlay (loc->section)
11086 || loc->section == sal.section));
11087 int line_match = 0;
11089 if ((default_match || sal.explicit_line)
11090 && loc->source_file != NULL
11091 && sal.symtab != NULL
11092 && sal.pspace == loc->pspace
11093 && loc->line_number == sal.line)
11095 if (filename_cmp (loc->source_file,
11096 sal.symtab->filename) == 0)
11098 else if (!IS_ABSOLUTE_PATH (sal.symtab->filename)
11099 && compare_filenames_for_search (loc->source_file,
11100 sal.symtab->filename,
11105 if (pc_match || line_match)
11114 VEC_safe_push(breakpoint_p, found, b);
11118 /* Now go thru the 'found' chain and delete them. */
11119 if (VEC_empty(breakpoint_p, found))
11122 error (_("No breakpoint at %s."), arg);
11124 error (_("No breakpoint at this line."));
11127 /* Remove duplicates from the vec. */
11128 qsort (VEC_address (breakpoint_p, found),
11129 VEC_length (breakpoint_p, found),
11130 sizeof (breakpoint_p),
11131 compare_breakpoints);
11132 prev = VEC_index (breakpoint_p, found, 0);
11133 for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix)
11137 VEC_ordered_remove (breakpoint_p, found, ix);
11142 if (VEC_length(breakpoint_p, found) > 1)
11143 from_tty = 1; /* Always report if deleted more than one. */
11146 if (VEC_length(breakpoint_p, found) == 1)
11147 printf_unfiltered (_("Deleted breakpoint "));
11149 printf_unfiltered (_("Deleted breakpoints "));
11151 breakpoints_changed ();
11153 for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++)
11156 printf_unfiltered ("%d ", b->number);
11157 delete_breakpoint (b);
11160 putchar_unfiltered ('\n');
11162 do_cleanups (cleanups);
11165 /* Delete breakpoint in BS if they are `delete' breakpoints and
11166 all breakpoints that are marked for deletion, whether hit or not.
11167 This is called after any breakpoint is hit, or after errors. */
11170 breakpoint_auto_delete (bpstat bs)
11172 struct breakpoint *b, *b_tmp;
11174 for (; bs; bs = bs->next)
11175 if (bs->breakpoint_at
11176 && bs->breakpoint_at->disposition == disp_del
11178 delete_breakpoint (bs->breakpoint_at);
11180 ALL_BREAKPOINTS_SAFE (b, b_tmp)
11182 if (b->disposition == disp_del_at_next_stop)
11183 delete_breakpoint (b);
11187 /* A comparison function for bp_location AP and BP being interfaced to
11188 qsort. Sort elements primarily by their ADDRESS (no matter what
11189 does breakpoint_address_is_meaningful say for its OWNER),
11190 secondarily by ordering first bp_permanent OWNERed elements and
11191 terciarily just ensuring the array is sorted stable way despite
11192 qsort being an unstable algorithm. */
11195 bp_location_compare (const void *ap, const void *bp)
11197 struct bp_location *a = *(void **) ap;
11198 struct bp_location *b = *(void **) bp;
11199 /* A and B come from existing breakpoints having non-NULL OWNER. */
11200 int a_perm = a->owner->enable_state == bp_permanent;
11201 int b_perm = b->owner->enable_state == bp_permanent;
11203 if (a->address != b->address)
11204 return (a->address > b->address) - (a->address < b->address);
11206 /* Sort locations at the same address by their pspace number, keeping
11207 locations of the same inferior (in a multi-inferior environment)
11210 if (a->pspace->num != b->pspace->num)
11211 return ((a->pspace->num > b->pspace->num)
11212 - (a->pspace->num < b->pspace->num));
11214 /* Sort permanent breakpoints first. */
11215 if (a_perm != b_perm)
11216 return (a_perm < b_perm) - (a_perm > b_perm);
11218 /* Make the internal GDB representation stable across GDB runs
11219 where A and B memory inside GDB can differ. Breakpoint locations of
11220 the same type at the same address can be sorted in arbitrary order. */
11222 if (a->owner->number != b->owner->number)
11223 return ((a->owner->number > b->owner->number)
11224 - (a->owner->number < b->owner->number));
11226 return (a > b) - (a < b);
11229 /* Set bp_location_placed_address_before_address_max and
11230 bp_location_shadow_len_after_address_max according to the current
11231 content of the bp_location array. */
11234 bp_location_target_extensions_update (void)
11236 struct bp_location *bl, **blp_tmp;
11238 bp_location_placed_address_before_address_max = 0;
11239 bp_location_shadow_len_after_address_max = 0;
11241 ALL_BP_LOCATIONS (bl, blp_tmp)
11243 CORE_ADDR start, end, addr;
11245 if (!bp_location_has_shadow (bl))
11248 start = bl->target_info.placed_address;
11249 end = start + bl->target_info.shadow_len;
11251 gdb_assert (bl->address >= start);
11252 addr = bl->address - start;
11253 if (addr > bp_location_placed_address_before_address_max)
11254 bp_location_placed_address_before_address_max = addr;
11256 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11258 gdb_assert (bl->address < end);
11259 addr = end - bl->address;
11260 if (addr > bp_location_shadow_len_after_address_max)
11261 bp_location_shadow_len_after_address_max = addr;
11265 /* Download tracepoint locations if they haven't been. */
11268 download_tracepoint_locations (void)
11270 struct bp_location *bl, **blp_tmp;
11271 struct cleanup *old_chain;
11273 if (!target_can_download_tracepoint ())
11276 old_chain = save_current_space_and_thread ();
11278 ALL_BP_LOCATIONS (bl, blp_tmp)
11280 struct tracepoint *t;
11282 if (!is_tracepoint (bl->owner))
11285 if ((bl->owner->type == bp_fast_tracepoint
11286 ? !may_insert_fast_tracepoints
11287 : !may_insert_tracepoints))
11290 /* In tracepoint, locations are _never_ duplicated, so
11291 should_be_inserted is equivalent to
11292 unduplicated_should_be_inserted. */
11293 if (!should_be_inserted (bl) || bl->inserted)
11296 switch_to_program_space_and_thread (bl->pspace);
11298 target_download_tracepoint (bl);
11301 t = (struct tracepoint *) bl->owner;
11302 t->number_on_target = bl->owner->number;
11305 do_cleanups (old_chain);
11308 /* Swap the insertion/duplication state between two locations. */
11311 swap_insertion (struct bp_location *left, struct bp_location *right)
11313 const int left_inserted = left->inserted;
11314 const int left_duplicate = left->duplicate;
11315 const int left_needs_update = left->needs_update;
11316 const struct bp_target_info left_target_info = left->target_info;
11318 /* Locations of tracepoints can never be duplicated. */
11319 if (is_tracepoint (left->owner))
11320 gdb_assert (!left->duplicate);
11321 if (is_tracepoint (right->owner))
11322 gdb_assert (!right->duplicate);
11324 left->inserted = right->inserted;
11325 left->duplicate = right->duplicate;
11326 left->needs_update = right->needs_update;
11327 left->target_info = right->target_info;
11328 right->inserted = left_inserted;
11329 right->duplicate = left_duplicate;
11330 right->needs_update = left_needs_update;
11331 right->target_info = left_target_info;
11334 /* Force the re-insertion of the locations at ADDRESS. This is called
11335 once a new/deleted/modified duplicate location is found and we are evaluating
11336 conditions on the target's side. Such conditions need to be updated on
11340 force_breakpoint_reinsertion (struct bp_location *bl)
11342 struct bp_location **locp = NULL, **loc2p;
11343 struct bp_location *loc;
11344 CORE_ADDR address = 0;
11347 address = bl->address;
11348 pspace_num = bl->pspace->num;
11350 /* This is only meaningful if the target is
11351 evaluating conditions and if the user has
11352 opted for condition evaluation on the target's
11354 if (gdb_evaluates_breakpoint_condition_p ()
11355 || !target_supports_evaluation_of_breakpoint_conditions ())
11358 /* Flag all breakpoint locations with this address and
11359 the same program space as the location
11360 as "its condition has changed". We need to
11361 update the conditions on the target's side. */
11362 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address)
11366 if (!is_breakpoint (loc->owner)
11367 || pspace_num != loc->pspace->num)
11370 /* Flag the location appropriately. We use a different state to
11371 let everyone know that we already updated the set of locations
11372 with addr bl->address and program space bl->pspace. This is so
11373 we don't have to keep calling these functions just to mark locations
11374 that have already been marked. */
11375 loc->condition_changed = condition_updated;
11377 /* Free the agent expression bytecode as well. We will compute
11379 if (loc->cond_bytecode)
11381 free_agent_expr (loc->cond_bytecode);
11382 loc->cond_bytecode = NULL;
11387 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
11388 into the inferior, only remove already-inserted locations that no
11389 longer should be inserted. Functions that delete a breakpoint or
11390 breakpoints should pass false, so that deleting a breakpoint
11391 doesn't have the side effect of inserting the locations of other
11392 breakpoints that are marked not-inserted, but should_be_inserted
11393 returns true on them.
11395 This behaviour is useful is situations close to tear-down -- e.g.,
11396 after an exec, while the target still has execution, but breakpoint
11397 shadows of the previous executable image should *NOT* be restored
11398 to the new image; or before detaching, where the target still has
11399 execution and wants to delete breakpoints from GDB's lists, and all
11400 breakpoints had already been removed from the inferior. */
11403 update_global_location_list (int should_insert)
11405 struct breakpoint *b;
11406 struct bp_location **locp, *loc;
11407 struct cleanup *cleanups;
11408 /* Last breakpoint location address that was marked for update. */
11409 CORE_ADDR last_addr = 0;
11410 /* Last breakpoint location program space that was marked for update. */
11411 int last_pspace_num = -1;
11413 /* Used in the duplicates detection below. When iterating over all
11414 bp_locations, points to the first bp_location of a given address.
11415 Breakpoints and watchpoints of different types are never
11416 duplicates of each other. Keep one pointer for each type of
11417 breakpoint/watchpoint, so we only need to loop over all locations
11419 struct bp_location *bp_loc_first; /* breakpoint */
11420 struct bp_location *wp_loc_first; /* hardware watchpoint */
11421 struct bp_location *awp_loc_first; /* access watchpoint */
11422 struct bp_location *rwp_loc_first; /* read watchpoint */
11424 /* Saved former bp_location array which we compare against the newly
11425 built bp_location from the current state of ALL_BREAKPOINTS. */
11426 struct bp_location **old_location, **old_locp;
11427 unsigned old_location_count;
11429 old_location = bp_location;
11430 old_location_count = bp_location_count;
11431 bp_location = NULL;
11432 bp_location_count = 0;
11433 cleanups = make_cleanup (xfree, old_location);
11435 ALL_BREAKPOINTS (b)
11436 for (loc = b->loc; loc; loc = loc->next)
11437 bp_location_count++;
11439 bp_location = xmalloc (sizeof (*bp_location) * bp_location_count);
11440 locp = bp_location;
11441 ALL_BREAKPOINTS (b)
11442 for (loc = b->loc; loc; loc = loc->next)
11444 qsort (bp_location, bp_location_count, sizeof (*bp_location),
11445 bp_location_compare);
11447 bp_location_target_extensions_update ();
11449 /* Identify bp_location instances that are no longer present in the
11450 new list, and therefore should be freed. Note that it's not
11451 necessary that those locations should be removed from inferior --
11452 if there's another location at the same address (previously
11453 marked as duplicate), we don't need to remove/insert the
11456 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11457 and former bp_location array state respectively. */
11459 locp = bp_location;
11460 for (old_locp = old_location; old_locp < old_location + old_location_count;
11463 struct bp_location *old_loc = *old_locp;
11464 struct bp_location **loc2p;
11466 /* Tells if 'old_loc' is found among the new locations. If
11467 not, we have to free it. */
11468 int found_object = 0;
11469 /* Tells if the location should remain inserted in the target. */
11470 int keep_in_target = 0;
11473 /* Skip LOCP entries which will definitely never be needed.
11474 Stop either at or being the one matching OLD_LOC. */
11475 while (locp < bp_location + bp_location_count
11476 && (*locp)->address < old_loc->address)
11480 (loc2p < bp_location + bp_location_count
11481 && (*loc2p)->address == old_loc->address);
11484 /* Check if this is a new/duplicated location or a duplicated
11485 location that had its condition modified. If so, we want to send
11486 its condition to the target if evaluation of conditions is taking
11488 if ((*loc2p)->condition_changed == condition_modified
11489 && (last_addr != old_loc->address
11490 || last_pspace_num != old_loc->pspace->num))
11492 force_breakpoint_reinsertion (*loc2p);
11493 last_pspace_num = old_loc->pspace->num;
11496 if (*loc2p == old_loc)
11500 /* We have already handled this address, update it so that we don't
11501 have to go through updates again. */
11502 last_addr = old_loc->address;
11504 /* Target-side condition evaluation: Handle deleted locations. */
11506 force_breakpoint_reinsertion (old_loc);
11508 /* If this location is no longer present, and inserted, look if
11509 there's maybe a new location at the same address. If so,
11510 mark that one inserted, and don't remove this one. This is
11511 needed so that we don't have a time window where a breakpoint
11512 at certain location is not inserted. */
11514 if (old_loc->inserted)
11516 /* If the location is inserted now, we might have to remove
11519 if (found_object && should_be_inserted (old_loc))
11521 /* The location is still present in the location list,
11522 and still should be inserted. Don't do anything. */
11523 keep_in_target = 1;
11527 /* This location still exists, but it won't be kept in the
11528 target since it may have been disabled. We proceed to
11529 remove its target-side condition. */
11531 /* The location is either no longer present, or got
11532 disabled. See if there's another location at the
11533 same address, in which case we don't need to remove
11534 this one from the target. */
11536 /* OLD_LOC comes from existing struct breakpoint. */
11537 if (breakpoint_address_is_meaningful (old_loc->owner))
11540 (loc2p < bp_location + bp_location_count
11541 && (*loc2p)->address == old_loc->address);
11544 struct bp_location *loc2 = *loc2p;
11546 if (breakpoint_locations_match (loc2, old_loc))
11548 /* Read watchpoint locations are switched to
11549 access watchpoints, if the former are not
11550 supported, but the latter are. */
11551 if (is_hardware_watchpoint (old_loc->owner))
11553 gdb_assert (is_hardware_watchpoint (loc2->owner));
11554 loc2->watchpoint_type = old_loc->watchpoint_type;
11557 /* loc2 is a duplicated location. We need to check
11558 if it should be inserted in case it will be
11560 if (loc2 != old_loc
11561 && unduplicated_should_be_inserted (loc2))
11563 swap_insertion (old_loc, loc2);
11564 keep_in_target = 1;
11572 if (!keep_in_target)
11574 if (remove_breakpoint (old_loc, mark_uninserted))
11576 /* This is just about all we can do. We could keep
11577 this location on the global list, and try to
11578 remove it next time, but there's no particular
11579 reason why we will succeed next time.
11581 Note that at this point, old_loc->owner is still
11582 valid, as delete_breakpoint frees the breakpoint
11583 only after calling us. */
11584 printf_filtered (_("warning: Error removing "
11585 "breakpoint %d\n"),
11586 old_loc->owner->number);
11594 if (removed && non_stop
11595 && breakpoint_address_is_meaningful (old_loc->owner)
11596 && !is_hardware_watchpoint (old_loc->owner))
11598 /* This location was removed from the target. In
11599 non-stop mode, a race condition is possible where
11600 we've removed a breakpoint, but stop events for that
11601 breakpoint are already queued and will arrive later.
11602 We apply an heuristic to be able to distinguish such
11603 SIGTRAPs from other random SIGTRAPs: we keep this
11604 breakpoint location for a bit, and will retire it
11605 after we see some number of events. The theory here
11606 is that reporting of events should, "on the average",
11607 be fair, so after a while we'll see events from all
11608 threads that have anything of interest, and no longer
11609 need to keep this breakpoint location around. We
11610 don't hold locations forever so to reduce chances of
11611 mistaking a non-breakpoint SIGTRAP for a breakpoint
11614 The heuristic failing can be disastrous on
11615 decr_pc_after_break targets.
11617 On decr_pc_after_break targets, like e.g., x86-linux,
11618 if we fail to recognize a late breakpoint SIGTRAP,
11619 because events_till_retirement has reached 0 too
11620 soon, we'll fail to do the PC adjustment, and report
11621 a random SIGTRAP to the user. When the user resumes
11622 the inferior, it will most likely immediately crash
11623 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
11624 corrupted, because of being resumed e.g., in the
11625 middle of a multi-byte instruction, or skipped a
11626 one-byte instruction. This was actually seen happen
11627 on native x86-linux, and should be less rare on
11628 targets that do not support new thread events, like
11629 remote, due to the heuristic depending on
11632 Mistaking a random SIGTRAP for a breakpoint trap
11633 causes similar symptoms (PC adjustment applied when
11634 it shouldn't), but then again, playing with SIGTRAPs
11635 behind the debugger's back is asking for trouble.
11637 Since hardware watchpoint traps are always
11638 distinguishable from other traps, so we don't need to
11639 apply keep hardware watchpoint moribund locations
11640 around. We simply always ignore hardware watchpoint
11641 traps we can no longer explain. */
11643 old_loc->events_till_retirement = 3 * (thread_count () + 1);
11644 old_loc->owner = NULL;
11646 VEC_safe_push (bp_location_p, moribund_locations, old_loc);
11650 old_loc->owner = NULL;
11651 decref_bp_location (&old_loc);
11656 /* Rescan breakpoints at the same address and section, marking the
11657 first one as "first" and any others as "duplicates". This is so
11658 that the bpt instruction is only inserted once. If we have a
11659 permanent breakpoint at the same place as BPT, make that one the
11660 official one, and the rest as duplicates. Permanent breakpoints
11661 are sorted first for the same address.
11663 Do the same for hardware watchpoints, but also considering the
11664 watchpoint's type (regular/access/read) and length. */
11666 bp_loc_first = NULL;
11667 wp_loc_first = NULL;
11668 awp_loc_first = NULL;
11669 rwp_loc_first = NULL;
11670 ALL_BP_LOCATIONS (loc, locp)
11672 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
11674 struct bp_location **loc_first_p;
11677 if (!should_be_inserted (loc)
11678 || !breakpoint_address_is_meaningful (b)
11679 /* Don't detect duplicate for tracepoint locations because they are
11680 never duplicated. See the comments in field `duplicate' of
11681 `struct bp_location'. */
11682 || is_tracepoint (b))
11684 /* Clear the condition modification flag. */
11685 loc->condition_changed = condition_unchanged;
11689 /* Permanent breakpoint should always be inserted. */
11690 if (b->enable_state == bp_permanent && ! loc->inserted)
11691 internal_error (__FILE__, __LINE__,
11692 _("allegedly permanent breakpoint is not "
11693 "actually inserted"));
11695 if (b->type == bp_hardware_watchpoint)
11696 loc_first_p = &wp_loc_first;
11697 else if (b->type == bp_read_watchpoint)
11698 loc_first_p = &rwp_loc_first;
11699 else if (b->type == bp_access_watchpoint)
11700 loc_first_p = &awp_loc_first;
11702 loc_first_p = &bp_loc_first;
11704 if (*loc_first_p == NULL
11705 || (overlay_debugging && loc->section != (*loc_first_p)->section)
11706 || !breakpoint_locations_match (loc, *loc_first_p))
11708 *loc_first_p = loc;
11709 loc->duplicate = 0;
11711 if (is_breakpoint (loc->owner) && loc->condition_changed)
11713 loc->needs_update = 1;
11714 /* Clear the condition modification flag. */
11715 loc->condition_changed = condition_unchanged;
11721 /* This and the above ensure the invariant that the first location
11722 is not duplicated, and is the inserted one.
11723 All following are marked as duplicated, and are not inserted. */
11725 swap_insertion (loc, *loc_first_p);
11726 loc->duplicate = 1;
11728 /* Clear the condition modification flag. */
11729 loc->condition_changed = condition_unchanged;
11731 if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted
11732 && b->enable_state != bp_permanent)
11733 internal_error (__FILE__, __LINE__,
11734 _("another breakpoint was inserted on top of "
11735 "a permanent breakpoint"));
11738 if (breakpoints_always_inserted_mode ()
11739 && (have_live_inferiors ()
11740 || (gdbarch_has_global_breakpoints (target_gdbarch))))
11743 insert_breakpoint_locations ();
11746 /* Though should_insert is false, we may need to update conditions
11747 on the target's side if it is evaluating such conditions. We
11748 only update conditions for locations that are marked
11750 update_inserted_breakpoint_locations ();
11755 download_tracepoint_locations ();
11757 do_cleanups (cleanups);
11761 breakpoint_retire_moribund (void)
11763 struct bp_location *loc;
11766 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
11767 if (--(loc->events_till_retirement) == 0)
11769 decref_bp_location (&loc);
11770 VEC_unordered_remove (bp_location_p, moribund_locations, ix);
11776 update_global_location_list_nothrow (int inserting)
11778 volatile struct gdb_exception e;
11780 TRY_CATCH (e, RETURN_MASK_ERROR)
11781 update_global_location_list (inserting);
11784 /* Clear BKP from a BPS. */
11787 bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt)
11791 for (bs = bps; bs; bs = bs->next)
11792 if (bs->breakpoint_at == bpt)
11794 bs->breakpoint_at = NULL;
11795 bs->old_val = NULL;
11796 /* bs->commands will be freed later. */
11800 /* Callback for iterate_over_threads. */
11802 bpstat_remove_breakpoint_callback (struct thread_info *th, void *data)
11804 struct breakpoint *bpt = data;
11806 bpstat_remove_bp_location (th->control.stop_bpstat, bpt);
11810 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
11814 say_where (struct breakpoint *b)
11816 struct ui_out *uiout = current_uiout;
11817 struct value_print_options opts;
11819 get_user_print_options (&opts);
11821 /* i18n: cagney/2005-02-11: Below needs to be merged into a
11823 if (b->loc == NULL)
11825 printf_filtered (_(" (%s) pending."), b->addr_string);
11829 if (opts.addressprint || b->loc->source_file == NULL)
11831 printf_filtered (" at ");
11832 fputs_filtered (paddress (b->loc->gdbarch, b->loc->address),
11835 if (b->loc->source_file)
11837 /* If there is a single location, we can print the location
11839 if (b->loc->next == NULL)
11840 printf_filtered (": file %s, line %d.",
11841 b->loc->source_file, b->loc->line_number);
11843 /* This is not ideal, but each location may have a
11844 different file name, and this at least reflects the
11845 real situation somewhat. */
11846 printf_filtered (": %s.", b->addr_string);
11851 struct bp_location *loc = b->loc;
11853 for (; loc; loc = loc->next)
11855 printf_filtered (" (%d locations)", n);
11860 /* Default bp_location_ops methods. */
11863 bp_location_dtor (struct bp_location *self)
11865 xfree (self->cond);
11866 if (self->cond_bytecode)
11867 free_agent_expr (self->cond_bytecode);
11868 xfree (self->function_name);
11869 xfree (self->source_file);
11872 static const struct bp_location_ops bp_location_ops =
11877 /* Default breakpoint_ops methods all breakpoint_ops ultimately
11881 base_breakpoint_dtor (struct breakpoint *self)
11883 decref_counted_command_line (&self->commands);
11884 xfree (self->cond_string);
11885 xfree (self->addr_string);
11886 xfree (self->filter);
11887 xfree (self->addr_string_range_end);
11890 static struct bp_location *
11891 base_breakpoint_allocate_location (struct breakpoint *self)
11893 struct bp_location *loc;
11895 loc = XNEW (struct bp_location);
11896 init_bp_location (loc, &bp_location_ops, self);
11901 base_breakpoint_re_set (struct breakpoint *b)
11903 /* Nothing to re-set. */
11906 #define internal_error_pure_virtual_called() \
11907 gdb_assert_not_reached ("pure virtual function called")
11910 base_breakpoint_insert_location (struct bp_location *bl)
11912 internal_error_pure_virtual_called ();
11916 base_breakpoint_remove_location (struct bp_location *bl)
11918 internal_error_pure_virtual_called ();
11922 base_breakpoint_breakpoint_hit (const struct bp_location *bl,
11923 struct address_space *aspace,
11925 const struct target_waitstatus *ws)
11927 internal_error_pure_virtual_called ();
11931 base_breakpoint_check_status (bpstat bs)
11936 /* A "works_in_software_mode" breakpoint_ops method that just internal
11940 base_breakpoint_works_in_software_mode (const struct breakpoint *b)
11942 internal_error_pure_virtual_called ();
11945 /* A "resources_needed" breakpoint_ops method that just internal
11949 base_breakpoint_resources_needed (const struct bp_location *bl)
11951 internal_error_pure_virtual_called ();
11954 static enum print_stop_action
11955 base_breakpoint_print_it (bpstat bs)
11957 internal_error_pure_virtual_called ();
11961 base_breakpoint_print_one_detail (const struct breakpoint *self,
11962 struct ui_out *uiout)
11968 base_breakpoint_print_mention (struct breakpoint *b)
11970 internal_error_pure_virtual_called ();
11974 base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp)
11976 internal_error_pure_virtual_called ();
11980 base_breakpoint_create_sals_from_address (char **arg,
11981 struct linespec_result *canonical,
11982 enum bptype type_wanted,
11986 internal_error_pure_virtual_called ();
11990 base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch,
11991 struct linespec_result *c,
11992 struct linespec_sals *lsal,
11994 enum bptype type_wanted,
11995 enum bpdisp disposition,
11997 int task, int ignore_count,
11998 const struct breakpoint_ops *o,
11999 int from_tty, int enabled,
12002 internal_error_pure_virtual_called ();
12006 base_breakpoint_decode_linespec (struct breakpoint *b, char **s,
12007 struct symtabs_and_lines *sals)
12009 internal_error_pure_virtual_called ();
12012 static struct breakpoint_ops base_breakpoint_ops =
12014 base_breakpoint_dtor,
12015 base_breakpoint_allocate_location,
12016 base_breakpoint_re_set,
12017 base_breakpoint_insert_location,
12018 base_breakpoint_remove_location,
12019 base_breakpoint_breakpoint_hit,
12020 base_breakpoint_check_status,
12021 base_breakpoint_resources_needed,
12022 base_breakpoint_works_in_software_mode,
12023 base_breakpoint_print_it,
12025 base_breakpoint_print_one_detail,
12026 base_breakpoint_print_mention,
12027 base_breakpoint_print_recreate,
12028 base_breakpoint_create_sals_from_address,
12029 base_breakpoint_create_breakpoints_sal,
12030 base_breakpoint_decode_linespec,
12033 /* Default breakpoint_ops methods. */
12036 bkpt_re_set (struct breakpoint *b)
12038 /* FIXME: is this still reachable? */
12039 if (b->addr_string == NULL)
12041 /* Anything without a string can't be re-set. */
12042 delete_breakpoint (b);
12046 breakpoint_re_set_default (b);
12050 bkpt_insert_location (struct bp_location *bl)
12052 if (bl->loc_type == bp_loc_hardware_breakpoint)
12053 return target_insert_hw_breakpoint (bl->gdbarch,
12056 return target_insert_breakpoint (bl->gdbarch,
12061 bkpt_remove_location (struct bp_location *bl)
12063 if (bl->loc_type == bp_loc_hardware_breakpoint)
12064 return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info);
12066 return target_remove_breakpoint (bl->gdbarch, &bl->target_info);
12070 bkpt_breakpoint_hit (const struct bp_location *bl,
12071 struct address_space *aspace, CORE_ADDR bp_addr,
12072 const struct target_waitstatus *ws)
12074 struct breakpoint *b = bl->owner;
12076 if (ws->kind != TARGET_WAITKIND_STOPPED
12077 || ws->value.sig != TARGET_SIGNAL_TRAP)
12080 if (!breakpoint_address_match (bl->pspace->aspace, bl->address,
12084 if (overlay_debugging /* unmapped overlay section */
12085 && section_is_overlay (bl->section)
12086 && !section_is_mapped (bl->section))
12093 bkpt_resources_needed (const struct bp_location *bl)
12095 gdb_assert (bl->owner->type == bp_hardware_breakpoint);
12100 static enum print_stop_action
12101 bkpt_print_it (bpstat bs)
12103 struct breakpoint *b;
12104 const struct bp_location *bl;
12106 struct ui_out *uiout = current_uiout;
12108 gdb_assert (bs->bp_location_at != NULL);
12110 bl = bs->bp_location_at;
12111 b = bs->breakpoint_at;
12113 bp_temp = b->disposition == disp_del;
12114 if (bl->address != bl->requested_address)
12115 breakpoint_adjustment_warning (bl->requested_address,
12118 annotate_breakpoint (b->number);
12120 ui_out_text (uiout, "\nTemporary breakpoint ");
12122 ui_out_text (uiout, "\nBreakpoint ");
12123 if (ui_out_is_mi_like_p (uiout))
12125 ui_out_field_string (uiout, "reason",
12126 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
12127 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
12129 ui_out_field_int (uiout, "bkptno", b->number);
12130 ui_out_text (uiout, ", ");
12132 return PRINT_SRC_AND_LOC;
12136 bkpt_print_mention (struct breakpoint *b)
12138 if (ui_out_is_mi_like_p (current_uiout))
12143 case bp_breakpoint:
12144 case bp_gnu_ifunc_resolver:
12145 if (b->disposition == disp_del)
12146 printf_filtered (_("Temporary breakpoint"));
12148 printf_filtered (_("Breakpoint"));
12149 printf_filtered (_(" %d"), b->number);
12150 if (b->type == bp_gnu_ifunc_resolver)
12151 printf_filtered (_(" at gnu-indirect-function resolver"));
12153 case bp_hardware_breakpoint:
12154 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
12162 bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp)
12164 if (tp->type == bp_breakpoint && tp->disposition == disp_del)
12165 fprintf_unfiltered (fp, "tbreak");
12166 else if (tp->type == bp_breakpoint)
12167 fprintf_unfiltered (fp, "break");
12168 else if (tp->type == bp_hardware_breakpoint
12169 && tp->disposition == disp_del)
12170 fprintf_unfiltered (fp, "thbreak");
12171 else if (tp->type == bp_hardware_breakpoint)
12172 fprintf_unfiltered (fp, "hbreak");
12174 internal_error (__FILE__, __LINE__,
12175 _("unhandled breakpoint type %d"), (int) tp->type);
12177 fprintf_unfiltered (fp, " %s", tp->addr_string);
12178 print_recreate_thread (tp, fp);
12182 bkpt_create_sals_from_address (char **arg,
12183 struct linespec_result *canonical,
12184 enum bptype type_wanted,
12185 char *addr_start, char **copy_arg)
12187 create_sals_from_address_default (arg, canonical, type_wanted,
12188 addr_start, copy_arg);
12192 bkpt_create_breakpoints_sal (struct gdbarch *gdbarch,
12193 struct linespec_result *canonical,
12194 struct linespec_sals *lsal,
12196 enum bptype type_wanted,
12197 enum bpdisp disposition,
12199 int task, int ignore_count,
12200 const struct breakpoint_ops *ops,
12201 int from_tty, int enabled,
12204 create_breakpoints_sal_default (gdbarch, canonical, lsal,
12205 cond_string, type_wanted,
12206 disposition, thread, task,
12207 ignore_count, ops, from_tty,
12208 enabled, internal);
12212 bkpt_decode_linespec (struct breakpoint *b, char **s,
12213 struct symtabs_and_lines *sals)
12215 decode_linespec_default (b, s, sals);
12218 /* Virtual table for internal breakpoints. */
12221 internal_bkpt_re_set (struct breakpoint *b)
12225 /* Delete overlay event and longjmp master breakpoints; they
12226 will be reset later by breakpoint_re_set. */
12227 case bp_overlay_event:
12228 case bp_longjmp_master:
12229 case bp_std_terminate_master:
12230 case bp_exception_master:
12231 delete_breakpoint (b);
12234 /* This breakpoint is special, it's set up when the inferior
12235 starts and we really don't want to touch it. */
12236 case bp_shlib_event:
12238 /* Like bp_shlib_event, this breakpoint type is special. Once
12239 it is set up, we do not want to touch it. */
12240 case bp_thread_event:
12246 internal_bkpt_check_status (bpstat bs)
12248 if (bs->breakpoint_at->type == bp_shlib_event)
12250 /* If requested, stop when the dynamic linker notifies GDB of
12251 events. This allows the user to get control and place
12252 breakpoints in initializer routines for dynamically loaded
12253 objects (among other things). */
12254 bs->stop = stop_on_solib_events;
12255 bs->print = stop_on_solib_events;
12261 static enum print_stop_action
12262 internal_bkpt_print_it (bpstat bs)
12264 struct ui_out *uiout = current_uiout;
12265 struct breakpoint *b;
12267 b = bs->breakpoint_at;
12271 case bp_shlib_event:
12272 /* Did we stop because the user set the stop_on_solib_events
12273 variable? (If so, we report this as a generic, "Stopped due
12274 to shlib event" message.) */
12275 print_solib_event (0);
12278 case bp_thread_event:
12279 /* Not sure how we will get here.
12280 GDB should not stop for these breakpoints. */
12281 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
12284 case bp_overlay_event:
12285 /* By analogy with the thread event, GDB should not stop for these. */
12286 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
12289 case bp_longjmp_master:
12290 /* These should never be enabled. */
12291 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
12294 case bp_std_terminate_master:
12295 /* These should never be enabled. */
12296 printf_filtered (_("std::terminate Master Breakpoint: "
12297 "gdb should not stop!\n"));
12300 case bp_exception_master:
12301 /* These should never be enabled. */
12302 printf_filtered (_("Exception Master Breakpoint: "
12303 "gdb should not stop!\n"));
12307 return PRINT_NOTHING;
12311 internal_bkpt_print_mention (struct breakpoint *b)
12313 /* Nothing to mention. These breakpoints are internal. */
12316 /* Virtual table for momentary breakpoints */
12319 momentary_bkpt_re_set (struct breakpoint *b)
12321 /* Keep temporary breakpoints, which can be encountered when we step
12322 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
12323 Otherwise these should have been blown away via the cleanup chain
12324 or by breakpoint_init_inferior when we rerun the executable. */
12328 momentary_bkpt_check_status (bpstat bs)
12330 /* Nothing. The point of these breakpoints is causing a stop. */
12333 static enum print_stop_action
12334 momentary_bkpt_print_it (bpstat bs)
12336 struct ui_out *uiout = current_uiout;
12338 if (ui_out_is_mi_like_p (uiout))
12340 struct breakpoint *b = bs->breakpoint_at;
12345 ui_out_field_string
12347 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED));
12351 ui_out_field_string
12353 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED));
12358 return PRINT_UNKNOWN;
12362 momentary_bkpt_print_mention (struct breakpoint *b)
12364 /* Nothing to mention. These breakpoints are internal. */
12367 /* The breakpoint_ops structure to be used in tracepoints. */
12370 tracepoint_re_set (struct breakpoint *b)
12372 breakpoint_re_set_default (b);
12376 tracepoint_breakpoint_hit (const struct bp_location *bl,
12377 struct address_space *aspace, CORE_ADDR bp_addr,
12378 const struct target_waitstatus *ws)
12380 /* By definition, the inferior does not report stops at
12386 tracepoint_print_one_detail (const struct breakpoint *self,
12387 struct ui_out *uiout)
12389 struct tracepoint *tp = (struct tracepoint *) self;
12390 if (tp->static_trace_marker_id)
12392 gdb_assert (self->type == bp_static_tracepoint);
12394 ui_out_text (uiout, "\tmarker id is ");
12395 ui_out_field_string (uiout, "static-tracepoint-marker-string-id",
12396 tp->static_trace_marker_id);
12397 ui_out_text (uiout, "\n");
12402 tracepoint_print_mention (struct breakpoint *b)
12404 if (ui_out_is_mi_like_p (current_uiout))
12409 case bp_tracepoint:
12410 printf_filtered (_("Tracepoint"));
12411 printf_filtered (_(" %d"), b->number);
12413 case bp_fast_tracepoint:
12414 printf_filtered (_("Fast tracepoint"));
12415 printf_filtered (_(" %d"), b->number);
12417 case bp_static_tracepoint:
12418 printf_filtered (_("Static tracepoint"));
12419 printf_filtered (_(" %d"), b->number);
12422 internal_error (__FILE__, __LINE__,
12423 _("unhandled tracepoint type %d"), (int) b->type);
12430 tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp)
12432 struct tracepoint *tp = (struct tracepoint *) self;
12434 if (self->type == bp_fast_tracepoint)
12435 fprintf_unfiltered (fp, "ftrace");
12436 if (self->type == bp_static_tracepoint)
12437 fprintf_unfiltered (fp, "strace");
12438 else if (self->type == bp_tracepoint)
12439 fprintf_unfiltered (fp, "trace");
12441 internal_error (__FILE__, __LINE__,
12442 _("unhandled tracepoint type %d"), (int) self->type);
12444 fprintf_unfiltered (fp, " %s", self->addr_string);
12445 print_recreate_thread (self, fp);
12447 if (tp->pass_count)
12448 fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count);
12452 tracepoint_create_sals_from_address (char **arg,
12453 struct linespec_result *canonical,
12454 enum bptype type_wanted,
12455 char *addr_start, char **copy_arg)
12457 create_sals_from_address_default (arg, canonical, type_wanted,
12458 addr_start, copy_arg);
12462 tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch,
12463 struct linespec_result *canonical,
12464 struct linespec_sals *lsal,
12466 enum bptype type_wanted,
12467 enum bpdisp disposition,
12469 int task, int ignore_count,
12470 const struct breakpoint_ops *ops,
12471 int from_tty, int enabled,
12474 create_breakpoints_sal_default (gdbarch, canonical, lsal,
12475 cond_string, type_wanted,
12476 disposition, thread, task,
12477 ignore_count, ops, from_tty,
12478 enabled, internal);
12482 tracepoint_decode_linespec (struct breakpoint *b, char **s,
12483 struct symtabs_and_lines *sals)
12485 decode_linespec_default (b, s, sals);
12488 struct breakpoint_ops tracepoint_breakpoint_ops;
12490 /* The breakpoint_ops structure to be used on static tracepoints with
12494 strace_marker_create_sals_from_address (char **arg,
12495 struct linespec_result *canonical,
12496 enum bptype type_wanted,
12497 char *addr_start, char **copy_arg)
12499 struct linespec_sals lsal;
12501 lsal.sals = decode_static_tracepoint_spec (arg);
12503 *copy_arg = savestring (addr_start, *arg - addr_start);
12505 canonical->addr_string = xstrdup (*copy_arg);
12506 lsal.canonical = xstrdup (*copy_arg);
12507 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
12511 strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch,
12512 struct linespec_result *canonical,
12513 struct linespec_sals *lsal,
12515 enum bptype type_wanted,
12516 enum bpdisp disposition,
12518 int task, int ignore_count,
12519 const struct breakpoint_ops *ops,
12520 int from_tty, int enabled,
12525 /* If the user is creating a static tracepoint by marker id
12526 (strace -m MARKER_ID), then store the sals index, so that
12527 breakpoint_re_set can try to match up which of the newly
12528 found markers corresponds to this one, and, don't try to
12529 expand multiple locations for each sal, given than SALS
12530 already should contain all sals for MARKER_ID. */
12532 for (i = 0; i < lsal->sals.nelts; ++i)
12534 struct symtabs_and_lines expanded;
12535 struct tracepoint *tp;
12536 struct cleanup *old_chain;
12539 expanded.nelts = 1;
12540 expanded.sals = &lsal->sals.sals[i];
12542 addr_string = xstrdup (canonical->addr_string);
12543 old_chain = make_cleanup (xfree, addr_string);
12545 tp = XCNEW (struct tracepoint);
12546 init_breakpoint_sal (&tp->base, gdbarch, expanded,
12548 cond_string, type_wanted, disposition,
12549 thread, task, ignore_count, ops,
12550 from_tty, enabled, internal,
12551 canonical->special_display);
12552 /* Given that its possible to have multiple markers with
12553 the same string id, if the user is creating a static
12554 tracepoint by marker id ("strace -m MARKER_ID"), then
12555 store the sals index, so that breakpoint_re_set can
12556 try to match up which of the newly found markers
12557 corresponds to this one */
12558 tp->static_trace_marker_id_idx = i;
12560 install_breakpoint (internal, &tp->base, 0);
12562 discard_cleanups (old_chain);
12567 strace_marker_decode_linespec (struct breakpoint *b, char **s,
12568 struct symtabs_and_lines *sals)
12570 struct tracepoint *tp = (struct tracepoint *) b;
12572 *sals = decode_static_tracepoint_spec (s);
12573 if (sals->nelts > tp->static_trace_marker_id_idx)
12575 sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx];
12579 error (_("marker %s not found"), tp->static_trace_marker_id);
12582 static struct breakpoint_ops strace_marker_breakpoint_ops;
12585 strace_marker_p (struct breakpoint *b)
12587 return b->ops == &strace_marker_breakpoint_ops;
12590 /* Delete a breakpoint and clean up all traces of it in the data
12594 delete_breakpoint (struct breakpoint *bpt)
12596 struct breakpoint *b;
12598 gdb_assert (bpt != NULL);
12600 /* Has this bp already been deleted? This can happen because
12601 multiple lists can hold pointers to bp's. bpstat lists are
12604 One example of this happening is a watchpoint's scope bp. When
12605 the scope bp triggers, we notice that the watchpoint is out of
12606 scope, and delete it. We also delete its scope bp. But the
12607 scope bp is marked "auto-deleting", and is already on a bpstat.
12608 That bpstat is then checked for auto-deleting bp's, which are
12611 A real solution to this problem might involve reference counts in
12612 bp's, and/or giving them pointers back to their referencing
12613 bpstat's, and teaching delete_breakpoint to only free a bp's
12614 storage when no more references were extent. A cheaper bandaid
12616 if (bpt->type == bp_none)
12619 /* At least avoid this stale reference until the reference counting
12620 of breakpoints gets resolved. */
12621 if (bpt->related_breakpoint != bpt)
12623 struct breakpoint *related;
12624 struct watchpoint *w;
12626 if (bpt->type == bp_watchpoint_scope)
12627 w = (struct watchpoint *) bpt->related_breakpoint;
12628 else if (bpt->related_breakpoint->type == bp_watchpoint_scope)
12629 w = (struct watchpoint *) bpt;
12633 watchpoint_del_at_next_stop (w);
12635 /* Unlink bpt from the bpt->related_breakpoint ring. */
12636 for (related = bpt; related->related_breakpoint != bpt;
12637 related = related->related_breakpoint);
12638 related->related_breakpoint = bpt->related_breakpoint;
12639 bpt->related_breakpoint = bpt;
12642 /* watch_command_1 creates a watchpoint but only sets its number if
12643 update_watchpoint succeeds in creating its bp_locations. If there's
12644 a problem in that process, we'll be asked to delete the half-created
12645 watchpoint. In that case, don't announce the deletion. */
12647 observer_notify_breakpoint_deleted (bpt);
12649 if (breakpoint_chain == bpt)
12650 breakpoint_chain = bpt->next;
12652 ALL_BREAKPOINTS (b)
12653 if (b->next == bpt)
12655 b->next = bpt->next;
12659 /* Be sure no bpstat's are pointing at the breakpoint after it's
12661 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
12662 in all threads for now. Note that we cannot just remove bpstats
12663 pointing at bpt from the stop_bpstat list entirely, as breakpoint
12664 commands are associated with the bpstat; if we remove it here,
12665 then the later call to bpstat_do_actions (&stop_bpstat); in
12666 event-top.c won't do anything, and temporary breakpoints with
12667 commands won't work. */
12669 iterate_over_threads (bpstat_remove_breakpoint_callback, bpt);
12671 /* Now that breakpoint is removed from breakpoint list, update the
12672 global location list. This will remove locations that used to
12673 belong to this breakpoint. Do this before freeing the breakpoint
12674 itself, since remove_breakpoint looks at location's owner. It
12675 might be better design to have location completely
12676 self-contained, but it's not the case now. */
12677 update_global_location_list (0);
12679 bpt->ops->dtor (bpt);
12680 /* On the chance that someone will soon try again to delete this
12681 same bp, we mark it as deleted before freeing its storage. */
12682 bpt->type = bp_none;
12687 do_delete_breakpoint_cleanup (void *b)
12689 delete_breakpoint (b);
12693 make_cleanup_delete_breakpoint (struct breakpoint *b)
12695 return make_cleanup (do_delete_breakpoint_cleanup, b);
12698 /* Iterator function to call a user-provided callback function once
12699 for each of B and its related breakpoints. */
12702 iterate_over_related_breakpoints (struct breakpoint *b,
12703 void (*function) (struct breakpoint *,
12707 struct breakpoint *related;
12712 struct breakpoint *next;
12714 /* FUNCTION may delete RELATED. */
12715 next = related->related_breakpoint;
12717 if (next == related)
12719 /* RELATED is the last ring entry. */
12720 function (related, data);
12722 /* FUNCTION may have deleted it, so we'd never reach back to
12723 B. There's nothing left to do anyway, so just break
12728 function (related, data);
12732 while (related != b);
12736 do_delete_breakpoint (struct breakpoint *b, void *ignore)
12738 delete_breakpoint (b);
12741 /* A callback for map_breakpoint_numbers that calls
12742 delete_breakpoint. */
12745 do_map_delete_breakpoint (struct breakpoint *b, void *ignore)
12747 iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL);
12751 delete_command (char *arg, int from_tty)
12753 struct breakpoint *b, *b_tmp;
12759 int breaks_to_delete = 0;
12761 /* Delete all breakpoints if no argument. Do not delete
12762 internal breakpoints, these have to be deleted with an
12763 explicit breakpoint number argument. */
12764 ALL_BREAKPOINTS (b)
12765 if (user_breakpoint_p (b))
12767 breaks_to_delete = 1;
12771 /* Ask user only if there are some breakpoints to delete. */
12773 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
12775 ALL_BREAKPOINTS_SAFE (b, b_tmp)
12776 if (user_breakpoint_p (b))
12777 delete_breakpoint (b);
12781 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
12785 all_locations_are_pending (struct bp_location *loc)
12787 for (; loc; loc = loc->next)
12788 if (!loc->shlib_disabled
12789 && !loc->pspace->executing_startup)
12794 /* Subroutine of update_breakpoint_locations to simplify it.
12795 Return non-zero if multiple fns in list LOC have the same name.
12796 Null names are ignored. */
12799 ambiguous_names_p (struct bp_location *loc)
12801 struct bp_location *l;
12802 htab_t htab = htab_create_alloc (13, htab_hash_string,
12803 (int (*) (const void *,
12804 const void *)) streq,
12805 NULL, xcalloc, xfree);
12807 for (l = loc; l != NULL; l = l->next)
12810 const char *name = l->function_name;
12812 /* Allow for some names to be NULL, ignore them. */
12816 slot = (const char **) htab_find_slot (htab, (const void *) name,
12818 /* NOTE: We can assume slot != NULL here because xcalloc never
12822 htab_delete (htab);
12828 htab_delete (htab);
12832 /* When symbols change, it probably means the sources changed as well,
12833 and it might mean the static tracepoint markers are no longer at
12834 the same address or line numbers they used to be at last we
12835 checked. Losing your static tracepoints whenever you rebuild is
12836 undesirable. This function tries to resync/rematch gdb static
12837 tracepoints with the markers on the target, for static tracepoints
12838 that have not been set by marker id. Static tracepoint that have
12839 been set by marker id are reset by marker id in breakpoint_re_set.
12842 1) For a tracepoint set at a specific address, look for a marker at
12843 the old PC. If one is found there, assume to be the same marker.
12844 If the name / string id of the marker found is different from the
12845 previous known name, assume that means the user renamed the marker
12846 in the sources, and output a warning.
12848 2) For a tracepoint set at a given line number, look for a marker
12849 at the new address of the old line number. If one is found there,
12850 assume to be the same marker. If the name / string id of the
12851 marker found is different from the previous known name, assume that
12852 means the user renamed the marker in the sources, and output a
12855 3) If a marker is no longer found at the same address or line, it
12856 may mean the marker no longer exists. But it may also just mean
12857 the code changed a bit. Maybe the user added a few lines of code
12858 that made the marker move up or down (in line number terms). Ask
12859 the target for info about the marker with the string id as we knew
12860 it. If found, update line number and address in the matching
12861 static tracepoint. This will get confused if there's more than one
12862 marker with the same ID (possible in UST, although unadvised
12863 precisely because it confuses tools). */
12865 static struct symtab_and_line
12866 update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal)
12868 struct tracepoint *tp = (struct tracepoint *) b;
12869 struct static_tracepoint_marker marker;
12875 find_line_pc (sal.symtab, sal.line, &pc);
12877 if (target_static_tracepoint_marker_at (pc, &marker))
12879 if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0)
12880 warning (_("static tracepoint %d changed probed marker from %s to %s"),
12882 tp->static_trace_marker_id, marker.str_id);
12884 xfree (tp->static_trace_marker_id);
12885 tp->static_trace_marker_id = xstrdup (marker.str_id);
12886 release_static_tracepoint_marker (&marker);
12891 /* Old marker wasn't found on target at lineno. Try looking it up
12893 if (!sal.explicit_pc
12895 && sal.symtab != NULL
12896 && tp->static_trace_marker_id != NULL)
12898 VEC(static_tracepoint_marker_p) *markers;
12901 = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id);
12903 if (!VEC_empty(static_tracepoint_marker_p, markers))
12905 struct symtab_and_line sal2;
12906 struct symbol *sym;
12907 struct static_tracepoint_marker *tpmarker;
12908 struct ui_out *uiout = current_uiout;
12910 tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0);
12912 xfree (tp->static_trace_marker_id);
12913 tp->static_trace_marker_id = xstrdup (tpmarker->str_id);
12915 warning (_("marker for static tracepoint %d (%s) not "
12916 "found at previous line number"),
12917 b->number, tp->static_trace_marker_id);
12921 sal2.pc = tpmarker->address;
12923 sal2 = find_pc_line (tpmarker->address, 0);
12924 sym = find_pc_sect_function (tpmarker->address, NULL);
12925 ui_out_text (uiout, "Now in ");
12928 ui_out_field_string (uiout, "func",
12929 SYMBOL_PRINT_NAME (sym));
12930 ui_out_text (uiout, " at ");
12932 ui_out_field_string (uiout, "file", sal2.symtab->filename);
12933 ui_out_text (uiout, ":");
12935 if (ui_out_is_mi_like_p (uiout))
12937 char *fullname = symtab_to_fullname (sal2.symtab);
12940 ui_out_field_string (uiout, "fullname", fullname);
12943 ui_out_field_int (uiout, "line", sal2.line);
12944 ui_out_text (uiout, "\n");
12946 b->loc->line_number = sal2.line;
12948 xfree (b->loc->source_file);
12950 b->loc->source_file = xstrdup (sal2.symtab->filename);
12952 b->loc->source_file = NULL;
12954 xfree (b->addr_string);
12955 b->addr_string = xstrprintf ("%s:%d",
12956 sal2.symtab->filename,
12957 b->loc->line_number);
12959 /* Might be nice to check if function changed, and warn if
12962 release_static_tracepoint_marker (tpmarker);
12968 /* Returns 1 iff locations A and B are sufficiently same that
12969 we don't need to report breakpoint as changed. */
12972 locations_are_equal (struct bp_location *a, struct bp_location *b)
12976 if (a->address != b->address)
12979 if (a->shlib_disabled != b->shlib_disabled)
12982 if (a->enabled != b->enabled)
12989 if ((a == NULL) != (b == NULL))
12995 /* Create new breakpoint locations for B (a hardware or software breakpoint)
12996 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
12997 a ranged breakpoint. */
13000 update_breakpoint_locations (struct breakpoint *b,
13001 struct symtabs_and_lines sals,
13002 struct symtabs_and_lines sals_end)
13005 struct bp_location *existing_locations = b->loc;
13007 if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1))
13009 /* Ranged breakpoints have only one start location and one end
13011 b->enable_state = bp_disabled;
13012 update_global_location_list (1);
13013 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
13014 "multiple locations found\n"),
13019 /* If there's no new locations, and all existing locations are
13020 pending, don't do anything. This optimizes the common case where
13021 all locations are in the same shared library, that was unloaded.
13022 We'd like to retain the location, so that when the library is
13023 loaded again, we don't loose the enabled/disabled status of the
13024 individual locations. */
13025 if (all_locations_are_pending (existing_locations) && sals.nelts == 0)
13030 for (i = 0; i < sals.nelts; ++i)
13032 struct bp_location *new_loc;
13034 switch_to_program_space_and_thread (sals.sals[i].pspace);
13036 new_loc = add_location_to_breakpoint (b, &(sals.sals[i]));
13038 /* Reparse conditions, they might contain references to the
13040 if (b->cond_string != NULL)
13043 volatile struct gdb_exception e;
13045 s = b->cond_string;
13046 TRY_CATCH (e, RETURN_MASK_ERROR)
13048 new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc),
13053 warning (_("failed to reevaluate condition "
13054 "for breakpoint %d: %s"),
13055 b->number, e.message);
13056 new_loc->enabled = 0;
13060 if (sals_end.nelts)
13062 CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]);
13064 new_loc->length = end - sals.sals[0].pc + 1;
13068 /* Update locations of permanent breakpoints. */
13069 if (b->enable_state == bp_permanent)
13070 make_breakpoint_permanent (b);
13072 /* If possible, carry over 'disable' status from existing
13075 struct bp_location *e = existing_locations;
13076 /* If there are multiple breakpoints with the same function name,
13077 e.g. for inline functions, comparing function names won't work.
13078 Instead compare pc addresses; this is just a heuristic as things
13079 may have moved, but in practice it gives the correct answer
13080 often enough until a better solution is found. */
13081 int have_ambiguous_names = ambiguous_names_p (b->loc);
13083 for (; e; e = e->next)
13085 if (!e->enabled && e->function_name)
13087 struct bp_location *l = b->loc;
13088 if (have_ambiguous_names)
13090 for (; l; l = l->next)
13091 if (breakpoint_locations_match (e, l))
13099 for (; l; l = l->next)
13100 if (l->function_name
13101 && strcmp (e->function_name, l->function_name) == 0)
13111 if (!locations_are_equal (existing_locations, b->loc))
13112 observer_notify_breakpoint_modified (b);
13114 update_global_location_list (1);
13117 /* Find the SaL locations corresponding to the given ADDR_STRING.
13118 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
13120 static struct symtabs_and_lines
13121 addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found)
13124 struct symtabs_and_lines sals = {0};
13125 volatile struct gdb_exception e;
13127 gdb_assert (b->ops != NULL);
13130 TRY_CATCH (e, RETURN_MASK_ERROR)
13132 b->ops->decode_linespec (b, &s, &sals);
13136 int not_found_and_ok = 0;
13137 /* For pending breakpoints, it's expected that parsing will
13138 fail until the right shared library is loaded. User has
13139 already told to create pending breakpoints and don't need
13140 extra messages. If breakpoint is in bp_shlib_disabled
13141 state, then user already saw the message about that
13142 breakpoint being disabled, and don't want to see more
13144 if (e.error == NOT_FOUND_ERROR
13145 && (b->condition_not_parsed
13146 || (b->loc && b->loc->shlib_disabled)
13147 || (b->loc && b->loc->pspace->executing_startup)
13148 || b->enable_state == bp_disabled))
13149 not_found_and_ok = 1;
13151 if (!not_found_and_ok)
13153 /* We surely don't want to warn about the same breakpoint
13154 10 times. One solution, implemented here, is disable
13155 the breakpoint on error. Another solution would be to
13156 have separate 'warning emitted' flag. Since this
13157 happens only when a binary has changed, I don't know
13158 which approach is better. */
13159 b->enable_state = bp_disabled;
13160 throw_exception (e);
13164 if (e.reason == 0 || e.error != NOT_FOUND_ERROR)
13168 for (i = 0; i < sals.nelts; ++i)
13169 resolve_sal_pc (&sals.sals[i]);
13170 if (b->condition_not_parsed && s && s[0])
13172 char *cond_string = 0;
13176 find_condition_and_thread (s, sals.sals[0].pc,
13177 &cond_string, &thread, &task);
13179 b->cond_string = cond_string;
13180 b->thread = thread;
13182 b->condition_not_parsed = 0;
13185 if (b->type == bp_static_tracepoint && !strace_marker_p (b))
13186 sals.sals[0] = update_static_tracepoint (b, sals.sals[0]);
13196 /* The default re_set method, for typical hardware or software
13197 breakpoints. Reevaluate the breakpoint and recreate its
13201 breakpoint_re_set_default (struct breakpoint *b)
13204 struct symtabs_and_lines sals, sals_end;
13205 struct symtabs_and_lines expanded = {0};
13206 struct symtabs_and_lines expanded_end = {0};
13208 sals = addr_string_to_sals (b, b->addr_string, &found);
13211 make_cleanup (xfree, sals.sals);
13215 if (b->addr_string_range_end)
13217 sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found);
13220 make_cleanup (xfree, sals_end.sals);
13221 expanded_end = sals_end;
13225 update_breakpoint_locations (b, expanded, expanded_end);
13228 /* Default method for creating SALs from an address string. It basically
13229 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
13232 create_sals_from_address_default (char **arg,
13233 struct linespec_result *canonical,
13234 enum bptype type_wanted,
13235 char *addr_start, char **copy_arg)
13237 parse_breakpoint_sals (arg, canonical);
13240 /* Call create_breakpoints_sal for the given arguments. This is the default
13241 function for the `create_breakpoints_sal' method of
13245 create_breakpoints_sal_default (struct gdbarch *gdbarch,
13246 struct linespec_result *canonical,
13247 struct linespec_sals *lsal,
13249 enum bptype type_wanted,
13250 enum bpdisp disposition,
13252 int task, int ignore_count,
13253 const struct breakpoint_ops *ops,
13254 int from_tty, int enabled,
13257 create_breakpoints_sal (gdbarch, canonical, cond_string,
13258 type_wanted, disposition,
13259 thread, task, ignore_count, ops, from_tty,
13260 enabled, internal);
13263 /* Decode the line represented by S by calling decode_line_full. This is the
13264 default function for the `decode_linespec' method of breakpoint_ops. */
13267 decode_linespec_default (struct breakpoint *b, char **s,
13268 struct symtabs_and_lines *sals)
13270 struct linespec_result canonical;
13272 init_linespec_result (&canonical);
13273 decode_line_full (s, DECODE_LINE_FUNFIRSTLINE,
13274 (struct symtab *) NULL, 0,
13275 &canonical, multiple_symbols_all,
13278 /* We should get 0 or 1 resulting SALs. */
13279 gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2);
13281 if (VEC_length (linespec_sals, canonical.sals) > 0)
13283 struct linespec_sals *lsal;
13285 lsal = VEC_index (linespec_sals, canonical.sals, 0);
13286 *sals = lsal->sals;
13287 /* Arrange it so the destructor does not free the
13289 lsal->sals.sals = NULL;
13292 destroy_linespec_result (&canonical);
13295 /* Prepare the global context for a re-set of breakpoint B. */
13297 static struct cleanup *
13298 prepare_re_set_context (struct breakpoint *b)
13300 struct cleanup *cleanups;
13302 input_radix = b->input_radix;
13303 cleanups = save_current_space_and_thread ();
13304 if (b->pspace != NULL)
13305 switch_to_program_space_and_thread (b->pspace);
13306 set_language (b->language);
13311 /* Reset a breakpoint given it's struct breakpoint * BINT.
13312 The value we return ends up being the return value from catch_errors.
13313 Unused in this case. */
13316 breakpoint_re_set_one (void *bint)
13318 /* Get past catch_errs. */
13319 struct breakpoint *b = (struct breakpoint *) bint;
13320 struct cleanup *cleanups;
13322 cleanups = prepare_re_set_context (b);
13323 b->ops->re_set (b);
13324 do_cleanups (cleanups);
13328 /* Re-set all breakpoints after symbols have been re-loaded. */
13330 breakpoint_re_set (void)
13332 struct breakpoint *b, *b_tmp;
13333 enum language save_language;
13334 int save_input_radix;
13335 struct cleanup *old_chain;
13337 save_language = current_language->la_language;
13338 save_input_radix = input_radix;
13339 old_chain = save_current_program_space ();
13341 ALL_BREAKPOINTS_SAFE (b, b_tmp)
13343 /* Format possible error msg. */
13344 char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
13346 struct cleanup *cleanups = make_cleanup (xfree, message);
13347 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
13348 do_cleanups (cleanups);
13350 set_language (save_language);
13351 input_radix = save_input_radix;
13353 jit_breakpoint_re_set ();
13355 do_cleanups (old_chain);
13357 create_overlay_event_breakpoint ();
13358 create_longjmp_master_breakpoint ();
13359 create_std_terminate_master_breakpoint ();
13360 create_exception_master_breakpoint ();
13362 /* While we're at it, reset the skip list too. */
13366 /* Reset the thread number of this breakpoint:
13368 - If the breakpoint is for all threads, leave it as-is.
13369 - Else, reset it to the current thread for inferior_ptid. */
13371 breakpoint_re_set_thread (struct breakpoint *b)
13373 if (b->thread != -1)
13375 if (in_thread_list (inferior_ptid))
13376 b->thread = pid_to_thread_id (inferior_ptid);
13378 /* We're being called after following a fork. The new fork is
13379 selected as current, and unless this was a vfork will have a
13380 different program space from the original thread. Reset that
13382 b->loc->pspace = current_program_space;
13386 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
13387 If from_tty is nonzero, it prints a message to that effect,
13388 which ends with a period (no newline). */
13391 set_ignore_count (int bptnum, int count, int from_tty)
13393 struct breakpoint *b;
13398 ALL_BREAKPOINTS (b)
13399 if (b->number == bptnum)
13401 if (is_tracepoint (b))
13403 if (from_tty && count != 0)
13404 printf_filtered (_("Ignore count ignored for tracepoint %d."),
13409 b->ignore_count = count;
13413 printf_filtered (_("Will stop next time "
13414 "breakpoint %d is reached."),
13416 else if (count == 1)
13417 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
13420 printf_filtered (_("Will ignore next %d "
13421 "crossings of breakpoint %d."),
13424 breakpoints_changed ();
13425 observer_notify_breakpoint_modified (b);
13429 error (_("No breakpoint number %d."), bptnum);
13432 /* Command to set ignore-count of breakpoint N to COUNT. */
13435 ignore_command (char *args, int from_tty)
13441 error_no_arg (_("a breakpoint number"));
13443 num = get_number (&p);
13445 error (_("bad breakpoint number: '%s'"), args);
13447 error (_("Second argument (specified ignore-count) is missing."));
13449 set_ignore_count (num,
13450 longest_to_int (value_as_long (parse_and_eval (p))),
13453 printf_filtered ("\n");
13456 /* Call FUNCTION on each of the breakpoints
13457 whose numbers are given in ARGS. */
13460 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *,
13465 struct breakpoint *b, *tmp;
13467 struct get_number_or_range_state state;
13470 error_no_arg (_("one or more breakpoint numbers"));
13472 init_number_or_range (&state, args);
13474 while (!state.finished)
13476 char *p = state.string;
13480 num = get_number_or_range (&state);
13483 warning (_("bad breakpoint number at or near '%s'"), p);
13487 ALL_BREAKPOINTS_SAFE (b, tmp)
13488 if (b->number == num)
13491 function (b, data);
13495 printf_unfiltered (_("No breakpoint number %d.\n"), num);
13500 static struct bp_location *
13501 find_location_by_number (char *number)
13503 char *dot = strchr (number, '.');
13507 struct breakpoint *b;
13508 struct bp_location *loc;
13513 bp_num = get_number (&p1);
13515 error (_("Bad breakpoint number '%s'"), number);
13517 ALL_BREAKPOINTS (b)
13518 if (b->number == bp_num)
13523 if (!b || b->number != bp_num)
13524 error (_("Bad breakpoint number '%s'"), number);
13527 loc_num = get_number (&p1);
13529 error (_("Bad breakpoint location number '%s'"), number);
13533 for (;loc_num && loc; --loc_num, loc = loc->next)
13536 error (_("Bad breakpoint location number '%s'"), dot+1);
13542 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
13543 If from_tty is nonzero, it prints a message to that effect,
13544 which ends with a period (no newline). */
13547 disable_breakpoint (struct breakpoint *bpt)
13549 /* Never disable a watchpoint scope breakpoint; we want to
13550 hit them when we leave scope so we can delete both the
13551 watchpoint and its scope breakpoint at that time. */
13552 if (bpt->type == bp_watchpoint_scope)
13555 /* You can't disable permanent breakpoints. */
13556 if (bpt->enable_state == bp_permanent)
13559 bpt->enable_state = bp_disabled;
13561 /* Mark breakpoint locations modified. */
13562 mark_breakpoint_modified (bpt);
13564 if (target_supports_enable_disable_tracepoint ()
13565 && current_trace_status ()->running && is_tracepoint (bpt))
13567 struct bp_location *location;
13569 for (location = bpt->loc; location; location = location->next)
13570 target_disable_tracepoint (location);
13573 update_global_location_list (0);
13575 observer_notify_breakpoint_modified (bpt);
13578 /* A callback for iterate_over_related_breakpoints. */
13581 do_disable_breakpoint (struct breakpoint *b, void *ignore)
13583 disable_breakpoint (b);
13586 /* A callback for map_breakpoint_numbers that calls
13587 disable_breakpoint. */
13590 do_map_disable_breakpoint (struct breakpoint *b, void *ignore)
13592 iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL);
13596 disable_command (char *args, int from_tty)
13600 struct breakpoint *bpt;
13602 ALL_BREAKPOINTS (bpt)
13603 if (user_breakpoint_p (bpt))
13604 disable_breakpoint (bpt);
13606 else if (strchr (args, '.'))
13608 struct bp_location *loc = find_location_by_number (args);
13614 mark_breakpoint_location_modified (loc);
13616 if (target_supports_enable_disable_tracepoint ()
13617 && current_trace_status ()->running && loc->owner
13618 && is_tracepoint (loc->owner))
13619 target_disable_tracepoint (loc);
13621 update_global_location_list (0);
13624 map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL);
13628 enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition,
13631 int target_resources_ok;
13633 if (bpt->type == bp_hardware_breakpoint)
13636 i = hw_breakpoint_used_count ();
13637 target_resources_ok =
13638 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
13640 if (target_resources_ok == 0)
13641 error (_("No hardware breakpoint support in the target."));
13642 else if (target_resources_ok < 0)
13643 error (_("Hardware breakpoints used exceeds limit."));
13646 if (is_watchpoint (bpt))
13648 /* Initialize it just to avoid a GCC false warning. */
13649 enum enable_state orig_enable_state = 0;
13650 volatile struct gdb_exception e;
13652 TRY_CATCH (e, RETURN_MASK_ALL)
13654 struct watchpoint *w = (struct watchpoint *) bpt;
13656 orig_enable_state = bpt->enable_state;
13657 bpt->enable_state = bp_enabled;
13658 update_watchpoint (w, 1 /* reparse */);
13662 bpt->enable_state = orig_enable_state;
13663 exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
13669 if (bpt->enable_state != bp_permanent)
13670 bpt->enable_state = bp_enabled;
13672 bpt->enable_state = bp_enabled;
13674 /* Mark breakpoint locations modified. */
13675 mark_breakpoint_modified (bpt);
13677 if (target_supports_enable_disable_tracepoint ()
13678 && current_trace_status ()->running && is_tracepoint (bpt))
13680 struct bp_location *location;
13682 for (location = bpt->loc; location; location = location->next)
13683 target_enable_tracepoint (location);
13686 bpt->disposition = disposition;
13687 bpt->enable_count = count;
13688 update_global_location_list (1);
13689 breakpoints_changed ();
13691 observer_notify_breakpoint_modified (bpt);
13696 enable_breakpoint (struct breakpoint *bpt)
13698 enable_breakpoint_disp (bpt, bpt->disposition, 0);
13702 do_enable_breakpoint (struct breakpoint *bpt, void *arg)
13704 enable_breakpoint (bpt);
13707 /* A callback for map_breakpoint_numbers that calls
13708 enable_breakpoint. */
13711 do_map_enable_breakpoint (struct breakpoint *b, void *ignore)
13713 iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL);
13716 /* The enable command enables the specified breakpoints (or all defined
13717 breakpoints) so they once again become (or continue to be) effective
13718 in stopping the inferior. */
13721 enable_command (char *args, int from_tty)
13725 struct breakpoint *bpt;
13727 ALL_BREAKPOINTS (bpt)
13728 if (user_breakpoint_p (bpt))
13729 enable_breakpoint (bpt);
13731 else if (strchr (args, '.'))
13733 struct bp_location *loc = find_location_by_number (args);
13739 mark_breakpoint_location_modified (loc);
13741 if (target_supports_enable_disable_tracepoint ()
13742 && current_trace_status ()->running && loc->owner
13743 && is_tracepoint (loc->owner))
13744 target_enable_tracepoint (loc);
13746 update_global_location_list (1);
13749 map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL);
13752 /* This struct packages up disposition data for application to multiple
13762 do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg)
13764 struct disp_data disp_data = *(struct disp_data *) arg;
13766 enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count);
13770 do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore)
13772 struct disp_data disp = { disp_disable, 1 };
13774 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
13778 enable_once_command (char *args, int from_tty)
13780 map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL);
13784 do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr)
13786 struct disp_data disp = { disp_disable, *(int *) countptr };
13788 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
13792 enable_count_command (char *args, int from_tty)
13794 int count = get_number (&args);
13796 map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count);
13800 do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore)
13802 struct disp_data disp = { disp_del, 1 };
13804 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
13808 enable_delete_command (char *args, int from_tty)
13810 map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL);
13814 set_breakpoint_cmd (char *args, int from_tty)
13819 show_breakpoint_cmd (char *args, int from_tty)
13823 /* Invalidate last known value of any hardware watchpoint if
13824 the memory which that value represents has been written to by
13828 invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len,
13829 const bfd_byte *data)
13831 struct breakpoint *bp;
13833 ALL_BREAKPOINTS (bp)
13834 if (bp->enable_state == bp_enabled
13835 && bp->type == bp_hardware_watchpoint)
13837 struct watchpoint *wp = (struct watchpoint *) bp;
13839 if (wp->val_valid && wp->val)
13841 struct bp_location *loc;
13843 for (loc = bp->loc; loc != NULL; loc = loc->next)
13844 if (loc->loc_type == bp_loc_hardware_watchpoint
13845 && loc->address + loc->length > addr
13846 && addr + len > loc->address)
13848 value_free (wp->val);
13856 /* Use the last displayed codepoint's values, or nothing
13857 if they aren't valid. */
13859 struct symtabs_and_lines
13860 decode_line_spec_1 (char *string, int flags)
13862 struct symtabs_and_lines sals;
13865 error (_("Empty line specification."));
13866 if (last_displayed_sal_is_valid ())
13867 sals = decode_line_1 (&string, flags,
13868 get_last_displayed_symtab (),
13869 get_last_displayed_line ());
13871 sals = decode_line_1 (&string, flags, (struct symtab *) NULL, 0);
13873 error (_("Junk at end of line specification: %s"), string);
13877 /* Create and insert a raw software breakpoint at PC. Return an
13878 identifier, which should be used to remove the breakpoint later.
13879 In general, places which call this should be using something on the
13880 breakpoint chain instead; this function should be eliminated
13884 deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch,
13885 struct address_space *aspace, CORE_ADDR pc)
13887 struct bp_target_info *bp_tgt;
13889 bp_tgt = XZALLOC (struct bp_target_info);
13891 bp_tgt->placed_address_space = aspace;
13892 bp_tgt->placed_address = pc;
13894 if (target_insert_breakpoint (gdbarch, bp_tgt) != 0)
13896 /* Could not insert the breakpoint. */
13904 /* Remove a breakpoint BP inserted by
13905 deprecated_insert_raw_breakpoint. */
13908 deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp)
13910 struct bp_target_info *bp_tgt = bp;
13913 ret = target_remove_breakpoint (gdbarch, bp_tgt);
13919 /* One (or perhaps two) breakpoints used for software single
13922 static void *single_step_breakpoints[2];
13923 static struct gdbarch *single_step_gdbarch[2];
13925 /* Create and insert a breakpoint for software single step. */
13928 insert_single_step_breakpoint (struct gdbarch *gdbarch,
13929 struct address_space *aspace,
13934 if (single_step_breakpoints[0] == NULL)
13936 bpt_p = &single_step_breakpoints[0];
13937 single_step_gdbarch[0] = gdbarch;
13941 gdb_assert (single_step_breakpoints[1] == NULL);
13942 bpt_p = &single_step_breakpoints[1];
13943 single_step_gdbarch[1] = gdbarch;
13946 /* NOTE drow/2006-04-11: A future improvement to this function would
13947 be to only create the breakpoints once, and actually put them on
13948 the breakpoint chain. That would let us use set_raw_breakpoint.
13949 We could adjust the addresses each time they were needed. Doing
13950 this requires corresponding changes elsewhere where single step
13951 breakpoints are handled, however. So, for now, we use this. */
13953 *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc);
13954 if (*bpt_p == NULL)
13955 error (_("Could not insert single-step breakpoint at %s"),
13956 paddress (gdbarch, next_pc));
13959 /* Check if the breakpoints used for software single stepping
13960 were inserted or not. */
13963 single_step_breakpoints_inserted (void)
13965 return (single_step_breakpoints[0] != NULL
13966 || single_step_breakpoints[1] != NULL);
13969 /* Remove and delete any breakpoints used for software single step. */
13972 remove_single_step_breakpoints (void)
13974 gdb_assert (single_step_breakpoints[0] != NULL);
13976 /* See insert_single_step_breakpoint for more about this deprecated
13978 deprecated_remove_raw_breakpoint (single_step_gdbarch[0],
13979 single_step_breakpoints[0]);
13980 single_step_gdbarch[0] = NULL;
13981 single_step_breakpoints[0] = NULL;
13983 if (single_step_breakpoints[1] != NULL)
13985 deprecated_remove_raw_breakpoint (single_step_gdbarch[1],
13986 single_step_breakpoints[1]);
13987 single_step_gdbarch[1] = NULL;
13988 single_step_breakpoints[1] = NULL;
13992 /* Delete software single step breakpoints without removing them from
13993 the inferior. This is intended to be used if the inferior's address
13994 space where they were inserted is already gone, e.g. after exit or
13998 cancel_single_step_breakpoints (void)
14002 for (i = 0; i < 2; i++)
14003 if (single_step_breakpoints[i])
14005 xfree (single_step_breakpoints[i]);
14006 single_step_breakpoints[i] = NULL;
14007 single_step_gdbarch[i] = NULL;
14011 /* Detach software single-step breakpoints from INFERIOR_PTID without
14015 detach_single_step_breakpoints (void)
14019 for (i = 0; i < 2; i++)
14020 if (single_step_breakpoints[i])
14021 target_remove_breakpoint (single_step_gdbarch[i],
14022 single_step_breakpoints[i]);
14025 /* Check whether a software single-step breakpoint is inserted at
14029 single_step_breakpoint_inserted_here_p (struct address_space *aspace,
14034 for (i = 0; i < 2; i++)
14036 struct bp_target_info *bp_tgt = single_step_breakpoints[i];
14038 && breakpoint_address_match (bp_tgt->placed_address_space,
14039 bp_tgt->placed_address,
14047 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
14048 non-zero otherwise. */
14050 is_syscall_catchpoint_enabled (struct breakpoint *bp)
14052 if (syscall_catchpoint_p (bp)
14053 && bp->enable_state != bp_disabled
14054 && bp->enable_state != bp_call_disabled)
14061 catch_syscall_enabled (void)
14063 struct inferior *inf = current_inferior ();
14065 return inf->total_syscalls_count != 0;
14069 catching_syscall_number (int syscall_number)
14071 struct breakpoint *bp;
14073 ALL_BREAKPOINTS (bp)
14074 if (is_syscall_catchpoint_enabled (bp))
14076 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp;
14078 if (c->syscalls_to_be_caught)
14082 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
14084 if (syscall_number == iter)
14094 /* Complete syscall names. Used by "catch syscall". */
14096 catch_syscall_completer (struct cmd_list_element *cmd,
14097 char *text, char *word)
14099 const char **list = get_syscall_names ();
14101 = (list == NULL) ? NULL : complete_on_enum (list, text, word);
14107 /* Tracepoint-specific operations. */
14109 /* Set tracepoint count to NUM. */
14111 set_tracepoint_count (int num)
14113 tracepoint_count = num;
14114 set_internalvar_integer (lookup_internalvar ("tpnum"), num);
14118 trace_command (char *arg, int from_tty)
14120 if (create_breakpoint (get_current_arch (),
14122 NULL, 0, 1 /* parse arg */,
14124 bp_tracepoint /* type_wanted */,
14125 0 /* Ignore count */,
14126 pending_break_support,
14127 &tracepoint_breakpoint_ops,
14131 set_tracepoint_count (breakpoint_count);
14135 ftrace_command (char *arg, int from_tty)
14137 if (create_breakpoint (get_current_arch (),
14139 NULL, 0, 1 /* parse arg */,
14141 bp_fast_tracepoint /* type_wanted */,
14142 0 /* Ignore count */,
14143 pending_break_support,
14144 &tracepoint_breakpoint_ops,
14148 set_tracepoint_count (breakpoint_count);
14151 /* strace command implementation. Creates a static tracepoint. */
14154 strace_command (char *arg, int from_tty)
14156 struct breakpoint_ops *ops;
14158 /* Decide if we are dealing with a static tracepoint marker (`-m'),
14159 or with a normal static tracepoint. */
14160 if (arg && strncmp (arg, "-m", 2) == 0 && isspace (arg[2]))
14161 ops = &strace_marker_breakpoint_ops;
14163 ops = &tracepoint_breakpoint_ops;
14165 if (create_breakpoint (get_current_arch (),
14167 NULL, 0, 1 /* parse arg */,
14169 bp_static_tracepoint /* type_wanted */,
14170 0 /* Ignore count */,
14171 pending_break_support,
14176 set_tracepoint_count (breakpoint_count);
14179 /* Set up a fake reader function that gets command lines from a linked
14180 list that was acquired during tracepoint uploading. */
14182 static struct uploaded_tp *this_utp;
14183 static int next_cmd;
14186 read_uploaded_action (void)
14190 VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt);
14197 /* Given information about a tracepoint as recorded on a target (which
14198 can be either a live system or a trace file), attempt to create an
14199 equivalent GDB tracepoint. This is not a reliable process, since
14200 the target does not necessarily have all the information used when
14201 the tracepoint was originally defined. */
14203 struct tracepoint *
14204 create_tracepoint_from_upload (struct uploaded_tp *utp)
14206 char *addr_str, small_buf[100];
14207 struct tracepoint *tp;
14209 if (utp->at_string)
14210 addr_str = utp->at_string;
14213 /* In the absence of a source location, fall back to raw
14214 address. Since there is no way to confirm that the address
14215 means the same thing as when the trace was started, warn the
14217 warning (_("Uploaded tracepoint %d has no "
14218 "source location, using raw address"),
14220 sprintf (small_buf, "*%s", hex_string (utp->addr));
14221 addr_str = small_buf;
14224 /* There's not much we can do with a sequence of bytecodes. */
14225 if (utp->cond && !utp->cond_string)
14226 warning (_("Uploaded tracepoint %d condition "
14227 "has no source form, ignoring it"),
14230 if (!create_breakpoint (get_current_arch (),
14232 utp->cond_string, -1, 0 /* parse cond/thread */,
14234 utp->type /* type_wanted */,
14235 0 /* Ignore count */,
14236 pending_break_support,
14237 &tracepoint_breakpoint_ops,
14239 utp->enabled /* enabled */,
14243 set_tracepoint_count (breakpoint_count);
14245 /* Get the tracepoint we just created. */
14246 tp = get_tracepoint (tracepoint_count);
14247 gdb_assert (tp != NULL);
14251 sprintf (small_buf, "%d %d", utp->pass, tp->base.number);
14253 trace_pass_command (small_buf, 0);
14256 /* If we have uploaded versions of the original commands, set up a
14257 special-purpose "reader" function and call the usual command line
14258 reader, then pass the result to the breakpoint command-setting
14260 if (!VEC_empty (char_ptr, utp->cmd_strings))
14262 struct command_line *cmd_list;
14267 cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL);
14269 breakpoint_set_commands (&tp->base, cmd_list);
14271 else if (!VEC_empty (char_ptr, utp->actions)
14272 || !VEC_empty (char_ptr, utp->step_actions))
14273 warning (_("Uploaded tracepoint %d actions "
14274 "have no source form, ignoring them"),
14277 /* Copy any status information that might be available. */
14278 tp->base.hit_count = utp->hit_count;
14279 tp->traceframe_usage = utp->traceframe_usage;
14284 /* Print information on tracepoint number TPNUM_EXP, or all if
14288 tracepoints_info (char *args, int from_tty)
14290 struct ui_out *uiout = current_uiout;
14293 num_printed = breakpoint_1 (args, 0, is_tracepoint);
14295 if (num_printed == 0)
14297 if (args == NULL || *args == '\0')
14298 ui_out_message (uiout, 0, "No tracepoints.\n");
14300 ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args);
14303 default_collect_info ();
14306 /* The 'enable trace' command enables tracepoints.
14307 Not supported by all targets. */
14309 enable_trace_command (char *args, int from_tty)
14311 enable_command (args, from_tty);
14314 /* The 'disable trace' command disables tracepoints.
14315 Not supported by all targets. */
14317 disable_trace_command (char *args, int from_tty)
14319 disable_command (args, from_tty);
14322 /* Remove a tracepoint (or all if no argument). */
14324 delete_trace_command (char *arg, int from_tty)
14326 struct breakpoint *b, *b_tmp;
14332 int breaks_to_delete = 0;
14334 /* Delete all breakpoints if no argument.
14335 Do not delete internal or call-dummy breakpoints, these
14336 have to be deleted with an explicit breakpoint number
14338 ALL_TRACEPOINTS (b)
14339 if (is_tracepoint (b) && user_breakpoint_p (b))
14341 breaks_to_delete = 1;
14345 /* Ask user only if there are some breakpoints to delete. */
14347 || (breaks_to_delete && query (_("Delete all tracepoints? "))))
14349 ALL_BREAKPOINTS_SAFE (b, b_tmp)
14350 if (is_tracepoint (b) && user_breakpoint_p (b))
14351 delete_breakpoint (b);
14355 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
14358 /* Helper function for trace_pass_command. */
14361 trace_pass_set_count (struct tracepoint *tp, int count, int from_tty)
14363 tp->pass_count = count;
14364 observer_notify_tracepoint_modified (tp->base.number);
14366 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
14367 tp->base.number, count);
14370 /* Set passcount for tracepoint.
14372 First command argument is passcount, second is tracepoint number.
14373 If tracepoint number omitted, apply to most recently defined.
14374 Also accepts special argument "all". */
14377 trace_pass_command (char *args, int from_tty)
14379 struct tracepoint *t1;
14380 unsigned int count;
14382 if (args == 0 || *args == 0)
14383 error (_("passcount command requires an "
14384 "argument (count + optional TP num)"));
14386 count = strtoul (args, &args, 10); /* Count comes first, then TP num. */
14388 while (*args && isspace ((int) *args))
14391 if (*args && strncasecmp (args, "all", 3) == 0)
14393 struct breakpoint *b;
14395 args += 3; /* Skip special argument "all". */
14397 error (_("Junk at end of arguments."));
14399 ALL_TRACEPOINTS (b)
14401 t1 = (struct tracepoint *) b;
14402 trace_pass_set_count (t1, count, from_tty);
14405 else if (*args == '\0')
14407 t1 = get_tracepoint_by_number (&args, NULL, 1);
14409 trace_pass_set_count (t1, count, from_tty);
14413 struct get_number_or_range_state state;
14415 init_number_or_range (&state, args);
14416 while (!state.finished)
14418 t1 = get_tracepoint_by_number (&args, &state, 1);
14420 trace_pass_set_count (t1, count, from_tty);
14425 struct tracepoint *
14426 get_tracepoint (int num)
14428 struct breakpoint *t;
14430 ALL_TRACEPOINTS (t)
14431 if (t->number == num)
14432 return (struct tracepoint *) t;
14437 /* Find the tracepoint with the given target-side number (which may be
14438 different from the tracepoint number after disconnecting and
14441 struct tracepoint *
14442 get_tracepoint_by_number_on_target (int num)
14444 struct breakpoint *b;
14446 ALL_TRACEPOINTS (b)
14448 struct tracepoint *t = (struct tracepoint *) b;
14450 if (t->number_on_target == num)
14457 /* Utility: parse a tracepoint number and look it up in the list.
14458 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
14459 If OPTIONAL_P is true, then if the argument is missing, the most
14460 recent tracepoint (tracepoint_count) is returned. */
14461 struct tracepoint *
14462 get_tracepoint_by_number (char **arg,
14463 struct get_number_or_range_state *state,
14466 extern int tracepoint_count;
14467 struct breakpoint *t;
14469 char *instring = arg == NULL ? NULL : *arg;
14473 gdb_assert (!state->finished);
14474 tpnum = get_number_or_range (state);
14476 else if (arg == NULL || *arg == NULL || ! **arg)
14479 tpnum = tracepoint_count;
14481 error_no_arg (_("tracepoint number"));
14484 tpnum = get_number (arg);
14488 if (instring && *instring)
14489 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
14492 printf_filtered (_("Tracepoint argument missing "
14493 "and no previous tracepoint\n"));
14497 ALL_TRACEPOINTS (t)
14498 if (t->number == tpnum)
14500 return (struct tracepoint *) t;
14503 printf_unfiltered ("No tracepoint number %d.\n", tpnum);
14508 print_recreate_thread (struct breakpoint *b, struct ui_file *fp)
14510 if (b->thread != -1)
14511 fprintf_unfiltered (fp, " thread %d", b->thread);
14514 fprintf_unfiltered (fp, " task %d", b->task);
14516 fprintf_unfiltered (fp, "\n");
14519 /* Save information on user settable breakpoints (watchpoints, etc) to
14520 a new script file named FILENAME. If FILTER is non-NULL, call it
14521 on each breakpoint and only include the ones for which it returns
14525 save_breakpoints (char *filename, int from_tty,
14526 int (*filter) (const struct breakpoint *))
14528 struct breakpoint *tp;
14531 struct cleanup *cleanup;
14532 struct ui_file *fp;
14533 int extra_trace_bits = 0;
14535 if (filename == 0 || *filename == 0)
14536 error (_("Argument required (file name in which to save)"));
14538 /* See if we have anything to save. */
14539 ALL_BREAKPOINTS (tp)
14541 /* Skip internal and momentary breakpoints. */
14542 if (!user_breakpoint_p (tp))
14545 /* If we have a filter, only save the breakpoints it accepts. */
14546 if (filter && !filter (tp))
14551 if (is_tracepoint (tp))
14553 extra_trace_bits = 1;
14555 /* We can stop searching. */
14562 warning (_("Nothing to save."));
14566 pathname = tilde_expand (filename);
14567 cleanup = make_cleanup (xfree, pathname);
14568 fp = gdb_fopen (pathname, "w");
14570 error (_("Unable to open file '%s' for saving (%s)"),
14571 filename, safe_strerror (errno));
14572 make_cleanup_ui_file_delete (fp);
14574 if (extra_trace_bits)
14575 save_trace_state_variables (fp);
14577 ALL_BREAKPOINTS (tp)
14579 /* Skip internal and momentary breakpoints. */
14580 if (!user_breakpoint_p (tp))
14583 /* If we have a filter, only save the breakpoints it accepts. */
14584 if (filter && !filter (tp))
14587 tp->ops->print_recreate (tp, fp);
14589 /* Note, we can't rely on tp->number for anything, as we can't
14590 assume the recreated breakpoint numbers will match. Use $bpnum
14593 if (tp->cond_string)
14594 fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string);
14596 if (tp->ignore_count)
14597 fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count);
14601 volatile struct gdb_exception ex;
14603 fprintf_unfiltered (fp, " commands\n");
14605 ui_out_redirect (current_uiout, fp);
14606 TRY_CATCH (ex, RETURN_MASK_ALL)
14608 print_command_lines (current_uiout, tp->commands->commands, 2);
14610 ui_out_redirect (current_uiout, NULL);
14613 throw_exception (ex);
14615 fprintf_unfiltered (fp, " end\n");
14618 if (tp->enable_state == bp_disabled)
14619 fprintf_unfiltered (fp, "disable\n");
14621 /* If this is a multi-location breakpoint, check if the locations
14622 should be individually disabled. Watchpoint locations are
14623 special, and not user visible. */
14624 if (!is_watchpoint (tp) && tp->loc && tp->loc->next)
14626 struct bp_location *loc;
14629 for (loc = tp->loc; loc != NULL; loc = loc->next, n++)
14631 fprintf_unfiltered (fp, "disable $bpnum.%d\n", n);
14635 if (extra_trace_bits && *default_collect)
14636 fprintf_unfiltered (fp, "set default-collect %s\n", default_collect);
14638 do_cleanups (cleanup);
14640 printf_filtered (_("Saved to file '%s'.\n"), filename);
14643 /* The `save breakpoints' command. */
14646 save_breakpoints_command (char *args, int from_tty)
14648 save_breakpoints (args, from_tty, NULL);
14651 /* The `save tracepoints' command. */
14654 save_tracepoints_command (char *args, int from_tty)
14656 save_breakpoints (args, from_tty, is_tracepoint);
14659 /* Create a vector of all tracepoints. */
14661 VEC(breakpoint_p) *
14662 all_tracepoints (void)
14664 VEC(breakpoint_p) *tp_vec = 0;
14665 struct breakpoint *tp;
14667 ALL_TRACEPOINTS (tp)
14669 VEC_safe_push (breakpoint_p, tp_vec, tp);
14676 /* This help string is used for the break, hbreak, tbreak and thbreak
14677 commands. It is defined as a macro to prevent duplication.
14678 COMMAND should be a string constant containing the name of the
14680 #define BREAK_ARGS_HELP(command) \
14681 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
14682 LOCATION may be a line number, function name, or \"*\" and an address.\n\
14683 If a line number is specified, break at start of code for that line.\n\
14684 If a function is specified, break at start of code for that function.\n\
14685 If an address is specified, break at that exact address.\n\
14686 With no LOCATION, uses current execution address of the selected\n\
14687 stack frame. This is useful for breaking on return to a stack frame.\n\
14689 THREADNUM is the number from \"info threads\".\n\
14690 CONDITION is a boolean expression.\n\
14692 Multiple breakpoints at one place are permitted, and useful if their\n\
14693 conditions are different.\n\
14695 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
14697 /* List of subcommands for "catch". */
14698 static struct cmd_list_element *catch_cmdlist;
14700 /* List of subcommands for "tcatch". */
14701 static struct cmd_list_element *tcatch_cmdlist;
14704 add_catch_command (char *name, char *docstring,
14705 void (*sfunc) (char *args, int from_tty,
14706 struct cmd_list_element *command),
14707 char **(*completer) (struct cmd_list_element *cmd,
14708 char *text, char *word),
14709 void *user_data_catch,
14710 void *user_data_tcatch)
14712 struct cmd_list_element *command;
14714 command = add_cmd (name, class_breakpoint, NULL, docstring,
14716 set_cmd_sfunc (command, sfunc);
14717 set_cmd_context (command, user_data_catch);
14718 set_cmd_completer (command, completer);
14720 command = add_cmd (name, class_breakpoint, NULL, docstring,
14722 set_cmd_sfunc (command, sfunc);
14723 set_cmd_context (command, user_data_tcatch);
14724 set_cmd_completer (command, completer);
14728 clear_syscall_counts (struct inferior *inf)
14730 inf->total_syscalls_count = 0;
14731 inf->any_syscall_count = 0;
14732 VEC_free (int, inf->syscalls_counts);
14736 save_command (char *arg, int from_tty)
14738 printf_unfiltered (_("\"save\" must be followed by "
14739 "the name of a save subcommand.\n"));
14740 help_list (save_cmdlist, "save ", -1, gdb_stdout);
14743 struct breakpoint *
14744 iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *),
14747 struct breakpoint *b, *b_tmp;
14749 ALL_BREAKPOINTS_SAFE (b, b_tmp)
14751 if ((*callback) (b, data))
14758 /* Zero if any of the breakpoint's locations could be a location where
14759 functions have been inlined, nonzero otherwise. */
14762 is_non_inline_function (struct breakpoint *b)
14764 /* The shared library event breakpoint is set on the address of a
14765 non-inline function. */
14766 if (b->type == bp_shlib_event)
14772 /* Nonzero if the specified PC cannot be a location where functions
14773 have been inlined. */
14776 pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc,
14777 const struct target_waitstatus *ws)
14779 struct breakpoint *b;
14780 struct bp_location *bl;
14782 ALL_BREAKPOINTS (b)
14784 if (!is_non_inline_function (b))
14787 for (bl = b->loc; bl != NULL; bl = bl->next)
14789 if (!bl->shlib_disabled
14790 && bpstat_check_location (bl, aspace, pc, ws))
14799 initialize_breakpoint_ops (void)
14801 static int initialized = 0;
14803 struct breakpoint_ops *ops;
14809 /* The breakpoint_ops structure to be inherit by all kinds of
14810 breakpoints (real breakpoints, i.e., user "break" breakpoints,
14811 internal and momentary breakpoints, etc.). */
14812 ops = &bkpt_base_breakpoint_ops;
14813 *ops = base_breakpoint_ops;
14814 ops->re_set = bkpt_re_set;
14815 ops->insert_location = bkpt_insert_location;
14816 ops->remove_location = bkpt_remove_location;
14817 ops->breakpoint_hit = bkpt_breakpoint_hit;
14818 ops->create_sals_from_address = bkpt_create_sals_from_address;
14819 ops->create_breakpoints_sal = bkpt_create_breakpoints_sal;
14820 ops->decode_linespec = bkpt_decode_linespec;
14822 /* The breakpoint_ops structure to be used in regular breakpoints. */
14823 ops = &bkpt_breakpoint_ops;
14824 *ops = bkpt_base_breakpoint_ops;
14825 ops->re_set = bkpt_re_set;
14826 ops->resources_needed = bkpt_resources_needed;
14827 ops->print_it = bkpt_print_it;
14828 ops->print_mention = bkpt_print_mention;
14829 ops->print_recreate = bkpt_print_recreate;
14831 /* Ranged breakpoints. */
14832 ops = &ranged_breakpoint_ops;
14833 *ops = bkpt_breakpoint_ops;
14834 ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint;
14835 ops->resources_needed = resources_needed_ranged_breakpoint;
14836 ops->print_it = print_it_ranged_breakpoint;
14837 ops->print_one = print_one_ranged_breakpoint;
14838 ops->print_one_detail = print_one_detail_ranged_breakpoint;
14839 ops->print_mention = print_mention_ranged_breakpoint;
14840 ops->print_recreate = print_recreate_ranged_breakpoint;
14842 /* Internal breakpoints. */
14843 ops = &internal_breakpoint_ops;
14844 *ops = bkpt_base_breakpoint_ops;
14845 ops->re_set = internal_bkpt_re_set;
14846 ops->check_status = internal_bkpt_check_status;
14847 ops->print_it = internal_bkpt_print_it;
14848 ops->print_mention = internal_bkpt_print_mention;
14850 /* Momentary breakpoints. */
14851 ops = &momentary_breakpoint_ops;
14852 *ops = bkpt_base_breakpoint_ops;
14853 ops->re_set = momentary_bkpt_re_set;
14854 ops->check_status = momentary_bkpt_check_status;
14855 ops->print_it = momentary_bkpt_print_it;
14856 ops->print_mention = momentary_bkpt_print_mention;
14858 /* GNU v3 exception catchpoints. */
14859 ops = &gnu_v3_exception_catchpoint_ops;
14860 *ops = bkpt_breakpoint_ops;
14861 ops->print_it = print_it_exception_catchpoint;
14862 ops->print_one = print_one_exception_catchpoint;
14863 ops->print_mention = print_mention_exception_catchpoint;
14864 ops->print_recreate = print_recreate_exception_catchpoint;
14867 ops = &watchpoint_breakpoint_ops;
14868 *ops = base_breakpoint_ops;
14869 ops->dtor = dtor_watchpoint;
14870 ops->re_set = re_set_watchpoint;
14871 ops->insert_location = insert_watchpoint;
14872 ops->remove_location = remove_watchpoint;
14873 ops->breakpoint_hit = breakpoint_hit_watchpoint;
14874 ops->check_status = check_status_watchpoint;
14875 ops->resources_needed = resources_needed_watchpoint;
14876 ops->works_in_software_mode = works_in_software_mode_watchpoint;
14877 ops->print_it = print_it_watchpoint;
14878 ops->print_mention = print_mention_watchpoint;
14879 ops->print_recreate = print_recreate_watchpoint;
14881 /* Masked watchpoints. */
14882 ops = &masked_watchpoint_breakpoint_ops;
14883 *ops = watchpoint_breakpoint_ops;
14884 ops->insert_location = insert_masked_watchpoint;
14885 ops->remove_location = remove_masked_watchpoint;
14886 ops->resources_needed = resources_needed_masked_watchpoint;
14887 ops->works_in_software_mode = works_in_software_mode_masked_watchpoint;
14888 ops->print_it = print_it_masked_watchpoint;
14889 ops->print_one_detail = print_one_detail_masked_watchpoint;
14890 ops->print_mention = print_mention_masked_watchpoint;
14891 ops->print_recreate = print_recreate_masked_watchpoint;
14894 ops = &tracepoint_breakpoint_ops;
14895 *ops = base_breakpoint_ops;
14896 ops->re_set = tracepoint_re_set;
14897 ops->breakpoint_hit = tracepoint_breakpoint_hit;
14898 ops->print_one_detail = tracepoint_print_one_detail;
14899 ops->print_mention = tracepoint_print_mention;
14900 ops->print_recreate = tracepoint_print_recreate;
14901 ops->create_sals_from_address = tracepoint_create_sals_from_address;
14902 ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal;
14903 ops->decode_linespec = tracepoint_decode_linespec;
14905 /* Static tracepoints with marker (`-m'). */
14906 ops = &strace_marker_breakpoint_ops;
14907 *ops = tracepoint_breakpoint_ops;
14908 ops->create_sals_from_address = strace_marker_create_sals_from_address;
14909 ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal;
14910 ops->decode_linespec = strace_marker_decode_linespec;
14912 /* Fork catchpoints. */
14913 ops = &catch_fork_breakpoint_ops;
14914 *ops = base_breakpoint_ops;
14915 ops->insert_location = insert_catch_fork;
14916 ops->remove_location = remove_catch_fork;
14917 ops->breakpoint_hit = breakpoint_hit_catch_fork;
14918 ops->print_it = print_it_catch_fork;
14919 ops->print_one = print_one_catch_fork;
14920 ops->print_mention = print_mention_catch_fork;
14921 ops->print_recreate = print_recreate_catch_fork;
14923 /* Vfork catchpoints. */
14924 ops = &catch_vfork_breakpoint_ops;
14925 *ops = base_breakpoint_ops;
14926 ops->insert_location = insert_catch_vfork;
14927 ops->remove_location = remove_catch_vfork;
14928 ops->breakpoint_hit = breakpoint_hit_catch_vfork;
14929 ops->print_it = print_it_catch_vfork;
14930 ops->print_one = print_one_catch_vfork;
14931 ops->print_mention = print_mention_catch_vfork;
14932 ops->print_recreate = print_recreate_catch_vfork;
14934 /* Exec catchpoints. */
14935 ops = &catch_exec_breakpoint_ops;
14936 *ops = base_breakpoint_ops;
14937 ops->dtor = dtor_catch_exec;
14938 ops->insert_location = insert_catch_exec;
14939 ops->remove_location = remove_catch_exec;
14940 ops->breakpoint_hit = breakpoint_hit_catch_exec;
14941 ops->print_it = print_it_catch_exec;
14942 ops->print_one = print_one_catch_exec;
14943 ops->print_mention = print_mention_catch_exec;
14944 ops->print_recreate = print_recreate_catch_exec;
14946 /* Syscall catchpoints. */
14947 ops = &catch_syscall_breakpoint_ops;
14948 *ops = base_breakpoint_ops;
14949 ops->dtor = dtor_catch_syscall;
14950 ops->insert_location = insert_catch_syscall;
14951 ops->remove_location = remove_catch_syscall;
14952 ops->breakpoint_hit = breakpoint_hit_catch_syscall;
14953 ops->print_it = print_it_catch_syscall;
14954 ops->print_one = print_one_catch_syscall;
14955 ops->print_mention = print_mention_catch_syscall;
14956 ops->print_recreate = print_recreate_catch_syscall;
14958 /* Solib-related catchpoints. */
14959 ops = &catch_solib_breakpoint_ops;
14960 *ops = base_breakpoint_ops;
14961 ops->dtor = dtor_catch_solib;
14962 ops->insert_location = insert_catch_solib;
14963 ops->remove_location = remove_catch_solib;
14964 ops->breakpoint_hit = breakpoint_hit_catch_solib;
14965 ops->check_status = check_status_catch_solib;
14966 ops->print_it = print_it_catch_solib;
14967 ops->print_one = print_one_catch_solib;
14968 ops->print_mention = print_mention_catch_solib;
14969 ops->print_recreate = print_recreate_catch_solib;
14973 _initialize_breakpoint (void)
14975 struct cmd_list_element *c;
14977 initialize_breakpoint_ops ();
14979 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
14980 observer_attach_inferior_exit (clear_syscall_counts);
14981 observer_attach_memory_changed (invalidate_bp_value_on_memory_change);
14983 breakpoint_objfile_key = register_objfile_data ();
14985 breakpoint_chain = 0;
14986 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
14987 before a breakpoint is set. */
14988 breakpoint_count = 0;
14990 tracepoint_count = 0;
14992 add_com ("ignore", class_breakpoint, ignore_command, _("\
14993 Set ignore-count of breakpoint number N to COUNT.\n\
14994 Usage is `ignore N COUNT'."));
14996 add_com_alias ("bc", "ignore", class_breakpoint, 1);
14998 add_com ("commands", class_breakpoint, commands_command, _("\
14999 Set commands to be executed when a breakpoint is hit.\n\
15000 Give breakpoint number as argument after \"commands\".\n\
15001 With no argument, the targeted breakpoint is the last one set.\n\
15002 The commands themselves follow starting on the next line.\n\
15003 Type a line containing \"end\" to indicate the end of them.\n\
15004 Give \"silent\" as the first line to make the breakpoint silent;\n\
15005 then no output is printed when it is hit, except what the commands print."));
15007 add_com ("condition", class_breakpoint, condition_command, _("\
15008 Specify breakpoint number N to break only if COND is true.\n\
15009 Usage is `condition N COND', where N is an integer and COND is an\n\
15010 expression to be evaluated whenever breakpoint N is reached."));
15012 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
15013 Set a temporary breakpoint.\n\
15014 Like \"break\" except the breakpoint is only temporary,\n\
15015 so it will be deleted when hit. Equivalent to \"break\" followed\n\
15016 by using \"enable delete\" on the breakpoint number.\n\
15018 BREAK_ARGS_HELP ("tbreak")));
15019 set_cmd_completer (c, location_completer);
15021 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
15022 Set a hardware assisted breakpoint.\n\
15023 Like \"break\" except the breakpoint requires hardware support,\n\
15024 some target hardware may not have this support.\n\
15026 BREAK_ARGS_HELP ("hbreak")));
15027 set_cmd_completer (c, location_completer);
15029 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
15030 Set a temporary hardware assisted breakpoint.\n\
15031 Like \"hbreak\" except the breakpoint is only temporary,\n\
15032 so it will be deleted when hit.\n\
15034 BREAK_ARGS_HELP ("thbreak")));
15035 set_cmd_completer (c, location_completer);
15037 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
15038 Enable some breakpoints.\n\
15039 Give breakpoint numbers (separated by spaces) as arguments.\n\
15040 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15041 This is used to cancel the effect of the \"disable\" command.\n\
15042 With a subcommand you can enable temporarily."),
15043 &enablelist, "enable ", 1, &cmdlist);
15045 add_com ("ab", class_breakpoint, enable_command, _("\
15046 Enable some breakpoints.\n\
15047 Give breakpoint numbers (separated by spaces) as arguments.\n\
15048 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15049 This is used to cancel the effect of the \"disable\" command.\n\
15050 With a subcommand you can enable temporarily."));
15052 add_com_alias ("en", "enable", class_breakpoint, 1);
15054 add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
15055 Enable some breakpoints.\n\
15056 Give breakpoint numbers (separated by spaces) as arguments.\n\
15057 This is used to cancel the effect of the \"disable\" command.\n\
15058 May be abbreviated to simply \"enable\".\n"),
15059 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
15061 add_cmd ("once", no_class, enable_once_command, _("\
15062 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15063 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15066 add_cmd ("delete", no_class, enable_delete_command, _("\
15067 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15068 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15071 add_cmd ("count", no_class, enable_count_command, _("\
15072 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15073 If a breakpoint is hit while enabled in this fashion,\n\
15074 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15077 add_cmd ("delete", no_class, enable_delete_command, _("\
15078 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15079 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15082 add_cmd ("once", no_class, enable_once_command, _("\
15083 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15084 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15087 add_cmd ("count", no_class, enable_count_command, _("\
15088 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15089 If a breakpoint is hit while enabled in this fashion,\n\
15090 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15093 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
15094 Disable some breakpoints.\n\
15095 Arguments are breakpoint numbers with spaces in between.\n\
15096 To disable all breakpoints, give no argument.\n\
15097 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
15098 &disablelist, "disable ", 1, &cmdlist);
15099 add_com_alias ("dis", "disable", class_breakpoint, 1);
15100 add_com_alias ("disa", "disable", class_breakpoint, 1);
15102 add_com ("sb", class_breakpoint, disable_command, _("\
15103 Disable some breakpoints.\n\
15104 Arguments are breakpoint numbers with spaces in between.\n\
15105 To disable all breakpoints, give no argument.\n\
15106 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
15108 add_cmd ("breakpoints", class_alias, disable_command, _("\
15109 Disable some breakpoints.\n\
15110 Arguments are breakpoint numbers with spaces in between.\n\
15111 To disable all breakpoints, give no argument.\n\
15112 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
15113 This command may be abbreviated \"disable\"."),
15116 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
15117 Delete some breakpoints or auto-display expressions.\n\
15118 Arguments are breakpoint numbers with spaces in between.\n\
15119 To delete all breakpoints, give no argument.\n\
15121 Also a prefix command for deletion of other GDB objects.\n\
15122 The \"unset\" command is also an alias for \"delete\"."),
15123 &deletelist, "delete ", 1, &cmdlist);
15124 add_com_alias ("d", "delete", class_breakpoint, 1);
15125 add_com_alias ("del", "delete", class_breakpoint, 1);
15127 add_com ("db", class_breakpoint, delete_command, _("\
15128 Delete some breakpoints.\n\
15129 Arguments are breakpoint numbers with spaces in between.\n\
15130 To delete all breakpoints, give no argument.\n"));
15132 add_cmd ("breakpoints", class_alias, delete_command, _("\
15133 Delete some breakpoints or auto-display expressions.\n\
15134 Arguments are breakpoint numbers with spaces in between.\n\
15135 To delete all breakpoints, give no argument.\n\
15136 This command may be abbreviated \"delete\"."),
15139 add_com ("clear", class_breakpoint, clear_command, _("\
15140 Clear breakpoint at specified line or function.\n\
15141 Argument may be line number, function name, or \"*\" and an address.\n\
15142 If line number is specified, all breakpoints in that line are cleared.\n\
15143 If function is specified, breakpoints at beginning of function are cleared.\n\
15144 If an address is specified, breakpoints at that address are cleared.\n\
15146 With no argument, clears all breakpoints in the line that the selected frame\n\
15147 is executing in.\n\
15149 See also the \"delete\" command which clears breakpoints by number."));
15150 add_com_alias ("cl", "clear", class_breakpoint, 1);
15152 c = add_com ("break", class_breakpoint, break_command, _("\
15153 Set breakpoint at specified line or function.\n"
15154 BREAK_ARGS_HELP ("break")));
15155 set_cmd_completer (c, location_completer);
15157 add_com_alias ("b", "break", class_run, 1);
15158 add_com_alias ("br", "break", class_run, 1);
15159 add_com_alias ("bre", "break", class_run, 1);
15160 add_com_alias ("brea", "break", class_run, 1);
15163 add_com_alias ("ba", "break", class_breakpoint, 1);
15167 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
15168 Break in function/address or break at a line in the current file."),
15169 &stoplist, "stop ", 1, &cmdlist);
15170 add_cmd ("in", class_breakpoint, stopin_command,
15171 _("Break in function or address."), &stoplist);
15172 add_cmd ("at", class_breakpoint, stopat_command,
15173 _("Break at a line in the current file."), &stoplist);
15174 add_com ("status", class_info, breakpoints_info, _("\
15175 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15176 The \"Type\" column indicates one of:\n\
15177 \tbreakpoint - normal breakpoint\n\
15178 \twatchpoint - watchpoint\n\
15179 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15180 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15181 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15182 address and file/line number respectively.\n\
15184 Convenience variable \"$_\" and default examine address for \"x\"\n\
15185 are set to the address of the last breakpoint listed unless the command\n\
15186 is prefixed with \"server \".\n\n\
15187 Convenience variable \"$bpnum\" contains the number of the last\n\
15188 breakpoint set."));
15191 add_info ("breakpoints", breakpoints_info, _("\
15192 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
15193 The \"Type\" column indicates one of:\n\
15194 \tbreakpoint - normal breakpoint\n\
15195 \twatchpoint - watchpoint\n\
15196 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15197 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15198 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15199 address and file/line number respectively.\n\
15201 Convenience variable \"$_\" and default examine address for \"x\"\n\
15202 are set to the address of the last breakpoint listed unless the command\n\
15203 is prefixed with \"server \".\n\n\
15204 Convenience variable \"$bpnum\" contains the number of the last\n\
15205 breakpoint set."));
15207 add_info_alias ("b", "breakpoints", 1);
15210 add_com ("lb", class_breakpoint, breakpoints_info, _("\
15211 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15212 The \"Type\" column indicates one of:\n\
15213 \tbreakpoint - normal breakpoint\n\
15214 \twatchpoint - watchpoint\n\
15215 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15216 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15217 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15218 address and file/line number respectively.\n\
15220 Convenience variable \"$_\" and default examine address for \"x\"\n\
15221 are set to the address of the last breakpoint listed unless the command\n\
15222 is prefixed with \"server \".\n\n\
15223 Convenience variable \"$bpnum\" contains the number of the last\n\
15224 breakpoint set."));
15226 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
15227 Status of all breakpoints, or breakpoint number NUMBER.\n\
15228 The \"Type\" column indicates one of:\n\
15229 \tbreakpoint - normal breakpoint\n\
15230 \twatchpoint - watchpoint\n\
15231 \tlongjmp - internal breakpoint used to step through longjmp()\n\
15232 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
15233 \tuntil - internal breakpoint used by the \"until\" command\n\
15234 \tfinish - internal breakpoint used by the \"finish\" command\n\
15235 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15236 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15237 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15238 address and file/line number respectively.\n\
15240 Convenience variable \"$_\" and default examine address for \"x\"\n\
15241 are set to the address of the last breakpoint listed unless the command\n\
15242 is prefixed with \"server \".\n\n\
15243 Convenience variable \"$bpnum\" contains the number of the last\n\
15245 &maintenanceinfolist);
15247 add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\
15248 Set catchpoints to catch events."),
15249 &catch_cmdlist, "catch ",
15250 0/*allow-unknown*/, &cmdlist);
15252 add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\
15253 Set temporary catchpoints to catch events."),
15254 &tcatch_cmdlist, "tcatch ",
15255 0/*allow-unknown*/, &cmdlist);
15257 /* Add catch and tcatch sub-commands. */
15258 add_catch_command ("catch", _("\
15259 Catch an exception, when caught."),
15260 catch_catch_command,
15264 add_catch_command ("throw", _("\
15265 Catch an exception, when thrown."),
15266 catch_throw_command,
15270 add_catch_command ("fork", _("Catch calls to fork."),
15271 catch_fork_command_1,
15273 (void *) (uintptr_t) catch_fork_permanent,
15274 (void *) (uintptr_t) catch_fork_temporary);
15275 add_catch_command ("vfork", _("Catch calls to vfork."),
15276 catch_fork_command_1,
15278 (void *) (uintptr_t) catch_vfork_permanent,
15279 (void *) (uintptr_t) catch_vfork_temporary);
15280 add_catch_command ("exec", _("Catch calls to exec."),
15281 catch_exec_command_1,
15285 add_catch_command ("load", _("Catch loads of shared libraries.\n\
15286 Usage: catch load [REGEX]\n\
15287 If REGEX is given, only stop for libraries matching the regular expression."),
15288 catch_load_command_1,
15292 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
15293 Usage: catch unload [REGEX]\n\
15294 If REGEX is given, only stop for libraries matching the regular expression."),
15295 catch_unload_command_1,
15299 add_catch_command ("syscall", _("\
15300 Catch system calls by their names and/or numbers.\n\
15301 Arguments say which system calls to catch. If no arguments\n\
15302 are given, every system call will be caught.\n\
15303 Arguments, if given, should be one or more system call names\n\
15304 (if your system supports that), or system call numbers."),
15305 catch_syscall_command_1,
15306 catch_syscall_completer,
15310 c = add_com ("watch", class_breakpoint, watch_command, _("\
15311 Set a watchpoint for an expression.\n\
15312 Usage: watch [-l|-location] EXPRESSION\n\
15313 A watchpoint stops execution of your program whenever the value of\n\
15314 an expression changes.\n\
15315 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15316 the memory to which it refers."));
15317 set_cmd_completer (c, expression_completer);
15319 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
15320 Set a read watchpoint for an expression.\n\
15321 Usage: rwatch [-l|-location] EXPRESSION\n\
15322 A watchpoint stops execution of your program whenever the value of\n\
15323 an expression is read.\n\
15324 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15325 the memory to which it refers."));
15326 set_cmd_completer (c, expression_completer);
15328 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
15329 Set a watchpoint for an expression.\n\
15330 Usage: awatch [-l|-location] EXPRESSION\n\
15331 A watchpoint stops execution of your program whenever the value of\n\
15332 an expression is either read or written.\n\
15333 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15334 the memory to which it refers."));
15335 set_cmd_completer (c, expression_completer);
15337 add_info ("watchpoints", watchpoints_info, _("\
15338 Status of specified watchpoints (all watchpoints if no argument)."));
15340 /* XXX: cagney/2005-02-23: This should be a boolean, and should
15341 respond to changes - contrary to the description. */
15342 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
15343 &can_use_hw_watchpoints, _("\
15344 Set debugger's willingness to use watchpoint hardware."), _("\
15345 Show debugger's willingness to use watchpoint hardware."), _("\
15346 If zero, gdb will not use hardware for new watchpoints, even if\n\
15347 such is available. (However, any hardware watchpoints that were\n\
15348 created before setting this to nonzero, will continue to use watchpoint\n\
15351 show_can_use_hw_watchpoints,
15352 &setlist, &showlist);
15354 can_use_hw_watchpoints = 1;
15356 /* Tracepoint manipulation commands. */
15358 c = add_com ("trace", class_breakpoint, trace_command, _("\
15359 Set a tracepoint at specified line or function.\n\
15361 BREAK_ARGS_HELP ("trace") "\n\
15362 Do \"help tracepoints\" for info on other tracepoint commands."));
15363 set_cmd_completer (c, location_completer);
15365 add_com_alias ("tp", "trace", class_alias, 0);
15366 add_com_alias ("tr", "trace", class_alias, 1);
15367 add_com_alias ("tra", "trace", class_alias, 1);
15368 add_com_alias ("trac", "trace", class_alias, 1);
15370 c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\
15371 Set a fast tracepoint at specified line or function.\n\
15373 BREAK_ARGS_HELP ("ftrace") "\n\
15374 Do \"help tracepoints\" for info on other tracepoint commands."));
15375 set_cmd_completer (c, location_completer);
15377 c = add_com ("strace", class_breakpoint, strace_command, _("\
15378 Set a static tracepoint at specified line, function or marker.\n\
15380 strace [LOCATION] [if CONDITION]\n\
15381 LOCATION may be a line number, function name, \"*\" and an address,\n\
15382 or -m MARKER_ID.\n\
15383 If a line number is specified, probe the marker at start of code\n\
15384 for that line. If a function is specified, probe the marker at start\n\
15385 of code for that function. If an address is specified, probe the marker\n\
15386 at that exact address. If a marker id is specified, probe the marker\n\
15387 with that name. With no LOCATION, uses current execution address of\n\
15388 the selected stack frame.\n\
15389 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
15390 This collects arbitrary user data passed in the probe point call to the\n\
15391 tracing library. You can inspect it when analyzing the trace buffer,\n\
15392 by printing the $_sdata variable like any other convenience variable.\n\
15394 CONDITION is a boolean expression.\n\
15396 Multiple tracepoints at one place are permitted, and useful if their\n\
15397 conditions are different.\n\
15399 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
15400 Do \"help tracepoints\" for info on other tracepoint commands."));
15401 set_cmd_completer (c, location_completer);
15403 add_info ("tracepoints", tracepoints_info, _("\
15404 Status of specified tracepoints (all tracepoints if no argument).\n\
15405 Convenience variable \"$tpnum\" contains the number of the\n\
15406 last tracepoint set."));
15408 add_info_alias ("tp", "tracepoints", 1);
15410 add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
15411 Delete specified tracepoints.\n\
15412 Arguments are tracepoint numbers, separated by spaces.\n\
15413 No argument means delete all tracepoints."),
15416 c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
15417 Disable specified tracepoints.\n\
15418 Arguments are tracepoint numbers, separated by spaces.\n\
15419 No argument means disable all tracepoints."),
15421 deprecate_cmd (c, "disable");
15423 c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\
15424 Enable specified tracepoints.\n\
15425 Arguments are tracepoint numbers, separated by spaces.\n\
15426 No argument means enable all tracepoints."),
15428 deprecate_cmd (c, "enable");
15430 add_com ("passcount", class_trace, trace_pass_command, _("\
15431 Set the passcount for a tracepoint.\n\
15432 The trace will end when the tracepoint has been passed 'count' times.\n\
15433 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
15434 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
15436 add_prefix_cmd ("save", class_breakpoint, save_command,
15437 _("Save breakpoint definitions as a script."),
15438 &save_cmdlist, "save ",
15439 0/*allow-unknown*/, &cmdlist);
15441 c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\
15442 Save current breakpoint definitions as a script.\n\
15443 This includes all types of breakpoints (breakpoints, watchpoints,\n\
15444 catchpoints, tracepoints). Use the 'source' command in another debug\n\
15445 session to restore them."),
15447 set_cmd_completer (c, filename_completer);
15449 c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\
15450 Save current tracepoint definitions as a script.\n\
15451 Use the 'source' command in another debug session to restore them."),
15453 set_cmd_completer (c, filename_completer);
15455 c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0);
15456 deprecate_cmd (c, "save tracepoints");
15458 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
15459 Breakpoint specific settings\n\
15460 Configure various breakpoint-specific variables such as\n\
15461 pending breakpoint behavior"),
15462 &breakpoint_set_cmdlist, "set breakpoint ",
15463 0/*allow-unknown*/, &setlist);
15464 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
15465 Breakpoint specific settings\n\
15466 Configure various breakpoint-specific variables such as\n\
15467 pending breakpoint behavior"),
15468 &breakpoint_show_cmdlist, "show breakpoint ",
15469 0/*allow-unknown*/, &showlist);
15471 add_setshow_auto_boolean_cmd ("pending", no_class,
15472 &pending_break_support, _("\
15473 Set debugger's behavior regarding pending breakpoints."), _("\
15474 Show debugger's behavior regarding pending breakpoints."), _("\
15475 If on, an unrecognized breakpoint location will cause gdb to create a\n\
15476 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
15477 an error. If auto, an unrecognized breakpoint location results in a\n\
15478 user-query to see if a pending breakpoint should be created."),
15480 show_pending_break_support,
15481 &breakpoint_set_cmdlist,
15482 &breakpoint_show_cmdlist);
15484 pending_break_support = AUTO_BOOLEAN_AUTO;
15486 add_setshow_boolean_cmd ("auto-hw", no_class,
15487 &automatic_hardware_breakpoints, _("\
15488 Set automatic usage of hardware breakpoints."), _("\
15489 Show automatic usage of hardware breakpoints."), _("\
15490 If set, the debugger will automatically use hardware breakpoints for\n\
15491 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
15492 a warning will be emitted for such breakpoints."),
15494 show_automatic_hardware_breakpoints,
15495 &breakpoint_set_cmdlist,
15496 &breakpoint_show_cmdlist);
15498 add_setshow_enum_cmd ("always-inserted", class_support,
15499 always_inserted_enums, &always_inserted_mode, _("\
15500 Set mode for inserting breakpoints."), _("\
15501 Show mode for inserting breakpoints."), _("\
15502 When this mode is off, breakpoints are inserted in inferior when it is\n\
15503 resumed, and removed when execution stops. When this mode is on,\n\
15504 breakpoints are inserted immediately and removed only when the user\n\
15505 deletes the breakpoint. When this mode is auto (which is the default),\n\
15506 the behaviour depends on the non-stop setting (see help set non-stop).\n\
15507 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
15508 behaves as if always-inserted mode is on; if gdb is controlling the\n\
15509 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
15511 &show_always_inserted_mode,
15512 &breakpoint_set_cmdlist,
15513 &breakpoint_show_cmdlist);
15515 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint,
15516 condition_evaluation_enums,
15517 &condition_evaluation_mode_1, _("\
15518 Set mode of breakpoint condition evaluation."), _("\
15519 Show mode of breakpoint condition evaluation."), _("\
15520 When this is set to \"host\", breakpoint conditions will be\n\
15521 evaluated on the host's side by GDB. When it is set to \"target\",\n\
15522 breakpoint conditions will be downloaded to the target (if the target\n\
15523 supports such feature) and conditions will be evaluated on the target's side.\n\
15524 If this is set to \"auto\" (default), this will be automatically set to\n\
15525 \"target\" if it supports condition evaluation, otherwise it will\n\
15526 be set to \"gdb\""),
15527 &set_condition_evaluation_mode,
15528 &show_condition_evaluation_mode,
15529 &breakpoint_set_cmdlist,
15530 &breakpoint_show_cmdlist);
15532 add_com ("break-range", class_breakpoint, break_range_command, _("\
15533 Set a breakpoint for an address range.\n\
15534 break-range START-LOCATION, END-LOCATION\n\
15535 where START-LOCATION and END-LOCATION can be one of the following:\n\
15536 LINENUM, for that line in the current file,\n\
15537 FILE:LINENUM, for that line in that file,\n\
15538 +OFFSET, for that number of lines after the current line\n\
15539 or the start of the range\n\
15540 FUNCTION, for the first line in that function,\n\
15541 FILE:FUNCTION, to distinguish among like-named static functions.\n\
15542 *ADDRESS, for the instruction at that address.\n\
15544 The breakpoint will stop execution of the inferior whenever it executes\n\
15545 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
15546 range (including START-LOCATION and END-LOCATION)."));
15548 automatic_hardware_breakpoints = 1;
15550 observer_attach_about_to_proceed (breakpoint_about_to_proceed);