1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
5 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "arch-utils.h"
28 #include "breakpoint.h"
29 #include "tracepoint.h"
31 #include "expression.h"
37 #include "gdbthread.h"
40 #include "gdb_string.h"
42 #include "filenames.h"
48 #include "completer.h"
51 #include "cli/cli-script.h"
52 #include "gdb_assert.h"
57 #include "exceptions.h"
64 #include "xml-syscall.h"
65 #include "parser-defs.h"
66 #include "cli/cli-utils.h"
67 #include "continuations.h"
69 /* readline include files */
70 #include "readline/readline.h"
71 #include "readline/history.h"
73 /* readline defines this. */
76 #include "mi/mi-common.h"
77 #include "python/python.h"
79 /* Prototypes for local functions. */
81 static void enable_delete_command (char *, int);
83 static void enable_once_command (char *, int);
85 static void disable_command (char *, int);
87 static void enable_command (char *, int);
89 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *,
93 static void ignore_command (char *, int);
95 static int breakpoint_re_set_one (void *);
97 static void clear_command (char *, int);
99 static void catch_command (char *, int);
101 static int can_use_hardware_watchpoint (struct value *);
103 static void break_command_1 (char *, int, int);
105 static void mention (struct breakpoint *);
107 /* This function is used in gdbtk sources and thus can not be made
109 struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch,
110 struct symtab_and_line,
113 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
115 static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch,
119 static void describe_other_breakpoints (struct gdbarch *,
120 struct program_space *, CORE_ADDR,
121 struct obj_section *, int);
123 static int breakpoint_address_match (struct address_space *aspace1,
125 struct address_space *aspace2,
128 static int watchpoint_locations_match (struct bp_location *loc1,
129 struct bp_location *loc2);
131 static int breakpoint_location_address_match (struct bp_location *bl,
132 struct address_space *aspace,
135 static void breakpoints_info (char *, int);
137 static void watchpoints_info (char *, int);
139 static int breakpoint_1 (char *, int,
140 int (*) (const struct breakpoint *));
142 static int breakpoint_cond_eval (void *);
144 static void cleanup_executing_breakpoints (void *);
146 static void commands_command (char *, int);
148 static void condition_command (char *, int);
157 static int remove_breakpoint (struct bp_location *, insertion_state_t);
158 static int remove_breakpoint_1 (struct bp_location *, insertion_state_t);
160 static enum print_stop_action print_it_typical (bpstat);
162 static enum print_stop_action print_bp_stop_message (bpstat bs);
164 static int watchpoint_check (void *);
166 static void maintenance_info_breakpoints (char *, int);
168 static int hw_breakpoint_used_count (void);
170 static int hw_watchpoint_used_count (enum bptype, int *);
172 static void hbreak_command (char *, int);
174 static void thbreak_command (char *, int);
176 static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp);
178 static void stop_command (char *arg, int from_tty);
180 static void stopin_command (char *arg, int from_tty);
182 static void stopat_command (char *arg, int from_tty);
184 static char *ep_parse_optional_if_clause (char **arg);
186 static void catch_exception_command_1 (enum exception_event_kind ex_event,
187 char *arg, int tempflag, int from_tty);
189 static void tcatch_command (char *arg, int from_tty);
191 static void detach_single_step_breakpoints (void);
193 static int single_step_breakpoint_inserted_here_p (struct address_space *,
196 static void free_bp_location (struct bp_location *loc);
197 static void incref_bp_location (struct bp_location *loc);
198 static void decref_bp_location (struct bp_location **loc);
200 static struct bp_location *allocate_bp_location (struct breakpoint *bpt);
202 static void update_global_location_list (int);
204 static void update_global_location_list_nothrow (int);
206 static int is_hardware_watchpoint (const struct breakpoint *bpt);
208 static int is_watchpoint (const struct breakpoint *bpt);
210 static void insert_breakpoint_locations (void);
212 static int syscall_catchpoint_p (struct breakpoint *b);
214 static void tracepoints_info (char *, int);
216 static void delete_trace_command (char *, int);
218 static void enable_trace_command (char *, int);
220 static void disable_trace_command (char *, int);
222 static void trace_pass_command (char *, int);
224 static int is_masked_watchpoint (const struct breakpoint *b);
226 /* Assuming we're creating a static tracepoint, does S look like a
227 static tracepoint marker spec ("-m MARKER_ID")? */
228 #define is_marker_spec(s) \
229 (s != NULL && strncmp (s, "-m", 2) == 0 && ((s)[2] == ' ' || (s)[2] == '\t'))
231 /* A reference-counted struct command_line. This lets multiple
232 breakpoints share a single command list. */
233 struct counted_command_line
235 /* The reference count. */
238 /* The command list. */
239 struct command_line *commands;
242 struct command_line *
243 breakpoint_commands (struct breakpoint *b)
245 return b->commands ? b->commands->commands : NULL;
248 /* Flag indicating that a command has proceeded the inferior past the
249 current breakpoint. */
251 static int breakpoint_proceeded;
254 bpdisp_text (enum bpdisp disp)
256 /* NOTE: the following values are a part of MI protocol and
257 represent values of 'disp' field returned when inferior stops at
259 static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"};
261 return bpdisps[(int) disp];
264 /* Prototypes for exported functions. */
265 /* If FALSE, gdb will not use hardware support for watchpoints, even
266 if such is available. */
267 static int can_use_hw_watchpoints;
270 show_can_use_hw_watchpoints (struct ui_file *file, int from_tty,
271 struct cmd_list_element *c,
274 fprintf_filtered (file,
275 _("Debugger's willingness to use "
276 "watchpoint hardware is %s.\n"),
280 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
281 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
282 for unrecognized breakpoint locations.
283 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
284 static enum auto_boolean pending_break_support;
286 show_pending_break_support (struct ui_file *file, int from_tty,
287 struct cmd_list_element *c,
290 fprintf_filtered (file,
291 _("Debugger's behavior regarding "
292 "pending breakpoints is %s.\n"),
296 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
297 set with "break" but falling in read-only memory.
298 If 0, gdb will warn about such breakpoints, but won't automatically
299 use hardware breakpoints. */
300 static int automatic_hardware_breakpoints;
302 show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty,
303 struct cmd_list_element *c,
306 fprintf_filtered (file,
307 _("Automatic usage of hardware breakpoints is %s.\n"),
311 /* If on, gdb will keep breakpoints inserted even as inferior is
312 stopped, and immediately insert any new breakpoints. If off, gdb
313 will insert breakpoints into inferior only when resuming it, and
314 will remove breakpoints upon stop. If auto, GDB will behave as ON
315 if in non-stop mode, and as OFF if all-stop mode.*/
317 static const char always_inserted_auto[] = "auto";
318 static const char always_inserted_on[] = "on";
319 static const char always_inserted_off[] = "off";
320 static const char *always_inserted_enums[] = {
321 always_inserted_auto,
326 static const char *always_inserted_mode = always_inserted_auto;
328 show_always_inserted_mode (struct ui_file *file, int from_tty,
329 struct cmd_list_element *c, const char *value)
331 if (always_inserted_mode == always_inserted_auto)
332 fprintf_filtered (file,
333 _("Always inserted breakpoint "
334 "mode is %s (currently %s).\n"),
336 breakpoints_always_inserted_mode () ? "on" : "off");
338 fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"),
343 breakpoints_always_inserted_mode (void)
345 return (always_inserted_mode == always_inserted_on
346 || (always_inserted_mode == always_inserted_auto && non_stop));
349 void _initialize_breakpoint (void);
351 /* Are we executing breakpoint commands? */
352 static int executing_breakpoint_commands;
354 /* Are overlay event breakpoints enabled? */
355 static int overlay_events_enabled;
357 /* See description in breakpoint.h. */
358 int target_exact_watchpoints = 0;
360 /* Walk the following statement or block through all breakpoints.
361 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the
362 current breakpoint. */
364 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
366 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
367 for (B = breakpoint_chain; \
368 B ? (TMP=B->next, 1): 0; \
371 /* Similar iterator for the low-level breakpoints. SAFE variant is
372 not provided so update_global_location_list must not be called
373 while executing the block of ALL_BP_LOCATIONS. */
375 #define ALL_BP_LOCATIONS(B,BP_TMP) \
376 for (BP_TMP = bp_location; \
377 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
380 /* Iterator for tracepoints only. */
382 #define ALL_TRACEPOINTS(B) \
383 for (B = breakpoint_chain; B; B = B->next) \
384 if (is_tracepoint (B))
386 /* Chains of all breakpoints defined. */
388 struct breakpoint *breakpoint_chain;
390 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
392 static struct bp_location **bp_location;
394 /* Number of elements of BP_LOCATION. */
396 static unsigned bp_location_count;
398 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
399 ADDRESS for the current elements of BP_LOCATION which get a valid
400 result from bp_location_has_shadow. You can use it for roughly
401 limiting the subrange of BP_LOCATION to scan for shadow bytes for
402 an address you need to read. */
404 static CORE_ADDR bp_location_placed_address_before_address_max;
406 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
407 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
408 BP_LOCATION which get a valid result from bp_location_has_shadow.
409 You can use it for roughly limiting the subrange of BP_LOCATION to
410 scan for shadow bytes for an address you need to read. */
412 static CORE_ADDR bp_location_shadow_len_after_address_max;
414 /* The locations that no longer correspond to any breakpoint, unlinked
415 from bp_location array, but for which a hit may still be reported
417 VEC(bp_location_p) *moribund_locations = NULL;
419 /* Number of last breakpoint made. */
421 static int breakpoint_count;
423 /* The value of `breakpoint_count' before the last command that
424 created breakpoints. If the last (break-like) command created more
425 than one breakpoint, then the difference between BREAKPOINT_COUNT
426 and PREV_BREAKPOINT_COUNT is more than one. */
427 static int prev_breakpoint_count;
429 /* Number of last tracepoint made. */
431 static int tracepoint_count;
433 static struct cmd_list_element *breakpoint_set_cmdlist;
434 static struct cmd_list_element *breakpoint_show_cmdlist;
435 struct cmd_list_element *save_cmdlist;
437 /* Return whether a breakpoint is an active enabled breakpoint. */
439 breakpoint_enabled (struct breakpoint *b)
441 return (b->enable_state == bp_enabled);
444 /* Set breakpoint count to NUM. */
447 set_breakpoint_count (int num)
449 prev_breakpoint_count = breakpoint_count;
450 breakpoint_count = num;
451 set_internalvar_integer (lookup_internalvar ("bpnum"), num);
454 /* Used by `start_rbreak_breakpoints' below, to record the current
455 breakpoint count before "rbreak" creates any breakpoint. */
456 static int rbreak_start_breakpoint_count;
458 /* Called at the start an "rbreak" command to record the first
462 start_rbreak_breakpoints (void)
464 rbreak_start_breakpoint_count = breakpoint_count;
467 /* Called at the end of an "rbreak" command to record the last
471 end_rbreak_breakpoints (void)
473 prev_breakpoint_count = rbreak_start_breakpoint_count;
476 /* Used in run_command to zero the hit count when a new run starts. */
479 clear_breakpoint_hit_counts (void)
481 struct breakpoint *b;
487 /* Allocate a new counted_command_line with reference count of 1.
488 The new structure owns COMMANDS. */
490 static struct counted_command_line *
491 alloc_counted_command_line (struct command_line *commands)
493 struct counted_command_line *result
494 = xmalloc (sizeof (struct counted_command_line));
497 result->commands = commands;
501 /* Increment reference count. This does nothing if CMD is NULL. */
504 incref_counted_command_line (struct counted_command_line *cmd)
510 /* Decrement reference count. If the reference count reaches 0,
511 destroy the counted_command_line. Sets *CMDP to NULL. This does
512 nothing if *CMDP is NULL. */
515 decref_counted_command_line (struct counted_command_line **cmdp)
519 if (--(*cmdp)->refc == 0)
521 free_command_lines (&(*cmdp)->commands);
528 /* A cleanup function that calls decref_counted_command_line. */
531 do_cleanup_counted_command_line (void *arg)
533 decref_counted_command_line (arg);
536 /* Create a cleanup that calls decref_counted_command_line on the
539 static struct cleanup *
540 make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp)
542 return make_cleanup (do_cleanup_counted_command_line, cmdp);
545 /* Default address, symtab and line to put a breakpoint at
546 for "break" command with no arg.
547 If default_breakpoint_valid is zero, the other three are
548 not valid, and "break" with no arg is an error.
550 This set by print_stack_frame, which calls set_default_breakpoint. */
552 int default_breakpoint_valid;
553 CORE_ADDR default_breakpoint_address;
554 struct symtab *default_breakpoint_symtab;
555 int default_breakpoint_line;
556 struct program_space *default_breakpoint_pspace;
559 /* Return the breakpoint with the specified number, or NULL
560 if the number does not refer to an existing breakpoint. */
563 get_breakpoint (int num)
565 struct breakpoint *b;
568 if (b->number == num)
577 set_breakpoint_condition (struct breakpoint *b, char *exp,
580 struct bp_location *loc = b->loc;
582 for (; loc; loc = loc->next)
587 xfree (b->cond_string);
588 b->cond_string = NULL;
595 printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number);
601 /* I don't know if it matters whether this is the string the user
602 typed in or the decompiled expression. */
603 b->cond_string = xstrdup (arg);
604 b->condition_not_parsed = 0;
606 if (is_watchpoint (b))
608 innermost_block = NULL;
610 b->cond_exp = parse_exp_1 (&arg, 0, 0);
612 error (_("Junk at end of expression"));
613 b->cond_exp_valid_block = innermost_block;
617 for (loc = b->loc; loc; loc = loc->next)
621 parse_exp_1 (&arg, block_for_pc (loc->address), 0);
623 error (_("Junk at end of expression"));
627 breakpoints_changed ();
628 observer_notify_breakpoint_modified (b);
631 /* condition N EXP -- set break condition of breakpoint N to EXP. */
634 condition_command (char *arg, int from_tty)
636 struct breakpoint *b;
641 error_no_arg (_("breakpoint number"));
644 bnum = get_number (&p);
646 error (_("Bad breakpoint argument: '%s'"), arg);
649 if (b->number == bnum)
651 /* Check if this breakpoint has a Python object assigned to
652 it, and if it has a definition of the "stop"
653 method. This method and conditions entered into GDB from
654 the CLI are mutually exclusive. */
656 && gdbpy_breakpoint_has_py_cond (b->py_bp_object))
657 error (_("Cannot set a condition where a Python 'stop' "
658 "method has been defined in the breakpoint."));
659 set_breakpoint_condition (b, p, from_tty);
663 error (_("No breakpoint number %d."), bnum);
666 /* Check that COMMAND do not contain commands that are suitable
667 only for tracepoints and not suitable for ordinary breakpoints.
668 Throw if any such commands is found. */
671 check_no_tracepoint_commands (struct command_line *commands)
673 struct command_line *c;
675 for (c = commands; c; c = c->next)
679 if (c->control_type == while_stepping_control)
680 error (_("The 'while-stepping' command can "
681 "only be used for tracepoints"));
683 for (i = 0; i < c->body_count; ++i)
684 check_no_tracepoint_commands ((c->body_list)[i]);
686 /* Not that command parsing removes leading whitespace and comment
687 lines and also empty lines. So, we only need to check for
689 if (strstr (c->line, "collect ") == c->line)
690 error (_("The 'collect' command can only be used for tracepoints"));
692 if (strstr (c->line, "teval ") == c->line)
693 error (_("The 'teval' command can only be used for tracepoints"));
697 /* Encapsulate tests for different types of tracepoints. */
700 is_tracepoint (const struct breakpoint *b)
702 return (b->type == bp_tracepoint
703 || b->type == bp_fast_tracepoint
704 || b->type == bp_static_tracepoint);
707 /* A helper function that validsates that COMMANDS are valid for a
708 breakpoint. This function will throw an exception if a problem is
712 validate_commands_for_breakpoint (struct breakpoint *b,
713 struct command_line *commands)
715 if (is_tracepoint (b))
717 /* We need to verify that each top-level element of commands is
718 valid for tracepoints, that there's at most one
719 while-stepping element, and that while-stepping's body has
720 valid tracing commands excluding nested while-stepping. */
721 struct command_line *c;
722 struct command_line *while_stepping = 0;
723 for (c = commands; c; c = c->next)
725 if (c->control_type == while_stepping_control)
727 if (b->type == bp_fast_tracepoint)
728 error (_("The 'while-stepping' command "
729 "cannot be used for fast tracepoint"));
730 else if (b->type == bp_static_tracepoint)
731 error (_("The 'while-stepping' command "
732 "cannot be used for static tracepoint"));
735 error (_("The 'while-stepping' command "
736 "can be used only once"));
743 struct command_line *c2;
745 gdb_assert (while_stepping->body_count == 1);
746 c2 = while_stepping->body_list[0];
747 for (; c2; c2 = c2->next)
749 if (c2->control_type == while_stepping_control)
750 error (_("The 'while-stepping' command cannot be nested"));
756 check_no_tracepoint_commands (commands);
760 /* Return a vector of all the static tracepoints set at ADDR. The
761 caller is responsible for releasing the vector. */
764 static_tracepoints_here (CORE_ADDR addr)
766 struct breakpoint *b;
767 VEC(breakpoint_p) *found = 0;
768 struct bp_location *loc;
771 if (b->type == bp_static_tracepoint)
773 for (loc = b->loc; loc; loc = loc->next)
774 if (loc->address == addr)
775 VEC_safe_push(breakpoint_p, found, b);
781 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
782 validate that only allowed commands are included. */
785 breakpoint_set_commands (struct breakpoint *b,
786 struct command_line *commands)
788 validate_commands_for_breakpoint (b, commands);
790 decref_counted_command_line (&b->commands);
791 b->commands = alloc_counted_command_line (commands);
792 breakpoints_changed ();
793 observer_notify_breakpoint_modified (b);
796 /* Set the internal `silent' flag on the breakpoint. Note that this
797 is not the same as the "silent" that may appear in the breakpoint's
801 breakpoint_set_silent (struct breakpoint *b, int silent)
803 int old_silent = b->silent;
806 if (old_silent != silent)
807 observer_notify_breakpoint_modified (b);
810 /* Set the thread for this breakpoint. If THREAD is -1, make the
811 breakpoint work for any thread. */
814 breakpoint_set_thread (struct breakpoint *b, int thread)
816 int old_thread = b->thread;
819 if (old_thread != thread)
820 observer_notify_breakpoint_modified (b);
823 /* Set the task for this breakpoint. If TASK is 0, make the
824 breakpoint work for any task. */
827 breakpoint_set_task (struct breakpoint *b, int task)
829 int old_task = b->task;
832 if (old_task != task)
833 observer_notify_breakpoint_modified (b);
837 check_tracepoint_command (char *line, void *closure)
839 struct breakpoint *b = closure;
841 validate_actionline (&line, b);
844 /* A structure used to pass information through
845 map_breakpoint_numbers. */
849 /* True if the command was typed at a tty. */
852 /* The breakpoint range spec. */
855 /* Non-NULL if the body of the commands are being read from this
856 already-parsed command. */
857 struct command_line *control;
859 /* The command lines read from the user, or NULL if they have not
861 struct counted_command_line *cmd;
864 /* A callback for map_breakpoint_numbers that sets the commands for
868 do_map_commands_command (struct breakpoint *b, void *data)
870 struct commands_info *info = data;
872 if (info->cmd == NULL)
874 struct command_line *l;
876 if (info->control != NULL)
877 l = copy_command_lines (info->control->body_list[0]);
880 struct cleanup *old_chain;
883 str = xstrprintf (_("Type commands for breakpoint(s) "
884 "%s, one per line."),
887 old_chain = make_cleanup (xfree, str);
889 l = read_command_lines (str,
892 ? check_tracepoint_command : 0),
895 do_cleanups (old_chain);
898 info->cmd = alloc_counted_command_line (l);
901 /* If a breakpoint was on the list more than once, we don't need to
903 if (b->commands != info->cmd)
905 validate_commands_for_breakpoint (b, info->cmd->commands);
906 incref_counted_command_line (info->cmd);
907 decref_counted_command_line (&b->commands);
908 b->commands = info->cmd;
909 breakpoints_changed ();
910 observer_notify_breakpoint_modified (b);
915 commands_command_1 (char *arg, int from_tty,
916 struct command_line *control)
918 struct cleanup *cleanups;
919 struct commands_info info;
921 info.from_tty = from_tty;
922 info.control = control;
924 /* If we read command lines from the user, then `info' will hold an
925 extra reference to the commands that we must clean up. */
926 cleanups = make_cleanup_decref_counted_command_line (&info.cmd);
928 if (arg == NULL || !*arg)
930 if (breakpoint_count - prev_breakpoint_count > 1)
931 arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1,
933 else if (breakpoint_count > 0)
934 arg = xstrprintf ("%d", breakpoint_count);
937 /* So that we don't try to free the incoming non-NULL
938 argument in the cleanup below. Mapping breakpoint
939 numbers will fail in this case. */
944 /* The command loop has some static state, so we need to preserve
949 make_cleanup (xfree, arg);
953 map_breakpoint_numbers (arg, do_map_commands_command, &info);
955 if (info.cmd == NULL)
956 error (_("No breakpoints specified."));
958 do_cleanups (cleanups);
962 commands_command (char *arg, int from_tty)
964 commands_command_1 (arg, from_tty, NULL);
967 /* Like commands_command, but instead of reading the commands from
968 input stream, takes them from an already parsed command structure.
970 This is used by cli-script.c to DTRT with breakpoint commands
971 that are part of if and while bodies. */
972 enum command_control_type
973 commands_from_control_command (char *arg, struct command_line *cmd)
975 commands_command_1 (arg, 0, cmd);
976 return simple_control;
979 /* Return non-zero if BL->TARGET_INFO contains valid information. */
982 bp_location_has_shadow (struct bp_location *bl)
984 if (bl->loc_type != bp_loc_software_breakpoint)
988 if (bl->target_info.shadow_len == 0)
989 /* bp isn't valid, or doesn't shadow memory. */
994 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
995 by replacing any memory breakpoints with their shadowed contents.
997 The range of shadowed area by each bp_location is:
998 bl->address - bp_location_placed_address_before_address_max
999 up to bl->address + bp_location_shadow_len_after_address_max
1000 The range we were requested to resolve shadows for is:
1001 memaddr ... memaddr + len
1002 Thus the safe cutoff boundaries for performance optimization are
1003 memaddr + len <= (bl->address
1004 - bp_location_placed_address_before_address_max)
1006 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1009 breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len)
1011 /* Left boundary, right boundary and median element of our binary
1013 unsigned bc_l, bc_r, bc;
1015 /* Find BC_L which is a leftmost element which may affect BUF
1016 content. It is safe to report lower value but a failure to
1017 report higher one. */
1020 bc_r = bp_location_count;
1021 while (bc_l + 1 < bc_r)
1023 struct bp_location *bl;
1025 bc = (bc_l + bc_r) / 2;
1026 bl = bp_location[bc];
1028 /* Check first BL->ADDRESS will not overflow due to the added
1029 constant. Then advance the left boundary only if we are sure
1030 the BC element can in no way affect the BUF content (MEMADDR
1031 to MEMADDR + LEN range).
1033 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1034 offset so that we cannot miss a breakpoint with its shadow
1035 range tail still reaching MEMADDR. */
1037 if ((bl->address + bp_location_shadow_len_after_address_max
1039 && (bl->address + bp_location_shadow_len_after_address_max
1046 /* Due to the binary search above, we need to make sure we pick the
1047 first location that's at BC_L's address. E.g., if there are
1048 multiple locations at the same address, BC_L may end up pointing
1049 at a duplicate location, and miss the "master"/"inserted"
1050 location. Say, given locations L1, L2 and L3 at addresses A and
1053 L1@A, L2@A, L3@B, ...
1055 BC_L could end up pointing at location L2, while the "master"
1056 location could be L1. Since the `loc->inserted' flag is only set
1057 on "master" locations, we'd forget to restore the shadow of L1
1060 && bp_location[bc_l]->address == bp_location[bc_l - 1]->address)
1063 /* Now do full processing of the found relevant range of elements. */
1065 for (bc = bc_l; bc < bp_location_count; bc++)
1067 struct bp_location *bl = bp_location[bc];
1068 CORE_ADDR bp_addr = 0;
1072 /* bp_location array has BL->OWNER always non-NULL. */
1073 if (bl->owner->type == bp_none)
1074 warning (_("reading through apparently deleted breakpoint #%d?"),
1077 /* Performance optimization: any futher element can no longer affect BUF
1080 if (bl->address >= bp_location_placed_address_before_address_max
1081 && memaddr + len <= (bl->address
1082 - bp_location_placed_address_before_address_max))
1085 if (!bp_location_has_shadow (bl))
1087 if (!breakpoint_address_match (bl->target_info.placed_address_space, 0,
1088 current_program_space->aspace, 0))
1091 /* Addresses and length of the part of the breakpoint that
1093 bp_addr = bl->target_info.placed_address;
1094 bp_size = bl->target_info.shadow_len;
1096 if (bp_addr + bp_size <= memaddr)
1097 /* The breakpoint is entirely before the chunk of memory we
1101 if (bp_addr >= memaddr + len)
1102 /* The breakpoint is entirely after the chunk of memory we are
1106 /* Offset within shadow_contents. */
1107 if (bp_addr < memaddr)
1109 /* Only copy the second part of the breakpoint. */
1110 bp_size -= memaddr - bp_addr;
1111 bptoffset = memaddr - bp_addr;
1115 if (bp_addr + bp_size > memaddr + len)
1117 /* Only copy the first part of the breakpoint. */
1118 bp_size -= (bp_addr + bp_size) - (memaddr + len);
1121 memcpy (buf + bp_addr - memaddr,
1122 bl->target_info.shadow_contents + bptoffset, bp_size);
1127 /* Return true if BPT is of any hardware watchpoint kind. */
1130 is_hardware_watchpoint (const struct breakpoint *bpt)
1132 return (bpt->type == bp_hardware_watchpoint
1133 || bpt->type == bp_read_watchpoint
1134 || bpt->type == bp_access_watchpoint);
1137 /* Return true if BPT is of any watchpoint kind, hardware or
1141 is_watchpoint (const struct breakpoint *bpt)
1143 return (is_hardware_watchpoint (bpt)
1144 || bpt->type == bp_watchpoint);
1147 /* Assuming that B is a watchpoint: returns true if the current thread
1148 and its running state are safe to evaluate or update watchpoint B.
1149 Watchpoints on local expressions need to be evaluated in the
1150 context of the thread that was current when the watchpoint was
1151 created, and, that thread needs to be stopped to be able to select
1152 the correct frame context. Watchpoints on global expressions can
1153 be evaluated on any thread, and in any state. It is presently left
1154 to the target allowing memory accesses when threads are
1158 watchpoint_in_thread_scope (struct breakpoint *b)
1160 return (ptid_equal (b->watchpoint_thread, null_ptid)
1161 || (ptid_equal (inferior_ptid, b->watchpoint_thread)
1162 && !is_executing (inferior_ptid)));
1165 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1166 associated bp_watchpoint_scope breakpoint. */
1169 watchpoint_del_at_next_stop (struct breakpoint *b)
1171 gdb_assert (is_watchpoint (b));
1173 if (b->related_breakpoint != b)
1175 gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope);
1176 gdb_assert (b->related_breakpoint->related_breakpoint == b);
1177 b->related_breakpoint->disposition = disp_del_at_next_stop;
1178 b->related_breakpoint->related_breakpoint = b->related_breakpoint;
1179 b->related_breakpoint = b;
1181 b->disposition = disp_del_at_next_stop;
1184 /* Assuming that B is a watchpoint:
1185 - Reparse watchpoint expression, if REPARSE is non-zero
1186 - Evaluate expression and store the result in B->val
1187 - Evaluate the condition if there is one, and store the result
1189 - Update the list of values that must be watched in B->loc.
1191 If the watchpoint disposition is disp_del_at_next_stop, then do
1192 nothing. If this is local watchpoint that is out of scope, delete
1195 Even with `set breakpoint always-inserted on' the watchpoints are
1196 removed + inserted on each stop here. Normal breakpoints must
1197 never be removed because they might be missed by a running thread
1198 when debugging in non-stop mode. On the other hand, hardware
1199 watchpoints (is_hardware_watchpoint; processed here) are specific
1200 to each LWP since they are stored in each LWP's hardware debug
1201 registers. Therefore, such LWP must be stopped first in order to
1202 be able to modify its hardware watchpoints.
1204 Hardware watchpoints must be reset exactly once after being
1205 presented to the user. It cannot be done sooner, because it would
1206 reset the data used to present the watchpoint hit to the user. And
1207 it must not be done later because it could display the same single
1208 watchpoint hit during multiple GDB stops. Note that the latter is
1209 relevant only to the hardware watchpoint types bp_read_watchpoint
1210 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1211 not user-visible - its hit is suppressed if the memory content has
1214 The following constraints influence the location where we can reset
1215 hardware watchpoints:
1217 * target_stopped_by_watchpoint and target_stopped_data_address are
1218 called several times when GDB stops.
1221 * Multiple hardware watchpoints can be hit at the same time,
1222 causing GDB to stop. GDB only presents one hardware watchpoint
1223 hit at a time as the reason for stopping, and all the other hits
1224 are presented later, one after the other, each time the user
1225 requests the execution to be resumed. Execution is not resumed
1226 for the threads still having pending hit event stored in
1227 LWP_INFO->STATUS. While the watchpoint is already removed from
1228 the inferior on the first stop the thread hit event is kept being
1229 reported from its cached value by linux_nat_stopped_data_address
1230 until the real thread resume happens after the watchpoint gets
1231 presented and thus its LWP_INFO->STATUS gets reset.
1233 Therefore the hardware watchpoint hit can get safely reset on the
1234 watchpoint removal from inferior. */
1237 update_watchpoint (struct breakpoint *b, int reparse)
1239 int within_current_scope;
1240 struct frame_id saved_frame_id;
1243 gdb_assert (is_watchpoint (b));
1245 /* If this is a local watchpoint, we only want to check if the
1246 watchpoint frame is in scope if the current thread is the thread
1247 that was used to create the watchpoint. */
1248 if (!watchpoint_in_thread_scope (b))
1251 if (b->disposition == disp_del_at_next_stop)
1256 /* Determine if the watchpoint is within scope. */
1257 if (b->exp_valid_block == NULL)
1258 within_current_scope = 1;
1261 struct frame_info *fi = get_current_frame ();
1262 struct gdbarch *frame_arch = get_frame_arch (fi);
1263 CORE_ADDR frame_pc = get_frame_pc (fi);
1265 /* If we're in a function epilogue, unwinding may not work
1266 properly, so do not attempt to recreate locations at this
1267 point. See similar comments in watchpoint_check. */
1268 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
1271 /* Save the current frame's ID so we can restore it after
1272 evaluating the watchpoint expression on its own frame. */
1273 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1274 took a frame parameter, so that we didn't have to change the
1277 saved_frame_id = get_frame_id (get_selected_frame (NULL));
1279 fi = frame_find_by_id (b->watchpoint_frame);
1280 within_current_scope = (fi != NULL);
1281 if (within_current_scope)
1285 /* We don't free locations. They are stored in the bp_location array
1286 and update_global_location_list will eventually delete them and
1287 remove breakpoints if needed. */
1290 if (within_current_scope && reparse)
1299 s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string;
1300 b->exp = parse_exp_1 (&s, b->exp_valid_block, 0);
1301 /* If the meaning of expression itself changed, the old value is
1302 no longer relevant. We don't want to report a watchpoint hit
1303 to the user when the old value and the new value may actually
1304 be completely different objects. */
1305 value_free (b->val);
1309 /* Note that unlike with breakpoints, the watchpoint's condition
1310 expression is stored in the breakpoint object, not in the
1311 locations (re)created below. */
1312 if (b->cond_string != NULL)
1314 if (b->cond_exp != NULL)
1316 xfree (b->cond_exp);
1321 b->cond_exp = parse_exp_1 (&s, b->cond_exp_valid_block, 0);
1325 /* If we failed to parse the expression, for example because
1326 it refers to a global variable in a not-yet-loaded shared library,
1327 don't try to insert watchpoint. We don't automatically delete
1328 such watchpoint, though, since failure to parse expression
1329 is different from out-of-scope watchpoint. */
1330 if ( !target_has_execution)
1332 /* Without execution, memory can't change. No use to try and
1333 set watchpoint locations. The watchpoint will be reset when
1334 the target gains execution, through breakpoint_re_set. */
1336 else if (within_current_scope && b->exp)
1339 struct value *val_chain, *v, *result, *next;
1340 struct program_space *frame_pspace;
1342 fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain);
1344 /* Avoid setting b->val if it's already set. The meaning of
1345 b->val is 'the last value' user saw, and we should update
1346 it only if we reported that last value to user. As it
1347 happens, the code that reports it updates b->val directly.
1348 We don't keep track of the memory value for masked
1350 if (!b->val_valid && !is_masked_watchpoint (b))
1356 frame_pspace = get_frame_program_space (get_selected_frame (NULL));
1358 /* Look at each value on the value chain. */
1359 for (v = val_chain; v; v = value_next (v))
1361 /* If it's a memory location, and GDB actually needed
1362 its contents to evaluate the expression, then we
1363 must watch it. If the first value returned is
1364 still lazy, that means an error occurred reading it;
1365 watch it anyway in case it becomes readable. */
1366 if (VALUE_LVAL (v) == lval_memory
1367 && (v == val_chain || ! value_lazy (v)))
1369 struct type *vtype = check_typedef (value_type (v));
1371 /* We only watch structs and arrays if user asked
1372 for it explicitly, never if they just happen to
1373 appear in the middle of some value chain. */
1375 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1376 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1380 struct bp_location *loc, **tmp;
1382 addr = value_address (v);
1383 len = TYPE_LENGTH (value_type (v));
1385 if (b->type == bp_read_watchpoint)
1387 else if (b->type == bp_access_watchpoint)
1390 loc = allocate_bp_location (b);
1391 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
1394 loc->gdbarch = get_type_arch (value_type (v));
1396 loc->pspace = frame_pspace;
1397 loc->address = addr;
1399 loc->watchpoint_type = type;
1404 /* Change the type of breakpoint between hardware assisted or
1405 an ordinary watchpoint depending on the hardware support
1406 and free hardware slots. REPARSE is set when the inferior
1411 enum bp_loc_type loc_type;
1412 struct bp_location *bl;
1414 reg_cnt = can_use_hardware_watchpoint (val_chain);
1418 int i, target_resources_ok, other_type_used;
1420 /* Use an exact watchpoint when there's only one memory region to be
1421 watched, and only one debug register is needed to watch it. */
1422 b->exact = target_exact_watchpoints && reg_cnt == 1;
1424 /* We need to determine how many resources are already
1425 used for all other hardware watchpoints plus this one
1426 to see if we still have enough resources to also fit
1427 this watchpoint in as well. To guarantee the
1428 hw_watchpoint_used_count call below counts this
1429 watchpoint, make sure that it is marked as a hardware
1431 if (b->type == bp_watchpoint)
1432 b->type = bp_hardware_watchpoint;
1434 i = hw_watchpoint_used_count (b->type, &other_type_used);
1435 target_resources_ok = target_can_use_hardware_watchpoint
1436 (b->type, i, other_type_used);
1437 if (target_resources_ok <= 0)
1439 /* If there's no works_in_software_mode method, we
1440 assume that the watchpoint works in software mode. */
1441 int sw_mode = (!b->ops || !b->ops->works_in_software_mode
1442 || b->ops->works_in_software_mode (b));
1444 if (target_resources_ok == 0 && !sw_mode)
1445 error (_("Target does not support this type of "
1446 "hardware watchpoint."));
1447 else if (target_resources_ok < 0 && !sw_mode)
1448 error (_("There are not enough available hardware "
1449 "resources for this watchpoint."));
1451 b->type = bp_watchpoint;
1454 else if (b->ops && b->ops->works_in_software_mode
1455 && !b->ops->works_in_software_mode (b))
1456 error (_("Expression cannot be implemented with "
1457 "read/access watchpoint."));
1459 b->type = bp_watchpoint;
1461 loc_type = (b->type == bp_watchpoint? bp_loc_other
1462 : bp_loc_hardware_watchpoint);
1463 for (bl = b->loc; bl; bl = bl->next)
1464 bl->loc_type = loc_type;
1467 for (v = val_chain; v; v = next)
1469 next = value_next (v);
1474 /* If a software watchpoint is not watching any memory, then the
1475 above left it without any location set up. But,
1476 bpstat_stop_status requires a location to be able to report
1477 stops, so make sure there's at least a dummy one. */
1478 if (b->type == bp_watchpoint && b->loc == NULL)
1480 b->loc = allocate_bp_location (b);
1481 b->loc->pspace = frame_pspace;
1482 b->loc->address = -1;
1483 b->loc->length = -1;
1484 b->loc->watchpoint_type = -1;
1487 else if (!within_current_scope)
1489 printf_filtered (_("\
1490 Watchpoint %d deleted because the program has left the block\n\
1491 in which its expression is valid.\n"),
1493 watchpoint_del_at_next_stop (b);
1496 /* Restore the selected frame. */
1498 select_frame (frame_find_by_id (saved_frame_id));
1502 /* Returns 1 iff breakpoint location should be
1503 inserted in the inferior. */
1505 should_be_inserted (struct bp_location *bl)
1507 if (bl->owner == NULL || !breakpoint_enabled (bl->owner))
1510 if (bl->owner->disposition == disp_del_at_next_stop)
1513 if (!bl->enabled || bl->shlib_disabled || bl->duplicate)
1516 /* This is set for example, when we're attached to the parent of a
1517 vfork, and have detached from the child. The child is running
1518 free, and we expect it to do an exec or exit, at which point the
1519 OS makes the parent schedulable again (and the target reports
1520 that the vfork is done). Until the child is done with the shared
1521 memory region, do not insert breakpoints in the parent, otherwise
1522 the child could still trip on the parent's breakpoints. Since
1523 the parent is blocked anyway, it won't miss any breakpoint. */
1524 if (bl->pspace->breakpoints_not_allowed)
1527 /* Tracepoints are inserted by the target at a time of its choosing,
1529 if (is_tracepoint (bl->owner))
1535 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
1536 location. Any error messages are printed to TMP_ERROR_STREAM; and
1537 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
1539 NOTE drow/2003-09-09: This routine could be broken down to an
1540 object-style method for each breakpoint or catchpoint type. */
1542 insert_bp_location (struct bp_location *bl,
1543 struct ui_file *tmp_error_stream,
1544 int *disabled_breaks,
1545 int *hw_breakpoint_error)
1549 if (!should_be_inserted (bl) || bl->inserted)
1552 /* Initialize the target-specific information. */
1553 memset (&bl->target_info, 0, sizeof (bl->target_info));
1554 bl->target_info.placed_address = bl->address;
1555 bl->target_info.placed_address_space = bl->pspace->aspace;
1556 bl->target_info.length = bl->length;
1558 if (bl->loc_type == bp_loc_software_breakpoint
1559 || bl->loc_type == bp_loc_hardware_breakpoint)
1561 if (bl->owner->type != bp_hardware_breakpoint)
1563 /* If the explicitly specified breakpoint type
1564 is not hardware breakpoint, check the memory map to see
1565 if the breakpoint address is in read only memory or not.
1567 Two important cases are:
1568 - location type is not hardware breakpoint, memory
1569 is readonly. We change the type of the location to
1570 hardware breakpoint.
1571 - location type is hardware breakpoint, memory is
1572 read-write. This means we've previously made the
1573 location hardware one, but then the memory map changed,
1576 When breakpoints are removed, remove_breakpoints will use
1577 location types we've just set here, the only possible
1578 problem is that memory map has changed during running
1579 program, but it's not going to work anyway with current
1581 struct mem_region *mr
1582 = lookup_mem_region (bl->target_info.placed_address);
1586 if (automatic_hardware_breakpoints)
1588 enum bp_loc_type new_type;
1590 if (mr->attrib.mode != MEM_RW)
1591 new_type = bp_loc_hardware_breakpoint;
1593 new_type = bp_loc_software_breakpoint;
1595 if (new_type != bl->loc_type)
1597 static int said = 0;
1599 bl->loc_type = new_type;
1602 fprintf_filtered (gdb_stdout,
1603 _("Note: automatically using "
1604 "hardware breakpoints for "
1605 "read-only addresses.\n"));
1610 else if (bl->loc_type == bp_loc_software_breakpoint
1611 && mr->attrib.mode != MEM_RW)
1612 warning (_("cannot set software breakpoint "
1613 "at readonly address %s"),
1614 paddress (bl->gdbarch, bl->address));
1618 /* First check to see if we have to handle an overlay. */
1619 if (overlay_debugging == ovly_off
1620 || bl->section == NULL
1621 || !(section_is_overlay (bl->section)))
1623 /* No overlay handling: just set the breakpoint. */
1625 if (bl->loc_type == bp_loc_hardware_breakpoint)
1626 val = target_insert_hw_breakpoint (bl->gdbarch,
1629 val = target_insert_breakpoint (bl->gdbarch,
1634 /* This breakpoint is in an overlay section.
1635 Shall we set a breakpoint at the LMA? */
1636 if (!overlay_events_enabled)
1638 /* Yes -- overlay event support is not active,
1639 so we must try to set a breakpoint at the LMA.
1640 This will not work for a hardware breakpoint. */
1641 if (bl->loc_type == bp_loc_hardware_breakpoint)
1642 warning (_("hardware breakpoint %d not supported in overlay!"),
1646 CORE_ADDR addr = overlay_unmapped_address (bl->address,
1648 /* Set a software (trap) breakpoint at the LMA. */
1649 bl->overlay_target_info = bl->target_info;
1650 bl->overlay_target_info.placed_address = addr;
1651 val = target_insert_breakpoint (bl->gdbarch,
1652 &bl->overlay_target_info);
1654 fprintf_unfiltered (tmp_error_stream,
1655 "Overlay breakpoint %d "
1656 "failed: in ROM?\n",
1660 /* Shall we set a breakpoint at the VMA? */
1661 if (section_is_mapped (bl->section))
1663 /* Yes. This overlay section is mapped into memory. */
1664 if (bl->loc_type == bp_loc_hardware_breakpoint)
1665 val = target_insert_hw_breakpoint (bl->gdbarch,
1668 val = target_insert_breakpoint (bl->gdbarch,
1673 /* No. This breakpoint will not be inserted.
1674 No error, but do not mark the bp as 'inserted'. */
1681 /* Can't set the breakpoint. */
1682 if (solib_name_from_address (bl->pspace, bl->address))
1684 /* See also: disable_breakpoints_in_shlibs. */
1686 bl->shlib_disabled = 1;
1687 observer_notify_breakpoint_modified (bl->owner);
1688 if (!*disabled_breaks)
1690 fprintf_unfiltered (tmp_error_stream,
1691 "Cannot insert breakpoint %d.\n",
1693 fprintf_unfiltered (tmp_error_stream,
1694 "Temporarily disabling shared "
1695 "library breakpoints:\n");
1697 *disabled_breaks = 1;
1698 fprintf_unfiltered (tmp_error_stream,
1699 "breakpoint #%d\n", bl->owner->number);
1703 if (bl->loc_type == bp_loc_hardware_breakpoint)
1705 *hw_breakpoint_error = 1;
1706 fprintf_unfiltered (tmp_error_stream,
1707 "Cannot insert hardware "
1713 fprintf_unfiltered (tmp_error_stream,
1714 "Cannot insert breakpoint %d.\n",
1716 fprintf_filtered (tmp_error_stream,
1717 "Error accessing memory address ");
1718 fputs_filtered (paddress (bl->gdbarch, bl->address),
1720 fprintf_filtered (tmp_error_stream, ": %s.\n",
1721 safe_strerror (val));
1732 else if (bl->loc_type == bp_loc_hardware_watchpoint
1733 /* NOTE drow/2003-09-08: This state only exists for removing
1734 watchpoints. It's not clear that it's necessary... */
1735 && bl->owner->disposition != disp_del_at_next_stop)
1737 gdb_assert (bl->owner->ops != NULL
1738 && bl->owner->ops->insert_location != NULL);
1740 val = bl->owner->ops->insert_location (bl);
1742 /* If trying to set a read-watchpoint, and it turns out it's not
1743 supported, try emulating one with an access watchpoint. */
1744 if (val == 1 && bl->watchpoint_type == hw_read)
1746 struct bp_location *loc, **loc_temp;
1748 /* But don't try to insert it, if there's already another
1749 hw_access location that would be considered a duplicate
1751 ALL_BP_LOCATIONS (loc, loc_temp)
1753 && loc->watchpoint_type == hw_access
1754 && watchpoint_locations_match (bl, loc))
1758 bl->target_info = loc->target_info;
1759 bl->watchpoint_type = hw_access;
1766 bl->watchpoint_type = hw_access;
1767 val = bl->owner->ops->insert_location (bl);
1770 /* Back to the original value. */
1771 bl->watchpoint_type = hw_read;
1775 bl->inserted = (val == 0);
1778 else if (bl->owner->type == bp_catchpoint)
1780 gdb_assert (bl->owner->ops != NULL
1781 && bl->owner->ops->insert_location != NULL);
1783 val = bl->owner->ops->insert_location (bl);
1786 bl->owner->enable_state = bp_disabled;
1790 Error inserting catchpoint %d: Your system does not support this type\n\
1791 of catchpoint."), bl->owner->number);
1793 warning (_("Error inserting catchpoint %d."), bl->owner->number);
1796 bl->inserted = (val == 0);
1798 /* We've already printed an error message if there was a problem
1799 inserting this catchpoint, and we've disabled the catchpoint,
1800 so just return success. */
1807 /* This function is called when program space PSPACE is about to be
1808 deleted. It takes care of updating breakpoints to not reference
1812 breakpoint_program_space_exit (struct program_space *pspace)
1814 struct breakpoint *b, *b_temp;
1815 struct bp_location *loc, **loc_temp;
1817 /* Remove any breakpoint that was set through this program space. */
1818 ALL_BREAKPOINTS_SAFE (b, b_temp)
1820 if (b->pspace == pspace)
1821 delete_breakpoint (b);
1824 /* Breakpoints set through other program spaces could have locations
1825 bound to PSPACE as well. Remove those. */
1826 ALL_BP_LOCATIONS (loc, loc_temp)
1828 struct bp_location *tmp;
1830 if (loc->pspace == pspace)
1832 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
1833 if (loc->owner->loc == loc)
1834 loc->owner->loc = loc->next;
1836 for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next)
1837 if (tmp->next == loc)
1839 tmp->next = loc->next;
1845 /* Now update the global location list to permanently delete the
1846 removed locations above. */
1847 update_global_location_list (0);
1850 /* Make sure all breakpoints are inserted in inferior.
1851 Throws exception on any error.
1852 A breakpoint that is already inserted won't be inserted
1853 again, so calling this function twice is safe. */
1855 insert_breakpoints (void)
1857 struct breakpoint *bpt;
1859 ALL_BREAKPOINTS (bpt)
1860 if (is_hardware_watchpoint (bpt))
1861 update_watchpoint (bpt, 0 /* don't reparse. */);
1863 update_global_location_list (1);
1865 /* update_global_location_list does not insert breakpoints when
1866 always_inserted_mode is not enabled. Explicitly insert them
1868 if (!breakpoints_always_inserted_mode ())
1869 insert_breakpoint_locations ();
1872 /* insert_breakpoints is used when starting or continuing the program.
1873 remove_breakpoints is used when the program stops.
1874 Both return zero if successful,
1875 or an `errno' value if could not write the inferior. */
1878 insert_breakpoint_locations (void)
1880 struct breakpoint *bpt;
1881 struct bp_location *bl, **blp_tmp;
1884 int disabled_breaks = 0;
1885 int hw_breakpoint_error = 0;
1887 struct ui_file *tmp_error_stream = mem_fileopen ();
1888 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
1890 /* Explicitly mark the warning -- this will only be printed if
1891 there was an error. */
1892 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
1894 save_current_space_and_thread ();
1896 ALL_BP_LOCATIONS (bl, blp_tmp)
1898 if (!should_be_inserted (bl) || bl->inserted)
1901 /* There is no point inserting thread-specific breakpoints if
1902 the thread no longer exists. ALL_BP_LOCATIONS bp_location
1903 has BL->OWNER always non-NULL. */
1904 if (bl->owner->thread != -1
1905 && !valid_thread_id (bl->owner->thread))
1908 switch_to_program_space_and_thread (bl->pspace);
1910 /* For targets that support global breakpoints, there's no need
1911 to select an inferior to insert breakpoint to. In fact, even
1912 if we aren't attached to any process yet, we should still
1913 insert breakpoints. */
1914 if (!gdbarch_has_global_breakpoints (target_gdbarch)
1915 && ptid_equal (inferior_ptid, null_ptid))
1918 val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
1919 &hw_breakpoint_error);
1924 /* If we failed to insert all locations of a watchpoint, remove
1925 them, as half-inserted watchpoint is of limited use. */
1926 ALL_BREAKPOINTS (bpt)
1928 int some_failed = 0;
1929 struct bp_location *loc;
1931 if (!is_hardware_watchpoint (bpt))
1934 if (!breakpoint_enabled (bpt))
1937 if (bpt->disposition == disp_del_at_next_stop)
1940 for (loc = bpt->loc; loc; loc = loc->next)
1941 if (!loc->inserted && should_be_inserted (loc))
1948 for (loc = bpt->loc; loc; loc = loc->next)
1950 remove_breakpoint (loc, mark_uninserted);
1952 hw_breakpoint_error = 1;
1953 fprintf_unfiltered (tmp_error_stream,
1954 "Could not insert hardware watchpoint %d.\n",
1962 /* If a hardware breakpoint or watchpoint was inserted, add a
1963 message about possibly exhausted resources. */
1964 if (hw_breakpoint_error)
1966 fprintf_unfiltered (tmp_error_stream,
1967 "Could not insert hardware breakpoints:\n\
1968 You may have requested too many hardware breakpoints/watchpoints.\n");
1970 target_terminal_ours_for_output ();
1971 error_stream (tmp_error_stream);
1974 do_cleanups (cleanups);
1978 remove_breakpoints (void)
1980 struct bp_location *bl, **blp_tmp;
1983 ALL_BP_LOCATIONS (bl, blp_tmp)
1986 val |= remove_breakpoint (bl, mark_uninserted);
1991 /* Remove breakpoints of process PID. */
1994 remove_breakpoints_pid (int pid)
1996 struct bp_location *bl, **blp_tmp;
1998 struct inferior *inf = find_inferior_pid (pid);
2000 ALL_BP_LOCATIONS (bl, blp_tmp)
2002 if (bl->pspace != inf->pspace)
2007 val = remove_breakpoint (bl, mark_uninserted);
2016 reattach_breakpoints (int pid)
2018 struct cleanup *old_chain;
2019 struct bp_location *bl, **blp_tmp;
2021 struct ui_file *tmp_error_stream;
2022 int dummy1 = 0, dummy2 = 0;
2023 struct inferior *inf;
2024 struct thread_info *tp;
2026 tp = any_live_thread_of_process (pid);
2030 inf = find_inferior_pid (pid);
2031 old_chain = save_inferior_ptid ();
2033 inferior_ptid = tp->ptid;
2035 tmp_error_stream = mem_fileopen ();
2036 make_cleanup_ui_file_delete (tmp_error_stream);
2038 ALL_BP_LOCATIONS (bl, blp_tmp)
2040 if (bl->pspace != inf->pspace)
2046 val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2);
2049 do_cleanups (old_chain);
2054 do_cleanups (old_chain);
2058 static int internal_breakpoint_number = -1;
2060 /* Set the breakpoint number of B, depending on the value of INTERNAL.
2061 If INTERNAL is non-zero, the breakpoint number will be populated
2062 from internal_breakpoint_number and that variable decremented.
2063 Otherwis the breakpoint number will be populated from
2064 breakpoint_count and that value incremented. Internal breakpoints
2065 do not set the internal var bpnum. */
2067 set_breakpoint_number (int internal, struct breakpoint *b)
2070 b->number = internal_breakpoint_number--;
2073 set_breakpoint_count (breakpoint_count + 1);
2074 b->number = breakpoint_count;
2078 static struct breakpoint *
2079 create_internal_breakpoint (struct gdbarch *gdbarch,
2080 CORE_ADDR address, enum bptype type)
2082 struct symtab_and_line sal;
2083 struct breakpoint *b;
2085 init_sal (&sal); /* Initialize to zeroes. */
2088 sal.section = find_pc_overlay (sal.pc);
2089 sal.pspace = current_program_space;
2091 b = set_raw_breakpoint (gdbarch, sal, type);
2092 b->number = internal_breakpoint_number--;
2093 b->disposition = disp_donttouch;
2098 static const char *const longjmp_names[] =
2100 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
2102 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
2104 /* Per-objfile data private to breakpoint.c. */
2105 struct breakpoint_objfile_data
2107 /* Minimal symbol for "_ovly_debug_event" (if any). */
2108 struct minimal_symbol *overlay_msym;
2110 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
2111 struct minimal_symbol *longjmp_msym[NUM_LONGJMP_NAMES];
2113 /* Minimal symbol for "std::terminate()" (if any). */
2114 struct minimal_symbol *terminate_msym;
2116 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
2117 struct minimal_symbol *exception_msym;
2120 static const struct objfile_data *breakpoint_objfile_key;
2122 /* Minimal symbol not found sentinel. */
2123 static struct minimal_symbol msym_not_found;
2125 /* Returns TRUE if MSYM point to the "not found" sentinel. */
2128 msym_not_found_p (const struct minimal_symbol *msym)
2130 return msym == &msym_not_found;
2133 /* Return per-objfile data needed by breakpoint.c.
2134 Allocate the data if necessary. */
2136 static struct breakpoint_objfile_data *
2137 get_breakpoint_objfile_data (struct objfile *objfile)
2139 struct breakpoint_objfile_data *bp_objfile_data;
2141 bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key);
2142 if (bp_objfile_data == NULL)
2144 bp_objfile_data = obstack_alloc (&objfile->objfile_obstack,
2145 sizeof (*bp_objfile_data));
2147 memset (bp_objfile_data, 0, sizeof (*bp_objfile_data));
2148 set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data);
2150 return bp_objfile_data;
2154 create_overlay_event_breakpoint (void)
2156 struct objfile *objfile;
2157 const char *const func_name = "_ovly_debug_event";
2159 ALL_OBJFILES (objfile)
2161 struct breakpoint *b;
2162 struct breakpoint_objfile_data *bp_objfile_data;
2165 bp_objfile_data = get_breakpoint_objfile_data (objfile);
2167 if (msym_not_found_p (bp_objfile_data->overlay_msym))
2170 if (bp_objfile_data->overlay_msym == NULL)
2172 struct minimal_symbol *m;
2174 m = lookup_minimal_symbol_text (func_name, objfile);
2177 /* Avoid future lookups in this objfile. */
2178 bp_objfile_data->overlay_msym = &msym_not_found;
2181 bp_objfile_data->overlay_msym = m;
2184 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym);
2185 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
2187 b->addr_string = xstrdup (func_name);
2189 if (overlay_debugging == ovly_auto)
2191 b->enable_state = bp_enabled;
2192 overlay_events_enabled = 1;
2196 b->enable_state = bp_disabled;
2197 overlay_events_enabled = 0;
2200 update_global_location_list (1);
2204 create_longjmp_master_breakpoint (void)
2206 struct program_space *pspace;
2207 struct cleanup *old_chain;
2209 old_chain = save_current_program_space ();
2211 ALL_PSPACES (pspace)
2213 struct objfile *objfile;
2215 set_current_program_space (pspace);
2217 ALL_OBJFILES (objfile)
2220 struct gdbarch *gdbarch;
2221 struct breakpoint_objfile_data *bp_objfile_data;
2223 gdbarch = get_objfile_arch (objfile);
2224 if (!gdbarch_get_longjmp_target_p (gdbarch))
2227 bp_objfile_data = get_breakpoint_objfile_data (objfile);
2229 for (i = 0; i < NUM_LONGJMP_NAMES; i++)
2231 struct breakpoint *b;
2232 const char *func_name;
2235 if (msym_not_found_p (bp_objfile_data->longjmp_msym[i]))
2238 func_name = longjmp_names[i];
2239 if (bp_objfile_data->longjmp_msym[i] == NULL)
2241 struct minimal_symbol *m;
2243 m = lookup_minimal_symbol_text (func_name, objfile);
2246 /* Prevent future lookups in this objfile. */
2247 bp_objfile_data->longjmp_msym[i] = &msym_not_found;
2250 bp_objfile_data->longjmp_msym[i] = m;
2253 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]);
2254 b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master);
2255 b->addr_string = xstrdup (func_name);
2256 b->enable_state = bp_disabled;
2260 update_global_location_list (1);
2262 do_cleanups (old_chain);
2265 /* Create a master std::terminate breakpoint. */
2267 create_std_terminate_master_breakpoint (void)
2269 struct program_space *pspace;
2270 struct cleanup *old_chain;
2271 const char *const func_name = "std::terminate()";
2273 old_chain = save_current_program_space ();
2275 ALL_PSPACES (pspace)
2277 struct objfile *objfile;
2280 set_current_program_space (pspace);
2282 ALL_OBJFILES (objfile)
2284 struct breakpoint *b;
2285 struct breakpoint_objfile_data *bp_objfile_data;
2287 bp_objfile_data = get_breakpoint_objfile_data (objfile);
2289 if (msym_not_found_p (bp_objfile_data->terminate_msym))
2292 if (bp_objfile_data->terminate_msym == NULL)
2294 struct minimal_symbol *m;
2296 m = lookup_minimal_symbol (func_name, NULL, objfile);
2297 if (m == NULL || (MSYMBOL_TYPE (m) != mst_text
2298 && MSYMBOL_TYPE (m) != mst_file_text))
2300 /* Prevent future lookups in this objfile. */
2301 bp_objfile_data->terminate_msym = &msym_not_found;
2304 bp_objfile_data->terminate_msym = m;
2307 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym);
2308 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
2309 bp_std_terminate_master);
2310 b->addr_string = xstrdup (func_name);
2311 b->enable_state = bp_disabled;
2315 update_global_location_list (1);
2317 do_cleanups (old_chain);
2320 /* Install a master breakpoint on the unwinder's debug hook. */
2323 create_exception_master_breakpoint (void)
2325 struct objfile *objfile;
2326 const char *const func_name = "_Unwind_DebugHook";
2328 ALL_OBJFILES (objfile)
2330 struct breakpoint *b;
2331 struct gdbarch *gdbarch;
2332 struct breakpoint_objfile_data *bp_objfile_data;
2335 bp_objfile_data = get_breakpoint_objfile_data (objfile);
2337 if (msym_not_found_p (bp_objfile_data->exception_msym))
2340 gdbarch = get_objfile_arch (objfile);
2342 if (bp_objfile_data->exception_msym == NULL)
2344 struct minimal_symbol *debug_hook;
2346 debug_hook = lookup_minimal_symbol (func_name, NULL, objfile);
2347 if (debug_hook == NULL)
2349 bp_objfile_data->exception_msym = &msym_not_found;
2353 bp_objfile_data->exception_msym = debug_hook;
2356 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym);
2357 addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
2359 b = create_internal_breakpoint (gdbarch, addr, bp_exception_master);
2360 b->addr_string = xstrdup (func_name);
2361 b->enable_state = bp_disabled;
2364 update_global_location_list (1);
2368 update_breakpoints_after_exec (void)
2370 struct breakpoint *b, *b_tmp;
2371 struct bp_location *bploc, **bplocp_tmp;
2373 /* We're about to delete breakpoints from GDB's lists. If the
2374 INSERTED flag is true, GDB will try to lift the breakpoints by
2375 writing the breakpoints' "shadow contents" back into memory. The
2376 "shadow contents" are NOT valid after an exec, so GDB should not
2377 do that. Instead, the target is responsible from marking
2378 breakpoints out as soon as it detects an exec. We don't do that
2379 here instead, because there may be other attempts to delete
2380 breakpoints after detecting an exec and before reaching here. */
2381 ALL_BP_LOCATIONS (bploc, bplocp_tmp)
2382 if (bploc->pspace == current_program_space)
2383 gdb_assert (!bploc->inserted);
2385 ALL_BREAKPOINTS_SAFE (b, b_tmp)
2387 if (b->pspace != current_program_space)
2390 /* Solib breakpoints must be explicitly reset after an exec(). */
2391 if (b->type == bp_shlib_event)
2393 delete_breakpoint (b);
2397 /* JIT breakpoints must be explicitly reset after an exec(). */
2398 if (b->type == bp_jit_event)
2400 delete_breakpoint (b);
2404 /* Thread event breakpoints must be set anew after an exec(),
2405 as must overlay event and longjmp master breakpoints. */
2406 if (b->type == bp_thread_event || b->type == bp_overlay_event
2407 || b->type == bp_longjmp_master || b->type == bp_std_terminate_master
2408 || b->type == bp_exception_master)
2410 delete_breakpoint (b);
2414 /* Step-resume breakpoints are meaningless after an exec(). */
2415 if (b->type == bp_step_resume || b->type == bp_hp_step_resume)
2417 delete_breakpoint (b);
2421 /* Longjmp and longjmp-resume breakpoints are also meaningless
2423 if (b->type == bp_longjmp || b->type == bp_longjmp_resume
2424 || b->type == bp_exception || b->type == bp_exception_resume)
2426 delete_breakpoint (b);
2430 if (b->type == bp_catchpoint)
2432 /* For now, none of the bp_catchpoint breakpoints need to
2433 do anything at this point. In the future, if some of
2434 the catchpoints need to something, we will need to add
2435 a new method, and call this method from here. */
2439 /* bp_finish is a special case. The only way we ought to be able
2440 to see one of these when an exec() has happened, is if the user
2441 caught a vfork, and then said "finish". Ordinarily a finish just
2442 carries them to the call-site of the current callee, by setting
2443 a temporary bp there and resuming. But in this case, the finish
2444 will carry them entirely through the vfork & exec.
2446 We don't want to allow a bp_finish to remain inserted now. But
2447 we can't safely delete it, 'cause finish_command has a handle to
2448 the bp on a bpstat, and will later want to delete it. There's a
2449 chance (and I've seen it happen) that if we delete the bp_finish
2450 here, that its storage will get reused by the time finish_command
2451 gets 'round to deleting the "use to be a bp_finish" breakpoint.
2452 We really must allow finish_command to delete a bp_finish.
2454 In the absense of a general solution for the "how do we know
2455 it's safe to delete something others may have handles to?"
2456 problem, what we'll do here is just uninsert the bp_finish, and
2457 let finish_command delete it.
2459 (We know the bp_finish is "doomed" in the sense that it's
2460 momentary, and will be deleted as soon as finish_command sees
2461 the inferior stopped. So it doesn't matter that the bp's
2462 address is probably bogus in the new a.out, unlike e.g., the
2463 solib breakpoints.) */
2465 if (b->type == bp_finish)
2470 /* Without a symbolic address, we have little hope of the
2471 pre-exec() address meaning the same thing in the post-exec()
2473 if (b->addr_string == NULL)
2475 delete_breakpoint (b);
2479 /* FIXME what about longjmp breakpoints? Re-create them here? */
2480 create_overlay_event_breakpoint ();
2481 create_longjmp_master_breakpoint ();
2482 create_std_terminate_master_breakpoint ();
2483 create_exception_master_breakpoint ();
2487 detach_breakpoints (int pid)
2489 struct bp_location *bl, **blp_tmp;
2491 struct cleanup *old_chain = save_inferior_ptid ();
2492 struct inferior *inf = current_inferior ();
2494 if (pid == PIDGET (inferior_ptid))
2495 error (_("Cannot detach breakpoints of inferior_ptid"));
2497 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
2498 inferior_ptid = pid_to_ptid (pid);
2499 ALL_BP_LOCATIONS (bl, blp_tmp)
2501 if (bl->pspace != inf->pspace)
2505 val |= remove_breakpoint_1 (bl, mark_inserted);
2508 /* Detach single-step breakpoints as well. */
2509 detach_single_step_breakpoints ();
2511 do_cleanups (old_chain);
2515 /* Remove the breakpoint location BL from the current address space.
2516 Note that this is used to detach breakpoints from a child fork.
2517 When we get here, the child isn't in the inferior list, and neither
2518 do we have objects to represent its address space --- we should
2519 *not* look at bl->pspace->aspace here. */
2522 remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is)
2526 /* BL is never in moribund_locations by our callers. */
2527 gdb_assert (bl->owner != NULL);
2529 if (bl->owner->enable_state == bp_permanent)
2530 /* Permanent breakpoints cannot be inserted or removed. */
2533 /* The type of none suggests that owner is actually deleted.
2534 This should not ever happen. */
2535 gdb_assert (bl->owner->type != bp_none);
2537 if (bl->loc_type == bp_loc_software_breakpoint
2538 || bl->loc_type == bp_loc_hardware_breakpoint)
2540 /* "Normal" instruction breakpoint: either the standard
2541 trap-instruction bp (bp_breakpoint), or a
2542 bp_hardware_breakpoint. */
2544 /* First check to see if we have to handle an overlay. */
2545 if (overlay_debugging == ovly_off
2546 || bl->section == NULL
2547 || !(section_is_overlay (bl->section)))
2549 /* No overlay handling: just remove the breakpoint. */
2551 if (bl->loc_type == bp_loc_hardware_breakpoint)
2552 val = target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info);
2554 val = target_remove_breakpoint (bl->gdbarch, &bl->target_info);
2558 /* This breakpoint is in an overlay section.
2559 Did we set a breakpoint at the LMA? */
2560 if (!overlay_events_enabled)
2562 /* Yes -- overlay event support is not active, so we
2563 should have set a breakpoint at the LMA. Remove it.
2565 /* Ignore any failures: if the LMA is in ROM, we will
2566 have already warned when we failed to insert it. */
2567 if (bl->loc_type == bp_loc_hardware_breakpoint)
2568 target_remove_hw_breakpoint (bl->gdbarch,
2569 &bl->overlay_target_info);
2571 target_remove_breakpoint (bl->gdbarch,
2572 &bl->overlay_target_info);
2574 /* Did we set a breakpoint at the VMA?
2575 If so, we will have marked the breakpoint 'inserted'. */
2578 /* Yes -- remove it. Previously we did not bother to
2579 remove the breakpoint if the section had been
2580 unmapped, but let's not rely on that being safe. We
2581 don't know what the overlay manager might do. */
2582 if (bl->loc_type == bp_loc_hardware_breakpoint)
2583 val = target_remove_hw_breakpoint (bl->gdbarch,
2586 /* However, we should remove *software* breakpoints only
2587 if the section is still mapped, or else we overwrite
2588 wrong code with the saved shadow contents. */
2589 else if (section_is_mapped (bl->section))
2590 val = target_remove_breakpoint (bl->gdbarch,
2597 /* No -- not inserted, so no need to remove. No error. */
2602 /* In some cases, we might not be able to remove a breakpoint
2603 in a shared library that has already been removed, but we
2604 have not yet processed the shlib unload event. */
2605 if (val && solib_name_from_address (bl->pspace, bl->address))
2610 bl->inserted = (is == mark_inserted);
2612 else if (bl->loc_type == bp_loc_hardware_watchpoint)
2614 gdb_assert (bl->owner->ops != NULL
2615 && bl->owner->ops->remove_location != NULL);
2617 bl->inserted = (is == mark_inserted);
2618 bl->owner->ops->remove_location (bl);
2620 /* Failure to remove any of the hardware watchpoints comes here. */
2621 if ((is == mark_uninserted) && (bl->inserted))
2622 warning (_("Could not remove hardware watchpoint %d."),
2625 else if (bl->owner->type == bp_catchpoint
2626 && breakpoint_enabled (bl->owner)
2629 gdb_assert (bl->owner->ops != NULL
2630 && bl->owner->ops->remove_location != NULL);
2632 val = bl->owner->ops->remove_location (bl);
2636 bl->inserted = (is == mark_inserted);
2643 remove_breakpoint (struct bp_location *bl, insertion_state_t is)
2646 struct cleanup *old_chain;
2648 /* BL is never in moribund_locations by our callers. */
2649 gdb_assert (bl->owner != NULL);
2651 if (bl->owner->enable_state == bp_permanent)
2652 /* Permanent breakpoints cannot be inserted or removed. */
2655 /* The type of none suggests that owner is actually deleted.
2656 This should not ever happen. */
2657 gdb_assert (bl->owner->type != bp_none);
2659 old_chain = save_current_space_and_thread ();
2661 switch_to_program_space_and_thread (bl->pspace);
2663 ret = remove_breakpoint_1 (bl, is);
2665 do_cleanups (old_chain);
2669 /* Clear the "inserted" flag in all breakpoints. */
2672 mark_breakpoints_out (void)
2674 struct bp_location *bl, **blp_tmp;
2676 ALL_BP_LOCATIONS (bl, blp_tmp)
2677 if (bl->pspace == current_program_space)
2681 /* Clear the "inserted" flag in all breakpoints and delete any
2682 breakpoints which should go away between runs of the program.
2684 Plus other such housekeeping that has to be done for breakpoints
2687 Note: this function gets called at the end of a run (by
2688 generic_mourn_inferior) and when a run begins (by
2689 init_wait_for_inferior). */
2694 breakpoint_init_inferior (enum inf_context context)
2696 struct breakpoint *b, *b_tmp;
2697 struct bp_location *bl, **blp_tmp;
2699 struct program_space *pspace = current_program_space;
2701 /* If breakpoint locations are shared across processes, then there's
2703 if (gdbarch_has_global_breakpoints (target_gdbarch))
2706 ALL_BP_LOCATIONS (bl, blp_tmp)
2708 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
2709 if (bl->pspace == pspace
2710 && bl->owner->enable_state != bp_permanent)
2714 ALL_BREAKPOINTS_SAFE (b, b_tmp)
2716 if (b->loc && b->loc->pspace != pspace)
2723 /* If the call dummy breakpoint is at the entry point it will
2724 cause problems when the inferior is rerun, so we better get
2727 case bp_watchpoint_scope:
2729 /* Also get rid of scope breakpoints. */
2731 case bp_shlib_event:
2733 /* Also remove solib event breakpoints. Their addresses may
2734 have changed since the last time we ran the program.
2735 Actually we may now be debugging against different target;
2736 and so the solib backend that installed this breakpoint may
2737 not be used in by the target. E.g.,
2739 (gdb) file prog-linux
2740 (gdb) run # native linux target
2743 (gdb) file prog-win.exe
2744 (gdb) tar rem :9999 # remote Windows gdbserver.
2747 delete_breakpoint (b);
2751 case bp_hardware_watchpoint:
2752 case bp_read_watchpoint:
2753 case bp_access_watchpoint:
2755 /* Likewise for watchpoints on local expressions. */
2756 if (b->exp_valid_block != NULL)
2757 delete_breakpoint (b);
2758 else if (context == inf_starting)
2760 /* Reset val field to force reread of starting value in
2761 insert_breakpoints. */
2763 value_free (b->val);
2773 /* Get rid of the moribund locations. */
2774 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix)
2775 decref_bp_location (&bl);
2776 VEC_free (bp_location_p, moribund_locations);
2779 /* These functions concern about actual breakpoints inserted in the
2780 target --- to e.g. check if we need to do decr_pc adjustment or if
2781 we need to hop over the bkpt --- so we check for address space
2782 match, not program space. */
2784 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2785 exists at PC. It returns ordinary_breakpoint_here if it's an
2786 ordinary breakpoint, or permanent_breakpoint_here if it's a
2787 permanent breakpoint.
2788 - When continuing from a location with an ordinary breakpoint, we
2789 actually single step once before calling insert_breakpoints.
2790 - When continuing from a localion with a permanent breakpoint, we
2791 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2792 the target, to advance the PC past the breakpoint. */
2794 enum breakpoint_here
2795 breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
2797 struct bp_location *bl, **blp_tmp;
2798 int any_breakpoint_here = 0;
2800 ALL_BP_LOCATIONS (bl, blp_tmp)
2802 if (bl->loc_type != bp_loc_software_breakpoint
2803 && bl->loc_type != bp_loc_hardware_breakpoint)
2806 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
2807 if ((breakpoint_enabled (bl->owner)
2808 || bl->owner->enable_state == bp_permanent)
2809 && breakpoint_location_address_match (bl, aspace, pc))
2811 if (overlay_debugging
2812 && section_is_overlay (bl->section)
2813 && !section_is_mapped (bl->section))
2814 continue; /* unmapped overlay -- can't be a match */
2815 else if (bl->owner->enable_state == bp_permanent)
2816 return permanent_breakpoint_here;
2818 any_breakpoint_here = 1;
2822 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
2825 /* Return true if there's a moribund breakpoint at PC. */
2828 moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
2830 struct bp_location *loc;
2833 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
2834 if (breakpoint_location_address_match (loc, aspace, pc))
2840 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2841 inserted using regular breakpoint_chain / bp_location array
2842 mechanism. This does not check for single-step breakpoints, which
2843 are inserted and removed using direct target manipulation. */
2846 regular_breakpoint_inserted_here_p (struct address_space *aspace,
2849 struct bp_location *bl, **blp_tmp;
2851 ALL_BP_LOCATIONS (bl, blp_tmp)
2853 if (bl->loc_type != bp_loc_software_breakpoint
2854 && bl->loc_type != bp_loc_hardware_breakpoint)
2858 && breakpoint_location_address_match (bl, aspace, pc))
2860 if (overlay_debugging
2861 && section_is_overlay (bl->section)
2862 && !section_is_mapped (bl->section))
2863 continue; /* unmapped overlay -- can't be a match */
2871 /* Returns non-zero iff there's either regular breakpoint
2872 or a single step breakpoint inserted at PC. */
2875 breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
2877 if (regular_breakpoint_inserted_here_p (aspace, pc))
2880 if (single_step_breakpoint_inserted_here_p (aspace, pc))
2886 /* This function returns non-zero iff there is a software breakpoint
2890 software_breakpoint_inserted_here_p (struct address_space *aspace,
2893 struct bp_location *bl, **blp_tmp;
2895 ALL_BP_LOCATIONS (bl, blp_tmp)
2897 if (bl->loc_type != bp_loc_software_breakpoint)
2901 && breakpoint_address_match (bl->pspace->aspace, bl->address,
2904 if (overlay_debugging
2905 && section_is_overlay (bl->section)
2906 && !section_is_mapped (bl->section))
2907 continue; /* unmapped overlay -- can't be a match */
2913 /* Also check for software single-step breakpoints. */
2914 if (single_step_breakpoint_inserted_here_p (aspace, pc))
2921 hardware_watchpoint_inserted_in_range (struct address_space *aspace,
2922 CORE_ADDR addr, ULONGEST len)
2924 struct breakpoint *bpt;
2926 ALL_BREAKPOINTS (bpt)
2928 struct bp_location *loc;
2930 if (bpt->type != bp_hardware_watchpoint
2931 && bpt->type != bp_access_watchpoint)
2934 if (!breakpoint_enabled (bpt))
2937 for (loc = bpt->loc; loc; loc = loc->next)
2938 if (loc->pspace->aspace == aspace && loc->inserted)
2942 /* Check for intersection. */
2943 l = max (loc->address, addr);
2944 h = min (loc->address + loc->length, addr + len);
2952 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
2953 PC is valid for process/thread PTID. */
2956 breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc,
2959 struct bp_location *bl, **blp_tmp;
2960 /* The thread and task IDs associated to PTID, computed lazily. */
2964 ALL_BP_LOCATIONS (bl, blp_tmp)
2966 if (bl->loc_type != bp_loc_software_breakpoint
2967 && bl->loc_type != bp_loc_hardware_breakpoint)
2970 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
2971 if (!breakpoint_enabled (bl->owner)
2972 && bl->owner->enable_state != bp_permanent)
2975 if (!breakpoint_location_address_match (bl, aspace, pc))
2978 if (bl->owner->thread != -1)
2980 /* This is a thread-specific breakpoint. Check that ptid
2981 matches that thread. If thread hasn't been computed yet,
2982 it is now time to do so. */
2984 thread = pid_to_thread_id (ptid);
2985 if (bl->owner->thread != thread)
2989 if (bl->owner->task != 0)
2991 /* This is a task-specific breakpoint. Check that ptid
2992 matches that task. If task hasn't been computed yet,
2993 it is now time to do so. */
2995 task = ada_get_task_number (ptid);
2996 if (bl->owner->task != task)
3000 if (overlay_debugging
3001 && section_is_overlay (bl->section)
3002 && !section_is_mapped (bl->section))
3003 continue; /* unmapped overlay -- can't be a match */
3012 /* bpstat stuff. External routines' interfaces are documented
3016 ep_is_catchpoint (struct breakpoint *ep)
3018 return (ep->type == bp_catchpoint);
3021 /* Frees any storage that is part of a bpstat. Does not walk the
3025 bpstat_free (bpstat bs)
3027 if (bs->old_val != NULL)
3028 value_free (bs->old_val);
3029 decref_counted_command_line (&bs->commands);
3030 decref_bp_location (&bs->bp_location_at);
3034 /* Clear a bpstat so that it says we are not at any breakpoint.
3035 Also free any storage that is part of a bpstat. */
3038 bpstat_clear (bpstat *bsp)
3055 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
3056 is part of the bpstat is copied as well. */
3059 bpstat_copy (bpstat bs)
3063 bpstat retval = NULL;
3068 for (; bs != NULL; bs = bs->next)
3070 tmp = (bpstat) xmalloc (sizeof (*tmp));
3071 memcpy (tmp, bs, sizeof (*tmp));
3072 incref_counted_command_line (tmp->commands);
3073 incref_bp_location (tmp->bp_location_at);
3074 if (bs->old_val != NULL)
3076 tmp->old_val = value_copy (bs->old_val);
3077 release_value (tmp->old_val);
3081 /* This is the first thing in the chain. */
3091 /* Find the bpstat associated with this breakpoint. */
3094 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
3099 for (; bsp != NULL; bsp = bsp->next)
3101 if (bsp->breakpoint_at == breakpoint)
3107 /* Put in *NUM the breakpoint number of the first breakpoint we are
3108 stopped at. *BSP upon return is a bpstat which points to the
3109 remaining breakpoints stopped at (but which is not guaranteed to be
3110 good for anything but further calls to bpstat_num).
3112 Return 0 if passed a bpstat which does not indicate any breakpoints.
3113 Return -1 if stopped at a breakpoint that has been deleted since
3115 Return 1 otherwise. */
3118 bpstat_num (bpstat *bsp, int *num)
3120 struct breakpoint *b;
3123 return 0; /* No more breakpoint values */
3125 /* We assume we'll never have several bpstats that correspond to a
3126 single breakpoint -- otherwise, this function might return the
3127 same number more than once and this will look ugly. */
3128 b = (*bsp)->breakpoint_at;
3129 *bsp = (*bsp)->next;
3131 return -1; /* breakpoint that's been deleted since */
3133 *num = b->number; /* We have its number */
3137 /* Modify BS so that the actions will not be performed. */
3140 bpstat_clear_actions (bpstat bs)
3142 for (; bs != NULL; bs = bs->next)
3144 decref_counted_command_line (&bs->commands);
3145 bs->commands_left = NULL;
3146 if (bs->old_val != NULL)
3148 value_free (bs->old_val);
3154 /* Called when a command is about to proceed the inferior. */
3157 breakpoint_about_to_proceed (void)
3159 if (!ptid_equal (inferior_ptid, null_ptid))
3161 struct thread_info *tp = inferior_thread ();
3163 /* Allow inferior function calls in breakpoint commands to not
3164 interrupt the command list. When the call finishes
3165 successfully, the inferior will be standing at the same
3166 breakpoint as if nothing happened. */
3167 if (tp->control.in_infcall)
3171 breakpoint_proceeded = 1;
3174 /* Stub for cleaning up our state if we error-out of a breakpoint
3177 cleanup_executing_breakpoints (void *ignore)
3179 executing_breakpoint_commands = 0;
3182 /* Execute all the commands associated with all the breakpoints at
3183 this location. Any of these commands could cause the process to
3184 proceed beyond this point, etc. We look out for such changes by
3185 checking the global "breakpoint_proceeded" after each command.
3187 Returns true if a breakpoint command resumed the inferior. In that
3188 case, it is the caller's responsibility to recall it again with the
3189 bpstat of the current thread. */
3192 bpstat_do_actions_1 (bpstat *bsp)
3195 struct cleanup *old_chain;
3198 /* Avoid endless recursion if a `source' command is contained
3200 if (executing_breakpoint_commands)
3203 executing_breakpoint_commands = 1;
3204 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
3206 prevent_dont_repeat ();
3208 /* This pointer will iterate over the list of bpstat's. */
3211 breakpoint_proceeded = 0;
3212 for (; bs != NULL; bs = bs->next)
3214 struct counted_command_line *ccmd;
3215 struct command_line *cmd;
3216 struct cleanup *this_cmd_tree_chain;
3218 /* Take ownership of the BSP's command tree, if it has one.
3220 The command tree could legitimately contain commands like
3221 'step' and 'next', which call clear_proceed_status, which
3222 frees stop_bpstat's command tree. To make sure this doesn't
3223 free the tree we're executing out from under us, we need to
3224 take ownership of the tree ourselves. Since a given bpstat's
3225 commands are only executed once, we don't need to copy it; we
3226 can clear the pointer in the bpstat, and make sure we free
3227 the tree when we're done. */
3228 ccmd = bs->commands;
3229 bs->commands = NULL;
3231 = make_cleanup_decref_counted_command_line (&ccmd);
3232 cmd = bs->commands_left;
3233 bs->commands_left = NULL;
3237 execute_control_command (cmd);
3239 if (breakpoint_proceeded)
3245 /* We can free this command tree now. */
3246 do_cleanups (this_cmd_tree_chain);
3248 if (breakpoint_proceeded)
3250 if (target_can_async_p ())
3251 /* If we are in async mode, then the target might be still
3252 running, not stopped at any breakpoint, so nothing for
3253 us to do here -- just return to the event loop. */
3256 /* In sync mode, when execute_control_command returns
3257 we're already standing on the next breakpoint.
3258 Breakpoint commands for that stop were not run, since
3259 execute_command does not run breakpoint commands --
3260 only command_line_handler does, but that one is not
3261 involved in execution of breakpoint commands. So, we
3262 can now execute breakpoint commands. It should be
3263 noted that making execute_command do bpstat actions is
3264 not an option -- in this case we'll have recursive
3265 invocation of bpstat for each breakpoint with a
3266 command, and can easily blow up GDB stack. Instead, we
3267 return true, which will trigger the caller to recall us
3268 with the new stop_bpstat. */
3273 do_cleanups (old_chain);
3278 bpstat_do_actions (void)
3280 /* Do any commands attached to breakpoint we are stopped at. */
3281 while (!ptid_equal (inferior_ptid, null_ptid)
3282 && target_has_execution
3283 && !is_exited (inferior_ptid)
3284 && !is_executing (inferior_ptid))
3285 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3286 and only return when it is stopped at the next breakpoint, we
3287 keep doing breakpoint actions until it returns false to
3288 indicate the inferior was not resumed. */
3289 if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat))
3293 /* Print out the (old or new) value associated with a watchpoint. */
3296 watchpoint_value_print (struct value *val, struct ui_file *stream)
3299 fprintf_unfiltered (stream, _("<unreadable>"));
3302 struct value_print_options opts;
3303 get_user_print_options (&opts);
3304 value_print (val, stream, &opts);
3308 /* This is the normal print function for a bpstat. In the future,
3309 much of this logic could (should?) be moved to bpstat_stop_status,
3310 by having it set different print_it values.
3312 Current scheme: When we stop, bpstat_print() is called. It loops
3313 through the bpstat list of things causing this stop, calling the
3314 print_bp_stop_message function on each one. The behavior of the
3315 print_bp_stop_message function depends on the print_it field of
3316 bpstat. If such field so indicates, call this function here.
3318 Return values from this routine (ultimately used by bpstat_print()
3319 and normal_stop() to decide what to do):
3320 PRINT_NOTHING: Means we already printed all we needed to print,
3321 don't print anything else.
3322 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
3323 that something to be followed by a location.
3324 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
3325 that something to be followed by a location.
3326 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
3329 static enum print_stop_action
3330 print_it_typical (bpstat bs)
3332 struct cleanup *old_chain;
3333 struct breakpoint *b;
3334 const struct bp_location *bl;
3335 struct ui_stream *stb;
3337 enum print_stop_action result;
3339 gdb_assert (bs->bp_location_at != NULL);
3341 bl = bs->bp_location_at;
3342 b = bs->breakpoint_at;
3344 stb = ui_out_stream_new (uiout);
3345 old_chain = make_cleanup_ui_out_stream_delete (stb);
3350 case bp_hardware_breakpoint:
3351 bp_temp = b->disposition == disp_del;
3352 if (bl->address != bl->requested_address)
3353 breakpoint_adjustment_warning (bl->requested_address,
3356 annotate_breakpoint (b->number);
3358 ui_out_text (uiout, "\nTemporary breakpoint ");
3360 ui_out_text (uiout, "\nBreakpoint ");
3361 if (ui_out_is_mi_like_p (uiout))
3363 ui_out_field_string (uiout, "reason",
3364 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
3365 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
3367 ui_out_field_int (uiout, "bkptno", b->number);
3368 ui_out_text (uiout, ", ");
3369 result = PRINT_SRC_AND_LOC;
3372 case bp_shlib_event:
3373 /* Did we stop because the user set the stop_on_solib_events
3374 variable? (If so, we report this as a generic, "Stopped due
3375 to shlib event" message.) */
3376 printf_filtered (_("Stopped due to shared library event\n"));
3377 result = PRINT_NOTHING;
3380 case bp_thread_event:
3381 /* Not sure how we will get here.
3382 GDB should not stop for these breakpoints. */
3383 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
3384 result = PRINT_NOTHING;
3387 case bp_overlay_event:
3388 /* By analogy with the thread event, GDB should not stop for these. */
3389 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
3390 result = PRINT_NOTHING;
3393 case bp_longjmp_master:
3394 /* These should never be enabled. */
3395 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
3396 result = PRINT_NOTHING;
3399 case bp_std_terminate_master:
3400 /* These should never be enabled. */
3401 printf_filtered (_("std::terminate Master Breakpoint: "
3402 "gdb should not stop!\n"));
3403 result = PRINT_NOTHING;
3406 case bp_exception_master:
3407 /* These should never be enabled. */
3408 printf_filtered (_("Exception Master Breakpoint: "
3409 "gdb should not stop!\n"));
3410 result = PRINT_NOTHING;
3414 case bp_hardware_watchpoint:
3415 annotate_watchpoint (b->number);
3416 if (ui_out_is_mi_like_p (uiout))
3419 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
3421 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
3422 ui_out_text (uiout, "\nOld value = ");
3423 watchpoint_value_print (bs->old_val, stb->stream);
3424 ui_out_field_stream (uiout, "old", stb);
3425 ui_out_text (uiout, "\nNew value = ");
3426 watchpoint_value_print (b->val, stb->stream);
3427 ui_out_field_stream (uiout, "new", stb);
3428 ui_out_text (uiout, "\n");
3429 /* More than one watchpoint may have been triggered. */
3430 result = PRINT_UNKNOWN;
3433 case bp_read_watchpoint:
3434 if (ui_out_is_mi_like_p (uiout))
3437 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
3439 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
3440 ui_out_text (uiout, "\nValue = ");
3441 watchpoint_value_print (b->val, stb->stream);
3442 ui_out_field_stream (uiout, "value", stb);
3443 ui_out_text (uiout, "\n");
3444 result = PRINT_UNKNOWN;
3447 case bp_access_watchpoint:
3448 if (bs->old_val != NULL)
3450 annotate_watchpoint (b->number);
3451 if (ui_out_is_mi_like_p (uiout))
3454 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
3456 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
3457 ui_out_text (uiout, "\nOld value = ");
3458 watchpoint_value_print (bs->old_val, stb->stream);
3459 ui_out_field_stream (uiout, "old", stb);
3460 ui_out_text (uiout, "\nNew value = ");
3465 if (ui_out_is_mi_like_p (uiout))
3468 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
3469 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
3470 ui_out_text (uiout, "\nValue = ");
3472 watchpoint_value_print (b->val, stb->stream);
3473 ui_out_field_stream (uiout, "new", stb);
3474 ui_out_text (uiout, "\n");
3475 result = PRINT_UNKNOWN;
3478 /* Fall through, we don't deal with these types of breakpoints
3482 if (ui_out_is_mi_like_p (uiout))
3485 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED));
3486 result = PRINT_UNKNOWN;
3490 if (ui_out_is_mi_like_p (uiout))
3493 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED));
3494 result = PRINT_UNKNOWN;
3499 case bp_longjmp_resume:
3501 case bp_exception_resume:
3502 case bp_step_resume:
3503 case bp_hp_step_resume:
3504 case bp_watchpoint_scope:
3506 case bp_std_terminate:
3508 case bp_fast_tracepoint:
3510 case bp_gnu_ifunc_resolver:
3511 case bp_gnu_ifunc_resolver_return:
3513 result = PRINT_UNKNOWN;
3517 do_cleanups (old_chain);
3521 /* Generic routine for printing messages indicating why we
3522 stopped. The behavior of this function depends on the value
3523 'print_it' in the bpstat structure. Under some circumstances we
3524 may decide not to print anything here and delegate the task to
3527 static enum print_stop_action
3528 print_bp_stop_message (bpstat bs)
3530 switch (bs->print_it)
3533 /* Nothing should be printed for this bpstat entry. */
3534 return PRINT_UNKNOWN;
3538 /* We still want to print the frame, but we already printed the
3539 relevant messages. */
3540 return PRINT_SRC_AND_LOC;
3543 case print_it_normal:
3545 struct breakpoint *b = bs->breakpoint_at;
3547 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3548 which has since been deleted. */
3550 return PRINT_UNKNOWN;
3552 /* Normal case. Call the breakpoint's print_it method, or
3553 print_it_typical. */
3554 if (b->ops != NULL && b->ops->print_it != NULL)
3555 return b->ops->print_it (b);
3557 return print_it_typical (bs);
3562 internal_error (__FILE__, __LINE__,
3563 _("print_bp_stop_message: unrecognized enum value"));
3568 /* Print a message indicating what happened. This is called from
3569 normal_stop(). The input to this routine is the head of the bpstat
3570 list - a list of the eventpoints that caused this stop. This
3571 routine calls the generic print routine for printing a message
3572 about reasons for stopping. This will print (for example) the
3573 "Breakpoint n," part of the output. The return value of this
3576 PRINT_UNKNOWN: Means we printed nothing.
3577 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3578 code to print the location. An example is
3579 "Breakpoint 1, " which should be followed by
3581 PRINT_SRC_ONLY: Means we printed something, but there is no need
3582 to also print the location part of the message.
3583 An example is the catch/throw messages, which
3584 don't require a location appended to the end.
3585 PRINT_NOTHING: We have done some printing and we don't need any
3586 further info to be printed. */
3588 enum print_stop_action
3589 bpstat_print (bpstat bs)
3593 /* Maybe another breakpoint in the chain caused us to stop.
3594 (Currently all watchpoints go on the bpstat whether hit or not.
3595 That probably could (should) be changed, provided care is taken
3596 with respect to bpstat_explains_signal). */
3597 for (; bs; bs = bs->next)
3599 val = print_bp_stop_message (bs);
3600 if (val == PRINT_SRC_ONLY
3601 || val == PRINT_SRC_AND_LOC
3602 || val == PRINT_NOTHING)
3606 /* We reached the end of the chain, or we got a null BS to start
3607 with and nothing was printed. */
3608 return PRINT_UNKNOWN;
3611 /* Evaluate the expression EXP and return 1 if value is zero. This is
3612 used inside a catch_errors to evaluate the breakpoint condition.
3613 The argument is a "struct expression *" that has been cast to a
3614 "char *" to make it pass through catch_errors. */
3617 breakpoint_cond_eval (void *exp)
3619 struct value *mark = value_mark ();
3620 int i = !value_true (evaluate_expression ((struct expression *) exp));
3622 value_free_to_mark (mark);
3626 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
3629 bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer)
3633 bs = (bpstat) xmalloc (sizeof (*bs));
3635 **bs_link_pointer = bs;
3636 *bs_link_pointer = &bs->next;
3637 bs->breakpoint_at = bl->owner;
3638 bs->bp_location_at = bl;
3639 incref_bp_location (bl);
3640 /* If the condition is false, etc., don't do the commands. */
3641 bs->commands = NULL;
3642 bs->commands_left = NULL;
3644 bs->print_it = print_it_normal;
3648 /* The target has stopped with waitstatus WS. Check if any hardware
3649 watchpoints have triggered, according to the target. */
3652 watchpoints_triggered (struct target_waitstatus *ws)
3654 int stopped_by_watchpoint = target_stopped_by_watchpoint ();
3656 struct breakpoint *b;
3658 if (!stopped_by_watchpoint)
3660 /* We were not stopped by a watchpoint. Mark all watchpoints
3661 as not triggered. */
3663 if (is_hardware_watchpoint (b))
3664 b->watchpoint_triggered = watch_triggered_no;
3669 if (!target_stopped_data_address (¤t_target, &addr))
3671 /* We were stopped by a watchpoint, but we don't know where.
3672 Mark all watchpoints as unknown. */
3674 if (is_hardware_watchpoint (b))
3675 b->watchpoint_triggered = watch_triggered_unknown;
3677 return stopped_by_watchpoint;
3680 /* The target could report the data address. Mark watchpoints
3681 affected by this data address as triggered, and all others as not
3685 if (is_hardware_watchpoint (b))
3687 struct bp_location *loc;
3689 b->watchpoint_triggered = watch_triggered_no;
3690 for (loc = b->loc; loc; loc = loc->next)
3692 if (is_masked_watchpoint (loc->owner))
3694 CORE_ADDR newaddr = addr & loc->owner->hw_wp_mask;
3695 CORE_ADDR start = loc->address & loc->owner->hw_wp_mask;
3697 if (newaddr == start)
3699 b->watchpoint_triggered = watch_triggered_yes;
3703 /* Exact match not required. Within range is sufficient. */
3704 else if (target_watchpoint_addr_within_range (¤t_target,
3708 b->watchpoint_triggered = watch_triggered_yes;
3717 /* Possible return values for watchpoint_check (this can't be an enum
3718 because of check_errors). */
3719 /* The watchpoint has been deleted. */
3720 #define WP_DELETED 1
3721 /* The value has changed. */
3722 #define WP_VALUE_CHANGED 2
3723 /* The value has not changed. */
3724 #define WP_VALUE_NOT_CHANGED 3
3725 /* Ignore this watchpoint, no matter if the value changed or not. */
3728 #define BP_TEMPFLAG 1
3729 #define BP_HARDWAREFLAG 2
3731 /* Evaluate watchpoint condition expression and check if its value
3734 P should be a pointer to struct bpstat, but is defined as a void *
3735 in order for this function to be usable with catch_errors. */
3738 watchpoint_check (void *p)
3740 bpstat bs = (bpstat) p;
3741 struct breakpoint *b;
3742 struct frame_info *fr;
3743 int within_current_scope;
3745 /* BS is built from an existing struct breakpoint. */
3746 gdb_assert (bs->breakpoint_at != NULL);
3747 b = bs->breakpoint_at;
3749 gdb_assert (is_watchpoint (b));
3751 /* If this is a local watchpoint, we only want to check if the
3752 watchpoint frame is in scope if the current thread is the thread
3753 that was used to create the watchpoint. */
3754 if (!watchpoint_in_thread_scope (b))
3757 if (b->exp_valid_block == NULL)
3758 within_current_scope = 1;
3761 struct frame_info *frame = get_current_frame ();
3762 struct gdbarch *frame_arch = get_frame_arch (frame);
3763 CORE_ADDR frame_pc = get_frame_pc (frame);
3765 /* in_function_epilogue_p() returns a non-zero value if we're
3766 still in the function but the stack frame has already been
3767 invalidated. Since we can't rely on the values of local
3768 variables after the stack has been destroyed, we are treating
3769 the watchpoint in that state as `not changed' without further
3770 checking. Don't mark watchpoints as changed if the current
3771 frame is in an epilogue - even if they are in some other
3772 frame, our view of the stack is likely to be wrong and
3773 frame_find_by_id could error out. */
3774 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
3777 fr = frame_find_by_id (b->watchpoint_frame);
3778 within_current_scope = (fr != NULL);
3780 /* If we've gotten confused in the unwinder, we might have
3781 returned a frame that can't describe this variable. */
3782 if (within_current_scope)
3784 struct symbol *function;
3786 function = get_frame_function (fr);
3787 if (function == NULL
3788 || !contained_in (b->exp_valid_block,
3789 SYMBOL_BLOCK_VALUE (function)))
3790 within_current_scope = 0;
3793 if (within_current_scope)
3794 /* If we end up stopping, the current frame will get selected
3795 in normal_stop. So this call to select_frame won't affect
3800 if (within_current_scope)
3802 /* We use value_{,free_to_}mark because it could be a *long*
3803 time before we return to the command level and call
3804 free_all_values. We can't call free_all_values because we
3805 might be in the middle of evaluating a function call. */
3809 struct value *new_val;
3811 if (is_masked_watchpoint (b))
3812 /* Since we don't know the exact trigger address (from
3813 stopped_data_address), just tell the user we've triggered
3814 a mask watchpoint. */
3815 return WP_VALUE_CHANGED;
3817 mark = value_mark ();
3818 fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL);
3820 /* We use value_equal_contents instead of value_equal because
3821 the latter coerces an array to a pointer, thus comparing just
3822 the address of the array instead of its contents. This is
3823 not what we want. */
3824 if ((b->val != NULL) != (new_val != NULL)
3825 || (b->val != NULL && !value_equal_contents (b->val, new_val)))
3827 if (new_val != NULL)
3829 release_value (new_val);
3830 value_free_to_mark (mark);
3832 bs->old_val = b->val;
3835 return WP_VALUE_CHANGED;
3839 /* Nothing changed. */
3840 value_free_to_mark (mark);
3841 return WP_VALUE_NOT_CHANGED;
3846 /* This seems like the only logical thing to do because
3847 if we temporarily ignored the watchpoint, then when
3848 we reenter the block in which it is valid it contains
3849 garbage (in the case of a function, it may have two
3850 garbage values, one before and one after the prologue).
3851 So we can't even detect the first assignment to it and
3852 watch after that (since the garbage may or may not equal
3853 the first value assigned). */
3854 /* We print all the stop information in print_it_typical(), but
3855 in this case, by the time we call print_it_typical() this bp
3856 will be deleted already. So we have no choice but print the
3857 information here. */
3858 if (ui_out_is_mi_like_p (uiout))
3860 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
3861 ui_out_text (uiout, "\nWatchpoint ");
3862 ui_out_field_int (uiout, "wpnum", b->number);
3864 " deleted because the program has left the block in\n\
3865 which its expression is valid.\n");
3867 /* Make sure the watchpoint's commands aren't executed. */
3868 decref_counted_command_line (&b->commands);
3869 watchpoint_del_at_next_stop (b);
3875 /* Return true if it looks like target has stopped due to hitting
3876 breakpoint location BL. This function does not check if we
3877 should stop, only if BL explains the stop. */
3879 bpstat_check_location (const struct bp_location *bl,
3880 struct address_space *aspace, CORE_ADDR bp_addr)
3882 struct breakpoint *b = bl->owner;
3884 /* BL is from existing struct breakpoint. */
3885 gdb_assert (b != NULL);
3887 if (b->ops && b->ops->breakpoint_hit)
3888 return b->ops->breakpoint_hit (bl, aspace, bp_addr);
3890 /* By definition, the inferior does not report stops at
3892 if (is_tracepoint (b))
3895 if (!is_watchpoint (b)
3896 && b->type != bp_hardware_breakpoint
3897 && b->type != bp_catchpoint) /* a non-watchpoint bp */
3899 if (!breakpoint_address_match (bl->pspace->aspace, bl->address,
3902 if (overlay_debugging /* unmapped overlay section */
3903 && section_is_overlay (bl->section)
3904 && !section_is_mapped (bl->section))
3908 /* Continuable hardware watchpoints are treated as non-existent if the
3909 reason we stopped wasn't a hardware watchpoint (we didn't stop on
3910 some data address). Otherwise gdb won't stop on a break instruction
3911 in the code (not from a breakpoint) when a hardware watchpoint has
3912 been defined. Also skip watchpoints which we know did not trigger
3913 (did not match the data address). */
3915 if (is_hardware_watchpoint (b)
3916 && b->watchpoint_triggered == watch_triggered_no)
3919 if (b->type == bp_hardware_breakpoint)
3921 if (bl->address != bp_addr)
3923 if (overlay_debugging /* unmapped overlay section */
3924 && section_is_overlay (bl->section)
3925 && !section_is_mapped (bl->section))
3932 /* If BS refers to a watchpoint, determine if the watched values
3933 has actually changed, and we should stop. If not, set BS->stop
3936 bpstat_check_watchpoint (bpstat bs)
3938 const struct bp_location *bl;
3939 struct breakpoint *b;
3941 /* BS is built for existing struct breakpoint. */
3942 bl = bs->bp_location_at;
3943 gdb_assert (bl != NULL);
3944 b = bs->breakpoint_at;
3945 gdb_assert (b != NULL);
3947 if (is_watchpoint (b))
3949 int must_check_value = 0;
3951 if (b->type == bp_watchpoint)
3952 /* For a software watchpoint, we must always check the
3954 must_check_value = 1;
3955 else if (b->watchpoint_triggered == watch_triggered_yes)
3956 /* We have a hardware watchpoint (read, write, or access)
3957 and the target earlier reported an address watched by
3959 must_check_value = 1;
3960 else if (b->watchpoint_triggered == watch_triggered_unknown
3961 && b->type == bp_hardware_watchpoint)
3962 /* We were stopped by a hardware watchpoint, but the target could
3963 not report the data address. We must check the watchpoint's
3964 value. Access and read watchpoints are out of luck; without
3965 a data address, we can't figure it out. */
3966 must_check_value = 1;
3968 if (must_check_value)
3971 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
3973 struct cleanup *cleanups = make_cleanup (xfree, message);
3974 int e = catch_errors (watchpoint_check, bs, message,
3976 do_cleanups (cleanups);
3980 /* We've already printed what needs to be printed. */
3981 bs->print_it = print_it_done;
3985 bs->print_it = print_it_noop;
3988 case WP_VALUE_CHANGED:
3989 if (b->type == bp_read_watchpoint)
3991 /* There are two cases to consider here:
3993 1. We're watching the triggered memory for reads.
3994 In that case, trust the target, and always report
3995 the watchpoint hit to the user. Even though
3996 reads don't cause value changes, the value may
3997 have changed since the last time it was read, and
3998 since we're not trapping writes, we will not see
3999 those, and as such we should ignore our notion of
4002 2. We're watching the triggered memory for both
4003 reads and writes. There are two ways this may
4006 2.1. This is a target that can't break on data
4007 reads only, but can break on accesses (reads or
4008 writes), such as e.g., x86. We detect this case
4009 at the time we try to insert read watchpoints.
4011 2.2. Otherwise, the target supports read
4012 watchpoints, but, the user set an access or write
4013 watchpoint watching the same memory as this read
4016 If we're watching memory writes as well as reads,
4017 ignore watchpoint hits when we find that the
4018 value hasn't changed, as reads don't cause
4019 changes. This still gives false positives when
4020 the program writes the same value to memory as
4021 what there was already in memory (we will confuse
4022 it for a read), but it's much better than
4025 int other_write_watchpoint = 0;
4027 if (bl->watchpoint_type == hw_read)
4029 struct breakpoint *other_b;
4031 ALL_BREAKPOINTS (other_b)
4032 if ((other_b->type == bp_hardware_watchpoint
4033 || other_b->type == bp_access_watchpoint)
4034 && (other_b->watchpoint_triggered
4035 == watch_triggered_yes))
4037 other_write_watchpoint = 1;
4042 if (other_write_watchpoint
4043 || bl->watchpoint_type == hw_access)
4045 /* We're watching the same memory for writes,
4046 and the value changed since the last time we
4047 updated it, so this trap must be for a write.
4049 bs->print_it = print_it_noop;
4054 case WP_VALUE_NOT_CHANGED:
4055 if (b->type == bp_hardware_watchpoint
4056 || b->type == bp_watchpoint)
4058 /* Don't stop: write watchpoints shouldn't fire if
4059 the value hasn't changed. */
4060 bs->print_it = print_it_noop;
4068 /* Error from catch_errors. */
4069 printf_filtered (_("Watchpoint %d deleted.\n"), b->number);
4070 watchpoint_del_at_next_stop (b);
4071 /* We've already printed what needs to be printed. */
4072 bs->print_it = print_it_done;
4076 else /* must_check_value == 0 */
4078 /* This is a case where some watchpoint(s) triggered, but
4079 not at the address of this watchpoint, or else no
4080 watchpoint triggered after all. So don't print
4081 anything for this watchpoint. */
4082 bs->print_it = print_it_noop;
4089 /* Check conditions (condition proper, frame, thread and ignore count)
4090 of breakpoint referred to by BS. If we should not stop for this
4091 breakpoint, set BS->stop to 0. */
4094 bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
4096 int thread_id = pid_to_thread_id (ptid);
4097 const struct bp_location *bl;
4098 struct breakpoint *b;
4100 /* BS is built for existing struct breakpoint. */
4101 bl = bs->bp_location_at;
4102 gdb_assert (bl != NULL);
4103 b = bs->breakpoint_at;
4104 gdb_assert (b != NULL);
4106 if (frame_id_p (b->frame_id)
4107 && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ())))
4111 int value_is_zero = 0;
4112 struct expression *cond;
4114 /* Evaluate Python breakpoints that have a "stop"
4115 method implemented. */
4116 if (b->py_bp_object)
4117 bs->stop = gdbpy_should_stop (b->py_bp_object);
4119 if (is_watchpoint (b))
4124 if (cond && b->disposition != disp_del_at_next_stop)
4126 int within_current_scope = 1;
4128 /* We use value_mark and value_free_to_mark because it could
4129 be a long time before we return to the command level and
4130 call free_all_values. We can't call free_all_values
4131 because we might be in the middle of evaluating a
4133 struct value *mark = value_mark ();
4135 /* Need to select the frame, with all that implies so that
4136 the conditions will have the right context. Because we
4137 use the frame, we will not see an inlined function's
4138 variables when we arrive at a breakpoint at the start
4139 of the inlined function; the current frame will be the
4141 if (!is_watchpoint (b) || b->cond_exp_valid_block == NULL)
4142 select_frame (get_current_frame ());
4145 struct frame_info *frame;
4147 /* For local watchpoint expressions, which particular
4148 instance of a local is being watched matters, so we
4149 keep track of the frame to evaluate the expression
4150 in. To evaluate the condition however, it doesn't
4151 really matter which instantiation of the function
4152 where the condition makes sense triggers the
4153 watchpoint. This allows an expression like "watch
4154 global if q > 10" set in `func', catch writes to
4155 global on all threads that call `func', or catch
4156 writes on all recursive calls of `func' by a single
4157 thread. We simply always evaluate the condition in
4158 the innermost frame that's executing where it makes
4159 sense to evaluate the condition. It seems
4161 frame = block_innermost_frame (b->cond_exp_valid_block);
4163 select_frame (frame);
4165 within_current_scope = 0;
4167 if (within_current_scope)
4169 = catch_errors (breakpoint_cond_eval, cond,
4170 "Error in testing breakpoint condition:\n",
4174 warning (_("Watchpoint condition cannot be tested "
4175 "in the current scope"));
4176 /* If we failed to set the right context for this
4177 watchpoint, unconditionally report it. */
4180 /* FIXME-someday, should give breakpoint #. */
4181 value_free_to_mark (mark);
4184 if (cond && value_is_zero)
4188 else if (b->thread != -1 && b->thread != thread_id)
4192 else if (b->ignore_count > 0)
4195 annotate_ignore_count_change ();
4197 /* Increase the hit count even though we don't stop. */
4199 observer_notify_breakpoint_modified (b);
4205 /* Get a bpstat associated with having just stopped at address
4206 BP_ADDR in thread PTID.
4208 Determine whether we stopped at a breakpoint, etc, or whether we
4209 don't understand this stop. Result is a chain of bpstat's such
4212 if we don't understand the stop, the result is a null pointer.
4214 if we understand why we stopped, the result is not null.
4216 Each element of the chain refers to a particular breakpoint or
4217 watchpoint at which we have stopped. (We may have stopped for
4218 several reasons concurrently.)
4220 Each element of the chain has valid next, breakpoint_at,
4221 commands, FIXME??? fields. */
4224 bpstat_stop_status (struct address_space *aspace,
4225 CORE_ADDR bp_addr, ptid_t ptid)
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))
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)
4283 b->related_breakpoint->watchpoint_triggered = watch_triggered_yes;
4287 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
4289 if (breakpoint_location_address_match (loc, aspace, bp_addr))
4291 bs = bpstat_alloc (loc, &bs_link);
4292 /* For hits of moribund locations, we should just proceed. */
4295 bs->print_it = print_it_noop;
4299 /* Now go through the locations that caused the target to stop, and
4300 check whether we're interested in reporting this stop to higher
4301 layers, or whether we should resume the target transparently. */
4305 for (bs = bs_head; bs != NULL; bs = bs->next)
4310 bpstat_check_watchpoint (bs);
4314 b = bs->breakpoint_at;
4316 if (b->type == bp_thread_event || b->type == bp_overlay_event
4317 || b->type == bp_longjmp_master
4318 || b->type == bp_std_terminate_master
4319 || b->type == bp_exception_master)
4320 /* We do not stop for these. */
4323 bpstat_check_breakpoint_conditions (bs, ptid);
4328 observer_notify_breakpoint_modified (b);
4330 /* We will stop here. */
4331 if (b->disposition == disp_disable)
4333 if (b->enable_state != bp_permanent)
4334 b->enable_state = bp_disabled;
4339 bs->commands = b->commands;
4340 incref_counted_command_line (bs->commands);
4341 bs->commands_left = bs->commands ? bs->commands->commands : NULL;
4342 if (bs->commands_left
4343 && (strcmp ("silent", bs->commands_left->line) == 0
4346 bs->commands_left->line) == 0)))
4348 bs->commands_left = bs->commands_left->next;
4353 /* Print nothing for this entry if we dont stop or dont print. */
4354 if (bs->stop == 0 || bs->print == 0)
4355 bs->print_it = print_it_noop;
4358 /* If we aren't stopping, the value of some hardware watchpoint may
4359 not have changed, but the intermediate memory locations we are
4360 watching may have. Don't bother if we're stopping; this will get
4362 need_remove_insert = 0;
4363 if (! bpstat_causes_stop (bs_head))
4364 for (bs = bs_head; bs != NULL; bs = bs->next)
4366 && bs->breakpoint_at
4367 && is_hardware_watchpoint (bs->breakpoint_at))
4369 update_watchpoint (bs->breakpoint_at, 0 /* don't reparse. */);
4370 need_remove_insert = 1;
4373 if (need_remove_insert)
4374 update_global_location_list (1);
4375 else if (removed_any)
4376 update_global_location_list (0);
4382 handle_jit_event (void)
4384 struct frame_info *frame;
4385 struct gdbarch *gdbarch;
4387 /* Switch terminal for any messages produced by
4388 breakpoint_re_set. */
4389 target_terminal_ours_for_output ();
4391 frame = get_current_frame ();
4392 gdbarch = get_frame_arch (frame);
4394 jit_event_handler (gdbarch);
4396 target_terminal_inferior ();
4399 /* Prepare WHAT final decision for infrun. */
4401 /* Decide what infrun needs to do with this bpstat. */
4404 bpstat_what (bpstat bs_head)
4406 struct bpstat_what retval;
4407 /* We need to defer calling `solib_add', as adding new symbols
4408 resets breakpoints, which in turn deletes breakpoint locations,
4409 and hence may clear unprocessed entries in the BS chain. */
4410 int shlib_event = 0;
4414 retval.main_action = BPSTAT_WHAT_KEEP_CHECKING;
4415 retval.call_dummy = STOP_NONE;
4416 retval.is_longjmp = 0;
4418 for (bs = bs_head; bs != NULL; bs = bs->next)
4420 /* Extract this BS's action. After processing each BS, we check
4421 if its action overrides all we've seem so far. */
4422 enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING;
4425 if (bs->breakpoint_at == NULL)
4427 /* I suspect this can happen if it was a momentary
4428 breakpoint which has since been deleted. */
4431 else if (bs->breakpoint_at == NULL)
4434 bptype = bs->breakpoint_at->type;
4441 case bp_hardware_breakpoint:
4447 this_action = BPSTAT_WHAT_STOP_NOISY;
4449 this_action = BPSTAT_WHAT_STOP_SILENT;
4452 this_action = BPSTAT_WHAT_SINGLE;
4455 case bp_hardware_watchpoint:
4456 case bp_read_watchpoint:
4457 case bp_access_watchpoint:
4461 this_action = BPSTAT_WHAT_STOP_NOISY;
4463 this_action = BPSTAT_WHAT_STOP_SILENT;
4467 /* There was a watchpoint, but we're not stopping.
4468 This requires no further action. */
4473 this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME;
4474 retval.is_longjmp = bptype == bp_longjmp;
4476 case bp_longjmp_resume:
4477 case bp_exception_resume:
4478 this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME;
4479 retval.is_longjmp = bptype == bp_longjmp_resume;
4481 case bp_step_resume:
4483 this_action = BPSTAT_WHAT_STEP_RESUME;
4486 /* It is for the wrong frame. */
4487 this_action = BPSTAT_WHAT_SINGLE;
4490 case bp_hp_step_resume:
4492 this_action = BPSTAT_WHAT_HP_STEP_RESUME;
4495 /* It is for the wrong frame. */
4496 this_action = BPSTAT_WHAT_SINGLE;
4499 case bp_watchpoint_scope:
4500 case bp_thread_event:
4501 case bp_overlay_event:
4502 case bp_longjmp_master:
4503 case bp_std_terminate_master:
4504 case bp_exception_master:
4505 this_action = BPSTAT_WHAT_SINGLE;
4511 this_action = BPSTAT_WHAT_STOP_NOISY;
4513 this_action = BPSTAT_WHAT_STOP_SILENT;
4517 /* There was a catchpoint, but we're not stopping.
4518 This requires no further action. */
4521 case bp_shlib_event:
4524 /* If requested, stop when the dynamic linker notifies GDB
4525 of events. This allows the user to get control and place
4526 breakpoints in initializer routines for dynamically
4527 loaded objects (among other things). */
4528 if (stop_on_solib_events)
4529 this_action = BPSTAT_WHAT_STOP_NOISY;
4531 this_action = BPSTAT_WHAT_SINGLE;
4535 this_action = BPSTAT_WHAT_SINGLE;
4538 /* Make sure the action is stop (silent or noisy),
4539 so infrun.c pops the dummy frame. */
4540 retval.call_dummy = STOP_STACK_DUMMY;
4541 this_action = BPSTAT_WHAT_STOP_SILENT;
4543 case bp_std_terminate:
4544 /* Make sure the action is stop (silent or noisy),
4545 so infrun.c pops the dummy frame. */
4546 retval.call_dummy = STOP_STD_TERMINATE;
4547 this_action = BPSTAT_WHAT_STOP_SILENT;
4550 case bp_fast_tracepoint:
4551 case bp_static_tracepoint:
4552 /* Tracepoint hits should not be reported back to GDB, and
4553 if one got through somehow, it should have been filtered
4555 internal_error (__FILE__, __LINE__,
4556 _("bpstat_what: tracepoint encountered"));
4558 case bp_gnu_ifunc_resolver:
4559 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
4560 this_action = BPSTAT_WHAT_SINGLE;
4562 case bp_gnu_ifunc_resolver_return:
4563 /* The breakpoint will be removed, execution will restart from the
4564 PC of the former breakpoint. */
4565 this_action = BPSTAT_WHAT_KEEP_CHECKING;
4568 internal_error (__FILE__, __LINE__,
4569 _("bpstat_what: unhandled bptype %d"), (int) bptype);
4572 retval.main_action = max (retval.main_action, this_action);
4575 /* These operations may affect the bs->breakpoint_at state so they are
4576 delayed after MAIN_ACTION is decided above. */
4581 fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_shlib_event\n");
4583 /* Check for any newly added shared libraries if we're supposed
4584 to be adding them automatically. */
4586 /* Switch terminal for any messages produced by
4587 breakpoint_re_set. */
4588 target_terminal_ours_for_output ();
4591 SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add);
4593 solib_add (NULL, 0, ¤t_target, auto_solib_add);
4596 target_terminal_inferior ();
4602 fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n");
4604 handle_jit_event ();
4607 for (bs = bs_head; bs != NULL; bs = bs->next)
4609 struct breakpoint *b = bs->breakpoint_at;
4615 case bp_gnu_ifunc_resolver:
4616 gnu_ifunc_resolver_stop (b);
4618 case bp_gnu_ifunc_resolver_return:
4619 gnu_ifunc_resolver_return_stop (b);
4627 /* Nonzero if we should step constantly (e.g. watchpoints on machines
4628 without hardware support). This isn't related to a specific bpstat,
4629 just to things like whether watchpoints are set. */
4632 bpstat_should_step (void)
4634 struct breakpoint *b;
4637 if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL)
4643 bpstat_causes_stop (bpstat bs)
4645 for (; bs != NULL; bs = bs->next)
4654 /* Compute a string of spaces suitable to indent the next line
4655 so it starts at the position corresponding to the table column
4656 named COL_NAME in the currently active table of UIOUT. */
4659 wrap_indent_at_field (struct ui_out *uiout, const char *col_name)
4661 static char wrap_indent[80];
4662 int i, total_width, width, align;
4666 for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++)
4668 if (strcmp (text, col_name) == 0)
4670 gdb_assert (total_width < sizeof wrap_indent);
4671 memset (wrap_indent, ' ', total_width);
4672 wrap_indent[total_width] = 0;
4677 total_width += width + 1;
4683 /* Print the LOC location out of the list of B->LOC locations. */
4686 print_breakpoint_location (struct breakpoint *b,
4687 struct bp_location *loc)
4689 struct cleanup *old_chain = save_current_program_space ();
4691 if (loc != NULL && loc->shlib_disabled)
4695 set_current_program_space (loc->pspace);
4697 if (b->display_canonical)
4698 ui_out_field_string (uiout, "what", b->addr_string);
4699 else if (b->source_file && loc)
4702 = find_pc_sect_function (loc->address, loc->section);
4705 ui_out_text (uiout, "in ");
4706 ui_out_field_string (uiout, "func",
4707 SYMBOL_PRINT_NAME (sym));
4708 ui_out_text (uiout, " ");
4709 ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what"));
4710 ui_out_text (uiout, "at ");
4712 ui_out_field_string (uiout, "file", b->source_file);
4713 ui_out_text (uiout, ":");
4715 if (ui_out_is_mi_like_p (uiout))
4717 struct symtab_and_line sal = find_pc_line (loc->address, 0);
4718 char *fullname = symtab_to_fullname (sal.symtab);
4721 ui_out_field_string (uiout, "fullname", fullname);
4724 ui_out_field_int (uiout, "line", b->line_number);
4728 struct ui_stream *stb = ui_out_stream_new (uiout);
4729 struct cleanup *stb_chain = make_cleanup_ui_out_stream_delete (stb);
4731 print_address_symbolic (loc->gdbarch, loc->address, stb->stream,
4733 ui_out_field_stream (uiout, "at", stb);
4735 do_cleanups (stb_chain);
4738 ui_out_field_string (uiout, "pending", b->addr_string);
4740 do_cleanups (old_chain);
4744 bptype_string (enum bptype type)
4746 struct ep_type_description
4751 static struct ep_type_description bptypes[] =
4753 {bp_none, "?deleted?"},
4754 {bp_breakpoint, "breakpoint"},
4755 {bp_hardware_breakpoint, "hw breakpoint"},
4756 {bp_until, "until"},
4757 {bp_finish, "finish"},
4758 {bp_watchpoint, "watchpoint"},
4759 {bp_hardware_watchpoint, "hw watchpoint"},
4760 {bp_read_watchpoint, "read watchpoint"},
4761 {bp_access_watchpoint, "acc watchpoint"},
4762 {bp_longjmp, "longjmp"},
4763 {bp_longjmp_resume, "longjmp resume"},
4764 {bp_exception, "exception"},
4765 {bp_exception_resume, "exception resume"},
4766 {bp_step_resume, "step resume"},
4767 {bp_hp_step_resume, "high-priority step resume"},
4768 {bp_watchpoint_scope, "watchpoint scope"},
4769 {bp_call_dummy, "call dummy"},
4770 {bp_std_terminate, "std::terminate"},
4771 {bp_shlib_event, "shlib events"},
4772 {bp_thread_event, "thread events"},
4773 {bp_overlay_event, "overlay events"},
4774 {bp_longjmp_master, "longjmp master"},
4775 {bp_std_terminate_master, "std::terminate master"},
4776 {bp_exception_master, "exception master"},
4777 {bp_catchpoint, "catchpoint"},
4778 {bp_tracepoint, "tracepoint"},
4779 {bp_fast_tracepoint, "fast tracepoint"},
4780 {bp_static_tracepoint, "static tracepoint"},
4781 {bp_jit_event, "jit events"},
4782 {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"},
4783 {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"},
4786 if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0])))
4787 || ((int) type != bptypes[(int) type].type))
4788 internal_error (__FILE__, __LINE__,
4789 _("bptypes table does not describe type #%d."),
4792 return bptypes[(int) type].description;
4795 /* Print B to gdb_stdout. */
4798 print_one_breakpoint_location (struct breakpoint *b,
4799 struct bp_location *loc,
4801 struct bp_location **last_loc,
4804 struct command_line *l;
4805 static char bpenables[] = "nynny";
4807 int header_of_multiple = 0;
4808 int part_of_multiple = (loc != NULL);
4809 struct value_print_options opts;
4811 get_user_print_options (&opts);
4813 gdb_assert (!loc || loc_number != 0);
4814 /* See comment in print_one_breakpoint concerning treatment of
4815 breakpoints with single disabled location. */
4818 && (b->loc->next != NULL || !b->loc->enabled)))
4819 header_of_multiple = 1;
4827 if (part_of_multiple)
4830 formatted = xstrprintf ("%d.%d", b->number, loc_number);
4831 ui_out_field_string (uiout, "number", formatted);
4836 ui_out_field_int (uiout, "number", b->number);
4841 if (part_of_multiple)
4842 ui_out_field_skip (uiout, "type");
4844 ui_out_field_string (uiout, "type", bptype_string (b->type));
4848 if (part_of_multiple)
4849 ui_out_field_skip (uiout, "disp");
4851 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
4856 if (part_of_multiple)
4857 ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n");
4859 ui_out_field_fmt (uiout, "enabled", "%c",
4860 bpenables[(int) b->enable_state]);
4861 ui_out_spaces (uiout, 2);
4865 if (b->ops != NULL && b->ops->print_one != NULL)
4867 /* Although the print_one can possibly print all locations,
4868 calling it here is not likely to get any nice result. So,
4869 make sure there's just one location. */
4870 gdb_assert (b->loc == NULL || b->loc->next == NULL);
4871 b->ops->print_one (b, last_loc);
4877 internal_error (__FILE__, __LINE__,
4878 _("print_one_breakpoint: bp_none encountered\n"));
4882 case bp_hardware_watchpoint:
4883 case bp_read_watchpoint:
4884 case bp_access_watchpoint:
4885 /* Field 4, the address, is omitted (which makes the columns
4886 not line up too nicely with the headers, but the effect
4887 is relatively readable). */
4888 if (opts.addressprint)
4889 ui_out_field_skip (uiout, "addr");
4891 ui_out_field_string (uiout, "what", b->exp_string);
4895 case bp_hardware_breakpoint:
4899 case bp_longjmp_resume:
4901 case bp_exception_resume:
4902 case bp_step_resume:
4903 case bp_hp_step_resume:
4904 case bp_watchpoint_scope:
4906 case bp_std_terminate:
4907 case bp_shlib_event:
4908 case bp_thread_event:
4909 case bp_overlay_event:
4910 case bp_longjmp_master:
4911 case bp_std_terminate_master:
4912 case bp_exception_master:
4914 case bp_fast_tracepoint:
4915 case bp_static_tracepoint:
4917 case bp_gnu_ifunc_resolver:
4918 case bp_gnu_ifunc_resolver_return:
4919 if (opts.addressprint)
4922 if (header_of_multiple)
4923 ui_out_field_string (uiout, "addr", "<MULTIPLE>");
4924 else if (b->loc == NULL || loc->shlib_disabled)
4925 ui_out_field_string (uiout, "addr", "<PENDING>");
4927 ui_out_field_core_addr (uiout, "addr",
4928 loc->gdbarch, loc->address);
4931 if (!header_of_multiple)
4932 print_breakpoint_location (b, loc);
4939 /* For backward compatibility, don't display inferiors unless there
4942 && !header_of_multiple
4944 || (!gdbarch_has_global_breakpoints (target_gdbarch)
4945 && (number_of_program_spaces () > 1
4946 || number_of_inferiors () > 1)
4947 /* LOC is for existing B, it cannot be in
4948 moribund_locations and thus having NULL OWNER. */
4949 && loc->owner->type != bp_catchpoint)))
4951 struct inferior *inf;
4954 for (inf = inferior_list; inf != NULL; inf = inf->next)
4956 if (inf->pspace == loc->pspace)
4961 ui_out_text (uiout, " inf ");
4964 ui_out_text (uiout, ", ");
4965 ui_out_text (uiout, plongest (inf->num));
4970 if (!part_of_multiple)
4972 if (b->thread != -1)
4974 /* FIXME: This seems to be redundant and lost here; see the
4975 "stop only in" line a little further down. */
4976 ui_out_text (uiout, " thread ");
4977 ui_out_field_int (uiout, "thread", b->thread);
4979 else if (b->task != 0)
4981 ui_out_text (uiout, " task ");
4982 ui_out_field_int (uiout, "task", b->task);
4986 ui_out_text (uiout, "\n");
4988 if (!part_of_multiple && b->ops && b->ops->print_one_detail)
4989 b->ops->print_one_detail (b, uiout);
4991 if (!part_of_multiple && b->static_trace_marker_id)
4993 gdb_assert (b->type == bp_static_tracepoint);
4995 ui_out_text (uiout, "\tmarker id is ");
4996 ui_out_field_string (uiout, "static-tracepoint-marker-string-id",
4997 b->static_trace_marker_id);
4998 ui_out_text (uiout, "\n");
5001 if (part_of_multiple && frame_id_p (b->frame_id))
5004 ui_out_text (uiout, "\tstop only in stack frame at ");
5005 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
5007 ui_out_field_core_addr (uiout, "frame",
5008 b->gdbarch, b->frame_id.stack_addr);
5009 ui_out_text (uiout, "\n");
5012 if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b))
5014 /* We do not print the condition for Ada exception catchpoints
5015 because the condition is an internal implementation detail
5016 that we do not want to expose to the user. */
5018 if (is_tracepoint (b))
5019 ui_out_text (uiout, "\ttrace only if ");
5021 ui_out_text (uiout, "\tstop only if ");
5022 ui_out_field_string (uiout, "cond", b->cond_string);
5023 ui_out_text (uiout, "\n");
5026 if (!part_of_multiple && b->thread != -1)
5028 /* FIXME should make an annotation for this. */
5029 ui_out_text (uiout, "\tstop only in thread ");
5030 ui_out_field_int (uiout, "thread", b->thread);
5031 ui_out_text (uiout, "\n");
5034 if (!part_of_multiple && b->hit_count)
5036 /* FIXME should make an annotation for this. */
5037 if (ep_is_catchpoint (b))
5038 ui_out_text (uiout, "\tcatchpoint");
5040 ui_out_text (uiout, "\tbreakpoint");
5041 ui_out_text (uiout, " already hit ");
5042 ui_out_field_int (uiout, "times", b->hit_count);
5043 if (b->hit_count == 1)
5044 ui_out_text (uiout, " time\n");
5046 ui_out_text (uiout, " times\n");
5049 /* Output the count also if it is zero, but only if this is mi.
5050 FIXME: Should have a better test for this. */
5051 if (ui_out_is_mi_like_p (uiout))
5052 if (!part_of_multiple && b->hit_count == 0)
5053 ui_out_field_int (uiout, "times", b->hit_count);
5055 if (!part_of_multiple && b->ignore_count)
5058 ui_out_text (uiout, "\tignore next ");
5059 ui_out_field_int (uiout, "ignore", b->ignore_count);
5060 ui_out_text (uiout, " hits\n");
5063 l = b->commands ? b->commands->commands : NULL;
5064 if (!part_of_multiple && l)
5066 struct cleanup *script_chain;
5069 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
5070 print_command_lines (uiout, l, 4);
5071 do_cleanups (script_chain);
5074 if (!part_of_multiple && b->pass_count)
5076 annotate_field (10);
5077 ui_out_text (uiout, "\tpass count ");
5078 ui_out_field_int (uiout, "pass", b->pass_count);
5079 ui_out_text (uiout, " \n");
5082 if (ui_out_is_mi_like_p (uiout) && !part_of_multiple)
5085 ui_out_field_string (uiout, "original-location", b->addr_string);
5086 else if (b->exp_string)
5087 ui_out_field_string (uiout, "original-location", b->exp_string);
5092 print_one_breakpoint (struct breakpoint *b,
5093 struct bp_location **last_loc,
5096 struct cleanup *bkpt_chain;
5098 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
5100 print_one_breakpoint_location (b, NULL, 0, last_loc, allflag);
5101 do_cleanups (bkpt_chain);
5103 /* If this breakpoint has custom print function,
5104 it's already printed. Otherwise, print individual
5105 locations, if any. */
5106 if (b->ops == NULL || b->ops->print_one == NULL)
5108 /* If breakpoint has a single location that is disabled, we
5109 print it as if it had several locations, since otherwise it's
5110 hard to represent "breakpoint enabled, location disabled"
5113 Note that while hardware watchpoints have several locations
5114 internally, that's not a property exposed to user. */
5116 && !is_hardware_watchpoint (b)
5117 && (b->loc->next || !b->loc->enabled))
5119 struct bp_location *loc;
5122 for (loc = b->loc; loc; loc = loc->next, ++n)
5124 struct cleanup *inner2 =
5125 make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
5126 print_one_breakpoint_location (b, loc, n, last_loc, allflag);
5127 do_cleanups (inner2);
5134 breakpoint_address_bits (struct breakpoint *b)
5136 int print_address_bits = 0;
5137 struct bp_location *loc;
5139 for (loc = b->loc; loc; loc = loc->next)
5143 /* Software watchpoints that aren't watching memory don't have
5144 an address to print. */
5145 if (b->type == bp_watchpoint && loc->watchpoint_type == -1)
5148 addr_bit = gdbarch_addr_bit (loc->gdbarch);
5149 if (addr_bit > print_address_bits)
5150 print_address_bits = addr_bit;
5153 return print_address_bits;
5156 struct captured_breakpoint_query_args
5162 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
5164 struct captured_breakpoint_query_args *args = data;
5165 struct breakpoint *b;
5166 struct bp_location *dummy_loc = NULL;
5170 if (args->bnum == b->number)
5172 print_one_breakpoint (b, &dummy_loc, 0);
5180 gdb_breakpoint_query (struct ui_out *uiout, int bnum,
5181 char **error_message)
5183 struct captured_breakpoint_query_args args;
5186 /* For the moment we don't trust print_one_breakpoint() to not throw
5188 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
5189 error_message, RETURN_MASK_ALL) < 0)
5195 /* Return true if this breakpoint was set by the user, false if it is
5196 internal or momentary. */
5199 user_breakpoint_p (struct breakpoint *b)
5201 return b->number > 0;
5204 /* Print information on user settable breakpoint (watchpoint, etc)
5205 number BNUM. If BNUM is -1 print all user-settable breakpoints.
5206 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
5207 FILTER is non-NULL, call it on each breakpoint and only include the
5208 ones for which it returns non-zero. Return the total number of
5209 breakpoints listed. */
5212 breakpoint_1 (char *args, int allflag,
5213 int (*filter) (const struct breakpoint *))
5215 struct breakpoint *b;
5216 struct bp_location *last_loc = NULL;
5217 int nr_printable_breakpoints;
5218 struct cleanup *bkpttbl_chain;
5219 struct value_print_options opts;
5220 int print_address_bits = 0;
5221 int print_type_col_width = 14;
5223 get_user_print_options (&opts);
5225 /* Compute the number of rows in the table, as well as the size
5226 required for address fields. */
5227 nr_printable_breakpoints = 0;
5230 /* If we have a filter, only list the breakpoints it accepts. */
5231 if (filter && !filter (b))
5234 /* If we have an "args" string, it is a list of breakpoints to
5235 accept. Skip the others. */
5236 if (args != NULL && *args != '\0')
5238 if (allflag && parse_and_eval_long (args) != b->number)
5240 if (!allflag && !number_is_in_list (args, b->number))
5244 if (allflag || user_breakpoint_p (b))
5246 int addr_bit, type_len;
5248 addr_bit = breakpoint_address_bits (b);
5249 if (addr_bit > print_address_bits)
5250 print_address_bits = addr_bit;
5252 type_len = strlen (bptype_string (b->type));
5253 if (type_len > print_type_col_width)
5254 print_type_col_width = type_len;
5256 nr_printable_breakpoints++;
5260 if (opts.addressprint)
5262 = make_cleanup_ui_out_table_begin_end (uiout, 6,
5263 nr_printable_breakpoints,
5267 = make_cleanup_ui_out_table_begin_end (uiout, 5,
5268 nr_printable_breakpoints,
5271 if (nr_printable_breakpoints > 0)
5272 annotate_breakpoints_headers ();
5273 if (nr_printable_breakpoints > 0)
5275 ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */
5276 if (nr_printable_breakpoints > 0)
5278 ui_out_table_header (uiout, print_type_col_width, ui_left,
5279 "type", "Type"); /* 2 */
5280 if (nr_printable_breakpoints > 0)
5282 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
5283 if (nr_printable_breakpoints > 0)
5285 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
5286 if (opts.addressprint)
5288 if (nr_printable_breakpoints > 0)
5290 if (print_address_bits <= 32)
5291 ui_out_table_header (uiout, 10, ui_left,
5292 "addr", "Address"); /* 5 */
5294 ui_out_table_header (uiout, 18, ui_left,
5295 "addr", "Address"); /* 5 */
5297 if (nr_printable_breakpoints > 0)
5299 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
5300 ui_out_table_body (uiout);
5301 if (nr_printable_breakpoints > 0)
5302 annotate_breakpoints_table ();
5307 /* If we have a filter, only list the breakpoints it accepts. */
5308 if (filter && !filter (b))
5311 /* If we have an "args" string, it is a list of breakpoints to
5312 accept. Skip the others. */
5314 if (args != NULL && *args != '\0')
5316 if (allflag) /* maintenance info breakpoint */
5318 if (parse_and_eval_long (args) != b->number)
5321 else /* all others */
5323 if (!number_is_in_list (args, b->number))
5327 /* We only print out user settable breakpoints unless the
5329 if (allflag || user_breakpoint_p (b))
5330 print_one_breakpoint (b, &last_loc, allflag);
5333 do_cleanups (bkpttbl_chain);
5335 if (nr_printable_breakpoints == 0)
5337 /* If there's a filter, let the caller decide how to report
5341 if (args == NULL || *args == '\0')
5342 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
5344 ui_out_message (uiout, 0,
5345 "No breakpoint or watchpoint matching '%s'.\n",
5351 if (last_loc && !server_command)
5352 set_next_address (last_loc->gdbarch, last_loc->address);
5355 /* FIXME? Should this be moved up so that it is only called when
5356 there have been breakpoints? */
5357 annotate_breakpoints_table_end ();
5359 return nr_printable_breakpoints;
5362 /* Display the value of default-collect in a way that is generally
5363 compatible with the breakpoint list. */
5366 default_collect_info (void)
5368 /* If it has no value (which is frequently the case), say nothing; a
5369 message like "No default-collect." gets in user's face when it's
5371 if (!*default_collect)
5374 /* The following phrase lines up nicely with per-tracepoint collect
5376 ui_out_text (uiout, "default collect ");
5377 ui_out_field_string (uiout, "default-collect", default_collect);
5378 ui_out_text (uiout, " \n");
5382 breakpoints_info (char *args, int from_tty)
5384 breakpoint_1 (args, 0, NULL);
5386 default_collect_info ();
5390 watchpoints_info (char *args, int from_tty)
5392 int num_printed = breakpoint_1 (args, 0, is_watchpoint);
5394 if (num_printed == 0)
5396 if (args == NULL || *args == '\0')
5397 ui_out_message (uiout, 0, "No watchpoints.\n");
5399 ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args);
5404 maintenance_info_breakpoints (char *args, int from_tty)
5406 breakpoint_1 (args, 1, NULL);
5408 default_collect_info ();
5412 breakpoint_has_pc (struct breakpoint *b,
5413 struct program_space *pspace,
5414 CORE_ADDR pc, struct obj_section *section)
5416 struct bp_location *bl = b->loc;
5418 for (; bl; bl = bl->next)
5420 if (bl->pspace == pspace
5421 && bl->address == pc
5422 && (!overlay_debugging || bl->section == section))
5428 /* Print a message describing any breakpoints set at PC. This
5429 concerns with logical breakpoints, so we match program spaces, not
5433 describe_other_breakpoints (struct gdbarch *gdbarch,
5434 struct program_space *pspace, CORE_ADDR pc,
5435 struct obj_section *section, int thread)
5438 struct breakpoint *b;
5441 others += breakpoint_has_pc (b, pspace, pc, section);
5445 printf_filtered (_("Note: breakpoint "));
5446 else /* if (others == ???) */
5447 printf_filtered (_("Note: breakpoints "));
5449 if (breakpoint_has_pc (b, pspace, pc, section))
5452 printf_filtered ("%d", b->number);
5453 if (b->thread == -1 && thread != -1)
5454 printf_filtered (" (all threads)");
5455 else if (b->thread != -1)
5456 printf_filtered (" (thread %d)", b->thread);
5457 printf_filtered ("%s%s ",
5458 ((b->enable_state == bp_disabled
5459 || b->enable_state == bp_call_disabled
5460 || b->enable_state == bp_startup_disabled)
5462 : b->enable_state == bp_permanent
5466 : ((others == 1) ? " and" : ""));
5468 printf_filtered (_("also set at pc "));
5469 fputs_filtered (paddress (gdbarch, pc), gdb_stdout);
5470 printf_filtered (".\n");
5474 /* Set the default place to put a breakpoint
5475 for the `break' command with no arguments. */
5478 set_default_breakpoint (int valid, struct program_space *pspace,
5479 CORE_ADDR addr, struct symtab *symtab,
5482 default_breakpoint_valid = valid;
5483 default_breakpoint_pspace = pspace;
5484 default_breakpoint_address = addr;
5485 default_breakpoint_symtab = symtab;
5486 default_breakpoint_line = line;
5489 /* Return true iff it is meaningful to use the address member of
5490 BPT. For some breakpoint types, the address member is irrelevant
5491 and it makes no sense to attempt to compare it to other addresses
5492 (or use it for any other purpose either).
5494 More specifically, each of the following breakpoint types will
5495 always have a zero valued address and we don't want to mark
5496 breakpoints of any of these types to be a duplicate of an actual
5497 breakpoint at address zero:
5505 breakpoint_address_is_meaningful (struct breakpoint *bpt)
5507 enum bptype type = bpt->type;
5509 return (type != bp_watchpoint && type != bp_catchpoint);
5512 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
5513 true if LOC1 and LOC2 represent the same watchpoint location. */
5516 watchpoint_locations_match (struct bp_location *loc1,
5517 struct bp_location *loc2)
5519 /* Both of them must not be in moribund_locations. */
5520 gdb_assert (loc1->owner != NULL);
5521 gdb_assert (loc2->owner != NULL);
5523 /* If the target can evaluate the condition expression in hardware,
5524 then we we need to insert both watchpoints even if they are at
5525 the same place. Otherwise the watchpoint will only trigger when
5526 the condition of whichever watchpoint was inserted evaluates to
5527 true, not giving a chance for GDB to check the condition of the
5528 other watchpoint. */
5529 if ((loc1->owner->cond_exp
5530 && target_can_accel_watchpoint_condition (loc1->address,
5532 loc1->watchpoint_type,
5533 loc1->owner->cond_exp))
5534 || (loc2->owner->cond_exp
5535 && target_can_accel_watchpoint_condition (loc2->address,
5537 loc2->watchpoint_type,
5538 loc2->owner->cond_exp)))
5541 /* Note that this checks the owner's type, not the location's. In
5542 case the target does not support read watchpoints, but does
5543 support access watchpoints, we'll have bp_read_watchpoint
5544 watchpoints with hw_access locations. Those should be considered
5545 duplicates of hw_read locations. The hw_read locations will
5546 become hw_access locations later. */
5547 return (loc1->owner->type == loc2->owner->type
5548 && loc1->pspace->aspace == loc2->pspace->aspace
5549 && loc1->address == loc2->address
5550 && loc1->length == loc2->length);
5553 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
5554 same breakpoint location. In most targets, this can only be true
5555 if ASPACE1 matches ASPACE2. On targets that have global
5556 breakpoints, the address space doesn't really matter. */
5559 breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1,
5560 struct address_space *aspace2, CORE_ADDR addr2)
5562 return ((gdbarch_has_global_breakpoints (target_gdbarch)
5563 || aspace1 == aspace2)
5567 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
5568 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
5569 matches ASPACE2. On targets that have global breakpoints, the address
5570 space doesn't really matter. */
5573 breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1,
5574 int len1, struct address_space *aspace2,
5577 return ((gdbarch_has_global_breakpoints (target_gdbarch)
5578 || aspace1 == aspace2)
5579 && addr2 >= addr1 && addr2 < addr1 + len1);
5582 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
5583 a ranged breakpoint. In most targets, a match happens only if ASPACE
5584 matches the breakpoint's address space. On targets that have global
5585 breakpoints, the address space doesn't really matter. */
5588 breakpoint_location_address_match (struct bp_location *bl,
5589 struct address_space *aspace,
5592 return (breakpoint_address_match (bl->pspace->aspace, bl->address,
5595 && breakpoint_address_match_range (bl->pspace->aspace,
5596 bl->address, bl->length,
5600 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
5601 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
5602 represent the same location. */
5605 breakpoint_locations_match (struct bp_location *loc1,
5606 struct bp_location *loc2)
5608 int hw_point1, hw_point2;
5610 /* Both of them must not be in moribund_locations. */
5611 gdb_assert (loc1->owner != NULL);
5612 gdb_assert (loc2->owner != NULL);
5614 hw_point1 = is_hardware_watchpoint (loc1->owner);
5615 hw_point2 = is_hardware_watchpoint (loc2->owner);
5617 if (hw_point1 != hw_point2)
5620 return watchpoint_locations_match (loc1, loc2);
5622 /* We compare bp_location.length in order to cover ranged breakpoints. */
5623 return (breakpoint_address_match (loc1->pspace->aspace, loc1->address,
5624 loc2->pspace->aspace, loc2->address)
5625 && loc1->length == loc2->length);
5629 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
5630 int bnum, int have_bnum)
5632 /* The longest string possibly returned by hex_string_custom
5633 is 50 chars. These must be at least that big for safety. */
5637 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
5638 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
5640 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
5641 bnum, astr1, astr2);
5643 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
5646 /* Adjust a breakpoint's address to account for architectural
5647 constraints on breakpoint placement. Return the adjusted address.
5648 Note: Very few targets require this kind of adjustment. For most
5649 targets, this function is simply the identity function. */
5652 adjust_breakpoint_address (struct gdbarch *gdbarch,
5653 CORE_ADDR bpaddr, enum bptype bptype)
5655 if (!gdbarch_adjust_breakpoint_address_p (gdbarch))
5657 /* Very few targets need any kind of breakpoint adjustment. */
5660 else if (bptype == bp_watchpoint
5661 || bptype == bp_hardware_watchpoint
5662 || bptype == bp_read_watchpoint
5663 || bptype == bp_access_watchpoint
5664 || bptype == bp_catchpoint)
5666 /* Watchpoints and the various bp_catch_* eventpoints should not
5667 have their addresses modified. */
5672 CORE_ADDR adjusted_bpaddr;
5674 /* Some targets have architectural constraints on the placement
5675 of breakpoint instructions. Obtain the adjusted address. */
5676 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr);
5678 /* An adjusted breakpoint address can significantly alter
5679 a user's expectations. Print a warning if an adjustment
5681 if (adjusted_bpaddr != bpaddr)
5682 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
5684 return adjusted_bpaddr;
5688 /* Allocate a struct bp_location. */
5690 static struct bp_location *
5691 allocate_bp_location (struct breakpoint *bpt)
5693 struct bp_location *loc;
5695 loc = xmalloc (sizeof (struct bp_location));
5696 memset (loc, 0, sizeof (*loc));
5700 loc->shlib_disabled = 0;
5709 case bp_longjmp_resume:
5711 case bp_exception_resume:
5712 case bp_step_resume:
5713 case bp_hp_step_resume:
5714 case bp_watchpoint_scope:
5716 case bp_std_terminate:
5717 case bp_shlib_event:
5718 case bp_thread_event:
5719 case bp_overlay_event:
5721 case bp_longjmp_master:
5722 case bp_std_terminate_master:
5723 case bp_exception_master:
5724 case bp_gnu_ifunc_resolver:
5725 case bp_gnu_ifunc_resolver_return:
5726 loc->loc_type = bp_loc_software_breakpoint;
5728 case bp_hardware_breakpoint:
5729 loc->loc_type = bp_loc_hardware_breakpoint;
5731 case bp_hardware_watchpoint:
5732 case bp_read_watchpoint:
5733 case bp_access_watchpoint:
5734 loc->loc_type = bp_loc_hardware_watchpoint;
5739 case bp_fast_tracepoint:
5740 case bp_static_tracepoint:
5741 loc->loc_type = bp_loc_other;
5744 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
5752 free_bp_location (struct bp_location *loc)
5757 if (loc->function_name)
5758 xfree (loc->function_name);
5763 /* Increment reference count. */
5766 incref_bp_location (struct bp_location *bl)
5771 /* Decrement reference count. If the reference count reaches 0,
5772 destroy the bp_location. Sets *BLP to NULL. */
5775 decref_bp_location (struct bp_location **blp)
5777 gdb_assert ((*blp)->refc > 0);
5779 if (--(*blp)->refc == 0)
5780 free_bp_location (*blp);
5784 /* Add breakpoint B at the end of the global breakpoint chain. */
5787 add_to_breakpoint_chain (struct breakpoint *b)
5789 struct breakpoint *b1;
5791 /* Add this breakpoint to the end of the chain so that a list of
5792 breakpoints will come out in order of increasing numbers. */
5794 b1 = breakpoint_chain;
5796 breakpoint_chain = b;
5805 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
5808 init_raw_breakpoint_without_location (struct breakpoint *b,
5809 struct gdbarch *gdbarch,
5812 memset (b, 0, sizeof (*b));
5815 b->gdbarch = gdbarch;
5816 b->language = current_language->la_language;
5817 b->input_radix = input_radix;
5819 b->enable_state = bp_enabled;
5822 b->ignore_count = 0;
5824 b->frame_id = null_frame_id;
5826 b->condition_not_parsed = 0;
5827 b->py_bp_object = NULL;
5828 b->related_breakpoint = b;
5831 /* Helper to set_raw_breakpoint below. Creates a breakpoint
5832 that has type BPTYPE and has no locations as yet. */
5833 /* This function is used in gdbtk sources and thus can not be made
5836 static struct breakpoint *
5837 set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
5840 struct breakpoint *b = XNEW (struct breakpoint);
5842 init_raw_breakpoint_without_location (b, gdbarch, bptype);
5843 add_to_breakpoint_chain (b);
5847 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
5848 resolutions should be made as the user specified the location explicitly
5852 set_breakpoint_location_function (struct bp_location *loc, int explicit_loc)
5854 gdb_assert (loc->owner != NULL);
5856 if (loc->owner->type == bp_breakpoint
5857 || loc->owner->type == bp_hardware_breakpoint
5858 || is_tracepoint (loc->owner))
5862 find_pc_partial_function_gnu_ifunc (loc->address, &loc->function_name,
5863 NULL, NULL, &is_gnu_ifunc);
5865 if (is_gnu_ifunc && !explicit_loc)
5867 struct breakpoint *b = loc->owner;
5869 gdb_assert (loc->pspace == current_program_space);
5870 if (gnu_ifunc_resolve_name (loc->function_name,
5871 &loc->requested_address))
5873 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
5874 loc->address = adjust_breakpoint_address (loc->gdbarch,
5875 loc->requested_address,
5878 else if (b->type == bp_breakpoint && b->loc == loc
5879 && loc->next == NULL && b->related_breakpoint == b)
5881 /* Create only the whole new breakpoint of this type but do not
5882 mess more complicated breakpoints with multiple locations. */
5883 b->type = bp_gnu_ifunc_resolver;
5887 if (loc->function_name)
5888 loc->function_name = xstrdup (loc->function_name);
5892 /* Attempt to determine architecture of location identified by SAL. */
5893 static struct gdbarch *
5894 get_sal_arch (struct symtab_and_line sal)
5897 return get_objfile_arch (sal.section->objfile);
5899 return get_objfile_arch (sal.symtab->objfile);
5904 /* Low level routine for partially initializing a breakpoint of type
5905 BPTYPE. The newly created breakpoint's address, section, source
5906 file name, and line number are provided by SAL.
5908 It is expected that the caller will complete the initialization of
5909 the newly created breakpoint struct as well as output any status
5910 information regarding the creation of a new breakpoint. */
5913 init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch,
5914 struct symtab_and_line sal, enum bptype bptype)
5916 CORE_ADDR adjusted_address;
5917 struct gdbarch *loc_gdbarch;
5919 init_raw_breakpoint_without_location (b, gdbarch, bptype);
5921 loc_gdbarch = get_sal_arch (sal);
5923 loc_gdbarch = b->gdbarch;
5925 if (bptype != bp_catchpoint)
5926 gdb_assert (sal.pspace != NULL);
5928 /* Adjust the breakpoint's address prior to allocating a location.
5929 Once we call allocate_bp_location(), that mostly uninitialized
5930 location will be placed on the location chain. Adjustment of the
5931 breakpoint may cause target_read_memory() to be called and we do
5932 not want its scan of the location chain to find a breakpoint and
5933 location that's only been partially initialized. */
5934 adjusted_address = adjust_breakpoint_address (loc_gdbarch,
5937 b->loc = allocate_bp_location (b);
5938 b->loc->gdbarch = loc_gdbarch;
5939 b->loc->requested_address = sal.pc;
5940 b->loc->address = adjusted_address;
5941 b->loc->pspace = sal.pspace;
5943 /* Store the program space that was used to set the breakpoint, for
5944 breakpoint resetting. */
5945 b->pspace = sal.pspace;
5947 if (sal.symtab == NULL)
5948 b->source_file = NULL;
5950 b->source_file = xstrdup (sal.symtab->filename);
5951 b->loc->section = sal.section;
5952 b->line_number = sal.line;
5954 set_breakpoint_location_function (b->loc,
5955 sal.explicit_pc || sal.explicit_line);
5957 breakpoints_changed ();
5960 /* set_raw_breakpoint is a low level routine for allocating and
5961 partially initializing a breakpoint of type BPTYPE. The newly
5962 created breakpoint's address, section, source file name, and line
5963 number are provided by SAL. The newly created and partially
5964 initialized breakpoint is added to the breakpoint chain and
5965 is also returned as the value of this function.
5967 It is expected that the caller will complete the initialization of
5968 the newly created breakpoint struct as well as output any status
5969 information regarding the creation of a new breakpoint. In
5970 particular, set_raw_breakpoint does NOT set the breakpoint
5971 number! Care should be taken to not allow an error to occur
5972 prior to completing the initialization of the breakpoint. If this
5973 should happen, a bogus breakpoint will be left on the chain. */
5976 set_raw_breakpoint (struct gdbarch *gdbarch,
5977 struct symtab_and_line sal, enum bptype bptype)
5979 struct breakpoint *b = XNEW (struct breakpoint);
5981 init_raw_breakpoint (b, gdbarch, sal, bptype);
5982 add_to_breakpoint_chain (b);
5987 /* Note that the breakpoint object B describes a permanent breakpoint
5988 instruction, hard-wired into the inferior's code. */
5990 make_breakpoint_permanent (struct breakpoint *b)
5992 struct bp_location *bl;
5994 b->enable_state = bp_permanent;
5996 /* By definition, permanent breakpoints are already present in the
5997 code. Mark all locations as inserted. For now,
5998 make_breakpoint_permanent is called in just one place, so it's
5999 hard to say if it's reasonable to have permanent breakpoint with
6000 multiple locations or not, but it's easy to implmement. */
6001 for (bl = b->loc; bl; bl = bl->next)
6005 /* Call this routine when stepping and nexting to enable a breakpoint
6006 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
6007 initiated the operation. */
6010 set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame)
6012 struct breakpoint *b, *b_tmp;
6013 int thread = tp->num;
6015 /* To avoid having to rescan all objfile symbols at every step,
6016 we maintain a list of continually-inserted but always disabled
6017 longjmp "master" breakpoints. Here, we simply create momentary
6018 clones of those and enable them for the requested thread. */
6019 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6020 if (b->pspace == current_program_space
6021 && (b->type == bp_longjmp_master
6022 || b->type == bp_exception_master))
6024 struct breakpoint *clone = clone_momentary_breakpoint (b);
6026 clone->type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception;
6027 clone->thread = thread;
6030 tp->initiating_frame = frame;
6033 /* Delete all longjmp breakpoints from THREAD. */
6035 delete_longjmp_breakpoint (int thread)
6037 struct breakpoint *b, *b_tmp;
6039 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6040 if (b->type == bp_longjmp || b->type == bp_exception)
6042 if (b->thread == thread)
6043 delete_breakpoint (b);
6048 enable_overlay_breakpoints (void)
6050 struct breakpoint *b;
6053 if (b->type == bp_overlay_event)
6055 b->enable_state = bp_enabled;
6056 update_global_location_list (1);
6057 overlay_events_enabled = 1;
6062 disable_overlay_breakpoints (void)
6064 struct breakpoint *b;
6067 if (b->type == bp_overlay_event)
6069 b->enable_state = bp_disabled;
6070 update_global_location_list (0);
6071 overlay_events_enabled = 0;
6075 /* Set an active std::terminate breakpoint for each std::terminate
6076 master breakpoint. */
6078 set_std_terminate_breakpoint (void)
6080 struct breakpoint *b, *b_tmp;
6082 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6083 if (b->pspace == current_program_space
6084 && b->type == bp_std_terminate_master)
6086 struct breakpoint *clone = clone_momentary_breakpoint (b);
6087 clone->type = bp_std_terminate;
6091 /* Delete all the std::terminate breakpoints. */
6093 delete_std_terminate_breakpoint (void)
6095 struct breakpoint *b, *b_tmp;
6097 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6098 if (b->type == bp_std_terminate)
6099 delete_breakpoint (b);
6103 create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
6105 struct breakpoint *b;
6107 b = create_internal_breakpoint (gdbarch, address, bp_thread_event);
6109 b->enable_state = bp_enabled;
6110 /* addr_string has to be used or breakpoint_re_set will delete me. */
6112 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
6114 update_global_location_list_nothrow (1);
6120 remove_thread_event_breakpoints (void)
6122 struct breakpoint *b, *b_tmp;
6124 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6125 if (b->type == bp_thread_event
6126 && b->loc->pspace == current_program_space)
6127 delete_breakpoint (b);
6130 struct lang_and_radix
6136 /* Create a breakpoint for JIT code registration and unregistration. */
6139 create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
6141 struct breakpoint *b;
6143 b = create_internal_breakpoint (gdbarch, address, bp_jit_event);
6144 update_global_location_list_nothrow (1);
6148 /* Remove JIT code registration and unregistration breakpoint(s). */
6151 remove_jit_event_breakpoints (void)
6153 struct breakpoint *b, *b_tmp;
6155 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6156 if (b->type == bp_jit_event
6157 && b->loc->pspace == current_program_space)
6158 delete_breakpoint (b);
6162 remove_solib_event_breakpoints (void)
6164 struct breakpoint *b, *b_tmp;
6166 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6167 if (b->type == bp_shlib_event
6168 && b->loc->pspace == current_program_space)
6169 delete_breakpoint (b);
6173 create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
6175 struct breakpoint *b;
6177 b = create_internal_breakpoint (gdbarch, address, bp_shlib_event);
6178 update_global_location_list_nothrow (1);
6182 /* Disable any breakpoints that are on code in shared libraries. Only
6183 apply to enabled breakpoints, disabled ones can just stay disabled. */
6186 disable_breakpoints_in_shlibs (void)
6188 struct bp_location *loc, **locp_tmp;
6190 ALL_BP_LOCATIONS (loc, locp_tmp)
6192 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6193 struct breakpoint *b = loc->owner;
6195 /* We apply the check to all breakpoints, including disabled for
6196 those with loc->duplicate set. This is so that when breakpoint
6197 becomes enabled, or the duplicate is removed, gdb will try to
6198 insert all breakpoints. If we don't set shlib_disabled here,
6199 we'll try to insert those breakpoints and fail. */
6200 if (((b->type == bp_breakpoint)
6201 || (b->type == bp_jit_event)
6202 || (b->type == bp_hardware_breakpoint)
6203 || (is_tracepoint (b)))
6204 && loc->pspace == current_program_space
6205 && !loc->shlib_disabled
6207 && PC_SOLIB (loc->address)
6209 && solib_name_from_address (loc->pspace, loc->address)
6213 loc->shlib_disabled = 1;
6218 /* Disable any breakpoints that are in an unloaded shared library.
6219 Only apply to enabled breakpoints, disabled ones can just stay
6223 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
6225 struct bp_location *loc, **locp_tmp;
6226 int disabled_shlib_breaks = 0;
6228 /* SunOS a.out shared libraries are always mapped, so do not
6229 disable breakpoints; they will only be reported as unloaded
6230 through clear_solib when GDB discards its shared library
6231 list. See clear_solib for more information. */
6232 if (exec_bfd != NULL
6233 && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour)
6236 ALL_BP_LOCATIONS (loc, locp_tmp)
6238 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6239 struct breakpoint *b = loc->owner;
6241 if ((loc->loc_type == bp_loc_hardware_breakpoint
6242 || loc->loc_type == bp_loc_software_breakpoint)
6243 && solib->pspace == loc->pspace
6244 && !loc->shlib_disabled
6245 && (b->type == bp_breakpoint
6246 || b->type == bp_jit_event
6247 || b->type == bp_hardware_breakpoint)
6248 && solib_contains_address_p (solib, loc->address))
6250 loc->shlib_disabled = 1;
6251 /* At this point, we cannot rely on remove_breakpoint
6252 succeeding so we must mark the breakpoint as not inserted
6253 to prevent future errors occurring in remove_breakpoints. */
6256 /* This may cause duplicate notifications for the same breakpoint. */
6257 observer_notify_breakpoint_modified (b);
6259 if (!disabled_shlib_breaks)
6261 target_terminal_ours_for_output ();
6262 warning (_("Temporarily disabling breakpoints "
6263 "for unloaded shared library \"%s\""),
6266 disabled_shlib_breaks = 1;
6271 /* FORK & VFORK catchpoints. */
6273 /* An instance of this type is used to represent a fork or vfork
6274 catchpoint. It includes a "struct breakpoint" as a kind of base
6275 class; users downcast to "struct breakpoint *" when needed. A
6276 breakpoint is really of this type iff its ops pointer points to
6277 CATCH_FORK_BREAKPOINT_OPS. */
6279 struct fork_catchpoint
6281 /* The base class. */
6282 struct breakpoint base;
6284 /* Process id of a child process whose forking triggered this
6285 catchpoint. This field is only valid immediately after this
6286 catchpoint has triggered. */
6287 ptid_t forked_inferior_pid;
6290 /* Implement the "insert" breakpoint_ops method for fork
6294 insert_catch_fork (struct bp_location *bl)
6296 return target_insert_fork_catchpoint (PIDGET (inferior_ptid));
6299 /* Implement the "remove" breakpoint_ops method for fork
6303 remove_catch_fork (struct bp_location *bl)
6305 return target_remove_fork_catchpoint (PIDGET (inferior_ptid));
6308 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
6312 breakpoint_hit_catch_fork (const struct bp_location *bl,
6313 struct address_space *aspace, CORE_ADDR bp_addr)
6315 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
6317 return inferior_has_forked (inferior_ptid, &c->forked_inferior_pid);
6320 /* Implement the "print_it" breakpoint_ops method for fork
6323 static enum print_stop_action
6324 print_it_catch_fork (struct breakpoint *b)
6326 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
6328 annotate_catchpoint (b->number);
6329 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
6330 b->number, ptid_get_pid (c->forked_inferior_pid));
6331 return PRINT_SRC_AND_LOC;
6334 /* Implement the "print_one" breakpoint_ops method for fork
6338 print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc)
6340 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
6341 struct value_print_options opts;
6343 get_user_print_options (&opts);
6345 /* Field 4, the address, is omitted (which makes the columns not
6346 line up too nicely with the headers, but the effect is relatively
6348 if (opts.addressprint)
6349 ui_out_field_skip (uiout, "addr");
6351 ui_out_text (uiout, "fork");
6352 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
6354 ui_out_text (uiout, ", process ");
6355 ui_out_field_int (uiout, "what",
6356 ptid_get_pid (c->forked_inferior_pid));
6357 ui_out_spaces (uiout, 1);
6361 /* Implement the "print_mention" breakpoint_ops method for fork
6365 print_mention_catch_fork (struct breakpoint *b)
6367 printf_filtered (_("Catchpoint %d (fork)"), b->number);
6370 /* Implement the "print_recreate" breakpoint_ops method for fork
6374 print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp)
6376 fprintf_unfiltered (fp, "catch fork");
6379 /* The breakpoint_ops structure to be used in fork catchpoints. */
6381 static struct breakpoint_ops catch_fork_breakpoint_ops =
6386 breakpoint_hit_catch_fork,
6387 NULL, /* resources_needed */
6388 NULL, /* works_in_software_mode */
6389 print_it_catch_fork,
6390 print_one_catch_fork,
6391 NULL, /* print_one_detail */
6392 print_mention_catch_fork,
6393 print_recreate_catch_fork
6396 /* Implement the "insert" breakpoint_ops method for vfork
6400 insert_catch_vfork (struct bp_location *bl)
6402 return target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
6405 /* Implement the "remove" breakpoint_ops method for vfork
6409 remove_catch_vfork (struct bp_location *bl)
6411 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
6414 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
6418 breakpoint_hit_catch_vfork (const struct bp_location *bl,
6419 struct address_space *aspace, CORE_ADDR bp_addr)
6421 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
6423 return inferior_has_vforked (inferior_ptid, &c->forked_inferior_pid);
6426 /* Implement the "print_it" breakpoint_ops method for vfork
6429 static enum print_stop_action
6430 print_it_catch_vfork (struct breakpoint *b)
6432 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
6434 annotate_catchpoint (b->number);
6435 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
6436 b->number, ptid_get_pid (c->forked_inferior_pid));
6437 return PRINT_SRC_AND_LOC;
6440 /* Implement the "print_one" breakpoint_ops method for vfork
6444 print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc)
6446 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
6447 struct value_print_options opts;
6449 get_user_print_options (&opts);
6450 /* Field 4, the address, is omitted (which makes the columns not
6451 line up too nicely with the headers, but the effect is relatively
6453 if (opts.addressprint)
6454 ui_out_field_skip (uiout, "addr");
6456 ui_out_text (uiout, "vfork");
6457 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
6459 ui_out_text (uiout, ", process ");
6460 ui_out_field_int (uiout, "what",
6461 ptid_get_pid (c->forked_inferior_pid));
6462 ui_out_spaces (uiout, 1);
6466 /* Implement the "print_mention" breakpoint_ops method for vfork
6470 print_mention_catch_vfork (struct breakpoint *b)
6472 printf_filtered (_("Catchpoint %d (vfork)"), b->number);
6475 /* Implement the "print_recreate" breakpoint_ops method for vfork
6479 print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp)
6481 fprintf_unfiltered (fp, "catch vfork");
6484 /* The breakpoint_ops structure to be used in vfork catchpoints. */
6486 static struct breakpoint_ops catch_vfork_breakpoint_ops =
6491 breakpoint_hit_catch_vfork,
6492 NULL, /* resources_needed */
6493 NULL, /* works_in_software_mode */
6494 print_it_catch_vfork,
6495 print_one_catch_vfork,
6496 NULL, /* print_one_detail */
6497 print_mention_catch_vfork,
6498 print_recreate_catch_vfork
6501 /* An instance of this type is used to represent a syscall catchpoint.
6502 It includes a "struct breakpoint" as a kind of base class; users
6503 downcast to "struct breakpoint *" when needed. A breakpoint is
6504 really of this type iff its ops pointer points to
6505 CATCH_SYSCALL_BREAKPOINT_OPS. */
6507 struct syscall_catchpoint
6509 /* The base class. */
6510 struct breakpoint base;
6512 /* Syscall numbers used for the 'catch syscall' feature. If no
6513 syscall has been specified for filtering, its value is NULL.
6514 Otherwise, it holds a list of all syscalls to be caught. The
6515 list elements are allocated with xmalloc. */
6516 VEC(int) *syscalls_to_be_caught;
6519 /* Implement the "dtor" breakpoint_ops method for syscall
6523 dtor_catch_syscall (struct breakpoint *b)
6525 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
6527 VEC_free (int, c->syscalls_to_be_caught);
6530 /* Implement the "insert" breakpoint_ops method for syscall
6534 insert_catch_syscall (struct bp_location *bl)
6536 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner;
6537 struct inferior *inf = current_inferior ();
6539 ++inf->total_syscalls_count;
6540 if (!c->syscalls_to_be_caught)
6541 ++inf->any_syscall_count;
6547 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
6552 if (iter >= VEC_length (int, inf->syscalls_counts))
6554 int old_size = VEC_length (int, inf->syscalls_counts);
6555 uintptr_t vec_addr_offset
6556 = old_size * ((uintptr_t) sizeof (int));
6558 VEC_safe_grow (int, inf->syscalls_counts, iter + 1);
6559 vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) +
6561 memset ((void *) vec_addr, 0,
6562 (iter + 1 - old_size) * sizeof (int));
6564 elem = VEC_index (int, inf->syscalls_counts, iter);
6565 VEC_replace (int, inf->syscalls_counts, iter, ++elem);
6569 return target_set_syscall_catchpoint (PIDGET (inferior_ptid),
6570 inf->total_syscalls_count != 0,
6571 inf->any_syscall_count,
6572 VEC_length (int, inf->syscalls_counts),
6573 VEC_address (int, inf->syscalls_counts));
6576 /* Implement the "remove" breakpoint_ops method for syscall
6580 remove_catch_syscall (struct bp_location *bl)
6582 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner;
6583 struct inferior *inf = current_inferior ();
6585 --inf->total_syscalls_count;
6586 if (!c->syscalls_to_be_caught)
6587 --inf->any_syscall_count;
6593 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
6597 if (iter >= VEC_length (int, inf->syscalls_counts))
6598 /* Shouldn't happen. */
6600 elem = VEC_index (int, inf->syscalls_counts, iter);
6601 VEC_replace (int, inf->syscalls_counts, iter, --elem);
6605 return target_set_syscall_catchpoint (PIDGET (inferior_ptid),
6606 inf->total_syscalls_count != 0,
6607 inf->any_syscall_count,
6608 VEC_length (int, inf->syscalls_counts),
6610 inf->syscalls_counts));
6613 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
6617 breakpoint_hit_catch_syscall (const struct bp_location *bl,
6618 struct address_space *aspace, CORE_ADDR bp_addr)
6620 /* We must check if we are catching specific syscalls in this
6621 breakpoint. If we are, then we must guarantee that the called
6622 syscall is the same syscall we are catching. */
6623 int syscall_number = 0;
6624 const struct syscall_catchpoint *c
6625 = (const struct syscall_catchpoint *) bl->owner;
6627 if (!inferior_has_called_syscall (inferior_ptid, &syscall_number))
6630 /* Now, checking if the syscall is the same. */
6631 if (c->syscalls_to_be_caught)
6636 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
6638 if (syscall_number == iter)
6648 /* Implement the "print_it" breakpoint_ops method for syscall
6651 static enum print_stop_action
6652 print_it_catch_syscall (struct breakpoint *b)
6654 /* These are needed because we want to know in which state a
6655 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
6656 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
6657 must print "called syscall" or "returned from syscall". */
6659 struct target_waitstatus last;
6661 struct cleanup *old_chain;
6664 get_last_target_status (&ptid, &last);
6666 get_syscall_by_number (last.value.syscall_number, &s);
6668 annotate_catchpoint (b->number);
6671 syscall_id = xstrprintf ("%d", last.value.syscall_number);
6673 syscall_id = xstrprintf ("'%s'", s.name);
6675 old_chain = make_cleanup (xfree, syscall_id);
6677 if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY)
6678 printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
6679 b->number, syscall_id);
6680 else if (last.kind == TARGET_WAITKIND_SYSCALL_RETURN)
6681 printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
6682 b->number, syscall_id);
6684 do_cleanups (old_chain);
6686 return PRINT_SRC_AND_LOC;
6689 /* Implement the "print_one" breakpoint_ops method for syscall
6693 print_one_catch_syscall (struct breakpoint *b,
6694 struct bp_location **last_loc)
6696 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
6697 struct value_print_options opts;
6699 get_user_print_options (&opts);
6700 /* Field 4, the address, is omitted (which makes the columns not
6701 line up too nicely with the headers, but the effect is relatively
6703 if (opts.addressprint)
6704 ui_out_field_skip (uiout, "addr");
6707 if (c->syscalls_to_be_caught
6708 && VEC_length (int, c->syscalls_to_be_caught) > 1)
6709 ui_out_text (uiout, "syscalls \"");
6711 ui_out_text (uiout, "syscall \"");
6713 if (c->syscalls_to_be_caught)
6716 char *text = xstrprintf ("%s", "");
6719 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
6724 get_syscall_by_number (iter, &s);
6727 text = xstrprintf ("%s%s, ", text, s.name);
6729 text = xstrprintf ("%s%d, ", text, iter);
6731 /* We have to xfree the last 'text' (now stored at 'x')
6732 because xstrprintf dinamically allocates new space for it
6736 /* Remove the last comma. */
6737 text[strlen (text) - 2] = '\0';
6738 ui_out_field_string (uiout, "what", text);
6741 ui_out_field_string (uiout, "what", "<any syscall>");
6742 ui_out_text (uiout, "\" ");
6745 /* Implement the "print_mention" breakpoint_ops method for syscall
6749 print_mention_catch_syscall (struct breakpoint *b)
6751 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
6753 if (c->syscalls_to_be_caught)
6757 if (VEC_length (int, c->syscalls_to_be_caught) > 1)
6758 printf_filtered (_("Catchpoint %d (syscalls"), b->number);
6760 printf_filtered (_("Catchpoint %d (syscall"), b->number);
6763 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
6767 get_syscall_by_number (iter, &s);
6770 printf_filtered (" '%s' [%d]", s.name, s.number);
6772 printf_filtered (" %d", s.number);
6774 printf_filtered (")");
6777 printf_filtered (_("Catchpoint %d (any syscall)"),
6781 /* Implement the "print_recreate" breakpoint_ops method for syscall
6785 print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp)
6787 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
6789 fprintf_unfiltered (fp, "catch syscall");
6791 if (c->syscalls_to_be_caught)
6796 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
6801 get_syscall_by_number (iter, &s);
6803 fprintf_unfiltered (fp, " %s", s.name);
6805 fprintf_unfiltered (fp, " %d", s.number);
6810 /* The breakpoint_ops structure to be used in syscall catchpoints. */
6812 static struct breakpoint_ops catch_syscall_breakpoint_ops =
6815 insert_catch_syscall,
6816 remove_catch_syscall,
6817 breakpoint_hit_catch_syscall,
6818 NULL, /* resources_needed */
6819 NULL, /* works_in_software_mode */
6820 print_it_catch_syscall,
6821 print_one_catch_syscall,
6822 NULL, /* print_one_detail */
6823 print_mention_catch_syscall,
6824 print_recreate_catch_syscall
6827 /* Returns non-zero if 'b' is a syscall catchpoint. */
6830 syscall_catchpoint_p (struct breakpoint *b)
6832 return (b->ops == &catch_syscall_breakpoint_ops);
6835 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
6836 is non-zero, then make the breakpoint temporary. If COND_STRING is
6837 not NULL, then store it in the breakpoint. OPS, if not NULL, is
6838 the breakpoint_ops structure associated to the catchpoint. */
6841 init_catchpoint (struct breakpoint *b,
6842 struct gdbarch *gdbarch, int tempflag,
6844 struct breakpoint_ops *ops)
6846 struct symtab_and_line sal;
6848 memset (b, 0, sizeof (*b));
6851 sal.pspace = current_program_space;
6853 init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint);
6855 b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string);
6857 b->addr_string = NULL;
6858 b->enable_state = bp_enabled;
6859 b->disposition = tempflag ? disp_del : disp_donttouch;
6863 /* Add breakpoint B on the breakpoint list, and notify the user, the
6864 target and breakpoint_created observers of its existence. */
6867 install_catchpoint (struct breakpoint *b)
6869 add_to_breakpoint_chain (b);
6870 set_breakpoint_count (breakpoint_count + 1);
6871 b->number = breakpoint_count;
6873 observer_notify_breakpoint_created (b);
6874 update_global_location_list (1);
6878 create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch,
6879 int tempflag, char *cond_string,
6880 struct breakpoint_ops *ops)
6882 struct fork_catchpoint *c = XNEW (struct fork_catchpoint);
6884 init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops);
6886 c->forked_inferior_pid = null_ptid;
6888 install_catchpoint (&c->base);
6891 /* Exec catchpoints. */
6893 /* An instance of this type is used to represent an exec catchpoint.
6894 It includes a "struct breakpoint" as a kind of base class; users
6895 downcast to "struct breakpoint *" when needed. A breakpoint is
6896 really of this type iff its ops pointer points to
6897 CATCH_EXEC_BREAKPOINT_OPS. */
6899 struct exec_catchpoint
6901 /* The base class. */
6902 struct breakpoint base;
6904 /* Filename of a program whose exec triggered this catchpoint.
6905 This field is only valid immediately after this catchpoint has
6907 char *exec_pathname;
6910 /* Implement the "dtor" breakpoint_ops method for exec
6914 dtor_catch_exec (struct breakpoint *b)
6916 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
6918 xfree (c->exec_pathname);
6922 insert_catch_exec (struct bp_location *bl)
6924 return target_insert_exec_catchpoint (PIDGET (inferior_ptid));
6928 remove_catch_exec (struct bp_location *bl)
6930 return target_remove_exec_catchpoint (PIDGET (inferior_ptid));
6934 breakpoint_hit_catch_exec (const struct bp_location *bl,
6935 struct address_space *aspace, CORE_ADDR bp_addr)
6937 struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner;
6939 return inferior_has_execd (inferior_ptid, &c->exec_pathname);
6942 static enum print_stop_action
6943 print_it_catch_exec (struct breakpoint *b)
6945 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
6947 annotate_catchpoint (b->number);
6948 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number,
6950 return PRINT_SRC_AND_LOC;
6954 print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc)
6956 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
6957 struct value_print_options opts;
6959 get_user_print_options (&opts);
6961 /* Field 4, the address, is omitted (which makes the columns
6962 not line up too nicely with the headers, but the effect
6963 is relatively readable). */
6964 if (opts.addressprint)
6965 ui_out_field_skip (uiout, "addr");
6967 ui_out_text (uiout, "exec");
6968 if (c->exec_pathname != NULL)
6970 ui_out_text (uiout, ", program \"");
6971 ui_out_field_string (uiout, "what", c->exec_pathname);
6972 ui_out_text (uiout, "\" ");
6977 print_mention_catch_exec (struct breakpoint *b)
6979 printf_filtered (_("Catchpoint %d (exec)"), b->number);
6982 /* Implement the "print_recreate" breakpoint_ops method for exec
6986 print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp)
6988 fprintf_unfiltered (fp, "catch exec");
6991 static struct breakpoint_ops catch_exec_breakpoint_ops =
6996 breakpoint_hit_catch_exec,
6997 NULL, /* resources_needed */
6998 NULL, /* works_in_software_mode */
6999 print_it_catch_exec,
7000 print_one_catch_exec,
7001 NULL, /* print_one_detail */
7002 print_mention_catch_exec,
7003 print_recreate_catch_exec
7007 create_syscall_event_catchpoint (int tempflag, VEC(int) *filter,
7008 struct breakpoint_ops *ops)
7010 struct syscall_catchpoint *c;
7011 struct gdbarch *gdbarch = get_current_arch ();
7013 c = XNEW (struct syscall_catchpoint);
7014 init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops);
7015 c->syscalls_to_be_caught = filter;
7017 install_catchpoint (&c->base);
7021 hw_breakpoint_used_count (void)
7024 struct breakpoint *b;
7025 struct bp_location *bl;
7029 if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b))
7030 for (bl = b->loc; bl; bl = bl->next)
7032 /* Special types of hardware breakpoints may use more than
7034 if (b->ops && b->ops->resources_needed)
7035 i += b->ops->resources_needed (bl);
7045 hw_watchpoint_used_count (enum bptype type, int *other_type_used)
7048 struct breakpoint *b;
7049 struct bp_location *bl;
7051 *other_type_used = 0;
7054 if (!breakpoint_enabled (b))
7057 if (b->type == type)
7058 for (bl = b->loc; bl; bl = bl->next)
7060 /* Special types of hardware watchpoints may use more than
7062 if (b->ops && b->ops->resources_needed)
7063 i += b->ops->resources_needed (bl);
7067 else if (is_hardware_watchpoint (b))
7068 *other_type_used = 1;
7075 disable_watchpoints_before_interactive_call_start (void)
7077 struct breakpoint *b;
7081 if (is_watchpoint (b) && breakpoint_enabled (b))
7083 b->enable_state = bp_call_disabled;
7084 update_global_location_list (0);
7090 enable_watchpoints_after_interactive_call_stop (void)
7092 struct breakpoint *b;
7096 if (is_watchpoint (b) && b->enable_state == bp_call_disabled)
7098 b->enable_state = bp_enabled;
7099 update_global_location_list (1);
7105 disable_breakpoints_before_startup (void)
7107 struct breakpoint *b;
7112 if (b->pspace != current_program_space)
7115 if ((b->type == bp_breakpoint
7116 || b->type == bp_hardware_breakpoint)
7117 && breakpoint_enabled (b))
7119 b->enable_state = bp_startup_disabled;
7125 update_global_location_list (0);
7127 current_program_space->executing_startup = 1;
7131 enable_breakpoints_after_startup (void)
7133 struct breakpoint *b;
7136 current_program_space->executing_startup = 0;
7140 if (b->pspace != current_program_space)
7143 if ((b->type == bp_breakpoint
7144 || b->type == bp_hardware_breakpoint)
7145 && b->enable_state == bp_startup_disabled)
7147 b->enable_state = bp_enabled;
7153 breakpoint_re_set ();
7157 /* Set a breakpoint that will evaporate an end of command
7158 at address specified by SAL.
7159 Restrict it to frame FRAME if FRAME is nonzero. */
7162 set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal,
7163 struct frame_id frame_id, enum bptype type)
7165 struct breakpoint *b;
7167 /* If FRAME_ID is valid, it should be a real frame, not an inlined
7169 gdb_assert (!frame_id_inlined_p (frame_id));
7171 b = set_raw_breakpoint (gdbarch, sal, type);
7172 b->enable_state = bp_enabled;
7173 b->disposition = disp_donttouch;
7174 b->frame_id = frame_id;
7176 /* If we're debugging a multi-threaded program, then we want
7177 momentary breakpoints to be active in only a single thread of
7179 if (in_thread_list (inferior_ptid))
7180 b->thread = pid_to_thread_id (inferior_ptid);
7182 update_global_location_list_nothrow (1);
7187 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
7191 clone_momentary_breakpoint (struct breakpoint *orig)
7193 struct breakpoint *copy;
7195 /* If there's nothing to clone, then return nothing. */
7199 copy = set_raw_breakpoint_without_location (orig->gdbarch, orig->type);
7200 copy->loc = allocate_bp_location (copy);
7201 set_breakpoint_location_function (copy->loc, 1);
7203 copy->loc->gdbarch = orig->loc->gdbarch;
7204 copy->loc->requested_address = orig->loc->requested_address;
7205 copy->loc->address = orig->loc->address;
7206 copy->loc->section = orig->loc->section;
7207 copy->loc->pspace = orig->loc->pspace;
7209 if (orig->source_file == NULL)
7210 copy->source_file = NULL;
7212 copy->source_file = xstrdup (orig->source_file);
7214 copy->line_number = orig->line_number;
7215 copy->frame_id = orig->frame_id;
7216 copy->thread = orig->thread;
7217 copy->pspace = orig->pspace;
7219 copy->enable_state = bp_enabled;
7220 copy->disposition = disp_donttouch;
7221 copy->number = internal_breakpoint_number--;
7223 update_global_location_list_nothrow (0);
7228 set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc,
7231 struct symtab_and_line sal;
7233 sal = find_pc_line (pc, 0);
7235 sal.section = find_pc_overlay (pc);
7236 sal.explicit_pc = 1;
7238 return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type);
7242 /* Tell the user we have just set a breakpoint B. */
7245 mention (struct breakpoint *b)
7248 struct cleanup *ui_out_chain;
7249 struct value_print_options opts;
7251 get_user_print_options (&opts);
7253 if (b->ops != NULL && b->ops->print_mention != NULL)
7254 b->ops->print_mention (b);
7259 printf_filtered (_("(apparently deleted?) Eventpoint %d: "),
7263 ui_out_text (uiout, "Watchpoint ");
7264 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
7265 ui_out_field_int (uiout, "number", b->number);
7266 ui_out_text (uiout, ": ");
7267 ui_out_field_string (uiout, "exp", b->exp_string);
7268 do_cleanups (ui_out_chain);
7270 case bp_hardware_watchpoint:
7271 ui_out_text (uiout, "Hardware watchpoint ");
7272 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
7273 ui_out_field_int (uiout, "number", b->number);
7274 ui_out_text (uiout, ": ");
7275 ui_out_field_string (uiout, "exp", b->exp_string);
7276 do_cleanups (ui_out_chain);
7278 case bp_read_watchpoint:
7279 ui_out_text (uiout, "Hardware read watchpoint ");
7280 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
7281 ui_out_field_int (uiout, "number", b->number);
7282 ui_out_text (uiout, ": ");
7283 ui_out_field_string (uiout, "exp", b->exp_string);
7284 do_cleanups (ui_out_chain);
7286 case bp_access_watchpoint:
7287 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
7288 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
7289 ui_out_field_int (uiout, "number", b->number);
7290 ui_out_text (uiout, ": ");
7291 ui_out_field_string (uiout, "exp", b->exp_string);
7292 do_cleanups (ui_out_chain);
7295 case bp_gnu_ifunc_resolver:
7296 if (ui_out_is_mi_like_p (uiout))
7301 if (b->disposition == disp_del)
7302 printf_filtered (_("Temporary breakpoint"));
7304 printf_filtered (_("Breakpoint"));
7305 printf_filtered (_(" %d"), b->number);
7306 if (b->type == bp_gnu_ifunc_resolver)
7307 printf_filtered (_(" at gnu-indirect-function resolver"));
7310 case bp_hardware_breakpoint:
7311 if (ui_out_is_mi_like_p (uiout))
7316 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
7320 if (ui_out_is_mi_like_p (uiout))
7325 printf_filtered (_("Tracepoint"));
7326 printf_filtered (_(" %d"), b->number);
7329 case bp_fast_tracepoint:
7330 if (ui_out_is_mi_like_p (uiout))
7335 printf_filtered (_("Fast tracepoint"));
7336 printf_filtered (_(" %d"), b->number);
7339 case bp_static_tracepoint:
7340 if (ui_out_is_mi_like_p (uiout))
7345 printf_filtered (_("Static tracepoint"));
7346 printf_filtered (_(" %d"), b->number);
7353 case bp_longjmp_resume:
7355 case bp_exception_resume:
7356 case bp_step_resume:
7357 case bp_hp_step_resume:
7359 case bp_std_terminate:
7360 case bp_watchpoint_scope:
7361 case bp_shlib_event:
7362 case bp_thread_event:
7363 case bp_overlay_event:
7365 case bp_longjmp_master:
7366 case bp_std_terminate_master:
7367 case bp_exception_master:
7368 case bp_gnu_ifunc_resolver_return:
7374 /* i18n: cagney/2005-02-11: Below needs to be merged into a
7378 printf_filtered (_(" (%s) pending."), b->addr_string);
7382 if (opts.addressprint || b->source_file == NULL)
7384 printf_filtered (" at ");
7385 fputs_filtered (paddress (b->loc->gdbarch, b->loc->address),
7389 printf_filtered (": file %s, line %d.",
7390 b->source_file, b->line_number);
7394 struct bp_location *loc = b->loc;
7396 for (; loc; loc = loc->next)
7398 printf_filtered (" (%d locations)", n);
7403 if (ui_out_is_mi_like_p (uiout))
7405 printf_filtered ("\n");
7409 static struct bp_location *
7410 add_location_to_breakpoint (struct breakpoint *b,
7411 const struct symtab_and_line *sal)
7413 struct bp_location *loc, **tmp;
7415 loc = allocate_bp_location (b);
7416 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
7419 loc->gdbarch = get_sal_arch (*sal);
7421 loc->gdbarch = b->gdbarch;
7422 loc->requested_address = sal->pc;
7423 loc->address = adjust_breakpoint_address (loc->gdbarch,
7424 loc->requested_address, b->type);
7425 loc->pspace = sal->pspace;
7426 gdb_assert (loc->pspace != NULL);
7427 loc->section = sal->section;
7429 set_breakpoint_location_function (loc,
7430 sal->explicit_pc || sal->explicit_line);
7435 /* Return 1 if LOC is pointing to a permanent breakpoint,
7436 return 0 otherwise. */
7439 bp_loc_is_permanent (struct bp_location *loc)
7443 const gdb_byte *brk;
7444 gdb_byte *target_mem;
7445 struct cleanup *cleanup;
7448 gdb_assert (loc != NULL);
7450 addr = loc->address;
7451 brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len);
7453 /* Software breakpoints unsupported? */
7457 target_mem = alloca (len);
7459 /* Enable the automatic memory restoration from breakpoints while
7460 we read the memory. Otherwise we could say about our temporary
7461 breakpoints they are permanent. */
7462 cleanup = save_current_space_and_thread ();
7464 switch_to_program_space_and_thread (loc->pspace);
7465 make_show_memory_breakpoints_cleanup (0);
7467 if (target_read_memory (loc->address, target_mem, len) == 0
7468 && memcmp (target_mem, brk, len) == 0)
7471 do_cleanups (cleanup);
7478 /* Create a breakpoint with SAL as location. Use ADDR_STRING
7479 as textual description of the location, and COND_STRING
7480 as condition expression. */
7483 create_breakpoint_sal (struct gdbarch *gdbarch,
7484 struct symtabs_and_lines sals, char *addr_string,
7486 enum bptype type, enum bpdisp disposition,
7487 int thread, int task, int ignore_count,
7488 struct breakpoint_ops *ops, int from_tty,
7489 int enabled, int internal, int display_canonical)
7491 struct breakpoint *b = NULL;
7494 if (type == bp_hardware_breakpoint)
7496 int i = hw_breakpoint_used_count ();
7497 int target_resources_ok =
7498 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
7500 if (target_resources_ok == 0)
7501 error (_("No hardware breakpoint support in the target."));
7502 else if (target_resources_ok < 0)
7503 error (_("Hardware breakpoints used exceeds limit."));
7506 gdb_assert (sals.nelts > 0);
7508 for (i = 0; i < sals.nelts; ++i)
7510 struct symtab_and_line sal = sals.sals[i];
7511 struct bp_location *loc;
7515 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
7517 loc_gdbarch = gdbarch;
7519 describe_other_breakpoints (loc_gdbarch,
7520 sal.pspace, sal.pc, sal.section, thread);
7525 b = set_raw_breakpoint (gdbarch, sal, type);
7526 set_breakpoint_number (internal, b);
7530 b->cond_string = cond_string;
7531 b->ignore_count = ignore_count;
7532 b->enable_state = enabled ? bp_enabled : bp_disabled;
7533 b->disposition = disposition;
7534 b->pspace = sals.sals[0].pspace;
7536 if (type == bp_static_tracepoint)
7538 struct static_tracepoint_marker marker;
7540 if (is_marker_spec (addr_string))
7542 /* We already know the marker exists, otherwise, we
7543 wouldn't see a sal for it. */
7544 char *p = &addr_string[3];
7549 p = skip_spaces (p);
7551 endp = skip_to_space (p);
7553 marker_str = savestring (p, endp - p);
7554 b->static_trace_marker_id = marker_str;
7556 printf_filtered (_("Probed static tracepoint "
7558 b->static_trace_marker_id);
7560 else if (target_static_tracepoint_marker_at (sal.pc, &marker))
7562 b->static_trace_marker_id = xstrdup (marker.str_id);
7563 release_static_tracepoint_marker (&marker);
7565 printf_filtered (_("Probed static tracepoint "
7567 b->static_trace_marker_id);
7570 warning (_("Couldn't determine the static "
7571 "tracepoint marker to probe"));
7574 if (enabled && b->pspace->executing_startup
7575 && (b->type == bp_breakpoint
7576 || b->type == bp_hardware_breakpoint))
7577 b->enable_state = bp_startup_disabled;
7583 loc = add_location_to_breakpoint (b, &sal);
7586 if (bp_loc_is_permanent (loc))
7587 make_breakpoint_permanent (b);
7591 char *arg = b->cond_string;
7592 loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0);
7594 error (_("Garbage %s follows condition"), arg);
7598 b->display_canonical = display_canonical;
7600 b->addr_string = addr_string;
7602 /* addr_string has to be used or breakpoint_re_set will delete
7605 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
7608 /* Do not mention breakpoints with a negative number, but do
7609 notify observers. */
7612 observer_notify_breakpoint_created (b);
7615 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
7616 elements to fill the void space. */
7618 remove_sal (struct symtabs_and_lines *sal, int index_to_remove)
7620 int i = index_to_remove+1;
7621 int last_index = sal->nelts-1;
7623 for (;i <= last_index; ++i)
7624 sal->sals[i-1] = sal->sals[i];
7629 /* If appropriate, obtains all sals that correspond to the same file
7630 and line as SAL, in all program spaces. Users debugging with IDEs,
7631 will want to set a breakpoint at foo.c:line, and not really care
7632 about program spaces. This is done only if SAL does not have
7633 explicit PC and has line and file information. If we got just a
7634 single expanded sal, return the original.
7636 Otherwise, if SAL.explicit_line is not set, filter out all sals for
7637 which the name of enclosing function is different from SAL. This
7638 makes sure that if we have breakpoint originally set in template
7639 instantiation, say foo<int>(), we won't expand SAL to locations at
7640 the same line in all existing instantiations of 'foo'. */
7642 static struct symtabs_and_lines
7643 expand_line_sal_maybe (struct symtab_and_line sal)
7645 struct symtabs_and_lines expanded;
7646 CORE_ADDR original_pc = sal.pc;
7647 char *original_function = NULL;
7650 struct cleanup *old_chain;
7652 /* If we have explicit pc, don't expand.
7653 If we have no line number, we can't expand. */
7654 if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL)
7657 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
7658 expanded.sals[0] = sal;
7664 old_chain = save_current_space_and_thread ();
7666 switch_to_program_space_and_thread (sal.pspace);
7668 find_pc_partial_function (original_pc, &original_function, NULL, NULL);
7670 /* Note that expand_line_sal visits *all* program spaces. */
7671 expanded = expand_line_sal (sal);
7673 if (expanded.nelts == 1)
7675 /* We had one sal, we got one sal. Return that sal, adjusting it
7676 past the function prologue if necessary. */
7677 xfree (expanded.sals);
7679 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
7680 sal.pc = original_pc;
7681 expanded.sals[0] = sal;
7682 skip_prologue_sal (&expanded.sals[0]);
7683 do_cleanups (old_chain);
7687 if (!sal.explicit_line)
7689 CORE_ADDR func_addr, func_end;
7690 for (i = 0; i < expanded.nelts; ++i)
7692 CORE_ADDR pc = expanded.sals[i].pc;
7693 char *this_function;
7695 /* We need to switch threads as well since we're about to
7697 switch_to_program_space_and_thread (expanded.sals[i].pspace);
7699 if (find_pc_partial_function (pc, &this_function,
7700 &func_addr, &func_end))
7703 && strcmp (this_function, original_function) != 0)
7705 remove_sal (&expanded, i);
7712 /* Skip the function prologue if necessary. */
7713 for (i = 0; i < expanded.nelts; ++i)
7714 skip_prologue_sal (&expanded.sals[i]);
7716 do_cleanups (old_chain);
7718 if (expanded.nelts <= 1)
7720 /* This is un ugly workaround. If we get zero expanded sals
7721 then something is really wrong. Fix that by returning the
7724 xfree (expanded.sals);
7726 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
7727 sal.pc = original_pc;
7728 expanded.sals[0] = sal;
7735 for (i = 0; i < expanded.nelts; ++i)
7736 if (expanded.sals[i].pc == original_pc)
7747 /* Add SALS.nelts breakpoints to the breakpoint table. For each
7748 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
7749 value. COND_STRING, if not NULL, specified the condition to be
7750 used for all breakpoints. Essentially the only case where
7751 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
7752 function. In that case, it's still not possible to specify
7753 separate conditions for different overloaded functions, so
7754 we take just a single condition string.
7756 NOTE: If the function succeeds, the caller is expected to cleanup
7757 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
7758 array contents). If the function fails (error() is called), the
7759 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
7760 COND and SALS arrays and each of those arrays contents. */
7763 create_breakpoints_sal (struct gdbarch *gdbarch,
7764 struct symtabs_and_lines sals,
7765 struct linespec_result *canonical,
7767 enum bptype type, enum bpdisp disposition,
7768 int thread, int task, int ignore_count,
7769 struct breakpoint_ops *ops, int from_tty,
7770 int enabled, int internal)
7774 for (i = 0; i < sals.nelts; ++i)
7776 struct symtabs_and_lines expanded =
7777 expand_line_sal_maybe (sals.sals[i]);
7779 create_breakpoint_sal (gdbarch, expanded, canonical->canonical[i],
7780 cond_string, type, disposition,
7781 thread, task, ignore_count, ops,
7782 from_tty, enabled, internal,
7783 canonical->special_display);
7787 /* Parse ADDRESS which is assumed to be a SAL specification possibly
7788 followed by conditionals. On return, SALS contains an array of SAL
7789 addresses found. ADDR_STRING contains a vector of (canonical)
7790 address strings. ADDRESS points to the end of the SAL.
7792 The array and the line spec strings are allocated on the heap, it is
7793 the caller's responsibility to free them. */
7796 parse_breakpoint_sals (char **address,
7797 struct symtabs_and_lines *sals,
7798 struct linespec_result *canonical)
7800 char *addr_start = *address;
7802 /* If no arg given, or if first arg is 'if ', use the default
7804 if ((*address) == NULL
7805 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
7807 if (default_breakpoint_valid)
7809 struct symtab_and_line sal;
7811 init_sal (&sal); /* Initialize to zeroes. */
7812 sals->sals = (struct symtab_and_line *)
7813 xmalloc (sizeof (struct symtab_and_line));
7814 sal.pc = default_breakpoint_address;
7815 sal.line = default_breakpoint_line;
7816 sal.symtab = default_breakpoint_symtab;
7817 sal.pspace = default_breakpoint_pspace;
7818 sal.section = find_pc_overlay (sal.pc);
7820 /* "break" without arguments is equivalent to "break *PC"
7821 where PC is the default_breakpoint_address. So make sure
7822 to set sal.explicit_pc to prevent GDB from trying to
7823 expand the list of sals to include all other instances
7824 with the same symtab and line. */
7825 sal.explicit_pc = 1;
7827 sals->sals[0] = sal;
7831 error (_("No default breakpoint address now."));
7835 /* Force almost all breakpoints to be in terms of the
7836 current_source_symtab (which is decode_line_1's default).
7837 This should produce the results we want almost all of the
7838 time while leaving default_breakpoint_* alone.
7840 ObjC: However, don't match an Objective-C method name which
7841 may have a '+' or '-' succeeded by a '[' */
7843 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
7845 if (default_breakpoint_valid
7847 || ((strchr ("+-", (*address)[0]) != NULL)
7848 && ((*address)[1] != '['))))
7849 *sals = decode_line_1 (address, 1, default_breakpoint_symtab,
7850 default_breakpoint_line, canonical);
7852 *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0,
7855 /* For any SAL that didn't have a canonical string, fill one in. */
7856 if (sals->nelts > 0 && canonical->canonical == NULL)
7857 canonical->canonical = xcalloc (sals->nelts, sizeof (char *));
7858 if (addr_start != (*address))
7862 for (i = 0; i < sals->nelts; i++)
7864 /* Add the string if not present. */
7865 if (canonical->canonical[i] == NULL)
7866 canonical->canonical[i] = savestring (addr_start,
7867 (*address) - addr_start);
7873 /* Convert each SAL into a real PC. Verify that the PC can be
7874 inserted as a breakpoint. If it can't throw an error. */
7877 breakpoint_sals_to_pc (struct symtabs_and_lines *sals)
7881 for (i = 0; i < sals->nelts; i++)
7882 resolve_sal_pc (&sals->sals[i]);
7885 /* Fast tracepoints may have restrictions on valid locations. For
7886 instance, a fast tracepoint using a jump instead of a trap will
7887 likely have to overwrite more bytes than a trap would, and so can
7888 only be placed where the instruction is longer than the jump, or a
7889 multi-instruction sequence does not have a jump into the middle of
7893 check_fast_tracepoint_sals (struct gdbarch *gdbarch,
7894 struct symtabs_and_lines *sals)
7897 struct symtab_and_line *sal;
7899 struct cleanup *old_chain;
7901 for (i = 0; i < sals->nelts; i++)
7903 sal = &sals->sals[i];
7905 rslt = gdbarch_fast_tracepoint_valid_at (gdbarch, sal->pc,
7907 old_chain = make_cleanup (xfree, msg);
7910 error (_("May not have a fast tracepoint at 0x%s%s"),
7911 paddress (gdbarch, sal->pc), (msg ? msg : ""));
7913 do_cleanups (old_chain);
7917 /* Given TOK, a string specification of condition and thread, as
7918 accepted by the 'break' command, extract the condition
7919 string and thread number and set *COND_STRING and *THREAD.
7920 PC identifies the context at which the condition should be parsed.
7921 If no condition is found, *COND_STRING is set to NULL.
7922 If no thread is found, *THREAD is set to -1. */
7924 find_condition_and_thread (char *tok, CORE_ADDR pc,
7925 char **cond_string, int *thread, int *task)
7927 *cond_string = NULL;
7933 char *cond_start = NULL;
7934 char *cond_end = NULL;
7936 tok = skip_spaces (tok);
7938 end_tok = skip_to_space (tok);
7940 toklen = end_tok - tok;
7942 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
7944 struct expression *expr;
7946 tok = cond_start = end_tok + 1;
7947 expr = parse_exp_1 (&tok, block_for_pc (pc), 0);
7950 *cond_string = savestring (cond_start,
7951 cond_end - cond_start);
7953 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
7959 *thread = strtol (tok, &tok, 0);
7961 error (_("Junk after thread keyword."));
7962 if (!valid_thread_id (*thread))
7963 error (_("Unknown thread %d."), *thread);
7965 else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0)
7971 *task = strtol (tok, &tok, 0);
7973 error (_("Junk after task keyword."));
7974 if (!valid_task_id (*task))
7975 error (_("Unknown task %d."), *task);
7978 error (_("Junk at end of arguments."));
7982 /* Decode a static tracepoint marker spec. */
7984 static struct symtabs_and_lines
7985 decode_static_tracepoint_spec (char **arg_p)
7987 VEC(static_tracepoint_marker_p) *markers = NULL;
7988 struct symtabs_and_lines sals;
7989 struct symtab_and_line sal;
7991 struct cleanup *old_chain;
7992 char *p = &(*arg_p)[3];
7997 p = skip_spaces (p);
7999 endp = skip_to_space (p);
8001 marker_str = savestring (p, endp - p);
8002 old_chain = make_cleanup (xfree, marker_str);
8004 markers = target_static_tracepoint_markers_by_strid (marker_str);
8005 if (VEC_empty(static_tracepoint_marker_p, markers))
8006 error (_("No known static tracepoint marker named %s"), marker_str);
8008 sals.nelts = VEC_length(static_tracepoint_marker_p, markers);
8009 sals.sals = xmalloc (sizeof *sals.sals * sals.nelts);
8011 for (i = 0; i < sals.nelts; i++)
8013 struct static_tracepoint_marker *marker;
8015 marker = VEC_index (static_tracepoint_marker_p, markers, i);
8017 init_sal (&sals.sals[i]);
8019 sals.sals[i] = find_pc_line (marker->address, 0);
8020 sals.sals[i].pc = marker->address;
8022 release_static_tracepoint_marker (marker);
8025 do_cleanups (old_chain);
8031 /* Set a breakpoint. This function is shared between CLI and MI
8032 functions for setting a breakpoint. This function has two major
8033 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
8034 parameter. If non-zero, the function will parse arg, extracting
8035 breakpoint location, address and thread. Otherwise, ARG is just
8036 the location of breakpoint, with condition and thread specified by
8037 the COND_STRING and THREAD parameters. If INTERNAL is non-zero,
8038 the breakpoint number will be allocated from the internal
8039 breakpoint count. Returns true if any breakpoint was created;
8043 create_breakpoint (struct gdbarch *gdbarch,
8044 char *arg, char *cond_string, int thread,
8045 int parse_condition_and_thread,
8046 int tempflag, enum bptype type_wanted,
8048 enum auto_boolean pending_break_support,
8049 struct breakpoint_ops *ops,
8050 int from_tty, int enabled, int internal)
8052 volatile struct gdb_exception e;
8053 struct symtabs_and_lines sals;
8054 struct symtab_and_line pending_sal;
8056 char *addr_start = arg;
8057 struct linespec_result canonical;
8058 struct cleanup *old_chain;
8059 struct cleanup *bkpt_chain = NULL;
8063 int prev_bkpt_count = breakpoint_count;
8067 init_linespec_result (&canonical);
8069 if (type_wanted == bp_static_tracepoint && is_marker_spec (arg))
8073 sals = decode_static_tracepoint_spec (&arg);
8075 copy_arg = savestring (addr_start, arg - addr_start);
8076 canonical.canonical = xcalloc (sals.nelts, sizeof (char *));
8077 for (i = 0; i < sals.nelts; i++)
8078 canonical.canonical[i] = xstrdup (copy_arg);
8082 TRY_CATCH (e, RETURN_MASK_ALL)
8084 parse_breakpoint_sals (&arg, &sals, &canonical);
8087 /* If caller is interested in rc value from parse, set value. */
8091 throw_exception (e);
8095 case NOT_FOUND_ERROR:
8097 /* If pending breakpoint support is turned off, throw
8100 if (pending_break_support == AUTO_BOOLEAN_FALSE)
8101 throw_exception (e);
8103 exception_print (gdb_stderr, e);
8105 /* If pending breakpoint support is auto query and the user
8106 selects no, then simply return the error code. */
8107 if (pending_break_support == AUTO_BOOLEAN_AUTO
8108 && !nquery (_("Make breakpoint pending on "
8109 "future shared library load? ")))
8112 /* At this point, either the user was queried about setting
8113 a pending breakpoint and selected yes, or pending
8114 breakpoint behavior is on and thus a pending breakpoint
8115 is defaulted on behalf of the user. */
8116 copy_arg = xstrdup (addr_start);
8117 canonical.canonical = ©_arg;
8119 sals.sals = &pending_sal;
8124 throw_exception (e);
8134 /* Create a chain of things that always need to be cleaned up. */
8135 old_chain = make_cleanup (null_cleanup, 0);
8139 /* Make sure that all storage allocated to SALS gets freed. */
8140 make_cleanup (xfree, sals.sals);
8142 /* Cleanup the canonical array but not its contents. */
8143 make_cleanup (xfree, canonical.canonical);
8146 /* ----------------------------- SNIP -----------------------------
8147 Anything added to the cleanup chain beyond this point is assumed
8148 to be part of a breakpoint. If the breakpoint create succeeds
8149 then the memory is not reclaimed. */
8150 bkpt_chain = make_cleanup (null_cleanup, 0);
8152 /* Mark the contents of the canonical for cleanup. These go on
8153 the bkpt_chain and only occur if the breakpoint create fails. */
8154 for (i = 0; i < sals.nelts; i++)
8156 if (canonical.canonical[i] != NULL)
8157 make_cleanup (xfree, canonical.canonical[i]);
8160 /* Resolve all line numbers to PC's and verify that the addresses
8161 are ok for the target. */
8163 breakpoint_sals_to_pc (&sals);
8165 /* Fast tracepoints may have additional restrictions on location. */
8166 if (type_wanted == bp_fast_tracepoint)
8167 check_fast_tracepoint_sals (gdbarch, &sals);
8169 /* Verify that condition can be parsed, before setting any
8170 breakpoints. Allocate a separate condition expression for each
8174 if (parse_condition_and_thread)
8176 /* Here we only parse 'arg' to separate condition
8177 from thread number, so parsing in context of first
8178 sal is OK. When setting the breakpoint we'll
8179 re-parse it in context of each sal. */
8182 find_condition_and_thread (arg, sals.sals[0].pc, &cond_string,
8185 make_cleanup (xfree, cond_string);
8189 /* Create a private copy of condition string. */
8192 cond_string = xstrdup (cond_string);
8193 make_cleanup (xfree, cond_string);
8197 /* If the user is creating a static tracepoint by marker id
8198 (strace -m MARKER_ID), then store the sals index, so that
8199 breakpoint_re_set can try to match up which of the newly
8200 found markers corresponds to this one, and, don't try to
8201 expand multiple locations for each sal, given than SALS
8202 already should contain all sals for MARKER_ID. */
8203 if (type_wanted == bp_static_tracepoint
8204 && is_marker_spec (canonical.canonical[0]))
8208 for (i = 0; i < sals.nelts; ++i)
8210 struct symtabs_and_lines expanded;
8211 struct breakpoint *tp;
8212 struct cleanup *old_chain;
8215 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
8216 expanded.sals[0] = sals.sals[i];
8217 old_chain = make_cleanup (xfree, expanded.sals);
8219 create_breakpoint_sal (gdbarch, expanded, canonical.canonical[i],
8220 cond_string, type_wanted,
8221 tempflag ? disp_del : disp_donttouch,
8222 thread, task, ignore_count, ops,
8223 from_tty, enabled, internal,
8224 canonical.special_display);
8226 do_cleanups (old_chain);
8228 /* Get the tracepoint we just created. */
8230 tp = get_breakpoint (internal_breakpoint_number);
8232 tp = get_breakpoint (breakpoint_count);
8233 gdb_assert (tp != NULL);
8235 /* Given that its possible to have multiple markers with
8236 the same string id, if the user is creating a static
8237 tracepoint by marker id ("strace -m MARKER_ID"), then
8238 store the sals index, so that breakpoint_re_set can
8239 try to match up which of the newly found markers
8240 corresponds to this one */
8241 tp->static_trace_marker_id_idx = i;
8245 create_breakpoints_sal (gdbarch, sals, &canonical, cond_string,
8247 tempflag ? disp_del : disp_donttouch,
8248 thread, task, ignore_count, ops, from_tty,
8253 struct breakpoint *b;
8255 make_cleanup (xfree, copy_arg);
8257 b = set_raw_breakpoint_without_location (gdbarch, type_wanted);
8258 set_breakpoint_number (internal, b);
8260 b->addr_string = canonical.canonical[0];
8261 b->cond_string = NULL;
8262 b->ignore_count = ignore_count;
8263 b->disposition = tempflag ? disp_del : disp_donttouch;
8264 b->condition_not_parsed = 1;
8266 b->enable_state = enabled ? bp_enabled : bp_disabled;
8267 b->pspace = current_program_space;
8268 b->py_bp_object = NULL;
8270 if (enabled && b->pspace->executing_startup
8271 && (b->type == bp_breakpoint
8272 || b->type == bp_hardware_breakpoint))
8273 b->enable_state = bp_startup_disabled;
8276 /* Do not mention breakpoints with a negative number,
8277 but do notify observers. */
8279 observer_notify_breakpoint_created (b);
8284 warning (_("Multiple breakpoints were set.\nUse the "
8285 "\"delete\" command to delete unwanted breakpoints."));
8286 prev_breakpoint_count = prev_bkpt_count;
8289 /* That's it. Discard the cleanups for data inserted into the
8291 discard_cleanups (bkpt_chain);
8292 /* But cleanup everything else. */
8293 do_cleanups (old_chain);
8295 /* error call may happen here - have BKPT_CHAIN already discarded. */
8296 update_global_location_list (1);
8301 /* Set a breakpoint.
8302 ARG is a string describing breakpoint address,
8303 condition, and thread.
8304 FLAG specifies if a breakpoint is hardware on,
8305 and if breakpoint is temporary, using BP_HARDWARE_FLAG
8309 break_command_1 (char *arg, int flag, int from_tty)
8311 int tempflag = flag & BP_TEMPFLAG;
8312 enum bptype type_wanted = (flag & BP_HARDWAREFLAG
8313 ? bp_hardware_breakpoint
8316 create_breakpoint (get_current_arch (),
8318 NULL, 0, 1 /* parse arg */,
8319 tempflag, type_wanted,
8320 0 /* Ignore count */,
8321 pending_break_support,
8322 NULL /* breakpoint_ops */,
8329 /* Helper function for break_command_1 and disassemble_command. */
8332 resolve_sal_pc (struct symtab_and_line *sal)
8336 if (sal->pc == 0 && sal->symtab != NULL)
8338 if (!find_line_pc (sal->symtab, sal->line, &pc))
8339 error (_("No line %d in file \"%s\"."),
8340 sal->line, sal->symtab->filename);
8343 /* If this SAL corresponds to a breakpoint inserted using a line
8344 number, then skip the function prologue if necessary. */
8345 if (sal->explicit_line)
8346 skip_prologue_sal (sal);
8349 if (sal->section == 0 && sal->symtab != NULL)
8351 struct blockvector *bv;
8355 bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab);
8358 sym = block_linkage_function (b);
8361 fixup_symbol_section (sym, sal->symtab->objfile);
8362 sal->section = SYMBOL_OBJ_SECTION (sym);
8366 /* It really is worthwhile to have the section, so we'll
8367 just have to look harder. This case can be executed
8368 if we have line numbers but no functions (as can
8369 happen in assembly source). */
8371 struct minimal_symbol *msym;
8372 struct cleanup *old_chain = save_current_space_and_thread ();
8374 switch_to_program_space_and_thread (sal->pspace);
8376 msym = lookup_minimal_symbol_by_pc (sal->pc);
8378 sal->section = SYMBOL_OBJ_SECTION (msym);
8380 do_cleanups (old_chain);
8387 break_command (char *arg, int from_tty)
8389 break_command_1 (arg, 0, from_tty);
8393 tbreak_command (char *arg, int from_tty)
8395 break_command_1 (arg, BP_TEMPFLAG, from_tty);
8399 hbreak_command (char *arg, int from_tty)
8401 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
8405 thbreak_command (char *arg, int from_tty)
8407 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
8411 stop_command (char *arg, int from_tty)
8413 printf_filtered (_("Specify the type of breakpoint to set.\n\
8414 Usage: stop in <function | address>\n\
8415 stop at <line>\n"));
8419 stopin_command (char *arg, int from_tty)
8423 if (arg == (char *) NULL)
8425 else if (*arg != '*')
8430 /* Look for a ':'. If this is a line number specification, then
8431 say it is bad, otherwise, it should be an address or
8432 function/method name. */
8433 while (*argptr && !hasColon)
8435 hasColon = (*argptr == ':');
8440 badInput = (*argptr != ':'); /* Not a class::method */
8442 badInput = isdigit (*arg); /* a simple line number */
8446 printf_filtered (_("Usage: stop in <function | address>\n"));
8448 break_command_1 (arg, 0, from_tty);
8452 stopat_command (char *arg, int from_tty)
8456 if (arg == (char *) NULL || *arg == '*') /* no line number */
8463 /* Look for a ':'. If there is a '::' then get out, otherwise
8464 it is probably a line number. */
8465 while (*argptr && !hasColon)
8467 hasColon = (*argptr == ':');
8472 badInput = (*argptr == ':'); /* we have class::method */
8474 badInput = !isdigit (*arg); /* not a line number */
8478 printf_filtered (_("Usage: stop at <line>\n"));
8480 break_command_1 (arg, 0, from_tty);
8483 /* Implement the "breakpoint_hit" breakpoint_ops method for
8484 ranged breakpoints. */
8487 breakpoint_hit_ranged_breakpoint (const struct bp_location *bl,
8488 struct address_space *aspace,
8491 return breakpoint_address_match_range (bl->pspace->aspace, bl->address,
8492 bl->length, aspace, bp_addr);
8495 /* Implement the "resources_needed" breakpoint_ops method for
8496 ranged breakpoints. */
8499 resources_needed_ranged_breakpoint (const struct bp_location *bl)
8501 return target_ranged_break_num_registers ();
8504 /* Implement the "print_it" breakpoint_ops method for
8505 ranged breakpoints. */
8507 static enum print_stop_action
8508 print_it_ranged_breakpoint (struct breakpoint *b)
8510 struct bp_location *bl = b->loc;
8512 gdb_assert (b->type == bp_hardware_breakpoint);
8514 /* Ranged breakpoints have only one location. */
8515 gdb_assert (bl && bl->next == NULL);
8517 annotate_breakpoint (b->number);
8518 if (b->disposition == disp_del)
8519 ui_out_text (uiout, "\nTemporary ranged breakpoint ");
8521 ui_out_text (uiout, "\nRanged breakpoint ");
8522 if (ui_out_is_mi_like_p (uiout))
8524 ui_out_field_string (uiout, "reason",
8525 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
8526 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8528 ui_out_field_int (uiout, "bkptno", b->number);
8529 ui_out_text (uiout, ", ");
8531 return PRINT_SRC_AND_LOC;
8534 /* Implement the "print_one" breakpoint_ops method for
8535 ranged breakpoints. */
8538 print_one_ranged_breakpoint (struct breakpoint *b,
8539 struct bp_location **last_loc)
8541 struct bp_location *bl = b->loc;
8542 struct value_print_options opts;
8544 /* Ranged breakpoints have only one location. */
8545 gdb_assert (bl && bl->next == NULL);
8547 get_user_print_options (&opts);
8549 if (opts.addressprint)
8550 /* We don't print the address range here, it will be printed later
8551 by print_one_detail_ranged_breakpoint. */
8552 ui_out_field_skip (uiout, "addr");
8554 print_breakpoint_location (b, bl);
8558 /* Implement the "print_one_detail" breakpoint_ops method for
8559 ranged breakpoints. */
8562 print_one_detail_ranged_breakpoint (const struct breakpoint *b,
8563 struct ui_out *uiout)
8565 CORE_ADDR address_start, address_end;
8566 struct bp_location *bl = b->loc;
8567 struct ui_stream *stb = ui_out_stream_new (uiout);
8568 struct cleanup *cleanup = make_cleanup_ui_out_stream_delete (stb);
8572 address_start = bl->address;
8573 address_end = address_start + bl->length - 1;
8575 ui_out_text (uiout, "\taddress range: ");
8576 fprintf_unfiltered (stb->stream, "[%s, %s]",
8577 print_core_address (bl->gdbarch, address_start),
8578 print_core_address (bl->gdbarch, address_end));
8579 ui_out_field_stream (uiout, "addr", stb);
8580 ui_out_text (uiout, "\n");
8582 do_cleanups (cleanup);
8585 /* Implement the "print_mention" breakpoint_ops method for
8586 ranged breakpoints. */
8589 print_mention_ranged_breakpoint (struct breakpoint *b)
8591 struct bp_location *bl = b->loc;
8594 gdb_assert (b->type == bp_hardware_breakpoint);
8596 if (ui_out_is_mi_like_p (uiout))
8599 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
8600 b->number, paddress (bl->gdbarch, bl->address),
8601 paddress (bl->gdbarch, bl->address + bl->length - 1));
8604 /* Implement the "print_recreate" breakpoint_ops method for
8605 ranged breakpoints. */
8608 print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp)
8610 fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string,
8611 b->addr_string_range_end);
8614 /* The breakpoint_ops structure to be used in ranged breakpoints. */
8616 static struct breakpoint_ops ranged_breakpoint_ops =
8621 breakpoint_hit_ranged_breakpoint,
8622 resources_needed_ranged_breakpoint,
8623 NULL, /* works_in_software_mode */
8624 print_it_ranged_breakpoint,
8625 print_one_ranged_breakpoint,
8626 print_one_detail_ranged_breakpoint,
8627 print_mention_ranged_breakpoint,
8628 print_recreate_ranged_breakpoint
8631 /* Find the address where the end of the breakpoint range should be
8632 placed, given the SAL of the end of the range. This is so that if
8633 the user provides a line number, the end of the range is set to the
8634 last instruction of the given line. */
8637 find_breakpoint_range_end (struct symtab_and_line sal)
8641 /* If the user provided a PC value, use it. Otherwise,
8642 find the address of the end of the given location. */
8643 if (sal.explicit_pc)
8650 ret = find_line_pc_range (sal, &start, &end);
8652 error (_("Could not find location of the end of the range."));
8654 /* find_line_pc_range returns the start of the next line. */
8661 /* Implement the "break-range" CLI command. */
8664 break_range_command (char *arg, int from_tty)
8666 char *arg_start, *addr_string_start, *addr_string_end;
8667 struct linespec_result canonical_start, canonical_end;
8668 int bp_count, can_use_bp, length;
8670 struct breakpoint *b;
8671 struct symtab_and_line sal_start, sal_end;
8672 struct symtabs_and_lines sals_start, sals_end;
8673 struct cleanup *cleanup_bkpt;
8675 /* We don't support software ranged breakpoints. */
8676 if (target_ranged_break_num_registers () < 0)
8677 error (_("This target does not support hardware ranged breakpoints."));
8679 bp_count = hw_breakpoint_used_count ();
8680 bp_count += target_ranged_break_num_registers ();
8681 can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
8684 error (_("Hardware breakpoints used exceeds limit."));
8686 if (arg == NULL || arg[0] == '\0')
8687 error(_("No address range specified."));
8689 sals_start.sals = NULL;
8690 sals_start.nelts = 0;
8691 init_linespec_result (&canonical_start);
8693 while (*arg == ' ' || *arg == '\t')
8696 parse_breakpoint_sals (&arg, &sals_start, &canonical_start);
8698 sal_start = sals_start.sals[0];
8699 addr_string_start = canonical_start.canonical[0];
8700 cleanup_bkpt = make_cleanup (xfree, addr_string_start);
8701 xfree (sals_start.sals);
8702 xfree (canonical_start.canonical);
8705 error (_("Too few arguments."));
8706 else if (sals_start.nelts == 0)
8707 error (_("Could not find location of the beginning of the range."));
8708 else if (sals_start.nelts != 1)
8709 error (_("Cannot create a ranged breakpoint with multiple locations."));
8711 resolve_sal_pc (&sal_start);
8713 arg++; /* Skip the comma. */
8714 while (*arg == ' ' || *arg == '\t')
8717 /* Parse the end location. */
8719 sals_end.sals = NULL;
8721 init_linespec_result (&canonical_end);
8724 /* We call decode_line_1 directly here instead of using
8725 parse_breakpoint_sals because we need to specify the start location's
8726 symtab and line as the default symtab and line for the end of the
8727 range. This makes it possible to have ranges like "foo.c:27, +14",
8728 where +14 means 14 lines from the start location. */
8729 sals_end = decode_line_1 (&arg, 1, sal_start.symtab, sal_start.line,
8732 /* canonical_end can be NULL if it was of the form "*0xdeadbeef". */
8733 if (canonical_end.canonical == NULL)
8734 canonical_end.canonical = xcalloc (1, sizeof (char *));
8735 /* Add the string if not present. */
8736 if (arg_start != arg && canonical_end.canonical[0] == NULL)
8737 canonical_end.canonical[0] = savestring (arg_start, arg - arg_start);
8739 sal_end = sals_end.sals[0];
8740 addr_string_end = canonical_end.canonical[0];
8741 make_cleanup (xfree, addr_string_end);
8742 xfree (sals_end.sals);
8743 xfree (canonical_end.canonical);
8745 if (sals_end.nelts == 0)
8746 error (_("Could not find location of the end of the range."));
8747 else if (sals_end.nelts != 1)
8748 error (_("Cannot create a ranged breakpoint with multiple locations."));
8750 resolve_sal_pc (&sal_end);
8752 end = find_breakpoint_range_end (sal_end);
8753 if (sal_start.pc > end)
8754 error (_("Invalid address range, end preceeds start."));
8756 length = end - sal_start.pc + 1;
8758 /* Length overflowed. */
8759 error (_("Address range too large."));
8760 else if (length == 1)
8762 /* This range is simple enough to be handled by
8763 the `hbreak' command. */
8764 hbreak_command (addr_string_start, 1);
8766 do_cleanups (cleanup_bkpt);
8771 /* Now set up the breakpoint. */
8772 b = set_raw_breakpoint (get_current_arch (), sal_start,
8773 bp_hardware_breakpoint);
8774 set_breakpoint_count (breakpoint_count + 1);
8775 b->number = breakpoint_count;
8776 b->disposition = disp_donttouch;
8777 b->addr_string = addr_string_start;
8778 b->addr_string_range_end = addr_string_end;
8779 b->ops = &ranged_breakpoint_ops;
8780 b->loc->length = length;
8782 discard_cleanups (cleanup_bkpt);
8785 observer_notify_breakpoint_created (b);
8786 update_global_location_list (1);
8789 /* Return non-zero if EXP is verified as constant. Returned zero
8790 means EXP is variable. Also the constant detection may fail for
8791 some constant expressions and in such case still falsely return
8794 watchpoint_exp_is_const (const struct expression *exp)
8802 /* We are only interested in the descriptor of each element. */
8803 operator_length (exp, i, &oplenp, &argsp);
8806 switch (exp->elts[i].opcode)
8816 case BINOP_LOGICAL_AND:
8817 case BINOP_LOGICAL_OR:
8818 case BINOP_BITWISE_AND:
8819 case BINOP_BITWISE_IOR:
8820 case BINOP_BITWISE_XOR:
8822 case BINOP_NOTEQUAL:
8838 case TERNOP_SLICE_COUNT:
8850 case OP_OBJC_NSSTRING:
8853 case UNOP_LOGICAL_NOT:
8854 case UNOP_COMPLEMENT:
8857 /* Unary, binary and ternary operators: We have to check
8858 their operands. If they are constant, then so is the
8859 result of that operation. For instance, if A and B are
8860 determined to be constants, then so is "A + B".
8862 UNOP_IND is one exception to the rule above, because the
8863 value of *ADDR is not necessarily a constant, even when
8868 /* Check whether the associated symbol is a constant.
8870 We use SYMBOL_CLASS rather than TYPE_CONST because it's
8871 possible that a buggy compiler could mark a variable as
8872 constant even when it is not, and TYPE_CONST would return
8873 true in this case, while SYMBOL_CLASS wouldn't.
8875 We also have to check for function symbols because they
8876 are always constant. */
8878 struct symbol *s = exp->elts[i + 2].symbol;
8880 if (SYMBOL_CLASS (s) != LOC_BLOCK
8881 && SYMBOL_CLASS (s) != LOC_CONST
8882 && SYMBOL_CLASS (s) != LOC_CONST_BYTES)
8887 /* The default action is to return 0 because we are using
8888 the optimistic approach here: If we don't know something,
8889 then it is not a constant. */
8898 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
8901 insert_watchpoint (struct bp_location *bl)
8903 int length = bl->owner->exact? 1 : bl->length;
8905 return target_insert_watchpoint (bl->address, length, bl->watchpoint_type,
8906 bl->owner->cond_exp);
8909 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
8912 remove_watchpoint (struct bp_location *bl)
8914 int length = bl->owner->exact? 1 : bl->length;
8916 return target_remove_watchpoint (bl->address, length, bl->watchpoint_type,
8917 bl->owner->cond_exp);
8920 /* Implement the "resources_needed" breakpoint_ops method for
8921 hardware watchpoints. */
8924 resources_needed_watchpoint (const struct bp_location *bl)
8926 int length = bl->owner->exact? 1 : bl->length;
8928 return target_region_ok_for_hw_watchpoint (bl->address, length);
8931 /* Implement the "works_in_software_mode" breakpoint_ops method for
8932 hardware watchpoints. */
8935 works_in_software_mode_watchpoint (const struct breakpoint *b)
8937 return b->type == bp_hardware_watchpoint;
8940 /* The breakpoint_ops structure to be used in hardware watchpoints. */
8942 static struct breakpoint_ops watchpoint_breakpoint_ops =
8947 NULL, /* breakpoint_hit */
8948 resources_needed_watchpoint,
8949 works_in_software_mode_watchpoint,
8950 NULL, /* print_it */
8951 NULL, /* print_one */
8952 NULL, /* print_one_detail */
8953 NULL, /* print_mention */
8954 NULL /* print_recreate */
8957 /* Implement the "insert" breakpoint_ops method for
8958 masked hardware watchpoints. */
8961 insert_masked_watchpoint (struct bp_location *bl)
8963 return target_insert_mask_watchpoint (bl->address, bl->owner->hw_wp_mask,
8964 bl->watchpoint_type);
8967 /* Implement the "remove" breakpoint_ops method for
8968 masked hardware watchpoints. */
8971 remove_masked_watchpoint (struct bp_location *bl)
8973 return target_remove_mask_watchpoint (bl->address, bl->owner->hw_wp_mask,
8974 bl->watchpoint_type);
8977 /* Implement the "resources_needed" breakpoint_ops method for
8978 masked hardware watchpoints. */
8981 resources_needed_masked_watchpoint (const struct bp_location *bl)
8983 return target_masked_watch_num_registers (bl->address,
8984 bl->owner->hw_wp_mask);
8987 /* Implement the "works_in_software_mode" breakpoint_ops method for
8988 masked hardware watchpoints. */
8991 works_in_software_mode_masked_watchpoint (const struct breakpoint *b)
8996 /* Implement the "print_it" breakpoint_ops method for
8997 masked hardware watchpoints. */
8999 static enum print_stop_action
9000 print_it_masked_watchpoint (struct breakpoint *b)
9002 /* Masked watchpoints have only one location. */
9003 gdb_assert (b->loc && b->loc->next == NULL);
9007 case bp_hardware_watchpoint:
9008 annotate_watchpoint (b->number);
9009 if (ui_out_is_mi_like_p (uiout))
9012 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
9015 case bp_read_watchpoint:
9016 if (ui_out_is_mi_like_p (uiout))
9019 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
9022 case bp_access_watchpoint:
9023 if (ui_out_is_mi_like_p (uiout))
9026 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
9029 internal_error (__FILE__, __LINE__,
9030 _("Invalid hardware watchpoint type."));
9034 ui_out_text (uiout, _("\n\
9035 Check the underlying instruction at PC for the memory\n\
9036 address and value which triggered this watchpoint.\n"));
9037 ui_out_text (uiout, "\n");
9039 /* More than one watchpoint may have been triggered. */
9040 return PRINT_UNKNOWN;
9043 /* Implement the "print_one_detail" breakpoint_ops method for
9044 masked hardware watchpoints. */
9047 print_one_detail_masked_watchpoint (const struct breakpoint *b,
9048 struct ui_out *uiout)
9050 /* Masked watchpoints have only one location. */
9051 gdb_assert (b->loc && b->loc->next == NULL);
9053 ui_out_text (uiout, "\tmask ");
9054 ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, b->hw_wp_mask);
9055 ui_out_text (uiout, "\n");
9058 /* Implement the "print_mention" breakpoint_ops method for
9059 masked hardware watchpoints. */
9062 print_mention_masked_watchpoint (struct breakpoint *b)
9064 struct cleanup *ui_out_chain;
9068 case bp_hardware_watchpoint:
9069 ui_out_text (uiout, "Masked hardware watchpoint ");
9070 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
9072 case bp_read_watchpoint:
9073 ui_out_text (uiout, "Masked hardware read watchpoint ");
9074 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
9076 case bp_access_watchpoint:
9077 ui_out_text (uiout, "Masked hardware access (read/write) watchpoint ");
9078 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
9081 internal_error (__FILE__, __LINE__,
9082 _("Invalid hardware watchpoint type."));
9085 ui_out_field_int (uiout, "number", b->number);
9086 ui_out_text (uiout, ": ");
9087 ui_out_field_string (uiout, "exp", b->exp_string);
9088 do_cleanups (ui_out_chain);
9091 /* Implement the "print_recreate" breakpoint_ops method for
9092 masked hardware watchpoints. */
9095 print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp)
9101 case bp_hardware_watchpoint:
9102 fprintf_unfiltered (fp, "watch");
9104 case bp_read_watchpoint:
9105 fprintf_unfiltered (fp, "rwatch");
9107 case bp_access_watchpoint:
9108 fprintf_unfiltered (fp, "awatch");
9111 internal_error (__FILE__, __LINE__,
9112 _("Invalid hardware watchpoint type."));
9115 sprintf_vma (tmp, b->hw_wp_mask);
9116 fprintf_unfiltered (fp, " %s mask 0x%s", b->exp_string, tmp);
9119 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
9121 static struct breakpoint_ops masked_watchpoint_breakpoint_ops =
9124 insert_masked_watchpoint,
9125 remove_masked_watchpoint,
9126 NULL, /* breakpoint_hit */
9127 resources_needed_masked_watchpoint,
9128 works_in_software_mode_masked_watchpoint,
9129 print_it_masked_watchpoint,
9130 NULL, /* print_one */
9131 print_one_detail_masked_watchpoint,
9132 print_mention_masked_watchpoint,
9133 print_recreate_masked_watchpoint
9136 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
9139 is_masked_watchpoint (const struct breakpoint *b)
9141 return b->ops == &masked_watchpoint_breakpoint_ops;
9144 /* accessflag: hw_write: watch write,
9145 hw_read: watch read,
9146 hw_access: watch access (read or write) */
9148 watch_command_1 (char *arg, int accessflag, int from_tty,
9149 int just_location, int internal)
9151 volatile struct gdb_exception e;
9152 struct breakpoint *b, *scope_breakpoint = NULL;
9153 struct expression *exp;
9154 struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL;
9155 struct value *val, *mark, *result;
9156 struct frame_info *frame;
9157 char *exp_start = NULL;
9158 char *exp_end = NULL;
9159 char *tok, *end_tok;
9161 char *cond_start = NULL;
9162 char *cond_end = NULL;
9163 enum bptype bp_type;
9166 /* Flag to indicate whether we are going to use masks for
9167 the hardware watchpoint. */
9171 /* Make sure that we actually have parameters to parse. */
9172 if (arg != NULL && arg[0] != '\0')
9176 /* Look for "parameter value" pairs at the end
9177 of the arguments string. */
9178 for (tok = arg + strlen (arg) - 1; tok > arg; tok--)
9180 /* Skip whitespace at the end of the argument list. */
9181 while (tok > arg && (*tok == ' ' || *tok == '\t'))
9184 /* Find the beginning of the last token.
9185 This is the value of the parameter. */
9186 while (tok > arg && (*tok != ' ' && *tok != '\t'))
9188 value_start = tok + 1;
9190 /* Skip whitespace. */
9191 while (tok > arg && (*tok == ' ' || *tok == '\t'))
9196 /* Find the beginning of the second to last token.
9197 This is the parameter itself. */
9198 while (tok > arg && (*tok != ' ' && *tok != '\t'))
9201 toklen = end_tok - tok + 1;
9203 if (toklen == 6 && !strncmp (tok, "thread", 6))
9205 /* At this point we've found a "thread" token, which means
9206 the user is trying to set a watchpoint that triggers
9207 only in a specific thread. */
9211 error(_("You can specify only one thread."));
9213 /* Extract the thread ID from the next token. */
9214 thread = strtol (value_start, &endp, 0);
9216 /* Check if the user provided a valid numeric value for the
9218 if (*endp != ' ' && *endp != '\t' && *endp != '\0')
9219 error (_("Invalid thread ID specification %s."), value_start);
9221 /* Check if the thread actually exists. */
9222 if (!valid_thread_id (thread))
9223 error (_("Unknown thread %d."), thread);
9225 else if (toklen == 4 && !strncmp (tok, "mask", 4))
9227 /* We've found a "mask" token, which means the user wants to
9228 create a hardware watchpoint that is going to have the mask
9230 struct value *mask_value, *mark;
9233 error(_("You can specify only one mask."));
9235 use_mask = just_location = 1;
9237 mark = value_mark ();
9238 mask_value = parse_to_comma_and_eval (&value_start);
9239 mask = value_as_address (mask_value);
9240 value_free_to_mark (mark);
9243 /* We didn't recognize what we found. We should stop here. */
9246 /* Truncate the string and get rid of the "parameter value" pair before
9247 the arguments string is parsed by the parse_exp_1 function. */
9252 /* Parse the rest of the arguments. */
9253 innermost_block = NULL;
9255 exp = parse_exp_1 (&arg, 0, 0);
9257 /* Remove trailing whitespace from the expression before saving it.
9258 This makes the eventual display of the expression string a bit
9260 while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t'))
9263 /* Checking if the expression is not constant. */
9264 if (watchpoint_exp_is_const (exp))
9268 len = exp_end - exp_start;
9269 while (len > 0 && isspace (exp_start[len - 1]))
9271 error (_("Cannot watch constant value `%.*s'."), len, exp_start);
9274 exp_valid_block = innermost_block;
9275 mark = value_mark ();
9276 fetch_subexp_value (exp, &pc, &val, &result, NULL);
9282 exp_valid_block = NULL;
9283 val = value_addr (result);
9284 release_value (val);
9285 value_free_to_mark (mark);
9289 ret = target_masked_watch_num_registers (value_as_address (val),
9292 error (_("This target does not support masked watchpoints."));
9294 error (_("Invalid mask or memory region."));
9297 else if (val != NULL)
9298 release_value (val);
9300 tok = skip_spaces (arg);
9301 end_tok = skip_to_space (tok);
9303 toklen = end_tok - tok;
9304 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
9306 struct expression *cond;
9308 innermost_block = NULL;
9309 tok = cond_start = end_tok + 1;
9310 cond = parse_exp_1 (&tok, 0, 0);
9312 /* The watchpoint expression may not be local, but the condition
9313 may still be. E.g.: `watch global if local > 0'. */
9314 cond_exp_valid_block = innermost_block;
9320 error (_("Junk at end of command."));
9322 if (accessflag == hw_read)
9323 bp_type = bp_read_watchpoint;
9324 else if (accessflag == hw_access)
9325 bp_type = bp_access_watchpoint;
9327 bp_type = bp_hardware_watchpoint;
9329 frame = block_innermost_frame (exp_valid_block);
9331 /* If the expression is "local", then set up a "watchpoint scope"
9332 breakpoint at the point where we've left the scope of the watchpoint
9333 expression. Create the scope breakpoint before the watchpoint, so
9334 that we will encounter it first in bpstat_stop_status. */
9335 if (exp_valid_block && frame)
9337 if (frame_id_p (frame_unwind_caller_id (frame)))
9340 = create_internal_breakpoint (frame_unwind_caller_arch (frame),
9341 frame_unwind_caller_pc (frame),
9342 bp_watchpoint_scope);
9344 scope_breakpoint->enable_state = bp_enabled;
9346 /* Automatically delete the breakpoint when it hits. */
9347 scope_breakpoint->disposition = disp_del;
9349 /* Only break in the proper frame (help with recursion). */
9350 scope_breakpoint->frame_id = frame_unwind_caller_id (frame);
9352 /* Set the address at which we will stop. */
9353 scope_breakpoint->loc->gdbarch
9354 = frame_unwind_caller_arch (frame);
9355 scope_breakpoint->loc->requested_address
9356 = frame_unwind_caller_pc (frame);
9357 scope_breakpoint->loc->address
9358 = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch,
9359 scope_breakpoint->loc->requested_address,
9360 scope_breakpoint->type);
9364 /* Now set up the breakpoint. */
9365 b = set_raw_breakpoint_without_location (NULL, bp_type);
9367 b->disposition = disp_donttouch;
9369 b->exp_valid_block = exp_valid_block;
9370 b->cond_exp_valid_block = cond_exp_valid_block;
9373 struct type *t = value_type (val);
9374 CORE_ADDR addr = value_as_address (val);
9377 t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t)));
9378 name = type_to_string (t);
9380 b->exp_string_reparse = xstrprintf ("* (%s *) %s", name,
9381 core_addr_to_string (addr));
9384 b->exp_string = xstrprintf ("-location %.*s",
9385 (int) (exp_end - exp_start), exp_start);
9387 /* The above expression is in C. */
9388 b->language = language_c;
9391 b->exp_string = savestring (exp_start, exp_end - exp_start);
9395 b->hw_wp_mask = mask;
9396 b->ops = &masked_watchpoint_breakpoint_ops;
9402 b->ops = &watchpoint_breakpoint_ops;
9406 b->cond_string = savestring (cond_start, cond_end - cond_start);
9412 b->watchpoint_frame = get_frame_id (frame);
9413 b->watchpoint_thread = inferior_ptid;
9417 b->watchpoint_frame = null_frame_id;
9418 b->watchpoint_thread = null_ptid;
9421 if (scope_breakpoint != NULL)
9423 /* The scope breakpoint is related to the watchpoint. We will
9424 need to act on them together. */
9425 b->related_breakpoint = scope_breakpoint;
9426 scope_breakpoint->related_breakpoint = b;
9430 value_free_to_mark (mark);
9432 TRY_CATCH (e, RETURN_MASK_ALL)
9434 /* Finally update the new watchpoint. This creates the locations
9435 that should be inserted. */
9436 update_watchpoint (b, 1);
9440 delete_breakpoint (b);
9441 throw_exception (e);
9444 set_breakpoint_number (internal, b);
9446 /* Do not mention breakpoints with a negative number, but do
9447 notify observers. */
9450 observer_notify_breakpoint_created (b);
9452 update_global_location_list (1);
9455 /* Return count of debug registers needed to watch the given expression.
9456 If the watchpoint cannot be handled in hardware return zero. */
9459 can_use_hardware_watchpoint (struct value *v)
9461 int found_memory_cnt = 0;
9462 struct value *head = v;
9464 /* Did the user specifically forbid us to use hardware watchpoints? */
9465 if (!can_use_hw_watchpoints)
9468 /* Make sure that the value of the expression depends only upon
9469 memory contents, and values computed from them within GDB. If we
9470 find any register references or function calls, we can't use a
9471 hardware watchpoint.
9473 The idea here is that evaluating an expression generates a series
9474 of values, one holding the value of every subexpression. (The
9475 expression a*b+c has five subexpressions: a, b, a*b, c, and
9476 a*b+c.) GDB's values hold almost enough information to establish
9477 the criteria given above --- they identify memory lvalues,
9478 register lvalues, computed values, etcetera. So we can evaluate
9479 the expression, and then scan the chain of values that leaves
9480 behind to decide whether we can detect any possible change to the
9481 expression's final value using only hardware watchpoints.
9483 However, I don't think that the values returned by inferior
9484 function calls are special in any way. So this function may not
9485 notice that an expression involving an inferior function call
9486 can't be watched with hardware watchpoints. FIXME. */
9487 for (; v; v = value_next (v))
9489 if (VALUE_LVAL (v) == lval_memory)
9491 if (v != head && value_lazy (v))
9492 /* A lazy memory lvalue in the chain is one that GDB never
9493 needed to fetch; we either just used its address (e.g.,
9494 `a' in `a.b') or we never needed it at all (e.g., `a'
9495 in `a,b'). This doesn't apply to HEAD; if that is
9496 lazy then it was not readable, but watch it anyway. */
9500 /* Ahh, memory we actually used! Check if we can cover
9501 it with hardware watchpoints. */
9502 struct type *vtype = check_typedef (value_type (v));
9504 /* We only watch structs and arrays if user asked for it
9505 explicitly, never if they just happen to appear in a
9506 middle of some value chain. */
9508 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
9509 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
9511 CORE_ADDR vaddr = value_address (v);
9515 len = (target_exact_watchpoints
9516 && is_scalar_type_recursive (vtype))?
9517 1 : TYPE_LENGTH (value_type (v));
9519 num_regs = target_region_ok_for_hw_watchpoint (vaddr, len);
9523 found_memory_cnt += num_regs;
9527 else if (VALUE_LVAL (v) != not_lval
9528 && deprecated_value_modifiable (v) == 0)
9529 return 0; /* These are values from the history (e.g., $1). */
9530 else if (VALUE_LVAL (v) == lval_register)
9531 return 0; /* Cannot watch a register with a HW watchpoint. */
9534 /* The expression itself looks suitable for using a hardware
9535 watchpoint, but give the target machine a chance to reject it. */
9536 return found_memory_cnt;
9540 watch_command_wrapper (char *arg, int from_tty, int internal)
9542 watch_command_1 (arg, hw_write, from_tty, 0, internal);
9545 /* A helper function that looks for an argument at the start of a
9546 string. The argument must also either be at the end of the string,
9547 or be followed by whitespace. Returns 1 if it finds the argument,
9548 0 otherwise. If the argument is found, it updates *STR. */
9551 check_for_argument (char **str, char *arg, int arg_len)
9553 if (strncmp (*str, arg, arg_len) == 0
9554 && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len])))
9562 /* A helper function that looks for the "-location" argument and then
9563 calls watch_command_1. */
9566 watch_maybe_just_location (char *arg, int accessflag, int from_tty)
9568 int just_location = 0;
9571 && (check_for_argument (&arg, "-location", sizeof ("-location") - 1)
9572 || check_for_argument (&arg, "-l", sizeof ("-l") - 1)))
9574 arg = skip_spaces (arg);
9578 watch_command_1 (arg, accessflag, from_tty, just_location, 0);
9582 watch_command (char *arg, int from_tty)
9584 watch_maybe_just_location (arg, hw_write, from_tty);
9588 rwatch_command_wrapper (char *arg, int from_tty, int internal)
9590 watch_command_1 (arg, hw_read, from_tty, 0, internal);
9594 rwatch_command (char *arg, int from_tty)
9596 watch_maybe_just_location (arg, hw_read, from_tty);
9600 awatch_command_wrapper (char *arg, int from_tty, int internal)
9602 watch_command_1 (arg, hw_access, from_tty, 0, internal);
9606 awatch_command (char *arg, int from_tty)
9608 watch_maybe_just_location (arg, hw_access, from_tty);
9612 /* Helper routines for the until_command routine in infcmd.c. Here
9613 because it uses the mechanisms of breakpoints. */
9615 struct until_break_command_continuation_args
9617 struct breakpoint *breakpoint;
9618 struct breakpoint *breakpoint2;
9622 /* This function is called by fetch_inferior_event via the
9623 cmd_continuation pointer, to complete the until command. It takes
9624 care of cleaning up the temporary breakpoints set up by the until
9627 until_break_command_continuation (void *arg, int err)
9629 struct until_break_command_continuation_args *a = arg;
9631 delete_breakpoint (a->breakpoint);
9633 delete_breakpoint (a->breakpoint2);
9634 delete_longjmp_breakpoint (a->thread_num);
9638 until_break_command (char *arg, int from_tty, int anywhere)
9640 struct symtabs_and_lines sals;
9641 struct symtab_and_line sal;
9642 struct frame_info *frame = get_selected_frame (NULL);
9643 struct breakpoint *breakpoint;
9644 struct breakpoint *breakpoint2 = NULL;
9645 struct cleanup *old_chain;
9647 struct thread_info *tp;
9649 clear_proceed_status ();
9651 /* Set a breakpoint where the user wants it and at return from
9654 if (default_breakpoint_valid)
9655 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
9656 default_breakpoint_line, NULL);
9658 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, 0, NULL);
9660 if (sals.nelts != 1)
9661 error (_("Couldn't get information on specified line."));
9664 xfree (sals.sals); /* malloc'd, so freed. */
9667 error (_("Junk at end of arguments."));
9669 resolve_sal_pc (&sal);
9672 /* If the user told us to continue until a specified location,
9673 we don't specify a frame at which we need to stop. */
9674 breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal,
9675 null_frame_id, bp_until);
9677 /* Otherwise, specify the selected frame, because we want to stop
9678 only at the very same frame. */
9679 breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal,
9680 get_stack_frame_id (frame),
9683 old_chain = make_cleanup_delete_breakpoint (breakpoint);
9685 tp = inferior_thread ();
9688 /* Keep within the current frame, or in frames called by the current
9691 if (frame_id_p (frame_unwind_caller_id (frame)))
9693 sal = find_pc_line (frame_unwind_caller_pc (frame), 0);
9694 sal.pc = frame_unwind_caller_pc (frame);
9695 breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame),
9697 frame_unwind_caller_id (frame),
9699 make_cleanup_delete_breakpoint (breakpoint2);
9701 set_longjmp_breakpoint (tp, frame_unwind_caller_id (frame));
9702 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
9705 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
9707 /* If we are running asynchronously, and proceed call above has
9708 actually managed to start the target, arrange for breakpoints to
9709 be deleted when the target stops. Otherwise, we're already
9710 stopped and delete breakpoints via cleanup chain. */
9712 if (target_can_async_p () && is_running (inferior_ptid))
9714 struct until_break_command_continuation_args *args;
9715 args = xmalloc (sizeof (*args));
9717 args->breakpoint = breakpoint;
9718 args->breakpoint2 = breakpoint2;
9719 args->thread_num = thread;
9721 discard_cleanups (old_chain);
9722 add_continuation (inferior_thread (),
9723 until_break_command_continuation, args,
9727 do_cleanups (old_chain);
9730 /* This function attempts to parse an optional "if <cond>" clause
9731 from the arg string. If one is not found, it returns NULL.
9733 Else, it returns a pointer to the condition string. (It does not
9734 attempt to evaluate the string against a particular block.) And,
9735 it updates arg to point to the first character following the parsed
9736 if clause in the arg string. */
9739 ep_parse_optional_if_clause (char **arg)
9743 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
9746 /* Skip the "if" keyword. */
9749 /* Skip any extra leading whitespace, and record the start of the
9750 condition string. */
9751 *arg = skip_spaces (*arg);
9754 /* Assume that the condition occupies the remainder of the arg
9756 (*arg) += strlen (cond_string);
9761 /* Commands to deal with catching events, such as signals, exceptions,
9762 process start/exit, etc. */
9766 catch_fork_temporary, catch_vfork_temporary,
9767 catch_fork_permanent, catch_vfork_permanent
9772 catch_fork_command_1 (char *arg, int from_tty,
9773 struct cmd_list_element *command)
9775 struct gdbarch *gdbarch = get_current_arch ();
9776 char *cond_string = NULL;
9777 catch_fork_kind fork_kind;
9780 fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command);
9781 tempflag = (fork_kind == catch_fork_temporary
9782 || fork_kind == catch_vfork_temporary);
9786 arg = skip_spaces (arg);
9788 /* The allowed syntax is:
9790 catch [v]fork if <cond>
9792 First, check if there's an if clause. */
9793 cond_string = ep_parse_optional_if_clause (&arg);
9795 if ((*arg != '\0') && !isspace (*arg))
9796 error (_("Junk at end of arguments."));
9798 /* If this target supports it, create a fork or vfork catchpoint
9799 and enable reporting of such events. */
9802 case catch_fork_temporary:
9803 case catch_fork_permanent:
9804 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
9805 &catch_fork_breakpoint_ops);
9807 case catch_vfork_temporary:
9808 case catch_vfork_permanent:
9809 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
9810 &catch_vfork_breakpoint_ops);
9813 error (_("unsupported or unknown fork kind; cannot catch it"));
9819 catch_exec_command_1 (char *arg, int from_tty,
9820 struct cmd_list_element *command)
9822 struct exec_catchpoint *c;
9823 struct gdbarch *gdbarch = get_current_arch ();
9825 char *cond_string = NULL;
9827 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
9831 arg = skip_spaces (arg);
9833 /* The allowed syntax is:
9835 catch exec if <cond>
9837 First, check if there's an if clause. */
9838 cond_string = ep_parse_optional_if_clause (&arg);
9840 if ((*arg != '\0') && !isspace (*arg))
9841 error (_("Junk at end of arguments."));
9843 c = XNEW (struct exec_catchpoint);
9844 init_catchpoint (&c->base, gdbarch, tempflag, cond_string,
9845 &catch_exec_breakpoint_ops);
9846 c->exec_pathname = NULL;
9848 install_catchpoint (&c->base);
9851 static enum print_stop_action
9852 print_it_exception_catchpoint (struct breakpoint *b)
9854 int bp_temp, bp_throw;
9856 annotate_catchpoint (b->number);
9858 bp_throw = strstr (b->addr_string, "throw") != NULL;
9859 if (b->loc->address != b->loc->requested_address)
9860 breakpoint_adjustment_warning (b->loc->requested_address,
9863 bp_temp = b->disposition == disp_del;
9865 bp_temp ? "Temporary catchpoint "
9867 if (!ui_out_is_mi_like_p (uiout))
9868 ui_out_field_int (uiout, "bkptno", b->number);
9870 bp_throw ? " (exception thrown), "
9871 : " (exception caught), ");
9872 if (ui_out_is_mi_like_p (uiout))
9874 ui_out_field_string (uiout, "reason",
9875 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
9876 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
9877 ui_out_field_int (uiout, "bkptno", b->number);
9879 return PRINT_SRC_AND_LOC;
9883 print_one_exception_catchpoint (struct breakpoint *b,
9884 struct bp_location **last_loc)
9886 struct value_print_options opts;
9888 get_user_print_options (&opts);
9889 if (opts.addressprint)
9892 if (b->loc == NULL || b->loc->shlib_disabled)
9893 ui_out_field_string (uiout, "addr", "<PENDING>");
9895 ui_out_field_core_addr (uiout, "addr",
9896 b->loc->gdbarch, b->loc->address);
9901 if (strstr (b->addr_string, "throw") != NULL)
9902 ui_out_field_string (uiout, "what", "exception throw");
9904 ui_out_field_string (uiout, "what", "exception catch");
9908 print_mention_exception_catchpoint (struct breakpoint *b)
9913 bp_temp = b->disposition == disp_del;
9914 bp_throw = strstr (b->addr_string, "throw") != NULL;
9915 ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ")
9916 : _("Catchpoint "));
9917 ui_out_field_int (uiout, "bkptno", b->number);
9918 ui_out_text (uiout, bp_throw ? _(" (throw)")
9922 /* Implement the "print_recreate" breakpoint_ops method for throw and
9923 catch catchpoints. */
9926 print_recreate_exception_catchpoint (struct breakpoint *b,
9932 bp_temp = b->disposition == disp_del;
9933 bp_throw = strstr (b->addr_string, "throw") != NULL;
9934 fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch ");
9935 fprintf_unfiltered (fp, bp_throw ? "throw" : "catch");
9938 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = {
9942 NULL, /* breakpoint_hit */
9943 NULL, /* resources_needed */
9944 NULL, /* works_in_software_mode */
9945 print_it_exception_catchpoint,
9946 print_one_exception_catchpoint,
9947 NULL, /* print_one_detail */
9948 print_mention_exception_catchpoint,
9949 print_recreate_exception_catchpoint
9953 handle_gnu_v3_exceptions (int tempflag, char *cond_string,
9954 enum exception_event_kind ex_event, int from_tty)
9956 char *trigger_func_name;
9958 if (ex_event == EX_EVENT_CATCH)
9959 trigger_func_name = "__cxa_begin_catch";
9961 trigger_func_name = "__cxa_throw";
9963 create_breakpoint (get_current_arch (),
9964 trigger_func_name, cond_string, -1,
9965 0 /* condition and thread are valid. */,
9966 tempflag, bp_breakpoint,
9968 AUTO_BOOLEAN_TRUE /* pending */,
9969 &gnu_v3_exception_catchpoint_ops, from_tty,
9976 /* Deal with "catch catch" and "catch throw" commands. */
9979 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
9980 int tempflag, int from_tty)
9982 char *cond_string = NULL;
9986 arg = skip_spaces (arg);
9988 cond_string = ep_parse_optional_if_clause (&arg);
9990 if ((*arg != '\0') && !isspace (*arg))
9991 error (_("Junk at end of arguments."));
9993 if (ex_event != EX_EVENT_THROW
9994 && ex_event != EX_EVENT_CATCH)
9995 error (_("Unsupported or unknown exception event; cannot catch it"));
9997 if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
10000 warning (_("Unsupported with this platform/compiler combination."));
10003 /* Implementation of "catch catch" command. */
10006 catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command)
10008 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
10010 catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty);
10013 /* Implementation of "catch throw" command. */
10016 catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command)
10018 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
10020 catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty);
10024 create_ada_exception_breakpoint (struct gdbarch *gdbarch,
10025 struct symtab_and_line sal,
10029 struct expression *cond,
10030 struct breakpoint_ops *ops,
10034 struct breakpoint *b;
10038 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
10040 loc_gdbarch = gdbarch;
10042 describe_other_breakpoints (loc_gdbarch,
10043 sal.pspace, sal.pc, sal.section, -1);
10044 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
10045 version for exception catchpoints, because two catchpoints
10046 used for different exception names will use the same address.
10047 In this case, a "breakpoint ... also set at..." warning is
10048 unproductive. Besides, the warning phrasing is also a bit
10049 inapropriate, we should use the word catchpoint, and tell
10050 the user what type of catchpoint it is. The above is good
10051 enough for now, though. */
10054 b = set_raw_breakpoint (gdbarch, sal, bp_breakpoint);
10055 set_breakpoint_count (breakpoint_count + 1);
10057 b->enable_state = bp_enabled;
10058 b->disposition = tempflag ? disp_del : disp_donttouch;
10059 b->number = breakpoint_count;
10060 b->ignore_count = 0;
10061 b->loc->cond = cond;
10062 b->addr_string = addr_string;
10063 b->language = language_ada;
10064 b->cond_string = cond_string;
10065 b->exp_string = exp_string;
10070 observer_notify_breakpoint_created (b);
10071 update_global_location_list (1);
10074 /* Cleanup function for a syscall filter list. */
10076 clean_up_filters (void *arg)
10078 VEC(int) *iter = *(VEC(int) **) arg;
10079 VEC_free (int, iter);
10082 /* Splits the argument using space as delimiter. Returns an xmalloc'd
10083 filter list, or NULL if no filtering is required. */
10085 catch_syscall_split_args (char *arg)
10087 VEC(int) *result = NULL;
10088 struct cleanup *cleanup = make_cleanup (clean_up_filters, &result);
10090 while (*arg != '\0')
10092 int i, syscall_number;
10094 char cur_name[128];
10097 /* Skip whitespace. */
10098 while (isspace (*arg))
10101 for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i)
10102 cur_name[i] = arg[i];
10103 cur_name[i] = '\0';
10106 /* Check if the user provided a syscall name or a number. */
10107 syscall_number = (int) strtol (cur_name, &endptr, 0);
10108 if (*endptr == '\0')
10109 get_syscall_by_number (syscall_number, &s);
10112 /* We have a name. Let's check if it's valid and convert it
10114 get_syscall_by_name (cur_name, &s);
10116 if (s.number == UNKNOWN_SYSCALL)
10117 /* Here we have to issue an error instead of a warning,
10118 because GDB cannot do anything useful if there's no
10119 syscall number to be caught. */
10120 error (_("Unknown syscall name '%s'."), cur_name);
10123 /* Ok, it's valid. */
10124 VEC_safe_push (int, result, s.number);
10127 discard_cleanups (cleanup);
10131 /* Implement the "catch syscall" command. */
10134 catch_syscall_command_1 (char *arg, int from_tty,
10135 struct cmd_list_element *command)
10140 struct gdbarch *gdbarch = get_current_arch ();
10142 /* Checking if the feature if supported. */
10143 if (gdbarch_get_syscall_number_p (gdbarch) == 0)
10144 error (_("The feature 'catch syscall' is not supported on \
10145 this architecture yet."));
10147 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
10149 arg = skip_spaces (arg);
10151 /* We need to do this first "dummy" translation in order
10152 to get the syscall XML file loaded or, most important,
10153 to display a warning to the user if there's no XML file
10154 for his/her architecture. */
10155 get_syscall_by_number (0, &s);
10157 /* The allowed syntax is:
10159 catch syscall <name | number> [<name | number> ... <name | number>]
10161 Let's check if there's a syscall name. */
10164 filter = catch_syscall_split_args (arg);
10168 create_syscall_event_catchpoint (tempflag, filter,
10169 &catch_syscall_breakpoint_ops);
10173 catch_command (char *arg, int from_tty)
10175 error (_("Catch requires an event name."));
10180 tcatch_command (char *arg, int from_tty)
10182 error (_("Catch requires an event name."));
10185 /* Delete breakpoints by address or line. */
10188 clear_command (char *arg, int from_tty)
10190 struct breakpoint *b;
10191 VEC(breakpoint_p) *found = 0;
10194 struct symtabs_and_lines sals;
10195 struct symtab_and_line sal;
10200 sals = decode_line_spec (arg, 1);
10205 sals.sals = (struct symtab_and_line *)
10206 xmalloc (sizeof (struct symtab_and_line));
10207 make_cleanup (xfree, sals.sals);
10208 init_sal (&sal); /* Initialize to zeroes. */
10209 sal.line = default_breakpoint_line;
10210 sal.symtab = default_breakpoint_symtab;
10211 sal.pc = default_breakpoint_address;
10212 sal.pspace = default_breakpoint_pspace;
10213 if (sal.symtab == 0)
10214 error (_("No source file specified."));
10216 sals.sals[0] = sal;
10222 /* We don't call resolve_sal_pc here. That's not as bad as it
10223 seems, because all existing breakpoints typically have both
10224 file/line and pc set. So, if clear is given file/line, we can
10225 match this to existing breakpoint without obtaining pc at all.
10227 We only support clearing given the address explicitly
10228 present in breakpoint table. Say, we've set breakpoint
10229 at file:line. There were several PC values for that file:line,
10230 due to optimization, all in one block.
10232 We've picked one PC value. If "clear" is issued with another
10233 PC corresponding to the same file:line, the breakpoint won't
10234 be cleared. We probably can still clear the breakpoint, but
10235 since the other PC value is never presented to user, user
10236 can only find it by guessing, and it does not seem important
10237 to support that. */
10239 /* For each line spec given, delete bps which correspond to it. Do
10240 it in two passes, solely to preserve the current behavior that
10241 from_tty is forced true if we delete more than one
10245 for (i = 0; i < sals.nelts; i++)
10247 /* If exact pc given, clear bpts at that pc.
10248 If line given (pc == 0), clear all bpts on specified line.
10249 If defaulting, clear all bpts on default line
10252 defaulting sal.pc != 0 tests to do
10257 1 0 <can't happen> */
10259 sal = sals.sals[i];
10261 /* Find all matching breakpoints and add them to 'found'. */
10262 ALL_BREAKPOINTS (b)
10265 /* Are we going to delete b? */
10266 if (b->type != bp_none && !is_watchpoint (b))
10268 struct bp_location *loc = b->loc;
10269 for (; loc; loc = loc->next)
10271 int pc_match = sal.pc
10272 && (loc->pspace == sal.pspace)
10273 && (loc->address == sal.pc)
10274 && (!section_is_overlay (loc->section)
10275 || loc->section == sal.section);
10276 int line_match = ((default_match || (0 == sal.pc))
10277 && b->source_file != NULL
10278 && sal.symtab != NULL
10279 && sal.pspace == loc->pspace
10280 && filename_cmp (b->source_file,
10281 sal.symtab->filename) == 0
10282 && b->line_number == sal.line);
10283 if (pc_match || line_match)
10292 VEC_safe_push(breakpoint_p, found, b);
10295 /* Now go thru the 'found' chain and delete them. */
10296 if (VEC_empty(breakpoint_p, found))
10299 error (_("No breakpoint at %s."), arg);
10301 error (_("No breakpoint at this line."));
10304 if (VEC_length(breakpoint_p, found) > 1)
10305 from_tty = 1; /* Always report if deleted more than one. */
10308 if (VEC_length(breakpoint_p, found) == 1)
10309 printf_unfiltered (_("Deleted breakpoint "));
10311 printf_unfiltered (_("Deleted breakpoints "));
10313 breakpoints_changed ();
10315 for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++)
10318 printf_unfiltered ("%d ", b->number);
10319 delete_breakpoint (b);
10322 putchar_unfiltered ('\n');
10325 /* Delete breakpoint in BS if they are `delete' breakpoints and
10326 all breakpoints that are marked for deletion, whether hit or not.
10327 This is called after any breakpoint is hit, or after errors. */
10330 breakpoint_auto_delete (bpstat bs)
10332 struct breakpoint *b, *b_tmp;
10334 for (; bs; bs = bs->next)
10335 if (bs->breakpoint_at
10336 && bs->breakpoint_at->disposition == disp_del
10338 delete_breakpoint (bs->breakpoint_at);
10340 ALL_BREAKPOINTS_SAFE (b, b_tmp)
10342 if (b->disposition == disp_del_at_next_stop)
10343 delete_breakpoint (b);
10347 /* A comparison function for bp_location AP and BP being interfaced to
10348 qsort. Sort elements primarily by their ADDRESS (no matter what
10349 does breakpoint_address_is_meaningful say for its OWNER),
10350 secondarily by ordering first bp_permanent OWNERed elements and
10351 terciarily just ensuring the array is sorted stable way despite
10352 qsort being an instable algorithm. */
10355 bp_location_compare (const void *ap, const void *bp)
10357 struct bp_location *a = *(void **) ap;
10358 struct bp_location *b = *(void **) bp;
10359 /* A and B come from existing breakpoints having non-NULL OWNER. */
10360 int a_perm = a->owner->enable_state == bp_permanent;
10361 int b_perm = b->owner->enable_state == bp_permanent;
10363 if (a->address != b->address)
10364 return (a->address > b->address) - (a->address < b->address);
10366 /* Sort permanent breakpoints first. */
10367 if (a_perm != b_perm)
10368 return (a_perm < b_perm) - (a_perm > b_perm);
10370 /* Make the user-visible order stable across GDB runs. Locations of
10371 the same breakpoint can be sorted in arbitrary order. */
10373 if (a->owner->number != b->owner->number)
10374 return (a->owner->number > b->owner->number)
10375 - (a->owner->number < b->owner->number);
10377 return (a > b) - (a < b);
10380 /* Set bp_location_placed_address_before_address_max and
10381 bp_location_shadow_len_after_address_max according to the current
10382 content of the bp_location array. */
10385 bp_location_target_extensions_update (void)
10387 struct bp_location *bl, **blp_tmp;
10389 bp_location_placed_address_before_address_max = 0;
10390 bp_location_shadow_len_after_address_max = 0;
10392 ALL_BP_LOCATIONS (bl, blp_tmp)
10394 CORE_ADDR start, end, addr;
10396 if (!bp_location_has_shadow (bl))
10399 start = bl->target_info.placed_address;
10400 end = start + bl->target_info.shadow_len;
10402 gdb_assert (bl->address >= start);
10403 addr = bl->address - start;
10404 if (addr > bp_location_placed_address_before_address_max)
10405 bp_location_placed_address_before_address_max = addr;
10407 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
10409 gdb_assert (bl->address < end);
10410 addr = end - bl->address;
10411 if (addr > bp_location_shadow_len_after_address_max)
10412 bp_location_shadow_len_after_address_max = addr;
10416 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
10417 into the inferior, only remove already-inserted locations that no
10418 longer should be inserted. Functions that delete a breakpoint or
10419 breakpoints should pass false, so that deleting a breakpoint
10420 doesn't have the side effect of inserting the locations of other
10421 breakpoints that are marked not-inserted, but should_be_inserted
10422 returns true on them.
10424 This behaviour is useful is situations close to tear-down -- e.g.,
10425 after an exec, while the target still has execution, but breakpoint
10426 shadows of the previous executable image should *NOT* be restored
10427 to the new image; or before detaching, where the target still has
10428 execution and wants to delete breakpoints from GDB's lists, and all
10429 breakpoints had already been removed from the inferior. */
10432 update_global_location_list (int should_insert)
10434 struct breakpoint *b;
10435 struct bp_location **locp, *loc;
10436 struct cleanup *cleanups;
10438 /* Used in the duplicates detection below. When iterating over all
10439 bp_locations, points to the first bp_location of a given address.
10440 Breakpoints and watchpoints of different types are never
10441 duplicates of each other. Keep one pointer for each type of
10442 breakpoint/watchpoint, so we only need to loop over all locations
10444 struct bp_location *bp_loc_first; /* breakpoint */
10445 struct bp_location *wp_loc_first; /* hardware watchpoint */
10446 struct bp_location *awp_loc_first; /* access watchpoint */
10447 struct bp_location *rwp_loc_first; /* read watchpoint */
10449 /* Saved former bp_location array which we compare against the newly
10450 built bp_location from the current state of ALL_BREAKPOINTS. */
10451 struct bp_location **old_location, **old_locp;
10452 unsigned old_location_count;
10454 old_location = bp_location;
10455 old_location_count = bp_location_count;
10456 bp_location = NULL;
10457 bp_location_count = 0;
10458 cleanups = make_cleanup (xfree, old_location);
10460 ALL_BREAKPOINTS (b)
10461 for (loc = b->loc; loc; loc = loc->next)
10462 bp_location_count++;
10464 bp_location = xmalloc (sizeof (*bp_location) * bp_location_count);
10465 locp = bp_location;
10466 ALL_BREAKPOINTS (b)
10467 for (loc = b->loc; loc; loc = loc->next)
10469 qsort (bp_location, bp_location_count, sizeof (*bp_location),
10470 bp_location_compare);
10472 bp_location_target_extensions_update ();
10474 /* Identify bp_location instances that are no longer present in the
10475 new list, and therefore should be freed. Note that it's not
10476 necessary that those locations should be removed from inferior --
10477 if there's another location at the same address (previously
10478 marked as duplicate), we don't need to remove/insert the
10481 LOCP is kept in sync with OLD_LOCP, each pointing to the current
10482 and former bp_location array state respectively. */
10484 locp = bp_location;
10485 for (old_locp = old_location; old_locp < old_location + old_location_count;
10488 struct bp_location *old_loc = *old_locp;
10489 struct bp_location **loc2p;
10491 /* Tells if 'old_loc' is found amoung the new locations. If
10492 not, we have to free it. */
10493 int found_object = 0;
10494 /* Tells if the location should remain inserted in the target. */
10495 int keep_in_target = 0;
10498 /* Skip LOCP entries which will definitely never be needed.
10499 Stop either at or being the one matching OLD_LOC. */
10500 while (locp < bp_location + bp_location_count
10501 && (*locp)->address < old_loc->address)
10505 (loc2p < bp_location + bp_location_count
10506 && (*loc2p)->address == old_loc->address);
10509 if (*loc2p == old_loc)
10516 /* If this location is no longer present, and inserted, look if
10517 there's maybe a new location at the same address. If so,
10518 mark that one inserted, and don't remove this one. This is
10519 needed so that we don't have a time window where a breakpoint
10520 at certain location is not inserted. */
10522 if (old_loc->inserted)
10524 /* If the location is inserted now, we might have to remove
10527 if (found_object && should_be_inserted (old_loc))
10529 /* The location is still present in the location list,
10530 and still should be inserted. Don't do anything. */
10531 keep_in_target = 1;
10535 /* The location is either no longer present, or got
10536 disabled. See if there's another location at the
10537 same address, in which case we don't need to remove
10538 this one from the target. */
10540 /* OLD_LOC comes from existing struct breakpoint. */
10541 if (breakpoint_address_is_meaningful (old_loc->owner))
10544 (loc2p < bp_location + bp_location_count
10545 && (*loc2p)->address == old_loc->address);
10548 struct bp_location *loc2 = *loc2p;
10550 if (breakpoint_locations_match (loc2, old_loc))
10552 /* For the sake of should_be_inserted.
10553 Duplicates check below will fix up this
10555 loc2->duplicate = 0;
10557 /* Read watchpoint locations are switched to
10558 access watchpoints, if the former are not
10559 supported, but the latter are. */
10560 if (is_hardware_watchpoint (old_loc->owner))
10562 gdb_assert (is_hardware_watchpoint (loc2->owner));
10563 loc2->watchpoint_type = old_loc->watchpoint_type;
10566 if (loc2 != old_loc && should_be_inserted (loc2))
10568 loc2->inserted = 1;
10569 loc2->target_info = old_loc->target_info;
10570 keep_in_target = 1;
10578 if (!keep_in_target)
10580 if (remove_breakpoint (old_loc, mark_uninserted))
10582 /* This is just about all we can do. We could keep
10583 this location on the global list, and try to
10584 remove it next time, but there's no particular
10585 reason why we will succeed next time.
10587 Note that at this point, old_loc->owner is still
10588 valid, as delete_breakpoint frees the breakpoint
10589 only after calling us. */
10590 printf_filtered (_("warning: Error removing "
10591 "breakpoint %d\n"),
10592 old_loc->owner->number);
10600 if (removed && non_stop
10601 && breakpoint_address_is_meaningful (old_loc->owner)
10602 && !is_hardware_watchpoint (old_loc->owner))
10604 /* This location was removed from the target. In
10605 non-stop mode, a race condition is possible where
10606 we've removed a breakpoint, but stop events for that
10607 breakpoint are already queued and will arrive later.
10608 We apply an heuristic to be able to distinguish such
10609 SIGTRAPs from other random SIGTRAPs: we keep this
10610 breakpoint location for a bit, and will retire it
10611 after we see some number of events. The theory here
10612 is that reporting of events should, "on the average",
10613 be fair, so after a while we'll see events from all
10614 threads that have anything of interest, and no longer
10615 need to keep this breakpoint location around. We
10616 don't hold locations forever so to reduce chances of
10617 mistaking a non-breakpoint SIGTRAP for a breakpoint
10620 The heuristic failing can be disastrous on
10621 decr_pc_after_break targets.
10623 On decr_pc_after_break targets, like e.g., x86-linux,
10624 if we fail to recognize a late breakpoint SIGTRAP,
10625 because events_till_retirement has reached 0 too
10626 soon, we'll fail to do the PC adjustment, and report
10627 a random SIGTRAP to the user. When the user resumes
10628 the inferior, it will most likely immediately crash
10629 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
10630 corrupted, because of being resumed e.g., in the
10631 middle of a multi-byte instruction, or skipped a
10632 one-byte instruction. This was actually seen happen
10633 on native x86-linux, and should be less rare on
10634 targets that do not support new thread events, like
10635 remote, due to the heuristic depending on
10638 Mistaking a random SIGTRAP for a breakpoint trap
10639 causes similar symptoms (PC adjustment applied when
10640 it shouldn't), but then again, playing with SIGTRAPs
10641 behind the debugger's back is asking for trouble.
10643 Since hardware watchpoint traps are always
10644 distinguishable from other traps, so we don't need to
10645 apply keep hardware watchpoint moribund locations
10646 around. We simply always ignore hardware watchpoint
10647 traps we can no longer explain. */
10649 old_loc->events_till_retirement = 3 * (thread_count () + 1);
10650 old_loc->owner = NULL;
10652 VEC_safe_push (bp_location_p, moribund_locations, old_loc);
10656 old_loc->owner = NULL;
10657 decref_bp_location (&old_loc);
10662 /* Rescan breakpoints at the same address and section, marking the
10663 first one as "first" and any others as "duplicates". This is so
10664 that the bpt instruction is only inserted once. If we have a
10665 permanent breakpoint at the same place as BPT, make that one the
10666 official one, and the rest as duplicates. Permanent breakpoints
10667 are sorted first for the same address.
10669 Do the same for hardware watchpoints, but also considering the
10670 watchpoint's type (regular/access/read) and length. */
10672 bp_loc_first = NULL;
10673 wp_loc_first = NULL;
10674 awp_loc_first = NULL;
10675 rwp_loc_first = NULL;
10676 ALL_BP_LOCATIONS (loc, locp)
10678 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
10680 struct breakpoint *b = loc->owner;
10681 struct bp_location **loc_first_p;
10683 if (b->enable_state == bp_disabled
10684 || b->enable_state == bp_call_disabled
10685 || b->enable_state == bp_startup_disabled
10687 || loc->shlib_disabled
10688 || !breakpoint_address_is_meaningful (b)
10689 || is_tracepoint (b))
10692 /* Permanent breakpoint should always be inserted. */
10693 if (b->enable_state == bp_permanent && ! loc->inserted)
10694 internal_error (__FILE__, __LINE__,
10695 _("allegedly permanent breakpoint is not "
10696 "actually inserted"));
10698 if (b->type == bp_hardware_watchpoint)
10699 loc_first_p = &wp_loc_first;
10700 else if (b->type == bp_read_watchpoint)
10701 loc_first_p = &rwp_loc_first;
10702 else if (b->type == bp_access_watchpoint)
10703 loc_first_p = &awp_loc_first;
10705 loc_first_p = &bp_loc_first;
10707 if (*loc_first_p == NULL
10708 || (overlay_debugging && loc->section != (*loc_first_p)->section)
10709 || !breakpoint_locations_match (loc, *loc_first_p))
10711 *loc_first_p = loc;
10712 loc->duplicate = 0;
10716 loc->duplicate = 1;
10718 if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted
10719 && b->enable_state != bp_permanent)
10720 internal_error (__FILE__, __LINE__,
10721 _("another breakpoint was inserted on top of "
10722 "a permanent breakpoint"));
10725 if (breakpoints_always_inserted_mode () && should_insert
10726 && (have_live_inferiors ()
10727 || (gdbarch_has_global_breakpoints (target_gdbarch))))
10728 insert_breakpoint_locations ();
10730 do_cleanups (cleanups);
10734 breakpoint_retire_moribund (void)
10736 struct bp_location *loc;
10739 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
10740 if (--(loc->events_till_retirement) == 0)
10742 decref_bp_location (&loc);
10743 VEC_unordered_remove (bp_location_p, moribund_locations, ix);
10749 update_global_location_list_nothrow (int inserting)
10751 struct gdb_exception e;
10753 TRY_CATCH (e, RETURN_MASK_ERROR)
10754 update_global_location_list (inserting);
10757 /* Clear BKP from a BPS. */
10760 bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt)
10764 for (bs = bps; bs; bs = bs->next)
10765 if (bs->breakpoint_at == bpt)
10767 bs->breakpoint_at = NULL;
10768 bs->old_val = NULL;
10769 /* bs->commands will be freed later. */
10773 /* Callback for iterate_over_threads. */
10775 bpstat_remove_breakpoint_callback (struct thread_info *th, void *data)
10777 struct breakpoint *bpt = data;
10779 bpstat_remove_bp_location (th->control.stop_bpstat, bpt);
10783 /* Delete a breakpoint and clean up all traces of it in the data
10787 delete_breakpoint (struct breakpoint *bpt)
10789 struct breakpoint *b;
10791 gdb_assert (bpt != NULL);
10793 /* Has this bp already been deleted? This can happen because
10794 multiple lists can hold pointers to bp's. bpstat lists are
10797 One example of this happening is a watchpoint's scope bp. When
10798 the scope bp triggers, we notice that the watchpoint is out of
10799 scope, and delete it. We also delete its scope bp. But the
10800 scope bp is marked "auto-deleting", and is already on a bpstat.
10801 That bpstat is then checked for auto-deleting bp's, which are
10804 A real solution to this problem might involve reference counts in
10805 bp's, and/or giving them pointers back to their referencing
10806 bpstat's, and teaching delete_breakpoint to only free a bp's
10807 storage when no more references were extent. A cheaper bandaid
10809 if (bpt->type == bp_none)
10812 /* At least avoid this stale reference until the reference counting
10813 of breakpoints gets resolved. */
10814 if (bpt->related_breakpoint != bpt)
10816 struct breakpoint *related;
10818 if (bpt->type == bp_watchpoint_scope)
10819 watchpoint_del_at_next_stop (bpt->related_breakpoint);
10820 else if (bpt->related_breakpoint->type == bp_watchpoint_scope)
10821 watchpoint_del_at_next_stop (bpt);
10823 /* Unlink bpt from the bpt->related_breakpoint ring. */
10824 for (related = bpt; related->related_breakpoint != bpt;
10825 related = related->related_breakpoint);
10826 related->related_breakpoint = bpt->related_breakpoint;
10827 bpt->related_breakpoint = bpt;
10830 /* watch_command_1 creates a watchpoint but only sets its number if
10831 update_watchpoint succeeds in creating its bp_locations. If there's
10832 a problem in that process, we'll be asked to delete the half-created
10833 watchpoint. In that case, don't announce the deletion. */
10835 observer_notify_breakpoint_deleted (bpt);
10837 if (breakpoint_chain == bpt)
10838 breakpoint_chain = bpt->next;
10840 ALL_BREAKPOINTS (b)
10841 if (b->next == bpt)
10843 b->next = bpt->next;
10847 if (bpt->ops != NULL && bpt->ops->dtor != NULL)
10848 bpt->ops->dtor (bpt);
10850 decref_counted_command_line (&bpt->commands);
10851 xfree (bpt->cond_string);
10852 xfree (bpt->cond_exp);
10853 xfree (bpt->addr_string);
10854 xfree (bpt->addr_string_range_end);
10856 xfree (bpt->exp_string);
10857 xfree (bpt->exp_string_reparse);
10858 value_free (bpt->val);
10859 xfree (bpt->source_file);
10862 /* Be sure no bpstat's are pointing at the breakpoint after it's
10864 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
10865 in all threeds for now. Note that we cannot just remove bpstats
10866 pointing at bpt from the stop_bpstat list entirely, as breakpoint
10867 commands are associated with the bpstat; if we remove it here,
10868 then the later call to bpstat_do_actions (&stop_bpstat); in
10869 event-top.c won't do anything, and temporary breakpoints with
10870 commands won't work. */
10872 iterate_over_threads (bpstat_remove_breakpoint_callback, bpt);
10874 /* Now that breakpoint is removed from breakpoint list, update the
10875 global location list. This will remove locations that used to
10876 belong to this breakpoint. Do this before freeing the breakpoint
10877 itself, since remove_breakpoint looks at location's owner. It
10878 might be better design to have location completely
10879 self-contained, but it's not the case now. */
10880 update_global_location_list (0);
10883 /* On the chance that someone will soon try again to delete this
10884 same bp, we mark it as deleted before freeing its storage. */
10885 bpt->type = bp_none;
10891 do_delete_breakpoint_cleanup (void *b)
10893 delete_breakpoint (b);
10897 make_cleanup_delete_breakpoint (struct breakpoint *b)
10899 return make_cleanup (do_delete_breakpoint_cleanup, b);
10902 /* Iterator function to call a user-provided callback function once
10903 for each of B and its related breakpoints. */
10906 iterate_over_related_breakpoints (struct breakpoint *b,
10907 void (*function) (struct breakpoint *,
10911 struct breakpoint *related;
10916 struct breakpoint *next;
10918 /* FUNCTION may delete RELATED. */
10919 next = related->related_breakpoint;
10921 if (next == related)
10923 /* RELATED is the last ring entry. */
10924 function (related, data);
10926 /* FUNCTION may have deleted it, so we'd never reach back to
10927 B. There's nothing left to do anyway, so just break
10932 function (related, data);
10936 while (related != b);
10940 do_delete_breakpoint (struct breakpoint *b, void *ignore)
10942 delete_breakpoint (b);
10945 /* A callback for map_breakpoint_numbers that calls
10946 delete_breakpoint. */
10949 do_map_delete_breakpoint (struct breakpoint *b, void *ignore)
10951 iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL);
10955 delete_command (char *arg, int from_tty)
10957 struct breakpoint *b, *b_tmp;
10963 int breaks_to_delete = 0;
10965 /* Delete all breakpoints if no argument. Do not delete
10966 internal breakpoints, these have to be deleted with an
10967 explicit breakpoint number argument. */
10968 ALL_BREAKPOINTS (b)
10969 if (user_breakpoint_p (b))
10971 breaks_to_delete = 1;
10975 /* Ask user only if there are some breakpoints to delete. */
10977 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
10979 ALL_BREAKPOINTS_SAFE (b, b_tmp)
10980 if (user_breakpoint_p (b))
10981 delete_breakpoint (b);
10985 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
10989 all_locations_are_pending (struct bp_location *loc)
10991 for (; loc; loc = loc->next)
10992 if (!loc->shlib_disabled)
10997 /* Subroutine of update_breakpoint_locations to simplify it.
10998 Return non-zero if multiple fns in list LOC have the same name.
10999 Null names are ignored. */
11002 ambiguous_names_p (struct bp_location *loc)
11004 struct bp_location *l;
11005 htab_t htab = htab_create_alloc (13, htab_hash_string,
11006 (int (*) (const void *,
11007 const void *)) streq,
11008 NULL, xcalloc, xfree);
11010 for (l = loc; l != NULL; l = l->next)
11013 const char *name = l->function_name;
11015 /* Allow for some names to be NULL, ignore them. */
11019 slot = (const char **) htab_find_slot (htab, (const void *) name,
11021 /* NOTE: We can assume slot != NULL here because xcalloc never
11025 htab_delete (htab);
11031 htab_delete (htab);
11035 /* When symbols change, it probably means the sources changed as well,
11036 and it might mean the static tracepoint markers are no longer at
11037 the same address or line numbers they used to be at last we
11038 checked. Losing your static tracepoints whenever you rebuild is
11039 undesirable. This function tries to resync/rematch gdb static
11040 tracepoints with the markers on the target, for static tracepoints
11041 that have not been set by marker id. Static tracepoint that have
11042 been set by marker id are reset by marker id in breakpoint_re_set.
11045 1) For a tracepoint set at a specific address, look for a marker at
11046 the old PC. If one is found there, assume to be the same marker.
11047 If the name / string id of the marker found is different from the
11048 previous known name, assume that means the user renamed the marker
11049 in the sources, and output a warning.
11051 2) For a tracepoint set at a given line number, look for a marker
11052 at the new address of the old line number. If one is found there,
11053 assume to be the same marker. If the name / string id of the
11054 marker found is different from the previous known name, assume that
11055 means the user renamed the marker in the sources, and output a
11058 3) If a marker is no longer found at the same address or line, it
11059 may mean the marker no longer exists. But it may also just mean
11060 the code changed a bit. Maybe the user added a few lines of code
11061 that made the marker move up or down (in line number terms). Ask
11062 the target for info about the marker with the string id as we knew
11063 it. If found, update line number and address in the matching
11064 static tracepoint. This will get confused if there's more than one
11065 marker with the same ID (possible in UST, although unadvised
11066 precisely because it confuses tools). */
11068 static struct symtab_and_line
11069 update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal)
11071 struct static_tracepoint_marker marker;
11077 find_line_pc (sal.symtab, sal.line, &pc);
11079 if (target_static_tracepoint_marker_at (pc, &marker))
11081 if (strcmp (b->static_trace_marker_id, marker.str_id) != 0)
11082 warning (_("static tracepoint %d changed probed marker from %s to %s"),
11084 b->static_trace_marker_id, marker.str_id);
11086 xfree (b->static_trace_marker_id);
11087 b->static_trace_marker_id = xstrdup (marker.str_id);
11088 release_static_tracepoint_marker (&marker);
11093 /* Old marker wasn't found on target at lineno. Try looking it up
11095 if (!sal.explicit_pc
11097 && sal.symtab != NULL
11098 && b->static_trace_marker_id != NULL)
11100 VEC(static_tracepoint_marker_p) *markers;
11103 = target_static_tracepoint_markers_by_strid (b->static_trace_marker_id);
11105 if (!VEC_empty(static_tracepoint_marker_p, markers))
11107 struct symtab_and_line sal;
11108 struct symbol *sym;
11109 struct static_tracepoint_marker *marker;
11111 marker = VEC_index (static_tracepoint_marker_p, markers, 0);
11113 xfree (b->static_trace_marker_id);
11114 b->static_trace_marker_id = xstrdup (marker->str_id);
11116 warning (_("marker for static tracepoint %d (%s) not "
11117 "found at previous line number"),
11118 b->number, b->static_trace_marker_id);
11122 sal.pc = marker->address;
11124 sal = find_pc_line (marker->address, 0);
11125 sym = find_pc_sect_function (marker->address, NULL);
11126 ui_out_text (uiout, "Now in ");
11129 ui_out_field_string (uiout, "func",
11130 SYMBOL_PRINT_NAME (sym));
11131 ui_out_text (uiout, " at ");
11133 ui_out_field_string (uiout, "file", sal.symtab->filename);
11134 ui_out_text (uiout, ":");
11136 if (ui_out_is_mi_like_p (uiout))
11138 char *fullname = symtab_to_fullname (sal.symtab);
11141 ui_out_field_string (uiout, "fullname", fullname);
11144 ui_out_field_int (uiout, "line", sal.line);
11145 ui_out_text (uiout, "\n");
11147 b->line_number = sal.line;
11149 xfree (b->source_file);
11151 b->source_file = xstrdup (sal.symtab->filename);
11153 b->source_file = NULL;
11155 xfree (b->addr_string);
11156 b->addr_string = xstrprintf ("%s:%d",
11157 sal.symtab->filename, b->line_number);
11159 /* Might be nice to check if function changed, and warn if
11162 release_static_tracepoint_marker (marker);
11168 /* Returns 1 iff locations A and B are sufficiently same that
11169 we don't need to report breakpoint as changed. */
11172 locations_are_equal (struct bp_location *a, struct bp_location *b)
11176 if (a->address != b->address)
11179 if (a->shlib_disabled != b->shlib_disabled)
11182 if (a->enabled != b->enabled)
11189 if ((a == NULL) != (b == NULL))
11195 /* Create new breakpoint locations for B (a hardware or software breakpoint)
11196 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
11197 a ranged breakpoint. */
11200 update_breakpoint_locations (struct breakpoint *b,
11201 struct symtabs_and_lines sals,
11202 struct symtabs_and_lines sals_end)
11205 struct bp_location *existing_locations = b->loc;
11207 /* Ranged breakpoints have only one start location and one end location. */
11208 gdb_assert (sals_end.nelts == 0 || (sals.nelts == 1 && sals_end.nelts == 1));
11210 /* If there's no new locations, and all existing locations are
11211 pending, don't do anything. This optimizes the common case where
11212 all locations are in the same shared library, that was unloaded.
11213 We'd like to retain the location, so that when the library is
11214 loaded again, we don't loose the enabled/disabled status of the
11215 individual locations. */
11216 if (all_locations_are_pending (existing_locations) && sals.nelts == 0)
11221 for (i = 0; i < sals.nelts; ++i)
11223 struct bp_location *new_loc =
11224 add_location_to_breakpoint (b, &(sals.sals[i]));
11226 /* Reparse conditions, they might contain references to the
11228 if (b->cond_string != NULL)
11231 struct gdb_exception e;
11233 s = b->cond_string;
11234 TRY_CATCH (e, RETURN_MASK_ERROR)
11236 new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc),
11241 warning (_("failed to reevaluate condition "
11242 "for breakpoint %d: %s"),
11243 b->number, e.message);
11244 new_loc->enabled = 0;
11248 if (b->source_file != NULL)
11249 xfree (b->source_file);
11250 if (sals.sals[i].symtab == NULL)
11251 b->source_file = NULL;
11253 b->source_file = xstrdup (sals.sals[i].symtab->filename);
11255 if (b->line_number == 0)
11256 b->line_number = sals.sals[i].line;
11258 if (sals_end.nelts)
11260 CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]);
11262 new_loc->length = end - sals.sals[0].pc + 1;
11266 /* Update locations of permanent breakpoints. */
11267 if (b->enable_state == bp_permanent)
11268 make_breakpoint_permanent (b);
11270 /* If possible, carry over 'disable' status from existing
11273 struct bp_location *e = existing_locations;
11274 /* If there are multiple breakpoints with the same function name,
11275 e.g. for inline functions, comparing function names won't work.
11276 Instead compare pc addresses; this is just a heuristic as things
11277 may have moved, but in practice it gives the correct answer
11278 often enough until a better solution is found. */
11279 int have_ambiguous_names = ambiguous_names_p (b->loc);
11281 for (; e; e = e->next)
11283 if (!e->enabled && e->function_name)
11285 struct bp_location *l = b->loc;
11286 if (have_ambiguous_names)
11288 for (; l; l = l->next)
11289 if (breakpoint_locations_match (e, l))
11297 for (; l; l = l->next)
11298 if (l->function_name
11299 && strcmp (e->function_name, l->function_name) == 0)
11309 if (!locations_are_equal (existing_locations, b->loc))
11310 observer_notify_breakpoint_modified (b);
11312 update_global_location_list (1);
11315 /* Find the SaL locations corresponding to the given ADDR_STRING.
11316 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
11318 static struct symtabs_and_lines
11319 addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found)
11323 struct symtabs_and_lines sals = {0};
11324 struct gdb_exception e;
11327 marker_spec = b->type == bp_static_tracepoint && is_marker_spec (s);
11329 TRY_CATCH (e, RETURN_MASK_ERROR)
11333 sals = decode_static_tracepoint_spec (&s);
11334 if (sals.nelts > b->static_trace_marker_id_idx)
11336 sals.sals[0] = sals.sals[b->static_trace_marker_id_idx];
11340 error (_("marker %s not found"), b->static_trace_marker_id);
11343 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, NULL);
11347 int not_found_and_ok = 0;
11348 /* For pending breakpoints, it's expected that parsing will
11349 fail until the right shared library is loaded. User has
11350 already told to create pending breakpoints and don't need
11351 extra messages. If breakpoint is in bp_shlib_disabled
11352 state, then user already saw the message about that
11353 breakpoint being disabled, and don't want to see more
11355 if (e.error == NOT_FOUND_ERROR
11356 && (b->condition_not_parsed
11357 || (b->loc && b->loc->shlib_disabled)
11358 || b->enable_state == bp_disabled))
11359 not_found_and_ok = 1;
11361 if (!not_found_and_ok)
11363 /* We surely don't want to warn about the same breakpoint
11364 10 times. One solution, implemented here, is disable
11365 the breakpoint on error. Another solution would be to
11366 have separate 'warning emitted' flag. Since this
11367 happens only when a binary has changed, I don't know
11368 which approach is better. */
11369 b->enable_state = bp_disabled;
11370 throw_exception (e);
11374 if (e.reason == 0 || e.error != NOT_FOUND_ERROR)
11376 gdb_assert (sals.nelts == 1);
11378 resolve_sal_pc (&sals.sals[0]);
11379 if (b->condition_not_parsed && s && s[0])
11381 char *cond_string = 0;
11385 find_condition_and_thread (s, sals.sals[0].pc,
11386 &cond_string, &thread, &task);
11388 b->cond_string = cond_string;
11389 b->thread = thread;
11391 b->condition_not_parsed = 0;
11394 if (b->type == bp_static_tracepoint && !marker_spec)
11395 sals.sals[0] = update_static_tracepoint (b, sals.sals[0]);
11405 /* Reevaluate a hardware or software breakpoint and recreate its locations.
11406 This is necessary after symbols are read (e.g., an executable or DSO
11407 was loaded, or the inferior just started). */
11410 re_set_breakpoint (struct breakpoint *b)
11413 struct symtabs_and_lines sals, sals_end;
11414 struct symtabs_and_lines expanded = {0};
11415 struct symtabs_and_lines expanded_end = {0};
11416 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
11418 input_radix = b->input_radix;
11419 save_current_space_and_thread ();
11420 switch_to_program_space_and_thread (b->pspace);
11421 set_language (b->language);
11423 sals = addr_string_to_sals (b, b->addr_string, &found);
11426 make_cleanup (xfree, sals.sals);
11427 expanded = expand_line_sal_maybe (sals.sals[0]);
11430 if (b->addr_string_range_end)
11432 sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found);
11435 make_cleanup (xfree, sals_end.sals);
11436 expanded_end = expand_line_sal_maybe (sals_end.sals[0]);
11440 update_breakpoint_locations (b, expanded, expanded_end);
11441 do_cleanups (cleanups);
11444 /* Reset a breakpoint given it's struct breakpoint * BINT.
11445 The value we return ends up being the return value from catch_errors.
11446 Unused in this case. */
11449 breakpoint_re_set_one (void *bint)
11451 /* Get past catch_errs. */
11452 struct breakpoint *b = (struct breakpoint *) bint;
11457 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
11460 case bp_breakpoint:
11461 case bp_hardware_breakpoint:
11462 case bp_tracepoint:
11463 case bp_fast_tracepoint:
11464 case bp_static_tracepoint:
11465 case bp_gnu_ifunc_resolver:
11466 /* Do not attempt to re-set breakpoints disabled during startup. */
11467 if (b->enable_state == bp_startup_disabled)
11470 if (b->addr_string == NULL)
11472 /* Anything without a string can't be re-set. */
11473 delete_breakpoint (b);
11477 re_set_breakpoint (b);
11480 case bp_watchpoint:
11481 case bp_hardware_watchpoint:
11482 case bp_read_watchpoint:
11483 case bp_access_watchpoint:
11484 /* Watchpoint can be either on expression using entirely global
11485 variables, or it can be on local variables.
11487 Watchpoints of the first kind are never auto-deleted, and
11488 even persist across program restarts. Since they can use
11489 variables from shared libraries, we need to reparse
11490 expression as libraries are loaded and unloaded.
11492 Watchpoints on local variables can also change meaning as
11493 result of solib event. For example, if a watchpoint uses
11494 both a local and a global variables in expression, it's a
11495 local watchpoint, but unloading of a shared library will make
11496 the expression invalid. This is not a very common use case,
11497 but we still re-evaluate expression, to avoid surprises to
11500 Note that for local watchpoints, we re-evaluate it only if
11501 watchpoints frame id is still valid. If it's not, it means
11502 the watchpoint is out of scope and will be deleted soon. In
11503 fact, I'm not sure we'll ever be called in this case.
11505 If a local watchpoint's frame id is still valid, then
11506 b->exp_valid_block is likewise valid, and we can safely use it.
11508 Don't do anything about disabled watchpoints, since they will
11509 be reevaluated again when enabled. */
11510 update_watchpoint (b, 1 /* reparse */);
11512 /* We needn't really do anything to reset these, since the mask
11513 that requests them is unaffected by e.g., new libraries being
11515 case bp_catchpoint:
11519 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type);
11521 /* Delete overlay event and longjmp master breakpoints; they will be
11522 reset later by breakpoint_re_set. */
11523 case bp_overlay_event:
11524 case bp_longjmp_master:
11525 case bp_std_terminate_master:
11526 case bp_exception_master:
11527 delete_breakpoint (b);
11530 /* This breakpoint is special, it's set up when the inferior
11531 starts and we really don't want to touch it. */
11532 case bp_shlib_event:
11534 /* Like bp_shlib_event, this breakpoint type is special.
11535 Once it is set up, we do not want to touch it. */
11536 case bp_thread_event:
11538 /* Keep temporary breakpoints, which can be encountered when we
11539 step over a dlopen call and SOLIB_ADD is resetting the
11540 breakpoints. Otherwise these should have been blown away via
11541 the cleanup chain or by breakpoint_init_inferior when we
11542 rerun the executable. */
11545 case bp_watchpoint_scope:
11546 case bp_call_dummy:
11547 case bp_std_terminate:
11548 case bp_step_resume:
11549 case bp_hp_step_resume:
11551 case bp_longjmp_resume:
11553 case bp_exception_resume:
11555 case bp_gnu_ifunc_resolver_return:
11562 /* Re-set all breakpoints after symbols have been re-loaded. */
11564 breakpoint_re_set (void)
11566 struct breakpoint *b, *b_tmp;
11567 enum language save_language;
11568 int save_input_radix;
11569 struct cleanup *old_chain;
11571 save_language = current_language->la_language;
11572 save_input_radix = input_radix;
11573 old_chain = save_current_program_space ();
11575 ALL_BREAKPOINTS_SAFE (b, b_tmp)
11577 /* Format possible error msg. */
11578 char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
11580 struct cleanup *cleanups = make_cleanup (xfree, message);
11581 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
11582 do_cleanups (cleanups);
11584 set_language (save_language);
11585 input_radix = save_input_radix;
11587 jit_breakpoint_re_set ();
11589 do_cleanups (old_chain);
11591 create_overlay_event_breakpoint ();
11592 create_longjmp_master_breakpoint ();
11593 create_std_terminate_master_breakpoint ();
11594 create_exception_master_breakpoint ();
11597 /* Reset the thread number of this breakpoint:
11599 - If the breakpoint is for all threads, leave it as-is.
11600 - Else, reset it to the current thread for inferior_ptid. */
11602 breakpoint_re_set_thread (struct breakpoint *b)
11604 if (b->thread != -1)
11606 if (in_thread_list (inferior_ptid))
11607 b->thread = pid_to_thread_id (inferior_ptid);
11609 /* We're being called after following a fork. The new fork is
11610 selected as current, and unless this was a vfork will have a
11611 different program space from the original thread. Reset that
11613 b->loc->pspace = current_program_space;
11617 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
11618 If from_tty is nonzero, it prints a message to that effect,
11619 which ends with a period (no newline). */
11622 set_ignore_count (int bptnum, int count, int from_tty)
11624 struct breakpoint *b;
11629 ALL_BREAKPOINTS (b)
11630 if (b->number == bptnum)
11632 if (is_tracepoint (b))
11634 if (from_tty && count != 0)
11635 printf_filtered (_("Ignore count ignored for tracepoint %d."),
11640 b->ignore_count = count;
11644 printf_filtered (_("Will stop next time "
11645 "breakpoint %d is reached."),
11647 else if (count == 1)
11648 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
11651 printf_filtered (_("Will ignore next %d "
11652 "crossings of breakpoint %d."),
11655 breakpoints_changed ();
11656 observer_notify_breakpoint_modified (b);
11660 error (_("No breakpoint number %d."), bptnum);
11663 /* Command to set ignore-count of breakpoint N to COUNT. */
11666 ignore_command (char *args, int from_tty)
11672 error_no_arg (_("a breakpoint number"));
11674 num = get_number (&p);
11676 error (_("bad breakpoint number: '%s'"), args);
11678 error (_("Second argument (specified ignore-count) is missing."));
11680 set_ignore_count (num,
11681 longest_to_int (value_as_long (parse_and_eval (p))),
11684 printf_filtered ("\n");
11687 /* Call FUNCTION on each of the breakpoints
11688 whose numbers are given in ARGS. */
11691 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *,
11696 struct breakpoint *b, *tmp;
11698 struct get_number_or_range_state state;
11701 error_no_arg (_("one or more breakpoint numbers"));
11703 init_number_or_range (&state, args);
11705 while (!state.finished)
11707 char *p = state.string;
11711 num = get_number_or_range (&state);
11714 warning (_("bad breakpoint number at or near '%s'"), p);
11718 ALL_BREAKPOINTS_SAFE (b, tmp)
11719 if (b->number == num)
11722 function (b, data);
11726 printf_unfiltered (_("No breakpoint number %d.\n"), num);
11731 static struct bp_location *
11732 find_location_by_number (char *number)
11734 char *dot = strchr (number, '.');
11738 struct breakpoint *b;
11739 struct bp_location *loc;
11744 bp_num = get_number (&p1);
11746 error (_("Bad breakpoint number '%s'"), number);
11748 ALL_BREAKPOINTS (b)
11749 if (b->number == bp_num)
11754 if (!b || b->number != bp_num)
11755 error (_("Bad breakpoint number '%s'"), number);
11758 loc_num = get_number (&p1);
11760 error (_("Bad breakpoint location number '%s'"), number);
11764 for (;loc_num && loc; --loc_num, loc = loc->next)
11767 error (_("Bad breakpoint location number '%s'"), dot+1);
11773 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
11774 If from_tty is nonzero, it prints a message to that effect,
11775 which ends with a period (no newline). */
11778 disable_breakpoint (struct breakpoint *bpt)
11780 /* Never disable a watchpoint scope breakpoint; we want to
11781 hit them when we leave scope so we can delete both the
11782 watchpoint and its scope breakpoint at that time. */
11783 if (bpt->type == bp_watchpoint_scope)
11786 /* You can't disable permanent breakpoints. */
11787 if (bpt->enable_state == bp_permanent)
11790 bpt->enable_state = bp_disabled;
11792 if (target_supports_enable_disable_tracepoint ()
11793 && current_trace_status ()->running && is_tracepoint (bpt))
11795 struct bp_location *location;
11797 for (location = bpt->loc; location; location = location->next)
11798 target_disable_tracepoint (location);
11801 update_global_location_list (0);
11803 observer_notify_breakpoint_modified (bpt);
11806 /* A callback for iterate_over_related_breakpoints. */
11809 do_disable_breakpoint (struct breakpoint *b, void *ignore)
11811 disable_breakpoint (b);
11814 /* A callback for map_breakpoint_numbers that calls
11815 disable_breakpoint. */
11818 do_map_disable_breakpoint (struct breakpoint *b, void *ignore)
11820 iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL);
11824 disable_command (char *args, int from_tty)
11828 struct breakpoint *bpt;
11830 ALL_BREAKPOINTS (bpt)
11831 if (user_breakpoint_p (bpt))
11832 disable_breakpoint (bpt);
11834 else if (strchr (args, '.'))
11836 struct bp_location *loc = find_location_by_number (args);
11840 if (target_supports_enable_disable_tracepoint ()
11841 && current_trace_status ()->running && loc->owner
11842 && is_tracepoint (loc->owner))
11843 target_disable_tracepoint (loc);
11845 update_global_location_list (0);
11848 map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL);
11852 enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition)
11854 int target_resources_ok;
11856 if (bpt->type == bp_hardware_breakpoint)
11859 i = hw_breakpoint_used_count ();
11860 target_resources_ok =
11861 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
11863 if (target_resources_ok == 0)
11864 error (_("No hardware breakpoint support in the target."));
11865 else if (target_resources_ok < 0)
11866 error (_("Hardware breakpoints used exceeds limit."));
11869 if (is_watchpoint (bpt))
11871 /* Initialize it just to avoid a GCC false warning. */
11872 enum enable_state orig_enable_state = 0;
11873 struct gdb_exception e;
11875 TRY_CATCH (e, RETURN_MASK_ALL)
11877 orig_enable_state = bpt->enable_state;
11878 bpt->enable_state = bp_enabled;
11879 update_watchpoint (bpt, 1 /* reparse */);
11883 bpt->enable_state = orig_enable_state;
11884 exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
11890 if (bpt->enable_state != bp_permanent)
11891 bpt->enable_state = bp_enabled;
11893 if (target_supports_enable_disable_tracepoint ()
11894 && current_trace_status ()->running && is_tracepoint (bpt))
11896 struct bp_location *location;
11898 for (location = bpt->loc; location; location = location->next)
11899 target_enable_tracepoint (location);
11902 bpt->disposition = disposition;
11903 update_global_location_list (1);
11904 breakpoints_changed ();
11906 observer_notify_breakpoint_modified (bpt);
11911 enable_breakpoint (struct breakpoint *bpt)
11913 enable_breakpoint_disp (bpt, bpt->disposition);
11917 do_enable_breakpoint (struct breakpoint *bpt, void *arg)
11919 enable_breakpoint (bpt);
11922 /* A callback for map_breakpoint_numbers that calls
11923 enable_breakpoint. */
11926 do_map_enable_breakpoint (struct breakpoint *b, void *ignore)
11928 iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL);
11931 /* The enable command enables the specified breakpoints (or all defined
11932 breakpoints) so they once again become (or continue to be) effective
11933 in stopping the inferior. */
11936 enable_command (char *args, int from_tty)
11940 struct breakpoint *bpt;
11942 ALL_BREAKPOINTS (bpt)
11943 if (user_breakpoint_p (bpt))
11944 enable_breakpoint (bpt);
11946 else if (strchr (args, '.'))
11948 struct bp_location *loc = find_location_by_number (args);
11952 if (target_supports_enable_disable_tracepoint ()
11953 && current_trace_status ()->running && loc->owner
11954 && is_tracepoint (loc->owner))
11955 target_enable_tracepoint (loc);
11957 update_global_location_list (1);
11960 map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL);
11964 do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg)
11966 enum bpdisp disp = *(enum bpdisp *) arg;
11968 enable_breakpoint_disp (bpt, disp);
11972 do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore)
11974 enum bpdisp disp = disp_disable;
11976 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
11980 enable_once_command (char *args, int from_tty)
11982 map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL);
11986 do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore)
11988 enum bpdisp disp = disp_del;
11990 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
11994 enable_delete_command (char *args, int from_tty)
11996 map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL);
12000 set_breakpoint_cmd (char *args, int from_tty)
12005 show_breakpoint_cmd (char *args, int from_tty)
12009 /* Invalidate last known value of any hardware watchpoint if
12010 the memory which that value represents has been written to by
12014 invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len,
12015 const bfd_byte *data)
12017 struct breakpoint *bp;
12019 ALL_BREAKPOINTS (bp)
12020 if (bp->enable_state == bp_enabled
12021 && bp->type == bp_hardware_watchpoint
12022 && bp->val_valid && bp->val)
12024 struct bp_location *loc;
12026 for (loc = bp->loc; loc != NULL; loc = loc->next)
12027 if (loc->loc_type == bp_loc_hardware_watchpoint
12028 && loc->address + loc->length > addr
12029 && addr + len > loc->address)
12031 value_free (bp->val);
12038 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
12040 struct symtabs_and_lines
12041 decode_line_spec_1 (char *string, int funfirstline)
12043 struct symtabs_and_lines sals;
12046 error (_("Empty line specification."));
12047 if (default_breakpoint_valid)
12048 sals = decode_line_1 (&string, funfirstline,
12049 default_breakpoint_symtab,
12050 default_breakpoint_line,
12053 sals = decode_line_1 (&string, funfirstline,
12054 (struct symtab *) NULL, 0, NULL);
12056 error (_("Junk at end of line specification: %s"), string);
12060 /* Create and insert a raw software breakpoint at PC. Return an
12061 identifier, which should be used to remove the breakpoint later.
12062 In general, places which call this should be using something on the
12063 breakpoint chain instead; this function should be eliminated
12067 deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch,
12068 struct address_space *aspace, CORE_ADDR pc)
12070 struct bp_target_info *bp_tgt;
12072 bp_tgt = XZALLOC (struct bp_target_info);
12074 bp_tgt->placed_address_space = aspace;
12075 bp_tgt->placed_address = pc;
12077 if (target_insert_breakpoint (gdbarch, bp_tgt) != 0)
12079 /* Could not insert the breakpoint. */
12087 /* Remove a breakpoint BP inserted by
12088 deprecated_insert_raw_breakpoint. */
12091 deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp)
12093 struct bp_target_info *bp_tgt = bp;
12096 ret = target_remove_breakpoint (gdbarch, bp_tgt);
12102 /* One (or perhaps two) breakpoints used for software single
12105 static void *single_step_breakpoints[2];
12106 static struct gdbarch *single_step_gdbarch[2];
12108 /* Create and insert a breakpoint for software single step. */
12111 insert_single_step_breakpoint (struct gdbarch *gdbarch,
12112 struct address_space *aspace,
12117 if (single_step_breakpoints[0] == NULL)
12119 bpt_p = &single_step_breakpoints[0];
12120 single_step_gdbarch[0] = gdbarch;
12124 gdb_assert (single_step_breakpoints[1] == NULL);
12125 bpt_p = &single_step_breakpoints[1];
12126 single_step_gdbarch[1] = gdbarch;
12129 /* NOTE drow/2006-04-11: A future improvement to this function would
12130 be to only create the breakpoints once, and actually put them on
12131 the breakpoint chain. That would let us use set_raw_breakpoint.
12132 We could adjust the addresses each time they were needed. Doing
12133 this requires corresponding changes elsewhere where single step
12134 breakpoints are handled, however. So, for now, we use this. */
12136 *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc);
12137 if (*bpt_p == NULL)
12138 error (_("Could not insert single-step breakpoint at %s"),
12139 paddress (gdbarch, next_pc));
12142 /* Check if the breakpoints used for software single stepping
12143 were inserted or not. */
12146 single_step_breakpoints_inserted (void)
12148 return (single_step_breakpoints[0] != NULL
12149 || single_step_breakpoints[1] != NULL);
12152 /* Remove and delete any breakpoints used for software single step. */
12155 remove_single_step_breakpoints (void)
12157 gdb_assert (single_step_breakpoints[0] != NULL);
12159 /* See insert_single_step_breakpoint for more about this deprecated
12161 deprecated_remove_raw_breakpoint (single_step_gdbarch[0],
12162 single_step_breakpoints[0]);
12163 single_step_gdbarch[0] = NULL;
12164 single_step_breakpoints[0] = NULL;
12166 if (single_step_breakpoints[1] != NULL)
12168 deprecated_remove_raw_breakpoint (single_step_gdbarch[1],
12169 single_step_breakpoints[1]);
12170 single_step_gdbarch[1] = NULL;
12171 single_step_breakpoints[1] = NULL;
12175 /* Delete software single step breakpoints without removing them from
12176 the inferior. This is intended to be used if the inferior's address
12177 space where they were inserted is already gone, e.g. after exit or
12181 cancel_single_step_breakpoints (void)
12185 for (i = 0; i < 2; i++)
12186 if (single_step_breakpoints[i])
12188 xfree (single_step_breakpoints[i]);
12189 single_step_breakpoints[i] = NULL;
12190 single_step_gdbarch[i] = NULL;
12194 /* Detach software single-step breakpoints from INFERIOR_PTID without
12198 detach_single_step_breakpoints (void)
12202 for (i = 0; i < 2; i++)
12203 if (single_step_breakpoints[i])
12204 target_remove_breakpoint (single_step_gdbarch[i],
12205 single_step_breakpoints[i]);
12208 /* Check whether a software single-step breakpoint is inserted at
12212 single_step_breakpoint_inserted_here_p (struct address_space *aspace,
12217 for (i = 0; i < 2; i++)
12219 struct bp_target_info *bp_tgt = single_step_breakpoints[i];
12221 && breakpoint_address_match (bp_tgt->placed_address_space,
12222 bp_tgt->placed_address,
12230 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
12231 non-zero otherwise. */
12233 is_syscall_catchpoint_enabled (struct breakpoint *bp)
12235 if (syscall_catchpoint_p (bp)
12236 && bp->enable_state != bp_disabled
12237 && bp->enable_state != bp_call_disabled)
12244 catch_syscall_enabled (void)
12246 struct inferior *inf = current_inferior ();
12248 return inf->total_syscalls_count != 0;
12252 catching_syscall_number (int syscall_number)
12254 struct breakpoint *bp;
12256 ALL_BREAKPOINTS (bp)
12257 if (is_syscall_catchpoint_enabled (bp))
12259 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp;
12261 if (c->syscalls_to_be_caught)
12265 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
12267 if (syscall_number == iter)
12277 /* Complete syscall names. Used by "catch syscall". */
12279 catch_syscall_completer (struct cmd_list_element *cmd,
12280 char *text, char *word)
12282 const char **list = get_syscall_names ();
12284 = (list == NULL) ? NULL : complete_on_enum (list, text, word);
12290 /* Tracepoint-specific operations. */
12292 /* Set tracepoint count to NUM. */
12294 set_tracepoint_count (int num)
12296 tracepoint_count = num;
12297 set_internalvar_integer (lookup_internalvar ("tpnum"), num);
12301 trace_command (char *arg, int from_tty)
12303 if (create_breakpoint (get_current_arch (),
12305 NULL, 0, 1 /* parse arg */,
12307 bp_tracepoint /* type_wanted */,
12308 0 /* Ignore count */,
12309 pending_break_support,
12314 set_tracepoint_count (breakpoint_count);
12318 ftrace_command (char *arg, int from_tty)
12320 if (create_breakpoint (get_current_arch (),
12322 NULL, 0, 1 /* parse arg */,
12324 bp_fast_tracepoint /* type_wanted */,
12325 0 /* Ignore count */,
12326 pending_break_support,
12331 set_tracepoint_count (breakpoint_count);
12334 /* strace command implementation. Creates a static tracepoint. */
12337 strace_command (char *arg, int from_tty)
12339 if (create_breakpoint (get_current_arch (),
12341 NULL, 0, 1 /* parse arg */,
12343 bp_static_tracepoint /* type_wanted */,
12344 0 /* Ignore count */,
12345 pending_break_support,
12350 set_tracepoint_count (breakpoint_count);
12353 /* Set up a fake reader function that gets command lines from a linked
12354 list that was acquired during tracepoint uploading. */
12356 static struct uploaded_tp *this_utp;
12357 static int next_cmd;
12360 read_uploaded_action (void)
12364 VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt);
12371 /* Given information about a tracepoint as recorded on a target (which
12372 can be either a live system or a trace file), attempt to create an
12373 equivalent GDB tracepoint. This is not a reliable process, since
12374 the target does not necessarily have all the information used when
12375 the tracepoint was originally defined. */
12377 struct breakpoint *
12378 create_tracepoint_from_upload (struct uploaded_tp *utp)
12380 char *addr_str, small_buf[100];
12381 struct breakpoint *tp;
12383 if (utp->at_string)
12384 addr_str = utp->at_string;
12387 /* In the absence of a source location, fall back to raw
12388 address. Since there is no way to confirm that the address
12389 means the same thing as when the trace was started, warn the
12391 warning (_("Uploaded tracepoint %d has no "
12392 "source location, using raw address"),
12394 sprintf (small_buf, "*%s", hex_string (utp->addr));
12395 addr_str = small_buf;
12398 /* There's not much we can do with a sequence of bytecodes. */
12399 if (utp->cond && !utp->cond_string)
12400 warning (_("Uploaded tracepoint %d condition "
12401 "has no source form, ignoring it"),
12404 if (!create_breakpoint (get_current_arch (),
12406 utp->cond_string, -1, 0 /* parse cond/thread */,
12408 utp->type /* type_wanted */,
12409 0 /* Ignore count */,
12410 pending_break_support,
12413 utp->enabled /* enabled */,
12417 set_tracepoint_count (breakpoint_count);
12419 /* Get the tracepoint we just created. */
12420 tp = get_tracepoint (tracepoint_count);
12421 gdb_assert (tp != NULL);
12425 sprintf (small_buf, "%d %d", utp->pass, tp->number);
12427 trace_pass_command (small_buf, 0);
12430 /* If we have uploaded versions of the original commands, set up a
12431 special-purpose "reader" function and call the usual command line
12432 reader, then pass the result to the breakpoint command-setting
12434 if (!VEC_empty (char_ptr, utp->cmd_strings))
12436 struct command_line *cmd_list;
12441 cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL);
12443 breakpoint_set_commands (tp, cmd_list);
12445 else if (!VEC_empty (char_ptr, utp->actions)
12446 || !VEC_empty (char_ptr, utp->step_actions))
12447 warning (_("Uploaded tracepoint %d actions "
12448 "have no source form, ignoring them"),
12454 /* Print information on tracepoint number TPNUM_EXP, or all if
12458 tracepoints_info (char *args, int from_tty)
12462 num_printed = breakpoint_1 (args, 0, is_tracepoint);
12464 if (num_printed == 0)
12466 if (args == NULL || *args == '\0')
12467 ui_out_message (uiout, 0, "No tracepoints.\n");
12469 ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args);
12472 default_collect_info ();
12475 /* The 'enable trace' command enables tracepoints.
12476 Not supported by all targets. */
12478 enable_trace_command (char *args, int from_tty)
12480 enable_command (args, from_tty);
12483 /* The 'disable trace' command disables tracepoints.
12484 Not supported by all targets. */
12486 disable_trace_command (char *args, int from_tty)
12488 disable_command (args, from_tty);
12491 /* Remove a tracepoint (or all if no argument). */
12493 delete_trace_command (char *arg, int from_tty)
12495 struct breakpoint *b, *b_tmp;
12501 int breaks_to_delete = 0;
12503 /* Delete all breakpoints if no argument.
12504 Do not delete internal or call-dummy breakpoints, these
12505 have to be deleted with an explicit breakpoint number
12507 ALL_TRACEPOINTS (b)
12508 if (is_tracepoint (b) && user_breakpoint_p (b))
12510 breaks_to_delete = 1;
12514 /* Ask user only if there are some breakpoints to delete. */
12516 || (breaks_to_delete && query (_("Delete all tracepoints? "))))
12518 ALL_BREAKPOINTS_SAFE (b, b_tmp)
12519 if (is_tracepoint (b) && user_breakpoint_p (b))
12520 delete_breakpoint (b);
12524 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
12527 /* Helper function for trace_pass_command. */
12530 trace_pass_set_count (struct breakpoint *bp, int count, int from_tty)
12532 bp->pass_count = count;
12533 observer_notify_tracepoint_modified (bp->number);
12535 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
12536 bp->number, count);
12539 /* Set passcount for tracepoint.
12541 First command argument is passcount, second is tracepoint number.
12542 If tracepoint number omitted, apply to most recently defined.
12543 Also accepts special argument "all". */
12546 trace_pass_command (char *args, int from_tty)
12548 struct breakpoint *t1;
12549 unsigned int count;
12551 if (args == 0 || *args == 0)
12552 error (_("passcount command requires an "
12553 "argument (count + optional TP num)"));
12555 count = strtoul (args, &args, 10); /* Count comes first, then TP num. */
12557 while (*args && isspace ((int) *args))
12560 if (*args && strncasecmp (args, "all", 3) == 0)
12562 args += 3; /* Skip special argument "all". */
12564 error (_("Junk at end of arguments."));
12566 ALL_TRACEPOINTS (t1)
12568 trace_pass_set_count (t1, count, from_tty);
12571 else if (*args == '\0')
12573 t1 = get_tracepoint_by_number (&args, NULL, 1);
12575 trace_pass_set_count (t1, count, from_tty);
12579 struct get_number_or_range_state state;
12581 init_number_or_range (&state, args);
12582 while (!state.finished)
12584 t1 = get_tracepoint_by_number (&args, &state, 1);
12586 trace_pass_set_count (t1, count, from_tty);
12591 struct breakpoint *
12592 get_tracepoint (int num)
12594 struct breakpoint *t;
12596 ALL_TRACEPOINTS (t)
12597 if (t->number == num)
12603 /* Find the tracepoint with the given target-side number (which may be
12604 different from the tracepoint number after disconnecting and
12607 struct breakpoint *
12608 get_tracepoint_by_number_on_target (int num)
12610 struct breakpoint *t;
12612 ALL_TRACEPOINTS (t)
12613 if (t->number_on_target == num)
12619 /* Utility: parse a tracepoint number and look it up in the list.
12620 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
12621 If OPTIONAL_P is true, then if the argument is missing, the most
12622 recent tracepoint (tracepoint_count) is returned. */
12623 struct breakpoint *
12624 get_tracepoint_by_number (char **arg,
12625 struct get_number_or_range_state *state,
12628 extern int tracepoint_count;
12629 struct breakpoint *t;
12631 char *instring = arg == NULL ? NULL : *arg;
12635 gdb_assert (!state->finished);
12636 tpnum = get_number_or_range (state);
12638 else if (arg == NULL || *arg == NULL || ! **arg)
12641 tpnum = tracepoint_count;
12643 error_no_arg (_("tracepoint number"));
12646 tpnum = get_number (arg);
12650 if (instring && *instring)
12651 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
12654 printf_filtered (_("Tracepoint argument missing "
12655 "and no previous tracepoint\n"));
12659 ALL_TRACEPOINTS (t)
12660 if (t->number == tpnum)
12665 printf_unfiltered ("No tracepoint number %d.\n", tpnum);
12669 /* Save information on user settable breakpoints (watchpoints, etc) to
12670 a new script file named FILENAME. If FILTER is non-NULL, call it
12671 on each breakpoint and only include the ones for which it returns
12675 save_breakpoints (char *filename, int from_tty,
12676 int (*filter) (const struct breakpoint *))
12678 struct breakpoint *tp;
12681 struct cleanup *cleanup;
12682 struct ui_file *fp;
12683 int extra_trace_bits = 0;
12685 if (filename == 0 || *filename == 0)
12686 error (_("Argument required (file name in which to save)"));
12688 /* See if we have anything to save. */
12689 ALL_BREAKPOINTS (tp)
12691 /* Skip internal and momentary breakpoints. */
12692 if (!user_breakpoint_p (tp))
12695 /* If we have a filter, only save the breakpoints it accepts. */
12696 if (filter && !filter (tp))
12701 if (is_tracepoint (tp))
12703 extra_trace_bits = 1;
12705 /* We can stop searching. */
12712 warning (_("Nothing to save."));
12716 pathname = tilde_expand (filename);
12717 cleanup = make_cleanup (xfree, pathname);
12718 fp = gdb_fopen (pathname, "w");
12720 error (_("Unable to open file '%s' for saving (%s)"),
12721 filename, safe_strerror (errno));
12722 make_cleanup_ui_file_delete (fp);
12724 if (extra_trace_bits)
12725 save_trace_state_variables (fp);
12727 ALL_BREAKPOINTS (tp)
12729 /* Skip internal and momentary breakpoints. */
12730 if (!user_breakpoint_p (tp))
12733 /* If we have a filter, only save the breakpoints it accepts. */
12734 if (filter && !filter (tp))
12737 if (tp->ops != NULL && tp->ops->print_recreate != NULL)
12738 (tp->ops->print_recreate) (tp, fp);
12741 if (tp->type == bp_fast_tracepoint)
12742 fprintf_unfiltered (fp, "ftrace");
12743 if (tp->type == bp_static_tracepoint)
12744 fprintf_unfiltered (fp, "strace");
12745 else if (tp->type == bp_tracepoint)
12746 fprintf_unfiltered (fp, "trace");
12747 else if (tp->type == bp_breakpoint && tp->disposition == disp_del)
12748 fprintf_unfiltered (fp, "tbreak");
12749 else if (tp->type == bp_breakpoint)
12750 fprintf_unfiltered (fp, "break");
12751 else if (tp->type == bp_hardware_breakpoint
12752 && tp->disposition == disp_del)
12753 fprintf_unfiltered (fp, "thbreak");
12754 else if (tp->type == bp_hardware_breakpoint)
12755 fprintf_unfiltered (fp, "hbreak");
12756 else if (tp->type == bp_watchpoint)
12757 fprintf_unfiltered (fp, "watch");
12758 else if (tp->type == bp_hardware_watchpoint)
12759 fprintf_unfiltered (fp, "watch");
12760 else if (tp->type == bp_read_watchpoint)
12761 fprintf_unfiltered (fp, "rwatch");
12762 else if (tp->type == bp_access_watchpoint)
12763 fprintf_unfiltered (fp, "awatch");
12765 internal_error (__FILE__, __LINE__,
12766 _("unhandled breakpoint type %d"), (int) tp->type);
12768 if (tp->exp_string)
12769 fprintf_unfiltered (fp, " %s", tp->exp_string);
12770 else if (tp->addr_string)
12771 fprintf_unfiltered (fp, " %s", tp->addr_string);
12776 sprintf_vma (tmp, tp->loc->address);
12777 fprintf_unfiltered (fp, " *0x%s", tmp);
12781 if (tp->thread != -1)
12782 fprintf_unfiltered (fp, " thread %d", tp->thread);
12785 fprintf_unfiltered (fp, " task %d", tp->task);
12787 fprintf_unfiltered (fp, "\n");
12789 /* Note, we can't rely on tp->number for anything, as we can't
12790 assume the recreated breakpoint numbers will match. Use $bpnum
12793 if (tp->cond_string)
12794 fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string);
12796 if (tp->ignore_count)
12797 fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count);
12799 if (tp->pass_count)
12800 fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count);
12804 volatile struct gdb_exception ex;
12806 fprintf_unfiltered (fp, " commands\n");
12808 ui_out_redirect (uiout, fp);
12809 TRY_CATCH (ex, RETURN_MASK_ALL)
12811 print_command_lines (uiout, tp->commands->commands, 2);
12813 ui_out_redirect (uiout, NULL);
12816 throw_exception (ex);
12818 fprintf_unfiltered (fp, " end\n");
12821 if (tp->enable_state == bp_disabled)
12822 fprintf_unfiltered (fp, "disable\n");
12824 /* If this is a multi-location breakpoint, check if the locations
12825 should be individually disabled. Watchpoint locations are
12826 special, and not user visible. */
12827 if (!is_watchpoint (tp) && tp->loc && tp->loc->next)
12829 struct bp_location *loc;
12832 for (loc = tp->loc; loc != NULL; loc = loc->next, n++)
12834 fprintf_unfiltered (fp, "disable $bpnum.%d\n", n);
12838 if (extra_trace_bits && *default_collect)
12839 fprintf_unfiltered (fp, "set default-collect %s\n", default_collect);
12841 do_cleanups (cleanup);
12843 printf_filtered (_("Saved to file '%s'.\n"), filename);
12846 /* The `save breakpoints' command. */
12849 save_breakpoints_command (char *args, int from_tty)
12851 save_breakpoints (args, from_tty, NULL);
12854 /* The `save tracepoints' command. */
12857 save_tracepoints_command (char *args, int from_tty)
12859 save_breakpoints (args, from_tty, is_tracepoint);
12862 /* Create a vector of all tracepoints. */
12864 VEC(breakpoint_p) *
12865 all_tracepoints (void)
12867 VEC(breakpoint_p) *tp_vec = 0;
12868 struct breakpoint *tp;
12870 ALL_TRACEPOINTS (tp)
12872 VEC_safe_push (breakpoint_p, tp_vec, tp);
12879 /* This help string is used for the break, hbreak, tbreak and thbreak
12880 commands. It is defined as a macro to prevent duplication.
12881 COMMAND should be a string constant containing the name of the
12883 #define BREAK_ARGS_HELP(command) \
12884 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
12885 LOCATION may be a line number, function name, or \"*\" and an address.\n\
12886 If a line number is specified, break at start of code for that line.\n\
12887 If a function is specified, break at start of code for that function.\n\
12888 If an address is specified, break at that exact address.\n\
12889 With no LOCATION, uses current execution address of the selected\n\
12890 stack frame. This is useful for breaking on return to a stack frame.\n\
12892 THREADNUM is the number from \"info threads\".\n\
12893 CONDITION is a boolean expression.\n\
12895 Multiple breakpoints at one place are permitted, and useful if their\n\
12896 conditions are different.\n\
12898 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
12900 /* List of subcommands for "catch". */
12901 static struct cmd_list_element *catch_cmdlist;
12903 /* List of subcommands for "tcatch". */
12904 static struct cmd_list_element *tcatch_cmdlist;
12907 add_catch_command (char *name, char *docstring,
12908 void (*sfunc) (char *args, int from_tty,
12909 struct cmd_list_element *command),
12910 char **(*completer) (struct cmd_list_element *cmd,
12911 char *text, char *word),
12912 void *user_data_catch,
12913 void *user_data_tcatch)
12915 struct cmd_list_element *command;
12917 command = add_cmd (name, class_breakpoint, NULL, docstring,
12919 set_cmd_sfunc (command, sfunc);
12920 set_cmd_context (command, user_data_catch);
12921 set_cmd_completer (command, completer);
12923 command = add_cmd (name, class_breakpoint, NULL, docstring,
12925 set_cmd_sfunc (command, sfunc);
12926 set_cmd_context (command, user_data_tcatch);
12927 set_cmd_completer (command, completer);
12931 clear_syscall_counts (struct inferior *inf)
12933 inf->total_syscalls_count = 0;
12934 inf->any_syscall_count = 0;
12935 VEC_free (int, inf->syscalls_counts);
12939 save_command (char *arg, int from_tty)
12941 printf_unfiltered (_("\"save\" must be followed by "
12942 "the name of a save subcommand.\n"));
12943 help_list (save_cmdlist, "save ", -1, gdb_stdout);
12946 struct breakpoint *
12947 iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *),
12950 struct breakpoint *b, *b_tmp;
12952 ALL_BREAKPOINTS_SAFE (b, b_tmp)
12954 if ((*callback) (b, data))
12962 _initialize_breakpoint (void)
12964 struct cmd_list_element *c;
12966 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
12967 observer_attach_inferior_exit (clear_syscall_counts);
12968 observer_attach_memory_changed (invalidate_bp_value_on_memory_change);
12970 breakpoint_objfile_key = register_objfile_data ();
12972 breakpoint_chain = 0;
12973 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
12974 before a breakpoint is set. */
12975 breakpoint_count = 0;
12977 tracepoint_count = 0;
12979 add_com ("ignore", class_breakpoint, ignore_command, _("\
12980 Set ignore-count of breakpoint number N to COUNT.\n\
12981 Usage is `ignore N COUNT'."));
12983 add_com_alias ("bc", "ignore", class_breakpoint, 1);
12985 add_com ("commands", class_breakpoint, commands_command, _("\
12986 Set commands to be executed when a breakpoint is hit.\n\
12987 Give breakpoint number as argument after \"commands\".\n\
12988 With no argument, the targeted breakpoint is the last one set.\n\
12989 The commands themselves follow starting on the next line.\n\
12990 Type a line containing \"end\" to indicate the end of them.\n\
12991 Give \"silent\" as the first line to make the breakpoint silent;\n\
12992 then no output is printed when it is hit, except what the commands print."));
12994 add_com ("condition", class_breakpoint, condition_command, _("\
12995 Specify breakpoint number N to break only if COND is true.\n\
12996 Usage is `condition N COND', where N is an integer and COND is an\n\
12997 expression to be evaluated whenever breakpoint N is reached."));
12999 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
13000 Set a temporary breakpoint.\n\
13001 Like \"break\" except the breakpoint is only temporary,\n\
13002 so it will be deleted when hit. Equivalent to \"break\" followed\n\
13003 by using \"enable delete\" on the breakpoint number.\n\
13005 BREAK_ARGS_HELP ("tbreak")));
13006 set_cmd_completer (c, location_completer);
13008 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
13009 Set a hardware assisted breakpoint.\n\
13010 Like \"break\" except the breakpoint requires hardware support,\n\
13011 some target hardware may not have this support.\n\
13013 BREAK_ARGS_HELP ("hbreak")));
13014 set_cmd_completer (c, location_completer);
13016 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
13017 Set a temporary hardware assisted breakpoint.\n\
13018 Like \"hbreak\" except the breakpoint is only temporary,\n\
13019 so it will be deleted when hit.\n\
13021 BREAK_ARGS_HELP ("thbreak")));
13022 set_cmd_completer (c, location_completer);
13024 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
13025 Enable some breakpoints.\n\
13026 Give breakpoint numbers (separated by spaces) as arguments.\n\
13027 With no subcommand, breakpoints are enabled until you command otherwise.\n\
13028 This is used to cancel the effect of the \"disable\" command.\n\
13029 With a subcommand you can enable temporarily."),
13030 &enablelist, "enable ", 1, &cmdlist);
13032 add_com ("ab", class_breakpoint, enable_command, _("\
13033 Enable some breakpoints.\n\
13034 Give breakpoint numbers (separated by spaces) as arguments.\n\
13035 With no subcommand, breakpoints are enabled until you command otherwise.\n\
13036 This is used to cancel the effect of the \"disable\" command.\n\
13037 With a subcommand you can enable temporarily."));
13039 add_com_alias ("en", "enable", class_breakpoint, 1);
13041 add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
13042 Enable some breakpoints.\n\
13043 Give breakpoint numbers (separated by spaces) as arguments.\n\
13044 This is used to cancel the effect of the \"disable\" command.\n\
13045 May be abbreviated to simply \"enable\".\n"),
13046 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
13048 add_cmd ("once", no_class, enable_once_command, _("\
13049 Enable breakpoints for one hit. Give breakpoint numbers.\n\
13050 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
13053 add_cmd ("delete", no_class, enable_delete_command, _("\
13054 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
13055 If a breakpoint is hit while enabled in this fashion, it is deleted."),
13058 add_cmd ("delete", no_class, enable_delete_command, _("\
13059 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
13060 If a breakpoint is hit while enabled in this fashion, it is deleted."),
13063 add_cmd ("once", no_class, enable_once_command, _("\
13064 Enable breakpoints for one hit. Give breakpoint numbers.\n\
13065 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
13068 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
13069 Disable some breakpoints.\n\
13070 Arguments are breakpoint numbers with spaces in between.\n\
13071 To disable all breakpoints, give no argument.\n\
13072 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
13073 &disablelist, "disable ", 1, &cmdlist);
13074 add_com_alias ("dis", "disable", class_breakpoint, 1);
13075 add_com_alias ("disa", "disable", class_breakpoint, 1);
13077 add_com ("sb", class_breakpoint, disable_command, _("\
13078 Disable some breakpoints.\n\
13079 Arguments are breakpoint numbers with spaces in between.\n\
13080 To disable all breakpoints, give no argument.\n\
13081 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
13083 add_cmd ("breakpoints", class_alias, disable_command, _("\
13084 Disable some breakpoints.\n\
13085 Arguments are breakpoint numbers with spaces in between.\n\
13086 To disable all breakpoints, give no argument.\n\
13087 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
13088 This command may be abbreviated \"disable\"."),
13091 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
13092 Delete some breakpoints or auto-display expressions.\n\
13093 Arguments are breakpoint numbers with spaces in between.\n\
13094 To delete all breakpoints, give no argument.\n\
13096 Also a prefix command for deletion of other GDB objects.\n\
13097 The \"unset\" command is also an alias for \"delete\"."),
13098 &deletelist, "delete ", 1, &cmdlist);
13099 add_com_alias ("d", "delete", class_breakpoint, 1);
13100 add_com_alias ("del", "delete", class_breakpoint, 1);
13102 add_com ("db", class_breakpoint, delete_command, _("\
13103 Delete some breakpoints.\n\
13104 Arguments are breakpoint numbers with spaces in between.\n\
13105 To delete all breakpoints, give no argument.\n"));
13107 add_cmd ("breakpoints", class_alias, delete_command, _("\
13108 Delete some breakpoints or auto-display expressions.\n\
13109 Arguments are breakpoint numbers with spaces in between.\n\
13110 To delete all breakpoints, give no argument.\n\
13111 This command may be abbreviated \"delete\"."),
13114 add_com ("clear", class_breakpoint, clear_command, _("\
13115 Clear breakpoint at specified line or function.\n\
13116 Argument may be line number, function name, or \"*\" and an address.\n\
13117 If line number is specified, all breakpoints in that line are cleared.\n\
13118 If function is specified, breakpoints at beginning of function are cleared.\n\
13119 If an address is specified, breakpoints at that address are cleared.\n\
13121 With no argument, clears all breakpoints in the line that the selected frame\n\
13122 is executing in.\n\
13124 See also the \"delete\" command which clears breakpoints by number."));
13125 add_com_alias ("cl", "clear", class_breakpoint, 1);
13127 c = add_com ("break", class_breakpoint, break_command, _("\
13128 Set breakpoint at specified line or function.\n"
13129 BREAK_ARGS_HELP ("break")));
13130 set_cmd_completer (c, location_completer);
13132 add_com_alias ("b", "break", class_run, 1);
13133 add_com_alias ("br", "break", class_run, 1);
13134 add_com_alias ("bre", "break", class_run, 1);
13135 add_com_alias ("brea", "break", class_run, 1);
13138 add_com_alias ("ba", "break", class_breakpoint, 1);
13142 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
13143 Break in function/address or break at a line in the current file."),
13144 &stoplist, "stop ", 1, &cmdlist);
13145 add_cmd ("in", class_breakpoint, stopin_command,
13146 _("Break in function or address."), &stoplist);
13147 add_cmd ("at", class_breakpoint, stopat_command,
13148 _("Break at a line in the current file."), &stoplist);
13149 add_com ("status", class_info, breakpoints_info, _("\
13150 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
13151 The \"Type\" column indicates one of:\n\
13152 \tbreakpoint - normal breakpoint\n\
13153 \twatchpoint - watchpoint\n\
13154 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13155 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13156 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13157 address and file/line number respectively.\n\
13159 Convenience variable \"$_\" and default examine address for \"x\"\n\
13160 are set to the address of the last breakpoint listed unless the command\n\
13161 is prefixed with \"server \".\n\n\
13162 Convenience variable \"$bpnum\" contains the number of the last\n\
13163 breakpoint set."));
13166 add_info ("breakpoints", breakpoints_info, _("\
13167 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
13168 The \"Type\" column indicates one of:\n\
13169 \tbreakpoint - normal breakpoint\n\
13170 \twatchpoint - watchpoint\n\
13171 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13172 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13173 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13174 address and file/line number respectively.\n\
13176 Convenience variable \"$_\" and default examine address for \"x\"\n\
13177 are set to the address of the last breakpoint listed unless the command\n\
13178 is prefixed with \"server \".\n\n\
13179 Convenience variable \"$bpnum\" contains the number of the last\n\
13180 breakpoint set."));
13182 add_info_alias ("b", "breakpoints", 1);
13185 add_com ("lb", class_breakpoint, breakpoints_info, _("\
13186 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
13187 The \"Type\" column indicates one of:\n\
13188 \tbreakpoint - normal breakpoint\n\
13189 \twatchpoint - watchpoint\n\
13190 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13191 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13192 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13193 address and file/line number respectively.\n\
13195 Convenience variable \"$_\" and default examine address for \"x\"\n\
13196 are set to the address of the last breakpoint listed unless the command\n\
13197 is prefixed with \"server \".\n\n\
13198 Convenience variable \"$bpnum\" contains the number of the last\n\
13199 breakpoint set."));
13201 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
13202 Status of all breakpoints, or breakpoint number NUMBER.\n\
13203 The \"Type\" column indicates one of:\n\
13204 \tbreakpoint - normal breakpoint\n\
13205 \twatchpoint - watchpoint\n\
13206 \tlongjmp - internal breakpoint used to step through longjmp()\n\
13207 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
13208 \tuntil - internal breakpoint used by the \"until\" command\n\
13209 \tfinish - internal breakpoint used by the \"finish\" command\n\
13210 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13211 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13212 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13213 address and file/line number respectively.\n\
13215 Convenience variable \"$_\" and default examine address for \"x\"\n\
13216 are set to the address of the last breakpoint listed unless the command\n\
13217 is prefixed with \"server \".\n\n\
13218 Convenience variable \"$bpnum\" contains the number of the last\n\
13220 &maintenanceinfolist);
13222 add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\
13223 Set catchpoints to catch events."),
13224 &catch_cmdlist, "catch ",
13225 0/*allow-unknown*/, &cmdlist);
13227 add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\
13228 Set temporary catchpoints to catch events."),
13229 &tcatch_cmdlist, "tcatch ",
13230 0/*allow-unknown*/, &cmdlist);
13232 /* Add catch and tcatch sub-commands. */
13233 add_catch_command ("catch", _("\
13234 Catch an exception, when caught.\n\
13235 With an argument, catch only exceptions with the given name."),
13236 catch_catch_command,
13240 add_catch_command ("throw", _("\
13241 Catch an exception, when thrown.\n\
13242 With an argument, catch only exceptions with the given name."),
13243 catch_throw_command,
13247 add_catch_command ("fork", _("Catch calls to fork."),
13248 catch_fork_command_1,
13250 (void *) (uintptr_t) catch_fork_permanent,
13251 (void *) (uintptr_t) catch_fork_temporary);
13252 add_catch_command ("vfork", _("Catch calls to vfork."),
13253 catch_fork_command_1,
13255 (void *) (uintptr_t) catch_vfork_permanent,
13256 (void *) (uintptr_t) catch_vfork_temporary);
13257 add_catch_command ("exec", _("Catch calls to exec."),
13258 catch_exec_command_1,
13262 add_catch_command ("syscall", _("\
13263 Catch system calls by their names and/or numbers.\n\
13264 Arguments say which system calls to catch. If no arguments\n\
13265 are given, every system call will be caught.\n\
13266 Arguments, if given, should be one or more system call names\n\
13267 (if your system supports that), or system call numbers."),
13268 catch_syscall_command_1,
13269 catch_syscall_completer,
13273 c = add_com ("watch", class_breakpoint, watch_command, _("\
13274 Set a watchpoint for an expression.\n\
13275 Usage: watch [-l|-location] EXPRESSION\n\
13276 A watchpoint stops execution of your program whenever the value of\n\
13277 an expression changes.\n\
13278 If -l or -location is given, this evaluates EXPRESSION and watches\n\
13279 the memory to which it refers."));
13280 set_cmd_completer (c, expression_completer);
13282 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
13283 Set a read watchpoint for an expression.\n\
13284 Usage: rwatch [-l|-location] EXPRESSION\n\
13285 A watchpoint stops execution of your program whenever the value of\n\
13286 an expression is read.\n\
13287 If -l or -location is given, this evaluates EXPRESSION and watches\n\
13288 the memory to which it refers."));
13289 set_cmd_completer (c, expression_completer);
13291 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
13292 Set a watchpoint for an expression.\n\
13293 Usage: awatch [-l|-location] EXPRESSION\n\
13294 A watchpoint stops execution of your program whenever the value of\n\
13295 an expression is either read or written.\n\
13296 If -l or -location is given, this evaluates EXPRESSION and watches\n\
13297 the memory to which it refers."));
13298 set_cmd_completer (c, expression_completer);
13300 add_info ("watchpoints", watchpoints_info, _("\
13301 Status of specified watchpoints (all watchpoints if no argument)."));
13303 /* XXX: cagney/2005-02-23: This should be a boolean, and should
13304 respond to changes - contrary to the description. */
13305 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
13306 &can_use_hw_watchpoints, _("\
13307 Set debugger's willingness to use watchpoint hardware."), _("\
13308 Show debugger's willingness to use watchpoint hardware."), _("\
13309 If zero, gdb will not use hardware for new watchpoints, even if\n\
13310 such is available. (However, any hardware watchpoints that were\n\
13311 created before setting this to nonzero, will continue to use watchpoint\n\
13314 show_can_use_hw_watchpoints,
13315 &setlist, &showlist);
13317 can_use_hw_watchpoints = 1;
13319 /* Tracepoint manipulation commands. */
13321 c = add_com ("trace", class_breakpoint, trace_command, _("\
13322 Set a tracepoint at specified line or function.\n\
13324 BREAK_ARGS_HELP ("trace") "\n\
13325 Do \"help tracepoints\" for info on other tracepoint commands."));
13326 set_cmd_completer (c, location_completer);
13328 add_com_alias ("tp", "trace", class_alias, 0);
13329 add_com_alias ("tr", "trace", class_alias, 1);
13330 add_com_alias ("tra", "trace", class_alias, 1);
13331 add_com_alias ("trac", "trace", class_alias, 1);
13333 c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\
13334 Set a fast tracepoint at specified line or function.\n\
13336 BREAK_ARGS_HELP ("ftrace") "\n\
13337 Do \"help tracepoints\" for info on other tracepoint commands."));
13338 set_cmd_completer (c, location_completer);
13340 c = add_com ("strace", class_breakpoint, strace_command, _("\
13341 Set a static tracepoint at specified line, function or marker.\n\
13343 strace [LOCATION] [if CONDITION]\n\
13344 LOCATION may be a line number, function name, \"*\" and an address,\n\
13345 or -m MARKER_ID.\n\
13346 If a line number is specified, probe the marker at start of code\n\
13347 for that line. If a function is specified, probe the marker at start\n\
13348 of code for that function. If an address is specified, probe the marker\n\
13349 at that exact address. If a marker id is specified, probe the marker\n\
13350 with that name. With no LOCATION, uses current execution address of\n\
13351 the selected stack frame.\n\
13352 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
13353 This collects arbitrary user data passed in the probe point call to the\n\
13354 tracing library. You can inspect it when analyzing the trace buffer,\n\
13355 by printing the $_sdata variable like any other convenience variable.\n\
13357 CONDITION is a boolean expression.\n\
13359 Multiple tracepoints at one place are permitted, and useful if their\n\
13360 conditions are different.\n\
13362 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
13363 Do \"help tracepoints\" for info on other tracepoint commands."));
13364 set_cmd_completer (c, location_completer);
13366 add_info ("tracepoints", tracepoints_info, _("\
13367 Status of specified tracepoints (all tracepoints if no argument).\n\
13368 Convenience variable \"$tpnum\" contains the number of the\n\
13369 last tracepoint set."));
13371 add_info_alias ("tp", "tracepoints", 1);
13373 add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
13374 Delete specified tracepoints.\n\
13375 Arguments are tracepoint numbers, separated by spaces.\n\
13376 No argument means delete all tracepoints."),
13379 c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
13380 Disable specified tracepoints.\n\
13381 Arguments are tracepoint numbers, separated by spaces.\n\
13382 No argument means disable all tracepoints."),
13384 deprecate_cmd (c, "disable");
13386 c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\
13387 Enable specified tracepoints.\n\
13388 Arguments are tracepoint numbers, separated by spaces.\n\
13389 No argument means enable all tracepoints."),
13391 deprecate_cmd (c, "enable");
13393 add_com ("passcount", class_trace, trace_pass_command, _("\
13394 Set the passcount for a tracepoint.\n\
13395 The trace will end when the tracepoint has been passed 'count' times.\n\
13396 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
13397 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
13399 add_prefix_cmd ("save", class_breakpoint, save_command,
13400 _("Save breakpoint definitions as a script."),
13401 &save_cmdlist, "save ",
13402 0/*allow-unknown*/, &cmdlist);
13404 c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\
13405 Save current breakpoint definitions as a script.\n\
13406 This includes all types of breakpoints (breakpoints, watchpoints,\n\
13407 catchpoints, tracepoints). Use the 'source' command in another debug\n\
13408 session to restore them."),
13410 set_cmd_completer (c, filename_completer);
13412 c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\
13413 Save current tracepoint definitions as a script.\n\
13414 Use the 'source' command in another debug session to restore them."),
13416 set_cmd_completer (c, filename_completer);
13418 c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0);
13419 deprecate_cmd (c, "save tracepoints");
13421 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
13422 Breakpoint specific settings\n\
13423 Configure various breakpoint-specific variables such as\n\
13424 pending breakpoint behavior"),
13425 &breakpoint_set_cmdlist, "set breakpoint ",
13426 0/*allow-unknown*/, &setlist);
13427 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
13428 Breakpoint specific settings\n\
13429 Configure various breakpoint-specific variables such as\n\
13430 pending breakpoint behavior"),
13431 &breakpoint_show_cmdlist, "show breakpoint ",
13432 0/*allow-unknown*/, &showlist);
13434 add_setshow_auto_boolean_cmd ("pending", no_class,
13435 &pending_break_support, _("\
13436 Set debugger's behavior regarding pending breakpoints."), _("\
13437 Show debugger's behavior regarding pending breakpoints."), _("\
13438 If on, an unrecognized breakpoint location will cause gdb to create a\n\
13439 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
13440 an error. If auto, an unrecognized breakpoint location results in a\n\
13441 user-query to see if a pending breakpoint should be created."),
13443 show_pending_break_support,
13444 &breakpoint_set_cmdlist,
13445 &breakpoint_show_cmdlist);
13447 pending_break_support = AUTO_BOOLEAN_AUTO;
13449 add_setshow_boolean_cmd ("auto-hw", no_class,
13450 &automatic_hardware_breakpoints, _("\
13451 Set automatic usage of hardware breakpoints."), _("\
13452 Show automatic usage of hardware breakpoints."), _("\
13453 If set, the debugger will automatically use hardware breakpoints for\n\
13454 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
13455 a warning will be emitted for such breakpoints."),
13457 show_automatic_hardware_breakpoints,
13458 &breakpoint_set_cmdlist,
13459 &breakpoint_show_cmdlist);
13461 add_setshow_enum_cmd ("always-inserted", class_support,
13462 always_inserted_enums, &always_inserted_mode, _("\
13463 Set mode for inserting breakpoints."), _("\
13464 Show mode for inserting breakpoints."), _("\
13465 When this mode is off, breakpoints are inserted in inferior when it is\n\
13466 resumed, and removed when execution stops. When this mode is on,\n\
13467 breakpoints are inserted immediately and removed only when the user\n\
13468 deletes the breakpoint. When this mode is auto (which is the default),\n\
13469 the behaviour depends on the non-stop setting (see help set non-stop).\n\
13470 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
13471 behaves as if always-inserted mode is on; if gdb is controlling the\n\
13472 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
13474 &show_always_inserted_mode,
13475 &breakpoint_set_cmdlist,
13476 &breakpoint_show_cmdlist);
13478 add_com ("break-range", class_breakpoint, break_range_command, _("\
13479 Set a breakpoint for an address range.\n\
13480 break-range START-LOCATION, END-LOCATION\n\
13481 where START-LOCATION and END-LOCATION can be one of the following:\n\
13482 LINENUM, for that line in the current file,\n\
13483 FILE:LINENUM, for that line in that file,\n\
13484 +OFFSET, for that number of lines after the current line\n\
13485 or the start of the range\n\
13486 FUNCTION, for the first line in that function,\n\
13487 FILE:FUNCTION, to distinguish among like-named static functions.\n\
13488 *ADDRESS, for the instruction at that address.\n\
13490 The breakpoint will stop execution of the inferior whenever it executes\n\
13491 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
13492 range (including START-LOCATION and END-LOCATION)."));
13494 automatic_hardware_breakpoints = 1;
13496 observer_attach_about_to_proceed (breakpoint_about_to_proceed);