1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2012 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "arch-utils.h"
26 #include "breakpoint.h"
27 #include "tracepoint.h"
29 #include "expression.h"
35 #include "gdbthread.h"
38 #include "gdb_string.h"
39 #include "gdb-demangle.h"
40 #include "filenames.h"
46 #include "completer.h"
49 #include "cli/cli-script.h"
50 #include "gdb_assert.h"
55 #include "exceptions.h"
61 #include "xml-syscall.h"
62 #include "parser-defs.h"
63 #include "cli/cli-utils.h"
64 #include "continuations.h"
68 #include "gdb_regex.h"
71 /* readline include files */
72 #include "readline/readline.h"
73 #include "readline/history.h"
75 /* readline defines this. */
78 #include "mi/mi-common.h"
79 #include "python/python.h"
81 /* Prototypes for local functions. */
83 static void enable_delete_command (char *, int);
85 static void enable_once_command (char *, int);
87 static void enable_count_command (char *, int);
89 static void disable_command (char *, int);
91 static void enable_command (char *, int);
93 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *,
97 static void ignore_command (char *, int);
99 static int breakpoint_re_set_one (void *);
101 static void breakpoint_re_set_default (struct breakpoint *);
103 static void create_sals_from_address_default (char **,
104 struct linespec_result *,
108 static void create_breakpoints_sal_default (struct gdbarch *,
109 struct linespec_result *,
110 struct linespec_sals *,
112 enum bpdisp, int, int,
114 const struct breakpoint_ops *,
117 static void decode_linespec_default (struct breakpoint *, char **,
118 struct symtabs_and_lines *);
120 static void clear_command (char *, int);
122 static void catch_command (char *, int);
124 static int can_use_hardware_watchpoint (struct value *);
126 static void break_command_1 (char *, int, int);
128 static void mention (struct breakpoint *);
130 static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *,
132 const struct breakpoint_ops *);
133 static struct bp_location *add_location_to_breakpoint (struct breakpoint *,
134 const struct symtab_and_line *);
136 /* This function is used in gdbtk sources and thus can not be made
138 struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch,
139 struct symtab_and_line,
141 const struct breakpoint_ops *);
143 static struct breakpoint *
144 momentary_breakpoint_from_master (struct breakpoint *orig,
146 const struct breakpoint_ops *ops);
148 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
150 static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch,
154 static void describe_other_breakpoints (struct gdbarch *,
155 struct program_space *, CORE_ADDR,
156 struct obj_section *, int);
158 static int breakpoint_address_match (struct address_space *aspace1,
160 struct address_space *aspace2,
163 static int watchpoint_locations_match (struct bp_location *loc1,
164 struct bp_location *loc2);
166 static int breakpoint_location_address_match (struct bp_location *bl,
167 struct address_space *aspace,
170 static void breakpoints_info (char *, int);
172 static void watchpoints_info (char *, int);
174 static int breakpoint_1 (char *, int,
175 int (*) (const struct breakpoint *));
177 static int breakpoint_cond_eval (void *);
179 static void cleanup_executing_breakpoints (void *);
181 static void commands_command (char *, int);
183 static void condition_command (char *, int);
192 static int remove_breakpoint (struct bp_location *, insertion_state_t);
193 static int remove_breakpoint_1 (struct bp_location *, insertion_state_t);
195 static enum print_stop_action print_bp_stop_message (bpstat bs);
197 static int watchpoint_check (void *);
199 static void maintenance_info_breakpoints (char *, int);
201 static int hw_breakpoint_used_count (void);
203 static int hw_watchpoint_use_count (struct breakpoint *);
205 static int hw_watchpoint_used_count_others (struct breakpoint *except,
207 int *other_type_used);
209 static void hbreak_command (char *, int);
211 static void thbreak_command (char *, int);
213 static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp,
216 static void stop_command (char *arg, int from_tty);
218 static void stopin_command (char *arg, int from_tty);
220 static void stopat_command (char *arg, int from_tty);
222 static char *ep_parse_optional_if_clause (char **arg);
224 static void catch_exception_command_1 (enum exception_event_kind ex_event,
225 char *arg, int tempflag, int from_tty);
227 static void tcatch_command (char *arg, int from_tty);
229 static void detach_single_step_breakpoints (void);
231 static int single_step_breakpoint_inserted_here_p (struct address_space *,
234 static void free_bp_location (struct bp_location *loc);
235 static void incref_bp_location (struct bp_location *loc);
236 static void decref_bp_location (struct bp_location **loc);
238 static struct bp_location *allocate_bp_location (struct breakpoint *bpt);
240 static void update_global_location_list (int);
242 static void update_global_location_list_nothrow (int);
244 static int is_hardware_watchpoint (const struct breakpoint *bpt);
246 static void insert_breakpoint_locations (void);
248 static int syscall_catchpoint_p (struct breakpoint *b);
250 static void tracepoints_info (char *, int);
252 static void delete_trace_command (char *, int);
254 static void enable_trace_command (char *, int);
256 static void disable_trace_command (char *, int);
258 static void trace_pass_command (char *, int);
260 static int is_masked_watchpoint (const struct breakpoint *b);
262 static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address);
264 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
267 static int strace_marker_p (struct breakpoint *b);
269 static void init_catchpoint (struct breakpoint *b,
270 struct gdbarch *gdbarch, int tempflag,
272 const struct breakpoint_ops *ops);
274 /* The abstract base class all breakpoint_ops structures inherit
276 static struct breakpoint_ops base_breakpoint_ops;
278 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
279 that are implemented on top of software or hardware breakpoints
280 (user breakpoints, internal and momentary breakpoints, etc.). */
281 static struct breakpoint_ops bkpt_base_breakpoint_ops;
283 /* Internal breakpoints class type. */
284 static struct breakpoint_ops internal_breakpoint_ops;
286 /* Momentary breakpoints class type. */
287 static struct breakpoint_ops momentary_breakpoint_ops;
289 /* The breakpoint_ops structure to be used in regular user created
291 struct breakpoint_ops bkpt_breakpoint_ops;
293 /* A reference-counted struct command_line. This lets multiple
294 breakpoints share a single command list. */
295 struct counted_command_line
297 /* The reference count. */
300 /* The command list. */
301 struct command_line *commands;
304 struct command_line *
305 breakpoint_commands (struct breakpoint *b)
307 return b->commands ? b->commands->commands : NULL;
310 /* Flag indicating that a command has proceeded the inferior past the
311 current breakpoint. */
313 static int breakpoint_proceeded;
316 bpdisp_text (enum bpdisp disp)
318 /* NOTE: the following values are a part of MI protocol and
319 represent values of 'disp' field returned when inferior stops at
321 static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"};
323 return bpdisps[(int) disp];
326 /* Prototypes for exported functions. */
327 /* If FALSE, gdb will not use hardware support for watchpoints, even
328 if such is available. */
329 static int can_use_hw_watchpoints;
332 show_can_use_hw_watchpoints (struct ui_file *file, int from_tty,
333 struct cmd_list_element *c,
336 fprintf_filtered (file,
337 _("Debugger's willingness to use "
338 "watchpoint hardware is %s.\n"),
342 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
343 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
344 for unrecognized breakpoint locations.
345 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
346 static enum auto_boolean pending_break_support;
348 show_pending_break_support (struct ui_file *file, int from_tty,
349 struct cmd_list_element *c,
352 fprintf_filtered (file,
353 _("Debugger's behavior regarding "
354 "pending breakpoints is %s.\n"),
358 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
359 set with "break" but falling in read-only memory.
360 If 0, gdb will warn about such breakpoints, but won't automatically
361 use hardware breakpoints. */
362 static int automatic_hardware_breakpoints;
364 show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty,
365 struct cmd_list_element *c,
368 fprintf_filtered (file,
369 _("Automatic usage of hardware breakpoints is %s.\n"),
373 /* If on, gdb will keep breakpoints inserted even as inferior is
374 stopped, and immediately insert any new breakpoints. If off, gdb
375 will insert breakpoints into inferior only when resuming it, and
376 will remove breakpoints upon stop. If auto, GDB will behave as ON
377 if in non-stop mode, and as OFF if all-stop mode.*/
379 static const char always_inserted_auto[] = "auto";
380 static const char always_inserted_on[] = "on";
381 static const char always_inserted_off[] = "off";
382 static const char *const always_inserted_enums[] = {
383 always_inserted_auto,
388 static const char *always_inserted_mode = always_inserted_auto;
390 show_always_inserted_mode (struct ui_file *file, int from_tty,
391 struct cmd_list_element *c, const char *value)
393 if (always_inserted_mode == always_inserted_auto)
394 fprintf_filtered (file,
395 _("Always inserted breakpoint "
396 "mode is %s (currently %s).\n"),
398 breakpoints_always_inserted_mode () ? "on" : "off");
400 fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"),
405 breakpoints_always_inserted_mode (void)
407 return ((always_inserted_mode == always_inserted_on
408 || (always_inserted_mode == always_inserted_auto && non_stop))
412 static const char condition_evaluation_both[] = "host or target";
414 /* Modes for breakpoint condition evaluation. */
415 static const char condition_evaluation_auto[] = "auto";
416 static const char condition_evaluation_host[] = "host";
417 static const char condition_evaluation_target[] = "target";
418 static const char *const condition_evaluation_enums[] = {
419 condition_evaluation_auto,
420 condition_evaluation_host,
421 condition_evaluation_target,
425 /* Global that holds the current mode for breakpoint condition evaluation. */
426 static const char *condition_evaluation_mode_1 = condition_evaluation_auto;
428 /* Global that we use to display information to the user (gets its value from
429 condition_evaluation_mode_1. */
430 static const char *condition_evaluation_mode = condition_evaluation_auto;
432 /* Translate a condition evaluation mode MODE into either "host"
433 or "target". This is used mostly to translate from "auto" to the
434 real setting that is being used. It returns the translated
438 translate_condition_evaluation_mode (const char *mode)
440 if (mode == condition_evaluation_auto)
442 if (target_supports_evaluation_of_breakpoint_conditions ())
443 return condition_evaluation_target;
445 return condition_evaluation_host;
451 /* Discovers what condition_evaluation_auto translates to. */
454 breakpoint_condition_evaluation_mode (void)
456 return translate_condition_evaluation_mode (condition_evaluation_mode);
459 /* Return true if GDB should evaluate breakpoint conditions or false
463 gdb_evaluates_breakpoint_condition_p (void)
465 const char *mode = breakpoint_condition_evaluation_mode ();
467 return (mode == condition_evaluation_host);
470 void _initialize_breakpoint (void);
472 /* Are we executing breakpoint commands? */
473 static int executing_breakpoint_commands;
475 /* Are overlay event breakpoints enabled? */
476 static int overlay_events_enabled;
478 /* See description in breakpoint.h. */
479 int target_exact_watchpoints = 0;
481 /* Walk the following statement or block through all breakpoints.
482 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
483 current breakpoint. */
485 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
487 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
488 for (B = breakpoint_chain; \
489 B ? (TMP=B->next, 1): 0; \
492 /* Similar iterator for the low-level breakpoints. SAFE variant is
493 not provided so update_global_location_list must not be called
494 while executing the block of ALL_BP_LOCATIONS. */
496 #define ALL_BP_LOCATIONS(B,BP_TMP) \
497 for (BP_TMP = bp_location; \
498 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
501 /* Iterates through locations with address ADDRESS for the currently selected
502 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
503 to where the loop should start from.
504 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
505 appropriate location to start with. */
507 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
508 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
509 BP_LOCP_TMP = BP_LOCP_START; \
511 && (BP_LOCP_TMP < bp_location + bp_location_count \
512 && (*BP_LOCP_TMP)->address == ADDRESS); \
515 /* Iterator for tracepoints only. */
517 #define ALL_TRACEPOINTS(B) \
518 for (B = breakpoint_chain; B; B = B->next) \
519 if (is_tracepoint (B))
521 /* Chains of all breakpoints defined. */
523 struct breakpoint *breakpoint_chain;
525 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
527 static struct bp_location **bp_location;
529 /* Number of elements of BP_LOCATION. */
531 static unsigned bp_location_count;
533 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
534 ADDRESS for the current elements of BP_LOCATION which get a valid
535 result from bp_location_has_shadow. You can use it for roughly
536 limiting the subrange of BP_LOCATION to scan for shadow bytes for
537 an address you need to read. */
539 static CORE_ADDR bp_location_placed_address_before_address_max;
541 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
542 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
543 BP_LOCATION which get a valid result from bp_location_has_shadow.
544 You can use it for roughly limiting the subrange of BP_LOCATION to
545 scan for shadow bytes for an address you need to read. */
547 static CORE_ADDR bp_location_shadow_len_after_address_max;
549 /* The locations that no longer correspond to any breakpoint, unlinked
550 from bp_location array, but for which a hit may still be reported
552 VEC(bp_location_p) *moribund_locations = NULL;
554 /* Number of last breakpoint made. */
556 static int breakpoint_count;
558 /* The value of `breakpoint_count' before the last command that
559 created breakpoints. If the last (break-like) command created more
560 than one breakpoint, then the difference between BREAKPOINT_COUNT
561 and PREV_BREAKPOINT_COUNT is more than one. */
562 static int prev_breakpoint_count;
564 /* Number of last tracepoint made. */
566 static int tracepoint_count;
568 static struct cmd_list_element *breakpoint_set_cmdlist;
569 static struct cmd_list_element *breakpoint_show_cmdlist;
570 struct cmd_list_element *save_cmdlist;
572 /* Return whether a breakpoint is an active enabled breakpoint. */
574 breakpoint_enabled (struct breakpoint *b)
576 return (b->enable_state == bp_enabled);
579 /* Set breakpoint count to NUM. */
582 set_breakpoint_count (int num)
584 prev_breakpoint_count = breakpoint_count;
585 breakpoint_count = num;
586 set_internalvar_integer (lookup_internalvar ("bpnum"), num);
589 /* Used by `start_rbreak_breakpoints' below, to record the current
590 breakpoint count before "rbreak" creates any breakpoint. */
591 static int rbreak_start_breakpoint_count;
593 /* Called at the start an "rbreak" command to record the first
597 start_rbreak_breakpoints (void)
599 rbreak_start_breakpoint_count = breakpoint_count;
602 /* Called at the end of an "rbreak" command to record the last
606 end_rbreak_breakpoints (void)
608 prev_breakpoint_count = rbreak_start_breakpoint_count;
611 /* Used in run_command to zero the hit count when a new run starts. */
614 clear_breakpoint_hit_counts (void)
616 struct breakpoint *b;
622 /* Allocate a new counted_command_line with reference count of 1.
623 The new structure owns COMMANDS. */
625 static struct counted_command_line *
626 alloc_counted_command_line (struct command_line *commands)
628 struct counted_command_line *result
629 = xmalloc (sizeof (struct counted_command_line));
632 result->commands = commands;
636 /* Increment reference count. This does nothing if CMD is NULL. */
639 incref_counted_command_line (struct counted_command_line *cmd)
645 /* Decrement reference count. If the reference count reaches 0,
646 destroy the counted_command_line. Sets *CMDP to NULL. This does
647 nothing if *CMDP is NULL. */
650 decref_counted_command_line (struct counted_command_line **cmdp)
654 if (--(*cmdp)->refc == 0)
656 free_command_lines (&(*cmdp)->commands);
663 /* A cleanup function that calls decref_counted_command_line. */
666 do_cleanup_counted_command_line (void *arg)
668 decref_counted_command_line (arg);
671 /* Create a cleanup that calls decref_counted_command_line on the
674 static struct cleanup *
675 make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp)
677 return make_cleanup (do_cleanup_counted_command_line, cmdp);
681 /* Return the breakpoint with the specified number, or NULL
682 if the number does not refer to an existing breakpoint. */
685 get_breakpoint (int num)
687 struct breakpoint *b;
690 if (b->number == num)
698 /* Mark locations as "conditions have changed" in case the target supports
699 evaluating conditions on its side. */
702 mark_breakpoint_modified (struct breakpoint *b)
704 struct bp_location *loc;
706 /* This is only meaningful if the target is
707 evaluating conditions and if the user has
708 opted for condition evaluation on the target's
710 if (gdb_evaluates_breakpoint_condition_p ()
711 || !target_supports_evaluation_of_breakpoint_conditions ())
714 if (!is_breakpoint (b))
717 for (loc = b->loc; loc; loc = loc->next)
718 loc->condition_changed = condition_modified;
721 /* Mark location as "conditions have changed" in case the target supports
722 evaluating conditions on its side. */
725 mark_breakpoint_location_modified (struct bp_location *loc)
727 /* This is only meaningful if the target is
728 evaluating conditions and if the user has
729 opted for condition evaluation on the target's
731 if (gdb_evaluates_breakpoint_condition_p ()
732 || !target_supports_evaluation_of_breakpoint_conditions ())
736 if (!is_breakpoint (loc->owner))
739 loc->condition_changed = condition_modified;
742 /* Sets the condition-evaluation mode using the static global
743 condition_evaluation_mode. */
746 set_condition_evaluation_mode (char *args, int from_tty,
747 struct cmd_list_element *c)
749 struct breakpoint *b;
750 const char *old_mode, *new_mode;
752 if ((condition_evaluation_mode_1 == condition_evaluation_target)
753 && !target_supports_evaluation_of_breakpoint_conditions ())
755 condition_evaluation_mode_1 = condition_evaluation_mode;
756 warning (_("Target does not support breakpoint condition evaluation.\n"
757 "Using host evaluation mode instead."));
761 new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1);
762 old_mode = translate_condition_evaluation_mode (condition_evaluation_mode);
764 /* Only update the mode if the user picked a different one. */
765 if (new_mode != old_mode)
767 struct bp_location *loc, **loc_tmp;
768 /* If the user switched to a different evaluation mode, we
769 need to synch the changes with the target as follows:
771 "host" -> "target": Send all (valid) conditions to the target.
772 "target" -> "host": Remove all the conditions from the target.
775 /* Flip the switch. */
776 condition_evaluation_mode = condition_evaluation_mode_1;
778 if (new_mode == condition_evaluation_target)
780 /* Mark everything modified and synch conditions with the
782 ALL_BP_LOCATIONS (loc, loc_tmp)
783 mark_breakpoint_location_modified (loc);
787 /* Manually mark non-duplicate locations to synch conditions
788 with the target. We do this to remove all the conditions the
789 target knows about. */
790 ALL_BP_LOCATIONS (loc, loc_tmp)
791 if (is_breakpoint (loc->owner) && loc->inserted)
792 loc->needs_update = 1;
796 update_global_location_list (1);
802 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
803 what "auto" is translating to. */
806 show_condition_evaluation_mode (struct ui_file *file, int from_tty,
807 struct cmd_list_element *c, const char *value)
809 if (condition_evaluation_mode == condition_evaluation_auto)
810 fprintf_filtered (file,
811 _("Breakpoint condition evaluation "
812 "mode is %s (currently %s).\n"),
814 breakpoint_condition_evaluation_mode ());
816 fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"),
820 /* A comparison function for bp_location AP and BP that is used by
821 bsearch. This comparison function only cares about addresses, unlike
822 the more general bp_location_compare function. */
825 bp_location_compare_addrs (const void *ap, const void *bp)
827 struct bp_location *a = *(void **) ap;
828 struct bp_location *b = *(void **) bp;
830 if (a->address == b->address)
833 return ((a->address > b->address) - (a->address < b->address));
836 /* Helper function to skip all bp_locations with addresses
837 less than ADDRESS. It returns the first bp_location that
838 is greater than or equal to ADDRESS. If none is found, just
841 static struct bp_location **
842 get_first_locp_gte_addr (CORE_ADDR address)
844 struct bp_location dummy_loc;
845 struct bp_location *dummy_locp = &dummy_loc;
846 struct bp_location **locp_found = NULL;
848 /* Initialize the dummy location's address field. */
849 memset (&dummy_loc, 0, sizeof (struct bp_location));
850 dummy_loc.address = address;
852 /* Find a close match to the first location at ADDRESS. */
853 locp_found = bsearch (&dummy_locp, bp_location, bp_location_count,
854 sizeof (struct bp_location **),
855 bp_location_compare_addrs);
857 /* Nothing was found, nothing left to do. */
858 if (locp_found == NULL)
861 /* We may have found a location that is at ADDRESS but is not the first in the
862 location's list. Go backwards (if possible) and locate the first one. */
863 while ((locp_found - 1) >= bp_location
864 && (*(locp_found - 1))->address == address)
871 set_breakpoint_condition (struct breakpoint *b, char *exp,
874 xfree (b->cond_string);
875 b->cond_string = NULL;
877 if (is_watchpoint (b))
879 struct watchpoint *w = (struct watchpoint *) b;
886 struct bp_location *loc;
888 for (loc = b->loc; loc; loc = loc->next)
893 /* No need to free the condition agent expression
894 bytecode (if we have one). We will handle this
895 when we go through update_global_location_list. */
902 printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number);
908 /* I don't know if it matters whether this is the string the user
909 typed in or the decompiled expression. */
910 b->cond_string = xstrdup (arg);
911 b->condition_not_parsed = 0;
913 if (is_watchpoint (b))
915 struct watchpoint *w = (struct watchpoint *) b;
917 innermost_block = NULL;
919 w->cond_exp = parse_exp_1 (&arg, 0, 0);
921 error (_("Junk at end of expression"));
922 w->cond_exp_valid_block = innermost_block;
926 struct bp_location *loc;
928 for (loc = b->loc; loc; loc = loc->next)
932 parse_exp_1 (&arg, block_for_pc (loc->address), 0);
934 error (_("Junk at end of expression"));
938 mark_breakpoint_modified (b);
940 breakpoints_changed ();
941 observer_notify_breakpoint_modified (b);
944 /* condition N EXP -- set break condition of breakpoint N to EXP. */
947 condition_command (char *arg, int from_tty)
949 struct breakpoint *b;
954 error_no_arg (_("breakpoint number"));
957 bnum = get_number (&p);
959 error (_("Bad breakpoint argument: '%s'"), arg);
962 if (b->number == bnum)
964 /* Check if this breakpoint has a Python object assigned to
965 it, and if it has a definition of the "stop"
966 method. This method and conditions entered into GDB from
967 the CLI are mutually exclusive. */
969 && gdbpy_breakpoint_has_py_cond (b->py_bp_object))
970 error (_("Cannot set a condition where a Python 'stop' "
971 "method has been defined in the breakpoint."));
972 set_breakpoint_condition (b, p, from_tty);
974 if (is_breakpoint (b))
975 update_global_location_list (1);
980 error (_("No breakpoint number %d."), bnum);
983 /* Check that COMMAND do not contain commands that are suitable
984 only for tracepoints and not suitable for ordinary breakpoints.
985 Throw if any such commands is found. */
988 check_no_tracepoint_commands (struct command_line *commands)
990 struct command_line *c;
992 for (c = commands; c; c = c->next)
996 if (c->control_type == while_stepping_control)
997 error (_("The 'while-stepping' command can "
998 "only be used for tracepoints"));
1000 for (i = 0; i < c->body_count; ++i)
1001 check_no_tracepoint_commands ((c->body_list)[i]);
1003 /* Not that command parsing removes leading whitespace and comment
1004 lines and also empty lines. So, we only need to check for
1005 command directly. */
1006 if (strstr (c->line, "collect ") == c->line)
1007 error (_("The 'collect' command can only be used for tracepoints"));
1009 if (strstr (c->line, "teval ") == c->line)
1010 error (_("The 'teval' command can only be used for tracepoints"));
1014 /* Encapsulate tests for different types of tracepoints. */
1017 is_tracepoint_type (enum bptype type)
1019 return (type == bp_tracepoint
1020 || type == bp_fast_tracepoint
1021 || type == bp_static_tracepoint);
1025 is_tracepoint (const struct breakpoint *b)
1027 return is_tracepoint_type (b->type);
1030 /* A helper function that validates that COMMANDS are valid for a
1031 breakpoint. This function will throw an exception if a problem is
1035 validate_commands_for_breakpoint (struct breakpoint *b,
1036 struct command_line *commands)
1038 if (is_tracepoint (b))
1040 /* We need to verify that each top-level element of commands is
1041 valid for tracepoints, that there's at most one
1042 while-stepping element, and that while-stepping's body has
1043 valid tracing commands excluding nested while-stepping. */
1044 struct command_line *c;
1045 struct command_line *while_stepping = 0;
1046 for (c = commands; c; c = c->next)
1048 if (c->control_type == while_stepping_control)
1050 if (b->type == bp_fast_tracepoint)
1051 error (_("The 'while-stepping' command "
1052 "cannot be used for fast tracepoint"));
1053 else if (b->type == bp_static_tracepoint)
1054 error (_("The 'while-stepping' command "
1055 "cannot be used for static tracepoint"));
1058 error (_("The 'while-stepping' command "
1059 "can be used only once"));
1066 struct command_line *c2;
1068 gdb_assert (while_stepping->body_count == 1);
1069 c2 = while_stepping->body_list[0];
1070 for (; c2; c2 = c2->next)
1072 if (c2->control_type == while_stepping_control)
1073 error (_("The 'while-stepping' command cannot be nested"));
1079 check_no_tracepoint_commands (commands);
1083 /* Return a vector of all the static tracepoints set at ADDR. The
1084 caller is responsible for releasing the vector. */
1087 static_tracepoints_here (CORE_ADDR addr)
1089 struct breakpoint *b;
1090 VEC(breakpoint_p) *found = 0;
1091 struct bp_location *loc;
1094 if (b->type == bp_static_tracepoint)
1096 for (loc = b->loc; loc; loc = loc->next)
1097 if (loc->address == addr)
1098 VEC_safe_push(breakpoint_p, found, b);
1104 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1105 validate that only allowed commands are included. */
1108 breakpoint_set_commands (struct breakpoint *b,
1109 struct command_line *commands)
1111 validate_commands_for_breakpoint (b, commands);
1113 decref_counted_command_line (&b->commands);
1114 b->commands = alloc_counted_command_line (commands);
1115 breakpoints_changed ();
1116 observer_notify_breakpoint_modified (b);
1119 /* Set the internal `silent' flag on the breakpoint. Note that this
1120 is not the same as the "silent" that may appear in the breakpoint's
1124 breakpoint_set_silent (struct breakpoint *b, int silent)
1126 int old_silent = b->silent;
1129 if (old_silent != silent)
1130 observer_notify_breakpoint_modified (b);
1133 /* Set the thread for this breakpoint. If THREAD is -1, make the
1134 breakpoint work for any thread. */
1137 breakpoint_set_thread (struct breakpoint *b, int thread)
1139 int old_thread = b->thread;
1142 if (old_thread != thread)
1143 observer_notify_breakpoint_modified (b);
1146 /* Set the task for this breakpoint. If TASK is 0, make the
1147 breakpoint work for any task. */
1150 breakpoint_set_task (struct breakpoint *b, int task)
1152 int old_task = b->task;
1155 if (old_task != task)
1156 observer_notify_breakpoint_modified (b);
1160 check_tracepoint_command (char *line, void *closure)
1162 struct breakpoint *b = closure;
1164 validate_actionline (&line, b);
1167 /* A structure used to pass information through
1168 map_breakpoint_numbers. */
1170 struct commands_info
1172 /* True if the command was typed at a tty. */
1175 /* The breakpoint range spec. */
1178 /* Non-NULL if the body of the commands are being read from this
1179 already-parsed command. */
1180 struct command_line *control;
1182 /* The command lines read from the user, or NULL if they have not
1184 struct counted_command_line *cmd;
1187 /* A callback for map_breakpoint_numbers that sets the commands for
1188 commands_command. */
1191 do_map_commands_command (struct breakpoint *b, void *data)
1193 struct commands_info *info = data;
1195 if (info->cmd == NULL)
1197 struct command_line *l;
1199 if (info->control != NULL)
1200 l = copy_command_lines (info->control->body_list[0]);
1203 struct cleanup *old_chain;
1206 str = xstrprintf (_("Type commands for breakpoint(s) "
1207 "%s, one per line."),
1210 old_chain = make_cleanup (xfree, str);
1212 l = read_command_lines (str,
1215 ? check_tracepoint_command : 0),
1218 do_cleanups (old_chain);
1221 info->cmd = alloc_counted_command_line (l);
1224 /* If a breakpoint was on the list more than once, we don't need to
1226 if (b->commands != info->cmd)
1228 validate_commands_for_breakpoint (b, info->cmd->commands);
1229 incref_counted_command_line (info->cmd);
1230 decref_counted_command_line (&b->commands);
1231 b->commands = info->cmd;
1232 breakpoints_changed ();
1233 observer_notify_breakpoint_modified (b);
1238 commands_command_1 (char *arg, int from_tty,
1239 struct command_line *control)
1241 struct cleanup *cleanups;
1242 struct commands_info info;
1244 info.from_tty = from_tty;
1245 info.control = control;
1247 /* If we read command lines from the user, then `info' will hold an
1248 extra reference to the commands that we must clean up. */
1249 cleanups = make_cleanup_decref_counted_command_line (&info.cmd);
1251 if (arg == NULL || !*arg)
1253 if (breakpoint_count - prev_breakpoint_count > 1)
1254 arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1,
1256 else if (breakpoint_count > 0)
1257 arg = xstrprintf ("%d", breakpoint_count);
1260 /* So that we don't try to free the incoming non-NULL
1261 argument in the cleanup below. Mapping breakpoint
1262 numbers will fail in this case. */
1267 /* The command loop has some static state, so we need to preserve
1269 arg = xstrdup (arg);
1272 make_cleanup (xfree, arg);
1276 map_breakpoint_numbers (arg, do_map_commands_command, &info);
1278 if (info.cmd == NULL)
1279 error (_("No breakpoints specified."));
1281 do_cleanups (cleanups);
1285 commands_command (char *arg, int from_tty)
1287 commands_command_1 (arg, from_tty, NULL);
1290 /* Like commands_command, but instead of reading the commands from
1291 input stream, takes them from an already parsed command structure.
1293 This is used by cli-script.c to DTRT with breakpoint commands
1294 that are part of if and while bodies. */
1295 enum command_control_type
1296 commands_from_control_command (char *arg, struct command_line *cmd)
1298 commands_command_1 (arg, 0, cmd);
1299 return simple_control;
1302 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1305 bp_location_has_shadow (struct bp_location *bl)
1307 if (bl->loc_type != bp_loc_software_breakpoint)
1311 if (bl->target_info.shadow_len == 0)
1312 /* BL isn't valid, or doesn't shadow memory. */
1317 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1318 by replacing any memory breakpoints with their shadowed contents.
1320 The range of shadowed area by each bp_location is:
1321 bl->address - bp_location_placed_address_before_address_max
1322 up to bl->address + bp_location_shadow_len_after_address_max
1323 The range we were requested to resolve shadows for is:
1324 memaddr ... memaddr + len
1325 Thus the safe cutoff boundaries for performance optimization are
1326 memaddr + len <= (bl->address
1327 - bp_location_placed_address_before_address_max)
1329 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1332 breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf,
1333 const gdb_byte *writebuf_org,
1334 ULONGEST memaddr, LONGEST len)
1336 /* Left boundary, right boundary and median element of our binary
1338 unsigned bc_l, bc_r, bc;
1340 /* Find BC_L which is a leftmost element which may affect BUF
1341 content. It is safe to report lower value but a failure to
1342 report higher one. */
1345 bc_r = bp_location_count;
1346 while (bc_l + 1 < bc_r)
1348 struct bp_location *bl;
1350 bc = (bc_l + bc_r) / 2;
1351 bl = bp_location[bc];
1353 /* Check first BL->ADDRESS will not overflow due to the added
1354 constant. Then advance the left boundary only if we are sure
1355 the BC element can in no way affect the BUF content (MEMADDR
1356 to MEMADDR + LEN range).
1358 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1359 offset so that we cannot miss a breakpoint with its shadow
1360 range tail still reaching MEMADDR. */
1362 if ((bl->address + bp_location_shadow_len_after_address_max
1364 && (bl->address + bp_location_shadow_len_after_address_max
1371 /* Due to the binary search above, we need to make sure we pick the
1372 first location that's at BC_L's address. E.g., if there are
1373 multiple locations at the same address, BC_L may end up pointing
1374 at a duplicate location, and miss the "master"/"inserted"
1375 location. Say, given locations L1, L2 and L3 at addresses A and
1378 L1@A, L2@A, L3@B, ...
1380 BC_L could end up pointing at location L2, while the "master"
1381 location could be L1. Since the `loc->inserted' flag is only set
1382 on "master" locations, we'd forget to restore the shadow of L1
1385 && bp_location[bc_l]->address == bp_location[bc_l - 1]->address)
1388 /* Now do full processing of the found relevant range of elements. */
1390 for (bc = bc_l; bc < bp_location_count; bc++)
1392 struct bp_location *bl = bp_location[bc];
1393 CORE_ADDR bp_addr = 0;
1397 /* bp_location array has BL->OWNER always non-NULL. */
1398 if (bl->owner->type == bp_none)
1399 warning (_("reading through apparently deleted breakpoint #%d?"),
1402 /* Performance optimization: any further element can no longer affect BUF
1405 if (bl->address >= bp_location_placed_address_before_address_max
1406 && memaddr + len <= (bl->address
1407 - bp_location_placed_address_before_address_max))
1410 if (!bp_location_has_shadow (bl))
1412 if (!breakpoint_address_match (bl->target_info.placed_address_space, 0,
1413 current_program_space->aspace, 0))
1416 /* Addresses and length of the part of the breakpoint that
1418 bp_addr = bl->target_info.placed_address;
1419 bp_size = bl->target_info.shadow_len;
1421 if (bp_addr + bp_size <= memaddr)
1422 /* The breakpoint is entirely before the chunk of memory we
1426 if (bp_addr >= memaddr + len)
1427 /* The breakpoint is entirely after the chunk of memory we are
1431 /* Offset within shadow_contents. */
1432 if (bp_addr < memaddr)
1434 /* Only copy the second part of the breakpoint. */
1435 bp_size -= memaddr - bp_addr;
1436 bptoffset = memaddr - bp_addr;
1440 if (bp_addr + bp_size > memaddr + len)
1442 /* Only copy the first part of the breakpoint. */
1443 bp_size -= (bp_addr + bp_size) - (memaddr + len);
1446 if (readbuf != NULL)
1448 /* Update the read buffer with this inserted breakpoint's
1450 memcpy (readbuf + bp_addr - memaddr,
1451 bl->target_info.shadow_contents + bptoffset, bp_size);
1455 struct gdbarch *gdbarch = bl->gdbarch;
1456 const unsigned char *bp;
1457 CORE_ADDR placed_address = bl->target_info.placed_address;
1458 unsigned placed_size = bl->target_info.placed_size;
1460 /* Update the shadow with what we want to write to memory. */
1461 memcpy (bl->target_info.shadow_contents + bptoffset,
1462 writebuf_org + bp_addr - memaddr, bp_size);
1464 /* Determine appropriate breakpoint contents and size for this
1466 bp = gdbarch_breakpoint_from_pc (gdbarch, &placed_address, &placed_size);
1468 /* Update the final write buffer with this inserted
1469 breakpoint's INSN. */
1470 memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size);
1476 /* Return true if BPT is either a software breakpoint or a hardware
1480 is_breakpoint (const struct breakpoint *bpt)
1482 return (bpt->type == bp_breakpoint
1483 || bpt->type == bp_hardware_breakpoint);
1486 /* Return true if BPT is of any hardware watchpoint kind. */
1489 is_hardware_watchpoint (const struct breakpoint *bpt)
1491 return (bpt->type == bp_hardware_watchpoint
1492 || bpt->type == bp_read_watchpoint
1493 || bpt->type == bp_access_watchpoint);
1496 /* Return true if BPT is of any watchpoint kind, hardware or
1500 is_watchpoint (const struct breakpoint *bpt)
1502 return (is_hardware_watchpoint (bpt)
1503 || bpt->type == bp_watchpoint);
1506 /* Returns true if the current thread and its running state are safe
1507 to evaluate or update watchpoint B. Watchpoints on local
1508 expressions need to be evaluated in the context of the thread that
1509 was current when the watchpoint was created, and, that thread needs
1510 to be stopped to be able to select the correct frame context.
1511 Watchpoints on global expressions can be evaluated on any thread,
1512 and in any state. It is presently left to the target allowing
1513 memory accesses when threads are running. */
1516 watchpoint_in_thread_scope (struct watchpoint *b)
1518 return (b->base.pspace == current_program_space
1519 && (ptid_equal (b->watchpoint_thread, null_ptid)
1520 || (ptid_equal (inferior_ptid, b->watchpoint_thread)
1521 && !is_executing (inferior_ptid))));
1524 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1525 associated bp_watchpoint_scope breakpoint. */
1528 watchpoint_del_at_next_stop (struct watchpoint *w)
1530 struct breakpoint *b = &w->base;
1532 if (b->related_breakpoint != b)
1534 gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope);
1535 gdb_assert (b->related_breakpoint->related_breakpoint == b);
1536 b->related_breakpoint->disposition = disp_del_at_next_stop;
1537 b->related_breakpoint->related_breakpoint = b->related_breakpoint;
1538 b->related_breakpoint = b;
1540 b->disposition = disp_del_at_next_stop;
1543 /* Assuming that B is a watchpoint:
1544 - Reparse watchpoint expression, if REPARSE is non-zero
1545 - Evaluate expression and store the result in B->val
1546 - Evaluate the condition if there is one, and store the result
1548 - Update the list of values that must be watched in B->loc.
1550 If the watchpoint disposition is disp_del_at_next_stop, then do
1551 nothing. If this is local watchpoint that is out of scope, delete
1554 Even with `set breakpoint always-inserted on' the watchpoints are
1555 removed + inserted on each stop here. Normal breakpoints must
1556 never be removed because they might be missed by a running thread
1557 when debugging in non-stop mode. On the other hand, hardware
1558 watchpoints (is_hardware_watchpoint; processed here) are specific
1559 to each LWP since they are stored in each LWP's hardware debug
1560 registers. Therefore, such LWP must be stopped first in order to
1561 be able to modify its hardware watchpoints.
1563 Hardware watchpoints must be reset exactly once after being
1564 presented to the user. It cannot be done sooner, because it would
1565 reset the data used to present the watchpoint hit to the user. And
1566 it must not be done later because it could display the same single
1567 watchpoint hit during multiple GDB stops. Note that the latter is
1568 relevant only to the hardware watchpoint types bp_read_watchpoint
1569 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1570 not user-visible - its hit is suppressed if the memory content has
1573 The following constraints influence the location where we can reset
1574 hardware watchpoints:
1576 * target_stopped_by_watchpoint and target_stopped_data_address are
1577 called several times when GDB stops.
1580 * Multiple hardware watchpoints can be hit at the same time,
1581 causing GDB to stop. GDB only presents one hardware watchpoint
1582 hit at a time as the reason for stopping, and all the other hits
1583 are presented later, one after the other, each time the user
1584 requests the execution to be resumed. Execution is not resumed
1585 for the threads still having pending hit event stored in
1586 LWP_INFO->STATUS. While the watchpoint is already removed from
1587 the inferior on the first stop the thread hit event is kept being
1588 reported from its cached value by linux_nat_stopped_data_address
1589 until the real thread resume happens after the watchpoint gets
1590 presented and thus its LWP_INFO->STATUS gets reset.
1592 Therefore the hardware watchpoint hit can get safely reset on the
1593 watchpoint removal from inferior. */
1596 update_watchpoint (struct watchpoint *b, int reparse)
1598 int within_current_scope;
1599 struct frame_id saved_frame_id;
1602 /* If this is a local watchpoint, we only want to check if the
1603 watchpoint frame is in scope if the current thread is the thread
1604 that was used to create the watchpoint. */
1605 if (!watchpoint_in_thread_scope (b))
1608 if (b->base.disposition == disp_del_at_next_stop)
1613 /* Determine if the watchpoint is within scope. */
1614 if (b->exp_valid_block == NULL)
1615 within_current_scope = 1;
1618 struct frame_info *fi = get_current_frame ();
1619 struct gdbarch *frame_arch = get_frame_arch (fi);
1620 CORE_ADDR frame_pc = get_frame_pc (fi);
1622 /* If we're in a function epilogue, unwinding may not work
1623 properly, so do not attempt to recreate locations at this
1624 point. See similar comments in watchpoint_check. */
1625 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
1628 /* Save the current frame's ID so we can restore it after
1629 evaluating the watchpoint expression on its own frame. */
1630 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1631 took a frame parameter, so that we didn't have to change the
1634 saved_frame_id = get_frame_id (get_selected_frame (NULL));
1636 fi = frame_find_by_id (b->watchpoint_frame);
1637 within_current_scope = (fi != NULL);
1638 if (within_current_scope)
1642 /* We don't free locations. They are stored in the bp_location array
1643 and update_global_location_list will eventually delete them and
1644 remove breakpoints if needed. */
1647 if (within_current_scope && reparse)
1656 s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string;
1657 b->exp = parse_exp_1 (&s, b->exp_valid_block, 0);
1658 /* If the meaning of expression itself changed, the old value is
1659 no longer relevant. We don't want to report a watchpoint hit
1660 to the user when the old value and the new value may actually
1661 be completely different objects. */
1662 value_free (b->val);
1666 /* Note that unlike with breakpoints, the watchpoint's condition
1667 expression is stored in the breakpoint object, not in the
1668 locations (re)created below. */
1669 if (b->base.cond_string != NULL)
1671 if (b->cond_exp != NULL)
1673 xfree (b->cond_exp);
1677 s = b->base.cond_string;
1678 b->cond_exp = parse_exp_1 (&s, b->cond_exp_valid_block, 0);
1682 /* If we failed to parse the expression, for example because
1683 it refers to a global variable in a not-yet-loaded shared library,
1684 don't try to insert watchpoint. We don't automatically delete
1685 such watchpoint, though, since failure to parse expression
1686 is different from out-of-scope watchpoint. */
1687 if ( !target_has_execution)
1689 /* Without execution, memory can't change. No use to try and
1690 set watchpoint locations. The watchpoint will be reset when
1691 the target gains execution, through breakpoint_re_set. */
1693 else if (within_current_scope && b->exp)
1696 struct value *val_chain, *v, *result, *next;
1697 struct program_space *frame_pspace;
1699 fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain);
1701 /* Avoid setting b->val if it's already set. The meaning of
1702 b->val is 'the last value' user saw, and we should update
1703 it only if we reported that last value to user. As it
1704 happens, the code that reports it updates b->val directly.
1705 We don't keep track of the memory value for masked
1707 if (!b->val_valid && !is_masked_watchpoint (&b->base))
1713 frame_pspace = get_frame_program_space (get_selected_frame (NULL));
1715 /* Look at each value on the value chain. */
1716 for (v = val_chain; v; v = value_next (v))
1718 /* If it's a memory location, and GDB actually needed
1719 its contents to evaluate the expression, then we
1720 must watch it. If the first value returned is
1721 still lazy, that means an error occurred reading it;
1722 watch it anyway in case it becomes readable. */
1723 if (VALUE_LVAL (v) == lval_memory
1724 && (v == val_chain || ! value_lazy (v)))
1726 struct type *vtype = check_typedef (value_type (v));
1728 /* We only watch structs and arrays if user asked
1729 for it explicitly, never if they just happen to
1730 appear in the middle of some value chain. */
1732 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1733 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1737 struct bp_location *loc, **tmp;
1739 addr = value_address (v);
1740 len = TYPE_LENGTH (value_type (v));
1742 if (b->base.type == bp_read_watchpoint)
1744 else if (b->base.type == bp_access_watchpoint)
1747 loc = allocate_bp_location (&b->base);
1748 for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next))
1751 loc->gdbarch = get_type_arch (value_type (v));
1753 loc->pspace = frame_pspace;
1754 loc->address = addr;
1756 loc->watchpoint_type = type;
1761 /* Change the type of breakpoint between hardware assisted or
1762 an ordinary watchpoint depending on the hardware support
1763 and free hardware slots. REPARSE is set when the inferior
1768 enum bp_loc_type loc_type;
1769 struct bp_location *bl;
1771 reg_cnt = can_use_hardware_watchpoint (val_chain);
1775 int i, target_resources_ok, other_type_used;
1778 /* Use an exact watchpoint when there's only one memory region to be
1779 watched, and only one debug register is needed to watch it. */
1780 b->exact = target_exact_watchpoints && reg_cnt == 1;
1782 /* We need to determine how many resources are already
1783 used for all other hardware watchpoints plus this one
1784 to see if we still have enough resources to also fit
1785 this watchpoint in as well. */
1787 /* If this is a software watchpoint, we try to turn it
1788 to a hardware one -- count resources as if B was of
1789 hardware watchpoint type. */
1790 type = b->base.type;
1791 if (type == bp_watchpoint)
1792 type = bp_hardware_watchpoint;
1794 /* This watchpoint may or may not have been placed on
1795 the list yet at this point (it won't be in the list
1796 if we're trying to create it for the first time,
1797 through watch_command), so always account for it
1800 /* Count resources used by all watchpoints except B. */
1801 i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used);
1803 /* Add in the resources needed for B. */
1804 i += hw_watchpoint_use_count (&b->base);
1807 = target_can_use_hardware_watchpoint (type, i, other_type_used);
1808 if (target_resources_ok <= 0)
1810 int sw_mode = b->base.ops->works_in_software_mode (&b->base);
1812 if (target_resources_ok == 0 && !sw_mode)
1813 error (_("Target does not support this type of "
1814 "hardware watchpoint."));
1815 else if (target_resources_ok < 0 && !sw_mode)
1816 error (_("There are not enough available hardware "
1817 "resources for this watchpoint."));
1819 /* Downgrade to software watchpoint. */
1820 b->base.type = bp_watchpoint;
1824 /* If this was a software watchpoint, we've just
1825 found we have enough resources to turn it to a
1826 hardware watchpoint. Otherwise, this is a
1828 b->base.type = type;
1831 else if (!b->base.ops->works_in_software_mode (&b->base))
1832 error (_("Expression cannot be implemented with "
1833 "read/access watchpoint."));
1835 b->base.type = bp_watchpoint;
1837 loc_type = (b->base.type == bp_watchpoint? bp_loc_other
1838 : bp_loc_hardware_watchpoint);
1839 for (bl = b->base.loc; bl; bl = bl->next)
1840 bl->loc_type = loc_type;
1843 for (v = val_chain; v; v = next)
1845 next = value_next (v);
1850 /* If a software watchpoint is not watching any memory, then the
1851 above left it without any location set up. But,
1852 bpstat_stop_status requires a location to be able to report
1853 stops, so make sure there's at least a dummy one. */
1854 if (b->base.type == bp_watchpoint && b->base.loc == NULL)
1856 struct breakpoint *base = &b->base;
1857 base->loc = allocate_bp_location (base);
1858 base->loc->pspace = frame_pspace;
1859 base->loc->address = -1;
1860 base->loc->length = -1;
1861 base->loc->watchpoint_type = -1;
1864 else if (!within_current_scope)
1866 printf_filtered (_("\
1867 Watchpoint %d deleted because the program has left the block\n\
1868 in which its expression is valid.\n"),
1870 watchpoint_del_at_next_stop (b);
1873 /* Restore the selected frame. */
1875 select_frame (frame_find_by_id (saved_frame_id));
1879 /* Returns 1 iff breakpoint location should be
1880 inserted in the inferior. We don't differentiate the type of BL's owner
1881 (breakpoint vs. tracepoint), although insert_location in tracepoint's
1882 breakpoint_ops is not defined, because in insert_bp_location,
1883 tracepoint's insert_location will not be called. */
1885 should_be_inserted (struct bp_location *bl)
1887 if (bl->owner == NULL || !breakpoint_enabled (bl->owner))
1890 if (bl->owner->disposition == disp_del_at_next_stop)
1893 if (!bl->enabled || bl->shlib_disabled || bl->duplicate)
1896 if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup)
1899 /* This is set for example, when we're attached to the parent of a
1900 vfork, and have detached from the child. The child is running
1901 free, and we expect it to do an exec or exit, at which point the
1902 OS makes the parent schedulable again (and the target reports
1903 that the vfork is done). Until the child is done with the shared
1904 memory region, do not insert breakpoints in the parent, otherwise
1905 the child could still trip on the parent's breakpoints. Since
1906 the parent is blocked anyway, it won't miss any breakpoint. */
1907 if (bl->pspace->breakpoints_not_allowed)
1913 /* Same as should_be_inserted but does the check assuming
1914 that the location is not duplicated. */
1917 unduplicated_should_be_inserted (struct bp_location *bl)
1920 const int save_duplicate = bl->duplicate;
1923 result = should_be_inserted (bl);
1924 bl->duplicate = save_duplicate;
1928 /* Parses a conditional described by an expression COND into an
1929 agent expression bytecode suitable for evaluation
1930 by the bytecode interpreter. Return NULL if there was
1931 any error during parsing. */
1933 static struct agent_expr *
1934 parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond)
1936 struct agent_expr *aexpr = NULL;
1937 struct cleanup *old_chain = NULL;
1938 volatile struct gdb_exception ex;
1943 /* We don't want to stop processing, so catch any errors
1944 that may show up. */
1945 TRY_CATCH (ex, RETURN_MASK_ERROR)
1947 aexpr = gen_eval_for_expr (scope, cond);
1952 /* If we got here, it means the condition could not be parsed to a valid
1953 bytecode expression and thus can't be evaluated on the target's side.
1954 It's no use iterating through the conditions. */
1958 /* We have a valid agent expression. */
1962 /* Based on location BL, create a list of breakpoint conditions to be
1963 passed on to the target. If we have duplicated locations with different
1964 conditions, we will add such conditions to the list. The idea is that the
1965 target will evaluate the list of conditions and will only notify GDB when
1966 one of them is true. */
1969 build_target_condition_list (struct bp_location *bl)
1971 struct bp_location **locp = NULL, **loc2p;
1972 int null_condition_or_parse_error = 0;
1973 int modified = bl->needs_update;
1974 struct bp_location *loc;
1976 /* This is only meaningful if the target is
1977 evaluating conditions and if the user has
1978 opted for condition evaluation on the target's
1980 if (gdb_evaluates_breakpoint_condition_p ()
1981 || !target_supports_evaluation_of_breakpoint_conditions ())
1984 /* Do a first pass to check for locations with no assigned
1985 conditions or conditions that fail to parse to a valid agent expression
1986 bytecode. If any of these happen, then it's no use to send conditions
1987 to the target since this location will always trigger and generate a
1988 response back to GDB. */
1989 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
1992 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
1996 struct agent_expr *aexpr;
1998 /* Re-parse the conditions since something changed. In that
1999 case we already freed the condition bytecodes (see
2000 force_breakpoint_reinsertion). We just
2001 need to parse the condition to bytecodes again. */
2002 aexpr = parse_cond_to_aexpr (bl->address, loc->cond);
2003 loc->cond_bytecode = aexpr;
2005 /* Check if we managed to parse the conditional expression
2006 correctly. If not, we will not send this condition
2012 /* If we have a NULL bytecode expression, it means something
2013 went wrong or we have a null condition expression. */
2014 if (!loc->cond_bytecode)
2016 null_condition_or_parse_error = 1;
2022 /* If any of these happened, it means we will have to evaluate the conditions
2023 for the location's address on gdb's side. It is no use keeping bytecodes
2024 for all the other duplicate locations, thus we free all of them here.
2026 This is so we have a finer control over which locations' conditions are
2027 being evaluated by GDB or the remote stub. */
2028 if (null_condition_or_parse_error)
2030 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2033 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2035 /* Only go as far as the first NULL bytecode is
2037 if (!loc->cond_bytecode)
2040 free_agent_expr (loc->cond_bytecode);
2041 loc->cond_bytecode = NULL;
2046 /* No NULL conditions or failed bytecode generation. Build a condition list
2047 for this location's address. */
2048 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2052 && is_breakpoint (loc->owner)
2053 && loc->pspace->num == bl->pspace->num
2054 && loc->owner->enable_state == bp_enabled
2056 /* Add the condition to the vector. This will be used later to send the
2057 conditions to the target. */
2058 VEC_safe_push (agent_expr_p, bl->target_info.conditions,
2059 loc->cond_bytecode);
2065 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2066 location. Any error messages are printed to TMP_ERROR_STREAM; and
2067 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2068 Returns 0 for success, 1 if the bp_location type is not supported or
2071 NOTE drow/2003-09-09: This routine could be broken down to an
2072 object-style method for each breakpoint or catchpoint type. */
2074 insert_bp_location (struct bp_location *bl,
2075 struct ui_file *tmp_error_stream,
2076 int *disabled_breaks,
2077 int *hw_breakpoint_error)
2081 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
2084 /* Initialize the target-specific information. */
2085 memset (&bl->target_info, 0, sizeof (bl->target_info));
2086 bl->target_info.placed_address = bl->address;
2087 bl->target_info.placed_address_space = bl->pspace->aspace;
2088 bl->target_info.length = bl->length;
2090 /* When working with target-side conditions, we must pass all the conditions
2091 for the same breakpoint address down to the target since GDB will not
2092 insert those locations. With a list of breakpoint conditions, the target
2093 can decide when to stop and notify GDB. */
2095 if (is_breakpoint (bl->owner))
2097 build_target_condition_list (bl);
2098 /* Reset the condition modification marker. */
2099 bl->needs_update = 0;
2102 if (bl->loc_type == bp_loc_software_breakpoint
2103 || bl->loc_type == bp_loc_hardware_breakpoint)
2105 if (bl->owner->type != bp_hardware_breakpoint)
2107 /* If the explicitly specified breakpoint type
2108 is not hardware breakpoint, check the memory map to see
2109 if the breakpoint address is in read only memory or not.
2111 Two important cases are:
2112 - location type is not hardware breakpoint, memory
2113 is readonly. We change the type of the location to
2114 hardware breakpoint.
2115 - location type is hardware breakpoint, memory is
2116 read-write. This means we've previously made the
2117 location hardware one, but then the memory map changed,
2120 When breakpoints are removed, remove_breakpoints will use
2121 location types we've just set here, the only possible
2122 problem is that memory map has changed during running
2123 program, but it's not going to work anyway with current
2125 struct mem_region *mr
2126 = lookup_mem_region (bl->target_info.placed_address);
2130 if (automatic_hardware_breakpoints)
2132 enum bp_loc_type new_type;
2134 if (mr->attrib.mode != MEM_RW)
2135 new_type = bp_loc_hardware_breakpoint;
2137 new_type = bp_loc_software_breakpoint;
2139 if (new_type != bl->loc_type)
2141 static int said = 0;
2143 bl->loc_type = new_type;
2146 fprintf_filtered (gdb_stdout,
2147 _("Note: automatically using "
2148 "hardware breakpoints for "
2149 "read-only addresses.\n"));
2154 else if (bl->loc_type == bp_loc_software_breakpoint
2155 && mr->attrib.mode != MEM_RW)
2156 warning (_("cannot set software breakpoint "
2157 "at readonly address %s"),
2158 paddress (bl->gdbarch, bl->address));
2162 /* First check to see if we have to handle an overlay. */
2163 if (overlay_debugging == ovly_off
2164 || bl->section == NULL
2165 || !(section_is_overlay (bl->section)))
2167 /* No overlay handling: just set the breakpoint. */
2169 val = bl->owner->ops->insert_location (bl);
2173 /* This breakpoint is in an overlay section.
2174 Shall we set a breakpoint at the LMA? */
2175 if (!overlay_events_enabled)
2177 /* Yes -- overlay event support is not active,
2178 so we must try to set a breakpoint at the LMA.
2179 This will not work for a hardware breakpoint. */
2180 if (bl->loc_type == bp_loc_hardware_breakpoint)
2181 warning (_("hardware breakpoint %d not supported in overlay!"),
2185 CORE_ADDR addr = overlay_unmapped_address (bl->address,
2187 /* Set a software (trap) breakpoint at the LMA. */
2188 bl->overlay_target_info = bl->target_info;
2189 bl->overlay_target_info.placed_address = addr;
2190 val = target_insert_breakpoint (bl->gdbarch,
2191 &bl->overlay_target_info);
2193 fprintf_unfiltered (tmp_error_stream,
2194 "Overlay breakpoint %d "
2195 "failed: in ROM?\n",
2199 /* Shall we set a breakpoint at the VMA? */
2200 if (section_is_mapped (bl->section))
2202 /* Yes. This overlay section is mapped into memory. */
2203 val = bl->owner->ops->insert_location (bl);
2207 /* No. This breakpoint will not be inserted.
2208 No error, but do not mark the bp as 'inserted'. */
2215 /* Can't set the breakpoint. */
2216 if (solib_name_from_address (bl->pspace, bl->address))
2218 /* See also: disable_breakpoints_in_shlibs. */
2220 bl->shlib_disabled = 1;
2221 observer_notify_breakpoint_modified (bl->owner);
2222 if (!*disabled_breaks)
2224 fprintf_unfiltered (tmp_error_stream,
2225 "Cannot insert breakpoint %d.\n",
2227 fprintf_unfiltered (tmp_error_stream,
2228 "Temporarily disabling shared "
2229 "library breakpoints:\n");
2231 *disabled_breaks = 1;
2232 fprintf_unfiltered (tmp_error_stream,
2233 "breakpoint #%d\n", bl->owner->number);
2237 if (bl->loc_type == bp_loc_hardware_breakpoint)
2239 *hw_breakpoint_error = 1;
2240 fprintf_unfiltered (tmp_error_stream,
2241 "Cannot insert hardware "
2247 fprintf_unfiltered (tmp_error_stream,
2248 "Cannot insert breakpoint %d.\n",
2250 fprintf_filtered (tmp_error_stream,
2251 "Error accessing memory address ");
2252 fputs_filtered (paddress (bl->gdbarch, bl->address),
2254 fprintf_filtered (tmp_error_stream, ": %s.\n",
2255 safe_strerror (val));
2266 else if (bl->loc_type == bp_loc_hardware_watchpoint
2267 /* NOTE drow/2003-09-08: This state only exists for removing
2268 watchpoints. It's not clear that it's necessary... */
2269 && bl->owner->disposition != disp_del_at_next_stop)
2271 gdb_assert (bl->owner->ops != NULL
2272 && bl->owner->ops->insert_location != NULL);
2274 val = bl->owner->ops->insert_location (bl);
2276 /* If trying to set a read-watchpoint, and it turns out it's not
2277 supported, try emulating one with an access watchpoint. */
2278 if (val == 1 && bl->watchpoint_type == hw_read)
2280 struct bp_location *loc, **loc_temp;
2282 /* But don't try to insert it, if there's already another
2283 hw_access location that would be considered a duplicate
2285 ALL_BP_LOCATIONS (loc, loc_temp)
2287 && loc->watchpoint_type == hw_access
2288 && watchpoint_locations_match (bl, loc))
2292 bl->target_info = loc->target_info;
2293 bl->watchpoint_type = hw_access;
2300 bl->watchpoint_type = hw_access;
2301 val = bl->owner->ops->insert_location (bl);
2304 /* Back to the original value. */
2305 bl->watchpoint_type = hw_read;
2309 bl->inserted = (val == 0);
2312 else if (bl->owner->type == bp_catchpoint)
2314 gdb_assert (bl->owner->ops != NULL
2315 && bl->owner->ops->insert_location != NULL);
2317 val = bl->owner->ops->insert_location (bl);
2320 bl->owner->enable_state = bp_disabled;
2324 Error inserting catchpoint %d: Your system does not support this type\n\
2325 of catchpoint."), bl->owner->number);
2327 warning (_("Error inserting catchpoint %d."), bl->owner->number);
2330 bl->inserted = (val == 0);
2332 /* We've already printed an error message if there was a problem
2333 inserting this catchpoint, and we've disabled the catchpoint,
2334 so just return success. */
2341 /* This function is called when program space PSPACE is about to be
2342 deleted. It takes care of updating breakpoints to not reference
2346 breakpoint_program_space_exit (struct program_space *pspace)
2348 struct breakpoint *b, *b_temp;
2349 struct bp_location *loc, **loc_temp;
2351 /* Remove any breakpoint that was set through this program space. */
2352 ALL_BREAKPOINTS_SAFE (b, b_temp)
2354 if (b->pspace == pspace)
2355 delete_breakpoint (b);
2358 /* Breakpoints set through other program spaces could have locations
2359 bound to PSPACE as well. Remove those. */
2360 ALL_BP_LOCATIONS (loc, loc_temp)
2362 struct bp_location *tmp;
2364 if (loc->pspace == pspace)
2366 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2367 if (loc->owner->loc == loc)
2368 loc->owner->loc = loc->next;
2370 for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next)
2371 if (tmp->next == loc)
2373 tmp->next = loc->next;
2379 /* Now update the global location list to permanently delete the
2380 removed locations above. */
2381 update_global_location_list (0);
2384 /* Make sure all breakpoints are inserted in inferior.
2385 Throws exception on any error.
2386 A breakpoint that is already inserted won't be inserted
2387 again, so calling this function twice is safe. */
2389 insert_breakpoints (void)
2391 struct breakpoint *bpt;
2393 ALL_BREAKPOINTS (bpt)
2394 if (is_hardware_watchpoint (bpt))
2396 struct watchpoint *w = (struct watchpoint *) bpt;
2398 update_watchpoint (w, 0 /* don't reparse. */);
2401 update_global_location_list (1);
2403 /* update_global_location_list does not insert breakpoints when
2404 always_inserted_mode is not enabled. Explicitly insert them
2406 if (!breakpoints_always_inserted_mode ())
2407 insert_breakpoint_locations ();
2410 /* This is used when we need to synch breakpoint conditions between GDB and the
2411 target. It is the case with deleting and disabling of breakpoints when using
2412 always-inserted mode. */
2415 update_inserted_breakpoint_locations (void)
2417 struct bp_location *bl, **blp_tmp;
2420 int disabled_breaks = 0;
2421 int hw_breakpoint_error = 0;
2423 struct ui_file *tmp_error_stream = mem_fileopen ();
2424 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
2426 /* Explicitly mark the warning -- this will only be printed if
2427 there was an error. */
2428 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
2430 save_current_space_and_thread ();
2432 ALL_BP_LOCATIONS (bl, blp_tmp)
2434 /* We only want to update software breakpoints and hardware
2436 if (!is_breakpoint (bl->owner))
2439 /* We only want to update locations that are already inserted
2440 and need updating. This is to avoid unwanted insertion during
2441 deletion of breakpoints. */
2442 if (!bl->inserted || (bl->inserted && !bl->needs_update))
2445 switch_to_program_space_and_thread (bl->pspace);
2447 /* For targets that support global breakpoints, there's no need
2448 to select an inferior to insert breakpoint to. In fact, even
2449 if we aren't attached to any process yet, we should still
2450 insert breakpoints. */
2451 if (!gdbarch_has_global_breakpoints (target_gdbarch)
2452 && ptid_equal (inferior_ptid, null_ptid))
2455 val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
2456 &hw_breakpoint_error);
2463 target_terminal_ours_for_output ();
2464 error_stream (tmp_error_stream);
2467 do_cleanups (cleanups);
2470 /* Used when starting or continuing the program. */
2473 insert_breakpoint_locations (void)
2475 struct breakpoint *bpt;
2476 struct bp_location *bl, **blp_tmp;
2479 int disabled_breaks = 0;
2480 int hw_breakpoint_error = 0;
2482 struct ui_file *tmp_error_stream = mem_fileopen ();
2483 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
2485 /* Explicitly mark the warning -- this will only be printed if
2486 there was an error. */
2487 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
2489 save_current_space_and_thread ();
2491 ALL_BP_LOCATIONS (bl, blp_tmp)
2493 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
2496 /* There is no point inserting thread-specific breakpoints if
2497 the thread no longer exists. ALL_BP_LOCATIONS bp_location
2498 has BL->OWNER always non-NULL. */
2499 if (bl->owner->thread != -1
2500 && !valid_thread_id (bl->owner->thread))
2503 switch_to_program_space_and_thread (bl->pspace);
2505 /* For targets that support global breakpoints, there's no need
2506 to select an inferior to insert breakpoint to. In fact, even
2507 if we aren't attached to any process yet, we should still
2508 insert breakpoints. */
2509 if (!gdbarch_has_global_breakpoints (target_gdbarch)
2510 && ptid_equal (inferior_ptid, null_ptid))
2513 val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
2514 &hw_breakpoint_error);
2519 /* If we failed to insert all locations of a watchpoint, remove
2520 them, as half-inserted watchpoint is of limited use. */
2521 ALL_BREAKPOINTS (bpt)
2523 int some_failed = 0;
2524 struct bp_location *loc;
2526 if (!is_hardware_watchpoint (bpt))
2529 if (!breakpoint_enabled (bpt))
2532 if (bpt->disposition == disp_del_at_next_stop)
2535 for (loc = bpt->loc; loc; loc = loc->next)
2536 if (!loc->inserted && should_be_inserted (loc))
2543 for (loc = bpt->loc; loc; loc = loc->next)
2545 remove_breakpoint (loc, mark_uninserted);
2547 hw_breakpoint_error = 1;
2548 fprintf_unfiltered (tmp_error_stream,
2549 "Could not insert hardware watchpoint %d.\n",
2557 /* If a hardware breakpoint or watchpoint was inserted, add a
2558 message about possibly exhausted resources. */
2559 if (hw_breakpoint_error)
2561 fprintf_unfiltered (tmp_error_stream,
2562 "Could not insert hardware breakpoints:\n\
2563 You may have requested too many hardware breakpoints/watchpoints.\n");
2565 target_terminal_ours_for_output ();
2566 error_stream (tmp_error_stream);
2569 do_cleanups (cleanups);
2572 /* Used when the program stops.
2573 Returns zero if successful, or non-zero if there was a problem
2574 removing a breakpoint location. */
2577 remove_breakpoints (void)
2579 struct bp_location *bl, **blp_tmp;
2582 ALL_BP_LOCATIONS (bl, blp_tmp)
2584 if (bl->inserted && !is_tracepoint (bl->owner))
2585 val |= remove_breakpoint (bl, mark_uninserted);
2590 /* Remove breakpoints of process PID. */
2593 remove_breakpoints_pid (int pid)
2595 struct bp_location *bl, **blp_tmp;
2597 struct inferior *inf = find_inferior_pid (pid);
2599 ALL_BP_LOCATIONS (bl, blp_tmp)
2601 if (bl->pspace != inf->pspace)
2606 val = remove_breakpoint (bl, mark_uninserted);
2615 reattach_breakpoints (int pid)
2617 struct cleanup *old_chain;
2618 struct bp_location *bl, **blp_tmp;
2620 struct ui_file *tmp_error_stream;
2621 int dummy1 = 0, dummy2 = 0;
2622 struct inferior *inf;
2623 struct thread_info *tp;
2625 tp = any_live_thread_of_process (pid);
2629 inf = find_inferior_pid (pid);
2630 old_chain = save_inferior_ptid ();
2632 inferior_ptid = tp->ptid;
2634 tmp_error_stream = mem_fileopen ();
2635 make_cleanup_ui_file_delete (tmp_error_stream);
2637 ALL_BP_LOCATIONS (bl, blp_tmp)
2639 if (bl->pspace != inf->pspace)
2645 val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2);
2648 do_cleanups (old_chain);
2653 do_cleanups (old_chain);
2657 static int internal_breakpoint_number = -1;
2659 /* Set the breakpoint number of B, depending on the value of INTERNAL.
2660 If INTERNAL is non-zero, the breakpoint number will be populated
2661 from internal_breakpoint_number and that variable decremented.
2662 Otherwise the breakpoint number will be populated from
2663 breakpoint_count and that value incremented. Internal breakpoints
2664 do not set the internal var bpnum. */
2666 set_breakpoint_number (int internal, struct breakpoint *b)
2669 b->number = internal_breakpoint_number--;
2672 set_breakpoint_count (breakpoint_count + 1);
2673 b->number = breakpoint_count;
2677 static struct breakpoint *
2678 create_internal_breakpoint (struct gdbarch *gdbarch,
2679 CORE_ADDR address, enum bptype type,
2680 const struct breakpoint_ops *ops)
2682 struct symtab_and_line sal;
2683 struct breakpoint *b;
2685 init_sal (&sal); /* Initialize to zeroes. */
2688 sal.section = find_pc_overlay (sal.pc);
2689 sal.pspace = current_program_space;
2691 b = set_raw_breakpoint (gdbarch, sal, type, ops);
2692 b->number = internal_breakpoint_number--;
2693 b->disposition = disp_donttouch;
2698 static const char *const longjmp_names[] =
2700 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
2702 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
2704 /* Per-objfile data private to breakpoint.c. */
2705 struct breakpoint_objfile_data
2707 /* Minimal symbol for "_ovly_debug_event" (if any). */
2708 struct minimal_symbol *overlay_msym;
2710 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
2711 struct minimal_symbol *longjmp_msym[NUM_LONGJMP_NAMES];
2713 /* Minimal symbol for "std::terminate()" (if any). */
2714 struct minimal_symbol *terminate_msym;
2716 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
2717 struct minimal_symbol *exception_msym;
2720 static const struct objfile_data *breakpoint_objfile_key;
2722 /* Minimal symbol not found sentinel. */
2723 static struct minimal_symbol msym_not_found;
2725 /* Returns TRUE if MSYM point to the "not found" sentinel. */
2728 msym_not_found_p (const struct minimal_symbol *msym)
2730 return msym == &msym_not_found;
2733 /* Return per-objfile data needed by breakpoint.c.
2734 Allocate the data if necessary. */
2736 static struct breakpoint_objfile_data *
2737 get_breakpoint_objfile_data (struct objfile *objfile)
2739 struct breakpoint_objfile_data *bp_objfile_data;
2741 bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key);
2742 if (bp_objfile_data == NULL)
2744 bp_objfile_data = obstack_alloc (&objfile->objfile_obstack,
2745 sizeof (*bp_objfile_data));
2747 memset (bp_objfile_data, 0, sizeof (*bp_objfile_data));
2748 set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data);
2750 return bp_objfile_data;
2754 create_overlay_event_breakpoint (void)
2756 struct objfile *objfile;
2757 const char *const func_name = "_ovly_debug_event";
2759 ALL_OBJFILES (objfile)
2761 struct breakpoint *b;
2762 struct breakpoint_objfile_data *bp_objfile_data;
2765 bp_objfile_data = get_breakpoint_objfile_data (objfile);
2767 if (msym_not_found_p (bp_objfile_data->overlay_msym))
2770 if (bp_objfile_data->overlay_msym == NULL)
2772 struct minimal_symbol *m;
2774 m = lookup_minimal_symbol_text (func_name, objfile);
2777 /* Avoid future lookups in this objfile. */
2778 bp_objfile_data->overlay_msym = &msym_not_found;
2781 bp_objfile_data->overlay_msym = m;
2784 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym);
2785 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
2787 &internal_breakpoint_ops);
2788 b->addr_string = xstrdup (func_name);
2790 if (overlay_debugging == ovly_auto)
2792 b->enable_state = bp_enabled;
2793 overlay_events_enabled = 1;
2797 b->enable_state = bp_disabled;
2798 overlay_events_enabled = 0;
2801 update_global_location_list (1);
2805 create_longjmp_master_breakpoint (void)
2807 struct program_space *pspace;
2808 struct cleanup *old_chain;
2810 old_chain = save_current_program_space ();
2812 ALL_PSPACES (pspace)
2814 struct objfile *objfile;
2816 set_current_program_space (pspace);
2818 ALL_OBJFILES (objfile)
2821 struct gdbarch *gdbarch;
2822 struct breakpoint_objfile_data *bp_objfile_data;
2824 gdbarch = get_objfile_arch (objfile);
2825 if (!gdbarch_get_longjmp_target_p (gdbarch))
2828 bp_objfile_data = get_breakpoint_objfile_data (objfile);
2830 for (i = 0; i < NUM_LONGJMP_NAMES; i++)
2832 struct breakpoint *b;
2833 const char *func_name;
2836 if (msym_not_found_p (bp_objfile_data->longjmp_msym[i]))
2839 func_name = longjmp_names[i];
2840 if (bp_objfile_data->longjmp_msym[i] == NULL)
2842 struct minimal_symbol *m;
2844 m = lookup_minimal_symbol_text (func_name, objfile);
2847 /* Prevent future lookups in this objfile. */
2848 bp_objfile_data->longjmp_msym[i] = &msym_not_found;
2851 bp_objfile_data->longjmp_msym[i] = m;
2854 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]);
2855 b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master,
2856 &internal_breakpoint_ops);
2857 b->addr_string = xstrdup (func_name);
2858 b->enable_state = bp_disabled;
2862 update_global_location_list (1);
2864 do_cleanups (old_chain);
2867 /* Create a master std::terminate breakpoint. */
2869 create_std_terminate_master_breakpoint (void)
2871 struct program_space *pspace;
2872 struct cleanup *old_chain;
2873 const char *const func_name = "std::terminate()";
2875 old_chain = save_current_program_space ();
2877 ALL_PSPACES (pspace)
2879 struct objfile *objfile;
2882 set_current_program_space (pspace);
2884 ALL_OBJFILES (objfile)
2886 struct breakpoint *b;
2887 struct breakpoint_objfile_data *bp_objfile_data;
2889 bp_objfile_data = get_breakpoint_objfile_data (objfile);
2891 if (msym_not_found_p (bp_objfile_data->terminate_msym))
2894 if (bp_objfile_data->terminate_msym == NULL)
2896 struct minimal_symbol *m;
2898 m = lookup_minimal_symbol (func_name, NULL, objfile);
2899 if (m == NULL || (MSYMBOL_TYPE (m) != mst_text
2900 && MSYMBOL_TYPE (m) != mst_file_text))
2902 /* Prevent future lookups in this objfile. */
2903 bp_objfile_data->terminate_msym = &msym_not_found;
2906 bp_objfile_data->terminate_msym = m;
2909 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym);
2910 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
2911 bp_std_terminate_master,
2912 &internal_breakpoint_ops);
2913 b->addr_string = xstrdup (func_name);
2914 b->enable_state = bp_disabled;
2918 update_global_location_list (1);
2920 do_cleanups (old_chain);
2923 /* Install a master breakpoint on the unwinder's debug hook. */
2926 create_exception_master_breakpoint (void)
2928 struct objfile *objfile;
2929 const char *const func_name = "_Unwind_DebugHook";
2931 ALL_OBJFILES (objfile)
2933 struct breakpoint *b;
2934 struct gdbarch *gdbarch;
2935 struct breakpoint_objfile_data *bp_objfile_data;
2938 bp_objfile_data = get_breakpoint_objfile_data (objfile);
2940 if (msym_not_found_p (bp_objfile_data->exception_msym))
2943 gdbarch = get_objfile_arch (objfile);
2945 if (bp_objfile_data->exception_msym == NULL)
2947 struct minimal_symbol *debug_hook;
2949 debug_hook = lookup_minimal_symbol (func_name, NULL, objfile);
2950 if (debug_hook == NULL)
2952 bp_objfile_data->exception_msym = &msym_not_found;
2956 bp_objfile_data->exception_msym = debug_hook;
2959 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym);
2960 addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
2962 b = create_internal_breakpoint (gdbarch, addr, bp_exception_master,
2963 &internal_breakpoint_ops);
2964 b->addr_string = xstrdup (func_name);
2965 b->enable_state = bp_disabled;
2968 update_global_location_list (1);
2972 update_breakpoints_after_exec (void)
2974 struct breakpoint *b, *b_tmp;
2975 struct bp_location *bploc, **bplocp_tmp;
2977 /* We're about to delete breakpoints from GDB's lists. If the
2978 INSERTED flag is true, GDB will try to lift the breakpoints by
2979 writing the breakpoints' "shadow contents" back into memory. The
2980 "shadow contents" are NOT valid after an exec, so GDB should not
2981 do that. Instead, the target is responsible from marking
2982 breakpoints out as soon as it detects an exec. We don't do that
2983 here instead, because there may be other attempts to delete
2984 breakpoints after detecting an exec and before reaching here. */
2985 ALL_BP_LOCATIONS (bploc, bplocp_tmp)
2986 if (bploc->pspace == current_program_space)
2987 gdb_assert (!bploc->inserted);
2989 ALL_BREAKPOINTS_SAFE (b, b_tmp)
2991 if (b->pspace != current_program_space)
2994 /* Solib breakpoints must be explicitly reset after an exec(). */
2995 if (b->type == bp_shlib_event)
2997 delete_breakpoint (b);
3001 /* JIT breakpoints must be explicitly reset after an exec(). */
3002 if (b->type == bp_jit_event)
3004 delete_breakpoint (b);
3008 /* Thread event breakpoints must be set anew after an exec(),
3009 as must overlay event and longjmp master breakpoints. */
3010 if (b->type == bp_thread_event || b->type == bp_overlay_event
3011 || b->type == bp_longjmp_master || b->type == bp_std_terminate_master
3012 || b->type == bp_exception_master)
3014 delete_breakpoint (b);
3018 /* Step-resume breakpoints are meaningless after an exec(). */
3019 if (b->type == bp_step_resume || b->type == bp_hp_step_resume)
3021 delete_breakpoint (b);
3025 /* Longjmp and longjmp-resume breakpoints are also meaningless
3027 if (b->type == bp_longjmp || b->type == bp_longjmp_resume
3028 || b->type == bp_exception || b->type == bp_exception_resume)
3030 delete_breakpoint (b);
3034 if (b->type == bp_catchpoint)
3036 /* For now, none of the bp_catchpoint breakpoints need to
3037 do anything at this point. In the future, if some of
3038 the catchpoints need to something, we will need to add
3039 a new method, and call this method from here. */
3043 /* bp_finish is a special case. The only way we ought to be able
3044 to see one of these when an exec() has happened, is if the user
3045 caught a vfork, and then said "finish". Ordinarily a finish just
3046 carries them to the call-site of the current callee, by setting
3047 a temporary bp there and resuming. But in this case, the finish
3048 will carry them entirely through the vfork & exec.
3050 We don't want to allow a bp_finish to remain inserted now. But
3051 we can't safely delete it, 'cause finish_command has a handle to
3052 the bp on a bpstat, and will later want to delete it. There's a
3053 chance (and I've seen it happen) that if we delete the bp_finish
3054 here, that its storage will get reused by the time finish_command
3055 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3056 We really must allow finish_command to delete a bp_finish.
3058 In the absence of a general solution for the "how do we know
3059 it's safe to delete something others may have handles to?"
3060 problem, what we'll do here is just uninsert the bp_finish, and
3061 let finish_command delete it.
3063 (We know the bp_finish is "doomed" in the sense that it's
3064 momentary, and will be deleted as soon as finish_command sees
3065 the inferior stopped. So it doesn't matter that the bp's
3066 address is probably bogus in the new a.out, unlike e.g., the
3067 solib breakpoints.) */
3069 if (b->type == bp_finish)
3074 /* Without a symbolic address, we have little hope of the
3075 pre-exec() address meaning the same thing in the post-exec()
3077 if (b->addr_string == NULL)
3079 delete_breakpoint (b);
3083 /* FIXME what about longjmp breakpoints? Re-create them here? */
3084 create_overlay_event_breakpoint ();
3085 create_longjmp_master_breakpoint ();
3086 create_std_terminate_master_breakpoint ();
3087 create_exception_master_breakpoint ();
3091 detach_breakpoints (int pid)
3093 struct bp_location *bl, **blp_tmp;
3095 struct cleanup *old_chain = save_inferior_ptid ();
3096 struct inferior *inf = current_inferior ();
3098 if (pid == PIDGET (inferior_ptid))
3099 error (_("Cannot detach breakpoints of inferior_ptid"));
3101 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3102 inferior_ptid = pid_to_ptid (pid);
3103 ALL_BP_LOCATIONS (bl, blp_tmp)
3105 if (bl->pspace != inf->pspace)
3109 val |= remove_breakpoint_1 (bl, mark_inserted);
3112 /* Detach single-step breakpoints as well. */
3113 detach_single_step_breakpoints ();
3115 do_cleanups (old_chain);
3119 /* Remove the breakpoint location BL from the current address space.
3120 Note that this is used to detach breakpoints from a child fork.
3121 When we get here, the child isn't in the inferior list, and neither
3122 do we have objects to represent its address space --- we should
3123 *not* look at bl->pspace->aspace here. */
3126 remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is)
3130 /* BL is never in moribund_locations by our callers. */
3131 gdb_assert (bl->owner != NULL);
3133 if (bl->owner->enable_state == bp_permanent)
3134 /* Permanent breakpoints cannot be inserted or removed. */
3137 /* The type of none suggests that owner is actually deleted.
3138 This should not ever happen. */
3139 gdb_assert (bl->owner->type != bp_none);
3141 if (bl->loc_type == bp_loc_software_breakpoint
3142 || bl->loc_type == bp_loc_hardware_breakpoint)
3144 /* "Normal" instruction breakpoint: either the standard
3145 trap-instruction bp (bp_breakpoint), or a
3146 bp_hardware_breakpoint. */
3148 /* First check to see if we have to handle an overlay. */
3149 if (overlay_debugging == ovly_off
3150 || bl->section == NULL
3151 || !(section_is_overlay (bl->section)))
3153 /* No overlay handling: just remove the breakpoint. */
3154 val = bl->owner->ops->remove_location (bl);
3158 /* This breakpoint is in an overlay section.
3159 Did we set a breakpoint at the LMA? */
3160 if (!overlay_events_enabled)
3162 /* Yes -- overlay event support is not active, so we
3163 should have set a breakpoint at the LMA. Remove it.
3165 /* Ignore any failures: if the LMA is in ROM, we will
3166 have already warned when we failed to insert it. */
3167 if (bl->loc_type == bp_loc_hardware_breakpoint)
3168 target_remove_hw_breakpoint (bl->gdbarch,
3169 &bl->overlay_target_info);
3171 target_remove_breakpoint (bl->gdbarch,
3172 &bl->overlay_target_info);
3174 /* Did we set a breakpoint at the VMA?
3175 If so, we will have marked the breakpoint 'inserted'. */
3178 /* Yes -- remove it. Previously we did not bother to
3179 remove the breakpoint if the section had been
3180 unmapped, but let's not rely on that being safe. We
3181 don't know what the overlay manager might do. */
3183 /* However, we should remove *software* breakpoints only
3184 if the section is still mapped, or else we overwrite
3185 wrong code with the saved shadow contents. */
3186 if (bl->loc_type == bp_loc_hardware_breakpoint
3187 || section_is_mapped (bl->section))
3188 val = bl->owner->ops->remove_location (bl);
3194 /* No -- not inserted, so no need to remove. No error. */
3199 /* In some cases, we might not be able to remove a breakpoint
3200 in a shared library that has already been removed, but we
3201 have not yet processed the shlib unload event. */
3202 if (val && solib_name_from_address (bl->pspace, bl->address))
3207 bl->inserted = (is == mark_inserted);
3209 else if (bl->loc_type == bp_loc_hardware_watchpoint)
3211 gdb_assert (bl->owner->ops != NULL
3212 && bl->owner->ops->remove_location != NULL);
3214 bl->inserted = (is == mark_inserted);
3215 bl->owner->ops->remove_location (bl);
3217 /* Failure to remove any of the hardware watchpoints comes here. */
3218 if ((is == mark_uninserted) && (bl->inserted))
3219 warning (_("Could not remove hardware watchpoint %d."),
3222 else if (bl->owner->type == bp_catchpoint
3223 && breakpoint_enabled (bl->owner)
3226 gdb_assert (bl->owner->ops != NULL
3227 && bl->owner->ops->remove_location != NULL);
3229 val = bl->owner->ops->remove_location (bl);
3233 bl->inserted = (is == mark_inserted);
3240 remove_breakpoint (struct bp_location *bl, insertion_state_t is)
3243 struct cleanup *old_chain;
3245 /* BL is never in moribund_locations by our callers. */
3246 gdb_assert (bl->owner != NULL);
3248 if (bl->owner->enable_state == bp_permanent)
3249 /* Permanent breakpoints cannot be inserted or removed. */
3252 /* The type of none suggests that owner is actually deleted.
3253 This should not ever happen. */
3254 gdb_assert (bl->owner->type != bp_none);
3256 old_chain = save_current_space_and_thread ();
3258 switch_to_program_space_and_thread (bl->pspace);
3260 ret = remove_breakpoint_1 (bl, is);
3262 do_cleanups (old_chain);
3266 /* Clear the "inserted" flag in all breakpoints. */
3269 mark_breakpoints_out (void)
3271 struct bp_location *bl, **blp_tmp;
3273 ALL_BP_LOCATIONS (bl, blp_tmp)
3274 if (bl->pspace == current_program_space)
3278 /* Clear the "inserted" flag in all breakpoints and delete any
3279 breakpoints which should go away between runs of the program.
3281 Plus other such housekeeping that has to be done for breakpoints
3284 Note: this function gets called at the end of a run (by
3285 generic_mourn_inferior) and when a run begins (by
3286 init_wait_for_inferior). */
3291 breakpoint_init_inferior (enum inf_context context)
3293 struct breakpoint *b, *b_tmp;
3294 struct bp_location *bl, **blp_tmp;
3296 struct program_space *pspace = current_program_space;
3298 /* If breakpoint locations are shared across processes, then there's
3300 if (gdbarch_has_global_breakpoints (target_gdbarch))
3303 ALL_BP_LOCATIONS (bl, blp_tmp)
3305 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3306 if (bl->pspace == pspace
3307 && bl->owner->enable_state != bp_permanent)
3311 ALL_BREAKPOINTS_SAFE (b, b_tmp)
3313 if (b->loc && b->loc->pspace != pspace)
3320 /* If the call dummy breakpoint is at the entry point it will
3321 cause problems when the inferior is rerun, so we better get
3324 case bp_watchpoint_scope:
3326 /* Also get rid of scope breakpoints. */
3328 case bp_shlib_event:
3330 /* Also remove solib event breakpoints. Their addresses may
3331 have changed since the last time we ran the program.
3332 Actually we may now be debugging against different target;
3333 and so the solib backend that installed this breakpoint may
3334 not be used in by the target. E.g.,
3336 (gdb) file prog-linux
3337 (gdb) run # native linux target
3340 (gdb) file prog-win.exe
3341 (gdb) tar rem :9999 # remote Windows gdbserver.
3344 delete_breakpoint (b);
3348 case bp_hardware_watchpoint:
3349 case bp_read_watchpoint:
3350 case bp_access_watchpoint:
3352 struct watchpoint *w = (struct watchpoint *) b;
3354 /* Likewise for watchpoints on local expressions. */
3355 if (w->exp_valid_block != NULL)
3356 delete_breakpoint (b);
3357 else if (context == inf_starting)
3359 /* Reset val field to force reread of starting value in
3360 insert_breakpoints. */
3362 value_free (w->val);
3373 /* Get rid of the moribund locations. */
3374 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix)
3375 decref_bp_location (&bl);
3376 VEC_free (bp_location_p, moribund_locations);
3379 /* These functions concern about actual breakpoints inserted in the
3380 target --- to e.g. check if we need to do decr_pc adjustment or if
3381 we need to hop over the bkpt --- so we check for address space
3382 match, not program space. */
3384 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
3385 exists at PC. It returns ordinary_breakpoint_here if it's an
3386 ordinary breakpoint, or permanent_breakpoint_here if it's a
3387 permanent breakpoint.
3388 - When continuing from a location with an ordinary breakpoint, we
3389 actually single step once before calling insert_breakpoints.
3390 - When continuing from a location with a permanent breakpoint, we
3391 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
3392 the target, to advance the PC past the breakpoint. */
3394 enum breakpoint_here
3395 breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
3397 struct bp_location *bl, **blp_tmp;
3398 int any_breakpoint_here = 0;
3400 ALL_BP_LOCATIONS (bl, blp_tmp)
3402 if (bl->loc_type != bp_loc_software_breakpoint
3403 && bl->loc_type != bp_loc_hardware_breakpoint)
3406 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3407 if ((breakpoint_enabled (bl->owner)
3408 || bl->owner->enable_state == bp_permanent)
3409 && breakpoint_location_address_match (bl, aspace, pc))
3411 if (overlay_debugging
3412 && section_is_overlay (bl->section)
3413 && !section_is_mapped (bl->section))
3414 continue; /* unmapped overlay -- can't be a match */
3415 else if (bl->owner->enable_state == bp_permanent)
3416 return permanent_breakpoint_here;
3418 any_breakpoint_here = 1;
3422 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
3425 /* Return true if there's a moribund breakpoint at PC. */
3428 moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
3430 struct bp_location *loc;
3433 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
3434 if (breakpoint_location_address_match (loc, aspace, pc))
3440 /* Returns non-zero if there's a breakpoint inserted at PC, which is
3441 inserted using regular breakpoint_chain / bp_location array
3442 mechanism. This does not check for single-step breakpoints, which
3443 are inserted and removed using direct target manipulation. */
3446 regular_breakpoint_inserted_here_p (struct address_space *aspace,
3449 struct bp_location *bl, **blp_tmp;
3451 ALL_BP_LOCATIONS (bl, blp_tmp)
3453 if (bl->loc_type != bp_loc_software_breakpoint
3454 && bl->loc_type != bp_loc_hardware_breakpoint)
3458 && breakpoint_location_address_match (bl, aspace, pc))
3460 if (overlay_debugging
3461 && section_is_overlay (bl->section)
3462 && !section_is_mapped (bl->section))
3463 continue; /* unmapped overlay -- can't be a match */
3471 /* Returns non-zero iff there's either regular breakpoint
3472 or a single step breakpoint inserted at PC. */
3475 breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
3477 if (regular_breakpoint_inserted_here_p (aspace, pc))
3480 if (single_step_breakpoint_inserted_here_p (aspace, pc))
3486 /* This function returns non-zero iff there is a software breakpoint
3490 software_breakpoint_inserted_here_p (struct address_space *aspace,
3493 struct bp_location *bl, **blp_tmp;
3495 ALL_BP_LOCATIONS (bl, blp_tmp)
3497 if (bl->loc_type != bp_loc_software_breakpoint)
3501 && breakpoint_address_match (bl->pspace->aspace, bl->address,
3504 if (overlay_debugging
3505 && section_is_overlay (bl->section)
3506 && !section_is_mapped (bl->section))
3507 continue; /* unmapped overlay -- can't be a match */
3513 /* Also check for software single-step breakpoints. */
3514 if (single_step_breakpoint_inserted_here_p (aspace, pc))
3521 hardware_watchpoint_inserted_in_range (struct address_space *aspace,
3522 CORE_ADDR addr, ULONGEST len)
3524 struct breakpoint *bpt;
3526 ALL_BREAKPOINTS (bpt)
3528 struct bp_location *loc;
3530 if (bpt->type != bp_hardware_watchpoint
3531 && bpt->type != bp_access_watchpoint)
3534 if (!breakpoint_enabled (bpt))
3537 for (loc = bpt->loc; loc; loc = loc->next)
3538 if (loc->pspace->aspace == aspace && loc->inserted)
3542 /* Check for intersection. */
3543 l = max (loc->address, addr);
3544 h = min (loc->address + loc->length, addr + len);
3552 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
3553 PC is valid for process/thread PTID. */
3556 breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc,
3559 struct bp_location *bl, **blp_tmp;
3560 /* The thread and task IDs associated to PTID, computed lazily. */
3564 ALL_BP_LOCATIONS (bl, blp_tmp)
3566 if (bl->loc_type != bp_loc_software_breakpoint
3567 && bl->loc_type != bp_loc_hardware_breakpoint)
3570 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
3571 if (!breakpoint_enabled (bl->owner)
3572 && bl->owner->enable_state != bp_permanent)
3575 if (!breakpoint_location_address_match (bl, aspace, pc))
3578 if (bl->owner->thread != -1)
3580 /* This is a thread-specific breakpoint. Check that ptid
3581 matches that thread. If thread hasn't been computed yet,
3582 it is now time to do so. */
3584 thread = pid_to_thread_id (ptid);
3585 if (bl->owner->thread != thread)
3589 if (bl->owner->task != 0)
3591 /* This is a task-specific breakpoint. Check that ptid
3592 matches that task. If task hasn't been computed yet,
3593 it is now time to do so. */
3595 task = ada_get_task_number (ptid);
3596 if (bl->owner->task != task)
3600 if (overlay_debugging
3601 && section_is_overlay (bl->section)
3602 && !section_is_mapped (bl->section))
3603 continue; /* unmapped overlay -- can't be a match */
3612 /* bpstat stuff. External routines' interfaces are documented
3616 ep_is_catchpoint (struct breakpoint *ep)
3618 return (ep->type == bp_catchpoint);
3621 /* Frees any storage that is part of a bpstat. Does not walk the
3625 bpstat_free (bpstat bs)
3627 if (bs->old_val != NULL)
3628 value_free (bs->old_val);
3629 decref_counted_command_line (&bs->commands);
3630 decref_bp_location (&bs->bp_location_at);
3634 /* Clear a bpstat so that it says we are not at any breakpoint.
3635 Also free any storage that is part of a bpstat. */
3638 bpstat_clear (bpstat *bsp)
3655 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
3656 is part of the bpstat is copied as well. */
3659 bpstat_copy (bpstat bs)
3663 bpstat retval = NULL;
3668 for (; bs != NULL; bs = bs->next)
3670 tmp = (bpstat) xmalloc (sizeof (*tmp));
3671 memcpy (tmp, bs, sizeof (*tmp));
3672 incref_counted_command_line (tmp->commands);
3673 incref_bp_location (tmp->bp_location_at);
3674 if (bs->old_val != NULL)
3676 tmp->old_val = value_copy (bs->old_val);
3677 release_value (tmp->old_val);
3681 /* This is the first thing in the chain. */
3691 /* Find the bpstat associated with this breakpoint. */
3694 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
3699 for (; bsp != NULL; bsp = bsp->next)
3701 if (bsp->breakpoint_at == breakpoint)
3707 /* Put in *NUM the breakpoint number of the first breakpoint we are
3708 stopped at. *BSP upon return is a bpstat which points to the
3709 remaining breakpoints stopped at (but which is not guaranteed to be
3710 good for anything but further calls to bpstat_num).
3712 Return 0 if passed a bpstat which does not indicate any breakpoints.
3713 Return -1 if stopped at a breakpoint that has been deleted since
3715 Return 1 otherwise. */
3718 bpstat_num (bpstat *bsp, int *num)
3720 struct breakpoint *b;
3723 return 0; /* No more breakpoint values */
3725 /* We assume we'll never have several bpstats that correspond to a
3726 single breakpoint -- otherwise, this function might return the
3727 same number more than once and this will look ugly. */
3728 b = (*bsp)->breakpoint_at;
3729 *bsp = (*bsp)->next;
3731 return -1; /* breakpoint that's been deleted since */
3733 *num = b->number; /* We have its number */
3737 /* See breakpoint.h. */
3740 bpstat_clear_actions (void)
3742 struct thread_info *tp;
3745 if (ptid_equal (inferior_ptid, null_ptid))
3748 tp = find_thread_ptid (inferior_ptid);
3752 for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next)
3754 decref_counted_command_line (&bs->commands);
3756 if (bs->old_val != NULL)
3758 value_free (bs->old_val);
3764 /* Called when a command is about to proceed the inferior. */
3767 breakpoint_about_to_proceed (void)
3769 if (!ptid_equal (inferior_ptid, null_ptid))
3771 struct thread_info *tp = inferior_thread ();
3773 /* Allow inferior function calls in breakpoint commands to not
3774 interrupt the command list. When the call finishes
3775 successfully, the inferior will be standing at the same
3776 breakpoint as if nothing happened. */
3777 if (tp->control.in_infcall)
3781 breakpoint_proceeded = 1;
3784 /* Stub for cleaning up our state if we error-out of a breakpoint
3787 cleanup_executing_breakpoints (void *ignore)
3789 executing_breakpoint_commands = 0;
3792 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
3793 or its equivalent. */
3796 command_line_is_silent (struct command_line *cmd)
3798 return cmd && (strcmp ("silent", cmd->line) == 0
3799 || (xdb_commands && strcmp ("Q", cmd->line) == 0));
3802 /* Execute all the commands associated with all the breakpoints at
3803 this location. Any of these commands could cause the process to
3804 proceed beyond this point, etc. We look out for such changes by
3805 checking the global "breakpoint_proceeded" after each command.
3807 Returns true if a breakpoint command resumed the inferior. In that
3808 case, it is the caller's responsibility to recall it again with the
3809 bpstat of the current thread. */
3812 bpstat_do_actions_1 (bpstat *bsp)
3815 struct cleanup *old_chain;
3818 /* Avoid endless recursion if a `source' command is contained
3820 if (executing_breakpoint_commands)
3823 executing_breakpoint_commands = 1;
3824 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
3826 prevent_dont_repeat ();
3828 /* This pointer will iterate over the list of bpstat's. */
3831 breakpoint_proceeded = 0;
3832 for (; bs != NULL; bs = bs->next)
3834 struct counted_command_line *ccmd;
3835 struct command_line *cmd;
3836 struct cleanup *this_cmd_tree_chain;
3838 /* Take ownership of the BSP's command tree, if it has one.
3840 The command tree could legitimately contain commands like
3841 'step' and 'next', which call clear_proceed_status, which
3842 frees stop_bpstat's command tree. To make sure this doesn't
3843 free the tree we're executing out from under us, we need to
3844 take ownership of the tree ourselves. Since a given bpstat's
3845 commands are only executed once, we don't need to copy it; we
3846 can clear the pointer in the bpstat, and make sure we free
3847 the tree when we're done. */
3848 ccmd = bs->commands;
3849 bs->commands = NULL;
3850 this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd);
3851 cmd = ccmd ? ccmd->commands : NULL;
3852 if (command_line_is_silent (cmd))
3854 /* The action has been already done by bpstat_stop_status. */
3860 execute_control_command (cmd);
3862 if (breakpoint_proceeded)
3868 /* We can free this command tree now. */
3869 do_cleanups (this_cmd_tree_chain);
3871 if (breakpoint_proceeded)
3873 if (target_can_async_p ())
3874 /* If we are in async mode, then the target might be still
3875 running, not stopped at any breakpoint, so nothing for
3876 us to do here -- just return to the event loop. */
3879 /* In sync mode, when execute_control_command returns
3880 we're already standing on the next breakpoint.
3881 Breakpoint commands for that stop were not run, since
3882 execute_command does not run breakpoint commands --
3883 only command_line_handler does, but that one is not
3884 involved in execution of breakpoint commands. So, we
3885 can now execute breakpoint commands. It should be
3886 noted that making execute_command do bpstat actions is
3887 not an option -- in this case we'll have recursive
3888 invocation of bpstat for each breakpoint with a
3889 command, and can easily blow up GDB stack. Instead, we
3890 return true, which will trigger the caller to recall us
3891 with the new stop_bpstat. */
3896 do_cleanups (old_chain);
3901 bpstat_do_actions (void)
3903 struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup ();
3905 /* Do any commands attached to breakpoint we are stopped at. */
3906 while (!ptid_equal (inferior_ptid, null_ptid)
3907 && target_has_execution
3908 && !is_exited (inferior_ptid)
3909 && !is_executing (inferior_ptid))
3910 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3911 and only return when it is stopped at the next breakpoint, we
3912 keep doing breakpoint actions until it returns false to
3913 indicate the inferior was not resumed. */
3914 if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat))
3917 discard_cleanups (cleanup_if_error);
3920 /* Print out the (old or new) value associated with a watchpoint. */
3923 watchpoint_value_print (struct value *val, struct ui_file *stream)
3926 fprintf_unfiltered (stream, _("<unreadable>"));
3929 struct value_print_options opts;
3930 get_user_print_options (&opts);
3931 value_print (val, stream, &opts);
3935 /* Generic routine for printing messages indicating why we
3936 stopped. The behavior of this function depends on the value
3937 'print_it' in the bpstat structure. Under some circumstances we
3938 may decide not to print anything here and delegate the task to
3941 static enum print_stop_action
3942 print_bp_stop_message (bpstat bs)
3944 switch (bs->print_it)
3947 /* Nothing should be printed for this bpstat entry. */
3948 return PRINT_UNKNOWN;
3952 /* We still want to print the frame, but we already printed the
3953 relevant messages. */
3954 return PRINT_SRC_AND_LOC;
3957 case print_it_normal:
3959 struct breakpoint *b = bs->breakpoint_at;
3961 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3962 which has since been deleted. */
3964 return PRINT_UNKNOWN;
3966 /* Normal case. Call the breakpoint's print_it method. */
3967 return b->ops->print_it (bs);
3972 internal_error (__FILE__, __LINE__,
3973 _("print_bp_stop_message: unrecognized enum value"));
3978 /* A helper function that prints a shared library stopped event. */
3981 print_solib_event (int is_catchpoint)
3984 = !VEC_empty (char_ptr, current_program_space->deleted_solibs);
3986 = !VEC_empty (so_list_ptr, current_program_space->added_solibs);
3990 if (any_added || any_deleted)
3991 ui_out_text (current_uiout,
3992 _("Stopped due to shared library event:\n"));
3994 ui_out_text (current_uiout,
3995 _("Stopped due to shared library event (no "
3996 "libraries added or removed)\n"));
3999 if (ui_out_is_mi_like_p (current_uiout))
4000 ui_out_field_string (current_uiout, "reason",
4001 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT));
4005 struct cleanup *cleanup;
4009 ui_out_text (current_uiout, _(" Inferior unloaded "));
4010 cleanup = make_cleanup_ui_out_list_begin_end (current_uiout,
4013 VEC_iterate (char_ptr, current_program_space->deleted_solibs,
4018 ui_out_text (current_uiout, " ");
4019 ui_out_field_string (current_uiout, "library", name);
4020 ui_out_text (current_uiout, "\n");
4023 do_cleanups (cleanup);
4028 struct so_list *iter;
4030 struct cleanup *cleanup;
4032 ui_out_text (current_uiout, _(" Inferior loaded "));
4033 cleanup = make_cleanup_ui_out_list_begin_end (current_uiout,
4036 VEC_iterate (so_list_ptr, current_program_space->added_solibs,
4041 ui_out_text (current_uiout, " ");
4042 ui_out_field_string (current_uiout, "library", iter->so_name);
4043 ui_out_text (current_uiout, "\n");
4046 do_cleanups (cleanup);
4050 /* Print a message indicating what happened. This is called from
4051 normal_stop(). The input to this routine is the head of the bpstat
4052 list - a list of the eventpoints that caused this stop. KIND is
4053 the target_waitkind for the stopping event. This
4054 routine calls the generic print routine for printing a message
4055 about reasons for stopping. This will print (for example) the
4056 "Breakpoint n," part of the output. The return value of this
4059 PRINT_UNKNOWN: Means we printed nothing.
4060 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4061 code to print the location. An example is
4062 "Breakpoint 1, " which should be followed by
4064 PRINT_SRC_ONLY: Means we printed something, but there is no need
4065 to also print the location part of the message.
4066 An example is the catch/throw messages, which
4067 don't require a location appended to the end.
4068 PRINT_NOTHING: We have done some printing and we don't need any
4069 further info to be printed. */
4071 enum print_stop_action
4072 bpstat_print (bpstat bs, int kind)
4076 /* Maybe another breakpoint in the chain caused us to stop.
4077 (Currently all watchpoints go on the bpstat whether hit or not.
4078 That probably could (should) be changed, provided care is taken
4079 with respect to bpstat_explains_signal). */
4080 for (; bs; bs = bs->next)
4082 val = print_bp_stop_message (bs);
4083 if (val == PRINT_SRC_ONLY
4084 || val == PRINT_SRC_AND_LOC
4085 || val == PRINT_NOTHING)
4089 /* If we had hit a shared library event breakpoint,
4090 print_bp_stop_message would print out this message. If we hit an
4091 OS-level shared library event, do the same thing. */
4092 if (kind == TARGET_WAITKIND_LOADED)
4094 print_solib_event (0);
4095 return PRINT_NOTHING;
4098 /* We reached the end of the chain, or we got a null BS to start
4099 with and nothing was printed. */
4100 return PRINT_UNKNOWN;
4103 /* Evaluate the expression EXP and return 1 if value is zero. This is
4104 used inside a catch_errors to evaluate the breakpoint condition.
4105 The argument is a "struct expression *" that has been cast to a
4106 "char *" to make it pass through catch_errors. */
4109 breakpoint_cond_eval (void *exp)
4111 struct value *mark = value_mark ();
4112 int i = !value_true (evaluate_expression ((struct expression *) exp));
4114 value_free_to_mark (mark);
4118 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4121 bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer)
4125 bs = (bpstat) xmalloc (sizeof (*bs));
4127 **bs_link_pointer = bs;
4128 *bs_link_pointer = &bs->next;
4129 bs->breakpoint_at = bl->owner;
4130 bs->bp_location_at = bl;
4131 incref_bp_location (bl);
4132 /* If the condition is false, etc., don't do the commands. */
4133 bs->commands = NULL;
4135 bs->print_it = print_it_normal;
4139 /* The target has stopped with waitstatus WS. Check if any hardware
4140 watchpoints have triggered, according to the target. */
4143 watchpoints_triggered (struct target_waitstatus *ws)
4145 int stopped_by_watchpoint = target_stopped_by_watchpoint ();
4147 struct breakpoint *b;
4149 if (!stopped_by_watchpoint)
4151 /* We were not stopped by a watchpoint. Mark all watchpoints
4152 as not triggered. */
4154 if (is_hardware_watchpoint (b))
4156 struct watchpoint *w = (struct watchpoint *) b;
4158 w->watchpoint_triggered = watch_triggered_no;
4164 if (!target_stopped_data_address (¤t_target, &addr))
4166 /* We were stopped by a watchpoint, but we don't know where.
4167 Mark all watchpoints as unknown. */
4169 if (is_hardware_watchpoint (b))
4171 struct watchpoint *w = (struct watchpoint *) b;
4173 w->watchpoint_triggered = watch_triggered_unknown;
4176 return stopped_by_watchpoint;
4179 /* The target could report the data address. Mark watchpoints
4180 affected by this data address as triggered, and all others as not
4184 if (is_hardware_watchpoint (b))
4186 struct watchpoint *w = (struct watchpoint *) b;
4187 struct bp_location *loc;
4189 w->watchpoint_triggered = watch_triggered_no;
4190 for (loc = b->loc; loc; loc = loc->next)
4192 if (is_masked_watchpoint (b))
4194 CORE_ADDR newaddr = addr & w->hw_wp_mask;
4195 CORE_ADDR start = loc->address & w->hw_wp_mask;
4197 if (newaddr == start)
4199 w->watchpoint_triggered = watch_triggered_yes;
4203 /* Exact match not required. Within range is sufficient. */
4204 else if (target_watchpoint_addr_within_range (¤t_target,
4208 w->watchpoint_triggered = watch_triggered_yes;
4217 /* Possible return values for watchpoint_check (this can't be an enum
4218 because of check_errors). */
4219 /* The watchpoint has been deleted. */
4220 #define WP_DELETED 1
4221 /* The value has changed. */
4222 #define WP_VALUE_CHANGED 2
4223 /* The value has not changed. */
4224 #define WP_VALUE_NOT_CHANGED 3
4225 /* Ignore this watchpoint, no matter if the value changed or not. */
4228 #define BP_TEMPFLAG 1
4229 #define BP_HARDWAREFLAG 2
4231 /* Evaluate watchpoint condition expression and check if its value
4234 P should be a pointer to struct bpstat, but is defined as a void *
4235 in order for this function to be usable with catch_errors. */
4238 watchpoint_check (void *p)
4240 bpstat bs = (bpstat) p;
4241 struct watchpoint *b;
4242 struct frame_info *fr;
4243 int within_current_scope;
4245 /* BS is built from an existing struct breakpoint. */
4246 gdb_assert (bs->breakpoint_at != NULL);
4247 b = (struct watchpoint *) bs->breakpoint_at;
4249 /* If this is a local watchpoint, we only want to check if the
4250 watchpoint frame is in scope if the current thread is the thread
4251 that was used to create the watchpoint. */
4252 if (!watchpoint_in_thread_scope (b))
4255 if (b->exp_valid_block == NULL)
4256 within_current_scope = 1;
4259 struct frame_info *frame = get_current_frame ();
4260 struct gdbarch *frame_arch = get_frame_arch (frame);
4261 CORE_ADDR frame_pc = get_frame_pc (frame);
4263 /* in_function_epilogue_p() returns a non-zero value if we're
4264 still in the function but the stack frame has already been
4265 invalidated. Since we can't rely on the values of local
4266 variables after the stack has been destroyed, we are treating
4267 the watchpoint in that state as `not changed' without further
4268 checking. Don't mark watchpoints as changed if the current
4269 frame is in an epilogue - even if they are in some other
4270 frame, our view of the stack is likely to be wrong and
4271 frame_find_by_id could error out. */
4272 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
4275 fr = frame_find_by_id (b->watchpoint_frame);
4276 within_current_scope = (fr != NULL);
4278 /* If we've gotten confused in the unwinder, we might have
4279 returned a frame that can't describe this variable. */
4280 if (within_current_scope)
4282 struct symbol *function;
4284 function = get_frame_function (fr);
4285 if (function == NULL
4286 || !contained_in (b->exp_valid_block,
4287 SYMBOL_BLOCK_VALUE (function)))
4288 within_current_scope = 0;
4291 if (within_current_scope)
4292 /* If we end up stopping, the current frame will get selected
4293 in normal_stop. So this call to select_frame won't affect
4298 if (within_current_scope)
4300 /* We use value_{,free_to_}mark because it could be a *long*
4301 time before we return to the command level and call
4302 free_all_values. We can't call free_all_values because we
4303 might be in the middle of evaluating a function call. */
4307 struct value *new_val;
4309 if (is_masked_watchpoint (&b->base))
4310 /* Since we don't know the exact trigger address (from
4311 stopped_data_address), just tell the user we've triggered
4312 a mask watchpoint. */
4313 return WP_VALUE_CHANGED;
4315 mark = value_mark ();
4316 fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL);
4318 /* We use value_equal_contents instead of value_equal because
4319 the latter coerces an array to a pointer, thus comparing just
4320 the address of the array instead of its contents. This is
4321 not what we want. */
4322 if ((b->val != NULL) != (new_val != NULL)
4323 || (b->val != NULL && !value_equal_contents (b->val, new_val)))
4325 if (new_val != NULL)
4327 release_value (new_val);
4328 value_free_to_mark (mark);
4330 bs->old_val = b->val;
4333 return WP_VALUE_CHANGED;
4337 /* Nothing changed. */
4338 value_free_to_mark (mark);
4339 return WP_VALUE_NOT_CHANGED;
4344 struct ui_out *uiout = current_uiout;
4346 /* This seems like the only logical thing to do because
4347 if we temporarily ignored the watchpoint, then when
4348 we reenter the block in which it is valid it contains
4349 garbage (in the case of a function, it may have two
4350 garbage values, one before and one after the prologue).
4351 So we can't even detect the first assignment to it and
4352 watch after that (since the garbage may or may not equal
4353 the first value assigned). */
4354 /* We print all the stop information in
4355 breakpoint_ops->print_it, but in this case, by the time we
4356 call breakpoint_ops->print_it this bp will be deleted
4357 already. So we have no choice but print the information
4359 if (ui_out_is_mi_like_p (uiout))
4361 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
4362 ui_out_text (uiout, "\nWatchpoint ");
4363 ui_out_field_int (uiout, "wpnum", b->base.number);
4365 " deleted because the program has left the block in\n\
4366 which its expression is valid.\n");
4368 /* Make sure the watchpoint's commands aren't executed. */
4369 decref_counted_command_line (&b->base.commands);
4370 watchpoint_del_at_next_stop (b);
4376 /* Return true if it looks like target has stopped due to hitting
4377 breakpoint location BL. This function does not check if we should
4378 stop, only if BL explains the stop. */
4381 bpstat_check_location (const struct bp_location *bl,
4382 struct address_space *aspace, CORE_ADDR bp_addr,
4383 const struct target_waitstatus *ws)
4385 struct breakpoint *b = bl->owner;
4387 /* BL is from an existing breakpoint. */
4388 gdb_assert (b != NULL);
4390 return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws);
4393 /* Determine if the watched values have actually changed, and we
4394 should stop. If not, set BS->stop to 0. */
4397 bpstat_check_watchpoint (bpstat bs)
4399 const struct bp_location *bl;
4400 struct watchpoint *b;
4402 /* BS is built for existing struct breakpoint. */
4403 bl = bs->bp_location_at;
4404 gdb_assert (bl != NULL);
4405 b = (struct watchpoint *) bs->breakpoint_at;
4406 gdb_assert (b != NULL);
4409 int must_check_value = 0;
4411 if (b->base.type == bp_watchpoint)
4412 /* For a software watchpoint, we must always check the
4414 must_check_value = 1;
4415 else if (b->watchpoint_triggered == watch_triggered_yes)
4416 /* We have a hardware watchpoint (read, write, or access)
4417 and the target earlier reported an address watched by
4419 must_check_value = 1;
4420 else if (b->watchpoint_triggered == watch_triggered_unknown
4421 && b->base.type == bp_hardware_watchpoint)
4422 /* We were stopped by a hardware watchpoint, but the target could
4423 not report the data address. We must check the watchpoint's
4424 value. Access and read watchpoints are out of luck; without
4425 a data address, we can't figure it out. */
4426 must_check_value = 1;
4428 if (must_check_value)
4431 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
4433 struct cleanup *cleanups = make_cleanup (xfree, message);
4434 int e = catch_errors (watchpoint_check, bs, message,
4436 do_cleanups (cleanups);
4440 /* We've already printed what needs to be printed. */
4441 bs->print_it = print_it_done;
4445 bs->print_it = print_it_noop;
4448 case WP_VALUE_CHANGED:
4449 if (b->base.type == bp_read_watchpoint)
4451 /* There are two cases to consider here:
4453 1. We're watching the triggered memory for reads.
4454 In that case, trust the target, and always report
4455 the watchpoint hit to the user. Even though
4456 reads don't cause value changes, the value may
4457 have changed since the last time it was read, and
4458 since we're not trapping writes, we will not see
4459 those, and as such we should ignore our notion of
4462 2. We're watching the triggered memory for both
4463 reads and writes. There are two ways this may
4466 2.1. This is a target that can't break on data
4467 reads only, but can break on accesses (reads or
4468 writes), such as e.g., x86. We detect this case
4469 at the time we try to insert read watchpoints.
4471 2.2. Otherwise, the target supports read
4472 watchpoints, but, the user set an access or write
4473 watchpoint watching the same memory as this read
4476 If we're watching memory writes as well as reads,
4477 ignore watchpoint hits when we find that the
4478 value hasn't changed, as reads don't cause
4479 changes. This still gives false positives when
4480 the program writes the same value to memory as
4481 what there was already in memory (we will confuse
4482 it for a read), but it's much better than
4485 int other_write_watchpoint = 0;
4487 if (bl->watchpoint_type == hw_read)
4489 struct breakpoint *other_b;
4491 ALL_BREAKPOINTS (other_b)
4492 if (other_b->type == bp_hardware_watchpoint
4493 || other_b->type == bp_access_watchpoint)
4495 struct watchpoint *other_w =
4496 (struct watchpoint *) other_b;
4498 if (other_w->watchpoint_triggered
4499 == watch_triggered_yes)
4501 other_write_watchpoint = 1;
4507 if (other_write_watchpoint
4508 || bl->watchpoint_type == hw_access)
4510 /* We're watching the same memory for writes,
4511 and the value changed since the last time we
4512 updated it, so this trap must be for a write.
4514 bs->print_it = print_it_noop;
4519 case WP_VALUE_NOT_CHANGED:
4520 if (b->base.type == bp_hardware_watchpoint
4521 || b->base.type == bp_watchpoint)
4523 /* Don't stop: write watchpoints shouldn't fire if
4524 the value hasn't changed. */
4525 bs->print_it = print_it_noop;
4533 /* Error from catch_errors. */
4534 printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number);
4535 watchpoint_del_at_next_stop (b);
4536 /* We've already printed what needs to be printed. */
4537 bs->print_it = print_it_done;
4541 else /* must_check_value == 0 */
4543 /* This is a case where some watchpoint(s) triggered, but
4544 not at the address of this watchpoint, or else no
4545 watchpoint triggered after all. So don't print
4546 anything for this watchpoint. */
4547 bs->print_it = print_it_noop;
4554 /* Check conditions (condition proper, frame, thread and ignore count)
4555 of breakpoint referred to by BS. If we should not stop for this
4556 breakpoint, set BS->stop to 0. */
4559 bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
4561 int thread_id = pid_to_thread_id (ptid);
4562 const struct bp_location *bl;
4563 struct breakpoint *b;
4565 /* BS is built for existing struct breakpoint. */
4566 bl = bs->bp_location_at;
4567 gdb_assert (bl != NULL);
4568 b = bs->breakpoint_at;
4569 gdb_assert (b != NULL);
4571 /* Even if the target evaluated the condition on its end and notified GDB, we
4572 need to do so again since GDB does not know if we stopped due to a
4573 breakpoint or a single step breakpoint. */
4575 if (frame_id_p (b->frame_id)
4576 && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ())))
4580 int value_is_zero = 0;
4581 struct expression *cond;
4583 /* Evaluate Python breakpoints that have a "stop"
4584 method implemented. */
4585 if (b->py_bp_object)
4586 bs->stop = gdbpy_should_stop (b->py_bp_object);
4588 if (is_watchpoint (b))
4590 struct watchpoint *w = (struct watchpoint *) b;
4597 if (cond && b->disposition != disp_del_at_next_stop)
4599 int within_current_scope = 1;
4600 struct watchpoint * w;
4602 /* We use value_mark and value_free_to_mark because it could
4603 be a long time before we return to the command level and
4604 call free_all_values. We can't call free_all_values
4605 because we might be in the middle of evaluating a
4607 struct value *mark = value_mark ();
4609 if (is_watchpoint (b))
4610 w = (struct watchpoint *) b;
4614 /* Need to select the frame, with all that implies so that
4615 the conditions will have the right context. Because we
4616 use the frame, we will not see an inlined function's
4617 variables when we arrive at a breakpoint at the start
4618 of the inlined function; the current frame will be the
4620 if (w == NULL || w->cond_exp_valid_block == NULL)
4621 select_frame (get_current_frame ());
4624 struct frame_info *frame;
4626 /* For local watchpoint expressions, which particular
4627 instance of a local is being watched matters, so we
4628 keep track of the frame to evaluate the expression
4629 in. To evaluate the condition however, it doesn't
4630 really matter which instantiation of the function
4631 where the condition makes sense triggers the
4632 watchpoint. This allows an expression like "watch
4633 global if q > 10" set in `func', catch writes to
4634 global on all threads that call `func', or catch
4635 writes on all recursive calls of `func' by a single
4636 thread. We simply always evaluate the condition in
4637 the innermost frame that's executing where it makes
4638 sense to evaluate the condition. It seems
4640 frame = block_innermost_frame (w->cond_exp_valid_block);
4642 select_frame (frame);
4644 within_current_scope = 0;
4646 if (within_current_scope)
4648 = catch_errors (breakpoint_cond_eval, cond,
4649 "Error in testing breakpoint condition:\n",
4653 warning (_("Watchpoint condition cannot be tested "
4654 "in the current scope"));
4655 /* If we failed to set the right context for this
4656 watchpoint, unconditionally report it. */
4659 /* FIXME-someday, should give breakpoint #. */
4660 value_free_to_mark (mark);
4663 if (cond && value_is_zero)
4667 else if (b->thread != -1 && b->thread != thread_id)
4671 else if (b->ignore_count > 0)
4674 annotate_ignore_count_change ();
4676 /* Increase the hit count even though we don't stop. */
4678 observer_notify_breakpoint_modified (b);
4684 /* Get a bpstat associated with having just stopped at address
4685 BP_ADDR in thread PTID.
4687 Determine whether we stopped at a breakpoint, etc, or whether we
4688 don't understand this stop. Result is a chain of bpstat's such
4691 if we don't understand the stop, the result is a null pointer.
4693 if we understand why we stopped, the result is not null.
4695 Each element of the chain refers to a particular breakpoint or
4696 watchpoint at which we have stopped. (We may have stopped for
4697 several reasons concurrently.)
4699 Each element of the chain has valid next, breakpoint_at,
4700 commands, FIXME??? fields. */
4703 bpstat_stop_status (struct address_space *aspace,
4704 CORE_ADDR bp_addr, ptid_t ptid,
4705 const struct target_waitstatus *ws)
4707 struct breakpoint *b = NULL;
4708 struct bp_location *bl;
4709 struct bp_location *loc;
4710 /* First item of allocated bpstat's. */
4711 bpstat bs_head = NULL, *bs_link = &bs_head;
4712 /* Pointer to the last thing in the chain currently. */
4715 int need_remove_insert;
4718 /* First, build the bpstat chain with locations that explain a
4719 target stop, while being careful to not set the target running,
4720 as that may invalidate locations (in particular watchpoint
4721 locations are recreated). Resuming will happen here with
4722 breakpoint conditions or watchpoint expressions that include
4723 inferior function calls. */
4727 if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
4730 for (bl = b->loc; bl != NULL; bl = bl->next)
4732 /* For hardware watchpoints, we look only at the first
4733 location. The watchpoint_check function will work on the
4734 entire expression, not the individual locations. For
4735 read watchpoints, the watchpoints_triggered function has
4736 checked all locations already. */
4737 if (b->type == bp_hardware_watchpoint && bl != b->loc)
4740 if (bl->shlib_disabled)
4743 if (!bpstat_check_location (bl, aspace, bp_addr, ws))
4746 /* Come here if it's a watchpoint, or if the break address
4749 bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to
4752 /* Assume we stop. Should we find a watchpoint that is not
4753 actually triggered, or if the condition of the breakpoint
4754 evaluates as false, we'll reset 'stop' to 0. */
4758 /* If this is a scope breakpoint, mark the associated
4759 watchpoint as triggered so that we will handle the
4760 out-of-scope event. We'll get to the watchpoint next
4762 if (b->type == bp_watchpoint_scope && b->related_breakpoint != b)
4764 struct watchpoint *w = (struct watchpoint *) b->related_breakpoint;
4766 w->watchpoint_triggered = watch_triggered_yes;
4771 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
4773 if (breakpoint_location_address_match (loc, aspace, bp_addr))
4775 bs = bpstat_alloc (loc, &bs_link);
4776 /* For hits of moribund locations, we should just proceed. */
4779 bs->print_it = print_it_noop;
4783 /* A bit of special processing for shlib breakpoints. We need to
4784 process solib loading here, so that the lists of loaded and
4785 unloaded libraries are correct before we handle "catch load" and
4787 for (bs = bs_head; bs != NULL; bs = bs->next)
4789 if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event)
4791 handle_solib_event ();
4796 /* Now go through the locations that caused the target to stop, and
4797 check whether we're interested in reporting this stop to higher
4798 layers, or whether we should resume the target transparently. */
4802 for (bs = bs_head; bs != NULL; bs = bs->next)
4807 b = bs->breakpoint_at;
4808 b->ops->check_status (bs);
4811 bpstat_check_breakpoint_conditions (bs, ptid);
4816 observer_notify_breakpoint_modified (b);
4818 /* We will stop here. */
4819 if (b->disposition == disp_disable)
4821 --(b->enable_count);
4822 if (b->enable_count <= 0
4823 && b->enable_state != bp_permanent)
4824 b->enable_state = bp_disabled;
4829 bs->commands = b->commands;
4830 incref_counted_command_line (bs->commands);
4831 if (command_line_is_silent (bs->commands
4832 ? bs->commands->commands : NULL))
4838 /* Print nothing for this entry if we don't stop or don't
4840 if (!bs->stop || !bs->print)
4841 bs->print_it = print_it_noop;
4844 /* If we aren't stopping, the value of some hardware watchpoint may
4845 not have changed, but the intermediate memory locations we are
4846 watching may have. Don't bother if we're stopping; this will get
4848 need_remove_insert = 0;
4849 if (! bpstat_causes_stop (bs_head))
4850 for (bs = bs_head; bs != NULL; bs = bs->next)
4852 && bs->breakpoint_at
4853 && is_hardware_watchpoint (bs->breakpoint_at))
4855 struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at;
4857 update_watchpoint (w, 0 /* don't reparse. */);
4858 need_remove_insert = 1;
4861 if (need_remove_insert)
4862 update_global_location_list (1);
4863 else if (removed_any)
4864 update_global_location_list (0);
4870 handle_jit_event (void)
4872 struct frame_info *frame;
4873 struct gdbarch *gdbarch;
4875 /* Switch terminal for any messages produced by
4876 breakpoint_re_set. */
4877 target_terminal_ours_for_output ();
4879 frame = get_current_frame ();
4880 gdbarch = get_frame_arch (frame);
4882 jit_event_handler (gdbarch);
4884 target_terminal_inferior ();
4887 /* Handle an solib event by calling solib_add. */
4890 handle_solib_event (void)
4892 clear_program_space_solib_cache (current_inferior ()->pspace);
4894 /* Check for any newly added shared libraries if we're supposed to
4895 be adding them automatically. Switch terminal for any messages
4896 produced by breakpoint_re_set. */
4897 target_terminal_ours_for_output ();
4899 SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add);
4901 solib_add (NULL, 0, ¤t_target, auto_solib_add);
4903 target_terminal_inferior ();
4906 /* Prepare WHAT final decision for infrun. */
4908 /* Decide what infrun needs to do with this bpstat. */
4911 bpstat_what (bpstat bs_head)
4913 struct bpstat_what retval;
4917 retval.main_action = BPSTAT_WHAT_KEEP_CHECKING;
4918 retval.call_dummy = STOP_NONE;
4919 retval.is_longjmp = 0;
4921 for (bs = bs_head; bs != NULL; bs = bs->next)
4923 /* Extract this BS's action. After processing each BS, we check
4924 if its action overrides all we've seem so far. */
4925 enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING;
4928 if (bs->breakpoint_at == NULL)
4930 /* I suspect this can happen if it was a momentary
4931 breakpoint which has since been deleted. */
4935 bptype = bs->breakpoint_at->type;
4942 case bp_hardware_breakpoint:
4945 case bp_shlib_event:
4949 this_action = BPSTAT_WHAT_STOP_NOISY;
4951 this_action = BPSTAT_WHAT_STOP_SILENT;
4954 this_action = BPSTAT_WHAT_SINGLE;
4957 case bp_hardware_watchpoint:
4958 case bp_read_watchpoint:
4959 case bp_access_watchpoint:
4963 this_action = BPSTAT_WHAT_STOP_NOISY;
4965 this_action = BPSTAT_WHAT_STOP_SILENT;
4969 /* There was a watchpoint, but we're not stopping.
4970 This requires no further action. */
4975 this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME;
4976 retval.is_longjmp = bptype == bp_longjmp;
4978 case bp_longjmp_resume:
4979 case bp_exception_resume:
4980 this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME;
4981 retval.is_longjmp = bptype == bp_longjmp_resume;
4983 case bp_step_resume:
4985 this_action = BPSTAT_WHAT_STEP_RESUME;
4988 /* It is for the wrong frame. */
4989 this_action = BPSTAT_WHAT_SINGLE;
4992 case bp_hp_step_resume:
4994 this_action = BPSTAT_WHAT_HP_STEP_RESUME;
4997 /* It is for the wrong frame. */
4998 this_action = BPSTAT_WHAT_SINGLE;
5001 case bp_watchpoint_scope:
5002 case bp_thread_event:
5003 case bp_overlay_event:
5004 case bp_longjmp_master:
5005 case bp_std_terminate_master:
5006 case bp_exception_master:
5007 this_action = BPSTAT_WHAT_SINGLE;
5013 this_action = BPSTAT_WHAT_STOP_NOISY;
5015 this_action = BPSTAT_WHAT_STOP_SILENT;
5019 /* There was a catchpoint, but we're not stopping.
5020 This requires no further action. */
5025 this_action = BPSTAT_WHAT_SINGLE;
5028 /* Make sure the action is stop (silent or noisy),
5029 so infrun.c pops the dummy frame. */
5030 retval.call_dummy = STOP_STACK_DUMMY;
5031 this_action = BPSTAT_WHAT_STOP_SILENT;
5033 case bp_std_terminate:
5034 /* Make sure the action is stop (silent or noisy),
5035 so infrun.c pops the dummy frame. */
5036 retval.call_dummy = STOP_STD_TERMINATE;
5037 this_action = BPSTAT_WHAT_STOP_SILENT;
5040 case bp_fast_tracepoint:
5041 case bp_static_tracepoint:
5042 /* Tracepoint hits should not be reported back to GDB, and
5043 if one got through somehow, it should have been filtered
5045 internal_error (__FILE__, __LINE__,
5046 _("bpstat_what: tracepoint encountered"));
5048 case bp_gnu_ifunc_resolver:
5049 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5050 this_action = BPSTAT_WHAT_SINGLE;
5052 case bp_gnu_ifunc_resolver_return:
5053 /* The breakpoint will be removed, execution will restart from the
5054 PC of the former breakpoint. */
5055 this_action = BPSTAT_WHAT_KEEP_CHECKING;
5058 internal_error (__FILE__, __LINE__,
5059 _("bpstat_what: unhandled bptype %d"), (int) bptype);
5062 retval.main_action = max (retval.main_action, this_action);
5065 /* These operations may affect the bs->breakpoint_at state so they are
5066 delayed after MAIN_ACTION is decided above. */
5071 fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n");
5073 handle_jit_event ();
5076 for (bs = bs_head; bs != NULL; bs = bs->next)
5078 struct breakpoint *b = bs->breakpoint_at;
5084 case bp_gnu_ifunc_resolver:
5085 gnu_ifunc_resolver_stop (b);
5087 case bp_gnu_ifunc_resolver_return:
5088 gnu_ifunc_resolver_return_stop (b);
5096 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5097 without hardware support). This isn't related to a specific bpstat,
5098 just to things like whether watchpoints are set. */
5101 bpstat_should_step (void)
5103 struct breakpoint *b;
5106 if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL)
5112 bpstat_causes_stop (bpstat bs)
5114 for (; bs != NULL; bs = bs->next)
5123 /* Compute a string of spaces suitable to indent the next line
5124 so it starts at the position corresponding to the table column
5125 named COL_NAME in the currently active table of UIOUT. */
5128 wrap_indent_at_field (struct ui_out *uiout, const char *col_name)
5130 static char wrap_indent[80];
5131 int i, total_width, width, align;
5135 for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++)
5137 if (strcmp (text, col_name) == 0)
5139 gdb_assert (total_width < sizeof wrap_indent);
5140 memset (wrap_indent, ' ', total_width);
5141 wrap_indent[total_width] = 0;
5146 total_width += width + 1;
5152 /* Determine if the locations of this breakpoint will have their conditions
5153 evaluated by the target, host or a mix of both. Returns the following:
5155 "host": Host evals condition.
5156 "host or target": Host or Target evals condition.
5157 "target": Target evals condition.
5161 bp_condition_evaluator (struct breakpoint *b)
5163 struct bp_location *bl;
5164 char host_evals = 0;
5165 char target_evals = 0;
5170 if (!is_breakpoint (b))
5173 if (gdb_evaluates_breakpoint_condition_p ()
5174 || !target_supports_evaluation_of_breakpoint_conditions ())
5175 return condition_evaluation_host;
5177 for (bl = b->loc; bl; bl = bl->next)
5179 if (bl->cond_bytecode)
5185 if (host_evals && target_evals)
5186 return condition_evaluation_both;
5187 else if (target_evals)
5188 return condition_evaluation_target;
5190 return condition_evaluation_host;
5193 /* Determine the breakpoint location's condition evaluator. This is
5194 similar to bp_condition_evaluator, but for locations. */
5197 bp_location_condition_evaluator (struct bp_location *bl)
5199 if (bl && !is_breakpoint (bl->owner))
5202 if (gdb_evaluates_breakpoint_condition_p ()
5203 || !target_supports_evaluation_of_breakpoint_conditions ())
5204 return condition_evaluation_host;
5206 if (bl && bl->cond_bytecode)
5207 return condition_evaluation_target;
5209 return condition_evaluation_host;
5212 /* Print the LOC location out of the list of B->LOC locations. */
5215 print_breakpoint_location (struct breakpoint *b,
5216 struct bp_location *loc)
5218 struct ui_out *uiout = current_uiout;
5219 struct cleanup *old_chain = save_current_program_space ();
5221 if (loc != NULL && loc->shlib_disabled)
5225 set_current_program_space (loc->pspace);
5227 if (b->display_canonical)
5228 ui_out_field_string (uiout, "what", b->addr_string);
5229 else if (loc && loc->source_file)
5232 = find_pc_sect_function (loc->address, loc->section);
5235 ui_out_text (uiout, "in ");
5236 ui_out_field_string (uiout, "func",
5237 SYMBOL_PRINT_NAME (sym));
5238 ui_out_text (uiout, " ");
5239 ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what"));
5240 ui_out_text (uiout, "at ");
5242 ui_out_field_string (uiout, "file", loc->source_file);
5243 ui_out_text (uiout, ":");
5245 if (ui_out_is_mi_like_p (uiout))
5247 struct symtab_and_line sal = find_pc_line (loc->address, 0);
5248 char *fullname = symtab_to_fullname (sal.symtab);
5251 ui_out_field_string (uiout, "fullname", fullname);
5254 ui_out_field_int (uiout, "line", loc->line_number);
5258 struct ui_stream *stb = ui_out_stream_new (uiout);
5259 struct cleanup *stb_chain = make_cleanup_ui_out_stream_delete (stb);
5261 print_address_symbolic (loc->gdbarch, loc->address, stb->stream,
5263 ui_out_field_stream (uiout, "at", stb);
5265 do_cleanups (stb_chain);
5268 ui_out_field_string (uiout, "pending", b->addr_string);
5270 if (loc && is_breakpoint (b)
5271 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
5272 && bp_condition_evaluator (b) == condition_evaluation_both)
5274 ui_out_text (uiout, " (");
5275 ui_out_field_string (uiout, "evaluated-by",
5276 bp_location_condition_evaluator (loc));
5277 ui_out_text (uiout, ")");
5280 do_cleanups (old_chain);
5284 bptype_string (enum bptype type)
5286 struct ep_type_description
5291 static struct ep_type_description bptypes[] =
5293 {bp_none, "?deleted?"},
5294 {bp_breakpoint, "breakpoint"},
5295 {bp_hardware_breakpoint, "hw breakpoint"},
5296 {bp_until, "until"},
5297 {bp_finish, "finish"},
5298 {bp_watchpoint, "watchpoint"},
5299 {bp_hardware_watchpoint, "hw watchpoint"},
5300 {bp_read_watchpoint, "read watchpoint"},
5301 {bp_access_watchpoint, "acc watchpoint"},
5302 {bp_longjmp, "longjmp"},
5303 {bp_longjmp_resume, "longjmp resume"},
5304 {bp_exception, "exception"},
5305 {bp_exception_resume, "exception resume"},
5306 {bp_step_resume, "step resume"},
5307 {bp_hp_step_resume, "high-priority step resume"},
5308 {bp_watchpoint_scope, "watchpoint scope"},
5309 {bp_call_dummy, "call dummy"},
5310 {bp_std_terminate, "std::terminate"},
5311 {bp_shlib_event, "shlib events"},
5312 {bp_thread_event, "thread events"},
5313 {bp_overlay_event, "overlay events"},
5314 {bp_longjmp_master, "longjmp master"},
5315 {bp_std_terminate_master, "std::terminate master"},
5316 {bp_exception_master, "exception master"},
5317 {bp_catchpoint, "catchpoint"},
5318 {bp_tracepoint, "tracepoint"},
5319 {bp_fast_tracepoint, "fast tracepoint"},
5320 {bp_static_tracepoint, "static tracepoint"},
5321 {bp_jit_event, "jit events"},
5322 {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"},
5323 {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"},
5326 if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0])))
5327 || ((int) type != bptypes[(int) type].type))
5328 internal_error (__FILE__, __LINE__,
5329 _("bptypes table does not describe type #%d."),
5332 return bptypes[(int) type].description;
5335 /* Print B to gdb_stdout. */
5338 print_one_breakpoint_location (struct breakpoint *b,
5339 struct bp_location *loc,
5341 struct bp_location **last_loc,
5344 struct command_line *l;
5345 static char bpenables[] = "nynny";
5347 struct ui_out *uiout = current_uiout;
5348 int header_of_multiple = 0;
5349 int part_of_multiple = (loc != NULL);
5350 struct value_print_options opts;
5352 get_user_print_options (&opts);
5354 gdb_assert (!loc || loc_number != 0);
5355 /* See comment in print_one_breakpoint concerning treatment of
5356 breakpoints with single disabled location. */
5359 && (b->loc->next != NULL || !b->loc->enabled)))
5360 header_of_multiple = 1;
5368 if (part_of_multiple)
5371 formatted = xstrprintf ("%d.%d", b->number, loc_number);
5372 ui_out_field_string (uiout, "number", formatted);
5377 ui_out_field_int (uiout, "number", b->number);
5382 if (part_of_multiple)
5383 ui_out_field_skip (uiout, "type");
5385 ui_out_field_string (uiout, "type", bptype_string (b->type));
5389 if (part_of_multiple)
5390 ui_out_field_skip (uiout, "disp");
5392 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
5397 if (part_of_multiple)
5398 ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n");
5400 ui_out_field_fmt (uiout, "enabled", "%c",
5401 bpenables[(int) b->enable_state]);
5402 ui_out_spaces (uiout, 2);
5406 if (b->ops != NULL && b->ops->print_one != NULL)
5408 /* Although the print_one can possibly print all locations,
5409 calling it here is not likely to get any nice result. So,
5410 make sure there's just one location. */
5411 gdb_assert (b->loc == NULL || b->loc->next == NULL);
5412 b->ops->print_one (b, last_loc);
5418 internal_error (__FILE__, __LINE__,
5419 _("print_one_breakpoint: bp_none encountered\n"));
5423 case bp_hardware_watchpoint:
5424 case bp_read_watchpoint:
5425 case bp_access_watchpoint:
5427 struct watchpoint *w = (struct watchpoint *) b;
5429 /* Field 4, the address, is omitted (which makes the columns
5430 not line up too nicely with the headers, but the effect
5431 is relatively readable). */
5432 if (opts.addressprint)
5433 ui_out_field_skip (uiout, "addr");
5435 ui_out_field_string (uiout, "what", w->exp_string);
5440 case bp_hardware_breakpoint:
5444 case bp_longjmp_resume:
5446 case bp_exception_resume:
5447 case bp_step_resume:
5448 case bp_hp_step_resume:
5449 case bp_watchpoint_scope:
5451 case bp_std_terminate:
5452 case bp_shlib_event:
5453 case bp_thread_event:
5454 case bp_overlay_event:
5455 case bp_longjmp_master:
5456 case bp_std_terminate_master:
5457 case bp_exception_master:
5459 case bp_fast_tracepoint:
5460 case bp_static_tracepoint:
5462 case bp_gnu_ifunc_resolver:
5463 case bp_gnu_ifunc_resolver_return:
5464 if (opts.addressprint)
5467 if (header_of_multiple)
5468 ui_out_field_string (uiout, "addr", "<MULTIPLE>");
5469 else if (b->loc == NULL || loc->shlib_disabled)
5470 ui_out_field_string (uiout, "addr", "<PENDING>");
5472 ui_out_field_core_addr (uiout, "addr",
5473 loc->gdbarch, loc->address);
5476 if (!header_of_multiple)
5477 print_breakpoint_location (b, loc);
5484 /* For backward compatibility, don't display inferiors unless there
5487 && !header_of_multiple
5489 || (!gdbarch_has_global_breakpoints (target_gdbarch)
5490 && (number_of_program_spaces () > 1
5491 || number_of_inferiors () > 1)
5492 /* LOC is for existing B, it cannot be in
5493 moribund_locations and thus having NULL OWNER. */
5494 && loc->owner->type != bp_catchpoint)))
5496 struct inferior *inf;
5499 for (inf = inferior_list; inf != NULL; inf = inf->next)
5501 if (inf->pspace == loc->pspace)
5506 ui_out_text (uiout, " inf ");
5509 ui_out_text (uiout, ", ");
5510 ui_out_text (uiout, plongest (inf->num));
5515 if (!part_of_multiple)
5517 if (b->thread != -1)
5519 /* FIXME: This seems to be redundant and lost here; see the
5520 "stop only in" line a little further down. */
5521 ui_out_text (uiout, " thread ");
5522 ui_out_field_int (uiout, "thread", b->thread);
5524 else if (b->task != 0)
5526 ui_out_text (uiout, " task ");
5527 ui_out_field_int (uiout, "task", b->task);
5531 ui_out_text (uiout, "\n");
5533 if (!part_of_multiple)
5534 b->ops->print_one_detail (b, uiout);
5536 if (part_of_multiple && frame_id_p (b->frame_id))
5539 ui_out_text (uiout, "\tstop only in stack frame at ");
5540 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
5542 ui_out_field_core_addr (uiout, "frame",
5543 b->gdbarch, b->frame_id.stack_addr);
5544 ui_out_text (uiout, "\n");
5547 if (!part_of_multiple && b->cond_string)
5550 if (is_tracepoint (b))
5551 ui_out_text (uiout, "\ttrace only if ");
5553 ui_out_text (uiout, "\tstop only if ");
5554 ui_out_field_string (uiout, "cond", b->cond_string);
5556 /* Print whether the target is doing the breakpoint's condition
5557 evaluation. If GDB is doing the evaluation, don't print anything. */
5558 if (is_breakpoint (b)
5559 && breakpoint_condition_evaluation_mode ()
5560 == condition_evaluation_target)
5562 ui_out_text (uiout, " (");
5563 ui_out_field_string (uiout, "evaluated-by",
5564 bp_condition_evaluator (b));
5565 ui_out_text (uiout, " evals)");
5567 ui_out_text (uiout, "\n");
5570 if (!part_of_multiple && b->thread != -1)
5572 /* FIXME should make an annotation for this. */
5573 ui_out_text (uiout, "\tstop only in thread ");
5574 ui_out_field_int (uiout, "thread", b->thread);
5575 ui_out_text (uiout, "\n");
5578 if (!part_of_multiple && b->hit_count)
5580 /* FIXME should make an annotation for this. */
5581 if (ep_is_catchpoint (b))
5582 ui_out_text (uiout, "\tcatchpoint");
5583 else if (is_tracepoint (b))
5584 ui_out_text (uiout, "\ttracepoint");
5586 ui_out_text (uiout, "\tbreakpoint");
5587 ui_out_text (uiout, " already hit ");
5588 ui_out_field_int (uiout, "times", b->hit_count);
5589 if (b->hit_count == 1)
5590 ui_out_text (uiout, " time\n");
5592 ui_out_text (uiout, " times\n");
5595 /* Output the count also if it is zero, but only if this is mi.
5596 FIXME: Should have a better test for this. */
5597 if (ui_out_is_mi_like_p (uiout))
5598 if (!part_of_multiple && b->hit_count == 0)
5599 ui_out_field_int (uiout, "times", b->hit_count);
5601 if (!part_of_multiple && b->ignore_count)
5604 ui_out_text (uiout, "\tignore next ");
5605 ui_out_field_int (uiout, "ignore", b->ignore_count);
5606 ui_out_text (uiout, " hits\n");
5609 /* Note that an enable count of 1 corresponds to "enable once"
5610 behavior, which is reported by the combination of enablement and
5611 disposition, so we don't need to mention it here. */
5612 if (!part_of_multiple && b->enable_count > 1)
5615 ui_out_text (uiout, "\tdisable after ");
5616 /* Tweak the wording to clarify that ignore and enable counts
5617 are distinct, and have additive effect. */
5618 if (b->ignore_count)
5619 ui_out_text (uiout, "additional ");
5621 ui_out_text (uiout, "next ");
5622 ui_out_field_int (uiout, "enable", b->enable_count);
5623 ui_out_text (uiout, " hits\n");
5626 if (!part_of_multiple && is_tracepoint (b))
5628 struct tracepoint *tp = (struct tracepoint *) b;
5630 if (tp->traceframe_usage)
5632 ui_out_text (uiout, "\ttrace buffer usage ");
5633 ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage);
5634 ui_out_text (uiout, " bytes\n");
5638 l = b->commands ? b->commands->commands : NULL;
5639 if (!part_of_multiple && l)
5641 struct cleanup *script_chain;
5644 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
5645 print_command_lines (uiout, l, 4);
5646 do_cleanups (script_chain);
5649 if (is_tracepoint (b))
5651 struct tracepoint *t = (struct tracepoint *) b;
5653 if (!part_of_multiple && t->pass_count)
5655 annotate_field (10);
5656 ui_out_text (uiout, "\tpass count ");
5657 ui_out_field_int (uiout, "pass", t->pass_count);
5658 ui_out_text (uiout, " \n");
5662 if (ui_out_is_mi_like_p (uiout) && !part_of_multiple)
5664 if (is_watchpoint (b))
5666 struct watchpoint *w = (struct watchpoint *) b;
5668 ui_out_field_string (uiout, "original-location", w->exp_string);
5670 else if (b->addr_string)
5671 ui_out_field_string (uiout, "original-location", b->addr_string);
5676 print_one_breakpoint (struct breakpoint *b,
5677 struct bp_location **last_loc,
5680 struct cleanup *bkpt_chain;
5681 struct ui_out *uiout = current_uiout;
5683 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
5685 print_one_breakpoint_location (b, NULL, 0, last_loc, allflag);
5686 do_cleanups (bkpt_chain);
5688 /* If this breakpoint has custom print function,
5689 it's already printed. Otherwise, print individual
5690 locations, if any. */
5691 if (b->ops == NULL || b->ops->print_one == NULL)
5693 /* If breakpoint has a single location that is disabled, we
5694 print it as if it had several locations, since otherwise it's
5695 hard to represent "breakpoint enabled, location disabled"
5698 Note that while hardware watchpoints have several locations
5699 internally, that's not a property exposed to user. */
5701 && !is_hardware_watchpoint (b)
5702 && (b->loc->next || !b->loc->enabled))
5704 struct bp_location *loc;
5707 for (loc = b->loc; loc; loc = loc->next, ++n)
5709 struct cleanup *inner2 =
5710 make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
5711 print_one_breakpoint_location (b, loc, n, last_loc, allflag);
5712 do_cleanups (inner2);
5719 breakpoint_address_bits (struct breakpoint *b)
5721 int print_address_bits = 0;
5722 struct bp_location *loc;
5724 for (loc = b->loc; loc; loc = loc->next)
5728 /* Software watchpoints that aren't watching memory don't have
5729 an address to print. */
5730 if (b->type == bp_watchpoint && loc->watchpoint_type == -1)
5733 addr_bit = gdbarch_addr_bit (loc->gdbarch);
5734 if (addr_bit > print_address_bits)
5735 print_address_bits = addr_bit;
5738 return print_address_bits;
5741 struct captured_breakpoint_query_args
5747 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
5749 struct captured_breakpoint_query_args *args = data;
5750 struct breakpoint *b;
5751 struct bp_location *dummy_loc = NULL;
5755 if (args->bnum == b->number)
5757 print_one_breakpoint (b, &dummy_loc, 0);
5765 gdb_breakpoint_query (struct ui_out *uiout, int bnum,
5766 char **error_message)
5768 struct captured_breakpoint_query_args args;
5771 /* For the moment we don't trust print_one_breakpoint() to not throw
5773 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
5774 error_message, RETURN_MASK_ALL) < 0)
5780 /* Return true if this breakpoint was set by the user, false if it is
5781 internal or momentary. */
5784 user_breakpoint_p (struct breakpoint *b)
5786 return b->number > 0;
5789 /* Print information on user settable breakpoint (watchpoint, etc)
5790 number BNUM. If BNUM is -1 print all user-settable breakpoints.
5791 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
5792 FILTER is non-NULL, call it on each breakpoint and only include the
5793 ones for which it returns non-zero. Return the total number of
5794 breakpoints listed. */
5797 breakpoint_1 (char *args, int allflag,
5798 int (*filter) (const struct breakpoint *))
5800 struct breakpoint *b;
5801 struct bp_location *last_loc = NULL;
5802 int nr_printable_breakpoints;
5803 struct cleanup *bkpttbl_chain;
5804 struct value_print_options opts;
5805 int print_address_bits = 0;
5806 int print_type_col_width = 14;
5807 struct ui_out *uiout = current_uiout;
5809 get_user_print_options (&opts);
5811 /* Compute the number of rows in the table, as well as the size
5812 required for address fields. */
5813 nr_printable_breakpoints = 0;
5816 /* If we have a filter, only list the breakpoints it accepts. */
5817 if (filter && !filter (b))
5820 /* If we have an "args" string, it is a list of breakpoints to
5821 accept. Skip the others. */
5822 if (args != NULL && *args != '\0')
5824 if (allflag && parse_and_eval_long (args) != b->number)
5826 if (!allflag && !number_is_in_list (args, b->number))
5830 if (allflag || user_breakpoint_p (b))
5832 int addr_bit, type_len;
5834 addr_bit = breakpoint_address_bits (b);
5835 if (addr_bit > print_address_bits)
5836 print_address_bits = addr_bit;
5838 type_len = strlen (bptype_string (b->type));
5839 if (type_len > print_type_col_width)
5840 print_type_col_width = type_len;
5842 nr_printable_breakpoints++;
5846 if (opts.addressprint)
5848 = make_cleanup_ui_out_table_begin_end (uiout, 6,
5849 nr_printable_breakpoints,
5853 = make_cleanup_ui_out_table_begin_end (uiout, 5,
5854 nr_printable_breakpoints,
5857 if (nr_printable_breakpoints > 0)
5858 annotate_breakpoints_headers ();
5859 if (nr_printable_breakpoints > 0)
5861 ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */
5862 if (nr_printable_breakpoints > 0)
5864 ui_out_table_header (uiout, print_type_col_width, ui_left,
5865 "type", "Type"); /* 2 */
5866 if (nr_printable_breakpoints > 0)
5868 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
5869 if (nr_printable_breakpoints > 0)
5871 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
5872 if (opts.addressprint)
5874 if (nr_printable_breakpoints > 0)
5876 if (print_address_bits <= 32)
5877 ui_out_table_header (uiout, 10, ui_left,
5878 "addr", "Address"); /* 5 */
5880 ui_out_table_header (uiout, 18, ui_left,
5881 "addr", "Address"); /* 5 */
5883 if (nr_printable_breakpoints > 0)
5885 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
5886 ui_out_table_body (uiout);
5887 if (nr_printable_breakpoints > 0)
5888 annotate_breakpoints_table ();
5893 /* If we have a filter, only list the breakpoints it accepts. */
5894 if (filter && !filter (b))
5897 /* If we have an "args" string, it is a list of breakpoints to
5898 accept. Skip the others. */
5900 if (args != NULL && *args != '\0')
5902 if (allflag) /* maintenance info breakpoint */
5904 if (parse_and_eval_long (args) != b->number)
5907 else /* all others */
5909 if (!number_is_in_list (args, b->number))
5913 /* We only print out user settable breakpoints unless the
5915 if (allflag || user_breakpoint_p (b))
5916 print_one_breakpoint (b, &last_loc, allflag);
5919 do_cleanups (bkpttbl_chain);
5921 if (nr_printable_breakpoints == 0)
5923 /* If there's a filter, let the caller decide how to report
5927 if (args == NULL || *args == '\0')
5928 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
5930 ui_out_message (uiout, 0,
5931 "No breakpoint or watchpoint matching '%s'.\n",
5937 if (last_loc && !server_command)
5938 set_next_address (last_loc->gdbarch, last_loc->address);
5941 /* FIXME? Should this be moved up so that it is only called when
5942 there have been breakpoints? */
5943 annotate_breakpoints_table_end ();
5945 return nr_printable_breakpoints;
5948 /* Display the value of default-collect in a way that is generally
5949 compatible with the breakpoint list. */
5952 default_collect_info (void)
5954 struct ui_out *uiout = current_uiout;
5956 /* If it has no value (which is frequently the case), say nothing; a
5957 message like "No default-collect." gets in user's face when it's
5959 if (!*default_collect)
5962 /* The following phrase lines up nicely with per-tracepoint collect
5964 ui_out_text (uiout, "default collect ");
5965 ui_out_field_string (uiout, "default-collect", default_collect);
5966 ui_out_text (uiout, " \n");
5970 breakpoints_info (char *args, int from_tty)
5972 breakpoint_1 (args, 0, NULL);
5974 default_collect_info ();
5978 watchpoints_info (char *args, int from_tty)
5980 int num_printed = breakpoint_1 (args, 0, is_watchpoint);
5981 struct ui_out *uiout = current_uiout;
5983 if (num_printed == 0)
5985 if (args == NULL || *args == '\0')
5986 ui_out_message (uiout, 0, "No watchpoints.\n");
5988 ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args);
5993 maintenance_info_breakpoints (char *args, int from_tty)
5995 breakpoint_1 (args, 1, NULL);
5997 default_collect_info ();
6001 breakpoint_has_pc (struct breakpoint *b,
6002 struct program_space *pspace,
6003 CORE_ADDR pc, struct obj_section *section)
6005 struct bp_location *bl = b->loc;
6007 for (; bl; bl = bl->next)
6009 if (bl->pspace == pspace
6010 && bl->address == pc
6011 && (!overlay_debugging || bl->section == section))
6017 /* Print a message describing any user-breakpoints set at PC. This
6018 concerns with logical breakpoints, so we match program spaces, not
6022 describe_other_breakpoints (struct gdbarch *gdbarch,
6023 struct program_space *pspace, CORE_ADDR pc,
6024 struct obj_section *section, int thread)
6027 struct breakpoint *b;
6030 others += (user_breakpoint_p (b)
6031 && breakpoint_has_pc (b, pspace, pc, section));
6035 printf_filtered (_("Note: breakpoint "));
6036 else /* if (others == ???) */
6037 printf_filtered (_("Note: breakpoints "));
6039 if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section))
6042 printf_filtered ("%d", b->number);
6043 if (b->thread == -1 && thread != -1)
6044 printf_filtered (" (all threads)");
6045 else if (b->thread != -1)
6046 printf_filtered (" (thread %d)", b->thread);
6047 printf_filtered ("%s%s ",
6048 ((b->enable_state == bp_disabled
6049 || b->enable_state == bp_call_disabled)
6051 : b->enable_state == bp_permanent
6055 : ((others == 1) ? " and" : ""));
6057 printf_filtered (_("also set at pc "));
6058 fputs_filtered (paddress (gdbarch, pc), gdb_stdout);
6059 printf_filtered (".\n");
6064 /* Return true iff it is meaningful to use the address member of
6065 BPT. For some breakpoint types, the address member is irrelevant
6066 and it makes no sense to attempt to compare it to other addresses
6067 (or use it for any other purpose either).
6069 More specifically, each of the following breakpoint types will
6070 always have a zero valued address and we don't want to mark
6071 breakpoints of any of these types to be a duplicate of an actual
6072 breakpoint at address zero:
6080 breakpoint_address_is_meaningful (struct breakpoint *bpt)
6082 enum bptype type = bpt->type;
6084 return (type != bp_watchpoint && type != bp_catchpoint);
6087 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6088 true if LOC1 and LOC2 represent the same watchpoint location. */
6091 watchpoint_locations_match (struct bp_location *loc1,
6092 struct bp_location *loc2)
6094 struct watchpoint *w1 = (struct watchpoint *) loc1->owner;
6095 struct watchpoint *w2 = (struct watchpoint *) loc2->owner;
6097 /* Both of them must exist. */
6098 gdb_assert (w1 != NULL);
6099 gdb_assert (w2 != NULL);
6101 /* If the target can evaluate the condition expression in hardware,
6102 then we we need to insert both watchpoints even if they are at
6103 the same place. Otherwise the watchpoint will only trigger when
6104 the condition of whichever watchpoint was inserted evaluates to
6105 true, not giving a chance for GDB to check the condition of the
6106 other watchpoint. */
6108 && target_can_accel_watchpoint_condition (loc1->address,
6110 loc1->watchpoint_type,
6113 && target_can_accel_watchpoint_condition (loc2->address,
6115 loc2->watchpoint_type,
6119 /* Note that this checks the owner's type, not the location's. In
6120 case the target does not support read watchpoints, but does
6121 support access watchpoints, we'll have bp_read_watchpoint
6122 watchpoints with hw_access locations. Those should be considered
6123 duplicates of hw_read locations. The hw_read locations will
6124 become hw_access locations later. */
6125 return (loc1->owner->type == loc2->owner->type
6126 && loc1->pspace->aspace == loc2->pspace->aspace
6127 && loc1->address == loc2->address
6128 && loc1->length == loc2->length);
6131 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
6132 same breakpoint location. In most targets, this can only be true
6133 if ASPACE1 matches ASPACE2. On targets that have global
6134 breakpoints, the address space doesn't really matter. */
6137 breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1,
6138 struct address_space *aspace2, CORE_ADDR addr2)
6140 return ((gdbarch_has_global_breakpoints (target_gdbarch)
6141 || aspace1 == aspace2)
6145 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6146 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6147 matches ASPACE2. On targets that have global breakpoints, the address
6148 space doesn't really matter. */
6151 breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1,
6152 int len1, struct address_space *aspace2,
6155 return ((gdbarch_has_global_breakpoints (target_gdbarch)
6156 || aspace1 == aspace2)
6157 && addr2 >= addr1 && addr2 < addr1 + len1);
6160 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6161 a ranged breakpoint. In most targets, a match happens only if ASPACE
6162 matches the breakpoint's address space. On targets that have global
6163 breakpoints, the address space doesn't really matter. */
6166 breakpoint_location_address_match (struct bp_location *bl,
6167 struct address_space *aspace,
6170 return (breakpoint_address_match (bl->pspace->aspace, bl->address,
6173 && breakpoint_address_match_range (bl->pspace->aspace,
6174 bl->address, bl->length,
6178 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6179 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6180 true, otherwise returns false. */
6183 tracepoint_locations_match (struct bp_location *loc1,
6184 struct bp_location *loc2)
6186 if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner))
6187 /* Since tracepoint locations are never duplicated with others', tracepoint
6188 locations at the same address of different tracepoints are regarded as
6189 different locations. */
6190 return (loc1->address == loc2->address && loc1->owner == loc2->owner);
6195 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
6196 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
6197 represent the same location. */
6200 breakpoint_locations_match (struct bp_location *loc1,
6201 struct bp_location *loc2)
6203 int hw_point1, hw_point2;
6205 /* Both of them must not be in moribund_locations. */
6206 gdb_assert (loc1->owner != NULL);
6207 gdb_assert (loc2->owner != NULL);
6209 hw_point1 = is_hardware_watchpoint (loc1->owner);
6210 hw_point2 = is_hardware_watchpoint (loc2->owner);
6212 if (hw_point1 != hw_point2)
6215 return watchpoint_locations_match (loc1, loc2);
6216 else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner))
6217 return tracepoint_locations_match (loc1, loc2);
6219 /* We compare bp_location.length in order to cover ranged breakpoints. */
6220 return (breakpoint_address_match (loc1->pspace->aspace, loc1->address,
6221 loc2->pspace->aspace, loc2->address)
6222 && loc1->length == loc2->length);
6226 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
6227 int bnum, int have_bnum)
6229 /* The longest string possibly returned by hex_string_custom
6230 is 50 chars. These must be at least that big for safety. */
6234 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
6235 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
6237 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
6238 bnum, astr1, astr2);
6240 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
6243 /* Adjust a breakpoint's address to account for architectural
6244 constraints on breakpoint placement. Return the adjusted address.
6245 Note: Very few targets require this kind of adjustment. For most
6246 targets, this function is simply the identity function. */
6249 adjust_breakpoint_address (struct gdbarch *gdbarch,
6250 CORE_ADDR bpaddr, enum bptype bptype)
6252 if (!gdbarch_adjust_breakpoint_address_p (gdbarch))
6254 /* Very few targets need any kind of breakpoint adjustment. */
6257 else if (bptype == bp_watchpoint
6258 || bptype == bp_hardware_watchpoint
6259 || bptype == bp_read_watchpoint
6260 || bptype == bp_access_watchpoint
6261 || bptype == bp_catchpoint)
6263 /* Watchpoints and the various bp_catch_* eventpoints should not
6264 have their addresses modified. */
6269 CORE_ADDR adjusted_bpaddr;
6271 /* Some targets have architectural constraints on the placement
6272 of breakpoint instructions. Obtain the adjusted address. */
6273 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr);
6275 /* An adjusted breakpoint address can significantly alter
6276 a user's expectations. Print a warning if an adjustment
6278 if (adjusted_bpaddr != bpaddr)
6279 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
6281 return adjusted_bpaddr;
6286 init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops,
6287 struct breakpoint *owner)
6289 memset (loc, 0, sizeof (*loc));
6291 gdb_assert (ops != NULL);
6296 loc->cond_bytecode = NULL;
6297 loc->shlib_disabled = 0;
6300 switch (owner->type)
6306 case bp_longjmp_resume:
6308 case bp_exception_resume:
6309 case bp_step_resume:
6310 case bp_hp_step_resume:
6311 case bp_watchpoint_scope:
6313 case bp_std_terminate:
6314 case bp_shlib_event:
6315 case bp_thread_event:
6316 case bp_overlay_event:
6318 case bp_longjmp_master:
6319 case bp_std_terminate_master:
6320 case bp_exception_master:
6321 case bp_gnu_ifunc_resolver:
6322 case bp_gnu_ifunc_resolver_return:
6323 loc->loc_type = bp_loc_software_breakpoint;
6324 mark_breakpoint_location_modified (loc);
6326 case bp_hardware_breakpoint:
6327 loc->loc_type = bp_loc_hardware_breakpoint;
6328 mark_breakpoint_location_modified (loc);
6330 case bp_hardware_watchpoint:
6331 case bp_read_watchpoint:
6332 case bp_access_watchpoint:
6333 loc->loc_type = bp_loc_hardware_watchpoint;
6338 case bp_fast_tracepoint:
6339 case bp_static_tracepoint:
6340 loc->loc_type = bp_loc_other;
6343 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
6349 /* Allocate a struct bp_location. */
6351 static struct bp_location *
6352 allocate_bp_location (struct breakpoint *bpt)
6354 return bpt->ops->allocate_location (bpt);
6358 free_bp_location (struct bp_location *loc)
6360 loc->ops->dtor (loc);
6364 /* Increment reference count. */
6367 incref_bp_location (struct bp_location *bl)
6372 /* Decrement reference count. If the reference count reaches 0,
6373 destroy the bp_location. Sets *BLP to NULL. */
6376 decref_bp_location (struct bp_location **blp)
6378 gdb_assert ((*blp)->refc > 0);
6380 if (--(*blp)->refc == 0)
6381 free_bp_location (*blp);
6385 /* Add breakpoint B at the end of the global breakpoint chain. */
6388 add_to_breakpoint_chain (struct breakpoint *b)
6390 struct breakpoint *b1;
6392 /* Add this breakpoint to the end of the chain so that a list of
6393 breakpoints will come out in order of increasing numbers. */
6395 b1 = breakpoint_chain;
6397 breakpoint_chain = b;
6406 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
6409 init_raw_breakpoint_without_location (struct breakpoint *b,
6410 struct gdbarch *gdbarch,
6412 const struct breakpoint_ops *ops)
6414 memset (b, 0, sizeof (*b));
6416 gdb_assert (ops != NULL);
6420 b->gdbarch = gdbarch;
6421 b->language = current_language->la_language;
6422 b->input_radix = input_radix;
6424 b->enable_state = bp_enabled;
6427 b->ignore_count = 0;
6429 b->frame_id = null_frame_id;
6430 b->condition_not_parsed = 0;
6431 b->py_bp_object = NULL;
6432 b->related_breakpoint = b;
6435 /* Helper to set_raw_breakpoint below. Creates a breakpoint
6436 that has type BPTYPE and has no locations as yet. */
6438 static struct breakpoint *
6439 set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
6441 const struct breakpoint_ops *ops)
6443 struct breakpoint *b = XNEW (struct breakpoint);
6445 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
6446 add_to_breakpoint_chain (b);
6450 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
6451 resolutions should be made as the user specified the location explicitly
6455 set_breakpoint_location_function (struct bp_location *loc, int explicit_loc)
6457 gdb_assert (loc->owner != NULL);
6459 if (loc->owner->type == bp_breakpoint
6460 || loc->owner->type == bp_hardware_breakpoint
6461 || is_tracepoint (loc->owner))
6464 const char *function_name;
6466 find_pc_partial_function_gnu_ifunc (loc->address, &function_name,
6467 NULL, NULL, &is_gnu_ifunc);
6469 if (is_gnu_ifunc && !explicit_loc)
6471 struct breakpoint *b = loc->owner;
6473 gdb_assert (loc->pspace == current_program_space);
6474 if (gnu_ifunc_resolve_name (function_name,
6475 &loc->requested_address))
6477 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
6478 loc->address = adjust_breakpoint_address (loc->gdbarch,
6479 loc->requested_address,
6482 else if (b->type == bp_breakpoint && b->loc == loc
6483 && loc->next == NULL && b->related_breakpoint == b)
6485 /* Create only the whole new breakpoint of this type but do not
6486 mess more complicated breakpoints with multiple locations. */
6487 b->type = bp_gnu_ifunc_resolver;
6492 loc->function_name = xstrdup (function_name);
6496 /* Attempt to determine architecture of location identified by SAL. */
6498 get_sal_arch (struct symtab_and_line sal)
6501 return get_objfile_arch (sal.section->objfile);
6503 return get_objfile_arch (sal.symtab->objfile);
6508 /* Low level routine for partially initializing a breakpoint of type
6509 BPTYPE. The newly created breakpoint's address, section, source
6510 file name, and line number are provided by SAL.
6512 It is expected that the caller will complete the initialization of
6513 the newly created breakpoint struct as well as output any status
6514 information regarding the creation of a new breakpoint. */
6517 init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch,
6518 struct symtab_and_line sal, enum bptype bptype,
6519 const struct breakpoint_ops *ops)
6521 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
6523 add_location_to_breakpoint (b, &sal);
6525 if (bptype != bp_catchpoint)
6526 gdb_assert (sal.pspace != NULL);
6528 /* Store the program space that was used to set the breakpoint,
6529 except for ordinary breakpoints, which are independent of the
6531 if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint)
6532 b->pspace = sal.pspace;
6534 breakpoints_changed ();
6537 /* set_raw_breakpoint is a low level routine for allocating and
6538 partially initializing a breakpoint of type BPTYPE. The newly
6539 created breakpoint's address, section, source file name, and line
6540 number are provided by SAL. The newly created and partially
6541 initialized breakpoint is added to the breakpoint chain and
6542 is also returned as the value of this function.
6544 It is expected that the caller will complete the initialization of
6545 the newly created breakpoint struct as well as output any status
6546 information regarding the creation of a new breakpoint. In
6547 particular, set_raw_breakpoint does NOT set the breakpoint
6548 number! Care should be taken to not allow an error to occur
6549 prior to completing the initialization of the breakpoint. If this
6550 should happen, a bogus breakpoint will be left on the chain. */
6553 set_raw_breakpoint (struct gdbarch *gdbarch,
6554 struct symtab_and_line sal, enum bptype bptype,
6555 const struct breakpoint_ops *ops)
6557 struct breakpoint *b = XNEW (struct breakpoint);
6559 init_raw_breakpoint (b, gdbarch, sal, bptype, ops);
6560 add_to_breakpoint_chain (b);
6565 /* Note that the breakpoint object B describes a permanent breakpoint
6566 instruction, hard-wired into the inferior's code. */
6568 make_breakpoint_permanent (struct breakpoint *b)
6570 struct bp_location *bl;
6572 b->enable_state = bp_permanent;
6574 /* By definition, permanent breakpoints are already present in the
6575 code. Mark all locations as inserted. For now,
6576 make_breakpoint_permanent is called in just one place, so it's
6577 hard to say if it's reasonable to have permanent breakpoint with
6578 multiple locations or not, but it's easy to implement. */
6579 for (bl = b->loc; bl; bl = bl->next)
6583 /* Call this routine when stepping and nexting to enable a breakpoint
6584 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
6585 initiated the operation. */
6588 set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame)
6590 struct breakpoint *b, *b_tmp;
6591 int thread = tp->num;
6593 /* To avoid having to rescan all objfile symbols at every step,
6594 we maintain a list of continually-inserted but always disabled
6595 longjmp "master" breakpoints. Here, we simply create momentary
6596 clones of those and enable them for the requested thread. */
6597 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6598 if (b->pspace == current_program_space
6599 && (b->type == bp_longjmp_master
6600 || b->type == bp_exception_master))
6602 enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception;
6603 struct breakpoint *clone;
6605 clone = momentary_breakpoint_from_master (b, type,
6606 &momentary_breakpoint_ops);
6607 clone->thread = thread;
6610 tp->initiating_frame = frame;
6613 /* Delete all longjmp breakpoints from THREAD. */
6615 delete_longjmp_breakpoint (int thread)
6617 struct breakpoint *b, *b_tmp;
6619 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6620 if (b->type == bp_longjmp || b->type == bp_exception)
6622 if (b->thread == thread)
6623 delete_breakpoint (b);
6628 enable_overlay_breakpoints (void)
6630 struct breakpoint *b;
6633 if (b->type == bp_overlay_event)
6635 b->enable_state = bp_enabled;
6636 update_global_location_list (1);
6637 overlay_events_enabled = 1;
6642 disable_overlay_breakpoints (void)
6644 struct breakpoint *b;
6647 if (b->type == bp_overlay_event)
6649 b->enable_state = bp_disabled;
6650 update_global_location_list (0);
6651 overlay_events_enabled = 0;
6655 /* Set an active std::terminate breakpoint for each std::terminate
6656 master breakpoint. */
6658 set_std_terminate_breakpoint (void)
6660 struct breakpoint *b, *b_tmp;
6662 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6663 if (b->pspace == current_program_space
6664 && b->type == bp_std_terminate_master)
6666 momentary_breakpoint_from_master (b, bp_std_terminate,
6667 &momentary_breakpoint_ops);
6671 /* Delete all the std::terminate breakpoints. */
6673 delete_std_terminate_breakpoint (void)
6675 struct breakpoint *b, *b_tmp;
6677 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6678 if (b->type == bp_std_terminate)
6679 delete_breakpoint (b);
6683 create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
6685 struct breakpoint *b;
6687 b = create_internal_breakpoint (gdbarch, address, bp_thread_event,
6688 &internal_breakpoint_ops);
6690 b->enable_state = bp_enabled;
6691 /* addr_string has to be used or breakpoint_re_set will delete me. */
6693 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
6695 update_global_location_list_nothrow (1);
6701 remove_thread_event_breakpoints (void)
6703 struct breakpoint *b, *b_tmp;
6705 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6706 if (b->type == bp_thread_event
6707 && b->loc->pspace == current_program_space)
6708 delete_breakpoint (b);
6711 struct lang_and_radix
6717 /* Create a breakpoint for JIT code registration and unregistration. */
6720 create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
6722 struct breakpoint *b;
6724 b = create_internal_breakpoint (gdbarch, address, bp_jit_event,
6725 &internal_breakpoint_ops);
6726 update_global_location_list_nothrow (1);
6730 /* Remove JIT code registration and unregistration breakpoint(s). */
6733 remove_jit_event_breakpoints (void)
6735 struct breakpoint *b, *b_tmp;
6737 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6738 if (b->type == bp_jit_event
6739 && b->loc->pspace == current_program_space)
6740 delete_breakpoint (b);
6744 remove_solib_event_breakpoints (void)
6746 struct breakpoint *b, *b_tmp;
6748 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6749 if (b->type == bp_shlib_event
6750 && b->loc->pspace == current_program_space)
6751 delete_breakpoint (b);
6755 create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
6757 struct breakpoint *b;
6759 b = create_internal_breakpoint (gdbarch, address, bp_shlib_event,
6760 &internal_breakpoint_ops);
6761 update_global_location_list_nothrow (1);
6765 /* Disable any breakpoints that are on code in shared libraries. Only
6766 apply to enabled breakpoints, disabled ones can just stay disabled. */
6769 disable_breakpoints_in_shlibs (void)
6771 struct bp_location *loc, **locp_tmp;
6773 ALL_BP_LOCATIONS (loc, locp_tmp)
6775 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6776 struct breakpoint *b = loc->owner;
6778 /* We apply the check to all breakpoints, including disabled for
6779 those with loc->duplicate set. This is so that when breakpoint
6780 becomes enabled, or the duplicate is removed, gdb will try to
6781 insert all breakpoints. If we don't set shlib_disabled here,
6782 we'll try to insert those breakpoints and fail. */
6783 if (((b->type == bp_breakpoint)
6784 || (b->type == bp_jit_event)
6785 || (b->type == bp_hardware_breakpoint)
6786 || (is_tracepoint (b)))
6787 && loc->pspace == current_program_space
6788 && !loc->shlib_disabled
6790 && PC_SOLIB (loc->address)
6792 && solib_name_from_address (loc->pspace, loc->address)
6796 loc->shlib_disabled = 1;
6801 /* Disable any breakpoints and tracepoints that are in an unloaded shared
6802 library. Only apply to enabled breakpoints, disabled ones can just stay
6806 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
6808 struct bp_location *loc, **locp_tmp;
6809 int disabled_shlib_breaks = 0;
6811 /* SunOS a.out shared libraries are always mapped, so do not
6812 disable breakpoints; they will only be reported as unloaded
6813 through clear_solib when GDB discards its shared library
6814 list. See clear_solib for more information. */
6815 if (exec_bfd != NULL
6816 && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour)
6819 ALL_BP_LOCATIONS (loc, locp_tmp)
6821 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6822 struct breakpoint *b = loc->owner;
6824 if (solib->pspace == loc->pspace
6825 && !loc->shlib_disabled
6826 && (((b->type == bp_breakpoint
6827 || b->type == bp_jit_event
6828 || b->type == bp_hardware_breakpoint)
6829 && (loc->loc_type == bp_loc_hardware_breakpoint
6830 || loc->loc_type == bp_loc_software_breakpoint))
6831 || is_tracepoint (b))
6832 && solib_contains_address_p (solib, loc->address))
6834 loc->shlib_disabled = 1;
6835 /* At this point, we cannot rely on remove_breakpoint
6836 succeeding so we must mark the breakpoint as not inserted
6837 to prevent future errors occurring in remove_breakpoints. */
6840 /* This may cause duplicate notifications for the same breakpoint. */
6841 observer_notify_breakpoint_modified (b);
6843 if (!disabled_shlib_breaks)
6845 target_terminal_ours_for_output ();
6846 warning (_("Temporarily disabling breakpoints "
6847 "for unloaded shared library \"%s\""),
6850 disabled_shlib_breaks = 1;
6855 /* FORK & VFORK catchpoints. */
6857 /* An instance of this type is used to represent a fork or vfork
6858 catchpoint. It includes a "struct breakpoint" as a kind of base
6859 class; users downcast to "struct breakpoint *" when needed. A
6860 breakpoint is really of this type iff its ops pointer points to
6861 CATCH_FORK_BREAKPOINT_OPS. */
6863 struct fork_catchpoint
6865 /* The base class. */
6866 struct breakpoint base;
6868 /* Process id of a child process whose forking triggered this
6869 catchpoint. This field is only valid immediately after this
6870 catchpoint has triggered. */
6871 ptid_t forked_inferior_pid;
6874 /* Implement the "insert" breakpoint_ops method for fork
6878 insert_catch_fork (struct bp_location *bl)
6880 return target_insert_fork_catchpoint (PIDGET (inferior_ptid));
6883 /* Implement the "remove" breakpoint_ops method for fork
6887 remove_catch_fork (struct bp_location *bl)
6889 return target_remove_fork_catchpoint (PIDGET (inferior_ptid));
6892 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
6896 breakpoint_hit_catch_fork (const struct bp_location *bl,
6897 struct address_space *aspace, CORE_ADDR bp_addr,
6898 const struct target_waitstatus *ws)
6900 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
6902 if (ws->kind != TARGET_WAITKIND_FORKED)
6905 c->forked_inferior_pid = ws->value.related_pid;
6909 /* Implement the "print_it" breakpoint_ops method for fork
6912 static enum print_stop_action
6913 print_it_catch_fork (bpstat bs)
6915 struct ui_out *uiout = current_uiout;
6916 struct breakpoint *b = bs->breakpoint_at;
6917 struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at;
6919 annotate_catchpoint (b->number);
6920 if (b->disposition == disp_del)
6921 ui_out_text (uiout, "\nTemporary catchpoint ");
6923 ui_out_text (uiout, "\nCatchpoint ");
6924 if (ui_out_is_mi_like_p (uiout))
6926 ui_out_field_string (uiout, "reason",
6927 async_reason_lookup (EXEC_ASYNC_FORK));
6928 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
6930 ui_out_field_int (uiout, "bkptno", b->number);
6931 ui_out_text (uiout, " (forked process ");
6932 ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid));
6933 ui_out_text (uiout, "), ");
6934 return PRINT_SRC_AND_LOC;
6937 /* Implement the "print_one" breakpoint_ops method for fork
6941 print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc)
6943 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
6944 struct value_print_options opts;
6945 struct ui_out *uiout = current_uiout;
6947 get_user_print_options (&opts);
6949 /* Field 4, the address, is omitted (which makes the columns not
6950 line up too nicely with the headers, but the effect is relatively
6952 if (opts.addressprint)
6953 ui_out_field_skip (uiout, "addr");
6955 ui_out_text (uiout, "fork");
6956 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
6958 ui_out_text (uiout, ", process ");
6959 ui_out_field_int (uiout, "what",
6960 ptid_get_pid (c->forked_inferior_pid));
6961 ui_out_spaces (uiout, 1);
6965 /* Implement the "print_mention" breakpoint_ops method for fork
6969 print_mention_catch_fork (struct breakpoint *b)
6971 printf_filtered (_("Catchpoint %d (fork)"), b->number);
6974 /* Implement the "print_recreate" breakpoint_ops method for fork
6978 print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp)
6980 fprintf_unfiltered (fp, "catch fork");
6981 print_recreate_thread (b, fp);
6984 /* The breakpoint_ops structure to be used in fork catchpoints. */
6986 static struct breakpoint_ops catch_fork_breakpoint_ops;
6988 /* Implement the "insert" breakpoint_ops method for vfork
6992 insert_catch_vfork (struct bp_location *bl)
6994 return target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
6997 /* Implement the "remove" breakpoint_ops method for vfork
7001 remove_catch_vfork (struct bp_location *bl)
7003 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
7006 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
7010 breakpoint_hit_catch_vfork (const struct bp_location *bl,
7011 struct address_space *aspace, CORE_ADDR bp_addr,
7012 const struct target_waitstatus *ws)
7014 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
7016 if (ws->kind != TARGET_WAITKIND_VFORKED)
7019 c->forked_inferior_pid = ws->value.related_pid;
7023 /* Implement the "print_it" breakpoint_ops method for vfork
7026 static enum print_stop_action
7027 print_it_catch_vfork (bpstat bs)
7029 struct ui_out *uiout = current_uiout;
7030 struct breakpoint *b = bs->breakpoint_at;
7031 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
7033 annotate_catchpoint (b->number);
7034 if (b->disposition == disp_del)
7035 ui_out_text (uiout, "\nTemporary catchpoint ");
7037 ui_out_text (uiout, "\nCatchpoint ");
7038 if (ui_out_is_mi_like_p (uiout))
7040 ui_out_field_string (uiout, "reason",
7041 async_reason_lookup (EXEC_ASYNC_VFORK));
7042 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7044 ui_out_field_int (uiout, "bkptno", b->number);
7045 ui_out_text (uiout, " (vforked process ");
7046 ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid));
7047 ui_out_text (uiout, "), ");
7048 return PRINT_SRC_AND_LOC;
7051 /* Implement the "print_one" breakpoint_ops method for vfork
7055 print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc)
7057 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
7058 struct value_print_options opts;
7059 struct ui_out *uiout = current_uiout;
7061 get_user_print_options (&opts);
7062 /* Field 4, the address, is omitted (which makes the columns not
7063 line up too nicely with the headers, but the effect is relatively
7065 if (opts.addressprint)
7066 ui_out_field_skip (uiout, "addr");
7068 ui_out_text (uiout, "vfork");
7069 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
7071 ui_out_text (uiout, ", process ");
7072 ui_out_field_int (uiout, "what",
7073 ptid_get_pid (c->forked_inferior_pid));
7074 ui_out_spaces (uiout, 1);
7078 /* Implement the "print_mention" breakpoint_ops method for vfork
7082 print_mention_catch_vfork (struct breakpoint *b)
7084 printf_filtered (_("Catchpoint %d (vfork)"), b->number);
7087 /* Implement the "print_recreate" breakpoint_ops method for vfork
7091 print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp)
7093 fprintf_unfiltered (fp, "catch vfork");
7094 print_recreate_thread (b, fp);
7097 /* The breakpoint_ops structure to be used in vfork catchpoints. */
7099 static struct breakpoint_ops catch_vfork_breakpoint_ops;
7101 /* An instance of this type is used to represent an solib catchpoint.
7102 It includes a "struct breakpoint" as a kind of base class; users
7103 downcast to "struct breakpoint *" when needed. A breakpoint is
7104 really of this type iff its ops pointer points to
7105 CATCH_SOLIB_BREAKPOINT_OPS. */
7107 struct solib_catchpoint
7109 /* The base class. */
7110 struct breakpoint base;
7112 /* True for "catch load", false for "catch unload". */
7113 unsigned char is_load;
7115 /* Regular expression to match, if any. COMPILED is only valid when
7116 REGEX is non-NULL. */
7122 dtor_catch_solib (struct breakpoint *b)
7124 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
7127 regfree (&self->compiled);
7128 xfree (self->regex);
7130 base_breakpoint_ops.dtor (b);
7134 insert_catch_solib (struct bp_location *ignore)
7140 remove_catch_solib (struct bp_location *ignore)
7146 breakpoint_hit_catch_solib (const struct bp_location *bl,
7147 struct address_space *aspace,
7149 const struct target_waitstatus *ws)
7151 struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner;
7152 struct breakpoint *other;
7154 if (ws->kind == TARGET_WAITKIND_LOADED)
7157 ALL_BREAKPOINTS (other)
7159 struct bp_location *other_bl;
7161 if (other == bl->owner)
7164 if (other->type != bp_shlib_event)
7167 if (self->base.pspace != NULL && other->pspace != self->base.pspace)
7170 for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next)
7172 if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws))
7181 check_status_catch_solib (struct bpstats *bs)
7183 struct solib_catchpoint *self
7184 = (struct solib_catchpoint *) bs->breakpoint_at;
7189 struct so_list *iter;
7192 VEC_iterate (so_list_ptr, current_program_space->added_solibs,
7197 || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0)
7206 VEC_iterate (char_ptr, current_program_space->deleted_solibs,
7211 || regexec (&self->compiled, iter, 0, NULL, 0) == 0)
7217 bs->print_it = print_it_noop;
7220 static enum print_stop_action
7221 print_it_catch_solib (bpstat bs)
7223 struct breakpoint *b = bs->breakpoint_at;
7224 struct ui_out *uiout = current_uiout;
7226 annotate_catchpoint (b->number);
7227 if (b->disposition == disp_del)
7228 ui_out_text (uiout, "\nTemporary catchpoint ");
7230 ui_out_text (uiout, "\nCatchpoint ");
7231 ui_out_field_int (uiout, "bkptno", b->number);
7232 ui_out_text (uiout, "\n");
7233 if (ui_out_is_mi_like_p (uiout))
7234 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7235 print_solib_event (1);
7236 return PRINT_SRC_AND_LOC;
7240 print_one_catch_solib (struct breakpoint *b, struct bp_location **locs)
7242 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
7243 struct value_print_options opts;
7244 struct ui_out *uiout = current_uiout;
7247 get_user_print_options (&opts);
7248 /* Field 4, the address, is omitted (which makes the columns not
7249 line up too nicely with the headers, but the effect is relatively
7251 if (opts.addressprint)
7254 ui_out_field_skip (uiout, "addr");
7261 msg = xstrprintf (_("load of library matching %s"), self->regex);
7263 msg = xstrdup (_("load of library"));
7268 msg = xstrprintf (_("unload of library matching %s"), self->regex);
7270 msg = xstrdup (_("unload of library"));
7272 ui_out_field_string (uiout, "what", msg);
7277 print_mention_catch_solib (struct breakpoint *b)
7279 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
7281 printf_filtered (_("Catchpoint %d (%s)"), b->number,
7282 self->is_load ? "load" : "unload");
7286 print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp)
7288 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
7290 fprintf_unfiltered (fp, "%s %s",
7291 b->disposition == disp_del ? "tcatch" : "catch",
7292 self->is_load ? "load" : "unload");
7294 fprintf_unfiltered (fp, " %s", self->regex);
7295 fprintf_unfiltered (fp, "\n");
7298 static struct breakpoint_ops catch_solib_breakpoint_ops;
7300 /* A helper function that does all the work for "catch load" and
7304 catch_load_or_unload (char *arg, int from_tty, int is_load,
7305 struct cmd_list_element *command)
7307 struct solib_catchpoint *c;
7308 struct gdbarch *gdbarch = get_current_arch ();
7311 struct cleanup *cleanup;
7313 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
7317 arg = skip_spaces (arg);
7319 c = XCNEW (struct solib_catchpoint);
7320 cleanup = make_cleanup (xfree, c);
7326 errcode = regcomp (&c->compiled, arg, REG_NOSUB);
7329 char *err = get_regcomp_error (errcode, &c->compiled);
7331 make_cleanup (xfree, err);
7332 error (_("Invalid regexp (%s): %s"), err, arg);
7334 c->regex = xstrdup (arg);
7337 c->is_load = is_load;
7338 init_catchpoint (&c->base, gdbarch, tempflag, NULL,
7339 &catch_solib_breakpoint_ops);
7341 discard_cleanups (cleanup);
7342 install_breakpoint (0, &c->base, 1);
7346 catch_load_command_1 (char *arg, int from_tty,
7347 struct cmd_list_element *command)
7349 catch_load_or_unload (arg, from_tty, 1, command);
7353 catch_unload_command_1 (char *arg, int from_tty,
7354 struct cmd_list_element *command)
7356 catch_load_or_unload (arg, from_tty, 0, command);
7359 /* An instance of this type is used to represent a syscall catchpoint.
7360 It includes a "struct breakpoint" as a kind of base class; users
7361 downcast to "struct breakpoint *" when needed. A breakpoint is
7362 really of this type iff its ops pointer points to
7363 CATCH_SYSCALL_BREAKPOINT_OPS. */
7365 struct syscall_catchpoint
7367 /* The base class. */
7368 struct breakpoint base;
7370 /* Syscall numbers used for the 'catch syscall' feature. If no
7371 syscall has been specified for filtering, its value is NULL.
7372 Otherwise, it holds a list of all syscalls to be caught. The
7373 list elements are allocated with xmalloc. */
7374 VEC(int) *syscalls_to_be_caught;
7377 /* Implement the "dtor" breakpoint_ops method for syscall
7381 dtor_catch_syscall (struct breakpoint *b)
7383 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
7385 VEC_free (int, c->syscalls_to_be_caught);
7387 base_breakpoint_ops.dtor (b);
7390 /* Implement the "insert" breakpoint_ops method for syscall
7394 insert_catch_syscall (struct bp_location *bl)
7396 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner;
7397 struct inferior *inf = current_inferior ();
7399 ++inf->total_syscalls_count;
7400 if (!c->syscalls_to_be_caught)
7401 ++inf->any_syscall_count;
7407 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
7412 if (iter >= VEC_length (int, inf->syscalls_counts))
7414 int old_size = VEC_length (int, inf->syscalls_counts);
7415 uintptr_t vec_addr_offset
7416 = old_size * ((uintptr_t) sizeof (int));
7418 VEC_safe_grow (int, inf->syscalls_counts, iter + 1);
7419 vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) +
7421 memset ((void *) vec_addr, 0,
7422 (iter + 1 - old_size) * sizeof (int));
7424 elem = VEC_index (int, inf->syscalls_counts, iter);
7425 VEC_replace (int, inf->syscalls_counts, iter, ++elem);
7429 return target_set_syscall_catchpoint (PIDGET (inferior_ptid),
7430 inf->total_syscalls_count != 0,
7431 inf->any_syscall_count,
7432 VEC_length (int, inf->syscalls_counts),
7433 VEC_address (int, inf->syscalls_counts));
7436 /* Implement the "remove" breakpoint_ops method for syscall
7440 remove_catch_syscall (struct bp_location *bl)
7442 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner;
7443 struct inferior *inf = current_inferior ();
7445 --inf->total_syscalls_count;
7446 if (!c->syscalls_to_be_caught)
7447 --inf->any_syscall_count;
7453 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
7457 if (iter >= VEC_length (int, inf->syscalls_counts))
7458 /* Shouldn't happen. */
7460 elem = VEC_index (int, inf->syscalls_counts, iter);
7461 VEC_replace (int, inf->syscalls_counts, iter, --elem);
7465 return target_set_syscall_catchpoint (PIDGET (inferior_ptid),
7466 inf->total_syscalls_count != 0,
7467 inf->any_syscall_count,
7468 VEC_length (int, inf->syscalls_counts),
7470 inf->syscalls_counts));
7473 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
7477 breakpoint_hit_catch_syscall (const struct bp_location *bl,
7478 struct address_space *aspace, CORE_ADDR bp_addr,
7479 const struct target_waitstatus *ws)
7481 /* We must check if we are catching specific syscalls in this
7482 breakpoint. If we are, then we must guarantee that the called
7483 syscall is the same syscall we are catching. */
7484 int syscall_number = 0;
7485 const struct syscall_catchpoint *c
7486 = (const struct syscall_catchpoint *) bl->owner;
7488 if (ws->kind != TARGET_WAITKIND_SYSCALL_ENTRY
7489 && ws->kind != TARGET_WAITKIND_SYSCALL_RETURN)
7492 syscall_number = ws->value.syscall_number;
7494 /* Now, checking if the syscall is the same. */
7495 if (c->syscalls_to_be_caught)
7500 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
7502 if (syscall_number == iter)
7512 /* Implement the "print_it" breakpoint_ops method for syscall
7515 static enum print_stop_action
7516 print_it_catch_syscall (bpstat bs)
7518 struct ui_out *uiout = current_uiout;
7519 struct breakpoint *b = bs->breakpoint_at;
7520 /* These are needed because we want to know in which state a
7521 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
7522 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
7523 must print "called syscall" or "returned from syscall". */
7525 struct target_waitstatus last;
7529 get_last_target_status (&ptid, &last);
7531 get_syscall_by_number (last.value.syscall_number, &s);
7533 annotate_catchpoint (b->number);
7535 if (b->disposition == disp_del)
7536 ui_out_text (uiout, "\nTemporary catchpoint ");
7538 ui_out_text (uiout, "\nCatchpoint ");
7539 if (ui_out_is_mi_like_p (uiout))
7541 ui_out_field_string (uiout, "reason",
7542 async_reason_lookup (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY
7543 ? EXEC_ASYNC_SYSCALL_ENTRY
7544 : EXEC_ASYNC_SYSCALL_RETURN));
7545 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7547 ui_out_field_int (uiout, "bkptno", b->number);
7549 if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY)
7550 ui_out_text (uiout, " (call to syscall ");
7552 ui_out_text (uiout, " (returned from syscall ");
7554 if (s.name == NULL || ui_out_is_mi_like_p (uiout))
7555 ui_out_field_int (uiout, "syscall-number", last.value.syscall_number);
7557 ui_out_field_string (uiout, "syscall-name", s.name);
7559 ui_out_text (uiout, "), ");
7561 return PRINT_SRC_AND_LOC;
7564 /* Implement the "print_one" breakpoint_ops method for syscall
7568 print_one_catch_syscall (struct breakpoint *b,
7569 struct bp_location **last_loc)
7571 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
7572 struct value_print_options opts;
7573 struct ui_out *uiout = current_uiout;
7575 get_user_print_options (&opts);
7576 /* Field 4, the address, is omitted (which makes the columns not
7577 line up too nicely with the headers, but the effect is relatively
7579 if (opts.addressprint)
7580 ui_out_field_skip (uiout, "addr");
7583 if (c->syscalls_to_be_caught
7584 && VEC_length (int, c->syscalls_to_be_caught) > 1)
7585 ui_out_text (uiout, "syscalls \"");
7587 ui_out_text (uiout, "syscall \"");
7589 if (c->syscalls_to_be_caught)
7592 char *text = xstrprintf ("%s", "");
7595 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
7600 get_syscall_by_number (iter, &s);
7603 text = xstrprintf ("%s%s, ", text, s.name);
7605 text = xstrprintf ("%s%d, ", text, iter);
7607 /* We have to xfree the last 'text' (now stored at 'x')
7608 because xstrprintf dynamically allocates new space for it
7612 /* Remove the last comma. */
7613 text[strlen (text) - 2] = '\0';
7614 ui_out_field_string (uiout, "what", text);
7617 ui_out_field_string (uiout, "what", "<any syscall>");
7618 ui_out_text (uiout, "\" ");
7621 /* Implement the "print_mention" breakpoint_ops method for syscall
7625 print_mention_catch_syscall (struct breakpoint *b)
7627 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
7629 if (c->syscalls_to_be_caught)
7633 if (VEC_length (int, c->syscalls_to_be_caught) > 1)
7634 printf_filtered (_("Catchpoint %d (syscalls"), b->number);
7636 printf_filtered (_("Catchpoint %d (syscall"), b->number);
7639 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
7643 get_syscall_by_number (iter, &s);
7646 printf_filtered (" '%s' [%d]", s.name, s.number);
7648 printf_filtered (" %d", s.number);
7650 printf_filtered (")");
7653 printf_filtered (_("Catchpoint %d (any syscall)"),
7657 /* Implement the "print_recreate" breakpoint_ops method for syscall
7661 print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp)
7663 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
7665 fprintf_unfiltered (fp, "catch syscall");
7667 if (c->syscalls_to_be_caught)
7672 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
7677 get_syscall_by_number (iter, &s);
7679 fprintf_unfiltered (fp, " %s", s.name);
7681 fprintf_unfiltered (fp, " %d", s.number);
7684 print_recreate_thread (b, fp);
7687 /* The breakpoint_ops structure to be used in syscall catchpoints. */
7689 static struct breakpoint_ops catch_syscall_breakpoint_ops;
7691 /* Returns non-zero if 'b' is a syscall catchpoint. */
7694 syscall_catchpoint_p (struct breakpoint *b)
7696 return (b->ops == &catch_syscall_breakpoint_ops);
7699 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
7700 is non-zero, then make the breakpoint temporary. If COND_STRING is
7701 not NULL, then store it in the breakpoint. OPS, if not NULL, is
7702 the breakpoint_ops structure associated to the catchpoint. */
7705 init_catchpoint (struct breakpoint *b,
7706 struct gdbarch *gdbarch, int tempflag,
7708 const struct breakpoint_ops *ops)
7710 struct symtab_and_line sal;
7713 sal.pspace = current_program_space;
7715 init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops);
7717 b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string);
7718 b->disposition = tempflag ? disp_del : disp_donttouch;
7722 install_breakpoint (int internal, struct breakpoint *b, int update_gll)
7724 add_to_breakpoint_chain (b);
7725 set_breakpoint_number (internal, b);
7728 observer_notify_breakpoint_created (b);
7731 update_global_location_list (1);
7735 create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch,
7736 int tempflag, char *cond_string,
7737 const struct breakpoint_ops *ops)
7739 struct fork_catchpoint *c = XNEW (struct fork_catchpoint);
7741 init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops);
7743 c->forked_inferior_pid = null_ptid;
7745 install_breakpoint (0, &c->base, 1);
7748 /* Exec catchpoints. */
7750 /* An instance of this type is used to represent an exec catchpoint.
7751 It includes a "struct breakpoint" as a kind of base class; users
7752 downcast to "struct breakpoint *" when needed. A breakpoint is
7753 really of this type iff its ops pointer points to
7754 CATCH_EXEC_BREAKPOINT_OPS. */
7756 struct exec_catchpoint
7758 /* The base class. */
7759 struct breakpoint base;
7761 /* Filename of a program whose exec triggered this catchpoint.
7762 This field is only valid immediately after this catchpoint has
7764 char *exec_pathname;
7767 /* Implement the "dtor" breakpoint_ops method for exec
7771 dtor_catch_exec (struct breakpoint *b)
7773 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
7775 xfree (c->exec_pathname);
7777 base_breakpoint_ops.dtor (b);
7781 insert_catch_exec (struct bp_location *bl)
7783 return target_insert_exec_catchpoint (PIDGET (inferior_ptid));
7787 remove_catch_exec (struct bp_location *bl)
7789 return target_remove_exec_catchpoint (PIDGET (inferior_ptid));
7793 breakpoint_hit_catch_exec (const struct bp_location *bl,
7794 struct address_space *aspace, CORE_ADDR bp_addr,
7795 const struct target_waitstatus *ws)
7797 struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner;
7799 if (ws->kind != TARGET_WAITKIND_EXECD)
7802 c->exec_pathname = xstrdup (ws->value.execd_pathname);
7806 static enum print_stop_action
7807 print_it_catch_exec (bpstat bs)
7809 struct ui_out *uiout = current_uiout;
7810 struct breakpoint *b = bs->breakpoint_at;
7811 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
7813 annotate_catchpoint (b->number);
7814 if (b->disposition == disp_del)
7815 ui_out_text (uiout, "\nTemporary catchpoint ");
7817 ui_out_text (uiout, "\nCatchpoint ");
7818 if (ui_out_is_mi_like_p (uiout))
7820 ui_out_field_string (uiout, "reason",
7821 async_reason_lookup (EXEC_ASYNC_EXEC));
7822 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7824 ui_out_field_int (uiout, "bkptno", b->number);
7825 ui_out_text (uiout, " (exec'd ");
7826 ui_out_field_string (uiout, "new-exec", c->exec_pathname);
7827 ui_out_text (uiout, "), ");
7829 return PRINT_SRC_AND_LOC;
7833 print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc)
7835 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
7836 struct value_print_options opts;
7837 struct ui_out *uiout = current_uiout;
7839 get_user_print_options (&opts);
7841 /* Field 4, the address, is omitted (which makes the columns
7842 not line up too nicely with the headers, but the effect
7843 is relatively readable). */
7844 if (opts.addressprint)
7845 ui_out_field_skip (uiout, "addr");
7847 ui_out_text (uiout, "exec");
7848 if (c->exec_pathname != NULL)
7850 ui_out_text (uiout, ", program \"");
7851 ui_out_field_string (uiout, "what", c->exec_pathname);
7852 ui_out_text (uiout, "\" ");
7857 print_mention_catch_exec (struct breakpoint *b)
7859 printf_filtered (_("Catchpoint %d (exec)"), b->number);
7862 /* Implement the "print_recreate" breakpoint_ops method for exec
7866 print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp)
7868 fprintf_unfiltered (fp, "catch exec");
7869 print_recreate_thread (b, fp);
7872 static struct breakpoint_ops catch_exec_breakpoint_ops;
7875 create_syscall_event_catchpoint (int tempflag, VEC(int) *filter,
7876 const struct breakpoint_ops *ops)
7878 struct syscall_catchpoint *c;
7879 struct gdbarch *gdbarch = get_current_arch ();
7881 c = XNEW (struct syscall_catchpoint);
7882 init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops);
7883 c->syscalls_to_be_caught = filter;
7885 install_breakpoint (0, &c->base, 1);
7889 hw_breakpoint_used_count (void)
7892 struct breakpoint *b;
7893 struct bp_location *bl;
7897 if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b))
7898 for (bl = b->loc; bl; bl = bl->next)
7900 /* Special types of hardware breakpoints may use more than
7902 i += b->ops->resources_needed (bl);
7909 /* Returns the resources B would use if it were a hardware
7913 hw_watchpoint_use_count (struct breakpoint *b)
7916 struct bp_location *bl;
7918 if (!breakpoint_enabled (b))
7921 for (bl = b->loc; bl; bl = bl->next)
7923 /* Special types of hardware watchpoints may use more than
7925 i += b->ops->resources_needed (bl);
7931 /* Returns the sum the used resources of all hardware watchpoints of
7932 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
7933 the sum of the used resources of all hardware watchpoints of other
7934 types _not_ TYPE. */
7937 hw_watchpoint_used_count_others (struct breakpoint *except,
7938 enum bptype type, int *other_type_used)
7941 struct breakpoint *b;
7943 *other_type_used = 0;
7948 if (!breakpoint_enabled (b))
7951 if (b->type == type)
7952 i += hw_watchpoint_use_count (b);
7953 else if (is_hardware_watchpoint (b))
7954 *other_type_used = 1;
7961 disable_watchpoints_before_interactive_call_start (void)
7963 struct breakpoint *b;
7967 if (is_watchpoint (b) && breakpoint_enabled (b))
7969 b->enable_state = bp_call_disabled;
7970 update_global_location_list (0);
7976 enable_watchpoints_after_interactive_call_stop (void)
7978 struct breakpoint *b;
7982 if (is_watchpoint (b) && b->enable_state == bp_call_disabled)
7984 b->enable_state = bp_enabled;
7985 update_global_location_list (1);
7991 disable_breakpoints_before_startup (void)
7993 current_program_space->executing_startup = 1;
7994 update_global_location_list (0);
7998 enable_breakpoints_after_startup (void)
8000 current_program_space->executing_startup = 0;
8001 breakpoint_re_set ();
8005 /* Set a breakpoint that will evaporate an end of command
8006 at address specified by SAL.
8007 Restrict it to frame FRAME if FRAME is nonzero. */
8010 set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal,
8011 struct frame_id frame_id, enum bptype type)
8013 struct breakpoint *b;
8015 /* If FRAME_ID is valid, it should be a real frame, not an inlined
8017 gdb_assert (!frame_id_inlined_p (frame_id));
8019 b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops);
8020 b->enable_state = bp_enabled;
8021 b->disposition = disp_donttouch;
8022 b->frame_id = frame_id;
8024 /* If we're debugging a multi-threaded program, then we want
8025 momentary breakpoints to be active in only a single thread of
8027 if (in_thread_list (inferior_ptid))
8028 b->thread = pid_to_thread_id (inferior_ptid);
8030 update_global_location_list_nothrow (1);
8035 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8036 The new breakpoint will have type TYPE, and use OPS as it
8039 static struct breakpoint *
8040 momentary_breakpoint_from_master (struct breakpoint *orig,
8042 const struct breakpoint_ops *ops)
8044 struct breakpoint *copy;
8046 copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops);
8047 copy->loc = allocate_bp_location (copy);
8048 set_breakpoint_location_function (copy->loc, 1);
8050 copy->loc->gdbarch = orig->loc->gdbarch;
8051 copy->loc->requested_address = orig->loc->requested_address;
8052 copy->loc->address = orig->loc->address;
8053 copy->loc->section = orig->loc->section;
8054 copy->loc->pspace = orig->loc->pspace;
8056 if (orig->loc->source_file != NULL)
8057 copy->loc->source_file = xstrdup (orig->loc->source_file);
8059 copy->loc->line_number = orig->loc->line_number;
8060 copy->frame_id = orig->frame_id;
8061 copy->thread = orig->thread;
8062 copy->pspace = orig->pspace;
8064 copy->enable_state = bp_enabled;
8065 copy->disposition = disp_donttouch;
8066 copy->number = internal_breakpoint_number--;
8068 update_global_location_list_nothrow (0);
8072 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8076 clone_momentary_breakpoint (struct breakpoint *orig)
8078 /* If there's nothing to clone, then return nothing. */
8082 return momentary_breakpoint_from_master (orig, orig->type, orig->ops);
8086 set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc,
8089 struct symtab_and_line sal;
8091 sal = find_pc_line (pc, 0);
8093 sal.section = find_pc_overlay (pc);
8094 sal.explicit_pc = 1;
8096 return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type);
8100 /* Tell the user we have just set a breakpoint B. */
8103 mention (struct breakpoint *b)
8105 b->ops->print_mention (b);
8106 if (ui_out_is_mi_like_p (current_uiout))
8108 printf_filtered ("\n");
8112 static struct bp_location *
8113 add_location_to_breakpoint (struct breakpoint *b,
8114 const struct symtab_and_line *sal)
8116 struct bp_location *loc, **tmp;
8117 CORE_ADDR adjusted_address;
8118 struct gdbarch *loc_gdbarch = get_sal_arch (*sal);
8120 if (loc_gdbarch == NULL)
8121 loc_gdbarch = b->gdbarch;
8123 /* Adjust the breakpoint's address prior to allocating a location.
8124 Once we call allocate_bp_location(), that mostly uninitialized
8125 location will be placed on the location chain. Adjustment of the
8126 breakpoint may cause target_read_memory() to be called and we do
8127 not want its scan of the location chain to find a breakpoint and
8128 location that's only been partially initialized. */
8129 adjusted_address = adjust_breakpoint_address (loc_gdbarch,
8132 loc = allocate_bp_location (b);
8133 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
8137 loc->requested_address = sal->pc;
8138 loc->address = adjusted_address;
8139 loc->pspace = sal->pspace;
8140 gdb_assert (loc->pspace != NULL);
8141 loc->section = sal->section;
8142 loc->gdbarch = loc_gdbarch;
8144 if (sal->symtab != NULL)
8145 loc->source_file = xstrdup (sal->symtab->filename);
8146 loc->line_number = sal->line;
8148 set_breakpoint_location_function (loc,
8149 sal->explicit_pc || sal->explicit_line);
8154 /* Return 1 if LOC is pointing to a permanent breakpoint,
8155 return 0 otherwise. */
8158 bp_loc_is_permanent (struct bp_location *loc)
8162 const gdb_byte *bpoint;
8163 gdb_byte *target_mem;
8164 struct cleanup *cleanup;
8167 gdb_assert (loc != NULL);
8169 addr = loc->address;
8170 bpoint = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len);
8172 /* Software breakpoints unsupported? */
8176 target_mem = alloca (len);
8178 /* Enable the automatic memory restoration from breakpoints while
8179 we read the memory. Otherwise we could say about our temporary
8180 breakpoints they are permanent. */
8181 cleanup = save_current_space_and_thread ();
8183 switch_to_program_space_and_thread (loc->pspace);
8184 make_show_memory_breakpoints_cleanup (0);
8186 if (target_read_memory (loc->address, target_mem, len) == 0
8187 && memcmp (target_mem, bpoint, len) == 0)
8190 do_cleanups (cleanup);
8197 /* Create a breakpoint with SAL as location. Use ADDR_STRING
8198 as textual description of the location, and COND_STRING
8199 as condition expression. */
8202 init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch,
8203 struct symtabs_and_lines sals, char *addr_string,
8204 char *filter, char *cond_string,
8205 enum bptype type, enum bpdisp disposition,
8206 int thread, int task, int ignore_count,
8207 const struct breakpoint_ops *ops, int from_tty,
8208 int enabled, int internal, int display_canonical)
8212 if (type == bp_hardware_breakpoint)
8214 int target_resources_ok;
8216 i = hw_breakpoint_used_count ();
8217 target_resources_ok =
8218 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
8220 if (target_resources_ok == 0)
8221 error (_("No hardware breakpoint support in the target."));
8222 else if (target_resources_ok < 0)
8223 error (_("Hardware breakpoints used exceeds limit."));
8226 gdb_assert (sals.nelts > 0);
8228 for (i = 0; i < sals.nelts; ++i)
8230 struct symtab_and_line sal = sals.sals[i];
8231 struct bp_location *loc;
8235 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
8237 loc_gdbarch = gdbarch;
8239 describe_other_breakpoints (loc_gdbarch,
8240 sal.pspace, sal.pc, sal.section, thread);
8245 init_raw_breakpoint (b, gdbarch, sal, type, ops);
8249 b->cond_string = cond_string;
8250 b->ignore_count = ignore_count;
8251 b->enable_state = enabled ? bp_enabled : bp_disabled;
8252 b->disposition = disposition;
8254 if (type == bp_static_tracepoint)
8256 struct tracepoint *t = (struct tracepoint *) b;
8257 struct static_tracepoint_marker marker;
8259 if (strace_marker_p (b))
8261 /* We already know the marker exists, otherwise, we
8262 wouldn't see a sal for it. */
8263 char *p = &addr_string[3];
8267 p = skip_spaces (p);
8269 endp = skip_to_space (p);
8271 marker_str = savestring (p, endp - p);
8272 t->static_trace_marker_id = marker_str;
8274 printf_filtered (_("Probed static tracepoint "
8276 t->static_trace_marker_id);
8278 else if (target_static_tracepoint_marker_at (sal.pc, &marker))
8280 t->static_trace_marker_id = xstrdup (marker.str_id);
8281 release_static_tracepoint_marker (&marker);
8283 printf_filtered (_("Probed static tracepoint "
8285 t->static_trace_marker_id);
8288 warning (_("Couldn't determine the static "
8289 "tracepoint marker to probe"));
8296 loc = add_location_to_breakpoint (b, &sal);
8299 if (bp_loc_is_permanent (loc))
8300 make_breakpoint_permanent (b);
8304 char *arg = b->cond_string;
8305 loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0);
8307 error (_("Garbage %s follows condition"), arg);
8311 b->display_canonical = display_canonical;
8313 b->addr_string = addr_string;
8315 /* addr_string has to be used or breakpoint_re_set will delete
8318 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
8323 create_breakpoint_sal (struct gdbarch *gdbarch,
8324 struct symtabs_and_lines sals, char *addr_string,
8325 char *filter, char *cond_string,
8326 enum bptype type, enum bpdisp disposition,
8327 int thread, int task, int ignore_count,
8328 const struct breakpoint_ops *ops, int from_tty,
8329 int enabled, int internal, int display_canonical)
8331 struct breakpoint *b;
8332 struct cleanup *old_chain;
8334 if (is_tracepoint_type (type))
8336 struct tracepoint *t;
8338 t = XCNEW (struct tracepoint);
8342 b = XNEW (struct breakpoint);
8344 old_chain = make_cleanup (xfree, b);
8346 init_breakpoint_sal (b, gdbarch,
8348 filter, cond_string,
8350 thread, task, ignore_count,
8352 enabled, internal, display_canonical);
8353 discard_cleanups (old_chain);
8355 install_breakpoint (internal, b, 0);
8358 /* Add SALS.nelts breakpoints to the breakpoint table. For each
8359 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
8360 value. COND_STRING, if not NULL, specified the condition to be
8361 used for all breakpoints. Essentially the only case where
8362 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
8363 function. In that case, it's still not possible to specify
8364 separate conditions for different overloaded functions, so
8365 we take just a single condition string.
8367 NOTE: If the function succeeds, the caller is expected to cleanup
8368 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
8369 array contents). If the function fails (error() is called), the
8370 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
8371 COND and SALS arrays and each of those arrays contents. */
8374 create_breakpoints_sal (struct gdbarch *gdbarch,
8375 struct linespec_result *canonical,
8377 enum bptype type, enum bpdisp disposition,
8378 int thread, int task, int ignore_count,
8379 const struct breakpoint_ops *ops, int from_tty,
8380 int enabled, int internal)
8383 struct linespec_sals *lsal;
8385 if (canonical->pre_expanded)
8386 gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1);
8388 for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i)
8390 /* Note that 'addr_string' can be NULL in the case of a plain
8391 'break', without arguments. */
8392 char *addr_string = (canonical->addr_string
8393 ? xstrdup (canonical->addr_string)
8395 char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL;
8396 struct cleanup *inner = make_cleanup (xfree, addr_string);
8398 make_cleanup (xfree, filter_string);
8399 create_breakpoint_sal (gdbarch, lsal->sals,
8402 cond_string, type, disposition,
8403 thread, task, ignore_count, ops,
8404 from_tty, enabled, internal,
8405 canonical->special_display);
8406 discard_cleanups (inner);
8410 /* Parse ADDRESS which is assumed to be a SAL specification possibly
8411 followed by conditionals. On return, SALS contains an array of SAL
8412 addresses found. ADDR_STRING contains a vector of (canonical)
8413 address strings. ADDRESS points to the end of the SAL.
8415 The array and the line spec strings are allocated on the heap, it is
8416 the caller's responsibility to free them. */
8419 parse_breakpoint_sals (char **address,
8420 struct linespec_result *canonical)
8422 char *addr_start = *address;
8424 /* If no arg given, or if first arg is 'if ', use the default
8426 if ((*address) == NULL
8427 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
8429 /* The last displayed codepoint, if it's valid, is our default breakpoint
8431 if (last_displayed_sal_is_valid ())
8433 struct linespec_sals lsal;
8434 struct symtab_and_line sal;
8436 init_sal (&sal); /* Initialize to zeroes. */
8437 lsal.sals.sals = (struct symtab_and_line *)
8438 xmalloc (sizeof (struct symtab_and_line));
8440 /* Set sal's pspace, pc, symtab, and line to the values
8441 corresponding to the last call to print_frame_info. */
8442 get_last_displayed_sal (&sal);
8443 sal.section = find_pc_overlay (sal.pc);
8445 /* "break" without arguments is equivalent to "break *PC"
8446 where PC is the last displayed codepoint's address. So
8447 make sure to set sal.explicit_pc to prevent GDB from
8448 trying to expand the list of sals to include all other
8449 instances with the same symtab and line. */
8450 sal.explicit_pc = 1;
8452 lsal.sals.sals[0] = sal;
8453 lsal.sals.nelts = 1;
8454 lsal.canonical = NULL;
8456 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
8459 error (_("No default breakpoint address now."));
8463 /* Force almost all breakpoints to be in terms of the
8464 current_source_symtab (which is decode_line_1's default).
8465 This should produce the results we want almost all of the
8466 time while leaving default_breakpoint_* alone. */
8467 if (last_displayed_sal_is_valid ())
8468 decode_line_full (address, DECODE_LINE_FUNFIRSTLINE,
8469 get_last_displayed_symtab (),
8470 get_last_displayed_line (),
8471 canonical, NULL, NULL);
8473 decode_line_full (address, DECODE_LINE_FUNFIRSTLINE,
8474 (struct symtab *) NULL, 0,
8475 canonical, NULL, NULL);
8480 /* Convert each SAL into a real PC. Verify that the PC can be
8481 inserted as a breakpoint. If it can't throw an error. */
8484 breakpoint_sals_to_pc (struct symtabs_and_lines *sals)
8488 for (i = 0; i < sals->nelts; i++)
8489 resolve_sal_pc (&sals->sals[i]);
8492 /* Fast tracepoints may have restrictions on valid locations. For
8493 instance, a fast tracepoint using a jump instead of a trap will
8494 likely have to overwrite more bytes than a trap would, and so can
8495 only be placed where the instruction is longer than the jump, or a
8496 multi-instruction sequence does not have a jump into the middle of
8500 check_fast_tracepoint_sals (struct gdbarch *gdbarch,
8501 struct symtabs_and_lines *sals)
8504 struct symtab_and_line *sal;
8506 struct cleanup *old_chain;
8508 for (i = 0; i < sals->nelts; i++)
8510 struct gdbarch *sarch;
8512 sal = &sals->sals[i];
8514 sarch = get_sal_arch (*sal);
8515 /* We fall back to GDBARCH if there is no architecture
8516 associated with SAL. */
8519 rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc,
8521 old_chain = make_cleanup (xfree, msg);
8524 error (_("May not have a fast tracepoint at 0x%s%s"),
8525 paddress (sarch, sal->pc), (msg ? msg : ""));
8527 do_cleanups (old_chain);
8531 /* Given TOK, a string specification of condition and thread, as
8532 accepted by the 'break' command, extract the condition
8533 string and thread number and set *COND_STRING and *THREAD.
8534 PC identifies the context at which the condition should be parsed.
8535 If no condition is found, *COND_STRING is set to NULL.
8536 If no thread is found, *THREAD is set to -1. */
8538 find_condition_and_thread (char *tok, CORE_ADDR pc,
8539 char **cond_string, int *thread, int *task)
8541 *cond_string = NULL;
8547 char *cond_start = NULL;
8548 char *cond_end = NULL;
8550 tok = skip_spaces (tok);
8552 end_tok = skip_to_space (tok);
8554 toklen = end_tok - tok;
8556 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
8558 struct expression *expr;
8560 tok = cond_start = end_tok + 1;
8561 expr = parse_exp_1 (&tok, block_for_pc (pc), 0);
8564 *cond_string = savestring (cond_start,
8565 cond_end - cond_start);
8567 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
8573 *thread = strtol (tok, &tok, 0);
8575 error (_("Junk after thread keyword."));
8576 if (!valid_thread_id (*thread))
8577 error (_("Unknown thread %d."), *thread);
8579 else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0)
8585 *task = strtol (tok, &tok, 0);
8587 error (_("Junk after task keyword."));
8588 if (!valid_task_id (*task))
8589 error (_("Unknown task %d."), *task);
8592 error (_("Junk at end of arguments."));
8596 /* Decode a static tracepoint marker spec. */
8598 static struct symtabs_and_lines
8599 decode_static_tracepoint_spec (char **arg_p)
8601 VEC(static_tracepoint_marker_p) *markers = NULL;
8602 struct symtabs_and_lines sals;
8603 struct symtab_and_line sal;
8605 struct cleanup *old_chain;
8606 char *p = &(*arg_p)[3];
8611 p = skip_spaces (p);
8613 endp = skip_to_space (p);
8615 marker_str = savestring (p, endp - p);
8616 old_chain = make_cleanup (xfree, marker_str);
8618 markers = target_static_tracepoint_markers_by_strid (marker_str);
8619 if (VEC_empty(static_tracepoint_marker_p, markers))
8620 error (_("No known static tracepoint marker named %s"), marker_str);
8622 sals.nelts = VEC_length(static_tracepoint_marker_p, markers);
8623 sals.sals = xmalloc (sizeof *sals.sals * sals.nelts);
8625 for (i = 0; i < sals.nelts; i++)
8627 struct static_tracepoint_marker *marker;
8629 marker = VEC_index (static_tracepoint_marker_p, markers, i);
8631 init_sal (&sals.sals[i]);
8633 sals.sals[i] = find_pc_line (marker->address, 0);
8634 sals.sals[i].pc = marker->address;
8636 release_static_tracepoint_marker (marker);
8639 do_cleanups (old_chain);
8645 /* Set a breakpoint. This function is shared between CLI and MI
8646 functions for setting a breakpoint. This function has two major
8647 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
8648 parameter. If non-zero, the function will parse arg, extracting
8649 breakpoint location, address and thread. Otherwise, ARG is just
8650 the location of breakpoint, with condition and thread specified by
8651 the COND_STRING and THREAD parameters. If INTERNAL is non-zero,
8652 the breakpoint number will be allocated from the internal
8653 breakpoint count. Returns true if any breakpoint was created;
8657 create_breakpoint (struct gdbarch *gdbarch,
8658 char *arg, char *cond_string, int thread,
8659 int parse_condition_and_thread,
8660 int tempflag, enum bptype type_wanted,
8662 enum auto_boolean pending_break_support,
8663 const struct breakpoint_ops *ops,
8664 int from_tty, int enabled, int internal)
8666 volatile struct gdb_exception e;
8667 char *copy_arg = NULL;
8668 char *addr_start = arg;
8669 struct linespec_result canonical;
8670 struct cleanup *old_chain;
8671 struct cleanup *bkpt_chain = NULL;
8675 int prev_bkpt_count = breakpoint_count;
8677 gdb_assert (ops != NULL);
8679 init_linespec_result (&canonical);
8681 TRY_CATCH (e, RETURN_MASK_ALL)
8683 ops->create_sals_from_address (&arg, &canonical, type_wanted,
8684 addr_start, ©_arg);
8687 /* If caller is interested in rc value from parse, set value. */
8691 if (VEC_empty (linespec_sals, canonical.sals))
8697 case NOT_FOUND_ERROR:
8699 /* If pending breakpoint support is turned off, throw
8702 if (pending_break_support == AUTO_BOOLEAN_FALSE)
8703 throw_exception (e);
8705 exception_print (gdb_stderr, e);
8707 /* If pending breakpoint support is auto query and the user
8708 selects no, then simply return the error code. */
8709 if (pending_break_support == AUTO_BOOLEAN_AUTO
8710 && !nquery (_("Make %s pending on future shared library load? "),
8711 bptype_string (type_wanted)))
8714 /* At this point, either the user was queried about setting
8715 a pending breakpoint and selected yes, or pending
8716 breakpoint behavior is on and thus a pending breakpoint
8717 is defaulted on behalf of the user. */
8719 struct linespec_sals lsal;
8721 copy_arg = xstrdup (addr_start);
8722 lsal.canonical = xstrdup (copy_arg);
8723 lsal.sals.nelts = 1;
8724 lsal.sals.sals = XNEW (struct symtab_and_line);
8725 init_sal (&lsal.sals.sals[0]);
8727 VEC_safe_push (linespec_sals, canonical.sals, &lsal);
8731 throw_exception (e);
8735 throw_exception (e);
8738 /* Create a chain of things that always need to be cleaned up. */
8739 old_chain = make_cleanup_destroy_linespec_result (&canonical);
8741 /* ----------------------------- SNIP -----------------------------
8742 Anything added to the cleanup chain beyond this point is assumed
8743 to be part of a breakpoint. If the breakpoint create succeeds
8744 then the memory is not reclaimed. */
8745 bkpt_chain = make_cleanup (null_cleanup, 0);
8747 /* Resolve all line numbers to PC's and verify that the addresses
8748 are ok for the target. */
8752 struct linespec_sals *iter;
8754 for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
8755 breakpoint_sals_to_pc (&iter->sals);
8758 /* Fast tracepoints may have additional restrictions on location. */
8759 if (!pending && type_wanted == bp_fast_tracepoint)
8762 struct linespec_sals *iter;
8764 for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
8765 check_fast_tracepoint_sals (gdbarch, &iter->sals);
8768 /* Verify that condition can be parsed, before setting any
8769 breakpoints. Allocate a separate condition expression for each
8773 struct linespec_sals *lsal;
8775 lsal = VEC_index (linespec_sals, canonical.sals, 0);
8777 if (parse_condition_and_thread)
8779 /* Here we only parse 'arg' to separate condition
8780 from thread number, so parsing in context of first
8781 sal is OK. When setting the breakpoint we'll
8782 re-parse it in context of each sal. */
8785 find_condition_and_thread (arg, lsal->sals.sals[0].pc, &cond_string,
8788 make_cleanup (xfree, cond_string);
8792 /* Create a private copy of condition string. */
8795 cond_string = xstrdup (cond_string);
8796 make_cleanup (xfree, cond_string);
8800 ops->create_breakpoints_sal (gdbarch, &canonical, lsal,
8801 cond_string, type_wanted,
8802 tempflag ? disp_del : disp_donttouch,
8803 thread, task, ignore_count, ops,
8804 from_tty, enabled, internal);
8808 struct breakpoint *b;
8810 make_cleanup (xfree, copy_arg);
8812 if (is_tracepoint_type (type_wanted))
8814 struct tracepoint *t;
8816 t = XCNEW (struct tracepoint);
8820 b = XNEW (struct breakpoint);
8822 init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops);
8824 b->addr_string = copy_arg;
8825 b->cond_string = NULL;
8826 b->ignore_count = ignore_count;
8827 b->disposition = tempflag ? disp_del : disp_donttouch;
8828 b->condition_not_parsed = 1;
8829 b->enable_state = enabled ? bp_enabled : bp_disabled;
8830 if ((type_wanted != bp_breakpoint
8831 && type_wanted != bp_hardware_breakpoint) || thread != -1)
8832 b->pspace = current_program_space;
8834 install_breakpoint (internal, b, 0);
8837 if (VEC_length (linespec_sals, canonical.sals) > 1)
8839 warning (_("Multiple breakpoints were set.\nUse the "
8840 "\"delete\" command to delete unwanted breakpoints."));
8841 prev_breakpoint_count = prev_bkpt_count;
8844 /* That's it. Discard the cleanups for data inserted into the
8846 discard_cleanups (bkpt_chain);
8847 /* But cleanup everything else. */
8848 do_cleanups (old_chain);
8850 /* error call may happen here - have BKPT_CHAIN already discarded. */
8851 update_global_location_list (1);
8856 /* Set a breakpoint.
8857 ARG is a string describing breakpoint address,
8858 condition, and thread.
8859 FLAG specifies if a breakpoint is hardware on,
8860 and if breakpoint is temporary, using BP_HARDWARE_FLAG
8864 break_command_1 (char *arg, int flag, int from_tty)
8866 int tempflag = flag & BP_TEMPFLAG;
8867 enum bptype type_wanted = (flag & BP_HARDWAREFLAG
8868 ? bp_hardware_breakpoint
8871 create_breakpoint (get_current_arch (),
8873 NULL, 0, 1 /* parse arg */,
8874 tempflag, type_wanted,
8875 0 /* Ignore count */,
8876 pending_break_support,
8877 &bkpt_breakpoint_ops,
8883 /* Helper function for break_command_1 and disassemble_command. */
8886 resolve_sal_pc (struct symtab_and_line *sal)
8890 if (sal->pc == 0 && sal->symtab != NULL)
8892 if (!find_line_pc (sal->symtab, sal->line, &pc))
8893 error (_("No line %d in file \"%s\"."),
8894 sal->line, sal->symtab->filename);
8897 /* If this SAL corresponds to a breakpoint inserted using a line
8898 number, then skip the function prologue if necessary. */
8899 if (sal->explicit_line)
8900 skip_prologue_sal (sal);
8903 if (sal->section == 0 && sal->symtab != NULL)
8905 struct blockvector *bv;
8909 bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab);
8912 sym = block_linkage_function (b);
8915 fixup_symbol_section (sym, sal->symtab->objfile);
8916 sal->section = SYMBOL_OBJ_SECTION (sym);
8920 /* It really is worthwhile to have the section, so we'll
8921 just have to look harder. This case can be executed
8922 if we have line numbers but no functions (as can
8923 happen in assembly source). */
8925 struct minimal_symbol *msym;
8926 struct cleanup *old_chain = save_current_space_and_thread ();
8928 switch_to_program_space_and_thread (sal->pspace);
8930 msym = lookup_minimal_symbol_by_pc (sal->pc);
8932 sal->section = SYMBOL_OBJ_SECTION (msym);
8934 do_cleanups (old_chain);
8941 break_command (char *arg, int from_tty)
8943 break_command_1 (arg, 0, from_tty);
8947 tbreak_command (char *arg, int from_tty)
8949 break_command_1 (arg, BP_TEMPFLAG, from_tty);
8953 hbreak_command (char *arg, int from_tty)
8955 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
8959 thbreak_command (char *arg, int from_tty)
8961 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
8965 stop_command (char *arg, int from_tty)
8967 printf_filtered (_("Specify the type of breakpoint to set.\n\
8968 Usage: stop in <function | address>\n\
8969 stop at <line>\n"));
8973 stopin_command (char *arg, int from_tty)
8977 if (arg == (char *) NULL)
8979 else if (*arg != '*')
8984 /* Look for a ':'. If this is a line number specification, then
8985 say it is bad, otherwise, it should be an address or
8986 function/method name. */
8987 while (*argptr && !hasColon)
8989 hasColon = (*argptr == ':');
8994 badInput = (*argptr != ':'); /* Not a class::method */
8996 badInput = isdigit (*arg); /* a simple line number */
9000 printf_filtered (_("Usage: stop in <function | address>\n"));
9002 break_command_1 (arg, 0, from_tty);
9006 stopat_command (char *arg, int from_tty)
9010 if (arg == (char *) NULL || *arg == '*') /* no line number */
9017 /* Look for a ':'. If there is a '::' then get out, otherwise
9018 it is probably a line number. */
9019 while (*argptr && !hasColon)
9021 hasColon = (*argptr == ':');
9026 badInput = (*argptr == ':'); /* we have class::method */
9028 badInput = !isdigit (*arg); /* not a line number */
9032 printf_filtered (_("Usage: stop at <line>\n"));
9034 break_command_1 (arg, 0, from_tty);
9037 /* Implement the "breakpoint_hit" breakpoint_ops method for
9038 ranged breakpoints. */
9041 breakpoint_hit_ranged_breakpoint (const struct bp_location *bl,
9042 struct address_space *aspace,
9044 const struct target_waitstatus *ws)
9046 if (ws->kind != TARGET_WAITKIND_STOPPED
9047 || ws->value.sig != TARGET_SIGNAL_TRAP)
9050 return breakpoint_address_match_range (bl->pspace->aspace, bl->address,
9051 bl->length, aspace, bp_addr);
9054 /* Implement the "resources_needed" breakpoint_ops method for
9055 ranged breakpoints. */
9058 resources_needed_ranged_breakpoint (const struct bp_location *bl)
9060 return target_ranged_break_num_registers ();
9063 /* Implement the "print_it" breakpoint_ops method for
9064 ranged breakpoints. */
9066 static enum print_stop_action
9067 print_it_ranged_breakpoint (bpstat bs)
9069 struct breakpoint *b = bs->breakpoint_at;
9070 struct bp_location *bl = b->loc;
9071 struct ui_out *uiout = current_uiout;
9073 gdb_assert (b->type == bp_hardware_breakpoint);
9075 /* Ranged breakpoints have only one location. */
9076 gdb_assert (bl && bl->next == NULL);
9078 annotate_breakpoint (b->number);
9079 if (b->disposition == disp_del)
9080 ui_out_text (uiout, "\nTemporary ranged breakpoint ");
9082 ui_out_text (uiout, "\nRanged breakpoint ");
9083 if (ui_out_is_mi_like_p (uiout))
9085 ui_out_field_string (uiout, "reason",
9086 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
9087 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
9089 ui_out_field_int (uiout, "bkptno", b->number);
9090 ui_out_text (uiout, ", ");
9092 return PRINT_SRC_AND_LOC;
9095 /* Implement the "print_one" breakpoint_ops method for
9096 ranged breakpoints. */
9099 print_one_ranged_breakpoint (struct breakpoint *b,
9100 struct bp_location **last_loc)
9102 struct bp_location *bl = b->loc;
9103 struct value_print_options opts;
9104 struct ui_out *uiout = current_uiout;
9106 /* Ranged breakpoints have only one location. */
9107 gdb_assert (bl && bl->next == NULL);
9109 get_user_print_options (&opts);
9111 if (opts.addressprint)
9112 /* We don't print the address range here, it will be printed later
9113 by print_one_detail_ranged_breakpoint. */
9114 ui_out_field_skip (uiout, "addr");
9116 print_breakpoint_location (b, bl);
9120 /* Implement the "print_one_detail" breakpoint_ops method for
9121 ranged breakpoints. */
9124 print_one_detail_ranged_breakpoint (const struct breakpoint *b,
9125 struct ui_out *uiout)
9127 CORE_ADDR address_start, address_end;
9128 struct bp_location *bl = b->loc;
9129 struct ui_stream *stb = ui_out_stream_new (uiout);
9130 struct cleanup *cleanup = make_cleanup_ui_out_stream_delete (stb);
9134 address_start = bl->address;
9135 address_end = address_start + bl->length - 1;
9137 ui_out_text (uiout, "\taddress range: ");
9138 fprintf_unfiltered (stb->stream, "[%s, %s]",
9139 print_core_address (bl->gdbarch, address_start),
9140 print_core_address (bl->gdbarch, address_end));
9141 ui_out_field_stream (uiout, "addr", stb);
9142 ui_out_text (uiout, "\n");
9144 do_cleanups (cleanup);
9147 /* Implement the "print_mention" breakpoint_ops method for
9148 ranged breakpoints. */
9151 print_mention_ranged_breakpoint (struct breakpoint *b)
9153 struct bp_location *bl = b->loc;
9154 struct ui_out *uiout = current_uiout;
9157 gdb_assert (b->type == bp_hardware_breakpoint);
9159 if (ui_out_is_mi_like_p (uiout))
9162 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
9163 b->number, paddress (bl->gdbarch, bl->address),
9164 paddress (bl->gdbarch, bl->address + bl->length - 1));
9167 /* Implement the "print_recreate" breakpoint_ops method for
9168 ranged breakpoints. */
9171 print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp)
9173 fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string,
9174 b->addr_string_range_end);
9175 print_recreate_thread (b, fp);
9178 /* The breakpoint_ops structure to be used in ranged breakpoints. */
9180 static struct breakpoint_ops ranged_breakpoint_ops;
9182 /* Find the address where the end of the breakpoint range should be
9183 placed, given the SAL of the end of the range. This is so that if
9184 the user provides a line number, the end of the range is set to the
9185 last instruction of the given line. */
9188 find_breakpoint_range_end (struct symtab_and_line sal)
9192 /* If the user provided a PC value, use it. Otherwise,
9193 find the address of the end of the given location. */
9194 if (sal.explicit_pc)
9201 ret = find_line_pc_range (sal, &start, &end);
9203 error (_("Could not find location of the end of the range."));
9205 /* find_line_pc_range returns the start of the next line. */
9212 /* Implement the "break-range" CLI command. */
9215 break_range_command (char *arg, int from_tty)
9217 char *arg_start, *addr_string_start, *addr_string_end;
9218 struct linespec_result canonical_start, canonical_end;
9219 int bp_count, can_use_bp, length;
9221 struct breakpoint *b;
9222 struct symtab_and_line sal_start, sal_end;
9223 struct cleanup *cleanup_bkpt;
9224 struct linespec_sals *lsal_start, *lsal_end;
9226 /* We don't support software ranged breakpoints. */
9227 if (target_ranged_break_num_registers () < 0)
9228 error (_("This target does not support hardware ranged breakpoints."));
9230 bp_count = hw_breakpoint_used_count ();
9231 bp_count += target_ranged_break_num_registers ();
9232 can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
9235 error (_("Hardware breakpoints used exceeds limit."));
9237 arg = skip_spaces (arg);
9238 if (arg == NULL || arg[0] == '\0')
9239 error(_("No address range specified."));
9241 init_linespec_result (&canonical_start);
9244 parse_breakpoint_sals (&arg, &canonical_start);
9246 cleanup_bkpt = make_cleanup_destroy_linespec_result (&canonical_start);
9249 error (_("Too few arguments."));
9250 else if (VEC_empty (linespec_sals, canonical_start.sals))
9251 error (_("Could not find location of the beginning of the range."));
9253 lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0);
9255 if (VEC_length (linespec_sals, canonical_start.sals) > 1
9256 || lsal_start->sals.nelts != 1)
9257 error (_("Cannot create a ranged breakpoint with multiple locations."));
9259 sal_start = lsal_start->sals.sals[0];
9260 addr_string_start = savestring (arg_start, arg - arg_start);
9261 make_cleanup (xfree, addr_string_start);
9263 arg++; /* Skip the comma. */
9264 arg = skip_spaces (arg);
9266 /* Parse the end location. */
9268 init_linespec_result (&canonical_end);
9271 /* We call decode_line_full directly here instead of using
9272 parse_breakpoint_sals because we need to specify the start location's
9273 symtab and line as the default symtab and line for the end of the
9274 range. This makes it possible to have ranges like "foo.c:27, +14",
9275 where +14 means 14 lines from the start location. */
9276 decode_line_full (&arg, DECODE_LINE_FUNFIRSTLINE,
9277 sal_start.symtab, sal_start.line,
9278 &canonical_end, NULL, NULL);
9280 make_cleanup_destroy_linespec_result (&canonical_end);
9282 if (VEC_empty (linespec_sals, canonical_end.sals))
9283 error (_("Could not find location of the end of the range."));
9285 lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0);
9286 if (VEC_length (linespec_sals, canonical_end.sals) > 1
9287 || lsal_end->sals.nelts != 1)
9288 error (_("Cannot create a ranged breakpoint with multiple locations."));
9290 sal_end = lsal_end->sals.sals[0];
9291 addr_string_end = savestring (arg_start, arg - arg_start);
9292 make_cleanup (xfree, addr_string_end);
9294 end = find_breakpoint_range_end (sal_end);
9295 if (sal_start.pc > end)
9296 error (_("Invalid address range, end precedes start."));
9298 length = end - sal_start.pc + 1;
9300 /* Length overflowed. */
9301 error (_("Address range too large."));
9302 else if (length == 1)
9304 /* This range is simple enough to be handled by
9305 the `hbreak' command. */
9306 hbreak_command (addr_string_start, 1);
9308 do_cleanups (cleanup_bkpt);
9313 /* Now set up the breakpoint. */
9314 b = set_raw_breakpoint (get_current_arch (), sal_start,
9315 bp_hardware_breakpoint, &ranged_breakpoint_ops);
9316 set_breakpoint_count (breakpoint_count + 1);
9317 b->number = breakpoint_count;
9318 b->disposition = disp_donttouch;
9319 b->addr_string = xstrdup (addr_string_start);
9320 b->addr_string_range_end = xstrdup (addr_string_end);
9321 b->loc->length = length;
9323 do_cleanups (cleanup_bkpt);
9326 observer_notify_breakpoint_created (b);
9327 update_global_location_list (1);
9330 /* Return non-zero if EXP is verified as constant. Returned zero
9331 means EXP is variable. Also the constant detection may fail for
9332 some constant expressions and in such case still falsely return
9336 watchpoint_exp_is_const (const struct expression *exp)
9344 /* We are only interested in the descriptor of each element. */
9345 operator_length (exp, i, &oplenp, &argsp);
9348 switch (exp->elts[i].opcode)
9358 case BINOP_LOGICAL_AND:
9359 case BINOP_LOGICAL_OR:
9360 case BINOP_BITWISE_AND:
9361 case BINOP_BITWISE_IOR:
9362 case BINOP_BITWISE_XOR:
9364 case BINOP_NOTEQUAL:
9380 case TERNOP_SLICE_COUNT:
9392 case OP_OBJC_NSSTRING:
9395 case UNOP_LOGICAL_NOT:
9396 case UNOP_COMPLEMENT:
9400 /* Unary, binary and ternary operators: We have to check
9401 their operands. If they are constant, then so is the
9402 result of that operation. For instance, if A and B are
9403 determined to be constants, then so is "A + B".
9405 UNOP_IND is one exception to the rule above, because the
9406 value of *ADDR is not necessarily a constant, even when
9411 /* Check whether the associated symbol is a constant.
9413 We use SYMBOL_CLASS rather than TYPE_CONST because it's
9414 possible that a buggy compiler could mark a variable as
9415 constant even when it is not, and TYPE_CONST would return
9416 true in this case, while SYMBOL_CLASS wouldn't.
9418 We also have to check for function symbols because they
9419 are always constant. */
9421 struct symbol *s = exp->elts[i + 2].symbol;
9423 if (SYMBOL_CLASS (s) != LOC_BLOCK
9424 && SYMBOL_CLASS (s) != LOC_CONST
9425 && SYMBOL_CLASS (s) != LOC_CONST_BYTES)
9430 /* The default action is to return 0 because we are using
9431 the optimistic approach here: If we don't know something,
9432 then it is not a constant. */
9441 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
9444 dtor_watchpoint (struct breakpoint *self)
9446 struct watchpoint *w = (struct watchpoint *) self;
9448 xfree (w->cond_exp);
9450 xfree (w->exp_string);
9451 xfree (w->exp_string_reparse);
9452 value_free (w->val);
9454 base_breakpoint_ops.dtor (self);
9457 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
9460 re_set_watchpoint (struct breakpoint *b)
9462 struct watchpoint *w = (struct watchpoint *) b;
9464 /* Watchpoint can be either on expression using entirely global
9465 variables, or it can be on local variables.
9467 Watchpoints of the first kind are never auto-deleted, and even
9468 persist across program restarts. Since they can use variables
9469 from shared libraries, we need to reparse expression as libraries
9470 are loaded and unloaded.
9472 Watchpoints on local variables can also change meaning as result
9473 of solib event. For example, if a watchpoint uses both a local
9474 and a global variables in expression, it's a local watchpoint,
9475 but unloading of a shared library will make the expression
9476 invalid. This is not a very common use case, but we still
9477 re-evaluate expression, to avoid surprises to the user.
9479 Note that for local watchpoints, we re-evaluate it only if
9480 watchpoints frame id is still valid. If it's not, it means the
9481 watchpoint is out of scope and will be deleted soon. In fact,
9482 I'm not sure we'll ever be called in this case.
9484 If a local watchpoint's frame id is still valid, then
9485 w->exp_valid_block is likewise valid, and we can safely use it.
9487 Don't do anything about disabled watchpoints, since they will be
9488 reevaluated again when enabled. */
9489 update_watchpoint (w, 1 /* reparse */);
9492 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
9495 insert_watchpoint (struct bp_location *bl)
9497 struct watchpoint *w = (struct watchpoint *) bl->owner;
9498 int length = w->exact ? 1 : bl->length;
9500 return target_insert_watchpoint (bl->address, length, bl->watchpoint_type,
9504 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
9507 remove_watchpoint (struct bp_location *bl)
9509 struct watchpoint *w = (struct watchpoint *) bl->owner;
9510 int length = w->exact ? 1 : bl->length;
9512 return target_remove_watchpoint (bl->address, length, bl->watchpoint_type,
9517 breakpoint_hit_watchpoint (const struct bp_location *bl,
9518 struct address_space *aspace, CORE_ADDR bp_addr,
9519 const struct target_waitstatus *ws)
9521 struct breakpoint *b = bl->owner;
9522 struct watchpoint *w = (struct watchpoint *) b;
9524 /* Continuable hardware watchpoints are treated as non-existent if the
9525 reason we stopped wasn't a hardware watchpoint (we didn't stop on
9526 some data address). Otherwise gdb won't stop on a break instruction
9527 in the code (not from a breakpoint) when a hardware watchpoint has
9528 been defined. Also skip watchpoints which we know did not trigger
9529 (did not match the data address). */
9530 if (is_hardware_watchpoint (b)
9531 && w->watchpoint_triggered == watch_triggered_no)
9538 check_status_watchpoint (bpstat bs)
9540 gdb_assert (is_watchpoint (bs->breakpoint_at));
9542 bpstat_check_watchpoint (bs);
9545 /* Implement the "resources_needed" breakpoint_ops method for
9546 hardware watchpoints. */
9549 resources_needed_watchpoint (const struct bp_location *bl)
9551 struct watchpoint *w = (struct watchpoint *) bl->owner;
9552 int length = w->exact? 1 : bl->length;
9554 return target_region_ok_for_hw_watchpoint (bl->address, length);
9557 /* Implement the "works_in_software_mode" breakpoint_ops method for
9558 hardware watchpoints. */
9561 works_in_software_mode_watchpoint (const struct breakpoint *b)
9563 /* Read and access watchpoints only work with hardware support. */
9564 return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint;
9567 static enum print_stop_action
9568 print_it_watchpoint (bpstat bs)
9570 struct cleanup *old_chain;
9571 struct breakpoint *b;
9572 const struct bp_location *bl;
9573 struct ui_stream *stb;
9574 enum print_stop_action result;
9575 struct watchpoint *w;
9576 struct ui_out *uiout = current_uiout;
9578 gdb_assert (bs->bp_location_at != NULL);
9580 bl = bs->bp_location_at;
9581 b = bs->breakpoint_at;
9582 w = (struct watchpoint *) b;
9584 stb = ui_out_stream_new (uiout);
9585 old_chain = make_cleanup_ui_out_stream_delete (stb);
9590 case bp_hardware_watchpoint:
9591 annotate_watchpoint (b->number);
9592 if (ui_out_is_mi_like_p (uiout))
9595 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
9597 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
9598 ui_out_text (uiout, "\nOld value = ");
9599 watchpoint_value_print (bs->old_val, stb->stream);
9600 ui_out_field_stream (uiout, "old", stb);
9601 ui_out_text (uiout, "\nNew value = ");
9602 watchpoint_value_print (w->val, stb->stream);
9603 ui_out_field_stream (uiout, "new", stb);
9604 ui_out_text (uiout, "\n");
9605 /* More than one watchpoint may have been triggered. */
9606 result = PRINT_UNKNOWN;
9609 case bp_read_watchpoint:
9610 if (ui_out_is_mi_like_p (uiout))
9613 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
9615 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
9616 ui_out_text (uiout, "\nValue = ");
9617 watchpoint_value_print (w->val, stb->stream);
9618 ui_out_field_stream (uiout, "value", stb);
9619 ui_out_text (uiout, "\n");
9620 result = PRINT_UNKNOWN;
9623 case bp_access_watchpoint:
9624 if (bs->old_val != NULL)
9626 annotate_watchpoint (b->number);
9627 if (ui_out_is_mi_like_p (uiout))
9630 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
9632 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
9633 ui_out_text (uiout, "\nOld value = ");
9634 watchpoint_value_print (bs->old_val, stb->stream);
9635 ui_out_field_stream (uiout, "old", stb);
9636 ui_out_text (uiout, "\nNew value = ");
9641 if (ui_out_is_mi_like_p (uiout))
9644 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
9645 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
9646 ui_out_text (uiout, "\nValue = ");
9648 watchpoint_value_print (w->val, stb->stream);
9649 ui_out_field_stream (uiout, "new", stb);
9650 ui_out_text (uiout, "\n");
9651 result = PRINT_UNKNOWN;
9654 result = PRINT_UNKNOWN;
9657 do_cleanups (old_chain);
9661 /* Implement the "print_mention" breakpoint_ops method for hardware
9665 print_mention_watchpoint (struct breakpoint *b)
9667 struct cleanup *ui_out_chain;
9668 struct watchpoint *w = (struct watchpoint *) b;
9669 struct ui_out *uiout = current_uiout;
9674 ui_out_text (uiout, "Watchpoint ");
9675 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
9677 case bp_hardware_watchpoint:
9678 ui_out_text (uiout, "Hardware watchpoint ");
9679 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
9681 case bp_read_watchpoint:
9682 ui_out_text (uiout, "Hardware read watchpoint ");
9683 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
9685 case bp_access_watchpoint:
9686 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
9687 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
9690 internal_error (__FILE__, __LINE__,
9691 _("Invalid hardware watchpoint type."));
9694 ui_out_field_int (uiout, "number", b->number);
9695 ui_out_text (uiout, ": ");
9696 ui_out_field_string (uiout, "exp", w->exp_string);
9697 do_cleanups (ui_out_chain);
9700 /* Implement the "print_recreate" breakpoint_ops method for
9704 print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp)
9706 struct watchpoint *w = (struct watchpoint *) b;
9711 case bp_hardware_watchpoint:
9712 fprintf_unfiltered (fp, "watch");
9714 case bp_read_watchpoint:
9715 fprintf_unfiltered (fp, "rwatch");
9717 case bp_access_watchpoint:
9718 fprintf_unfiltered (fp, "awatch");
9721 internal_error (__FILE__, __LINE__,
9722 _("Invalid watchpoint type."));
9725 fprintf_unfiltered (fp, " %s", w->exp_string);
9726 print_recreate_thread (b, fp);
9729 /* The breakpoint_ops structure to be used in hardware watchpoints. */
9731 static struct breakpoint_ops watchpoint_breakpoint_ops;
9733 /* Implement the "insert" breakpoint_ops method for
9734 masked hardware watchpoints. */
9737 insert_masked_watchpoint (struct bp_location *bl)
9739 struct watchpoint *w = (struct watchpoint *) bl->owner;
9741 return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask,
9742 bl->watchpoint_type);
9745 /* Implement the "remove" breakpoint_ops method for
9746 masked hardware watchpoints. */
9749 remove_masked_watchpoint (struct bp_location *bl)
9751 struct watchpoint *w = (struct watchpoint *) bl->owner;
9753 return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask,
9754 bl->watchpoint_type);
9757 /* Implement the "resources_needed" breakpoint_ops method for
9758 masked hardware watchpoints. */
9761 resources_needed_masked_watchpoint (const struct bp_location *bl)
9763 struct watchpoint *w = (struct watchpoint *) bl->owner;
9765 return target_masked_watch_num_registers (bl->address, w->hw_wp_mask);
9768 /* Implement the "works_in_software_mode" breakpoint_ops method for
9769 masked hardware watchpoints. */
9772 works_in_software_mode_masked_watchpoint (const struct breakpoint *b)
9777 /* Implement the "print_it" breakpoint_ops method for
9778 masked hardware watchpoints. */
9780 static enum print_stop_action
9781 print_it_masked_watchpoint (bpstat bs)
9783 struct breakpoint *b = bs->breakpoint_at;
9784 struct ui_out *uiout = current_uiout;
9786 /* Masked watchpoints have only one location. */
9787 gdb_assert (b->loc && b->loc->next == NULL);
9791 case bp_hardware_watchpoint:
9792 annotate_watchpoint (b->number);
9793 if (ui_out_is_mi_like_p (uiout))
9796 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
9799 case bp_read_watchpoint:
9800 if (ui_out_is_mi_like_p (uiout))
9803 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
9806 case bp_access_watchpoint:
9807 if (ui_out_is_mi_like_p (uiout))
9810 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
9813 internal_error (__FILE__, __LINE__,
9814 _("Invalid hardware watchpoint type."));
9818 ui_out_text (uiout, _("\n\
9819 Check the underlying instruction at PC for the memory\n\
9820 address and value which triggered this watchpoint.\n"));
9821 ui_out_text (uiout, "\n");
9823 /* More than one watchpoint may have been triggered. */
9824 return PRINT_UNKNOWN;
9827 /* Implement the "print_one_detail" breakpoint_ops method for
9828 masked hardware watchpoints. */
9831 print_one_detail_masked_watchpoint (const struct breakpoint *b,
9832 struct ui_out *uiout)
9834 struct watchpoint *w = (struct watchpoint *) b;
9836 /* Masked watchpoints have only one location. */
9837 gdb_assert (b->loc && b->loc->next == NULL);
9839 ui_out_text (uiout, "\tmask ");
9840 ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask);
9841 ui_out_text (uiout, "\n");
9844 /* Implement the "print_mention" breakpoint_ops method for
9845 masked hardware watchpoints. */
9848 print_mention_masked_watchpoint (struct breakpoint *b)
9850 struct watchpoint *w = (struct watchpoint *) b;
9851 struct ui_out *uiout = current_uiout;
9852 struct cleanup *ui_out_chain;
9856 case bp_hardware_watchpoint:
9857 ui_out_text (uiout, "Masked hardware watchpoint ");
9858 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
9860 case bp_read_watchpoint:
9861 ui_out_text (uiout, "Masked hardware read watchpoint ");
9862 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
9864 case bp_access_watchpoint:
9865 ui_out_text (uiout, "Masked hardware access (read/write) watchpoint ");
9866 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
9869 internal_error (__FILE__, __LINE__,
9870 _("Invalid hardware watchpoint type."));
9873 ui_out_field_int (uiout, "number", b->number);
9874 ui_out_text (uiout, ": ");
9875 ui_out_field_string (uiout, "exp", w->exp_string);
9876 do_cleanups (ui_out_chain);
9879 /* Implement the "print_recreate" breakpoint_ops method for
9880 masked hardware watchpoints. */
9883 print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp)
9885 struct watchpoint *w = (struct watchpoint *) b;
9890 case bp_hardware_watchpoint:
9891 fprintf_unfiltered (fp, "watch");
9893 case bp_read_watchpoint:
9894 fprintf_unfiltered (fp, "rwatch");
9896 case bp_access_watchpoint:
9897 fprintf_unfiltered (fp, "awatch");
9900 internal_error (__FILE__, __LINE__,
9901 _("Invalid hardware watchpoint type."));
9904 sprintf_vma (tmp, w->hw_wp_mask);
9905 fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp);
9906 print_recreate_thread (b, fp);
9909 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
9911 static struct breakpoint_ops masked_watchpoint_breakpoint_ops;
9913 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
9916 is_masked_watchpoint (const struct breakpoint *b)
9918 return b->ops == &masked_watchpoint_breakpoint_ops;
9921 /* accessflag: hw_write: watch write,
9922 hw_read: watch read,
9923 hw_access: watch access (read or write) */
9925 watch_command_1 (char *arg, int accessflag, int from_tty,
9926 int just_location, int internal)
9928 volatile struct gdb_exception e;
9929 struct breakpoint *b, *scope_breakpoint = NULL;
9930 struct expression *exp;
9931 struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL;
9932 struct value *val, *mark, *result;
9933 struct frame_info *frame;
9934 char *exp_start = NULL;
9935 char *exp_end = NULL;
9936 char *tok, *end_tok;
9938 char *cond_start = NULL;
9939 char *cond_end = NULL;
9940 enum bptype bp_type;
9943 /* Flag to indicate whether we are going to use masks for
9944 the hardware watchpoint. */
9947 struct watchpoint *w;
9949 /* Make sure that we actually have parameters to parse. */
9950 if (arg != NULL && arg[0] != '\0')
9954 /* Look for "parameter value" pairs at the end
9955 of the arguments string. */
9956 for (tok = arg + strlen (arg) - 1; tok > arg; tok--)
9958 /* Skip whitespace at the end of the argument list. */
9959 while (tok > arg && (*tok == ' ' || *tok == '\t'))
9962 /* Find the beginning of the last token.
9963 This is the value of the parameter. */
9964 while (tok > arg && (*tok != ' ' && *tok != '\t'))
9966 value_start = tok + 1;
9968 /* Skip whitespace. */
9969 while (tok > arg && (*tok == ' ' || *tok == '\t'))
9974 /* Find the beginning of the second to last token.
9975 This is the parameter itself. */
9976 while (tok > arg && (*tok != ' ' && *tok != '\t'))
9979 toklen = end_tok - tok + 1;
9981 if (toklen == 6 && !strncmp (tok, "thread", 6))
9983 /* At this point we've found a "thread" token, which means
9984 the user is trying to set a watchpoint that triggers
9985 only in a specific thread. */
9989 error(_("You can specify only one thread."));
9991 /* Extract the thread ID from the next token. */
9992 thread = strtol (value_start, &endp, 0);
9994 /* Check if the user provided a valid numeric value for the
9996 if (*endp != ' ' && *endp != '\t' && *endp != '\0')
9997 error (_("Invalid thread ID specification %s."), value_start);
9999 /* Check if the thread actually exists. */
10000 if (!valid_thread_id (thread))
10001 error (_("Unknown thread %d."), thread);
10003 else if (toklen == 4 && !strncmp (tok, "mask", 4))
10005 /* We've found a "mask" token, which means the user wants to
10006 create a hardware watchpoint that is going to have the mask
10008 struct value *mask_value, *mark;
10011 error(_("You can specify only one mask."));
10013 use_mask = just_location = 1;
10015 mark = value_mark ();
10016 mask_value = parse_to_comma_and_eval (&value_start);
10017 mask = value_as_address (mask_value);
10018 value_free_to_mark (mark);
10021 /* We didn't recognize what we found. We should stop here. */
10024 /* Truncate the string and get rid of the "parameter value" pair before
10025 the arguments string is parsed by the parse_exp_1 function. */
10030 /* Parse the rest of the arguments. */
10031 innermost_block = NULL;
10033 exp = parse_exp_1 (&arg, 0, 0);
10035 /* Remove trailing whitespace from the expression before saving it.
10036 This makes the eventual display of the expression string a bit
10038 while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t'))
10041 /* Checking if the expression is not constant. */
10042 if (watchpoint_exp_is_const (exp))
10046 len = exp_end - exp_start;
10047 while (len > 0 && isspace (exp_start[len - 1]))
10049 error (_("Cannot watch constant value `%.*s'."), len, exp_start);
10052 exp_valid_block = innermost_block;
10053 mark = value_mark ();
10054 fetch_subexp_value (exp, &pc, &val, &result, NULL);
10060 exp_valid_block = NULL;
10061 val = value_addr (result);
10062 release_value (val);
10063 value_free_to_mark (mark);
10067 ret = target_masked_watch_num_registers (value_as_address (val),
10070 error (_("This target does not support masked watchpoints."));
10071 else if (ret == -2)
10072 error (_("Invalid mask or memory region."));
10075 else if (val != NULL)
10076 release_value (val);
10078 tok = skip_spaces (arg);
10079 end_tok = skip_to_space (tok);
10081 toklen = end_tok - tok;
10082 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
10084 struct expression *cond;
10086 innermost_block = NULL;
10087 tok = cond_start = end_tok + 1;
10088 cond = parse_exp_1 (&tok, 0, 0);
10090 /* The watchpoint expression may not be local, but the condition
10091 may still be. E.g.: `watch global if local > 0'. */
10092 cond_exp_valid_block = innermost_block;
10098 error (_("Junk at end of command."));
10100 if (accessflag == hw_read)
10101 bp_type = bp_read_watchpoint;
10102 else if (accessflag == hw_access)
10103 bp_type = bp_access_watchpoint;
10105 bp_type = bp_hardware_watchpoint;
10107 frame = block_innermost_frame (exp_valid_block);
10109 /* If the expression is "local", then set up a "watchpoint scope"
10110 breakpoint at the point where we've left the scope of the watchpoint
10111 expression. Create the scope breakpoint before the watchpoint, so
10112 that we will encounter it first in bpstat_stop_status. */
10113 if (exp_valid_block && frame)
10115 if (frame_id_p (frame_unwind_caller_id (frame)))
10118 = create_internal_breakpoint (frame_unwind_caller_arch (frame),
10119 frame_unwind_caller_pc (frame),
10120 bp_watchpoint_scope,
10121 &momentary_breakpoint_ops);
10123 scope_breakpoint->enable_state = bp_enabled;
10125 /* Automatically delete the breakpoint when it hits. */
10126 scope_breakpoint->disposition = disp_del;
10128 /* Only break in the proper frame (help with recursion). */
10129 scope_breakpoint->frame_id = frame_unwind_caller_id (frame);
10131 /* Set the address at which we will stop. */
10132 scope_breakpoint->loc->gdbarch
10133 = frame_unwind_caller_arch (frame);
10134 scope_breakpoint->loc->requested_address
10135 = frame_unwind_caller_pc (frame);
10136 scope_breakpoint->loc->address
10137 = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch,
10138 scope_breakpoint->loc->requested_address,
10139 scope_breakpoint->type);
10143 /* Now set up the breakpoint. */
10145 w = XCNEW (struct watchpoint);
10148 init_raw_breakpoint_without_location (b, NULL, bp_type,
10149 &masked_watchpoint_breakpoint_ops);
10151 init_raw_breakpoint_without_location (b, NULL, bp_type,
10152 &watchpoint_breakpoint_ops);
10153 b->thread = thread;
10154 b->disposition = disp_donttouch;
10155 b->pspace = current_program_space;
10157 w->exp_valid_block = exp_valid_block;
10158 w->cond_exp_valid_block = cond_exp_valid_block;
10161 struct type *t = value_type (val);
10162 CORE_ADDR addr = value_as_address (val);
10165 t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t)));
10166 name = type_to_string (t);
10168 w->exp_string_reparse = xstrprintf ("* (%s *) %s", name,
10169 core_addr_to_string (addr));
10172 w->exp_string = xstrprintf ("-location %.*s",
10173 (int) (exp_end - exp_start), exp_start);
10175 /* The above expression is in C. */
10176 b->language = language_c;
10179 w->exp_string = savestring (exp_start, exp_end - exp_start);
10183 w->hw_wp_mask = mask;
10192 b->cond_string = savestring (cond_start, cond_end - cond_start);
10194 b->cond_string = 0;
10198 w->watchpoint_frame = get_frame_id (frame);
10199 w->watchpoint_thread = inferior_ptid;
10203 w->watchpoint_frame = null_frame_id;
10204 w->watchpoint_thread = null_ptid;
10207 if (scope_breakpoint != NULL)
10209 /* The scope breakpoint is related to the watchpoint. We will
10210 need to act on them together. */
10211 b->related_breakpoint = scope_breakpoint;
10212 scope_breakpoint->related_breakpoint = b;
10215 if (!just_location)
10216 value_free_to_mark (mark);
10218 TRY_CATCH (e, RETURN_MASK_ALL)
10220 /* Finally update the new watchpoint. This creates the locations
10221 that should be inserted. */
10222 update_watchpoint (w, 1);
10226 delete_breakpoint (b);
10227 throw_exception (e);
10230 install_breakpoint (internal, b, 1);
10233 /* Return count of debug registers needed to watch the given expression.
10234 If the watchpoint cannot be handled in hardware return zero. */
10237 can_use_hardware_watchpoint (struct value *v)
10239 int found_memory_cnt = 0;
10240 struct value *head = v;
10242 /* Did the user specifically forbid us to use hardware watchpoints? */
10243 if (!can_use_hw_watchpoints)
10246 /* Make sure that the value of the expression depends only upon
10247 memory contents, and values computed from them within GDB. If we
10248 find any register references or function calls, we can't use a
10249 hardware watchpoint.
10251 The idea here is that evaluating an expression generates a series
10252 of values, one holding the value of every subexpression. (The
10253 expression a*b+c has five subexpressions: a, b, a*b, c, and
10254 a*b+c.) GDB's values hold almost enough information to establish
10255 the criteria given above --- they identify memory lvalues,
10256 register lvalues, computed values, etcetera. So we can evaluate
10257 the expression, and then scan the chain of values that leaves
10258 behind to decide whether we can detect any possible change to the
10259 expression's final value using only hardware watchpoints.
10261 However, I don't think that the values returned by inferior
10262 function calls are special in any way. So this function may not
10263 notice that an expression involving an inferior function call
10264 can't be watched with hardware watchpoints. FIXME. */
10265 for (; v; v = value_next (v))
10267 if (VALUE_LVAL (v) == lval_memory)
10269 if (v != head && value_lazy (v))
10270 /* A lazy memory lvalue in the chain is one that GDB never
10271 needed to fetch; we either just used its address (e.g.,
10272 `a' in `a.b') or we never needed it at all (e.g., `a'
10273 in `a,b'). This doesn't apply to HEAD; if that is
10274 lazy then it was not readable, but watch it anyway. */
10278 /* Ahh, memory we actually used! Check if we can cover
10279 it with hardware watchpoints. */
10280 struct type *vtype = check_typedef (value_type (v));
10282 /* We only watch structs and arrays if user asked for it
10283 explicitly, never if they just happen to appear in a
10284 middle of some value chain. */
10286 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
10287 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
10289 CORE_ADDR vaddr = value_address (v);
10293 len = (target_exact_watchpoints
10294 && is_scalar_type_recursive (vtype))?
10295 1 : TYPE_LENGTH (value_type (v));
10297 num_regs = target_region_ok_for_hw_watchpoint (vaddr, len);
10301 found_memory_cnt += num_regs;
10305 else if (VALUE_LVAL (v) != not_lval
10306 && deprecated_value_modifiable (v) == 0)
10307 return 0; /* These are values from the history (e.g., $1). */
10308 else if (VALUE_LVAL (v) == lval_register)
10309 return 0; /* Cannot watch a register with a HW watchpoint. */
10312 /* The expression itself looks suitable for using a hardware
10313 watchpoint, but give the target machine a chance to reject it. */
10314 return found_memory_cnt;
10318 watch_command_wrapper (char *arg, int from_tty, int internal)
10320 watch_command_1 (arg, hw_write, from_tty, 0, internal);
10323 /* A helper function that looks for an argument at the start of a
10324 string. The argument must also either be at the end of the string,
10325 or be followed by whitespace. Returns 1 if it finds the argument,
10326 0 otherwise. If the argument is found, it updates *STR. */
10329 check_for_argument (char **str, char *arg, int arg_len)
10331 if (strncmp (*str, arg, arg_len) == 0
10332 && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len])))
10340 /* A helper function that looks for the "-location" argument and then
10341 calls watch_command_1. */
10344 watch_maybe_just_location (char *arg, int accessflag, int from_tty)
10346 int just_location = 0;
10349 && (check_for_argument (&arg, "-location", sizeof ("-location") - 1)
10350 || check_for_argument (&arg, "-l", sizeof ("-l") - 1)))
10352 arg = skip_spaces (arg);
10356 watch_command_1 (arg, accessflag, from_tty, just_location, 0);
10360 watch_command (char *arg, int from_tty)
10362 watch_maybe_just_location (arg, hw_write, from_tty);
10366 rwatch_command_wrapper (char *arg, int from_tty, int internal)
10368 watch_command_1 (arg, hw_read, from_tty, 0, internal);
10372 rwatch_command (char *arg, int from_tty)
10374 watch_maybe_just_location (arg, hw_read, from_tty);
10378 awatch_command_wrapper (char *arg, int from_tty, int internal)
10380 watch_command_1 (arg, hw_access, from_tty, 0, internal);
10384 awatch_command (char *arg, int from_tty)
10386 watch_maybe_just_location (arg, hw_access, from_tty);
10390 /* Helper routines for the until_command routine in infcmd.c. Here
10391 because it uses the mechanisms of breakpoints. */
10393 struct until_break_command_continuation_args
10395 struct breakpoint *breakpoint;
10396 struct breakpoint *breakpoint2;
10400 /* This function is called by fetch_inferior_event via the
10401 cmd_continuation pointer, to complete the until command. It takes
10402 care of cleaning up the temporary breakpoints set up by the until
10405 until_break_command_continuation (void *arg, int err)
10407 struct until_break_command_continuation_args *a = arg;
10409 delete_breakpoint (a->breakpoint);
10410 if (a->breakpoint2)
10411 delete_breakpoint (a->breakpoint2);
10412 delete_longjmp_breakpoint (a->thread_num);
10416 until_break_command (char *arg, int from_tty, int anywhere)
10418 struct symtabs_and_lines sals;
10419 struct symtab_and_line sal;
10420 struct frame_info *frame = get_selected_frame (NULL);
10421 struct breakpoint *breakpoint;
10422 struct breakpoint *breakpoint2 = NULL;
10423 struct cleanup *old_chain;
10425 struct thread_info *tp;
10427 clear_proceed_status ();
10429 /* Set a breakpoint where the user wants it and at return from
10432 if (last_displayed_sal_is_valid ())
10433 sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE,
10434 get_last_displayed_symtab (),
10435 get_last_displayed_line ());
10437 sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE,
10438 (struct symtab *) NULL, 0);
10440 if (sals.nelts != 1)
10441 error (_("Couldn't get information on specified line."));
10443 sal = sals.sals[0];
10444 xfree (sals.sals); /* malloc'd, so freed. */
10447 error (_("Junk at end of arguments."));
10449 resolve_sal_pc (&sal);
10452 /* If the user told us to continue until a specified location,
10453 we don't specify a frame at which we need to stop. */
10454 breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal,
10455 null_frame_id, bp_until);
10457 /* Otherwise, specify the selected frame, because we want to stop
10458 only at the very same frame. */
10459 breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal,
10460 get_stack_frame_id (frame),
10463 old_chain = make_cleanup_delete_breakpoint (breakpoint);
10465 tp = inferior_thread ();
10468 /* Keep within the current frame, or in frames called by the current
10471 if (frame_id_p (frame_unwind_caller_id (frame)))
10473 sal = find_pc_line (frame_unwind_caller_pc (frame), 0);
10474 sal.pc = frame_unwind_caller_pc (frame);
10475 breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame),
10477 frame_unwind_caller_id (frame),
10479 make_cleanup_delete_breakpoint (breakpoint2);
10481 set_longjmp_breakpoint (tp, frame_unwind_caller_id (frame));
10482 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
10485 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
10487 /* If we are running asynchronously, and proceed call above has
10488 actually managed to start the target, arrange for breakpoints to
10489 be deleted when the target stops. Otherwise, we're already
10490 stopped and delete breakpoints via cleanup chain. */
10492 if (target_can_async_p () && is_running (inferior_ptid))
10494 struct until_break_command_continuation_args *args;
10495 args = xmalloc (sizeof (*args));
10497 args->breakpoint = breakpoint;
10498 args->breakpoint2 = breakpoint2;
10499 args->thread_num = thread;
10501 discard_cleanups (old_chain);
10502 add_continuation (inferior_thread (),
10503 until_break_command_continuation, args,
10507 do_cleanups (old_chain);
10510 /* This function attempts to parse an optional "if <cond>" clause
10511 from the arg string. If one is not found, it returns NULL.
10513 Else, it returns a pointer to the condition string. (It does not
10514 attempt to evaluate the string against a particular block.) And,
10515 it updates arg to point to the first character following the parsed
10516 if clause in the arg string. */
10519 ep_parse_optional_if_clause (char **arg)
10523 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
10526 /* Skip the "if" keyword. */
10529 /* Skip any extra leading whitespace, and record the start of the
10530 condition string. */
10531 *arg = skip_spaces (*arg);
10532 cond_string = *arg;
10534 /* Assume that the condition occupies the remainder of the arg
10536 (*arg) += strlen (cond_string);
10538 return cond_string;
10541 /* Commands to deal with catching events, such as signals, exceptions,
10542 process start/exit, etc. */
10546 catch_fork_temporary, catch_vfork_temporary,
10547 catch_fork_permanent, catch_vfork_permanent
10552 catch_fork_command_1 (char *arg, int from_tty,
10553 struct cmd_list_element *command)
10555 struct gdbarch *gdbarch = get_current_arch ();
10556 char *cond_string = NULL;
10557 catch_fork_kind fork_kind;
10560 fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command);
10561 tempflag = (fork_kind == catch_fork_temporary
10562 || fork_kind == catch_vfork_temporary);
10566 arg = skip_spaces (arg);
10568 /* The allowed syntax is:
10570 catch [v]fork if <cond>
10572 First, check if there's an if clause. */
10573 cond_string = ep_parse_optional_if_clause (&arg);
10575 if ((*arg != '\0') && !isspace (*arg))
10576 error (_("Junk at end of arguments."));
10578 /* If this target supports it, create a fork or vfork catchpoint
10579 and enable reporting of such events. */
10582 case catch_fork_temporary:
10583 case catch_fork_permanent:
10584 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
10585 &catch_fork_breakpoint_ops);
10587 case catch_vfork_temporary:
10588 case catch_vfork_permanent:
10589 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
10590 &catch_vfork_breakpoint_ops);
10593 error (_("unsupported or unknown fork kind; cannot catch it"));
10599 catch_exec_command_1 (char *arg, int from_tty,
10600 struct cmd_list_element *command)
10602 struct exec_catchpoint *c;
10603 struct gdbarch *gdbarch = get_current_arch ();
10605 char *cond_string = NULL;
10607 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
10611 arg = skip_spaces (arg);
10613 /* The allowed syntax is:
10615 catch exec if <cond>
10617 First, check if there's an if clause. */
10618 cond_string = ep_parse_optional_if_clause (&arg);
10620 if ((*arg != '\0') && !isspace (*arg))
10621 error (_("Junk at end of arguments."));
10623 c = XNEW (struct exec_catchpoint);
10624 init_catchpoint (&c->base, gdbarch, tempflag, cond_string,
10625 &catch_exec_breakpoint_ops);
10626 c->exec_pathname = NULL;
10628 install_breakpoint (0, &c->base, 1);
10631 static enum print_stop_action
10632 print_it_exception_catchpoint (bpstat bs)
10634 struct ui_out *uiout = current_uiout;
10635 struct breakpoint *b = bs->breakpoint_at;
10636 int bp_temp, bp_throw;
10638 annotate_catchpoint (b->number);
10640 bp_throw = strstr (b->addr_string, "throw") != NULL;
10641 if (b->loc->address != b->loc->requested_address)
10642 breakpoint_adjustment_warning (b->loc->requested_address,
10645 bp_temp = b->disposition == disp_del;
10646 ui_out_text (uiout,
10647 bp_temp ? "Temporary catchpoint "
10649 if (!ui_out_is_mi_like_p (uiout))
10650 ui_out_field_int (uiout, "bkptno", b->number);
10651 ui_out_text (uiout,
10652 bp_throw ? " (exception thrown), "
10653 : " (exception caught), ");
10654 if (ui_out_is_mi_like_p (uiout))
10656 ui_out_field_string (uiout, "reason",
10657 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
10658 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
10659 ui_out_field_int (uiout, "bkptno", b->number);
10661 return PRINT_SRC_AND_LOC;
10665 print_one_exception_catchpoint (struct breakpoint *b,
10666 struct bp_location **last_loc)
10668 struct value_print_options opts;
10669 struct ui_out *uiout = current_uiout;
10671 get_user_print_options (&opts);
10672 if (opts.addressprint)
10674 annotate_field (4);
10675 if (b->loc == NULL || b->loc->shlib_disabled)
10676 ui_out_field_string (uiout, "addr", "<PENDING>");
10678 ui_out_field_core_addr (uiout, "addr",
10679 b->loc->gdbarch, b->loc->address);
10681 annotate_field (5);
10683 *last_loc = b->loc;
10684 if (strstr (b->addr_string, "throw") != NULL)
10685 ui_out_field_string (uiout, "what", "exception throw");
10687 ui_out_field_string (uiout, "what", "exception catch");
10691 print_mention_exception_catchpoint (struct breakpoint *b)
10693 struct ui_out *uiout = current_uiout;
10697 bp_temp = b->disposition == disp_del;
10698 bp_throw = strstr (b->addr_string, "throw") != NULL;
10699 ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ")
10700 : _("Catchpoint "));
10701 ui_out_field_int (uiout, "bkptno", b->number);
10702 ui_out_text (uiout, bp_throw ? _(" (throw)")
10706 /* Implement the "print_recreate" breakpoint_ops method for throw and
10707 catch catchpoints. */
10710 print_recreate_exception_catchpoint (struct breakpoint *b,
10711 struct ui_file *fp)
10716 bp_temp = b->disposition == disp_del;
10717 bp_throw = strstr (b->addr_string, "throw") != NULL;
10718 fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch ");
10719 fprintf_unfiltered (fp, bp_throw ? "throw" : "catch");
10720 print_recreate_thread (b, fp);
10723 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops;
10726 handle_gnu_v3_exceptions (int tempflag, char *cond_string,
10727 enum exception_event_kind ex_event, int from_tty)
10729 char *trigger_func_name;
10731 if (ex_event == EX_EVENT_CATCH)
10732 trigger_func_name = "__cxa_begin_catch";
10734 trigger_func_name = "__cxa_throw";
10736 create_breakpoint (get_current_arch (),
10737 trigger_func_name, cond_string, -1,
10738 0 /* condition and thread are valid. */,
10739 tempflag, bp_breakpoint,
10741 AUTO_BOOLEAN_TRUE /* pending */,
10742 &gnu_v3_exception_catchpoint_ops, from_tty,
10749 /* Deal with "catch catch" and "catch throw" commands. */
10752 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
10753 int tempflag, int from_tty)
10755 char *cond_string = NULL;
10759 arg = skip_spaces (arg);
10761 cond_string = ep_parse_optional_if_clause (&arg);
10763 if ((*arg != '\0') && !isspace (*arg))
10764 error (_("Junk at end of arguments."));
10766 if (ex_event != EX_EVENT_THROW
10767 && ex_event != EX_EVENT_CATCH)
10768 error (_("Unsupported or unknown exception event; cannot catch it"));
10770 if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
10773 warning (_("Unsupported with this platform/compiler combination."));
10776 /* Implementation of "catch catch" command. */
10779 catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command)
10781 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
10783 catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty);
10786 /* Implementation of "catch throw" command. */
10789 catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command)
10791 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
10793 catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty);
10797 init_ada_exception_breakpoint (struct breakpoint *b,
10798 struct gdbarch *gdbarch,
10799 struct symtab_and_line sal,
10801 const struct breakpoint_ops *ops,
10807 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
10809 loc_gdbarch = gdbarch;
10811 describe_other_breakpoints (loc_gdbarch,
10812 sal.pspace, sal.pc, sal.section, -1);
10813 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
10814 version for exception catchpoints, because two catchpoints
10815 used for different exception names will use the same address.
10816 In this case, a "breakpoint ... also set at..." warning is
10817 unproductive. Besides, the warning phrasing is also a bit
10818 inappropriate, we should use the word catchpoint, and tell
10819 the user what type of catchpoint it is. The above is good
10820 enough for now, though. */
10823 init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops);
10825 b->enable_state = bp_enabled;
10826 b->disposition = tempflag ? disp_del : disp_donttouch;
10827 b->addr_string = addr_string;
10828 b->language = language_ada;
10831 /* Splits the argument using space as delimiter. Returns an xmalloc'd
10832 filter list, or NULL if no filtering is required. */
10834 catch_syscall_split_args (char *arg)
10836 VEC(int) *result = NULL;
10837 struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result);
10839 while (*arg != '\0')
10841 int i, syscall_number;
10843 char cur_name[128];
10846 /* Skip whitespace. */
10847 while (isspace (*arg))
10850 for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i)
10851 cur_name[i] = arg[i];
10852 cur_name[i] = '\0';
10855 /* Check if the user provided a syscall name or a number. */
10856 syscall_number = (int) strtol (cur_name, &endptr, 0);
10857 if (*endptr == '\0')
10858 get_syscall_by_number (syscall_number, &s);
10861 /* We have a name. Let's check if it's valid and convert it
10863 get_syscall_by_name (cur_name, &s);
10865 if (s.number == UNKNOWN_SYSCALL)
10866 /* Here we have to issue an error instead of a warning,
10867 because GDB cannot do anything useful if there's no
10868 syscall number to be caught. */
10869 error (_("Unknown syscall name '%s'."), cur_name);
10872 /* Ok, it's valid. */
10873 VEC_safe_push (int, result, s.number);
10876 discard_cleanups (cleanup);
10880 /* Implement the "catch syscall" command. */
10883 catch_syscall_command_1 (char *arg, int from_tty,
10884 struct cmd_list_element *command)
10889 struct gdbarch *gdbarch = get_current_arch ();
10891 /* Checking if the feature if supported. */
10892 if (gdbarch_get_syscall_number_p (gdbarch) == 0)
10893 error (_("The feature 'catch syscall' is not supported on \
10894 this architecture yet."));
10896 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
10898 arg = skip_spaces (arg);
10900 /* We need to do this first "dummy" translation in order
10901 to get the syscall XML file loaded or, most important,
10902 to display a warning to the user if there's no XML file
10903 for his/her architecture. */
10904 get_syscall_by_number (0, &s);
10906 /* The allowed syntax is:
10908 catch syscall <name | number> [<name | number> ... <name | number>]
10910 Let's check if there's a syscall name. */
10913 filter = catch_syscall_split_args (arg);
10917 create_syscall_event_catchpoint (tempflag, filter,
10918 &catch_syscall_breakpoint_ops);
10922 catch_command (char *arg, int from_tty)
10924 error (_("Catch requires an event name."));
10929 tcatch_command (char *arg, int from_tty)
10931 error (_("Catch requires an event name."));
10934 /* A qsort comparison function that sorts breakpoints in order. */
10937 compare_breakpoints (const void *a, const void *b)
10939 const breakpoint_p *ba = a;
10940 uintptr_t ua = (uintptr_t) *ba;
10941 const breakpoint_p *bb = b;
10942 uintptr_t ub = (uintptr_t) *bb;
10944 if ((*ba)->number < (*bb)->number)
10946 else if ((*ba)->number > (*bb)->number)
10949 /* Now sort by address, in case we see, e..g, two breakpoints with
10953 return ub > ub ? 1 : 0;
10956 /* Delete breakpoints by address or line. */
10959 clear_command (char *arg, int from_tty)
10961 struct breakpoint *b, *prev;
10962 VEC(breakpoint_p) *found = 0;
10965 struct symtabs_and_lines sals;
10966 struct symtab_and_line sal;
10968 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
10972 sals = decode_line_spec (arg, (DECODE_LINE_FUNFIRSTLINE
10973 | DECODE_LINE_LIST_MODE));
10978 sals.sals = (struct symtab_and_line *)
10979 xmalloc (sizeof (struct symtab_and_line));
10980 make_cleanup (xfree, sals.sals);
10981 init_sal (&sal); /* Initialize to zeroes. */
10983 /* Set sal's line, symtab, pc, and pspace to the values
10984 corresponding to the last call to print_frame_info. If the
10985 codepoint is not valid, this will set all the fields to 0. */
10986 get_last_displayed_sal (&sal);
10987 if (sal.symtab == 0)
10988 error (_("No source file specified."));
10990 sals.sals[0] = sal;
10996 /* We don't call resolve_sal_pc here. That's not as bad as it
10997 seems, because all existing breakpoints typically have both
10998 file/line and pc set. So, if clear is given file/line, we can
10999 match this to existing breakpoint without obtaining pc at all.
11001 We only support clearing given the address explicitly
11002 present in breakpoint table. Say, we've set breakpoint
11003 at file:line. There were several PC values for that file:line,
11004 due to optimization, all in one block.
11006 We've picked one PC value. If "clear" is issued with another
11007 PC corresponding to the same file:line, the breakpoint won't
11008 be cleared. We probably can still clear the breakpoint, but
11009 since the other PC value is never presented to user, user
11010 can only find it by guessing, and it does not seem important
11011 to support that. */
11013 /* For each line spec given, delete bps which correspond to it. Do
11014 it in two passes, solely to preserve the current behavior that
11015 from_tty is forced true if we delete more than one
11019 make_cleanup (VEC_cleanup (breakpoint_p), &found);
11020 for (i = 0; i < sals.nelts; i++)
11022 int is_abs, sal_name_len;
11024 /* If exact pc given, clear bpts at that pc.
11025 If line given (pc == 0), clear all bpts on specified line.
11026 If defaulting, clear all bpts on default line
11029 defaulting sal.pc != 0 tests to do
11034 1 0 <can't happen> */
11036 sal = sals.sals[i];
11037 is_abs = sal.symtab == NULL ? 1 : IS_ABSOLUTE_PATH (sal.symtab->filename);
11038 sal_name_len = is_abs ? 0 : strlen (sal.symtab->filename);
11040 /* Find all matching breakpoints and add them to 'found'. */
11041 ALL_BREAKPOINTS (b)
11044 /* Are we going to delete b? */
11045 if (b->type != bp_none && !is_watchpoint (b))
11047 struct bp_location *loc = b->loc;
11048 for (; loc; loc = loc->next)
11050 /* If the user specified file:line, don't allow a PC
11051 match. This matches historical gdb behavior. */
11052 int pc_match = (!sal.explicit_line
11054 && (loc->pspace == sal.pspace)
11055 && (loc->address == sal.pc)
11056 && (!section_is_overlay (loc->section)
11057 || loc->section == sal.section));
11058 int line_match = 0;
11060 if ((default_match || sal.explicit_line)
11061 && loc->source_file != NULL
11062 && sal.symtab != NULL
11063 && sal.pspace == loc->pspace
11064 && loc->line_number == sal.line)
11066 if (filename_cmp (loc->source_file,
11067 sal.symtab->filename) == 0)
11069 else if (!IS_ABSOLUTE_PATH (sal.symtab->filename)
11070 && compare_filenames_for_search (loc->source_file,
11071 sal.symtab->filename,
11076 if (pc_match || line_match)
11085 VEC_safe_push(breakpoint_p, found, b);
11089 /* Now go thru the 'found' chain and delete them. */
11090 if (VEC_empty(breakpoint_p, found))
11093 error (_("No breakpoint at %s."), arg);
11095 error (_("No breakpoint at this line."));
11098 /* Remove duplicates from the vec. */
11099 qsort (VEC_address (breakpoint_p, found),
11100 VEC_length (breakpoint_p, found),
11101 sizeof (breakpoint_p),
11102 compare_breakpoints);
11103 prev = VEC_index (breakpoint_p, found, 0);
11104 for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix)
11108 VEC_ordered_remove (breakpoint_p, found, ix);
11113 if (VEC_length(breakpoint_p, found) > 1)
11114 from_tty = 1; /* Always report if deleted more than one. */
11117 if (VEC_length(breakpoint_p, found) == 1)
11118 printf_unfiltered (_("Deleted breakpoint "));
11120 printf_unfiltered (_("Deleted breakpoints "));
11122 breakpoints_changed ();
11124 for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++)
11127 printf_unfiltered ("%d ", b->number);
11128 delete_breakpoint (b);
11131 putchar_unfiltered ('\n');
11133 do_cleanups (cleanups);
11136 /* Delete breakpoint in BS if they are `delete' breakpoints and
11137 all breakpoints that are marked for deletion, whether hit or not.
11138 This is called after any breakpoint is hit, or after errors. */
11141 breakpoint_auto_delete (bpstat bs)
11143 struct breakpoint *b, *b_tmp;
11145 for (; bs; bs = bs->next)
11146 if (bs->breakpoint_at
11147 && bs->breakpoint_at->disposition == disp_del
11149 delete_breakpoint (bs->breakpoint_at);
11151 ALL_BREAKPOINTS_SAFE (b, b_tmp)
11153 if (b->disposition == disp_del_at_next_stop)
11154 delete_breakpoint (b);
11158 /* A comparison function for bp_location AP and BP being interfaced to
11159 qsort. Sort elements primarily by their ADDRESS (no matter what
11160 does breakpoint_address_is_meaningful say for its OWNER),
11161 secondarily by ordering first bp_permanent OWNERed elements and
11162 terciarily just ensuring the array is sorted stable way despite
11163 qsort being an unstable algorithm. */
11166 bp_location_compare (const void *ap, const void *bp)
11168 struct bp_location *a = *(void **) ap;
11169 struct bp_location *b = *(void **) bp;
11170 /* A and B come from existing breakpoints having non-NULL OWNER. */
11171 int a_perm = a->owner->enable_state == bp_permanent;
11172 int b_perm = b->owner->enable_state == bp_permanent;
11174 if (a->address != b->address)
11175 return (a->address > b->address) - (a->address < b->address);
11177 /* Sort locations at the same address by their pspace number, keeping
11178 locations of the same inferior (in a multi-inferior environment)
11181 if (a->pspace->num != b->pspace->num)
11182 return ((a->pspace->num > b->pspace->num)
11183 - (a->pspace->num < b->pspace->num));
11185 /* Sort permanent breakpoints first. */
11186 if (a_perm != b_perm)
11187 return (a_perm < b_perm) - (a_perm > b_perm);
11189 /* Make the internal GDB representation stable across GDB runs
11190 where A and B memory inside GDB can differ. Breakpoint locations of
11191 the same type at the same address can be sorted in arbitrary order. */
11193 if (a->owner->number != b->owner->number)
11194 return ((a->owner->number > b->owner->number)
11195 - (a->owner->number < b->owner->number));
11197 return (a > b) - (a < b);
11200 /* Set bp_location_placed_address_before_address_max and
11201 bp_location_shadow_len_after_address_max according to the current
11202 content of the bp_location array. */
11205 bp_location_target_extensions_update (void)
11207 struct bp_location *bl, **blp_tmp;
11209 bp_location_placed_address_before_address_max = 0;
11210 bp_location_shadow_len_after_address_max = 0;
11212 ALL_BP_LOCATIONS (bl, blp_tmp)
11214 CORE_ADDR start, end, addr;
11216 if (!bp_location_has_shadow (bl))
11219 start = bl->target_info.placed_address;
11220 end = start + bl->target_info.shadow_len;
11222 gdb_assert (bl->address >= start);
11223 addr = bl->address - start;
11224 if (addr > bp_location_placed_address_before_address_max)
11225 bp_location_placed_address_before_address_max = addr;
11227 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11229 gdb_assert (bl->address < end);
11230 addr = end - bl->address;
11231 if (addr > bp_location_shadow_len_after_address_max)
11232 bp_location_shadow_len_after_address_max = addr;
11236 /* Download tracepoint locations if they haven't been. */
11239 download_tracepoint_locations (void)
11241 struct bp_location *bl, **blp_tmp;
11242 struct cleanup *old_chain;
11244 if (!target_can_download_tracepoint ())
11247 old_chain = save_current_space_and_thread ();
11249 ALL_BP_LOCATIONS (bl, blp_tmp)
11251 struct tracepoint *t;
11253 if (!is_tracepoint (bl->owner))
11256 if ((bl->owner->type == bp_fast_tracepoint
11257 ? !may_insert_fast_tracepoints
11258 : !may_insert_tracepoints))
11261 /* In tracepoint, locations are _never_ duplicated, so
11262 should_be_inserted is equivalent to
11263 unduplicated_should_be_inserted. */
11264 if (!should_be_inserted (bl) || bl->inserted)
11267 switch_to_program_space_and_thread (bl->pspace);
11269 target_download_tracepoint (bl);
11272 t = (struct tracepoint *) bl->owner;
11273 t->number_on_target = bl->owner->number;
11276 do_cleanups (old_chain);
11279 /* Swap the insertion/duplication state between two locations. */
11282 swap_insertion (struct bp_location *left, struct bp_location *right)
11284 const int left_inserted = left->inserted;
11285 const int left_duplicate = left->duplicate;
11286 const int left_needs_update = left->needs_update;
11287 const struct bp_target_info left_target_info = left->target_info;
11289 /* Locations of tracepoints can never be duplicated. */
11290 if (is_tracepoint (left->owner))
11291 gdb_assert (!left->duplicate);
11292 if (is_tracepoint (right->owner))
11293 gdb_assert (!right->duplicate);
11295 left->inserted = right->inserted;
11296 left->duplicate = right->duplicate;
11297 left->needs_update = right->needs_update;
11298 left->target_info = right->target_info;
11299 right->inserted = left_inserted;
11300 right->duplicate = left_duplicate;
11301 right->needs_update = left_needs_update;
11302 right->target_info = left_target_info;
11305 /* Force the re-insertion of the locations at ADDRESS. This is called
11306 once a new/deleted/modified duplicate location is found and we are evaluating
11307 conditions on the target's side. Such conditions need to be updated on
11311 force_breakpoint_reinsertion (struct bp_location *bl)
11313 struct bp_location **locp = NULL, **loc2p;
11314 struct bp_location *loc;
11315 CORE_ADDR address = 0;
11318 address = bl->address;
11319 pspace_num = bl->pspace->num;
11321 /* This is only meaningful if the target is
11322 evaluating conditions and if the user has
11323 opted for condition evaluation on the target's
11325 if (gdb_evaluates_breakpoint_condition_p ()
11326 || !target_supports_evaluation_of_breakpoint_conditions ())
11329 /* Flag all breakpoint locations with this address and
11330 the same program space as the location
11331 as "its condition has changed". We need to
11332 update the conditions on the target's side. */
11333 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address)
11337 if (!is_breakpoint (loc->owner)
11338 || pspace_num != loc->pspace->num)
11341 /* Flag the location appropriately. We use a different state to
11342 let everyone know that we already updated the set of locations
11343 with addr bl->address and program space bl->pspace. This is so
11344 we don't have to keep calling these functions just to mark locations
11345 that have already been marked. */
11346 loc->condition_changed = condition_updated;
11348 /* Free the agent expression bytecode as well. We will compute
11350 if (loc->cond_bytecode)
11352 free_agent_expr (loc->cond_bytecode);
11353 loc->cond_bytecode = NULL;
11358 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
11359 into the inferior, only remove already-inserted locations that no
11360 longer should be inserted. Functions that delete a breakpoint or
11361 breakpoints should pass false, so that deleting a breakpoint
11362 doesn't have the side effect of inserting the locations of other
11363 breakpoints that are marked not-inserted, but should_be_inserted
11364 returns true on them.
11366 This behaviour is useful is situations close to tear-down -- e.g.,
11367 after an exec, while the target still has execution, but breakpoint
11368 shadows of the previous executable image should *NOT* be restored
11369 to the new image; or before detaching, where the target still has
11370 execution and wants to delete breakpoints from GDB's lists, and all
11371 breakpoints had already been removed from the inferior. */
11374 update_global_location_list (int should_insert)
11376 struct breakpoint *b;
11377 struct bp_location **locp, *loc;
11378 struct cleanup *cleanups;
11379 /* Last breakpoint location address that was marked for update. */
11380 CORE_ADDR last_addr = 0;
11381 /* Last breakpoint location program space that was marked for update. */
11382 int last_pspace_num = -1;
11384 /* Used in the duplicates detection below. When iterating over all
11385 bp_locations, points to the first bp_location of a given address.
11386 Breakpoints and watchpoints of different types are never
11387 duplicates of each other. Keep one pointer for each type of
11388 breakpoint/watchpoint, so we only need to loop over all locations
11390 struct bp_location *bp_loc_first; /* breakpoint */
11391 struct bp_location *wp_loc_first; /* hardware watchpoint */
11392 struct bp_location *awp_loc_first; /* access watchpoint */
11393 struct bp_location *rwp_loc_first; /* read watchpoint */
11395 /* Saved former bp_location array which we compare against the newly
11396 built bp_location from the current state of ALL_BREAKPOINTS. */
11397 struct bp_location **old_location, **old_locp;
11398 unsigned old_location_count;
11400 old_location = bp_location;
11401 old_location_count = bp_location_count;
11402 bp_location = NULL;
11403 bp_location_count = 0;
11404 cleanups = make_cleanup (xfree, old_location);
11406 ALL_BREAKPOINTS (b)
11407 for (loc = b->loc; loc; loc = loc->next)
11408 bp_location_count++;
11410 bp_location = xmalloc (sizeof (*bp_location) * bp_location_count);
11411 locp = bp_location;
11412 ALL_BREAKPOINTS (b)
11413 for (loc = b->loc; loc; loc = loc->next)
11415 qsort (bp_location, bp_location_count, sizeof (*bp_location),
11416 bp_location_compare);
11418 bp_location_target_extensions_update ();
11420 /* Identify bp_location instances that are no longer present in the
11421 new list, and therefore should be freed. Note that it's not
11422 necessary that those locations should be removed from inferior --
11423 if there's another location at the same address (previously
11424 marked as duplicate), we don't need to remove/insert the
11427 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11428 and former bp_location array state respectively. */
11430 locp = bp_location;
11431 for (old_locp = old_location; old_locp < old_location + old_location_count;
11434 struct bp_location *old_loc = *old_locp;
11435 struct bp_location **loc2p;
11437 /* Tells if 'old_loc' is found among the new locations. If
11438 not, we have to free it. */
11439 int found_object = 0;
11440 /* Tells if the location should remain inserted in the target. */
11441 int keep_in_target = 0;
11444 /* Skip LOCP entries which will definitely never be needed.
11445 Stop either at or being the one matching OLD_LOC. */
11446 while (locp < bp_location + bp_location_count
11447 && (*locp)->address < old_loc->address)
11451 (loc2p < bp_location + bp_location_count
11452 && (*loc2p)->address == old_loc->address);
11455 /* Check if this is a new/duplicated location or a duplicated
11456 location that had its condition modified. If so, we want to send
11457 its condition to the target if evaluation of conditions is taking
11459 if ((*loc2p)->condition_changed == condition_modified
11460 && (last_addr != old_loc->address
11461 || last_pspace_num != old_loc->pspace->num))
11463 force_breakpoint_reinsertion (*loc2p);
11464 last_pspace_num = old_loc->pspace->num;
11467 if (*loc2p == old_loc)
11471 /* We have already handled this address, update it so that we don't
11472 have to go through updates again. */
11473 last_addr = old_loc->address;
11475 /* Target-side condition evaluation: Handle deleted locations. */
11477 force_breakpoint_reinsertion (old_loc);
11479 /* If this location is no longer present, and inserted, look if
11480 there's maybe a new location at the same address. If so,
11481 mark that one inserted, and don't remove this one. This is
11482 needed so that we don't have a time window where a breakpoint
11483 at certain location is not inserted. */
11485 if (old_loc->inserted)
11487 /* If the location is inserted now, we might have to remove
11490 if (found_object && should_be_inserted (old_loc))
11492 /* The location is still present in the location list,
11493 and still should be inserted. Don't do anything. */
11494 keep_in_target = 1;
11498 /* This location still exists, but it won't be kept in the
11499 target since it may have been disabled. We proceed to
11500 remove its target-side condition. */
11502 /* The location is either no longer present, or got
11503 disabled. See if there's another location at the
11504 same address, in which case we don't need to remove
11505 this one from the target. */
11507 /* OLD_LOC comes from existing struct breakpoint. */
11508 if (breakpoint_address_is_meaningful (old_loc->owner))
11511 (loc2p < bp_location + bp_location_count
11512 && (*loc2p)->address == old_loc->address);
11515 struct bp_location *loc2 = *loc2p;
11517 if (breakpoint_locations_match (loc2, old_loc))
11519 /* Read watchpoint locations are switched to
11520 access watchpoints, if the former are not
11521 supported, but the latter are. */
11522 if (is_hardware_watchpoint (old_loc->owner))
11524 gdb_assert (is_hardware_watchpoint (loc2->owner));
11525 loc2->watchpoint_type = old_loc->watchpoint_type;
11528 /* loc2 is a duplicated location. We need to check
11529 if it should be inserted in case it will be
11531 if (loc2 != old_loc
11532 && unduplicated_should_be_inserted (loc2))
11534 swap_insertion (old_loc, loc2);
11535 keep_in_target = 1;
11543 if (!keep_in_target)
11545 if (remove_breakpoint (old_loc, mark_uninserted))
11547 /* This is just about all we can do. We could keep
11548 this location on the global list, and try to
11549 remove it next time, but there's no particular
11550 reason why we will succeed next time.
11552 Note that at this point, old_loc->owner is still
11553 valid, as delete_breakpoint frees the breakpoint
11554 only after calling us. */
11555 printf_filtered (_("warning: Error removing "
11556 "breakpoint %d\n"),
11557 old_loc->owner->number);
11565 if (removed && non_stop
11566 && breakpoint_address_is_meaningful (old_loc->owner)
11567 && !is_hardware_watchpoint (old_loc->owner))
11569 /* This location was removed from the target. In
11570 non-stop mode, a race condition is possible where
11571 we've removed a breakpoint, but stop events for that
11572 breakpoint are already queued and will arrive later.
11573 We apply an heuristic to be able to distinguish such
11574 SIGTRAPs from other random SIGTRAPs: we keep this
11575 breakpoint location for a bit, and will retire it
11576 after we see some number of events. The theory here
11577 is that reporting of events should, "on the average",
11578 be fair, so after a while we'll see events from all
11579 threads that have anything of interest, and no longer
11580 need to keep this breakpoint location around. We
11581 don't hold locations forever so to reduce chances of
11582 mistaking a non-breakpoint SIGTRAP for a breakpoint
11585 The heuristic failing can be disastrous on
11586 decr_pc_after_break targets.
11588 On decr_pc_after_break targets, like e.g., x86-linux,
11589 if we fail to recognize a late breakpoint SIGTRAP,
11590 because events_till_retirement has reached 0 too
11591 soon, we'll fail to do the PC adjustment, and report
11592 a random SIGTRAP to the user. When the user resumes
11593 the inferior, it will most likely immediately crash
11594 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
11595 corrupted, because of being resumed e.g., in the
11596 middle of a multi-byte instruction, or skipped a
11597 one-byte instruction. This was actually seen happen
11598 on native x86-linux, and should be less rare on
11599 targets that do not support new thread events, like
11600 remote, due to the heuristic depending on
11603 Mistaking a random SIGTRAP for a breakpoint trap
11604 causes similar symptoms (PC adjustment applied when
11605 it shouldn't), but then again, playing with SIGTRAPs
11606 behind the debugger's back is asking for trouble.
11608 Since hardware watchpoint traps are always
11609 distinguishable from other traps, so we don't need to
11610 apply keep hardware watchpoint moribund locations
11611 around. We simply always ignore hardware watchpoint
11612 traps we can no longer explain. */
11614 old_loc->events_till_retirement = 3 * (thread_count () + 1);
11615 old_loc->owner = NULL;
11617 VEC_safe_push (bp_location_p, moribund_locations, old_loc);
11621 old_loc->owner = NULL;
11622 decref_bp_location (&old_loc);
11627 /* Rescan breakpoints at the same address and section, marking the
11628 first one as "first" and any others as "duplicates". This is so
11629 that the bpt instruction is only inserted once. If we have a
11630 permanent breakpoint at the same place as BPT, make that one the
11631 official one, and the rest as duplicates. Permanent breakpoints
11632 are sorted first for the same address.
11634 Do the same for hardware watchpoints, but also considering the
11635 watchpoint's type (regular/access/read) and length. */
11637 bp_loc_first = NULL;
11638 wp_loc_first = NULL;
11639 awp_loc_first = NULL;
11640 rwp_loc_first = NULL;
11641 ALL_BP_LOCATIONS (loc, locp)
11643 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
11645 struct bp_location **loc_first_p;
11648 if (!should_be_inserted (loc)
11649 || !breakpoint_address_is_meaningful (b)
11650 /* Don't detect duplicate for tracepoint locations because they are
11651 never duplicated. See the comments in field `duplicate' of
11652 `struct bp_location'. */
11653 || is_tracepoint (b))
11655 /* Clear the condition modification flag. */
11656 loc->condition_changed = condition_unchanged;
11660 /* Permanent breakpoint should always be inserted. */
11661 if (b->enable_state == bp_permanent && ! loc->inserted)
11662 internal_error (__FILE__, __LINE__,
11663 _("allegedly permanent breakpoint is not "
11664 "actually inserted"));
11666 if (b->type == bp_hardware_watchpoint)
11667 loc_first_p = &wp_loc_first;
11668 else if (b->type == bp_read_watchpoint)
11669 loc_first_p = &rwp_loc_first;
11670 else if (b->type == bp_access_watchpoint)
11671 loc_first_p = &awp_loc_first;
11673 loc_first_p = &bp_loc_first;
11675 if (*loc_first_p == NULL
11676 || (overlay_debugging && loc->section != (*loc_first_p)->section)
11677 || !breakpoint_locations_match (loc, *loc_first_p))
11679 *loc_first_p = loc;
11680 loc->duplicate = 0;
11682 if (is_breakpoint (loc->owner) && loc->condition_changed)
11684 loc->needs_update = 1;
11685 /* Clear the condition modification flag. */
11686 loc->condition_changed = condition_unchanged;
11692 /* This and the above ensure the invariant that the first location
11693 is not duplicated, and is the inserted one.
11694 All following are marked as duplicated, and are not inserted. */
11696 swap_insertion (loc, *loc_first_p);
11697 loc->duplicate = 1;
11699 /* Clear the condition modification flag. */
11700 loc->condition_changed = condition_unchanged;
11702 if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted
11703 && b->enable_state != bp_permanent)
11704 internal_error (__FILE__, __LINE__,
11705 _("another breakpoint was inserted on top of "
11706 "a permanent breakpoint"));
11709 if (breakpoints_always_inserted_mode ()
11710 && (have_live_inferiors ()
11711 || (gdbarch_has_global_breakpoints (target_gdbarch))))
11714 insert_breakpoint_locations ();
11717 /* Though should_insert is false, we may need to update conditions
11718 on the target's side if it is evaluating such conditions. We
11719 only update conditions for locations that are marked
11721 update_inserted_breakpoint_locations ();
11726 download_tracepoint_locations ();
11728 do_cleanups (cleanups);
11732 breakpoint_retire_moribund (void)
11734 struct bp_location *loc;
11737 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
11738 if (--(loc->events_till_retirement) == 0)
11740 decref_bp_location (&loc);
11741 VEC_unordered_remove (bp_location_p, moribund_locations, ix);
11747 update_global_location_list_nothrow (int inserting)
11749 volatile struct gdb_exception e;
11751 TRY_CATCH (e, RETURN_MASK_ERROR)
11752 update_global_location_list (inserting);
11755 /* Clear BKP from a BPS. */
11758 bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt)
11762 for (bs = bps; bs; bs = bs->next)
11763 if (bs->breakpoint_at == bpt)
11765 bs->breakpoint_at = NULL;
11766 bs->old_val = NULL;
11767 /* bs->commands will be freed later. */
11771 /* Callback for iterate_over_threads. */
11773 bpstat_remove_breakpoint_callback (struct thread_info *th, void *data)
11775 struct breakpoint *bpt = data;
11777 bpstat_remove_bp_location (th->control.stop_bpstat, bpt);
11781 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
11785 say_where (struct breakpoint *b)
11787 struct ui_out *uiout = current_uiout;
11788 struct value_print_options opts;
11790 get_user_print_options (&opts);
11792 /* i18n: cagney/2005-02-11: Below needs to be merged into a
11794 if (b->loc == NULL)
11796 printf_filtered (_(" (%s) pending."), b->addr_string);
11800 if (opts.addressprint || b->loc->source_file == NULL)
11802 printf_filtered (" at ");
11803 fputs_filtered (paddress (b->loc->gdbarch, b->loc->address),
11806 if (b->loc->source_file)
11808 /* If there is a single location, we can print the location
11810 if (b->loc->next == NULL)
11811 printf_filtered (": file %s, line %d.",
11812 b->loc->source_file, b->loc->line_number);
11814 /* This is not ideal, but each location may have a
11815 different file name, and this at least reflects the
11816 real situation somewhat. */
11817 printf_filtered (": %s.", b->addr_string);
11822 struct bp_location *loc = b->loc;
11824 for (; loc; loc = loc->next)
11826 printf_filtered (" (%d locations)", n);
11831 /* Default bp_location_ops methods. */
11834 bp_location_dtor (struct bp_location *self)
11836 xfree (self->cond);
11837 if (self->cond_bytecode)
11838 free_agent_expr (self->cond_bytecode);
11839 xfree (self->function_name);
11840 xfree (self->source_file);
11843 static const struct bp_location_ops bp_location_ops =
11848 /* Default breakpoint_ops methods all breakpoint_ops ultimately
11852 base_breakpoint_dtor (struct breakpoint *self)
11854 decref_counted_command_line (&self->commands);
11855 xfree (self->cond_string);
11856 xfree (self->addr_string);
11857 xfree (self->filter);
11858 xfree (self->addr_string_range_end);
11861 static struct bp_location *
11862 base_breakpoint_allocate_location (struct breakpoint *self)
11864 struct bp_location *loc;
11866 loc = XNEW (struct bp_location);
11867 init_bp_location (loc, &bp_location_ops, self);
11872 base_breakpoint_re_set (struct breakpoint *b)
11874 /* Nothing to re-set. */
11877 #define internal_error_pure_virtual_called() \
11878 gdb_assert_not_reached ("pure virtual function called")
11881 base_breakpoint_insert_location (struct bp_location *bl)
11883 internal_error_pure_virtual_called ();
11887 base_breakpoint_remove_location (struct bp_location *bl)
11889 internal_error_pure_virtual_called ();
11893 base_breakpoint_breakpoint_hit (const struct bp_location *bl,
11894 struct address_space *aspace,
11896 const struct target_waitstatus *ws)
11898 internal_error_pure_virtual_called ();
11902 base_breakpoint_check_status (bpstat bs)
11907 /* A "works_in_software_mode" breakpoint_ops method that just internal
11911 base_breakpoint_works_in_software_mode (const struct breakpoint *b)
11913 internal_error_pure_virtual_called ();
11916 /* A "resources_needed" breakpoint_ops method that just internal
11920 base_breakpoint_resources_needed (const struct bp_location *bl)
11922 internal_error_pure_virtual_called ();
11925 static enum print_stop_action
11926 base_breakpoint_print_it (bpstat bs)
11928 internal_error_pure_virtual_called ();
11932 base_breakpoint_print_one_detail (const struct breakpoint *self,
11933 struct ui_out *uiout)
11939 base_breakpoint_print_mention (struct breakpoint *b)
11941 internal_error_pure_virtual_called ();
11945 base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp)
11947 internal_error_pure_virtual_called ();
11951 base_breakpoint_create_sals_from_address (char **arg,
11952 struct linespec_result *canonical,
11953 enum bptype type_wanted,
11957 internal_error_pure_virtual_called ();
11961 base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch,
11962 struct linespec_result *c,
11963 struct linespec_sals *lsal,
11965 enum bptype type_wanted,
11966 enum bpdisp disposition,
11968 int task, int ignore_count,
11969 const struct breakpoint_ops *o,
11970 int from_tty, int enabled,
11973 internal_error_pure_virtual_called ();
11977 base_breakpoint_decode_linespec (struct breakpoint *b, char **s,
11978 struct symtabs_and_lines *sals)
11980 internal_error_pure_virtual_called ();
11983 static struct breakpoint_ops base_breakpoint_ops =
11985 base_breakpoint_dtor,
11986 base_breakpoint_allocate_location,
11987 base_breakpoint_re_set,
11988 base_breakpoint_insert_location,
11989 base_breakpoint_remove_location,
11990 base_breakpoint_breakpoint_hit,
11991 base_breakpoint_check_status,
11992 base_breakpoint_resources_needed,
11993 base_breakpoint_works_in_software_mode,
11994 base_breakpoint_print_it,
11996 base_breakpoint_print_one_detail,
11997 base_breakpoint_print_mention,
11998 base_breakpoint_print_recreate,
11999 base_breakpoint_create_sals_from_address,
12000 base_breakpoint_create_breakpoints_sal,
12001 base_breakpoint_decode_linespec,
12004 /* Default breakpoint_ops methods. */
12007 bkpt_re_set (struct breakpoint *b)
12009 /* FIXME: is this still reachable? */
12010 if (b->addr_string == NULL)
12012 /* Anything without a string can't be re-set. */
12013 delete_breakpoint (b);
12017 breakpoint_re_set_default (b);
12021 bkpt_insert_location (struct bp_location *bl)
12023 if (bl->loc_type == bp_loc_hardware_breakpoint)
12024 return target_insert_hw_breakpoint (bl->gdbarch,
12027 return target_insert_breakpoint (bl->gdbarch,
12032 bkpt_remove_location (struct bp_location *bl)
12034 if (bl->loc_type == bp_loc_hardware_breakpoint)
12035 return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info);
12037 return target_remove_breakpoint (bl->gdbarch, &bl->target_info);
12041 bkpt_breakpoint_hit (const struct bp_location *bl,
12042 struct address_space *aspace, CORE_ADDR bp_addr,
12043 const struct target_waitstatus *ws)
12045 struct breakpoint *b = bl->owner;
12047 if (ws->kind != TARGET_WAITKIND_STOPPED
12048 || ws->value.sig != TARGET_SIGNAL_TRAP)
12051 if (!breakpoint_address_match (bl->pspace->aspace, bl->address,
12055 if (overlay_debugging /* unmapped overlay section */
12056 && section_is_overlay (bl->section)
12057 && !section_is_mapped (bl->section))
12064 bkpt_resources_needed (const struct bp_location *bl)
12066 gdb_assert (bl->owner->type == bp_hardware_breakpoint);
12071 static enum print_stop_action
12072 bkpt_print_it (bpstat bs)
12074 struct breakpoint *b;
12075 const struct bp_location *bl;
12077 struct ui_out *uiout = current_uiout;
12079 gdb_assert (bs->bp_location_at != NULL);
12081 bl = bs->bp_location_at;
12082 b = bs->breakpoint_at;
12084 bp_temp = b->disposition == disp_del;
12085 if (bl->address != bl->requested_address)
12086 breakpoint_adjustment_warning (bl->requested_address,
12089 annotate_breakpoint (b->number);
12091 ui_out_text (uiout, "\nTemporary breakpoint ");
12093 ui_out_text (uiout, "\nBreakpoint ");
12094 if (ui_out_is_mi_like_p (uiout))
12096 ui_out_field_string (uiout, "reason",
12097 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
12098 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
12100 ui_out_field_int (uiout, "bkptno", b->number);
12101 ui_out_text (uiout, ", ");
12103 return PRINT_SRC_AND_LOC;
12107 bkpt_print_mention (struct breakpoint *b)
12109 if (ui_out_is_mi_like_p (current_uiout))
12114 case bp_breakpoint:
12115 case bp_gnu_ifunc_resolver:
12116 if (b->disposition == disp_del)
12117 printf_filtered (_("Temporary breakpoint"));
12119 printf_filtered (_("Breakpoint"));
12120 printf_filtered (_(" %d"), b->number);
12121 if (b->type == bp_gnu_ifunc_resolver)
12122 printf_filtered (_(" at gnu-indirect-function resolver"));
12124 case bp_hardware_breakpoint:
12125 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
12133 bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp)
12135 if (tp->type == bp_breakpoint && tp->disposition == disp_del)
12136 fprintf_unfiltered (fp, "tbreak");
12137 else if (tp->type == bp_breakpoint)
12138 fprintf_unfiltered (fp, "break");
12139 else if (tp->type == bp_hardware_breakpoint
12140 && tp->disposition == disp_del)
12141 fprintf_unfiltered (fp, "thbreak");
12142 else if (tp->type == bp_hardware_breakpoint)
12143 fprintf_unfiltered (fp, "hbreak");
12145 internal_error (__FILE__, __LINE__,
12146 _("unhandled breakpoint type %d"), (int) tp->type);
12148 fprintf_unfiltered (fp, " %s", tp->addr_string);
12149 print_recreate_thread (tp, fp);
12153 bkpt_create_sals_from_address (char **arg,
12154 struct linespec_result *canonical,
12155 enum bptype type_wanted,
12156 char *addr_start, char **copy_arg)
12158 create_sals_from_address_default (arg, canonical, type_wanted,
12159 addr_start, copy_arg);
12163 bkpt_create_breakpoints_sal (struct gdbarch *gdbarch,
12164 struct linespec_result *canonical,
12165 struct linespec_sals *lsal,
12167 enum bptype type_wanted,
12168 enum bpdisp disposition,
12170 int task, int ignore_count,
12171 const struct breakpoint_ops *ops,
12172 int from_tty, int enabled,
12175 create_breakpoints_sal_default (gdbarch, canonical, lsal,
12176 cond_string, type_wanted,
12177 disposition, thread, task,
12178 ignore_count, ops, from_tty,
12179 enabled, internal);
12183 bkpt_decode_linespec (struct breakpoint *b, char **s,
12184 struct symtabs_and_lines *sals)
12186 decode_linespec_default (b, s, sals);
12189 /* Virtual table for internal breakpoints. */
12192 internal_bkpt_re_set (struct breakpoint *b)
12196 /* Delete overlay event and longjmp master breakpoints; they
12197 will be reset later by breakpoint_re_set. */
12198 case bp_overlay_event:
12199 case bp_longjmp_master:
12200 case bp_std_terminate_master:
12201 case bp_exception_master:
12202 delete_breakpoint (b);
12205 /* This breakpoint is special, it's set up when the inferior
12206 starts and we really don't want to touch it. */
12207 case bp_shlib_event:
12209 /* Like bp_shlib_event, this breakpoint type is special. Once
12210 it is set up, we do not want to touch it. */
12211 case bp_thread_event:
12217 internal_bkpt_check_status (bpstat bs)
12219 if (bs->breakpoint_at->type == bp_shlib_event)
12221 /* If requested, stop when the dynamic linker notifies GDB of
12222 events. This allows the user to get control and place
12223 breakpoints in initializer routines for dynamically loaded
12224 objects (among other things). */
12225 bs->stop = stop_on_solib_events;
12226 bs->print = stop_on_solib_events;
12232 static enum print_stop_action
12233 internal_bkpt_print_it (bpstat bs)
12235 struct ui_out *uiout = current_uiout;
12236 struct breakpoint *b;
12238 b = bs->breakpoint_at;
12242 case bp_shlib_event:
12243 /* Did we stop because the user set the stop_on_solib_events
12244 variable? (If so, we report this as a generic, "Stopped due
12245 to shlib event" message.) */
12246 print_solib_event (0);
12249 case bp_thread_event:
12250 /* Not sure how we will get here.
12251 GDB should not stop for these breakpoints. */
12252 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
12255 case bp_overlay_event:
12256 /* By analogy with the thread event, GDB should not stop for these. */
12257 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
12260 case bp_longjmp_master:
12261 /* These should never be enabled. */
12262 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
12265 case bp_std_terminate_master:
12266 /* These should never be enabled. */
12267 printf_filtered (_("std::terminate Master Breakpoint: "
12268 "gdb should not stop!\n"));
12271 case bp_exception_master:
12272 /* These should never be enabled. */
12273 printf_filtered (_("Exception Master Breakpoint: "
12274 "gdb should not stop!\n"));
12278 return PRINT_NOTHING;
12282 internal_bkpt_print_mention (struct breakpoint *b)
12284 /* Nothing to mention. These breakpoints are internal. */
12287 /* Virtual table for momentary breakpoints */
12290 momentary_bkpt_re_set (struct breakpoint *b)
12292 /* Keep temporary breakpoints, which can be encountered when we step
12293 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
12294 Otherwise these should have been blown away via the cleanup chain
12295 or by breakpoint_init_inferior when we rerun the executable. */
12299 momentary_bkpt_check_status (bpstat bs)
12301 /* Nothing. The point of these breakpoints is causing a stop. */
12304 static enum print_stop_action
12305 momentary_bkpt_print_it (bpstat bs)
12307 struct ui_out *uiout = current_uiout;
12309 if (ui_out_is_mi_like_p (uiout))
12311 struct breakpoint *b = bs->breakpoint_at;
12316 ui_out_field_string
12318 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED));
12322 ui_out_field_string
12324 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED));
12329 return PRINT_UNKNOWN;
12333 momentary_bkpt_print_mention (struct breakpoint *b)
12335 /* Nothing to mention. These breakpoints are internal. */
12338 /* The breakpoint_ops structure to be used in tracepoints. */
12341 tracepoint_re_set (struct breakpoint *b)
12343 breakpoint_re_set_default (b);
12347 tracepoint_breakpoint_hit (const struct bp_location *bl,
12348 struct address_space *aspace, CORE_ADDR bp_addr,
12349 const struct target_waitstatus *ws)
12351 /* By definition, the inferior does not report stops at
12357 tracepoint_print_one_detail (const struct breakpoint *self,
12358 struct ui_out *uiout)
12360 struct tracepoint *tp = (struct tracepoint *) self;
12361 if (tp->static_trace_marker_id)
12363 gdb_assert (self->type == bp_static_tracepoint);
12365 ui_out_text (uiout, "\tmarker id is ");
12366 ui_out_field_string (uiout, "static-tracepoint-marker-string-id",
12367 tp->static_trace_marker_id);
12368 ui_out_text (uiout, "\n");
12373 tracepoint_print_mention (struct breakpoint *b)
12375 if (ui_out_is_mi_like_p (current_uiout))
12380 case bp_tracepoint:
12381 printf_filtered (_("Tracepoint"));
12382 printf_filtered (_(" %d"), b->number);
12384 case bp_fast_tracepoint:
12385 printf_filtered (_("Fast tracepoint"));
12386 printf_filtered (_(" %d"), b->number);
12388 case bp_static_tracepoint:
12389 printf_filtered (_("Static tracepoint"));
12390 printf_filtered (_(" %d"), b->number);
12393 internal_error (__FILE__, __LINE__,
12394 _("unhandled tracepoint type %d"), (int) b->type);
12401 tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp)
12403 struct tracepoint *tp = (struct tracepoint *) self;
12405 if (self->type == bp_fast_tracepoint)
12406 fprintf_unfiltered (fp, "ftrace");
12407 if (self->type == bp_static_tracepoint)
12408 fprintf_unfiltered (fp, "strace");
12409 else if (self->type == bp_tracepoint)
12410 fprintf_unfiltered (fp, "trace");
12412 internal_error (__FILE__, __LINE__,
12413 _("unhandled tracepoint type %d"), (int) self->type);
12415 fprintf_unfiltered (fp, " %s", self->addr_string);
12416 print_recreate_thread (self, fp);
12418 if (tp->pass_count)
12419 fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count);
12423 tracepoint_create_sals_from_address (char **arg,
12424 struct linespec_result *canonical,
12425 enum bptype type_wanted,
12426 char *addr_start, char **copy_arg)
12428 create_sals_from_address_default (arg, canonical, type_wanted,
12429 addr_start, copy_arg);
12433 tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch,
12434 struct linespec_result *canonical,
12435 struct linespec_sals *lsal,
12437 enum bptype type_wanted,
12438 enum bpdisp disposition,
12440 int task, int ignore_count,
12441 const struct breakpoint_ops *ops,
12442 int from_tty, int enabled,
12445 create_breakpoints_sal_default (gdbarch, canonical, lsal,
12446 cond_string, type_wanted,
12447 disposition, thread, task,
12448 ignore_count, ops, from_tty,
12449 enabled, internal);
12453 tracepoint_decode_linespec (struct breakpoint *b, char **s,
12454 struct symtabs_and_lines *sals)
12456 decode_linespec_default (b, s, sals);
12459 struct breakpoint_ops tracepoint_breakpoint_ops;
12461 /* The breakpoint_ops structure to be used on static tracepoints with
12465 strace_marker_create_sals_from_address (char **arg,
12466 struct linespec_result *canonical,
12467 enum bptype type_wanted,
12468 char *addr_start, char **copy_arg)
12470 struct linespec_sals lsal;
12472 lsal.sals = decode_static_tracepoint_spec (arg);
12474 *copy_arg = savestring (addr_start, *arg - addr_start);
12476 canonical->addr_string = xstrdup (*copy_arg);
12477 lsal.canonical = xstrdup (*copy_arg);
12478 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
12482 strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch,
12483 struct linespec_result *canonical,
12484 struct linespec_sals *lsal,
12486 enum bptype type_wanted,
12487 enum bpdisp disposition,
12489 int task, int ignore_count,
12490 const struct breakpoint_ops *ops,
12491 int from_tty, int enabled,
12496 /* If the user is creating a static tracepoint by marker id
12497 (strace -m MARKER_ID), then store the sals index, so that
12498 breakpoint_re_set can try to match up which of the newly
12499 found markers corresponds to this one, and, don't try to
12500 expand multiple locations for each sal, given than SALS
12501 already should contain all sals for MARKER_ID. */
12503 for (i = 0; i < lsal->sals.nelts; ++i)
12505 struct symtabs_and_lines expanded;
12506 struct tracepoint *tp;
12507 struct cleanup *old_chain;
12510 expanded.nelts = 1;
12511 expanded.sals = &lsal->sals.sals[i];
12513 addr_string = xstrdup (canonical->addr_string);
12514 old_chain = make_cleanup (xfree, addr_string);
12516 tp = XCNEW (struct tracepoint);
12517 init_breakpoint_sal (&tp->base, gdbarch, expanded,
12519 cond_string, type_wanted, disposition,
12520 thread, task, ignore_count, ops,
12521 from_tty, enabled, internal,
12522 canonical->special_display);
12523 /* Given that its possible to have multiple markers with
12524 the same string id, if the user is creating a static
12525 tracepoint by marker id ("strace -m MARKER_ID"), then
12526 store the sals index, so that breakpoint_re_set can
12527 try to match up which of the newly found markers
12528 corresponds to this one */
12529 tp->static_trace_marker_id_idx = i;
12531 install_breakpoint (internal, &tp->base, 0);
12533 discard_cleanups (old_chain);
12538 strace_marker_decode_linespec (struct breakpoint *b, char **s,
12539 struct symtabs_and_lines *sals)
12541 struct tracepoint *tp = (struct tracepoint *) b;
12543 *sals = decode_static_tracepoint_spec (s);
12544 if (sals->nelts > tp->static_trace_marker_id_idx)
12546 sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx];
12550 error (_("marker %s not found"), tp->static_trace_marker_id);
12553 static struct breakpoint_ops strace_marker_breakpoint_ops;
12556 strace_marker_p (struct breakpoint *b)
12558 return b->ops == &strace_marker_breakpoint_ops;
12561 /* Delete a breakpoint and clean up all traces of it in the data
12565 delete_breakpoint (struct breakpoint *bpt)
12567 struct breakpoint *b;
12569 gdb_assert (bpt != NULL);
12571 /* Has this bp already been deleted? This can happen because
12572 multiple lists can hold pointers to bp's. bpstat lists are
12575 One example of this happening is a watchpoint's scope bp. When
12576 the scope bp triggers, we notice that the watchpoint is out of
12577 scope, and delete it. We also delete its scope bp. But the
12578 scope bp is marked "auto-deleting", and is already on a bpstat.
12579 That bpstat is then checked for auto-deleting bp's, which are
12582 A real solution to this problem might involve reference counts in
12583 bp's, and/or giving them pointers back to their referencing
12584 bpstat's, and teaching delete_breakpoint to only free a bp's
12585 storage when no more references were extent. A cheaper bandaid
12587 if (bpt->type == bp_none)
12590 /* At least avoid this stale reference until the reference counting
12591 of breakpoints gets resolved. */
12592 if (bpt->related_breakpoint != bpt)
12594 struct breakpoint *related;
12595 struct watchpoint *w;
12597 if (bpt->type == bp_watchpoint_scope)
12598 w = (struct watchpoint *) bpt->related_breakpoint;
12599 else if (bpt->related_breakpoint->type == bp_watchpoint_scope)
12600 w = (struct watchpoint *) bpt;
12604 watchpoint_del_at_next_stop (w);
12606 /* Unlink bpt from the bpt->related_breakpoint ring. */
12607 for (related = bpt; related->related_breakpoint != bpt;
12608 related = related->related_breakpoint);
12609 related->related_breakpoint = bpt->related_breakpoint;
12610 bpt->related_breakpoint = bpt;
12613 /* watch_command_1 creates a watchpoint but only sets its number if
12614 update_watchpoint succeeds in creating its bp_locations. If there's
12615 a problem in that process, we'll be asked to delete the half-created
12616 watchpoint. In that case, don't announce the deletion. */
12618 observer_notify_breakpoint_deleted (bpt);
12620 if (breakpoint_chain == bpt)
12621 breakpoint_chain = bpt->next;
12623 ALL_BREAKPOINTS (b)
12624 if (b->next == bpt)
12626 b->next = bpt->next;
12630 /* Be sure no bpstat's are pointing at the breakpoint after it's
12632 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
12633 in all threads for now. Note that we cannot just remove bpstats
12634 pointing at bpt from the stop_bpstat list entirely, as breakpoint
12635 commands are associated with the bpstat; if we remove it here,
12636 then the later call to bpstat_do_actions (&stop_bpstat); in
12637 event-top.c won't do anything, and temporary breakpoints with
12638 commands won't work. */
12640 iterate_over_threads (bpstat_remove_breakpoint_callback, bpt);
12642 /* Now that breakpoint is removed from breakpoint list, update the
12643 global location list. This will remove locations that used to
12644 belong to this breakpoint. Do this before freeing the breakpoint
12645 itself, since remove_breakpoint looks at location's owner. It
12646 might be better design to have location completely
12647 self-contained, but it's not the case now. */
12648 update_global_location_list (0);
12650 bpt->ops->dtor (bpt);
12651 /* On the chance that someone will soon try again to delete this
12652 same bp, we mark it as deleted before freeing its storage. */
12653 bpt->type = bp_none;
12658 do_delete_breakpoint_cleanup (void *b)
12660 delete_breakpoint (b);
12664 make_cleanup_delete_breakpoint (struct breakpoint *b)
12666 return make_cleanup (do_delete_breakpoint_cleanup, b);
12669 /* Iterator function to call a user-provided callback function once
12670 for each of B and its related breakpoints. */
12673 iterate_over_related_breakpoints (struct breakpoint *b,
12674 void (*function) (struct breakpoint *,
12678 struct breakpoint *related;
12683 struct breakpoint *next;
12685 /* FUNCTION may delete RELATED. */
12686 next = related->related_breakpoint;
12688 if (next == related)
12690 /* RELATED is the last ring entry. */
12691 function (related, data);
12693 /* FUNCTION may have deleted it, so we'd never reach back to
12694 B. There's nothing left to do anyway, so just break
12699 function (related, data);
12703 while (related != b);
12707 do_delete_breakpoint (struct breakpoint *b, void *ignore)
12709 delete_breakpoint (b);
12712 /* A callback for map_breakpoint_numbers that calls
12713 delete_breakpoint. */
12716 do_map_delete_breakpoint (struct breakpoint *b, void *ignore)
12718 iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL);
12722 delete_command (char *arg, int from_tty)
12724 struct breakpoint *b, *b_tmp;
12730 int breaks_to_delete = 0;
12732 /* Delete all breakpoints if no argument. Do not delete
12733 internal breakpoints, these have to be deleted with an
12734 explicit breakpoint number argument. */
12735 ALL_BREAKPOINTS (b)
12736 if (user_breakpoint_p (b))
12738 breaks_to_delete = 1;
12742 /* Ask user only if there are some breakpoints to delete. */
12744 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
12746 ALL_BREAKPOINTS_SAFE (b, b_tmp)
12747 if (user_breakpoint_p (b))
12748 delete_breakpoint (b);
12752 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
12756 all_locations_are_pending (struct bp_location *loc)
12758 for (; loc; loc = loc->next)
12759 if (!loc->shlib_disabled
12760 && !loc->pspace->executing_startup)
12765 /* Subroutine of update_breakpoint_locations to simplify it.
12766 Return non-zero if multiple fns in list LOC have the same name.
12767 Null names are ignored. */
12770 ambiguous_names_p (struct bp_location *loc)
12772 struct bp_location *l;
12773 htab_t htab = htab_create_alloc (13, htab_hash_string,
12774 (int (*) (const void *,
12775 const void *)) streq,
12776 NULL, xcalloc, xfree);
12778 for (l = loc; l != NULL; l = l->next)
12781 const char *name = l->function_name;
12783 /* Allow for some names to be NULL, ignore them. */
12787 slot = (const char **) htab_find_slot (htab, (const void *) name,
12789 /* NOTE: We can assume slot != NULL here because xcalloc never
12793 htab_delete (htab);
12799 htab_delete (htab);
12803 /* When symbols change, it probably means the sources changed as well,
12804 and it might mean the static tracepoint markers are no longer at
12805 the same address or line numbers they used to be at last we
12806 checked. Losing your static tracepoints whenever you rebuild is
12807 undesirable. This function tries to resync/rematch gdb static
12808 tracepoints with the markers on the target, for static tracepoints
12809 that have not been set by marker id. Static tracepoint that have
12810 been set by marker id are reset by marker id in breakpoint_re_set.
12813 1) For a tracepoint set at a specific address, look for a marker at
12814 the old PC. If one is found there, assume to be the same marker.
12815 If the name / string id of the marker found is different from the
12816 previous known name, assume that means the user renamed the marker
12817 in the sources, and output a warning.
12819 2) For a tracepoint set at a given line number, look for a marker
12820 at the new address of the old line number. If one is found there,
12821 assume to be the same marker. If the name / string id of the
12822 marker found is different from the previous known name, assume that
12823 means the user renamed the marker in the sources, and output a
12826 3) If a marker is no longer found at the same address or line, it
12827 may mean the marker no longer exists. But it may also just mean
12828 the code changed a bit. Maybe the user added a few lines of code
12829 that made the marker move up or down (in line number terms). Ask
12830 the target for info about the marker with the string id as we knew
12831 it. If found, update line number and address in the matching
12832 static tracepoint. This will get confused if there's more than one
12833 marker with the same ID (possible in UST, although unadvised
12834 precisely because it confuses tools). */
12836 static struct symtab_and_line
12837 update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal)
12839 struct tracepoint *tp = (struct tracepoint *) b;
12840 struct static_tracepoint_marker marker;
12846 find_line_pc (sal.symtab, sal.line, &pc);
12848 if (target_static_tracepoint_marker_at (pc, &marker))
12850 if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0)
12851 warning (_("static tracepoint %d changed probed marker from %s to %s"),
12853 tp->static_trace_marker_id, marker.str_id);
12855 xfree (tp->static_trace_marker_id);
12856 tp->static_trace_marker_id = xstrdup (marker.str_id);
12857 release_static_tracepoint_marker (&marker);
12862 /* Old marker wasn't found on target at lineno. Try looking it up
12864 if (!sal.explicit_pc
12866 && sal.symtab != NULL
12867 && tp->static_trace_marker_id != NULL)
12869 VEC(static_tracepoint_marker_p) *markers;
12872 = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id);
12874 if (!VEC_empty(static_tracepoint_marker_p, markers))
12876 struct symtab_and_line sal2;
12877 struct symbol *sym;
12878 struct static_tracepoint_marker *tpmarker;
12879 struct ui_out *uiout = current_uiout;
12881 tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0);
12883 xfree (tp->static_trace_marker_id);
12884 tp->static_trace_marker_id = xstrdup (tpmarker->str_id);
12886 warning (_("marker for static tracepoint %d (%s) not "
12887 "found at previous line number"),
12888 b->number, tp->static_trace_marker_id);
12892 sal2.pc = tpmarker->address;
12894 sal2 = find_pc_line (tpmarker->address, 0);
12895 sym = find_pc_sect_function (tpmarker->address, NULL);
12896 ui_out_text (uiout, "Now in ");
12899 ui_out_field_string (uiout, "func",
12900 SYMBOL_PRINT_NAME (sym));
12901 ui_out_text (uiout, " at ");
12903 ui_out_field_string (uiout, "file", sal2.symtab->filename);
12904 ui_out_text (uiout, ":");
12906 if (ui_out_is_mi_like_p (uiout))
12908 char *fullname = symtab_to_fullname (sal2.symtab);
12911 ui_out_field_string (uiout, "fullname", fullname);
12914 ui_out_field_int (uiout, "line", sal2.line);
12915 ui_out_text (uiout, "\n");
12917 b->loc->line_number = sal2.line;
12919 xfree (b->loc->source_file);
12921 b->loc->source_file = xstrdup (sal2.symtab->filename);
12923 b->loc->source_file = NULL;
12925 xfree (b->addr_string);
12926 b->addr_string = xstrprintf ("%s:%d",
12927 sal2.symtab->filename,
12928 b->loc->line_number);
12930 /* Might be nice to check if function changed, and warn if
12933 release_static_tracepoint_marker (tpmarker);
12939 /* Returns 1 iff locations A and B are sufficiently same that
12940 we don't need to report breakpoint as changed. */
12943 locations_are_equal (struct bp_location *a, struct bp_location *b)
12947 if (a->address != b->address)
12950 if (a->shlib_disabled != b->shlib_disabled)
12953 if (a->enabled != b->enabled)
12960 if ((a == NULL) != (b == NULL))
12966 /* Create new breakpoint locations for B (a hardware or software breakpoint)
12967 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
12968 a ranged breakpoint. */
12971 update_breakpoint_locations (struct breakpoint *b,
12972 struct symtabs_and_lines sals,
12973 struct symtabs_and_lines sals_end)
12976 struct bp_location *existing_locations = b->loc;
12978 if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1))
12980 /* Ranged breakpoints have only one start location and one end
12982 b->enable_state = bp_disabled;
12983 update_global_location_list (1);
12984 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
12985 "multiple locations found\n"),
12990 /* If there's no new locations, and all existing locations are
12991 pending, don't do anything. This optimizes the common case where
12992 all locations are in the same shared library, that was unloaded.
12993 We'd like to retain the location, so that when the library is
12994 loaded again, we don't loose the enabled/disabled status of the
12995 individual locations. */
12996 if (all_locations_are_pending (existing_locations) && sals.nelts == 0)
13001 for (i = 0; i < sals.nelts; ++i)
13003 struct bp_location *new_loc;
13005 switch_to_program_space_and_thread (sals.sals[i].pspace);
13007 new_loc = add_location_to_breakpoint (b, &(sals.sals[i]));
13009 /* Reparse conditions, they might contain references to the
13011 if (b->cond_string != NULL)
13014 volatile struct gdb_exception e;
13016 s = b->cond_string;
13017 TRY_CATCH (e, RETURN_MASK_ERROR)
13019 new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc),
13024 warning (_("failed to reevaluate condition "
13025 "for breakpoint %d: %s"),
13026 b->number, e.message);
13027 new_loc->enabled = 0;
13031 if (sals_end.nelts)
13033 CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]);
13035 new_loc->length = end - sals.sals[0].pc + 1;
13039 /* Update locations of permanent breakpoints. */
13040 if (b->enable_state == bp_permanent)
13041 make_breakpoint_permanent (b);
13043 /* If possible, carry over 'disable' status from existing
13046 struct bp_location *e = existing_locations;
13047 /* If there are multiple breakpoints with the same function name,
13048 e.g. for inline functions, comparing function names won't work.
13049 Instead compare pc addresses; this is just a heuristic as things
13050 may have moved, but in practice it gives the correct answer
13051 often enough until a better solution is found. */
13052 int have_ambiguous_names = ambiguous_names_p (b->loc);
13054 for (; e; e = e->next)
13056 if (!e->enabled && e->function_name)
13058 struct bp_location *l = b->loc;
13059 if (have_ambiguous_names)
13061 for (; l; l = l->next)
13062 if (breakpoint_locations_match (e, l))
13070 for (; l; l = l->next)
13071 if (l->function_name
13072 && strcmp (e->function_name, l->function_name) == 0)
13082 if (!locations_are_equal (existing_locations, b->loc))
13083 observer_notify_breakpoint_modified (b);
13085 update_global_location_list (1);
13088 /* Find the SaL locations corresponding to the given ADDR_STRING.
13089 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
13091 static struct symtabs_and_lines
13092 addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found)
13095 struct symtabs_and_lines sals = {0};
13096 volatile struct gdb_exception e;
13098 gdb_assert (b->ops != NULL);
13101 TRY_CATCH (e, RETURN_MASK_ERROR)
13103 b->ops->decode_linespec (b, &s, &sals);
13107 int not_found_and_ok = 0;
13108 /* For pending breakpoints, it's expected that parsing will
13109 fail until the right shared library is loaded. User has
13110 already told to create pending breakpoints and don't need
13111 extra messages. If breakpoint is in bp_shlib_disabled
13112 state, then user already saw the message about that
13113 breakpoint being disabled, and don't want to see more
13115 if (e.error == NOT_FOUND_ERROR
13116 && (b->condition_not_parsed
13117 || (b->loc && b->loc->shlib_disabled)
13118 || (b->loc && b->loc->pspace->executing_startup)
13119 || b->enable_state == bp_disabled))
13120 not_found_and_ok = 1;
13122 if (!not_found_and_ok)
13124 /* We surely don't want to warn about the same breakpoint
13125 10 times. One solution, implemented here, is disable
13126 the breakpoint on error. Another solution would be to
13127 have separate 'warning emitted' flag. Since this
13128 happens only when a binary has changed, I don't know
13129 which approach is better. */
13130 b->enable_state = bp_disabled;
13131 throw_exception (e);
13135 if (e.reason == 0 || e.error != NOT_FOUND_ERROR)
13139 for (i = 0; i < sals.nelts; ++i)
13140 resolve_sal_pc (&sals.sals[i]);
13141 if (b->condition_not_parsed && s && s[0])
13143 char *cond_string = 0;
13147 find_condition_and_thread (s, sals.sals[0].pc,
13148 &cond_string, &thread, &task);
13150 b->cond_string = cond_string;
13151 b->thread = thread;
13153 b->condition_not_parsed = 0;
13156 if (b->type == bp_static_tracepoint && !strace_marker_p (b))
13157 sals.sals[0] = update_static_tracepoint (b, sals.sals[0]);
13167 /* The default re_set method, for typical hardware or software
13168 breakpoints. Reevaluate the breakpoint and recreate its
13172 breakpoint_re_set_default (struct breakpoint *b)
13175 struct symtabs_and_lines sals, sals_end;
13176 struct symtabs_and_lines expanded = {0};
13177 struct symtabs_and_lines expanded_end = {0};
13179 sals = addr_string_to_sals (b, b->addr_string, &found);
13182 make_cleanup (xfree, sals.sals);
13186 if (b->addr_string_range_end)
13188 sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found);
13191 make_cleanup (xfree, sals_end.sals);
13192 expanded_end = sals_end;
13196 update_breakpoint_locations (b, expanded, expanded_end);
13199 /* Default method for creating SALs from an address string. It basically
13200 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
13203 create_sals_from_address_default (char **arg,
13204 struct linespec_result *canonical,
13205 enum bptype type_wanted,
13206 char *addr_start, char **copy_arg)
13208 parse_breakpoint_sals (arg, canonical);
13211 /* Call create_breakpoints_sal for the given arguments. This is the default
13212 function for the `create_breakpoints_sal' method of
13216 create_breakpoints_sal_default (struct gdbarch *gdbarch,
13217 struct linespec_result *canonical,
13218 struct linespec_sals *lsal,
13220 enum bptype type_wanted,
13221 enum bpdisp disposition,
13223 int task, int ignore_count,
13224 const struct breakpoint_ops *ops,
13225 int from_tty, int enabled,
13228 create_breakpoints_sal (gdbarch, canonical, cond_string,
13229 type_wanted, disposition,
13230 thread, task, ignore_count, ops, from_tty,
13231 enabled, internal);
13234 /* Decode the line represented by S by calling decode_line_full. This is the
13235 default function for the `decode_linespec' method of breakpoint_ops. */
13238 decode_linespec_default (struct breakpoint *b, char **s,
13239 struct symtabs_and_lines *sals)
13241 struct linespec_result canonical;
13243 init_linespec_result (&canonical);
13244 decode_line_full (s, DECODE_LINE_FUNFIRSTLINE,
13245 (struct symtab *) NULL, 0,
13246 &canonical, multiple_symbols_all,
13249 /* We should get 0 or 1 resulting SALs. */
13250 gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2);
13252 if (VEC_length (linespec_sals, canonical.sals) > 0)
13254 struct linespec_sals *lsal;
13256 lsal = VEC_index (linespec_sals, canonical.sals, 0);
13257 *sals = lsal->sals;
13258 /* Arrange it so the destructor does not free the
13260 lsal->sals.sals = NULL;
13263 destroy_linespec_result (&canonical);
13266 /* Prepare the global context for a re-set of breakpoint B. */
13268 static struct cleanup *
13269 prepare_re_set_context (struct breakpoint *b)
13271 struct cleanup *cleanups;
13273 input_radix = b->input_radix;
13274 cleanups = save_current_space_and_thread ();
13275 if (b->pspace != NULL)
13276 switch_to_program_space_and_thread (b->pspace);
13277 set_language (b->language);
13282 /* Reset a breakpoint given it's struct breakpoint * BINT.
13283 The value we return ends up being the return value from catch_errors.
13284 Unused in this case. */
13287 breakpoint_re_set_one (void *bint)
13289 /* Get past catch_errs. */
13290 struct breakpoint *b = (struct breakpoint *) bint;
13291 struct cleanup *cleanups;
13293 cleanups = prepare_re_set_context (b);
13294 b->ops->re_set (b);
13295 do_cleanups (cleanups);
13299 /* Re-set all breakpoints after symbols have been re-loaded. */
13301 breakpoint_re_set (void)
13303 struct breakpoint *b, *b_tmp;
13304 enum language save_language;
13305 int save_input_radix;
13306 struct cleanup *old_chain;
13308 save_language = current_language->la_language;
13309 save_input_radix = input_radix;
13310 old_chain = save_current_program_space ();
13312 ALL_BREAKPOINTS_SAFE (b, b_tmp)
13314 /* Format possible error msg. */
13315 char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
13317 struct cleanup *cleanups = make_cleanup (xfree, message);
13318 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
13319 do_cleanups (cleanups);
13321 set_language (save_language);
13322 input_radix = save_input_radix;
13324 jit_breakpoint_re_set ();
13326 do_cleanups (old_chain);
13328 create_overlay_event_breakpoint ();
13329 create_longjmp_master_breakpoint ();
13330 create_std_terminate_master_breakpoint ();
13331 create_exception_master_breakpoint ();
13333 /* While we're at it, reset the skip list too. */
13337 /* Reset the thread number of this breakpoint:
13339 - If the breakpoint is for all threads, leave it as-is.
13340 - Else, reset it to the current thread for inferior_ptid. */
13342 breakpoint_re_set_thread (struct breakpoint *b)
13344 if (b->thread != -1)
13346 if (in_thread_list (inferior_ptid))
13347 b->thread = pid_to_thread_id (inferior_ptid);
13349 /* We're being called after following a fork. The new fork is
13350 selected as current, and unless this was a vfork will have a
13351 different program space from the original thread. Reset that
13353 b->loc->pspace = current_program_space;
13357 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
13358 If from_tty is nonzero, it prints a message to that effect,
13359 which ends with a period (no newline). */
13362 set_ignore_count (int bptnum, int count, int from_tty)
13364 struct breakpoint *b;
13369 ALL_BREAKPOINTS (b)
13370 if (b->number == bptnum)
13372 if (is_tracepoint (b))
13374 if (from_tty && count != 0)
13375 printf_filtered (_("Ignore count ignored for tracepoint %d."),
13380 b->ignore_count = count;
13384 printf_filtered (_("Will stop next time "
13385 "breakpoint %d is reached."),
13387 else if (count == 1)
13388 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
13391 printf_filtered (_("Will ignore next %d "
13392 "crossings of breakpoint %d."),
13395 breakpoints_changed ();
13396 observer_notify_breakpoint_modified (b);
13400 error (_("No breakpoint number %d."), bptnum);
13403 /* Command to set ignore-count of breakpoint N to COUNT. */
13406 ignore_command (char *args, int from_tty)
13412 error_no_arg (_("a breakpoint number"));
13414 num = get_number (&p);
13416 error (_("bad breakpoint number: '%s'"), args);
13418 error (_("Second argument (specified ignore-count) is missing."));
13420 set_ignore_count (num,
13421 longest_to_int (value_as_long (parse_and_eval (p))),
13424 printf_filtered ("\n");
13427 /* Call FUNCTION on each of the breakpoints
13428 whose numbers are given in ARGS. */
13431 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *,
13436 struct breakpoint *b, *tmp;
13438 struct get_number_or_range_state state;
13441 error_no_arg (_("one or more breakpoint numbers"));
13443 init_number_or_range (&state, args);
13445 while (!state.finished)
13447 char *p = state.string;
13451 num = get_number_or_range (&state);
13454 warning (_("bad breakpoint number at or near '%s'"), p);
13458 ALL_BREAKPOINTS_SAFE (b, tmp)
13459 if (b->number == num)
13462 function (b, data);
13466 printf_unfiltered (_("No breakpoint number %d.\n"), num);
13471 static struct bp_location *
13472 find_location_by_number (char *number)
13474 char *dot = strchr (number, '.');
13478 struct breakpoint *b;
13479 struct bp_location *loc;
13484 bp_num = get_number (&p1);
13486 error (_("Bad breakpoint number '%s'"), number);
13488 ALL_BREAKPOINTS (b)
13489 if (b->number == bp_num)
13494 if (!b || b->number != bp_num)
13495 error (_("Bad breakpoint number '%s'"), number);
13498 loc_num = get_number (&p1);
13500 error (_("Bad breakpoint location number '%s'"), number);
13504 for (;loc_num && loc; --loc_num, loc = loc->next)
13507 error (_("Bad breakpoint location number '%s'"), dot+1);
13513 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
13514 If from_tty is nonzero, it prints a message to that effect,
13515 which ends with a period (no newline). */
13518 disable_breakpoint (struct breakpoint *bpt)
13520 /* Never disable a watchpoint scope breakpoint; we want to
13521 hit them when we leave scope so we can delete both the
13522 watchpoint and its scope breakpoint at that time. */
13523 if (bpt->type == bp_watchpoint_scope)
13526 /* You can't disable permanent breakpoints. */
13527 if (bpt->enable_state == bp_permanent)
13530 bpt->enable_state = bp_disabled;
13532 /* Mark breakpoint locations modified. */
13533 mark_breakpoint_modified (bpt);
13535 if (target_supports_enable_disable_tracepoint ()
13536 && current_trace_status ()->running && is_tracepoint (bpt))
13538 struct bp_location *location;
13540 for (location = bpt->loc; location; location = location->next)
13541 target_disable_tracepoint (location);
13544 update_global_location_list (0);
13546 observer_notify_breakpoint_modified (bpt);
13549 /* A callback for iterate_over_related_breakpoints. */
13552 do_disable_breakpoint (struct breakpoint *b, void *ignore)
13554 disable_breakpoint (b);
13557 /* A callback for map_breakpoint_numbers that calls
13558 disable_breakpoint. */
13561 do_map_disable_breakpoint (struct breakpoint *b, void *ignore)
13563 iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL);
13567 disable_command (char *args, int from_tty)
13571 struct breakpoint *bpt;
13573 ALL_BREAKPOINTS (bpt)
13574 if (user_breakpoint_p (bpt))
13575 disable_breakpoint (bpt);
13577 else if (strchr (args, '.'))
13579 struct bp_location *loc = find_location_by_number (args);
13585 mark_breakpoint_location_modified (loc);
13587 if (target_supports_enable_disable_tracepoint ()
13588 && current_trace_status ()->running && loc->owner
13589 && is_tracepoint (loc->owner))
13590 target_disable_tracepoint (loc);
13592 update_global_location_list (0);
13595 map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL);
13599 enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition,
13602 int target_resources_ok;
13604 if (bpt->type == bp_hardware_breakpoint)
13607 i = hw_breakpoint_used_count ();
13608 target_resources_ok =
13609 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
13611 if (target_resources_ok == 0)
13612 error (_("No hardware breakpoint support in the target."));
13613 else if (target_resources_ok < 0)
13614 error (_("Hardware breakpoints used exceeds limit."));
13617 if (is_watchpoint (bpt))
13619 /* Initialize it just to avoid a GCC false warning. */
13620 enum enable_state orig_enable_state = 0;
13621 volatile struct gdb_exception e;
13623 TRY_CATCH (e, RETURN_MASK_ALL)
13625 struct watchpoint *w = (struct watchpoint *) bpt;
13627 orig_enable_state = bpt->enable_state;
13628 bpt->enable_state = bp_enabled;
13629 update_watchpoint (w, 1 /* reparse */);
13633 bpt->enable_state = orig_enable_state;
13634 exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
13640 if (bpt->enable_state != bp_permanent)
13641 bpt->enable_state = bp_enabled;
13643 bpt->enable_state = bp_enabled;
13645 /* Mark breakpoint locations modified. */
13646 mark_breakpoint_modified (bpt);
13648 if (target_supports_enable_disable_tracepoint ()
13649 && current_trace_status ()->running && is_tracepoint (bpt))
13651 struct bp_location *location;
13653 for (location = bpt->loc; location; location = location->next)
13654 target_enable_tracepoint (location);
13657 bpt->disposition = disposition;
13658 bpt->enable_count = count;
13659 update_global_location_list (1);
13660 breakpoints_changed ();
13662 observer_notify_breakpoint_modified (bpt);
13667 enable_breakpoint (struct breakpoint *bpt)
13669 enable_breakpoint_disp (bpt, bpt->disposition, 0);
13673 do_enable_breakpoint (struct breakpoint *bpt, void *arg)
13675 enable_breakpoint (bpt);
13678 /* A callback for map_breakpoint_numbers that calls
13679 enable_breakpoint. */
13682 do_map_enable_breakpoint (struct breakpoint *b, void *ignore)
13684 iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL);
13687 /* The enable command enables the specified breakpoints (or all defined
13688 breakpoints) so they once again become (or continue to be) effective
13689 in stopping the inferior. */
13692 enable_command (char *args, int from_tty)
13696 struct breakpoint *bpt;
13698 ALL_BREAKPOINTS (bpt)
13699 if (user_breakpoint_p (bpt))
13700 enable_breakpoint (bpt);
13702 else if (strchr (args, '.'))
13704 struct bp_location *loc = find_location_by_number (args);
13710 mark_breakpoint_location_modified (loc);
13712 if (target_supports_enable_disable_tracepoint ()
13713 && current_trace_status ()->running && loc->owner
13714 && is_tracepoint (loc->owner))
13715 target_enable_tracepoint (loc);
13717 update_global_location_list (1);
13720 map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL);
13723 /* This struct packages up disposition data for application to multiple
13733 do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg)
13735 struct disp_data disp_data = *(struct disp_data *) arg;
13737 enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count);
13741 do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore)
13743 struct disp_data disp = { disp_disable, 1 };
13745 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
13749 enable_once_command (char *args, int from_tty)
13751 map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL);
13755 do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr)
13757 struct disp_data disp = { disp_disable, *(int *) countptr };
13759 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
13763 enable_count_command (char *args, int from_tty)
13765 int count = get_number (&args);
13767 map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count);
13771 do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore)
13773 struct disp_data disp = { disp_del, 1 };
13775 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
13779 enable_delete_command (char *args, int from_tty)
13781 map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL);
13785 set_breakpoint_cmd (char *args, int from_tty)
13790 show_breakpoint_cmd (char *args, int from_tty)
13794 /* Invalidate last known value of any hardware watchpoint if
13795 the memory which that value represents has been written to by
13799 invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len,
13800 const bfd_byte *data)
13802 struct breakpoint *bp;
13804 ALL_BREAKPOINTS (bp)
13805 if (bp->enable_state == bp_enabled
13806 && bp->type == bp_hardware_watchpoint)
13808 struct watchpoint *wp = (struct watchpoint *) bp;
13810 if (wp->val_valid && wp->val)
13812 struct bp_location *loc;
13814 for (loc = bp->loc; loc != NULL; loc = loc->next)
13815 if (loc->loc_type == bp_loc_hardware_watchpoint
13816 && loc->address + loc->length > addr
13817 && addr + len > loc->address)
13819 value_free (wp->val);
13827 /* Use the last displayed codepoint's values, or nothing
13828 if they aren't valid. */
13830 struct symtabs_and_lines
13831 decode_line_spec_1 (char *string, int flags)
13833 struct symtabs_and_lines sals;
13836 error (_("Empty line specification."));
13837 if (last_displayed_sal_is_valid ())
13838 sals = decode_line_1 (&string, flags,
13839 get_last_displayed_symtab (),
13840 get_last_displayed_line ());
13842 sals = decode_line_1 (&string, flags, (struct symtab *) NULL, 0);
13844 error (_("Junk at end of line specification: %s"), string);
13848 /* Create and insert a raw software breakpoint at PC. Return an
13849 identifier, which should be used to remove the breakpoint later.
13850 In general, places which call this should be using something on the
13851 breakpoint chain instead; this function should be eliminated
13855 deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch,
13856 struct address_space *aspace, CORE_ADDR pc)
13858 struct bp_target_info *bp_tgt;
13860 bp_tgt = XZALLOC (struct bp_target_info);
13862 bp_tgt->placed_address_space = aspace;
13863 bp_tgt->placed_address = pc;
13865 if (target_insert_breakpoint (gdbarch, bp_tgt) != 0)
13867 /* Could not insert the breakpoint. */
13875 /* Remove a breakpoint BP inserted by
13876 deprecated_insert_raw_breakpoint. */
13879 deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp)
13881 struct bp_target_info *bp_tgt = bp;
13884 ret = target_remove_breakpoint (gdbarch, bp_tgt);
13890 /* One (or perhaps two) breakpoints used for software single
13893 static void *single_step_breakpoints[2];
13894 static struct gdbarch *single_step_gdbarch[2];
13896 /* Create and insert a breakpoint for software single step. */
13899 insert_single_step_breakpoint (struct gdbarch *gdbarch,
13900 struct address_space *aspace,
13905 if (single_step_breakpoints[0] == NULL)
13907 bpt_p = &single_step_breakpoints[0];
13908 single_step_gdbarch[0] = gdbarch;
13912 gdb_assert (single_step_breakpoints[1] == NULL);
13913 bpt_p = &single_step_breakpoints[1];
13914 single_step_gdbarch[1] = gdbarch;
13917 /* NOTE drow/2006-04-11: A future improvement to this function would
13918 be to only create the breakpoints once, and actually put them on
13919 the breakpoint chain. That would let us use set_raw_breakpoint.
13920 We could adjust the addresses each time they were needed. Doing
13921 this requires corresponding changes elsewhere where single step
13922 breakpoints are handled, however. So, for now, we use this. */
13924 *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc);
13925 if (*bpt_p == NULL)
13926 error (_("Could not insert single-step breakpoint at %s"),
13927 paddress (gdbarch, next_pc));
13930 /* Check if the breakpoints used for software single stepping
13931 were inserted or not. */
13934 single_step_breakpoints_inserted (void)
13936 return (single_step_breakpoints[0] != NULL
13937 || single_step_breakpoints[1] != NULL);
13940 /* Remove and delete any breakpoints used for software single step. */
13943 remove_single_step_breakpoints (void)
13945 gdb_assert (single_step_breakpoints[0] != NULL);
13947 /* See insert_single_step_breakpoint for more about this deprecated
13949 deprecated_remove_raw_breakpoint (single_step_gdbarch[0],
13950 single_step_breakpoints[0]);
13951 single_step_gdbarch[0] = NULL;
13952 single_step_breakpoints[0] = NULL;
13954 if (single_step_breakpoints[1] != NULL)
13956 deprecated_remove_raw_breakpoint (single_step_gdbarch[1],
13957 single_step_breakpoints[1]);
13958 single_step_gdbarch[1] = NULL;
13959 single_step_breakpoints[1] = NULL;
13963 /* Delete software single step breakpoints without removing them from
13964 the inferior. This is intended to be used if the inferior's address
13965 space where they were inserted is already gone, e.g. after exit or
13969 cancel_single_step_breakpoints (void)
13973 for (i = 0; i < 2; i++)
13974 if (single_step_breakpoints[i])
13976 xfree (single_step_breakpoints[i]);
13977 single_step_breakpoints[i] = NULL;
13978 single_step_gdbarch[i] = NULL;
13982 /* Detach software single-step breakpoints from INFERIOR_PTID without
13986 detach_single_step_breakpoints (void)
13990 for (i = 0; i < 2; i++)
13991 if (single_step_breakpoints[i])
13992 target_remove_breakpoint (single_step_gdbarch[i],
13993 single_step_breakpoints[i]);
13996 /* Check whether a software single-step breakpoint is inserted at
14000 single_step_breakpoint_inserted_here_p (struct address_space *aspace,
14005 for (i = 0; i < 2; i++)
14007 struct bp_target_info *bp_tgt = single_step_breakpoints[i];
14009 && breakpoint_address_match (bp_tgt->placed_address_space,
14010 bp_tgt->placed_address,
14018 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
14019 non-zero otherwise. */
14021 is_syscall_catchpoint_enabled (struct breakpoint *bp)
14023 if (syscall_catchpoint_p (bp)
14024 && bp->enable_state != bp_disabled
14025 && bp->enable_state != bp_call_disabled)
14032 catch_syscall_enabled (void)
14034 struct inferior *inf = current_inferior ();
14036 return inf->total_syscalls_count != 0;
14040 catching_syscall_number (int syscall_number)
14042 struct breakpoint *bp;
14044 ALL_BREAKPOINTS (bp)
14045 if (is_syscall_catchpoint_enabled (bp))
14047 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp;
14049 if (c->syscalls_to_be_caught)
14053 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
14055 if (syscall_number == iter)
14065 /* Complete syscall names. Used by "catch syscall". */
14067 catch_syscall_completer (struct cmd_list_element *cmd,
14068 char *text, char *word)
14070 const char **list = get_syscall_names ();
14072 = (list == NULL) ? NULL : complete_on_enum (list, text, word);
14078 /* Tracepoint-specific operations. */
14080 /* Set tracepoint count to NUM. */
14082 set_tracepoint_count (int num)
14084 tracepoint_count = num;
14085 set_internalvar_integer (lookup_internalvar ("tpnum"), num);
14089 trace_command (char *arg, int from_tty)
14091 if (create_breakpoint (get_current_arch (),
14093 NULL, 0, 1 /* parse arg */,
14095 bp_tracepoint /* type_wanted */,
14096 0 /* Ignore count */,
14097 pending_break_support,
14098 &tracepoint_breakpoint_ops,
14102 set_tracepoint_count (breakpoint_count);
14106 ftrace_command (char *arg, int from_tty)
14108 if (create_breakpoint (get_current_arch (),
14110 NULL, 0, 1 /* parse arg */,
14112 bp_fast_tracepoint /* type_wanted */,
14113 0 /* Ignore count */,
14114 pending_break_support,
14115 &tracepoint_breakpoint_ops,
14119 set_tracepoint_count (breakpoint_count);
14122 /* strace command implementation. Creates a static tracepoint. */
14125 strace_command (char *arg, int from_tty)
14127 struct breakpoint_ops *ops;
14129 /* Decide if we are dealing with a static tracepoint marker (`-m'),
14130 or with a normal static tracepoint. */
14131 if (arg && strncmp (arg, "-m", 2) == 0 && isspace (arg[2]))
14132 ops = &strace_marker_breakpoint_ops;
14134 ops = &tracepoint_breakpoint_ops;
14136 if (create_breakpoint (get_current_arch (),
14138 NULL, 0, 1 /* parse arg */,
14140 bp_static_tracepoint /* type_wanted */,
14141 0 /* Ignore count */,
14142 pending_break_support,
14147 set_tracepoint_count (breakpoint_count);
14150 /* Set up a fake reader function that gets command lines from a linked
14151 list that was acquired during tracepoint uploading. */
14153 static struct uploaded_tp *this_utp;
14154 static int next_cmd;
14157 read_uploaded_action (void)
14161 VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt);
14168 /* Given information about a tracepoint as recorded on a target (which
14169 can be either a live system or a trace file), attempt to create an
14170 equivalent GDB tracepoint. This is not a reliable process, since
14171 the target does not necessarily have all the information used when
14172 the tracepoint was originally defined. */
14174 struct tracepoint *
14175 create_tracepoint_from_upload (struct uploaded_tp *utp)
14177 char *addr_str, small_buf[100];
14178 struct tracepoint *tp;
14180 if (utp->at_string)
14181 addr_str = utp->at_string;
14184 /* In the absence of a source location, fall back to raw
14185 address. Since there is no way to confirm that the address
14186 means the same thing as when the trace was started, warn the
14188 warning (_("Uploaded tracepoint %d has no "
14189 "source location, using raw address"),
14191 sprintf (small_buf, "*%s", hex_string (utp->addr));
14192 addr_str = small_buf;
14195 /* There's not much we can do with a sequence of bytecodes. */
14196 if (utp->cond && !utp->cond_string)
14197 warning (_("Uploaded tracepoint %d condition "
14198 "has no source form, ignoring it"),
14201 if (!create_breakpoint (get_current_arch (),
14203 utp->cond_string, -1, 0 /* parse cond/thread */,
14205 utp->type /* type_wanted */,
14206 0 /* Ignore count */,
14207 pending_break_support,
14208 &tracepoint_breakpoint_ops,
14210 utp->enabled /* enabled */,
14214 set_tracepoint_count (breakpoint_count);
14216 /* Get the tracepoint we just created. */
14217 tp = get_tracepoint (tracepoint_count);
14218 gdb_assert (tp != NULL);
14222 sprintf (small_buf, "%d %d", utp->pass, tp->base.number);
14224 trace_pass_command (small_buf, 0);
14227 /* If we have uploaded versions of the original commands, set up a
14228 special-purpose "reader" function and call the usual command line
14229 reader, then pass the result to the breakpoint command-setting
14231 if (!VEC_empty (char_ptr, utp->cmd_strings))
14233 struct command_line *cmd_list;
14238 cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL);
14240 breakpoint_set_commands (&tp->base, cmd_list);
14242 else if (!VEC_empty (char_ptr, utp->actions)
14243 || !VEC_empty (char_ptr, utp->step_actions))
14244 warning (_("Uploaded tracepoint %d actions "
14245 "have no source form, ignoring them"),
14248 /* Copy any status information that might be available. */
14249 tp->base.hit_count = utp->hit_count;
14250 tp->traceframe_usage = utp->traceframe_usage;
14255 /* Print information on tracepoint number TPNUM_EXP, or all if
14259 tracepoints_info (char *args, int from_tty)
14261 struct ui_out *uiout = current_uiout;
14264 num_printed = breakpoint_1 (args, 0, is_tracepoint);
14266 if (num_printed == 0)
14268 if (args == NULL || *args == '\0')
14269 ui_out_message (uiout, 0, "No tracepoints.\n");
14271 ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args);
14274 default_collect_info ();
14277 /* The 'enable trace' command enables tracepoints.
14278 Not supported by all targets. */
14280 enable_trace_command (char *args, int from_tty)
14282 enable_command (args, from_tty);
14285 /* The 'disable trace' command disables tracepoints.
14286 Not supported by all targets. */
14288 disable_trace_command (char *args, int from_tty)
14290 disable_command (args, from_tty);
14293 /* Remove a tracepoint (or all if no argument). */
14295 delete_trace_command (char *arg, int from_tty)
14297 struct breakpoint *b, *b_tmp;
14303 int breaks_to_delete = 0;
14305 /* Delete all breakpoints if no argument.
14306 Do not delete internal or call-dummy breakpoints, these
14307 have to be deleted with an explicit breakpoint number
14309 ALL_TRACEPOINTS (b)
14310 if (is_tracepoint (b) && user_breakpoint_p (b))
14312 breaks_to_delete = 1;
14316 /* Ask user only if there are some breakpoints to delete. */
14318 || (breaks_to_delete && query (_("Delete all tracepoints? "))))
14320 ALL_BREAKPOINTS_SAFE (b, b_tmp)
14321 if (is_tracepoint (b) && user_breakpoint_p (b))
14322 delete_breakpoint (b);
14326 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
14329 /* Helper function for trace_pass_command. */
14332 trace_pass_set_count (struct tracepoint *tp, int count, int from_tty)
14334 tp->pass_count = count;
14335 observer_notify_tracepoint_modified (tp->base.number);
14337 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
14338 tp->base.number, count);
14341 /* Set passcount for tracepoint.
14343 First command argument is passcount, second is tracepoint number.
14344 If tracepoint number omitted, apply to most recently defined.
14345 Also accepts special argument "all". */
14348 trace_pass_command (char *args, int from_tty)
14350 struct tracepoint *t1;
14351 unsigned int count;
14353 if (args == 0 || *args == 0)
14354 error (_("passcount command requires an "
14355 "argument (count + optional TP num)"));
14357 count = strtoul (args, &args, 10); /* Count comes first, then TP num. */
14359 while (*args && isspace ((int) *args))
14362 if (*args && strncasecmp (args, "all", 3) == 0)
14364 struct breakpoint *b;
14366 args += 3; /* Skip special argument "all". */
14368 error (_("Junk at end of arguments."));
14370 ALL_TRACEPOINTS (b)
14372 t1 = (struct tracepoint *) b;
14373 trace_pass_set_count (t1, count, from_tty);
14376 else if (*args == '\0')
14378 t1 = get_tracepoint_by_number (&args, NULL, 1);
14380 trace_pass_set_count (t1, count, from_tty);
14384 struct get_number_or_range_state state;
14386 init_number_or_range (&state, args);
14387 while (!state.finished)
14389 t1 = get_tracepoint_by_number (&args, &state, 1);
14391 trace_pass_set_count (t1, count, from_tty);
14396 struct tracepoint *
14397 get_tracepoint (int num)
14399 struct breakpoint *t;
14401 ALL_TRACEPOINTS (t)
14402 if (t->number == num)
14403 return (struct tracepoint *) t;
14408 /* Find the tracepoint with the given target-side number (which may be
14409 different from the tracepoint number after disconnecting and
14412 struct tracepoint *
14413 get_tracepoint_by_number_on_target (int num)
14415 struct breakpoint *b;
14417 ALL_TRACEPOINTS (b)
14419 struct tracepoint *t = (struct tracepoint *) b;
14421 if (t->number_on_target == num)
14428 /* Utility: parse a tracepoint number and look it up in the list.
14429 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
14430 If OPTIONAL_P is true, then if the argument is missing, the most
14431 recent tracepoint (tracepoint_count) is returned. */
14432 struct tracepoint *
14433 get_tracepoint_by_number (char **arg,
14434 struct get_number_or_range_state *state,
14437 extern int tracepoint_count;
14438 struct breakpoint *t;
14440 char *instring = arg == NULL ? NULL : *arg;
14444 gdb_assert (!state->finished);
14445 tpnum = get_number_or_range (state);
14447 else if (arg == NULL || *arg == NULL || ! **arg)
14450 tpnum = tracepoint_count;
14452 error_no_arg (_("tracepoint number"));
14455 tpnum = get_number (arg);
14459 if (instring && *instring)
14460 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
14463 printf_filtered (_("Tracepoint argument missing "
14464 "and no previous tracepoint\n"));
14468 ALL_TRACEPOINTS (t)
14469 if (t->number == tpnum)
14471 return (struct tracepoint *) t;
14474 printf_unfiltered ("No tracepoint number %d.\n", tpnum);
14479 print_recreate_thread (struct breakpoint *b, struct ui_file *fp)
14481 if (b->thread != -1)
14482 fprintf_unfiltered (fp, " thread %d", b->thread);
14485 fprintf_unfiltered (fp, " task %d", b->task);
14487 fprintf_unfiltered (fp, "\n");
14490 /* Save information on user settable breakpoints (watchpoints, etc) to
14491 a new script file named FILENAME. If FILTER is non-NULL, call it
14492 on each breakpoint and only include the ones for which it returns
14496 save_breakpoints (char *filename, int from_tty,
14497 int (*filter) (const struct breakpoint *))
14499 struct breakpoint *tp;
14502 struct cleanup *cleanup;
14503 struct ui_file *fp;
14504 int extra_trace_bits = 0;
14506 if (filename == 0 || *filename == 0)
14507 error (_("Argument required (file name in which to save)"));
14509 /* See if we have anything to save. */
14510 ALL_BREAKPOINTS (tp)
14512 /* Skip internal and momentary breakpoints. */
14513 if (!user_breakpoint_p (tp))
14516 /* If we have a filter, only save the breakpoints it accepts. */
14517 if (filter && !filter (tp))
14522 if (is_tracepoint (tp))
14524 extra_trace_bits = 1;
14526 /* We can stop searching. */
14533 warning (_("Nothing to save."));
14537 pathname = tilde_expand (filename);
14538 cleanup = make_cleanup (xfree, pathname);
14539 fp = gdb_fopen (pathname, "w");
14541 error (_("Unable to open file '%s' for saving (%s)"),
14542 filename, safe_strerror (errno));
14543 make_cleanup_ui_file_delete (fp);
14545 if (extra_trace_bits)
14546 save_trace_state_variables (fp);
14548 ALL_BREAKPOINTS (tp)
14550 /* Skip internal and momentary breakpoints. */
14551 if (!user_breakpoint_p (tp))
14554 /* If we have a filter, only save the breakpoints it accepts. */
14555 if (filter && !filter (tp))
14558 tp->ops->print_recreate (tp, fp);
14560 /* Note, we can't rely on tp->number for anything, as we can't
14561 assume the recreated breakpoint numbers will match. Use $bpnum
14564 if (tp->cond_string)
14565 fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string);
14567 if (tp->ignore_count)
14568 fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count);
14572 volatile struct gdb_exception ex;
14574 fprintf_unfiltered (fp, " commands\n");
14576 ui_out_redirect (current_uiout, fp);
14577 TRY_CATCH (ex, RETURN_MASK_ALL)
14579 print_command_lines (current_uiout, tp->commands->commands, 2);
14581 ui_out_redirect (current_uiout, NULL);
14584 throw_exception (ex);
14586 fprintf_unfiltered (fp, " end\n");
14589 if (tp->enable_state == bp_disabled)
14590 fprintf_unfiltered (fp, "disable\n");
14592 /* If this is a multi-location breakpoint, check if the locations
14593 should be individually disabled. Watchpoint locations are
14594 special, and not user visible. */
14595 if (!is_watchpoint (tp) && tp->loc && tp->loc->next)
14597 struct bp_location *loc;
14600 for (loc = tp->loc; loc != NULL; loc = loc->next, n++)
14602 fprintf_unfiltered (fp, "disable $bpnum.%d\n", n);
14606 if (extra_trace_bits && *default_collect)
14607 fprintf_unfiltered (fp, "set default-collect %s\n", default_collect);
14609 do_cleanups (cleanup);
14611 printf_filtered (_("Saved to file '%s'.\n"), filename);
14614 /* The `save breakpoints' command. */
14617 save_breakpoints_command (char *args, int from_tty)
14619 save_breakpoints (args, from_tty, NULL);
14622 /* The `save tracepoints' command. */
14625 save_tracepoints_command (char *args, int from_tty)
14627 save_breakpoints (args, from_tty, is_tracepoint);
14630 /* Create a vector of all tracepoints. */
14632 VEC(breakpoint_p) *
14633 all_tracepoints (void)
14635 VEC(breakpoint_p) *tp_vec = 0;
14636 struct breakpoint *tp;
14638 ALL_TRACEPOINTS (tp)
14640 VEC_safe_push (breakpoint_p, tp_vec, tp);
14647 /* This help string is used for the break, hbreak, tbreak and thbreak
14648 commands. It is defined as a macro to prevent duplication.
14649 COMMAND should be a string constant containing the name of the
14651 #define BREAK_ARGS_HELP(command) \
14652 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
14653 LOCATION may be a line number, function name, or \"*\" and an address.\n\
14654 If a line number is specified, break at start of code for that line.\n\
14655 If a function is specified, break at start of code for that function.\n\
14656 If an address is specified, break at that exact address.\n\
14657 With no LOCATION, uses current execution address of the selected\n\
14658 stack frame. This is useful for breaking on return to a stack frame.\n\
14660 THREADNUM is the number from \"info threads\".\n\
14661 CONDITION is a boolean expression.\n\
14663 Multiple breakpoints at one place are permitted, and useful if their\n\
14664 conditions are different.\n\
14666 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
14668 /* List of subcommands for "catch". */
14669 static struct cmd_list_element *catch_cmdlist;
14671 /* List of subcommands for "tcatch". */
14672 static struct cmd_list_element *tcatch_cmdlist;
14675 add_catch_command (char *name, char *docstring,
14676 void (*sfunc) (char *args, int from_tty,
14677 struct cmd_list_element *command),
14678 char **(*completer) (struct cmd_list_element *cmd,
14679 char *text, char *word),
14680 void *user_data_catch,
14681 void *user_data_tcatch)
14683 struct cmd_list_element *command;
14685 command = add_cmd (name, class_breakpoint, NULL, docstring,
14687 set_cmd_sfunc (command, sfunc);
14688 set_cmd_context (command, user_data_catch);
14689 set_cmd_completer (command, completer);
14691 command = add_cmd (name, class_breakpoint, NULL, docstring,
14693 set_cmd_sfunc (command, sfunc);
14694 set_cmd_context (command, user_data_tcatch);
14695 set_cmd_completer (command, completer);
14699 clear_syscall_counts (struct inferior *inf)
14701 inf->total_syscalls_count = 0;
14702 inf->any_syscall_count = 0;
14703 VEC_free (int, inf->syscalls_counts);
14707 save_command (char *arg, int from_tty)
14709 printf_unfiltered (_("\"save\" must be followed by "
14710 "the name of a save subcommand.\n"));
14711 help_list (save_cmdlist, "save ", -1, gdb_stdout);
14714 struct breakpoint *
14715 iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *),
14718 struct breakpoint *b, *b_tmp;
14720 ALL_BREAKPOINTS_SAFE (b, b_tmp)
14722 if ((*callback) (b, data))
14729 /* Zero if any of the breakpoint's locations could be a location where
14730 functions have been inlined, nonzero otherwise. */
14733 is_non_inline_function (struct breakpoint *b)
14735 /* The shared library event breakpoint is set on the address of a
14736 non-inline function. */
14737 if (b->type == bp_shlib_event)
14743 /* Nonzero if the specified PC cannot be a location where functions
14744 have been inlined. */
14747 pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc,
14748 const struct target_waitstatus *ws)
14750 struct breakpoint *b;
14751 struct bp_location *bl;
14753 ALL_BREAKPOINTS (b)
14755 if (!is_non_inline_function (b))
14758 for (bl = b->loc; bl != NULL; bl = bl->next)
14760 if (!bl->shlib_disabled
14761 && bpstat_check_location (bl, aspace, pc, ws))
14770 initialize_breakpoint_ops (void)
14772 static int initialized = 0;
14774 struct breakpoint_ops *ops;
14780 /* The breakpoint_ops structure to be inherit by all kinds of
14781 breakpoints (real breakpoints, i.e., user "break" breakpoints,
14782 internal and momentary breakpoints, etc.). */
14783 ops = &bkpt_base_breakpoint_ops;
14784 *ops = base_breakpoint_ops;
14785 ops->re_set = bkpt_re_set;
14786 ops->insert_location = bkpt_insert_location;
14787 ops->remove_location = bkpt_remove_location;
14788 ops->breakpoint_hit = bkpt_breakpoint_hit;
14789 ops->create_sals_from_address = bkpt_create_sals_from_address;
14790 ops->create_breakpoints_sal = bkpt_create_breakpoints_sal;
14791 ops->decode_linespec = bkpt_decode_linespec;
14793 /* The breakpoint_ops structure to be used in regular breakpoints. */
14794 ops = &bkpt_breakpoint_ops;
14795 *ops = bkpt_base_breakpoint_ops;
14796 ops->re_set = bkpt_re_set;
14797 ops->resources_needed = bkpt_resources_needed;
14798 ops->print_it = bkpt_print_it;
14799 ops->print_mention = bkpt_print_mention;
14800 ops->print_recreate = bkpt_print_recreate;
14802 /* Ranged breakpoints. */
14803 ops = &ranged_breakpoint_ops;
14804 *ops = bkpt_breakpoint_ops;
14805 ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint;
14806 ops->resources_needed = resources_needed_ranged_breakpoint;
14807 ops->print_it = print_it_ranged_breakpoint;
14808 ops->print_one = print_one_ranged_breakpoint;
14809 ops->print_one_detail = print_one_detail_ranged_breakpoint;
14810 ops->print_mention = print_mention_ranged_breakpoint;
14811 ops->print_recreate = print_recreate_ranged_breakpoint;
14813 /* Internal breakpoints. */
14814 ops = &internal_breakpoint_ops;
14815 *ops = bkpt_base_breakpoint_ops;
14816 ops->re_set = internal_bkpt_re_set;
14817 ops->check_status = internal_bkpt_check_status;
14818 ops->print_it = internal_bkpt_print_it;
14819 ops->print_mention = internal_bkpt_print_mention;
14821 /* Momentary breakpoints. */
14822 ops = &momentary_breakpoint_ops;
14823 *ops = bkpt_base_breakpoint_ops;
14824 ops->re_set = momentary_bkpt_re_set;
14825 ops->check_status = momentary_bkpt_check_status;
14826 ops->print_it = momentary_bkpt_print_it;
14827 ops->print_mention = momentary_bkpt_print_mention;
14829 /* GNU v3 exception catchpoints. */
14830 ops = &gnu_v3_exception_catchpoint_ops;
14831 *ops = bkpt_breakpoint_ops;
14832 ops->print_it = print_it_exception_catchpoint;
14833 ops->print_one = print_one_exception_catchpoint;
14834 ops->print_mention = print_mention_exception_catchpoint;
14835 ops->print_recreate = print_recreate_exception_catchpoint;
14838 ops = &watchpoint_breakpoint_ops;
14839 *ops = base_breakpoint_ops;
14840 ops->dtor = dtor_watchpoint;
14841 ops->re_set = re_set_watchpoint;
14842 ops->insert_location = insert_watchpoint;
14843 ops->remove_location = remove_watchpoint;
14844 ops->breakpoint_hit = breakpoint_hit_watchpoint;
14845 ops->check_status = check_status_watchpoint;
14846 ops->resources_needed = resources_needed_watchpoint;
14847 ops->works_in_software_mode = works_in_software_mode_watchpoint;
14848 ops->print_it = print_it_watchpoint;
14849 ops->print_mention = print_mention_watchpoint;
14850 ops->print_recreate = print_recreate_watchpoint;
14852 /* Masked watchpoints. */
14853 ops = &masked_watchpoint_breakpoint_ops;
14854 *ops = watchpoint_breakpoint_ops;
14855 ops->insert_location = insert_masked_watchpoint;
14856 ops->remove_location = remove_masked_watchpoint;
14857 ops->resources_needed = resources_needed_masked_watchpoint;
14858 ops->works_in_software_mode = works_in_software_mode_masked_watchpoint;
14859 ops->print_it = print_it_masked_watchpoint;
14860 ops->print_one_detail = print_one_detail_masked_watchpoint;
14861 ops->print_mention = print_mention_masked_watchpoint;
14862 ops->print_recreate = print_recreate_masked_watchpoint;
14865 ops = &tracepoint_breakpoint_ops;
14866 *ops = base_breakpoint_ops;
14867 ops->re_set = tracepoint_re_set;
14868 ops->breakpoint_hit = tracepoint_breakpoint_hit;
14869 ops->print_one_detail = tracepoint_print_one_detail;
14870 ops->print_mention = tracepoint_print_mention;
14871 ops->print_recreate = tracepoint_print_recreate;
14872 ops->create_sals_from_address = tracepoint_create_sals_from_address;
14873 ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal;
14874 ops->decode_linespec = tracepoint_decode_linespec;
14876 /* Static tracepoints with marker (`-m'). */
14877 ops = &strace_marker_breakpoint_ops;
14878 *ops = tracepoint_breakpoint_ops;
14879 ops->create_sals_from_address = strace_marker_create_sals_from_address;
14880 ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal;
14881 ops->decode_linespec = strace_marker_decode_linespec;
14883 /* Fork catchpoints. */
14884 ops = &catch_fork_breakpoint_ops;
14885 *ops = base_breakpoint_ops;
14886 ops->insert_location = insert_catch_fork;
14887 ops->remove_location = remove_catch_fork;
14888 ops->breakpoint_hit = breakpoint_hit_catch_fork;
14889 ops->print_it = print_it_catch_fork;
14890 ops->print_one = print_one_catch_fork;
14891 ops->print_mention = print_mention_catch_fork;
14892 ops->print_recreate = print_recreate_catch_fork;
14894 /* Vfork catchpoints. */
14895 ops = &catch_vfork_breakpoint_ops;
14896 *ops = base_breakpoint_ops;
14897 ops->insert_location = insert_catch_vfork;
14898 ops->remove_location = remove_catch_vfork;
14899 ops->breakpoint_hit = breakpoint_hit_catch_vfork;
14900 ops->print_it = print_it_catch_vfork;
14901 ops->print_one = print_one_catch_vfork;
14902 ops->print_mention = print_mention_catch_vfork;
14903 ops->print_recreate = print_recreate_catch_vfork;
14905 /* Exec catchpoints. */
14906 ops = &catch_exec_breakpoint_ops;
14907 *ops = base_breakpoint_ops;
14908 ops->dtor = dtor_catch_exec;
14909 ops->insert_location = insert_catch_exec;
14910 ops->remove_location = remove_catch_exec;
14911 ops->breakpoint_hit = breakpoint_hit_catch_exec;
14912 ops->print_it = print_it_catch_exec;
14913 ops->print_one = print_one_catch_exec;
14914 ops->print_mention = print_mention_catch_exec;
14915 ops->print_recreate = print_recreate_catch_exec;
14917 /* Syscall catchpoints. */
14918 ops = &catch_syscall_breakpoint_ops;
14919 *ops = base_breakpoint_ops;
14920 ops->dtor = dtor_catch_syscall;
14921 ops->insert_location = insert_catch_syscall;
14922 ops->remove_location = remove_catch_syscall;
14923 ops->breakpoint_hit = breakpoint_hit_catch_syscall;
14924 ops->print_it = print_it_catch_syscall;
14925 ops->print_one = print_one_catch_syscall;
14926 ops->print_mention = print_mention_catch_syscall;
14927 ops->print_recreate = print_recreate_catch_syscall;
14929 /* Solib-related catchpoints. */
14930 ops = &catch_solib_breakpoint_ops;
14931 *ops = base_breakpoint_ops;
14932 ops->dtor = dtor_catch_solib;
14933 ops->insert_location = insert_catch_solib;
14934 ops->remove_location = remove_catch_solib;
14935 ops->breakpoint_hit = breakpoint_hit_catch_solib;
14936 ops->check_status = check_status_catch_solib;
14937 ops->print_it = print_it_catch_solib;
14938 ops->print_one = print_one_catch_solib;
14939 ops->print_mention = print_mention_catch_solib;
14940 ops->print_recreate = print_recreate_catch_solib;
14944 _initialize_breakpoint (void)
14946 struct cmd_list_element *c;
14948 initialize_breakpoint_ops ();
14950 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
14951 observer_attach_inferior_exit (clear_syscall_counts);
14952 observer_attach_memory_changed (invalidate_bp_value_on_memory_change);
14954 breakpoint_objfile_key = register_objfile_data ();
14956 breakpoint_chain = 0;
14957 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
14958 before a breakpoint is set. */
14959 breakpoint_count = 0;
14961 tracepoint_count = 0;
14963 add_com ("ignore", class_breakpoint, ignore_command, _("\
14964 Set ignore-count of breakpoint number N to COUNT.\n\
14965 Usage is `ignore N COUNT'."));
14967 add_com_alias ("bc", "ignore", class_breakpoint, 1);
14969 add_com ("commands", class_breakpoint, commands_command, _("\
14970 Set commands to be executed when a breakpoint is hit.\n\
14971 Give breakpoint number as argument after \"commands\".\n\
14972 With no argument, the targeted breakpoint is the last one set.\n\
14973 The commands themselves follow starting on the next line.\n\
14974 Type a line containing \"end\" to indicate the end of them.\n\
14975 Give \"silent\" as the first line to make the breakpoint silent;\n\
14976 then no output is printed when it is hit, except what the commands print."));
14978 add_com ("condition", class_breakpoint, condition_command, _("\
14979 Specify breakpoint number N to break only if COND is true.\n\
14980 Usage is `condition N COND', where N is an integer and COND is an\n\
14981 expression to be evaluated whenever breakpoint N is reached."));
14983 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
14984 Set a temporary breakpoint.\n\
14985 Like \"break\" except the breakpoint is only temporary,\n\
14986 so it will be deleted when hit. Equivalent to \"break\" followed\n\
14987 by using \"enable delete\" on the breakpoint number.\n\
14989 BREAK_ARGS_HELP ("tbreak")));
14990 set_cmd_completer (c, location_completer);
14992 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
14993 Set a hardware assisted breakpoint.\n\
14994 Like \"break\" except the breakpoint requires hardware support,\n\
14995 some target hardware may not have this support.\n\
14997 BREAK_ARGS_HELP ("hbreak")));
14998 set_cmd_completer (c, location_completer);
15000 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
15001 Set a temporary hardware assisted breakpoint.\n\
15002 Like \"hbreak\" except the breakpoint is only temporary,\n\
15003 so it will be deleted when hit.\n\
15005 BREAK_ARGS_HELP ("thbreak")));
15006 set_cmd_completer (c, location_completer);
15008 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
15009 Enable some breakpoints.\n\
15010 Give breakpoint numbers (separated by spaces) as arguments.\n\
15011 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15012 This is used to cancel the effect of the \"disable\" command.\n\
15013 With a subcommand you can enable temporarily."),
15014 &enablelist, "enable ", 1, &cmdlist);
15016 add_com ("ab", class_breakpoint, enable_command, _("\
15017 Enable some breakpoints.\n\
15018 Give breakpoint numbers (separated by spaces) as arguments.\n\
15019 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15020 This is used to cancel the effect of the \"disable\" command.\n\
15021 With a subcommand you can enable temporarily."));
15023 add_com_alias ("en", "enable", class_breakpoint, 1);
15025 add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
15026 Enable some breakpoints.\n\
15027 Give breakpoint numbers (separated by spaces) as arguments.\n\
15028 This is used to cancel the effect of the \"disable\" command.\n\
15029 May be abbreviated to simply \"enable\".\n"),
15030 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
15032 add_cmd ("once", no_class, enable_once_command, _("\
15033 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15034 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15037 add_cmd ("delete", no_class, enable_delete_command, _("\
15038 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15039 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15042 add_cmd ("count", no_class, enable_count_command, _("\
15043 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15044 If a breakpoint is hit while enabled in this fashion,\n\
15045 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15048 add_cmd ("delete", no_class, enable_delete_command, _("\
15049 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15050 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15053 add_cmd ("once", no_class, enable_once_command, _("\
15054 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15055 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15058 add_cmd ("count", no_class, enable_count_command, _("\
15059 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15060 If a breakpoint is hit while enabled in this fashion,\n\
15061 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15064 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
15065 Disable some breakpoints.\n\
15066 Arguments are breakpoint numbers with spaces in between.\n\
15067 To disable all breakpoints, give no argument.\n\
15068 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
15069 &disablelist, "disable ", 1, &cmdlist);
15070 add_com_alias ("dis", "disable", class_breakpoint, 1);
15071 add_com_alias ("disa", "disable", class_breakpoint, 1);
15073 add_com ("sb", class_breakpoint, disable_command, _("\
15074 Disable some breakpoints.\n\
15075 Arguments are breakpoint numbers with spaces in between.\n\
15076 To disable all breakpoints, give no argument.\n\
15077 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
15079 add_cmd ("breakpoints", class_alias, disable_command, _("\
15080 Disable some breakpoints.\n\
15081 Arguments are breakpoint numbers with spaces in between.\n\
15082 To disable all breakpoints, give no argument.\n\
15083 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
15084 This command may be abbreviated \"disable\"."),
15087 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
15088 Delete some breakpoints or auto-display expressions.\n\
15089 Arguments are breakpoint numbers with spaces in between.\n\
15090 To delete all breakpoints, give no argument.\n\
15092 Also a prefix command for deletion of other GDB objects.\n\
15093 The \"unset\" command is also an alias for \"delete\"."),
15094 &deletelist, "delete ", 1, &cmdlist);
15095 add_com_alias ("d", "delete", class_breakpoint, 1);
15096 add_com_alias ("del", "delete", class_breakpoint, 1);
15098 add_com ("db", class_breakpoint, delete_command, _("\
15099 Delete some breakpoints.\n\
15100 Arguments are breakpoint numbers with spaces in between.\n\
15101 To delete all breakpoints, give no argument.\n"));
15103 add_cmd ("breakpoints", class_alias, delete_command, _("\
15104 Delete some breakpoints or auto-display expressions.\n\
15105 Arguments are breakpoint numbers with spaces in between.\n\
15106 To delete all breakpoints, give no argument.\n\
15107 This command may be abbreviated \"delete\"."),
15110 add_com ("clear", class_breakpoint, clear_command, _("\
15111 Clear breakpoint at specified line or function.\n\
15112 Argument may be line number, function name, or \"*\" and an address.\n\
15113 If line number is specified, all breakpoints in that line are cleared.\n\
15114 If function is specified, breakpoints at beginning of function are cleared.\n\
15115 If an address is specified, breakpoints at that address are cleared.\n\
15117 With no argument, clears all breakpoints in the line that the selected frame\n\
15118 is executing in.\n\
15120 See also the \"delete\" command which clears breakpoints by number."));
15121 add_com_alias ("cl", "clear", class_breakpoint, 1);
15123 c = add_com ("break", class_breakpoint, break_command, _("\
15124 Set breakpoint at specified line or function.\n"
15125 BREAK_ARGS_HELP ("break")));
15126 set_cmd_completer (c, location_completer);
15128 add_com_alias ("b", "break", class_run, 1);
15129 add_com_alias ("br", "break", class_run, 1);
15130 add_com_alias ("bre", "break", class_run, 1);
15131 add_com_alias ("brea", "break", class_run, 1);
15134 add_com_alias ("ba", "break", class_breakpoint, 1);
15138 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
15139 Break in function/address or break at a line in the current file."),
15140 &stoplist, "stop ", 1, &cmdlist);
15141 add_cmd ("in", class_breakpoint, stopin_command,
15142 _("Break in function or address."), &stoplist);
15143 add_cmd ("at", class_breakpoint, stopat_command,
15144 _("Break at a line in the current file."), &stoplist);
15145 add_com ("status", class_info, breakpoints_info, _("\
15146 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15147 The \"Type\" column indicates one of:\n\
15148 \tbreakpoint - normal breakpoint\n\
15149 \twatchpoint - watchpoint\n\
15150 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15151 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15152 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15153 address and file/line number respectively.\n\
15155 Convenience variable \"$_\" and default examine address for \"x\"\n\
15156 are set to the address of the last breakpoint listed unless the command\n\
15157 is prefixed with \"server \".\n\n\
15158 Convenience variable \"$bpnum\" contains the number of the last\n\
15159 breakpoint set."));
15162 add_info ("breakpoints", breakpoints_info, _("\
15163 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
15164 The \"Type\" column indicates one of:\n\
15165 \tbreakpoint - normal breakpoint\n\
15166 \twatchpoint - watchpoint\n\
15167 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15168 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15169 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15170 address and file/line number respectively.\n\
15172 Convenience variable \"$_\" and default examine address for \"x\"\n\
15173 are set to the address of the last breakpoint listed unless the command\n\
15174 is prefixed with \"server \".\n\n\
15175 Convenience variable \"$bpnum\" contains the number of the last\n\
15176 breakpoint set."));
15178 add_info_alias ("b", "breakpoints", 1);
15181 add_com ("lb", class_breakpoint, breakpoints_info, _("\
15182 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15183 The \"Type\" column indicates one of:\n\
15184 \tbreakpoint - normal breakpoint\n\
15185 \twatchpoint - watchpoint\n\
15186 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15187 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15188 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15189 address and file/line number respectively.\n\
15191 Convenience variable \"$_\" and default examine address for \"x\"\n\
15192 are set to the address of the last breakpoint listed unless the command\n\
15193 is prefixed with \"server \".\n\n\
15194 Convenience variable \"$bpnum\" contains the number of the last\n\
15195 breakpoint set."));
15197 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
15198 Status of all breakpoints, or breakpoint number NUMBER.\n\
15199 The \"Type\" column indicates one of:\n\
15200 \tbreakpoint - normal breakpoint\n\
15201 \twatchpoint - watchpoint\n\
15202 \tlongjmp - internal breakpoint used to step through longjmp()\n\
15203 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
15204 \tuntil - internal breakpoint used by the \"until\" command\n\
15205 \tfinish - internal breakpoint used by the \"finish\" command\n\
15206 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15207 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15208 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15209 address and file/line number respectively.\n\
15211 Convenience variable \"$_\" and default examine address for \"x\"\n\
15212 are set to the address of the last breakpoint listed unless the command\n\
15213 is prefixed with \"server \".\n\n\
15214 Convenience variable \"$bpnum\" contains the number of the last\n\
15216 &maintenanceinfolist);
15218 add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\
15219 Set catchpoints to catch events."),
15220 &catch_cmdlist, "catch ",
15221 0/*allow-unknown*/, &cmdlist);
15223 add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\
15224 Set temporary catchpoints to catch events."),
15225 &tcatch_cmdlist, "tcatch ",
15226 0/*allow-unknown*/, &cmdlist);
15228 /* Add catch and tcatch sub-commands. */
15229 add_catch_command ("catch", _("\
15230 Catch an exception, when caught."),
15231 catch_catch_command,
15235 add_catch_command ("throw", _("\
15236 Catch an exception, when thrown."),
15237 catch_throw_command,
15241 add_catch_command ("fork", _("Catch calls to fork."),
15242 catch_fork_command_1,
15244 (void *) (uintptr_t) catch_fork_permanent,
15245 (void *) (uintptr_t) catch_fork_temporary);
15246 add_catch_command ("vfork", _("Catch calls to vfork."),
15247 catch_fork_command_1,
15249 (void *) (uintptr_t) catch_vfork_permanent,
15250 (void *) (uintptr_t) catch_vfork_temporary);
15251 add_catch_command ("exec", _("Catch calls to exec."),
15252 catch_exec_command_1,
15256 add_catch_command ("load", _("Catch loads of shared libraries.\n\
15257 Usage: catch load [REGEX]\n\
15258 If REGEX is given, only stop for libraries matching the regular expression."),
15259 catch_load_command_1,
15263 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
15264 Usage: catch unload [REGEX]\n\
15265 If REGEX is given, only stop for libraries matching the regular expression."),
15266 catch_unload_command_1,
15270 add_catch_command ("syscall", _("\
15271 Catch system calls by their names and/or numbers.\n\
15272 Arguments say which system calls to catch. If no arguments\n\
15273 are given, every system call will be caught.\n\
15274 Arguments, if given, should be one or more system call names\n\
15275 (if your system supports that), or system call numbers."),
15276 catch_syscall_command_1,
15277 catch_syscall_completer,
15281 c = add_com ("watch", class_breakpoint, watch_command, _("\
15282 Set a watchpoint for an expression.\n\
15283 Usage: watch [-l|-location] EXPRESSION\n\
15284 A watchpoint stops execution of your program whenever the value of\n\
15285 an expression changes.\n\
15286 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15287 the memory to which it refers."));
15288 set_cmd_completer (c, expression_completer);
15290 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
15291 Set a read watchpoint for an expression.\n\
15292 Usage: rwatch [-l|-location] EXPRESSION\n\
15293 A watchpoint stops execution of your program whenever the value of\n\
15294 an expression is read.\n\
15295 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15296 the memory to which it refers."));
15297 set_cmd_completer (c, expression_completer);
15299 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
15300 Set a watchpoint for an expression.\n\
15301 Usage: awatch [-l|-location] EXPRESSION\n\
15302 A watchpoint stops execution of your program whenever the value of\n\
15303 an expression is either read or written.\n\
15304 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15305 the memory to which it refers."));
15306 set_cmd_completer (c, expression_completer);
15308 add_info ("watchpoints", watchpoints_info, _("\
15309 Status of specified watchpoints (all watchpoints if no argument)."));
15311 /* XXX: cagney/2005-02-23: This should be a boolean, and should
15312 respond to changes - contrary to the description. */
15313 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
15314 &can_use_hw_watchpoints, _("\
15315 Set debugger's willingness to use watchpoint hardware."), _("\
15316 Show debugger's willingness to use watchpoint hardware."), _("\
15317 If zero, gdb will not use hardware for new watchpoints, even if\n\
15318 such is available. (However, any hardware watchpoints that were\n\
15319 created before setting this to nonzero, will continue to use watchpoint\n\
15322 show_can_use_hw_watchpoints,
15323 &setlist, &showlist);
15325 can_use_hw_watchpoints = 1;
15327 /* Tracepoint manipulation commands. */
15329 c = add_com ("trace", class_breakpoint, trace_command, _("\
15330 Set a tracepoint at specified line or function.\n\
15332 BREAK_ARGS_HELP ("trace") "\n\
15333 Do \"help tracepoints\" for info on other tracepoint commands."));
15334 set_cmd_completer (c, location_completer);
15336 add_com_alias ("tp", "trace", class_alias, 0);
15337 add_com_alias ("tr", "trace", class_alias, 1);
15338 add_com_alias ("tra", "trace", class_alias, 1);
15339 add_com_alias ("trac", "trace", class_alias, 1);
15341 c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\
15342 Set a fast tracepoint at specified line or function.\n\
15344 BREAK_ARGS_HELP ("ftrace") "\n\
15345 Do \"help tracepoints\" for info on other tracepoint commands."));
15346 set_cmd_completer (c, location_completer);
15348 c = add_com ("strace", class_breakpoint, strace_command, _("\
15349 Set a static tracepoint at specified line, function or marker.\n\
15351 strace [LOCATION] [if CONDITION]\n\
15352 LOCATION may be a line number, function name, \"*\" and an address,\n\
15353 or -m MARKER_ID.\n\
15354 If a line number is specified, probe the marker at start of code\n\
15355 for that line. If a function is specified, probe the marker at start\n\
15356 of code for that function. If an address is specified, probe the marker\n\
15357 at that exact address. If a marker id is specified, probe the marker\n\
15358 with that name. With no LOCATION, uses current execution address of\n\
15359 the selected stack frame.\n\
15360 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
15361 This collects arbitrary user data passed in the probe point call to the\n\
15362 tracing library. You can inspect it when analyzing the trace buffer,\n\
15363 by printing the $_sdata variable like any other convenience variable.\n\
15365 CONDITION is a boolean expression.\n\
15367 Multiple tracepoints at one place are permitted, and useful if their\n\
15368 conditions are different.\n\
15370 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
15371 Do \"help tracepoints\" for info on other tracepoint commands."));
15372 set_cmd_completer (c, location_completer);
15374 add_info ("tracepoints", tracepoints_info, _("\
15375 Status of specified tracepoints (all tracepoints if no argument).\n\
15376 Convenience variable \"$tpnum\" contains the number of the\n\
15377 last tracepoint set."));
15379 add_info_alias ("tp", "tracepoints", 1);
15381 add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
15382 Delete specified tracepoints.\n\
15383 Arguments are tracepoint numbers, separated by spaces.\n\
15384 No argument means delete all tracepoints."),
15387 c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
15388 Disable specified tracepoints.\n\
15389 Arguments are tracepoint numbers, separated by spaces.\n\
15390 No argument means disable all tracepoints."),
15392 deprecate_cmd (c, "disable");
15394 c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\
15395 Enable specified tracepoints.\n\
15396 Arguments are tracepoint numbers, separated by spaces.\n\
15397 No argument means enable all tracepoints."),
15399 deprecate_cmd (c, "enable");
15401 add_com ("passcount", class_trace, trace_pass_command, _("\
15402 Set the passcount for a tracepoint.\n\
15403 The trace will end when the tracepoint has been passed 'count' times.\n\
15404 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
15405 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
15407 add_prefix_cmd ("save", class_breakpoint, save_command,
15408 _("Save breakpoint definitions as a script."),
15409 &save_cmdlist, "save ",
15410 0/*allow-unknown*/, &cmdlist);
15412 c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\
15413 Save current breakpoint definitions as a script.\n\
15414 This includes all types of breakpoints (breakpoints, watchpoints,\n\
15415 catchpoints, tracepoints). Use the 'source' command in another debug\n\
15416 session to restore them."),
15418 set_cmd_completer (c, filename_completer);
15420 c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\
15421 Save current tracepoint definitions as a script.\n\
15422 Use the 'source' command in another debug session to restore them."),
15424 set_cmd_completer (c, filename_completer);
15426 c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0);
15427 deprecate_cmd (c, "save tracepoints");
15429 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
15430 Breakpoint specific settings\n\
15431 Configure various breakpoint-specific variables such as\n\
15432 pending breakpoint behavior"),
15433 &breakpoint_set_cmdlist, "set breakpoint ",
15434 0/*allow-unknown*/, &setlist);
15435 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
15436 Breakpoint specific settings\n\
15437 Configure various breakpoint-specific variables such as\n\
15438 pending breakpoint behavior"),
15439 &breakpoint_show_cmdlist, "show breakpoint ",
15440 0/*allow-unknown*/, &showlist);
15442 add_setshow_auto_boolean_cmd ("pending", no_class,
15443 &pending_break_support, _("\
15444 Set debugger's behavior regarding pending breakpoints."), _("\
15445 Show debugger's behavior regarding pending breakpoints."), _("\
15446 If on, an unrecognized breakpoint location will cause gdb to create a\n\
15447 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
15448 an error. If auto, an unrecognized breakpoint location results in a\n\
15449 user-query to see if a pending breakpoint should be created."),
15451 show_pending_break_support,
15452 &breakpoint_set_cmdlist,
15453 &breakpoint_show_cmdlist);
15455 pending_break_support = AUTO_BOOLEAN_AUTO;
15457 add_setshow_boolean_cmd ("auto-hw", no_class,
15458 &automatic_hardware_breakpoints, _("\
15459 Set automatic usage of hardware breakpoints."), _("\
15460 Show automatic usage of hardware breakpoints."), _("\
15461 If set, the debugger will automatically use hardware breakpoints for\n\
15462 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
15463 a warning will be emitted for such breakpoints."),
15465 show_automatic_hardware_breakpoints,
15466 &breakpoint_set_cmdlist,
15467 &breakpoint_show_cmdlist);
15469 add_setshow_enum_cmd ("always-inserted", class_support,
15470 always_inserted_enums, &always_inserted_mode, _("\
15471 Set mode for inserting breakpoints."), _("\
15472 Show mode for inserting breakpoints."), _("\
15473 When this mode is off, breakpoints are inserted in inferior when it is\n\
15474 resumed, and removed when execution stops. When this mode is on,\n\
15475 breakpoints are inserted immediately and removed only when the user\n\
15476 deletes the breakpoint. When this mode is auto (which is the default),\n\
15477 the behaviour depends on the non-stop setting (see help set non-stop).\n\
15478 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
15479 behaves as if always-inserted mode is on; if gdb is controlling the\n\
15480 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
15482 &show_always_inserted_mode,
15483 &breakpoint_set_cmdlist,
15484 &breakpoint_show_cmdlist);
15486 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint,
15487 condition_evaluation_enums,
15488 &condition_evaluation_mode_1, _("\
15489 Set mode of breakpoint condition evaluation."), _("\
15490 Show mode of breakpoint condition evaluation."), _("\
15491 When this is set to \"gdb\", breakpoint conditions will be\n\
15492 evaluated on the host's side by GDB. When it is set to \"target\",\n\
15493 breakpoint conditions will be downloaded to the target (if the target\n\
15494 supports such feature) and conditions will be evaluated on the target's side.\n\
15495 If this is set to \"auto\" (default), this will be automatically set to\n\
15496 \"target\" if it supports condition evaluation, otherwise it will\n\
15497 be set to \"gdb\""),
15498 &set_condition_evaluation_mode,
15499 &show_condition_evaluation_mode,
15500 &breakpoint_set_cmdlist,
15501 &breakpoint_show_cmdlist);
15503 add_com ("break-range", class_breakpoint, break_range_command, _("\
15504 Set a breakpoint for an address range.\n\
15505 break-range START-LOCATION, END-LOCATION\n\
15506 where START-LOCATION and END-LOCATION can be one of the following:\n\
15507 LINENUM, for that line in the current file,\n\
15508 FILE:LINENUM, for that line in that file,\n\
15509 +OFFSET, for that number of lines after the current line\n\
15510 or the start of the range\n\
15511 FUNCTION, for the first line in that function,\n\
15512 FILE:FUNCTION, to distinguish among like-named static functions.\n\
15513 *ADDRESS, for the instruction at that address.\n\
15515 The breakpoint will stop execution of the inferior whenever it executes\n\
15516 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
15517 range (including START-LOCATION and END-LOCATION)."));
15519 automatic_hardware_breakpoints = 1;
15521 observer_attach_about_to_proceed (breakpoint_about_to_proceed);