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"
70 /* readline include files */
71 #include "readline/readline.h"
72 #include "readline/history.h"
74 /* readline defines this. */
77 #include "mi/mi-common.h"
78 #include "python/python.h"
80 /* Prototypes for local functions. */
82 static void enable_delete_command (char *, int);
84 static void enable_once_command (char *, int);
86 static void enable_count_command (char *, int);
88 static void disable_command (char *, int);
90 static void enable_command (char *, int);
92 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *,
96 static void ignore_command (char *, int);
98 static int breakpoint_re_set_one (void *);
100 static void breakpoint_re_set_default (struct breakpoint *);
102 static void create_sals_from_address_default (char **,
103 struct linespec_result *,
107 static void create_breakpoints_sal_default (struct gdbarch *,
108 struct linespec_result *,
109 struct linespec_sals *,
111 enum bpdisp, int, int,
113 const struct breakpoint_ops *,
116 static void decode_linespec_default (struct breakpoint *, char **,
117 struct symtabs_and_lines *);
119 static void clear_command (char *, int);
121 static void catch_command (char *, int);
123 static int can_use_hardware_watchpoint (struct value *);
125 static void break_command_1 (char *, int, int);
127 static void mention (struct breakpoint *);
129 static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *,
131 const struct breakpoint_ops *);
132 static struct bp_location *add_location_to_breakpoint (struct breakpoint *,
133 const struct symtab_and_line *);
135 /* This function is used in gdbtk sources and thus can not be made
137 struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch,
138 struct symtab_and_line,
140 const struct breakpoint_ops *);
142 static struct breakpoint *
143 momentary_breakpoint_from_master (struct breakpoint *orig,
145 const struct breakpoint_ops *ops);
147 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
149 static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch,
153 static void describe_other_breakpoints (struct gdbarch *,
154 struct program_space *, CORE_ADDR,
155 struct obj_section *, int);
157 static int breakpoint_address_match (struct address_space *aspace1,
159 struct address_space *aspace2,
162 static int watchpoint_locations_match (struct bp_location *loc1,
163 struct bp_location *loc2);
165 static int breakpoint_location_address_match (struct bp_location *bl,
166 struct address_space *aspace,
169 static void breakpoints_info (char *, int);
171 static void watchpoints_info (char *, int);
173 static int breakpoint_1 (char *, int,
174 int (*) (const struct breakpoint *));
176 static int breakpoint_cond_eval (void *);
178 static void cleanup_executing_breakpoints (void *);
180 static void commands_command (char *, int);
182 static void condition_command (char *, int);
191 static int remove_breakpoint (struct bp_location *, insertion_state_t);
192 static int remove_breakpoint_1 (struct bp_location *, insertion_state_t);
194 static enum print_stop_action print_bp_stop_message (bpstat bs);
196 static int watchpoint_check (void *);
198 static void maintenance_info_breakpoints (char *, int);
200 static int hw_breakpoint_used_count (void);
202 static int hw_watchpoint_use_count (struct breakpoint *);
204 static int hw_watchpoint_used_count_others (struct breakpoint *except,
206 int *other_type_used);
208 static void hbreak_command (char *, int);
210 static void thbreak_command (char *, int);
212 static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp,
215 static void stop_command (char *arg, int from_tty);
217 static void stopin_command (char *arg, int from_tty);
219 static void stopat_command (char *arg, int from_tty);
221 static char *ep_parse_optional_if_clause (char **arg);
223 static void catch_exception_command_1 (enum exception_event_kind ex_event,
224 char *arg, int tempflag, int from_tty);
226 static void tcatch_command (char *arg, int from_tty);
228 static void detach_single_step_breakpoints (void);
230 static int single_step_breakpoint_inserted_here_p (struct address_space *,
233 static void free_bp_location (struct bp_location *loc);
234 static void incref_bp_location (struct bp_location *loc);
235 static void decref_bp_location (struct bp_location **loc);
237 static struct bp_location *allocate_bp_location (struct breakpoint *bpt);
239 static void update_global_location_list (int);
241 static void update_global_location_list_nothrow (int);
243 static int is_hardware_watchpoint (const struct breakpoint *bpt);
245 static void insert_breakpoint_locations (void);
247 static int syscall_catchpoint_p (struct breakpoint *b);
249 static void tracepoints_info (char *, int);
251 static void delete_trace_command (char *, int);
253 static void enable_trace_command (char *, int);
255 static void disable_trace_command (char *, int);
257 static void trace_pass_command (char *, int);
259 static int is_masked_watchpoint (const struct breakpoint *b);
261 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
264 static int strace_marker_p (struct breakpoint *b);
266 static void init_catchpoint (struct breakpoint *b,
267 struct gdbarch *gdbarch, int tempflag,
269 const struct breakpoint_ops *ops);
271 /* The abstract base class all breakpoint_ops structures inherit
273 static struct breakpoint_ops base_breakpoint_ops;
275 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
276 that are implemented on top of software or hardware breakpoints
277 (user breakpoints, internal and momentary breakpoints, etc.). */
278 static struct breakpoint_ops bkpt_base_breakpoint_ops;
280 /* Internal breakpoints class type. */
281 static struct breakpoint_ops internal_breakpoint_ops;
283 /* Momentary breakpoints class type. */
284 static struct breakpoint_ops momentary_breakpoint_ops;
286 /* The breakpoint_ops structure to be used in regular user created
288 struct breakpoint_ops bkpt_breakpoint_ops;
290 /* A reference-counted struct command_line. This lets multiple
291 breakpoints share a single command list. */
292 struct counted_command_line
294 /* The reference count. */
297 /* The command list. */
298 struct command_line *commands;
301 struct command_line *
302 breakpoint_commands (struct breakpoint *b)
304 return b->commands ? b->commands->commands : NULL;
307 /* Flag indicating that a command has proceeded the inferior past the
308 current breakpoint. */
310 static int breakpoint_proceeded;
313 bpdisp_text (enum bpdisp disp)
315 /* NOTE: the following values are a part of MI protocol and
316 represent values of 'disp' field returned when inferior stops at
318 static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"};
320 return bpdisps[(int) disp];
323 /* Prototypes for exported functions. */
324 /* If FALSE, gdb will not use hardware support for watchpoints, even
325 if such is available. */
326 static int can_use_hw_watchpoints;
329 show_can_use_hw_watchpoints (struct ui_file *file, int from_tty,
330 struct cmd_list_element *c,
333 fprintf_filtered (file,
334 _("Debugger's willingness to use "
335 "watchpoint hardware is %s.\n"),
339 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
340 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
341 for unrecognized breakpoint locations.
342 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
343 static enum auto_boolean pending_break_support;
345 show_pending_break_support (struct ui_file *file, int from_tty,
346 struct cmd_list_element *c,
349 fprintf_filtered (file,
350 _("Debugger's behavior regarding "
351 "pending breakpoints is %s.\n"),
355 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
356 set with "break" but falling in read-only memory.
357 If 0, gdb will warn about such breakpoints, but won't automatically
358 use hardware breakpoints. */
359 static int automatic_hardware_breakpoints;
361 show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty,
362 struct cmd_list_element *c,
365 fprintf_filtered (file,
366 _("Automatic usage of hardware breakpoints is %s.\n"),
370 /* If on, gdb will keep breakpoints inserted even as inferior is
371 stopped, and immediately insert any new breakpoints. If off, gdb
372 will insert breakpoints into inferior only when resuming it, and
373 will remove breakpoints upon stop. If auto, GDB will behave as ON
374 if in non-stop mode, and as OFF if all-stop mode.*/
376 static const char always_inserted_auto[] = "auto";
377 static const char always_inserted_on[] = "on";
378 static const char always_inserted_off[] = "off";
379 static const char *const always_inserted_enums[] = {
380 always_inserted_auto,
385 static const char *always_inserted_mode = always_inserted_auto;
387 show_always_inserted_mode (struct ui_file *file, int from_tty,
388 struct cmd_list_element *c, const char *value)
390 if (always_inserted_mode == always_inserted_auto)
391 fprintf_filtered (file,
392 _("Always inserted breakpoint "
393 "mode is %s (currently %s).\n"),
395 breakpoints_always_inserted_mode () ? "on" : "off");
397 fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"),
402 breakpoints_always_inserted_mode (void)
404 return ((always_inserted_mode == always_inserted_on
405 || (always_inserted_mode == always_inserted_auto && non_stop))
409 void _initialize_breakpoint (void);
411 /* Are we executing breakpoint commands? */
412 static int executing_breakpoint_commands;
414 /* Are overlay event breakpoints enabled? */
415 static int overlay_events_enabled;
417 /* See description in breakpoint.h. */
418 int target_exact_watchpoints = 0;
420 /* Walk the following statement or block through all breakpoints.
421 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
422 current breakpoint. */
424 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
426 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
427 for (B = breakpoint_chain; \
428 B ? (TMP=B->next, 1): 0; \
431 /* Similar iterator for the low-level breakpoints. SAFE variant is
432 not provided so update_global_location_list must not be called
433 while executing the block of ALL_BP_LOCATIONS. */
435 #define ALL_BP_LOCATIONS(B,BP_TMP) \
436 for (BP_TMP = bp_location; \
437 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
440 /* Iterator for tracepoints only. */
442 #define ALL_TRACEPOINTS(B) \
443 for (B = breakpoint_chain; B; B = B->next) \
444 if (is_tracepoint (B))
446 /* Chains of all breakpoints defined. */
448 struct breakpoint *breakpoint_chain;
450 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
452 static struct bp_location **bp_location;
454 /* Number of elements of BP_LOCATION. */
456 static unsigned bp_location_count;
458 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
459 ADDRESS for the current elements of BP_LOCATION which get a valid
460 result from bp_location_has_shadow. You can use it for roughly
461 limiting the subrange of BP_LOCATION to scan for shadow bytes for
462 an address you need to read. */
464 static CORE_ADDR bp_location_placed_address_before_address_max;
466 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
467 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
468 BP_LOCATION which get a valid result from bp_location_has_shadow.
469 You can use it for roughly limiting the subrange of BP_LOCATION to
470 scan for shadow bytes for an address you need to read. */
472 static CORE_ADDR bp_location_shadow_len_after_address_max;
474 /* The locations that no longer correspond to any breakpoint, unlinked
475 from bp_location array, but for which a hit may still be reported
477 VEC(bp_location_p) *moribund_locations = NULL;
479 /* Number of last breakpoint made. */
481 static int breakpoint_count;
483 /* The value of `breakpoint_count' before the last command that
484 created breakpoints. If the last (break-like) command created more
485 than one breakpoint, then the difference between BREAKPOINT_COUNT
486 and PREV_BREAKPOINT_COUNT is more than one. */
487 static int prev_breakpoint_count;
489 /* Number of last tracepoint made. */
491 static int tracepoint_count;
493 static struct cmd_list_element *breakpoint_set_cmdlist;
494 static struct cmd_list_element *breakpoint_show_cmdlist;
495 struct cmd_list_element *save_cmdlist;
497 /* Return whether a breakpoint is an active enabled breakpoint. */
499 breakpoint_enabled (struct breakpoint *b)
501 return (b->enable_state == bp_enabled);
504 /* Set breakpoint count to NUM. */
507 set_breakpoint_count (int num)
509 prev_breakpoint_count = breakpoint_count;
510 breakpoint_count = num;
511 set_internalvar_integer (lookup_internalvar ("bpnum"), num);
514 /* Used by `start_rbreak_breakpoints' below, to record the current
515 breakpoint count before "rbreak" creates any breakpoint. */
516 static int rbreak_start_breakpoint_count;
518 /* Called at the start an "rbreak" command to record the first
522 start_rbreak_breakpoints (void)
524 rbreak_start_breakpoint_count = breakpoint_count;
527 /* Called at the end of an "rbreak" command to record the last
531 end_rbreak_breakpoints (void)
533 prev_breakpoint_count = rbreak_start_breakpoint_count;
536 /* Used in run_command to zero the hit count when a new run starts. */
539 clear_breakpoint_hit_counts (void)
541 struct breakpoint *b;
547 /* Allocate a new counted_command_line with reference count of 1.
548 The new structure owns COMMANDS. */
550 static struct counted_command_line *
551 alloc_counted_command_line (struct command_line *commands)
553 struct counted_command_line *result
554 = xmalloc (sizeof (struct counted_command_line));
557 result->commands = commands;
561 /* Increment reference count. This does nothing if CMD is NULL. */
564 incref_counted_command_line (struct counted_command_line *cmd)
570 /* Decrement reference count. If the reference count reaches 0,
571 destroy the counted_command_line. Sets *CMDP to NULL. This does
572 nothing if *CMDP is NULL. */
575 decref_counted_command_line (struct counted_command_line **cmdp)
579 if (--(*cmdp)->refc == 0)
581 free_command_lines (&(*cmdp)->commands);
588 /* A cleanup function that calls decref_counted_command_line. */
591 do_cleanup_counted_command_line (void *arg)
593 decref_counted_command_line (arg);
596 /* Create a cleanup that calls decref_counted_command_line on the
599 static struct cleanup *
600 make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp)
602 return make_cleanup (do_cleanup_counted_command_line, cmdp);
606 /* Return the breakpoint with the specified number, or NULL
607 if the number does not refer to an existing breakpoint. */
610 get_breakpoint (int num)
612 struct breakpoint *b;
615 if (b->number == num)
624 set_breakpoint_condition (struct breakpoint *b, char *exp,
627 xfree (b->cond_string);
628 b->cond_string = NULL;
630 if (is_watchpoint (b))
632 struct watchpoint *w = (struct watchpoint *) b;
639 struct bp_location *loc;
641 for (loc = b->loc; loc; loc = loc->next)
651 printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number);
657 /* I don't know if it matters whether this is the string the user
658 typed in or the decompiled expression. */
659 b->cond_string = xstrdup (arg);
660 b->condition_not_parsed = 0;
662 if (is_watchpoint (b))
664 struct watchpoint *w = (struct watchpoint *) b;
666 innermost_block = NULL;
668 w->cond_exp = parse_exp_1 (&arg, 0, 0);
670 error (_("Junk at end of expression"));
671 w->cond_exp_valid_block = innermost_block;
675 struct bp_location *loc;
677 for (loc = b->loc; loc; loc = loc->next)
681 parse_exp_1 (&arg, block_for_pc (loc->address), 0);
683 error (_("Junk at end of expression"));
687 breakpoints_changed ();
688 observer_notify_breakpoint_modified (b);
691 /* condition N EXP -- set break condition of breakpoint N to EXP. */
694 condition_command (char *arg, int from_tty)
696 struct breakpoint *b;
701 error_no_arg (_("breakpoint number"));
704 bnum = get_number (&p);
706 error (_("Bad breakpoint argument: '%s'"), arg);
709 if (b->number == bnum)
711 /* Check if this breakpoint has a Python object assigned to
712 it, and if it has a definition of the "stop"
713 method. This method and conditions entered into GDB from
714 the CLI are mutually exclusive. */
716 && gdbpy_breakpoint_has_py_cond (b->py_bp_object))
717 error (_("Cannot set a condition where a Python 'stop' "
718 "method has been defined in the breakpoint."));
719 set_breakpoint_condition (b, p, from_tty);
723 error (_("No breakpoint number %d."), bnum);
726 /* Check that COMMAND do not contain commands that are suitable
727 only for tracepoints and not suitable for ordinary breakpoints.
728 Throw if any such commands is found. */
731 check_no_tracepoint_commands (struct command_line *commands)
733 struct command_line *c;
735 for (c = commands; c; c = c->next)
739 if (c->control_type == while_stepping_control)
740 error (_("The 'while-stepping' command can "
741 "only be used for tracepoints"));
743 for (i = 0; i < c->body_count; ++i)
744 check_no_tracepoint_commands ((c->body_list)[i]);
746 /* Not that command parsing removes leading whitespace and comment
747 lines and also empty lines. So, we only need to check for
749 if (strstr (c->line, "collect ") == c->line)
750 error (_("The 'collect' command can only be used for tracepoints"));
752 if (strstr (c->line, "teval ") == c->line)
753 error (_("The 'teval' command can only be used for tracepoints"));
757 /* Encapsulate tests for different types of tracepoints. */
760 is_tracepoint_type (enum bptype type)
762 return (type == bp_tracepoint
763 || type == bp_fast_tracepoint
764 || type == bp_static_tracepoint);
768 is_tracepoint (const struct breakpoint *b)
770 return is_tracepoint_type (b->type);
773 /* A helper function that validates that COMMANDS are valid for a
774 breakpoint. This function will throw an exception if a problem is
778 validate_commands_for_breakpoint (struct breakpoint *b,
779 struct command_line *commands)
781 if (is_tracepoint (b))
783 /* We need to verify that each top-level element of commands is
784 valid for tracepoints, that there's at most one
785 while-stepping element, and that while-stepping's body has
786 valid tracing commands excluding nested while-stepping. */
787 struct command_line *c;
788 struct command_line *while_stepping = 0;
789 for (c = commands; c; c = c->next)
791 if (c->control_type == while_stepping_control)
793 if (b->type == bp_fast_tracepoint)
794 error (_("The 'while-stepping' command "
795 "cannot be used for fast tracepoint"));
796 else if (b->type == bp_static_tracepoint)
797 error (_("The 'while-stepping' command "
798 "cannot be used for static tracepoint"));
801 error (_("The 'while-stepping' command "
802 "can be used only once"));
809 struct command_line *c2;
811 gdb_assert (while_stepping->body_count == 1);
812 c2 = while_stepping->body_list[0];
813 for (; c2; c2 = c2->next)
815 if (c2->control_type == while_stepping_control)
816 error (_("The 'while-stepping' command cannot be nested"));
822 check_no_tracepoint_commands (commands);
826 /* Return a vector of all the static tracepoints set at ADDR. The
827 caller is responsible for releasing the vector. */
830 static_tracepoints_here (CORE_ADDR addr)
832 struct breakpoint *b;
833 VEC(breakpoint_p) *found = 0;
834 struct bp_location *loc;
837 if (b->type == bp_static_tracepoint)
839 for (loc = b->loc; loc; loc = loc->next)
840 if (loc->address == addr)
841 VEC_safe_push(breakpoint_p, found, b);
847 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
848 validate that only allowed commands are included. */
851 breakpoint_set_commands (struct breakpoint *b,
852 struct command_line *commands)
854 validate_commands_for_breakpoint (b, commands);
856 decref_counted_command_line (&b->commands);
857 b->commands = alloc_counted_command_line (commands);
858 breakpoints_changed ();
859 observer_notify_breakpoint_modified (b);
862 /* Set the internal `silent' flag on the breakpoint. Note that this
863 is not the same as the "silent" that may appear in the breakpoint's
867 breakpoint_set_silent (struct breakpoint *b, int silent)
869 int old_silent = b->silent;
872 if (old_silent != silent)
873 observer_notify_breakpoint_modified (b);
876 /* Set the thread for this breakpoint. If THREAD is -1, make the
877 breakpoint work for any thread. */
880 breakpoint_set_thread (struct breakpoint *b, int thread)
882 int old_thread = b->thread;
885 if (old_thread != thread)
886 observer_notify_breakpoint_modified (b);
889 /* Set the task for this breakpoint. If TASK is 0, make the
890 breakpoint work for any task. */
893 breakpoint_set_task (struct breakpoint *b, int task)
895 int old_task = b->task;
898 if (old_task != task)
899 observer_notify_breakpoint_modified (b);
903 check_tracepoint_command (char *line, void *closure)
905 struct breakpoint *b = closure;
907 validate_actionline (&line, b);
910 /* A structure used to pass information through
911 map_breakpoint_numbers. */
915 /* True if the command was typed at a tty. */
918 /* The breakpoint range spec. */
921 /* Non-NULL if the body of the commands are being read from this
922 already-parsed command. */
923 struct command_line *control;
925 /* The command lines read from the user, or NULL if they have not
927 struct counted_command_line *cmd;
930 /* A callback for map_breakpoint_numbers that sets the commands for
934 do_map_commands_command (struct breakpoint *b, void *data)
936 struct commands_info *info = data;
938 if (info->cmd == NULL)
940 struct command_line *l;
942 if (info->control != NULL)
943 l = copy_command_lines (info->control->body_list[0]);
946 struct cleanup *old_chain;
949 str = xstrprintf (_("Type commands for breakpoint(s) "
950 "%s, one per line."),
953 old_chain = make_cleanup (xfree, str);
955 l = read_command_lines (str,
958 ? check_tracepoint_command : 0),
961 do_cleanups (old_chain);
964 info->cmd = alloc_counted_command_line (l);
967 /* If a breakpoint was on the list more than once, we don't need to
969 if (b->commands != info->cmd)
971 validate_commands_for_breakpoint (b, info->cmd->commands);
972 incref_counted_command_line (info->cmd);
973 decref_counted_command_line (&b->commands);
974 b->commands = info->cmd;
975 breakpoints_changed ();
976 observer_notify_breakpoint_modified (b);
981 commands_command_1 (char *arg, int from_tty,
982 struct command_line *control)
984 struct cleanup *cleanups;
985 struct commands_info info;
987 info.from_tty = from_tty;
988 info.control = control;
990 /* If we read command lines from the user, then `info' will hold an
991 extra reference to the commands that we must clean up. */
992 cleanups = make_cleanup_decref_counted_command_line (&info.cmd);
994 if (arg == NULL || !*arg)
996 if (breakpoint_count - prev_breakpoint_count > 1)
997 arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1,
999 else if (breakpoint_count > 0)
1000 arg = xstrprintf ("%d", breakpoint_count);
1003 /* So that we don't try to free the incoming non-NULL
1004 argument in the cleanup below. Mapping breakpoint
1005 numbers will fail in this case. */
1010 /* The command loop has some static state, so we need to preserve
1012 arg = xstrdup (arg);
1015 make_cleanup (xfree, arg);
1019 map_breakpoint_numbers (arg, do_map_commands_command, &info);
1021 if (info.cmd == NULL)
1022 error (_("No breakpoints specified."));
1024 do_cleanups (cleanups);
1028 commands_command (char *arg, int from_tty)
1030 commands_command_1 (arg, from_tty, NULL);
1033 /* Like commands_command, but instead of reading the commands from
1034 input stream, takes them from an already parsed command structure.
1036 This is used by cli-script.c to DTRT with breakpoint commands
1037 that are part of if and while bodies. */
1038 enum command_control_type
1039 commands_from_control_command (char *arg, struct command_line *cmd)
1041 commands_command_1 (arg, 0, cmd);
1042 return simple_control;
1045 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1048 bp_location_has_shadow (struct bp_location *bl)
1050 if (bl->loc_type != bp_loc_software_breakpoint)
1054 if (bl->target_info.shadow_len == 0)
1055 /* BL isn't valid, or doesn't shadow memory. */
1060 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1061 by replacing any memory breakpoints with their shadowed contents.
1063 The range of shadowed area by each bp_location is:
1064 bl->address - bp_location_placed_address_before_address_max
1065 up to bl->address + bp_location_shadow_len_after_address_max
1066 The range we were requested to resolve shadows for is:
1067 memaddr ... memaddr + len
1068 Thus the safe cutoff boundaries for performance optimization are
1069 memaddr + len <= (bl->address
1070 - bp_location_placed_address_before_address_max)
1072 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1075 breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf,
1076 const gdb_byte *writebuf_org,
1077 ULONGEST memaddr, LONGEST len)
1079 /* Left boundary, right boundary and median element of our binary
1081 unsigned bc_l, bc_r, bc;
1083 /* Find BC_L which is a leftmost element which may affect BUF
1084 content. It is safe to report lower value but a failure to
1085 report higher one. */
1088 bc_r = bp_location_count;
1089 while (bc_l + 1 < bc_r)
1091 struct bp_location *bl;
1093 bc = (bc_l + bc_r) / 2;
1094 bl = bp_location[bc];
1096 /* Check first BL->ADDRESS will not overflow due to the added
1097 constant. Then advance the left boundary only if we are sure
1098 the BC element can in no way affect the BUF content (MEMADDR
1099 to MEMADDR + LEN range).
1101 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1102 offset so that we cannot miss a breakpoint with its shadow
1103 range tail still reaching MEMADDR. */
1105 if ((bl->address + bp_location_shadow_len_after_address_max
1107 && (bl->address + bp_location_shadow_len_after_address_max
1114 /* Due to the binary search above, we need to make sure we pick the
1115 first location that's at BC_L's address. E.g., if there are
1116 multiple locations at the same address, BC_L may end up pointing
1117 at a duplicate location, and miss the "master"/"inserted"
1118 location. Say, given locations L1, L2 and L3 at addresses A and
1121 L1@A, L2@A, L3@B, ...
1123 BC_L could end up pointing at location L2, while the "master"
1124 location could be L1. Since the `loc->inserted' flag is only set
1125 on "master" locations, we'd forget to restore the shadow of L1
1128 && bp_location[bc_l]->address == bp_location[bc_l - 1]->address)
1131 /* Now do full processing of the found relevant range of elements. */
1133 for (bc = bc_l; bc < bp_location_count; bc++)
1135 struct bp_location *bl = bp_location[bc];
1136 CORE_ADDR bp_addr = 0;
1140 /* bp_location array has BL->OWNER always non-NULL. */
1141 if (bl->owner->type == bp_none)
1142 warning (_("reading through apparently deleted breakpoint #%d?"),
1145 /* Performance optimization: any further element can no longer affect BUF
1148 if (bl->address >= bp_location_placed_address_before_address_max
1149 && memaddr + len <= (bl->address
1150 - bp_location_placed_address_before_address_max))
1153 if (!bp_location_has_shadow (bl))
1155 if (!breakpoint_address_match (bl->target_info.placed_address_space, 0,
1156 current_program_space->aspace, 0))
1159 /* Addresses and length of the part of the breakpoint that
1161 bp_addr = bl->target_info.placed_address;
1162 bp_size = bl->target_info.shadow_len;
1164 if (bp_addr + bp_size <= memaddr)
1165 /* The breakpoint is entirely before the chunk of memory we
1169 if (bp_addr >= memaddr + len)
1170 /* The breakpoint is entirely after the chunk of memory we are
1174 /* Offset within shadow_contents. */
1175 if (bp_addr < memaddr)
1177 /* Only copy the second part of the breakpoint. */
1178 bp_size -= memaddr - bp_addr;
1179 bptoffset = memaddr - bp_addr;
1183 if (bp_addr + bp_size > memaddr + len)
1185 /* Only copy the first part of the breakpoint. */
1186 bp_size -= (bp_addr + bp_size) - (memaddr + len);
1189 if (readbuf != NULL)
1191 /* Update the read buffer with this inserted breakpoint's
1193 memcpy (readbuf + bp_addr - memaddr,
1194 bl->target_info.shadow_contents + bptoffset, bp_size);
1198 struct gdbarch *gdbarch = bl->gdbarch;
1199 const unsigned char *bp;
1200 CORE_ADDR placed_address = bl->target_info.placed_address;
1201 unsigned placed_size = bl->target_info.placed_size;
1203 /* Update the shadow with what we want to write to memory. */
1204 memcpy (bl->target_info.shadow_contents + bptoffset,
1205 writebuf_org + bp_addr - memaddr, bp_size);
1207 /* Determine appropriate breakpoint contents and size for this
1209 bp = gdbarch_breakpoint_from_pc (gdbarch, &placed_address, &placed_size);
1211 /* Update the final write buffer with this inserted
1212 breakpoint's INSN. */
1213 memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size);
1219 /* Return true if BPT is of any hardware watchpoint kind. */
1222 is_hardware_watchpoint (const struct breakpoint *bpt)
1224 return (bpt->type == bp_hardware_watchpoint
1225 || bpt->type == bp_read_watchpoint
1226 || bpt->type == bp_access_watchpoint);
1229 /* Return true if BPT is of any watchpoint kind, hardware or
1233 is_watchpoint (const struct breakpoint *bpt)
1235 return (is_hardware_watchpoint (bpt)
1236 || bpt->type == bp_watchpoint);
1239 /* Returns true if the current thread and its running state are safe
1240 to evaluate or update watchpoint B. Watchpoints on local
1241 expressions need to be evaluated in the context of the thread that
1242 was current when the watchpoint was created, and, that thread needs
1243 to be stopped to be able to select the correct frame context.
1244 Watchpoints on global expressions can be evaluated on any thread,
1245 and in any state. It is presently left to the target allowing
1246 memory accesses when threads are running. */
1249 watchpoint_in_thread_scope (struct watchpoint *b)
1251 return (b->base.pspace == current_program_space
1252 && (ptid_equal (b->watchpoint_thread, null_ptid)
1253 || (ptid_equal (inferior_ptid, b->watchpoint_thread)
1254 && !is_executing (inferior_ptid))));
1257 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1258 associated bp_watchpoint_scope breakpoint. */
1261 watchpoint_del_at_next_stop (struct watchpoint *w)
1263 struct breakpoint *b = &w->base;
1265 if (b->related_breakpoint != b)
1267 gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope);
1268 gdb_assert (b->related_breakpoint->related_breakpoint == b);
1269 b->related_breakpoint->disposition = disp_del_at_next_stop;
1270 b->related_breakpoint->related_breakpoint = b->related_breakpoint;
1271 b->related_breakpoint = b;
1273 b->disposition = disp_del_at_next_stop;
1276 /* Assuming that B is a watchpoint:
1277 - Reparse watchpoint expression, if REPARSE is non-zero
1278 - Evaluate expression and store the result in B->val
1279 - Evaluate the condition if there is one, and store the result
1281 - Update the list of values that must be watched in B->loc.
1283 If the watchpoint disposition is disp_del_at_next_stop, then do
1284 nothing. If this is local watchpoint that is out of scope, delete
1287 Even with `set breakpoint always-inserted on' the watchpoints are
1288 removed + inserted on each stop here. Normal breakpoints must
1289 never be removed because they might be missed by a running thread
1290 when debugging in non-stop mode. On the other hand, hardware
1291 watchpoints (is_hardware_watchpoint; processed here) are specific
1292 to each LWP since they are stored in each LWP's hardware debug
1293 registers. Therefore, such LWP must be stopped first in order to
1294 be able to modify its hardware watchpoints.
1296 Hardware watchpoints must be reset exactly once after being
1297 presented to the user. It cannot be done sooner, because it would
1298 reset the data used to present the watchpoint hit to the user. And
1299 it must not be done later because it could display the same single
1300 watchpoint hit during multiple GDB stops. Note that the latter is
1301 relevant only to the hardware watchpoint types bp_read_watchpoint
1302 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1303 not user-visible - its hit is suppressed if the memory content has
1306 The following constraints influence the location where we can reset
1307 hardware watchpoints:
1309 * target_stopped_by_watchpoint and target_stopped_data_address are
1310 called several times when GDB stops.
1313 * Multiple hardware watchpoints can be hit at the same time,
1314 causing GDB to stop. GDB only presents one hardware watchpoint
1315 hit at a time as the reason for stopping, and all the other hits
1316 are presented later, one after the other, each time the user
1317 requests the execution to be resumed. Execution is not resumed
1318 for the threads still having pending hit event stored in
1319 LWP_INFO->STATUS. While the watchpoint is already removed from
1320 the inferior on the first stop the thread hit event is kept being
1321 reported from its cached value by linux_nat_stopped_data_address
1322 until the real thread resume happens after the watchpoint gets
1323 presented and thus its LWP_INFO->STATUS gets reset.
1325 Therefore the hardware watchpoint hit can get safely reset on the
1326 watchpoint removal from inferior. */
1329 update_watchpoint (struct watchpoint *b, int reparse)
1331 int within_current_scope;
1332 struct frame_id saved_frame_id;
1335 /* If this is a local watchpoint, we only want to check if the
1336 watchpoint frame is in scope if the current thread is the thread
1337 that was used to create the watchpoint. */
1338 if (!watchpoint_in_thread_scope (b))
1341 if (b->base.disposition == disp_del_at_next_stop)
1346 /* Determine if the watchpoint is within scope. */
1347 if (b->exp_valid_block == NULL)
1348 within_current_scope = 1;
1351 struct frame_info *fi = get_current_frame ();
1352 struct gdbarch *frame_arch = get_frame_arch (fi);
1353 CORE_ADDR frame_pc = get_frame_pc (fi);
1355 /* If we're in a function epilogue, unwinding may not work
1356 properly, so do not attempt to recreate locations at this
1357 point. See similar comments in watchpoint_check. */
1358 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
1361 /* Save the current frame's ID so we can restore it after
1362 evaluating the watchpoint expression on its own frame. */
1363 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1364 took a frame parameter, so that we didn't have to change the
1367 saved_frame_id = get_frame_id (get_selected_frame (NULL));
1369 fi = frame_find_by_id (b->watchpoint_frame);
1370 within_current_scope = (fi != NULL);
1371 if (within_current_scope)
1375 /* We don't free locations. They are stored in the bp_location array
1376 and update_global_location_list will eventually delete them and
1377 remove breakpoints if needed. */
1380 if (within_current_scope && reparse)
1389 s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string;
1390 b->exp = parse_exp_1 (&s, b->exp_valid_block, 0);
1391 /* If the meaning of expression itself changed, the old value is
1392 no longer relevant. We don't want to report a watchpoint hit
1393 to the user when the old value and the new value may actually
1394 be completely different objects. */
1395 value_free (b->val);
1399 /* Note that unlike with breakpoints, the watchpoint's condition
1400 expression is stored in the breakpoint object, not in the
1401 locations (re)created below. */
1402 if (b->base.cond_string != NULL)
1404 if (b->cond_exp != NULL)
1406 xfree (b->cond_exp);
1410 s = b->base.cond_string;
1411 b->cond_exp = parse_exp_1 (&s, b->cond_exp_valid_block, 0);
1415 /* If we failed to parse the expression, for example because
1416 it refers to a global variable in a not-yet-loaded shared library,
1417 don't try to insert watchpoint. We don't automatically delete
1418 such watchpoint, though, since failure to parse expression
1419 is different from out-of-scope watchpoint. */
1420 if ( !target_has_execution)
1422 /* Without execution, memory can't change. No use to try and
1423 set watchpoint locations. The watchpoint will be reset when
1424 the target gains execution, through breakpoint_re_set. */
1426 else if (within_current_scope && b->exp)
1429 struct value *val_chain, *v, *result, *next;
1430 struct program_space *frame_pspace;
1432 fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain);
1434 /* Avoid setting b->val if it's already set. The meaning of
1435 b->val is 'the last value' user saw, and we should update
1436 it only if we reported that last value to user. As it
1437 happens, the code that reports it updates b->val directly.
1438 We don't keep track of the memory value for masked
1440 if (!b->val_valid && !is_masked_watchpoint (&b->base))
1446 frame_pspace = get_frame_program_space (get_selected_frame (NULL));
1448 /* Look at each value on the value chain. */
1449 for (v = val_chain; v; v = value_next (v))
1451 /* If it's a memory location, and GDB actually needed
1452 its contents to evaluate the expression, then we
1453 must watch it. If the first value returned is
1454 still lazy, that means an error occurred reading it;
1455 watch it anyway in case it becomes readable. */
1456 if (VALUE_LVAL (v) == lval_memory
1457 && (v == val_chain || ! value_lazy (v)))
1459 struct type *vtype = check_typedef (value_type (v));
1461 /* We only watch structs and arrays if user asked
1462 for it explicitly, never if they just happen to
1463 appear in the middle of some value chain. */
1465 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1466 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1470 struct bp_location *loc, **tmp;
1472 addr = value_address (v);
1473 len = TYPE_LENGTH (value_type (v));
1475 if (b->base.type == bp_read_watchpoint)
1477 else if (b->base.type == bp_access_watchpoint)
1480 loc = allocate_bp_location (&b->base);
1481 for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next))
1484 loc->gdbarch = get_type_arch (value_type (v));
1486 loc->pspace = frame_pspace;
1487 loc->address = addr;
1489 loc->watchpoint_type = type;
1494 /* Change the type of breakpoint between hardware assisted or
1495 an ordinary watchpoint depending on the hardware support
1496 and free hardware slots. REPARSE is set when the inferior
1501 enum bp_loc_type loc_type;
1502 struct bp_location *bl;
1504 reg_cnt = can_use_hardware_watchpoint (val_chain);
1508 int i, target_resources_ok, other_type_used;
1511 /* Use an exact watchpoint when there's only one memory region to be
1512 watched, and only one debug register is needed to watch it. */
1513 b->exact = target_exact_watchpoints && reg_cnt == 1;
1515 /* We need to determine how many resources are already
1516 used for all other hardware watchpoints plus this one
1517 to see if we still have enough resources to also fit
1518 this watchpoint in as well. */
1520 /* If this is a software watchpoint, we try to turn it
1521 to a hardware one -- count resources as if B was of
1522 hardware watchpoint type. */
1523 type = b->base.type;
1524 if (type == bp_watchpoint)
1525 type = bp_hardware_watchpoint;
1527 /* This watchpoint may or may not have been placed on
1528 the list yet at this point (it won't be in the list
1529 if we're trying to create it for the first time,
1530 through watch_command), so always account for it
1533 /* Count resources used by all watchpoints except B. */
1534 i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used);
1536 /* Add in the resources needed for B. */
1537 i += hw_watchpoint_use_count (&b->base);
1540 = target_can_use_hardware_watchpoint (type, i, other_type_used);
1541 if (target_resources_ok <= 0)
1543 int sw_mode = b->base.ops->works_in_software_mode (&b->base);
1545 if (target_resources_ok == 0 && !sw_mode)
1546 error (_("Target does not support this type of "
1547 "hardware watchpoint."));
1548 else if (target_resources_ok < 0 && !sw_mode)
1549 error (_("There are not enough available hardware "
1550 "resources for this watchpoint."));
1552 /* Downgrade to software watchpoint. */
1553 b->base.type = bp_watchpoint;
1557 /* If this was a software watchpoint, we've just
1558 found we have enough resources to turn it to a
1559 hardware watchpoint. Otherwise, this is a
1561 b->base.type = type;
1564 else if (!b->base.ops->works_in_software_mode (&b->base))
1565 error (_("Expression cannot be implemented with "
1566 "read/access watchpoint."));
1568 b->base.type = bp_watchpoint;
1570 loc_type = (b->base.type == bp_watchpoint? bp_loc_other
1571 : bp_loc_hardware_watchpoint);
1572 for (bl = b->base.loc; bl; bl = bl->next)
1573 bl->loc_type = loc_type;
1576 for (v = val_chain; v; v = next)
1578 next = value_next (v);
1583 /* If a software watchpoint is not watching any memory, then the
1584 above left it without any location set up. But,
1585 bpstat_stop_status requires a location to be able to report
1586 stops, so make sure there's at least a dummy one. */
1587 if (b->base.type == bp_watchpoint && b->base.loc == NULL)
1589 struct breakpoint *base = &b->base;
1590 base->loc = allocate_bp_location (base);
1591 base->loc->pspace = frame_pspace;
1592 base->loc->address = -1;
1593 base->loc->length = -1;
1594 base->loc->watchpoint_type = -1;
1597 else if (!within_current_scope)
1599 printf_filtered (_("\
1600 Watchpoint %d deleted because the program has left the block\n\
1601 in which its expression is valid.\n"),
1603 watchpoint_del_at_next_stop (b);
1606 /* Restore the selected frame. */
1608 select_frame (frame_find_by_id (saved_frame_id));
1612 /* Returns 1 iff breakpoint location should be
1613 inserted in the inferior. We don't differentiate the type of BL's owner
1614 (breakpoint vs. tracepoint), although insert_location in tracepoint's
1615 breakpoint_ops is not defined, because in insert_bp_location,
1616 tracepoint's insert_location will not be called. */
1618 should_be_inserted (struct bp_location *bl)
1620 if (bl->owner == NULL || !breakpoint_enabled (bl->owner))
1623 if (bl->owner->disposition == disp_del_at_next_stop)
1626 if (!bl->enabled || bl->shlib_disabled || bl->duplicate)
1629 if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup)
1632 /* This is set for example, when we're attached to the parent of a
1633 vfork, and have detached from the child. The child is running
1634 free, and we expect it to do an exec or exit, at which point the
1635 OS makes the parent schedulable again (and the target reports
1636 that the vfork is done). Until the child is done with the shared
1637 memory region, do not insert breakpoints in the parent, otherwise
1638 the child could still trip on the parent's breakpoints. Since
1639 the parent is blocked anyway, it won't miss any breakpoint. */
1640 if (bl->pspace->breakpoints_not_allowed)
1646 /* Same as should_be_inserted but does the check assuming
1647 that the location is not duplicated. */
1650 unduplicated_should_be_inserted (struct bp_location *bl)
1653 const int save_duplicate = bl->duplicate;
1656 result = should_be_inserted (bl);
1657 bl->duplicate = save_duplicate;
1661 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
1662 location. Any error messages are printed to TMP_ERROR_STREAM; and
1663 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
1664 Returns 0 for success, 1 if the bp_location type is not supported or
1667 NOTE drow/2003-09-09: This routine could be broken down to an
1668 object-style method for each breakpoint or catchpoint type. */
1670 insert_bp_location (struct bp_location *bl,
1671 struct ui_file *tmp_error_stream,
1672 int *disabled_breaks,
1673 int *hw_breakpoint_error)
1677 if (!should_be_inserted (bl) || bl->inserted)
1680 /* Initialize the target-specific information. */
1681 memset (&bl->target_info, 0, sizeof (bl->target_info));
1682 bl->target_info.placed_address = bl->address;
1683 bl->target_info.placed_address_space = bl->pspace->aspace;
1684 bl->target_info.length = bl->length;
1686 if (bl->loc_type == bp_loc_software_breakpoint
1687 || bl->loc_type == bp_loc_hardware_breakpoint)
1689 if (bl->owner->type != bp_hardware_breakpoint)
1691 /* If the explicitly specified breakpoint type
1692 is not hardware breakpoint, check the memory map to see
1693 if the breakpoint address is in read only memory or not.
1695 Two important cases are:
1696 - location type is not hardware breakpoint, memory
1697 is readonly. We change the type of the location to
1698 hardware breakpoint.
1699 - location type is hardware breakpoint, memory is
1700 read-write. This means we've previously made the
1701 location hardware one, but then the memory map changed,
1704 When breakpoints are removed, remove_breakpoints will use
1705 location types we've just set here, the only possible
1706 problem is that memory map has changed during running
1707 program, but it's not going to work anyway with current
1709 struct mem_region *mr
1710 = lookup_mem_region (bl->target_info.placed_address);
1714 if (automatic_hardware_breakpoints)
1716 enum bp_loc_type new_type;
1718 if (mr->attrib.mode != MEM_RW)
1719 new_type = bp_loc_hardware_breakpoint;
1721 new_type = bp_loc_software_breakpoint;
1723 if (new_type != bl->loc_type)
1725 static int said = 0;
1727 bl->loc_type = new_type;
1730 fprintf_filtered (gdb_stdout,
1731 _("Note: automatically using "
1732 "hardware breakpoints for "
1733 "read-only addresses.\n"));
1738 else if (bl->loc_type == bp_loc_software_breakpoint
1739 && mr->attrib.mode != MEM_RW)
1740 warning (_("cannot set software breakpoint "
1741 "at readonly address %s"),
1742 paddress (bl->gdbarch, bl->address));
1746 /* First check to see if we have to handle an overlay. */
1747 if (overlay_debugging == ovly_off
1748 || bl->section == NULL
1749 || !(section_is_overlay (bl->section)))
1751 /* No overlay handling: just set the breakpoint. */
1753 val = bl->owner->ops->insert_location (bl);
1757 /* This breakpoint is in an overlay section.
1758 Shall we set a breakpoint at the LMA? */
1759 if (!overlay_events_enabled)
1761 /* Yes -- overlay event support is not active,
1762 so we must try to set a breakpoint at the LMA.
1763 This will not work for a hardware breakpoint. */
1764 if (bl->loc_type == bp_loc_hardware_breakpoint)
1765 warning (_("hardware breakpoint %d not supported in overlay!"),
1769 CORE_ADDR addr = overlay_unmapped_address (bl->address,
1771 /* Set a software (trap) breakpoint at the LMA. */
1772 bl->overlay_target_info = bl->target_info;
1773 bl->overlay_target_info.placed_address = addr;
1774 val = target_insert_breakpoint (bl->gdbarch,
1775 &bl->overlay_target_info);
1777 fprintf_unfiltered (tmp_error_stream,
1778 "Overlay breakpoint %d "
1779 "failed: in ROM?\n",
1783 /* Shall we set a breakpoint at the VMA? */
1784 if (section_is_mapped (bl->section))
1786 /* Yes. This overlay section is mapped into memory. */
1787 val = bl->owner->ops->insert_location (bl);
1791 /* No. This breakpoint will not be inserted.
1792 No error, but do not mark the bp as 'inserted'. */
1799 /* Can't set the breakpoint. */
1800 if (solib_name_from_address (bl->pspace, bl->address))
1802 /* See also: disable_breakpoints_in_shlibs. */
1804 bl->shlib_disabled = 1;
1805 observer_notify_breakpoint_modified (bl->owner);
1806 if (!*disabled_breaks)
1808 fprintf_unfiltered (tmp_error_stream,
1809 "Cannot insert breakpoint %d.\n",
1811 fprintf_unfiltered (tmp_error_stream,
1812 "Temporarily disabling shared "
1813 "library breakpoints:\n");
1815 *disabled_breaks = 1;
1816 fprintf_unfiltered (tmp_error_stream,
1817 "breakpoint #%d\n", bl->owner->number);
1821 if (bl->loc_type == bp_loc_hardware_breakpoint)
1823 *hw_breakpoint_error = 1;
1824 fprintf_unfiltered (tmp_error_stream,
1825 "Cannot insert hardware "
1831 fprintf_unfiltered (tmp_error_stream,
1832 "Cannot insert breakpoint %d.\n",
1834 fprintf_filtered (tmp_error_stream,
1835 "Error accessing memory address ");
1836 fputs_filtered (paddress (bl->gdbarch, bl->address),
1838 fprintf_filtered (tmp_error_stream, ": %s.\n",
1839 safe_strerror (val));
1850 else if (bl->loc_type == bp_loc_hardware_watchpoint
1851 /* NOTE drow/2003-09-08: This state only exists for removing
1852 watchpoints. It's not clear that it's necessary... */
1853 && bl->owner->disposition != disp_del_at_next_stop)
1855 gdb_assert (bl->owner->ops != NULL
1856 && bl->owner->ops->insert_location != NULL);
1858 val = bl->owner->ops->insert_location (bl);
1860 /* If trying to set a read-watchpoint, and it turns out it's not
1861 supported, try emulating one with an access watchpoint. */
1862 if (val == 1 && bl->watchpoint_type == hw_read)
1864 struct bp_location *loc, **loc_temp;
1866 /* But don't try to insert it, if there's already another
1867 hw_access location that would be considered a duplicate
1869 ALL_BP_LOCATIONS (loc, loc_temp)
1871 && loc->watchpoint_type == hw_access
1872 && watchpoint_locations_match (bl, loc))
1876 bl->target_info = loc->target_info;
1877 bl->watchpoint_type = hw_access;
1884 bl->watchpoint_type = hw_access;
1885 val = bl->owner->ops->insert_location (bl);
1888 /* Back to the original value. */
1889 bl->watchpoint_type = hw_read;
1893 bl->inserted = (val == 0);
1896 else if (bl->owner->type == bp_catchpoint)
1898 gdb_assert (bl->owner->ops != NULL
1899 && bl->owner->ops->insert_location != NULL);
1901 val = bl->owner->ops->insert_location (bl);
1904 bl->owner->enable_state = bp_disabled;
1908 Error inserting catchpoint %d: Your system does not support this type\n\
1909 of catchpoint."), bl->owner->number);
1911 warning (_("Error inserting catchpoint %d."), bl->owner->number);
1914 bl->inserted = (val == 0);
1916 /* We've already printed an error message if there was a problem
1917 inserting this catchpoint, and we've disabled the catchpoint,
1918 so just return success. */
1925 /* This function is called when program space PSPACE is about to be
1926 deleted. It takes care of updating breakpoints to not reference
1930 breakpoint_program_space_exit (struct program_space *pspace)
1932 struct breakpoint *b, *b_temp;
1933 struct bp_location *loc, **loc_temp;
1935 /* Remove any breakpoint that was set through this program space. */
1936 ALL_BREAKPOINTS_SAFE (b, b_temp)
1938 if (b->pspace == pspace)
1939 delete_breakpoint (b);
1942 /* Breakpoints set through other program spaces could have locations
1943 bound to PSPACE as well. Remove those. */
1944 ALL_BP_LOCATIONS (loc, loc_temp)
1946 struct bp_location *tmp;
1948 if (loc->pspace == pspace)
1950 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
1951 if (loc->owner->loc == loc)
1952 loc->owner->loc = loc->next;
1954 for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next)
1955 if (tmp->next == loc)
1957 tmp->next = loc->next;
1963 /* Now update the global location list to permanently delete the
1964 removed locations above. */
1965 update_global_location_list (0);
1968 /* Make sure all breakpoints are inserted in inferior.
1969 Throws exception on any error.
1970 A breakpoint that is already inserted won't be inserted
1971 again, so calling this function twice is safe. */
1973 insert_breakpoints (void)
1975 struct breakpoint *bpt;
1977 ALL_BREAKPOINTS (bpt)
1978 if (is_hardware_watchpoint (bpt))
1980 struct watchpoint *w = (struct watchpoint *) bpt;
1982 update_watchpoint (w, 0 /* don't reparse. */);
1985 update_global_location_list (1);
1987 /* update_global_location_list does not insert breakpoints when
1988 always_inserted_mode is not enabled. Explicitly insert them
1990 if (!breakpoints_always_inserted_mode ())
1991 insert_breakpoint_locations ();
1994 /* Used when starting or continuing the program. */
1997 insert_breakpoint_locations (void)
1999 struct breakpoint *bpt;
2000 struct bp_location *bl, **blp_tmp;
2003 int disabled_breaks = 0;
2004 int hw_breakpoint_error = 0;
2006 struct ui_file *tmp_error_stream = mem_fileopen ();
2007 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
2009 /* Explicitly mark the warning -- this will only be printed if
2010 there was an error. */
2011 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
2013 save_current_space_and_thread ();
2015 ALL_BP_LOCATIONS (bl, blp_tmp)
2017 if (!should_be_inserted (bl) || bl->inserted)
2020 /* There is no point inserting thread-specific breakpoints if
2021 the thread no longer exists. ALL_BP_LOCATIONS bp_location
2022 has BL->OWNER always non-NULL. */
2023 if (bl->owner->thread != -1
2024 && !valid_thread_id (bl->owner->thread))
2027 switch_to_program_space_and_thread (bl->pspace);
2029 /* For targets that support global breakpoints, there's no need
2030 to select an inferior to insert breakpoint to. In fact, even
2031 if we aren't attached to any process yet, we should still
2032 insert breakpoints. */
2033 if (!gdbarch_has_global_breakpoints (target_gdbarch)
2034 && ptid_equal (inferior_ptid, null_ptid))
2037 val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
2038 &hw_breakpoint_error);
2043 /* If we failed to insert all locations of a watchpoint, remove
2044 them, as half-inserted watchpoint is of limited use. */
2045 ALL_BREAKPOINTS (bpt)
2047 int some_failed = 0;
2048 struct bp_location *loc;
2050 if (!is_hardware_watchpoint (bpt))
2053 if (!breakpoint_enabled (bpt))
2056 if (bpt->disposition == disp_del_at_next_stop)
2059 for (loc = bpt->loc; loc; loc = loc->next)
2060 if (!loc->inserted && should_be_inserted (loc))
2067 for (loc = bpt->loc; loc; loc = loc->next)
2069 remove_breakpoint (loc, mark_uninserted);
2071 hw_breakpoint_error = 1;
2072 fprintf_unfiltered (tmp_error_stream,
2073 "Could not insert hardware watchpoint %d.\n",
2081 /* If a hardware breakpoint or watchpoint was inserted, add a
2082 message about possibly exhausted resources. */
2083 if (hw_breakpoint_error)
2085 fprintf_unfiltered (tmp_error_stream,
2086 "Could not insert hardware breakpoints:\n\
2087 You may have requested too many hardware breakpoints/watchpoints.\n");
2089 target_terminal_ours_for_output ();
2090 error_stream (tmp_error_stream);
2093 do_cleanups (cleanups);
2096 /* Used when the program stops.
2097 Returns zero if successful, or non-zero if there was a problem
2098 removing a breakpoint location. */
2101 remove_breakpoints (void)
2103 struct bp_location *bl, **blp_tmp;
2106 ALL_BP_LOCATIONS (bl, blp_tmp)
2108 if (bl->inserted && !is_tracepoint (bl->owner))
2109 val |= remove_breakpoint (bl, mark_uninserted);
2114 /* Remove breakpoints of process PID. */
2117 remove_breakpoints_pid (int pid)
2119 struct bp_location *bl, **blp_tmp;
2121 struct inferior *inf = find_inferior_pid (pid);
2123 ALL_BP_LOCATIONS (bl, blp_tmp)
2125 if (bl->pspace != inf->pspace)
2130 val = remove_breakpoint (bl, mark_uninserted);
2139 reattach_breakpoints (int pid)
2141 struct cleanup *old_chain;
2142 struct bp_location *bl, **blp_tmp;
2144 struct ui_file *tmp_error_stream;
2145 int dummy1 = 0, dummy2 = 0;
2146 struct inferior *inf;
2147 struct thread_info *tp;
2149 tp = any_live_thread_of_process (pid);
2153 inf = find_inferior_pid (pid);
2154 old_chain = save_inferior_ptid ();
2156 inferior_ptid = tp->ptid;
2158 tmp_error_stream = mem_fileopen ();
2159 make_cleanup_ui_file_delete (tmp_error_stream);
2161 ALL_BP_LOCATIONS (bl, blp_tmp)
2163 if (bl->pspace != inf->pspace)
2169 val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2);
2172 do_cleanups (old_chain);
2177 do_cleanups (old_chain);
2181 static int internal_breakpoint_number = -1;
2183 /* Set the breakpoint number of B, depending on the value of INTERNAL.
2184 If INTERNAL is non-zero, the breakpoint number will be populated
2185 from internal_breakpoint_number and that variable decremented.
2186 Otherwise the breakpoint number will be populated from
2187 breakpoint_count and that value incremented. Internal breakpoints
2188 do not set the internal var bpnum. */
2190 set_breakpoint_number (int internal, struct breakpoint *b)
2193 b->number = internal_breakpoint_number--;
2196 set_breakpoint_count (breakpoint_count + 1);
2197 b->number = breakpoint_count;
2201 static struct breakpoint *
2202 create_internal_breakpoint (struct gdbarch *gdbarch,
2203 CORE_ADDR address, enum bptype type,
2204 const struct breakpoint_ops *ops)
2206 struct symtab_and_line sal;
2207 struct breakpoint *b;
2209 init_sal (&sal); /* Initialize to zeroes. */
2212 sal.section = find_pc_overlay (sal.pc);
2213 sal.pspace = current_program_space;
2215 b = set_raw_breakpoint (gdbarch, sal, type, ops);
2216 b->number = internal_breakpoint_number--;
2217 b->disposition = disp_donttouch;
2222 static const char *const longjmp_names[] =
2224 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
2226 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
2228 /* Per-objfile data private to breakpoint.c. */
2229 struct breakpoint_objfile_data
2231 /* Minimal symbol for "_ovly_debug_event" (if any). */
2232 struct minimal_symbol *overlay_msym;
2234 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
2235 struct minimal_symbol *longjmp_msym[NUM_LONGJMP_NAMES];
2237 /* Minimal symbol for "std::terminate()" (if any). */
2238 struct minimal_symbol *terminate_msym;
2240 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
2241 struct minimal_symbol *exception_msym;
2244 static const struct objfile_data *breakpoint_objfile_key;
2246 /* Minimal symbol not found sentinel. */
2247 static struct minimal_symbol msym_not_found;
2249 /* Returns TRUE if MSYM point to the "not found" sentinel. */
2252 msym_not_found_p (const struct minimal_symbol *msym)
2254 return msym == &msym_not_found;
2257 /* Return per-objfile data needed by breakpoint.c.
2258 Allocate the data if necessary. */
2260 static struct breakpoint_objfile_data *
2261 get_breakpoint_objfile_data (struct objfile *objfile)
2263 struct breakpoint_objfile_data *bp_objfile_data;
2265 bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key);
2266 if (bp_objfile_data == NULL)
2268 bp_objfile_data = obstack_alloc (&objfile->objfile_obstack,
2269 sizeof (*bp_objfile_data));
2271 memset (bp_objfile_data, 0, sizeof (*bp_objfile_data));
2272 set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data);
2274 return bp_objfile_data;
2278 create_overlay_event_breakpoint (void)
2280 struct objfile *objfile;
2281 const char *const func_name = "_ovly_debug_event";
2283 ALL_OBJFILES (objfile)
2285 struct breakpoint *b;
2286 struct breakpoint_objfile_data *bp_objfile_data;
2289 bp_objfile_data = get_breakpoint_objfile_data (objfile);
2291 if (msym_not_found_p (bp_objfile_data->overlay_msym))
2294 if (bp_objfile_data->overlay_msym == NULL)
2296 struct minimal_symbol *m;
2298 m = lookup_minimal_symbol_text (func_name, objfile);
2301 /* Avoid future lookups in this objfile. */
2302 bp_objfile_data->overlay_msym = &msym_not_found;
2305 bp_objfile_data->overlay_msym = m;
2308 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym);
2309 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
2311 &internal_breakpoint_ops);
2312 b->addr_string = xstrdup (func_name);
2314 if (overlay_debugging == ovly_auto)
2316 b->enable_state = bp_enabled;
2317 overlay_events_enabled = 1;
2321 b->enable_state = bp_disabled;
2322 overlay_events_enabled = 0;
2325 update_global_location_list (1);
2329 create_longjmp_master_breakpoint (void)
2331 struct program_space *pspace;
2332 struct cleanup *old_chain;
2334 old_chain = save_current_program_space ();
2336 ALL_PSPACES (pspace)
2338 struct objfile *objfile;
2340 set_current_program_space (pspace);
2342 ALL_OBJFILES (objfile)
2345 struct gdbarch *gdbarch;
2346 struct breakpoint_objfile_data *bp_objfile_data;
2348 gdbarch = get_objfile_arch (objfile);
2349 if (!gdbarch_get_longjmp_target_p (gdbarch))
2352 bp_objfile_data = get_breakpoint_objfile_data (objfile);
2354 for (i = 0; i < NUM_LONGJMP_NAMES; i++)
2356 struct breakpoint *b;
2357 const char *func_name;
2360 if (msym_not_found_p (bp_objfile_data->longjmp_msym[i]))
2363 func_name = longjmp_names[i];
2364 if (bp_objfile_data->longjmp_msym[i] == NULL)
2366 struct minimal_symbol *m;
2368 m = lookup_minimal_symbol_text (func_name, objfile);
2371 /* Prevent future lookups in this objfile. */
2372 bp_objfile_data->longjmp_msym[i] = &msym_not_found;
2375 bp_objfile_data->longjmp_msym[i] = m;
2378 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]);
2379 b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master,
2380 &internal_breakpoint_ops);
2381 b->addr_string = xstrdup (func_name);
2382 b->enable_state = bp_disabled;
2386 update_global_location_list (1);
2388 do_cleanups (old_chain);
2391 /* Create a master std::terminate breakpoint. */
2393 create_std_terminate_master_breakpoint (void)
2395 struct program_space *pspace;
2396 struct cleanup *old_chain;
2397 const char *const func_name = "std::terminate()";
2399 old_chain = save_current_program_space ();
2401 ALL_PSPACES (pspace)
2403 struct objfile *objfile;
2406 set_current_program_space (pspace);
2408 ALL_OBJFILES (objfile)
2410 struct breakpoint *b;
2411 struct breakpoint_objfile_data *bp_objfile_data;
2413 bp_objfile_data = get_breakpoint_objfile_data (objfile);
2415 if (msym_not_found_p (bp_objfile_data->terminate_msym))
2418 if (bp_objfile_data->terminate_msym == NULL)
2420 struct minimal_symbol *m;
2422 m = lookup_minimal_symbol (func_name, NULL, objfile);
2423 if (m == NULL || (MSYMBOL_TYPE (m) != mst_text
2424 && MSYMBOL_TYPE (m) != mst_file_text))
2426 /* Prevent future lookups in this objfile. */
2427 bp_objfile_data->terminate_msym = &msym_not_found;
2430 bp_objfile_data->terminate_msym = m;
2433 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym);
2434 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
2435 bp_std_terminate_master,
2436 &internal_breakpoint_ops);
2437 b->addr_string = xstrdup (func_name);
2438 b->enable_state = bp_disabled;
2442 update_global_location_list (1);
2444 do_cleanups (old_chain);
2447 /* Install a master breakpoint on the unwinder's debug hook. */
2450 create_exception_master_breakpoint (void)
2452 struct objfile *objfile;
2453 const char *const func_name = "_Unwind_DebugHook";
2455 ALL_OBJFILES (objfile)
2457 struct breakpoint *b;
2458 struct gdbarch *gdbarch;
2459 struct breakpoint_objfile_data *bp_objfile_data;
2462 bp_objfile_data = get_breakpoint_objfile_data (objfile);
2464 if (msym_not_found_p (bp_objfile_data->exception_msym))
2467 gdbarch = get_objfile_arch (objfile);
2469 if (bp_objfile_data->exception_msym == NULL)
2471 struct minimal_symbol *debug_hook;
2473 debug_hook = lookup_minimal_symbol (func_name, NULL, objfile);
2474 if (debug_hook == NULL)
2476 bp_objfile_data->exception_msym = &msym_not_found;
2480 bp_objfile_data->exception_msym = debug_hook;
2483 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym);
2484 addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
2486 b = create_internal_breakpoint (gdbarch, addr, bp_exception_master,
2487 &internal_breakpoint_ops);
2488 b->addr_string = xstrdup (func_name);
2489 b->enable_state = bp_disabled;
2492 update_global_location_list (1);
2496 update_breakpoints_after_exec (void)
2498 struct breakpoint *b, *b_tmp;
2499 struct bp_location *bploc, **bplocp_tmp;
2501 /* We're about to delete breakpoints from GDB's lists. If the
2502 INSERTED flag is true, GDB will try to lift the breakpoints by
2503 writing the breakpoints' "shadow contents" back into memory. The
2504 "shadow contents" are NOT valid after an exec, so GDB should not
2505 do that. Instead, the target is responsible from marking
2506 breakpoints out as soon as it detects an exec. We don't do that
2507 here instead, because there may be other attempts to delete
2508 breakpoints after detecting an exec and before reaching here. */
2509 ALL_BP_LOCATIONS (bploc, bplocp_tmp)
2510 if (bploc->pspace == current_program_space)
2511 gdb_assert (!bploc->inserted);
2513 ALL_BREAKPOINTS_SAFE (b, b_tmp)
2515 if (b->pspace != current_program_space)
2518 /* Solib breakpoints must be explicitly reset after an exec(). */
2519 if (b->type == bp_shlib_event)
2521 delete_breakpoint (b);
2525 /* JIT breakpoints must be explicitly reset after an exec(). */
2526 if (b->type == bp_jit_event)
2528 delete_breakpoint (b);
2532 /* Thread event breakpoints must be set anew after an exec(),
2533 as must overlay event and longjmp master breakpoints. */
2534 if (b->type == bp_thread_event || b->type == bp_overlay_event
2535 || b->type == bp_longjmp_master || b->type == bp_std_terminate_master
2536 || b->type == bp_exception_master)
2538 delete_breakpoint (b);
2542 /* Step-resume breakpoints are meaningless after an exec(). */
2543 if (b->type == bp_step_resume || b->type == bp_hp_step_resume)
2545 delete_breakpoint (b);
2549 /* Longjmp and longjmp-resume breakpoints are also meaningless
2551 if (b->type == bp_longjmp || b->type == bp_longjmp_resume
2552 || b->type == bp_exception || b->type == bp_exception_resume)
2554 delete_breakpoint (b);
2558 if (b->type == bp_catchpoint)
2560 /* For now, none of the bp_catchpoint breakpoints need to
2561 do anything at this point. In the future, if some of
2562 the catchpoints need to something, we will need to add
2563 a new method, and call this method from here. */
2567 /* bp_finish is a special case. The only way we ought to be able
2568 to see one of these when an exec() has happened, is if the user
2569 caught a vfork, and then said "finish". Ordinarily a finish just
2570 carries them to the call-site of the current callee, by setting
2571 a temporary bp there and resuming. But in this case, the finish
2572 will carry them entirely through the vfork & exec.
2574 We don't want to allow a bp_finish to remain inserted now. But
2575 we can't safely delete it, 'cause finish_command has a handle to
2576 the bp on a bpstat, and will later want to delete it. There's a
2577 chance (and I've seen it happen) that if we delete the bp_finish
2578 here, that its storage will get reused by the time finish_command
2579 gets 'round to deleting the "use to be a bp_finish" breakpoint.
2580 We really must allow finish_command to delete a bp_finish.
2582 In the absence of a general solution for the "how do we know
2583 it's safe to delete something others may have handles to?"
2584 problem, what we'll do here is just uninsert the bp_finish, and
2585 let finish_command delete it.
2587 (We know the bp_finish is "doomed" in the sense that it's
2588 momentary, and will be deleted as soon as finish_command sees
2589 the inferior stopped. So it doesn't matter that the bp's
2590 address is probably bogus in the new a.out, unlike e.g., the
2591 solib breakpoints.) */
2593 if (b->type == bp_finish)
2598 /* Without a symbolic address, we have little hope of the
2599 pre-exec() address meaning the same thing in the post-exec()
2601 if (b->addr_string == NULL)
2603 delete_breakpoint (b);
2607 /* FIXME what about longjmp breakpoints? Re-create them here? */
2608 create_overlay_event_breakpoint ();
2609 create_longjmp_master_breakpoint ();
2610 create_std_terminate_master_breakpoint ();
2611 create_exception_master_breakpoint ();
2615 detach_breakpoints (int pid)
2617 struct bp_location *bl, **blp_tmp;
2619 struct cleanup *old_chain = save_inferior_ptid ();
2620 struct inferior *inf = current_inferior ();
2622 if (pid == PIDGET (inferior_ptid))
2623 error (_("Cannot detach breakpoints of inferior_ptid"));
2625 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
2626 inferior_ptid = pid_to_ptid (pid);
2627 ALL_BP_LOCATIONS (bl, blp_tmp)
2629 if (bl->pspace != inf->pspace)
2633 val |= remove_breakpoint_1 (bl, mark_inserted);
2636 /* Detach single-step breakpoints as well. */
2637 detach_single_step_breakpoints ();
2639 do_cleanups (old_chain);
2643 /* Remove the breakpoint location BL from the current address space.
2644 Note that this is used to detach breakpoints from a child fork.
2645 When we get here, the child isn't in the inferior list, and neither
2646 do we have objects to represent its address space --- we should
2647 *not* look at bl->pspace->aspace here. */
2650 remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is)
2654 /* BL is never in moribund_locations by our callers. */
2655 gdb_assert (bl->owner != NULL);
2657 if (bl->owner->enable_state == bp_permanent)
2658 /* Permanent breakpoints cannot be inserted or removed. */
2661 /* The type of none suggests that owner is actually deleted.
2662 This should not ever happen. */
2663 gdb_assert (bl->owner->type != bp_none);
2665 if (bl->loc_type == bp_loc_software_breakpoint
2666 || bl->loc_type == bp_loc_hardware_breakpoint)
2668 /* "Normal" instruction breakpoint: either the standard
2669 trap-instruction bp (bp_breakpoint), or a
2670 bp_hardware_breakpoint. */
2672 /* First check to see if we have to handle an overlay. */
2673 if (overlay_debugging == ovly_off
2674 || bl->section == NULL
2675 || !(section_is_overlay (bl->section)))
2677 /* No overlay handling: just remove the breakpoint. */
2678 val = bl->owner->ops->remove_location (bl);
2682 /* This breakpoint is in an overlay section.
2683 Did we set a breakpoint at the LMA? */
2684 if (!overlay_events_enabled)
2686 /* Yes -- overlay event support is not active, so we
2687 should have set a breakpoint at the LMA. Remove it.
2689 /* Ignore any failures: if the LMA is in ROM, we will
2690 have already warned when we failed to insert it. */
2691 if (bl->loc_type == bp_loc_hardware_breakpoint)
2692 target_remove_hw_breakpoint (bl->gdbarch,
2693 &bl->overlay_target_info);
2695 target_remove_breakpoint (bl->gdbarch,
2696 &bl->overlay_target_info);
2698 /* Did we set a breakpoint at the VMA?
2699 If so, we will have marked the breakpoint 'inserted'. */
2702 /* Yes -- remove it. Previously we did not bother to
2703 remove the breakpoint if the section had been
2704 unmapped, but let's not rely on that being safe. We
2705 don't know what the overlay manager might do. */
2707 /* However, we should remove *software* breakpoints only
2708 if the section is still mapped, or else we overwrite
2709 wrong code with the saved shadow contents. */
2710 if (bl->loc_type == bp_loc_hardware_breakpoint
2711 || section_is_mapped (bl->section))
2712 val = bl->owner->ops->remove_location (bl);
2718 /* No -- not inserted, so no need to remove. No error. */
2723 /* In some cases, we might not be able to remove a breakpoint
2724 in a shared library that has already been removed, but we
2725 have not yet processed the shlib unload event. */
2726 if (val && solib_name_from_address (bl->pspace, bl->address))
2731 bl->inserted = (is == mark_inserted);
2733 else if (bl->loc_type == bp_loc_hardware_watchpoint)
2735 gdb_assert (bl->owner->ops != NULL
2736 && bl->owner->ops->remove_location != NULL);
2738 bl->inserted = (is == mark_inserted);
2739 bl->owner->ops->remove_location (bl);
2741 /* Failure to remove any of the hardware watchpoints comes here. */
2742 if ((is == mark_uninserted) && (bl->inserted))
2743 warning (_("Could not remove hardware watchpoint %d."),
2746 else if (bl->owner->type == bp_catchpoint
2747 && breakpoint_enabled (bl->owner)
2750 gdb_assert (bl->owner->ops != NULL
2751 && bl->owner->ops->remove_location != NULL);
2753 val = bl->owner->ops->remove_location (bl);
2757 bl->inserted = (is == mark_inserted);
2764 remove_breakpoint (struct bp_location *bl, insertion_state_t is)
2767 struct cleanup *old_chain;
2769 /* BL is never in moribund_locations by our callers. */
2770 gdb_assert (bl->owner != NULL);
2772 if (bl->owner->enable_state == bp_permanent)
2773 /* Permanent breakpoints cannot be inserted or removed. */
2776 /* The type of none suggests that owner is actually deleted.
2777 This should not ever happen. */
2778 gdb_assert (bl->owner->type != bp_none);
2780 old_chain = save_current_space_and_thread ();
2782 switch_to_program_space_and_thread (bl->pspace);
2784 ret = remove_breakpoint_1 (bl, is);
2786 do_cleanups (old_chain);
2790 /* Clear the "inserted" flag in all breakpoints. */
2793 mark_breakpoints_out (void)
2795 struct bp_location *bl, **blp_tmp;
2797 ALL_BP_LOCATIONS (bl, blp_tmp)
2798 if (bl->pspace == current_program_space)
2802 /* Clear the "inserted" flag in all breakpoints and delete any
2803 breakpoints which should go away between runs of the program.
2805 Plus other such housekeeping that has to be done for breakpoints
2808 Note: this function gets called at the end of a run (by
2809 generic_mourn_inferior) and when a run begins (by
2810 init_wait_for_inferior). */
2815 breakpoint_init_inferior (enum inf_context context)
2817 struct breakpoint *b, *b_tmp;
2818 struct bp_location *bl, **blp_tmp;
2820 struct program_space *pspace = current_program_space;
2822 /* If breakpoint locations are shared across processes, then there's
2824 if (gdbarch_has_global_breakpoints (target_gdbarch))
2827 ALL_BP_LOCATIONS (bl, blp_tmp)
2829 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
2830 if (bl->pspace == pspace
2831 && bl->owner->enable_state != bp_permanent)
2835 ALL_BREAKPOINTS_SAFE (b, b_tmp)
2837 if (b->loc && b->loc->pspace != pspace)
2844 /* If the call dummy breakpoint is at the entry point it will
2845 cause problems when the inferior is rerun, so we better get
2848 case bp_watchpoint_scope:
2850 /* Also get rid of scope breakpoints. */
2852 case bp_shlib_event:
2854 /* Also remove solib event breakpoints. Their addresses may
2855 have changed since the last time we ran the program.
2856 Actually we may now be debugging against different target;
2857 and so the solib backend that installed this breakpoint may
2858 not be used in by the target. E.g.,
2860 (gdb) file prog-linux
2861 (gdb) run # native linux target
2864 (gdb) file prog-win.exe
2865 (gdb) tar rem :9999 # remote Windows gdbserver.
2868 delete_breakpoint (b);
2872 case bp_hardware_watchpoint:
2873 case bp_read_watchpoint:
2874 case bp_access_watchpoint:
2876 struct watchpoint *w = (struct watchpoint *) b;
2878 /* Likewise for watchpoints on local expressions. */
2879 if (w->exp_valid_block != NULL)
2880 delete_breakpoint (b);
2881 else if (context == inf_starting)
2883 /* Reset val field to force reread of starting value in
2884 insert_breakpoints. */
2886 value_free (w->val);
2897 /* Get rid of the moribund locations. */
2898 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix)
2899 decref_bp_location (&bl);
2900 VEC_free (bp_location_p, moribund_locations);
2903 /* These functions concern about actual breakpoints inserted in the
2904 target --- to e.g. check if we need to do decr_pc adjustment or if
2905 we need to hop over the bkpt --- so we check for address space
2906 match, not program space. */
2908 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2909 exists at PC. It returns ordinary_breakpoint_here if it's an
2910 ordinary breakpoint, or permanent_breakpoint_here if it's a
2911 permanent breakpoint.
2912 - When continuing from a location with an ordinary breakpoint, we
2913 actually single step once before calling insert_breakpoints.
2914 - When continuing from a location with a permanent breakpoint, we
2915 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2916 the target, to advance the PC past the breakpoint. */
2918 enum breakpoint_here
2919 breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
2921 struct bp_location *bl, **blp_tmp;
2922 int any_breakpoint_here = 0;
2924 ALL_BP_LOCATIONS (bl, blp_tmp)
2926 if (bl->loc_type != bp_loc_software_breakpoint
2927 && bl->loc_type != bp_loc_hardware_breakpoint)
2930 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
2931 if ((breakpoint_enabled (bl->owner)
2932 || bl->owner->enable_state == bp_permanent)
2933 && breakpoint_location_address_match (bl, aspace, pc))
2935 if (overlay_debugging
2936 && section_is_overlay (bl->section)
2937 && !section_is_mapped (bl->section))
2938 continue; /* unmapped overlay -- can't be a match */
2939 else if (bl->owner->enable_state == bp_permanent)
2940 return permanent_breakpoint_here;
2942 any_breakpoint_here = 1;
2946 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
2949 /* Return true if there's a moribund breakpoint at PC. */
2952 moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
2954 struct bp_location *loc;
2957 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
2958 if (breakpoint_location_address_match (loc, aspace, pc))
2964 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2965 inserted using regular breakpoint_chain / bp_location array
2966 mechanism. This does not check for single-step breakpoints, which
2967 are inserted and removed using direct target manipulation. */
2970 regular_breakpoint_inserted_here_p (struct address_space *aspace,
2973 struct bp_location *bl, **blp_tmp;
2975 ALL_BP_LOCATIONS (bl, blp_tmp)
2977 if (bl->loc_type != bp_loc_software_breakpoint
2978 && bl->loc_type != bp_loc_hardware_breakpoint)
2982 && breakpoint_location_address_match (bl, aspace, pc))
2984 if (overlay_debugging
2985 && section_is_overlay (bl->section)
2986 && !section_is_mapped (bl->section))
2987 continue; /* unmapped overlay -- can't be a match */
2995 /* Returns non-zero iff there's either regular breakpoint
2996 or a single step breakpoint inserted at PC. */
2999 breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
3001 if (regular_breakpoint_inserted_here_p (aspace, pc))
3004 if (single_step_breakpoint_inserted_here_p (aspace, pc))
3010 /* This function returns non-zero iff there is a software breakpoint
3014 software_breakpoint_inserted_here_p (struct address_space *aspace,
3017 struct bp_location *bl, **blp_tmp;
3019 ALL_BP_LOCATIONS (bl, blp_tmp)
3021 if (bl->loc_type != bp_loc_software_breakpoint)
3025 && breakpoint_address_match (bl->pspace->aspace, bl->address,
3028 if (overlay_debugging
3029 && section_is_overlay (bl->section)
3030 && !section_is_mapped (bl->section))
3031 continue; /* unmapped overlay -- can't be a match */
3037 /* Also check for software single-step breakpoints. */
3038 if (single_step_breakpoint_inserted_here_p (aspace, pc))
3045 hardware_watchpoint_inserted_in_range (struct address_space *aspace,
3046 CORE_ADDR addr, ULONGEST len)
3048 struct breakpoint *bpt;
3050 ALL_BREAKPOINTS (bpt)
3052 struct bp_location *loc;
3054 if (bpt->type != bp_hardware_watchpoint
3055 && bpt->type != bp_access_watchpoint)
3058 if (!breakpoint_enabled (bpt))
3061 for (loc = bpt->loc; loc; loc = loc->next)
3062 if (loc->pspace->aspace == aspace && loc->inserted)
3066 /* Check for intersection. */
3067 l = max (loc->address, addr);
3068 h = min (loc->address + loc->length, addr + len);
3076 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
3077 PC is valid for process/thread PTID. */
3080 breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc,
3083 struct bp_location *bl, **blp_tmp;
3084 /* The thread and task IDs associated to PTID, computed lazily. */
3088 ALL_BP_LOCATIONS (bl, blp_tmp)
3090 if (bl->loc_type != bp_loc_software_breakpoint
3091 && bl->loc_type != bp_loc_hardware_breakpoint)
3094 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
3095 if (!breakpoint_enabled (bl->owner)
3096 && bl->owner->enable_state != bp_permanent)
3099 if (!breakpoint_location_address_match (bl, aspace, pc))
3102 if (bl->owner->thread != -1)
3104 /* This is a thread-specific breakpoint. Check that ptid
3105 matches that thread. If thread hasn't been computed yet,
3106 it is now time to do so. */
3108 thread = pid_to_thread_id (ptid);
3109 if (bl->owner->thread != thread)
3113 if (bl->owner->task != 0)
3115 /* This is a task-specific breakpoint. Check that ptid
3116 matches that task. If task hasn't been computed yet,
3117 it is now time to do so. */
3119 task = ada_get_task_number (ptid);
3120 if (bl->owner->task != task)
3124 if (overlay_debugging
3125 && section_is_overlay (bl->section)
3126 && !section_is_mapped (bl->section))
3127 continue; /* unmapped overlay -- can't be a match */
3136 /* bpstat stuff. External routines' interfaces are documented
3140 ep_is_catchpoint (struct breakpoint *ep)
3142 return (ep->type == bp_catchpoint);
3145 /* Frees any storage that is part of a bpstat. Does not walk the
3149 bpstat_free (bpstat bs)
3151 if (bs->old_val != NULL)
3152 value_free (bs->old_val);
3153 decref_counted_command_line (&bs->commands);
3154 decref_bp_location (&bs->bp_location_at);
3158 /* Clear a bpstat so that it says we are not at any breakpoint.
3159 Also free any storage that is part of a bpstat. */
3162 bpstat_clear (bpstat *bsp)
3179 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
3180 is part of the bpstat is copied as well. */
3183 bpstat_copy (bpstat bs)
3187 bpstat retval = NULL;
3192 for (; bs != NULL; bs = bs->next)
3194 tmp = (bpstat) xmalloc (sizeof (*tmp));
3195 memcpy (tmp, bs, sizeof (*tmp));
3196 incref_counted_command_line (tmp->commands);
3197 incref_bp_location (tmp->bp_location_at);
3198 if (bs->old_val != NULL)
3200 tmp->old_val = value_copy (bs->old_val);
3201 release_value (tmp->old_val);
3205 /* This is the first thing in the chain. */
3215 /* Find the bpstat associated with this breakpoint. */
3218 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
3223 for (; bsp != NULL; bsp = bsp->next)
3225 if (bsp->breakpoint_at == breakpoint)
3231 /* Put in *NUM the breakpoint number of the first breakpoint we are
3232 stopped at. *BSP upon return is a bpstat which points to the
3233 remaining breakpoints stopped at (but which is not guaranteed to be
3234 good for anything but further calls to bpstat_num).
3236 Return 0 if passed a bpstat which does not indicate any breakpoints.
3237 Return -1 if stopped at a breakpoint that has been deleted since
3239 Return 1 otherwise. */
3242 bpstat_num (bpstat *bsp, int *num)
3244 struct breakpoint *b;
3247 return 0; /* No more breakpoint values */
3249 /* We assume we'll never have several bpstats that correspond to a
3250 single breakpoint -- otherwise, this function might return the
3251 same number more than once and this will look ugly. */
3252 b = (*bsp)->breakpoint_at;
3253 *bsp = (*bsp)->next;
3255 return -1; /* breakpoint that's been deleted since */
3257 *num = b->number; /* We have its number */
3261 /* See breakpoint.h. */
3264 bpstat_clear_actions (void)
3266 struct thread_info *tp;
3269 if (ptid_equal (inferior_ptid, null_ptid))
3272 tp = find_thread_ptid (inferior_ptid);
3276 for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next)
3278 decref_counted_command_line (&bs->commands);
3280 if (bs->old_val != NULL)
3282 value_free (bs->old_val);
3288 /* Called when a command is about to proceed the inferior. */
3291 breakpoint_about_to_proceed (void)
3293 if (!ptid_equal (inferior_ptid, null_ptid))
3295 struct thread_info *tp = inferior_thread ();
3297 /* Allow inferior function calls in breakpoint commands to not
3298 interrupt the command list. When the call finishes
3299 successfully, the inferior will be standing at the same
3300 breakpoint as if nothing happened. */
3301 if (tp->control.in_infcall)
3305 breakpoint_proceeded = 1;
3308 /* Stub for cleaning up our state if we error-out of a breakpoint
3311 cleanup_executing_breakpoints (void *ignore)
3313 executing_breakpoint_commands = 0;
3316 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
3317 or its equivalent. */
3320 command_line_is_silent (struct command_line *cmd)
3322 return cmd && (strcmp ("silent", cmd->line) == 0
3323 || (xdb_commands && strcmp ("Q", cmd->line) == 0));
3326 /* Execute all the commands associated with all the breakpoints at
3327 this location. Any of these commands could cause the process to
3328 proceed beyond this point, etc. We look out for such changes by
3329 checking the global "breakpoint_proceeded" after each command.
3331 Returns true if a breakpoint command resumed the inferior. In that
3332 case, it is the caller's responsibility to recall it again with the
3333 bpstat of the current thread. */
3336 bpstat_do_actions_1 (bpstat *bsp)
3339 struct cleanup *old_chain;
3342 /* Avoid endless recursion if a `source' command is contained
3344 if (executing_breakpoint_commands)
3347 executing_breakpoint_commands = 1;
3348 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
3350 prevent_dont_repeat ();
3352 /* This pointer will iterate over the list of bpstat's. */
3355 breakpoint_proceeded = 0;
3356 for (; bs != NULL; bs = bs->next)
3358 struct counted_command_line *ccmd;
3359 struct command_line *cmd;
3360 struct cleanup *this_cmd_tree_chain;
3362 /* Take ownership of the BSP's command tree, if it has one.
3364 The command tree could legitimately contain commands like
3365 'step' and 'next', which call clear_proceed_status, which
3366 frees stop_bpstat's command tree. To make sure this doesn't
3367 free the tree we're executing out from under us, we need to
3368 take ownership of the tree ourselves. Since a given bpstat's
3369 commands are only executed once, we don't need to copy it; we
3370 can clear the pointer in the bpstat, and make sure we free
3371 the tree when we're done. */
3372 ccmd = bs->commands;
3373 bs->commands = NULL;
3374 this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd);
3375 cmd = ccmd ? ccmd->commands : NULL;
3376 if (command_line_is_silent (cmd))
3378 /* The action has been already done by bpstat_stop_status. */
3384 execute_control_command (cmd);
3386 if (breakpoint_proceeded)
3392 /* We can free this command tree now. */
3393 do_cleanups (this_cmd_tree_chain);
3395 if (breakpoint_proceeded)
3397 if (target_can_async_p ())
3398 /* If we are in async mode, then the target might be still
3399 running, not stopped at any breakpoint, so nothing for
3400 us to do here -- just return to the event loop. */
3403 /* In sync mode, when execute_control_command returns
3404 we're already standing on the next breakpoint.
3405 Breakpoint commands for that stop were not run, since
3406 execute_command does not run breakpoint commands --
3407 only command_line_handler does, but that one is not
3408 involved in execution of breakpoint commands. So, we
3409 can now execute breakpoint commands. It should be
3410 noted that making execute_command do bpstat actions is
3411 not an option -- in this case we'll have recursive
3412 invocation of bpstat for each breakpoint with a
3413 command, and can easily blow up GDB stack. Instead, we
3414 return true, which will trigger the caller to recall us
3415 with the new stop_bpstat. */
3420 do_cleanups (old_chain);
3425 bpstat_do_actions (void)
3427 struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup ();
3429 /* Do any commands attached to breakpoint we are stopped at. */
3430 while (!ptid_equal (inferior_ptid, null_ptid)
3431 && target_has_execution
3432 && !is_exited (inferior_ptid)
3433 && !is_executing (inferior_ptid))
3434 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3435 and only return when it is stopped at the next breakpoint, we
3436 keep doing breakpoint actions until it returns false to
3437 indicate the inferior was not resumed. */
3438 if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat))
3441 discard_cleanups (cleanup_if_error);
3444 /* Print out the (old or new) value associated with a watchpoint. */
3447 watchpoint_value_print (struct value *val, struct ui_file *stream)
3450 fprintf_unfiltered (stream, _("<unreadable>"));
3453 struct value_print_options opts;
3454 get_user_print_options (&opts);
3455 value_print (val, stream, &opts);
3459 /* Generic routine for printing messages indicating why we
3460 stopped. The behavior of this function depends on the value
3461 'print_it' in the bpstat structure. Under some circumstances we
3462 may decide not to print anything here and delegate the task to
3465 static enum print_stop_action
3466 print_bp_stop_message (bpstat bs)
3468 switch (bs->print_it)
3471 /* Nothing should be printed for this bpstat entry. */
3472 return PRINT_UNKNOWN;
3476 /* We still want to print the frame, but we already printed the
3477 relevant messages. */
3478 return PRINT_SRC_AND_LOC;
3481 case print_it_normal:
3483 struct breakpoint *b = bs->breakpoint_at;
3485 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3486 which has since been deleted. */
3488 return PRINT_UNKNOWN;
3490 /* Normal case. Call the breakpoint's print_it method. */
3491 return b->ops->print_it (bs);
3496 internal_error (__FILE__, __LINE__,
3497 _("print_bp_stop_message: unrecognized enum value"));
3502 /* A helper function that prints a shared library stopped event. */
3505 print_solib_event (int is_catchpoint)
3508 = !VEC_empty (char_ptr, current_program_space->deleted_solibs);
3510 = !VEC_empty (so_list_ptr, current_program_space->added_solibs);
3514 if (any_added || any_deleted)
3515 ui_out_text (current_uiout,
3516 _("Stopped due to shared library event:\n"));
3518 ui_out_text (current_uiout,
3519 _("Stopped due to shared library event (no "
3520 "libraries added or removed)\n"));
3523 if (ui_out_is_mi_like_p (current_uiout))
3524 ui_out_field_string (current_uiout, "reason",
3525 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT));
3529 struct cleanup *cleanup;
3533 ui_out_text (current_uiout, _(" Inferior unloaded "));
3534 cleanup = make_cleanup_ui_out_list_begin_end (current_uiout,
3537 VEC_iterate (char_ptr, current_program_space->deleted_solibs,
3542 ui_out_text (current_uiout, " ");
3543 ui_out_field_string (current_uiout, "library", name);
3544 ui_out_text (current_uiout, "\n");
3547 do_cleanups (cleanup);
3552 struct so_list *iter;
3554 struct cleanup *cleanup;
3556 ui_out_text (current_uiout, _(" Inferior loaded "));
3557 cleanup = make_cleanup_ui_out_list_begin_end (current_uiout,
3560 VEC_iterate (so_list_ptr, current_program_space->added_solibs,
3565 ui_out_text (current_uiout, " ");
3566 ui_out_field_string (current_uiout, "library", iter->so_name);
3567 ui_out_text (current_uiout, "\n");
3570 do_cleanups (cleanup);
3574 /* Print a message indicating what happened. This is called from
3575 normal_stop(). The input to this routine is the head of the bpstat
3576 list - a list of the eventpoints that caused this stop. KIND is
3577 the target_waitkind for the stopping event. This
3578 routine calls the generic print routine for printing a message
3579 about reasons for stopping. This will print (for example) the
3580 "Breakpoint n," part of the output. The return value of this
3583 PRINT_UNKNOWN: Means we printed nothing.
3584 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3585 code to print the location. An example is
3586 "Breakpoint 1, " which should be followed by
3588 PRINT_SRC_ONLY: Means we printed something, but there is no need
3589 to also print the location part of the message.
3590 An example is the catch/throw messages, which
3591 don't require a location appended to the end.
3592 PRINT_NOTHING: We have done some printing and we don't need any
3593 further info to be printed. */
3595 enum print_stop_action
3596 bpstat_print (bpstat bs, int kind)
3600 /* Maybe another breakpoint in the chain caused us to stop.
3601 (Currently all watchpoints go on the bpstat whether hit or not.
3602 That probably could (should) be changed, provided care is taken
3603 with respect to bpstat_explains_signal). */
3604 for (; bs; bs = bs->next)
3606 val = print_bp_stop_message (bs);
3607 if (val == PRINT_SRC_ONLY
3608 || val == PRINT_SRC_AND_LOC
3609 || val == PRINT_NOTHING)
3613 /* If we had hit a shared library event breakpoint,
3614 print_bp_stop_message would print out this message. If we hit an
3615 OS-level shared library event, do the same thing. */
3616 if (kind == TARGET_WAITKIND_LOADED)
3618 print_solib_event (0);
3619 return PRINT_NOTHING;
3622 /* We reached the end of the chain, or we got a null BS to start
3623 with and nothing was printed. */
3624 return PRINT_UNKNOWN;
3627 /* Evaluate the expression EXP and return 1 if value is zero. This is
3628 used inside a catch_errors to evaluate the breakpoint condition.
3629 The argument is a "struct expression *" that has been cast to a
3630 "char *" to make it pass through catch_errors. */
3633 breakpoint_cond_eval (void *exp)
3635 struct value *mark = value_mark ();
3636 int i = !value_true (evaluate_expression ((struct expression *) exp));
3638 value_free_to_mark (mark);
3642 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
3645 bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer)
3649 bs = (bpstat) xmalloc (sizeof (*bs));
3651 **bs_link_pointer = bs;
3652 *bs_link_pointer = &bs->next;
3653 bs->breakpoint_at = bl->owner;
3654 bs->bp_location_at = bl;
3655 incref_bp_location (bl);
3656 /* If the condition is false, etc., don't do the commands. */
3657 bs->commands = NULL;
3659 bs->print_it = print_it_normal;
3663 /* The target has stopped with waitstatus WS. Check if any hardware
3664 watchpoints have triggered, according to the target. */
3667 watchpoints_triggered (struct target_waitstatus *ws)
3669 int stopped_by_watchpoint = target_stopped_by_watchpoint ();
3671 struct breakpoint *b;
3673 if (!stopped_by_watchpoint)
3675 /* We were not stopped by a watchpoint. Mark all watchpoints
3676 as not triggered. */
3678 if (is_hardware_watchpoint (b))
3680 struct watchpoint *w = (struct watchpoint *) b;
3682 w->watchpoint_triggered = watch_triggered_no;
3688 if (!target_stopped_data_address (¤t_target, &addr))
3690 /* We were stopped by a watchpoint, but we don't know where.
3691 Mark all watchpoints as unknown. */
3693 if (is_hardware_watchpoint (b))
3695 struct watchpoint *w = (struct watchpoint *) b;
3697 w->watchpoint_triggered = watch_triggered_unknown;
3700 return stopped_by_watchpoint;
3703 /* The target could report the data address. Mark watchpoints
3704 affected by this data address as triggered, and all others as not
3708 if (is_hardware_watchpoint (b))
3710 struct watchpoint *w = (struct watchpoint *) b;
3711 struct bp_location *loc;
3713 w->watchpoint_triggered = watch_triggered_no;
3714 for (loc = b->loc; loc; loc = loc->next)
3716 if (is_masked_watchpoint (b))
3718 CORE_ADDR newaddr = addr & w->hw_wp_mask;
3719 CORE_ADDR start = loc->address & w->hw_wp_mask;
3721 if (newaddr == start)
3723 w->watchpoint_triggered = watch_triggered_yes;
3727 /* Exact match not required. Within range is sufficient. */
3728 else if (target_watchpoint_addr_within_range (¤t_target,
3732 w->watchpoint_triggered = watch_triggered_yes;
3741 /* Possible return values for watchpoint_check (this can't be an enum
3742 because of check_errors). */
3743 /* The watchpoint has been deleted. */
3744 #define WP_DELETED 1
3745 /* The value has changed. */
3746 #define WP_VALUE_CHANGED 2
3747 /* The value has not changed. */
3748 #define WP_VALUE_NOT_CHANGED 3
3749 /* Ignore this watchpoint, no matter if the value changed or not. */
3752 #define BP_TEMPFLAG 1
3753 #define BP_HARDWAREFLAG 2
3755 /* Evaluate watchpoint condition expression and check if its value
3758 P should be a pointer to struct bpstat, but is defined as a void *
3759 in order for this function to be usable with catch_errors. */
3762 watchpoint_check (void *p)
3764 bpstat bs = (bpstat) p;
3765 struct watchpoint *b;
3766 struct frame_info *fr;
3767 int within_current_scope;
3769 /* BS is built from an existing struct breakpoint. */
3770 gdb_assert (bs->breakpoint_at != NULL);
3771 b = (struct watchpoint *) bs->breakpoint_at;
3773 /* If this is a local watchpoint, we only want to check if the
3774 watchpoint frame is in scope if the current thread is the thread
3775 that was used to create the watchpoint. */
3776 if (!watchpoint_in_thread_scope (b))
3779 if (b->exp_valid_block == NULL)
3780 within_current_scope = 1;
3783 struct frame_info *frame = get_current_frame ();
3784 struct gdbarch *frame_arch = get_frame_arch (frame);
3785 CORE_ADDR frame_pc = get_frame_pc (frame);
3787 /* in_function_epilogue_p() returns a non-zero value if we're
3788 still in the function but the stack frame has already been
3789 invalidated. Since we can't rely on the values of local
3790 variables after the stack has been destroyed, we are treating
3791 the watchpoint in that state as `not changed' without further
3792 checking. Don't mark watchpoints as changed if the current
3793 frame is in an epilogue - even if they are in some other
3794 frame, our view of the stack is likely to be wrong and
3795 frame_find_by_id could error out. */
3796 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
3799 fr = frame_find_by_id (b->watchpoint_frame);
3800 within_current_scope = (fr != NULL);
3802 /* If we've gotten confused in the unwinder, we might have
3803 returned a frame that can't describe this variable. */
3804 if (within_current_scope)
3806 struct symbol *function;
3808 function = get_frame_function (fr);
3809 if (function == NULL
3810 || !contained_in (b->exp_valid_block,
3811 SYMBOL_BLOCK_VALUE (function)))
3812 within_current_scope = 0;
3815 if (within_current_scope)
3816 /* If we end up stopping, the current frame will get selected
3817 in normal_stop. So this call to select_frame won't affect
3822 if (within_current_scope)
3824 /* We use value_{,free_to_}mark because it could be a *long*
3825 time before we return to the command level and call
3826 free_all_values. We can't call free_all_values because we
3827 might be in the middle of evaluating a function call. */
3831 struct value *new_val;
3833 if (is_masked_watchpoint (&b->base))
3834 /* Since we don't know the exact trigger address (from
3835 stopped_data_address), just tell the user we've triggered
3836 a mask watchpoint. */
3837 return WP_VALUE_CHANGED;
3839 mark = value_mark ();
3840 fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL);
3842 /* We use value_equal_contents instead of value_equal because
3843 the latter coerces an array to a pointer, thus comparing just
3844 the address of the array instead of its contents. This is
3845 not what we want. */
3846 if ((b->val != NULL) != (new_val != NULL)
3847 || (b->val != NULL && !value_equal_contents (b->val, new_val)))
3849 if (new_val != NULL)
3851 release_value (new_val);
3852 value_free_to_mark (mark);
3854 bs->old_val = b->val;
3857 return WP_VALUE_CHANGED;
3861 /* Nothing changed. */
3862 value_free_to_mark (mark);
3863 return WP_VALUE_NOT_CHANGED;
3868 struct ui_out *uiout = current_uiout;
3870 /* This seems like the only logical thing to do because
3871 if we temporarily ignored the watchpoint, then when
3872 we reenter the block in which it is valid it contains
3873 garbage (in the case of a function, it may have two
3874 garbage values, one before and one after the prologue).
3875 So we can't even detect the first assignment to it and
3876 watch after that (since the garbage may or may not equal
3877 the first value assigned). */
3878 /* We print all the stop information in
3879 breakpoint_ops->print_it, but in this case, by the time we
3880 call breakpoint_ops->print_it this bp will be deleted
3881 already. So we have no choice but print the information
3883 if (ui_out_is_mi_like_p (uiout))
3885 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
3886 ui_out_text (uiout, "\nWatchpoint ");
3887 ui_out_field_int (uiout, "wpnum", b->base.number);
3889 " deleted because the program has left the block in\n\
3890 which its expression is valid.\n");
3892 /* Make sure the watchpoint's commands aren't executed. */
3893 decref_counted_command_line (&b->base.commands);
3894 watchpoint_del_at_next_stop (b);
3900 /* Return true if it looks like target has stopped due to hitting
3901 breakpoint location BL. This function does not check if we should
3902 stop, only if BL explains the stop. */
3905 bpstat_check_location (const struct bp_location *bl,
3906 struct address_space *aspace, CORE_ADDR bp_addr,
3907 const struct target_waitstatus *ws)
3909 struct breakpoint *b = bl->owner;
3911 /* BL is from an existing breakpoint. */
3912 gdb_assert (b != NULL);
3914 return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws);
3917 /* Determine if the watched values have actually changed, and we
3918 should stop. If not, set BS->stop to 0. */
3921 bpstat_check_watchpoint (bpstat bs)
3923 const struct bp_location *bl;
3924 struct watchpoint *b;
3926 /* BS is built for existing struct breakpoint. */
3927 bl = bs->bp_location_at;
3928 gdb_assert (bl != NULL);
3929 b = (struct watchpoint *) bs->breakpoint_at;
3930 gdb_assert (b != NULL);
3933 int must_check_value = 0;
3935 if (b->base.type == bp_watchpoint)
3936 /* For a software watchpoint, we must always check the
3938 must_check_value = 1;
3939 else if (b->watchpoint_triggered == watch_triggered_yes)
3940 /* We have a hardware watchpoint (read, write, or access)
3941 and the target earlier reported an address watched by
3943 must_check_value = 1;
3944 else if (b->watchpoint_triggered == watch_triggered_unknown
3945 && b->base.type == bp_hardware_watchpoint)
3946 /* We were stopped by a hardware watchpoint, but the target could
3947 not report the data address. We must check the watchpoint's
3948 value. Access and read watchpoints are out of luck; without
3949 a data address, we can't figure it out. */
3950 must_check_value = 1;
3952 if (must_check_value)
3955 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
3957 struct cleanup *cleanups = make_cleanup (xfree, message);
3958 int e = catch_errors (watchpoint_check, bs, message,
3960 do_cleanups (cleanups);
3964 /* We've already printed what needs to be printed. */
3965 bs->print_it = print_it_done;
3969 bs->print_it = print_it_noop;
3972 case WP_VALUE_CHANGED:
3973 if (b->base.type == bp_read_watchpoint)
3975 /* There are two cases to consider here:
3977 1. We're watching the triggered memory for reads.
3978 In that case, trust the target, and always report
3979 the watchpoint hit to the user. Even though
3980 reads don't cause value changes, the value may
3981 have changed since the last time it was read, and
3982 since we're not trapping writes, we will not see
3983 those, and as such we should ignore our notion of
3986 2. We're watching the triggered memory for both
3987 reads and writes. There are two ways this may
3990 2.1. This is a target that can't break on data
3991 reads only, but can break on accesses (reads or
3992 writes), such as e.g., x86. We detect this case
3993 at the time we try to insert read watchpoints.
3995 2.2. Otherwise, the target supports read
3996 watchpoints, but, the user set an access or write
3997 watchpoint watching the same memory as this read
4000 If we're watching memory writes as well as reads,
4001 ignore watchpoint hits when we find that the
4002 value hasn't changed, as reads don't cause
4003 changes. This still gives false positives when
4004 the program writes the same value to memory as
4005 what there was already in memory (we will confuse
4006 it for a read), but it's much better than
4009 int other_write_watchpoint = 0;
4011 if (bl->watchpoint_type == hw_read)
4013 struct breakpoint *other_b;
4015 ALL_BREAKPOINTS (other_b)
4016 if (other_b->type == bp_hardware_watchpoint
4017 || other_b->type == bp_access_watchpoint)
4019 struct watchpoint *other_w =
4020 (struct watchpoint *) other_b;
4022 if (other_w->watchpoint_triggered
4023 == watch_triggered_yes)
4025 other_write_watchpoint = 1;
4031 if (other_write_watchpoint
4032 || bl->watchpoint_type == hw_access)
4034 /* We're watching the same memory for writes,
4035 and the value changed since the last time we
4036 updated it, so this trap must be for a write.
4038 bs->print_it = print_it_noop;
4043 case WP_VALUE_NOT_CHANGED:
4044 if (b->base.type == bp_hardware_watchpoint
4045 || b->base.type == bp_watchpoint)
4047 /* Don't stop: write watchpoints shouldn't fire if
4048 the value hasn't changed. */
4049 bs->print_it = print_it_noop;
4057 /* Error from catch_errors. */
4058 printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number);
4059 watchpoint_del_at_next_stop (b);
4060 /* We've already printed what needs to be printed. */
4061 bs->print_it = print_it_done;
4065 else /* must_check_value == 0 */
4067 /* This is a case where some watchpoint(s) triggered, but
4068 not at the address of this watchpoint, or else no
4069 watchpoint triggered after all. So don't print
4070 anything for this watchpoint. */
4071 bs->print_it = print_it_noop;
4078 /* Check conditions (condition proper, frame, thread and ignore count)
4079 of breakpoint referred to by BS. If we should not stop for this
4080 breakpoint, set BS->stop to 0. */
4083 bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
4085 int thread_id = pid_to_thread_id (ptid);
4086 const struct bp_location *bl;
4087 struct breakpoint *b;
4089 /* BS is built for existing struct breakpoint. */
4090 bl = bs->bp_location_at;
4091 gdb_assert (bl != NULL);
4092 b = bs->breakpoint_at;
4093 gdb_assert (b != NULL);
4095 if (frame_id_p (b->frame_id)
4096 && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ())))
4100 int value_is_zero = 0;
4101 struct expression *cond;
4103 /* Evaluate Python breakpoints that have a "stop"
4104 method implemented. */
4105 if (b->py_bp_object)
4106 bs->stop = gdbpy_should_stop (b->py_bp_object);
4108 if (is_watchpoint (b))
4110 struct watchpoint *w = (struct watchpoint *) b;
4117 if (cond && b->disposition != disp_del_at_next_stop)
4119 int within_current_scope = 1;
4120 struct watchpoint * w;
4122 /* We use value_mark and value_free_to_mark because it could
4123 be a long time before we return to the command level and
4124 call free_all_values. We can't call free_all_values
4125 because we might be in the middle of evaluating a
4127 struct value *mark = value_mark ();
4129 if (is_watchpoint (b))
4130 w = (struct watchpoint *) b;
4134 /* Need to select the frame, with all that implies so that
4135 the conditions will have the right context. Because we
4136 use the frame, we will not see an inlined function's
4137 variables when we arrive at a breakpoint at the start
4138 of the inlined function; the current frame will be the
4140 if (w == NULL || w->cond_exp_valid_block == NULL)
4141 select_frame (get_current_frame ());
4144 struct frame_info *frame;
4146 /* For local watchpoint expressions, which particular
4147 instance of a local is being watched matters, so we
4148 keep track of the frame to evaluate the expression
4149 in. To evaluate the condition however, it doesn't
4150 really matter which instantiation of the function
4151 where the condition makes sense triggers the
4152 watchpoint. This allows an expression like "watch
4153 global if q > 10" set in `func', catch writes to
4154 global on all threads that call `func', or catch
4155 writes on all recursive calls of `func' by a single
4156 thread. We simply always evaluate the condition in
4157 the innermost frame that's executing where it makes
4158 sense to evaluate the condition. It seems
4160 frame = block_innermost_frame (w->cond_exp_valid_block);
4162 select_frame (frame);
4164 within_current_scope = 0;
4166 if (within_current_scope)
4168 = catch_errors (breakpoint_cond_eval, cond,
4169 "Error in testing breakpoint condition:\n",
4173 warning (_("Watchpoint condition cannot be tested "
4174 "in the current scope"));
4175 /* If we failed to set the right context for this
4176 watchpoint, unconditionally report it. */
4179 /* FIXME-someday, should give breakpoint #. */
4180 value_free_to_mark (mark);
4183 if (cond && value_is_zero)
4187 else if (b->thread != -1 && b->thread != thread_id)
4191 else if (b->ignore_count > 0)
4194 annotate_ignore_count_change ();
4196 /* Increase the hit count even though we don't stop. */
4198 observer_notify_breakpoint_modified (b);
4204 /* Get a bpstat associated with having just stopped at address
4205 BP_ADDR in thread PTID.
4207 Determine whether we stopped at a breakpoint, etc, or whether we
4208 don't understand this stop. Result is a chain of bpstat's such
4211 if we don't understand the stop, the result is a null pointer.
4213 if we understand why we stopped, the result is not null.
4215 Each element of the chain refers to a particular breakpoint or
4216 watchpoint at which we have stopped. (We may have stopped for
4217 several reasons concurrently.)
4219 Each element of the chain has valid next, breakpoint_at,
4220 commands, FIXME??? fields. */
4223 bpstat_stop_status (struct address_space *aspace,
4224 CORE_ADDR bp_addr, ptid_t ptid,
4225 const struct target_waitstatus *ws)
4227 struct breakpoint *b = NULL;
4228 struct bp_location *bl;
4229 struct bp_location *loc;
4230 /* First item of allocated bpstat's. */
4231 bpstat bs_head = NULL, *bs_link = &bs_head;
4232 /* Pointer to the last thing in the chain currently. */
4235 int need_remove_insert;
4238 /* First, build the bpstat chain with locations that explain a
4239 target stop, while being careful to not set the target running,
4240 as that may invalidate locations (in particular watchpoint
4241 locations are recreated). Resuming will happen here with
4242 breakpoint conditions or watchpoint expressions that include
4243 inferior function calls. */
4247 if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
4250 for (bl = b->loc; bl != NULL; bl = bl->next)
4252 /* For hardware watchpoints, we look only at the first
4253 location. The watchpoint_check function will work on the
4254 entire expression, not the individual locations. For
4255 read watchpoints, the watchpoints_triggered function has
4256 checked all locations already. */
4257 if (b->type == bp_hardware_watchpoint && bl != b->loc)
4260 if (bl->shlib_disabled)
4263 if (!bpstat_check_location (bl, aspace, bp_addr, ws))
4266 /* Come here if it's a watchpoint, or if the break address
4269 bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to
4272 /* Assume we stop. Should we find a watchpoint that is not
4273 actually triggered, or if the condition of the breakpoint
4274 evaluates as false, we'll reset 'stop' to 0. */
4278 /* If this is a scope breakpoint, mark the associated
4279 watchpoint as triggered so that we will handle the
4280 out-of-scope event. We'll get to the watchpoint next
4282 if (b->type == bp_watchpoint_scope && b->related_breakpoint != b)
4284 struct watchpoint *w = (struct watchpoint *) b->related_breakpoint;
4286 w->watchpoint_triggered = watch_triggered_yes;
4291 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
4293 if (breakpoint_location_address_match (loc, aspace, bp_addr))
4295 bs = bpstat_alloc (loc, &bs_link);
4296 /* For hits of moribund locations, we should just proceed. */
4299 bs->print_it = print_it_noop;
4303 /* A bit of special processing for shlib breakpoints. We need to
4304 process solib loading here, so that the lists of loaded and
4305 unloaded libraries are correct before we handle "catch load" and
4307 for (bs = bs_head; bs != NULL; bs = bs->next)
4309 if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event)
4311 handle_solib_event ();
4316 /* Now go through the locations that caused the target to stop, and
4317 check whether we're interested in reporting this stop to higher
4318 layers, or whether we should resume the target transparently. */
4322 for (bs = bs_head; bs != NULL; bs = bs->next)
4327 b = bs->breakpoint_at;
4328 b->ops->check_status (bs);
4331 bpstat_check_breakpoint_conditions (bs, ptid);
4336 observer_notify_breakpoint_modified (b);
4338 /* We will stop here. */
4339 if (b->disposition == disp_disable)
4341 --(b->enable_count);
4342 if (b->enable_count <= 0
4343 && b->enable_state != bp_permanent)
4344 b->enable_state = bp_disabled;
4349 bs->commands = b->commands;
4350 incref_counted_command_line (bs->commands);
4351 if (command_line_is_silent (bs->commands
4352 ? bs->commands->commands : NULL))
4358 /* Print nothing for this entry if we don't stop or don't
4360 if (!bs->stop || !bs->print)
4361 bs->print_it = print_it_noop;
4364 /* If we aren't stopping, the value of some hardware watchpoint may
4365 not have changed, but the intermediate memory locations we are
4366 watching may have. Don't bother if we're stopping; this will get
4368 need_remove_insert = 0;
4369 if (! bpstat_causes_stop (bs_head))
4370 for (bs = bs_head; bs != NULL; bs = bs->next)
4372 && bs->breakpoint_at
4373 && is_hardware_watchpoint (bs->breakpoint_at))
4375 struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at;
4377 update_watchpoint (w, 0 /* don't reparse. */);
4378 need_remove_insert = 1;
4381 if (need_remove_insert)
4382 update_global_location_list (1);
4383 else if (removed_any)
4384 update_global_location_list (0);
4390 handle_jit_event (void)
4392 struct frame_info *frame;
4393 struct gdbarch *gdbarch;
4395 /* Switch terminal for any messages produced by
4396 breakpoint_re_set. */
4397 target_terminal_ours_for_output ();
4399 frame = get_current_frame ();
4400 gdbarch = get_frame_arch (frame);
4402 jit_event_handler (gdbarch);
4404 target_terminal_inferior ();
4407 /* Handle an solib event by calling solib_add. */
4410 handle_solib_event (void)
4412 clear_program_space_solib_cache (current_inferior ()->pspace);
4414 /* Check for any newly added shared libraries if we're supposed to
4415 be adding them automatically. Switch terminal for any messages
4416 produced by breakpoint_re_set. */
4417 target_terminal_ours_for_output ();
4419 SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add);
4421 solib_add (NULL, 0, ¤t_target, auto_solib_add);
4423 target_terminal_inferior ();
4426 /* Prepare WHAT final decision for infrun. */
4428 /* Decide what infrun needs to do with this bpstat. */
4431 bpstat_what (bpstat bs_head)
4433 struct bpstat_what retval;
4437 retval.main_action = BPSTAT_WHAT_KEEP_CHECKING;
4438 retval.call_dummy = STOP_NONE;
4439 retval.is_longjmp = 0;
4441 for (bs = bs_head; bs != NULL; bs = bs->next)
4443 /* Extract this BS's action. After processing each BS, we check
4444 if its action overrides all we've seem so far. */
4445 enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING;
4448 if (bs->breakpoint_at == NULL)
4450 /* I suspect this can happen if it was a momentary
4451 breakpoint which has since been deleted. */
4455 bptype = bs->breakpoint_at->type;
4462 case bp_hardware_breakpoint:
4465 case bp_shlib_event:
4469 this_action = BPSTAT_WHAT_STOP_NOISY;
4471 this_action = BPSTAT_WHAT_STOP_SILENT;
4474 this_action = BPSTAT_WHAT_SINGLE;
4477 case bp_hardware_watchpoint:
4478 case bp_read_watchpoint:
4479 case bp_access_watchpoint:
4483 this_action = BPSTAT_WHAT_STOP_NOISY;
4485 this_action = BPSTAT_WHAT_STOP_SILENT;
4489 /* There was a watchpoint, but we're not stopping.
4490 This requires no further action. */
4495 this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME;
4496 retval.is_longjmp = bptype == bp_longjmp;
4498 case bp_longjmp_resume:
4499 case bp_exception_resume:
4500 this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME;
4501 retval.is_longjmp = bptype == bp_longjmp_resume;
4503 case bp_step_resume:
4505 this_action = BPSTAT_WHAT_STEP_RESUME;
4508 /* It is for the wrong frame. */
4509 this_action = BPSTAT_WHAT_SINGLE;
4512 case bp_hp_step_resume:
4514 this_action = BPSTAT_WHAT_HP_STEP_RESUME;
4517 /* It is for the wrong frame. */
4518 this_action = BPSTAT_WHAT_SINGLE;
4521 case bp_watchpoint_scope:
4522 case bp_thread_event:
4523 case bp_overlay_event:
4524 case bp_longjmp_master:
4525 case bp_std_terminate_master:
4526 case bp_exception_master:
4527 this_action = BPSTAT_WHAT_SINGLE;
4533 this_action = BPSTAT_WHAT_STOP_NOISY;
4535 this_action = BPSTAT_WHAT_STOP_SILENT;
4539 /* There was a catchpoint, but we're not stopping.
4540 This requires no further action. */
4545 this_action = BPSTAT_WHAT_SINGLE;
4548 /* Make sure the action is stop (silent or noisy),
4549 so infrun.c pops the dummy frame. */
4550 retval.call_dummy = STOP_STACK_DUMMY;
4551 this_action = BPSTAT_WHAT_STOP_SILENT;
4553 case bp_std_terminate:
4554 /* Make sure the action is stop (silent or noisy),
4555 so infrun.c pops the dummy frame. */
4556 retval.call_dummy = STOP_STD_TERMINATE;
4557 this_action = BPSTAT_WHAT_STOP_SILENT;
4560 case bp_fast_tracepoint:
4561 case bp_static_tracepoint:
4562 /* Tracepoint hits should not be reported back to GDB, and
4563 if one got through somehow, it should have been filtered
4565 internal_error (__FILE__, __LINE__,
4566 _("bpstat_what: tracepoint encountered"));
4568 case bp_gnu_ifunc_resolver:
4569 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
4570 this_action = BPSTAT_WHAT_SINGLE;
4572 case bp_gnu_ifunc_resolver_return:
4573 /* The breakpoint will be removed, execution will restart from the
4574 PC of the former breakpoint. */
4575 this_action = BPSTAT_WHAT_KEEP_CHECKING;
4578 internal_error (__FILE__, __LINE__,
4579 _("bpstat_what: unhandled bptype %d"), (int) bptype);
4582 retval.main_action = max (retval.main_action, this_action);
4585 /* These operations may affect the bs->breakpoint_at state so they are
4586 delayed after MAIN_ACTION is decided above. */
4591 fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n");
4593 handle_jit_event ();
4596 for (bs = bs_head; bs != NULL; bs = bs->next)
4598 struct breakpoint *b = bs->breakpoint_at;
4604 case bp_gnu_ifunc_resolver:
4605 gnu_ifunc_resolver_stop (b);
4607 case bp_gnu_ifunc_resolver_return:
4608 gnu_ifunc_resolver_return_stop (b);
4616 /* Nonzero if we should step constantly (e.g. watchpoints on machines
4617 without hardware support). This isn't related to a specific bpstat,
4618 just to things like whether watchpoints are set. */
4621 bpstat_should_step (void)
4623 struct breakpoint *b;
4626 if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL)
4632 bpstat_causes_stop (bpstat bs)
4634 for (; bs != NULL; bs = bs->next)
4643 /* Compute a string of spaces suitable to indent the next line
4644 so it starts at the position corresponding to the table column
4645 named COL_NAME in the currently active table of UIOUT. */
4648 wrap_indent_at_field (struct ui_out *uiout, const char *col_name)
4650 static char wrap_indent[80];
4651 int i, total_width, width, align;
4655 for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++)
4657 if (strcmp (text, col_name) == 0)
4659 gdb_assert (total_width < sizeof wrap_indent);
4660 memset (wrap_indent, ' ', total_width);
4661 wrap_indent[total_width] = 0;
4666 total_width += width + 1;
4672 /* Print the LOC location out of the list of B->LOC locations. */
4675 print_breakpoint_location (struct breakpoint *b,
4676 struct bp_location *loc)
4678 struct ui_out *uiout = current_uiout;
4679 struct cleanup *old_chain = save_current_program_space ();
4681 if (loc != NULL && loc->shlib_disabled)
4685 set_current_program_space (loc->pspace);
4687 if (b->display_canonical)
4688 ui_out_field_string (uiout, "what", b->addr_string);
4689 else if (loc && loc->source_file)
4692 = find_pc_sect_function (loc->address, loc->section);
4695 ui_out_text (uiout, "in ");
4696 ui_out_field_string (uiout, "func",
4697 SYMBOL_PRINT_NAME (sym));
4698 ui_out_text (uiout, " ");
4699 ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what"));
4700 ui_out_text (uiout, "at ");
4702 ui_out_field_string (uiout, "file", loc->source_file);
4703 ui_out_text (uiout, ":");
4705 if (ui_out_is_mi_like_p (uiout))
4707 struct symtab_and_line sal = find_pc_line (loc->address, 0);
4708 char *fullname = symtab_to_fullname (sal.symtab);
4711 ui_out_field_string (uiout, "fullname", fullname);
4714 ui_out_field_int (uiout, "line", loc->line_number);
4718 struct ui_stream *stb = ui_out_stream_new (uiout);
4719 struct cleanup *stb_chain = make_cleanup_ui_out_stream_delete (stb);
4721 print_address_symbolic (loc->gdbarch, loc->address, stb->stream,
4723 ui_out_field_stream (uiout, "at", stb);
4725 do_cleanups (stb_chain);
4728 ui_out_field_string (uiout, "pending", b->addr_string);
4730 do_cleanups (old_chain);
4734 bptype_string (enum bptype type)
4736 struct ep_type_description
4741 static struct ep_type_description bptypes[] =
4743 {bp_none, "?deleted?"},
4744 {bp_breakpoint, "breakpoint"},
4745 {bp_hardware_breakpoint, "hw breakpoint"},
4746 {bp_until, "until"},
4747 {bp_finish, "finish"},
4748 {bp_watchpoint, "watchpoint"},
4749 {bp_hardware_watchpoint, "hw watchpoint"},
4750 {bp_read_watchpoint, "read watchpoint"},
4751 {bp_access_watchpoint, "acc watchpoint"},
4752 {bp_longjmp, "longjmp"},
4753 {bp_longjmp_resume, "longjmp resume"},
4754 {bp_exception, "exception"},
4755 {bp_exception_resume, "exception resume"},
4756 {bp_step_resume, "step resume"},
4757 {bp_hp_step_resume, "high-priority step resume"},
4758 {bp_watchpoint_scope, "watchpoint scope"},
4759 {bp_call_dummy, "call dummy"},
4760 {bp_std_terminate, "std::terminate"},
4761 {bp_shlib_event, "shlib events"},
4762 {bp_thread_event, "thread events"},
4763 {bp_overlay_event, "overlay events"},
4764 {bp_longjmp_master, "longjmp master"},
4765 {bp_std_terminate_master, "std::terminate master"},
4766 {bp_exception_master, "exception master"},
4767 {bp_catchpoint, "catchpoint"},
4768 {bp_tracepoint, "tracepoint"},
4769 {bp_fast_tracepoint, "fast tracepoint"},
4770 {bp_static_tracepoint, "static tracepoint"},
4771 {bp_jit_event, "jit events"},
4772 {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"},
4773 {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"},
4776 if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0])))
4777 || ((int) type != bptypes[(int) type].type))
4778 internal_error (__FILE__, __LINE__,
4779 _("bptypes table does not describe type #%d."),
4782 return bptypes[(int) type].description;
4785 /* Print B to gdb_stdout. */
4788 print_one_breakpoint_location (struct breakpoint *b,
4789 struct bp_location *loc,
4791 struct bp_location **last_loc,
4794 struct command_line *l;
4795 static char bpenables[] = "nynny";
4797 struct ui_out *uiout = current_uiout;
4798 int header_of_multiple = 0;
4799 int part_of_multiple = (loc != NULL);
4800 struct value_print_options opts;
4802 get_user_print_options (&opts);
4804 gdb_assert (!loc || loc_number != 0);
4805 /* See comment in print_one_breakpoint concerning treatment of
4806 breakpoints with single disabled location. */
4809 && (b->loc->next != NULL || !b->loc->enabled)))
4810 header_of_multiple = 1;
4818 if (part_of_multiple)
4821 formatted = xstrprintf ("%d.%d", b->number, loc_number);
4822 ui_out_field_string (uiout, "number", formatted);
4827 ui_out_field_int (uiout, "number", b->number);
4832 if (part_of_multiple)
4833 ui_out_field_skip (uiout, "type");
4835 ui_out_field_string (uiout, "type", bptype_string (b->type));
4839 if (part_of_multiple)
4840 ui_out_field_skip (uiout, "disp");
4842 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
4847 if (part_of_multiple)
4848 ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n");
4850 ui_out_field_fmt (uiout, "enabled", "%c",
4851 bpenables[(int) b->enable_state]);
4852 ui_out_spaces (uiout, 2);
4856 if (b->ops != NULL && b->ops->print_one != NULL)
4858 /* Although the print_one can possibly print all locations,
4859 calling it here is not likely to get any nice result. So,
4860 make sure there's just one location. */
4861 gdb_assert (b->loc == NULL || b->loc->next == NULL);
4862 b->ops->print_one (b, last_loc);
4868 internal_error (__FILE__, __LINE__,
4869 _("print_one_breakpoint: bp_none encountered\n"));
4873 case bp_hardware_watchpoint:
4874 case bp_read_watchpoint:
4875 case bp_access_watchpoint:
4877 struct watchpoint *w = (struct watchpoint *) b;
4879 /* Field 4, the address, is omitted (which makes the columns
4880 not line up too nicely with the headers, but the effect
4881 is relatively readable). */
4882 if (opts.addressprint)
4883 ui_out_field_skip (uiout, "addr");
4885 ui_out_field_string (uiout, "what", w->exp_string);
4890 case bp_hardware_breakpoint:
4894 case bp_longjmp_resume:
4896 case bp_exception_resume:
4897 case bp_step_resume:
4898 case bp_hp_step_resume:
4899 case bp_watchpoint_scope:
4901 case bp_std_terminate:
4902 case bp_shlib_event:
4903 case bp_thread_event:
4904 case bp_overlay_event:
4905 case bp_longjmp_master:
4906 case bp_std_terminate_master:
4907 case bp_exception_master:
4909 case bp_fast_tracepoint:
4910 case bp_static_tracepoint:
4912 case bp_gnu_ifunc_resolver:
4913 case bp_gnu_ifunc_resolver_return:
4914 if (opts.addressprint)
4917 if (header_of_multiple)
4918 ui_out_field_string (uiout, "addr", "<MULTIPLE>");
4919 else if (b->loc == NULL || loc->shlib_disabled)
4920 ui_out_field_string (uiout, "addr", "<PENDING>");
4922 ui_out_field_core_addr (uiout, "addr",
4923 loc->gdbarch, loc->address);
4926 if (!header_of_multiple)
4927 print_breakpoint_location (b, loc);
4934 /* For backward compatibility, don't display inferiors unless there
4937 && !header_of_multiple
4939 || (!gdbarch_has_global_breakpoints (target_gdbarch)
4940 && (number_of_program_spaces () > 1
4941 || number_of_inferiors () > 1)
4942 /* LOC is for existing B, it cannot be in
4943 moribund_locations and thus having NULL OWNER. */
4944 && loc->owner->type != bp_catchpoint)))
4946 struct inferior *inf;
4949 for (inf = inferior_list; inf != NULL; inf = inf->next)
4951 if (inf->pspace == loc->pspace)
4956 ui_out_text (uiout, " inf ");
4959 ui_out_text (uiout, ", ");
4960 ui_out_text (uiout, plongest (inf->num));
4965 if (!part_of_multiple)
4967 if (b->thread != -1)
4969 /* FIXME: This seems to be redundant and lost here; see the
4970 "stop only in" line a little further down. */
4971 ui_out_text (uiout, " thread ");
4972 ui_out_field_int (uiout, "thread", b->thread);
4974 else if (b->task != 0)
4976 ui_out_text (uiout, " task ");
4977 ui_out_field_int (uiout, "task", b->task);
4981 ui_out_text (uiout, "\n");
4983 if (!part_of_multiple)
4984 b->ops->print_one_detail (b, uiout);
4986 if (part_of_multiple && frame_id_p (b->frame_id))
4989 ui_out_text (uiout, "\tstop only in stack frame at ");
4990 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
4992 ui_out_field_core_addr (uiout, "frame",
4993 b->gdbarch, b->frame_id.stack_addr);
4994 ui_out_text (uiout, "\n");
4997 if (!part_of_multiple && b->cond_string)
5000 if (is_tracepoint (b))
5001 ui_out_text (uiout, "\ttrace only if ");
5003 ui_out_text (uiout, "\tstop only if ");
5004 ui_out_field_string (uiout, "cond", b->cond_string);
5005 ui_out_text (uiout, "\n");
5008 if (!part_of_multiple && b->thread != -1)
5010 /* FIXME should make an annotation for this. */
5011 ui_out_text (uiout, "\tstop only in thread ");
5012 ui_out_field_int (uiout, "thread", b->thread);
5013 ui_out_text (uiout, "\n");
5016 if (!part_of_multiple && b->hit_count)
5018 /* FIXME should make an annotation for this. */
5019 if (ep_is_catchpoint (b))
5020 ui_out_text (uiout, "\tcatchpoint");
5021 else if (is_tracepoint (b))
5022 ui_out_text (uiout, "\ttracepoint");
5024 ui_out_text (uiout, "\tbreakpoint");
5025 ui_out_text (uiout, " already hit ");
5026 ui_out_field_int (uiout, "times", b->hit_count);
5027 if (b->hit_count == 1)
5028 ui_out_text (uiout, " time\n");
5030 ui_out_text (uiout, " times\n");
5033 /* Output the count also if it is zero, but only if this is mi.
5034 FIXME: Should have a better test for this. */
5035 if (ui_out_is_mi_like_p (uiout))
5036 if (!part_of_multiple && b->hit_count == 0)
5037 ui_out_field_int (uiout, "times", b->hit_count);
5039 if (!part_of_multiple && b->ignore_count)
5042 ui_out_text (uiout, "\tignore next ");
5043 ui_out_field_int (uiout, "ignore", b->ignore_count);
5044 ui_out_text (uiout, " hits\n");
5047 /* Note that an enable count of 1 corresponds to "enable once"
5048 behavior, which is reported by the combination of enablement and
5049 disposition, so we don't need to mention it here. */
5050 if (!part_of_multiple && b->enable_count > 1)
5053 ui_out_text (uiout, "\tdisable after ");
5054 /* Tweak the wording to clarify that ignore and enable counts
5055 are distinct, and have additive effect. */
5056 if (b->ignore_count)
5057 ui_out_text (uiout, "additional ");
5059 ui_out_text (uiout, "next ");
5060 ui_out_field_int (uiout, "enable", b->enable_count);
5061 ui_out_text (uiout, " hits\n");
5064 if (!part_of_multiple && is_tracepoint (b))
5066 struct tracepoint *tp = (struct tracepoint *) b;
5068 if (tp->traceframe_usage)
5070 ui_out_text (uiout, "\ttrace buffer usage ");
5071 ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage);
5072 ui_out_text (uiout, " bytes\n");
5076 l = b->commands ? b->commands->commands : NULL;
5077 if (!part_of_multiple && l)
5079 struct cleanup *script_chain;
5082 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
5083 print_command_lines (uiout, l, 4);
5084 do_cleanups (script_chain);
5087 if (is_tracepoint (b))
5089 struct tracepoint *t = (struct tracepoint *) b;
5091 if (!part_of_multiple && t->pass_count)
5093 annotate_field (10);
5094 ui_out_text (uiout, "\tpass count ");
5095 ui_out_field_int (uiout, "pass", t->pass_count);
5096 ui_out_text (uiout, " \n");
5100 if (ui_out_is_mi_like_p (uiout) && !part_of_multiple)
5102 if (is_watchpoint (b))
5104 struct watchpoint *w = (struct watchpoint *) b;
5106 ui_out_field_string (uiout, "original-location", w->exp_string);
5108 else if (b->addr_string)
5109 ui_out_field_string (uiout, "original-location", b->addr_string);
5114 print_one_breakpoint (struct breakpoint *b,
5115 struct bp_location **last_loc,
5118 struct cleanup *bkpt_chain;
5119 struct ui_out *uiout = current_uiout;
5121 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
5123 print_one_breakpoint_location (b, NULL, 0, last_loc, allflag);
5124 do_cleanups (bkpt_chain);
5126 /* If this breakpoint has custom print function,
5127 it's already printed. Otherwise, print individual
5128 locations, if any. */
5129 if (b->ops == NULL || b->ops->print_one == NULL)
5131 /* If breakpoint has a single location that is disabled, we
5132 print it as if it had several locations, since otherwise it's
5133 hard to represent "breakpoint enabled, location disabled"
5136 Note that while hardware watchpoints have several locations
5137 internally, that's not a property exposed to user. */
5139 && !is_hardware_watchpoint (b)
5140 && (b->loc->next || !b->loc->enabled))
5142 struct bp_location *loc;
5145 for (loc = b->loc; loc; loc = loc->next, ++n)
5147 struct cleanup *inner2 =
5148 make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
5149 print_one_breakpoint_location (b, loc, n, last_loc, allflag);
5150 do_cleanups (inner2);
5157 breakpoint_address_bits (struct breakpoint *b)
5159 int print_address_bits = 0;
5160 struct bp_location *loc;
5162 for (loc = b->loc; loc; loc = loc->next)
5166 /* Software watchpoints that aren't watching memory don't have
5167 an address to print. */
5168 if (b->type == bp_watchpoint && loc->watchpoint_type == -1)
5171 addr_bit = gdbarch_addr_bit (loc->gdbarch);
5172 if (addr_bit > print_address_bits)
5173 print_address_bits = addr_bit;
5176 return print_address_bits;
5179 struct captured_breakpoint_query_args
5185 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
5187 struct captured_breakpoint_query_args *args = data;
5188 struct breakpoint *b;
5189 struct bp_location *dummy_loc = NULL;
5193 if (args->bnum == b->number)
5195 print_one_breakpoint (b, &dummy_loc, 0);
5203 gdb_breakpoint_query (struct ui_out *uiout, int bnum,
5204 char **error_message)
5206 struct captured_breakpoint_query_args args;
5209 /* For the moment we don't trust print_one_breakpoint() to not throw
5211 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
5212 error_message, RETURN_MASK_ALL) < 0)
5218 /* Return true if this breakpoint was set by the user, false if it is
5219 internal or momentary. */
5222 user_breakpoint_p (struct breakpoint *b)
5224 return b->number > 0;
5227 /* Print information on user settable breakpoint (watchpoint, etc)
5228 number BNUM. If BNUM is -1 print all user-settable breakpoints.
5229 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
5230 FILTER is non-NULL, call it on each breakpoint and only include the
5231 ones for which it returns non-zero. Return the total number of
5232 breakpoints listed. */
5235 breakpoint_1 (char *args, int allflag,
5236 int (*filter) (const struct breakpoint *))
5238 struct breakpoint *b;
5239 struct bp_location *last_loc = NULL;
5240 int nr_printable_breakpoints;
5241 struct cleanup *bkpttbl_chain;
5242 struct value_print_options opts;
5243 int print_address_bits = 0;
5244 int print_type_col_width = 14;
5245 struct ui_out *uiout = current_uiout;
5247 get_user_print_options (&opts);
5249 /* Compute the number of rows in the table, as well as the size
5250 required for address fields. */
5251 nr_printable_breakpoints = 0;
5254 /* If we have a filter, only list the breakpoints it accepts. */
5255 if (filter && !filter (b))
5258 /* If we have an "args" string, it is a list of breakpoints to
5259 accept. Skip the others. */
5260 if (args != NULL && *args != '\0')
5262 if (allflag && parse_and_eval_long (args) != b->number)
5264 if (!allflag && !number_is_in_list (args, b->number))
5268 if (allflag || user_breakpoint_p (b))
5270 int addr_bit, type_len;
5272 addr_bit = breakpoint_address_bits (b);
5273 if (addr_bit > print_address_bits)
5274 print_address_bits = addr_bit;
5276 type_len = strlen (bptype_string (b->type));
5277 if (type_len > print_type_col_width)
5278 print_type_col_width = type_len;
5280 nr_printable_breakpoints++;
5284 if (opts.addressprint)
5286 = make_cleanup_ui_out_table_begin_end (uiout, 6,
5287 nr_printable_breakpoints,
5291 = make_cleanup_ui_out_table_begin_end (uiout, 5,
5292 nr_printable_breakpoints,
5295 if (nr_printable_breakpoints > 0)
5296 annotate_breakpoints_headers ();
5297 if (nr_printable_breakpoints > 0)
5299 ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */
5300 if (nr_printable_breakpoints > 0)
5302 ui_out_table_header (uiout, print_type_col_width, ui_left,
5303 "type", "Type"); /* 2 */
5304 if (nr_printable_breakpoints > 0)
5306 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
5307 if (nr_printable_breakpoints > 0)
5309 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
5310 if (opts.addressprint)
5312 if (nr_printable_breakpoints > 0)
5314 if (print_address_bits <= 32)
5315 ui_out_table_header (uiout, 10, ui_left,
5316 "addr", "Address"); /* 5 */
5318 ui_out_table_header (uiout, 18, ui_left,
5319 "addr", "Address"); /* 5 */
5321 if (nr_printable_breakpoints > 0)
5323 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
5324 ui_out_table_body (uiout);
5325 if (nr_printable_breakpoints > 0)
5326 annotate_breakpoints_table ();
5331 /* If we have a filter, only list the breakpoints it accepts. */
5332 if (filter && !filter (b))
5335 /* If we have an "args" string, it is a list of breakpoints to
5336 accept. Skip the others. */
5338 if (args != NULL && *args != '\0')
5340 if (allflag) /* maintenance info breakpoint */
5342 if (parse_and_eval_long (args) != b->number)
5345 else /* all others */
5347 if (!number_is_in_list (args, b->number))
5351 /* We only print out user settable breakpoints unless the
5353 if (allflag || user_breakpoint_p (b))
5354 print_one_breakpoint (b, &last_loc, allflag);
5357 do_cleanups (bkpttbl_chain);
5359 if (nr_printable_breakpoints == 0)
5361 /* If there's a filter, let the caller decide how to report
5365 if (args == NULL || *args == '\0')
5366 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
5368 ui_out_message (uiout, 0,
5369 "No breakpoint or watchpoint matching '%s'.\n",
5375 if (last_loc && !server_command)
5376 set_next_address (last_loc->gdbarch, last_loc->address);
5379 /* FIXME? Should this be moved up so that it is only called when
5380 there have been breakpoints? */
5381 annotate_breakpoints_table_end ();
5383 return nr_printable_breakpoints;
5386 /* Display the value of default-collect in a way that is generally
5387 compatible with the breakpoint list. */
5390 default_collect_info (void)
5392 struct ui_out *uiout = current_uiout;
5394 /* If it has no value (which is frequently the case), say nothing; a
5395 message like "No default-collect." gets in user's face when it's
5397 if (!*default_collect)
5400 /* The following phrase lines up nicely with per-tracepoint collect
5402 ui_out_text (uiout, "default collect ");
5403 ui_out_field_string (uiout, "default-collect", default_collect);
5404 ui_out_text (uiout, " \n");
5408 breakpoints_info (char *args, int from_tty)
5410 breakpoint_1 (args, 0, NULL);
5412 default_collect_info ();
5416 watchpoints_info (char *args, int from_tty)
5418 int num_printed = breakpoint_1 (args, 0, is_watchpoint);
5419 struct ui_out *uiout = current_uiout;
5421 if (num_printed == 0)
5423 if (args == NULL || *args == '\0')
5424 ui_out_message (uiout, 0, "No watchpoints.\n");
5426 ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args);
5431 maintenance_info_breakpoints (char *args, int from_tty)
5433 breakpoint_1 (args, 1, NULL);
5435 default_collect_info ();
5439 breakpoint_has_pc (struct breakpoint *b,
5440 struct program_space *pspace,
5441 CORE_ADDR pc, struct obj_section *section)
5443 struct bp_location *bl = b->loc;
5445 for (; bl; bl = bl->next)
5447 if (bl->pspace == pspace
5448 && bl->address == pc
5449 && (!overlay_debugging || bl->section == section))
5455 /* Print a message describing any user-breakpoints set at PC. This
5456 concerns with logical breakpoints, so we match program spaces, not
5460 describe_other_breakpoints (struct gdbarch *gdbarch,
5461 struct program_space *pspace, CORE_ADDR pc,
5462 struct obj_section *section, int thread)
5465 struct breakpoint *b;
5468 others += (user_breakpoint_p (b)
5469 && breakpoint_has_pc (b, pspace, pc, section));
5473 printf_filtered (_("Note: breakpoint "));
5474 else /* if (others == ???) */
5475 printf_filtered (_("Note: breakpoints "));
5477 if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section))
5480 printf_filtered ("%d", b->number);
5481 if (b->thread == -1 && thread != -1)
5482 printf_filtered (" (all threads)");
5483 else if (b->thread != -1)
5484 printf_filtered (" (thread %d)", b->thread);
5485 printf_filtered ("%s%s ",
5486 ((b->enable_state == bp_disabled
5487 || b->enable_state == bp_call_disabled)
5489 : b->enable_state == bp_permanent
5493 : ((others == 1) ? " and" : ""));
5495 printf_filtered (_("also set at pc "));
5496 fputs_filtered (paddress (gdbarch, pc), gdb_stdout);
5497 printf_filtered (".\n");
5502 /* Return true iff it is meaningful to use the address member of
5503 BPT. For some breakpoint types, the address member is irrelevant
5504 and it makes no sense to attempt to compare it to other addresses
5505 (or use it for any other purpose either).
5507 More specifically, each of the following breakpoint types will
5508 always have a zero valued address and we don't want to mark
5509 breakpoints of any of these types to be a duplicate of an actual
5510 breakpoint at address zero:
5518 breakpoint_address_is_meaningful (struct breakpoint *bpt)
5520 enum bptype type = bpt->type;
5522 return (type != bp_watchpoint && type != bp_catchpoint);
5525 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
5526 true if LOC1 and LOC2 represent the same watchpoint location. */
5529 watchpoint_locations_match (struct bp_location *loc1,
5530 struct bp_location *loc2)
5532 struct watchpoint *w1 = (struct watchpoint *) loc1->owner;
5533 struct watchpoint *w2 = (struct watchpoint *) loc2->owner;
5535 /* Both of them must exist. */
5536 gdb_assert (w1 != NULL);
5537 gdb_assert (w2 != NULL);
5539 /* If the target can evaluate the condition expression in hardware,
5540 then we we need to insert both watchpoints even if they are at
5541 the same place. Otherwise the watchpoint will only trigger when
5542 the condition of whichever watchpoint was inserted evaluates to
5543 true, not giving a chance for GDB to check the condition of the
5544 other watchpoint. */
5546 && target_can_accel_watchpoint_condition (loc1->address,
5548 loc1->watchpoint_type,
5551 && target_can_accel_watchpoint_condition (loc2->address,
5553 loc2->watchpoint_type,
5557 /* Note that this checks the owner's type, not the location's. In
5558 case the target does not support read watchpoints, but does
5559 support access watchpoints, we'll have bp_read_watchpoint
5560 watchpoints with hw_access locations. Those should be considered
5561 duplicates of hw_read locations. The hw_read locations will
5562 become hw_access locations later. */
5563 return (loc1->owner->type == loc2->owner->type
5564 && loc1->pspace->aspace == loc2->pspace->aspace
5565 && loc1->address == loc2->address
5566 && loc1->length == loc2->length);
5569 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
5570 same breakpoint location. In most targets, this can only be true
5571 if ASPACE1 matches ASPACE2. On targets that have global
5572 breakpoints, the address space doesn't really matter. */
5575 breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1,
5576 struct address_space *aspace2, CORE_ADDR addr2)
5578 return ((gdbarch_has_global_breakpoints (target_gdbarch)
5579 || aspace1 == aspace2)
5583 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
5584 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
5585 matches ASPACE2. On targets that have global breakpoints, the address
5586 space doesn't really matter. */
5589 breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1,
5590 int len1, struct address_space *aspace2,
5593 return ((gdbarch_has_global_breakpoints (target_gdbarch)
5594 || aspace1 == aspace2)
5595 && addr2 >= addr1 && addr2 < addr1 + len1);
5598 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
5599 a ranged breakpoint. In most targets, a match happens only if ASPACE
5600 matches the breakpoint's address space. On targets that have global
5601 breakpoints, the address space doesn't really matter. */
5604 breakpoint_location_address_match (struct bp_location *bl,
5605 struct address_space *aspace,
5608 return (breakpoint_address_match (bl->pspace->aspace, bl->address,
5611 && breakpoint_address_match_range (bl->pspace->aspace,
5612 bl->address, bl->length,
5616 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
5617 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
5618 true, otherwise returns false. */
5621 tracepoint_locations_match (struct bp_location *loc1,
5622 struct bp_location *loc2)
5624 if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner))
5625 /* Since tracepoint locations are never duplicated with others', tracepoint
5626 locations at the same address of different tracepoints are regarded as
5627 different locations. */
5628 return (loc1->address == loc2->address && loc1->owner == loc2->owner);
5633 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
5634 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
5635 represent the same location. */
5638 breakpoint_locations_match (struct bp_location *loc1,
5639 struct bp_location *loc2)
5641 int hw_point1, hw_point2;
5643 /* Both of them must not be in moribund_locations. */
5644 gdb_assert (loc1->owner != NULL);
5645 gdb_assert (loc2->owner != NULL);
5647 hw_point1 = is_hardware_watchpoint (loc1->owner);
5648 hw_point2 = is_hardware_watchpoint (loc2->owner);
5650 if (hw_point1 != hw_point2)
5653 return watchpoint_locations_match (loc1, loc2);
5654 else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner))
5655 return tracepoint_locations_match (loc1, loc2);
5657 /* We compare bp_location.length in order to cover ranged breakpoints. */
5658 return (breakpoint_address_match (loc1->pspace->aspace, loc1->address,
5659 loc2->pspace->aspace, loc2->address)
5660 && loc1->length == loc2->length);
5664 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
5665 int bnum, int have_bnum)
5667 /* The longest string possibly returned by hex_string_custom
5668 is 50 chars. These must be at least that big for safety. */
5672 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
5673 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
5675 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
5676 bnum, astr1, astr2);
5678 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
5681 /* Adjust a breakpoint's address to account for architectural
5682 constraints on breakpoint placement. Return the adjusted address.
5683 Note: Very few targets require this kind of adjustment. For most
5684 targets, this function is simply the identity function. */
5687 adjust_breakpoint_address (struct gdbarch *gdbarch,
5688 CORE_ADDR bpaddr, enum bptype bptype)
5690 if (!gdbarch_adjust_breakpoint_address_p (gdbarch))
5692 /* Very few targets need any kind of breakpoint adjustment. */
5695 else if (bptype == bp_watchpoint
5696 || bptype == bp_hardware_watchpoint
5697 || bptype == bp_read_watchpoint
5698 || bptype == bp_access_watchpoint
5699 || bptype == bp_catchpoint)
5701 /* Watchpoints and the various bp_catch_* eventpoints should not
5702 have their addresses modified. */
5707 CORE_ADDR adjusted_bpaddr;
5709 /* Some targets have architectural constraints on the placement
5710 of breakpoint instructions. Obtain the adjusted address. */
5711 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr);
5713 /* An adjusted breakpoint address can significantly alter
5714 a user's expectations. Print a warning if an adjustment
5716 if (adjusted_bpaddr != bpaddr)
5717 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
5719 return adjusted_bpaddr;
5724 init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops,
5725 struct breakpoint *owner)
5727 memset (loc, 0, sizeof (*loc));
5729 gdb_assert (ops != NULL);
5734 loc->shlib_disabled = 0;
5737 switch (owner->type)
5743 case bp_longjmp_resume:
5745 case bp_exception_resume:
5746 case bp_step_resume:
5747 case bp_hp_step_resume:
5748 case bp_watchpoint_scope:
5750 case bp_std_terminate:
5751 case bp_shlib_event:
5752 case bp_thread_event:
5753 case bp_overlay_event:
5755 case bp_longjmp_master:
5756 case bp_std_terminate_master:
5757 case bp_exception_master:
5758 case bp_gnu_ifunc_resolver:
5759 case bp_gnu_ifunc_resolver_return:
5760 loc->loc_type = bp_loc_software_breakpoint;
5762 case bp_hardware_breakpoint:
5763 loc->loc_type = bp_loc_hardware_breakpoint;
5765 case bp_hardware_watchpoint:
5766 case bp_read_watchpoint:
5767 case bp_access_watchpoint:
5768 loc->loc_type = bp_loc_hardware_watchpoint;
5773 case bp_fast_tracepoint:
5774 case bp_static_tracepoint:
5775 loc->loc_type = bp_loc_other;
5778 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
5784 /* Allocate a struct bp_location. */
5786 static struct bp_location *
5787 allocate_bp_location (struct breakpoint *bpt)
5789 return bpt->ops->allocate_location (bpt);
5793 free_bp_location (struct bp_location *loc)
5795 loc->ops->dtor (loc);
5799 /* Increment reference count. */
5802 incref_bp_location (struct bp_location *bl)
5807 /* Decrement reference count. If the reference count reaches 0,
5808 destroy the bp_location. Sets *BLP to NULL. */
5811 decref_bp_location (struct bp_location **blp)
5813 gdb_assert ((*blp)->refc > 0);
5815 if (--(*blp)->refc == 0)
5816 free_bp_location (*blp);
5820 /* Add breakpoint B at the end of the global breakpoint chain. */
5823 add_to_breakpoint_chain (struct breakpoint *b)
5825 struct breakpoint *b1;
5827 /* Add this breakpoint to the end of the chain so that a list of
5828 breakpoints will come out in order of increasing numbers. */
5830 b1 = breakpoint_chain;
5832 breakpoint_chain = b;
5841 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
5844 init_raw_breakpoint_without_location (struct breakpoint *b,
5845 struct gdbarch *gdbarch,
5847 const struct breakpoint_ops *ops)
5849 memset (b, 0, sizeof (*b));
5851 gdb_assert (ops != NULL);
5855 b->gdbarch = gdbarch;
5856 b->language = current_language->la_language;
5857 b->input_radix = input_radix;
5859 b->enable_state = bp_enabled;
5862 b->ignore_count = 0;
5864 b->frame_id = null_frame_id;
5865 b->condition_not_parsed = 0;
5866 b->py_bp_object = NULL;
5867 b->related_breakpoint = b;
5870 /* Helper to set_raw_breakpoint below. Creates a breakpoint
5871 that has type BPTYPE and has no locations as yet. */
5873 static struct breakpoint *
5874 set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
5876 const struct breakpoint_ops *ops)
5878 struct breakpoint *b = XNEW (struct breakpoint);
5880 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
5881 add_to_breakpoint_chain (b);
5885 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
5886 resolutions should be made as the user specified the location explicitly
5890 set_breakpoint_location_function (struct bp_location *loc, int explicit_loc)
5892 gdb_assert (loc->owner != NULL);
5894 if (loc->owner->type == bp_breakpoint
5895 || loc->owner->type == bp_hardware_breakpoint
5896 || is_tracepoint (loc->owner))
5899 const char *function_name;
5901 find_pc_partial_function_gnu_ifunc (loc->address, &function_name,
5902 NULL, NULL, &is_gnu_ifunc);
5904 if (is_gnu_ifunc && !explicit_loc)
5906 struct breakpoint *b = loc->owner;
5908 gdb_assert (loc->pspace == current_program_space);
5909 if (gnu_ifunc_resolve_name (function_name,
5910 &loc->requested_address))
5912 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
5913 loc->address = adjust_breakpoint_address (loc->gdbarch,
5914 loc->requested_address,
5917 else if (b->type == bp_breakpoint && b->loc == loc
5918 && loc->next == NULL && b->related_breakpoint == b)
5920 /* Create only the whole new breakpoint of this type but do not
5921 mess more complicated breakpoints with multiple locations. */
5922 b->type = bp_gnu_ifunc_resolver;
5927 loc->function_name = xstrdup (function_name);
5931 /* Attempt to determine architecture of location identified by SAL. */
5933 get_sal_arch (struct symtab_and_line sal)
5936 return get_objfile_arch (sal.section->objfile);
5938 return get_objfile_arch (sal.symtab->objfile);
5943 /* Low level routine for partially initializing a breakpoint of type
5944 BPTYPE. The newly created breakpoint's address, section, source
5945 file name, and line number are provided by SAL.
5947 It is expected that the caller will complete the initialization of
5948 the newly created breakpoint struct as well as output any status
5949 information regarding the creation of a new breakpoint. */
5952 init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch,
5953 struct symtab_and_line sal, enum bptype bptype,
5954 const struct breakpoint_ops *ops)
5956 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
5958 add_location_to_breakpoint (b, &sal);
5960 if (bptype != bp_catchpoint)
5961 gdb_assert (sal.pspace != NULL);
5963 /* Store the program space that was used to set the breakpoint,
5964 except for ordinary breakpoints, which are independent of the
5966 if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint)
5967 b->pspace = sal.pspace;
5969 breakpoints_changed ();
5972 /* set_raw_breakpoint is a low level routine for allocating and
5973 partially initializing a breakpoint of type BPTYPE. The newly
5974 created breakpoint's address, section, source file name, and line
5975 number are provided by SAL. The newly created and partially
5976 initialized breakpoint is added to the breakpoint chain and
5977 is also returned as the value of this function.
5979 It is expected that the caller will complete the initialization of
5980 the newly created breakpoint struct as well as output any status
5981 information regarding the creation of a new breakpoint. In
5982 particular, set_raw_breakpoint does NOT set the breakpoint
5983 number! Care should be taken to not allow an error to occur
5984 prior to completing the initialization of the breakpoint. If this
5985 should happen, a bogus breakpoint will be left on the chain. */
5988 set_raw_breakpoint (struct gdbarch *gdbarch,
5989 struct symtab_and_line sal, enum bptype bptype,
5990 const struct breakpoint_ops *ops)
5992 struct breakpoint *b = XNEW (struct breakpoint);
5994 init_raw_breakpoint (b, gdbarch, sal, bptype, ops);
5995 add_to_breakpoint_chain (b);
6000 /* Note that the breakpoint object B describes a permanent breakpoint
6001 instruction, hard-wired into the inferior's code. */
6003 make_breakpoint_permanent (struct breakpoint *b)
6005 struct bp_location *bl;
6007 b->enable_state = bp_permanent;
6009 /* By definition, permanent breakpoints are already present in the
6010 code. Mark all locations as inserted. For now,
6011 make_breakpoint_permanent is called in just one place, so it's
6012 hard to say if it's reasonable to have permanent breakpoint with
6013 multiple locations or not, but it's easy to implement. */
6014 for (bl = b->loc; bl; bl = bl->next)
6018 /* Call this routine when stepping and nexting to enable a breakpoint
6019 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
6020 initiated the operation. */
6023 set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame)
6025 struct breakpoint *b, *b_tmp;
6026 int thread = tp->num;
6028 /* To avoid having to rescan all objfile symbols at every step,
6029 we maintain a list of continually-inserted but always disabled
6030 longjmp "master" breakpoints. Here, we simply create momentary
6031 clones of those and enable them for the requested thread. */
6032 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6033 if (b->pspace == current_program_space
6034 && (b->type == bp_longjmp_master
6035 || b->type == bp_exception_master))
6037 enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception;
6038 struct breakpoint *clone;
6040 clone = momentary_breakpoint_from_master (b, type,
6041 &momentary_breakpoint_ops);
6042 clone->thread = thread;
6045 tp->initiating_frame = frame;
6048 /* Delete all longjmp breakpoints from THREAD. */
6050 delete_longjmp_breakpoint (int thread)
6052 struct breakpoint *b, *b_tmp;
6054 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6055 if (b->type == bp_longjmp || b->type == bp_exception)
6057 if (b->thread == thread)
6058 delete_breakpoint (b);
6063 enable_overlay_breakpoints (void)
6065 struct breakpoint *b;
6068 if (b->type == bp_overlay_event)
6070 b->enable_state = bp_enabled;
6071 update_global_location_list (1);
6072 overlay_events_enabled = 1;
6077 disable_overlay_breakpoints (void)
6079 struct breakpoint *b;
6082 if (b->type == bp_overlay_event)
6084 b->enable_state = bp_disabled;
6085 update_global_location_list (0);
6086 overlay_events_enabled = 0;
6090 /* Set an active std::terminate breakpoint for each std::terminate
6091 master breakpoint. */
6093 set_std_terminate_breakpoint (void)
6095 struct breakpoint *b, *b_tmp;
6097 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6098 if (b->pspace == current_program_space
6099 && b->type == bp_std_terminate_master)
6101 momentary_breakpoint_from_master (b, bp_std_terminate,
6102 &momentary_breakpoint_ops);
6106 /* Delete all the std::terminate breakpoints. */
6108 delete_std_terminate_breakpoint (void)
6110 struct breakpoint *b, *b_tmp;
6112 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6113 if (b->type == bp_std_terminate)
6114 delete_breakpoint (b);
6118 create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
6120 struct breakpoint *b;
6122 b = create_internal_breakpoint (gdbarch, address, bp_thread_event,
6123 &internal_breakpoint_ops);
6125 b->enable_state = bp_enabled;
6126 /* addr_string has to be used or breakpoint_re_set will delete me. */
6128 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
6130 update_global_location_list_nothrow (1);
6136 remove_thread_event_breakpoints (void)
6138 struct breakpoint *b, *b_tmp;
6140 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6141 if (b->type == bp_thread_event
6142 && b->loc->pspace == current_program_space)
6143 delete_breakpoint (b);
6146 struct lang_and_radix
6152 /* Create a breakpoint for JIT code registration and unregistration. */
6155 create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
6157 struct breakpoint *b;
6159 b = create_internal_breakpoint (gdbarch, address, bp_jit_event,
6160 &internal_breakpoint_ops);
6161 update_global_location_list_nothrow (1);
6165 /* Remove JIT code registration and unregistration breakpoint(s). */
6168 remove_jit_event_breakpoints (void)
6170 struct breakpoint *b, *b_tmp;
6172 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6173 if (b->type == bp_jit_event
6174 && b->loc->pspace == current_program_space)
6175 delete_breakpoint (b);
6179 remove_solib_event_breakpoints (void)
6181 struct breakpoint *b, *b_tmp;
6183 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6184 if (b->type == bp_shlib_event
6185 && b->loc->pspace == current_program_space)
6186 delete_breakpoint (b);
6190 create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
6192 struct breakpoint *b;
6194 b = create_internal_breakpoint (gdbarch, address, bp_shlib_event,
6195 &internal_breakpoint_ops);
6196 update_global_location_list_nothrow (1);
6200 /* Disable any breakpoints that are on code in shared libraries. Only
6201 apply to enabled breakpoints, disabled ones can just stay disabled. */
6204 disable_breakpoints_in_shlibs (void)
6206 struct bp_location *loc, **locp_tmp;
6208 ALL_BP_LOCATIONS (loc, locp_tmp)
6210 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6211 struct breakpoint *b = loc->owner;
6213 /* We apply the check to all breakpoints, including disabled for
6214 those with loc->duplicate set. This is so that when breakpoint
6215 becomes enabled, or the duplicate is removed, gdb will try to
6216 insert all breakpoints. If we don't set shlib_disabled here,
6217 we'll try to insert those breakpoints and fail. */
6218 if (((b->type == bp_breakpoint)
6219 || (b->type == bp_jit_event)
6220 || (b->type == bp_hardware_breakpoint)
6221 || (is_tracepoint (b)))
6222 && loc->pspace == current_program_space
6223 && !loc->shlib_disabled
6225 && PC_SOLIB (loc->address)
6227 && solib_name_from_address (loc->pspace, loc->address)
6231 loc->shlib_disabled = 1;
6236 /* Disable any breakpoints and tracepoints that are in an unloaded shared
6237 library. Only apply to enabled breakpoints, disabled ones can just stay
6241 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
6243 struct bp_location *loc, **locp_tmp;
6244 int disabled_shlib_breaks = 0;
6246 /* SunOS a.out shared libraries are always mapped, so do not
6247 disable breakpoints; they will only be reported as unloaded
6248 through clear_solib when GDB discards its shared library
6249 list. See clear_solib for more information. */
6250 if (exec_bfd != NULL
6251 && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour)
6254 ALL_BP_LOCATIONS (loc, locp_tmp)
6256 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6257 struct breakpoint *b = loc->owner;
6259 if (solib->pspace == loc->pspace
6260 && !loc->shlib_disabled
6261 && (((b->type == bp_breakpoint
6262 || b->type == bp_jit_event
6263 || b->type == bp_hardware_breakpoint)
6264 && (loc->loc_type == bp_loc_hardware_breakpoint
6265 || loc->loc_type == bp_loc_software_breakpoint))
6266 || is_tracepoint (b))
6267 && solib_contains_address_p (solib, loc->address))
6269 loc->shlib_disabled = 1;
6270 /* At this point, we cannot rely on remove_breakpoint
6271 succeeding so we must mark the breakpoint as not inserted
6272 to prevent future errors occurring in remove_breakpoints. */
6275 /* This may cause duplicate notifications for the same breakpoint. */
6276 observer_notify_breakpoint_modified (b);
6278 if (!disabled_shlib_breaks)
6280 target_terminal_ours_for_output ();
6281 warning (_("Temporarily disabling breakpoints "
6282 "for unloaded shared library \"%s\""),
6285 disabled_shlib_breaks = 1;
6290 /* FORK & VFORK catchpoints. */
6292 /* An instance of this type is used to represent a fork or vfork
6293 catchpoint. It includes a "struct breakpoint" as a kind of base
6294 class; users downcast to "struct breakpoint *" when needed. A
6295 breakpoint is really of this type iff its ops pointer points to
6296 CATCH_FORK_BREAKPOINT_OPS. */
6298 struct fork_catchpoint
6300 /* The base class. */
6301 struct breakpoint base;
6303 /* Process id of a child process whose forking triggered this
6304 catchpoint. This field is only valid immediately after this
6305 catchpoint has triggered. */
6306 ptid_t forked_inferior_pid;
6309 /* Implement the "insert" breakpoint_ops method for fork
6313 insert_catch_fork (struct bp_location *bl)
6315 return target_insert_fork_catchpoint (PIDGET (inferior_ptid));
6318 /* Implement the "remove" breakpoint_ops method for fork
6322 remove_catch_fork (struct bp_location *bl)
6324 return target_remove_fork_catchpoint (PIDGET (inferior_ptid));
6327 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
6331 breakpoint_hit_catch_fork (const struct bp_location *bl,
6332 struct address_space *aspace, CORE_ADDR bp_addr,
6333 const struct target_waitstatus *ws)
6335 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
6337 if (ws->kind != TARGET_WAITKIND_FORKED)
6340 c->forked_inferior_pid = ws->value.related_pid;
6344 /* Implement the "print_it" breakpoint_ops method for fork
6347 static enum print_stop_action
6348 print_it_catch_fork (bpstat bs)
6350 struct ui_out *uiout = current_uiout;
6351 struct breakpoint *b = bs->breakpoint_at;
6352 struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at;
6354 annotate_catchpoint (b->number);
6355 if (b->disposition == disp_del)
6356 ui_out_text (uiout, "\nTemporary catchpoint ");
6358 ui_out_text (uiout, "\nCatchpoint ");
6359 if (ui_out_is_mi_like_p (uiout))
6361 ui_out_field_string (uiout, "reason",
6362 async_reason_lookup (EXEC_ASYNC_FORK));
6363 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
6365 ui_out_field_int (uiout, "bkptno", b->number);
6366 ui_out_text (uiout, " (forked process ");
6367 ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid));
6368 ui_out_text (uiout, "), ");
6369 return PRINT_SRC_AND_LOC;
6372 /* Implement the "print_one" breakpoint_ops method for fork
6376 print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc)
6378 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
6379 struct value_print_options opts;
6380 struct ui_out *uiout = current_uiout;
6382 get_user_print_options (&opts);
6384 /* Field 4, the address, is omitted (which makes the columns not
6385 line up too nicely with the headers, but the effect is relatively
6387 if (opts.addressprint)
6388 ui_out_field_skip (uiout, "addr");
6390 ui_out_text (uiout, "fork");
6391 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
6393 ui_out_text (uiout, ", process ");
6394 ui_out_field_int (uiout, "what",
6395 ptid_get_pid (c->forked_inferior_pid));
6396 ui_out_spaces (uiout, 1);
6400 /* Implement the "print_mention" breakpoint_ops method for fork
6404 print_mention_catch_fork (struct breakpoint *b)
6406 printf_filtered (_("Catchpoint %d (fork)"), b->number);
6409 /* Implement the "print_recreate" breakpoint_ops method for fork
6413 print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp)
6415 fprintf_unfiltered (fp, "catch fork");
6416 print_recreate_thread (b, fp);
6419 /* The breakpoint_ops structure to be used in fork catchpoints. */
6421 static struct breakpoint_ops catch_fork_breakpoint_ops;
6423 /* Implement the "insert" breakpoint_ops method for vfork
6427 insert_catch_vfork (struct bp_location *bl)
6429 return target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
6432 /* Implement the "remove" breakpoint_ops method for vfork
6436 remove_catch_vfork (struct bp_location *bl)
6438 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
6441 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
6445 breakpoint_hit_catch_vfork (const struct bp_location *bl,
6446 struct address_space *aspace, CORE_ADDR bp_addr,
6447 const struct target_waitstatus *ws)
6449 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
6451 if (ws->kind != TARGET_WAITKIND_VFORKED)
6454 c->forked_inferior_pid = ws->value.related_pid;
6458 /* Implement the "print_it" breakpoint_ops method for vfork
6461 static enum print_stop_action
6462 print_it_catch_vfork (bpstat bs)
6464 struct ui_out *uiout = current_uiout;
6465 struct breakpoint *b = bs->breakpoint_at;
6466 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
6468 annotate_catchpoint (b->number);
6469 if (b->disposition == disp_del)
6470 ui_out_text (uiout, "\nTemporary catchpoint ");
6472 ui_out_text (uiout, "\nCatchpoint ");
6473 if (ui_out_is_mi_like_p (uiout))
6475 ui_out_field_string (uiout, "reason",
6476 async_reason_lookup (EXEC_ASYNC_VFORK));
6477 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
6479 ui_out_field_int (uiout, "bkptno", b->number);
6480 ui_out_text (uiout, " (vforked process ");
6481 ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid));
6482 ui_out_text (uiout, "), ");
6483 return PRINT_SRC_AND_LOC;
6486 /* Implement the "print_one" breakpoint_ops method for vfork
6490 print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc)
6492 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
6493 struct value_print_options opts;
6494 struct ui_out *uiout = current_uiout;
6496 get_user_print_options (&opts);
6497 /* Field 4, the address, is omitted (which makes the columns not
6498 line up too nicely with the headers, but the effect is relatively
6500 if (opts.addressprint)
6501 ui_out_field_skip (uiout, "addr");
6503 ui_out_text (uiout, "vfork");
6504 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
6506 ui_out_text (uiout, ", process ");
6507 ui_out_field_int (uiout, "what",
6508 ptid_get_pid (c->forked_inferior_pid));
6509 ui_out_spaces (uiout, 1);
6513 /* Implement the "print_mention" breakpoint_ops method for vfork
6517 print_mention_catch_vfork (struct breakpoint *b)
6519 printf_filtered (_("Catchpoint %d (vfork)"), b->number);
6522 /* Implement the "print_recreate" breakpoint_ops method for vfork
6526 print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp)
6528 fprintf_unfiltered (fp, "catch vfork");
6529 print_recreate_thread (b, fp);
6532 /* The breakpoint_ops structure to be used in vfork catchpoints. */
6534 static struct breakpoint_ops catch_vfork_breakpoint_ops;
6536 /* An instance of this type is used to represent an solib catchpoint.
6537 It includes a "struct breakpoint" as a kind of base class; users
6538 downcast to "struct breakpoint *" when needed. A breakpoint is
6539 really of this type iff its ops pointer points to
6540 CATCH_SOLIB_BREAKPOINT_OPS. */
6542 struct solib_catchpoint
6544 /* The base class. */
6545 struct breakpoint base;
6547 /* True for "catch load", false for "catch unload". */
6548 unsigned char is_load;
6550 /* Regular expression to match, if any. COMPILED is only valid when
6551 REGEX is non-NULL. */
6557 dtor_catch_solib (struct breakpoint *b)
6559 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
6562 regfree (&self->compiled);
6563 xfree (self->regex);
6565 base_breakpoint_ops.dtor (b);
6569 insert_catch_solib (struct bp_location *ignore)
6575 remove_catch_solib (struct bp_location *ignore)
6581 breakpoint_hit_catch_solib (const struct bp_location *bl,
6582 struct address_space *aspace,
6584 const struct target_waitstatus *ws)
6586 struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner;
6587 struct breakpoint *other;
6589 if (ws->kind == TARGET_WAITKIND_LOADED)
6592 ALL_BREAKPOINTS (other)
6594 struct bp_location *other_bl;
6596 if (other == bl->owner)
6599 if (other->type != bp_shlib_event)
6602 if (self->base.pspace != NULL && other->pspace != self->base.pspace)
6605 for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next)
6607 if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws))
6616 check_status_catch_solib (struct bpstats *bs)
6618 struct solib_catchpoint *self
6619 = (struct solib_catchpoint *) bs->breakpoint_at;
6624 struct so_list *iter;
6627 VEC_iterate (so_list_ptr, current_program_space->added_solibs,
6632 || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0)
6641 VEC_iterate (char_ptr, current_program_space->deleted_solibs,
6646 || regexec (&self->compiled, iter, 0, NULL, 0) == 0)
6652 bs->print_it = print_it_noop;
6655 static enum print_stop_action
6656 print_it_catch_solib (bpstat bs)
6658 struct breakpoint *b = bs->breakpoint_at;
6659 struct ui_out *uiout = current_uiout;
6661 annotate_catchpoint (b->number);
6662 if (b->disposition == disp_del)
6663 ui_out_text (uiout, "\nTemporary catchpoint ");
6665 ui_out_text (uiout, "\nCatchpoint ");
6666 ui_out_field_int (uiout, "bkptno", b->number);
6667 ui_out_text (uiout, "\n");
6668 if (ui_out_is_mi_like_p (uiout))
6669 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
6670 print_solib_event (1);
6671 return PRINT_SRC_AND_LOC;
6675 print_one_catch_solib (struct breakpoint *b, struct bp_location **locs)
6677 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
6678 struct value_print_options opts;
6679 struct ui_out *uiout = current_uiout;
6682 get_user_print_options (&opts);
6683 /* Field 4, the address, is omitted (which makes the columns not
6684 line up too nicely with the headers, but the effect is relatively
6686 if (opts.addressprint)
6689 ui_out_field_skip (uiout, "addr");
6696 msg = xstrprintf (_("load of library matching %s"), self->regex);
6698 msg = xstrdup (_("load of library"));
6703 msg = xstrprintf (_("unload of library matching %s"), self->regex);
6705 msg = xstrdup (_("unload of library"));
6707 ui_out_field_string (uiout, "what", msg);
6712 print_mention_catch_solib (struct breakpoint *b)
6714 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
6716 printf_filtered (_("Catchpoint %d (%s)"), b->number,
6717 self->is_load ? "load" : "unload");
6721 print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp)
6723 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
6725 fprintf_unfiltered (fp, "%s %s",
6726 b->disposition == disp_del ? "tcatch" : "catch",
6727 self->is_load ? "load" : "unload");
6729 fprintf_unfiltered (fp, " %s", self->regex);
6730 fprintf_unfiltered (fp, "\n");
6733 static struct breakpoint_ops catch_solib_breakpoint_ops;
6735 /* A helper function that does all the work for "catch load" and
6739 catch_load_or_unload (char *arg, int from_tty, int is_load,
6740 struct cmd_list_element *command)
6742 struct solib_catchpoint *c;
6743 struct gdbarch *gdbarch = get_current_arch ();
6746 struct cleanup *cleanup;
6748 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
6752 arg = skip_spaces (arg);
6754 c = XCNEW (struct solib_catchpoint);
6755 cleanup = make_cleanup (xfree, c);
6761 errcode = regcomp (&c->compiled, arg, REG_NOSUB);
6764 char *err = get_regcomp_error (errcode, &c->compiled);
6766 make_cleanup (xfree, err);
6767 error (_("Invalid regexp (%s): %s"), err, arg);
6769 c->regex = xstrdup (arg);
6772 c->is_load = is_load;
6773 init_catchpoint (&c->base, gdbarch, tempflag, NULL,
6774 &catch_solib_breakpoint_ops);
6776 discard_cleanups (cleanup);
6777 install_breakpoint (0, &c->base, 1);
6781 catch_load_command_1 (char *arg, int from_tty,
6782 struct cmd_list_element *command)
6784 catch_load_or_unload (arg, from_tty, 1, command);
6788 catch_unload_command_1 (char *arg, int from_tty,
6789 struct cmd_list_element *command)
6791 catch_load_or_unload (arg, from_tty, 0, command);
6794 /* An instance of this type is used to represent a syscall catchpoint.
6795 It includes a "struct breakpoint" as a kind of base class; users
6796 downcast to "struct breakpoint *" when needed. A breakpoint is
6797 really of this type iff its ops pointer points to
6798 CATCH_SYSCALL_BREAKPOINT_OPS. */
6800 struct syscall_catchpoint
6802 /* The base class. */
6803 struct breakpoint base;
6805 /* Syscall numbers used for the 'catch syscall' feature. If no
6806 syscall has been specified for filtering, its value is NULL.
6807 Otherwise, it holds a list of all syscalls to be caught. The
6808 list elements are allocated with xmalloc. */
6809 VEC(int) *syscalls_to_be_caught;
6812 /* Implement the "dtor" breakpoint_ops method for syscall
6816 dtor_catch_syscall (struct breakpoint *b)
6818 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
6820 VEC_free (int, c->syscalls_to_be_caught);
6822 base_breakpoint_ops.dtor (b);
6825 /* Implement the "insert" breakpoint_ops method for syscall
6829 insert_catch_syscall (struct bp_location *bl)
6831 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner;
6832 struct inferior *inf = current_inferior ();
6834 ++inf->total_syscalls_count;
6835 if (!c->syscalls_to_be_caught)
6836 ++inf->any_syscall_count;
6842 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
6847 if (iter >= VEC_length (int, inf->syscalls_counts))
6849 int old_size = VEC_length (int, inf->syscalls_counts);
6850 uintptr_t vec_addr_offset
6851 = old_size * ((uintptr_t) sizeof (int));
6853 VEC_safe_grow (int, inf->syscalls_counts, iter + 1);
6854 vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) +
6856 memset ((void *) vec_addr, 0,
6857 (iter + 1 - old_size) * sizeof (int));
6859 elem = VEC_index (int, inf->syscalls_counts, iter);
6860 VEC_replace (int, inf->syscalls_counts, iter, ++elem);
6864 return target_set_syscall_catchpoint (PIDGET (inferior_ptid),
6865 inf->total_syscalls_count != 0,
6866 inf->any_syscall_count,
6867 VEC_length (int, inf->syscalls_counts),
6868 VEC_address (int, inf->syscalls_counts));
6871 /* Implement the "remove" breakpoint_ops method for syscall
6875 remove_catch_syscall (struct bp_location *bl)
6877 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner;
6878 struct inferior *inf = current_inferior ();
6880 --inf->total_syscalls_count;
6881 if (!c->syscalls_to_be_caught)
6882 --inf->any_syscall_count;
6888 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
6892 if (iter >= VEC_length (int, inf->syscalls_counts))
6893 /* Shouldn't happen. */
6895 elem = VEC_index (int, inf->syscalls_counts, iter);
6896 VEC_replace (int, inf->syscalls_counts, iter, --elem);
6900 return target_set_syscall_catchpoint (PIDGET (inferior_ptid),
6901 inf->total_syscalls_count != 0,
6902 inf->any_syscall_count,
6903 VEC_length (int, inf->syscalls_counts),
6905 inf->syscalls_counts));
6908 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
6912 breakpoint_hit_catch_syscall (const struct bp_location *bl,
6913 struct address_space *aspace, CORE_ADDR bp_addr,
6914 const struct target_waitstatus *ws)
6916 /* We must check if we are catching specific syscalls in this
6917 breakpoint. If we are, then we must guarantee that the called
6918 syscall is the same syscall we are catching. */
6919 int syscall_number = 0;
6920 const struct syscall_catchpoint *c
6921 = (const struct syscall_catchpoint *) bl->owner;
6923 if (ws->kind != TARGET_WAITKIND_SYSCALL_ENTRY
6924 && ws->kind != TARGET_WAITKIND_SYSCALL_RETURN)
6927 syscall_number = ws->value.syscall_number;
6929 /* Now, checking if the syscall is the same. */
6930 if (c->syscalls_to_be_caught)
6935 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
6937 if (syscall_number == iter)
6947 /* Implement the "print_it" breakpoint_ops method for syscall
6950 static enum print_stop_action
6951 print_it_catch_syscall (bpstat bs)
6953 struct ui_out *uiout = current_uiout;
6954 struct breakpoint *b = bs->breakpoint_at;
6955 /* These are needed because we want to know in which state a
6956 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
6957 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
6958 must print "called syscall" or "returned from syscall". */
6960 struct target_waitstatus last;
6964 get_last_target_status (&ptid, &last);
6966 get_syscall_by_number (last.value.syscall_number, &s);
6968 annotate_catchpoint (b->number);
6970 if (b->disposition == disp_del)
6971 ui_out_text (uiout, "\nTemporary catchpoint ");
6973 ui_out_text (uiout, "\nCatchpoint ");
6974 if (ui_out_is_mi_like_p (uiout))
6976 ui_out_field_string (uiout, "reason",
6977 async_reason_lookup (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY
6978 ? EXEC_ASYNC_SYSCALL_ENTRY
6979 : EXEC_ASYNC_SYSCALL_RETURN));
6980 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
6982 ui_out_field_int (uiout, "bkptno", b->number);
6984 if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY)
6985 ui_out_text (uiout, " (call to syscall ");
6987 ui_out_text (uiout, " (returned from syscall ");
6989 if (s.name == NULL || ui_out_is_mi_like_p (uiout))
6990 ui_out_field_int (uiout, "syscall-number", last.value.syscall_number);
6992 ui_out_field_string (uiout, "syscall-name", s.name);
6994 ui_out_text (uiout, "), ");
6996 return PRINT_SRC_AND_LOC;
6999 /* Implement the "print_one" breakpoint_ops method for syscall
7003 print_one_catch_syscall (struct breakpoint *b,
7004 struct bp_location **last_loc)
7006 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
7007 struct value_print_options opts;
7008 struct ui_out *uiout = current_uiout;
7010 get_user_print_options (&opts);
7011 /* Field 4, the address, is omitted (which makes the columns not
7012 line up too nicely with the headers, but the effect is relatively
7014 if (opts.addressprint)
7015 ui_out_field_skip (uiout, "addr");
7018 if (c->syscalls_to_be_caught
7019 && VEC_length (int, c->syscalls_to_be_caught) > 1)
7020 ui_out_text (uiout, "syscalls \"");
7022 ui_out_text (uiout, "syscall \"");
7024 if (c->syscalls_to_be_caught)
7027 char *text = xstrprintf ("%s", "");
7030 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
7035 get_syscall_by_number (iter, &s);
7038 text = xstrprintf ("%s%s, ", text, s.name);
7040 text = xstrprintf ("%s%d, ", text, iter);
7042 /* We have to xfree the last 'text' (now stored at 'x')
7043 because xstrprintf dynamically allocates new space for it
7047 /* Remove the last comma. */
7048 text[strlen (text) - 2] = '\0';
7049 ui_out_field_string (uiout, "what", text);
7052 ui_out_field_string (uiout, "what", "<any syscall>");
7053 ui_out_text (uiout, "\" ");
7056 /* Implement the "print_mention" breakpoint_ops method for syscall
7060 print_mention_catch_syscall (struct breakpoint *b)
7062 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
7064 if (c->syscalls_to_be_caught)
7068 if (VEC_length (int, c->syscalls_to_be_caught) > 1)
7069 printf_filtered (_("Catchpoint %d (syscalls"), b->number);
7071 printf_filtered (_("Catchpoint %d (syscall"), b->number);
7074 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
7078 get_syscall_by_number (iter, &s);
7081 printf_filtered (" '%s' [%d]", s.name, s.number);
7083 printf_filtered (" %d", s.number);
7085 printf_filtered (")");
7088 printf_filtered (_("Catchpoint %d (any syscall)"),
7092 /* Implement the "print_recreate" breakpoint_ops method for syscall
7096 print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp)
7098 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
7100 fprintf_unfiltered (fp, "catch syscall");
7102 if (c->syscalls_to_be_caught)
7107 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
7112 get_syscall_by_number (iter, &s);
7114 fprintf_unfiltered (fp, " %s", s.name);
7116 fprintf_unfiltered (fp, " %d", s.number);
7119 print_recreate_thread (b, fp);
7122 /* The breakpoint_ops structure to be used in syscall catchpoints. */
7124 static struct breakpoint_ops catch_syscall_breakpoint_ops;
7126 /* Returns non-zero if 'b' is a syscall catchpoint. */
7129 syscall_catchpoint_p (struct breakpoint *b)
7131 return (b->ops == &catch_syscall_breakpoint_ops);
7134 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
7135 is non-zero, then make the breakpoint temporary. If COND_STRING is
7136 not NULL, then store it in the breakpoint. OPS, if not NULL, is
7137 the breakpoint_ops structure associated to the catchpoint. */
7140 init_catchpoint (struct breakpoint *b,
7141 struct gdbarch *gdbarch, int tempflag,
7143 const struct breakpoint_ops *ops)
7145 struct symtab_and_line sal;
7148 sal.pspace = current_program_space;
7150 init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops);
7152 b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string);
7153 b->disposition = tempflag ? disp_del : disp_donttouch;
7157 install_breakpoint (int internal, struct breakpoint *b, int update_gll)
7159 add_to_breakpoint_chain (b);
7160 set_breakpoint_number (internal, b);
7163 observer_notify_breakpoint_created (b);
7166 update_global_location_list (1);
7170 create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch,
7171 int tempflag, char *cond_string,
7172 const struct breakpoint_ops *ops)
7174 struct fork_catchpoint *c = XNEW (struct fork_catchpoint);
7176 init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops);
7178 c->forked_inferior_pid = null_ptid;
7180 install_breakpoint (0, &c->base, 1);
7183 /* Exec catchpoints. */
7185 /* An instance of this type is used to represent an exec catchpoint.
7186 It includes a "struct breakpoint" as a kind of base class; users
7187 downcast to "struct breakpoint *" when needed. A breakpoint is
7188 really of this type iff its ops pointer points to
7189 CATCH_EXEC_BREAKPOINT_OPS. */
7191 struct exec_catchpoint
7193 /* The base class. */
7194 struct breakpoint base;
7196 /* Filename of a program whose exec triggered this catchpoint.
7197 This field is only valid immediately after this catchpoint has
7199 char *exec_pathname;
7202 /* Implement the "dtor" breakpoint_ops method for exec
7206 dtor_catch_exec (struct breakpoint *b)
7208 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
7210 xfree (c->exec_pathname);
7212 base_breakpoint_ops.dtor (b);
7216 insert_catch_exec (struct bp_location *bl)
7218 return target_insert_exec_catchpoint (PIDGET (inferior_ptid));
7222 remove_catch_exec (struct bp_location *bl)
7224 return target_remove_exec_catchpoint (PIDGET (inferior_ptid));
7228 breakpoint_hit_catch_exec (const struct bp_location *bl,
7229 struct address_space *aspace, CORE_ADDR bp_addr,
7230 const struct target_waitstatus *ws)
7232 struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner;
7234 if (ws->kind != TARGET_WAITKIND_EXECD)
7237 c->exec_pathname = xstrdup (ws->value.execd_pathname);
7241 static enum print_stop_action
7242 print_it_catch_exec (bpstat bs)
7244 struct ui_out *uiout = current_uiout;
7245 struct breakpoint *b = bs->breakpoint_at;
7246 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
7248 annotate_catchpoint (b->number);
7249 if (b->disposition == disp_del)
7250 ui_out_text (uiout, "\nTemporary catchpoint ");
7252 ui_out_text (uiout, "\nCatchpoint ");
7253 if (ui_out_is_mi_like_p (uiout))
7255 ui_out_field_string (uiout, "reason",
7256 async_reason_lookup (EXEC_ASYNC_EXEC));
7257 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7259 ui_out_field_int (uiout, "bkptno", b->number);
7260 ui_out_text (uiout, " (exec'd ");
7261 ui_out_field_string (uiout, "new-exec", c->exec_pathname);
7262 ui_out_text (uiout, "), ");
7264 return PRINT_SRC_AND_LOC;
7268 print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc)
7270 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
7271 struct value_print_options opts;
7272 struct ui_out *uiout = current_uiout;
7274 get_user_print_options (&opts);
7276 /* Field 4, the address, is omitted (which makes the columns
7277 not line up too nicely with the headers, but the effect
7278 is relatively readable). */
7279 if (opts.addressprint)
7280 ui_out_field_skip (uiout, "addr");
7282 ui_out_text (uiout, "exec");
7283 if (c->exec_pathname != NULL)
7285 ui_out_text (uiout, ", program \"");
7286 ui_out_field_string (uiout, "what", c->exec_pathname);
7287 ui_out_text (uiout, "\" ");
7292 print_mention_catch_exec (struct breakpoint *b)
7294 printf_filtered (_("Catchpoint %d (exec)"), b->number);
7297 /* Implement the "print_recreate" breakpoint_ops method for exec
7301 print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp)
7303 fprintf_unfiltered (fp, "catch exec");
7304 print_recreate_thread (b, fp);
7307 static struct breakpoint_ops catch_exec_breakpoint_ops;
7310 create_syscall_event_catchpoint (int tempflag, VEC(int) *filter,
7311 const struct breakpoint_ops *ops)
7313 struct syscall_catchpoint *c;
7314 struct gdbarch *gdbarch = get_current_arch ();
7316 c = XNEW (struct syscall_catchpoint);
7317 init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops);
7318 c->syscalls_to_be_caught = filter;
7320 install_breakpoint (0, &c->base, 1);
7324 hw_breakpoint_used_count (void)
7327 struct breakpoint *b;
7328 struct bp_location *bl;
7332 if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b))
7333 for (bl = b->loc; bl; bl = bl->next)
7335 /* Special types of hardware breakpoints may use more than
7337 i += b->ops->resources_needed (bl);
7344 /* Returns the resources B would use if it were a hardware
7348 hw_watchpoint_use_count (struct breakpoint *b)
7351 struct bp_location *bl;
7353 if (!breakpoint_enabled (b))
7356 for (bl = b->loc; bl; bl = bl->next)
7358 /* Special types of hardware watchpoints may use more than
7360 i += b->ops->resources_needed (bl);
7366 /* Returns the sum the used resources of all hardware watchpoints of
7367 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
7368 the sum of the used resources of all hardware watchpoints of other
7369 types _not_ TYPE. */
7372 hw_watchpoint_used_count_others (struct breakpoint *except,
7373 enum bptype type, int *other_type_used)
7376 struct breakpoint *b;
7378 *other_type_used = 0;
7383 if (!breakpoint_enabled (b))
7386 if (b->type == type)
7387 i += hw_watchpoint_use_count (b);
7388 else if (is_hardware_watchpoint (b))
7389 *other_type_used = 1;
7396 disable_watchpoints_before_interactive_call_start (void)
7398 struct breakpoint *b;
7402 if (is_watchpoint (b) && breakpoint_enabled (b))
7404 b->enable_state = bp_call_disabled;
7405 update_global_location_list (0);
7411 enable_watchpoints_after_interactive_call_stop (void)
7413 struct breakpoint *b;
7417 if (is_watchpoint (b) && b->enable_state == bp_call_disabled)
7419 b->enable_state = bp_enabled;
7420 update_global_location_list (1);
7426 disable_breakpoints_before_startup (void)
7428 current_program_space->executing_startup = 1;
7429 update_global_location_list (0);
7433 enable_breakpoints_after_startup (void)
7435 current_program_space->executing_startup = 0;
7436 breakpoint_re_set ();
7440 /* Set a breakpoint that will evaporate an end of command
7441 at address specified by SAL.
7442 Restrict it to frame FRAME if FRAME is nonzero. */
7445 set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal,
7446 struct frame_id frame_id, enum bptype type)
7448 struct breakpoint *b;
7450 /* If FRAME_ID is valid, it should be a real frame, not an inlined
7452 gdb_assert (!frame_id_inlined_p (frame_id));
7454 b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops);
7455 b->enable_state = bp_enabled;
7456 b->disposition = disp_donttouch;
7457 b->frame_id = frame_id;
7459 /* If we're debugging a multi-threaded program, then we want
7460 momentary breakpoints to be active in only a single thread of
7462 if (in_thread_list (inferior_ptid))
7463 b->thread = pid_to_thread_id (inferior_ptid);
7465 update_global_location_list_nothrow (1);
7470 /* Make a momentary breakpoint based on the master breakpoint ORIG.
7471 The new breakpoint will have type TYPE, and use OPS as it
7474 static struct breakpoint *
7475 momentary_breakpoint_from_master (struct breakpoint *orig,
7477 const struct breakpoint_ops *ops)
7479 struct breakpoint *copy;
7481 copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops);
7482 copy->loc = allocate_bp_location (copy);
7483 set_breakpoint_location_function (copy->loc, 1);
7485 copy->loc->gdbarch = orig->loc->gdbarch;
7486 copy->loc->requested_address = orig->loc->requested_address;
7487 copy->loc->address = orig->loc->address;
7488 copy->loc->section = orig->loc->section;
7489 copy->loc->pspace = orig->loc->pspace;
7491 if (orig->loc->source_file != NULL)
7492 copy->loc->source_file = xstrdup (orig->loc->source_file);
7494 copy->loc->line_number = orig->loc->line_number;
7495 copy->frame_id = orig->frame_id;
7496 copy->thread = orig->thread;
7497 copy->pspace = orig->pspace;
7499 copy->enable_state = bp_enabled;
7500 copy->disposition = disp_donttouch;
7501 copy->number = internal_breakpoint_number--;
7503 update_global_location_list_nothrow (0);
7507 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
7511 clone_momentary_breakpoint (struct breakpoint *orig)
7513 /* If there's nothing to clone, then return nothing. */
7517 return momentary_breakpoint_from_master (orig, orig->type, orig->ops);
7521 set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc,
7524 struct symtab_and_line sal;
7526 sal = find_pc_line (pc, 0);
7528 sal.section = find_pc_overlay (pc);
7529 sal.explicit_pc = 1;
7531 return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type);
7535 /* Tell the user we have just set a breakpoint B. */
7538 mention (struct breakpoint *b)
7540 b->ops->print_mention (b);
7541 if (ui_out_is_mi_like_p (current_uiout))
7543 printf_filtered ("\n");
7547 static struct bp_location *
7548 add_location_to_breakpoint (struct breakpoint *b,
7549 const struct symtab_and_line *sal)
7551 struct bp_location *loc, **tmp;
7552 CORE_ADDR adjusted_address;
7553 struct gdbarch *loc_gdbarch = get_sal_arch (*sal);
7555 if (loc_gdbarch == NULL)
7556 loc_gdbarch = b->gdbarch;
7558 /* Adjust the breakpoint's address prior to allocating a location.
7559 Once we call allocate_bp_location(), that mostly uninitialized
7560 location will be placed on the location chain. Adjustment of the
7561 breakpoint may cause target_read_memory() to be called and we do
7562 not want its scan of the location chain to find a breakpoint and
7563 location that's only been partially initialized. */
7564 adjusted_address = adjust_breakpoint_address (loc_gdbarch,
7567 loc = allocate_bp_location (b);
7568 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
7572 loc->requested_address = sal->pc;
7573 loc->address = adjusted_address;
7574 loc->pspace = sal->pspace;
7575 gdb_assert (loc->pspace != NULL);
7576 loc->section = sal->section;
7577 loc->gdbarch = loc_gdbarch;
7579 if (sal->symtab != NULL)
7580 loc->source_file = xstrdup (sal->symtab->filename);
7581 loc->line_number = sal->line;
7583 set_breakpoint_location_function (loc,
7584 sal->explicit_pc || sal->explicit_line);
7589 /* Return 1 if LOC is pointing to a permanent breakpoint,
7590 return 0 otherwise. */
7593 bp_loc_is_permanent (struct bp_location *loc)
7597 const gdb_byte *bpoint;
7598 gdb_byte *target_mem;
7599 struct cleanup *cleanup;
7602 gdb_assert (loc != NULL);
7604 addr = loc->address;
7605 bpoint = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len);
7607 /* Software breakpoints unsupported? */
7611 target_mem = alloca (len);
7613 /* Enable the automatic memory restoration from breakpoints while
7614 we read the memory. Otherwise we could say about our temporary
7615 breakpoints they are permanent. */
7616 cleanup = save_current_space_and_thread ();
7618 switch_to_program_space_and_thread (loc->pspace);
7619 make_show_memory_breakpoints_cleanup (0);
7621 if (target_read_memory (loc->address, target_mem, len) == 0
7622 && memcmp (target_mem, bpoint, len) == 0)
7625 do_cleanups (cleanup);
7632 /* Create a breakpoint with SAL as location. Use ADDR_STRING
7633 as textual description of the location, and COND_STRING
7634 as condition expression. */
7637 init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch,
7638 struct symtabs_and_lines sals, char *addr_string,
7639 char *filter, char *cond_string,
7640 enum bptype type, enum bpdisp disposition,
7641 int thread, int task, int ignore_count,
7642 const struct breakpoint_ops *ops, int from_tty,
7643 int enabled, int internal, int display_canonical)
7647 if (type == bp_hardware_breakpoint)
7649 int target_resources_ok;
7651 i = hw_breakpoint_used_count ();
7652 target_resources_ok =
7653 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
7655 if (target_resources_ok == 0)
7656 error (_("No hardware breakpoint support in the target."));
7657 else if (target_resources_ok < 0)
7658 error (_("Hardware breakpoints used exceeds limit."));
7661 gdb_assert (sals.nelts > 0);
7663 for (i = 0; i < sals.nelts; ++i)
7665 struct symtab_and_line sal = sals.sals[i];
7666 struct bp_location *loc;
7670 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
7672 loc_gdbarch = gdbarch;
7674 describe_other_breakpoints (loc_gdbarch,
7675 sal.pspace, sal.pc, sal.section, thread);
7680 init_raw_breakpoint (b, gdbarch, sal, type, ops);
7684 b->cond_string = cond_string;
7685 b->ignore_count = ignore_count;
7686 b->enable_state = enabled ? bp_enabled : bp_disabled;
7687 b->disposition = disposition;
7689 if (type == bp_static_tracepoint)
7691 struct tracepoint *t = (struct tracepoint *) b;
7692 struct static_tracepoint_marker marker;
7694 if (strace_marker_p (b))
7696 /* We already know the marker exists, otherwise, we
7697 wouldn't see a sal for it. */
7698 char *p = &addr_string[3];
7702 p = skip_spaces (p);
7704 endp = skip_to_space (p);
7706 marker_str = savestring (p, endp - p);
7707 t->static_trace_marker_id = marker_str;
7709 printf_filtered (_("Probed static tracepoint "
7711 t->static_trace_marker_id);
7713 else if (target_static_tracepoint_marker_at (sal.pc, &marker))
7715 t->static_trace_marker_id = xstrdup (marker.str_id);
7716 release_static_tracepoint_marker (&marker);
7718 printf_filtered (_("Probed static tracepoint "
7720 t->static_trace_marker_id);
7723 warning (_("Couldn't determine the static "
7724 "tracepoint marker to probe"));
7731 loc = add_location_to_breakpoint (b, &sal);
7734 if (bp_loc_is_permanent (loc))
7735 make_breakpoint_permanent (b);
7739 char *arg = b->cond_string;
7740 loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0);
7742 error (_("Garbage %s follows condition"), arg);
7746 b->display_canonical = display_canonical;
7748 b->addr_string = addr_string;
7750 /* addr_string has to be used or breakpoint_re_set will delete
7753 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
7758 create_breakpoint_sal (struct gdbarch *gdbarch,
7759 struct symtabs_and_lines sals, char *addr_string,
7760 char *filter, char *cond_string,
7761 enum bptype type, enum bpdisp disposition,
7762 int thread, int task, int ignore_count,
7763 const struct breakpoint_ops *ops, int from_tty,
7764 int enabled, int internal, int display_canonical)
7766 struct breakpoint *b;
7767 struct cleanup *old_chain;
7769 if (is_tracepoint_type (type))
7771 struct tracepoint *t;
7773 t = XCNEW (struct tracepoint);
7777 b = XNEW (struct breakpoint);
7779 old_chain = make_cleanup (xfree, b);
7781 init_breakpoint_sal (b, gdbarch,
7783 filter, cond_string,
7785 thread, task, ignore_count,
7787 enabled, internal, display_canonical);
7788 discard_cleanups (old_chain);
7790 install_breakpoint (internal, b, 0);
7793 /* Add SALS.nelts breakpoints to the breakpoint table. For each
7794 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
7795 value. COND_STRING, if not NULL, specified the condition to be
7796 used for all breakpoints. Essentially the only case where
7797 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
7798 function. In that case, it's still not possible to specify
7799 separate conditions for different overloaded functions, so
7800 we take just a single condition string.
7802 NOTE: If the function succeeds, the caller is expected to cleanup
7803 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
7804 array contents). If the function fails (error() is called), the
7805 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
7806 COND and SALS arrays and each of those arrays contents. */
7809 create_breakpoints_sal (struct gdbarch *gdbarch,
7810 struct linespec_result *canonical,
7812 enum bptype type, enum bpdisp disposition,
7813 int thread, int task, int ignore_count,
7814 const struct breakpoint_ops *ops, int from_tty,
7815 int enabled, int internal)
7818 struct linespec_sals *lsal;
7820 if (canonical->pre_expanded)
7821 gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1);
7823 for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i)
7825 /* Note that 'addr_string' can be NULL in the case of a plain
7826 'break', without arguments. */
7827 char *addr_string = (canonical->addr_string
7828 ? xstrdup (canonical->addr_string)
7830 char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL;
7831 struct cleanup *inner = make_cleanup (xfree, addr_string);
7833 make_cleanup (xfree, filter_string);
7834 create_breakpoint_sal (gdbarch, lsal->sals,
7837 cond_string, type, disposition,
7838 thread, task, ignore_count, ops,
7839 from_tty, enabled, internal,
7840 canonical->special_display);
7841 discard_cleanups (inner);
7845 /* Parse ADDRESS which is assumed to be a SAL specification possibly
7846 followed by conditionals. On return, SALS contains an array of SAL
7847 addresses found. ADDR_STRING contains a vector of (canonical)
7848 address strings. ADDRESS points to the end of the SAL.
7850 The array and the line spec strings are allocated on the heap, it is
7851 the caller's responsibility to free them. */
7854 parse_breakpoint_sals (char **address,
7855 struct linespec_result *canonical)
7857 char *addr_start = *address;
7859 /* If no arg given, or if first arg is 'if ', use the default
7861 if ((*address) == NULL
7862 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
7864 /* The last displayed codepoint, if it's valid, is our default breakpoint
7866 if (last_displayed_sal_is_valid ())
7868 struct linespec_sals lsal;
7869 struct symtab_and_line sal;
7871 init_sal (&sal); /* Initialize to zeroes. */
7872 lsal.sals.sals = (struct symtab_and_line *)
7873 xmalloc (sizeof (struct symtab_and_line));
7875 /* Set sal's pspace, pc, symtab, and line to the values
7876 corresponding to the last call to print_frame_info. */
7877 get_last_displayed_sal (&sal);
7878 sal.section = find_pc_overlay (sal.pc);
7880 /* "break" without arguments is equivalent to "break *PC"
7881 where PC is the last displayed codepoint's address. So
7882 make sure to set sal.explicit_pc to prevent GDB from
7883 trying to expand the list of sals to include all other
7884 instances with the same symtab and line. */
7885 sal.explicit_pc = 1;
7887 lsal.sals.sals[0] = sal;
7888 lsal.sals.nelts = 1;
7889 lsal.canonical = NULL;
7891 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
7894 error (_("No default breakpoint address now."));
7898 /* Force almost all breakpoints to be in terms of the
7899 current_source_symtab (which is decode_line_1's default).
7900 This should produce the results we want almost all of the
7901 time while leaving default_breakpoint_* alone. */
7902 if (last_displayed_sal_is_valid ())
7903 decode_line_full (address, DECODE_LINE_FUNFIRSTLINE,
7904 get_last_displayed_symtab (),
7905 get_last_displayed_line (),
7906 canonical, NULL, NULL);
7908 decode_line_full (address, DECODE_LINE_FUNFIRSTLINE,
7909 (struct symtab *) NULL, 0,
7910 canonical, NULL, NULL);
7915 /* Convert each SAL into a real PC. Verify that the PC can be
7916 inserted as a breakpoint. If it can't throw an error. */
7919 breakpoint_sals_to_pc (struct symtabs_and_lines *sals)
7923 for (i = 0; i < sals->nelts; i++)
7924 resolve_sal_pc (&sals->sals[i]);
7927 /* Fast tracepoints may have restrictions on valid locations. For
7928 instance, a fast tracepoint using a jump instead of a trap will
7929 likely have to overwrite more bytes than a trap would, and so can
7930 only be placed where the instruction is longer than the jump, or a
7931 multi-instruction sequence does not have a jump into the middle of
7935 check_fast_tracepoint_sals (struct gdbarch *gdbarch,
7936 struct symtabs_and_lines *sals)
7939 struct symtab_and_line *sal;
7941 struct cleanup *old_chain;
7943 for (i = 0; i < sals->nelts; i++)
7945 struct gdbarch *sarch;
7947 sal = &sals->sals[i];
7949 sarch = get_sal_arch (*sal);
7950 /* We fall back to GDBARCH if there is no architecture
7951 associated with SAL. */
7954 rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc,
7956 old_chain = make_cleanup (xfree, msg);
7959 error (_("May not have a fast tracepoint at 0x%s%s"),
7960 paddress (sarch, sal->pc), (msg ? msg : ""));
7962 do_cleanups (old_chain);
7966 /* Given TOK, a string specification of condition and thread, as
7967 accepted by the 'break' command, extract the condition
7968 string and thread number and set *COND_STRING and *THREAD.
7969 PC identifies the context at which the condition should be parsed.
7970 If no condition is found, *COND_STRING is set to NULL.
7971 If no thread is found, *THREAD is set to -1. */
7973 find_condition_and_thread (char *tok, CORE_ADDR pc,
7974 char **cond_string, int *thread, int *task)
7976 *cond_string = NULL;
7982 char *cond_start = NULL;
7983 char *cond_end = NULL;
7985 tok = skip_spaces (tok);
7987 end_tok = skip_to_space (tok);
7989 toklen = end_tok - tok;
7991 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
7993 struct expression *expr;
7995 tok = cond_start = end_tok + 1;
7996 expr = parse_exp_1 (&tok, block_for_pc (pc), 0);
7999 *cond_string = savestring (cond_start,
8000 cond_end - cond_start);
8002 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
8008 *thread = strtol (tok, &tok, 0);
8010 error (_("Junk after thread keyword."));
8011 if (!valid_thread_id (*thread))
8012 error (_("Unknown thread %d."), *thread);
8014 else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0)
8020 *task = strtol (tok, &tok, 0);
8022 error (_("Junk after task keyword."));
8023 if (!valid_task_id (*task))
8024 error (_("Unknown task %d."), *task);
8027 error (_("Junk at end of arguments."));
8031 /* Decode a static tracepoint marker spec. */
8033 static struct symtabs_and_lines
8034 decode_static_tracepoint_spec (char **arg_p)
8036 VEC(static_tracepoint_marker_p) *markers = NULL;
8037 struct symtabs_and_lines sals;
8038 struct symtab_and_line sal;
8040 struct cleanup *old_chain;
8041 char *p = &(*arg_p)[3];
8046 p = skip_spaces (p);
8048 endp = skip_to_space (p);
8050 marker_str = savestring (p, endp - p);
8051 old_chain = make_cleanup (xfree, marker_str);
8053 markers = target_static_tracepoint_markers_by_strid (marker_str);
8054 if (VEC_empty(static_tracepoint_marker_p, markers))
8055 error (_("No known static tracepoint marker named %s"), marker_str);
8057 sals.nelts = VEC_length(static_tracepoint_marker_p, markers);
8058 sals.sals = xmalloc (sizeof *sals.sals * sals.nelts);
8060 for (i = 0; i < sals.nelts; i++)
8062 struct static_tracepoint_marker *marker;
8064 marker = VEC_index (static_tracepoint_marker_p, markers, i);
8066 init_sal (&sals.sals[i]);
8068 sals.sals[i] = find_pc_line (marker->address, 0);
8069 sals.sals[i].pc = marker->address;
8071 release_static_tracepoint_marker (marker);
8074 do_cleanups (old_chain);
8080 /* Set a breakpoint. This function is shared between CLI and MI
8081 functions for setting a breakpoint. This function has two major
8082 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
8083 parameter. If non-zero, the function will parse arg, extracting
8084 breakpoint location, address and thread. Otherwise, ARG is just
8085 the location of breakpoint, with condition and thread specified by
8086 the COND_STRING and THREAD parameters. If INTERNAL is non-zero,
8087 the breakpoint number will be allocated from the internal
8088 breakpoint count. Returns true if any breakpoint was created;
8092 create_breakpoint (struct gdbarch *gdbarch,
8093 char *arg, char *cond_string, int thread,
8094 int parse_condition_and_thread,
8095 int tempflag, enum bptype type_wanted,
8097 enum auto_boolean pending_break_support,
8098 const struct breakpoint_ops *ops,
8099 int from_tty, int enabled, int internal)
8101 volatile struct gdb_exception e;
8102 char *copy_arg = NULL;
8103 char *addr_start = arg;
8104 struct linespec_result canonical;
8105 struct cleanup *old_chain;
8106 struct cleanup *bkpt_chain = NULL;
8110 int prev_bkpt_count = breakpoint_count;
8112 gdb_assert (ops != NULL);
8114 init_linespec_result (&canonical);
8116 TRY_CATCH (e, RETURN_MASK_ALL)
8118 ops->create_sals_from_address (&arg, &canonical, type_wanted,
8119 addr_start, ©_arg);
8122 /* If caller is interested in rc value from parse, set value. */
8126 if (VEC_empty (linespec_sals, canonical.sals))
8132 case NOT_FOUND_ERROR:
8134 /* If pending breakpoint support is turned off, throw
8137 if (pending_break_support == AUTO_BOOLEAN_FALSE)
8138 throw_exception (e);
8140 exception_print (gdb_stderr, e);
8142 /* If pending breakpoint support is auto query and the user
8143 selects no, then simply return the error code. */
8144 if (pending_break_support == AUTO_BOOLEAN_AUTO
8145 && !nquery (_("Make %s pending on future shared library load? "),
8146 bptype_string (type_wanted)))
8149 /* At this point, either the user was queried about setting
8150 a pending breakpoint and selected yes, or pending
8151 breakpoint behavior is on and thus a pending breakpoint
8152 is defaulted on behalf of the user. */
8154 struct linespec_sals lsal;
8156 copy_arg = xstrdup (addr_start);
8157 lsal.canonical = xstrdup (copy_arg);
8158 lsal.sals.nelts = 1;
8159 lsal.sals.sals = XNEW (struct symtab_and_line);
8160 init_sal (&lsal.sals.sals[0]);
8162 VEC_safe_push (linespec_sals, canonical.sals, &lsal);
8166 throw_exception (e);
8170 throw_exception (e);
8173 /* Create a chain of things that always need to be cleaned up. */
8174 old_chain = make_cleanup_destroy_linespec_result (&canonical);
8176 /* ----------------------------- SNIP -----------------------------
8177 Anything added to the cleanup chain beyond this point is assumed
8178 to be part of a breakpoint. If the breakpoint create succeeds
8179 then the memory is not reclaimed. */
8180 bkpt_chain = make_cleanup (null_cleanup, 0);
8182 /* Resolve all line numbers to PC's and verify that the addresses
8183 are ok for the target. */
8187 struct linespec_sals *iter;
8189 for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
8190 breakpoint_sals_to_pc (&iter->sals);
8193 /* Fast tracepoints may have additional restrictions on location. */
8194 if (!pending && type_wanted == bp_fast_tracepoint)
8197 struct linespec_sals *iter;
8199 for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
8200 check_fast_tracepoint_sals (gdbarch, &iter->sals);
8203 /* Verify that condition can be parsed, before setting any
8204 breakpoints. Allocate a separate condition expression for each
8208 struct linespec_sals *lsal;
8210 lsal = VEC_index (linespec_sals, canonical.sals, 0);
8212 if (parse_condition_and_thread)
8214 /* Here we only parse 'arg' to separate condition
8215 from thread number, so parsing in context of first
8216 sal is OK. When setting the breakpoint we'll
8217 re-parse it in context of each sal. */
8220 find_condition_and_thread (arg, lsal->sals.sals[0].pc, &cond_string,
8223 make_cleanup (xfree, cond_string);
8227 /* Create a private copy of condition string. */
8230 cond_string = xstrdup (cond_string);
8231 make_cleanup (xfree, cond_string);
8235 ops->create_breakpoints_sal (gdbarch, &canonical, lsal,
8236 cond_string, type_wanted,
8237 tempflag ? disp_del : disp_donttouch,
8238 thread, task, ignore_count, ops,
8239 from_tty, enabled, internal);
8243 struct breakpoint *b;
8245 make_cleanup (xfree, copy_arg);
8247 if (is_tracepoint_type (type_wanted))
8249 struct tracepoint *t;
8251 t = XCNEW (struct tracepoint);
8255 b = XNEW (struct breakpoint);
8257 init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops);
8259 b->addr_string = copy_arg;
8260 b->cond_string = NULL;
8261 b->ignore_count = ignore_count;
8262 b->disposition = tempflag ? disp_del : disp_donttouch;
8263 b->condition_not_parsed = 1;
8264 b->enable_state = enabled ? bp_enabled : bp_disabled;
8265 if ((type_wanted != bp_breakpoint
8266 && type_wanted != bp_hardware_breakpoint) || thread != -1)
8267 b->pspace = current_program_space;
8269 install_breakpoint (internal, b, 0);
8272 if (VEC_length (linespec_sals, canonical.sals) > 1)
8274 warning (_("Multiple breakpoints were set.\nUse the "
8275 "\"delete\" command to delete unwanted breakpoints."));
8276 prev_breakpoint_count = prev_bkpt_count;
8279 /* That's it. Discard the cleanups for data inserted into the
8281 discard_cleanups (bkpt_chain);
8282 /* But cleanup everything else. */
8283 do_cleanups (old_chain);
8285 /* error call may happen here - have BKPT_CHAIN already discarded. */
8286 update_global_location_list (1);
8291 /* Set a breakpoint.
8292 ARG is a string describing breakpoint address,
8293 condition, and thread.
8294 FLAG specifies if a breakpoint is hardware on,
8295 and if breakpoint is temporary, using BP_HARDWARE_FLAG
8299 break_command_1 (char *arg, int flag, int from_tty)
8301 int tempflag = flag & BP_TEMPFLAG;
8302 enum bptype type_wanted = (flag & BP_HARDWAREFLAG
8303 ? bp_hardware_breakpoint
8306 create_breakpoint (get_current_arch (),
8308 NULL, 0, 1 /* parse arg */,
8309 tempflag, type_wanted,
8310 0 /* Ignore count */,
8311 pending_break_support,
8312 &bkpt_breakpoint_ops,
8318 /* Helper function for break_command_1 and disassemble_command. */
8321 resolve_sal_pc (struct symtab_and_line *sal)
8325 if (sal->pc == 0 && sal->symtab != NULL)
8327 if (!find_line_pc (sal->symtab, sal->line, &pc))
8328 error (_("No line %d in file \"%s\"."),
8329 sal->line, sal->symtab->filename);
8332 /* If this SAL corresponds to a breakpoint inserted using a line
8333 number, then skip the function prologue if necessary. */
8334 if (sal->explicit_line)
8335 skip_prologue_sal (sal);
8338 if (sal->section == 0 && sal->symtab != NULL)
8340 struct blockvector *bv;
8344 bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab);
8347 sym = block_linkage_function (b);
8350 fixup_symbol_section (sym, sal->symtab->objfile);
8351 sal->section = SYMBOL_OBJ_SECTION (sym);
8355 /* It really is worthwhile to have the section, so we'll
8356 just have to look harder. This case can be executed
8357 if we have line numbers but no functions (as can
8358 happen in assembly source). */
8360 struct minimal_symbol *msym;
8361 struct cleanup *old_chain = save_current_space_and_thread ();
8363 switch_to_program_space_and_thread (sal->pspace);
8365 msym = lookup_minimal_symbol_by_pc (sal->pc);
8367 sal->section = SYMBOL_OBJ_SECTION (msym);
8369 do_cleanups (old_chain);
8376 break_command (char *arg, int from_tty)
8378 break_command_1 (arg, 0, from_tty);
8382 tbreak_command (char *arg, int from_tty)
8384 break_command_1 (arg, BP_TEMPFLAG, from_tty);
8388 hbreak_command (char *arg, int from_tty)
8390 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
8394 thbreak_command (char *arg, int from_tty)
8396 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
8400 stop_command (char *arg, int from_tty)
8402 printf_filtered (_("Specify the type of breakpoint to set.\n\
8403 Usage: stop in <function | address>\n\
8404 stop at <line>\n"));
8408 stopin_command (char *arg, int from_tty)
8412 if (arg == (char *) NULL)
8414 else if (*arg != '*')
8419 /* Look for a ':'. If this is a line number specification, then
8420 say it is bad, otherwise, it should be an address or
8421 function/method name. */
8422 while (*argptr && !hasColon)
8424 hasColon = (*argptr == ':');
8429 badInput = (*argptr != ':'); /* Not a class::method */
8431 badInput = isdigit (*arg); /* a simple line number */
8435 printf_filtered (_("Usage: stop in <function | address>\n"));
8437 break_command_1 (arg, 0, from_tty);
8441 stopat_command (char *arg, int from_tty)
8445 if (arg == (char *) NULL || *arg == '*') /* no line number */
8452 /* Look for a ':'. If there is a '::' then get out, otherwise
8453 it is probably a line number. */
8454 while (*argptr && !hasColon)
8456 hasColon = (*argptr == ':');
8461 badInput = (*argptr == ':'); /* we have class::method */
8463 badInput = !isdigit (*arg); /* not a line number */
8467 printf_filtered (_("Usage: stop at <line>\n"));
8469 break_command_1 (arg, 0, from_tty);
8472 /* Implement the "breakpoint_hit" breakpoint_ops method for
8473 ranged breakpoints. */
8476 breakpoint_hit_ranged_breakpoint (const struct bp_location *bl,
8477 struct address_space *aspace,
8479 const struct target_waitstatus *ws)
8481 if (ws->kind != TARGET_WAITKIND_STOPPED
8482 || ws->value.sig != TARGET_SIGNAL_TRAP)
8485 return breakpoint_address_match_range (bl->pspace->aspace, bl->address,
8486 bl->length, aspace, bp_addr);
8489 /* Implement the "resources_needed" breakpoint_ops method for
8490 ranged breakpoints. */
8493 resources_needed_ranged_breakpoint (const struct bp_location *bl)
8495 return target_ranged_break_num_registers ();
8498 /* Implement the "print_it" breakpoint_ops method for
8499 ranged breakpoints. */
8501 static enum print_stop_action
8502 print_it_ranged_breakpoint (bpstat bs)
8504 struct breakpoint *b = bs->breakpoint_at;
8505 struct bp_location *bl = b->loc;
8506 struct ui_out *uiout = current_uiout;
8508 gdb_assert (b->type == bp_hardware_breakpoint);
8510 /* Ranged breakpoints have only one location. */
8511 gdb_assert (bl && bl->next == NULL);
8513 annotate_breakpoint (b->number);
8514 if (b->disposition == disp_del)
8515 ui_out_text (uiout, "\nTemporary ranged breakpoint ");
8517 ui_out_text (uiout, "\nRanged breakpoint ");
8518 if (ui_out_is_mi_like_p (uiout))
8520 ui_out_field_string (uiout, "reason",
8521 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
8522 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8524 ui_out_field_int (uiout, "bkptno", b->number);
8525 ui_out_text (uiout, ", ");
8527 return PRINT_SRC_AND_LOC;
8530 /* Implement the "print_one" breakpoint_ops method for
8531 ranged breakpoints. */
8534 print_one_ranged_breakpoint (struct breakpoint *b,
8535 struct bp_location **last_loc)
8537 struct bp_location *bl = b->loc;
8538 struct value_print_options opts;
8539 struct ui_out *uiout = current_uiout;
8541 /* Ranged breakpoints have only one location. */
8542 gdb_assert (bl && bl->next == NULL);
8544 get_user_print_options (&opts);
8546 if (opts.addressprint)
8547 /* We don't print the address range here, it will be printed later
8548 by print_one_detail_ranged_breakpoint. */
8549 ui_out_field_skip (uiout, "addr");
8551 print_breakpoint_location (b, bl);
8555 /* Implement the "print_one_detail" breakpoint_ops method for
8556 ranged breakpoints. */
8559 print_one_detail_ranged_breakpoint (const struct breakpoint *b,
8560 struct ui_out *uiout)
8562 CORE_ADDR address_start, address_end;
8563 struct bp_location *bl = b->loc;
8564 struct ui_stream *stb = ui_out_stream_new (uiout);
8565 struct cleanup *cleanup = make_cleanup_ui_out_stream_delete (stb);
8569 address_start = bl->address;
8570 address_end = address_start + bl->length - 1;
8572 ui_out_text (uiout, "\taddress range: ");
8573 fprintf_unfiltered (stb->stream, "[%s, %s]",
8574 print_core_address (bl->gdbarch, address_start),
8575 print_core_address (bl->gdbarch, address_end));
8576 ui_out_field_stream (uiout, "addr", stb);
8577 ui_out_text (uiout, "\n");
8579 do_cleanups (cleanup);
8582 /* Implement the "print_mention" breakpoint_ops method for
8583 ranged breakpoints. */
8586 print_mention_ranged_breakpoint (struct breakpoint *b)
8588 struct bp_location *bl = b->loc;
8589 struct ui_out *uiout = current_uiout;
8592 gdb_assert (b->type == bp_hardware_breakpoint);
8594 if (ui_out_is_mi_like_p (uiout))
8597 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
8598 b->number, paddress (bl->gdbarch, bl->address),
8599 paddress (bl->gdbarch, bl->address + bl->length - 1));
8602 /* Implement the "print_recreate" breakpoint_ops method for
8603 ranged breakpoints. */
8606 print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp)
8608 fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string,
8609 b->addr_string_range_end);
8610 print_recreate_thread (b, fp);
8613 /* The breakpoint_ops structure to be used in ranged breakpoints. */
8615 static struct breakpoint_ops ranged_breakpoint_ops;
8617 /* Find the address where the end of the breakpoint range should be
8618 placed, given the SAL of the end of the range. This is so that if
8619 the user provides a line number, the end of the range is set to the
8620 last instruction of the given line. */
8623 find_breakpoint_range_end (struct symtab_and_line sal)
8627 /* If the user provided a PC value, use it. Otherwise,
8628 find the address of the end of the given location. */
8629 if (sal.explicit_pc)
8636 ret = find_line_pc_range (sal, &start, &end);
8638 error (_("Could not find location of the end of the range."));
8640 /* find_line_pc_range returns the start of the next line. */
8647 /* Implement the "break-range" CLI command. */
8650 break_range_command (char *arg, int from_tty)
8652 char *arg_start, *addr_string_start, *addr_string_end;
8653 struct linespec_result canonical_start, canonical_end;
8654 int bp_count, can_use_bp, length;
8656 struct breakpoint *b;
8657 struct symtab_and_line sal_start, sal_end;
8658 struct cleanup *cleanup_bkpt;
8659 struct linespec_sals *lsal_start, *lsal_end;
8661 /* We don't support software ranged breakpoints. */
8662 if (target_ranged_break_num_registers () < 0)
8663 error (_("This target does not support hardware ranged breakpoints."));
8665 bp_count = hw_breakpoint_used_count ();
8666 bp_count += target_ranged_break_num_registers ();
8667 can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
8670 error (_("Hardware breakpoints used exceeds limit."));
8672 arg = skip_spaces (arg);
8673 if (arg == NULL || arg[0] == '\0')
8674 error(_("No address range specified."));
8676 init_linespec_result (&canonical_start);
8679 parse_breakpoint_sals (&arg, &canonical_start);
8681 cleanup_bkpt = make_cleanup_destroy_linespec_result (&canonical_start);
8684 error (_("Too few arguments."));
8685 else if (VEC_empty (linespec_sals, canonical_start.sals))
8686 error (_("Could not find location of the beginning of the range."));
8688 lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0);
8690 if (VEC_length (linespec_sals, canonical_start.sals) > 1
8691 || lsal_start->sals.nelts != 1)
8692 error (_("Cannot create a ranged breakpoint with multiple locations."));
8694 sal_start = lsal_start->sals.sals[0];
8695 addr_string_start = savestring (arg_start, arg - arg_start);
8696 make_cleanup (xfree, addr_string_start);
8698 arg++; /* Skip the comma. */
8699 arg = skip_spaces (arg);
8701 /* Parse the end location. */
8703 init_linespec_result (&canonical_end);
8706 /* We call decode_line_full directly here instead of using
8707 parse_breakpoint_sals because we need to specify the start location's
8708 symtab and line as the default symtab and line for the end of the
8709 range. This makes it possible to have ranges like "foo.c:27, +14",
8710 where +14 means 14 lines from the start location. */
8711 decode_line_full (&arg, DECODE_LINE_FUNFIRSTLINE,
8712 sal_start.symtab, sal_start.line,
8713 &canonical_end, NULL, NULL);
8715 make_cleanup_destroy_linespec_result (&canonical_end);
8717 if (VEC_empty (linespec_sals, canonical_end.sals))
8718 error (_("Could not find location of the end of the range."));
8720 lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0);
8721 if (VEC_length (linespec_sals, canonical_end.sals) > 1
8722 || lsal_end->sals.nelts != 1)
8723 error (_("Cannot create a ranged breakpoint with multiple locations."));
8725 sal_end = lsal_end->sals.sals[0];
8726 addr_string_end = savestring (arg_start, arg - arg_start);
8727 make_cleanup (xfree, addr_string_end);
8729 end = find_breakpoint_range_end (sal_end);
8730 if (sal_start.pc > end)
8731 error (_("Invalid address range, end precedes start."));
8733 length = end - sal_start.pc + 1;
8735 /* Length overflowed. */
8736 error (_("Address range too large."));
8737 else if (length == 1)
8739 /* This range is simple enough to be handled by
8740 the `hbreak' command. */
8741 hbreak_command (addr_string_start, 1);
8743 do_cleanups (cleanup_bkpt);
8748 /* Now set up the breakpoint. */
8749 b = set_raw_breakpoint (get_current_arch (), sal_start,
8750 bp_hardware_breakpoint, &ranged_breakpoint_ops);
8751 set_breakpoint_count (breakpoint_count + 1);
8752 b->number = breakpoint_count;
8753 b->disposition = disp_donttouch;
8754 b->addr_string = xstrdup (addr_string_start);
8755 b->addr_string_range_end = xstrdup (addr_string_end);
8756 b->loc->length = length;
8758 do_cleanups (cleanup_bkpt);
8761 observer_notify_breakpoint_created (b);
8762 update_global_location_list (1);
8765 /* Return non-zero if EXP is verified as constant. Returned zero
8766 means EXP is variable. Also the constant detection may fail for
8767 some constant expressions and in such case still falsely return
8770 watchpoint_exp_is_const (const struct expression *exp)
8778 /* We are only interested in the descriptor of each element. */
8779 operator_length (exp, i, &oplenp, &argsp);
8782 switch (exp->elts[i].opcode)
8792 case BINOP_LOGICAL_AND:
8793 case BINOP_LOGICAL_OR:
8794 case BINOP_BITWISE_AND:
8795 case BINOP_BITWISE_IOR:
8796 case BINOP_BITWISE_XOR:
8798 case BINOP_NOTEQUAL:
8814 case TERNOP_SLICE_COUNT:
8826 case OP_OBJC_NSSTRING:
8829 case UNOP_LOGICAL_NOT:
8830 case UNOP_COMPLEMENT:
8833 /* Unary, binary and ternary operators: We have to check
8834 their operands. If they are constant, then so is the
8835 result of that operation. For instance, if A and B are
8836 determined to be constants, then so is "A + B".
8838 UNOP_IND is one exception to the rule above, because the
8839 value of *ADDR is not necessarily a constant, even when
8844 /* Check whether the associated symbol is a constant.
8846 We use SYMBOL_CLASS rather than TYPE_CONST because it's
8847 possible that a buggy compiler could mark a variable as
8848 constant even when it is not, and TYPE_CONST would return
8849 true in this case, while SYMBOL_CLASS wouldn't.
8851 We also have to check for function symbols because they
8852 are always constant. */
8854 struct symbol *s = exp->elts[i + 2].symbol;
8856 if (SYMBOL_CLASS (s) != LOC_BLOCK
8857 && SYMBOL_CLASS (s) != LOC_CONST
8858 && SYMBOL_CLASS (s) != LOC_CONST_BYTES)
8863 /* The default action is to return 0 because we are using
8864 the optimistic approach here: If we don't know something,
8865 then it is not a constant. */
8874 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
8877 dtor_watchpoint (struct breakpoint *self)
8879 struct watchpoint *w = (struct watchpoint *) self;
8881 xfree (w->cond_exp);
8883 xfree (w->exp_string);
8884 xfree (w->exp_string_reparse);
8885 value_free (w->val);
8887 base_breakpoint_ops.dtor (self);
8890 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
8893 re_set_watchpoint (struct breakpoint *b)
8895 struct watchpoint *w = (struct watchpoint *) b;
8897 /* Watchpoint can be either on expression using entirely global
8898 variables, or it can be on local variables.
8900 Watchpoints of the first kind are never auto-deleted, and even
8901 persist across program restarts. Since they can use variables
8902 from shared libraries, we need to reparse expression as libraries
8903 are loaded and unloaded.
8905 Watchpoints on local variables can also change meaning as result
8906 of solib event. For example, if a watchpoint uses both a local
8907 and a global variables in expression, it's a local watchpoint,
8908 but unloading of a shared library will make the expression
8909 invalid. This is not a very common use case, but we still
8910 re-evaluate expression, to avoid surprises to the user.
8912 Note that for local watchpoints, we re-evaluate it only if
8913 watchpoints frame id is still valid. If it's not, it means the
8914 watchpoint is out of scope and will be deleted soon. In fact,
8915 I'm not sure we'll ever be called in this case.
8917 If a local watchpoint's frame id is still valid, then
8918 w->exp_valid_block is likewise valid, and we can safely use it.
8920 Don't do anything about disabled watchpoints, since they will be
8921 reevaluated again when enabled. */
8922 update_watchpoint (w, 1 /* reparse */);
8925 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
8928 insert_watchpoint (struct bp_location *bl)
8930 struct watchpoint *w = (struct watchpoint *) bl->owner;
8931 int length = w->exact ? 1 : bl->length;
8933 return target_insert_watchpoint (bl->address, length, bl->watchpoint_type,
8937 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
8940 remove_watchpoint (struct bp_location *bl)
8942 struct watchpoint *w = (struct watchpoint *) bl->owner;
8943 int length = w->exact ? 1 : bl->length;
8945 return target_remove_watchpoint (bl->address, length, bl->watchpoint_type,
8950 breakpoint_hit_watchpoint (const struct bp_location *bl,
8951 struct address_space *aspace, CORE_ADDR bp_addr,
8952 const struct target_waitstatus *ws)
8954 struct breakpoint *b = bl->owner;
8955 struct watchpoint *w = (struct watchpoint *) b;
8957 /* Continuable hardware watchpoints are treated as non-existent if the
8958 reason we stopped wasn't a hardware watchpoint (we didn't stop on
8959 some data address). Otherwise gdb won't stop on a break instruction
8960 in the code (not from a breakpoint) when a hardware watchpoint has
8961 been defined. Also skip watchpoints which we know did not trigger
8962 (did not match the data address). */
8963 if (is_hardware_watchpoint (b)
8964 && w->watchpoint_triggered == watch_triggered_no)
8971 check_status_watchpoint (bpstat bs)
8973 gdb_assert (is_watchpoint (bs->breakpoint_at));
8975 bpstat_check_watchpoint (bs);
8978 /* Implement the "resources_needed" breakpoint_ops method for
8979 hardware watchpoints. */
8982 resources_needed_watchpoint (const struct bp_location *bl)
8984 struct watchpoint *w = (struct watchpoint *) bl->owner;
8985 int length = w->exact? 1 : bl->length;
8987 return target_region_ok_for_hw_watchpoint (bl->address, length);
8990 /* Implement the "works_in_software_mode" breakpoint_ops method for
8991 hardware watchpoints. */
8994 works_in_software_mode_watchpoint (const struct breakpoint *b)
8996 /* Read and access watchpoints only work with hardware support. */
8997 return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint;
9000 static enum print_stop_action
9001 print_it_watchpoint (bpstat bs)
9003 struct cleanup *old_chain;
9004 struct breakpoint *b;
9005 const struct bp_location *bl;
9006 struct ui_stream *stb;
9007 enum print_stop_action result;
9008 struct watchpoint *w;
9009 struct ui_out *uiout = current_uiout;
9011 gdb_assert (bs->bp_location_at != NULL);
9013 bl = bs->bp_location_at;
9014 b = bs->breakpoint_at;
9015 w = (struct watchpoint *) b;
9017 stb = ui_out_stream_new (uiout);
9018 old_chain = make_cleanup_ui_out_stream_delete (stb);
9023 case bp_hardware_watchpoint:
9024 annotate_watchpoint (b->number);
9025 if (ui_out_is_mi_like_p (uiout))
9028 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
9030 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
9031 ui_out_text (uiout, "\nOld value = ");
9032 watchpoint_value_print (bs->old_val, stb->stream);
9033 ui_out_field_stream (uiout, "old", stb);
9034 ui_out_text (uiout, "\nNew value = ");
9035 watchpoint_value_print (w->val, stb->stream);
9036 ui_out_field_stream (uiout, "new", stb);
9037 ui_out_text (uiout, "\n");
9038 /* More than one watchpoint may have been triggered. */
9039 result = PRINT_UNKNOWN;
9042 case bp_read_watchpoint:
9043 if (ui_out_is_mi_like_p (uiout))
9046 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
9048 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
9049 ui_out_text (uiout, "\nValue = ");
9050 watchpoint_value_print (w->val, stb->stream);
9051 ui_out_field_stream (uiout, "value", stb);
9052 ui_out_text (uiout, "\n");
9053 result = PRINT_UNKNOWN;
9056 case bp_access_watchpoint:
9057 if (bs->old_val != NULL)
9059 annotate_watchpoint (b->number);
9060 if (ui_out_is_mi_like_p (uiout))
9063 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
9065 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
9066 ui_out_text (uiout, "\nOld value = ");
9067 watchpoint_value_print (bs->old_val, stb->stream);
9068 ui_out_field_stream (uiout, "old", stb);
9069 ui_out_text (uiout, "\nNew value = ");
9074 if (ui_out_is_mi_like_p (uiout))
9077 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
9078 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
9079 ui_out_text (uiout, "\nValue = ");
9081 watchpoint_value_print (w->val, stb->stream);
9082 ui_out_field_stream (uiout, "new", stb);
9083 ui_out_text (uiout, "\n");
9084 result = PRINT_UNKNOWN;
9087 result = PRINT_UNKNOWN;
9090 do_cleanups (old_chain);
9094 /* Implement the "print_mention" breakpoint_ops method for hardware
9098 print_mention_watchpoint (struct breakpoint *b)
9100 struct cleanup *ui_out_chain;
9101 struct watchpoint *w = (struct watchpoint *) b;
9102 struct ui_out *uiout = current_uiout;
9107 ui_out_text (uiout, "Watchpoint ");
9108 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
9110 case bp_hardware_watchpoint:
9111 ui_out_text (uiout, "Hardware watchpoint ");
9112 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
9114 case bp_read_watchpoint:
9115 ui_out_text (uiout, "Hardware read watchpoint ");
9116 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
9118 case bp_access_watchpoint:
9119 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
9120 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
9123 internal_error (__FILE__, __LINE__,
9124 _("Invalid hardware watchpoint type."));
9127 ui_out_field_int (uiout, "number", b->number);
9128 ui_out_text (uiout, ": ");
9129 ui_out_field_string (uiout, "exp", w->exp_string);
9130 do_cleanups (ui_out_chain);
9133 /* Implement the "print_recreate" breakpoint_ops method for
9137 print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp)
9139 struct watchpoint *w = (struct watchpoint *) b;
9144 case bp_hardware_watchpoint:
9145 fprintf_unfiltered (fp, "watch");
9147 case bp_read_watchpoint:
9148 fprintf_unfiltered (fp, "rwatch");
9150 case bp_access_watchpoint:
9151 fprintf_unfiltered (fp, "awatch");
9154 internal_error (__FILE__, __LINE__,
9155 _("Invalid watchpoint type."));
9158 fprintf_unfiltered (fp, " %s", w->exp_string);
9159 print_recreate_thread (b, fp);
9162 /* The breakpoint_ops structure to be used in hardware watchpoints. */
9164 static struct breakpoint_ops watchpoint_breakpoint_ops;
9166 /* Implement the "insert" breakpoint_ops method for
9167 masked hardware watchpoints. */
9170 insert_masked_watchpoint (struct bp_location *bl)
9172 struct watchpoint *w = (struct watchpoint *) bl->owner;
9174 return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask,
9175 bl->watchpoint_type);
9178 /* Implement the "remove" breakpoint_ops method for
9179 masked hardware watchpoints. */
9182 remove_masked_watchpoint (struct bp_location *bl)
9184 struct watchpoint *w = (struct watchpoint *) bl->owner;
9186 return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask,
9187 bl->watchpoint_type);
9190 /* Implement the "resources_needed" breakpoint_ops method for
9191 masked hardware watchpoints. */
9194 resources_needed_masked_watchpoint (const struct bp_location *bl)
9196 struct watchpoint *w = (struct watchpoint *) bl->owner;
9198 return target_masked_watch_num_registers (bl->address, w->hw_wp_mask);
9201 /* Implement the "works_in_software_mode" breakpoint_ops method for
9202 masked hardware watchpoints. */
9205 works_in_software_mode_masked_watchpoint (const struct breakpoint *b)
9210 /* Implement the "print_it" breakpoint_ops method for
9211 masked hardware watchpoints. */
9213 static enum print_stop_action
9214 print_it_masked_watchpoint (bpstat bs)
9216 struct breakpoint *b = bs->breakpoint_at;
9217 struct ui_out *uiout = current_uiout;
9219 /* Masked watchpoints have only one location. */
9220 gdb_assert (b->loc && b->loc->next == NULL);
9224 case bp_hardware_watchpoint:
9225 annotate_watchpoint (b->number);
9226 if (ui_out_is_mi_like_p (uiout))
9229 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
9232 case bp_read_watchpoint:
9233 if (ui_out_is_mi_like_p (uiout))
9236 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
9239 case bp_access_watchpoint:
9240 if (ui_out_is_mi_like_p (uiout))
9243 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
9246 internal_error (__FILE__, __LINE__,
9247 _("Invalid hardware watchpoint type."));
9251 ui_out_text (uiout, _("\n\
9252 Check the underlying instruction at PC for the memory\n\
9253 address and value which triggered this watchpoint.\n"));
9254 ui_out_text (uiout, "\n");
9256 /* More than one watchpoint may have been triggered. */
9257 return PRINT_UNKNOWN;
9260 /* Implement the "print_one_detail" breakpoint_ops method for
9261 masked hardware watchpoints. */
9264 print_one_detail_masked_watchpoint (const struct breakpoint *b,
9265 struct ui_out *uiout)
9267 struct watchpoint *w = (struct watchpoint *) b;
9269 /* Masked watchpoints have only one location. */
9270 gdb_assert (b->loc && b->loc->next == NULL);
9272 ui_out_text (uiout, "\tmask ");
9273 ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask);
9274 ui_out_text (uiout, "\n");
9277 /* Implement the "print_mention" breakpoint_ops method for
9278 masked hardware watchpoints. */
9281 print_mention_masked_watchpoint (struct breakpoint *b)
9283 struct watchpoint *w = (struct watchpoint *) b;
9284 struct ui_out *uiout = current_uiout;
9285 struct cleanup *ui_out_chain;
9289 case bp_hardware_watchpoint:
9290 ui_out_text (uiout, "Masked hardware watchpoint ");
9291 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
9293 case bp_read_watchpoint:
9294 ui_out_text (uiout, "Masked hardware read watchpoint ");
9295 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
9297 case bp_access_watchpoint:
9298 ui_out_text (uiout, "Masked hardware access (read/write) watchpoint ");
9299 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
9302 internal_error (__FILE__, __LINE__,
9303 _("Invalid hardware watchpoint type."));
9306 ui_out_field_int (uiout, "number", b->number);
9307 ui_out_text (uiout, ": ");
9308 ui_out_field_string (uiout, "exp", w->exp_string);
9309 do_cleanups (ui_out_chain);
9312 /* Implement the "print_recreate" breakpoint_ops method for
9313 masked hardware watchpoints. */
9316 print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp)
9318 struct watchpoint *w = (struct watchpoint *) b;
9323 case bp_hardware_watchpoint:
9324 fprintf_unfiltered (fp, "watch");
9326 case bp_read_watchpoint:
9327 fprintf_unfiltered (fp, "rwatch");
9329 case bp_access_watchpoint:
9330 fprintf_unfiltered (fp, "awatch");
9333 internal_error (__FILE__, __LINE__,
9334 _("Invalid hardware watchpoint type."));
9337 sprintf_vma (tmp, w->hw_wp_mask);
9338 fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp);
9339 print_recreate_thread (b, fp);
9342 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
9344 static struct breakpoint_ops masked_watchpoint_breakpoint_ops;
9346 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
9349 is_masked_watchpoint (const struct breakpoint *b)
9351 return b->ops == &masked_watchpoint_breakpoint_ops;
9354 /* accessflag: hw_write: watch write,
9355 hw_read: watch read,
9356 hw_access: watch access (read or write) */
9358 watch_command_1 (char *arg, int accessflag, int from_tty,
9359 int just_location, int internal)
9361 volatile struct gdb_exception e;
9362 struct breakpoint *b, *scope_breakpoint = NULL;
9363 struct expression *exp;
9364 struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL;
9365 struct value *val, *mark, *result;
9366 struct frame_info *frame;
9367 char *exp_start = NULL;
9368 char *exp_end = NULL;
9369 char *tok, *end_tok;
9371 char *cond_start = NULL;
9372 char *cond_end = NULL;
9373 enum bptype bp_type;
9376 /* Flag to indicate whether we are going to use masks for
9377 the hardware watchpoint. */
9380 struct watchpoint *w;
9382 /* Make sure that we actually have parameters to parse. */
9383 if (arg != NULL && arg[0] != '\0')
9387 /* Look for "parameter value" pairs at the end
9388 of the arguments string. */
9389 for (tok = arg + strlen (arg) - 1; tok > arg; tok--)
9391 /* Skip whitespace at the end of the argument list. */
9392 while (tok > arg && (*tok == ' ' || *tok == '\t'))
9395 /* Find the beginning of the last token.
9396 This is the value of the parameter. */
9397 while (tok > arg && (*tok != ' ' && *tok != '\t'))
9399 value_start = tok + 1;
9401 /* Skip whitespace. */
9402 while (tok > arg && (*tok == ' ' || *tok == '\t'))
9407 /* Find the beginning of the second to last token.
9408 This is the parameter itself. */
9409 while (tok > arg && (*tok != ' ' && *tok != '\t'))
9412 toklen = end_tok - tok + 1;
9414 if (toklen == 6 && !strncmp (tok, "thread", 6))
9416 /* At this point we've found a "thread" token, which means
9417 the user is trying to set a watchpoint that triggers
9418 only in a specific thread. */
9422 error(_("You can specify only one thread."));
9424 /* Extract the thread ID from the next token. */
9425 thread = strtol (value_start, &endp, 0);
9427 /* Check if the user provided a valid numeric value for the
9429 if (*endp != ' ' && *endp != '\t' && *endp != '\0')
9430 error (_("Invalid thread ID specification %s."), value_start);
9432 /* Check if the thread actually exists. */
9433 if (!valid_thread_id (thread))
9434 error (_("Unknown thread %d."), thread);
9436 else if (toklen == 4 && !strncmp (tok, "mask", 4))
9438 /* We've found a "mask" token, which means the user wants to
9439 create a hardware watchpoint that is going to have the mask
9441 struct value *mask_value, *mark;
9444 error(_("You can specify only one mask."));
9446 use_mask = just_location = 1;
9448 mark = value_mark ();
9449 mask_value = parse_to_comma_and_eval (&value_start);
9450 mask = value_as_address (mask_value);
9451 value_free_to_mark (mark);
9454 /* We didn't recognize what we found. We should stop here. */
9457 /* Truncate the string and get rid of the "parameter value" pair before
9458 the arguments string is parsed by the parse_exp_1 function. */
9463 /* Parse the rest of the arguments. */
9464 innermost_block = NULL;
9466 exp = parse_exp_1 (&arg, 0, 0);
9468 /* Remove trailing whitespace from the expression before saving it.
9469 This makes the eventual display of the expression string a bit
9471 while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t'))
9474 /* Checking if the expression is not constant. */
9475 if (watchpoint_exp_is_const (exp))
9479 len = exp_end - exp_start;
9480 while (len > 0 && isspace (exp_start[len - 1]))
9482 error (_("Cannot watch constant value `%.*s'."), len, exp_start);
9485 exp_valid_block = innermost_block;
9486 mark = value_mark ();
9487 fetch_subexp_value (exp, &pc, &val, &result, NULL);
9493 exp_valid_block = NULL;
9494 val = value_addr (result);
9495 release_value (val);
9496 value_free_to_mark (mark);
9500 ret = target_masked_watch_num_registers (value_as_address (val),
9503 error (_("This target does not support masked watchpoints."));
9505 error (_("Invalid mask or memory region."));
9508 else if (val != NULL)
9509 release_value (val);
9511 tok = skip_spaces (arg);
9512 end_tok = skip_to_space (tok);
9514 toklen = end_tok - tok;
9515 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
9517 struct expression *cond;
9519 innermost_block = NULL;
9520 tok = cond_start = end_tok + 1;
9521 cond = parse_exp_1 (&tok, 0, 0);
9523 /* The watchpoint expression may not be local, but the condition
9524 may still be. E.g.: `watch global if local > 0'. */
9525 cond_exp_valid_block = innermost_block;
9531 error (_("Junk at end of command."));
9533 if (accessflag == hw_read)
9534 bp_type = bp_read_watchpoint;
9535 else if (accessflag == hw_access)
9536 bp_type = bp_access_watchpoint;
9538 bp_type = bp_hardware_watchpoint;
9540 frame = block_innermost_frame (exp_valid_block);
9542 /* If the expression is "local", then set up a "watchpoint scope"
9543 breakpoint at the point where we've left the scope of the watchpoint
9544 expression. Create the scope breakpoint before the watchpoint, so
9545 that we will encounter it first in bpstat_stop_status. */
9546 if (exp_valid_block && frame)
9548 if (frame_id_p (frame_unwind_caller_id (frame)))
9551 = create_internal_breakpoint (frame_unwind_caller_arch (frame),
9552 frame_unwind_caller_pc (frame),
9553 bp_watchpoint_scope,
9554 &momentary_breakpoint_ops);
9556 scope_breakpoint->enable_state = bp_enabled;
9558 /* Automatically delete the breakpoint when it hits. */
9559 scope_breakpoint->disposition = disp_del;
9561 /* Only break in the proper frame (help with recursion). */
9562 scope_breakpoint->frame_id = frame_unwind_caller_id (frame);
9564 /* Set the address at which we will stop. */
9565 scope_breakpoint->loc->gdbarch
9566 = frame_unwind_caller_arch (frame);
9567 scope_breakpoint->loc->requested_address
9568 = frame_unwind_caller_pc (frame);
9569 scope_breakpoint->loc->address
9570 = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch,
9571 scope_breakpoint->loc->requested_address,
9572 scope_breakpoint->type);
9576 /* Now set up the breakpoint. */
9578 w = XCNEW (struct watchpoint);
9581 init_raw_breakpoint_without_location (b, NULL, bp_type,
9582 &masked_watchpoint_breakpoint_ops);
9584 init_raw_breakpoint_without_location (b, NULL, bp_type,
9585 &watchpoint_breakpoint_ops);
9587 b->disposition = disp_donttouch;
9588 b->pspace = current_program_space;
9590 w->exp_valid_block = exp_valid_block;
9591 w->cond_exp_valid_block = cond_exp_valid_block;
9594 struct type *t = value_type (val);
9595 CORE_ADDR addr = value_as_address (val);
9598 t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t)));
9599 name = type_to_string (t);
9601 w->exp_string_reparse = xstrprintf ("* (%s *) %s", name,
9602 core_addr_to_string (addr));
9605 w->exp_string = xstrprintf ("-location %.*s",
9606 (int) (exp_end - exp_start), exp_start);
9608 /* The above expression is in C. */
9609 b->language = language_c;
9612 w->exp_string = savestring (exp_start, exp_end - exp_start);
9616 w->hw_wp_mask = mask;
9625 b->cond_string = savestring (cond_start, cond_end - cond_start);
9631 w->watchpoint_frame = get_frame_id (frame);
9632 w->watchpoint_thread = inferior_ptid;
9636 w->watchpoint_frame = null_frame_id;
9637 w->watchpoint_thread = null_ptid;
9640 if (scope_breakpoint != NULL)
9642 /* The scope breakpoint is related to the watchpoint. We will
9643 need to act on them together. */
9644 b->related_breakpoint = scope_breakpoint;
9645 scope_breakpoint->related_breakpoint = b;
9649 value_free_to_mark (mark);
9651 TRY_CATCH (e, RETURN_MASK_ALL)
9653 /* Finally update the new watchpoint. This creates the locations
9654 that should be inserted. */
9655 update_watchpoint (w, 1);
9659 delete_breakpoint (b);
9660 throw_exception (e);
9663 install_breakpoint (internal, b, 1);
9666 /* Return count of debug registers needed to watch the given expression.
9667 If the watchpoint cannot be handled in hardware return zero. */
9670 can_use_hardware_watchpoint (struct value *v)
9672 int found_memory_cnt = 0;
9673 struct value *head = v;
9675 /* Did the user specifically forbid us to use hardware watchpoints? */
9676 if (!can_use_hw_watchpoints)
9679 /* Make sure that the value of the expression depends only upon
9680 memory contents, and values computed from them within GDB. If we
9681 find any register references or function calls, we can't use a
9682 hardware watchpoint.
9684 The idea here is that evaluating an expression generates a series
9685 of values, one holding the value of every subexpression. (The
9686 expression a*b+c has five subexpressions: a, b, a*b, c, and
9687 a*b+c.) GDB's values hold almost enough information to establish
9688 the criteria given above --- they identify memory lvalues,
9689 register lvalues, computed values, etcetera. So we can evaluate
9690 the expression, and then scan the chain of values that leaves
9691 behind to decide whether we can detect any possible change to the
9692 expression's final value using only hardware watchpoints.
9694 However, I don't think that the values returned by inferior
9695 function calls are special in any way. So this function may not
9696 notice that an expression involving an inferior function call
9697 can't be watched with hardware watchpoints. FIXME. */
9698 for (; v; v = value_next (v))
9700 if (VALUE_LVAL (v) == lval_memory)
9702 if (v != head && value_lazy (v))
9703 /* A lazy memory lvalue in the chain is one that GDB never
9704 needed to fetch; we either just used its address (e.g.,
9705 `a' in `a.b') or we never needed it at all (e.g., `a'
9706 in `a,b'). This doesn't apply to HEAD; if that is
9707 lazy then it was not readable, but watch it anyway. */
9711 /* Ahh, memory we actually used! Check if we can cover
9712 it with hardware watchpoints. */
9713 struct type *vtype = check_typedef (value_type (v));
9715 /* We only watch structs and arrays if user asked for it
9716 explicitly, never if they just happen to appear in a
9717 middle of some value chain. */
9719 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
9720 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
9722 CORE_ADDR vaddr = value_address (v);
9726 len = (target_exact_watchpoints
9727 && is_scalar_type_recursive (vtype))?
9728 1 : TYPE_LENGTH (value_type (v));
9730 num_regs = target_region_ok_for_hw_watchpoint (vaddr, len);
9734 found_memory_cnt += num_regs;
9738 else if (VALUE_LVAL (v) != not_lval
9739 && deprecated_value_modifiable (v) == 0)
9740 return 0; /* These are values from the history (e.g., $1). */
9741 else if (VALUE_LVAL (v) == lval_register)
9742 return 0; /* Cannot watch a register with a HW watchpoint. */
9745 /* The expression itself looks suitable for using a hardware
9746 watchpoint, but give the target machine a chance to reject it. */
9747 return found_memory_cnt;
9751 watch_command_wrapper (char *arg, int from_tty, int internal)
9753 watch_command_1 (arg, hw_write, from_tty, 0, internal);
9756 /* A helper function that looks for an argument at the start of a
9757 string. The argument must also either be at the end of the string,
9758 or be followed by whitespace. Returns 1 if it finds the argument,
9759 0 otherwise. If the argument is found, it updates *STR. */
9762 check_for_argument (char **str, char *arg, int arg_len)
9764 if (strncmp (*str, arg, arg_len) == 0
9765 && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len])))
9773 /* A helper function that looks for the "-location" argument and then
9774 calls watch_command_1. */
9777 watch_maybe_just_location (char *arg, int accessflag, int from_tty)
9779 int just_location = 0;
9782 && (check_for_argument (&arg, "-location", sizeof ("-location") - 1)
9783 || check_for_argument (&arg, "-l", sizeof ("-l") - 1)))
9785 arg = skip_spaces (arg);
9789 watch_command_1 (arg, accessflag, from_tty, just_location, 0);
9793 watch_command (char *arg, int from_tty)
9795 watch_maybe_just_location (arg, hw_write, from_tty);
9799 rwatch_command_wrapper (char *arg, int from_tty, int internal)
9801 watch_command_1 (arg, hw_read, from_tty, 0, internal);
9805 rwatch_command (char *arg, int from_tty)
9807 watch_maybe_just_location (arg, hw_read, from_tty);
9811 awatch_command_wrapper (char *arg, int from_tty, int internal)
9813 watch_command_1 (arg, hw_access, from_tty, 0, internal);
9817 awatch_command (char *arg, int from_tty)
9819 watch_maybe_just_location (arg, hw_access, from_tty);
9823 /* Helper routines for the until_command routine in infcmd.c. Here
9824 because it uses the mechanisms of breakpoints. */
9826 struct until_break_command_continuation_args
9828 struct breakpoint *breakpoint;
9829 struct breakpoint *breakpoint2;
9833 /* This function is called by fetch_inferior_event via the
9834 cmd_continuation pointer, to complete the until command. It takes
9835 care of cleaning up the temporary breakpoints set up by the until
9838 until_break_command_continuation (void *arg, int err)
9840 struct until_break_command_continuation_args *a = arg;
9842 delete_breakpoint (a->breakpoint);
9844 delete_breakpoint (a->breakpoint2);
9845 delete_longjmp_breakpoint (a->thread_num);
9849 until_break_command (char *arg, int from_tty, int anywhere)
9851 struct symtabs_and_lines sals;
9852 struct symtab_and_line sal;
9853 struct frame_info *frame = get_selected_frame (NULL);
9854 struct breakpoint *breakpoint;
9855 struct breakpoint *breakpoint2 = NULL;
9856 struct cleanup *old_chain;
9858 struct thread_info *tp;
9860 clear_proceed_status ();
9862 /* Set a breakpoint where the user wants it and at return from
9865 if (last_displayed_sal_is_valid ())
9866 sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE,
9867 get_last_displayed_symtab (),
9868 get_last_displayed_line ());
9870 sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE,
9871 (struct symtab *) NULL, 0);
9873 if (sals.nelts != 1)
9874 error (_("Couldn't get information on specified line."));
9877 xfree (sals.sals); /* malloc'd, so freed. */
9880 error (_("Junk at end of arguments."));
9882 resolve_sal_pc (&sal);
9885 /* If the user told us to continue until a specified location,
9886 we don't specify a frame at which we need to stop. */
9887 breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal,
9888 null_frame_id, bp_until);
9890 /* Otherwise, specify the selected frame, because we want to stop
9891 only at the very same frame. */
9892 breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal,
9893 get_stack_frame_id (frame),
9896 old_chain = make_cleanup_delete_breakpoint (breakpoint);
9898 tp = inferior_thread ();
9901 /* Keep within the current frame, or in frames called by the current
9904 if (frame_id_p (frame_unwind_caller_id (frame)))
9906 sal = find_pc_line (frame_unwind_caller_pc (frame), 0);
9907 sal.pc = frame_unwind_caller_pc (frame);
9908 breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame),
9910 frame_unwind_caller_id (frame),
9912 make_cleanup_delete_breakpoint (breakpoint2);
9914 set_longjmp_breakpoint (tp, frame_unwind_caller_id (frame));
9915 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
9918 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
9920 /* If we are running asynchronously, and proceed call above has
9921 actually managed to start the target, arrange for breakpoints to
9922 be deleted when the target stops. Otherwise, we're already
9923 stopped and delete breakpoints via cleanup chain. */
9925 if (target_can_async_p () && is_running (inferior_ptid))
9927 struct until_break_command_continuation_args *args;
9928 args = xmalloc (sizeof (*args));
9930 args->breakpoint = breakpoint;
9931 args->breakpoint2 = breakpoint2;
9932 args->thread_num = thread;
9934 discard_cleanups (old_chain);
9935 add_continuation (inferior_thread (),
9936 until_break_command_continuation, args,
9940 do_cleanups (old_chain);
9943 /* This function attempts to parse an optional "if <cond>" clause
9944 from the arg string. If one is not found, it returns NULL.
9946 Else, it returns a pointer to the condition string. (It does not
9947 attempt to evaluate the string against a particular block.) And,
9948 it updates arg to point to the first character following the parsed
9949 if clause in the arg string. */
9952 ep_parse_optional_if_clause (char **arg)
9956 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
9959 /* Skip the "if" keyword. */
9962 /* Skip any extra leading whitespace, and record the start of the
9963 condition string. */
9964 *arg = skip_spaces (*arg);
9967 /* Assume that the condition occupies the remainder of the arg
9969 (*arg) += strlen (cond_string);
9974 /* Commands to deal with catching events, such as signals, exceptions,
9975 process start/exit, etc. */
9979 catch_fork_temporary, catch_vfork_temporary,
9980 catch_fork_permanent, catch_vfork_permanent
9985 catch_fork_command_1 (char *arg, int from_tty,
9986 struct cmd_list_element *command)
9988 struct gdbarch *gdbarch = get_current_arch ();
9989 char *cond_string = NULL;
9990 catch_fork_kind fork_kind;
9993 fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command);
9994 tempflag = (fork_kind == catch_fork_temporary
9995 || fork_kind == catch_vfork_temporary);
9999 arg = skip_spaces (arg);
10001 /* The allowed syntax is:
10003 catch [v]fork if <cond>
10005 First, check if there's an if clause. */
10006 cond_string = ep_parse_optional_if_clause (&arg);
10008 if ((*arg != '\0') && !isspace (*arg))
10009 error (_("Junk at end of arguments."));
10011 /* If this target supports it, create a fork or vfork catchpoint
10012 and enable reporting of such events. */
10015 case catch_fork_temporary:
10016 case catch_fork_permanent:
10017 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
10018 &catch_fork_breakpoint_ops);
10020 case catch_vfork_temporary:
10021 case catch_vfork_permanent:
10022 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
10023 &catch_vfork_breakpoint_ops);
10026 error (_("unsupported or unknown fork kind; cannot catch it"));
10032 catch_exec_command_1 (char *arg, int from_tty,
10033 struct cmd_list_element *command)
10035 struct exec_catchpoint *c;
10036 struct gdbarch *gdbarch = get_current_arch ();
10038 char *cond_string = NULL;
10040 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
10044 arg = skip_spaces (arg);
10046 /* The allowed syntax is:
10048 catch exec if <cond>
10050 First, check if there's an if clause. */
10051 cond_string = ep_parse_optional_if_clause (&arg);
10053 if ((*arg != '\0') && !isspace (*arg))
10054 error (_("Junk at end of arguments."));
10056 c = XNEW (struct exec_catchpoint);
10057 init_catchpoint (&c->base, gdbarch, tempflag, cond_string,
10058 &catch_exec_breakpoint_ops);
10059 c->exec_pathname = NULL;
10061 install_breakpoint (0, &c->base, 1);
10064 static enum print_stop_action
10065 print_it_exception_catchpoint (bpstat bs)
10067 struct ui_out *uiout = current_uiout;
10068 struct breakpoint *b = bs->breakpoint_at;
10069 int bp_temp, bp_throw;
10071 annotate_catchpoint (b->number);
10073 bp_throw = strstr (b->addr_string, "throw") != NULL;
10074 if (b->loc->address != b->loc->requested_address)
10075 breakpoint_adjustment_warning (b->loc->requested_address,
10078 bp_temp = b->disposition == disp_del;
10079 ui_out_text (uiout,
10080 bp_temp ? "Temporary catchpoint "
10082 if (!ui_out_is_mi_like_p (uiout))
10083 ui_out_field_int (uiout, "bkptno", b->number);
10084 ui_out_text (uiout,
10085 bp_throw ? " (exception thrown), "
10086 : " (exception caught), ");
10087 if (ui_out_is_mi_like_p (uiout))
10089 ui_out_field_string (uiout, "reason",
10090 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
10091 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
10092 ui_out_field_int (uiout, "bkptno", b->number);
10094 return PRINT_SRC_AND_LOC;
10098 print_one_exception_catchpoint (struct breakpoint *b,
10099 struct bp_location **last_loc)
10101 struct value_print_options opts;
10102 struct ui_out *uiout = current_uiout;
10104 get_user_print_options (&opts);
10105 if (opts.addressprint)
10107 annotate_field (4);
10108 if (b->loc == NULL || b->loc->shlib_disabled)
10109 ui_out_field_string (uiout, "addr", "<PENDING>");
10111 ui_out_field_core_addr (uiout, "addr",
10112 b->loc->gdbarch, b->loc->address);
10114 annotate_field (5);
10116 *last_loc = b->loc;
10117 if (strstr (b->addr_string, "throw") != NULL)
10118 ui_out_field_string (uiout, "what", "exception throw");
10120 ui_out_field_string (uiout, "what", "exception catch");
10124 print_mention_exception_catchpoint (struct breakpoint *b)
10126 struct ui_out *uiout = current_uiout;
10130 bp_temp = b->disposition == disp_del;
10131 bp_throw = strstr (b->addr_string, "throw") != NULL;
10132 ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ")
10133 : _("Catchpoint "));
10134 ui_out_field_int (uiout, "bkptno", b->number);
10135 ui_out_text (uiout, bp_throw ? _(" (throw)")
10139 /* Implement the "print_recreate" breakpoint_ops method for throw and
10140 catch catchpoints. */
10143 print_recreate_exception_catchpoint (struct breakpoint *b,
10144 struct ui_file *fp)
10149 bp_temp = b->disposition == disp_del;
10150 bp_throw = strstr (b->addr_string, "throw") != NULL;
10151 fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch ");
10152 fprintf_unfiltered (fp, bp_throw ? "throw" : "catch");
10153 print_recreate_thread (b, fp);
10156 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops;
10159 handle_gnu_v3_exceptions (int tempflag, char *cond_string,
10160 enum exception_event_kind ex_event, int from_tty)
10162 char *trigger_func_name;
10164 if (ex_event == EX_EVENT_CATCH)
10165 trigger_func_name = "__cxa_begin_catch";
10167 trigger_func_name = "__cxa_throw";
10169 create_breakpoint (get_current_arch (),
10170 trigger_func_name, cond_string, -1,
10171 0 /* condition and thread are valid. */,
10172 tempflag, bp_breakpoint,
10174 AUTO_BOOLEAN_TRUE /* pending */,
10175 &gnu_v3_exception_catchpoint_ops, from_tty,
10182 /* Deal with "catch catch" and "catch throw" commands. */
10185 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
10186 int tempflag, int from_tty)
10188 char *cond_string = NULL;
10192 arg = skip_spaces (arg);
10194 cond_string = ep_parse_optional_if_clause (&arg);
10196 if ((*arg != '\0') && !isspace (*arg))
10197 error (_("Junk at end of arguments."));
10199 if (ex_event != EX_EVENT_THROW
10200 && ex_event != EX_EVENT_CATCH)
10201 error (_("Unsupported or unknown exception event; cannot catch it"));
10203 if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
10206 warning (_("Unsupported with this platform/compiler combination."));
10209 /* Implementation of "catch catch" command. */
10212 catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command)
10214 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
10216 catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty);
10219 /* Implementation of "catch throw" command. */
10222 catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command)
10224 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
10226 catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty);
10230 init_ada_exception_breakpoint (struct breakpoint *b,
10231 struct gdbarch *gdbarch,
10232 struct symtab_and_line sal,
10234 const struct breakpoint_ops *ops,
10240 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
10242 loc_gdbarch = gdbarch;
10244 describe_other_breakpoints (loc_gdbarch,
10245 sal.pspace, sal.pc, sal.section, -1);
10246 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
10247 version for exception catchpoints, because two catchpoints
10248 used for different exception names will use the same address.
10249 In this case, a "breakpoint ... also set at..." warning is
10250 unproductive. Besides, the warning phrasing is also a bit
10251 inappropriate, we should use the word catchpoint, and tell
10252 the user what type of catchpoint it is. The above is good
10253 enough for now, though. */
10256 init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops);
10258 b->enable_state = bp_enabled;
10259 b->disposition = tempflag ? disp_del : disp_donttouch;
10260 b->addr_string = addr_string;
10261 b->language = language_ada;
10264 /* Splits the argument using space as delimiter. Returns an xmalloc'd
10265 filter list, or NULL if no filtering is required. */
10267 catch_syscall_split_args (char *arg)
10269 VEC(int) *result = NULL;
10270 struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result);
10272 while (*arg != '\0')
10274 int i, syscall_number;
10276 char cur_name[128];
10279 /* Skip whitespace. */
10280 while (isspace (*arg))
10283 for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i)
10284 cur_name[i] = arg[i];
10285 cur_name[i] = '\0';
10288 /* Check if the user provided a syscall name or a number. */
10289 syscall_number = (int) strtol (cur_name, &endptr, 0);
10290 if (*endptr == '\0')
10291 get_syscall_by_number (syscall_number, &s);
10294 /* We have a name. Let's check if it's valid and convert it
10296 get_syscall_by_name (cur_name, &s);
10298 if (s.number == UNKNOWN_SYSCALL)
10299 /* Here we have to issue an error instead of a warning,
10300 because GDB cannot do anything useful if there's no
10301 syscall number to be caught. */
10302 error (_("Unknown syscall name '%s'."), cur_name);
10305 /* Ok, it's valid. */
10306 VEC_safe_push (int, result, s.number);
10309 discard_cleanups (cleanup);
10313 /* Implement the "catch syscall" command. */
10316 catch_syscall_command_1 (char *arg, int from_tty,
10317 struct cmd_list_element *command)
10322 struct gdbarch *gdbarch = get_current_arch ();
10324 /* Checking if the feature if supported. */
10325 if (gdbarch_get_syscall_number_p (gdbarch) == 0)
10326 error (_("The feature 'catch syscall' is not supported on \
10327 this architecture yet."));
10329 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
10331 arg = skip_spaces (arg);
10333 /* We need to do this first "dummy" translation in order
10334 to get the syscall XML file loaded or, most important,
10335 to display a warning to the user if there's no XML file
10336 for his/her architecture. */
10337 get_syscall_by_number (0, &s);
10339 /* The allowed syntax is:
10341 catch syscall <name | number> [<name | number> ... <name | number>]
10343 Let's check if there's a syscall name. */
10346 filter = catch_syscall_split_args (arg);
10350 create_syscall_event_catchpoint (tempflag, filter,
10351 &catch_syscall_breakpoint_ops);
10355 catch_command (char *arg, int from_tty)
10357 error (_("Catch requires an event name."));
10362 tcatch_command (char *arg, int from_tty)
10364 error (_("Catch requires an event name."));
10367 /* A qsort comparison function that sorts breakpoints in order. */
10370 compare_breakpoints (const void *a, const void *b)
10372 const breakpoint_p *ba = a;
10373 uintptr_t ua = (uintptr_t) *ba;
10374 const breakpoint_p *bb = b;
10375 uintptr_t ub = (uintptr_t) *bb;
10377 if ((*ba)->number < (*bb)->number)
10379 else if ((*ba)->number > (*bb)->number)
10382 /* Now sort by address, in case we see, e..g, two breakpoints with
10386 return ub > ub ? 1 : 0;
10389 /* Delete breakpoints by address or line. */
10392 clear_command (char *arg, int from_tty)
10394 struct breakpoint *b, *prev;
10395 VEC(breakpoint_p) *found = 0;
10398 struct symtabs_and_lines sals;
10399 struct symtab_and_line sal;
10401 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
10405 sals = decode_line_spec (arg, (DECODE_LINE_FUNFIRSTLINE
10406 | DECODE_LINE_LIST_MODE));
10411 sals.sals = (struct symtab_and_line *)
10412 xmalloc (sizeof (struct symtab_and_line));
10413 make_cleanup (xfree, sals.sals);
10414 init_sal (&sal); /* Initialize to zeroes. */
10416 /* Set sal's line, symtab, pc, and pspace to the values
10417 corresponding to the last call to print_frame_info. If the
10418 codepoint is not valid, this will set all the fields to 0. */
10419 get_last_displayed_sal (&sal);
10420 if (sal.symtab == 0)
10421 error (_("No source file specified."));
10423 sals.sals[0] = sal;
10429 /* We don't call resolve_sal_pc here. That's not as bad as it
10430 seems, because all existing breakpoints typically have both
10431 file/line and pc set. So, if clear is given file/line, we can
10432 match this to existing breakpoint without obtaining pc at all.
10434 We only support clearing given the address explicitly
10435 present in breakpoint table. Say, we've set breakpoint
10436 at file:line. There were several PC values for that file:line,
10437 due to optimization, all in one block.
10439 We've picked one PC value. If "clear" is issued with another
10440 PC corresponding to the same file:line, the breakpoint won't
10441 be cleared. We probably can still clear the breakpoint, but
10442 since the other PC value is never presented to user, user
10443 can only find it by guessing, and it does not seem important
10444 to support that. */
10446 /* For each line spec given, delete bps which correspond to it. Do
10447 it in two passes, solely to preserve the current behavior that
10448 from_tty is forced true if we delete more than one
10452 make_cleanup (VEC_cleanup (breakpoint_p), &found);
10453 for (i = 0; i < sals.nelts; i++)
10455 int is_abs, sal_name_len;
10457 /* If exact pc given, clear bpts at that pc.
10458 If line given (pc == 0), clear all bpts on specified line.
10459 If defaulting, clear all bpts on default line
10462 defaulting sal.pc != 0 tests to do
10467 1 0 <can't happen> */
10469 sal = sals.sals[i];
10470 is_abs = sal.symtab == NULL ? 1 : IS_ABSOLUTE_PATH (sal.symtab->filename);
10471 sal_name_len = is_abs ? 0 : strlen (sal.symtab->filename);
10473 /* Find all matching breakpoints and add them to 'found'. */
10474 ALL_BREAKPOINTS (b)
10477 /* Are we going to delete b? */
10478 if (b->type != bp_none && !is_watchpoint (b))
10480 struct bp_location *loc = b->loc;
10481 for (; loc; loc = loc->next)
10483 /* If the user specified file:line, don't allow a PC
10484 match. This matches historical gdb behavior. */
10485 int pc_match = (!sal.explicit_line
10487 && (loc->pspace == sal.pspace)
10488 && (loc->address == sal.pc)
10489 && (!section_is_overlay (loc->section)
10490 || loc->section == sal.section));
10491 int line_match = 0;
10493 if ((default_match || sal.explicit_line)
10494 && loc->source_file != NULL
10495 && sal.symtab != NULL
10496 && sal.pspace == loc->pspace
10497 && loc->line_number == sal.line)
10499 if (filename_cmp (loc->source_file,
10500 sal.symtab->filename) == 0)
10502 else if (!IS_ABSOLUTE_PATH (sal.symtab->filename)
10503 && compare_filenames_for_search (loc->source_file,
10504 sal.symtab->filename,
10509 if (pc_match || line_match)
10518 VEC_safe_push(breakpoint_p, found, b);
10522 /* Now go thru the 'found' chain and delete them. */
10523 if (VEC_empty(breakpoint_p, found))
10526 error (_("No breakpoint at %s."), arg);
10528 error (_("No breakpoint at this line."));
10531 /* Remove duplicates from the vec. */
10532 qsort (VEC_address (breakpoint_p, found),
10533 VEC_length (breakpoint_p, found),
10534 sizeof (breakpoint_p),
10535 compare_breakpoints);
10536 prev = VEC_index (breakpoint_p, found, 0);
10537 for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix)
10541 VEC_ordered_remove (breakpoint_p, found, ix);
10546 if (VEC_length(breakpoint_p, found) > 1)
10547 from_tty = 1; /* Always report if deleted more than one. */
10550 if (VEC_length(breakpoint_p, found) == 1)
10551 printf_unfiltered (_("Deleted breakpoint "));
10553 printf_unfiltered (_("Deleted breakpoints "));
10555 breakpoints_changed ();
10557 for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++)
10560 printf_unfiltered ("%d ", b->number);
10561 delete_breakpoint (b);
10564 putchar_unfiltered ('\n');
10566 do_cleanups (cleanups);
10569 /* Delete breakpoint in BS if they are `delete' breakpoints and
10570 all breakpoints that are marked for deletion, whether hit or not.
10571 This is called after any breakpoint is hit, or after errors. */
10574 breakpoint_auto_delete (bpstat bs)
10576 struct breakpoint *b, *b_tmp;
10578 for (; bs; bs = bs->next)
10579 if (bs->breakpoint_at
10580 && bs->breakpoint_at->disposition == disp_del
10582 delete_breakpoint (bs->breakpoint_at);
10584 ALL_BREAKPOINTS_SAFE (b, b_tmp)
10586 if (b->disposition == disp_del_at_next_stop)
10587 delete_breakpoint (b);
10591 /* A comparison function for bp_location AP and BP being interfaced to
10592 qsort. Sort elements primarily by their ADDRESS (no matter what
10593 does breakpoint_address_is_meaningful say for its OWNER),
10594 secondarily by ordering first bp_permanent OWNERed elements and
10595 terciarily just ensuring the array is sorted stable way despite
10596 qsort being an unstable algorithm. */
10599 bp_location_compare (const void *ap, const void *bp)
10601 struct bp_location *a = *(void **) ap;
10602 struct bp_location *b = *(void **) bp;
10603 /* A and B come from existing breakpoints having non-NULL OWNER. */
10604 int a_perm = a->owner->enable_state == bp_permanent;
10605 int b_perm = b->owner->enable_state == bp_permanent;
10607 if (a->address != b->address)
10608 return (a->address > b->address) - (a->address < b->address);
10610 /* Sort permanent breakpoints first. */
10611 if (a_perm != b_perm)
10612 return (a_perm < b_perm) - (a_perm > b_perm);
10614 /* Make the internal GDB representation stable across GDB runs
10615 where A and B memory inside GDB can differ. Breakpoint locations of
10616 the same type at the same address can be sorted in arbitrary order. */
10618 if (a->owner->number != b->owner->number)
10619 return ((a->owner->number > b->owner->number)
10620 - (a->owner->number < b->owner->number));
10622 return (a > b) - (a < b);
10625 /* Set bp_location_placed_address_before_address_max and
10626 bp_location_shadow_len_after_address_max according to the current
10627 content of the bp_location array. */
10630 bp_location_target_extensions_update (void)
10632 struct bp_location *bl, **blp_tmp;
10634 bp_location_placed_address_before_address_max = 0;
10635 bp_location_shadow_len_after_address_max = 0;
10637 ALL_BP_LOCATIONS (bl, blp_tmp)
10639 CORE_ADDR start, end, addr;
10641 if (!bp_location_has_shadow (bl))
10644 start = bl->target_info.placed_address;
10645 end = start + bl->target_info.shadow_len;
10647 gdb_assert (bl->address >= start);
10648 addr = bl->address - start;
10649 if (addr > bp_location_placed_address_before_address_max)
10650 bp_location_placed_address_before_address_max = addr;
10652 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
10654 gdb_assert (bl->address < end);
10655 addr = end - bl->address;
10656 if (addr > bp_location_shadow_len_after_address_max)
10657 bp_location_shadow_len_after_address_max = addr;
10661 /* Download tracepoint locations if they haven't been. */
10664 download_tracepoint_locations (void)
10666 struct bp_location *bl, **blp_tmp;
10667 struct cleanup *old_chain;
10669 if (!target_can_download_tracepoint ())
10672 old_chain = save_current_space_and_thread ();
10674 ALL_BP_LOCATIONS (bl, blp_tmp)
10676 struct tracepoint *t;
10678 if (!is_tracepoint (bl->owner))
10681 if ((bl->owner->type == bp_fast_tracepoint
10682 ? !may_insert_fast_tracepoints
10683 : !may_insert_tracepoints))
10686 /* In tracepoint, locations are _never_ duplicated, so
10687 should_be_inserted is equivalent to
10688 unduplicated_should_be_inserted. */
10689 if (!should_be_inserted (bl) || bl->inserted)
10692 switch_to_program_space_and_thread (bl->pspace);
10694 target_download_tracepoint (bl);
10697 t = (struct tracepoint *) bl->owner;
10698 t->number_on_target = bl->owner->number;
10701 do_cleanups (old_chain);
10704 /* Swap the insertion/duplication state between two locations. */
10707 swap_insertion (struct bp_location *left, struct bp_location *right)
10709 const int left_inserted = left->inserted;
10710 const int left_duplicate = left->duplicate;
10711 const struct bp_target_info left_target_info = left->target_info;
10713 /* Locations of tracepoints can never be duplicated. */
10714 if (is_tracepoint (left->owner))
10715 gdb_assert (!left->duplicate);
10716 if (is_tracepoint (right->owner))
10717 gdb_assert (!right->duplicate);
10719 left->inserted = right->inserted;
10720 left->duplicate = right->duplicate;
10721 left->target_info = right->target_info;
10722 right->inserted = left_inserted;
10723 right->duplicate = left_duplicate;
10724 right->target_info = left_target_info;
10727 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
10728 into the inferior, only remove already-inserted locations that no
10729 longer should be inserted. Functions that delete a breakpoint or
10730 breakpoints should pass false, so that deleting a breakpoint
10731 doesn't have the side effect of inserting the locations of other
10732 breakpoints that are marked not-inserted, but should_be_inserted
10733 returns true on them.
10735 This behaviour is useful is situations close to tear-down -- e.g.,
10736 after an exec, while the target still has execution, but breakpoint
10737 shadows of the previous executable image should *NOT* be restored
10738 to the new image; or before detaching, where the target still has
10739 execution and wants to delete breakpoints from GDB's lists, and all
10740 breakpoints had already been removed from the inferior. */
10743 update_global_location_list (int should_insert)
10745 struct breakpoint *b;
10746 struct bp_location **locp, *loc;
10747 struct cleanup *cleanups;
10749 /* Used in the duplicates detection below. When iterating over all
10750 bp_locations, points to the first bp_location of a given address.
10751 Breakpoints and watchpoints of different types are never
10752 duplicates of each other. Keep one pointer for each type of
10753 breakpoint/watchpoint, so we only need to loop over all locations
10755 struct bp_location *bp_loc_first; /* breakpoint */
10756 struct bp_location *wp_loc_first; /* hardware watchpoint */
10757 struct bp_location *awp_loc_first; /* access watchpoint */
10758 struct bp_location *rwp_loc_first; /* read watchpoint */
10760 /* Saved former bp_location array which we compare against the newly
10761 built bp_location from the current state of ALL_BREAKPOINTS. */
10762 struct bp_location **old_location, **old_locp;
10763 unsigned old_location_count;
10765 old_location = bp_location;
10766 old_location_count = bp_location_count;
10767 bp_location = NULL;
10768 bp_location_count = 0;
10769 cleanups = make_cleanup (xfree, old_location);
10771 ALL_BREAKPOINTS (b)
10772 for (loc = b->loc; loc; loc = loc->next)
10773 bp_location_count++;
10775 bp_location = xmalloc (sizeof (*bp_location) * bp_location_count);
10776 locp = bp_location;
10777 ALL_BREAKPOINTS (b)
10778 for (loc = b->loc; loc; loc = loc->next)
10780 qsort (bp_location, bp_location_count, sizeof (*bp_location),
10781 bp_location_compare);
10783 bp_location_target_extensions_update ();
10785 /* Identify bp_location instances that are no longer present in the
10786 new list, and therefore should be freed. Note that it's not
10787 necessary that those locations should be removed from inferior --
10788 if there's another location at the same address (previously
10789 marked as duplicate), we don't need to remove/insert the
10792 LOCP is kept in sync with OLD_LOCP, each pointing to the current
10793 and former bp_location array state respectively. */
10795 locp = bp_location;
10796 for (old_locp = old_location; old_locp < old_location + old_location_count;
10799 struct bp_location *old_loc = *old_locp;
10800 struct bp_location **loc2p;
10802 /* Tells if 'old_loc' is found among the new locations. If
10803 not, we have to free it. */
10804 int found_object = 0;
10805 /* Tells if the location should remain inserted in the target. */
10806 int keep_in_target = 0;
10809 /* Skip LOCP entries which will definitely never be needed.
10810 Stop either at or being the one matching OLD_LOC. */
10811 while (locp < bp_location + bp_location_count
10812 && (*locp)->address < old_loc->address)
10816 (loc2p < bp_location + bp_location_count
10817 && (*loc2p)->address == old_loc->address);
10820 if (*loc2p == old_loc)
10827 /* If this location is no longer present, and inserted, look if
10828 there's maybe a new location at the same address. If so,
10829 mark that one inserted, and don't remove this one. This is
10830 needed so that we don't have a time window where a breakpoint
10831 at certain location is not inserted. */
10833 if (old_loc->inserted)
10835 /* If the location is inserted now, we might have to remove
10838 if (found_object && should_be_inserted (old_loc))
10840 /* The location is still present in the location list,
10841 and still should be inserted. Don't do anything. */
10842 keep_in_target = 1;
10846 /* The location is either no longer present, or got
10847 disabled. See if there's another location at the
10848 same address, in which case we don't need to remove
10849 this one from the target. */
10851 /* OLD_LOC comes from existing struct breakpoint. */
10852 if (breakpoint_address_is_meaningful (old_loc->owner))
10855 (loc2p < bp_location + bp_location_count
10856 && (*loc2p)->address == old_loc->address);
10859 struct bp_location *loc2 = *loc2p;
10861 if (breakpoint_locations_match (loc2, old_loc))
10863 /* Read watchpoint locations are switched to
10864 access watchpoints, if the former are not
10865 supported, but the latter are. */
10866 if (is_hardware_watchpoint (old_loc->owner))
10868 gdb_assert (is_hardware_watchpoint (loc2->owner));
10869 loc2->watchpoint_type = old_loc->watchpoint_type;
10872 /* loc2 is a duplicated location. We need to check
10873 if it should be inserted in case it will be
10875 if (loc2 != old_loc
10876 && unduplicated_should_be_inserted (loc2))
10878 swap_insertion (old_loc, loc2);
10879 keep_in_target = 1;
10887 if (!keep_in_target)
10889 if (remove_breakpoint (old_loc, mark_uninserted))
10891 /* This is just about all we can do. We could keep
10892 this location on the global list, and try to
10893 remove it next time, but there's no particular
10894 reason why we will succeed next time.
10896 Note that at this point, old_loc->owner is still
10897 valid, as delete_breakpoint frees the breakpoint
10898 only after calling us. */
10899 printf_filtered (_("warning: Error removing "
10900 "breakpoint %d\n"),
10901 old_loc->owner->number);
10909 if (removed && non_stop
10910 && breakpoint_address_is_meaningful (old_loc->owner)
10911 && !is_hardware_watchpoint (old_loc->owner))
10913 /* This location was removed from the target. In
10914 non-stop mode, a race condition is possible where
10915 we've removed a breakpoint, but stop events for that
10916 breakpoint are already queued and will arrive later.
10917 We apply an heuristic to be able to distinguish such
10918 SIGTRAPs from other random SIGTRAPs: we keep this
10919 breakpoint location for a bit, and will retire it
10920 after we see some number of events. The theory here
10921 is that reporting of events should, "on the average",
10922 be fair, so after a while we'll see events from all
10923 threads that have anything of interest, and no longer
10924 need to keep this breakpoint location around. We
10925 don't hold locations forever so to reduce chances of
10926 mistaking a non-breakpoint SIGTRAP for a breakpoint
10929 The heuristic failing can be disastrous on
10930 decr_pc_after_break targets.
10932 On decr_pc_after_break targets, like e.g., x86-linux,
10933 if we fail to recognize a late breakpoint SIGTRAP,
10934 because events_till_retirement has reached 0 too
10935 soon, we'll fail to do the PC adjustment, and report
10936 a random SIGTRAP to the user. When the user resumes
10937 the inferior, it will most likely immediately crash
10938 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
10939 corrupted, because of being resumed e.g., in the
10940 middle of a multi-byte instruction, or skipped a
10941 one-byte instruction. This was actually seen happen
10942 on native x86-linux, and should be less rare on
10943 targets that do not support new thread events, like
10944 remote, due to the heuristic depending on
10947 Mistaking a random SIGTRAP for a breakpoint trap
10948 causes similar symptoms (PC adjustment applied when
10949 it shouldn't), but then again, playing with SIGTRAPs
10950 behind the debugger's back is asking for trouble.
10952 Since hardware watchpoint traps are always
10953 distinguishable from other traps, so we don't need to
10954 apply keep hardware watchpoint moribund locations
10955 around. We simply always ignore hardware watchpoint
10956 traps we can no longer explain. */
10958 old_loc->events_till_retirement = 3 * (thread_count () + 1);
10959 old_loc->owner = NULL;
10961 VEC_safe_push (bp_location_p, moribund_locations, old_loc);
10965 old_loc->owner = NULL;
10966 decref_bp_location (&old_loc);
10971 /* Rescan breakpoints at the same address and section, marking the
10972 first one as "first" and any others as "duplicates". This is so
10973 that the bpt instruction is only inserted once. If we have a
10974 permanent breakpoint at the same place as BPT, make that one the
10975 official one, and the rest as duplicates. Permanent breakpoints
10976 are sorted first for the same address.
10978 Do the same for hardware watchpoints, but also considering the
10979 watchpoint's type (regular/access/read) and length. */
10981 bp_loc_first = NULL;
10982 wp_loc_first = NULL;
10983 awp_loc_first = NULL;
10984 rwp_loc_first = NULL;
10985 ALL_BP_LOCATIONS (loc, locp)
10987 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
10989 struct bp_location **loc_first_p;
10992 if (!should_be_inserted (loc)
10993 || !breakpoint_address_is_meaningful (b)
10994 /* Don't detect duplicate for tracepoint locations because they are
10995 never duplicated. See the comments in field `duplicate' of
10996 `struct bp_location'. */
10997 || is_tracepoint (b))
11000 /* Permanent breakpoint should always be inserted. */
11001 if (b->enable_state == bp_permanent && ! loc->inserted)
11002 internal_error (__FILE__, __LINE__,
11003 _("allegedly permanent breakpoint is not "
11004 "actually inserted"));
11006 if (b->type == bp_hardware_watchpoint)
11007 loc_first_p = &wp_loc_first;
11008 else if (b->type == bp_read_watchpoint)
11009 loc_first_p = &rwp_loc_first;
11010 else if (b->type == bp_access_watchpoint)
11011 loc_first_p = &awp_loc_first;
11013 loc_first_p = &bp_loc_first;
11015 if (*loc_first_p == NULL
11016 || (overlay_debugging && loc->section != (*loc_first_p)->section)
11017 || !breakpoint_locations_match (loc, *loc_first_p))
11019 *loc_first_p = loc;
11020 loc->duplicate = 0;
11025 /* This and the above ensure the invariant that the first location
11026 is not duplicated, and is the inserted one.
11027 All following are marked as duplicated, and are not inserted. */
11029 swap_insertion (loc, *loc_first_p);
11030 loc->duplicate = 1;
11032 if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted
11033 && b->enable_state != bp_permanent)
11034 internal_error (__FILE__, __LINE__,
11035 _("another breakpoint was inserted on top of "
11036 "a permanent breakpoint"));
11039 if (breakpoints_always_inserted_mode () && should_insert
11040 && (have_live_inferiors ()
11041 || (gdbarch_has_global_breakpoints (target_gdbarch))))
11042 insert_breakpoint_locations ();
11045 download_tracepoint_locations ();
11047 do_cleanups (cleanups);
11051 breakpoint_retire_moribund (void)
11053 struct bp_location *loc;
11056 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
11057 if (--(loc->events_till_retirement) == 0)
11059 decref_bp_location (&loc);
11060 VEC_unordered_remove (bp_location_p, moribund_locations, ix);
11066 update_global_location_list_nothrow (int inserting)
11068 volatile struct gdb_exception e;
11070 TRY_CATCH (e, RETURN_MASK_ERROR)
11071 update_global_location_list (inserting);
11074 /* Clear BKP from a BPS. */
11077 bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt)
11081 for (bs = bps; bs; bs = bs->next)
11082 if (bs->breakpoint_at == bpt)
11084 bs->breakpoint_at = NULL;
11085 bs->old_val = NULL;
11086 /* bs->commands will be freed later. */
11090 /* Callback for iterate_over_threads. */
11092 bpstat_remove_breakpoint_callback (struct thread_info *th, void *data)
11094 struct breakpoint *bpt = data;
11096 bpstat_remove_bp_location (th->control.stop_bpstat, bpt);
11100 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
11104 say_where (struct breakpoint *b)
11106 struct ui_out *uiout = current_uiout;
11107 struct value_print_options opts;
11109 get_user_print_options (&opts);
11111 /* i18n: cagney/2005-02-11: Below needs to be merged into a
11113 if (b->loc == NULL)
11115 printf_filtered (_(" (%s) pending."), b->addr_string);
11119 if (opts.addressprint || b->loc->source_file == NULL)
11121 printf_filtered (" at ");
11122 fputs_filtered (paddress (b->loc->gdbarch, b->loc->address),
11125 if (b->loc->source_file)
11127 /* If there is a single location, we can print the location
11129 if (b->loc->next == NULL)
11130 printf_filtered (": file %s, line %d.",
11131 b->loc->source_file, b->loc->line_number);
11133 /* This is not ideal, but each location may have a
11134 different file name, and this at least reflects the
11135 real situation somewhat. */
11136 printf_filtered (": %s.", b->addr_string);
11141 struct bp_location *loc = b->loc;
11143 for (; loc; loc = loc->next)
11145 printf_filtered (" (%d locations)", n);
11150 /* Default bp_location_ops methods. */
11153 bp_location_dtor (struct bp_location *self)
11155 xfree (self->cond);
11156 xfree (self->function_name);
11157 xfree (self->source_file);
11160 static const struct bp_location_ops bp_location_ops =
11165 /* Default breakpoint_ops methods all breakpoint_ops ultimately
11169 base_breakpoint_dtor (struct breakpoint *self)
11171 decref_counted_command_line (&self->commands);
11172 xfree (self->cond_string);
11173 xfree (self->addr_string);
11174 xfree (self->filter);
11175 xfree (self->addr_string_range_end);
11178 static struct bp_location *
11179 base_breakpoint_allocate_location (struct breakpoint *self)
11181 struct bp_location *loc;
11183 loc = XNEW (struct bp_location);
11184 init_bp_location (loc, &bp_location_ops, self);
11189 base_breakpoint_re_set (struct breakpoint *b)
11191 /* Nothing to re-set. */
11194 #define internal_error_pure_virtual_called() \
11195 gdb_assert_not_reached ("pure virtual function called")
11198 base_breakpoint_insert_location (struct bp_location *bl)
11200 internal_error_pure_virtual_called ();
11204 base_breakpoint_remove_location (struct bp_location *bl)
11206 internal_error_pure_virtual_called ();
11210 base_breakpoint_breakpoint_hit (const struct bp_location *bl,
11211 struct address_space *aspace,
11213 const struct target_waitstatus *ws)
11215 internal_error_pure_virtual_called ();
11219 base_breakpoint_check_status (bpstat bs)
11224 /* A "works_in_software_mode" breakpoint_ops method that just internal
11228 base_breakpoint_works_in_software_mode (const struct breakpoint *b)
11230 internal_error_pure_virtual_called ();
11233 /* A "resources_needed" breakpoint_ops method that just internal
11237 base_breakpoint_resources_needed (const struct bp_location *bl)
11239 internal_error_pure_virtual_called ();
11242 static enum print_stop_action
11243 base_breakpoint_print_it (bpstat bs)
11245 internal_error_pure_virtual_called ();
11249 base_breakpoint_print_one_detail (const struct breakpoint *self,
11250 struct ui_out *uiout)
11256 base_breakpoint_print_mention (struct breakpoint *b)
11258 internal_error_pure_virtual_called ();
11262 base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp)
11264 internal_error_pure_virtual_called ();
11268 base_breakpoint_create_sals_from_address (char **arg,
11269 struct linespec_result *canonical,
11270 enum bptype type_wanted,
11274 internal_error_pure_virtual_called ();
11278 base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch,
11279 struct linespec_result *c,
11280 struct linespec_sals *lsal,
11282 enum bptype type_wanted,
11283 enum bpdisp disposition,
11285 int task, int ignore_count,
11286 const struct breakpoint_ops *o,
11287 int from_tty, int enabled,
11290 internal_error_pure_virtual_called ();
11294 base_breakpoint_decode_linespec (struct breakpoint *b, char **s,
11295 struct symtabs_and_lines *sals)
11297 internal_error_pure_virtual_called ();
11300 static struct breakpoint_ops base_breakpoint_ops =
11302 base_breakpoint_dtor,
11303 base_breakpoint_allocate_location,
11304 base_breakpoint_re_set,
11305 base_breakpoint_insert_location,
11306 base_breakpoint_remove_location,
11307 base_breakpoint_breakpoint_hit,
11308 base_breakpoint_check_status,
11309 base_breakpoint_resources_needed,
11310 base_breakpoint_works_in_software_mode,
11311 base_breakpoint_print_it,
11313 base_breakpoint_print_one_detail,
11314 base_breakpoint_print_mention,
11315 base_breakpoint_print_recreate,
11316 base_breakpoint_create_sals_from_address,
11317 base_breakpoint_create_breakpoints_sal,
11318 base_breakpoint_decode_linespec,
11321 /* Default breakpoint_ops methods. */
11324 bkpt_re_set (struct breakpoint *b)
11326 /* FIXME: is this still reachable? */
11327 if (b->addr_string == NULL)
11329 /* Anything without a string can't be re-set. */
11330 delete_breakpoint (b);
11334 breakpoint_re_set_default (b);
11338 bkpt_insert_location (struct bp_location *bl)
11340 if (bl->loc_type == bp_loc_hardware_breakpoint)
11341 return target_insert_hw_breakpoint (bl->gdbarch,
11344 return target_insert_breakpoint (bl->gdbarch,
11349 bkpt_remove_location (struct bp_location *bl)
11351 if (bl->loc_type == bp_loc_hardware_breakpoint)
11352 return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info);
11354 return target_remove_breakpoint (bl->gdbarch, &bl->target_info);
11358 bkpt_breakpoint_hit (const struct bp_location *bl,
11359 struct address_space *aspace, CORE_ADDR bp_addr,
11360 const struct target_waitstatus *ws)
11362 struct breakpoint *b = bl->owner;
11364 if (ws->kind != TARGET_WAITKIND_STOPPED
11365 || ws->value.sig != TARGET_SIGNAL_TRAP)
11368 if (!breakpoint_address_match (bl->pspace->aspace, bl->address,
11372 if (overlay_debugging /* unmapped overlay section */
11373 && section_is_overlay (bl->section)
11374 && !section_is_mapped (bl->section))
11381 bkpt_resources_needed (const struct bp_location *bl)
11383 gdb_assert (bl->owner->type == bp_hardware_breakpoint);
11388 static enum print_stop_action
11389 bkpt_print_it (bpstat bs)
11391 struct breakpoint *b;
11392 const struct bp_location *bl;
11394 struct ui_out *uiout = current_uiout;
11396 gdb_assert (bs->bp_location_at != NULL);
11398 bl = bs->bp_location_at;
11399 b = bs->breakpoint_at;
11401 bp_temp = b->disposition == disp_del;
11402 if (bl->address != bl->requested_address)
11403 breakpoint_adjustment_warning (bl->requested_address,
11406 annotate_breakpoint (b->number);
11408 ui_out_text (uiout, "\nTemporary breakpoint ");
11410 ui_out_text (uiout, "\nBreakpoint ");
11411 if (ui_out_is_mi_like_p (uiout))
11413 ui_out_field_string (uiout, "reason",
11414 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
11415 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
11417 ui_out_field_int (uiout, "bkptno", b->number);
11418 ui_out_text (uiout, ", ");
11420 return PRINT_SRC_AND_LOC;
11424 bkpt_print_mention (struct breakpoint *b)
11426 if (ui_out_is_mi_like_p (current_uiout))
11431 case bp_breakpoint:
11432 case bp_gnu_ifunc_resolver:
11433 if (b->disposition == disp_del)
11434 printf_filtered (_("Temporary breakpoint"));
11436 printf_filtered (_("Breakpoint"));
11437 printf_filtered (_(" %d"), b->number);
11438 if (b->type == bp_gnu_ifunc_resolver)
11439 printf_filtered (_(" at gnu-indirect-function resolver"));
11441 case bp_hardware_breakpoint:
11442 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
11450 bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp)
11452 if (tp->type == bp_breakpoint && tp->disposition == disp_del)
11453 fprintf_unfiltered (fp, "tbreak");
11454 else if (tp->type == bp_breakpoint)
11455 fprintf_unfiltered (fp, "break");
11456 else if (tp->type == bp_hardware_breakpoint
11457 && tp->disposition == disp_del)
11458 fprintf_unfiltered (fp, "thbreak");
11459 else if (tp->type == bp_hardware_breakpoint)
11460 fprintf_unfiltered (fp, "hbreak");
11462 internal_error (__FILE__, __LINE__,
11463 _("unhandled breakpoint type %d"), (int) tp->type);
11465 fprintf_unfiltered (fp, " %s", tp->addr_string);
11466 print_recreate_thread (tp, fp);
11470 bkpt_create_sals_from_address (char **arg,
11471 struct linespec_result *canonical,
11472 enum bptype type_wanted,
11473 char *addr_start, char **copy_arg)
11475 create_sals_from_address_default (arg, canonical, type_wanted,
11476 addr_start, copy_arg);
11480 bkpt_create_breakpoints_sal (struct gdbarch *gdbarch,
11481 struct linespec_result *canonical,
11482 struct linespec_sals *lsal,
11484 enum bptype type_wanted,
11485 enum bpdisp disposition,
11487 int task, int ignore_count,
11488 const struct breakpoint_ops *ops,
11489 int from_tty, int enabled,
11492 create_breakpoints_sal_default (gdbarch, canonical, lsal,
11493 cond_string, type_wanted,
11494 disposition, thread, task,
11495 ignore_count, ops, from_tty,
11496 enabled, internal);
11500 bkpt_decode_linespec (struct breakpoint *b, char **s,
11501 struct symtabs_and_lines *sals)
11503 decode_linespec_default (b, s, sals);
11506 /* Virtual table for internal breakpoints. */
11509 internal_bkpt_re_set (struct breakpoint *b)
11513 /* Delete overlay event and longjmp master breakpoints; they
11514 will be reset later by breakpoint_re_set. */
11515 case bp_overlay_event:
11516 case bp_longjmp_master:
11517 case bp_std_terminate_master:
11518 case bp_exception_master:
11519 delete_breakpoint (b);
11522 /* This breakpoint is special, it's set up when the inferior
11523 starts and we really don't want to touch it. */
11524 case bp_shlib_event:
11526 /* Like bp_shlib_event, this breakpoint type is special. Once
11527 it is set up, we do not want to touch it. */
11528 case bp_thread_event:
11534 internal_bkpt_check_status (bpstat bs)
11536 if (bs->breakpoint_at->type == bp_shlib_event)
11538 /* If requested, stop when the dynamic linker notifies GDB of
11539 events. This allows the user to get control and place
11540 breakpoints in initializer routines for dynamically loaded
11541 objects (among other things). */
11542 bs->stop = stop_on_solib_events;
11543 bs->print = stop_on_solib_events;
11549 static enum print_stop_action
11550 internal_bkpt_print_it (bpstat bs)
11552 struct ui_out *uiout = current_uiout;
11553 struct breakpoint *b;
11555 b = bs->breakpoint_at;
11559 case bp_shlib_event:
11560 /* Did we stop because the user set the stop_on_solib_events
11561 variable? (If so, we report this as a generic, "Stopped due
11562 to shlib event" message.) */
11563 print_solib_event (0);
11566 case bp_thread_event:
11567 /* Not sure how we will get here.
11568 GDB should not stop for these breakpoints. */
11569 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
11572 case bp_overlay_event:
11573 /* By analogy with the thread event, GDB should not stop for these. */
11574 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
11577 case bp_longjmp_master:
11578 /* These should never be enabled. */
11579 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
11582 case bp_std_terminate_master:
11583 /* These should never be enabled. */
11584 printf_filtered (_("std::terminate Master Breakpoint: "
11585 "gdb should not stop!\n"));
11588 case bp_exception_master:
11589 /* These should never be enabled. */
11590 printf_filtered (_("Exception Master Breakpoint: "
11591 "gdb should not stop!\n"));
11595 return PRINT_NOTHING;
11599 internal_bkpt_print_mention (struct breakpoint *b)
11601 /* Nothing to mention. These breakpoints are internal. */
11604 /* Virtual table for momentary breakpoints */
11607 momentary_bkpt_re_set (struct breakpoint *b)
11609 /* Keep temporary breakpoints, which can be encountered when we step
11610 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
11611 Otherwise these should have been blown away via the cleanup chain
11612 or by breakpoint_init_inferior when we rerun the executable. */
11616 momentary_bkpt_check_status (bpstat bs)
11618 /* Nothing. The point of these breakpoints is causing a stop. */
11621 static enum print_stop_action
11622 momentary_bkpt_print_it (bpstat bs)
11624 struct ui_out *uiout = current_uiout;
11626 if (ui_out_is_mi_like_p (uiout))
11628 struct breakpoint *b = bs->breakpoint_at;
11633 ui_out_field_string
11635 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED));
11639 ui_out_field_string
11641 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED));
11646 return PRINT_UNKNOWN;
11650 momentary_bkpt_print_mention (struct breakpoint *b)
11652 /* Nothing to mention. These breakpoints are internal. */
11655 /* The breakpoint_ops structure to be used in tracepoints. */
11658 tracepoint_re_set (struct breakpoint *b)
11660 breakpoint_re_set_default (b);
11664 tracepoint_breakpoint_hit (const struct bp_location *bl,
11665 struct address_space *aspace, CORE_ADDR bp_addr,
11666 const struct target_waitstatus *ws)
11668 /* By definition, the inferior does not report stops at
11674 tracepoint_print_one_detail (const struct breakpoint *self,
11675 struct ui_out *uiout)
11677 struct tracepoint *tp = (struct tracepoint *) self;
11678 if (tp->static_trace_marker_id)
11680 gdb_assert (self->type == bp_static_tracepoint);
11682 ui_out_text (uiout, "\tmarker id is ");
11683 ui_out_field_string (uiout, "static-tracepoint-marker-string-id",
11684 tp->static_trace_marker_id);
11685 ui_out_text (uiout, "\n");
11690 tracepoint_print_mention (struct breakpoint *b)
11692 if (ui_out_is_mi_like_p (current_uiout))
11697 case bp_tracepoint:
11698 printf_filtered (_("Tracepoint"));
11699 printf_filtered (_(" %d"), b->number);
11701 case bp_fast_tracepoint:
11702 printf_filtered (_("Fast tracepoint"));
11703 printf_filtered (_(" %d"), b->number);
11705 case bp_static_tracepoint:
11706 printf_filtered (_("Static tracepoint"));
11707 printf_filtered (_(" %d"), b->number);
11710 internal_error (__FILE__, __LINE__,
11711 _("unhandled tracepoint type %d"), (int) b->type);
11718 tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp)
11720 struct tracepoint *tp = (struct tracepoint *) self;
11722 if (self->type == bp_fast_tracepoint)
11723 fprintf_unfiltered (fp, "ftrace");
11724 if (self->type == bp_static_tracepoint)
11725 fprintf_unfiltered (fp, "strace");
11726 else if (self->type == bp_tracepoint)
11727 fprintf_unfiltered (fp, "trace");
11729 internal_error (__FILE__, __LINE__,
11730 _("unhandled tracepoint type %d"), (int) self->type);
11732 fprintf_unfiltered (fp, " %s", self->addr_string);
11733 print_recreate_thread (self, fp);
11735 if (tp->pass_count)
11736 fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count);
11740 tracepoint_create_sals_from_address (char **arg,
11741 struct linespec_result *canonical,
11742 enum bptype type_wanted,
11743 char *addr_start, char **copy_arg)
11745 create_sals_from_address_default (arg, canonical, type_wanted,
11746 addr_start, copy_arg);
11750 tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch,
11751 struct linespec_result *canonical,
11752 struct linespec_sals *lsal,
11754 enum bptype type_wanted,
11755 enum bpdisp disposition,
11757 int task, int ignore_count,
11758 const struct breakpoint_ops *ops,
11759 int from_tty, int enabled,
11762 create_breakpoints_sal_default (gdbarch, canonical, lsal,
11763 cond_string, type_wanted,
11764 disposition, thread, task,
11765 ignore_count, ops, from_tty,
11766 enabled, internal);
11770 tracepoint_decode_linespec (struct breakpoint *b, char **s,
11771 struct symtabs_and_lines *sals)
11773 decode_linespec_default (b, s, sals);
11776 struct breakpoint_ops tracepoint_breakpoint_ops;
11778 /* The breakpoint_ops structure to be used on static tracepoints with
11782 strace_marker_create_sals_from_address (char **arg,
11783 struct linespec_result *canonical,
11784 enum bptype type_wanted,
11785 char *addr_start, char **copy_arg)
11787 struct linespec_sals lsal;
11789 lsal.sals = decode_static_tracepoint_spec (arg);
11791 *copy_arg = savestring (addr_start, *arg - addr_start);
11793 canonical->addr_string = xstrdup (*copy_arg);
11794 lsal.canonical = xstrdup (*copy_arg);
11795 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
11799 strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch,
11800 struct linespec_result *canonical,
11801 struct linespec_sals *lsal,
11803 enum bptype type_wanted,
11804 enum bpdisp disposition,
11806 int task, int ignore_count,
11807 const struct breakpoint_ops *ops,
11808 int from_tty, int enabled,
11813 /* If the user is creating a static tracepoint by marker id
11814 (strace -m MARKER_ID), then store the sals index, so that
11815 breakpoint_re_set can try to match up which of the newly
11816 found markers corresponds to this one, and, don't try to
11817 expand multiple locations for each sal, given than SALS
11818 already should contain all sals for MARKER_ID. */
11820 for (i = 0; i < lsal->sals.nelts; ++i)
11822 struct symtabs_and_lines expanded;
11823 struct tracepoint *tp;
11824 struct cleanup *old_chain;
11827 expanded.nelts = 1;
11828 expanded.sals = &lsal->sals.sals[i];
11830 addr_string = xstrdup (canonical->addr_string);
11831 old_chain = make_cleanup (xfree, addr_string);
11833 tp = XCNEW (struct tracepoint);
11834 init_breakpoint_sal (&tp->base, gdbarch, expanded,
11836 cond_string, type_wanted, disposition,
11837 thread, task, ignore_count, ops,
11838 from_tty, enabled, internal,
11839 canonical->special_display);
11840 /* Given that its possible to have multiple markers with
11841 the same string id, if the user is creating a static
11842 tracepoint by marker id ("strace -m MARKER_ID"), then
11843 store the sals index, so that breakpoint_re_set can
11844 try to match up which of the newly found markers
11845 corresponds to this one */
11846 tp->static_trace_marker_id_idx = i;
11848 install_breakpoint (internal, &tp->base, 0);
11850 discard_cleanups (old_chain);
11855 strace_marker_decode_linespec (struct breakpoint *b, char **s,
11856 struct symtabs_and_lines *sals)
11858 struct tracepoint *tp = (struct tracepoint *) b;
11860 *sals = decode_static_tracepoint_spec (s);
11861 if (sals->nelts > tp->static_trace_marker_id_idx)
11863 sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx];
11867 error (_("marker %s not found"), tp->static_trace_marker_id);
11870 static struct breakpoint_ops strace_marker_breakpoint_ops;
11873 strace_marker_p (struct breakpoint *b)
11875 return b->ops == &strace_marker_breakpoint_ops;
11878 /* Delete a breakpoint and clean up all traces of it in the data
11882 delete_breakpoint (struct breakpoint *bpt)
11884 struct breakpoint *b;
11886 gdb_assert (bpt != NULL);
11888 /* Has this bp already been deleted? This can happen because
11889 multiple lists can hold pointers to bp's. bpstat lists are
11892 One example of this happening is a watchpoint's scope bp. When
11893 the scope bp triggers, we notice that the watchpoint is out of
11894 scope, and delete it. We also delete its scope bp. But the
11895 scope bp is marked "auto-deleting", and is already on a bpstat.
11896 That bpstat is then checked for auto-deleting bp's, which are
11899 A real solution to this problem might involve reference counts in
11900 bp's, and/or giving them pointers back to their referencing
11901 bpstat's, and teaching delete_breakpoint to only free a bp's
11902 storage when no more references were extent. A cheaper bandaid
11904 if (bpt->type == bp_none)
11907 /* At least avoid this stale reference until the reference counting
11908 of breakpoints gets resolved. */
11909 if (bpt->related_breakpoint != bpt)
11911 struct breakpoint *related;
11912 struct watchpoint *w;
11914 if (bpt->type == bp_watchpoint_scope)
11915 w = (struct watchpoint *) bpt->related_breakpoint;
11916 else if (bpt->related_breakpoint->type == bp_watchpoint_scope)
11917 w = (struct watchpoint *) bpt;
11921 watchpoint_del_at_next_stop (w);
11923 /* Unlink bpt from the bpt->related_breakpoint ring. */
11924 for (related = bpt; related->related_breakpoint != bpt;
11925 related = related->related_breakpoint);
11926 related->related_breakpoint = bpt->related_breakpoint;
11927 bpt->related_breakpoint = bpt;
11930 /* watch_command_1 creates a watchpoint but only sets its number if
11931 update_watchpoint succeeds in creating its bp_locations. If there's
11932 a problem in that process, we'll be asked to delete the half-created
11933 watchpoint. In that case, don't announce the deletion. */
11935 observer_notify_breakpoint_deleted (bpt);
11937 if (breakpoint_chain == bpt)
11938 breakpoint_chain = bpt->next;
11940 ALL_BREAKPOINTS (b)
11941 if (b->next == bpt)
11943 b->next = bpt->next;
11947 /* Be sure no bpstat's are pointing at the breakpoint after it's
11949 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
11950 in all threads for now. Note that we cannot just remove bpstats
11951 pointing at bpt from the stop_bpstat list entirely, as breakpoint
11952 commands are associated with the bpstat; if we remove it here,
11953 then the later call to bpstat_do_actions (&stop_bpstat); in
11954 event-top.c won't do anything, and temporary breakpoints with
11955 commands won't work. */
11957 iterate_over_threads (bpstat_remove_breakpoint_callback, bpt);
11959 /* Now that breakpoint is removed from breakpoint list, update the
11960 global location list. This will remove locations that used to
11961 belong to this breakpoint. Do this before freeing the breakpoint
11962 itself, since remove_breakpoint looks at location's owner. It
11963 might be better design to have location completely
11964 self-contained, but it's not the case now. */
11965 update_global_location_list (0);
11967 bpt->ops->dtor (bpt);
11968 /* On the chance that someone will soon try again to delete this
11969 same bp, we mark it as deleted before freeing its storage. */
11970 bpt->type = bp_none;
11975 do_delete_breakpoint_cleanup (void *b)
11977 delete_breakpoint (b);
11981 make_cleanup_delete_breakpoint (struct breakpoint *b)
11983 return make_cleanup (do_delete_breakpoint_cleanup, b);
11986 /* Iterator function to call a user-provided callback function once
11987 for each of B and its related breakpoints. */
11990 iterate_over_related_breakpoints (struct breakpoint *b,
11991 void (*function) (struct breakpoint *,
11995 struct breakpoint *related;
12000 struct breakpoint *next;
12002 /* FUNCTION may delete RELATED. */
12003 next = related->related_breakpoint;
12005 if (next == related)
12007 /* RELATED is the last ring entry. */
12008 function (related, data);
12010 /* FUNCTION may have deleted it, so we'd never reach back to
12011 B. There's nothing left to do anyway, so just break
12016 function (related, data);
12020 while (related != b);
12024 do_delete_breakpoint (struct breakpoint *b, void *ignore)
12026 delete_breakpoint (b);
12029 /* A callback for map_breakpoint_numbers that calls
12030 delete_breakpoint. */
12033 do_map_delete_breakpoint (struct breakpoint *b, void *ignore)
12035 iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL);
12039 delete_command (char *arg, int from_tty)
12041 struct breakpoint *b, *b_tmp;
12047 int breaks_to_delete = 0;
12049 /* Delete all breakpoints if no argument. Do not delete
12050 internal breakpoints, these have to be deleted with an
12051 explicit breakpoint number argument. */
12052 ALL_BREAKPOINTS (b)
12053 if (user_breakpoint_p (b))
12055 breaks_to_delete = 1;
12059 /* Ask user only if there are some breakpoints to delete. */
12061 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
12063 ALL_BREAKPOINTS_SAFE (b, b_tmp)
12064 if (user_breakpoint_p (b))
12065 delete_breakpoint (b);
12069 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
12073 all_locations_are_pending (struct bp_location *loc)
12075 for (; loc; loc = loc->next)
12076 if (!loc->shlib_disabled
12077 && !loc->pspace->executing_startup)
12082 /* Subroutine of update_breakpoint_locations to simplify it.
12083 Return non-zero if multiple fns in list LOC have the same name.
12084 Null names are ignored. */
12087 ambiguous_names_p (struct bp_location *loc)
12089 struct bp_location *l;
12090 htab_t htab = htab_create_alloc (13, htab_hash_string,
12091 (int (*) (const void *,
12092 const void *)) streq,
12093 NULL, xcalloc, xfree);
12095 for (l = loc; l != NULL; l = l->next)
12098 const char *name = l->function_name;
12100 /* Allow for some names to be NULL, ignore them. */
12104 slot = (const char **) htab_find_slot (htab, (const void *) name,
12106 /* NOTE: We can assume slot != NULL here because xcalloc never
12110 htab_delete (htab);
12116 htab_delete (htab);
12120 /* When symbols change, it probably means the sources changed as well,
12121 and it might mean the static tracepoint markers are no longer at
12122 the same address or line numbers they used to be at last we
12123 checked. Losing your static tracepoints whenever you rebuild is
12124 undesirable. This function tries to resync/rematch gdb static
12125 tracepoints with the markers on the target, for static tracepoints
12126 that have not been set by marker id. Static tracepoint that have
12127 been set by marker id are reset by marker id in breakpoint_re_set.
12130 1) For a tracepoint set at a specific address, look for a marker at
12131 the old PC. If one is found there, assume to be the same marker.
12132 If the name / string id of the marker found is different from the
12133 previous known name, assume that means the user renamed the marker
12134 in the sources, and output a warning.
12136 2) For a tracepoint set at a given line number, look for a marker
12137 at the new address of the old line number. If one is found there,
12138 assume to be the same marker. If the name / string id of the
12139 marker found is different from the previous known name, assume that
12140 means the user renamed the marker in the sources, and output a
12143 3) If a marker is no longer found at the same address or line, it
12144 may mean the marker no longer exists. But it may also just mean
12145 the code changed a bit. Maybe the user added a few lines of code
12146 that made the marker move up or down (in line number terms). Ask
12147 the target for info about the marker with the string id as we knew
12148 it. If found, update line number and address in the matching
12149 static tracepoint. This will get confused if there's more than one
12150 marker with the same ID (possible in UST, although unadvised
12151 precisely because it confuses tools). */
12153 static struct symtab_and_line
12154 update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal)
12156 struct tracepoint *tp = (struct tracepoint *) b;
12157 struct static_tracepoint_marker marker;
12163 find_line_pc (sal.symtab, sal.line, &pc);
12165 if (target_static_tracepoint_marker_at (pc, &marker))
12167 if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0)
12168 warning (_("static tracepoint %d changed probed marker from %s to %s"),
12170 tp->static_trace_marker_id, marker.str_id);
12172 xfree (tp->static_trace_marker_id);
12173 tp->static_trace_marker_id = xstrdup (marker.str_id);
12174 release_static_tracepoint_marker (&marker);
12179 /* Old marker wasn't found on target at lineno. Try looking it up
12181 if (!sal.explicit_pc
12183 && sal.symtab != NULL
12184 && tp->static_trace_marker_id != NULL)
12186 VEC(static_tracepoint_marker_p) *markers;
12189 = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id);
12191 if (!VEC_empty(static_tracepoint_marker_p, markers))
12193 struct symtab_and_line sal2;
12194 struct symbol *sym;
12195 struct static_tracepoint_marker *tpmarker;
12196 struct ui_out *uiout = current_uiout;
12198 tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0);
12200 xfree (tp->static_trace_marker_id);
12201 tp->static_trace_marker_id = xstrdup (tpmarker->str_id);
12203 warning (_("marker for static tracepoint %d (%s) not "
12204 "found at previous line number"),
12205 b->number, tp->static_trace_marker_id);
12209 sal2.pc = tpmarker->address;
12211 sal2 = find_pc_line (tpmarker->address, 0);
12212 sym = find_pc_sect_function (tpmarker->address, NULL);
12213 ui_out_text (uiout, "Now in ");
12216 ui_out_field_string (uiout, "func",
12217 SYMBOL_PRINT_NAME (sym));
12218 ui_out_text (uiout, " at ");
12220 ui_out_field_string (uiout, "file", sal2.symtab->filename);
12221 ui_out_text (uiout, ":");
12223 if (ui_out_is_mi_like_p (uiout))
12225 char *fullname = symtab_to_fullname (sal2.symtab);
12228 ui_out_field_string (uiout, "fullname", fullname);
12231 ui_out_field_int (uiout, "line", sal2.line);
12232 ui_out_text (uiout, "\n");
12234 b->loc->line_number = sal2.line;
12236 xfree (b->loc->source_file);
12238 b->loc->source_file = xstrdup (sal2.symtab->filename);
12240 b->loc->source_file = NULL;
12242 xfree (b->addr_string);
12243 b->addr_string = xstrprintf ("%s:%d",
12244 sal2.symtab->filename,
12245 b->loc->line_number);
12247 /* Might be nice to check if function changed, and warn if
12250 release_static_tracepoint_marker (tpmarker);
12256 /* Returns 1 iff locations A and B are sufficiently same that
12257 we don't need to report breakpoint as changed. */
12260 locations_are_equal (struct bp_location *a, struct bp_location *b)
12264 if (a->address != b->address)
12267 if (a->shlib_disabled != b->shlib_disabled)
12270 if (a->enabled != b->enabled)
12277 if ((a == NULL) != (b == NULL))
12283 /* Create new breakpoint locations for B (a hardware or software breakpoint)
12284 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
12285 a ranged breakpoint. */
12288 update_breakpoint_locations (struct breakpoint *b,
12289 struct symtabs_and_lines sals,
12290 struct symtabs_and_lines sals_end)
12293 struct bp_location *existing_locations = b->loc;
12295 if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1))
12297 /* Ranged breakpoints have only one start location and one end
12299 b->enable_state = bp_disabled;
12300 update_global_location_list (1);
12301 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
12302 "multiple locations found\n"),
12307 /* If there's no new locations, and all existing locations are
12308 pending, don't do anything. This optimizes the common case where
12309 all locations are in the same shared library, that was unloaded.
12310 We'd like to retain the location, so that when the library is
12311 loaded again, we don't loose the enabled/disabled status of the
12312 individual locations. */
12313 if (all_locations_are_pending (existing_locations) && sals.nelts == 0)
12318 for (i = 0; i < sals.nelts; ++i)
12320 struct bp_location *new_loc;
12322 switch_to_program_space_and_thread (sals.sals[i].pspace);
12324 new_loc = add_location_to_breakpoint (b, &(sals.sals[i]));
12326 /* Reparse conditions, they might contain references to the
12328 if (b->cond_string != NULL)
12331 volatile struct gdb_exception e;
12333 s = b->cond_string;
12334 TRY_CATCH (e, RETURN_MASK_ERROR)
12336 new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc),
12341 warning (_("failed to reevaluate condition "
12342 "for breakpoint %d: %s"),
12343 b->number, e.message);
12344 new_loc->enabled = 0;
12348 if (sals_end.nelts)
12350 CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]);
12352 new_loc->length = end - sals.sals[0].pc + 1;
12356 /* Update locations of permanent breakpoints. */
12357 if (b->enable_state == bp_permanent)
12358 make_breakpoint_permanent (b);
12360 /* If possible, carry over 'disable' status from existing
12363 struct bp_location *e = existing_locations;
12364 /* If there are multiple breakpoints with the same function name,
12365 e.g. for inline functions, comparing function names won't work.
12366 Instead compare pc addresses; this is just a heuristic as things
12367 may have moved, but in practice it gives the correct answer
12368 often enough until a better solution is found. */
12369 int have_ambiguous_names = ambiguous_names_p (b->loc);
12371 for (; e; e = e->next)
12373 if (!e->enabled && e->function_name)
12375 struct bp_location *l = b->loc;
12376 if (have_ambiguous_names)
12378 for (; l; l = l->next)
12379 if (breakpoint_locations_match (e, l))
12387 for (; l; l = l->next)
12388 if (l->function_name
12389 && strcmp (e->function_name, l->function_name) == 0)
12399 if (!locations_are_equal (existing_locations, b->loc))
12400 observer_notify_breakpoint_modified (b);
12402 update_global_location_list (1);
12405 /* Find the SaL locations corresponding to the given ADDR_STRING.
12406 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
12408 static struct symtabs_and_lines
12409 addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found)
12412 struct symtabs_and_lines sals = {0};
12413 volatile struct gdb_exception e;
12415 gdb_assert (b->ops != NULL);
12418 TRY_CATCH (e, RETURN_MASK_ERROR)
12420 b->ops->decode_linespec (b, &s, &sals);
12424 int not_found_and_ok = 0;
12425 /* For pending breakpoints, it's expected that parsing will
12426 fail until the right shared library is loaded. User has
12427 already told to create pending breakpoints and don't need
12428 extra messages. If breakpoint is in bp_shlib_disabled
12429 state, then user already saw the message about that
12430 breakpoint being disabled, and don't want to see more
12432 if (e.error == NOT_FOUND_ERROR
12433 && (b->condition_not_parsed
12434 || (b->loc && b->loc->shlib_disabled)
12435 || (b->loc && b->loc->pspace->executing_startup)
12436 || b->enable_state == bp_disabled))
12437 not_found_and_ok = 1;
12439 if (!not_found_and_ok)
12441 /* We surely don't want to warn about the same breakpoint
12442 10 times. One solution, implemented here, is disable
12443 the breakpoint on error. Another solution would be to
12444 have separate 'warning emitted' flag. Since this
12445 happens only when a binary has changed, I don't know
12446 which approach is better. */
12447 b->enable_state = bp_disabled;
12448 throw_exception (e);
12452 if (e.reason == 0 || e.error != NOT_FOUND_ERROR)
12456 for (i = 0; i < sals.nelts; ++i)
12457 resolve_sal_pc (&sals.sals[i]);
12458 if (b->condition_not_parsed && s && s[0])
12460 char *cond_string = 0;
12464 find_condition_and_thread (s, sals.sals[0].pc,
12465 &cond_string, &thread, &task);
12467 b->cond_string = cond_string;
12468 b->thread = thread;
12470 b->condition_not_parsed = 0;
12473 if (b->type == bp_static_tracepoint && !strace_marker_p (b))
12474 sals.sals[0] = update_static_tracepoint (b, sals.sals[0]);
12484 /* The default re_set method, for typical hardware or software
12485 breakpoints. Reevaluate the breakpoint and recreate its
12489 breakpoint_re_set_default (struct breakpoint *b)
12492 struct symtabs_and_lines sals, sals_end;
12493 struct symtabs_and_lines expanded = {0};
12494 struct symtabs_and_lines expanded_end = {0};
12496 sals = addr_string_to_sals (b, b->addr_string, &found);
12499 make_cleanup (xfree, sals.sals);
12503 if (b->addr_string_range_end)
12505 sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found);
12508 make_cleanup (xfree, sals_end.sals);
12509 expanded_end = sals_end;
12513 update_breakpoint_locations (b, expanded, expanded_end);
12516 /* Default method for creating SALs from an address string. It basically
12517 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
12520 create_sals_from_address_default (char **arg,
12521 struct linespec_result *canonical,
12522 enum bptype type_wanted,
12523 char *addr_start, char **copy_arg)
12525 parse_breakpoint_sals (arg, canonical);
12528 /* Call create_breakpoints_sal for the given arguments. This is the default
12529 function for the `create_breakpoints_sal' method of
12533 create_breakpoints_sal_default (struct gdbarch *gdbarch,
12534 struct linespec_result *canonical,
12535 struct linespec_sals *lsal,
12537 enum bptype type_wanted,
12538 enum bpdisp disposition,
12540 int task, int ignore_count,
12541 const struct breakpoint_ops *ops,
12542 int from_tty, int enabled,
12545 create_breakpoints_sal (gdbarch, canonical, cond_string,
12546 type_wanted, disposition,
12547 thread, task, ignore_count, ops, from_tty,
12548 enabled, internal);
12551 /* Decode the line represented by S by calling decode_line_full. This is the
12552 default function for the `decode_linespec' method of breakpoint_ops. */
12555 decode_linespec_default (struct breakpoint *b, char **s,
12556 struct symtabs_and_lines *sals)
12558 struct linespec_result canonical;
12560 init_linespec_result (&canonical);
12561 decode_line_full (s, DECODE_LINE_FUNFIRSTLINE,
12562 (struct symtab *) NULL, 0,
12563 &canonical, multiple_symbols_all,
12566 /* We should get 0 or 1 resulting SALs. */
12567 gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2);
12569 if (VEC_length (linespec_sals, canonical.sals) > 0)
12571 struct linespec_sals *lsal;
12573 lsal = VEC_index (linespec_sals, canonical.sals, 0);
12574 *sals = lsal->sals;
12575 /* Arrange it so the destructor does not free the
12577 lsal->sals.sals = NULL;
12580 destroy_linespec_result (&canonical);
12583 /* Prepare the global context for a re-set of breakpoint B. */
12585 static struct cleanup *
12586 prepare_re_set_context (struct breakpoint *b)
12588 struct cleanup *cleanups;
12590 input_radix = b->input_radix;
12591 cleanups = save_current_space_and_thread ();
12592 if (b->pspace != NULL)
12593 switch_to_program_space_and_thread (b->pspace);
12594 set_language (b->language);
12599 /* Reset a breakpoint given it's struct breakpoint * BINT.
12600 The value we return ends up being the return value from catch_errors.
12601 Unused in this case. */
12604 breakpoint_re_set_one (void *bint)
12606 /* Get past catch_errs. */
12607 struct breakpoint *b = (struct breakpoint *) bint;
12608 struct cleanup *cleanups;
12610 cleanups = prepare_re_set_context (b);
12611 b->ops->re_set (b);
12612 do_cleanups (cleanups);
12616 /* Re-set all breakpoints after symbols have been re-loaded. */
12618 breakpoint_re_set (void)
12620 struct breakpoint *b, *b_tmp;
12621 enum language save_language;
12622 int save_input_radix;
12623 struct cleanup *old_chain;
12625 save_language = current_language->la_language;
12626 save_input_radix = input_radix;
12627 old_chain = save_current_program_space ();
12629 ALL_BREAKPOINTS_SAFE (b, b_tmp)
12631 /* Format possible error msg. */
12632 char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
12634 struct cleanup *cleanups = make_cleanup (xfree, message);
12635 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
12636 do_cleanups (cleanups);
12638 set_language (save_language);
12639 input_radix = save_input_radix;
12641 jit_breakpoint_re_set ();
12643 do_cleanups (old_chain);
12645 create_overlay_event_breakpoint ();
12646 create_longjmp_master_breakpoint ();
12647 create_std_terminate_master_breakpoint ();
12648 create_exception_master_breakpoint ();
12650 /* While we're at it, reset the skip list too. */
12654 /* Reset the thread number of this breakpoint:
12656 - If the breakpoint is for all threads, leave it as-is.
12657 - Else, reset it to the current thread for inferior_ptid. */
12659 breakpoint_re_set_thread (struct breakpoint *b)
12661 if (b->thread != -1)
12663 if (in_thread_list (inferior_ptid))
12664 b->thread = pid_to_thread_id (inferior_ptid);
12666 /* We're being called after following a fork. The new fork is
12667 selected as current, and unless this was a vfork will have a
12668 different program space from the original thread. Reset that
12670 b->loc->pspace = current_program_space;
12674 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
12675 If from_tty is nonzero, it prints a message to that effect,
12676 which ends with a period (no newline). */
12679 set_ignore_count (int bptnum, int count, int from_tty)
12681 struct breakpoint *b;
12686 ALL_BREAKPOINTS (b)
12687 if (b->number == bptnum)
12689 if (is_tracepoint (b))
12691 if (from_tty && count != 0)
12692 printf_filtered (_("Ignore count ignored for tracepoint %d."),
12697 b->ignore_count = count;
12701 printf_filtered (_("Will stop next time "
12702 "breakpoint %d is reached."),
12704 else if (count == 1)
12705 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
12708 printf_filtered (_("Will ignore next %d "
12709 "crossings of breakpoint %d."),
12712 breakpoints_changed ();
12713 observer_notify_breakpoint_modified (b);
12717 error (_("No breakpoint number %d."), bptnum);
12720 /* Command to set ignore-count of breakpoint N to COUNT. */
12723 ignore_command (char *args, int from_tty)
12729 error_no_arg (_("a breakpoint number"));
12731 num = get_number (&p);
12733 error (_("bad breakpoint number: '%s'"), args);
12735 error (_("Second argument (specified ignore-count) is missing."));
12737 set_ignore_count (num,
12738 longest_to_int (value_as_long (parse_and_eval (p))),
12741 printf_filtered ("\n");
12744 /* Call FUNCTION on each of the breakpoints
12745 whose numbers are given in ARGS. */
12748 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *,
12753 struct breakpoint *b, *tmp;
12755 struct get_number_or_range_state state;
12758 error_no_arg (_("one or more breakpoint numbers"));
12760 init_number_or_range (&state, args);
12762 while (!state.finished)
12764 char *p = state.string;
12768 num = get_number_or_range (&state);
12771 warning (_("bad breakpoint number at or near '%s'"), p);
12775 ALL_BREAKPOINTS_SAFE (b, tmp)
12776 if (b->number == num)
12779 function (b, data);
12783 printf_unfiltered (_("No breakpoint number %d.\n"), num);
12788 static struct bp_location *
12789 find_location_by_number (char *number)
12791 char *dot = strchr (number, '.');
12795 struct breakpoint *b;
12796 struct bp_location *loc;
12801 bp_num = get_number (&p1);
12803 error (_("Bad breakpoint number '%s'"), number);
12805 ALL_BREAKPOINTS (b)
12806 if (b->number == bp_num)
12811 if (!b || b->number != bp_num)
12812 error (_("Bad breakpoint number '%s'"), number);
12815 loc_num = get_number (&p1);
12817 error (_("Bad breakpoint location number '%s'"), number);
12821 for (;loc_num && loc; --loc_num, loc = loc->next)
12824 error (_("Bad breakpoint location number '%s'"), dot+1);
12830 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
12831 If from_tty is nonzero, it prints a message to that effect,
12832 which ends with a period (no newline). */
12835 disable_breakpoint (struct breakpoint *bpt)
12837 /* Never disable a watchpoint scope breakpoint; we want to
12838 hit them when we leave scope so we can delete both the
12839 watchpoint and its scope breakpoint at that time. */
12840 if (bpt->type == bp_watchpoint_scope)
12843 /* You can't disable permanent breakpoints. */
12844 if (bpt->enable_state == bp_permanent)
12847 bpt->enable_state = bp_disabled;
12849 if (target_supports_enable_disable_tracepoint ()
12850 && current_trace_status ()->running && is_tracepoint (bpt))
12852 struct bp_location *location;
12854 for (location = bpt->loc; location; location = location->next)
12855 target_disable_tracepoint (location);
12858 update_global_location_list (0);
12860 observer_notify_breakpoint_modified (bpt);
12863 /* A callback for iterate_over_related_breakpoints. */
12866 do_disable_breakpoint (struct breakpoint *b, void *ignore)
12868 disable_breakpoint (b);
12871 /* A callback for map_breakpoint_numbers that calls
12872 disable_breakpoint. */
12875 do_map_disable_breakpoint (struct breakpoint *b, void *ignore)
12877 iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL);
12881 disable_command (char *args, int from_tty)
12885 struct breakpoint *bpt;
12887 ALL_BREAKPOINTS (bpt)
12888 if (user_breakpoint_p (bpt))
12889 disable_breakpoint (bpt);
12891 else if (strchr (args, '.'))
12893 struct bp_location *loc = find_location_by_number (args);
12897 if (target_supports_enable_disable_tracepoint ()
12898 && current_trace_status ()->running && loc->owner
12899 && is_tracepoint (loc->owner))
12900 target_disable_tracepoint (loc);
12902 update_global_location_list (0);
12905 map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL);
12909 enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition,
12912 int target_resources_ok;
12914 if (bpt->type == bp_hardware_breakpoint)
12917 i = hw_breakpoint_used_count ();
12918 target_resources_ok =
12919 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
12921 if (target_resources_ok == 0)
12922 error (_("No hardware breakpoint support in the target."));
12923 else if (target_resources_ok < 0)
12924 error (_("Hardware breakpoints used exceeds limit."));
12927 if (is_watchpoint (bpt))
12929 /* Initialize it just to avoid a GCC false warning. */
12930 enum enable_state orig_enable_state = 0;
12931 volatile struct gdb_exception e;
12933 TRY_CATCH (e, RETURN_MASK_ALL)
12935 struct watchpoint *w = (struct watchpoint *) bpt;
12937 orig_enable_state = bpt->enable_state;
12938 bpt->enable_state = bp_enabled;
12939 update_watchpoint (w, 1 /* reparse */);
12943 bpt->enable_state = orig_enable_state;
12944 exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
12950 if (bpt->enable_state != bp_permanent)
12951 bpt->enable_state = bp_enabled;
12953 if (target_supports_enable_disable_tracepoint ()
12954 && current_trace_status ()->running && is_tracepoint (bpt))
12956 struct bp_location *location;
12958 for (location = bpt->loc; location; location = location->next)
12959 target_enable_tracepoint (location);
12962 bpt->disposition = disposition;
12963 bpt->enable_count = count;
12964 update_global_location_list (1);
12965 breakpoints_changed ();
12967 observer_notify_breakpoint_modified (bpt);
12972 enable_breakpoint (struct breakpoint *bpt)
12974 enable_breakpoint_disp (bpt, bpt->disposition, 0);
12978 do_enable_breakpoint (struct breakpoint *bpt, void *arg)
12980 enable_breakpoint (bpt);
12983 /* A callback for map_breakpoint_numbers that calls
12984 enable_breakpoint. */
12987 do_map_enable_breakpoint (struct breakpoint *b, void *ignore)
12989 iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL);
12992 /* The enable command enables the specified breakpoints (or all defined
12993 breakpoints) so they once again become (or continue to be) effective
12994 in stopping the inferior. */
12997 enable_command (char *args, int from_tty)
13001 struct breakpoint *bpt;
13003 ALL_BREAKPOINTS (bpt)
13004 if (user_breakpoint_p (bpt))
13005 enable_breakpoint (bpt);
13007 else if (strchr (args, '.'))
13009 struct bp_location *loc = find_location_by_number (args);
13013 if (target_supports_enable_disable_tracepoint ()
13014 && current_trace_status ()->running && loc->owner
13015 && is_tracepoint (loc->owner))
13016 target_enable_tracepoint (loc);
13018 update_global_location_list (1);
13021 map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL);
13024 /* This struct packages up disposition data for application to multiple
13034 do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg)
13036 struct disp_data disp_data = *(struct disp_data *) arg;
13038 enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count);
13042 do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore)
13044 struct disp_data disp = { disp_disable, 1 };
13046 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
13050 enable_once_command (char *args, int from_tty)
13052 map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL);
13056 do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr)
13058 struct disp_data disp = { disp_disable, *(int *) countptr };
13060 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
13064 enable_count_command (char *args, int from_tty)
13066 int count = get_number (&args);
13068 map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count);
13072 do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore)
13074 struct disp_data disp = { disp_del, 1 };
13076 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
13080 enable_delete_command (char *args, int from_tty)
13082 map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL);
13086 set_breakpoint_cmd (char *args, int from_tty)
13091 show_breakpoint_cmd (char *args, int from_tty)
13095 /* Invalidate last known value of any hardware watchpoint if
13096 the memory which that value represents has been written to by
13100 invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len,
13101 const bfd_byte *data)
13103 struct breakpoint *bp;
13105 ALL_BREAKPOINTS (bp)
13106 if (bp->enable_state == bp_enabled
13107 && bp->type == bp_hardware_watchpoint)
13109 struct watchpoint *wp = (struct watchpoint *) bp;
13111 if (wp->val_valid && wp->val)
13113 struct bp_location *loc;
13115 for (loc = bp->loc; loc != NULL; loc = loc->next)
13116 if (loc->loc_type == bp_loc_hardware_watchpoint
13117 && loc->address + loc->length > addr
13118 && addr + len > loc->address)
13120 value_free (wp->val);
13128 /* Use the last displayed codepoint's values, or nothing
13129 if they aren't valid. */
13131 struct symtabs_and_lines
13132 decode_line_spec_1 (char *string, int flags)
13134 struct symtabs_and_lines sals;
13137 error (_("Empty line specification."));
13138 if (last_displayed_sal_is_valid ())
13139 sals = decode_line_1 (&string, flags,
13140 get_last_displayed_symtab (),
13141 get_last_displayed_line ());
13143 sals = decode_line_1 (&string, flags, (struct symtab *) NULL, 0);
13145 error (_("Junk at end of line specification: %s"), string);
13149 /* Create and insert a raw software breakpoint at PC. Return an
13150 identifier, which should be used to remove the breakpoint later.
13151 In general, places which call this should be using something on the
13152 breakpoint chain instead; this function should be eliminated
13156 deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch,
13157 struct address_space *aspace, CORE_ADDR pc)
13159 struct bp_target_info *bp_tgt;
13161 bp_tgt = XZALLOC (struct bp_target_info);
13163 bp_tgt->placed_address_space = aspace;
13164 bp_tgt->placed_address = pc;
13166 if (target_insert_breakpoint (gdbarch, bp_tgt) != 0)
13168 /* Could not insert the breakpoint. */
13176 /* Remove a breakpoint BP inserted by
13177 deprecated_insert_raw_breakpoint. */
13180 deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp)
13182 struct bp_target_info *bp_tgt = bp;
13185 ret = target_remove_breakpoint (gdbarch, bp_tgt);
13191 /* One (or perhaps two) breakpoints used for software single
13194 static void *single_step_breakpoints[2];
13195 static struct gdbarch *single_step_gdbarch[2];
13197 /* Create and insert a breakpoint for software single step. */
13200 insert_single_step_breakpoint (struct gdbarch *gdbarch,
13201 struct address_space *aspace,
13206 if (single_step_breakpoints[0] == NULL)
13208 bpt_p = &single_step_breakpoints[0];
13209 single_step_gdbarch[0] = gdbarch;
13213 gdb_assert (single_step_breakpoints[1] == NULL);
13214 bpt_p = &single_step_breakpoints[1];
13215 single_step_gdbarch[1] = gdbarch;
13218 /* NOTE drow/2006-04-11: A future improvement to this function would
13219 be to only create the breakpoints once, and actually put them on
13220 the breakpoint chain. That would let us use set_raw_breakpoint.
13221 We could adjust the addresses each time they were needed. Doing
13222 this requires corresponding changes elsewhere where single step
13223 breakpoints are handled, however. So, for now, we use this. */
13225 *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc);
13226 if (*bpt_p == NULL)
13227 error (_("Could not insert single-step breakpoint at %s"),
13228 paddress (gdbarch, next_pc));
13231 /* Check if the breakpoints used for software single stepping
13232 were inserted or not. */
13235 single_step_breakpoints_inserted (void)
13237 return (single_step_breakpoints[0] != NULL
13238 || single_step_breakpoints[1] != NULL);
13241 /* Remove and delete any breakpoints used for software single step. */
13244 remove_single_step_breakpoints (void)
13246 gdb_assert (single_step_breakpoints[0] != NULL);
13248 /* See insert_single_step_breakpoint for more about this deprecated
13250 deprecated_remove_raw_breakpoint (single_step_gdbarch[0],
13251 single_step_breakpoints[0]);
13252 single_step_gdbarch[0] = NULL;
13253 single_step_breakpoints[0] = NULL;
13255 if (single_step_breakpoints[1] != NULL)
13257 deprecated_remove_raw_breakpoint (single_step_gdbarch[1],
13258 single_step_breakpoints[1]);
13259 single_step_gdbarch[1] = NULL;
13260 single_step_breakpoints[1] = NULL;
13264 /* Delete software single step breakpoints without removing them from
13265 the inferior. This is intended to be used if the inferior's address
13266 space where they were inserted is already gone, e.g. after exit or
13270 cancel_single_step_breakpoints (void)
13274 for (i = 0; i < 2; i++)
13275 if (single_step_breakpoints[i])
13277 xfree (single_step_breakpoints[i]);
13278 single_step_breakpoints[i] = NULL;
13279 single_step_gdbarch[i] = NULL;
13283 /* Detach software single-step breakpoints from INFERIOR_PTID without
13287 detach_single_step_breakpoints (void)
13291 for (i = 0; i < 2; i++)
13292 if (single_step_breakpoints[i])
13293 target_remove_breakpoint (single_step_gdbarch[i],
13294 single_step_breakpoints[i]);
13297 /* Check whether a software single-step breakpoint is inserted at
13301 single_step_breakpoint_inserted_here_p (struct address_space *aspace,
13306 for (i = 0; i < 2; i++)
13308 struct bp_target_info *bp_tgt = single_step_breakpoints[i];
13310 && breakpoint_address_match (bp_tgt->placed_address_space,
13311 bp_tgt->placed_address,
13319 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
13320 non-zero otherwise. */
13322 is_syscall_catchpoint_enabled (struct breakpoint *bp)
13324 if (syscall_catchpoint_p (bp)
13325 && bp->enable_state != bp_disabled
13326 && bp->enable_state != bp_call_disabled)
13333 catch_syscall_enabled (void)
13335 struct inferior *inf = current_inferior ();
13337 return inf->total_syscalls_count != 0;
13341 catching_syscall_number (int syscall_number)
13343 struct breakpoint *bp;
13345 ALL_BREAKPOINTS (bp)
13346 if (is_syscall_catchpoint_enabled (bp))
13348 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp;
13350 if (c->syscalls_to_be_caught)
13354 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
13356 if (syscall_number == iter)
13366 /* Complete syscall names. Used by "catch syscall". */
13368 catch_syscall_completer (struct cmd_list_element *cmd,
13369 char *text, char *word)
13371 const char **list = get_syscall_names ();
13373 = (list == NULL) ? NULL : complete_on_enum (list, text, word);
13379 /* Tracepoint-specific operations. */
13381 /* Set tracepoint count to NUM. */
13383 set_tracepoint_count (int num)
13385 tracepoint_count = num;
13386 set_internalvar_integer (lookup_internalvar ("tpnum"), num);
13390 trace_command (char *arg, int from_tty)
13392 if (create_breakpoint (get_current_arch (),
13394 NULL, 0, 1 /* parse arg */,
13396 bp_tracepoint /* type_wanted */,
13397 0 /* Ignore count */,
13398 pending_break_support,
13399 &tracepoint_breakpoint_ops,
13403 set_tracepoint_count (breakpoint_count);
13407 ftrace_command (char *arg, int from_tty)
13409 if (create_breakpoint (get_current_arch (),
13411 NULL, 0, 1 /* parse arg */,
13413 bp_fast_tracepoint /* type_wanted */,
13414 0 /* Ignore count */,
13415 pending_break_support,
13416 &tracepoint_breakpoint_ops,
13420 set_tracepoint_count (breakpoint_count);
13423 /* strace command implementation. Creates a static tracepoint. */
13426 strace_command (char *arg, int from_tty)
13428 struct breakpoint_ops *ops;
13430 /* Decide if we are dealing with a static tracepoint marker (`-m'),
13431 or with a normal static tracepoint. */
13432 if (arg && strncmp (arg, "-m", 2) == 0 && isspace (arg[2]))
13433 ops = &strace_marker_breakpoint_ops;
13435 ops = &tracepoint_breakpoint_ops;
13437 if (create_breakpoint (get_current_arch (),
13439 NULL, 0, 1 /* parse arg */,
13441 bp_static_tracepoint /* type_wanted */,
13442 0 /* Ignore count */,
13443 pending_break_support,
13448 set_tracepoint_count (breakpoint_count);
13451 /* Set up a fake reader function that gets command lines from a linked
13452 list that was acquired during tracepoint uploading. */
13454 static struct uploaded_tp *this_utp;
13455 static int next_cmd;
13458 read_uploaded_action (void)
13462 VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt);
13469 /* Given information about a tracepoint as recorded on a target (which
13470 can be either a live system or a trace file), attempt to create an
13471 equivalent GDB tracepoint. This is not a reliable process, since
13472 the target does not necessarily have all the information used when
13473 the tracepoint was originally defined. */
13475 struct tracepoint *
13476 create_tracepoint_from_upload (struct uploaded_tp *utp)
13478 char *addr_str, small_buf[100];
13479 struct tracepoint *tp;
13481 if (utp->at_string)
13482 addr_str = utp->at_string;
13485 /* In the absence of a source location, fall back to raw
13486 address. Since there is no way to confirm that the address
13487 means the same thing as when the trace was started, warn the
13489 warning (_("Uploaded tracepoint %d has no "
13490 "source location, using raw address"),
13492 sprintf (small_buf, "*%s", hex_string (utp->addr));
13493 addr_str = small_buf;
13496 /* There's not much we can do with a sequence of bytecodes. */
13497 if (utp->cond && !utp->cond_string)
13498 warning (_("Uploaded tracepoint %d condition "
13499 "has no source form, ignoring it"),
13502 if (!create_breakpoint (get_current_arch (),
13504 utp->cond_string, -1, 0 /* parse cond/thread */,
13506 utp->type /* type_wanted */,
13507 0 /* Ignore count */,
13508 pending_break_support,
13509 &tracepoint_breakpoint_ops,
13511 utp->enabled /* enabled */,
13515 set_tracepoint_count (breakpoint_count);
13517 /* Get the tracepoint we just created. */
13518 tp = get_tracepoint (tracepoint_count);
13519 gdb_assert (tp != NULL);
13523 sprintf (small_buf, "%d %d", utp->pass, tp->base.number);
13525 trace_pass_command (small_buf, 0);
13528 /* If we have uploaded versions of the original commands, set up a
13529 special-purpose "reader" function and call the usual command line
13530 reader, then pass the result to the breakpoint command-setting
13532 if (!VEC_empty (char_ptr, utp->cmd_strings))
13534 struct command_line *cmd_list;
13539 cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL);
13541 breakpoint_set_commands (&tp->base, cmd_list);
13543 else if (!VEC_empty (char_ptr, utp->actions)
13544 || !VEC_empty (char_ptr, utp->step_actions))
13545 warning (_("Uploaded tracepoint %d actions "
13546 "have no source form, ignoring them"),
13549 /* Copy any status information that might be available. */
13550 tp->base.hit_count = utp->hit_count;
13551 tp->traceframe_usage = utp->traceframe_usage;
13556 /* Print information on tracepoint number TPNUM_EXP, or all if
13560 tracepoints_info (char *args, int from_tty)
13562 struct ui_out *uiout = current_uiout;
13565 num_printed = breakpoint_1 (args, 0, is_tracepoint);
13567 if (num_printed == 0)
13569 if (args == NULL || *args == '\0')
13570 ui_out_message (uiout, 0, "No tracepoints.\n");
13572 ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args);
13575 default_collect_info ();
13578 /* The 'enable trace' command enables tracepoints.
13579 Not supported by all targets. */
13581 enable_trace_command (char *args, int from_tty)
13583 enable_command (args, from_tty);
13586 /* The 'disable trace' command disables tracepoints.
13587 Not supported by all targets. */
13589 disable_trace_command (char *args, int from_tty)
13591 disable_command (args, from_tty);
13594 /* Remove a tracepoint (or all if no argument). */
13596 delete_trace_command (char *arg, int from_tty)
13598 struct breakpoint *b, *b_tmp;
13604 int breaks_to_delete = 0;
13606 /* Delete all breakpoints if no argument.
13607 Do not delete internal or call-dummy breakpoints, these
13608 have to be deleted with an explicit breakpoint number
13610 ALL_TRACEPOINTS (b)
13611 if (is_tracepoint (b) && user_breakpoint_p (b))
13613 breaks_to_delete = 1;
13617 /* Ask user only if there are some breakpoints to delete. */
13619 || (breaks_to_delete && query (_("Delete all tracepoints? "))))
13621 ALL_BREAKPOINTS_SAFE (b, b_tmp)
13622 if (is_tracepoint (b) && user_breakpoint_p (b))
13623 delete_breakpoint (b);
13627 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
13630 /* Helper function for trace_pass_command. */
13633 trace_pass_set_count (struct tracepoint *tp, int count, int from_tty)
13635 tp->pass_count = count;
13636 observer_notify_tracepoint_modified (tp->base.number);
13638 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
13639 tp->base.number, count);
13642 /* Set passcount for tracepoint.
13644 First command argument is passcount, second is tracepoint number.
13645 If tracepoint number omitted, apply to most recently defined.
13646 Also accepts special argument "all". */
13649 trace_pass_command (char *args, int from_tty)
13651 struct tracepoint *t1;
13652 unsigned int count;
13654 if (args == 0 || *args == 0)
13655 error (_("passcount command requires an "
13656 "argument (count + optional TP num)"));
13658 count = strtoul (args, &args, 10); /* Count comes first, then TP num. */
13660 while (*args && isspace ((int) *args))
13663 if (*args && strncasecmp (args, "all", 3) == 0)
13665 struct breakpoint *b;
13667 args += 3; /* Skip special argument "all". */
13669 error (_("Junk at end of arguments."));
13671 ALL_TRACEPOINTS (b)
13673 t1 = (struct tracepoint *) b;
13674 trace_pass_set_count (t1, count, from_tty);
13677 else if (*args == '\0')
13679 t1 = get_tracepoint_by_number (&args, NULL, 1);
13681 trace_pass_set_count (t1, count, from_tty);
13685 struct get_number_or_range_state state;
13687 init_number_or_range (&state, args);
13688 while (!state.finished)
13690 t1 = get_tracepoint_by_number (&args, &state, 1);
13692 trace_pass_set_count (t1, count, from_tty);
13697 struct tracepoint *
13698 get_tracepoint (int num)
13700 struct breakpoint *t;
13702 ALL_TRACEPOINTS (t)
13703 if (t->number == num)
13704 return (struct tracepoint *) t;
13709 /* Find the tracepoint with the given target-side number (which may be
13710 different from the tracepoint number after disconnecting and
13713 struct tracepoint *
13714 get_tracepoint_by_number_on_target (int num)
13716 struct breakpoint *b;
13718 ALL_TRACEPOINTS (b)
13720 struct tracepoint *t = (struct tracepoint *) b;
13722 if (t->number_on_target == num)
13729 /* Utility: parse a tracepoint number and look it up in the list.
13730 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
13731 If OPTIONAL_P is true, then if the argument is missing, the most
13732 recent tracepoint (tracepoint_count) is returned. */
13733 struct tracepoint *
13734 get_tracepoint_by_number (char **arg,
13735 struct get_number_or_range_state *state,
13738 extern int tracepoint_count;
13739 struct breakpoint *t;
13741 char *instring = arg == NULL ? NULL : *arg;
13745 gdb_assert (!state->finished);
13746 tpnum = get_number_or_range (state);
13748 else if (arg == NULL || *arg == NULL || ! **arg)
13751 tpnum = tracepoint_count;
13753 error_no_arg (_("tracepoint number"));
13756 tpnum = get_number (arg);
13760 if (instring && *instring)
13761 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
13764 printf_filtered (_("Tracepoint argument missing "
13765 "and no previous tracepoint\n"));
13769 ALL_TRACEPOINTS (t)
13770 if (t->number == tpnum)
13772 return (struct tracepoint *) t;
13775 printf_unfiltered ("No tracepoint number %d.\n", tpnum);
13780 print_recreate_thread (struct breakpoint *b, struct ui_file *fp)
13782 if (b->thread != -1)
13783 fprintf_unfiltered (fp, " thread %d", b->thread);
13786 fprintf_unfiltered (fp, " task %d", b->task);
13788 fprintf_unfiltered (fp, "\n");
13791 /* Save information on user settable breakpoints (watchpoints, etc) to
13792 a new script file named FILENAME. If FILTER is non-NULL, call it
13793 on each breakpoint and only include the ones for which it returns
13797 save_breakpoints (char *filename, int from_tty,
13798 int (*filter) (const struct breakpoint *))
13800 struct breakpoint *tp;
13803 struct cleanup *cleanup;
13804 struct ui_file *fp;
13805 int extra_trace_bits = 0;
13807 if (filename == 0 || *filename == 0)
13808 error (_("Argument required (file name in which to save)"));
13810 /* See if we have anything to save. */
13811 ALL_BREAKPOINTS (tp)
13813 /* Skip internal and momentary breakpoints. */
13814 if (!user_breakpoint_p (tp))
13817 /* If we have a filter, only save the breakpoints it accepts. */
13818 if (filter && !filter (tp))
13823 if (is_tracepoint (tp))
13825 extra_trace_bits = 1;
13827 /* We can stop searching. */
13834 warning (_("Nothing to save."));
13838 pathname = tilde_expand (filename);
13839 cleanup = make_cleanup (xfree, pathname);
13840 fp = gdb_fopen (pathname, "w");
13842 error (_("Unable to open file '%s' for saving (%s)"),
13843 filename, safe_strerror (errno));
13844 make_cleanup_ui_file_delete (fp);
13846 if (extra_trace_bits)
13847 save_trace_state_variables (fp);
13849 ALL_BREAKPOINTS (tp)
13851 /* Skip internal and momentary breakpoints. */
13852 if (!user_breakpoint_p (tp))
13855 /* If we have a filter, only save the breakpoints it accepts. */
13856 if (filter && !filter (tp))
13859 tp->ops->print_recreate (tp, fp);
13861 /* Note, we can't rely on tp->number for anything, as we can't
13862 assume the recreated breakpoint numbers will match. Use $bpnum
13865 if (tp->cond_string)
13866 fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string);
13868 if (tp->ignore_count)
13869 fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count);
13873 volatile struct gdb_exception ex;
13875 fprintf_unfiltered (fp, " commands\n");
13877 ui_out_redirect (current_uiout, fp);
13878 TRY_CATCH (ex, RETURN_MASK_ALL)
13880 print_command_lines (current_uiout, tp->commands->commands, 2);
13882 ui_out_redirect (current_uiout, NULL);
13885 throw_exception (ex);
13887 fprintf_unfiltered (fp, " end\n");
13890 if (tp->enable_state == bp_disabled)
13891 fprintf_unfiltered (fp, "disable\n");
13893 /* If this is a multi-location breakpoint, check if the locations
13894 should be individually disabled. Watchpoint locations are
13895 special, and not user visible. */
13896 if (!is_watchpoint (tp) && tp->loc && tp->loc->next)
13898 struct bp_location *loc;
13901 for (loc = tp->loc; loc != NULL; loc = loc->next, n++)
13903 fprintf_unfiltered (fp, "disable $bpnum.%d\n", n);
13907 if (extra_trace_bits && *default_collect)
13908 fprintf_unfiltered (fp, "set default-collect %s\n", default_collect);
13910 do_cleanups (cleanup);
13912 printf_filtered (_("Saved to file '%s'.\n"), filename);
13915 /* The `save breakpoints' command. */
13918 save_breakpoints_command (char *args, int from_tty)
13920 save_breakpoints (args, from_tty, NULL);
13923 /* The `save tracepoints' command. */
13926 save_tracepoints_command (char *args, int from_tty)
13928 save_breakpoints (args, from_tty, is_tracepoint);
13931 /* Create a vector of all tracepoints. */
13933 VEC(breakpoint_p) *
13934 all_tracepoints (void)
13936 VEC(breakpoint_p) *tp_vec = 0;
13937 struct breakpoint *tp;
13939 ALL_TRACEPOINTS (tp)
13941 VEC_safe_push (breakpoint_p, tp_vec, tp);
13948 /* This help string is used for the break, hbreak, tbreak and thbreak
13949 commands. It is defined as a macro to prevent duplication.
13950 COMMAND should be a string constant containing the name of the
13952 #define BREAK_ARGS_HELP(command) \
13953 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
13954 LOCATION may be a line number, function name, or \"*\" and an address.\n\
13955 If a line number is specified, break at start of code for that line.\n\
13956 If a function is specified, break at start of code for that function.\n\
13957 If an address is specified, break at that exact address.\n\
13958 With no LOCATION, uses current execution address of the selected\n\
13959 stack frame. This is useful for breaking on return to a stack frame.\n\
13961 THREADNUM is the number from \"info threads\".\n\
13962 CONDITION is a boolean expression.\n\
13964 Multiple breakpoints at one place are permitted, and useful if their\n\
13965 conditions are different.\n\
13967 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
13969 /* List of subcommands for "catch". */
13970 static struct cmd_list_element *catch_cmdlist;
13972 /* List of subcommands for "tcatch". */
13973 static struct cmd_list_element *tcatch_cmdlist;
13976 add_catch_command (char *name, char *docstring,
13977 void (*sfunc) (char *args, int from_tty,
13978 struct cmd_list_element *command),
13979 char **(*completer) (struct cmd_list_element *cmd,
13980 char *text, char *word),
13981 void *user_data_catch,
13982 void *user_data_tcatch)
13984 struct cmd_list_element *command;
13986 command = add_cmd (name, class_breakpoint, NULL, docstring,
13988 set_cmd_sfunc (command, sfunc);
13989 set_cmd_context (command, user_data_catch);
13990 set_cmd_completer (command, completer);
13992 command = add_cmd (name, class_breakpoint, NULL, docstring,
13994 set_cmd_sfunc (command, sfunc);
13995 set_cmd_context (command, user_data_tcatch);
13996 set_cmd_completer (command, completer);
14000 clear_syscall_counts (struct inferior *inf)
14002 inf->total_syscalls_count = 0;
14003 inf->any_syscall_count = 0;
14004 VEC_free (int, inf->syscalls_counts);
14008 save_command (char *arg, int from_tty)
14010 printf_unfiltered (_("\"save\" must be followed by "
14011 "the name of a save subcommand.\n"));
14012 help_list (save_cmdlist, "save ", -1, gdb_stdout);
14015 struct breakpoint *
14016 iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *),
14019 struct breakpoint *b, *b_tmp;
14021 ALL_BREAKPOINTS_SAFE (b, b_tmp)
14023 if ((*callback) (b, data))
14030 /* Zero if any of the breakpoint's locations could be a location where
14031 functions have been inlined, nonzero otherwise. */
14034 is_non_inline_function (struct breakpoint *b)
14036 /* The shared library event breakpoint is set on the address of a
14037 non-inline function. */
14038 if (b->type == bp_shlib_event)
14044 /* Nonzero if the specified PC cannot be a location where functions
14045 have been inlined. */
14048 pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc,
14049 const struct target_waitstatus *ws)
14051 struct breakpoint *b;
14052 struct bp_location *bl;
14054 ALL_BREAKPOINTS (b)
14056 if (!is_non_inline_function (b))
14059 for (bl = b->loc; bl != NULL; bl = bl->next)
14061 if (!bl->shlib_disabled
14062 && bpstat_check_location (bl, aspace, pc, ws))
14071 initialize_breakpoint_ops (void)
14073 static int initialized = 0;
14075 struct breakpoint_ops *ops;
14081 /* The breakpoint_ops structure to be inherit by all kinds of
14082 breakpoints (real breakpoints, i.e., user "break" breakpoints,
14083 internal and momentary breakpoints, etc.). */
14084 ops = &bkpt_base_breakpoint_ops;
14085 *ops = base_breakpoint_ops;
14086 ops->re_set = bkpt_re_set;
14087 ops->insert_location = bkpt_insert_location;
14088 ops->remove_location = bkpt_remove_location;
14089 ops->breakpoint_hit = bkpt_breakpoint_hit;
14090 ops->create_sals_from_address = bkpt_create_sals_from_address;
14091 ops->create_breakpoints_sal = bkpt_create_breakpoints_sal;
14092 ops->decode_linespec = bkpt_decode_linespec;
14094 /* The breakpoint_ops structure to be used in regular breakpoints. */
14095 ops = &bkpt_breakpoint_ops;
14096 *ops = bkpt_base_breakpoint_ops;
14097 ops->re_set = bkpt_re_set;
14098 ops->resources_needed = bkpt_resources_needed;
14099 ops->print_it = bkpt_print_it;
14100 ops->print_mention = bkpt_print_mention;
14101 ops->print_recreate = bkpt_print_recreate;
14103 /* Ranged breakpoints. */
14104 ops = &ranged_breakpoint_ops;
14105 *ops = bkpt_breakpoint_ops;
14106 ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint;
14107 ops->resources_needed = resources_needed_ranged_breakpoint;
14108 ops->print_it = print_it_ranged_breakpoint;
14109 ops->print_one = print_one_ranged_breakpoint;
14110 ops->print_one_detail = print_one_detail_ranged_breakpoint;
14111 ops->print_mention = print_mention_ranged_breakpoint;
14112 ops->print_recreate = print_recreate_ranged_breakpoint;
14114 /* Internal breakpoints. */
14115 ops = &internal_breakpoint_ops;
14116 *ops = bkpt_base_breakpoint_ops;
14117 ops->re_set = internal_bkpt_re_set;
14118 ops->check_status = internal_bkpt_check_status;
14119 ops->print_it = internal_bkpt_print_it;
14120 ops->print_mention = internal_bkpt_print_mention;
14122 /* Momentary breakpoints. */
14123 ops = &momentary_breakpoint_ops;
14124 *ops = bkpt_base_breakpoint_ops;
14125 ops->re_set = momentary_bkpt_re_set;
14126 ops->check_status = momentary_bkpt_check_status;
14127 ops->print_it = momentary_bkpt_print_it;
14128 ops->print_mention = momentary_bkpt_print_mention;
14130 /* GNU v3 exception catchpoints. */
14131 ops = &gnu_v3_exception_catchpoint_ops;
14132 *ops = bkpt_breakpoint_ops;
14133 ops->print_it = print_it_exception_catchpoint;
14134 ops->print_one = print_one_exception_catchpoint;
14135 ops->print_mention = print_mention_exception_catchpoint;
14136 ops->print_recreate = print_recreate_exception_catchpoint;
14139 ops = &watchpoint_breakpoint_ops;
14140 *ops = base_breakpoint_ops;
14141 ops->dtor = dtor_watchpoint;
14142 ops->re_set = re_set_watchpoint;
14143 ops->insert_location = insert_watchpoint;
14144 ops->remove_location = remove_watchpoint;
14145 ops->breakpoint_hit = breakpoint_hit_watchpoint;
14146 ops->check_status = check_status_watchpoint;
14147 ops->resources_needed = resources_needed_watchpoint;
14148 ops->works_in_software_mode = works_in_software_mode_watchpoint;
14149 ops->print_it = print_it_watchpoint;
14150 ops->print_mention = print_mention_watchpoint;
14151 ops->print_recreate = print_recreate_watchpoint;
14153 /* Masked watchpoints. */
14154 ops = &masked_watchpoint_breakpoint_ops;
14155 *ops = watchpoint_breakpoint_ops;
14156 ops->insert_location = insert_masked_watchpoint;
14157 ops->remove_location = remove_masked_watchpoint;
14158 ops->resources_needed = resources_needed_masked_watchpoint;
14159 ops->works_in_software_mode = works_in_software_mode_masked_watchpoint;
14160 ops->print_it = print_it_masked_watchpoint;
14161 ops->print_one_detail = print_one_detail_masked_watchpoint;
14162 ops->print_mention = print_mention_masked_watchpoint;
14163 ops->print_recreate = print_recreate_masked_watchpoint;
14166 ops = &tracepoint_breakpoint_ops;
14167 *ops = base_breakpoint_ops;
14168 ops->re_set = tracepoint_re_set;
14169 ops->breakpoint_hit = tracepoint_breakpoint_hit;
14170 ops->print_one_detail = tracepoint_print_one_detail;
14171 ops->print_mention = tracepoint_print_mention;
14172 ops->print_recreate = tracepoint_print_recreate;
14173 ops->create_sals_from_address = tracepoint_create_sals_from_address;
14174 ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal;
14175 ops->decode_linespec = tracepoint_decode_linespec;
14177 /* Static tracepoints with marker (`-m'). */
14178 ops = &strace_marker_breakpoint_ops;
14179 *ops = tracepoint_breakpoint_ops;
14180 ops->create_sals_from_address = strace_marker_create_sals_from_address;
14181 ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal;
14182 ops->decode_linespec = strace_marker_decode_linespec;
14184 /* Fork catchpoints. */
14185 ops = &catch_fork_breakpoint_ops;
14186 *ops = base_breakpoint_ops;
14187 ops->insert_location = insert_catch_fork;
14188 ops->remove_location = remove_catch_fork;
14189 ops->breakpoint_hit = breakpoint_hit_catch_fork;
14190 ops->print_it = print_it_catch_fork;
14191 ops->print_one = print_one_catch_fork;
14192 ops->print_mention = print_mention_catch_fork;
14193 ops->print_recreate = print_recreate_catch_fork;
14195 /* Vfork catchpoints. */
14196 ops = &catch_vfork_breakpoint_ops;
14197 *ops = base_breakpoint_ops;
14198 ops->insert_location = insert_catch_vfork;
14199 ops->remove_location = remove_catch_vfork;
14200 ops->breakpoint_hit = breakpoint_hit_catch_vfork;
14201 ops->print_it = print_it_catch_vfork;
14202 ops->print_one = print_one_catch_vfork;
14203 ops->print_mention = print_mention_catch_vfork;
14204 ops->print_recreate = print_recreate_catch_vfork;
14206 /* Exec catchpoints. */
14207 ops = &catch_exec_breakpoint_ops;
14208 *ops = base_breakpoint_ops;
14209 ops->dtor = dtor_catch_exec;
14210 ops->insert_location = insert_catch_exec;
14211 ops->remove_location = remove_catch_exec;
14212 ops->breakpoint_hit = breakpoint_hit_catch_exec;
14213 ops->print_it = print_it_catch_exec;
14214 ops->print_one = print_one_catch_exec;
14215 ops->print_mention = print_mention_catch_exec;
14216 ops->print_recreate = print_recreate_catch_exec;
14218 /* Syscall catchpoints. */
14219 ops = &catch_syscall_breakpoint_ops;
14220 *ops = base_breakpoint_ops;
14221 ops->dtor = dtor_catch_syscall;
14222 ops->insert_location = insert_catch_syscall;
14223 ops->remove_location = remove_catch_syscall;
14224 ops->breakpoint_hit = breakpoint_hit_catch_syscall;
14225 ops->print_it = print_it_catch_syscall;
14226 ops->print_one = print_one_catch_syscall;
14227 ops->print_mention = print_mention_catch_syscall;
14228 ops->print_recreate = print_recreate_catch_syscall;
14230 /* Solib-related catchpoints. */
14231 ops = &catch_solib_breakpoint_ops;
14232 *ops = base_breakpoint_ops;
14233 ops->dtor = dtor_catch_solib;
14234 ops->insert_location = insert_catch_solib;
14235 ops->remove_location = remove_catch_solib;
14236 ops->breakpoint_hit = breakpoint_hit_catch_solib;
14237 ops->check_status = check_status_catch_solib;
14238 ops->print_it = print_it_catch_solib;
14239 ops->print_one = print_one_catch_solib;
14240 ops->print_mention = print_mention_catch_solib;
14241 ops->print_recreate = print_recreate_catch_solib;
14245 _initialize_breakpoint (void)
14247 struct cmd_list_element *c;
14249 initialize_breakpoint_ops ();
14251 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
14252 observer_attach_inferior_exit (clear_syscall_counts);
14253 observer_attach_memory_changed (invalidate_bp_value_on_memory_change);
14255 breakpoint_objfile_key = register_objfile_data ();
14257 breakpoint_chain = 0;
14258 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
14259 before a breakpoint is set. */
14260 breakpoint_count = 0;
14262 tracepoint_count = 0;
14264 add_com ("ignore", class_breakpoint, ignore_command, _("\
14265 Set ignore-count of breakpoint number N to COUNT.\n\
14266 Usage is `ignore N COUNT'."));
14268 add_com_alias ("bc", "ignore", class_breakpoint, 1);
14270 add_com ("commands", class_breakpoint, commands_command, _("\
14271 Set commands to be executed when a breakpoint is hit.\n\
14272 Give breakpoint number as argument after \"commands\".\n\
14273 With no argument, the targeted breakpoint is the last one set.\n\
14274 The commands themselves follow starting on the next line.\n\
14275 Type a line containing \"end\" to indicate the end of them.\n\
14276 Give \"silent\" as the first line to make the breakpoint silent;\n\
14277 then no output is printed when it is hit, except what the commands print."));
14279 add_com ("condition", class_breakpoint, condition_command, _("\
14280 Specify breakpoint number N to break only if COND is true.\n\
14281 Usage is `condition N COND', where N is an integer and COND is an\n\
14282 expression to be evaluated whenever breakpoint N is reached."));
14284 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
14285 Set a temporary breakpoint.\n\
14286 Like \"break\" except the breakpoint is only temporary,\n\
14287 so it will be deleted when hit. Equivalent to \"break\" followed\n\
14288 by using \"enable delete\" on the breakpoint number.\n\
14290 BREAK_ARGS_HELP ("tbreak")));
14291 set_cmd_completer (c, location_completer);
14293 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
14294 Set a hardware assisted breakpoint.\n\
14295 Like \"break\" except the breakpoint requires hardware support,\n\
14296 some target hardware may not have this support.\n\
14298 BREAK_ARGS_HELP ("hbreak")));
14299 set_cmd_completer (c, location_completer);
14301 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
14302 Set a temporary hardware assisted breakpoint.\n\
14303 Like \"hbreak\" except the breakpoint is only temporary,\n\
14304 so it will be deleted when hit.\n\
14306 BREAK_ARGS_HELP ("thbreak")));
14307 set_cmd_completer (c, location_completer);
14309 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
14310 Enable some breakpoints.\n\
14311 Give breakpoint numbers (separated by spaces) as arguments.\n\
14312 With no subcommand, breakpoints are enabled until you command otherwise.\n\
14313 This is used to cancel the effect of the \"disable\" command.\n\
14314 With a subcommand you can enable temporarily."),
14315 &enablelist, "enable ", 1, &cmdlist);
14317 add_com ("ab", class_breakpoint, enable_command, _("\
14318 Enable some breakpoints.\n\
14319 Give breakpoint numbers (separated by spaces) as arguments.\n\
14320 With no subcommand, breakpoints are enabled until you command otherwise.\n\
14321 This is used to cancel the effect of the \"disable\" command.\n\
14322 With a subcommand you can enable temporarily."));
14324 add_com_alias ("en", "enable", class_breakpoint, 1);
14326 add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
14327 Enable some breakpoints.\n\
14328 Give breakpoint numbers (separated by spaces) as arguments.\n\
14329 This is used to cancel the effect of the \"disable\" command.\n\
14330 May be abbreviated to simply \"enable\".\n"),
14331 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
14333 add_cmd ("once", no_class, enable_once_command, _("\
14334 Enable breakpoints for one hit. Give breakpoint numbers.\n\
14335 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
14338 add_cmd ("delete", no_class, enable_delete_command, _("\
14339 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
14340 If a breakpoint is hit while enabled in this fashion, it is deleted."),
14343 add_cmd ("count", no_class, enable_count_command, _("\
14344 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
14345 If a breakpoint is hit while enabled in this fashion,\n\
14346 the count is decremented; when it reaches zero, the breakpoint is disabled."),
14349 add_cmd ("delete", no_class, enable_delete_command, _("\
14350 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
14351 If a breakpoint is hit while enabled in this fashion, it is deleted."),
14354 add_cmd ("once", no_class, enable_once_command, _("\
14355 Enable breakpoints for one hit. Give breakpoint numbers.\n\
14356 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
14359 add_cmd ("count", no_class, enable_count_command, _("\
14360 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
14361 If a breakpoint is hit while enabled in this fashion,\n\
14362 the count is decremented; when it reaches zero, the breakpoint is disabled."),
14365 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
14366 Disable some breakpoints.\n\
14367 Arguments are breakpoint numbers with spaces in between.\n\
14368 To disable all breakpoints, give no argument.\n\
14369 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
14370 &disablelist, "disable ", 1, &cmdlist);
14371 add_com_alias ("dis", "disable", class_breakpoint, 1);
14372 add_com_alias ("disa", "disable", class_breakpoint, 1);
14374 add_com ("sb", class_breakpoint, disable_command, _("\
14375 Disable some breakpoints.\n\
14376 Arguments are breakpoint numbers with spaces in between.\n\
14377 To disable all breakpoints, give no argument.\n\
14378 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
14380 add_cmd ("breakpoints", class_alias, disable_command, _("\
14381 Disable some breakpoints.\n\
14382 Arguments are breakpoint numbers with spaces in between.\n\
14383 To disable all breakpoints, give no argument.\n\
14384 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
14385 This command may be abbreviated \"disable\"."),
14388 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
14389 Delete some breakpoints or auto-display expressions.\n\
14390 Arguments are breakpoint numbers with spaces in between.\n\
14391 To delete all breakpoints, give no argument.\n\
14393 Also a prefix command for deletion of other GDB objects.\n\
14394 The \"unset\" command is also an alias for \"delete\"."),
14395 &deletelist, "delete ", 1, &cmdlist);
14396 add_com_alias ("d", "delete", class_breakpoint, 1);
14397 add_com_alias ("del", "delete", class_breakpoint, 1);
14399 add_com ("db", class_breakpoint, delete_command, _("\
14400 Delete some breakpoints.\n\
14401 Arguments are breakpoint numbers with spaces in between.\n\
14402 To delete all breakpoints, give no argument.\n"));
14404 add_cmd ("breakpoints", class_alias, delete_command, _("\
14405 Delete some breakpoints or auto-display expressions.\n\
14406 Arguments are breakpoint numbers with spaces in between.\n\
14407 To delete all breakpoints, give no argument.\n\
14408 This command may be abbreviated \"delete\"."),
14411 add_com ("clear", class_breakpoint, clear_command, _("\
14412 Clear breakpoint at specified line or function.\n\
14413 Argument may be line number, function name, or \"*\" and an address.\n\
14414 If line number is specified, all breakpoints in that line are cleared.\n\
14415 If function is specified, breakpoints at beginning of function are cleared.\n\
14416 If an address is specified, breakpoints at that address are cleared.\n\
14418 With no argument, clears all breakpoints in the line that the selected frame\n\
14419 is executing in.\n\
14421 See also the \"delete\" command which clears breakpoints by number."));
14422 add_com_alias ("cl", "clear", class_breakpoint, 1);
14424 c = add_com ("break", class_breakpoint, break_command, _("\
14425 Set breakpoint at specified line or function.\n"
14426 BREAK_ARGS_HELP ("break")));
14427 set_cmd_completer (c, location_completer);
14429 add_com_alias ("b", "break", class_run, 1);
14430 add_com_alias ("br", "break", class_run, 1);
14431 add_com_alias ("bre", "break", class_run, 1);
14432 add_com_alias ("brea", "break", class_run, 1);
14435 add_com_alias ("ba", "break", class_breakpoint, 1);
14439 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
14440 Break in function/address or break at a line in the current file."),
14441 &stoplist, "stop ", 1, &cmdlist);
14442 add_cmd ("in", class_breakpoint, stopin_command,
14443 _("Break in function or address."), &stoplist);
14444 add_cmd ("at", class_breakpoint, stopat_command,
14445 _("Break at a line in the current file."), &stoplist);
14446 add_com ("status", class_info, breakpoints_info, _("\
14447 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
14448 The \"Type\" column indicates one of:\n\
14449 \tbreakpoint - normal breakpoint\n\
14450 \twatchpoint - watchpoint\n\
14451 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
14452 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
14453 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
14454 address and file/line number respectively.\n\
14456 Convenience variable \"$_\" and default examine address for \"x\"\n\
14457 are set to the address of the last breakpoint listed unless the command\n\
14458 is prefixed with \"server \".\n\n\
14459 Convenience variable \"$bpnum\" contains the number of the last\n\
14460 breakpoint set."));
14463 add_info ("breakpoints", breakpoints_info, _("\
14464 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
14465 The \"Type\" column indicates one of:\n\
14466 \tbreakpoint - normal breakpoint\n\
14467 \twatchpoint - watchpoint\n\
14468 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
14469 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
14470 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
14471 address and file/line number respectively.\n\
14473 Convenience variable \"$_\" and default examine address for \"x\"\n\
14474 are set to the address of the last breakpoint listed unless the command\n\
14475 is prefixed with \"server \".\n\n\
14476 Convenience variable \"$bpnum\" contains the number of the last\n\
14477 breakpoint set."));
14479 add_info_alias ("b", "breakpoints", 1);
14482 add_com ("lb", class_breakpoint, breakpoints_info, _("\
14483 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
14484 The \"Type\" column indicates one of:\n\
14485 \tbreakpoint - normal breakpoint\n\
14486 \twatchpoint - watchpoint\n\
14487 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
14488 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
14489 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
14490 address and file/line number respectively.\n\
14492 Convenience variable \"$_\" and default examine address for \"x\"\n\
14493 are set to the address of the last breakpoint listed unless the command\n\
14494 is prefixed with \"server \".\n\n\
14495 Convenience variable \"$bpnum\" contains the number of the last\n\
14496 breakpoint set."));
14498 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
14499 Status of all breakpoints, or breakpoint number NUMBER.\n\
14500 The \"Type\" column indicates one of:\n\
14501 \tbreakpoint - normal breakpoint\n\
14502 \twatchpoint - watchpoint\n\
14503 \tlongjmp - internal breakpoint used to step through longjmp()\n\
14504 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
14505 \tuntil - internal breakpoint used by the \"until\" command\n\
14506 \tfinish - internal breakpoint used by the \"finish\" command\n\
14507 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
14508 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
14509 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
14510 address and file/line number respectively.\n\
14512 Convenience variable \"$_\" and default examine address for \"x\"\n\
14513 are set to the address of the last breakpoint listed unless the command\n\
14514 is prefixed with \"server \".\n\n\
14515 Convenience variable \"$bpnum\" contains the number of the last\n\
14517 &maintenanceinfolist);
14519 add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\
14520 Set catchpoints to catch events."),
14521 &catch_cmdlist, "catch ",
14522 0/*allow-unknown*/, &cmdlist);
14524 add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\
14525 Set temporary catchpoints to catch events."),
14526 &tcatch_cmdlist, "tcatch ",
14527 0/*allow-unknown*/, &cmdlist);
14529 /* Add catch and tcatch sub-commands. */
14530 add_catch_command ("catch", _("\
14531 Catch an exception, when caught."),
14532 catch_catch_command,
14536 add_catch_command ("throw", _("\
14537 Catch an exception, when thrown."),
14538 catch_throw_command,
14542 add_catch_command ("fork", _("Catch calls to fork."),
14543 catch_fork_command_1,
14545 (void *) (uintptr_t) catch_fork_permanent,
14546 (void *) (uintptr_t) catch_fork_temporary);
14547 add_catch_command ("vfork", _("Catch calls to vfork."),
14548 catch_fork_command_1,
14550 (void *) (uintptr_t) catch_vfork_permanent,
14551 (void *) (uintptr_t) catch_vfork_temporary);
14552 add_catch_command ("exec", _("Catch calls to exec."),
14553 catch_exec_command_1,
14557 add_catch_command ("load", _("Catch loads of shared libraries.\n\
14558 Usage: catch load [REGEX]\n\
14559 If REGEX is given, only stop for libraries matching the regular expression."),
14560 catch_load_command_1,
14564 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
14565 Usage: catch unload [REGEX]\n\
14566 If REGEX is given, only stop for libraries matching the regular expression."),
14567 catch_unload_command_1,
14571 add_catch_command ("syscall", _("\
14572 Catch system calls by their names and/or numbers.\n\
14573 Arguments say which system calls to catch. If no arguments\n\
14574 are given, every system call will be caught.\n\
14575 Arguments, if given, should be one or more system call names\n\
14576 (if your system supports that), or system call numbers."),
14577 catch_syscall_command_1,
14578 catch_syscall_completer,
14582 c = add_com ("watch", class_breakpoint, watch_command, _("\
14583 Set a watchpoint for an expression.\n\
14584 Usage: watch [-l|-location] EXPRESSION\n\
14585 A watchpoint stops execution of your program whenever the value of\n\
14586 an expression changes.\n\
14587 If -l or -location is given, this evaluates EXPRESSION and watches\n\
14588 the memory to which it refers."));
14589 set_cmd_completer (c, expression_completer);
14591 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
14592 Set a read watchpoint for an expression.\n\
14593 Usage: rwatch [-l|-location] EXPRESSION\n\
14594 A watchpoint stops execution of your program whenever the value of\n\
14595 an expression is read.\n\
14596 If -l or -location is given, this evaluates EXPRESSION and watches\n\
14597 the memory to which it refers."));
14598 set_cmd_completer (c, expression_completer);
14600 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
14601 Set a watchpoint for an expression.\n\
14602 Usage: awatch [-l|-location] EXPRESSION\n\
14603 A watchpoint stops execution of your program whenever the value of\n\
14604 an expression is either read or written.\n\
14605 If -l or -location is given, this evaluates EXPRESSION and watches\n\
14606 the memory to which it refers."));
14607 set_cmd_completer (c, expression_completer);
14609 add_info ("watchpoints", watchpoints_info, _("\
14610 Status of specified watchpoints (all watchpoints if no argument)."));
14612 /* XXX: cagney/2005-02-23: This should be a boolean, and should
14613 respond to changes - contrary to the description. */
14614 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
14615 &can_use_hw_watchpoints, _("\
14616 Set debugger's willingness to use watchpoint hardware."), _("\
14617 Show debugger's willingness to use watchpoint hardware."), _("\
14618 If zero, gdb will not use hardware for new watchpoints, even if\n\
14619 such is available. (However, any hardware watchpoints that were\n\
14620 created before setting this to nonzero, will continue to use watchpoint\n\
14623 show_can_use_hw_watchpoints,
14624 &setlist, &showlist);
14626 can_use_hw_watchpoints = 1;
14628 /* Tracepoint manipulation commands. */
14630 c = add_com ("trace", class_breakpoint, trace_command, _("\
14631 Set a tracepoint at specified line or function.\n\
14633 BREAK_ARGS_HELP ("trace") "\n\
14634 Do \"help tracepoints\" for info on other tracepoint commands."));
14635 set_cmd_completer (c, location_completer);
14637 add_com_alias ("tp", "trace", class_alias, 0);
14638 add_com_alias ("tr", "trace", class_alias, 1);
14639 add_com_alias ("tra", "trace", class_alias, 1);
14640 add_com_alias ("trac", "trace", class_alias, 1);
14642 c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\
14643 Set a fast tracepoint at specified line or function.\n\
14645 BREAK_ARGS_HELP ("ftrace") "\n\
14646 Do \"help tracepoints\" for info on other tracepoint commands."));
14647 set_cmd_completer (c, location_completer);
14649 c = add_com ("strace", class_breakpoint, strace_command, _("\
14650 Set a static tracepoint at specified line, function or marker.\n\
14652 strace [LOCATION] [if CONDITION]\n\
14653 LOCATION may be a line number, function name, \"*\" and an address,\n\
14654 or -m MARKER_ID.\n\
14655 If a line number is specified, probe the marker at start of code\n\
14656 for that line. If a function is specified, probe the marker at start\n\
14657 of code for that function. If an address is specified, probe the marker\n\
14658 at that exact address. If a marker id is specified, probe the marker\n\
14659 with that name. With no LOCATION, uses current execution address of\n\
14660 the selected stack frame.\n\
14661 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
14662 This collects arbitrary user data passed in the probe point call to the\n\
14663 tracing library. You can inspect it when analyzing the trace buffer,\n\
14664 by printing the $_sdata variable like any other convenience variable.\n\
14666 CONDITION is a boolean expression.\n\
14668 Multiple tracepoints at one place are permitted, and useful if their\n\
14669 conditions are different.\n\
14671 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
14672 Do \"help tracepoints\" for info on other tracepoint commands."));
14673 set_cmd_completer (c, location_completer);
14675 add_info ("tracepoints", tracepoints_info, _("\
14676 Status of specified tracepoints (all tracepoints if no argument).\n\
14677 Convenience variable \"$tpnum\" contains the number of the\n\
14678 last tracepoint set."));
14680 add_info_alias ("tp", "tracepoints", 1);
14682 add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
14683 Delete specified tracepoints.\n\
14684 Arguments are tracepoint numbers, separated by spaces.\n\
14685 No argument means delete all tracepoints."),
14688 c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
14689 Disable specified tracepoints.\n\
14690 Arguments are tracepoint numbers, separated by spaces.\n\
14691 No argument means disable all tracepoints."),
14693 deprecate_cmd (c, "disable");
14695 c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\
14696 Enable specified tracepoints.\n\
14697 Arguments are tracepoint numbers, separated by spaces.\n\
14698 No argument means enable all tracepoints."),
14700 deprecate_cmd (c, "enable");
14702 add_com ("passcount", class_trace, trace_pass_command, _("\
14703 Set the passcount for a tracepoint.\n\
14704 The trace will end when the tracepoint has been passed 'count' times.\n\
14705 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
14706 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
14708 add_prefix_cmd ("save", class_breakpoint, save_command,
14709 _("Save breakpoint definitions as a script."),
14710 &save_cmdlist, "save ",
14711 0/*allow-unknown*/, &cmdlist);
14713 c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\
14714 Save current breakpoint definitions as a script.\n\
14715 This includes all types of breakpoints (breakpoints, watchpoints,\n\
14716 catchpoints, tracepoints). Use the 'source' command in another debug\n\
14717 session to restore them."),
14719 set_cmd_completer (c, filename_completer);
14721 c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\
14722 Save current tracepoint definitions as a script.\n\
14723 Use the 'source' command in another debug session to restore them."),
14725 set_cmd_completer (c, filename_completer);
14727 c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0);
14728 deprecate_cmd (c, "save tracepoints");
14730 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
14731 Breakpoint specific settings\n\
14732 Configure various breakpoint-specific variables such as\n\
14733 pending breakpoint behavior"),
14734 &breakpoint_set_cmdlist, "set breakpoint ",
14735 0/*allow-unknown*/, &setlist);
14736 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
14737 Breakpoint specific settings\n\
14738 Configure various breakpoint-specific variables such as\n\
14739 pending breakpoint behavior"),
14740 &breakpoint_show_cmdlist, "show breakpoint ",
14741 0/*allow-unknown*/, &showlist);
14743 add_setshow_auto_boolean_cmd ("pending", no_class,
14744 &pending_break_support, _("\
14745 Set debugger's behavior regarding pending breakpoints."), _("\
14746 Show debugger's behavior regarding pending breakpoints."), _("\
14747 If on, an unrecognized breakpoint location will cause gdb to create a\n\
14748 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
14749 an error. If auto, an unrecognized breakpoint location results in a\n\
14750 user-query to see if a pending breakpoint should be created."),
14752 show_pending_break_support,
14753 &breakpoint_set_cmdlist,
14754 &breakpoint_show_cmdlist);
14756 pending_break_support = AUTO_BOOLEAN_AUTO;
14758 add_setshow_boolean_cmd ("auto-hw", no_class,
14759 &automatic_hardware_breakpoints, _("\
14760 Set automatic usage of hardware breakpoints."), _("\
14761 Show automatic usage of hardware breakpoints."), _("\
14762 If set, the debugger will automatically use hardware breakpoints for\n\
14763 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
14764 a warning will be emitted for such breakpoints."),
14766 show_automatic_hardware_breakpoints,
14767 &breakpoint_set_cmdlist,
14768 &breakpoint_show_cmdlist);
14770 add_setshow_enum_cmd ("always-inserted", class_support,
14771 always_inserted_enums, &always_inserted_mode, _("\
14772 Set mode for inserting breakpoints."), _("\
14773 Show mode for inserting breakpoints."), _("\
14774 When this mode is off, breakpoints are inserted in inferior when it is\n\
14775 resumed, and removed when execution stops. When this mode is on,\n\
14776 breakpoints are inserted immediately and removed only when the user\n\
14777 deletes the breakpoint. When this mode is auto (which is the default),\n\
14778 the behaviour depends on the non-stop setting (see help set non-stop).\n\
14779 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
14780 behaves as if always-inserted mode is on; if gdb is controlling the\n\
14781 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
14783 &show_always_inserted_mode,
14784 &breakpoint_set_cmdlist,
14785 &breakpoint_show_cmdlist);
14787 add_com ("break-range", class_breakpoint, break_range_command, _("\
14788 Set a breakpoint for an address range.\n\
14789 break-range START-LOCATION, END-LOCATION\n\
14790 where START-LOCATION and END-LOCATION can be one of the following:\n\
14791 LINENUM, for that line in the current file,\n\
14792 FILE:LINENUM, for that line in that file,\n\
14793 +OFFSET, for that number of lines after the current line\n\
14794 or the start of the range\n\
14795 FUNCTION, for the first line in that function,\n\
14796 FILE:FUNCTION, to distinguish among like-named static functions.\n\
14797 *ADDRESS, for the instruction at that address.\n\
14799 The breakpoint will stop execution of the inferior whenever it executes\n\
14800 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
14801 range (including START-LOCATION and END-LOCATION)."));
14803 automatic_hardware_breakpoints = 1;
14805 observer_attach_about_to_proceed (breakpoint_about_to_proceed);