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 gdbarch *frame_gdbarch = get_frame_arch (frame);
10422 struct frame_id stack_frame_id = get_stack_frame_id (frame);
10423 struct frame_id caller_frame_id = frame_unwind_caller_id (frame);
10424 struct breakpoint *breakpoint;
10425 struct breakpoint *breakpoint2 = NULL;
10426 struct cleanup *old_chain;
10428 struct thread_info *tp;
10430 clear_proceed_status ();
10432 /* Set a breakpoint where the user wants it and at return from
10435 if (last_displayed_sal_is_valid ())
10436 sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE,
10437 get_last_displayed_symtab (),
10438 get_last_displayed_line ());
10440 sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE,
10441 (struct symtab *) NULL, 0);
10443 if (sals.nelts != 1)
10444 error (_("Couldn't get information on specified line."));
10446 sal = sals.sals[0];
10447 xfree (sals.sals); /* malloc'd, so freed. */
10450 error (_("Junk at end of arguments."));
10452 resolve_sal_pc (&sal);
10454 tp = inferior_thread ();
10457 old_chain = make_cleanup (null_cleanup, NULL);
10459 /* Installing a breakpoint invalidates the frame chain (as it may
10460 need to switch threads), so do any frame handling first. */
10462 /* Keep within the current frame, or in frames called by the current
10465 if (frame_id_p (caller_frame_id))
10467 struct symtab_and_line sal2;
10469 sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0);
10470 sal2.pc = frame_unwind_caller_pc (frame);
10471 breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame),
10475 make_cleanup_delete_breakpoint (breakpoint2);
10477 set_longjmp_breakpoint (tp, caller_frame_id);
10478 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
10481 /* set_momentary_breakpoint could invalidate FRAME. */
10485 /* If the user told us to continue until a specified location,
10486 we don't specify a frame at which we need to stop. */
10487 breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
10488 null_frame_id, bp_until);
10490 /* Otherwise, specify the selected frame, because we want to stop
10491 only at the very same frame. */
10492 breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
10493 stack_frame_id, bp_until);
10494 make_cleanup_delete_breakpoint (breakpoint);
10496 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
10498 /* If we are running asynchronously, and proceed call above has
10499 actually managed to start the target, arrange for breakpoints to
10500 be deleted when the target stops. Otherwise, we're already
10501 stopped and delete breakpoints via cleanup chain. */
10503 if (target_can_async_p () && is_running (inferior_ptid))
10505 struct until_break_command_continuation_args *args;
10506 args = xmalloc (sizeof (*args));
10508 args->breakpoint = breakpoint;
10509 args->breakpoint2 = breakpoint2;
10510 args->thread_num = thread;
10512 discard_cleanups (old_chain);
10513 add_continuation (inferior_thread (),
10514 until_break_command_continuation, args,
10518 do_cleanups (old_chain);
10521 /* This function attempts to parse an optional "if <cond>" clause
10522 from the arg string. If one is not found, it returns NULL.
10524 Else, it returns a pointer to the condition string. (It does not
10525 attempt to evaluate the string against a particular block.) And,
10526 it updates arg to point to the first character following the parsed
10527 if clause in the arg string. */
10530 ep_parse_optional_if_clause (char **arg)
10534 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
10537 /* Skip the "if" keyword. */
10540 /* Skip any extra leading whitespace, and record the start of the
10541 condition string. */
10542 *arg = skip_spaces (*arg);
10543 cond_string = *arg;
10545 /* Assume that the condition occupies the remainder of the arg
10547 (*arg) += strlen (cond_string);
10549 return cond_string;
10552 /* Commands to deal with catching events, such as signals, exceptions,
10553 process start/exit, etc. */
10557 catch_fork_temporary, catch_vfork_temporary,
10558 catch_fork_permanent, catch_vfork_permanent
10563 catch_fork_command_1 (char *arg, int from_tty,
10564 struct cmd_list_element *command)
10566 struct gdbarch *gdbarch = get_current_arch ();
10567 char *cond_string = NULL;
10568 catch_fork_kind fork_kind;
10571 fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command);
10572 tempflag = (fork_kind == catch_fork_temporary
10573 || fork_kind == catch_vfork_temporary);
10577 arg = skip_spaces (arg);
10579 /* The allowed syntax is:
10581 catch [v]fork if <cond>
10583 First, check if there's an if clause. */
10584 cond_string = ep_parse_optional_if_clause (&arg);
10586 if ((*arg != '\0') && !isspace (*arg))
10587 error (_("Junk at end of arguments."));
10589 /* If this target supports it, create a fork or vfork catchpoint
10590 and enable reporting of such events. */
10593 case catch_fork_temporary:
10594 case catch_fork_permanent:
10595 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
10596 &catch_fork_breakpoint_ops);
10598 case catch_vfork_temporary:
10599 case catch_vfork_permanent:
10600 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
10601 &catch_vfork_breakpoint_ops);
10604 error (_("unsupported or unknown fork kind; cannot catch it"));
10610 catch_exec_command_1 (char *arg, int from_tty,
10611 struct cmd_list_element *command)
10613 struct exec_catchpoint *c;
10614 struct gdbarch *gdbarch = get_current_arch ();
10616 char *cond_string = NULL;
10618 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
10622 arg = skip_spaces (arg);
10624 /* The allowed syntax is:
10626 catch exec if <cond>
10628 First, check if there's an if clause. */
10629 cond_string = ep_parse_optional_if_clause (&arg);
10631 if ((*arg != '\0') && !isspace (*arg))
10632 error (_("Junk at end of arguments."));
10634 c = XNEW (struct exec_catchpoint);
10635 init_catchpoint (&c->base, gdbarch, tempflag, cond_string,
10636 &catch_exec_breakpoint_ops);
10637 c->exec_pathname = NULL;
10639 install_breakpoint (0, &c->base, 1);
10642 static enum print_stop_action
10643 print_it_exception_catchpoint (bpstat bs)
10645 struct ui_out *uiout = current_uiout;
10646 struct breakpoint *b = bs->breakpoint_at;
10647 int bp_temp, bp_throw;
10649 annotate_catchpoint (b->number);
10651 bp_throw = strstr (b->addr_string, "throw") != NULL;
10652 if (b->loc->address != b->loc->requested_address)
10653 breakpoint_adjustment_warning (b->loc->requested_address,
10656 bp_temp = b->disposition == disp_del;
10657 ui_out_text (uiout,
10658 bp_temp ? "Temporary catchpoint "
10660 if (!ui_out_is_mi_like_p (uiout))
10661 ui_out_field_int (uiout, "bkptno", b->number);
10662 ui_out_text (uiout,
10663 bp_throw ? " (exception thrown), "
10664 : " (exception caught), ");
10665 if (ui_out_is_mi_like_p (uiout))
10667 ui_out_field_string (uiout, "reason",
10668 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
10669 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
10670 ui_out_field_int (uiout, "bkptno", b->number);
10672 return PRINT_SRC_AND_LOC;
10676 print_one_exception_catchpoint (struct breakpoint *b,
10677 struct bp_location **last_loc)
10679 struct value_print_options opts;
10680 struct ui_out *uiout = current_uiout;
10682 get_user_print_options (&opts);
10683 if (opts.addressprint)
10685 annotate_field (4);
10686 if (b->loc == NULL || b->loc->shlib_disabled)
10687 ui_out_field_string (uiout, "addr", "<PENDING>");
10689 ui_out_field_core_addr (uiout, "addr",
10690 b->loc->gdbarch, b->loc->address);
10692 annotate_field (5);
10694 *last_loc = b->loc;
10695 if (strstr (b->addr_string, "throw") != NULL)
10696 ui_out_field_string (uiout, "what", "exception throw");
10698 ui_out_field_string (uiout, "what", "exception catch");
10702 print_mention_exception_catchpoint (struct breakpoint *b)
10704 struct ui_out *uiout = current_uiout;
10708 bp_temp = b->disposition == disp_del;
10709 bp_throw = strstr (b->addr_string, "throw") != NULL;
10710 ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ")
10711 : _("Catchpoint "));
10712 ui_out_field_int (uiout, "bkptno", b->number);
10713 ui_out_text (uiout, bp_throw ? _(" (throw)")
10717 /* Implement the "print_recreate" breakpoint_ops method for throw and
10718 catch catchpoints. */
10721 print_recreate_exception_catchpoint (struct breakpoint *b,
10722 struct ui_file *fp)
10727 bp_temp = b->disposition == disp_del;
10728 bp_throw = strstr (b->addr_string, "throw") != NULL;
10729 fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch ");
10730 fprintf_unfiltered (fp, bp_throw ? "throw" : "catch");
10731 print_recreate_thread (b, fp);
10734 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops;
10737 handle_gnu_v3_exceptions (int tempflag, char *cond_string,
10738 enum exception_event_kind ex_event, int from_tty)
10740 char *trigger_func_name;
10742 if (ex_event == EX_EVENT_CATCH)
10743 trigger_func_name = "__cxa_begin_catch";
10745 trigger_func_name = "__cxa_throw";
10747 create_breakpoint (get_current_arch (),
10748 trigger_func_name, cond_string, -1,
10749 0 /* condition and thread are valid. */,
10750 tempflag, bp_breakpoint,
10752 AUTO_BOOLEAN_TRUE /* pending */,
10753 &gnu_v3_exception_catchpoint_ops, from_tty,
10760 /* Deal with "catch catch" and "catch throw" commands. */
10763 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
10764 int tempflag, int from_tty)
10766 char *cond_string = NULL;
10770 arg = skip_spaces (arg);
10772 cond_string = ep_parse_optional_if_clause (&arg);
10774 if ((*arg != '\0') && !isspace (*arg))
10775 error (_("Junk at end of arguments."));
10777 if (ex_event != EX_EVENT_THROW
10778 && ex_event != EX_EVENT_CATCH)
10779 error (_("Unsupported or unknown exception event; cannot catch it"));
10781 if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
10784 warning (_("Unsupported with this platform/compiler combination."));
10787 /* Implementation of "catch catch" command. */
10790 catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command)
10792 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
10794 catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty);
10797 /* Implementation of "catch throw" command. */
10800 catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command)
10802 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
10804 catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty);
10808 init_ada_exception_breakpoint (struct breakpoint *b,
10809 struct gdbarch *gdbarch,
10810 struct symtab_and_line sal,
10812 const struct breakpoint_ops *ops,
10818 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
10820 loc_gdbarch = gdbarch;
10822 describe_other_breakpoints (loc_gdbarch,
10823 sal.pspace, sal.pc, sal.section, -1);
10824 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
10825 version for exception catchpoints, because two catchpoints
10826 used for different exception names will use the same address.
10827 In this case, a "breakpoint ... also set at..." warning is
10828 unproductive. Besides, the warning phrasing is also a bit
10829 inappropriate, we should use the word catchpoint, and tell
10830 the user what type of catchpoint it is. The above is good
10831 enough for now, though. */
10834 init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops);
10836 b->enable_state = bp_enabled;
10837 b->disposition = tempflag ? disp_del : disp_donttouch;
10838 b->addr_string = addr_string;
10839 b->language = language_ada;
10842 /* Splits the argument using space as delimiter. Returns an xmalloc'd
10843 filter list, or NULL if no filtering is required. */
10845 catch_syscall_split_args (char *arg)
10847 VEC(int) *result = NULL;
10848 struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result);
10850 while (*arg != '\0')
10852 int i, syscall_number;
10854 char cur_name[128];
10857 /* Skip whitespace. */
10858 while (isspace (*arg))
10861 for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i)
10862 cur_name[i] = arg[i];
10863 cur_name[i] = '\0';
10866 /* Check if the user provided a syscall name or a number. */
10867 syscall_number = (int) strtol (cur_name, &endptr, 0);
10868 if (*endptr == '\0')
10869 get_syscall_by_number (syscall_number, &s);
10872 /* We have a name. Let's check if it's valid and convert it
10874 get_syscall_by_name (cur_name, &s);
10876 if (s.number == UNKNOWN_SYSCALL)
10877 /* Here we have to issue an error instead of a warning,
10878 because GDB cannot do anything useful if there's no
10879 syscall number to be caught. */
10880 error (_("Unknown syscall name '%s'."), cur_name);
10883 /* Ok, it's valid. */
10884 VEC_safe_push (int, result, s.number);
10887 discard_cleanups (cleanup);
10891 /* Implement the "catch syscall" command. */
10894 catch_syscall_command_1 (char *arg, int from_tty,
10895 struct cmd_list_element *command)
10900 struct gdbarch *gdbarch = get_current_arch ();
10902 /* Checking if the feature if supported. */
10903 if (gdbarch_get_syscall_number_p (gdbarch) == 0)
10904 error (_("The feature 'catch syscall' is not supported on \
10905 this architecture yet."));
10907 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
10909 arg = skip_spaces (arg);
10911 /* We need to do this first "dummy" translation in order
10912 to get the syscall XML file loaded or, most important,
10913 to display a warning to the user if there's no XML file
10914 for his/her architecture. */
10915 get_syscall_by_number (0, &s);
10917 /* The allowed syntax is:
10919 catch syscall <name | number> [<name | number> ... <name | number>]
10921 Let's check if there's a syscall name. */
10924 filter = catch_syscall_split_args (arg);
10928 create_syscall_event_catchpoint (tempflag, filter,
10929 &catch_syscall_breakpoint_ops);
10933 catch_command (char *arg, int from_tty)
10935 error (_("Catch requires an event name."));
10940 tcatch_command (char *arg, int from_tty)
10942 error (_("Catch requires an event name."));
10945 /* A qsort comparison function that sorts breakpoints in order. */
10948 compare_breakpoints (const void *a, const void *b)
10950 const breakpoint_p *ba = a;
10951 uintptr_t ua = (uintptr_t) *ba;
10952 const breakpoint_p *bb = b;
10953 uintptr_t ub = (uintptr_t) *bb;
10955 if ((*ba)->number < (*bb)->number)
10957 else if ((*ba)->number > (*bb)->number)
10960 /* Now sort by address, in case we see, e..g, two breakpoints with
10964 return ub > ub ? 1 : 0;
10967 /* Delete breakpoints by address or line. */
10970 clear_command (char *arg, int from_tty)
10972 struct breakpoint *b, *prev;
10973 VEC(breakpoint_p) *found = 0;
10976 struct symtabs_and_lines sals;
10977 struct symtab_and_line sal;
10979 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
10983 sals = decode_line_spec (arg, (DECODE_LINE_FUNFIRSTLINE
10984 | DECODE_LINE_LIST_MODE));
10989 sals.sals = (struct symtab_and_line *)
10990 xmalloc (sizeof (struct symtab_and_line));
10991 make_cleanup (xfree, sals.sals);
10992 init_sal (&sal); /* Initialize to zeroes. */
10994 /* Set sal's line, symtab, pc, and pspace to the values
10995 corresponding to the last call to print_frame_info. If the
10996 codepoint is not valid, this will set all the fields to 0. */
10997 get_last_displayed_sal (&sal);
10998 if (sal.symtab == 0)
10999 error (_("No source file specified."));
11001 sals.sals[0] = sal;
11007 /* We don't call resolve_sal_pc here. That's not as bad as it
11008 seems, because all existing breakpoints typically have both
11009 file/line and pc set. So, if clear is given file/line, we can
11010 match this to existing breakpoint without obtaining pc at all.
11012 We only support clearing given the address explicitly
11013 present in breakpoint table. Say, we've set breakpoint
11014 at file:line. There were several PC values for that file:line,
11015 due to optimization, all in one block.
11017 We've picked one PC value. If "clear" is issued with another
11018 PC corresponding to the same file:line, the breakpoint won't
11019 be cleared. We probably can still clear the breakpoint, but
11020 since the other PC value is never presented to user, user
11021 can only find it by guessing, and it does not seem important
11022 to support that. */
11024 /* For each line spec given, delete bps which correspond to it. Do
11025 it in two passes, solely to preserve the current behavior that
11026 from_tty is forced true if we delete more than one
11030 make_cleanup (VEC_cleanup (breakpoint_p), &found);
11031 for (i = 0; i < sals.nelts; i++)
11033 int is_abs, sal_name_len;
11035 /* If exact pc given, clear bpts at that pc.
11036 If line given (pc == 0), clear all bpts on specified line.
11037 If defaulting, clear all bpts on default line
11040 defaulting sal.pc != 0 tests to do
11045 1 0 <can't happen> */
11047 sal = sals.sals[i];
11048 is_abs = sal.symtab == NULL ? 1 : IS_ABSOLUTE_PATH (sal.symtab->filename);
11049 sal_name_len = is_abs ? 0 : strlen (sal.symtab->filename);
11051 /* Find all matching breakpoints and add them to 'found'. */
11052 ALL_BREAKPOINTS (b)
11055 /* Are we going to delete b? */
11056 if (b->type != bp_none && !is_watchpoint (b))
11058 struct bp_location *loc = b->loc;
11059 for (; loc; loc = loc->next)
11061 /* If the user specified file:line, don't allow a PC
11062 match. This matches historical gdb behavior. */
11063 int pc_match = (!sal.explicit_line
11065 && (loc->pspace == sal.pspace)
11066 && (loc->address == sal.pc)
11067 && (!section_is_overlay (loc->section)
11068 || loc->section == sal.section));
11069 int line_match = 0;
11071 if ((default_match || sal.explicit_line)
11072 && loc->source_file != NULL
11073 && sal.symtab != NULL
11074 && sal.pspace == loc->pspace
11075 && loc->line_number == sal.line)
11077 if (filename_cmp (loc->source_file,
11078 sal.symtab->filename) == 0)
11080 else if (!IS_ABSOLUTE_PATH (sal.symtab->filename)
11081 && compare_filenames_for_search (loc->source_file,
11082 sal.symtab->filename,
11087 if (pc_match || line_match)
11096 VEC_safe_push(breakpoint_p, found, b);
11100 /* Now go thru the 'found' chain and delete them. */
11101 if (VEC_empty(breakpoint_p, found))
11104 error (_("No breakpoint at %s."), arg);
11106 error (_("No breakpoint at this line."));
11109 /* Remove duplicates from the vec. */
11110 qsort (VEC_address (breakpoint_p, found),
11111 VEC_length (breakpoint_p, found),
11112 sizeof (breakpoint_p),
11113 compare_breakpoints);
11114 prev = VEC_index (breakpoint_p, found, 0);
11115 for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix)
11119 VEC_ordered_remove (breakpoint_p, found, ix);
11124 if (VEC_length(breakpoint_p, found) > 1)
11125 from_tty = 1; /* Always report if deleted more than one. */
11128 if (VEC_length(breakpoint_p, found) == 1)
11129 printf_unfiltered (_("Deleted breakpoint "));
11131 printf_unfiltered (_("Deleted breakpoints "));
11133 breakpoints_changed ();
11135 for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++)
11138 printf_unfiltered ("%d ", b->number);
11139 delete_breakpoint (b);
11142 putchar_unfiltered ('\n');
11144 do_cleanups (cleanups);
11147 /* Delete breakpoint in BS if they are `delete' breakpoints and
11148 all breakpoints that are marked for deletion, whether hit or not.
11149 This is called after any breakpoint is hit, or after errors. */
11152 breakpoint_auto_delete (bpstat bs)
11154 struct breakpoint *b, *b_tmp;
11156 for (; bs; bs = bs->next)
11157 if (bs->breakpoint_at
11158 && bs->breakpoint_at->disposition == disp_del
11160 delete_breakpoint (bs->breakpoint_at);
11162 ALL_BREAKPOINTS_SAFE (b, b_tmp)
11164 if (b->disposition == disp_del_at_next_stop)
11165 delete_breakpoint (b);
11169 /* A comparison function for bp_location AP and BP being interfaced to
11170 qsort. Sort elements primarily by their ADDRESS (no matter what
11171 does breakpoint_address_is_meaningful say for its OWNER),
11172 secondarily by ordering first bp_permanent OWNERed elements and
11173 terciarily just ensuring the array is sorted stable way despite
11174 qsort being an unstable algorithm. */
11177 bp_location_compare (const void *ap, const void *bp)
11179 struct bp_location *a = *(void **) ap;
11180 struct bp_location *b = *(void **) bp;
11181 /* A and B come from existing breakpoints having non-NULL OWNER. */
11182 int a_perm = a->owner->enable_state == bp_permanent;
11183 int b_perm = b->owner->enable_state == bp_permanent;
11185 if (a->address != b->address)
11186 return (a->address > b->address) - (a->address < b->address);
11188 /* Sort locations at the same address by their pspace number, keeping
11189 locations of the same inferior (in a multi-inferior environment)
11192 if (a->pspace->num != b->pspace->num)
11193 return ((a->pspace->num > b->pspace->num)
11194 - (a->pspace->num < b->pspace->num));
11196 /* Sort permanent breakpoints first. */
11197 if (a_perm != b_perm)
11198 return (a_perm < b_perm) - (a_perm > b_perm);
11200 /* Make the internal GDB representation stable across GDB runs
11201 where A and B memory inside GDB can differ. Breakpoint locations of
11202 the same type at the same address can be sorted in arbitrary order. */
11204 if (a->owner->number != b->owner->number)
11205 return ((a->owner->number > b->owner->number)
11206 - (a->owner->number < b->owner->number));
11208 return (a > b) - (a < b);
11211 /* Set bp_location_placed_address_before_address_max and
11212 bp_location_shadow_len_after_address_max according to the current
11213 content of the bp_location array. */
11216 bp_location_target_extensions_update (void)
11218 struct bp_location *bl, **blp_tmp;
11220 bp_location_placed_address_before_address_max = 0;
11221 bp_location_shadow_len_after_address_max = 0;
11223 ALL_BP_LOCATIONS (bl, blp_tmp)
11225 CORE_ADDR start, end, addr;
11227 if (!bp_location_has_shadow (bl))
11230 start = bl->target_info.placed_address;
11231 end = start + bl->target_info.shadow_len;
11233 gdb_assert (bl->address >= start);
11234 addr = bl->address - start;
11235 if (addr > bp_location_placed_address_before_address_max)
11236 bp_location_placed_address_before_address_max = addr;
11238 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11240 gdb_assert (bl->address < end);
11241 addr = end - bl->address;
11242 if (addr > bp_location_shadow_len_after_address_max)
11243 bp_location_shadow_len_after_address_max = addr;
11247 /* Download tracepoint locations if they haven't been. */
11250 download_tracepoint_locations (void)
11252 struct bp_location *bl, **blp_tmp;
11253 struct cleanup *old_chain;
11255 if (!target_can_download_tracepoint ())
11258 old_chain = save_current_space_and_thread ();
11260 ALL_BP_LOCATIONS (bl, blp_tmp)
11262 struct tracepoint *t;
11264 if (!is_tracepoint (bl->owner))
11267 if ((bl->owner->type == bp_fast_tracepoint
11268 ? !may_insert_fast_tracepoints
11269 : !may_insert_tracepoints))
11272 /* In tracepoint, locations are _never_ duplicated, so
11273 should_be_inserted is equivalent to
11274 unduplicated_should_be_inserted. */
11275 if (!should_be_inserted (bl) || bl->inserted)
11278 switch_to_program_space_and_thread (bl->pspace);
11280 target_download_tracepoint (bl);
11283 t = (struct tracepoint *) bl->owner;
11284 t->number_on_target = bl->owner->number;
11287 do_cleanups (old_chain);
11290 /* Swap the insertion/duplication state between two locations. */
11293 swap_insertion (struct bp_location *left, struct bp_location *right)
11295 const int left_inserted = left->inserted;
11296 const int left_duplicate = left->duplicate;
11297 const int left_needs_update = left->needs_update;
11298 const struct bp_target_info left_target_info = left->target_info;
11300 /* Locations of tracepoints can never be duplicated. */
11301 if (is_tracepoint (left->owner))
11302 gdb_assert (!left->duplicate);
11303 if (is_tracepoint (right->owner))
11304 gdb_assert (!right->duplicate);
11306 left->inserted = right->inserted;
11307 left->duplicate = right->duplicate;
11308 left->needs_update = right->needs_update;
11309 left->target_info = right->target_info;
11310 right->inserted = left_inserted;
11311 right->duplicate = left_duplicate;
11312 right->needs_update = left_needs_update;
11313 right->target_info = left_target_info;
11316 /* Force the re-insertion of the locations at ADDRESS. This is called
11317 once a new/deleted/modified duplicate location is found and we are evaluating
11318 conditions on the target's side. Such conditions need to be updated on
11322 force_breakpoint_reinsertion (struct bp_location *bl)
11324 struct bp_location **locp = NULL, **loc2p;
11325 struct bp_location *loc;
11326 CORE_ADDR address = 0;
11329 address = bl->address;
11330 pspace_num = bl->pspace->num;
11332 /* This is only meaningful if the target is
11333 evaluating conditions and if the user has
11334 opted for condition evaluation on the target's
11336 if (gdb_evaluates_breakpoint_condition_p ()
11337 || !target_supports_evaluation_of_breakpoint_conditions ())
11340 /* Flag all breakpoint locations with this address and
11341 the same program space as the location
11342 as "its condition has changed". We need to
11343 update the conditions on the target's side. */
11344 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address)
11348 if (!is_breakpoint (loc->owner)
11349 || pspace_num != loc->pspace->num)
11352 /* Flag the location appropriately. We use a different state to
11353 let everyone know that we already updated the set of locations
11354 with addr bl->address and program space bl->pspace. This is so
11355 we don't have to keep calling these functions just to mark locations
11356 that have already been marked. */
11357 loc->condition_changed = condition_updated;
11359 /* Free the agent expression bytecode as well. We will compute
11361 if (loc->cond_bytecode)
11363 free_agent_expr (loc->cond_bytecode);
11364 loc->cond_bytecode = NULL;
11369 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
11370 into the inferior, only remove already-inserted locations that no
11371 longer should be inserted. Functions that delete a breakpoint or
11372 breakpoints should pass false, so that deleting a breakpoint
11373 doesn't have the side effect of inserting the locations of other
11374 breakpoints that are marked not-inserted, but should_be_inserted
11375 returns true on them.
11377 This behaviour is useful is situations close to tear-down -- e.g.,
11378 after an exec, while the target still has execution, but breakpoint
11379 shadows of the previous executable image should *NOT* be restored
11380 to the new image; or before detaching, where the target still has
11381 execution and wants to delete breakpoints from GDB's lists, and all
11382 breakpoints had already been removed from the inferior. */
11385 update_global_location_list (int should_insert)
11387 struct breakpoint *b;
11388 struct bp_location **locp, *loc;
11389 struct cleanup *cleanups;
11390 /* Last breakpoint location address that was marked for update. */
11391 CORE_ADDR last_addr = 0;
11392 /* Last breakpoint location program space that was marked for update. */
11393 int last_pspace_num = -1;
11395 /* Used in the duplicates detection below. When iterating over all
11396 bp_locations, points to the first bp_location of a given address.
11397 Breakpoints and watchpoints of different types are never
11398 duplicates of each other. Keep one pointer for each type of
11399 breakpoint/watchpoint, so we only need to loop over all locations
11401 struct bp_location *bp_loc_first; /* breakpoint */
11402 struct bp_location *wp_loc_first; /* hardware watchpoint */
11403 struct bp_location *awp_loc_first; /* access watchpoint */
11404 struct bp_location *rwp_loc_first; /* read watchpoint */
11406 /* Saved former bp_location array which we compare against the newly
11407 built bp_location from the current state of ALL_BREAKPOINTS. */
11408 struct bp_location **old_location, **old_locp;
11409 unsigned old_location_count;
11411 old_location = bp_location;
11412 old_location_count = bp_location_count;
11413 bp_location = NULL;
11414 bp_location_count = 0;
11415 cleanups = make_cleanup (xfree, old_location);
11417 ALL_BREAKPOINTS (b)
11418 for (loc = b->loc; loc; loc = loc->next)
11419 bp_location_count++;
11421 bp_location = xmalloc (sizeof (*bp_location) * bp_location_count);
11422 locp = bp_location;
11423 ALL_BREAKPOINTS (b)
11424 for (loc = b->loc; loc; loc = loc->next)
11426 qsort (bp_location, bp_location_count, sizeof (*bp_location),
11427 bp_location_compare);
11429 bp_location_target_extensions_update ();
11431 /* Identify bp_location instances that are no longer present in the
11432 new list, and therefore should be freed. Note that it's not
11433 necessary that those locations should be removed from inferior --
11434 if there's another location at the same address (previously
11435 marked as duplicate), we don't need to remove/insert the
11438 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11439 and former bp_location array state respectively. */
11441 locp = bp_location;
11442 for (old_locp = old_location; old_locp < old_location + old_location_count;
11445 struct bp_location *old_loc = *old_locp;
11446 struct bp_location **loc2p;
11448 /* Tells if 'old_loc' is found among the new locations. If
11449 not, we have to free it. */
11450 int found_object = 0;
11451 /* Tells if the location should remain inserted in the target. */
11452 int keep_in_target = 0;
11455 /* Skip LOCP entries which will definitely never be needed.
11456 Stop either at or being the one matching OLD_LOC. */
11457 while (locp < bp_location + bp_location_count
11458 && (*locp)->address < old_loc->address)
11462 (loc2p < bp_location + bp_location_count
11463 && (*loc2p)->address == old_loc->address);
11466 /* Check if this is a new/duplicated location or a duplicated
11467 location that had its condition modified. If so, we want to send
11468 its condition to the target if evaluation of conditions is taking
11470 if ((*loc2p)->condition_changed == condition_modified
11471 && (last_addr != old_loc->address
11472 || last_pspace_num != old_loc->pspace->num))
11474 force_breakpoint_reinsertion (*loc2p);
11475 last_pspace_num = old_loc->pspace->num;
11478 if (*loc2p == old_loc)
11482 /* We have already handled this address, update it so that we don't
11483 have to go through updates again. */
11484 last_addr = old_loc->address;
11486 /* Target-side condition evaluation: Handle deleted locations. */
11488 force_breakpoint_reinsertion (old_loc);
11490 /* If this location is no longer present, and inserted, look if
11491 there's maybe a new location at the same address. If so,
11492 mark that one inserted, and don't remove this one. This is
11493 needed so that we don't have a time window where a breakpoint
11494 at certain location is not inserted. */
11496 if (old_loc->inserted)
11498 /* If the location is inserted now, we might have to remove
11501 if (found_object && should_be_inserted (old_loc))
11503 /* The location is still present in the location list,
11504 and still should be inserted. Don't do anything. */
11505 keep_in_target = 1;
11509 /* This location still exists, but it won't be kept in the
11510 target since it may have been disabled. We proceed to
11511 remove its target-side condition. */
11513 /* The location is either no longer present, or got
11514 disabled. See if there's another location at the
11515 same address, in which case we don't need to remove
11516 this one from the target. */
11518 /* OLD_LOC comes from existing struct breakpoint. */
11519 if (breakpoint_address_is_meaningful (old_loc->owner))
11522 (loc2p < bp_location + bp_location_count
11523 && (*loc2p)->address == old_loc->address);
11526 struct bp_location *loc2 = *loc2p;
11528 if (breakpoint_locations_match (loc2, old_loc))
11530 /* Read watchpoint locations are switched to
11531 access watchpoints, if the former are not
11532 supported, but the latter are. */
11533 if (is_hardware_watchpoint (old_loc->owner))
11535 gdb_assert (is_hardware_watchpoint (loc2->owner));
11536 loc2->watchpoint_type = old_loc->watchpoint_type;
11539 /* loc2 is a duplicated location. We need to check
11540 if it should be inserted in case it will be
11542 if (loc2 != old_loc
11543 && unduplicated_should_be_inserted (loc2))
11545 swap_insertion (old_loc, loc2);
11546 keep_in_target = 1;
11554 if (!keep_in_target)
11556 if (remove_breakpoint (old_loc, mark_uninserted))
11558 /* This is just about all we can do. We could keep
11559 this location on the global list, and try to
11560 remove it next time, but there's no particular
11561 reason why we will succeed next time.
11563 Note that at this point, old_loc->owner is still
11564 valid, as delete_breakpoint frees the breakpoint
11565 only after calling us. */
11566 printf_filtered (_("warning: Error removing "
11567 "breakpoint %d\n"),
11568 old_loc->owner->number);
11576 if (removed && non_stop
11577 && breakpoint_address_is_meaningful (old_loc->owner)
11578 && !is_hardware_watchpoint (old_loc->owner))
11580 /* This location was removed from the target. In
11581 non-stop mode, a race condition is possible where
11582 we've removed a breakpoint, but stop events for that
11583 breakpoint are already queued and will arrive later.
11584 We apply an heuristic to be able to distinguish such
11585 SIGTRAPs from other random SIGTRAPs: we keep this
11586 breakpoint location for a bit, and will retire it
11587 after we see some number of events. The theory here
11588 is that reporting of events should, "on the average",
11589 be fair, so after a while we'll see events from all
11590 threads that have anything of interest, and no longer
11591 need to keep this breakpoint location around. We
11592 don't hold locations forever so to reduce chances of
11593 mistaking a non-breakpoint SIGTRAP for a breakpoint
11596 The heuristic failing can be disastrous on
11597 decr_pc_after_break targets.
11599 On decr_pc_after_break targets, like e.g., x86-linux,
11600 if we fail to recognize a late breakpoint SIGTRAP,
11601 because events_till_retirement has reached 0 too
11602 soon, we'll fail to do the PC adjustment, and report
11603 a random SIGTRAP to the user. When the user resumes
11604 the inferior, it will most likely immediately crash
11605 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
11606 corrupted, because of being resumed e.g., in the
11607 middle of a multi-byte instruction, or skipped a
11608 one-byte instruction. This was actually seen happen
11609 on native x86-linux, and should be less rare on
11610 targets that do not support new thread events, like
11611 remote, due to the heuristic depending on
11614 Mistaking a random SIGTRAP for a breakpoint trap
11615 causes similar symptoms (PC adjustment applied when
11616 it shouldn't), but then again, playing with SIGTRAPs
11617 behind the debugger's back is asking for trouble.
11619 Since hardware watchpoint traps are always
11620 distinguishable from other traps, so we don't need to
11621 apply keep hardware watchpoint moribund locations
11622 around. We simply always ignore hardware watchpoint
11623 traps we can no longer explain. */
11625 old_loc->events_till_retirement = 3 * (thread_count () + 1);
11626 old_loc->owner = NULL;
11628 VEC_safe_push (bp_location_p, moribund_locations, old_loc);
11632 old_loc->owner = NULL;
11633 decref_bp_location (&old_loc);
11638 /* Rescan breakpoints at the same address and section, marking the
11639 first one as "first" and any others as "duplicates". This is so
11640 that the bpt instruction is only inserted once. If we have a
11641 permanent breakpoint at the same place as BPT, make that one the
11642 official one, and the rest as duplicates. Permanent breakpoints
11643 are sorted first for the same address.
11645 Do the same for hardware watchpoints, but also considering the
11646 watchpoint's type (regular/access/read) and length. */
11648 bp_loc_first = NULL;
11649 wp_loc_first = NULL;
11650 awp_loc_first = NULL;
11651 rwp_loc_first = NULL;
11652 ALL_BP_LOCATIONS (loc, locp)
11654 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
11656 struct bp_location **loc_first_p;
11659 if (!should_be_inserted (loc)
11660 || !breakpoint_address_is_meaningful (b)
11661 /* Don't detect duplicate for tracepoint locations because they are
11662 never duplicated. See the comments in field `duplicate' of
11663 `struct bp_location'. */
11664 || is_tracepoint (b))
11666 /* Clear the condition modification flag. */
11667 loc->condition_changed = condition_unchanged;
11671 /* Permanent breakpoint should always be inserted. */
11672 if (b->enable_state == bp_permanent && ! loc->inserted)
11673 internal_error (__FILE__, __LINE__,
11674 _("allegedly permanent breakpoint is not "
11675 "actually inserted"));
11677 if (b->type == bp_hardware_watchpoint)
11678 loc_first_p = &wp_loc_first;
11679 else if (b->type == bp_read_watchpoint)
11680 loc_first_p = &rwp_loc_first;
11681 else if (b->type == bp_access_watchpoint)
11682 loc_first_p = &awp_loc_first;
11684 loc_first_p = &bp_loc_first;
11686 if (*loc_first_p == NULL
11687 || (overlay_debugging && loc->section != (*loc_first_p)->section)
11688 || !breakpoint_locations_match (loc, *loc_first_p))
11690 *loc_first_p = loc;
11691 loc->duplicate = 0;
11693 if (is_breakpoint (loc->owner) && loc->condition_changed)
11695 loc->needs_update = 1;
11696 /* Clear the condition modification flag. */
11697 loc->condition_changed = condition_unchanged;
11703 /* This and the above ensure the invariant that the first location
11704 is not duplicated, and is the inserted one.
11705 All following are marked as duplicated, and are not inserted. */
11707 swap_insertion (loc, *loc_first_p);
11708 loc->duplicate = 1;
11710 /* Clear the condition modification flag. */
11711 loc->condition_changed = condition_unchanged;
11713 if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted
11714 && b->enable_state != bp_permanent)
11715 internal_error (__FILE__, __LINE__,
11716 _("another breakpoint was inserted on top of "
11717 "a permanent breakpoint"));
11720 if (breakpoints_always_inserted_mode ()
11721 && (have_live_inferiors ()
11722 || (gdbarch_has_global_breakpoints (target_gdbarch))))
11725 insert_breakpoint_locations ();
11728 /* Though should_insert is false, we may need to update conditions
11729 on the target's side if it is evaluating such conditions. We
11730 only update conditions for locations that are marked
11732 update_inserted_breakpoint_locations ();
11737 download_tracepoint_locations ();
11739 do_cleanups (cleanups);
11743 breakpoint_retire_moribund (void)
11745 struct bp_location *loc;
11748 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
11749 if (--(loc->events_till_retirement) == 0)
11751 decref_bp_location (&loc);
11752 VEC_unordered_remove (bp_location_p, moribund_locations, ix);
11758 update_global_location_list_nothrow (int inserting)
11760 volatile struct gdb_exception e;
11762 TRY_CATCH (e, RETURN_MASK_ERROR)
11763 update_global_location_list (inserting);
11766 /* Clear BKP from a BPS. */
11769 bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt)
11773 for (bs = bps; bs; bs = bs->next)
11774 if (bs->breakpoint_at == bpt)
11776 bs->breakpoint_at = NULL;
11777 bs->old_val = NULL;
11778 /* bs->commands will be freed later. */
11782 /* Callback for iterate_over_threads. */
11784 bpstat_remove_breakpoint_callback (struct thread_info *th, void *data)
11786 struct breakpoint *bpt = data;
11788 bpstat_remove_bp_location (th->control.stop_bpstat, bpt);
11792 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
11796 say_where (struct breakpoint *b)
11798 struct ui_out *uiout = current_uiout;
11799 struct value_print_options opts;
11801 get_user_print_options (&opts);
11803 /* i18n: cagney/2005-02-11: Below needs to be merged into a
11805 if (b->loc == NULL)
11807 printf_filtered (_(" (%s) pending."), b->addr_string);
11811 if (opts.addressprint || b->loc->source_file == NULL)
11813 printf_filtered (" at ");
11814 fputs_filtered (paddress (b->loc->gdbarch, b->loc->address),
11817 if (b->loc->source_file)
11819 /* If there is a single location, we can print the location
11821 if (b->loc->next == NULL)
11822 printf_filtered (": file %s, line %d.",
11823 b->loc->source_file, b->loc->line_number);
11825 /* This is not ideal, but each location may have a
11826 different file name, and this at least reflects the
11827 real situation somewhat. */
11828 printf_filtered (": %s.", b->addr_string);
11833 struct bp_location *loc = b->loc;
11835 for (; loc; loc = loc->next)
11837 printf_filtered (" (%d locations)", n);
11842 /* Default bp_location_ops methods. */
11845 bp_location_dtor (struct bp_location *self)
11847 xfree (self->cond);
11848 if (self->cond_bytecode)
11849 free_agent_expr (self->cond_bytecode);
11850 xfree (self->function_name);
11851 xfree (self->source_file);
11854 static const struct bp_location_ops bp_location_ops =
11859 /* Default breakpoint_ops methods all breakpoint_ops ultimately
11863 base_breakpoint_dtor (struct breakpoint *self)
11865 decref_counted_command_line (&self->commands);
11866 xfree (self->cond_string);
11867 xfree (self->addr_string);
11868 xfree (self->filter);
11869 xfree (self->addr_string_range_end);
11872 static struct bp_location *
11873 base_breakpoint_allocate_location (struct breakpoint *self)
11875 struct bp_location *loc;
11877 loc = XNEW (struct bp_location);
11878 init_bp_location (loc, &bp_location_ops, self);
11883 base_breakpoint_re_set (struct breakpoint *b)
11885 /* Nothing to re-set. */
11888 #define internal_error_pure_virtual_called() \
11889 gdb_assert_not_reached ("pure virtual function called")
11892 base_breakpoint_insert_location (struct bp_location *bl)
11894 internal_error_pure_virtual_called ();
11898 base_breakpoint_remove_location (struct bp_location *bl)
11900 internal_error_pure_virtual_called ();
11904 base_breakpoint_breakpoint_hit (const struct bp_location *bl,
11905 struct address_space *aspace,
11907 const struct target_waitstatus *ws)
11909 internal_error_pure_virtual_called ();
11913 base_breakpoint_check_status (bpstat bs)
11918 /* A "works_in_software_mode" breakpoint_ops method that just internal
11922 base_breakpoint_works_in_software_mode (const struct breakpoint *b)
11924 internal_error_pure_virtual_called ();
11927 /* A "resources_needed" breakpoint_ops method that just internal
11931 base_breakpoint_resources_needed (const struct bp_location *bl)
11933 internal_error_pure_virtual_called ();
11936 static enum print_stop_action
11937 base_breakpoint_print_it (bpstat bs)
11939 internal_error_pure_virtual_called ();
11943 base_breakpoint_print_one_detail (const struct breakpoint *self,
11944 struct ui_out *uiout)
11950 base_breakpoint_print_mention (struct breakpoint *b)
11952 internal_error_pure_virtual_called ();
11956 base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp)
11958 internal_error_pure_virtual_called ();
11962 base_breakpoint_create_sals_from_address (char **arg,
11963 struct linespec_result *canonical,
11964 enum bptype type_wanted,
11968 internal_error_pure_virtual_called ();
11972 base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch,
11973 struct linespec_result *c,
11974 struct linespec_sals *lsal,
11976 enum bptype type_wanted,
11977 enum bpdisp disposition,
11979 int task, int ignore_count,
11980 const struct breakpoint_ops *o,
11981 int from_tty, int enabled,
11984 internal_error_pure_virtual_called ();
11988 base_breakpoint_decode_linespec (struct breakpoint *b, char **s,
11989 struct symtabs_and_lines *sals)
11991 internal_error_pure_virtual_called ();
11994 static struct breakpoint_ops base_breakpoint_ops =
11996 base_breakpoint_dtor,
11997 base_breakpoint_allocate_location,
11998 base_breakpoint_re_set,
11999 base_breakpoint_insert_location,
12000 base_breakpoint_remove_location,
12001 base_breakpoint_breakpoint_hit,
12002 base_breakpoint_check_status,
12003 base_breakpoint_resources_needed,
12004 base_breakpoint_works_in_software_mode,
12005 base_breakpoint_print_it,
12007 base_breakpoint_print_one_detail,
12008 base_breakpoint_print_mention,
12009 base_breakpoint_print_recreate,
12010 base_breakpoint_create_sals_from_address,
12011 base_breakpoint_create_breakpoints_sal,
12012 base_breakpoint_decode_linespec,
12015 /* Default breakpoint_ops methods. */
12018 bkpt_re_set (struct breakpoint *b)
12020 /* FIXME: is this still reachable? */
12021 if (b->addr_string == NULL)
12023 /* Anything without a string can't be re-set. */
12024 delete_breakpoint (b);
12028 breakpoint_re_set_default (b);
12032 bkpt_insert_location (struct bp_location *bl)
12034 if (bl->loc_type == bp_loc_hardware_breakpoint)
12035 return target_insert_hw_breakpoint (bl->gdbarch,
12038 return target_insert_breakpoint (bl->gdbarch,
12043 bkpt_remove_location (struct bp_location *bl)
12045 if (bl->loc_type == bp_loc_hardware_breakpoint)
12046 return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info);
12048 return target_remove_breakpoint (bl->gdbarch, &bl->target_info);
12052 bkpt_breakpoint_hit (const struct bp_location *bl,
12053 struct address_space *aspace, CORE_ADDR bp_addr,
12054 const struct target_waitstatus *ws)
12056 struct breakpoint *b = bl->owner;
12058 if (ws->kind != TARGET_WAITKIND_STOPPED
12059 || ws->value.sig != TARGET_SIGNAL_TRAP)
12062 if (!breakpoint_address_match (bl->pspace->aspace, bl->address,
12066 if (overlay_debugging /* unmapped overlay section */
12067 && section_is_overlay (bl->section)
12068 && !section_is_mapped (bl->section))
12075 bkpt_resources_needed (const struct bp_location *bl)
12077 gdb_assert (bl->owner->type == bp_hardware_breakpoint);
12082 static enum print_stop_action
12083 bkpt_print_it (bpstat bs)
12085 struct breakpoint *b;
12086 const struct bp_location *bl;
12088 struct ui_out *uiout = current_uiout;
12090 gdb_assert (bs->bp_location_at != NULL);
12092 bl = bs->bp_location_at;
12093 b = bs->breakpoint_at;
12095 bp_temp = b->disposition == disp_del;
12096 if (bl->address != bl->requested_address)
12097 breakpoint_adjustment_warning (bl->requested_address,
12100 annotate_breakpoint (b->number);
12102 ui_out_text (uiout, "\nTemporary breakpoint ");
12104 ui_out_text (uiout, "\nBreakpoint ");
12105 if (ui_out_is_mi_like_p (uiout))
12107 ui_out_field_string (uiout, "reason",
12108 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
12109 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
12111 ui_out_field_int (uiout, "bkptno", b->number);
12112 ui_out_text (uiout, ", ");
12114 return PRINT_SRC_AND_LOC;
12118 bkpt_print_mention (struct breakpoint *b)
12120 if (ui_out_is_mi_like_p (current_uiout))
12125 case bp_breakpoint:
12126 case bp_gnu_ifunc_resolver:
12127 if (b->disposition == disp_del)
12128 printf_filtered (_("Temporary breakpoint"));
12130 printf_filtered (_("Breakpoint"));
12131 printf_filtered (_(" %d"), b->number);
12132 if (b->type == bp_gnu_ifunc_resolver)
12133 printf_filtered (_(" at gnu-indirect-function resolver"));
12135 case bp_hardware_breakpoint:
12136 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
12144 bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp)
12146 if (tp->type == bp_breakpoint && tp->disposition == disp_del)
12147 fprintf_unfiltered (fp, "tbreak");
12148 else if (tp->type == bp_breakpoint)
12149 fprintf_unfiltered (fp, "break");
12150 else if (tp->type == bp_hardware_breakpoint
12151 && tp->disposition == disp_del)
12152 fprintf_unfiltered (fp, "thbreak");
12153 else if (tp->type == bp_hardware_breakpoint)
12154 fprintf_unfiltered (fp, "hbreak");
12156 internal_error (__FILE__, __LINE__,
12157 _("unhandled breakpoint type %d"), (int) tp->type);
12159 fprintf_unfiltered (fp, " %s", tp->addr_string);
12160 print_recreate_thread (tp, fp);
12164 bkpt_create_sals_from_address (char **arg,
12165 struct linespec_result *canonical,
12166 enum bptype type_wanted,
12167 char *addr_start, char **copy_arg)
12169 create_sals_from_address_default (arg, canonical, type_wanted,
12170 addr_start, copy_arg);
12174 bkpt_create_breakpoints_sal (struct gdbarch *gdbarch,
12175 struct linespec_result *canonical,
12176 struct linespec_sals *lsal,
12178 enum bptype type_wanted,
12179 enum bpdisp disposition,
12181 int task, int ignore_count,
12182 const struct breakpoint_ops *ops,
12183 int from_tty, int enabled,
12186 create_breakpoints_sal_default (gdbarch, canonical, lsal,
12187 cond_string, type_wanted,
12188 disposition, thread, task,
12189 ignore_count, ops, from_tty,
12190 enabled, internal);
12194 bkpt_decode_linespec (struct breakpoint *b, char **s,
12195 struct symtabs_and_lines *sals)
12197 decode_linespec_default (b, s, sals);
12200 /* Virtual table for internal breakpoints. */
12203 internal_bkpt_re_set (struct breakpoint *b)
12207 /* Delete overlay event and longjmp master breakpoints; they
12208 will be reset later by breakpoint_re_set. */
12209 case bp_overlay_event:
12210 case bp_longjmp_master:
12211 case bp_std_terminate_master:
12212 case bp_exception_master:
12213 delete_breakpoint (b);
12216 /* This breakpoint is special, it's set up when the inferior
12217 starts and we really don't want to touch it. */
12218 case bp_shlib_event:
12220 /* Like bp_shlib_event, this breakpoint type is special. Once
12221 it is set up, we do not want to touch it. */
12222 case bp_thread_event:
12228 internal_bkpt_check_status (bpstat bs)
12230 if (bs->breakpoint_at->type == bp_shlib_event)
12232 /* If requested, stop when the dynamic linker notifies GDB of
12233 events. This allows the user to get control and place
12234 breakpoints in initializer routines for dynamically loaded
12235 objects (among other things). */
12236 bs->stop = stop_on_solib_events;
12237 bs->print = stop_on_solib_events;
12243 static enum print_stop_action
12244 internal_bkpt_print_it (bpstat bs)
12246 struct ui_out *uiout = current_uiout;
12247 struct breakpoint *b;
12249 b = bs->breakpoint_at;
12253 case bp_shlib_event:
12254 /* Did we stop because the user set the stop_on_solib_events
12255 variable? (If so, we report this as a generic, "Stopped due
12256 to shlib event" message.) */
12257 print_solib_event (0);
12260 case bp_thread_event:
12261 /* Not sure how we will get here.
12262 GDB should not stop for these breakpoints. */
12263 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
12266 case bp_overlay_event:
12267 /* By analogy with the thread event, GDB should not stop for these. */
12268 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
12271 case bp_longjmp_master:
12272 /* These should never be enabled. */
12273 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
12276 case bp_std_terminate_master:
12277 /* These should never be enabled. */
12278 printf_filtered (_("std::terminate Master Breakpoint: "
12279 "gdb should not stop!\n"));
12282 case bp_exception_master:
12283 /* These should never be enabled. */
12284 printf_filtered (_("Exception Master Breakpoint: "
12285 "gdb should not stop!\n"));
12289 return PRINT_NOTHING;
12293 internal_bkpt_print_mention (struct breakpoint *b)
12295 /* Nothing to mention. These breakpoints are internal. */
12298 /* Virtual table for momentary breakpoints */
12301 momentary_bkpt_re_set (struct breakpoint *b)
12303 /* Keep temporary breakpoints, which can be encountered when we step
12304 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
12305 Otherwise these should have been blown away via the cleanup chain
12306 or by breakpoint_init_inferior when we rerun the executable. */
12310 momentary_bkpt_check_status (bpstat bs)
12312 /* Nothing. The point of these breakpoints is causing a stop. */
12315 static enum print_stop_action
12316 momentary_bkpt_print_it (bpstat bs)
12318 struct ui_out *uiout = current_uiout;
12320 if (ui_out_is_mi_like_p (uiout))
12322 struct breakpoint *b = bs->breakpoint_at;
12327 ui_out_field_string
12329 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED));
12333 ui_out_field_string
12335 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED));
12340 return PRINT_UNKNOWN;
12344 momentary_bkpt_print_mention (struct breakpoint *b)
12346 /* Nothing to mention. These breakpoints are internal. */
12349 /* The breakpoint_ops structure to be used in tracepoints. */
12352 tracepoint_re_set (struct breakpoint *b)
12354 breakpoint_re_set_default (b);
12358 tracepoint_breakpoint_hit (const struct bp_location *bl,
12359 struct address_space *aspace, CORE_ADDR bp_addr,
12360 const struct target_waitstatus *ws)
12362 /* By definition, the inferior does not report stops at
12368 tracepoint_print_one_detail (const struct breakpoint *self,
12369 struct ui_out *uiout)
12371 struct tracepoint *tp = (struct tracepoint *) self;
12372 if (tp->static_trace_marker_id)
12374 gdb_assert (self->type == bp_static_tracepoint);
12376 ui_out_text (uiout, "\tmarker id is ");
12377 ui_out_field_string (uiout, "static-tracepoint-marker-string-id",
12378 tp->static_trace_marker_id);
12379 ui_out_text (uiout, "\n");
12384 tracepoint_print_mention (struct breakpoint *b)
12386 if (ui_out_is_mi_like_p (current_uiout))
12391 case bp_tracepoint:
12392 printf_filtered (_("Tracepoint"));
12393 printf_filtered (_(" %d"), b->number);
12395 case bp_fast_tracepoint:
12396 printf_filtered (_("Fast tracepoint"));
12397 printf_filtered (_(" %d"), b->number);
12399 case bp_static_tracepoint:
12400 printf_filtered (_("Static tracepoint"));
12401 printf_filtered (_(" %d"), b->number);
12404 internal_error (__FILE__, __LINE__,
12405 _("unhandled tracepoint type %d"), (int) b->type);
12412 tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp)
12414 struct tracepoint *tp = (struct tracepoint *) self;
12416 if (self->type == bp_fast_tracepoint)
12417 fprintf_unfiltered (fp, "ftrace");
12418 if (self->type == bp_static_tracepoint)
12419 fprintf_unfiltered (fp, "strace");
12420 else if (self->type == bp_tracepoint)
12421 fprintf_unfiltered (fp, "trace");
12423 internal_error (__FILE__, __LINE__,
12424 _("unhandled tracepoint type %d"), (int) self->type);
12426 fprintf_unfiltered (fp, " %s", self->addr_string);
12427 print_recreate_thread (self, fp);
12429 if (tp->pass_count)
12430 fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count);
12434 tracepoint_create_sals_from_address (char **arg,
12435 struct linespec_result *canonical,
12436 enum bptype type_wanted,
12437 char *addr_start, char **copy_arg)
12439 create_sals_from_address_default (arg, canonical, type_wanted,
12440 addr_start, copy_arg);
12444 tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch,
12445 struct linespec_result *canonical,
12446 struct linespec_sals *lsal,
12448 enum bptype type_wanted,
12449 enum bpdisp disposition,
12451 int task, int ignore_count,
12452 const struct breakpoint_ops *ops,
12453 int from_tty, int enabled,
12456 create_breakpoints_sal_default (gdbarch, canonical, lsal,
12457 cond_string, type_wanted,
12458 disposition, thread, task,
12459 ignore_count, ops, from_tty,
12460 enabled, internal);
12464 tracepoint_decode_linespec (struct breakpoint *b, char **s,
12465 struct symtabs_and_lines *sals)
12467 decode_linespec_default (b, s, sals);
12470 struct breakpoint_ops tracepoint_breakpoint_ops;
12472 /* The breakpoint_ops structure to be used on static tracepoints with
12476 strace_marker_create_sals_from_address (char **arg,
12477 struct linespec_result *canonical,
12478 enum bptype type_wanted,
12479 char *addr_start, char **copy_arg)
12481 struct linespec_sals lsal;
12483 lsal.sals = decode_static_tracepoint_spec (arg);
12485 *copy_arg = savestring (addr_start, *arg - addr_start);
12487 canonical->addr_string = xstrdup (*copy_arg);
12488 lsal.canonical = xstrdup (*copy_arg);
12489 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
12493 strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch,
12494 struct linespec_result *canonical,
12495 struct linespec_sals *lsal,
12497 enum bptype type_wanted,
12498 enum bpdisp disposition,
12500 int task, int ignore_count,
12501 const struct breakpoint_ops *ops,
12502 int from_tty, int enabled,
12507 /* If the user is creating a static tracepoint by marker id
12508 (strace -m MARKER_ID), then store the sals index, so that
12509 breakpoint_re_set can try to match up which of the newly
12510 found markers corresponds to this one, and, don't try to
12511 expand multiple locations for each sal, given than SALS
12512 already should contain all sals for MARKER_ID. */
12514 for (i = 0; i < lsal->sals.nelts; ++i)
12516 struct symtabs_and_lines expanded;
12517 struct tracepoint *tp;
12518 struct cleanup *old_chain;
12521 expanded.nelts = 1;
12522 expanded.sals = &lsal->sals.sals[i];
12524 addr_string = xstrdup (canonical->addr_string);
12525 old_chain = make_cleanup (xfree, addr_string);
12527 tp = XCNEW (struct tracepoint);
12528 init_breakpoint_sal (&tp->base, gdbarch, expanded,
12530 cond_string, type_wanted, disposition,
12531 thread, task, ignore_count, ops,
12532 from_tty, enabled, internal,
12533 canonical->special_display);
12534 /* Given that its possible to have multiple markers with
12535 the same string id, if the user is creating a static
12536 tracepoint by marker id ("strace -m MARKER_ID"), then
12537 store the sals index, so that breakpoint_re_set can
12538 try to match up which of the newly found markers
12539 corresponds to this one */
12540 tp->static_trace_marker_id_idx = i;
12542 install_breakpoint (internal, &tp->base, 0);
12544 discard_cleanups (old_chain);
12549 strace_marker_decode_linespec (struct breakpoint *b, char **s,
12550 struct symtabs_and_lines *sals)
12552 struct tracepoint *tp = (struct tracepoint *) b;
12554 *sals = decode_static_tracepoint_spec (s);
12555 if (sals->nelts > tp->static_trace_marker_id_idx)
12557 sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx];
12561 error (_("marker %s not found"), tp->static_trace_marker_id);
12564 static struct breakpoint_ops strace_marker_breakpoint_ops;
12567 strace_marker_p (struct breakpoint *b)
12569 return b->ops == &strace_marker_breakpoint_ops;
12572 /* Delete a breakpoint and clean up all traces of it in the data
12576 delete_breakpoint (struct breakpoint *bpt)
12578 struct breakpoint *b;
12580 gdb_assert (bpt != NULL);
12582 /* Has this bp already been deleted? This can happen because
12583 multiple lists can hold pointers to bp's. bpstat lists are
12586 One example of this happening is a watchpoint's scope bp. When
12587 the scope bp triggers, we notice that the watchpoint is out of
12588 scope, and delete it. We also delete its scope bp. But the
12589 scope bp is marked "auto-deleting", and is already on a bpstat.
12590 That bpstat is then checked for auto-deleting bp's, which are
12593 A real solution to this problem might involve reference counts in
12594 bp's, and/or giving them pointers back to their referencing
12595 bpstat's, and teaching delete_breakpoint to only free a bp's
12596 storage when no more references were extent. A cheaper bandaid
12598 if (bpt->type == bp_none)
12601 /* At least avoid this stale reference until the reference counting
12602 of breakpoints gets resolved. */
12603 if (bpt->related_breakpoint != bpt)
12605 struct breakpoint *related;
12606 struct watchpoint *w;
12608 if (bpt->type == bp_watchpoint_scope)
12609 w = (struct watchpoint *) bpt->related_breakpoint;
12610 else if (bpt->related_breakpoint->type == bp_watchpoint_scope)
12611 w = (struct watchpoint *) bpt;
12615 watchpoint_del_at_next_stop (w);
12617 /* Unlink bpt from the bpt->related_breakpoint ring. */
12618 for (related = bpt; related->related_breakpoint != bpt;
12619 related = related->related_breakpoint);
12620 related->related_breakpoint = bpt->related_breakpoint;
12621 bpt->related_breakpoint = bpt;
12624 /* watch_command_1 creates a watchpoint but only sets its number if
12625 update_watchpoint succeeds in creating its bp_locations. If there's
12626 a problem in that process, we'll be asked to delete the half-created
12627 watchpoint. In that case, don't announce the deletion. */
12629 observer_notify_breakpoint_deleted (bpt);
12631 if (breakpoint_chain == bpt)
12632 breakpoint_chain = bpt->next;
12634 ALL_BREAKPOINTS (b)
12635 if (b->next == bpt)
12637 b->next = bpt->next;
12641 /* Be sure no bpstat's are pointing at the breakpoint after it's
12643 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
12644 in all threads for now. Note that we cannot just remove bpstats
12645 pointing at bpt from the stop_bpstat list entirely, as breakpoint
12646 commands are associated with the bpstat; if we remove it here,
12647 then the later call to bpstat_do_actions (&stop_bpstat); in
12648 event-top.c won't do anything, and temporary breakpoints with
12649 commands won't work. */
12651 iterate_over_threads (bpstat_remove_breakpoint_callback, bpt);
12653 /* Now that breakpoint is removed from breakpoint list, update the
12654 global location list. This will remove locations that used to
12655 belong to this breakpoint. Do this before freeing the breakpoint
12656 itself, since remove_breakpoint looks at location's owner. It
12657 might be better design to have location completely
12658 self-contained, but it's not the case now. */
12659 update_global_location_list (0);
12661 bpt->ops->dtor (bpt);
12662 /* On the chance that someone will soon try again to delete this
12663 same bp, we mark it as deleted before freeing its storage. */
12664 bpt->type = bp_none;
12669 do_delete_breakpoint_cleanup (void *b)
12671 delete_breakpoint (b);
12675 make_cleanup_delete_breakpoint (struct breakpoint *b)
12677 return make_cleanup (do_delete_breakpoint_cleanup, b);
12680 /* Iterator function to call a user-provided callback function once
12681 for each of B and its related breakpoints. */
12684 iterate_over_related_breakpoints (struct breakpoint *b,
12685 void (*function) (struct breakpoint *,
12689 struct breakpoint *related;
12694 struct breakpoint *next;
12696 /* FUNCTION may delete RELATED. */
12697 next = related->related_breakpoint;
12699 if (next == related)
12701 /* RELATED is the last ring entry. */
12702 function (related, data);
12704 /* FUNCTION may have deleted it, so we'd never reach back to
12705 B. There's nothing left to do anyway, so just break
12710 function (related, data);
12714 while (related != b);
12718 do_delete_breakpoint (struct breakpoint *b, void *ignore)
12720 delete_breakpoint (b);
12723 /* A callback for map_breakpoint_numbers that calls
12724 delete_breakpoint. */
12727 do_map_delete_breakpoint (struct breakpoint *b, void *ignore)
12729 iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL);
12733 delete_command (char *arg, int from_tty)
12735 struct breakpoint *b, *b_tmp;
12741 int breaks_to_delete = 0;
12743 /* Delete all breakpoints if no argument. Do not delete
12744 internal breakpoints, these have to be deleted with an
12745 explicit breakpoint number argument. */
12746 ALL_BREAKPOINTS (b)
12747 if (user_breakpoint_p (b))
12749 breaks_to_delete = 1;
12753 /* Ask user only if there are some breakpoints to delete. */
12755 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
12757 ALL_BREAKPOINTS_SAFE (b, b_tmp)
12758 if (user_breakpoint_p (b))
12759 delete_breakpoint (b);
12763 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
12767 all_locations_are_pending (struct bp_location *loc)
12769 for (; loc; loc = loc->next)
12770 if (!loc->shlib_disabled
12771 && !loc->pspace->executing_startup)
12776 /* Subroutine of update_breakpoint_locations to simplify it.
12777 Return non-zero if multiple fns in list LOC have the same name.
12778 Null names are ignored. */
12781 ambiguous_names_p (struct bp_location *loc)
12783 struct bp_location *l;
12784 htab_t htab = htab_create_alloc (13, htab_hash_string,
12785 (int (*) (const void *,
12786 const void *)) streq,
12787 NULL, xcalloc, xfree);
12789 for (l = loc; l != NULL; l = l->next)
12792 const char *name = l->function_name;
12794 /* Allow for some names to be NULL, ignore them. */
12798 slot = (const char **) htab_find_slot (htab, (const void *) name,
12800 /* NOTE: We can assume slot != NULL here because xcalloc never
12804 htab_delete (htab);
12810 htab_delete (htab);
12814 /* When symbols change, it probably means the sources changed as well,
12815 and it might mean the static tracepoint markers are no longer at
12816 the same address or line numbers they used to be at last we
12817 checked. Losing your static tracepoints whenever you rebuild is
12818 undesirable. This function tries to resync/rematch gdb static
12819 tracepoints with the markers on the target, for static tracepoints
12820 that have not been set by marker id. Static tracepoint that have
12821 been set by marker id are reset by marker id in breakpoint_re_set.
12824 1) For a tracepoint set at a specific address, look for a marker at
12825 the old PC. If one is found there, assume to be the same marker.
12826 If the name / string id of the marker found is different from the
12827 previous known name, assume that means the user renamed the marker
12828 in the sources, and output a warning.
12830 2) For a tracepoint set at a given line number, look for a marker
12831 at the new address of the old line number. If one is found there,
12832 assume to be the same marker. If the name / string id of the
12833 marker found is different from the previous known name, assume that
12834 means the user renamed the marker in the sources, and output a
12837 3) If a marker is no longer found at the same address or line, it
12838 may mean the marker no longer exists. But it may also just mean
12839 the code changed a bit. Maybe the user added a few lines of code
12840 that made the marker move up or down (in line number terms). Ask
12841 the target for info about the marker with the string id as we knew
12842 it. If found, update line number and address in the matching
12843 static tracepoint. This will get confused if there's more than one
12844 marker with the same ID (possible in UST, although unadvised
12845 precisely because it confuses tools). */
12847 static struct symtab_and_line
12848 update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal)
12850 struct tracepoint *tp = (struct tracepoint *) b;
12851 struct static_tracepoint_marker marker;
12857 find_line_pc (sal.symtab, sal.line, &pc);
12859 if (target_static_tracepoint_marker_at (pc, &marker))
12861 if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0)
12862 warning (_("static tracepoint %d changed probed marker from %s to %s"),
12864 tp->static_trace_marker_id, marker.str_id);
12866 xfree (tp->static_trace_marker_id);
12867 tp->static_trace_marker_id = xstrdup (marker.str_id);
12868 release_static_tracepoint_marker (&marker);
12873 /* Old marker wasn't found on target at lineno. Try looking it up
12875 if (!sal.explicit_pc
12877 && sal.symtab != NULL
12878 && tp->static_trace_marker_id != NULL)
12880 VEC(static_tracepoint_marker_p) *markers;
12883 = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id);
12885 if (!VEC_empty(static_tracepoint_marker_p, markers))
12887 struct symtab_and_line sal2;
12888 struct symbol *sym;
12889 struct static_tracepoint_marker *tpmarker;
12890 struct ui_out *uiout = current_uiout;
12892 tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0);
12894 xfree (tp->static_trace_marker_id);
12895 tp->static_trace_marker_id = xstrdup (tpmarker->str_id);
12897 warning (_("marker for static tracepoint %d (%s) not "
12898 "found at previous line number"),
12899 b->number, tp->static_trace_marker_id);
12903 sal2.pc = tpmarker->address;
12905 sal2 = find_pc_line (tpmarker->address, 0);
12906 sym = find_pc_sect_function (tpmarker->address, NULL);
12907 ui_out_text (uiout, "Now in ");
12910 ui_out_field_string (uiout, "func",
12911 SYMBOL_PRINT_NAME (sym));
12912 ui_out_text (uiout, " at ");
12914 ui_out_field_string (uiout, "file", sal2.symtab->filename);
12915 ui_out_text (uiout, ":");
12917 if (ui_out_is_mi_like_p (uiout))
12919 char *fullname = symtab_to_fullname (sal2.symtab);
12922 ui_out_field_string (uiout, "fullname", fullname);
12925 ui_out_field_int (uiout, "line", sal2.line);
12926 ui_out_text (uiout, "\n");
12928 b->loc->line_number = sal2.line;
12930 xfree (b->loc->source_file);
12932 b->loc->source_file = xstrdup (sal2.symtab->filename);
12934 b->loc->source_file = NULL;
12936 xfree (b->addr_string);
12937 b->addr_string = xstrprintf ("%s:%d",
12938 sal2.symtab->filename,
12939 b->loc->line_number);
12941 /* Might be nice to check if function changed, and warn if
12944 release_static_tracepoint_marker (tpmarker);
12950 /* Returns 1 iff locations A and B are sufficiently same that
12951 we don't need to report breakpoint as changed. */
12954 locations_are_equal (struct bp_location *a, struct bp_location *b)
12958 if (a->address != b->address)
12961 if (a->shlib_disabled != b->shlib_disabled)
12964 if (a->enabled != b->enabled)
12971 if ((a == NULL) != (b == NULL))
12977 /* Create new breakpoint locations for B (a hardware or software breakpoint)
12978 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
12979 a ranged breakpoint. */
12982 update_breakpoint_locations (struct breakpoint *b,
12983 struct symtabs_and_lines sals,
12984 struct symtabs_and_lines sals_end)
12987 struct bp_location *existing_locations = b->loc;
12989 if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1))
12991 /* Ranged breakpoints have only one start location and one end
12993 b->enable_state = bp_disabled;
12994 update_global_location_list (1);
12995 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
12996 "multiple locations found\n"),
13001 /* If there's no new locations, and all existing locations are
13002 pending, don't do anything. This optimizes the common case where
13003 all locations are in the same shared library, that was unloaded.
13004 We'd like to retain the location, so that when the library is
13005 loaded again, we don't loose the enabled/disabled status of the
13006 individual locations. */
13007 if (all_locations_are_pending (existing_locations) && sals.nelts == 0)
13012 for (i = 0; i < sals.nelts; ++i)
13014 struct bp_location *new_loc;
13016 switch_to_program_space_and_thread (sals.sals[i].pspace);
13018 new_loc = add_location_to_breakpoint (b, &(sals.sals[i]));
13020 /* Reparse conditions, they might contain references to the
13022 if (b->cond_string != NULL)
13025 volatile struct gdb_exception e;
13027 s = b->cond_string;
13028 TRY_CATCH (e, RETURN_MASK_ERROR)
13030 new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc),
13035 warning (_("failed to reevaluate condition "
13036 "for breakpoint %d: %s"),
13037 b->number, e.message);
13038 new_loc->enabled = 0;
13042 if (sals_end.nelts)
13044 CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]);
13046 new_loc->length = end - sals.sals[0].pc + 1;
13050 /* Update locations of permanent breakpoints. */
13051 if (b->enable_state == bp_permanent)
13052 make_breakpoint_permanent (b);
13054 /* If possible, carry over 'disable' status from existing
13057 struct bp_location *e = existing_locations;
13058 /* If there are multiple breakpoints with the same function name,
13059 e.g. for inline functions, comparing function names won't work.
13060 Instead compare pc addresses; this is just a heuristic as things
13061 may have moved, but in practice it gives the correct answer
13062 often enough until a better solution is found. */
13063 int have_ambiguous_names = ambiguous_names_p (b->loc);
13065 for (; e; e = e->next)
13067 if (!e->enabled && e->function_name)
13069 struct bp_location *l = b->loc;
13070 if (have_ambiguous_names)
13072 for (; l; l = l->next)
13073 if (breakpoint_locations_match (e, l))
13081 for (; l; l = l->next)
13082 if (l->function_name
13083 && strcmp (e->function_name, l->function_name) == 0)
13093 if (!locations_are_equal (existing_locations, b->loc))
13094 observer_notify_breakpoint_modified (b);
13096 update_global_location_list (1);
13099 /* Find the SaL locations corresponding to the given ADDR_STRING.
13100 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
13102 static struct symtabs_and_lines
13103 addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found)
13106 struct symtabs_and_lines sals = {0};
13107 volatile struct gdb_exception e;
13109 gdb_assert (b->ops != NULL);
13112 TRY_CATCH (e, RETURN_MASK_ERROR)
13114 b->ops->decode_linespec (b, &s, &sals);
13118 int not_found_and_ok = 0;
13119 /* For pending breakpoints, it's expected that parsing will
13120 fail until the right shared library is loaded. User has
13121 already told to create pending breakpoints and don't need
13122 extra messages. If breakpoint is in bp_shlib_disabled
13123 state, then user already saw the message about that
13124 breakpoint being disabled, and don't want to see more
13126 if (e.error == NOT_FOUND_ERROR
13127 && (b->condition_not_parsed
13128 || (b->loc && b->loc->shlib_disabled)
13129 || (b->loc && b->loc->pspace->executing_startup)
13130 || b->enable_state == bp_disabled))
13131 not_found_and_ok = 1;
13133 if (!not_found_and_ok)
13135 /* We surely don't want to warn about the same breakpoint
13136 10 times. One solution, implemented here, is disable
13137 the breakpoint on error. Another solution would be to
13138 have separate 'warning emitted' flag. Since this
13139 happens only when a binary has changed, I don't know
13140 which approach is better. */
13141 b->enable_state = bp_disabled;
13142 throw_exception (e);
13146 if (e.reason == 0 || e.error != NOT_FOUND_ERROR)
13150 for (i = 0; i < sals.nelts; ++i)
13151 resolve_sal_pc (&sals.sals[i]);
13152 if (b->condition_not_parsed && s && s[0])
13154 char *cond_string = 0;
13158 find_condition_and_thread (s, sals.sals[0].pc,
13159 &cond_string, &thread, &task);
13161 b->cond_string = cond_string;
13162 b->thread = thread;
13164 b->condition_not_parsed = 0;
13167 if (b->type == bp_static_tracepoint && !strace_marker_p (b))
13168 sals.sals[0] = update_static_tracepoint (b, sals.sals[0]);
13178 /* The default re_set method, for typical hardware or software
13179 breakpoints. Reevaluate the breakpoint and recreate its
13183 breakpoint_re_set_default (struct breakpoint *b)
13186 struct symtabs_and_lines sals, sals_end;
13187 struct symtabs_and_lines expanded = {0};
13188 struct symtabs_and_lines expanded_end = {0};
13190 sals = addr_string_to_sals (b, b->addr_string, &found);
13193 make_cleanup (xfree, sals.sals);
13197 if (b->addr_string_range_end)
13199 sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found);
13202 make_cleanup (xfree, sals_end.sals);
13203 expanded_end = sals_end;
13207 update_breakpoint_locations (b, expanded, expanded_end);
13210 /* Default method for creating SALs from an address string. It basically
13211 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
13214 create_sals_from_address_default (char **arg,
13215 struct linespec_result *canonical,
13216 enum bptype type_wanted,
13217 char *addr_start, char **copy_arg)
13219 parse_breakpoint_sals (arg, canonical);
13222 /* Call create_breakpoints_sal for the given arguments. This is the default
13223 function for the `create_breakpoints_sal' method of
13227 create_breakpoints_sal_default (struct gdbarch *gdbarch,
13228 struct linespec_result *canonical,
13229 struct linespec_sals *lsal,
13231 enum bptype type_wanted,
13232 enum bpdisp disposition,
13234 int task, int ignore_count,
13235 const struct breakpoint_ops *ops,
13236 int from_tty, int enabled,
13239 create_breakpoints_sal (gdbarch, canonical, cond_string,
13240 type_wanted, disposition,
13241 thread, task, ignore_count, ops, from_tty,
13242 enabled, internal);
13245 /* Decode the line represented by S by calling decode_line_full. This is the
13246 default function for the `decode_linespec' method of breakpoint_ops. */
13249 decode_linespec_default (struct breakpoint *b, char **s,
13250 struct symtabs_and_lines *sals)
13252 struct linespec_result canonical;
13254 init_linespec_result (&canonical);
13255 decode_line_full (s, DECODE_LINE_FUNFIRSTLINE,
13256 (struct symtab *) NULL, 0,
13257 &canonical, multiple_symbols_all,
13260 /* We should get 0 or 1 resulting SALs. */
13261 gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2);
13263 if (VEC_length (linespec_sals, canonical.sals) > 0)
13265 struct linespec_sals *lsal;
13267 lsal = VEC_index (linespec_sals, canonical.sals, 0);
13268 *sals = lsal->sals;
13269 /* Arrange it so the destructor does not free the
13271 lsal->sals.sals = NULL;
13274 destroy_linespec_result (&canonical);
13277 /* Prepare the global context for a re-set of breakpoint B. */
13279 static struct cleanup *
13280 prepare_re_set_context (struct breakpoint *b)
13282 struct cleanup *cleanups;
13284 input_radix = b->input_radix;
13285 cleanups = save_current_space_and_thread ();
13286 if (b->pspace != NULL)
13287 switch_to_program_space_and_thread (b->pspace);
13288 set_language (b->language);
13293 /* Reset a breakpoint given it's struct breakpoint * BINT.
13294 The value we return ends up being the return value from catch_errors.
13295 Unused in this case. */
13298 breakpoint_re_set_one (void *bint)
13300 /* Get past catch_errs. */
13301 struct breakpoint *b = (struct breakpoint *) bint;
13302 struct cleanup *cleanups;
13304 cleanups = prepare_re_set_context (b);
13305 b->ops->re_set (b);
13306 do_cleanups (cleanups);
13310 /* Re-set all breakpoints after symbols have been re-loaded. */
13312 breakpoint_re_set (void)
13314 struct breakpoint *b, *b_tmp;
13315 enum language save_language;
13316 int save_input_radix;
13317 struct cleanup *old_chain;
13319 save_language = current_language->la_language;
13320 save_input_radix = input_radix;
13321 old_chain = save_current_program_space ();
13323 ALL_BREAKPOINTS_SAFE (b, b_tmp)
13325 /* Format possible error msg. */
13326 char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
13328 struct cleanup *cleanups = make_cleanup (xfree, message);
13329 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
13330 do_cleanups (cleanups);
13332 set_language (save_language);
13333 input_radix = save_input_radix;
13335 jit_breakpoint_re_set ();
13337 do_cleanups (old_chain);
13339 create_overlay_event_breakpoint ();
13340 create_longjmp_master_breakpoint ();
13341 create_std_terminate_master_breakpoint ();
13342 create_exception_master_breakpoint ();
13344 /* While we're at it, reset the skip list too. */
13348 /* Reset the thread number of this breakpoint:
13350 - If the breakpoint is for all threads, leave it as-is.
13351 - Else, reset it to the current thread for inferior_ptid. */
13353 breakpoint_re_set_thread (struct breakpoint *b)
13355 if (b->thread != -1)
13357 if (in_thread_list (inferior_ptid))
13358 b->thread = pid_to_thread_id (inferior_ptid);
13360 /* We're being called after following a fork. The new fork is
13361 selected as current, and unless this was a vfork will have a
13362 different program space from the original thread. Reset that
13364 b->loc->pspace = current_program_space;
13368 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
13369 If from_tty is nonzero, it prints a message to that effect,
13370 which ends with a period (no newline). */
13373 set_ignore_count (int bptnum, int count, int from_tty)
13375 struct breakpoint *b;
13380 ALL_BREAKPOINTS (b)
13381 if (b->number == bptnum)
13383 if (is_tracepoint (b))
13385 if (from_tty && count != 0)
13386 printf_filtered (_("Ignore count ignored for tracepoint %d."),
13391 b->ignore_count = count;
13395 printf_filtered (_("Will stop next time "
13396 "breakpoint %d is reached."),
13398 else if (count == 1)
13399 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
13402 printf_filtered (_("Will ignore next %d "
13403 "crossings of breakpoint %d."),
13406 breakpoints_changed ();
13407 observer_notify_breakpoint_modified (b);
13411 error (_("No breakpoint number %d."), bptnum);
13414 /* Command to set ignore-count of breakpoint N to COUNT. */
13417 ignore_command (char *args, int from_tty)
13423 error_no_arg (_("a breakpoint number"));
13425 num = get_number (&p);
13427 error (_("bad breakpoint number: '%s'"), args);
13429 error (_("Second argument (specified ignore-count) is missing."));
13431 set_ignore_count (num,
13432 longest_to_int (value_as_long (parse_and_eval (p))),
13435 printf_filtered ("\n");
13438 /* Call FUNCTION on each of the breakpoints
13439 whose numbers are given in ARGS. */
13442 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *,
13447 struct breakpoint *b, *tmp;
13449 struct get_number_or_range_state state;
13452 error_no_arg (_("one or more breakpoint numbers"));
13454 init_number_or_range (&state, args);
13456 while (!state.finished)
13458 char *p = state.string;
13462 num = get_number_or_range (&state);
13465 warning (_("bad breakpoint number at or near '%s'"), p);
13469 ALL_BREAKPOINTS_SAFE (b, tmp)
13470 if (b->number == num)
13473 function (b, data);
13477 printf_unfiltered (_("No breakpoint number %d.\n"), num);
13482 static struct bp_location *
13483 find_location_by_number (char *number)
13485 char *dot = strchr (number, '.');
13489 struct breakpoint *b;
13490 struct bp_location *loc;
13495 bp_num = get_number (&p1);
13497 error (_("Bad breakpoint number '%s'"), number);
13499 ALL_BREAKPOINTS (b)
13500 if (b->number == bp_num)
13505 if (!b || b->number != bp_num)
13506 error (_("Bad breakpoint number '%s'"), number);
13509 loc_num = get_number (&p1);
13511 error (_("Bad breakpoint location number '%s'"), number);
13515 for (;loc_num && loc; --loc_num, loc = loc->next)
13518 error (_("Bad breakpoint location number '%s'"), dot+1);
13524 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
13525 If from_tty is nonzero, it prints a message to that effect,
13526 which ends with a period (no newline). */
13529 disable_breakpoint (struct breakpoint *bpt)
13531 /* Never disable a watchpoint scope breakpoint; we want to
13532 hit them when we leave scope so we can delete both the
13533 watchpoint and its scope breakpoint at that time. */
13534 if (bpt->type == bp_watchpoint_scope)
13537 /* You can't disable permanent breakpoints. */
13538 if (bpt->enable_state == bp_permanent)
13541 bpt->enable_state = bp_disabled;
13543 /* Mark breakpoint locations modified. */
13544 mark_breakpoint_modified (bpt);
13546 if (target_supports_enable_disable_tracepoint ()
13547 && current_trace_status ()->running && is_tracepoint (bpt))
13549 struct bp_location *location;
13551 for (location = bpt->loc; location; location = location->next)
13552 target_disable_tracepoint (location);
13555 update_global_location_list (0);
13557 observer_notify_breakpoint_modified (bpt);
13560 /* A callback for iterate_over_related_breakpoints. */
13563 do_disable_breakpoint (struct breakpoint *b, void *ignore)
13565 disable_breakpoint (b);
13568 /* A callback for map_breakpoint_numbers that calls
13569 disable_breakpoint. */
13572 do_map_disable_breakpoint (struct breakpoint *b, void *ignore)
13574 iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL);
13578 disable_command (char *args, int from_tty)
13582 struct breakpoint *bpt;
13584 ALL_BREAKPOINTS (bpt)
13585 if (user_breakpoint_p (bpt))
13586 disable_breakpoint (bpt);
13588 else if (strchr (args, '.'))
13590 struct bp_location *loc = find_location_by_number (args);
13596 mark_breakpoint_location_modified (loc);
13598 if (target_supports_enable_disable_tracepoint ()
13599 && current_trace_status ()->running && loc->owner
13600 && is_tracepoint (loc->owner))
13601 target_disable_tracepoint (loc);
13603 update_global_location_list (0);
13606 map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL);
13610 enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition,
13613 int target_resources_ok;
13615 if (bpt->type == bp_hardware_breakpoint)
13618 i = hw_breakpoint_used_count ();
13619 target_resources_ok =
13620 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
13622 if (target_resources_ok == 0)
13623 error (_("No hardware breakpoint support in the target."));
13624 else if (target_resources_ok < 0)
13625 error (_("Hardware breakpoints used exceeds limit."));
13628 if (is_watchpoint (bpt))
13630 /* Initialize it just to avoid a GCC false warning. */
13631 enum enable_state orig_enable_state = 0;
13632 volatile struct gdb_exception e;
13634 TRY_CATCH (e, RETURN_MASK_ALL)
13636 struct watchpoint *w = (struct watchpoint *) bpt;
13638 orig_enable_state = bpt->enable_state;
13639 bpt->enable_state = bp_enabled;
13640 update_watchpoint (w, 1 /* reparse */);
13644 bpt->enable_state = orig_enable_state;
13645 exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
13651 if (bpt->enable_state != bp_permanent)
13652 bpt->enable_state = bp_enabled;
13654 bpt->enable_state = bp_enabled;
13656 /* Mark breakpoint locations modified. */
13657 mark_breakpoint_modified (bpt);
13659 if (target_supports_enable_disable_tracepoint ()
13660 && current_trace_status ()->running && is_tracepoint (bpt))
13662 struct bp_location *location;
13664 for (location = bpt->loc; location; location = location->next)
13665 target_enable_tracepoint (location);
13668 bpt->disposition = disposition;
13669 bpt->enable_count = count;
13670 update_global_location_list (1);
13671 breakpoints_changed ();
13673 observer_notify_breakpoint_modified (bpt);
13678 enable_breakpoint (struct breakpoint *bpt)
13680 enable_breakpoint_disp (bpt, bpt->disposition, 0);
13684 do_enable_breakpoint (struct breakpoint *bpt, void *arg)
13686 enable_breakpoint (bpt);
13689 /* A callback for map_breakpoint_numbers that calls
13690 enable_breakpoint. */
13693 do_map_enable_breakpoint (struct breakpoint *b, void *ignore)
13695 iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL);
13698 /* The enable command enables the specified breakpoints (or all defined
13699 breakpoints) so they once again become (or continue to be) effective
13700 in stopping the inferior. */
13703 enable_command (char *args, int from_tty)
13707 struct breakpoint *bpt;
13709 ALL_BREAKPOINTS (bpt)
13710 if (user_breakpoint_p (bpt))
13711 enable_breakpoint (bpt);
13713 else if (strchr (args, '.'))
13715 struct bp_location *loc = find_location_by_number (args);
13721 mark_breakpoint_location_modified (loc);
13723 if (target_supports_enable_disable_tracepoint ()
13724 && current_trace_status ()->running && loc->owner
13725 && is_tracepoint (loc->owner))
13726 target_enable_tracepoint (loc);
13728 update_global_location_list (1);
13731 map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL);
13734 /* This struct packages up disposition data for application to multiple
13744 do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg)
13746 struct disp_data disp_data = *(struct disp_data *) arg;
13748 enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count);
13752 do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore)
13754 struct disp_data disp = { disp_disable, 1 };
13756 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
13760 enable_once_command (char *args, int from_tty)
13762 map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL);
13766 do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr)
13768 struct disp_data disp = { disp_disable, *(int *) countptr };
13770 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
13774 enable_count_command (char *args, int from_tty)
13776 int count = get_number (&args);
13778 map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count);
13782 do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore)
13784 struct disp_data disp = { disp_del, 1 };
13786 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
13790 enable_delete_command (char *args, int from_tty)
13792 map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL);
13796 set_breakpoint_cmd (char *args, int from_tty)
13801 show_breakpoint_cmd (char *args, int from_tty)
13805 /* Invalidate last known value of any hardware watchpoint if
13806 the memory which that value represents has been written to by
13810 invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len,
13811 const bfd_byte *data)
13813 struct breakpoint *bp;
13815 ALL_BREAKPOINTS (bp)
13816 if (bp->enable_state == bp_enabled
13817 && bp->type == bp_hardware_watchpoint)
13819 struct watchpoint *wp = (struct watchpoint *) bp;
13821 if (wp->val_valid && wp->val)
13823 struct bp_location *loc;
13825 for (loc = bp->loc; loc != NULL; loc = loc->next)
13826 if (loc->loc_type == bp_loc_hardware_watchpoint
13827 && loc->address + loc->length > addr
13828 && addr + len > loc->address)
13830 value_free (wp->val);
13838 /* Use the last displayed codepoint's values, or nothing
13839 if they aren't valid. */
13841 struct symtabs_and_lines
13842 decode_line_spec_1 (char *string, int flags)
13844 struct symtabs_and_lines sals;
13847 error (_("Empty line specification."));
13848 if (last_displayed_sal_is_valid ())
13849 sals = decode_line_1 (&string, flags,
13850 get_last_displayed_symtab (),
13851 get_last_displayed_line ());
13853 sals = decode_line_1 (&string, flags, (struct symtab *) NULL, 0);
13855 error (_("Junk at end of line specification: %s"), string);
13859 /* Create and insert a raw software breakpoint at PC. Return an
13860 identifier, which should be used to remove the breakpoint later.
13861 In general, places which call this should be using something on the
13862 breakpoint chain instead; this function should be eliminated
13866 deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch,
13867 struct address_space *aspace, CORE_ADDR pc)
13869 struct bp_target_info *bp_tgt;
13871 bp_tgt = XZALLOC (struct bp_target_info);
13873 bp_tgt->placed_address_space = aspace;
13874 bp_tgt->placed_address = pc;
13876 if (target_insert_breakpoint (gdbarch, bp_tgt) != 0)
13878 /* Could not insert the breakpoint. */
13886 /* Remove a breakpoint BP inserted by
13887 deprecated_insert_raw_breakpoint. */
13890 deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp)
13892 struct bp_target_info *bp_tgt = bp;
13895 ret = target_remove_breakpoint (gdbarch, bp_tgt);
13901 /* One (or perhaps two) breakpoints used for software single
13904 static void *single_step_breakpoints[2];
13905 static struct gdbarch *single_step_gdbarch[2];
13907 /* Create and insert a breakpoint for software single step. */
13910 insert_single_step_breakpoint (struct gdbarch *gdbarch,
13911 struct address_space *aspace,
13916 if (single_step_breakpoints[0] == NULL)
13918 bpt_p = &single_step_breakpoints[0];
13919 single_step_gdbarch[0] = gdbarch;
13923 gdb_assert (single_step_breakpoints[1] == NULL);
13924 bpt_p = &single_step_breakpoints[1];
13925 single_step_gdbarch[1] = gdbarch;
13928 /* NOTE drow/2006-04-11: A future improvement to this function would
13929 be to only create the breakpoints once, and actually put them on
13930 the breakpoint chain. That would let us use set_raw_breakpoint.
13931 We could adjust the addresses each time they were needed. Doing
13932 this requires corresponding changes elsewhere where single step
13933 breakpoints are handled, however. So, for now, we use this. */
13935 *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc);
13936 if (*bpt_p == NULL)
13937 error (_("Could not insert single-step breakpoint at %s"),
13938 paddress (gdbarch, next_pc));
13941 /* Check if the breakpoints used for software single stepping
13942 were inserted or not. */
13945 single_step_breakpoints_inserted (void)
13947 return (single_step_breakpoints[0] != NULL
13948 || single_step_breakpoints[1] != NULL);
13951 /* Remove and delete any breakpoints used for software single step. */
13954 remove_single_step_breakpoints (void)
13956 gdb_assert (single_step_breakpoints[0] != NULL);
13958 /* See insert_single_step_breakpoint for more about this deprecated
13960 deprecated_remove_raw_breakpoint (single_step_gdbarch[0],
13961 single_step_breakpoints[0]);
13962 single_step_gdbarch[0] = NULL;
13963 single_step_breakpoints[0] = NULL;
13965 if (single_step_breakpoints[1] != NULL)
13967 deprecated_remove_raw_breakpoint (single_step_gdbarch[1],
13968 single_step_breakpoints[1]);
13969 single_step_gdbarch[1] = NULL;
13970 single_step_breakpoints[1] = NULL;
13974 /* Delete software single step breakpoints without removing them from
13975 the inferior. This is intended to be used if the inferior's address
13976 space where they were inserted is already gone, e.g. after exit or
13980 cancel_single_step_breakpoints (void)
13984 for (i = 0; i < 2; i++)
13985 if (single_step_breakpoints[i])
13987 xfree (single_step_breakpoints[i]);
13988 single_step_breakpoints[i] = NULL;
13989 single_step_gdbarch[i] = NULL;
13993 /* Detach software single-step breakpoints from INFERIOR_PTID without
13997 detach_single_step_breakpoints (void)
14001 for (i = 0; i < 2; i++)
14002 if (single_step_breakpoints[i])
14003 target_remove_breakpoint (single_step_gdbarch[i],
14004 single_step_breakpoints[i]);
14007 /* Check whether a software single-step breakpoint is inserted at
14011 single_step_breakpoint_inserted_here_p (struct address_space *aspace,
14016 for (i = 0; i < 2; i++)
14018 struct bp_target_info *bp_tgt = single_step_breakpoints[i];
14020 && breakpoint_address_match (bp_tgt->placed_address_space,
14021 bp_tgt->placed_address,
14029 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
14030 non-zero otherwise. */
14032 is_syscall_catchpoint_enabled (struct breakpoint *bp)
14034 if (syscall_catchpoint_p (bp)
14035 && bp->enable_state != bp_disabled
14036 && bp->enable_state != bp_call_disabled)
14043 catch_syscall_enabled (void)
14045 struct inferior *inf = current_inferior ();
14047 return inf->total_syscalls_count != 0;
14051 catching_syscall_number (int syscall_number)
14053 struct breakpoint *bp;
14055 ALL_BREAKPOINTS (bp)
14056 if (is_syscall_catchpoint_enabled (bp))
14058 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp;
14060 if (c->syscalls_to_be_caught)
14064 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
14066 if (syscall_number == iter)
14076 /* Complete syscall names. Used by "catch syscall". */
14078 catch_syscall_completer (struct cmd_list_element *cmd,
14079 char *text, char *word)
14081 const char **list = get_syscall_names ();
14083 = (list == NULL) ? NULL : complete_on_enum (list, text, word);
14089 /* Tracepoint-specific operations. */
14091 /* Set tracepoint count to NUM. */
14093 set_tracepoint_count (int num)
14095 tracepoint_count = num;
14096 set_internalvar_integer (lookup_internalvar ("tpnum"), num);
14100 trace_command (char *arg, int from_tty)
14102 if (create_breakpoint (get_current_arch (),
14104 NULL, 0, 1 /* parse arg */,
14106 bp_tracepoint /* type_wanted */,
14107 0 /* Ignore count */,
14108 pending_break_support,
14109 &tracepoint_breakpoint_ops,
14113 set_tracepoint_count (breakpoint_count);
14117 ftrace_command (char *arg, int from_tty)
14119 if (create_breakpoint (get_current_arch (),
14121 NULL, 0, 1 /* parse arg */,
14123 bp_fast_tracepoint /* type_wanted */,
14124 0 /* Ignore count */,
14125 pending_break_support,
14126 &tracepoint_breakpoint_ops,
14130 set_tracepoint_count (breakpoint_count);
14133 /* strace command implementation. Creates a static tracepoint. */
14136 strace_command (char *arg, int from_tty)
14138 struct breakpoint_ops *ops;
14140 /* Decide if we are dealing with a static tracepoint marker (`-m'),
14141 or with a normal static tracepoint. */
14142 if (arg && strncmp (arg, "-m", 2) == 0 && isspace (arg[2]))
14143 ops = &strace_marker_breakpoint_ops;
14145 ops = &tracepoint_breakpoint_ops;
14147 if (create_breakpoint (get_current_arch (),
14149 NULL, 0, 1 /* parse arg */,
14151 bp_static_tracepoint /* type_wanted */,
14152 0 /* Ignore count */,
14153 pending_break_support,
14158 set_tracepoint_count (breakpoint_count);
14161 /* Set up a fake reader function that gets command lines from a linked
14162 list that was acquired during tracepoint uploading. */
14164 static struct uploaded_tp *this_utp;
14165 static int next_cmd;
14168 read_uploaded_action (void)
14172 VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt);
14179 /* Given information about a tracepoint as recorded on a target (which
14180 can be either a live system or a trace file), attempt to create an
14181 equivalent GDB tracepoint. This is not a reliable process, since
14182 the target does not necessarily have all the information used when
14183 the tracepoint was originally defined. */
14185 struct tracepoint *
14186 create_tracepoint_from_upload (struct uploaded_tp *utp)
14188 char *addr_str, small_buf[100];
14189 struct tracepoint *tp;
14191 if (utp->at_string)
14192 addr_str = utp->at_string;
14195 /* In the absence of a source location, fall back to raw
14196 address. Since there is no way to confirm that the address
14197 means the same thing as when the trace was started, warn the
14199 warning (_("Uploaded tracepoint %d has no "
14200 "source location, using raw address"),
14202 sprintf (small_buf, "*%s", hex_string (utp->addr));
14203 addr_str = small_buf;
14206 /* There's not much we can do with a sequence of bytecodes. */
14207 if (utp->cond && !utp->cond_string)
14208 warning (_("Uploaded tracepoint %d condition "
14209 "has no source form, ignoring it"),
14212 if (!create_breakpoint (get_current_arch (),
14214 utp->cond_string, -1, 0 /* parse cond/thread */,
14216 utp->type /* type_wanted */,
14217 0 /* Ignore count */,
14218 pending_break_support,
14219 &tracepoint_breakpoint_ops,
14221 utp->enabled /* enabled */,
14225 set_tracepoint_count (breakpoint_count);
14227 /* Get the tracepoint we just created. */
14228 tp = get_tracepoint (tracepoint_count);
14229 gdb_assert (tp != NULL);
14233 sprintf (small_buf, "%d %d", utp->pass, tp->base.number);
14235 trace_pass_command (small_buf, 0);
14238 /* If we have uploaded versions of the original commands, set up a
14239 special-purpose "reader" function and call the usual command line
14240 reader, then pass the result to the breakpoint command-setting
14242 if (!VEC_empty (char_ptr, utp->cmd_strings))
14244 struct command_line *cmd_list;
14249 cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL);
14251 breakpoint_set_commands (&tp->base, cmd_list);
14253 else if (!VEC_empty (char_ptr, utp->actions)
14254 || !VEC_empty (char_ptr, utp->step_actions))
14255 warning (_("Uploaded tracepoint %d actions "
14256 "have no source form, ignoring them"),
14259 /* Copy any status information that might be available. */
14260 tp->base.hit_count = utp->hit_count;
14261 tp->traceframe_usage = utp->traceframe_usage;
14266 /* Print information on tracepoint number TPNUM_EXP, or all if
14270 tracepoints_info (char *args, int from_tty)
14272 struct ui_out *uiout = current_uiout;
14275 num_printed = breakpoint_1 (args, 0, is_tracepoint);
14277 if (num_printed == 0)
14279 if (args == NULL || *args == '\0')
14280 ui_out_message (uiout, 0, "No tracepoints.\n");
14282 ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args);
14285 default_collect_info ();
14288 /* The 'enable trace' command enables tracepoints.
14289 Not supported by all targets. */
14291 enable_trace_command (char *args, int from_tty)
14293 enable_command (args, from_tty);
14296 /* The 'disable trace' command disables tracepoints.
14297 Not supported by all targets. */
14299 disable_trace_command (char *args, int from_tty)
14301 disable_command (args, from_tty);
14304 /* Remove a tracepoint (or all if no argument). */
14306 delete_trace_command (char *arg, int from_tty)
14308 struct breakpoint *b, *b_tmp;
14314 int breaks_to_delete = 0;
14316 /* Delete all breakpoints if no argument.
14317 Do not delete internal or call-dummy breakpoints, these
14318 have to be deleted with an explicit breakpoint number
14320 ALL_TRACEPOINTS (b)
14321 if (is_tracepoint (b) && user_breakpoint_p (b))
14323 breaks_to_delete = 1;
14327 /* Ask user only if there are some breakpoints to delete. */
14329 || (breaks_to_delete && query (_("Delete all tracepoints? "))))
14331 ALL_BREAKPOINTS_SAFE (b, b_tmp)
14332 if (is_tracepoint (b) && user_breakpoint_p (b))
14333 delete_breakpoint (b);
14337 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
14340 /* Helper function for trace_pass_command. */
14343 trace_pass_set_count (struct tracepoint *tp, int count, int from_tty)
14345 tp->pass_count = count;
14346 observer_notify_tracepoint_modified (tp->base.number);
14348 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
14349 tp->base.number, count);
14352 /* Set passcount for tracepoint.
14354 First command argument is passcount, second is tracepoint number.
14355 If tracepoint number omitted, apply to most recently defined.
14356 Also accepts special argument "all". */
14359 trace_pass_command (char *args, int from_tty)
14361 struct tracepoint *t1;
14362 unsigned int count;
14364 if (args == 0 || *args == 0)
14365 error (_("passcount command requires an "
14366 "argument (count + optional TP num)"));
14368 count = strtoul (args, &args, 10); /* Count comes first, then TP num. */
14370 while (*args && isspace ((int) *args))
14373 if (*args && strncasecmp (args, "all", 3) == 0)
14375 struct breakpoint *b;
14377 args += 3; /* Skip special argument "all". */
14379 error (_("Junk at end of arguments."));
14381 ALL_TRACEPOINTS (b)
14383 t1 = (struct tracepoint *) b;
14384 trace_pass_set_count (t1, count, from_tty);
14387 else if (*args == '\0')
14389 t1 = get_tracepoint_by_number (&args, NULL, 1);
14391 trace_pass_set_count (t1, count, from_tty);
14395 struct get_number_or_range_state state;
14397 init_number_or_range (&state, args);
14398 while (!state.finished)
14400 t1 = get_tracepoint_by_number (&args, &state, 1);
14402 trace_pass_set_count (t1, count, from_tty);
14407 struct tracepoint *
14408 get_tracepoint (int num)
14410 struct breakpoint *t;
14412 ALL_TRACEPOINTS (t)
14413 if (t->number == num)
14414 return (struct tracepoint *) t;
14419 /* Find the tracepoint with the given target-side number (which may be
14420 different from the tracepoint number after disconnecting and
14423 struct tracepoint *
14424 get_tracepoint_by_number_on_target (int num)
14426 struct breakpoint *b;
14428 ALL_TRACEPOINTS (b)
14430 struct tracepoint *t = (struct tracepoint *) b;
14432 if (t->number_on_target == num)
14439 /* Utility: parse a tracepoint number and look it up in the list.
14440 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
14441 If OPTIONAL_P is true, then if the argument is missing, the most
14442 recent tracepoint (tracepoint_count) is returned. */
14443 struct tracepoint *
14444 get_tracepoint_by_number (char **arg,
14445 struct get_number_or_range_state *state,
14448 extern int tracepoint_count;
14449 struct breakpoint *t;
14451 char *instring = arg == NULL ? NULL : *arg;
14455 gdb_assert (!state->finished);
14456 tpnum = get_number_or_range (state);
14458 else if (arg == NULL || *arg == NULL || ! **arg)
14461 tpnum = tracepoint_count;
14463 error_no_arg (_("tracepoint number"));
14466 tpnum = get_number (arg);
14470 if (instring && *instring)
14471 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
14474 printf_filtered (_("Tracepoint argument missing "
14475 "and no previous tracepoint\n"));
14479 ALL_TRACEPOINTS (t)
14480 if (t->number == tpnum)
14482 return (struct tracepoint *) t;
14485 printf_unfiltered ("No tracepoint number %d.\n", tpnum);
14490 print_recreate_thread (struct breakpoint *b, struct ui_file *fp)
14492 if (b->thread != -1)
14493 fprintf_unfiltered (fp, " thread %d", b->thread);
14496 fprintf_unfiltered (fp, " task %d", b->task);
14498 fprintf_unfiltered (fp, "\n");
14501 /* Save information on user settable breakpoints (watchpoints, etc) to
14502 a new script file named FILENAME. If FILTER is non-NULL, call it
14503 on each breakpoint and only include the ones for which it returns
14507 save_breakpoints (char *filename, int from_tty,
14508 int (*filter) (const struct breakpoint *))
14510 struct breakpoint *tp;
14513 struct cleanup *cleanup;
14514 struct ui_file *fp;
14515 int extra_trace_bits = 0;
14517 if (filename == 0 || *filename == 0)
14518 error (_("Argument required (file name in which to save)"));
14520 /* See if we have anything to save. */
14521 ALL_BREAKPOINTS (tp)
14523 /* Skip internal and momentary breakpoints. */
14524 if (!user_breakpoint_p (tp))
14527 /* If we have a filter, only save the breakpoints it accepts. */
14528 if (filter && !filter (tp))
14533 if (is_tracepoint (tp))
14535 extra_trace_bits = 1;
14537 /* We can stop searching. */
14544 warning (_("Nothing to save."));
14548 pathname = tilde_expand (filename);
14549 cleanup = make_cleanup (xfree, pathname);
14550 fp = gdb_fopen (pathname, "w");
14552 error (_("Unable to open file '%s' for saving (%s)"),
14553 filename, safe_strerror (errno));
14554 make_cleanup_ui_file_delete (fp);
14556 if (extra_trace_bits)
14557 save_trace_state_variables (fp);
14559 ALL_BREAKPOINTS (tp)
14561 /* Skip internal and momentary breakpoints. */
14562 if (!user_breakpoint_p (tp))
14565 /* If we have a filter, only save the breakpoints it accepts. */
14566 if (filter && !filter (tp))
14569 tp->ops->print_recreate (tp, fp);
14571 /* Note, we can't rely on tp->number for anything, as we can't
14572 assume the recreated breakpoint numbers will match. Use $bpnum
14575 if (tp->cond_string)
14576 fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string);
14578 if (tp->ignore_count)
14579 fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count);
14583 volatile struct gdb_exception ex;
14585 fprintf_unfiltered (fp, " commands\n");
14587 ui_out_redirect (current_uiout, fp);
14588 TRY_CATCH (ex, RETURN_MASK_ALL)
14590 print_command_lines (current_uiout, tp->commands->commands, 2);
14592 ui_out_redirect (current_uiout, NULL);
14595 throw_exception (ex);
14597 fprintf_unfiltered (fp, " end\n");
14600 if (tp->enable_state == bp_disabled)
14601 fprintf_unfiltered (fp, "disable\n");
14603 /* If this is a multi-location breakpoint, check if the locations
14604 should be individually disabled. Watchpoint locations are
14605 special, and not user visible. */
14606 if (!is_watchpoint (tp) && tp->loc && tp->loc->next)
14608 struct bp_location *loc;
14611 for (loc = tp->loc; loc != NULL; loc = loc->next, n++)
14613 fprintf_unfiltered (fp, "disable $bpnum.%d\n", n);
14617 if (extra_trace_bits && *default_collect)
14618 fprintf_unfiltered (fp, "set default-collect %s\n", default_collect);
14620 do_cleanups (cleanup);
14622 printf_filtered (_("Saved to file '%s'.\n"), filename);
14625 /* The `save breakpoints' command. */
14628 save_breakpoints_command (char *args, int from_tty)
14630 save_breakpoints (args, from_tty, NULL);
14633 /* The `save tracepoints' command. */
14636 save_tracepoints_command (char *args, int from_tty)
14638 save_breakpoints (args, from_tty, is_tracepoint);
14641 /* Create a vector of all tracepoints. */
14643 VEC(breakpoint_p) *
14644 all_tracepoints (void)
14646 VEC(breakpoint_p) *tp_vec = 0;
14647 struct breakpoint *tp;
14649 ALL_TRACEPOINTS (tp)
14651 VEC_safe_push (breakpoint_p, tp_vec, tp);
14658 /* This help string is used for the break, hbreak, tbreak and thbreak
14659 commands. It is defined as a macro to prevent duplication.
14660 COMMAND should be a string constant containing the name of the
14662 #define BREAK_ARGS_HELP(command) \
14663 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
14664 LOCATION may be a line number, function name, or \"*\" and an address.\n\
14665 If a line number is specified, break at start of code for that line.\n\
14666 If a function is specified, break at start of code for that function.\n\
14667 If an address is specified, break at that exact address.\n\
14668 With no LOCATION, uses current execution address of the selected\n\
14669 stack frame. This is useful for breaking on return to a stack frame.\n\
14671 THREADNUM is the number from \"info threads\".\n\
14672 CONDITION is a boolean expression.\n\
14674 Multiple breakpoints at one place are permitted, and useful if their\n\
14675 conditions are different.\n\
14677 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
14679 /* List of subcommands for "catch". */
14680 static struct cmd_list_element *catch_cmdlist;
14682 /* List of subcommands for "tcatch". */
14683 static struct cmd_list_element *tcatch_cmdlist;
14686 add_catch_command (char *name, char *docstring,
14687 void (*sfunc) (char *args, int from_tty,
14688 struct cmd_list_element *command),
14689 char **(*completer) (struct cmd_list_element *cmd,
14690 char *text, char *word),
14691 void *user_data_catch,
14692 void *user_data_tcatch)
14694 struct cmd_list_element *command;
14696 command = add_cmd (name, class_breakpoint, NULL, docstring,
14698 set_cmd_sfunc (command, sfunc);
14699 set_cmd_context (command, user_data_catch);
14700 set_cmd_completer (command, completer);
14702 command = add_cmd (name, class_breakpoint, NULL, docstring,
14704 set_cmd_sfunc (command, sfunc);
14705 set_cmd_context (command, user_data_tcatch);
14706 set_cmd_completer (command, completer);
14710 clear_syscall_counts (struct inferior *inf)
14712 inf->total_syscalls_count = 0;
14713 inf->any_syscall_count = 0;
14714 VEC_free (int, inf->syscalls_counts);
14718 save_command (char *arg, int from_tty)
14720 printf_unfiltered (_("\"save\" must be followed by "
14721 "the name of a save subcommand.\n"));
14722 help_list (save_cmdlist, "save ", -1, gdb_stdout);
14725 struct breakpoint *
14726 iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *),
14729 struct breakpoint *b, *b_tmp;
14731 ALL_BREAKPOINTS_SAFE (b, b_tmp)
14733 if ((*callback) (b, data))
14740 /* Zero if any of the breakpoint's locations could be a location where
14741 functions have been inlined, nonzero otherwise. */
14744 is_non_inline_function (struct breakpoint *b)
14746 /* The shared library event breakpoint is set on the address of a
14747 non-inline function. */
14748 if (b->type == bp_shlib_event)
14754 /* Nonzero if the specified PC cannot be a location where functions
14755 have been inlined. */
14758 pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc,
14759 const struct target_waitstatus *ws)
14761 struct breakpoint *b;
14762 struct bp_location *bl;
14764 ALL_BREAKPOINTS (b)
14766 if (!is_non_inline_function (b))
14769 for (bl = b->loc; bl != NULL; bl = bl->next)
14771 if (!bl->shlib_disabled
14772 && bpstat_check_location (bl, aspace, pc, ws))
14781 initialize_breakpoint_ops (void)
14783 static int initialized = 0;
14785 struct breakpoint_ops *ops;
14791 /* The breakpoint_ops structure to be inherit by all kinds of
14792 breakpoints (real breakpoints, i.e., user "break" breakpoints,
14793 internal and momentary breakpoints, etc.). */
14794 ops = &bkpt_base_breakpoint_ops;
14795 *ops = base_breakpoint_ops;
14796 ops->re_set = bkpt_re_set;
14797 ops->insert_location = bkpt_insert_location;
14798 ops->remove_location = bkpt_remove_location;
14799 ops->breakpoint_hit = bkpt_breakpoint_hit;
14800 ops->create_sals_from_address = bkpt_create_sals_from_address;
14801 ops->create_breakpoints_sal = bkpt_create_breakpoints_sal;
14802 ops->decode_linespec = bkpt_decode_linespec;
14804 /* The breakpoint_ops structure to be used in regular breakpoints. */
14805 ops = &bkpt_breakpoint_ops;
14806 *ops = bkpt_base_breakpoint_ops;
14807 ops->re_set = bkpt_re_set;
14808 ops->resources_needed = bkpt_resources_needed;
14809 ops->print_it = bkpt_print_it;
14810 ops->print_mention = bkpt_print_mention;
14811 ops->print_recreate = bkpt_print_recreate;
14813 /* Ranged breakpoints. */
14814 ops = &ranged_breakpoint_ops;
14815 *ops = bkpt_breakpoint_ops;
14816 ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint;
14817 ops->resources_needed = resources_needed_ranged_breakpoint;
14818 ops->print_it = print_it_ranged_breakpoint;
14819 ops->print_one = print_one_ranged_breakpoint;
14820 ops->print_one_detail = print_one_detail_ranged_breakpoint;
14821 ops->print_mention = print_mention_ranged_breakpoint;
14822 ops->print_recreate = print_recreate_ranged_breakpoint;
14824 /* Internal breakpoints. */
14825 ops = &internal_breakpoint_ops;
14826 *ops = bkpt_base_breakpoint_ops;
14827 ops->re_set = internal_bkpt_re_set;
14828 ops->check_status = internal_bkpt_check_status;
14829 ops->print_it = internal_bkpt_print_it;
14830 ops->print_mention = internal_bkpt_print_mention;
14832 /* Momentary breakpoints. */
14833 ops = &momentary_breakpoint_ops;
14834 *ops = bkpt_base_breakpoint_ops;
14835 ops->re_set = momentary_bkpt_re_set;
14836 ops->check_status = momentary_bkpt_check_status;
14837 ops->print_it = momentary_bkpt_print_it;
14838 ops->print_mention = momentary_bkpt_print_mention;
14840 /* GNU v3 exception catchpoints. */
14841 ops = &gnu_v3_exception_catchpoint_ops;
14842 *ops = bkpt_breakpoint_ops;
14843 ops->print_it = print_it_exception_catchpoint;
14844 ops->print_one = print_one_exception_catchpoint;
14845 ops->print_mention = print_mention_exception_catchpoint;
14846 ops->print_recreate = print_recreate_exception_catchpoint;
14849 ops = &watchpoint_breakpoint_ops;
14850 *ops = base_breakpoint_ops;
14851 ops->dtor = dtor_watchpoint;
14852 ops->re_set = re_set_watchpoint;
14853 ops->insert_location = insert_watchpoint;
14854 ops->remove_location = remove_watchpoint;
14855 ops->breakpoint_hit = breakpoint_hit_watchpoint;
14856 ops->check_status = check_status_watchpoint;
14857 ops->resources_needed = resources_needed_watchpoint;
14858 ops->works_in_software_mode = works_in_software_mode_watchpoint;
14859 ops->print_it = print_it_watchpoint;
14860 ops->print_mention = print_mention_watchpoint;
14861 ops->print_recreate = print_recreate_watchpoint;
14863 /* Masked watchpoints. */
14864 ops = &masked_watchpoint_breakpoint_ops;
14865 *ops = watchpoint_breakpoint_ops;
14866 ops->insert_location = insert_masked_watchpoint;
14867 ops->remove_location = remove_masked_watchpoint;
14868 ops->resources_needed = resources_needed_masked_watchpoint;
14869 ops->works_in_software_mode = works_in_software_mode_masked_watchpoint;
14870 ops->print_it = print_it_masked_watchpoint;
14871 ops->print_one_detail = print_one_detail_masked_watchpoint;
14872 ops->print_mention = print_mention_masked_watchpoint;
14873 ops->print_recreate = print_recreate_masked_watchpoint;
14876 ops = &tracepoint_breakpoint_ops;
14877 *ops = base_breakpoint_ops;
14878 ops->re_set = tracepoint_re_set;
14879 ops->breakpoint_hit = tracepoint_breakpoint_hit;
14880 ops->print_one_detail = tracepoint_print_one_detail;
14881 ops->print_mention = tracepoint_print_mention;
14882 ops->print_recreate = tracepoint_print_recreate;
14883 ops->create_sals_from_address = tracepoint_create_sals_from_address;
14884 ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal;
14885 ops->decode_linespec = tracepoint_decode_linespec;
14887 /* Static tracepoints with marker (`-m'). */
14888 ops = &strace_marker_breakpoint_ops;
14889 *ops = tracepoint_breakpoint_ops;
14890 ops->create_sals_from_address = strace_marker_create_sals_from_address;
14891 ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal;
14892 ops->decode_linespec = strace_marker_decode_linespec;
14894 /* Fork catchpoints. */
14895 ops = &catch_fork_breakpoint_ops;
14896 *ops = base_breakpoint_ops;
14897 ops->insert_location = insert_catch_fork;
14898 ops->remove_location = remove_catch_fork;
14899 ops->breakpoint_hit = breakpoint_hit_catch_fork;
14900 ops->print_it = print_it_catch_fork;
14901 ops->print_one = print_one_catch_fork;
14902 ops->print_mention = print_mention_catch_fork;
14903 ops->print_recreate = print_recreate_catch_fork;
14905 /* Vfork catchpoints. */
14906 ops = &catch_vfork_breakpoint_ops;
14907 *ops = base_breakpoint_ops;
14908 ops->insert_location = insert_catch_vfork;
14909 ops->remove_location = remove_catch_vfork;
14910 ops->breakpoint_hit = breakpoint_hit_catch_vfork;
14911 ops->print_it = print_it_catch_vfork;
14912 ops->print_one = print_one_catch_vfork;
14913 ops->print_mention = print_mention_catch_vfork;
14914 ops->print_recreate = print_recreate_catch_vfork;
14916 /* Exec catchpoints. */
14917 ops = &catch_exec_breakpoint_ops;
14918 *ops = base_breakpoint_ops;
14919 ops->dtor = dtor_catch_exec;
14920 ops->insert_location = insert_catch_exec;
14921 ops->remove_location = remove_catch_exec;
14922 ops->breakpoint_hit = breakpoint_hit_catch_exec;
14923 ops->print_it = print_it_catch_exec;
14924 ops->print_one = print_one_catch_exec;
14925 ops->print_mention = print_mention_catch_exec;
14926 ops->print_recreate = print_recreate_catch_exec;
14928 /* Syscall catchpoints. */
14929 ops = &catch_syscall_breakpoint_ops;
14930 *ops = base_breakpoint_ops;
14931 ops->dtor = dtor_catch_syscall;
14932 ops->insert_location = insert_catch_syscall;
14933 ops->remove_location = remove_catch_syscall;
14934 ops->breakpoint_hit = breakpoint_hit_catch_syscall;
14935 ops->print_it = print_it_catch_syscall;
14936 ops->print_one = print_one_catch_syscall;
14937 ops->print_mention = print_mention_catch_syscall;
14938 ops->print_recreate = print_recreate_catch_syscall;
14940 /* Solib-related catchpoints. */
14941 ops = &catch_solib_breakpoint_ops;
14942 *ops = base_breakpoint_ops;
14943 ops->dtor = dtor_catch_solib;
14944 ops->insert_location = insert_catch_solib;
14945 ops->remove_location = remove_catch_solib;
14946 ops->breakpoint_hit = breakpoint_hit_catch_solib;
14947 ops->check_status = check_status_catch_solib;
14948 ops->print_it = print_it_catch_solib;
14949 ops->print_one = print_one_catch_solib;
14950 ops->print_mention = print_mention_catch_solib;
14951 ops->print_recreate = print_recreate_catch_solib;
14955 _initialize_breakpoint (void)
14957 struct cmd_list_element *c;
14959 initialize_breakpoint_ops ();
14961 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
14962 observer_attach_inferior_exit (clear_syscall_counts);
14963 observer_attach_memory_changed (invalidate_bp_value_on_memory_change);
14965 breakpoint_objfile_key = register_objfile_data ();
14967 breakpoint_chain = 0;
14968 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
14969 before a breakpoint is set. */
14970 breakpoint_count = 0;
14972 tracepoint_count = 0;
14974 add_com ("ignore", class_breakpoint, ignore_command, _("\
14975 Set ignore-count of breakpoint number N to COUNT.\n\
14976 Usage is `ignore N COUNT'."));
14978 add_com_alias ("bc", "ignore", class_breakpoint, 1);
14980 add_com ("commands", class_breakpoint, commands_command, _("\
14981 Set commands to be executed when a breakpoint is hit.\n\
14982 Give breakpoint number as argument after \"commands\".\n\
14983 With no argument, the targeted breakpoint is the last one set.\n\
14984 The commands themselves follow starting on the next line.\n\
14985 Type a line containing \"end\" to indicate the end of them.\n\
14986 Give \"silent\" as the first line to make the breakpoint silent;\n\
14987 then no output is printed when it is hit, except what the commands print."));
14989 add_com ("condition", class_breakpoint, condition_command, _("\
14990 Specify breakpoint number N to break only if COND is true.\n\
14991 Usage is `condition N COND', where N is an integer and COND is an\n\
14992 expression to be evaluated whenever breakpoint N is reached."));
14994 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
14995 Set a temporary breakpoint.\n\
14996 Like \"break\" except the breakpoint is only temporary,\n\
14997 so it will be deleted when hit. Equivalent to \"break\" followed\n\
14998 by using \"enable delete\" on the breakpoint number.\n\
15000 BREAK_ARGS_HELP ("tbreak")));
15001 set_cmd_completer (c, location_completer);
15003 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
15004 Set a hardware assisted breakpoint.\n\
15005 Like \"break\" except the breakpoint requires hardware support,\n\
15006 some target hardware may not have this support.\n\
15008 BREAK_ARGS_HELP ("hbreak")));
15009 set_cmd_completer (c, location_completer);
15011 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
15012 Set a temporary hardware assisted breakpoint.\n\
15013 Like \"hbreak\" except the breakpoint is only temporary,\n\
15014 so it will be deleted when hit.\n\
15016 BREAK_ARGS_HELP ("thbreak")));
15017 set_cmd_completer (c, location_completer);
15019 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
15020 Enable some breakpoints.\n\
15021 Give breakpoint numbers (separated by spaces) as arguments.\n\
15022 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15023 This is used to cancel the effect of the \"disable\" command.\n\
15024 With a subcommand you can enable temporarily."),
15025 &enablelist, "enable ", 1, &cmdlist);
15027 add_com ("ab", class_breakpoint, enable_command, _("\
15028 Enable some breakpoints.\n\
15029 Give breakpoint numbers (separated by spaces) as arguments.\n\
15030 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15031 This is used to cancel the effect of the \"disable\" command.\n\
15032 With a subcommand you can enable temporarily."));
15034 add_com_alias ("en", "enable", class_breakpoint, 1);
15036 add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
15037 Enable some breakpoints.\n\
15038 Give breakpoint numbers (separated by spaces) as arguments.\n\
15039 This is used to cancel the effect of the \"disable\" command.\n\
15040 May be abbreviated to simply \"enable\".\n"),
15041 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
15043 add_cmd ("once", no_class, enable_once_command, _("\
15044 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15045 If a breakpoint is hit while enabled in this fashion, it becomes 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 ("count", no_class, enable_count_command, _("\
15054 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15055 If a breakpoint is hit while enabled in this fashion,\n\
15056 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15059 add_cmd ("delete", no_class, enable_delete_command, _("\
15060 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15061 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15064 add_cmd ("once", no_class, enable_once_command, _("\
15065 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15066 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15069 add_cmd ("count", no_class, enable_count_command, _("\
15070 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15071 If a breakpoint is hit while enabled in this fashion,\n\
15072 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15075 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
15076 Disable some breakpoints.\n\
15077 Arguments are breakpoint numbers with spaces in between.\n\
15078 To disable all breakpoints, give no argument.\n\
15079 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
15080 &disablelist, "disable ", 1, &cmdlist);
15081 add_com_alias ("dis", "disable", class_breakpoint, 1);
15082 add_com_alias ("disa", "disable", class_breakpoint, 1);
15084 add_com ("sb", class_breakpoint, disable_command, _("\
15085 Disable some breakpoints.\n\
15086 Arguments are breakpoint numbers with spaces in between.\n\
15087 To disable all breakpoints, give no argument.\n\
15088 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
15090 add_cmd ("breakpoints", class_alias, disable_command, _("\
15091 Disable some breakpoints.\n\
15092 Arguments are breakpoint numbers with spaces in between.\n\
15093 To disable all breakpoints, give no argument.\n\
15094 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
15095 This command may be abbreviated \"disable\"."),
15098 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
15099 Delete some breakpoints or auto-display expressions.\n\
15100 Arguments are breakpoint numbers with spaces in between.\n\
15101 To delete all breakpoints, give no argument.\n\
15103 Also a prefix command for deletion of other GDB objects.\n\
15104 The \"unset\" command is also an alias for \"delete\"."),
15105 &deletelist, "delete ", 1, &cmdlist);
15106 add_com_alias ("d", "delete", class_breakpoint, 1);
15107 add_com_alias ("del", "delete", class_breakpoint, 1);
15109 add_com ("db", class_breakpoint, delete_command, _("\
15110 Delete some breakpoints.\n\
15111 Arguments are breakpoint numbers with spaces in between.\n\
15112 To delete all breakpoints, give no argument.\n"));
15114 add_cmd ("breakpoints", class_alias, delete_command, _("\
15115 Delete some breakpoints or auto-display expressions.\n\
15116 Arguments are breakpoint numbers with spaces in between.\n\
15117 To delete all breakpoints, give no argument.\n\
15118 This command may be abbreviated \"delete\"."),
15121 add_com ("clear", class_breakpoint, clear_command, _("\
15122 Clear breakpoint at specified line or function.\n\
15123 Argument may be line number, function name, or \"*\" and an address.\n\
15124 If line number is specified, all breakpoints in that line are cleared.\n\
15125 If function is specified, breakpoints at beginning of function are cleared.\n\
15126 If an address is specified, breakpoints at that address are cleared.\n\
15128 With no argument, clears all breakpoints in the line that the selected frame\n\
15129 is executing in.\n\
15131 See also the \"delete\" command which clears breakpoints by number."));
15132 add_com_alias ("cl", "clear", class_breakpoint, 1);
15134 c = add_com ("break", class_breakpoint, break_command, _("\
15135 Set breakpoint at specified line or function.\n"
15136 BREAK_ARGS_HELP ("break")));
15137 set_cmd_completer (c, location_completer);
15139 add_com_alias ("b", "break", class_run, 1);
15140 add_com_alias ("br", "break", class_run, 1);
15141 add_com_alias ("bre", "break", class_run, 1);
15142 add_com_alias ("brea", "break", class_run, 1);
15145 add_com_alias ("ba", "break", class_breakpoint, 1);
15149 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
15150 Break in function/address or break at a line in the current file."),
15151 &stoplist, "stop ", 1, &cmdlist);
15152 add_cmd ("in", class_breakpoint, stopin_command,
15153 _("Break in function or address."), &stoplist);
15154 add_cmd ("at", class_breakpoint, stopat_command,
15155 _("Break at a line in the current file."), &stoplist);
15156 add_com ("status", class_info, breakpoints_info, _("\
15157 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15158 The \"Type\" column indicates one of:\n\
15159 \tbreakpoint - normal breakpoint\n\
15160 \twatchpoint - watchpoint\n\
15161 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15162 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15163 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15164 address and file/line number respectively.\n\
15166 Convenience variable \"$_\" and default examine address for \"x\"\n\
15167 are set to the address of the last breakpoint listed unless the command\n\
15168 is prefixed with \"server \".\n\n\
15169 Convenience variable \"$bpnum\" contains the number of the last\n\
15170 breakpoint set."));
15173 add_info ("breakpoints", breakpoints_info, _("\
15174 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
15175 The \"Type\" column indicates one of:\n\
15176 \tbreakpoint - normal breakpoint\n\
15177 \twatchpoint - watchpoint\n\
15178 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15179 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15180 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15181 address and file/line number respectively.\n\
15183 Convenience variable \"$_\" and default examine address for \"x\"\n\
15184 are set to the address of the last breakpoint listed unless the command\n\
15185 is prefixed with \"server \".\n\n\
15186 Convenience variable \"$bpnum\" contains the number of the last\n\
15187 breakpoint set."));
15189 add_info_alias ("b", "breakpoints", 1);
15192 add_com ("lb", class_breakpoint, breakpoints_info, _("\
15193 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15194 The \"Type\" column indicates one of:\n\
15195 \tbreakpoint - normal breakpoint\n\
15196 \twatchpoint - watchpoint\n\
15197 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15198 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15199 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15200 address and file/line number respectively.\n\
15202 Convenience variable \"$_\" and default examine address for \"x\"\n\
15203 are set to the address of the last breakpoint listed unless the command\n\
15204 is prefixed with \"server \".\n\n\
15205 Convenience variable \"$bpnum\" contains the number of the last\n\
15206 breakpoint set."));
15208 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
15209 Status of all breakpoints, or breakpoint number NUMBER.\n\
15210 The \"Type\" column indicates one of:\n\
15211 \tbreakpoint - normal breakpoint\n\
15212 \twatchpoint - watchpoint\n\
15213 \tlongjmp - internal breakpoint used to step through longjmp()\n\
15214 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
15215 \tuntil - internal breakpoint used by the \"until\" command\n\
15216 \tfinish - internal breakpoint used by the \"finish\" command\n\
15217 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15218 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15219 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15220 address and file/line number respectively.\n\
15222 Convenience variable \"$_\" and default examine address for \"x\"\n\
15223 are set to the address of the last breakpoint listed unless the command\n\
15224 is prefixed with \"server \".\n\n\
15225 Convenience variable \"$bpnum\" contains the number of the last\n\
15227 &maintenanceinfolist);
15229 add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\
15230 Set catchpoints to catch events."),
15231 &catch_cmdlist, "catch ",
15232 0/*allow-unknown*/, &cmdlist);
15234 add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\
15235 Set temporary catchpoints to catch events."),
15236 &tcatch_cmdlist, "tcatch ",
15237 0/*allow-unknown*/, &cmdlist);
15239 /* Add catch and tcatch sub-commands. */
15240 add_catch_command ("catch", _("\
15241 Catch an exception, when caught."),
15242 catch_catch_command,
15246 add_catch_command ("throw", _("\
15247 Catch an exception, when thrown."),
15248 catch_throw_command,
15252 add_catch_command ("fork", _("Catch calls to fork."),
15253 catch_fork_command_1,
15255 (void *) (uintptr_t) catch_fork_permanent,
15256 (void *) (uintptr_t) catch_fork_temporary);
15257 add_catch_command ("vfork", _("Catch calls to vfork."),
15258 catch_fork_command_1,
15260 (void *) (uintptr_t) catch_vfork_permanent,
15261 (void *) (uintptr_t) catch_vfork_temporary);
15262 add_catch_command ("exec", _("Catch calls to exec."),
15263 catch_exec_command_1,
15267 add_catch_command ("load", _("Catch loads of shared libraries.\n\
15268 Usage: catch load [REGEX]\n\
15269 If REGEX is given, only stop for libraries matching the regular expression."),
15270 catch_load_command_1,
15274 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
15275 Usage: catch unload [REGEX]\n\
15276 If REGEX is given, only stop for libraries matching the regular expression."),
15277 catch_unload_command_1,
15281 add_catch_command ("syscall", _("\
15282 Catch system calls by their names and/or numbers.\n\
15283 Arguments say which system calls to catch. If no arguments\n\
15284 are given, every system call will be caught.\n\
15285 Arguments, if given, should be one or more system call names\n\
15286 (if your system supports that), or system call numbers."),
15287 catch_syscall_command_1,
15288 catch_syscall_completer,
15292 c = add_com ("watch", class_breakpoint, watch_command, _("\
15293 Set a watchpoint for an expression.\n\
15294 Usage: watch [-l|-location] EXPRESSION\n\
15295 A watchpoint stops execution of your program whenever the value of\n\
15296 an expression changes.\n\
15297 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15298 the memory to which it refers."));
15299 set_cmd_completer (c, expression_completer);
15301 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
15302 Set a read watchpoint for an expression.\n\
15303 Usage: rwatch [-l|-location] EXPRESSION\n\
15304 A watchpoint stops execution of your program whenever the value of\n\
15305 an expression is read.\n\
15306 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15307 the memory to which it refers."));
15308 set_cmd_completer (c, expression_completer);
15310 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
15311 Set a watchpoint for an expression.\n\
15312 Usage: awatch [-l|-location] EXPRESSION\n\
15313 A watchpoint stops execution of your program whenever the value of\n\
15314 an expression is either read or written.\n\
15315 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15316 the memory to which it refers."));
15317 set_cmd_completer (c, expression_completer);
15319 add_info ("watchpoints", watchpoints_info, _("\
15320 Status of specified watchpoints (all watchpoints if no argument)."));
15322 /* XXX: cagney/2005-02-23: This should be a boolean, and should
15323 respond to changes - contrary to the description. */
15324 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
15325 &can_use_hw_watchpoints, _("\
15326 Set debugger's willingness to use watchpoint hardware."), _("\
15327 Show debugger's willingness to use watchpoint hardware."), _("\
15328 If zero, gdb will not use hardware for new watchpoints, even if\n\
15329 such is available. (However, any hardware watchpoints that were\n\
15330 created before setting this to nonzero, will continue to use watchpoint\n\
15333 show_can_use_hw_watchpoints,
15334 &setlist, &showlist);
15336 can_use_hw_watchpoints = 1;
15338 /* Tracepoint manipulation commands. */
15340 c = add_com ("trace", class_breakpoint, trace_command, _("\
15341 Set a tracepoint at specified line or function.\n\
15343 BREAK_ARGS_HELP ("trace") "\n\
15344 Do \"help tracepoints\" for info on other tracepoint commands."));
15345 set_cmd_completer (c, location_completer);
15347 add_com_alias ("tp", "trace", class_alias, 0);
15348 add_com_alias ("tr", "trace", class_alias, 1);
15349 add_com_alias ("tra", "trace", class_alias, 1);
15350 add_com_alias ("trac", "trace", class_alias, 1);
15352 c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\
15353 Set a fast tracepoint at specified line or function.\n\
15355 BREAK_ARGS_HELP ("ftrace") "\n\
15356 Do \"help tracepoints\" for info on other tracepoint commands."));
15357 set_cmd_completer (c, location_completer);
15359 c = add_com ("strace", class_breakpoint, strace_command, _("\
15360 Set a static tracepoint at specified line, function or marker.\n\
15362 strace [LOCATION] [if CONDITION]\n\
15363 LOCATION may be a line number, function name, \"*\" and an address,\n\
15364 or -m MARKER_ID.\n\
15365 If a line number is specified, probe the marker at start of code\n\
15366 for that line. If a function is specified, probe the marker at start\n\
15367 of code for that function. If an address is specified, probe the marker\n\
15368 at that exact address. If a marker id is specified, probe the marker\n\
15369 with that name. With no LOCATION, uses current execution address of\n\
15370 the selected stack frame.\n\
15371 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
15372 This collects arbitrary user data passed in the probe point call to the\n\
15373 tracing library. You can inspect it when analyzing the trace buffer,\n\
15374 by printing the $_sdata variable like any other convenience variable.\n\
15376 CONDITION is a boolean expression.\n\
15378 Multiple tracepoints at one place are permitted, and useful if their\n\
15379 conditions are different.\n\
15381 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
15382 Do \"help tracepoints\" for info on other tracepoint commands."));
15383 set_cmd_completer (c, location_completer);
15385 add_info ("tracepoints", tracepoints_info, _("\
15386 Status of specified tracepoints (all tracepoints if no argument).\n\
15387 Convenience variable \"$tpnum\" contains the number of the\n\
15388 last tracepoint set."));
15390 add_info_alias ("tp", "tracepoints", 1);
15392 add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
15393 Delete specified tracepoints.\n\
15394 Arguments are tracepoint numbers, separated by spaces.\n\
15395 No argument means delete all tracepoints."),
15398 c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
15399 Disable specified tracepoints.\n\
15400 Arguments are tracepoint numbers, separated by spaces.\n\
15401 No argument means disable all tracepoints."),
15403 deprecate_cmd (c, "disable");
15405 c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\
15406 Enable specified tracepoints.\n\
15407 Arguments are tracepoint numbers, separated by spaces.\n\
15408 No argument means enable all tracepoints."),
15410 deprecate_cmd (c, "enable");
15412 add_com ("passcount", class_trace, trace_pass_command, _("\
15413 Set the passcount for a tracepoint.\n\
15414 The trace will end when the tracepoint has been passed 'count' times.\n\
15415 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
15416 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
15418 add_prefix_cmd ("save", class_breakpoint, save_command,
15419 _("Save breakpoint definitions as a script."),
15420 &save_cmdlist, "save ",
15421 0/*allow-unknown*/, &cmdlist);
15423 c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\
15424 Save current breakpoint definitions as a script.\n\
15425 This includes all types of breakpoints (breakpoints, watchpoints,\n\
15426 catchpoints, tracepoints). Use the 'source' command in another debug\n\
15427 session to restore them."),
15429 set_cmd_completer (c, filename_completer);
15431 c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\
15432 Save current tracepoint definitions as a script.\n\
15433 Use the 'source' command in another debug session to restore them."),
15435 set_cmd_completer (c, filename_completer);
15437 c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0);
15438 deprecate_cmd (c, "save tracepoints");
15440 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
15441 Breakpoint specific settings\n\
15442 Configure various breakpoint-specific variables such as\n\
15443 pending breakpoint behavior"),
15444 &breakpoint_set_cmdlist, "set breakpoint ",
15445 0/*allow-unknown*/, &setlist);
15446 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
15447 Breakpoint specific settings\n\
15448 Configure various breakpoint-specific variables such as\n\
15449 pending breakpoint behavior"),
15450 &breakpoint_show_cmdlist, "show breakpoint ",
15451 0/*allow-unknown*/, &showlist);
15453 add_setshow_auto_boolean_cmd ("pending", no_class,
15454 &pending_break_support, _("\
15455 Set debugger's behavior regarding pending breakpoints."), _("\
15456 Show debugger's behavior regarding pending breakpoints."), _("\
15457 If on, an unrecognized breakpoint location will cause gdb to create a\n\
15458 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
15459 an error. If auto, an unrecognized breakpoint location results in a\n\
15460 user-query to see if a pending breakpoint should be created."),
15462 show_pending_break_support,
15463 &breakpoint_set_cmdlist,
15464 &breakpoint_show_cmdlist);
15466 pending_break_support = AUTO_BOOLEAN_AUTO;
15468 add_setshow_boolean_cmd ("auto-hw", no_class,
15469 &automatic_hardware_breakpoints, _("\
15470 Set automatic usage of hardware breakpoints."), _("\
15471 Show automatic usage of hardware breakpoints."), _("\
15472 If set, the debugger will automatically use hardware breakpoints for\n\
15473 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
15474 a warning will be emitted for such breakpoints."),
15476 show_automatic_hardware_breakpoints,
15477 &breakpoint_set_cmdlist,
15478 &breakpoint_show_cmdlist);
15480 add_setshow_enum_cmd ("always-inserted", class_support,
15481 always_inserted_enums, &always_inserted_mode, _("\
15482 Set mode for inserting breakpoints."), _("\
15483 Show mode for inserting breakpoints."), _("\
15484 When this mode is off, breakpoints are inserted in inferior when it is\n\
15485 resumed, and removed when execution stops. When this mode is on,\n\
15486 breakpoints are inserted immediately and removed only when the user\n\
15487 deletes the breakpoint. When this mode is auto (which is the default),\n\
15488 the behaviour depends on the non-stop setting (see help set non-stop).\n\
15489 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
15490 behaves as if always-inserted mode is on; if gdb is controlling the\n\
15491 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
15493 &show_always_inserted_mode,
15494 &breakpoint_set_cmdlist,
15495 &breakpoint_show_cmdlist);
15497 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint,
15498 condition_evaluation_enums,
15499 &condition_evaluation_mode_1, _("\
15500 Set mode of breakpoint condition evaluation."), _("\
15501 Show mode of breakpoint condition evaluation."), _("\
15502 When this is set to \"gdb\", breakpoint conditions will be\n\
15503 evaluated on the host's side by GDB. When it is set to \"target\",\n\
15504 breakpoint conditions will be downloaded to the target (if the target\n\
15505 supports such feature) and conditions will be evaluated on the target's side.\n\
15506 If this is set to \"auto\" (default), this will be automatically set to\n\
15507 \"target\" if it supports condition evaluation, otherwise it will\n\
15508 be set to \"gdb\""),
15509 &set_condition_evaluation_mode,
15510 &show_condition_evaluation_mode,
15511 &breakpoint_set_cmdlist,
15512 &breakpoint_show_cmdlist);
15514 add_com ("break-range", class_breakpoint, break_range_command, _("\
15515 Set a breakpoint for an address range.\n\
15516 break-range START-LOCATION, END-LOCATION\n\
15517 where START-LOCATION and END-LOCATION can be one of the following:\n\
15518 LINENUM, for that line in the current file,\n\
15519 FILE:LINENUM, for that line in that file,\n\
15520 +OFFSET, for that number of lines after the current line\n\
15521 or the start of the range\n\
15522 FUNCTION, for the first line in that function,\n\
15523 FILE:FUNCTION, to distinguish among like-named static functions.\n\
15524 *ADDRESS, for the instruction at that address.\n\
15526 The breakpoint will stop execution of the inferior whenever it executes\n\
15527 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
15528 range (including START-LOCATION and END-LOCATION)."));
15530 automatic_hardware_breakpoints = 1;
15532 observer_attach_about_to_proceed (breakpoint_about_to_proceed);