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 "gdb_regex.h"
65 #include "cli/cli-utils.h"
66 #include "continuations.h"
69 #include "gdb_regex.h"
72 /* readline include files */
73 #include "readline/readline.h"
74 #include "readline/history.h"
76 /* readline defines this. */
79 #include "mi/mi-common.h"
80 #include "python/python.h"
82 /* Prototypes for local functions. */
84 static void enable_delete_command (char *, int);
86 static void enable_once_command (char *, int);
88 static void enable_count_command (char *, int);
90 static void disable_command (char *, int);
92 static void enable_command (char *, int);
94 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *,
98 static void ignore_command (char *, int);
100 static int breakpoint_re_set_one (void *);
102 static void breakpoint_re_set_default (struct breakpoint *);
104 static void create_sals_from_address_default (char **,
105 struct linespec_result *,
109 static void create_breakpoints_sal_default (struct gdbarch *,
110 struct linespec_result *,
111 struct linespec_sals *,
112 char *, char *, enum bptype,
113 enum bpdisp, int, int,
115 const struct breakpoint_ops *,
116 int, int, int, unsigned);
118 static void decode_linespec_default (struct breakpoint *, char **,
119 struct symtabs_and_lines *);
121 static void clear_command (char *, int);
123 static void catch_command (char *, int);
125 static int can_use_hardware_watchpoint (struct value *);
127 static void break_command_1 (char *, int, int);
129 static void mention (struct breakpoint *);
131 static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *,
133 const struct breakpoint_ops *);
134 static struct bp_location *add_location_to_breakpoint (struct breakpoint *,
135 const struct symtab_and_line *);
137 /* This function is used in gdbtk sources and thus can not be made
139 struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch,
140 struct symtab_and_line,
142 const struct breakpoint_ops *);
144 static struct breakpoint *
145 momentary_breakpoint_from_master (struct breakpoint *orig,
147 const struct breakpoint_ops *ops);
149 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
151 static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch,
155 static void describe_other_breakpoints (struct gdbarch *,
156 struct program_space *, CORE_ADDR,
157 struct obj_section *, int);
159 static int breakpoint_address_match (struct address_space *aspace1,
161 struct address_space *aspace2,
164 static int watchpoint_locations_match (struct bp_location *loc1,
165 struct bp_location *loc2);
167 static int breakpoint_location_address_match (struct bp_location *bl,
168 struct address_space *aspace,
171 static void breakpoints_info (char *, int);
173 static void watchpoints_info (char *, int);
175 static int breakpoint_1 (char *, int,
176 int (*) (const struct breakpoint *));
178 static int breakpoint_cond_eval (void *);
180 static void cleanup_executing_breakpoints (void *);
182 static void commands_command (char *, int);
184 static void condition_command (char *, int);
193 static int remove_breakpoint (struct bp_location *, insertion_state_t);
194 static int remove_breakpoint_1 (struct bp_location *, insertion_state_t);
196 static enum print_stop_action print_bp_stop_message (bpstat bs);
198 static int watchpoint_check (void *);
200 static void maintenance_info_breakpoints (char *, int);
202 static int hw_breakpoint_used_count (void);
204 static int hw_watchpoint_use_count (struct breakpoint *);
206 static int hw_watchpoint_used_count_others (struct breakpoint *except,
208 int *other_type_used);
210 static void hbreak_command (char *, int);
212 static void thbreak_command (char *, int);
214 static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp,
217 static void stop_command (char *arg, int from_tty);
219 static void stopin_command (char *arg, int from_tty);
221 static void stopat_command (char *arg, int from_tty);
223 static char *ep_parse_optional_if_clause (char **arg);
225 static void catch_exception_command_1 (enum exception_event_kind ex_event,
226 char *arg, int tempflag, int from_tty);
228 static void tcatch_command (char *arg, int from_tty);
230 static void detach_single_step_breakpoints (void);
232 static int single_step_breakpoint_inserted_here_p (struct address_space *,
235 static void free_bp_location (struct bp_location *loc);
236 static void incref_bp_location (struct bp_location *loc);
237 static void decref_bp_location (struct bp_location **loc);
239 static struct bp_location *allocate_bp_location (struct breakpoint *bpt);
241 static void update_global_location_list (int);
243 static void update_global_location_list_nothrow (int);
245 static int is_hardware_watchpoint (const struct breakpoint *bpt);
247 static void insert_breakpoint_locations (void);
249 static int syscall_catchpoint_p (struct breakpoint *b);
251 static void tracepoints_info (char *, int);
253 static void delete_trace_command (char *, int);
255 static void enable_trace_command (char *, int);
257 static void disable_trace_command (char *, int);
259 static void trace_pass_command (char *, int);
261 static int is_masked_watchpoint (const struct breakpoint *b);
263 static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address);
265 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
268 static int strace_marker_p (struct breakpoint *b);
270 static void init_catchpoint (struct breakpoint *b,
271 struct gdbarch *gdbarch, int tempflag,
273 const struct breakpoint_ops *ops);
275 /* The abstract base class all breakpoint_ops structures inherit
277 static struct breakpoint_ops base_breakpoint_ops;
279 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
280 that are implemented on top of software or hardware breakpoints
281 (user breakpoints, internal and momentary breakpoints, etc.). */
282 static struct breakpoint_ops bkpt_base_breakpoint_ops;
284 /* Internal breakpoints class type. */
285 static struct breakpoint_ops internal_breakpoint_ops;
287 /* Momentary breakpoints class type. */
288 static struct breakpoint_ops momentary_breakpoint_ops;
290 /* The breakpoint_ops structure to be used in regular user created
292 struct breakpoint_ops bkpt_breakpoint_ops;
294 /* Breakpoints set on probes. */
295 static struct breakpoint_ops bkpt_probe_breakpoint_ops;
297 /* Dynamic printf class type. */
298 static struct breakpoint_ops dprintf_breakpoint_ops;
300 /* A reference-counted struct command_line. This lets multiple
301 breakpoints share a single command list. */
302 struct counted_command_line
304 /* The reference count. */
307 /* The command list. */
308 struct command_line *commands;
311 struct command_line *
312 breakpoint_commands (struct breakpoint *b)
314 return b->commands ? b->commands->commands : NULL;
317 /* Flag indicating that a command has proceeded the inferior past the
318 current breakpoint. */
320 static int breakpoint_proceeded;
323 bpdisp_text (enum bpdisp disp)
325 /* NOTE: the following values are a part of MI protocol and
326 represent values of 'disp' field returned when inferior stops at
328 static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"};
330 return bpdisps[(int) disp];
333 /* Prototypes for exported functions. */
334 /* If FALSE, gdb will not use hardware support for watchpoints, even
335 if such is available. */
336 static int can_use_hw_watchpoints;
339 show_can_use_hw_watchpoints (struct ui_file *file, int from_tty,
340 struct cmd_list_element *c,
343 fprintf_filtered (file,
344 _("Debugger's willingness to use "
345 "watchpoint hardware is %s.\n"),
349 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
350 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
351 for unrecognized breakpoint locations.
352 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
353 static enum auto_boolean pending_break_support;
355 show_pending_break_support (struct ui_file *file, int from_tty,
356 struct cmd_list_element *c,
359 fprintf_filtered (file,
360 _("Debugger's behavior regarding "
361 "pending breakpoints is %s.\n"),
365 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
366 set with "break" but falling in read-only memory.
367 If 0, gdb will warn about such breakpoints, but won't automatically
368 use hardware breakpoints. */
369 static int automatic_hardware_breakpoints;
371 show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty,
372 struct cmd_list_element *c,
375 fprintf_filtered (file,
376 _("Automatic usage of hardware breakpoints is %s.\n"),
380 /* If on, gdb will keep breakpoints inserted even as inferior is
381 stopped, and immediately insert any new breakpoints. If off, gdb
382 will insert breakpoints into inferior only when resuming it, and
383 will remove breakpoints upon stop. If auto, GDB will behave as ON
384 if in non-stop mode, and as OFF if all-stop mode.*/
386 static const char always_inserted_auto[] = "auto";
387 static const char always_inserted_on[] = "on";
388 static const char always_inserted_off[] = "off";
389 static const char *const always_inserted_enums[] = {
390 always_inserted_auto,
395 static const char *always_inserted_mode = always_inserted_auto;
397 show_always_inserted_mode (struct ui_file *file, int from_tty,
398 struct cmd_list_element *c, const char *value)
400 if (always_inserted_mode == always_inserted_auto)
401 fprintf_filtered (file,
402 _("Always inserted breakpoint "
403 "mode is %s (currently %s).\n"),
405 breakpoints_always_inserted_mode () ? "on" : "off");
407 fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"),
412 breakpoints_always_inserted_mode (void)
414 return (always_inserted_mode == always_inserted_on
415 || (always_inserted_mode == always_inserted_auto && non_stop));
418 static const char condition_evaluation_both[] = "host or target";
420 /* Modes for breakpoint condition evaluation. */
421 static const char condition_evaluation_auto[] = "auto";
422 static const char condition_evaluation_host[] = "host";
423 static const char condition_evaluation_target[] = "target";
424 static const char *const condition_evaluation_enums[] = {
425 condition_evaluation_auto,
426 condition_evaluation_host,
427 condition_evaluation_target,
431 /* Global that holds the current mode for breakpoint condition evaluation. */
432 static const char *condition_evaluation_mode_1 = condition_evaluation_auto;
434 /* Global that we use to display information to the user (gets its value from
435 condition_evaluation_mode_1. */
436 static const char *condition_evaluation_mode = condition_evaluation_auto;
438 /* Translate a condition evaluation mode MODE into either "host"
439 or "target". This is used mostly to translate from "auto" to the
440 real setting that is being used. It returns the translated
444 translate_condition_evaluation_mode (const char *mode)
446 if (mode == condition_evaluation_auto)
448 if (target_supports_evaluation_of_breakpoint_conditions ())
449 return condition_evaluation_target;
451 return condition_evaluation_host;
457 /* Discovers what condition_evaluation_auto translates to. */
460 breakpoint_condition_evaluation_mode (void)
462 return translate_condition_evaluation_mode (condition_evaluation_mode);
465 /* Return true if GDB should evaluate breakpoint conditions or false
469 gdb_evaluates_breakpoint_condition_p (void)
471 const char *mode = breakpoint_condition_evaluation_mode ();
473 return (mode == condition_evaluation_host);
476 void _initialize_breakpoint (void);
478 /* Are we executing breakpoint commands? */
479 static int executing_breakpoint_commands;
481 /* Are overlay event breakpoints enabled? */
482 static int overlay_events_enabled;
484 /* See description in breakpoint.h. */
485 int target_exact_watchpoints = 0;
487 /* Walk the following statement or block through all breakpoints.
488 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
489 current breakpoint. */
491 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
493 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
494 for (B = breakpoint_chain; \
495 B ? (TMP=B->next, 1): 0; \
498 /* Similar iterator for the low-level breakpoints. SAFE variant is
499 not provided so update_global_location_list must not be called
500 while executing the block of ALL_BP_LOCATIONS. */
502 #define ALL_BP_LOCATIONS(B,BP_TMP) \
503 for (BP_TMP = bp_location; \
504 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
507 /* Iterates through locations with address ADDRESS for the currently selected
508 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
509 to where the loop should start from.
510 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
511 appropriate location to start with. */
513 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
514 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
515 BP_LOCP_TMP = BP_LOCP_START; \
517 && (BP_LOCP_TMP < bp_location + bp_location_count \
518 && (*BP_LOCP_TMP)->address == ADDRESS); \
521 /* Iterator for tracepoints only. */
523 #define ALL_TRACEPOINTS(B) \
524 for (B = breakpoint_chain; B; B = B->next) \
525 if (is_tracepoint (B))
527 /* Chains of all breakpoints defined. */
529 struct breakpoint *breakpoint_chain;
531 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
533 static struct bp_location **bp_location;
535 /* Number of elements of BP_LOCATION. */
537 static unsigned bp_location_count;
539 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
540 ADDRESS for the current elements of BP_LOCATION which get a valid
541 result from bp_location_has_shadow. You can use it for roughly
542 limiting the subrange of BP_LOCATION to scan for shadow bytes for
543 an address you need to read. */
545 static CORE_ADDR bp_location_placed_address_before_address_max;
547 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
548 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
549 BP_LOCATION which get a valid result from bp_location_has_shadow.
550 You can use it for roughly limiting the subrange of BP_LOCATION to
551 scan for shadow bytes for an address you need to read. */
553 static CORE_ADDR bp_location_shadow_len_after_address_max;
555 /* The locations that no longer correspond to any breakpoint, unlinked
556 from bp_location array, but for which a hit may still be reported
558 VEC(bp_location_p) *moribund_locations = NULL;
560 /* Number of last breakpoint made. */
562 static int breakpoint_count;
564 /* The value of `breakpoint_count' before the last command that
565 created breakpoints. If the last (break-like) command created more
566 than one breakpoint, then the difference between BREAKPOINT_COUNT
567 and PREV_BREAKPOINT_COUNT is more than one. */
568 static int prev_breakpoint_count;
570 /* Number of last tracepoint made. */
572 static int tracepoint_count;
574 static struct cmd_list_element *breakpoint_set_cmdlist;
575 static struct cmd_list_element *breakpoint_show_cmdlist;
576 struct cmd_list_element *save_cmdlist;
578 /* Return whether a breakpoint is an active enabled breakpoint. */
580 breakpoint_enabled (struct breakpoint *b)
582 return (b->enable_state == bp_enabled);
585 /* Set breakpoint count to NUM. */
588 set_breakpoint_count (int num)
590 prev_breakpoint_count = breakpoint_count;
591 breakpoint_count = num;
592 set_internalvar_integer (lookup_internalvar ("bpnum"), num);
595 /* Used by `start_rbreak_breakpoints' below, to record the current
596 breakpoint count before "rbreak" creates any breakpoint. */
597 static int rbreak_start_breakpoint_count;
599 /* Called at the start an "rbreak" command to record the first
603 start_rbreak_breakpoints (void)
605 rbreak_start_breakpoint_count = breakpoint_count;
608 /* Called at the end of an "rbreak" command to record the last
612 end_rbreak_breakpoints (void)
614 prev_breakpoint_count = rbreak_start_breakpoint_count;
617 /* Used in run_command to zero the hit count when a new run starts. */
620 clear_breakpoint_hit_counts (void)
622 struct breakpoint *b;
628 /* Allocate a new counted_command_line with reference count of 1.
629 The new structure owns COMMANDS. */
631 static struct counted_command_line *
632 alloc_counted_command_line (struct command_line *commands)
634 struct counted_command_line *result
635 = xmalloc (sizeof (struct counted_command_line));
638 result->commands = commands;
642 /* Increment reference count. This does nothing if CMD is NULL. */
645 incref_counted_command_line (struct counted_command_line *cmd)
651 /* Decrement reference count. If the reference count reaches 0,
652 destroy the counted_command_line. Sets *CMDP to NULL. This does
653 nothing if *CMDP is NULL. */
656 decref_counted_command_line (struct counted_command_line **cmdp)
660 if (--(*cmdp)->refc == 0)
662 free_command_lines (&(*cmdp)->commands);
669 /* A cleanup function that calls decref_counted_command_line. */
672 do_cleanup_counted_command_line (void *arg)
674 decref_counted_command_line (arg);
677 /* Create a cleanup that calls decref_counted_command_line on the
680 static struct cleanup *
681 make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp)
683 return make_cleanup (do_cleanup_counted_command_line, cmdp);
687 /* Return the breakpoint with the specified number, or NULL
688 if the number does not refer to an existing breakpoint. */
691 get_breakpoint (int num)
693 struct breakpoint *b;
696 if (b->number == num)
704 /* Mark locations as "conditions have changed" in case the target supports
705 evaluating conditions on its side. */
708 mark_breakpoint_modified (struct breakpoint *b)
710 struct bp_location *loc;
712 /* This is only meaningful if the target is
713 evaluating conditions and if the user has
714 opted for condition evaluation on the target's
716 if (gdb_evaluates_breakpoint_condition_p ()
717 || !target_supports_evaluation_of_breakpoint_conditions ())
720 if (!is_breakpoint (b))
723 for (loc = b->loc; loc; loc = loc->next)
724 loc->condition_changed = condition_modified;
727 /* Mark location as "conditions have changed" in case the target supports
728 evaluating conditions on its side. */
731 mark_breakpoint_location_modified (struct bp_location *loc)
733 /* This is only meaningful if the target is
734 evaluating conditions and if the user has
735 opted for condition evaluation on the target's
737 if (gdb_evaluates_breakpoint_condition_p ()
738 || !target_supports_evaluation_of_breakpoint_conditions ())
742 if (!is_breakpoint (loc->owner))
745 loc->condition_changed = condition_modified;
748 /* Sets the condition-evaluation mode using the static global
749 condition_evaluation_mode. */
752 set_condition_evaluation_mode (char *args, int from_tty,
753 struct cmd_list_element *c)
755 struct breakpoint *b;
756 const char *old_mode, *new_mode;
758 if ((condition_evaluation_mode_1 == condition_evaluation_target)
759 && !target_supports_evaluation_of_breakpoint_conditions ())
761 condition_evaluation_mode_1 = condition_evaluation_mode;
762 warning (_("Target does not support breakpoint condition evaluation.\n"
763 "Using host evaluation mode instead."));
767 new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1);
768 old_mode = translate_condition_evaluation_mode (condition_evaluation_mode);
770 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
771 settings was "auto". */
772 condition_evaluation_mode = condition_evaluation_mode_1;
774 /* Only update the mode if the user picked a different one. */
775 if (new_mode != old_mode)
777 struct bp_location *loc, **loc_tmp;
778 /* If the user switched to a different evaluation mode, we
779 need to synch the changes with the target as follows:
781 "host" -> "target": Send all (valid) conditions to the target.
782 "target" -> "host": Remove all the conditions from the target.
785 if (new_mode == condition_evaluation_target)
787 /* Mark everything modified and synch conditions with the
789 ALL_BP_LOCATIONS (loc, loc_tmp)
790 mark_breakpoint_location_modified (loc);
794 /* Manually mark non-duplicate locations to synch conditions
795 with the target. We do this to remove all the conditions the
796 target knows about. */
797 ALL_BP_LOCATIONS (loc, loc_tmp)
798 if (is_breakpoint (loc->owner) && loc->inserted)
799 loc->needs_update = 1;
803 update_global_location_list (1);
809 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
810 what "auto" is translating to. */
813 show_condition_evaluation_mode (struct ui_file *file, int from_tty,
814 struct cmd_list_element *c, const char *value)
816 if (condition_evaluation_mode == condition_evaluation_auto)
817 fprintf_filtered (file,
818 _("Breakpoint condition evaluation "
819 "mode is %s (currently %s).\n"),
821 breakpoint_condition_evaluation_mode ());
823 fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"),
827 /* A comparison function for bp_location AP and BP that is used by
828 bsearch. This comparison function only cares about addresses, unlike
829 the more general bp_location_compare function. */
832 bp_location_compare_addrs (const void *ap, const void *bp)
834 struct bp_location *a = *(void **) ap;
835 struct bp_location *b = *(void **) bp;
837 if (a->address == b->address)
840 return ((a->address > b->address) - (a->address < b->address));
843 /* Helper function to skip all bp_locations with addresses
844 less than ADDRESS. It returns the first bp_location that
845 is greater than or equal to ADDRESS. If none is found, just
848 static struct bp_location **
849 get_first_locp_gte_addr (CORE_ADDR address)
851 struct bp_location dummy_loc;
852 struct bp_location *dummy_locp = &dummy_loc;
853 struct bp_location **locp_found = NULL;
855 /* Initialize the dummy location's address field. */
856 memset (&dummy_loc, 0, sizeof (struct bp_location));
857 dummy_loc.address = address;
859 /* Find a close match to the first location at ADDRESS. */
860 locp_found = bsearch (&dummy_locp, bp_location, bp_location_count,
861 sizeof (struct bp_location **),
862 bp_location_compare_addrs);
864 /* Nothing was found, nothing left to do. */
865 if (locp_found == NULL)
868 /* We may have found a location that is at ADDRESS but is not the first in the
869 location's list. Go backwards (if possible) and locate the first one. */
870 while ((locp_found - 1) >= bp_location
871 && (*(locp_found - 1))->address == address)
878 set_breakpoint_condition (struct breakpoint *b, char *exp,
881 xfree (b->cond_string);
882 b->cond_string = NULL;
884 if (is_watchpoint (b))
886 struct watchpoint *w = (struct watchpoint *) b;
893 struct bp_location *loc;
895 for (loc = b->loc; loc; loc = loc->next)
900 /* No need to free the condition agent expression
901 bytecode (if we have one). We will handle this
902 when we go through update_global_location_list. */
909 printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number);
915 /* I don't know if it matters whether this is the string the user
916 typed in or the decompiled expression. */
917 b->cond_string = xstrdup (arg);
918 b->condition_not_parsed = 0;
920 if (is_watchpoint (b))
922 struct watchpoint *w = (struct watchpoint *) b;
924 innermost_block = NULL;
926 w->cond_exp = parse_exp_1 (&arg, 0, 0);
928 error (_("Junk at end of expression"));
929 w->cond_exp_valid_block = innermost_block;
933 struct bp_location *loc;
935 for (loc = b->loc; loc; loc = loc->next)
939 parse_exp_1 (&arg, block_for_pc (loc->address), 0);
941 error (_("Junk at end of expression"));
945 mark_breakpoint_modified (b);
947 breakpoints_changed ();
948 observer_notify_breakpoint_modified (b);
951 /* condition N EXP -- set break condition of breakpoint N to EXP. */
954 condition_command (char *arg, int from_tty)
956 struct breakpoint *b;
961 error_no_arg (_("breakpoint number"));
964 bnum = get_number (&p);
966 error (_("Bad breakpoint argument: '%s'"), arg);
969 if (b->number == bnum)
971 /* Check if this breakpoint has a Python object assigned to
972 it, and if it has a definition of the "stop"
973 method. This method and conditions entered into GDB from
974 the CLI are mutually exclusive. */
976 && gdbpy_breakpoint_has_py_cond (b->py_bp_object))
977 error (_("Cannot set a condition where a Python 'stop' "
978 "method has been defined in the breakpoint."));
979 set_breakpoint_condition (b, p, from_tty);
981 if (is_breakpoint (b))
982 update_global_location_list (1);
987 error (_("No breakpoint number %d."), bnum);
990 /* Check that COMMAND do not contain commands that are suitable
991 only for tracepoints and not suitable for ordinary breakpoints.
992 Throw if any such commands is found. */
995 check_no_tracepoint_commands (struct command_line *commands)
997 struct command_line *c;
999 for (c = commands; c; c = c->next)
1003 if (c->control_type == while_stepping_control)
1004 error (_("The 'while-stepping' command can "
1005 "only be used for tracepoints"));
1007 for (i = 0; i < c->body_count; ++i)
1008 check_no_tracepoint_commands ((c->body_list)[i]);
1010 /* Not that command parsing removes leading whitespace and comment
1011 lines and also empty lines. So, we only need to check for
1012 command directly. */
1013 if (strstr (c->line, "collect ") == c->line)
1014 error (_("The 'collect' command can only be used for tracepoints"));
1016 if (strstr (c->line, "teval ") == c->line)
1017 error (_("The 'teval' command can only be used for tracepoints"));
1021 /* Encapsulate tests for different types of tracepoints. */
1024 is_tracepoint_type (enum bptype type)
1026 return (type == bp_tracepoint
1027 || type == bp_fast_tracepoint
1028 || type == bp_static_tracepoint);
1032 is_tracepoint (const struct breakpoint *b)
1034 return is_tracepoint_type (b->type);
1037 /* A helper function that validates that COMMANDS are valid for a
1038 breakpoint. This function will throw an exception if a problem is
1042 validate_commands_for_breakpoint (struct breakpoint *b,
1043 struct command_line *commands)
1045 if (is_tracepoint (b))
1047 /* We need to verify that each top-level element of commands is
1048 valid for tracepoints, that there's at most one
1049 while-stepping element, and that while-stepping's body has
1050 valid tracing commands excluding nested while-stepping. */
1051 struct command_line *c;
1052 struct command_line *while_stepping = 0;
1053 for (c = commands; c; c = c->next)
1055 if (c->control_type == while_stepping_control)
1057 if (b->type == bp_fast_tracepoint)
1058 error (_("The 'while-stepping' command "
1059 "cannot be used for fast tracepoint"));
1060 else if (b->type == bp_static_tracepoint)
1061 error (_("The 'while-stepping' command "
1062 "cannot be used for static tracepoint"));
1065 error (_("The 'while-stepping' command "
1066 "can be used only once"));
1073 struct command_line *c2;
1075 gdb_assert (while_stepping->body_count == 1);
1076 c2 = while_stepping->body_list[0];
1077 for (; c2; c2 = c2->next)
1079 if (c2->control_type == while_stepping_control)
1080 error (_("The 'while-stepping' command cannot be nested"));
1086 check_no_tracepoint_commands (commands);
1090 /* Return a vector of all the static tracepoints set at ADDR. The
1091 caller is responsible for releasing the vector. */
1094 static_tracepoints_here (CORE_ADDR addr)
1096 struct breakpoint *b;
1097 VEC(breakpoint_p) *found = 0;
1098 struct bp_location *loc;
1101 if (b->type == bp_static_tracepoint)
1103 for (loc = b->loc; loc; loc = loc->next)
1104 if (loc->address == addr)
1105 VEC_safe_push(breakpoint_p, found, b);
1111 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1112 validate that only allowed commands are included. */
1115 breakpoint_set_commands (struct breakpoint *b,
1116 struct command_line *commands)
1118 validate_commands_for_breakpoint (b, commands);
1120 decref_counted_command_line (&b->commands);
1121 b->commands = alloc_counted_command_line (commands);
1122 breakpoints_changed ();
1123 observer_notify_breakpoint_modified (b);
1126 /* Set the internal `silent' flag on the breakpoint. Note that this
1127 is not the same as the "silent" that may appear in the breakpoint's
1131 breakpoint_set_silent (struct breakpoint *b, int silent)
1133 int old_silent = b->silent;
1136 if (old_silent != silent)
1137 observer_notify_breakpoint_modified (b);
1140 /* Set the thread for this breakpoint. If THREAD is -1, make the
1141 breakpoint work for any thread. */
1144 breakpoint_set_thread (struct breakpoint *b, int thread)
1146 int old_thread = b->thread;
1149 if (old_thread != thread)
1150 observer_notify_breakpoint_modified (b);
1153 /* Set the task for this breakpoint. If TASK is 0, make the
1154 breakpoint work for any task. */
1157 breakpoint_set_task (struct breakpoint *b, int task)
1159 int old_task = b->task;
1162 if (old_task != task)
1163 observer_notify_breakpoint_modified (b);
1167 check_tracepoint_command (char *line, void *closure)
1169 struct breakpoint *b = closure;
1171 validate_actionline (&line, b);
1174 /* A structure used to pass information through
1175 map_breakpoint_numbers. */
1177 struct commands_info
1179 /* True if the command was typed at a tty. */
1182 /* The breakpoint range spec. */
1185 /* Non-NULL if the body of the commands are being read from this
1186 already-parsed command. */
1187 struct command_line *control;
1189 /* The command lines read from the user, or NULL if they have not
1191 struct counted_command_line *cmd;
1194 /* A callback for map_breakpoint_numbers that sets the commands for
1195 commands_command. */
1198 do_map_commands_command (struct breakpoint *b, void *data)
1200 struct commands_info *info = data;
1202 if (info->cmd == NULL)
1204 struct command_line *l;
1206 if (info->control != NULL)
1207 l = copy_command_lines (info->control->body_list[0]);
1210 struct cleanup *old_chain;
1213 str = xstrprintf (_("Type commands for breakpoint(s) "
1214 "%s, one per line."),
1217 old_chain = make_cleanup (xfree, str);
1219 l = read_command_lines (str,
1222 ? check_tracepoint_command : 0),
1225 do_cleanups (old_chain);
1228 info->cmd = alloc_counted_command_line (l);
1231 /* If a breakpoint was on the list more than once, we don't need to
1233 if (b->commands != info->cmd)
1235 validate_commands_for_breakpoint (b, info->cmd->commands);
1236 incref_counted_command_line (info->cmd);
1237 decref_counted_command_line (&b->commands);
1238 b->commands = info->cmd;
1239 breakpoints_changed ();
1240 observer_notify_breakpoint_modified (b);
1245 commands_command_1 (char *arg, int from_tty,
1246 struct command_line *control)
1248 struct cleanup *cleanups;
1249 struct commands_info info;
1251 info.from_tty = from_tty;
1252 info.control = control;
1254 /* If we read command lines from the user, then `info' will hold an
1255 extra reference to the commands that we must clean up. */
1256 cleanups = make_cleanup_decref_counted_command_line (&info.cmd);
1258 if (arg == NULL || !*arg)
1260 if (breakpoint_count - prev_breakpoint_count > 1)
1261 arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1,
1263 else if (breakpoint_count > 0)
1264 arg = xstrprintf ("%d", breakpoint_count);
1267 /* So that we don't try to free the incoming non-NULL
1268 argument in the cleanup below. Mapping breakpoint
1269 numbers will fail in this case. */
1274 /* The command loop has some static state, so we need to preserve
1276 arg = xstrdup (arg);
1279 make_cleanup (xfree, arg);
1283 map_breakpoint_numbers (arg, do_map_commands_command, &info);
1285 if (info.cmd == NULL)
1286 error (_("No breakpoints specified."));
1288 do_cleanups (cleanups);
1292 commands_command (char *arg, int from_tty)
1294 commands_command_1 (arg, from_tty, NULL);
1297 /* Like commands_command, but instead of reading the commands from
1298 input stream, takes them from an already parsed command structure.
1300 This is used by cli-script.c to DTRT with breakpoint commands
1301 that are part of if and while bodies. */
1302 enum command_control_type
1303 commands_from_control_command (char *arg, struct command_line *cmd)
1305 commands_command_1 (arg, 0, cmd);
1306 return simple_control;
1309 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1312 bp_location_has_shadow (struct bp_location *bl)
1314 if (bl->loc_type != bp_loc_software_breakpoint)
1318 if (bl->target_info.shadow_len == 0)
1319 /* BL isn't valid, or doesn't shadow memory. */
1324 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1325 by replacing any memory breakpoints with their shadowed contents.
1327 If READBUF is not NULL, this buffer must not overlap with any of
1328 the breakpoint location's shadow_contents buffers. Otherwise,
1329 a failed assertion internal error will be raised.
1331 The range of shadowed area by each bp_location is:
1332 bl->address - bp_location_placed_address_before_address_max
1333 up to bl->address + bp_location_shadow_len_after_address_max
1334 The range we were requested to resolve shadows for is:
1335 memaddr ... memaddr + len
1336 Thus the safe cutoff boundaries for performance optimization are
1337 memaddr + len <= (bl->address
1338 - bp_location_placed_address_before_address_max)
1340 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1343 breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf,
1344 const gdb_byte *writebuf_org,
1345 ULONGEST memaddr, LONGEST len)
1347 /* Left boundary, right boundary and median element of our binary
1349 unsigned bc_l, bc_r, bc;
1351 /* Find BC_L which is a leftmost element which may affect BUF
1352 content. It is safe to report lower value but a failure to
1353 report higher one. */
1356 bc_r = bp_location_count;
1357 while (bc_l + 1 < bc_r)
1359 struct bp_location *bl;
1361 bc = (bc_l + bc_r) / 2;
1362 bl = bp_location[bc];
1364 /* Check first BL->ADDRESS will not overflow due to the added
1365 constant. Then advance the left boundary only if we are sure
1366 the BC element can in no way affect the BUF content (MEMADDR
1367 to MEMADDR + LEN range).
1369 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1370 offset so that we cannot miss a breakpoint with its shadow
1371 range tail still reaching MEMADDR. */
1373 if ((bl->address + bp_location_shadow_len_after_address_max
1375 && (bl->address + bp_location_shadow_len_after_address_max
1382 /* Due to the binary search above, we need to make sure we pick the
1383 first location that's at BC_L's address. E.g., if there are
1384 multiple locations at the same address, BC_L may end up pointing
1385 at a duplicate location, and miss the "master"/"inserted"
1386 location. Say, given locations L1, L2 and L3 at addresses A and
1389 L1@A, L2@A, L3@B, ...
1391 BC_L could end up pointing at location L2, while the "master"
1392 location could be L1. Since the `loc->inserted' flag is only set
1393 on "master" locations, we'd forget to restore the shadow of L1
1396 && bp_location[bc_l]->address == bp_location[bc_l - 1]->address)
1399 /* Now do full processing of the found relevant range of elements. */
1401 for (bc = bc_l; bc < bp_location_count; bc++)
1403 struct bp_location *bl = bp_location[bc];
1404 CORE_ADDR bp_addr = 0;
1408 /* bp_location array has BL->OWNER always non-NULL. */
1409 if (bl->owner->type == bp_none)
1410 warning (_("reading through apparently deleted breakpoint #%d?"),
1413 /* Performance optimization: any further element can no longer affect BUF
1416 if (bl->address >= bp_location_placed_address_before_address_max
1417 && memaddr + len <= (bl->address
1418 - bp_location_placed_address_before_address_max))
1421 if (!bp_location_has_shadow (bl))
1423 if (!breakpoint_address_match (bl->target_info.placed_address_space, 0,
1424 current_program_space->aspace, 0))
1427 /* Addresses and length of the part of the breakpoint that
1429 bp_addr = bl->target_info.placed_address;
1430 bp_size = bl->target_info.shadow_len;
1432 if (bp_addr + bp_size <= memaddr)
1433 /* The breakpoint is entirely before the chunk of memory we
1437 if (bp_addr >= memaddr + len)
1438 /* The breakpoint is entirely after the chunk of memory we are
1442 /* Offset within shadow_contents. */
1443 if (bp_addr < memaddr)
1445 /* Only copy the second part of the breakpoint. */
1446 bp_size -= memaddr - bp_addr;
1447 bptoffset = memaddr - bp_addr;
1451 if (bp_addr + bp_size > memaddr + len)
1453 /* Only copy the first part of the breakpoint. */
1454 bp_size -= (bp_addr + bp_size) - (memaddr + len);
1457 if (readbuf != NULL)
1459 /* Verify that the readbuf buffer does not overlap with
1460 the shadow_contents buffer. */
1461 gdb_assert (bl->target_info.shadow_contents >= readbuf + len
1462 || readbuf >= (bl->target_info.shadow_contents
1463 + bl->target_info.shadow_len));
1465 /* Update the read buffer with this inserted breakpoint's
1467 memcpy (readbuf + bp_addr - memaddr,
1468 bl->target_info.shadow_contents + bptoffset, bp_size);
1472 struct gdbarch *gdbarch = bl->gdbarch;
1473 const unsigned char *bp;
1474 CORE_ADDR placed_address = bl->target_info.placed_address;
1475 unsigned placed_size = bl->target_info.placed_size;
1477 /* Update the shadow with what we want to write to memory. */
1478 memcpy (bl->target_info.shadow_contents + bptoffset,
1479 writebuf_org + bp_addr - memaddr, bp_size);
1481 /* Determine appropriate breakpoint contents and size for this
1483 bp = gdbarch_breakpoint_from_pc (gdbarch, &placed_address, &placed_size);
1485 /* Update the final write buffer with this inserted
1486 breakpoint's INSN. */
1487 memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size);
1493 /* Return true if BPT is either a software breakpoint or a hardware
1497 is_breakpoint (const struct breakpoint *bpt)
1499 return (bpt->type == bp_breakpoint
1500 || bpt->type == bp_hardware_breakpoint
1501 || bpt->type == bp_dprintf);
1504 /* Return true if BPT is of any hardware watchpoint kind. */
1507 is_hardware_watchpoint (const struct breakpoint *bpt)
1509 return (bpt->type == bp_hardware_watchpoint
1510 || bpt->type == bp_read_watchpoint
1511 || bpt->type == bp_access_watchpoint);
1514 /* Return true if BPT is of any watchpoint kind, hardware or
1518 is_watchpoint (const struct breakpoint *bpt)
1520 return (is_hardware_watchpoint (bpt)
1521 || bpt->type == bp_watchpoint);
1524 /* Returns true if the current thread and its running state are safe
1525 to evaluate or update watchpoint B. Watchpoints on local
1526 expressions need to be evaluated in the context of the thread that
1527 was current when the watchpoint was created, and, that thread needs
1528 to be stopped to be able to select the correct frame context.
1529 Watchpoints on global expressions can be evaluated on any thread,
1530 and in any state. It is presently left to the target allowing
1531 memory accesses when threads are running. */
1534 watchpoint_in_thread_scope (struct watchpoint *b)
1536 return (b->base.pspace == current_program_space
1537 && (ptid_equal (b->watchpoint_thread, null_ptid)
1538 || (ptid_equal (inferior_ptid, b->watchpoint_thread)
1539 && !is_executing (inferior_ptid))));
1542 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1543 associated bp_watchpoint_scope breakpoint. */
1546 watchpoint_del_at_next_stop (struct watchpoint *w)
1548 struct breakpoint *b = &w->base;
1550 if (b->related_breakpoint != b)
1552 gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope);
1553 gdb_assert (b->related_breakpoint->related_breakpoint == b);
1554 b->related_breakpoint->disposition = disp_del_at_next_stop;
1555 b->related_breakpoint->related_breakpoint = b->related_breakpoint;
1556 b->related_breakpoint = b;
1558 b->disposition = disp_del_at_next_stop;
1561 /* Assuming that B is a watchpoint:
1562 - Reparse watchpoint expression, if REPARSE is non-zero
1563 - Evaluate expression and store the result in B->val
1564 - Evaluate the condition if there is one, and store the result
1566 - Update the list of values that must be watched in B->loc.
1568 If the watchpoint disposition is disp_del_at_next_stop, then do
1569 nothing. If this is local watchpoint that is out of scope, delete
1572 Even with `set breakpoint always-inserted on' the watchpoints are
1573 removed + inserted on each stop here. Normal breakpoints must
1574 never be removed because they might be missed by a running thread
1575 when debugging in non-stop mode. On the other hand, hardware
1576 watchpoints (is_hardware_watchpoint; processed here) are specific
1577 to each LWP since they are stored in each LWP's hardware debug
1578 registers. Therefore, such LWP must be stopped first in order to
1579 be able to modify its hardware watchpoints.
1581 Hardware watchpoints must be reset exactly once after being
1582 presented to the user. It cannot be done sooner, because it would
1583 reset the data used to present the watchpoint hit to the user. And
1584 it must not be done later because it could display the same single
1585 watchpoint hit during multiple GDB stops. Note that the latter is
1586 relevant only to the hardware watchpoint types bp_read_watchpoint
1587 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1588 not user-visible - its hit is suppressed if the memory content has
1591 The following constraints influence the location where we can reset
1592 hardware watchpoints:
1594 * target_stopped_by_watchpoint and target_stopped_data_address are
1595 called several times when GDB stops.
1598 * Multiple hardware watchpoints can be hit at the same time,
1599 causing GDB to stop. GDB only presents one hardware watchpoint
1600 hit at a time as the reason for stopping, and all the other hits
1601 are presented later, one after the other, each time the user
1602 requests the execution to be resumed. Execution is not resumed
1603 for the threads still having pending hit event stored in
1604 LWP_INFO->STATUS. While the watchpoint is already removed from
1605 the inferior on the first stop the thread hit event is kept being
1606 reported from its cached value by linux_nat_stopped_data_address
1607 until the real thread resume happens after the watchpoint gets
1608 presented and thus its LWP_INFO->STATUS gets reset.
1610 Therefore the hardware watchpoint hit can get safely reset on the
1611 watchpoint removal from inferior. */
1614 update_watchpoint (struct watchpoint *b, int reparse)
1616 int within_current_scope;
1617 struct frame_id saved_frame_id;
1620 /* If this is a local watchpoint, we only want to check if the
1621 watchpoint frame is in scope if the current thread is the thread
1622 that was used to create the watchpoint. */
1623 if (!watchpoint_in_thread_scope (b))
1626 if (b->base.disposition == disp_del_at_next_stop)
1631 /* Determine if the watchpoint is within scope. */
1632 if (b->exp_valid_block == NULL)
1633 within_current_scope = 1;
1636 struct frame_info *fi = get_current_frame ();
1637 struct gdbarch *frame_arch = get_frame_arch (fi);
1638 CORE_ADDR frame_pc = get_frame_pc (fi);
1640 /* If we're in a function epilogue, unwinding may not work
1641 properly, so do not attempt to recreate locations at this
1642 point. See similar comments in watchpoint_check. */
1643 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
1646 /* Save the current frame's ID so we can restore it after
1647 evaluating the watchpoint expression on its own frame. */
1648 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1649 took a frame parameter, so that we didn't have to change the
1652 saved_frame_id = get_frame_id (get_selected_frame (NULL));
1654 fi = frame_find_by_id (b->watchpoint_frame);
1655 within_current_scope = (fi != NULL);
1656 if (within_current_scope)
1660 /* We don't free locations. They are stored in the bp_location array
1661 and update_global_location_list will eventually delete them and
1662 remove breakpoints if needed. */
1665 if (within_current_scope && reparse)
1674 s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string;
1675 b->exp = parse_exp_1 (&s, b->exp_valid_block, 0);
1676 /* If the meaning of expression itself changed, the old value is
1677 no longer relevant. We don't want to report a watchpoint hit
1678 to the user when the old value and the new value may actually
1679 be completely different objects. */
1680 value_free (b->val);
1684 /* Note that unlike with breakpoints, the watchpoint's condition
1685 expression is stored in the breakpoint object, not in the
1686 locations (re)created below. */
1687 if (b->base.cond_string != NULL)
1689 if (b->cond_exp != NULL)
1691 xfree (b->cond_exp);
1695 s = b->base.cond_string;
1696 b->cond_exp = parse_exp_1 (&s, b->cond_exp_valid_block, 0);
1700 /* If we failed to parse the expression, for example because
1701 it refers to a global variable in a not-yet-loaded shared library,
1702 don't try to insert watchpoint. We don't automatically delete
1703 such watchpoint, though, since failure to parse expression
1704 is different from out-of-scope watchpoint. */
1705 if ( !target_has_execution)
1707 /* Without execution, memory can't change. No use to try and
1708 set watchpoint locations. The watchpoint will be reset when
1709 the target gains execution, through breakpoint_re_set. */
1711 else if (within_current_scope && b->exp)
1714 struct value *val_chain, *v, *result, *next;
1715 struct program_space *frame_pspace;
1717 fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain);
1719 /* Avoid setting b->val if it's already set. The meaning of
1720 b->val is 'the last value' user saw, and we should update
1721 it only if we reported that last value to user. As it
1722 happens, the code that reports it updates b->val directly.
1723 We don't keep track of the memory value for masked
1725 if (!b->val_valid && !is_masked_watchpoint (&b->base))
1731 frame_pspace = get_frame_program_space (get_selected_frame (NULL));
1733 /* Look at each value on the value chain. */
1734 for (v = val_chain; v; v = value_next (v))
1736 /* If it's a memory location, and GDB actually needed
1737 its contents to evaluate the expression, then we
1738 must watch it. If the first value returned is
1739 still lazy, that means an error occurred reading it;
1740 watch it anyway in case it becomes readable. */
1741 if (VALUE_LVAL (v) == lval_memory
1742 && (v == val_chain || ! value_lazy (v)))
1744 struct type *vtype = check_typedef (value_type (v));
1746 /* We only watch structs and arrays if user asked
1747 for it explicitly, never if they just happen to
1748 appear in the middle of some value chain. */
1750 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1751 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1755 struct bp_location *loc, **tmp;
1757 addr = value_address (v);
1758 len = TYPE_LENGTH (value_type (v));
1760 if (b->base.type == bp_read_watchpoint)
1762 else if (b->base.type == bp_access_watchpoint)
1765 loc = allocate_bp_location (&b->base);
1766 for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next))
1769 loc->gdbarch = get_type_arch (value_type (v));
1771 loc->pspace = frame_pspace;
1772 loc->address = addr;
1774 loc->watchpoint_type = type;
1779 /* Change the type of breakpoint between hardware assisted or
1780 an ordinary watchpoint depending on the hardware support
1781 and free hardware slots. REPARSE is set when the inferior
1786 enum bp_loc_type loc_type;
1787 struct bp_location *bl;
1789 reg_cnt = can_use_hardware_watchpoint (val_chain);
1793 int i, target_resources_ok, other_type_used;
1796 /* Use an exact watchpoint when there's only one memory region to be
1797 watched, and only one debug register is needed to watch it. */
1798 b->exact = target_exact_watchpoints && reg_cnt == 1;
1800 /* We need to determine how many resources are already
1801 used for all other hardware watchpoints plus this one
1802 to see if we still have enough resources to also fit
1803 this watchpoint in as well. */
1805 /* If this is a software watchpoint, we try to turn it
1806 to a hardware one -- count resources as if B was of
1807 hardware watchpoint type. */
1808 type = b->base.type;
1809 if (type == bp_watchpoint)
1810 type = bp_hardware_watchpoint;
1812 /* This watchpoint may or may not have been placed on
1813 the list yet at this point (it won't be in the list
1814 if we're trying to create it for the first time,
1815 through watch_command), so always account for it
1818 /* Count resources used by all watchpoints except B. */
1819 i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used);
1821 /* Add in the resources needed for B. */
1822 i += hw_watchpoint_use_count (&b->base);
1825 = target_can_use_hardware_watchpoint (type, i, other_type_used);
1826 if (target_resources_ok <= 0)
1828 int sw_mode = b->base.ops->works_in_software_mode (&b->base);
1830 if (target_resources_ok == 0 && !sw_mode)
1831 error (_("Target does not support this type of "
1832 "hardware watchpoint."));
1833 else if (target_resources_ok < 0 && !sw_mode)
1834 error (_("There are not enough available hardware "
1835 "resources for this watchpoint."));
1837 /* Downgrade to software watchpoint. */
1838 b->base.type = bp_watchpoint;
1842 /* If this was a software watchpoint, we've just
1843 found we have enough resources to turn it to a
1844 hardware watchpoint. Otherwise, this is a
1846 b->base.type = type;
1849 else if (!b->base.ops->works_in_software_mode (&b->base))
1850 error (_("Expression cannot be implemented with "
1851 "read/access watchpoint."));
1853 b->base.type = bp_watchpoint;
1855 loc_type = (b->base.type == bp_watchpoint? bp_loc_other
1856 : bp_loc_hardware_watchpoint);
1857 for (bl = b->base.loc; bl; bl = bl->next)
1858 bl->loc_type = loc_type;
1861 for (v = val_chain; v; v = next)
1863 next = value_next (v);
1868 /* If a software watchpoint is not watching any memory, then the
1869 above left it without any location set up. But,
1870 bpstat_stop_status requires a location to be able to report
1871 stops, so make sure there's at least a dummy one. */
1872 if (b->base.type == bp_watchpoint && b->base.loc == NULL)
1874 struct breakpoint *base = &b->base;
1875 base->loc = allocate_bp_location (base);
1876 base->loc->pspace = frame_pspace;
1877 base->loc->address = -1;
1878 base->loc->length = -1;
1879 base->loc->watchpoint_type = -1;
1882 else if (!within_current_scope)
1884 printf_filtered (_("\
1885 Watchpoint %d deleted because the program has left the block\n\
1886 in which its expression is valid.\n"),
1888 watchpoint_del_at_next_stop (b);
1891 /* Restore the selected frame. */
1893 select_frame (frame_find_by_id (saved_frame_id));
1897 /* Returns 1 iff breakpoint location should be
1898 inserted in the inferior. We don't differentiate the type of BL's owner
1899 (breakpoint vs. tracepoint), although insert_location in tracepoint's
1900 breakpoint_ops is not defined, because in insert_bp_location,
1901 tracepoint's insert_location will not be called. */
1903 should_be_inserted (struct bp_location *bl)
1905 if (bl->owner == NULL || !breakpoint_enabled (bl->owner))
1908 if (bl->owner->disposition == disp_del_at_next_stop)
1911 if (!bl->enabled || bl->shlib_disabled || bl->duplicate)
1914 if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup)
1917 /* This is set for example, when we're attached to the parent of a
1918 vfork, and have detached from the child. The child is running
1919 free, and we expect it to do an exec or exit, at which point the
1920 OS makes the parent schedulable again (and the target reports
1921 that the vfork is done). Until the child is done with the shared
1922 memory region, do not insert breakpoints in the parent, otherwise
1923 the child could still trip on the parent's breakpoints. Since
1924 the parent is blocked anyway, it won't miss any breakpoint. */
1925 if (bl->pspace->breakpoints_not_allowed)
1931 /* Same as should_be_inserted but does the check assuming
1932 that the location is not duplicated. */
1935 unduplicated_should_be_inserted (struct bp_location *bl)
1938 const int save_duplicate = bl->duplicate;
1941 result = should_be_inserted (bl);
1942 bl->duplicate = save_duplicate;
1946 /* Parses a conditional described by an expression COND into an
1947 agent expression bytecode suitable for evaluation
1948 by the bytecode interpreter. Return NULL if there was
1949 any error during parsing. */
1951 static struct agent_expr *
1952 parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond)
1954 struct agent_expr *aexpr = NULL;
1955 struct cleanup *old_chain = NULL;
1956 volatile struct gdb_exception ex;
1961 /* We don't want to stop processing, so catch any errors
1962 that may show up. */
1963 TRY_CATCH (ex, RETURN_MASK_ERROR)
1965 aexpr = gen_eval_for_expr (scope, cond);
1970 /* If we got here, it means the condition could not be parsed to a valid
1971 bytecode expression and thus can't be evaluated on the target's side.
1972 It's no use iterating through the conditions. */
1976 /* We have a valid agent expression. */
1980 /* Based on location BL, create a list of breakpoint conditions to be
1981 passed on to the target. If we have duplicated locations with different
1982 conditions, we will add such conditions to the list. The idea is that the
1983 target will evaluate the list of conditions and will only notify GDB when
1984 one of them is true. */
1987 build_target_condition_list (struct bp_location *bl)
1989 struct bp_location **locp = NULL, **loc2p;
1990 int null_condition_or_parse_error = 0;
1991 int modified = bl->needs_update;
1992 struct bp_location *loc;
1994 /* This is only meaningful if the target is
1995 evaluating conditions and if the user has
1996 opted for condition evaluation on the target's
1998 if (gdb_evaluates_breakpoint_condition_p ()
1999 || !target_supports_evaluation_of_breakpoint_conditions ())
2002 /* Do a first pass to check for locations with no assigned
2003 conditions or conditions that fail to parse to a valid agent expression
2004 bytecode. If any of these happen, then it's no use to send conditions
2005 to the target since this location will always trigger and generate a
2006 response back to GDB. */
2007 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2010 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2014 struct agent_expr *aexpr;
2016 /* Re-parse the conditions since something changed. In that
2017 case we already freed the condition bytecodes (see
2018 force_breakpoint_reinsertion). We just
2019 need to parse the condition to bytecodes again. */
2020 aexpr = parse_cond_to_aexpr (bl->address, loc->cond);
2021 loc->cond_bytecode = aexpr;
2023 /* Check if we managed to parse the conditional expression
2024 correctly. If not, we will not send this condition
2030 /* If we have a NULL bytecode expression, it means something
2031 went wrong or we have a null condition expression. */
2032 if (!loc->cond_bytecode)
2034 null_condition_or_parse_error = 1;
2040 /* If any of these happened, it means we will have to evaluate the conditions
2041 for the location's address on gdb's side. It is no use keeping bytecodes
2042 for all the other duplicate locations, thus we free all of them here.
2044 This is so we have a finer control over which locations' conditions are
2045 being evaluated by GDB or the remote stub. */
2046 if (null_condition_or_parse_error)
2048 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2051 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2053 /* Only go as far as the first NULL bytecode is
2055 if (!loc->cond_bytecode)
2058 free_agent_expr (loc->cond_bytecode);
2059 loc->cond_bytecode = NULL;
2064 /* No NULL conditions or failed bytecode generation. Build a condition list
2065 for this location's address. */
2066 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2070 && is_breakpoint (loc->owner)
2071 && loc->pspace->num == bl->pspace->num
2072 && loc->owner->enable_state == bp_enabled
2074 /* Add the condition to the vector. This will be used later to send the
2075 conditions to the target. */
2076 VEC_safe_push (agent_expr_p, bl->target_info.conditions,
2077 loc->cond_bytecode);
2083 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2084 location. Any error messages are printed to TMP_ERROR_STREAM; and
2085 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2086 Returns 0 for success, 1 if the bp_location type is not supported or
2089 NOTE drow/2003-09-09: This routine could be broken down to an
2090 object-style method for each breakpoint or catchpoint type. */
2092 insert_bp_location (struct bp_location *bl,
2093 struct ui_file *tmp_error_stream,
2094 int *disabled_breaks,
2095 int *hw_breakpoint_error)
2099 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
2102 /* Note we don't initialize bl->target_info, as that wipes out
2103 the breakpoint location's shadow_contents if the breakpoint
2104 is still inserted at that location. This in turn breaks
2105 target_read_memory which depends on these buffers when
2106 a memory read is requested at the breakpoint location:
2107 Once the target_info has been wiped, we fail to see that
2108 we have a breakpoint inserted at that address and thus
2109 read the breakpoint instead of returning the data saved in
2110 the breakpoint location's shadow contents. */
2111 bl->target_info.placed_address = bl->address;
2112 bl->target_info.placed_address_space = bl->pspace->aspace;
2113 bl->target_info.length = bl->length;
2115 /* When working with target-side conditions, we must pass all the conditions
2116 for the same breakpoint address down to the target since GDB will not
2117 insert those locations. With a list of breakpoint conditions, the target
2118 can decide when to stop and notify GDB. */
2120 if (is_breakpoint (bl->owner))
2122 build_target_condition_list (bl);
2123 /* Reset the condition modification marker. */
2124 bl->needs_update = 0;
2127 if (bl->loc_type == bp_loc_software_breakpoint
2128 || bl->loc_type == bp_loc_hardware_breakpoint)
2130 if (bl->owner->type != bp_hardware_breakpoint)
2132 /* If the explicitly specified breakpoint type
2133 is not hardware breakpoint, check the memory map to see
2134 if the breakpoint address is in read only memory or not.
2136 Two important cases are:
2137 - location type is not hardware breakpoint, memory
2138 is readonly. We change the type of the location to
2139 hardware breakpoint.
2140 - location type is hardware breakpoint, memory is
2141 read-write. This means we've previously made the
2142 location hardware one, but then the memory map changed,
2145 When breakpoints are removed, remove_breakpoints will use
2146 location types we've just set here, the only possible
2147 problem is that memory map has changed during running
2148 program, but it's not going to work anyway with current
2150 struct mem_region *mr
2151 = lookup_mem_region (bl->target_info.placed_address);
2155 if (automatic_hardware_breakpoints)
2157 enum bp_loc_type new_type;
2159 if (mr->attrib.mode != MEM_RW)
2160 new_type = bp_loc_hardware_breakpoint;
2162 new_type = bp_loc_software_breakpoint;
2164 if (new_type != bl->loc_type)
2166 static int said = 0;
2168 bl->loc_type = new_type;
2171 fprintf_filtered (gdb_stdout,
2172 _("Note: automatically using "
2173 "hardware breakpoints for "
2174 "read-only addresses.\n"));
2179 else if (bl->loc_type == bp_loc_software_breakpoint
2180 && mr->attrib.mode != MEM_RW)
2181 warning (_("cannot set software breakpoint "
2182 "at readonly address %s"),
2183 paddress (bl->gdbarch, bl->address));
2187 /* First check to see if we have to handle an overlay. */
2188 if (overlay_debugging == ovly_off
2189 || bl->section == NULL
2190 || !(section_is_overlay (bl->section)))
2192 /* No overlay handling: just set the breakpoint. */
2194 val = bl->owner->ops->insert_location (bl);
2198 /* This breakpoint is in an overlay section.
2199 Shall we set a breakpoint at the LMA? */
2200 if (!overlay_events_enabled)
2202 /* Yes -- overlay event support is not active,
2203 so we must try to set a breakpoint at the LMA.
2204 This will not work for a hardware breakpoint. */
2205 if (bl->loc_type == bp_loc_hardware_breakpoint)
2206 warning (_("hardware breakpoint %d not supported in overlay!"),
2210 CORE_ADDR addr = overlay_unmapped_address (bl->address,
2212 /* Set a software (trap) breakpoint at the LMA. */
2213 bl->overlay_target_info = bl->target_info;
2214 bl->overlay_target_info.placed_address = addr;
2215 val = target_insert_breakpoint (bl->gdbarch,
2216 &bl->overlay_target_info);
2218 fprintf_unfiltered (tmp_error_stream,
2219 "Overlay breakpoint %d "
2220 "failed: in ROM?\n",
2224 /* Shall we set a breakpoint at the VMA? */
2225 if (section_is_mapped (bl->section))
2227 /* Yes. This overlay section is mapped into memory. */
2228 val = bl->owner->ops->insert_location (bl);
2232 /* No. This breakpoint will not be inserted.
2233 No error, but do not mark the bp as 'inserted'. */
2240 /* Can't set the breakpoint. */
2241 if (solib_name_from_address (bl->pspace, bl->address))
2243 /* See also: disable_breakpoints_in_shlibs. */
2245 bl->shlib_disabled = 1;
2246 observer_notify_breakpoint_modified (bl->owner);
2247 if (!*disabled_breaks)
2249 fprintf_unfiltered (tmp_error_stream,
2250 "Cannot insert breakpoint %d.\n",
2252 fprintf_unfiltered (tmp_error_stream,
2253 "Temporarily disabling shared "
2254 "library breakpoints:\n");
2256 *disabled_breaks = 1;
2257 fprintf_unfiltered (tmp_error_stream,
2258 "breakpoint #%d\n", bl->owner->number);
2262 if (bl->loc_type == bp_loc_hardware_breakpoint)
2264 *hw_breakpoint_error = 1;
2265 fprintf_unfiltered (tmp_error_stream,
2266 "Cannot insert hardware "
2272 fprintf_unfiltered (tmp_error_stream,
2273 "Cannot insert breakpoint %d.\n",
2275 fprintf_filtered (tmp_error_stream,
2276 "Error accessing memory address ");
2277 fputs_filtered (paddress (bl->gdbarch, bl->address),
2279 fprintf_filtered (tmp_error_stream, ": %s.\n",
2280 safe_strerror (val));
2291 else if (bl->loc_type == bp_loc_hardware_watchpoint
2292 /* NOTE drow/2003-09-08: This state only exists for removing
2293 watchpoints. It's not clear that it's necessary... */
2294 && bl->owner->disposition != disp_del_at_next_stop)
2296 gdb_assert (bl->owner->ops != NULL
2297 && bl->owner->ops->insert_location != NULL);
2299 val = bl->owner->ops->insert_location (bl);
2301 /* If trying to set a read-watchpoint, and it turns out it's not
2302 supported, try emulating one with an access watchpoint. */
2303 if (val == 1 && bl->watchpoint_type == hw_read)
2305 struct bp_location *loc, **loc_temp;
2307 /* But don't try to insert it, if there's already another
2308 hw_access location that would be considered a duplicate
2310 ALL_BP_LOCATIONS (loc, loc_temp)
2312 && loc->watchpoint_type == hw_access
2313 && watchpoint_locations_match (bl, loc))
2317 bl->target_info = loc->target_info;
2318 bl->watchpoint_type = hw_access;
2325 bl->watchpoint_type = hw_access;
2326 val = bl->owner->ops->insert_location (bl);
2329 /* Back to the original value. */
2330 bl->watchpoint_type = hw_read;
2334 bl->inserted = (val == 0);
2337 else if (bl->owner->type == bp_catchpoint)
2339 gdb_assert (bl->owner->ops != NULL
2340 && bl->owner->ops->insert_location != NULL);
2342 val = bl->owner->ops->insert_location (bl);
2345 bl->owner->enable_state = bp_disabled;
2349 Error inserting catchpoint %d: Your system does not support this type\n\
2350 of catchpoint."), bl->owner->number);
2352 warning (_("Error inserting catchpoint %d."), bl->owner->number);
2355 bl->inserted = (val == 0);
2357 /* We've already printed an error message if there was a problem
2358 inserting this catchpoint, and we've disabled the catchpoint,
2359 so just return success. */
2366 /* This function is called when program space PSPACE is about to be
2367 deleted. It takes care of updating breakpoints to not reference
2371 breakpoint_program_space_exit (struct program_space *pspace)
2373 struct breakpoint *b, *b_temp;
2374 struct bp_location *loc, **loc_temp;
2376 /* Remove any breakpoint that was set through this program space. */
2377 ALL_BREAKPOINTS_SAFE (b, b_temp)
2379 if (b->pspace == pspace)
2380 delete_breakpoint (b);
2383 /* Breakpoints set through other program spaces could have locations
2384 bound to PSPACE as well. Remove those. */
2385 ALL_BP_LOCATIONS (loc, loc_temp)
2387 struct bp_location *tmp;
2389 if (loc->pspace == pspace)
2391 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2392 if (loc->owner->loc == loc)
2393 loc->owner->loc = loc->next;
2395 for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next)
2396 if (tmp->next == loc)
2398 tmp->next = loc->next;
2404 /* Now update the global location list to permanently delete the
2405 removed locations above. */
2406 update_global_location_list (0);
2409 /* Make sure all breakpoints are inserted in inferior.
2410 Throws exception on any error.
2411 A breakpoint that is already inserted won't be inserted
2412 again, so calling this function twice is safe. */
2414 insert_breakpoints (void)
2416 struct breakpoint *bpt;
2418 ALL_BREAKPOINTS (bpt)
2419 if (is_hardware_watchpoint (bpt))
2421 struct watchpoint *w = (struct watchpoint *) bpt;
2423 update_watchpoint (w, 0 /* don't reparse. */);
2426 update_global_location_list (1);
2428 /* update_global_location_list does not insert breakpoints when
2429 always_inserted_mode is not enabled. Explicitly insert them
2431 if (!breakpoints_always_inserted_mode ())
2432 insert_breakpoint_locations ();
2435 /* Invoke CALLBACK for each of bp_location. */
2438 iterate_over_bp_locations (walk_bp_location_callback callback)
2440 struct bp_location *loc, **loc_tmp;
2442 ALL_BP_LOCATIONS (loc, loc_tmp)
2444 callback (loc, NULL);
2448 /* This is used when we need to synch breakpoint conditions between GDB and the
2449 target. It is the case with deleting and disabling of breakpoints when using
2450 always-inserted mode. */
2453 update_inserted_breakpoint_locations (void)
2455 struct bp_location *bl, **blp_tmp;
2458 int disabled_breaks = 0;
2459 int hw_breakpoint_error = 0;
2461 struct ui_file *tmp_error_stream = mem_fileopen ();
2462 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
2464 /* Explicitly mark the warning -- this will only be printed if
2465 there was an error. */
2466 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
2468 save_current_space_and_thread ();
2470 ALL_BP_LOCATIONS (bl, blp_tmp)
2472 /* We only want to update software breakpoints and hardware
2474 if (!is_breakpoint (bl->owner))
2477 /* We only want to update locations that are already inserted
2478 and need updating. This is to avoid unwanted insertion during
2479 deletion of breakpoints. */
2480 if (!bl->inserted || (bl->inserted && !bl->needs_update))
2483 switch_to_program_space_and_thread (bl->pspace);
2485 /* For targets that support global breakpoints, there's no need
2486 to select an inferior to insert breakpoint to. In fact, even
2487 if we aren't attached to any process yet, we should still
2488 insert breakpoints. */
2489 if (!gdbarch_has_global_breakpoints (target_gdbarch)
2490 && ptid_equal (inferior_ptid, null_ptid))
2493 val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
2494 &hw_breakpoint_error);
2501 target_terminal_ours_for_output ();
2502 error_stream (tmp_error_stream);
2505 do_cleanups (cleanups);
2508 /* Used when starting or continuing the program. */
2511 insert_breakpoint_locations (void)
2513 struct breakpoint *bpt;
2514 struct bp_location *bl, **blp_tmp;
2517 int disabled_breaks = 0;
2518 int hw_breakpoint_error = 0;
2520 struct ui_file *tmp_error_stream = mem_fileopen ();
2521 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
2523 /* Explicitly mark the warning -- this will only be printed if
2524 there was an error. */
2525 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
2527 save_current_space_and_thread ();
2529 ALL_BP_LOCATIONS (bl, blp_tmp)
2531 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
2534 /* There is no point inserting thread-specific breakpoints if
2535 the thread no longer exists. ALL_BP_LOCATIONS bp_location
2536 has BL->OWNER always non-NULL. */
2537 if (bl->owner->thread != -1
2538 && !valid_thread_id (bl->owner->thread))
2541 switch_to_program_space_and_thread (bl->pspace);
2543 /* For targets that support global breakpoints, there's no need
2544 to select an inferior to insert breakpoint to. In fact, even
2545 if we aren't attached to any process yet, we should still
2546 insert breakpoints. */
2547 if (!gdbarch_has_global_breakpoints (target_gdbarch)
2548 && ptid_equal (inferior_ptid, null_ptid))
2551 val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
2552 &hw_breakpoint_error);
2557 /* If we failed to insert all locations of a watchpoint, remove
2558 them, as half-inserted watchpoint is of limited use. */
2559 ALL_BREAKPOINTS (bpt)
2561 int some_failed = 0;
2562 struct bp_location *loc;
2564 if (!is_hardware_watchpoint (bpt))
2567 if (!breakpoint_enabled (bpt))
2570 if (bpt->disposition == disp_del_at_next_stop)
2573 for (loc = bpt->loc; loc; loc = loc->next)
2574 if (!loc->inserted && should_be_inserted (loc))
2581 for (loc = bpt->loc; loc; loc = loc->next)
2583 remove_breakpoint (loc, mark_uninserted);
2585 hw_breakpoint_error = 1;
2586 fprintf_unfiltered (tmp_error_stream,
2587 "Could not insert hardware watchpoint %d.\n",
2595 /* If a hardware breakpoint or watchpoint was inserted, add a
2596 message about possibly exhausted resources. */
2597 if (hw_breakpoint_error)
2599 fprintf_unfiltered (tmp_error_stream,
2600 "Could not insert hardware breakpoints:\n\
2601 You may have requested too many hardware breakpoints/watchpoints.\n");
2603 target_terminal_ours_for_output ();
2604 error_stream (tmp_error_stream);
2607 do_cleanups (cleanups);
2610 /* Used when the program stops.
2611 Returns zero if successful, or non-zero if there was a problem
2612 removing a breakpoint location. */
2615 remove_breakpoints (void)
2617 struct bp_location *bl, **blp_tmp;
2620 ALL_BP_LOCATIONS (bl, blp_tmp)
2622 if (bl->inserted && !is_tracepoint (bl->owner))
2623 val |= remove_breakpoint (bl, mark_uninserted);
2628 /* Remove breakpoints of process PID. */
2631 remove_breakpoints_pid (int pid)
2633 struct bp_location *bl, **blp_tmp;
2635 struct inferior *inf = find_inferior_pid (pid);
2637 ALL_BP_LOCATIONS (bl, blp_tmp)
2639 if (bl->pspace != inf->pspace)
2644 val = remove_breakpoint (bl, mark_uninserted);
2653 reattach_breakpoints (int pid)
2655 struct cleanup *old_chain;
2656 struct bp_location *bl, **blp_tmp;
2658 struct ui_file *tmp_error_stream;
2659 int dummy1 = 0, dummy2 = 0;
2660 struct inferior *inf;
2661 struct thread_info *tp;
2663 tp = any_live_thread_of_process (pid);
2667 inf = find_inferior_pid (pid);
2668 old_chain = save_inferior_ptid ();
2670 inferior_ptid = tp->ptid;
2672 tmp_error_stream = mem_fileopen ();
2673 make_cleanup_ui_file_delete (tmp_error_stream);
2675 ALL_BP_LOCATIONS (bl, blp_tmp)
2677 if (bl->pspace != inf->pspace)
2683 val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2);
2686 do_cleanups (old_chain);
2691 do_cleanups (old_chain);
2695 static int internal_breakpoint_number = -1;
2697 /* Set the breakpoint number of B, depending on the value of INTERNAL.
2698 If INTERNAL is non-zero, the breakpoint number will be populated
2699 from internal_breakpoint_number and that variable decremented.
2700 Otherwise the breakpoint number will be populated from
2701 breakpoint_count and that value incremented. Internal breakpoints
2702 do not set the internal var bpnum. */
2704 set_breakpoint_number (int internal, struct breakpoint *b)
2707 b->number = internal_breakpoint_number--;
2710 set_breakpoint_count (breakpoint_count + 1);
2711 b->number = breakpoint_count;
2715 static struct breakpoint *
2716 create_internal_breakpoint (struct gdbarch *gdbarch,
2717 CORE_ADDR address, enum bptype type,
2718 const struct breakpoint_ops *ops)
2720 struct symtab_and_line sal;
2721 struct breakpoint *b;
2723 init_sal (&sal); /* Initialize to zeroes. */
2726 sal.section = find_pc_overlay (sal.pc);
2727 sal.pspace = current_program_space;
2729 b = set_raw_breakpoint (gdbarch, sal, type, ops);
2730 b->number = internal_breakpoint_number--;
2731 b->disposition = disp_donttouch;
2736 static const char *const longjmp_names[] =
2738 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
2740 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
2742 /* Per-objfile data private to breakpoint.c. */
2743 struct breakpoint_objfile_data
2745 /* Minimal symbol for "_ovly_debug_event" (if any). */
2746 struct minimal_symbol *overlay_msym;
2748 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
2749 struct minimal_symbol *longjmp_msym[NUM_LONGJMP_NAMES];
2751 /* True if we have looked for longjmp probes. */
2752 int longjmp_searched;
2754 /* SystemTap probe points for longjmp (if any). */
2755 VEC (probe_p) *longjmp_probes;
2757 /* Minimal symbol for "std::terminate()" (if any). */
2758 struct minimal_symbol *terminate_msym;
2760 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
2761 struct minimal_symbol *exception_msym;
2763 /* True if we have looked for exception probes. */
2764 int exception_searched;
2766 /* SystemTap probe points for unwinding (if any). */
2767 VEC (probe_p) *exception_probes;
2770 static const struct objfile_data *breakpoint_objfile_key;
2772 /* Minimal symbol not found sentinel. */
2773 static struct minimal_symbol msym_not_found;
2775 /* Returns TRUE if MSYM point to the "not found" sentinel. */
2778 msym_not_found_p (const struct minimal_symbol *msym)
2780 return msym == &msym_not_found;
2783 /* Return per-objfile data needed by breakpoint.c.
2784 Allocate the data if necessary. */
2786 static struct breakpoint_objfile_data *
2787 get_breakpoint_objfile_data (struct objfile *objfile)
2789 struct breakpoint_objfile_data *bp_objfile_data;
2791 bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key);
2792 if (bp_objfile_data == NULL)
2794 bp_objfile_data = obstack_alloc (&objfile->objfile_obstack,
2795 sizeof (*bp_objfile_data));
2797 memset (bp_objfile_data, 0, sizeof (*bp_objfile_data));
2798 set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data);
2800 return bp_objfile_data;
2804 free_breakpoint_probes (struct objfile *obj, void *data)
2806 struct breakpoint_objfile_data *bp_objfile_data = data;
2808 VEC_free (probe_p, bp_objfile_data->longjmp_probes);
2809 VEC_free (probe_p, bp_objfile_data->exception_probes);
2813 create_overlay_event_breakpoint (void)
2815 struct objfile *objfile;
2816 const char *const func_name = "_ovly_debug_event";
2818 ALL_OBJFILES (objfile)
2820 struct breakpoint *b;
2821 struct breakpoint_objfile_data *bp_objfile_data;
2824 bp_objfile_data = get_breakpoint_objfile_data (objfile);
2826 if (msym_not_found_p (bp_objfile_data->overlay_msym))
2829 if (bp_objfile_data->overlay_msym == NULL)
2831 struct minimal_symbol *m;
2833 m = lookup_minimal_symbol_text (func_name, objfile);
2836 /* Avoid future lookups in this objfile. */
2837 bp_objfile_data->overlay_msym = &msym_not_found;
2840 bp_objfile_data->overlay_msym = m;
2843 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym);
2844 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
2846 &internal_breakpoint_ops);
2847 b->addr_string = xstrdup (func_name);
2849 if (overlay_debugging == ovly_auto)
2851 b->enable_state = bp_enabled;
2852 overlay_events_enabled = 1;
2856 b->enable_state = bp_disabled;
2857 overlay_events_enabled = 0;
2860 update_global_location_list (1);
2864 create_longjmp_master_breakpoint (void)
2866 struct program_space *pspace;
2867 struct cleanup *old_chain;
2869 old_chain = save_current_program_space ();
2871 ALL_PSPACES (pspace)
2873 struct objfile *objfile;
2875 set_current_program_space (pspace);
2877 ALL_OBJFILES (objfile)
2880 struct gdbarch *gdbarch;
2881 struct breakpoint_objfile_data *bp_objfile_data;
2883 gdbarch = get_objfile_arch (objfile);
2884 if (!gdbarch_get_longjmp_target_p (gdbarch))
2887 bp_objfile_data = get_breakpoint_objfile_data (objfile);
2889 if (!bp_objfile_data->longjmp_searched)
2891 bp_objfile_data->longjmp_probes
2892 = find_probes_in_objfile (objfile, "libc", "longjmp");
2893 bp_objfile_data->longjmp_searched = 1;
2896 if (bp_objfile_data->longjmp_probes != NULL)
2899 struct probe *probe;
2900 struct gdbarch *gdbarch = get_objfile_arch (objfile);
2903 VEC_iterate (probe_p,
2904 bp_objfile_data->longjmp_probes,
2908 struct breakpoint *b;
2910 b = create_internal_breakpoint (gdbarch, probe->address,
2912 &internal_breakpoint_ops);
2913 b->addr_string = xstrdup ("-probe-stap libc:longjmp");
2914 b->enable_state = bp_disabled;
2920 for (i = 0; i < NUM_LONGJMP_NAMES; i++)
2922 struct breakpoint *b;
2923 const char *func_name;
2926 if (msym_not_found_p (bp_objfile_data->longjmp_msym[i]))
2929 func_name = longjmp_names[i];
2930 if (bp_objfile_data->longjmp_msym[i] == NULL)
2932 struct minimal_symbol *m;
2934 m = lookup_minimal_symbol_text (func_name, objfile);
2937 /* Prevent future lookups in this objfile. */
2938 bp_objfile_data->longjmp_msym[i] = &msym_not_found;
2941 bp_objfile_data->longjmp_msym[i] = m;
2944 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]);
2945 b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master,
2946 &internal_breakpoint_ops);
2947 b->addr_string = xstrdup (func_name);
2948 b->enable_state = bp_disabled;
2952 update_global_location_list (1);
2954 do_cleanups (old_chain);
2957 /* Create a master std::terminate breakpoint. */
2959 create_std_terminate_master_breakpoint (void)
2961 struct program_space *pspace;
2962 struct cleanup *old_chain;
2963 const char *const func_name = "std::terminate()";
2965 old_chain = save_current_program_space ();
2967 ALL_PSPACES (pspace)
2969 struct objfile *objfile;
2972 set_current_program_space (pspace);
2974 ALL_OBJFILES (objfile)
2976 struct breakpoint *b;
2977 struct breakpoint_objfile_data *bp_objfile_data;
2979 bp_objfile_data = get_breakpoint_objfile_data (objfile);
2981 if (msym_not_found_p (bp_objfile_data->terminate_msym))
2984 if (bp_objfile_data->terminate_msym == NULL)
2986 struct minimal_symbol *m;
2988 m = lookup_minimal_symbol (func_name, NULL, objfile);
2989 if (m == NULL || (MSYMBOL_TYPE (m) != mst_text
2990 && MSYMBOL_TYPE (m) != mst_file_text))
2992 /* Prevent future lookups in this objfile. */
2993 bp_objfile_data->terminate_msym = &msym_not_found;
2996 bp_objfile_data->terminate_msym = m;
2999 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym);
3000 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
3001 bp_std_terminate_master,
3002 &internal_breakpoint_ops);
3003 b->addr_string = xstrdup (func_name);
3004 b->enable_state = bp_disabled;
3008 update_global_location_list (1);
3010 do_cleanups (old_chain);
3013 /* Install a master breakpoint on the unwinder's debug hook. */
3016 create_exception_master_breakpoint (void)
3018 struct objfile *objfile;
3019 const char *const func_name = "_Unwind_DebugHook";
3021 ALL_OBJFILES (objfile)
3023 struct breakpoint *b;
3024 struct gdbarch *gdbarch;
3025 struct breakpoint_objfile_data *bp_objfile_data;
3028 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3030 /* We prefer the SystemTap probe point if it exists. */
3031 if (!bp_objfile_data->exception_searched)
3033 bp_objfile_data->exception_probes
3034 = find_probes_in_objfile (objfile, "libgcc", "unwind");
3035 bp_objfile_data->exception_searched = 1;
3038 if (bp_objfile_data->exception_probes != NULL)
3040 struct gdbarch *gdbarch = get_objfile_arch (objfile);
3042 struct probe *probe;
3045 VEC_iterate (probe_p,
3046 bp_objfile_data->exception_probes,
3050 struct breakpoint *b;
3052 b = create_internal_breakpoint (gdbarch, probe->address,
3053 bp_exception_master,
3054 &internal_breakpoint_ops);
3055 b->addr_string = xstrdup ("-probe-stap libgcc:unwind");
3056 b->enable_state = bp_disabled;
3062 /* Otherwise, try the hook function. */
3064 if (msym_not_found_p (bp_objfile_data->exception_msym))
3067 gdbarch = get_objfile_arch (objfile);
3069 if (bp_objfile_data->exception_msym == NULL)
3071 struct minimal_symbol *debug_hook;
3073 debug_hook = lookup_minimal_symbol (func_name, NULL, objfile);
3074 if (debug_hook == NULL)
3076 bp_objfile_data->exception_msym = &msym_not_found;
3080 bp_objfile_data->exception_msym = debug_hook;
3083 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym);
3084 addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
3086 b = create_internal_breakpoint (gdbarch, addr, bp_exception_master,
3087 &internal_breakpoint_ops);
3088 b->addr_string = xstrdup (func_name);
3089 b->enable_state = bp_disabled;
3092 update_global_location_list (1);
3096 update_breakpoints_after_exec (void)
3098 struct breakpoint *b, *b_tmp;
3099 struct bp_location *bploc, **bplocp_tmp;
3101 /* We're about to delete breakpoints from GDB's lists. If the
3102 INSERTED flag is true, GDB will try to lift the breakpoints by
3103 writing the breakpoints' "shadow contents" back into memory. The
3104 "shadow contents" are NOT valid after an exec, so GDB should not
3105 do that. Instead, the target is responsible from marking
3106 breakpoints out as soon as it detects an exec. We don't do that
3107 here instead, because there may be other attempts to delete
3108 breakpoints after detecting an exec and before reaching here. */
3109 ALL_BP_LOCATIONS (bploc, bplocp_tmp)
3110 if (bploc->pspace == current_program_space)
3111 gdb_assert (!bploc->inserted);
3113 ALL_BREAKPOINTS_SAFE (b, b_tmp)
3115 if (b->pspace != current_program_space)
3118 /* Solib breakpoints must be explicitly reset after an exec(). */
3119 if (b->type == bp_shlib_event)
3121 delete_breakpoint (b);
3125 /* JIT breakpoints must be explicitly reset after an exec(). */
3126 if (b->type == bp_jit_event)
3128 delete_breakpoint (b);
3132 /* Thread event breakpoints must be set anew after an exec(),
3133 as must overlay event and longjmp master breakpoints. */
3134 if (b->type == bp_thread_event || b->type == bp_overlay_event
3135 || b->type == bp_longjmp_master || b->type == bp_std_terminate_master
3136 || b->type == bp_exception_master)
3138 delete_breakpoint (b);
3142 /* Step-resume breakpoints are meaningless after an exec(). */
3143 if (b->type == bp_step_resume || b->type == bp_hp_step_resume)
3145 delete_breakpoint (b);
3149 /* Longjmp and longjmp-resume breakpoints are also meaningless
3151 if (b->type == bp_longjmp || b->type == bp_longjmp_resume
3152 || b->type == bp_exception || b->type == bp_exception_resume)
3154 delete_breakpoint (b);
3158 if (b->type == bp_catchpoint)
3160 /* For now, none of the bp_catchpoint breakpoints need to
3161 do anything at this point. In the future, if some of
3162 the catchpoints need to something, we will need to add
3163 a new method, and call this method from here. */
3167 /* bp_finish is a special case. The only way we ought to be able
3168 to see one of these when an exec() has happened, is if the user
3169 caught a vfork, and then said "finish". Ordinarily a finish just
3170 carries them to the call-site of the current callee, by setting
3171 a temporary bp there and resuming. But in this case, the finish
3172 will carry them entirely through the vfork & exec.
3174 We don't want to allow a bp_finish to remain inserted now. But
3175 we can't safely delete it, 'cause finish_command has a handle to
3176 the bp on a bpstat, and will later want to delete it. There's a
3177 chance (and I've seen it happen) that if we delete the bp_finish
3178 here, that its storage will get reused by the time finish_command
3179 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3180 We really must allow finish_command to delete a bp_finish.
3182 In the absence of a general solution for the "how do we know
3183 it's safe to delete something others may have handles to?"
3184 problem, what we'll do here is just uninsert the bp_finish, and
3185 let finish_command delete it.
3187 (We know the bp_finish is "doomed" in the sense that it's
3188 momentary, and will be deleted as soon as finish_command sees
3189 the inferior stopped. So it doesn't matter that the bp's
3190 address is probably bogus in the new a.out, unlike e.g., the
3191 solib breakpoints.) */
3193 if (b->type == bp_finish)
3198 /* Without a symbolic address, we have little hope of the
3199 pre-exec() address meaning the same thing in the post-exec()
3201 if (b->addr_string == NULL)
3203 delete_breakpoint (b);
3207 /* FIXME what about longjmp breakpoints? Re-create them here? */
3208 create_overlay_event_breakpoint ();
3209 create_longjmp_master_breakpoint ();
3210 create_std_terminate_master_breakpoint ();
3211 create_exception_master_breakpoint ();
3215 detach_breakpoints (int pid)
3217 struct bp_location *bl, **blp_tmp;
3219 struct cleanup *old_chain = save_inferior_ptid ();
3220 struct inferior *inf = current_inferior ();
3222 if (pid == PIDGET (inferior_ptid))
3223 error (_("Cannot detach breakpoints of inferior_ptid"));
3225 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3226 inferior_ptid = pid_to_ptid (pid);
3227 ALL_BP_LOCATIONS (bl, blp_tmp)
3229 if (bl->pspace != inf->pspace)
3233 val |= remove_breakpoint_1 (bl, mark_inserted);
3236 /* Detach single-step breakpoints as well. */
3237 detach_single_step_breakpoints ();
3239 do_cleanups (old_chain);
3243 /* Remove the breakpoint location BL from the current address space.
3244 Note that this is used to detach breakpoints from a child fork.
3245 When we get here, the child isn't in the inferior list, and neither
3246 do we have objects to represent its address space --- we should
3247 *not* look at bl->pspace->aspace here. */
3250 remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is)
3254 /* BL is never in moribund_locations by our callers. */
3255 gdb_assert (bl->owner != NULL);
3257 if (bl->owner->enable_state == bp_permanent)
3258 /* Permanent breakpoints cannot be inserted or removed. */
3261 /* The type of none suggests that owner is actually deleted.
3262 This should not ever happen. */
3263 gdb_assert (bl->owner->type != bp_none);
3265 if (bl->loc_type == bp_loc_software_breakpoint
3266 || bl->loc_type == bp_loc_hardware_breakpoint)
3268 /* "Normal" instruction breakpoint: either the standard
3269 trap-instruction bp (bp_breakpoint), or a
3270 bp_hardware_breakpoint. */
3272 /* First check to see if we have to handle an overlay. */
3273 if (overlay_debugging == ovly_off
3274 || bl->section == NULL
3275 || !(section_is_overlay (bl->section)))
3277 /* No overlay handling: just remove the breakpoint. */
3278 val = bl->owner->ops->remove_location (bl);
3282 /* This breakpoint is in an overlay section.
3283 Did we set a breakpoint at the LMA? */
3284 if (!overlay_events_enabled)
3286 /* Yes -- overlay event support is not active, so we
3287 should have set a breakpoint at the LMA. Remove it.
3289 /* Ignore any failures: if the LMA is in ROM, we will
3290 have already warned when we failed to insert it. */
3291 if (bl->loc_type == bp_loc_hardware_breakpoint)
3292 target_remove_hw_breakpoint (bl->gdbarch,
3293 &bl->overlay_target_info);
3295 target_remove_breakpoint (bl->gdbarch,
3296 &bl->overlay_target_info);
3298 /* Did we set a breakpoint at the VMA?
3299 If so, we will have marked the breakpoint 'inserted'. */
3302 /* Yes -- remove it. Previously we did not bother to
3303 remove the breakpoint if the section had been
3304 unmapped, but let's not rely on that being safe. We
3305 don't know what the overlay manager might do. */
3307 /* However, we should remove *software* breakpoints only
3308 if the section is still mapped, or else we overwrite
3309 wrong code with the saved shadow contents. */
3310 if (bl->loc_type == bp_loc_hardware_breakpoint
3311 || section_is_mapped (bl->section))
3312 val = bl->owner->ops->remove_location (bl);
3318 /* No -- not inserted, so no need to remove. No error. */
3323 /* In some cases, we might not be able to remove a breakpoint
3324 in a shared library that has already been removed, but we
3325 have not yet processed the shlib unload event. */
3326 if (val && solib_name_from_address (bl->pspace, bl->address))
3331 bl->inserted = (is == mark_inserted);
3333 else if (bl->loc_type == bp_loc_hardware_watchpoint)
3335 gdb_assert (bl->owner->ops != NULL
3336 && bl->owner->ops->remove_location != NULL);
3338 bl->inserted = (is == mark_inserted);
3339 bl->owner->ops->remove_location (bl);
3341 /* Failure to remove any of the hardware watchpoints comes here. */
3342 if ((is == mark_uninserted) && (bl->inserted))
3343 warning (_("Could not remove hardware watchpoint %d."),
3346 else if (bl->owner->type == bp_catchpoint
3347 && breakpoint_enabled (bl->owner)
3350 gdb_assert (bl->owner->ops != NULL
3351 && bl->owner->ops->remove_location != NULL);
3353 val = bl->owner->ops->remove_location (bl);
3357 bl->inserted = (is == mark_inserted);
3364 remove_breakpoint (struct bp_location *bl, insertion_state_t is)
3367 struct cleanup *old_chain;
3369 /* BL is never in moribund_locations by our callers. */
3370 gdb_assert (bl->owner != NULL);
3372 if (bl->owner->enable_state == bp_permanent)
3373 /* Permanent breakpoints cannot be inserted or removed. */
3376 /* The type of none suggests that owner is actually deleted.
3377 This should not ever happen. */
3378 gdb_assert (bl->owner->type != bp_none);
3380 old_chain = save_current_space_and_thread ();
3382 switch_to_program_space_and_thread (bl->pspace);
3384 ret = remove_breakpoint_1 (bl, is);
3386 do_cleanups (old_chain);
3390 /* Clear the "inserted" flag in all breakpoints. */
3393 mark_breakpoints_out (void)
3395 struct bp_location *bl, **blp_tmp;
3397 ALL_BP_LOCATIONS (bl, blp_tmp)
3398 if (bl->pspace == current_program_space)
3402 /* Clear the "inserted" flag in all breakpoints and delete any
3403 breakpoints which should go away between runs of the program.
3405 Plus other such housekeeping that has to be done for breakpoints
3408 Note: this function gets called at the end of a run (by
3409 generic_mourn_inferior) and when a run begins (by
3410 init_wait_for_inferior). */
3415 breakpoint_init_inferior (enum inf_context context)
3417 struct breakpoint *b, *b_tmp;
3418 struct bp_location *bl, **blp_tmp;
3420 struct program_space *pspace = current_program_space;
3422 /* If breakpoint locations are shared across processes, then there's
3424 if (gdbarch_has_global_breakpoints (target_gdbarch))
3427 ALL_BP_LOCATIONS (bl, blp_tmp)
3429 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3430 if (bl->pspace == pspace
3431 && bl->owner->enable_state != bp_permanent)
3435 ALL_BREAKPOINTS_SAFE (b, b_tmp)
3437 if (b->loc && b->loc->pspace != pspace)
3444 /* If the call dummy breakpoint is at the entry point it will
3445 cause problems when the inferior is rerun, so we better get
3448 case bp_watchpoint_scope:
3450 /* Also get rid of scope breakpoints. */
3452 case bp_shlib_event:
3454 /* Also remove solib event breakpoints. Their addresses may
3455 have changed since the last time we ran the program.
3456 Actually we may now be debugging against different target;
3457 and so the solib backend that installed this breakpoint may
3458 not be used in by the target. E.g.,
3460 (gdb) file prog-linux
3461 (gdb) run # native linux target
3464 (gdb) file prog-win.exe
3465 (gdb) tar rem :9999 # remote Windows gdbserver.
3468 case bp_step_resume:
3470 /* Also remove step-resume breakpoints. */
3472 delete_breakpoint (b);
3476 case bp_hardware_watchpoint:
3477 case bp_read_watchpoint:
3478 case bp_access_watchpoint:
3480 struct watchpoint *w = (struct watchpoint *) b;
3482 /* Likewise for watchpoints on local expressions. */
3483 if (w->exp_valid_block != NULL)
3484 delete_breakpoint (b);
3485 else if (context == inf_starting)
3487 /* Reset val field to force reread of starting value in
3488 insert_breakpoints. */
3490 value_free (w->val);
3501 /* Get rid of the moribund locations. */
3502 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix)
3503 decref_bp_location (&bl);
3504 VEC_free (bp_location_p, moribund_locations);
3507 /* These functions concern about actual breakpoints inserted in the
3508 target --- to e.g. check if we need to do decr_pc adjustment or if
3509 we need to hop over the bkpt --- so we check for address space
3510 match, not program space. */
3512 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
3513 exists at PC. It returns ordinary_breakpoint_here if it's an
3514 ordinary breakpoint, or permanent_breakpoint_here if it's a
3515 permanent breakpoint.
3516 - When continuing from a location with an ordinary breakpoint, we
3517 actually single step once before calling insert_breakpoints.
3518 - When continuing from a location with a permanent breakpoint, we
3519 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
3520 the target, to advance the PC past the breakpoint. */
3522 enum breakpoint_here
3523 breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
3525 struct bp_location *bl, **blp_tmp;
3526 int any_breakpoint_here = 0;
3528 ALL_BP_LOCATIONS (bl, blp_tmp)
3530 if (bl->loc_type != bp_loc_software_breakpoint
3531 && bl->loc_type != bp_loc_hardware_breakpoint)
3534 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3535 if ((breakpoint_enabled (bl->owner)
3536 || bl->owner->enable_state == bp_permanent)
3537 && breakpoint_location_address_match (bl, aspace, pc))
3539 if (overlay_debugging
3540 && section_is_overlay (bl->section)
3541 && !section_is_mapped (bl->section))
3542 continue; /* unmapped overlay -- can't be a match */
3543 else if (bl->owner->enable_state == bp_permanent)
3544 return permanent_breakpoint_here;
3546 any_breakpoint_here = 1;
3550 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
3553 /* Return true if there's a moribund breakpoint at PC. */
3556 moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
3558 struct bp_location *loc;
3561 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
3562 if (breakpoint_location_address_match (loc, aspace, pc))
3568 /* Returns non-zero if there's a breakpoint inserted at PC, which is
3569 inserted using regular breakpoint_chain / bp_location array
3570 mechanism. This does not check for single-step breakpoints, which
3571 are inserted and removed using direct target manipulation. */
3574 regular_breakpoint_inserted_here_p (struct address_space *aspace,
3577 struct bp_location *bl, **blp_tmp;
3579 ALL_BP_LOCATIONS (bl, blp_tmp)
3581 if (bl->loc_type != bp_loc_software_breakpoint
3582 && bl->loc_type != bp_loc_hardware_breakpoint)
3586 && breakpoint_location_address_match (bl, aspace, pc))
3588 if (overlay_debugging
3589 && section_is_overlay (bl->section)
3590 && !section_is_mapped (bl->section))
3591 continue; /* unmapped overlay -- can't be a match */
3599 /* Returns non-zero iff there's either regular breakpoint
3600 or a single step breakpoint inserted at PC. */
3603 breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
3605 if (regular_breakpoint_inserted_here_p (aspace, pc))
3608 if (single_step_breakpoint_inserted_here_p (aspace, pc))
3614 /* This function returns non-zero iff there is a software breakpoint
3618 software_breakpoint_inserted_here_p (struct address_space *aspace,
3621 struct bp_location *bl, **blp_tmp;
3623 ALL_BP_LOCATIONS (bl, blp_tmp)
3625 if (bl->loc_type != bp_loc_software_breakpoint)
3629 && breakpoint_address_match (bl->pspace->aspace, bl->address,
3632 if (overlay_debugging
3633 && section_is_overlay (bl->section)
3634 && !section_is_mapped (bl->section))
3635 continue; /* unmapped overlay -- can't be a match */
3641 /* Also check for software single-step breakpoints. */
3642 if (single_step_breakpoint_inserted_here_p (aspace, pc))
3649 hardware_watchpoint_inserted_in_range (struct address_space *aspace,
3650 CORE_ADDR addr, ULONGEST len)
3652 struct breakpoint *bpt;
3654 ALL_BREAKPOINTS (bpt)
3656 struct bp_location *loc;
3658 if (bpt->type != bp_hardware_watchpoint
3659 && bpt->type != bp_access_watchpoint)
3662 if (!breakpoint_enabled (bpt))
3665 for (loc = bpt->loc; loc; loc = loc->next)
3666 if (loc->pspace->aspace == aspace && loc->inserted)
3670 /* Check for intersection. */
3671 l = max (loc->address, addr);
3672 h = min (loc->address + loc->length, addr + len);
3680 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
3681 PC is valid for process/thread PTID. */
3684 breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc,
3687 struct bp_location *bl, **blp_tmp;
3688 /* The thread and task IDs associated to PTID, computed lazily. */
3692 ALL_BP_LOCATIONS (bl, blp_tmp)
3694 if (bl->loc_type != bp_loc_software_breakpoint
3695 && bl->loc_type != bp_loc_hardware_breakpoint)
3698 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
3699 if (!breakpoint_enabled (bl->owner)
3700 && bl->owner->enable_state != bp_permanent)
3703 if (!breakpoint_location_address_match (bl, aspace, pc))
3706 if (bl->owner->thread != -1)
3708 /* This is a thread-specific breakpoint. Check that ptid
3709 matches that thread. If thread hasn't been computed yet,
3710 it is now time to do so. */
3712 thread = pid_to_thread_id (ptid);
3713 if (bl->owner->thread != thread)
3717 if (bl->owner->task != 0)
3719 /* This is a task-specific breakpoint. Check that ptid
3720 matches that task. If task hasn't been computed yet,
3721 it is now time to do so. */
3723 task = ada_get_task_number (ptid);
3724 if (bl->owner->task != task)
3728 if (overlay_debugging
3729 && section_is_overlay (bl->section)
3730 && !section_is_mapped (bl->section))
3731 continue; /* unmapped overlay -- can't be a match */
3740 /* bpstat stuff. External routines' interfaces are documented
3744 is_catchpoint (struct breakpoint *ep)
3746 return (ep->type == bp_catchpoint);
3749 /* Frees any storage that is part of a bpstat. Does not walk the
3753 bpstat_free (bpstat bs)
3755 if (bs->old_val != NULL)
3756 value_free (bs->old_val);
3757 decref_counted_command_line (&bs->commands);
3758 decref_bp_location (&bs->bp_location_at);
3762 /* Clear a bpstat so that it says we are not at any breakpoint.
3763 Also free any storage that is part of a bpstat. */
3766 bpstat_clear (bpstat *bsp)
3783 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
3784 is part of the bpstat is copied as well. */
3787 bpstat_copy (bpstat bs)
3791 bpstat retval = NULL;
3796 for (; bs != NULL; bs = bs->next)
3798 tmp = (bpstat) xmalloc (sizeof (*tmp));
3799 memcpy (tmp, bs, sizeof (*tmp));
3800 incref_counted_command_line (tmp->commands);
3801 incref_bp_location (tmp->bp_location_at);
3802 if (bs->old_val != NULL)
3804 tmp->old_val = value_copy (bs->old_val);
3805 release_value (tmp->old_val);
3809 /* This is the first thing in the chain. */
3819 /* Find the bpstat associated with this breakpoint. */
3822 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
3827 for (; bsp != NULL; bsp = bsp->next)
3829 if (bsp->breakpoint_at == breakpoint)
3835 /* Put in *NUM the breakpoint number of the first breakpoint we are
3836 stopped at. *BSP upon return is a bpstat which points to the
3837 remaining breakpoints stopped at (but which is not guaranteed to be
3838 good for anything but further calls to bpstat_num).
3840 Return 0 if passed a bpstat which does not indicate any breakpoints.
3841 Return -1 if stopped at a breakpoint that has been deleted since
3843 Return 1 otherwise. */
3846 bpstat_num (bpstat *bsp, int *num)
3848 struct breakpoint *b;
3851 return 0; /* No more breakpoint values */
3853 /* We assume we'll never have several bpstats that correspond to a
3854 single breakpoint -- otherwise, this function might return the
3855 same number more than once and this will look ugly. */
3856 b = (*bsp)->breakpoint_at;
3857 *bsp = (*bsp)->next;
3859 return -1; /* breakpoint that's been deleted since */
3861 *num = b->number; /* We have its number */
3865 /* See breakpoint.h. */
3868 bpstat_clear_actions (void)
3870 struct thread_info *tp;
3873 if (ptid_equal (inferior_ptid, null_ptid))
3876 tp = find_thread_ptid (inferior_ptid);
3880 for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next)
3882 decref_counted_command_line (&bs->commands);
3884 if (bs->old_val != NULL)
3886 value_free (bs->old_val);
3892 /* Called when a command is about to proceed the inferior. */
3895 breakpoint_about_to_proceed (void)
3897 if (!ptid_equal (inferior_ptid, null_ptid))
3899 struct thread_info *tp = inferior_thread ();
3901 /* Allow inferior function calls in breakpoint commands to not
3902 interrupt the command list. When the call finishes
3903 successfully, the inferior will be standing at the same
3904 breakpoint as if nothing happened. */
3905 if (tp->control.in_infcall)
3909 breakpoint_proceeded = 1;
3912 /* Stub for cleaning up our state if we error-out of a breakpoint
3915 cleanup_executing_breakpoints (void *ignore)
3917 executing_breakpoint_commands = 0;
3920 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
3921 or its equivalent. */
3924 command_line_is_silent (struct command_line *cmd)
3926 return cmd && (strcmp ("silent", cmd->line) == 0
3927 || (xdb_commands && strcmp ("Q", cmd->line) == 0));
3930 /* Execute all the commands associated with all the breakpoints at
3931 this location. Any of these commands could cause the process to
3932 proceed beyond this point, etc. We look out for such changes by
3933 checking the global "breakpoint_proceeded" after each command.
3935 Returns true if a breakpoint command resumed the inferior. In that
3936 case, it is the caller's responsibility to recall it again with the
3937 bpstat of the current thread. */
3940 bpstat_do_actions_1 (bpstat *bsp)
3943 struct cleanup *old_chain;
3946 /* Avoid endless recursion if a `source' command is contained
3948 if (executing_breakpoint_commands)
3951 executing_breakpoint_commands = 1;
3952 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
3954 prevent_dont_repeat ();
3956 /* This pointer will iterate over the list of bpstat's. */
3959 breakpoint_proceeded = 0;
3960 for (; bs != NULL; bs = bs->next)
3962 struct counted_command_line *ccmd;
3963 struct command_line *cmd;
3964 struct cleanup *this_cmd_tree_chain;
3966 /* Take ownership of the BSP's command tree, if it has one.
3968 The command tree could legitimately contain commands like
3969 'step' and 'next', which call clear_proceed_status, which
3970 frees stop_bpstat's command tree. To make sure this doesn't
3971 free the tree we're executing out from under us, we need to
3972 take ownership of the tree ourselves. Since a given bpstat's
3973 commands are only executed once, we don't need to copy it; we
3974 can clear the pointer in the bpstat, and make sure we free
3975 the tree when we're done. */
3976 ccmd = bs->commands;
3977 bs->commands = NULL;
3978 this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd);
3979 cmd = ccmd ? ccmd->commands : NULL;
3980 if (command_line_is_silent (cmd))
3982 /* The action has been already done by bpstat_stop_status. */
3988 execute_control_command (cmd);
3990 if (breakpoint_proceeded)
3996 /* We can free this command tree now. */
3997 do_cleanups (this_cmd_tree_chain);
3999 if (breakpoint_proceeded)
4001 if (target_can_async_p ())
4002 /* If we are in async mode, then the target might be still
4003 running, not stopped at any breakpoint, so nothing for
4004 us to do here -- just return to the event loop. */
4007 /* In sync mode, when execute_control_command returns
4008 we're already standing on the next breakpoint.
4009 Breakpoint commands for that stop were not run, since
4010 execute_command does not run breakpoint commands --
4011 only command_line_handler does, but that one is not
4012 involved in execution of breakpoint commands. So, we
4013 can now execute breakpoint commands. It should be
4014 noted that making execute_command do bpstat actions is
4015 not an option -- in this case we'll have recursive
4016 invocation of bpstat for each breakpoint with a
4017 command, and can easily blow up GDB stack. Instead, we
4018 return true, which will trigger the caller to recall us
4019 with the new stop_bpstat. */
4024 do_cleanups (old_chain);
4029 bpstat_do_actions (void)
4031 struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup ();
4033 /* Do any commands attached to breakpoint we are stopped at. */
4034 while (!ptid_equal (inferior_ptid, null_ptid)
4035 && target_has_execution
4036 && !is_exited (inferior_ptid)
4037 && !is_executing (inferior_ptid))
4038 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4039 and only return when it is stopped at the next breakpoint, we
4040 keep doing breakpoint actions until it returns false to
4041 indicate the inferior was not resumed. */
4042 if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat))
4045 discard_cleanups (cleanup_if_error);
4048 /* Print out the (old or new) value associated with a watchpoint. */
4051 watchpoint_value_print (struct value *val, struct ui_file *stream)
4054 fprintf_unfiltered (stream, _("<unreadable>"));
4057 struct value_print_options opts;
4058 get_user_print_options (&opts);
4059 value_print (val, stream, &opts);
4063 /* Generic routine for printing messages indicating why we
4064 stopped. The behavior of this function depends on the value
4065 'print_it' in the bpstat structure. Under some circumstances we
4066 may decide not to print anything here and delegate the task to
4069 static enum print_stop_action
4070 print_bp_stop_message (bpstat bs)
4072 switch (bs->print_it)
4075 /* Nothing should be printed for this bpstat entry. */
4076 return PRINT_UNKNOWN;
4080 /* We still want to print the frame, but we already printed the
4081 relevant messages. */
4082 return PRINT_SRC_AND_LOC;
4085 case print_it_normal:
4087 struct breakpoint *b = bs->breakpoint_at;
4089 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4090 which has since been deleted. */
4092 return PRINT_UNKNOWN;
4094 /* Normal case. Call the breakpoint's print_it method. */
4095 return b->ops->print_it (bs);
4100 internal_error (__FILE__, __LINE__,
4101 _("print_bp_stop_message: unrecognized enum value"));
4106 /* A helper function that prints a shared library stopped event. */
4109 print_solib_event (int is_catchpoint)
4112 = !VEC_empty (char_ptr, current_program_space->deleted_solibs);
4114 = !VEC_empty (so_list_ptr, current_program_space->added_solibs);
4118 if (any_added || any_deleted)
4119 ui_out_text (current_uiout,
4120 _("Stopped due to shared library event:\n"));
4122 ui_out_text (current_uiout,
4123 _("Stopped due to shared library event (no "
4124 "libraries added or removed)\n"));
4127 if (ui_out_is_mi_like_p (current_uiout))
4128 ui_out_field_string (current_uiout, "reason",
4129 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT));
4133 struct cleanup *cleanup;
4137 ui_out_text (current_uiout, _(" Inferior unloaded "));
4138 cleanup = make_cleanup_ui_out_list_begin_end (current_uiout,
4141 VEC_iterate (char_ptr, current_program_space->deleted_solibs,
4146 ui_out_text (current_uiout, " ");
4147 ui_out_field_string (current_uiout, "library", name);
4148 ui_out_text (current_uiout, "\n");
4151 do_cleanups (cleanup);
4156 struct so_list *iter;
4158 struct cleanup *cleanup;
4160 ui_out_text (current_uiout, _(" Inferior loaded "));
4161 cleanup = make_cleanup_ui_out_list_begin_end (current_uiout,
4164 VEC_iterate (so_list_ptr, current_program_space->added_solibs,
4169 ui_out_text (current_uiout, " ");
4170 ui_out_field_string (current_uiout, "library", iter->so_name);
4171 ui_out_text (current_uiout, "\n");
4174 do_cleanups (cleanup);
4178 /* Print a message indicating what happened. This is called from
4179 normal_stop(). The input to this routine is the head of the bpstat
4180 list - a list of the eventpoints that caused this stop. KIND is
4181 the target_waitkind for the stopping event. This
4182 routine calls the generic print routine for printing a message
4183 about reasons for stopping. This will print (for example) the
4184 "Breakpoint n," part of the output. The return value of this
4187 PRINT_UNKNOWN: Means we printed nothing.
4188 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4189 code to print the location. An example is
4190 "Breakpoint 1, " which should be followed by
4192 PRINT_SRC_ONLY: Means we printed something, but there is no need
4193 to also print the location part of the message.
4194 An example is the catch/throw messages, which
4195 don't require a location appended to the end.
4196 PRINT_NOTHING: We have done some printing and we don't need any
4197 further info to be printed. */
4199 enum print_stop_action
4200 bpstat_print (bpstat bs, int kind)
4204 /* Maybe another breakpoint in the chain caused us to stop.
4205 (Currently all watchpoints go on the bpstat whether hit or not.
4206 That probably could (should) be changed, provided care is taken
4207 with respect to bpstat_explains_signal). */
4208 for (; bs; bs = bs->next)
4210 val = print_bp_stop_message (bs);
4211 if (val == PRINT_SRC_ONLY
4212 || val == PRINT_SRC_AND_LOC
4213 || val == PRINT_NOTHING)
4217 /* If we had hit a shared library event breakpoint,
4218 print_bp_stop_message would print out this message. If we hit an
4219 OS-level shared library event, do the same thing. */
4220 if (kind == TARGET_WAITKIND_LOADED)
4222 print_solib_event (0);
4223 return PRINT_NOTHING;
4226 /* We reached the end of the chain, or we got a null BS to start
4227 with and nothing was printed. */
4228 return PRINT_UNKNOWN;
4231 /* Evaluate the expression EXP and return 1 if value is zero. This is
4232 used inside a catch_errors to evaluate the breakpoint condition.
4233 The argument is a "struct expression *" that has been cast to a
4234 "char *" to make it pass through catch_errors. */
4237 breakpoint_cond_eval (void *exp)
4239 struct value *mark = value_mark ();
4240 int i = !value_true (evaluate_expression ((struct expression *) exp));
4242 value_free_to_mark (mark);
4246 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4249 bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer)
4253 bs = (bpstat) xmalloc (sizeof (*bs));
4255 **bs_link_pointer = bs;
4256 *bs_link_pointer = &bs->next;
4257 bs->breakpoint_at = bl->owner;
4258 bs->bp_location_at = bl;
4259 incref_bp_location (bl);
4260 /* If the condition is false, etc., don't do the commands. */
4261 bs->commands = NULL;
4263 bs->print_it = print_it_normal;
4267 /* The target has stopped with waitstatus WS. Check if any hardware
4268 watchpoints have triggered, according to the target. */
4271 watchpoints_triggered (struct target_waitstatus *ws)
4273 int stopped_by_watchpoint = target_stopped_by_watchpoint ();
4275 struct breakpoint *b;
4277 if (!stopped_by_watchpoint)
4279 /* We were not stopped by a watchpoint. Mark all watchpoints
4280 as not triggered. */
4282 if (is_hardware_watchpoint (b))
4284 struct watchpoint *w = (struct watchpoint *) b;
4286 w->watchpoint_triggered = watch_triggered_no;
4292 if (!target_stopped_data_address (¤t_target, &addr))
4294 /* We were stopped by a watchpoint, but we don't know where.
4295 Mark all watchpoints as unknown. */
4297 if (is_hardware_watchpoint (b))
4299 struct watchpoint *w = (struct watchpoint *) b;
4301 w->watchpoint_triggered = watch_triggered_unknown;
4304 return stopped_by_watchpoint;
4307 /* The target could report the data address. Mark watchpoints
4308 affected by this data address as triggered, and all others as not
4312 if (is_hardware_watchpoint (b))
4314 struct watchpoint *w = (struct watchpoint *) b;
4315 struct bp_location *loc;
4317 w->watchpoint_triggered = watch_triggered_no;
4318 for (loc = b->loc; loc; loc = loc->next)
4320 if (is_masked_watchpoint (b))
4322 CORE_ADDR newaddr = addr & w->hw_wp_mask;
4323 CORE_ADDR start = loc->address & w->hw_wp_mask;
4325 if (newaddr == start)
4327 w->watchpoint_triggered = watch_triggered_yes;
4331 /* Exact match not required. Within range is sufficient. */
4332 else if (target_watchpoint_addr_within_range (¤t_target,
4336 w->watchpoint_triggered = watch_triggered_yes;
4345 /* Possible return values for watchpoint_check (this can't be an enum
4346 because of check_errors). */
4347 /* The watchpoint has been deleted. */
4348 #define WP_DELETED 1
4349 /* The value has changed. */
4350 #define WP_VALUE_CHANGED 2
4351 /* The value has not changed. */
4352 #define WP_VALUE_NOT_CHANGED 3
4353 /* Ignore this watchpoint, no matter if the value changed or not. */
4356 #define BP_TEMPFLAG 1
4357 #define BP_HARDWAREFLAG 2
4359 /* Evaluate watchpoint condition expression and check if its value
4362 P should be a pointer to struct bpstat, but is defined as a void *
4363 in order for this function to be usable with catch_errors. */
4366 watchpoint_check (void *p)
4368 bpstat bs = (bpstat) p;
4369 struct watchpoint *b;
4370 struct frame_info *fr;
4371 int within_current_scope;
4373 /* BS is built from an existing struct breakpoint. */
4374 gdb_assert (bs->breakpoint_at != NULL);
4375 b = (struct watchpoint *) bs->breakpoint_at;
4377 /* If this is a local watchpoint, we only want to check if the
4378 watchpoint frame is in scope if the current thread is the thread
4379 that was used to create the watchpoint. */
4380 if (!watchpoint_in_thread_scope (b))
4383 if (b->exp_valid_block == NULL)
4384 within_current_scope = 1;
4387 struct frame_info *frame = get_current_frame ();
4388 struct gdbarch *frame_arch = get_frame_arch (frame);
4389 CORE_ADDR frame_pc = get_frame_pc (frame);
4391 /* in_function_epilogue_p() returns a non-zero value if we're
4392 still in the function but the stack frame has already been
4393 invalidated. Since we can't rely on the values of local
4394 variables after the stack has been destroyed, we are treating
4395 the watchpoint in that state as `not changed' without further
4396 checking. Don't mark watchpoints as changed if the current
4397 frame is in an epilogue - even if they are in some other
4398 frame, our view of the stack is likely to be wrong and
4399 frame_find_by_id could error out. */
4400 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
4403 fr = frame_find_by_id (b->watchpoint_frame);
4404 within_current_scope = (fr != NULL);
4406 /* If we've gotten confused in the unwinder, we might have
4407 returned a frame that can't describe this variable. */
4408 if (within_current_scope)
4410 struct symbol *function;
4412 function = get_frame_function (fr);
4413 if (function == NULL
4414 || !contained_in (b->exp_valid_block,
4415 SYMBOL_BLOCK_VALUE (function)))
4416 within_current_scope = 0;
4419 if (within_current_scope)
4420 /* If we end up stopping, the current frame will get selected
4421 in normal_stop. So this call to select_frame won't affect
4426 if (within_current_scope)
4428 /* We use value_{,free_to_}mark because it could be a *long*
4429 time before we return to the command level and call
4430 free_all_values. We can't call free_all_values because we
4431 might be in the middle of evaluating a function call. */
4435 struct value *new_val;
4437 if (is_masked_watchpoint (&b->base))
4438 /* Since we don't know the exact trigger address (from
4439 stopped_data_address), just tell the user we've triggered
4440 a mask watchpoint. */
4441 return WP_VALUE_CHANGED;
4443 mark = value_mark ();
4444 fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL);
4446 /* We use value_equal_contents instead of value_equal because
4447 the latter coerces an array to a pointer, thus comparing just
4448 the address of the array instead of its contents. This is
4449 not what we want. */
4450 if ((b->val != NULL) != (new_val != NULL)
4451 || (b->val != NULL && !value_equal_contents (b->val, new_val)))
4453 if (new_val != NULL)
4455 release_value (new_val);
4456 value_free_to_mark (mark);
4458 bs->old_val = b->val;
4461 return WP_VALUE_CHANGED;
4465 /* Nothing changed. */
4466 value_free_to_mark (mark);
4467 return WP_VALUE_NOT_CHANGED;
4472 struct ui_out *uiout = current_uiout;
4474 /* This seems like the only logical thing to do because
4475 if we temporarily ignored the watchpoint, then when
4476 we reenter the block in which it is valid it contains
4477 garbage (in the case of a function, it may have two
4478 garbage values, one before and one after the prologue).
4479 So we can't even detect the first assignment to it and
4480 watch after that (since the garbage may or may not equal
4481 the first value assigned). */
4482 /* We print all the stop information in
4483 breakpoint_ops->print_it, but in this case, by the time we
4484 call breakpoint_ops->print_it this bp will be deleted
4485 already. So we have no choice but print the information
4487 if (ui_out_is_mi_like_p (uiout))
4489 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
4490 ui_out_text (uiout, "\nWatchpoint ");
4491 ui_out_field_int (uiout, "wpnum", b->base.number);
4493 " deleted because the program has left the block in\n\
4494 which its expression is valid.\n");
4496 /* Make sure the watchpoint's commands aren't executed. */
4497 decref_counted_command_line (&b->base.commands);
4498 watchpoint_del_at_next_stop (b);
4504 /* Return true if it looks like target has stopped due to hitting
4505 breakpoint location BL. This function does not check if we should
4506 stop, only if BL explains the stop. */
4509 bpstat_check_location (const struct bp_location *bl,
4510 struct address_space *aspace, CORE_ADDR bp_addr,
4511 const struct target_waitstatus *ws)
4513 struct breakpoint *b = bl->owner;
4515 /* BL is from an existing breakpoint. */
4516 gdb_assert (b != NULL);
4518 return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws);
4521 /* Determine if the watched values have actually changed, and we
4522 should stop. If not, set BS->stop to 0. */
4525 bpstat_check_watchpoint (bpstat bs)
4527 const struct bp_location *bl;
4528 struct watchpoint *b;
4530 /* BS is built for existing struct breakpoint. */
4531 bl = bs->bp_location_at;
4532 gdb_assert (bl != NULL);
4533 b = (struct watchpoint *) bs->breakpoint_at;
4534 gdb_assert (b != NULL);
4537 int must_check_value = 0;
4539 if (b->base.type == bp_watchpoint)
4540 /* For a software watchpoint, we must always check the
4542 must_check_value = 1;
4543 else if (b->watchpoint_triggered == watch_triggered_yes)
4544 /* We have a hardware watchpoint (read, write, or access)
4545 and the target earlier reported an address watched by
4547 must_check_value = 1;
4548 else if (b->watchpoint_triggered == watch_triggered_unknown
4549 && b->base.type == bp_hardware_watchpoint)
4550 /* We were stopped by a hardware watchpoint, but the target could
4551 not report the data address. We must check the watchpoint's
4552 value. Access and read watchpoints are out of luck; without
4553 a data address, we can't figure it out. */
4554 must_check_value = 1;
4556 if (must_check_value)
4559 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
4561 struct cleanup *cleanups = make_cleanup (xfree, message);
4562 int e = catch_errors (watchpoint_check, bs, message,
4564 do_cleanups (cleanups);
4568 /* We've already printed what needs to be printed. */
4569 bs->print_it = print_it_done;
4573 bs->print_it = print_it_noop;
4576 case WP_VALUE_CHANGED:
4577 if (b->base.type == bp_read_watchpoint)
4579 /* There are two cases to consider here:
4581 1. We're watching the triggered memory for reads.
4582 In that case, trust the target, and always report
4583 the watchpoint hit to the user. Even though
4584 reads don't cause value changes, the value may
4585 have changed since the last time it was read, and
4586 since we're not trapping writes, we will not see
4587 those, and as such we should ignore our notion of
4590 2. We're watching the triggered memory for both
4591 reads and writes. There are two ways this may
4594 2.1. This is a target that can't break on data
4595 reads only, but can break on accesses (reads or
4596 writes), such as e.g., x86. We detect this case
4597 at the time we try to insert read watchpoints.
4599 2.2. Otherwise, the target supports read
4600 watchpoints, but, the user set an access or write
4601 watchpoint watching the same memory as this read
4604 If we're watching memory writes as well as reads,
4605 ignore watchpoint hits when we find that the
4606 value hasn't changed, as reads don't cause
4607 changes. This still gives false positives when
4608 the program writes the same value to memory as
4609 what there was already in memory (we will confuse
4610 it for a read), but it's much better than
4613 int other_write_watchpoint = 0;
4615 if (bl->watchpoint_type == hw_read)
4617 struct breakpoint *other_b;
4619 ALL_BREAKPOINTS (other_b)
4620 if (other_b->type == bp_hardware_watchpoint
4621 || other_b->type == bp_access_watchpoint)
4623 struct watchpoint *other_w =
4624 (struct watchpoint *) other_b;
4626 if (other_w->watchpoint_triggered
4627 == watch_triggered_yes)
4629 other_write_watchpoint = 1;
4635 if (other_write_watchpoint
4636 || bl->watchpoint_type == hw_access)
4638 /* We're watching the same memory for writes,
4639 and the value changed since the last time we
4640 updated it, so this trap must be for a write.
4642 bs->print_it = print_it_noop;
4647 case WP_VALUE_NOT_CHANGED:
4648 if (b->base.type == bp_hardware_watchpoint
4649 || b->base.type == bp_watchpoint)
4651 /* Don't stop: write watchpoints shouldn't fire if
4652 the value hasn't changed. */
4653 bs->print_it = print_it_noop;
4661 /* Error from catch_errors. */
4662 printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number);
4663 watchpoint_del_at_next_stop (b);
4664 /* We've already printed what needs to be printed. */
4665 bs->print_it = print_it_done;
4669 else /* must_check_value == 0 */
4671 /* This is a case where some watchpoint(s) triggered, but
4672 not at the address of this watchpoint, or else no
4673 watchpoint triggered after all. So don't print
4674 anything for this watchpoint. */
4675 bs->print_it = print_it_noop;
4682 /* Check conditions (condition proper, frame, thread and ignore count)
4683 of breakpoint referred to by BS. If we should not stop for this
4684 breakpoint, set BS->stop to 0. */
4687 bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
4689 int thread_id = pid_to_thread_id (ptid);
4690 const struct bp_location *bl;
4691 struct breakpoint *b;
4693 /* BS is built for existing struct breakpoint. */
4694 bl = bs->bp_location_at;
4695 gdb_assert (bl != NULL);
4696 b = bs->breakpoint_at;
4697 gdb_assert (b != NULL);
4699 /* Even if the target evaluated the condition on its end and notified GDB, we
4700 need to do so again since GDB does not know if we stopped due to a
4701 breakpoint or a single step breakpoint. */
4703 if (frame_id_p (b->frame_id)
4704 && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ())))
4708 int value_is_zero = 0;
4709 struct expression *cond;
4711 /* Evaluate Python breakpoints that have a "stop"
4712 method implemented. */
4713 if (b->py_bp_object)
4714 bs->stop = gdbpy_should_stop (b->py_bp_object);
4716 if (is_watchpoint (b))
4718 struct watchpoint *w = (struct watchpoint *) b;
4725 if (cond && b->disposition != disp_del_at_next_stop)
4727 int within_current_scope = 1;
4728 struct watchpoint * w;
4730 /* We use value_mark and value_free_to_mark because it could
4731 be a long time before we return to the command level and
4732 call free_all_values. We can't call free_all_values
4733 because we might be in the middle of evaluating a
4735 struct value *mark = value_mark ();
4737 if (is_watchpoint (b))
4738 w = (struct watchpoint *) b;
4742 /* Need to select the frame, with all that implies so that
4743 the conditions will have the right context. Because we
4744 use the frame, we will not see an inlined function's
4745 variables when we arrive at a breakpoint at the start
4746 of the inlined function; the current frame will be the
4748 if (w == NULL || w->cond_exp_valid_block == NULL)
4749 select_frame (get_current_frame ());
4752 struct frame_info *frame;
4754 /* For local watchpoint expressions, which particular
4755 instance of a local is being watched matters, so we
4756 keep track of the frame to evaluate the expression
4757 in. To evaluate the condition however, it doesn't
4758 really matter which instantiation of the function
4759 where the condition makes sense triggers the
4760 watchpoint. This allows an expression like "watch
4761 global if q > 10" set in `func', catch writes to
4762 global on all threads that call `func', or catch
4763 writes on all recursive calls of `func' by a single
4764 thread. We simply always evaluate the condition in
4765 the innermost frame that's executing where it makes
4766 sense to evaluate the condition. It seems
4768 frame = block_innermost_frame (w->cond_exp_valid_block);
4770 select_frame (frame);
4772 within_current_scope = 0;
4774 if (within_current_scope)
4776 = catch_errors (breakpoint_cond_eval, cond,
4777 "Error in testing breakpoint condition:\n",
4781 warning (_("Watchpoint condition cannot be tested "
4782 "in the current scope"));
4783 /* If we failed to set the right context for this
4784 watchpoint, unconditionally report it. */
4787 /* FIXME-someday, should give breakpoint #. */
4788 value_free_to_mark (mark);
4791 if (cond && value_is_zero)
4795 else if (b->thread != -1 && b->thread != thread_id)
4799 else if (b->ignore_count > 0)
4802 annotate_ignore_count_change ();
4804 /* Increase the hit count even though we don't stop. */
4806 observer_notify_breakpoint_modified (b);
4812 /* Get a bpstat associated with having just stopped at address
4813 BP_ADDR in thread PTID.
4815 Determine whether we stopped at a breakpoint, etc, or whether we
4816 don't understand this stop. Result is a chain of bpstat's such
4819 if we don't understand the stop, the result is a null pointer.
4821 if we understand why we stopped, the result is not null.
4823 Each element of the chain refers to a particular breakpoint or
4824 watchpoint at which we have stopped. (We may have stopped for
4825 several reasons concurrently.)
4827 Each element of the chain has valid next, breakpoint_at,
4828 commands, FIXME??? fields. */
4831 bpstat_stop_status (struct address_space *aspace,
4832 CORE_ADDR bp_addr, ptid_t ptid,
4833 const struct target_waitstatus *ws)
4835 struct breakpoint *b = NULL;
4836 struct bp_location *bl;
4837 struct bp_location *loc;
4838 /* First item of allocated bpstat's. */
4839 bpstat bs_head = NULL, *bs_link = &bs_head;
4840 /* Pointer to the last thing in the chain currently. */
4843 int need_remove_insert;
4846 /* First, build the bpstat chain with locations that explain a
4847 target stop, while being careful to not set the target running,
4848 as that may invalidate locations (in particular watchpoint
4849 locations are recreated). Resuming will happen here with
4850 breakpoint conditions or watchpoint expressions that include
4851 inferior function calls. */
4855 if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
4858 for (bl = b->loc; bl != NULL; bl = bl->next)
4860 /* For hardware watchpoints, we look only at the first
4861 location. The watchpoint_check function will work on the
4862 entire expression, not the individual locations. For
4863 read watchpoints, the watchpoints_triggered function has
4864 checked all locations already. */
4865 if (b->type == bp_hardware_watchpoint && bl != b->loc)
4868 if (bl->shlib_disabled)
4871 if (!bpstat_check_location (bl, aspace, bp_addr, ws))
4874 /* Come here if it's a watchpoint, or if the break address
4877 bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to
4880 /* Assume we stop. Should we find a watchpoint that is not
4881 actually triggered, or if the condition of the breakpoint
4882 evaluates as false, we'll reset 'stop' to 0. */
4886 /* If this is a scope breakpoint, mark the associated
4887 watchpoint as triggered so that we will handle the
4888 out-of-scope event. We'll get to the watchpoint next
4890 if (b->type == bp_watchpoint_scope && b->related_breakpoint != b)
4892 struct watchpoint *w = (struct watchpoint *) b->related_breakpoint;
4894 w->watchpoint_triggered = watch_triggered_yes;
4899 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
4901 if (breakpoint_location_address_match (loc, aspace, bp_addr))
4903 bs = bpstat_alloc (loc, &bs_link);
4904 /* For hits of moribund locations, we should just proceed. */
4907 bs->print_it = print_it_noop;
4911 /* A bit of special processing for shlib breakpoints. We need to
4912 process solib loading here, so that the lists of loaded and
4913 unloaded libraries are correct before we handle "catch load" and
4915 for (bs = bs_head; bs != NULL; bs = bs->next)
4917 if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event)
4919 handle_solib_event ();
4924 /* Now go through the locations that caused the target to stop, and
4925 check whether we're interested in reporting this stop to higher
4926 layers, or whether we should resume the target transparently. */
4930 for (bs = bs_head; bs != NULL; bs = bs->next)
4935 b = bs->breakpoint_at;
4936 b->ops->check_status (bs);
4939 bpstat_check_breakpoint_conditions (bs, ptid);
4944 observer_notify_breakpoint_modified (b);
4946 /* We will stop here. */
4947 if (b->disposition == disp_disable)
4949 --(b->enable_count);
4950 if (b->enable_count <= 0
4951 && b->enable_state != bp_permanent)
4952 b->enable_state = bp_disabled;
4957 bs->commands = b->commands;
4958 incref_counted_command_line (bs->commands);
4959 if (command_line_is_silent (bs->commands
4960 ? bs->commands->commands : NULL))
4966 /* Print nothing for this entry if we don't stop or don't
4968 if (!bs->stop || !bs->print)
4969 bs->print_it = print_it_noop;
4972 /* If we aren't stopping, the value of some hardware watchpoint may
4973 not have changed, but the intermediate memory locations we are
4974 watching may have. Don't bother if we're stopping; this will get
4976 need_remove_insert = 0;
4977 if (! bpstat_causes_stop (bs_head))
4978 for (bs = bs_head; bs != NULL; bs = bs->next)
4980 && bs->breakpoint_at
4981 && is_hardware_watchpoint (bs->breakpoint_at))
4983 struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at;
4985 update_watchpoint (w, 0 /* don't reparse. */);
4986 need_remove_insert = 1;
4989 if (need_remove_insert)
4990 update_global_location_list (1);
4991 else if (removed_any)
4992 update_global_location_list (0);
4998 handle_jit_event (void)
5000 struct frame_info *frame;
5001 struct gdbarch *gdbarch;
5003 /* Switch terminal for any messages produced by
5004 breakpoint_re_set. */
5005 target_terminal_ours_for_output ();
5007 frame = get_current_frame ();
5008 gdbarch = get_frame_arch (frame);
5010 jit_event_handler (gdbarch);
5012 target_terminal_inferior ();
5015 /* Handle an solib event by calling solib_add. */
5018 handle_solib_event (void)
5020 clear_program_space_solib_cache (current_inferior ()->pspace);
5022 /* Check for any newly added shared libraries if we're supposed to
5023 be adding them automatically. Switch terminal for any messages
5024 produced by breakpoint_re_set. */
5025 target_terminal_ours_for_output ();
5027 SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add);
5029 solib_add (NULL, 0, ¤t_target, auto_solib_add);
5031 target_terminal_inferior ();
5034 /* Prepare WHAT final decision for infrun. */
5036 /* Decide what infrun needs to do with this bpstat. */
5039 bpstat_what (bpstat bs_head)
5041 struct bpstat_what retval;
5045 retval.main_action = BPSTAT_WHAT_KEEP_CHECKING;
5046 retval.call_dummy = STOP_NONE;
5047 retval.is_longjmp = 0;
5049 for (bs = bs_head; bs != NULL; bs = bs->next)
5051 /* Extract this BS's action. After processing each BS, we check
5052 if its action overrides all we've seem so far. */
5053 enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING;
5056 if (bs->breakpoint_at == NULL)
5058 /* I suspect this can happen if it was a momentary
5059 breakpoint which has since been deleted. */
5063 bptype = bs->breakpoint_at->type;
5070 case bp_hardware_breakpoint:
5073 case bp_shlib_event:
5077 this_action = BPSTAT_WHAT_STOP_NOISY;
5079 this_action = BPSTAT_WHAT_STOP_SILENT;
5082 this_action = BPSTAT_WHAT_SINGLE;
5085 case bp_hardware_watchpoint:
5086 case bp_read_watchpoint:
5087 case bp_access_watchpoint:
5091 this_action = BPSTAT_WHAT_STOP_NOISY;
5093 this_action = BPSTAT_WHAT_STOP_SILENT;
5097 /* There was a watchpoint, but we're not stopping.
5098 This requires no further action. */
5103 this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME;
5104 retval.is_longjmp = bptype == bp_longjmp;
5106 case bp_longjmp_resume:
5107 case bp_exception_resume:
5108 this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME;
5109 retval.is_longjmp = bptype == bp_longjmp_resume;
5111 case bp_step_resume:
5113 this_action = BPSTAT_WHAT_STEP_RESUME;
5116 /* It is for the wrong frame. */
5117 this_action = BPSTAT_WHAT_SINGLE;
5120 case bp_hp_step_resume:
5122 this_action = BPSTAT_WHAT_HP_STEP_RESUME;
5125 /* It is for the wrong frame. */
5126 this_action = BPSTAT_WHAT_SINGLE;
5129 case bp_watchpoint_scope:
5130 case bp_thread_event:
5131 case bp_overlay_event:
5132 case bp_longjmp_master:
5133 case bp_std_terminate_master:
5134 case bp_exception_master:
5135 this_action = BPSTAT_WHAT_SINGLE;
5141 this_action = BPSTAT_WHAT_STOP_NOISY;
5143 this_action = BPSTAT_WHAT_STOP_SILENT;
5147 /* There was a catchpoint, but we're not stopping.
5148 This requires no further action. */
5153 this_action = BPSTAT_WHAT_SINGLE;
5156 /* Make sure the action is stop (silent or noisy),
5157 so infrun.c pops the dummy frame. */
5158 retval.call_dummy = STOP_STACK_DUMMY;
5159 this_action = BPSTAT_WHAT_STOP_SILENT;
5161 case bp_std_terminate:
5162 /* Make sure the action is stop (silent or noisy),
5163 so infrun.c pops the dummy frame. */
5164 retval.call_dummy = STOP_STD_TERMINATE;
5165 this_action = BPSTAT_WHAT_STOP_SILENT;
5168 case bp_fast_tracepoint:
5169 case bp_static_tracepoint:
5170 /* Tracepoint hits should not be reported back to GDB, and
5171 if one got through somehow, it should have been filtered
5173 internal_error (__FILE__, __LINE__,
5174 _("bpstat_what: tracepoint encountered"));
5176 case bp_gnu_ifunc_resolver:
5177 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5178 this_action = BPSTAT_WHAT_SINGLE;
5180 case bp_gnu_ifunc_resolver_return:
5181 /* The breakpoint will be removed, execution will restart from the
5182 PC of the former breakpoint. */
5183 this_action = BPSTAT_WHAT_KEEP_CHECKING;
5187 this_action = BPSTAT_WHAT_STOP_SILENT;
5191 internal_error (__FILE__, __LINE__,
5192 _("bpstat_what: unhandled bptype %d"), (int) bptype);
5195 retval.main_action = max (retval.main_action, this_action);
5198 /* These operations may affect the bs->breakpoint_at state so they are
5199 delayed after MAIN_ACTION is decided above. */
5204 fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n");
5206 handle_jit_event ();
5209 for (bs = bs_head; bs != NULL; bs = bs->next)
5211 struct breakpoint *b = bs->breakpoint_at;
5217 case bp_gnu_ifunc_resolver:
5218 gnu_ifunc_resolver_stop (b);
5220 case bp_gnu_ifunc_resolver_return:
5221 gnu_ifunc_resolver_return_stop (b);
5229 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5230 without hardware support). This isn't related to a specific bpstat,
5231 just to things like whether watchpoints are set. */
5234 bpstat_should_step (void)
5236 struct breakpoint *b;
5239 if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL)
5245 bpstat_causes_stop (bpstat bs)
5247 for (; bs != NULL; bs = bs->next)
5256 /* Compute a string of spaces suitable to indent the next line
5257 so it starts at the position corresponding to the table column
5258 named COL_NAME in the currently active table of UIOUT. */
5261 wrap_indent_at_field (struct ui_out *uiout, const char *col_name)
5263 static char wrap_indent[80];
5264 int i, total_width, width, align;
5268 for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++)
5270 if (strcmp (text, col_name) == 0)
5272 gdb_assert (total_width < sizeof wrap_indent);
5273 memset (wrap_indent, ' ', total_width);
5274 wrap_indent[total_width] = 0;
5279 total_width += width + 1;
5285 /* Determine if the locations of this breakpoint will have their conditions
5286 evaluated by the target, host or a mix of both. Returns the following:
5288 "host": Host evals condition.
5289 "host or target": Host or Target evals condition.
5290 "target": Target evals condition.
5294 bp_condition_evaluator (struct breakpoint *b)
5296 struct bp_location *bl;
5297 char host_evals = 0;
5298 char target_evals = 0;
5303 if (!is_breakpoint (b))
5306 if (gdb_evaluates_breakpoint_condition_p ()
5307 || !target_supports_evaluation_of_breakpoint_conditions ())
5308 return condition_evaluation_host;
5310 for (bl = b->loc; bl; bl = bl->next)
5312 if (bl->cond_bytecode)
5318 if (host_evals && target_evals)
5319 return condition_evaluation_both;
5320 else if (target_evals)
5321 return condition_evaluation_target;
5323 return condition_evaluation_host;
5326 /* Determine the breakpoint location's condition evaluator. This is
5327 similar to bp_condition_evaluator, but for locations. */
5330 bp_location_condition_evaluator (struct bp_location *bl)
5332 if (bl && !is_breakpoint (bl->owner))
5335 if (gdb_evaluates_breakpoint_condition_p ()
5336 || !target_supports_evaluation_of_breakpoint_conditions ())
5337 return condition_evaluation_host;
5339 if (bl && bl->cond_bytecode)
5340 return condition_evaluation_target;
5342 return condition_evaluation_host;
5345 /* Print the LOC location out of the list of B->LOC locations. */
5348 print_breakpoint_location (struct breakpoint *b,
5349 struct bp_location *loc)
5351 struct ui_out *uiout = current_uiout;
5352 struct cleanup *old_chain = save_current_program_space ();
5354 if (loc != NULL && loc->shlib_disabled)
5358 set_current_program_space (loc->pspace);
5360 if (b->display_canonical)
5361 ui_out_field_string (uiout, "what", b->addr_string);
5362 else if (loc && loc->source_file)
5365 = find_pc_sect_function (loc->address, loc->section);
5368 ui_out_text (uiout, "in ");
5369 ui_out_field_string (uiout, "func",
5370 SYMBOL_PRINT_NAME (sym));
5371 ui_out_text (uiout, " ");
5372 ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what"));
5373 ui_out_text (uiout, "at ");
5375 ui_out_field_string (uiout, "file", loc->source_file);
5376 ui_out_text (uiout, ":");
5378 if (ui_out_is_mi_like_p (uiout))
5380 struct symtab_and_line sal = find_pc_line (loc->address, 0);
5381 char *fullname = symtab_to_fullname (sal.symtab);
5384 ui_out_field_string (uiout, "fullname", fullname);
5387 ui_out_field_int (uiout, "line", loc->line_number);
5391 struct ui_file *stb = mem_fileopen ();
5392 struct cleanup *stb_chain = make_cleanup_ui_file_delete (stb);
5394 print_address_symbolic (loc->gdbarch, loc->address, stb,
5396 ui_out_field_stream (uiout, "at", stb);
5398 do_cleanups (stb_chain);
5401 ui_out_field_string (uiout, "pending", b->addr_string);
5403 if (loc && is_breakpoint (b)
5404 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
5405 && bp_condition_evaluator (b) == condition_evaluation_both)
5407 ui_out_text (uiout, " (");
5408 ui_out_field_string (uiout, "evaluated-by",
5409 bp_location_condition_evaluator (loc));
5410 ui_out_text (uiout, ")");
5413 do_cleanups (old_chain);
5417 bptype_string (enum bptype type)
5419 struct ep_type_description
5424 static struct ep_type_description bptypes[] =
5426 {bp_none, "?deleted?"},
5427 {bp_breakpoint, "breakpoint"},
5428 {bp_hardware_breakpoint, "hw breakpoint"},
5429 {bp_until, "until"},
5430 {bp_finish, "finish"},
5431 {bp_watchpoint, "watchpoint"},
5432 {bp_hardware_watchpoint, "hw watchpoint"},
5433 {bp_read_watchpoint, "read watchpoint"},
5434 {bp_access_watchpoint, "acc watchpoint"},
5435 {bp_longjmp, "longjmp"},
5436 {bp_longjmp_resume, "longjmp resume"},
5437 {bp_exception, "exception"},
5438 {bp_exception_resume, "exception resume"},
5439 {bp_step_resume, "step resume"},
5440 {bp_hp_step_resume, "high-priority step resume"},
5441 {bp_watchpoint_scope, "watchpoint scope"},
5442 {bp_call_dummy, "call dummy"},
5443 {bp_std_terminate, "std::terminate"},
5444 {bp_shlib_event, "shlib events"},
5445 {bp_thread_event, "thread events"},
5446 {bp_overlay_event, "overlay events"},
5447 {bp_longjmp_master, "longjmp master"},
5448 {bp_std_terminate_master, "std::terminate master"},
5449 {bp_exception_master, "exception master"},
5450 {bp_catchpoint, "catchpoint"},
5451 {bp_tracepoint, "tracepoint"},
5452 {bp_fast_tracepoint, "fast tracepoint"},
5453 {bp_static_tracepoint, "static tracepoint"},
5454 {bp_dprintf, "dprintf"},
5455 {bp_jit_event, "jit events"},
5456 {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"},
5457 {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"},
5460 if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0])))
5461 || ((int) type != bptypes[(int) type].type))
5462 internal_error (__FILE__, __LINE__,
5463 _("bptypes table does not describe type #%d."),
5466 return bptypes[(int) type].description;
5469 /* Print B to gdb_stdout. */
5472 print_one_breakpoint_location (struct breakpoint *b,
5473 struct bp_location *loc,
5475 struct bp_location **last_loc,
5478 struct command_line *l;
5479 static char bpenables[] = "nynny";
5481 struct ui_out *uiout = current_uiout;
5482 int header_of_multiple = 0;
5483 int part_of_multiple = (loc != NULL);
5484 struct value_print_options opts;
5486 get_user_print_options (&opts);
5488 gdb_assert (!loc || loc_number != 0);
5489 /* See comment in print_one_breakpoint concerning treatment of
5490 breakpoints with single disabled location. */
5493 && (b->loc->next != NULL || !b->loc->enabled)))
5494 header_of_multiple = 1;
5502 if (part_of_multiple)
5505 formatted = xstrprintf ("%d.%d", b->number, loc_number);
5506 ui_out_field_string (uiout, "number", formatted);
5511 ui_out_field_int (uiout, "number", b->number);
5516 if (part_of_multiple)
5517 ui_out_field_skip (uiout, "type");
5519 ui_out_field_string (uiout, "type", bptype_string (b->type));
5523 if (part_of_multiple)
5524 ui_out_field_skip (uiout, "disp");
5526 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
5531 if (part_of_multiple)
5532 ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n");
5534 ui_out_field_fmt (uiout, "enabled", "%c",
5535 bpenables[(int) b->enable_state]);
5536 ui_out_spaces (uiout, 2);
5540 if (b->ops != NULL && b->ops->print_one != NULL)
5542 /* Although the print_one can possibly print all locations,
5543 calling it here is not likely to get any nice result. So,
5544 make sure there's just one location. */
5545 gdb_assert (b->loc == NULL || b->loc->next == NULL);
5546 b->ops->print_one (b, last_loc);
5552 internal_error (__FILE__, __LINE__,
5553 _("print_one_breakpoint: bp_none encountered\n"));
5557 case bp_hardware_watchpoint:
5558 case bp_read_watchpoint:
5559 case bp_access_watchpoint:
5561 struct watchpoint *w = (struct watchpoint *) b;
5563 /* Field 4, the address, is omitted (which makes the columns
5564 not line up too nicely with the headers, but the effect
5565 is relatively readable). */
5566 if (opts.addressprint)
5567 ui_out_field_skip (uiout, "addr");
5569 ui_out_field_string (uiout, "what", w->exp_string);
5574 case bp_hardware_breakpoint:
5578 case bp_longjmp_resume:
5580 case bp_exception_resume:
5581 case bp_step_resume:
5582 case bp_hp_step_resume:
5583 case bp_watchpoint_scope:
5585 case bp_std_terminate:
5586 case bp_shlib_event:
5587 case bp_thread_event:
5588 case bp_overlay_event:
5589 case bp_longjmp_master:
5590 case bp_std_terminate_master:
5591 case bp_exception_master:
5593 case bp_fast_tracepoint:
5594 case bp_static_tracepoint:
5597 case bp_gnu_ifunc_resolver:
5598 case bp_gnu_ifunc_resolver_return:
5599 if (opts.addressprint)
5602 if (header_of_multiple)
5603 ui_out_field_string (uiout, "addr", "<MULTIPLE>");
5604 else if (b->loc == NULL || loc->shlib_disabled)
5605 ui_out_field_string (uiout, "addr", "<PENDING>");
5607 ui_out_field_core_addr (uiout, "addr",
5608 loc->gdbarch, loc->address);
5611 if (!header_of_multiple)
5612 print_breakpoint_location (b, loc);
5619 /* For backward compatibility, don't display inferiors unless there
5622 && !header_of_multiple
5624 || (!gdbarch_has_global_breakpoints (target_gdbarch)
5625 && (number_of_program_spaces () > 1
5626 || number_of_inferiors () > 1)
5627 /* LOC is for existing B, it cannot be in
5628 moribund_locations and thus having NULL OWNER. */
5629 && loc->owner->type != bp_catchpoint)))
5631 struct inferior *inf;
5634 for (inf = inferior_list; inf != NULL; inf = inf->next)
5636 if (inf->pspace == loc->pspace)
5641 ui_out_text (uiout, " inf ");
5644 ui_out_text (uiout, ", ");
5645 ui_out_text (uiout, plongest (inf->num));
5650 if (!part_of_multiple)
5652 if (b->thread != -1)
5654 /* FIXME: This seems to be redundant and lost here; see the
5655 "stop only in" line a little further down. */
5656 ui_out_text (uiout, " thread ");
5657 ui_out_field_int (uiout, "thread", b->thread);
5659 else if (b->task != 0)
5661 ui_out_text (uiout, " task ");
5662 ui_out_field_int (uiout, "task", b->task);
5666 ui_out_text (uiout, "\n");
5668 if (!part_of_multiple)
5669 b->ops->print_one_detail (b, uiout);
5671 if (part_of_multiple && frame_id_p (b->frame_id))
5674 ui_out_text (uiout, "\tstop only in stack frame at ");
5675 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
5677 ui_out_field_core_addr (uiout, "frame",
5678 b->gdbarch, b->frame_id.stack_addr);
5679 ui_out_text (uiout, "\n");
5682 if (!part_of_multiple && b->cond_string)
5685 if (is_tracepoint (b))
5686 ui_out_text (uiout, "\ttrace only if ");
5688 ui_out_text (uiout, "\tstop only if ");
5689 ui_out_field_string (uiout, "cond", b->cond_string);
5691 /* Print whether the target is doing the breakpoint's condition
5692 evaluation. If GDB is doing the evaluation, don't print anything. */
5693 if (is_breakpoint (b)
5694 && breakpoint_condition_evaluation_mode ()
5695 == condition_evaluation_target)
5697 ui_out_text (uiout, " (");
5698 ui_out_field_string (uiout, "evaluated-by",
5699 bp_condition_evaluator (b));
5700 ui_out_text (uiout, " evals)");
5702 ui_out_text (uiout, "\n");
5705 if (!part_of_multiple && b->thread != -1)
5707 /* FIXME should make an annotation for this. */
5708 ui_out_text (uiout, "\tstop only in thread ");
5709 ui_out_field_int (uiout, "thread", b->thread);
5710 ui_out_text (uiout, "\n");
5713 if (!part_of_multiple && b->hit_count)
5715 /* FIXME should make an annotation for this. */
5716 if (is_catchpoint (b))
5717 ui_out_text (uiout, "\tcatchpoint");
5718 else if (is_tracepoint (b))
5719 ui_out_text (uiout, "\ttracepoint");
5721 ui_out_text (uiout, "\tbreakpoint");
5722 ui_out_text (uiout, " already hit ");
5723 ui_out_field_int (uiout, "times", b->hit_count);
5724 if (b->hit_count == 1)
5725 ui_out_text (uiout, " time\n");
5727 ui_out_text (uiout, " times\n");
5730 /* Output the count also if it is zero, but only if this is mi.
5731 FIXME: Should have a better test for this. */
5732 if (ui_out_is_mi_like_p (uiout))
5733 if (!part_of_multiple && b->hit_count == 0)
5734 ui_out_field_int (uiout, "times", b->hit_count);
5736 if (!part_of_multiple && b->ignore_count)
5739 ui_out_text (uiout, "\tignore next ");
5740 ui_out_field_int (uiout, "ignore", b->ignore_count);
5741 ui_out_text (uiout, " hits\n");
5744 /* Note that an enable count of 1 corresponds to "enable once"
5745 behavior, which is reported by the combination of enablement and
5746 disposition, so we don't need to mention it here. */
5747 if (!part_of_multiple && b->enable_count > 1)
5750 ui_out_text (uiout, "\tdisable after ");
5751 /* Tweak the wording to clarify that ignore and enable counts
5752 are distinct, and have additive effect. */
5753 if (b->ignore_count)
5754 ui_out_text (uiout, "additional ");
5756 ui_out_text (uiout, "next ");
5757 ui_out_field_int (uiout, "enable", b->enable_count);
5758 ui_out_text (uiout, " hits\n");
5761 if (!part_of_multiple && is_tracepoint (b))
5763 struct tracepoint *tp = (struct tracepoint *) b;
5765 if (tp->traceframe_usage)
5767 ui_out_text (uiout, "\ttrace buffer usage ");
5768 ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage);
5769 ui_out_text (uiout, " bytes\n");
5773 l = b->commands ? b->commands->commands : NULL;
5774 if (!part_of_multiple && l)
5776 struct cleanup *script_chain;
5779 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
5780 print_command_lines (uiout, l, 4);
5781 do_cleanups (script_chain);
5784 if (is_tracepoint (b))
5786 struct tracepoint *t = (struct tracepoint *) b;
5788 if (!part_of_multiple && t->pass_count)
5790 annotate_field (10);
5791 ui_out_text (uiout, "\tpass count ");
5792 ui_out_field_int (uiout, "pass", t->pass_count);
5793 ui_out_text (uiout, " \n");
5797 if (ui_out_is_mi_like_p (uiout) && !part_of_multiple)
5799 if (is_watchpoint (b))
5801 struct watchpoint *w = (struct watchpoint *) b;
5803 ui_out_field_string (uiout, "original-location", w->exp_string);
5805 else if (b->addr_string)
5806 ui_out_field_string (uiout, "original-location", b->addr_string);
5811 print_one_breakpoint (struct breakpoint *b,
5812 struct bp_location **last_loc,
5815 struct cleanup *bkpt_chain;
5816 struct ui_out *uiout = current_uiout;
5818 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
5820 print_one_breakpoint_location (b, NULL, 0, last_loc, allflag);
5821 do_cleanups (bkpt_chain);
5823 /* If this breakpoint has custom print function,
5824 it's already printed. Otherwise, print individual
5825 locations, if any. */
5826 if (b->ops == NULL || b->ops->print_one == NULL)
5828 /* If breakpoint has a single location that is disabled, we
5829 print it as if it had several locations, since otherwise it's
5830 hard to represent "breakpoint enabled, location disabled"
5833 Note that while hardware watchpoints have several locations
5834 internally, that's not a property exposed to user. */
5836 && !is_hardware_watchpoint (b)
5837 && (b->loc->next || !b->loc->enabled))
5839 struct bp_location *loc;
5842 for (loc = b->loc; loc; loc = loc->next, ++n)
5844 struct cleanup *inner2 =
5845 make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
5846 print_one_breakpoint_location (b, loc, n, last_loc, allflag);
5847 do_cleanups (inner2);
5854 breakpoint_address_bits (struct breakpoint *b)
5856 int print_address_bits = 0;
5857 struct bp_location *loc;
5859 for (loc = b->loc; loc; loc = loc->next)
5863 /* Software watchpoints that aren't watching memory don't have
5864 an address to print. */
5865 if (b->type == bp_watchpoint && loc->watchpoint_type == -1)
5868 addr_bit = gdbarch_addr_bit (loc->gdbarch);
5869 if (addr_bit > print_address_bits)
5870 print_address_bits = addr_bit;
5873 return print_address_bits;
5876 struct captured_breakpoint_query_args
5882 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
5884 struct captured_breakpoint_query_args *args = data;
5885 struct breakpoint *b;
5886 struct bp_location *dummy_loc = NULL;
5890 if (args->bnum == b->number)
5892 print_one_breakpoint (b, &dummy_loc, 0);
5900 gdb_breakpoint_query (struct ui_out *uiout, int bnum,
5901 char **error_message)
5903 struct captured_breakpoint_query_args args;
5906 /* For the moment we don't trust print_one_breakpoint() to not throw
5908 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
5909 error_message, RETURN_MASK_ALL) < 0)
5915 /* Return true if this breakpoint was set by the user, false if it is
5916 internal or momentary. */
5919 user_breakpoint_p (struct breakpoint *b)
5921 return b->number > 0;
5924 /* Print information on user settable breakpoint (watchpoint, etc)
5925 number BNUM. If BNUM is -1 print all user-settable breakpoints.
5926 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
5927 FILTER is non-NULL, call it on each breakpoint and only include the
5928 ones for which it returns non-zero. Return the total number of
5929 breakpoints listed. */
5932 breakpoint_1 (char *args, int allflag,
5933 int (*filter) (const struct breakpoint *))
5935 struct breakpoint *b;
5936 struct bp_location *last_loc = NULL;
5937 int nr_printable_breakpoints;
5938 struct cleanup *bkpttbl_chain;
5939 struct value_print_options opts;
5940 int print_address_bits = 0;
5941 int print_type_col_width = 14;
5942 struct ui_out *uiout = current_uiout;
5944 get_user_print_options (&opts);
5946 /* Compute the number of rows in the table, as well as the size
5947 required for address fields. */
5948 nr_printable_breakpoints = 0;
5951 /* If we have a filter, only list the breakpoints it accepts. */
5952 if (filter && !filter (b))
5955 /* If we have an "args" string, it is a list of breakpoints to
5956 accept. Skip the others. */
5957 if (args != NULL && *args != '\0')
5959 if (allflag && parse_and_eval_long (args) != b->number)
5961 if (!allflag && !number_is_in_list (args, b->number))
5965 if (allflag || user_breakpoint_p (b))
5967 int addr_bit, type_len;
5969 addr_bit = breakpoint_address_bits (b);
5970 if (addr_bit > print_address_bits)
5971 print_address_bits = addr_bit;
5973 type_len = strlen (bptype_string (b->type));
5974 if (type_len > print_type_col_width)
5975 print_type_col_width = type_len;
5977 nr_printable_breakpoints++;
5981 if (opts.addressprint)
5983 = make_cleanup_ui_out_table_begin_end (uiout, 6,
5984 nr_printable_breakpoints,
5988 = make_cleanup_ui_out_table_begin_end (uiout, 5,
5989 nr_printable_breakpoints,
5992 if (nr_printable_breakpoints > 0)
5993 annotate_breakpoints_headers ();
5994 if (nr_printable_breakpoints > 0)
5996 ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */
5997 if (nr_printable_breakpoints > 0)
5999 ui_out_table_header (uiout, print_type_col_width, ui_left,
6000 "type", "Type"); /* 2 */
6001 if (nr_printable_breakpoints > 0)
6003 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
6004 if (nr_printable_breakpoints > 0)
6006 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
6007 if (opts.addressprint)
6009 if (nr_printable_breakpoints > 0)
6011 if (print_address_bits <= 32)
6012 ui_out_table_header (uiout, 10, ui_left,
6013 "addr", "Address"); /* 5 */
6015 ui_out_table_header (uiout, 18, ui_left,
6016 "addr", "Address"); /* 5 */
6018 if (nr_printable_breakpoints > 0)
6020 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
6021 ui_out_table_body (uiout);
6022 if (nr_printable_breakpoints > 0)
6023 annotate_breakpoints_table ();
6028 /* If we have a filter, only list the breakpoints it accepts. */
6029 if (filter && !filter (b))
6032 /* If we have an "args" string, it is a list of breakpoints to
6033 accept. Skip the others. */
6035 if (args != NULL && *args != '\0')
6037 if (allflag) /* maintenance info breakpoint */
6039 if (parse_and_eval_long (args) != b->number)
6042 else /* all others */
6044 if (!number_is_in_list (args, b->number))
6048 /* We only print out user settable breakpoints unless the
6050 if (allflag || user_breakpoint_p (b))
6051 print_one_breakpoint (b, &last_loc, allflag);
6054 do_cleanups (bkpttbl_chain);
6056 if (nr_printable_breakpoints == 0)
6058 /* If there's a filter, let the caller decide how to report
6062 if (args == NULL || *args == '\0')
6063 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
6065 ui_out_message (uiout, 0,
6066 "No breakpoint or watchpoint matching '%s'.\n",
6072 if (last_loc && !server_command)
6073 set_next_address (last_loc->gdbarch, last_loc->address);
6076 /* FIXME? Should this be moved up so that it is only called when
6077 there have been breakpoints? */
6078 annotate_breakpoints_table_end ();
6080 return nr_printable_breakpoints;
6083 /* Display the value of default-collect in a way that is generally
6084 compatible with the breakpoint list. */
6087 default_collect_info (void)
6089 struct ui_out *uiout = current_uiout;
6091 /* If it has no value (which is frequently the case), say nothing; a
6092 message like "No default-collect." gets in user's face when it's
6094 if (!*default_collect)
6097 /* The following phrase lines up nicely with per-tracepoint collect
6099 ui_out_text (uiout, "default collect ");
6100 ui_out_field_string (uiout, "default-collect", default_collect);
6101 ui_out_text (uiout, " \n");
6105 breakpoints_info (char *args, int from_tty)
6107 breakpoint_1 (args, 0, NULL);
6109 default_collect_info ();
6113 watchpoints_info (char *args, int from_tty)
6115 int num_printed = breakpoint_1 (args, 0, is_watchpoint);
6116 struct ui_out *uiout = current_uiout;
6118 if (num_printed == 0)
6120 if (args == NULL || *args == '\0')
6121 ui_out_message (uiout, 0, "No watchpoints.\n");
6123 ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args);
6128 maintenance_info_breakpoints (char *args, int from_tty)
6130 breakpoint_1 (args, 1, NULL);
6132 default_collect_info ();
6136 breakpoint_has_pc (struct breakpoint *b,
6137 struct program_space *pspace,
6138 CORE_ADDR pc, struct obj_section *section)
6140 struct bp_location *bl = b->loc;
6142 for (; bl; bl = bl->next)
6144 if (bl->pspace == pspace
6145 && bl->address == pc
6146 && (!overlay_debugging || bl->section == section))
6152 /* Print a message describing any user-breakpoints set at PC. This
6153 concerns with logical breakpoints, so we match program spaces, not
6157 describe_other_breakpoints (struct gdbarch *gdbarch,
6158 struct program_space *pspace, CORE_ADDR pc,
6159 struct obj_section *section, int thread)
6162 struct breakpoint *b;
6165 others += (user_breakpoint_p (b)
6166 && breakpoint_has_pc (b, pspace, pc, section));
6170 printf_filtered (_("Note: breakpoint "));
6171 else /* if (others == ???) */
6172 printf_filtered (_("Note: breakpoints "));
6174 if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section))
6177 printf_filtered ("%d", b->number);
6178 if (b->thread == -1 && thread != -1)
6179 printf_filtered (" (all threads)");
6180 else if (b->thread != -1)
6181 printf_filtered (" (thread %d)", b->thread);
6182 printf_filtered ("%s%s ",
6183 ((b->enable_state == bp_disabled
6184 || b->enable_state == bp_call_disabled)
6186 : b->enable_state == bp_permanent
6190 : ((others == 1) ? " and" : ""));
6192 printf_filtered (_("also set at pc "));
6193 fputs_filtered (paddress (gdbarch, pc), gdb_stdout);
6194 printf_filtered (".\n");
6199 /* Return true iff it is meaningful to use the address member of
6200 BPT. For some breakpoint types, the address member is irrelevant
6201 and it makes no sense to attempt to compare it to other addresses
6202 (or use it for any other purpose either).
6204 More specifically, each of the following breakpoint types will
6205 always have a zero valued address and we don't want to mark
6206 breakpoints of any of these types to be a duplicate of an actual
6207 breakpoint at address zero:
6215 breakpoint_address_is_meaningful (struct breakpoint *bpt)
6217 enum bptype type = bpt->type;
6219 return (type != bp_watchpoint && type != bp_catchpoint);
6222 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6223 true if LOC1 and LOC2 represent the same watchpoint location. */
6226 watchpoint_locations_match (struct bp_location *loc1,
6227 struct bp_location *loc2)
6229 struct watchpoint *w1 = (struct watchpoint *) loc1->owner;
6230 struct watchpoint *w2 = (struct watchpoint *) loc2->owner;
6232 /* Both of them must exist. */
6233 gdb_assert (w1 != NULL);
6234 gdb_assert (w2 != NULL);
6236 /* If the target can evaluate the condition expression in hardware,
6237 then we we need to insert both watchpoints even if they are at
6238 the same place. Otherwise the watchpoint will only trigger when
6239 the condition of whichever watchpoint was inserted evaluates to
6240 true, not giving a chance for GDB to check the condition of the
6241 other watchpoint. */
6243 && target_can_accel_watchpoint_condition (loc1->address,
6245 loc1->watchpoint_type,
6248 && target_can_accel_watchpoint_condition (loc2->address,
6250 loc2->watchpoint_type,
6254 /* Note that this checks the owner's type, not the location's. In
6255 case the target does not support read watchpoints, but does
6256 support access watchpoints, we'll have bp_read_watchpoint
6257 watchpoints with hw_access locations. Those should be considered
6258 duplicates of hw_read locations. The hw_read locations will
6259 become hw_access locations later. */
6260 return (loc1->owner->type == loc2->owner->type
6261 && loc1->pspace->aspace == loc2->pspace->aspace
6262 && loc1->address == loc2->address
6263 && loc1->length == loc2->length);
6266 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
6267 same breakpoint location. In most targets, this can only be true
6268 if ASPACE1 matches ASPACE2. On targets that have global
6269 breakpoints, the address space doesn't really matter. */
6272 breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1,
6273 struct address_space *aspace2, CORE_ADDR addr2)
6275 return ((gdbarch_has_global_breakpoints (target_gdbarch)
6276 || aspace1 == aspace2)
6280 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6281 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6282 matches ASPACE2. On targets that have global breakpoints, the address
6283 space doesn't really matter. */
6286 breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1,
6287 int len1, struct address_space *aspace2,
6290 return ((gdbarch_has_global_breakpoints (target_gdbarch)
6291 || aspace1 == aspace2)
6292 && addr2 >= addr1 && addr2 < addr1 + len1);
6295 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6296 a ranged breakpoint. In most targets, a match happens only if ASPACE
6297 matches the breakpoint's address space. On targets that have global
6298 breakpoints, the address space doesn't really matter. */
6301 breakpoint_location_address_match (struct bp_location *bl,
6302 struct address_space *aspace,
6305 return (breakpoint_address_match (bl->pspace->aspace, bl->address,
6308 && breakpoint_address_match_range (bl->pspace->aspace,
6309 bl->address, bl->length,
6313 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6314 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6315 true, otherwise returns false. */
6318 tracepoint_locations_match (struct bp_location *loc1,
6319 struct bp_location *loc2)
6321 if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner))
6322 /* Since tracepoint locations are never duplicated with others', tracepoint
6323 locations at the same address of different tracepoints are regarded as
6324 different locations. */
6325 return (loc1->address == loc2->address && loc1->owner == loc2->owner);
6330 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
6331 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
6332 represent the same location. */
6335 breakpoint_locations_match (struct bp_location *loc1,
6336 struct bp_location *loc2)
6338 int hw_point1, hw_point2;
6340 /* Both of them must not be in moribund_locations. */
6341 gdb_assert (loc1->owner != NULL);
6342 gdb_assert (loc2->owner != NULL);
6344 hw_point1 = is_hardware_watchpoint (loc1->owner);
6345 hw_point2 = is_hardware_watchpoint (loc2->owner);
6347 if (hw_point1 != hw_point2)
6350 return watchpoint_locations_match (loc1, loc2);
6351 else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner))
6352 return tracepoint_locations_match (loc1, loc2);
6354 /* We compare bp_location.length in order to cover ranged breakpoints. */
6355 return (breakpoint_address_match (loc1->pspace->aspace, loc1->address,
6356 loc2->pspace->aspace, loc2->address)
6357 && loc1->length == loc2->length);
6361 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
6362 int bnum, int have_bnum)
6364 /* The longest string possibly returned by hex_string_custom
6365 is 50 chars. These must be at least that big for safety. */
6369 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
6370 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
6372 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
6373 bnum, astr1, astr2);
6375 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
6378 /* Adjust a breakpoint's address to account for architectural
6379 constraints on breakpoint placement. Return the adjusted address.
6380 Note: Very few targets require this kind of adjustment. For most
6381 targets, this function is simply the identity function. */
6384 adjust_breakpoint_address (struct gdbarch *gdbarch,
6385 CORE_ADDR bpaddr, enum bptype bptype)
6387 if (!gdbarch_adjust_breakpoint_address_p (gdbarch))
6389 /* Very few targets need any kind of breakpoint adjustment. */
6392 else if (bptype == bp_watchpoint
6393 || bptype == bp_hardware_watchpoint
6394 || bptype == bp_read_watchpoint
6395 || bptype == bp_access_watchpoint
6396 || bptype == bp_catchpoint)
6398 /* Watchpoints and the various bp_catch_* eventpoints should not
6399 have their addresses modified. */
6404 CORE_ADDR adjusted_bpaddr;
6406 /* Some targets have architectural constraints on the placement
6407 of breakpoint instructions. Obtain the adjusted address. */
6408 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr);
6410 /* An adjusted breakpoint address can significantly alter
6411 a user's expectations. Print a warning if an adjustment
6413 if (adjusted_bpaddr != bpaddr)
6414 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
6416 return adjusted_bpaddr;
6421 init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops,
6422 struct breakpoint *owner)
6424 memset (loc, 0, sizeof (*loc));
6426 gdb_assert (ops != NULL);
6431 loc->cond_bytecode = NULL;
6432 loc->shlib_disabled = 0;
6435 switch (owner->type)
6441 case bp_longjmp_resume:
6443 case bp_exception_resume:
6444 case bp_step_resume:
6445 case bp_hp_step_resume:
6446 case bp_watchpoint_scope:
6448 case bp_std_terminate:
6449 case bp_shlib_event:
6450 case bp_thread_event:
6451 case bp_overlay_event:
6453 case bp_longjmp_master:
6454 case bp_std_terminate_master:
6455 case bp_exception_master:
6456 case bp_gnu_ifunc_resolver:
6457 case bp_gnu_ifunc_resolver_return:
6459 loc->loc_type = bp_loc_software_breakpoint;
6460 mark_breakpoint_location_modified (loc);
6462 case bp_hardware_breakpoint:
6463 loc->loc_type = bp_loc_hardware_breakpoint;
6464 mark_breakpoint_location_modified (loc);
6466 case bp_hardware_watchpoint:
6467 case bp_read_watchpoint:
6468 case bp_access_watchpoint:
6469 loc->loc_type = bp_loc_hardware_watchpoint;
6474 case bp_fast_tracepoint:
6475 case bp_static_tracepoint:
6476 loc->loc_type = bp_loc_other;
6479 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
6485 /* Allocate a struct bp_location. */
6487 static struct bp_location *
6488 allocate_bp_location (struct breakpoint *bpt)
6490 return bpt->ops->allocate_location (bpt);
6494 free_bp_location (struct bp_location *loc)
6496 loc->ops->dtor (loc);
6500 /* Increment reference count. */
6503 incref_bp_location (struct bp_location *bl)
6508 /* Decrement reference count. If the reference count reaches 0,
6509 destroy the bp_location. Sets *BLP to NULL. */
6512 decref_bp_location (struct bp_location **blp)
6514 gdb_assert ((*blp)->refc > 0);
6516 if (--(*blp)->refc == 0)
6517 free_bp_location (*blp);
6521 /* Add breakpoint B at the end of the global breakpoint chain. */
6524 add_to_breakpoint_chain (struct breakpoint *b)
6526 struct breakpoint *b1;
6528 /* Add this breakpoint to the end of the chain so that a list of
6529 breakpoints will come out in order of increasing numbers. */
6531 b1 = breakpoint_chain;
6533 breakpoint_chain = b;
6542 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
6545 init_raw_breakpoint_without_location (struct breakpoint *b,
6546 struct gdbarch *gdbarch,
6548 const struct breakpoint_ops *ops)
6550 memset (b, 0, sizeof (*b));
6552 gdb_assert (ops != NULL);
6556 b->gdbarch = gdbarch;
6557 b->language = current_language->la_language;
6558 b->input_radix = input_radix;
6560 b->enable_state = bp_enabled;
6563 b->ignore_count = 0;
6565 b->frame_id = null_frame_id;
6566 b->condition_not_parsed = 0;
6567 b->py_bp_object = NULL;
6568 b->related_breakpoint = b;
6571 /* Helper to set_raw_breakpoint below. Creates a breakpoint
6572 that has type BPTYPE and has no locations as yet. */
6574 static struct breakpoint *
6575 set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
6577 const struct breakpoint_ops *ops)
6579 struct breakpoint *b = XNEW (struct breakpoint);
6581 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
6582 add_to_breakpoint_chain (b);
6586 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
6587 resolutions should be made as the user specified the location explicitly
6591 set_breakpoint_location_function (struct bp_location *loc, int explicit_loc)
6593 gdb_assert (loc->owner != NULL);
6595 if (loc->owner->type == bp_breakpoint
6596 || loc->owner->type == bp_hardware_breakpoint
6597 || is_tracepoint (loc->owner))
6600 const char *function_name;
6601 CORE_ADDR func_addr;
6603 find_pc_partial_function_gnu_ifunc (loc->address, &function_name,
6604 &func_addr, NULL, &is_gnu_ifunc);
6606 if (is_gnu_ifunc && !explicit_loc)
6608 struct breakpoint *b = loc->owner;
6610 gdb_assert (loc->pspace == current_program_space);
6611 if (gnu_ifunc_resolve_name (function_name,
6612 &loc->requested_address))
6614 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
6615 loc->address = adjust_breakpoint_address (loc->gdbarch,
6616 loc->requested_address,
6619 else if (b->type == bp_breakpoint && b->loc == loc
6620 && loc->next == NULL && b->related_breakpoint == b)
6622 /* Create only the whole new breakpoint of this type but do not
6623 mess more complicated breakpoints with multiple locations. */
6624 b->type = bp_gnu_ifunc_resolver;
6625 /* Remember the resolver's address for use by the return
6627 loc->related_address = func_addr;
6632 loc->function_name = xstrdup (function_name);
6636 /* Attempt to determine architecture of location identified by SAL. */
6638 get_sal_arch (struct symtab_and_line sal)
6641 return get_objfile_arch (sal.section->objfile);
6643 return get_objfile_arch (sal.symtab->objfile);
6648 /* Low level routine for partially initializing a breakpoint of type
6649 BPTYPE. The newly created breakpoint's address, section, source
6650 file name, and line number are provided by SAL.
6652 It is expected that the caller will complete the initialization of
6653 the newly created breakpoint struct as well as output any status
6654 information regarding the creation of a new breakpoint. */
6657 init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch,
6658 struct symtab_and_line sal, enum bptype bptype,
6659 const struct breakpoint_ops *ops)
6661 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
6663 add_location_to_breakpoint (b, &sal);
6665 if (bptype != bp_catchpoint)
6666 gdb_assert (sal.pspace != NULL);
6668 /* Store the program space that was used to set the breakpoint,
6669 except for ordinary breakpoints, which are independent of the
6671 if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint)
6672 b->pspace = sal.pspace;
6674 breakpoints_changed ();
6677 /* set_raw_breakpoint is a low level routine for allocating and
6678 partially initializing a breakpoint of type BPTYPE. The newly
6679 created breakpoint's address, section, source file name, and line
6680 number are provided by SAL. The newly created and partially
6681 initialized breakpoint is added to the breakpoint chain and
6682 is also returned as the value of this function.
6684 It is expected that the caller will complete the initialization of
6685 the newly created breakpoint struct as well as output any status
6686 information regarding the creation of a new breakpoint. In
6687 particular, set_raw_breakpoint does NOT set the breakpoint
6688 number! Care should be taken to not allow an error to occur
6689 prior to completing the initialization of the breakpoint. If this
6690 should happen, a bogus breakpoint will be left on the chain. */
6693 set_raw_breakpoint (struct gdbarch *gdbarch,
6694 struct symtab_and_line sal, enum bptype bptype,
6695 const struct breakpoint_ops *ops)
6697 struct breakpoint *b = XNEW (struct breakpoint);
6699 init_raw_breakpoint (b, gdbarch, sal, bptype, ops);
6700 add_to_breakpoint_chain (b);
6705 /* Note that the breakpoint object B describes a permanent breakpoint
6706 instruction, hard-wired into the inferior's code. */
6708 make_breakpoint_permanent (struct breakpoint *b)
6710 struct bp_location *bl;
6712 b->enable_state = bp_permanent;
6714 /* By definition, permanent breakpoints are already present in the
6715 code. Mark all locations as inserted. For now,
6716 make_breakpoint_permanent is called in just one place, so it's
6717 hard to say if it's reasonable to have permanent breakpoint with
6718 multiple locations or not, but it's easy to implement. */
6719 for (bl = b->loc; bl; bl = bl->next)
6723 /* Call this routine when stepping and nexting to enable a breakpoint
6724 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
6725 initiated the operation. */
6728 set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame)
6730 struct breakpoint *b, *b_tmp;
6731 int thread = tp->num;
6733 /* To avoid having to rescan all objfile symbols at every step,
6734 we maintain a list of continually-inserted but always disabled
6735 longjmp "master" breakpoints. Here, we simply create momentary
6736 clones of those and enable them for the requested thread. */
6737 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6738 if (b->pspace == current_program_space
6739 && (b->type == bp_longjmp_master
6740 || b->type == bp_exception_master))
6742 enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception;
6743 struct breakpoint *clone;
6745 clone = momentary_breakpoint_from_master (b, type,
6746 &momentary_breakpoint_ops);
6747 clone->thread = thread;
6750 tp->initiating_frame = frame;
6753 /* Delete all longjmp breakpoints from THREAD. */
6755 delete_longjmp_breakpoint (int thread)
6757 struct breakpoint *b, *b_tmp;
6759 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6760 if (b->type == bp_longjmp || b->type == bp_exception)
6762 if (b->thread == thread)
6763 delete_breakpoint (b);
6768 delete_longjmp_breakpoint_at_next_stop (int thread)
6770 struct breakpoint *b, *b_tmp;
6772 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6773 if (b->type == bp_longjmp || b->type == bp_exception)
6775 if (b->thread == thread)
6776 b->disposition = disp_del_at_next_stop;
6781 enable_overlay_breakpoints (void)
6783 struct breakpoint *b;
6786 if (b->type == bp_overlay_event)
6788 b->enable_state = bp_enabled;
6789 update_global_location_list (1);
6790 overlay_events_enabled = 1;
6795 disable_overlay_breakpoints (void)
6797 struct breakpoint *b;
6800 if (b->type == bp_overlay_event)
6802 b->enable_state = bp_disabled;
6803 update_global_location_list (0);
6804 overlay_events_enabled = 0;
6808 /* Set an active std::terminate breakpoint for each std::terminate
6809 master breakpoint. */
6811 set_std_terminate_breakpoint (void)
6813 struct breakpoint *b, *b_tmp;
6815 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6816 if (b->pspace == current_program_space
6817 && b->type == bp_std_terminate_master)
6819 momentary_breakpoint_from_master (b, bp_std_terminate,
6820 &momentary_breakpoint_ops);
6824 /* Delete all the std::terminate breakpoints. */
6826 delete_std_terminate_breakpoint (void)
6828 struct breakpoint *b, *b_tmp;
6830 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6831 if (b->type == bp_std_terminate)
6832 delete_breakpoint (b);
6836 create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
6838 struct breakpoint *b;
6840 b = create_internal_breakpoint (gdbarch, address, bp_thread_event,
6841 &internal_breakpoint_ops);
6843 b->enable_state = bp_enabled;
6844 /* addr_string has to be used or breakpoint_re_set will delete me. */
6846 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
6848 update_global_location_list_nothrow (1);
6854 remove_thread_event_breakpoints (void)
6856 struct breakpoint *b, *b_tmp;
6858 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6859 if (b->type == bp_thread_event
6860 && b->loc->pspace == current_program_space)
6861 delete_breakpoint (b);
6864 struct lang_and_radix
6870 /* Create a breakpoint for JIT code registration and unregistration. */
6873 create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
6875 struct breakpoint *b;
6877 b = create_internal_breakpoint (gdbarch, address, bp_jit_event,
6878 &internal_breakpoint_ops);
6879 update_global_location_list_nothrow (1);
6883 /* Remove JIT code registration and unregistration breakpoint(s). */
6886 remove_jit_event_breakpoints (void)
6888 struct breakpoint *b, *b_tmp;
6890 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6891 if (b->type == bp_jit_event
6892 && b->loc->pspace == current_program_space)
6893 delete_breakpoint (b);
6897 remove_solib_event_breakpoints (void)
6899 struct breakpoint *b, *b_tmp;
6901 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6902 if (b->type == bp_shlib_event
6903 && b->loc->pspace == current_program_space)
6904 delete_breakpoint (b);
6908 create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
6910 struct breakpoint *b;
6912 b = create_internal_breakpoint (gdbarch, address, bp_shlib_event,
6913 &internal_breakpoint_ops);
6914 update_global_location_list_nothrow (1);
6918 /* Disable any breakpoints that are on code in shared libraries. Only
6919 apply to enabled breakpoints, disabled ones can just stay disabled. */
6922 disable_breakpoints_in_shlibs (void)
6924 struct bp_location *loc, **locp_tmp;
6926 ALL_BP_LOCATIONS (loc, locp_tmp)
6928 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6929 struct breakpoint *b = loc->owner;
6931 /* We apply the check to all breakpoints, including disabled for
6932 those with loc->duplicate set. This is so that when breakpoint
6933 becomes enabled, or the duplicate is removed, gdb will try to
6934 insert all breakpoints. If we don't set shlib_disabled here,
6935 we'll try to insert those breakpoints and fail. */
6936 if (((b->type == bp_breakpoint)
6937 || (b->type == bp_jit_event)
6938 || (b->type == bp_hardware_breakpoint)
6939 || (is_tracepoint (b)))
6940 && loc->pspace == current_program_space
6941 && !loc->shlib_disabled
6943 && PC_SOLIB (loc->address)
6945 && solib_name_from_address (loc->pspace, loc->address)
6949 loc->shlib_disabled = 1;
6954 /* Disable any breakpoints and tracepoints that are in an unloaded shared
6955 library. Only apply to enabled breakpoints, disabled ones can just stay
6959 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
6961 struct bp_location *loc, **locp_tmp;
6962 int disabled_shlib_breaks = 0;
6964 /* SunOS a.out shared libraries are always mapped, so do not
6965 disable breakpoints; they will only be reported as unloaded
6966 through clear_solib when GDB discards its shared library
6967 list. See clear_solib for more information. */
6968 if (exec_bfd != NULL
6969 && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour)
6972 ALL_BP_LOCATIONS (loc, locp_tmp)
6974 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6975 struct breakpoint *b = loc->owner;
6977 if (solib->pspace == loc->pspace
6978 && !loc->shlib_disabled
6979 && (((b->type == bp_breakpoint
6980 || b->type == bp_jit_event
6981 || b->type == bp_hardware_breakpoint)
6982 && (loc->loc_type == bp_loc_hardware_breakpoint
6983 || loc->loc_type == bp_loc_software_breakpoint))
6984 || is_tracepoint (b))
6985 && solib_contains_address_p (solib, loc->address))
6987 loc->shlib_disabled = 1;
6988 /* At this point, we cannot rely on remove_breakpoint
6989 succeeding so we must mark the breakpoint as not inserted
6990 to prevent future errors occurring in remove_breakpoints. */
6993 /* This may cause duplicate notifications for the same breakpoint. */
6994 observer_notify_breakpoint_modified (b);
6996 if (!disabled_shlib_breaks)
6998 target_terminal_ours_for_output ();
6999 warning (_("Temporarily disabling breakpoints "
7000 "for unloaded shared library \"%s\""),
7003 disabled_shlib_breaks = 1;
7008 /* FORK & VFORK catchpoints. */
7010 /* An instance of this type is used to represent a fork or vfork
7011 catchpoint. It includes a "struct breakpoint" as a kind of base
7012 class; users downcast to "struct breakpoint *" when needed. A
7013 breakpoint is really of this type iff its ops pointer points to
7014 CATCH_FORK_BREAKPOINT_OPS. */
7016 struct fork_catchpoint
7018 /* The base class. */
7019 struct breakpoint base;
7021 /* Process id of a child process whose forking triggered this
7022 catchpoint. This field is only valid immediately after this
7023 catchpoint has triggered. */
7024 ptid_t forked_inferior_pid;
7027 /* Implement the "insert" breakpoint_ops method for fork
7031 insert_catch_fork (struct bp_location *bl)
7033 return target_insert_fork_catchpoint (PIDGET (inferior_ptid));
7036 /* Implement the "remove" breakpoint_ops method for fork
7040 remove_catch_fork (struct bp_location *bl)
7042 return target_remove_fork_catchpoint (PIDGET (inferior_ptid));
7045 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7049 breakpoint_hit_catch_fork (const struct bp_location *bl,
7050 struct address_space *aspace, CORE_ADDR bp_addr,
7051 const struct target_waitstatus *ws)
7053 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
7055 if (ws->kind != TARGET_WAITKIND_FORKED)
7058 c->forked_inferior_pid = ws->value.related_pid;
7062 /* Implement the "print_it" breakpoint_ops method for fork
7065 static enum print_stop_action
7066 print_it_catch_fork (bpstat bs)
7068 struct ui_out *uiout = current_uiout;
7069 struct breakpoint *b = bs->breakpoint_at;
7070 struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at;
7072 annotate_catchpoint (b->number);
7073 if (b->disposition == disp_del)
7074 ui_out_text (uiout, "\nTemporary catchpoint ");
7076 ui_out_text (uiout, "\nCatchpoint ");
7077 if (ui_out_is_mi_like_p (uiout))
7079 ui_out_field_string (uiout, "reason",
7080 async_reason_lookup (EXEC_ASYNC_FORK));
7081 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7083 ui_out_field_int (uiout, "bkptno", b->number);
7084 ui_out_text (uiout, " (forked process ");
7085 ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid));
7086 ui_out_text (uiout, "), ");
7087 return PRINT_SRC_AND_LOC;
7090 /* Implement the "print_one" breakpoint_ops method for fork
7094 print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc)
7096 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
7097 struct value_print_options opts;
7098 struct ui_out *uiout = current_uiout;
7100 get_user_print_options (&opts);
7102 /* Field 4, the address, is omitted (which makes the columns not
7103 line up too nicely with the headers, but the effect is relatively
7105 if (opts.addressprint)
7106 ui_out_field_skip (uiout, "addr");
7108 ui_out_text (uiout, "fork");
7109 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
7111 ui_out_text (uiout, ", process ");
7112 ui_out_field_int (uiout, "what",
7113 ptid_get_pid (c->forked_inferior_pid));
7114 ui_out_spaces (uiout, 1);
7118 /* Implement the "print_mention" breakpoint_ops method for fork
7122 print_mention_catch_fork (struct breakpoint *b)
7124 printf_filtered (_("Catchpoint %d (fork)"), b->number);
7127 /* Implement the "print_recreate" breakpoint_ops method for fork
7131 print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp)
7133 fprintf_unfiltered (fp, "catch fork");
7134 print_recreate_thread (b, fp);
7137 /* The breakpoint_ops structure to be used in fork catchpoints. */
7139 static struct breakpoint_ops catch_fork_breakpoint_ops;
7141 /* Implement the "insert" breakpoint_ops method for vfork
7145 insert_catch_vfork (struct bp_location *bl)
7147 return target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
7150 /* Implement the "remove" breakpoint_ops method for vfork
7154 remove_catch_vfork (struct bp_location *bl)
7156 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
7159 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
7163 breakpoint_hit_catch_vfork (const struct bp_location *bl,
7164 struct address_space *aspace, CORE_ADDR bp_addr,
7165 const struct target_waitstatus *ws)
7167 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
7169 if (ws->kind != TARGET_WAITKIND_VFORKED)
7172 c->forked_inferior_pid = ws->value.related_pid;
7176 /* Implement the "print_it" breakpoint_ops method for vfork
7179 static enum print_stop_action
7180 print_it_catch_vfork (bpstat bs)
7182 struct ui_out *uiout = current_uiout;
7183 struct breakpoint *b = bs->breakpoint_at;
7184 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
7186 annotate_catchpoint (b->number);
7187 if (b->disposition == disp_del)
7188 ui_out_text (uiout, "\nTemporary catchpoint ");
7190 ui_out_text (uiout, "\nCatchpoint ");
7191 if (ui_out_is_mi_like_p (uiout))
7193 ui_out_field_string (uiout, "reason",
7194 async_reason_lookup (EXEC_ASYNC_VFORK));
7195 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7197 ui_out_field_int (uiout, "bkptno", b->number);
7198 ui_out_text (uiout, " (vforked process ");
7199 ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid));
7200 ui_out_text (uiout, "), ");
7201 return PRINT_SRC_AND_LOC;
7204 /* Implement the "print_one" breakpoint_ops method for vfork
7208 print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc)
7210 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
7211 struct value_print_options opts;
7212 struct ui_out *uiout = current_uiout;
7214 get_user_print_options (&opts);
7215 /* Field 4, the address, is omitted (which makes the columns not
7216 line up too nicely with the headers, but the effect is relatively
7218 if (opts.addressprint)
7219 ui_out_field_skip (uiout, "addr");
7221 ui_out_text (uiout, "vfork");
7222 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
7224 ui_out_text (uiout, ", process ");
7225 ui_out_field_int (uiout, "what",
7226 ptid_get_pid (c->forked_inferior_pid));
7227 ui_out_spaces (uiout, 1);
7231 /* Implement the "print_mention" breakpoint_ops method for vfork
7235 print_mention_catch_vfork (struct breakpoint *b)
7237 printf_filtered (_("Catchpoint %d (vfork)"), b->number);
7240 /* Implement the "print_recreate" breakpoint_ops method for vfork
7244 print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp)
7246 fprintf_unfiltered (fp, "catch vfork");
7247 print_recreate_thread (b, fp);
7250 /* The breakpoint_ops structure to be used in vfork catchpoints. */
7252 static struct breakpoint_ops catch_vfork_breakpoint_ops;
7254 /* An instance of this type is used to represent an solib catchpoint.
7255 It includes a "struct breakpoint" as a kind of base class; users
7256 downcast to "struct breakpoint *" when needed. A breakpoint is
7257 really of this type iff its ops pointer points to
7258 CATCH_SOLIB_BREAKPOINT_OPS. */
7260 struct solib_catchpoint
7262 /* The base class. */
7263 struct breakpoint base;
7265 /* True for "catch load", false for "catch unload". */
7266 unsigned char is_load;
7268 /* Regular expression to match, if any. COMPILED is only valid when
7269 REGEX is non-NULL. */
7275 dtor_catch_solib (struct breakpoint *b)
7277 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
7280 regfree (&self->compiled);
7281 xfree (self->regex);
7283 base_breakpoint_ops.dtor (b);
7287 insert_catch_solib (struct bp_location *ignore)
7293 remove_catch_solib (struct bp_location *ignore)
7299 breakpoint_hit_catch_solib (const struct bp_location *bl,
7300 struct address_space *aspace,
7302 const struct target_waitstatus *ws)
7304 struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner;
7305 struct breakpoint *other;
7307 if (ws->kind == TARGET_WAITKIND_LOADED)
7310 ALL_BREAKPOINTS (other)
7312 struct bp_location *other_bl;
7314 if (other == bl->owner)
7317 if (other->type != bp_shlib_event)
7320 if (self->base.pspace != NULL && other->pspace != self->base.pspace)
7323 for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next)
7325 if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws))
7334 check_status_catch_solib (struct bpstats *bs)
7336 struct solib_catchpoint *self
7337 = (struct solib_catchpoint *) bs->breakpoint_at;
7342 struct so_list *iter;
7345 VEC_iterate (so_list_ptr, current_program_space->added_solibs,
7350 || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0)
7359 VEC_iterate (char_ptr, current_program_space->deleted_solibs,
7364 || regexec (&self->compiled, iter, 0, NULL, 0) == 0)
7370 bs->print_it = print_it_noop;
7373 static enum print_stop_action
7374 print_it_catch_solib (bpstat bs)
7376 struct breakpoint *b = bs->breakpoint_at;
7377 struct ui_out *uiout = current_uiout;
7379 annotate_catchpoint (b->number);
7380 if (b->disposition == disp_del)
7381 ui_out_text (uiout, "\nTemporary catchpoint ");
7383 ui_out_text (uiout, "\nCatchpoint ");
7384 ui_out_field_int (uiout, "bkptno", b->number);
7385 ui_out_text (uiout, "\n");
7386 if (ui_out_is_mi_like_p (uiout))
7387 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7388 print_solib_event (1);
7389 return PRINT_SRC_AND_LOC;
7393 print_one_catch_solib (struct breakpoint *b, struct bp_location **locs)
7395 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
7396 struct value_print_options opts;
7397 struct ui_out *uiout = current_uiout;
7400 get_user_print_options (&opts);
7401 /* Field 4, the address, is omitted (which makes the columns not
7402 line up too nicely with the headers, but the effect is relatively
7404 if (opts.addressprint)
7407 ui_out_field_skip (uiout, "addr");
7414 msg = xstrprintf (_("load of library matching %s"), self->regex);
7416 msg = xstrdup (_("load of library"));
7421 msg = xstrprintf (_("unload of library matching %s"), self->regex);
7423 msg = xstrdup (_("unload of library"));
7425 ui_out_field_string (uiout, "what", msg);
7430 print_mention_catch_solib (struct breakpoint *b)
7432 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
7434 printf_filtered (_("Catchpoint %d (%s)"), b->number,
7435 self->is_load ? "load" : "unload");
7439 print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp)
7441 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
7443 fprintf_unfiltered (fp, "%s %s",
7444 b->disposition == disp_del ? "tcatch" : "catch",
7445 self->is_load ? "load" : "unload");
7447 fprintf_unfiltered (fp, " %s", self->regex);
7448 fprintf_unfiltered (fp, "\n");
7451 static struct breakpoint_ops catch_solib_breakpoint_ops;
7453 /* A helper function that does all the work for "catch load" and
7457 catch_load_or_unload (char *arg, int from_tty, int is_load,
7458 struct cmd_list_element *command)
7460 struct solib_catchpoint *c;
7461 struct gdbarch *gdbarch = get_current_arch ();
7464 struct cleanup *cleanup;
7466 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
7470 arg = skip_spaces (arg);
7472 c = XCNEW (struct solib_catchpoint);
7473 cleanup = make_cleanup (xfree, c);
7479 errcode = regcomp (&c->compiled, arg, REG_NOSUB);
7482 char *err = get_regcomp_error (errcode, &c->compiled);
7484 make_cleanup (xfree, err);
7485 error (_("Invalid regexp (%s): %s"), err, arg);
7487 c->regex = xstrdup (arg);
7490 c->is_load = is_load;
7491 init_catchpoint (&c->base, gdbarch, tempflag, NULL,
7492 &catch_solib_breakpoint_ops);
7494 discard_cleanups (cleanup);
7495 install_breakpoint (0, &c->base, 1);
7499 catch_load_command_1 (char *arg, int from_tty,
7500 struct cmd_list_element *command)
7502 catch_load_or_unload (arg, from_tty, 1, command);
7506 catch_unload_command_1 (char *arg, int from_tty,
7507 struct cmd_list_element *command)
7509 catch_load_or_unload (arg, from_tty, 0, command);
7514 /* An instance of this type is used to represent a syscall catchpoint.
7515 It includes a "struct breakpoint" as a kind of base class; users
7516 downcast to "struct breakpoint *" when needed. A breakpoint is
7517 really of this type iff its ops pointer points to
7518 CATCH_SYSCALL_BREAKPOINT_OPS. */
7520 struct syscall_catchpoint
7522 /* The base class. */
7523 struct breakpoint base;
7525 /* Syscall numbers used for the 'catch syscall' feature. If no
7526 syscall has been specified for filtering, its value is NULL.
7527 Otherwise, it holds a list of all syscalls to be caught. The
7528 list elements are allocated with xmalloc. */
7529 VEC(int) *syscalls_to_be_caught;
7532 /* Implement the "dtor" breakpoint_ops method for syscall
7536 dtor_catch_syscall (struct breakpoint *b)
7538 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
7540 VEC_free (int, c->syscalls_to_be_caught);
7542 base_breakpoint_ops.dtor (b);
7545 static const struct inferior_data *catch_syscall_inferior_data = NULL;
7547 struct catch_syscall_inferior_data
7549 /* We keep a count of the number of times the user has requested a
7550 particular syscall to be tracked, and pass this information to the
7551 target. This lets capable targets implement filtering directly. */
7553 /* Number of times that "any" syscall is requested. */
7554 int any_syscall_count;
7556 /* Count of each system call. */
7557 VEC(int) *syscalls_counts;
7559 /* This counts all syscall catch requests, so we can readily determine
7560 if any catching is necessary. */
7561 int total_syscalls_count;
7564 static struct catch_syscall_inferior_data*
7565 get_catch_syscall_inferior_data (struct inferior *inf)
7567 struct catch_syscall_inferior_data *inf_data;
7569 inf_data = inferior_data (inf, catch_syscall_inferior_data);
7570 if (inf_data == NULL)
7572 inf_data = XZALLOC (struct catch_syscall_inferior_data);
7573 set_inferior_data (inf, catch_syscall_inferior_data, inf_data);
7580 catch_syscall_inferior_data_cleanup (struct inferior *inf, void *arg)
7586 /* Implement the "insert" breakpoint_ops method for syscall
7590 insert_catch_syscall (struct bp_location *bl)
7592 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner;
7593 struct inferior *inf = current_inferior ();
7594 struct catch_syscall_inferior_data *inf_data
7595 = get_catch_syscall_inferior_data (inf);
7597 ++inf_data->total_syscalls_count;
7598 if (!c->syscalls_to_be_caught)
7599 ++inf_data->any_syscall_count;
7605 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
7610 if (iter >= VEC_length (int, inf_data->syscalls_counts))
7612 int old_size = VEC_length (int, inf_data->syscalls_counts);
7613 uintptr_t vec_addr_offset
7614 = old_size * ((uintptr_t) sizeof (int));
7616 VEC_safe_grow (int, inf_data->syscalls_counts, iter + 1);
7617 vec_addr = ((uintptr_t) VEC_address (int,
7618 inf_data->syscalls_counts)
7620 memset ((void *) vec_addr, 0,
7621 (iter + 1 - old_size) * sizeof (int));
7623 elem = VEC_index (int, inf_data->syscalls_counts, iter);
7624 VEC_replace (int, inf_data->syscalls_counts, iter, ++elem);
7628 return target_set_syscall_catchpoint (PIDGET (inferior_ptid),
7629 inf_data->total_syscalls_count != 0,
7630 inf_data->any_syscall_count,
7632 inf_data->syscalls_counts),
7634 inf_data->syscalls_counts));
7637 /* Implement the "remove" breakpoint_ops method for syscall
7641 remove_catch_syscall (struct bp_location *bl)
7643 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner;
7644 struct inferior *inf = current_inferior ();
7645 struct catch_syscall_inferior_data *inf_data
7646 = get_catch_syscall_inferior_data (inf);
7648 --inf_data->total_syscalls_count;
7649 if (!c->syscalls_to_be_caught)
7650 --inf_data->any_syscall_count;
7656 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
7660 if (iter >= VEC_length (int, inf_data->syscalls_counts))
7661 /* Shouldn't happen. */
7663 elem = VEC_index (int, inf_data->syscalls_counts, iter);
7664 VEC_replace (int, inf_data->syscalls_counts, iter, --elem);
7668 return target_set_syscall_catchpoint (PIDGET (inferior_ptid),
7669 inf_data->total_syscalls_count != 0,
7670 inf_data->any_syscall_count,
7672 inf_data->syscalls_counts),
7674 inf_data->syscalls_counts));
7677 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
7681 breakpoint_hit_catch_syscall (const struct bp_location *bl,
7682 struct address_space *aspace, CORE_ADDR bp_addr,
7683 const struct target_waitstatus *ws)
7685 /* We must check if we are catching specific syscalls in this
7686 breakpoint. If we are, then we must guarantee that the called
7687 syscall is the same syscall we are catching. */
7688 int syscall_number = 0;
7689 const struct syscall_catchpoint *c
7690 = (const struct syscall_catchpoint *) bl->owner;
7692 if (ws->kind != TARGET_WAITKIND_SYSCALL_ENTRY
7693 && ws->kind != TARGET_WAITKIND_SYSCALL_RETURN)
7696 syscall_number = ws->value.syscall_number;
7698 /* Now, checking if the syscall is the same. */
7699 if (c->syscalls_to_be_caught)
7704 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
7706 if (syscall_number == iter)
7716 /* Implement the "print_it" breakpoint_ops method for syscall
7719 static enum print_stop_action
7720 print_it_catch_syscall (bpstat bs)
7722 struct ui_out *uiout = current_uiout;
7723 struct breakpoint *b = bs->breakpoint_at;
7724 /* These are needed because we want to know in which state a
7725 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
7726 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
7727 must print "called syscall" or "returned from syscall". */
7729 struct target_waitstatus last;
7733 get_last_target_status (&ptid, &last);
7735 get_syscall_by_number (last.value.syscall_number, &s);
7737 annotate_catchpoint (b->number);
7739 if (b->disposition == disp_del)
7740 ui_out_text (uiout, "\nTemporary catchpoint ");
7742 ui_out_text (uiout, "\nCatchpoint ");
7743 if (ui_out_is_mi_like_p (uiout))
7745 ui_out_field_string (uiout, "reason",
7746 async_reason_lookup (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY
7747 ? EXEC_ASYNC_SYSCALL_ENTRY
7748 : EXEC_ASYNC_SYSCALL_RETURN));
7749 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7751 ui_out_field_int (uiout, "bkptno", b->number);
7753 if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY)
7754 ui_out_text (uiout, " (call to syscall ");
7756 ui_out_text (uiout, " (returned from syscall ");
7758 if (s.name == NULL || ui_out_is_mi_like_p (uiout))
7759 ui_out_field_int (uiout, "syscall-number", last.value.syscall_number);
7761 ui_out_field_string (uiout, "syscall-name", s.name);
7763 ui_out_text (uiout, "), ");
7765 return PRINT_SRC_AND_LOC;
7768 /* Implement the "print_one" breakpoint_ops method for syscall
7772 print_one_catch_syscall (struct breakpoint *b,
7773 struct bp_location **last_loc)
7775 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
7776 struct value_print_options opts;
7777 struct ui_out *uiout = current_uiout;
7779 get_user_print_options (&opts);
7780 /* Field 4, the address, is omitted (which makes the columns not
7781 line up too nicely with the headers, but the effect is relatively
7783 if (opts.addressprint)
7784 ui_out_field_skip (uiout, "addr");
7787 if (c->syscalls_to_be_caught
7788 && VEC_length (int, c->syscalls_to_be_caught) > 1)
7789 ui_out_text (uiout, "syscalls \"");
7791 ui_out_text (uiout, "syscall \"");
7793 if (c->syscalls_to_be_caught)
7796 char *text = xstrprintf ("%s", "");
7799 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
7804 get_syscall_by_number (iter, &s);
7807 text = xstrprintf ("%s%s, ", text, s.name);
7809 text = xstrprintf ("%s%d, ", text, iter);
7811 /* We have to xfree the last 'text' (now stored at 'x')
7812 because xstrprintf dynamically allocates new space for it
7816 /* Remove the last comma. */
7817 text[strlen (text) - 2] = '\0';
7818 ui_out_field_string (uiout, "what", text);
7821 ui_out_field_string (uiout, "what", "<any syscall>");
7822 ui_out_text (uiout, "\" ");
7825 /* Implement the "print_mention" breakpoint_ops method for syscall
7829 print_mention_catch_syscall (struct breakpoint *b)
7831 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
7833 if (c->syscalls_to_be_caught)
7837 if (VEC_length (int, c->syscalls_to_be_caught) > 1)
7838 printf_filtered (_("Catchpoint %d (syscalls"), b->number);
7840 printf_filtered (_("Catchpoint %d (syscall"), b->number);
7843 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
7847 get_syscall_by_number (iter, &s);
7850 printf_filtered (" '%s' [%d]", s.name, s.number);
7852 printf_filtered (" %d", s.number);
7854 printf_filtered (")");
7857 printf_filtered (_("Catchpoint %d (any syscall)"),
7861 /* Implement the "print_recreate" breakpoint_ops method for syscall
7865 print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp)
7867 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
7869 fprintf_unfiltered (fp, "catch syscall");
7871 if (c->syscalls_to_be_caught)
7876 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
7881 get_syscall_by_number (iter, &s);
7883 fprintf_unfiltered (fp, " %s", s.name);
7885 fprintf_unfiltered (fp, " %d", s.number);
7888 print_recreate_thread (b, fp);
7891 /* The breakpoint_ops structure to be used in syscall catchpoints. */
7893 static struct breakpoint_ops catch_syscall_breakpoint_ops;
7895 /* Returns non-zero if 'b' is a syscall catchpoint. */
7898 syscall_catchpoint_p (struct breakpoint *b)
7900 return (b->ops == &catch_syscall_breakpoint_ops);
7903 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
7904 is non-zero, then make the breakpoint temporary. If COND_STRING is
7905 not NULL, then store it in the breakpoint. OPS, if not NULL, is
7906 the breakpoint_ops structure associated to the catchpoint. */
7909 init_catchpoint (struct breakpoint *b,
7910 struct gdbarch *gdbarch, int tempflag,
7912 const struct breakpoint_ops *ops)
7914 struct symtab_and_line sal;
7917 sal.pspace = current_program_space;
7919 init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops);
7921 b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string);
7922 b->disposition = tempflag ? disp_del : disp_donttouch;
7926 install_breakpoint (int internal, struct breakpoint *b, int update_gll)
7928 add_to_breakpoint_chain (b);
7929 set_breakpoint_number (internal, b);
7932 observer_notify_breakpoint_created (b);
7935 update_global_location_list (1);
7939 create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch,
7940 int tempflag, char *cond_string,
7941 const struct breakpoint_ops *ops)
7943 struct fork_catchpoint *c = XNEW (struct fork_catchpoint);
7945 init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops);
7947 c->forked_inferior_pid = null_ptid;
7949 install_breakpoint (0, &c->base, 1);
7952 /* Exec catchpoints. */
7954 /* An instance of this type is used to represent an exec catchpoint.
7955 It includes a "struct breakpoint" as a kind of base class; users
7956 downcast to "struct breakpoint *" when needed. A breakpoint is
7957 really of this type iff its ops pointer points to
7958 CATCH_EXEC_BREAKPOINT_OPS. */
7960 struct exec_catchpoint
7962 /* The base class. */
7963 struct breakpoint base;
7965 /* Filename of a program whose exec triggered this catchpoint.
7966 This field is only valid immediately after this catchpoint has
7968 char *exec_pathname;
7971 /* Implement the "dtor" breakpoint_ops method for exec
7975 dtor_catch_exec (struct breakpoint *b)
7977 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
7979 xfree (c->exec_pathname);
7981 base_breakpoint_ops.dtor (b);
7985 insert_catch_exec (struct bp_location *bl)
7987 return target_insert_exec_catchpoint (PIDGET (inferior_ptid));
7991 remove_catch_exec (struct bp_location *bl)
7993 return target_remove_exec_catchpoint (PIDGET (inferior_ptid));
7997 breakpoint_hit_catch_exec (const struct bp_location *bl,
7998 struct address_space *aspace, CORE_ADDR bp_addr,
7999 const struct target_waitstatus *ws)
8001 struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner;
8003 if (ws->kind != TARGET_WAITKIND_EXECD)
8006 c->exec_pathname = xstrdup (ws->value.execd_pathname);
8010 static enum print_stop_action
8011 print_it_catch_exec (bpstat bs)
8013 struct ui_out *uiout = current_uiout;
8014 struct breakpoint *b = bs->breakpoint_at;
8015 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8017 annotate_catchpoint (b->number);
8018 if (b->disposition == disp_del)
8019 ui_out_text (uiout, "\nTemporary catchpoint ");
8021 ui_out_text (uiout, "\nCatchpoint ");
8022 if (ui_out_is_mi_like_p (uiout))
8024 ui_out_field_string (uiout, "reason",
8025 async_reason_lookup (EXEC_ASYNC_EXEC));
8026 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8028 ui_out_field_int (uiout, "bkptno", b->number);
8029 ui_out_text (uiout, " (exec'd ");
8030 ui_out_field_string (uiout, "new-exec", c->exec_pathname);
8031 ui_out_text (uiout, "), ");
8033 return PRINT_SRC_AND_LOC;
8037 print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc)
8039 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8040 struct value_print_options opts;
8041 struct ui_out *uiout = current_uiout;
8043 get_user_print_options (&opts);
8045 /* Field 4, the address, is omitted (which makes the columns
8046 not line up too nicely with the headers, but the effect
8047 is relatively readable). */
8048 if (opts.addressprint)
8049 ui_out_field_skip (uiout, "addr");
8051 ui_out_text (uiout, "exec");
8052 if (c->exec_pathname != NULL)
8054 ui_out_text (uiout, ", program \"");
8055 ui_out_field_string (uiout, "what", c->exec_pathname);
8056 ui_out_text (uiout, "\" ");
8061 print_mention_catch_exec (struct breakpoint *b)
8063 printf_filtered (_("Catchpoint %d (exec)"), b->number);
8066 /* Implement the "print_recreate" breakpoint_ops method for exec
8070 print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp)
8072 fprintf_unfiltered (fp, "catch exec");
8073 print_recreate_thread (b, fp);
8076 static struct breakpoint_ops catch_exec_breakpoint_ops;
8079 create_syscall_event_catchpoint (int tempflag, VEC(int) *filter,
8080 const struct breakpoint_ops *ops)
8082 struct syscall_catchpoint *c;
8083 struct gdbarch *gdbarch = get_current_arch ();
8085 c = XNEW (struct syscall_catchpoint);
8086 init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops);
8087 c->syscalls_to_be_caught = filter;
8089 install_breakpoint (0, &c->base, 1);
8093 hw_breakpoint_used_count (void)
8096 struct breakpoint *b;
8097 struct bp_location *bl;
8101 if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b))
8102 for (bl = b->loc; bl; bl = bl->next)
8104 /* Special types of hardware breakpoints may use more than
8106 i += b->ops->resources_needed (bl);
8113 /* Returns the resources B would use if it were a hardware
8117 hw_watchpoint_use_count (struct breakpoint *b)
8120 struct bp_location *bl;
8122 if (!breakpoint_enabled (b))
8125 for (bl = b->loc; bl; bl = bl->next)
8127 /* Special types of hardware watchpoints may use more than
8129 i += b->ops->resources_needed (bl);
8135 /* Returns the sum the used resources of all hardware watchpoints of
8136 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8137 the sum of the used resources of all hardware watchpoints of other
8138 types _not_ TYPE. */
8141 hw_watchpoint_used_count_others (struct breakpoint *except,
8142 enum bptype type, int *other_type_used)
8145 struct breakpoint *b;
8147 *other_type_used = 0;
8152 if (!breakpoint_enabled (b))
8155 if (b->type == type)
8156 i += hw_watchpoint_use_count (b);
8157 else if (is_hardware_watchpoint (b))
8158 *other_type_used = 1;
8165 disable_watchpoints_before_interactive_call_start (void)
8167 struct breakpoint *b;
8171 if (is_watchpoint (b) && breakpoint_enabled (b))
8173 b->enable_state = bp_call_disabled;
8174 update_global_location_list (0);
8180 enable_watchpoints_after_interactive_call_stop (void)
8182 struct breakpoint *b;
8186 if (is_watchpoint (b) && b->enable_state == bp_call_disabled)
8188 b->enable_state = bp_enabled;
8189 update_global_location_list (1);
8195 disable_breakpoints_before_startup (void)
8197 current_program_space->executing_startup = 1;
8198 update_global_location_list (0);
8202 enable_breakpoints_after_startup (void)
8204 current_program_space->executing_startup = 0;
8205 breakpoint_re_set ();
8209 /* Set a breakpoint that will evaporate an end of command
8210 at address specified by SAL.
8211 Restrict it to frame FRAME if FRAME is nonzero. */
8214 set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal,
8215 struct frame_id frame_id, enum bptype type)
8217 struct breakpoint *b;
8219 /* If FRAME_ID is valid, it should be a real frame, not an inlined
8221 gdb_assert (!frame_id_inlined_p (frame_id));
8223 b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops);
8224 b->enable_state = bp_enabled;
8225 b->disposition = disp_donttouch;
8226 b->frame_id = frame_id;
8228 /* If we're debugging a multi-threaded program, then we want
8229 momentary breakpoints to be active in only a single thread of
8231 if (in_thread_list (inferior_ptid))
8232 b->thread = pid_to_thread_id (inferior_ptid);
8234 update_global_location_list_nothrow (1);
8239 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8240 The new breakpoint will have type TYPE, and use OPS as it
8243 static struct breakpoint *
8244 momentary_breakpoint_from_master (struct breakpoint *orig,
8246 const struct breakpoint_ops *ops)
8248 struct breakpoint *copy;
8250 copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops);
8251 copy->loc = allocate_bp_location (copy);
8252 set_breakpoint_location_function (copy->loc, 1);
8254 copy->loc->gdbarch = orig->loc->gdbarch;
8255 copy->loc->requested_address = orig->loc->requested_address;
8256 copy->loc->address = orig->loc->address;
8257 copy->loc->section = orig->loc->section;
8258 copy->loc->pspace = orig->loc->pspace;
8259 copy->loc->probe = orig->loc->probe;
8261 if (orig->loc->source_file != NULL)
8262 copy->loc->source_file = xstrdup (orig->loc->source_file);
8264 copy->loc->line_number = orig->loc->line_number;
8265 copy->frame_id = orig->frame_id;
8266 copy->thread = orig->thread;
8267 copy->pspace = orig->pspace;
8269 copy->enable_state = bp_enabled;
8270 copy->disposition = disp_donttouch;
8271 copy->number = internal_breakpoint_number--;
8273 update_global_location_list_nothrow (0);
8277 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8281 clone_momentary_breakpoint (struct breakpoint *orig)
8283 /* If there's nothing to clone, then return nothing. */
8287 return momentary_breakpoint_from_master (orig, orig->type, orig->ops);
8291 set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc,
8294 struct symtab_and_line sal;
8296 sal = find_pc_line (pc, 0);
8298 sal.section = find_pc_overlay (pc);
8299 sal.explicit_pc = 1;
8301 return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type);
8305 /* Tell the user we have just set a breakpoint B. */
8308 mention (struct breakpoint *b)
8310 b->ops->print_mention (b);
8311 if (ui_out_is_mi_like_p (current_uiout))
8313 printf_filtered ("\n");
8317 static struct bp_location *
8318 add_location_to_breakpoint (struct breakpoint *b,
8319 const struct symtab_and_line *sal)
8321 struct bp_location *loc, **tmp;
8322 CORE_ADDR adjusted_address;
8323 struct gdbarch *loc_gdbarch = get_sal_arch (*sal);
8325 if (loc_gdbarch == NULL)
8326 loc_gdbarch = b->gdbarch;
8328 /* Adjust the breakpoint's address prior to allocating a location.
8329 Once we call allocate_bp_location(), that mostly uninitialized
8330 location will be placed on the location chain. Adjustment of the
8331 breakpoint may cause target_read_memory() to be called and we do
8332 not want its scan of the location chain to find a breakpoint and
8333 location that's only been partially initialized. */
8334 adjusted_address = adjust_breakpoint_address (loc_gdbarch,
8337 loc = allocate_bp_location (b);
8338 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
8342 loc->requested_address = sal->pc;
8343 loc->address = adjusted_address;
8344 loc->pspace = sal->pspace;
8345 loc->probe = sal->probe;
8346 gdb_assert (loc->pspace != NULL);
8347 loc->section = sal->section;
8348 loc->gdbarch = loc_gdbarch;
8350 if (sal->symtab != NULL)
8351 loc->source_file = xstrdup (sal->symtab->filename);
8352 loc->line_number = sal->line;
8354 set_breakpoint_location_function (loc,
8355 sal->explicit_pc || sal->explicit_line);
8360 /* Return 1 if LOC is pointing to a permanent breakpoint,
8361 return 0 otherwise. */
8364 bp_loc_is_permanent (struct bp_location *loc)
8368 const gdb_byte *bpoint;
8369 gdb_byte *target_mem;
8370 struct cleanup *cleanup;
8373 gdb_assert (loc != NULL);
8375 addr = loc->address;
8376 bpoint = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len);
8378 /* Software breakpoints unsupported? */
8382 target_mem = alloca (len);
8384 /* Enable the automatic memory restoration from breakpoints while
8385 we read the memory. Otherwise we could say about our temporary
8386 breakpoints they are permanent. */
8387 cleanup = save_current_space_and_thread ();
8389 switch_to_program_space_and_thread (loc->pspace);
8390 make_show_memory_breakpoints_cleanup (0);
8392 if (target_read_memory (loc->address, target_mem, len) == 0
8393 && memcmp (target_mem, bpoint, len) == 0)
8396 do_cleanups (cleanup);
8401 /* The style in which to perform a dynamic printf. This is a user
8402 option because different output options have different tradeoffs;
8403 if GDB does the printing, there is better error handling if there
8404 is a problem with any of the arguments, but using an inferior
8405 function lets you have special-purpose printers and sending of
8406 output to the same place as compiled-in print functions. (Future
8407 styles may include the ability to do a target-side printf.) */
8409 static const char dprintf_style_gdb[] = "gdb";
8410 static const char dprintf_style_call[] = "call";
8411 static const char *const dprintf_style_enums[] = {
8416 static const char *dprintf_style = dprintf_style_gdb;
8418 /* The function to use for dynamic printf if the preferred style is to
8419 call into the inferior. The value is simply a string that is
8420 copied into the command, so it can be anything that GDB can
8421 evaluate to a callable address, not necessarily a function name. */
8423 static char *dprintf_function = "";
8425 /* The channel to use for dynamic printf if the preferred style is to
8426 call into the inferior; if a nonempty string, it will be passed to
8427 the call as the first argument, with the format string as the
8428 second. As with the dprintf function, this can be anything that
8429 GDB knows how to evaluate, so in addition to common choices like
8430 "stderr", this could be an app-specific expression like
8431 "mystreams[curlogger]". */
8433 static char *dprintf_channel = "";
8435 /* Build a command list for the dprintf corresponding to the current
8436 settings of the dprintf style options. */
8439 update_dprintf_command_list (struct breakpoint *b)
8441 char *dprintf_args = b->extra_string;
8442 char *printf_line = NULL;
8447 dprintf_args = skip_spaces (dprintf_args);
8449 /* Allow a comma, as it may have terminated a location, but don't
8451 if (*dprintf_args == ',')
8453 dprintf_args = skip_spaces (dprintf_args);
8455 if (*dprintf_args != '"')
8456 error (_("Bad format string, missing '\"'."));
8458 if (strcmp (dprintf_style, "gdb") == 0)
8459 printf_line = xstrprintf ("printf %s", dprintf_args);
8460 else if (strcmp (dprintf_style, "call") == 0)
8462 if (!dprintf_function)
8463 error (_("No function supplied for dprintf call"));
8465 if (dprintf_channel && strlen (dprintf_channel) > 0)
8466 printf_line = xstrprintf ("call (void) %s (%s,%s)",
8471 printf_line = xstrprintf ("call (void) %s (%s)",
8476 internal_error (__FILE__, __LINE__,
8477 _("Invalid dprintf style."));
8479 /* Manufacture a printf/continue sequence. */
8482 struct command_line *printf_cmd_line, *cont_cmd_line = NULL;
8484 cont_cmd_line = xmalloc (sizeof (struct command_line));
8485 cont_cmd_line->control_type = simple_control;
8486 cont_cmd_line->body_count = 0;
8487 cont_cmd_line->body_list = NULL;
8488 cont_cmd_line->next = NULL;
8489 cont_cmd_line->line = xstrdup ("continue");
8491 printf_cmd_line = xmalloc (sizeof (struct command_line));
8492 printf_cmd_line->control_type = simple_control;
8493 printf_cmd_line->body_count = 0;
8494 printf_cmd_line->body_list = NULL;
8495 printf_cmd_line->next = cont_cmd_line;
8496 printf_cmd_line->line = printf_line;
8498 breakpoint_set_commands (b, printf_cmd_line);
8502 /* Update all dprintf commands, making their command lists reflect
8503 current style settings. */
8506 update_dprintf_commands (char *args, int from_tty,
8507 struct cmd_list_element *c)
8509 struct breakpoint *b;
8513 if (b->type == bp_dprintf)
8514 update_dprintf_command_list (b);
8518 /* Create a breakpoint with SAL as location. Use ADDR_STRING
8519 as textual description of the location, and COND_STRING
8520 as condition expression. */
8523 init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch,
8524 struct symtabs_and_lines sals, char *addr_string,
8525 char *filter, char *cond_string,
8527 enum bptype type, enum bpdisp disposition,
8528 int thread, int task, int ignore_count,
8529 const struct breakpoint_ops *ops, int from_tty,
8530 int enabled, int internal, unsigned flags,
8531 int display_canonical)
8535 if (type == bp_hardware_breakpoint)
8537 int target_resources_ok;
8539 i = hw_breakpoint_used_count ();
8540 target_resources_ok =
8541 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
8543 if (target_resources_ok == 0)
8544 error (_("No hardware breakpoint support in the target."));
8545 else if (target_resources_ok < 0)
8546 error (_("Hardware breakpoints used exceeds limit."));
8549 gdb_assert (sals.nelts > 0);
8551 for (i = 0; i < sals.nelts; ++i)
8553 struct symtab_and_line sal = sals.sals[i];
8554 struct bp_location *loc;
8558 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
8560 loc_gdbarch = gdbarch;
8562 describe_other_breakpoints (loc_gdbarch,
8563 sal.pspace, sal.pc, sal.section, thread);
8568 init_raw_breakpoint (b, gdbarch, sal, type, ops);
8572 b->cond_string = cond_string;
8573 b->extra_string = extra_string;
8574 b->ignore_count = ignore_count;
8575 b->enable_state = enabled ? bp_enabled : bp_disabled;
8576 b->disposition = disposition;
8578 if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
8579 b->loc->inserted = 1;
8581 if (type == bp_static_tracepoint)
8583 struct tracepoint *t = (struct tracepoint *) b;
8584 struct static_tracepoint_marker marker;
8586 if (strace_marker_p (b))
8588 /* We already know the marker exists, otherwise, we
8589 wouldn't see a sal for it. */
8590 char *p = &addr_string[3];
8594 p = skip_spaces (p);
8596 endp = skip_to_space (p);
8598 marker_str = savestring (p, endp - p);
8599 t->static_trace_marker_id = marker_str;
8601 printf_filtered (_("Probed static tracepoint "
8603 t->static_trace_marker_id);
8605 else if (target_static_tracepoint_marker_at (sal.pc, &marker))
8607 t->static_trace_marker_id = xstrdup (marker.str_id);
8608 release_static_tracepoint_marker (&marker);
8610 printf_filtered (_("Probed static tracepoint "
8612 t->static_trace_marker_id);
8615 warning (_("Couldn't determine the static "
8616 "tracepoint marker to probe"));
8623 loc = add_location_to_breakpoint (b, &sal);
8624 if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
8628 if (bp_loc_is_permanent (loc))
8629 make_breakpoint_permanent (b);
8633 char *arg = b->cond_string;
8634 loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0);
8636 error (_("Garbage '%s' follows condition"), arg);
8639 /* Dynamic printf requires and uses additional arguments on the
8640 command line, otherwise it's an error. */
8641 if (type == bp_dprintf)
8643 if (b->extra_string)
8644 update_dprintf_command_list (b);
8646 error (_("Format string required"));
8648 else if (b->extra_string)
8649 error (_("Garbage '%s' at end of command"), b->extra_string);
8652 b->display_canonical = display_canonical;
8654 b->addr_string = addr_string;
8656 /* addr_string has to be used or breakpoint_re_set will delete
8659 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
8664 create_breakpoint_sal (struct gdbarch *gdbarch,
8665 struct symtabs_and_lines sals, char *addr_string,
8666 char *filter, char *cond_string,
8668 enum bptype type, enum bpdisp disposition,
8669 int thread, int task, int ignore_count,
8670 const struct breakpoint_ops *ops, int from_tty,
8671 int enabled, int internal, unsigned flags,
8672 int display_canonical)
8674 struct breakpoint *b;
8675 struct cleanup *old_chain;
8677 if (is_tracepoint_type (type))
8679 struct tracepoint *t;
8681 t = XCNEW (struct tracepoint);
8685 b = XNEW (struct breakpoint);
8687 old_chain = make_cleanup (xfree, b);
8689 init_breakpoint_sal (b, gdbarch,
8691 filter, cond_string, extra_string,
8693 thread, task, ignore_count,
8695 enabled, internal, flags,
8697 discard_cleanups (old_chain);
8699 install_breakpoint (internal, b, 0);
8702 /* Add SALS.nelts breakpoints to the breakpoint table. For each
8703 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
8704 value. COND_STRING, if not NULL, specified the condition to be
8705 used for all breakpoints. Essentially the only case where
8706 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
8707 function. In that case, it's still not possible to specify
8708 separate conditions for different overloaded functions, so
8709 we take just a single condition string.
8711 NOTE: If the function succeeds, the caller is expected to cleanup
8712 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
8713 array contents). If the function fails (error() is called), the
8714 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
8715 COND and SALS arrays and each of those arrays contents. */
8718 create_breakpoints_sal (struct gdbarch *gdbarch,
8719 struct linespec_result *canonical,
8720 char *cond_string, char *extra_string,
8721 enum bptype type, enum bpdisp disposition,
8722 int thread, int task, int ignore_count,
8723 const struct breakpoint_ops *ops, int from_tty,
8724 int enabled, int internal, unsigned flags)
8727 struct linespec_sals *lsal;
8729 if (canonical->pre_expanded)
8730 gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1);
8732 for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i)
8734 /* Note that 'addr_string' can be NULL in the case of a plain
8735 'break', without arguments. */
8736 char *addr_string = (canonical->addr_string
8737 ? xstrdup (canonical->addr_string)
8739 char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL;
8740 struct cleanup *inner = make_cleanup (xfree, addr_string);
8742 make_cleanup (xfree, filter_string);
8743 create_breakpoint_sal (gdbarch, lsal->sals,
8746 cond_string, extra_string,
8748 thread, task, ignore_count, ops,
8749 from_tty, enabled, internal, flags,
8750 canonical->special_display);
8751 discard_cleanups (inner);
8755 /* Parse ADDRESS which is assumed to be a SAL specification possibly
8756 followed by conditionals. On return, SALS contains an array of SAL
8757 addresses found. ADDR_STRING contains a vector of (canonical)
8758 address strings. ADDRESS points to the end of the SAL.
8760 The array and the line spec strings are allocated on the heap, it is
8761 the caller's responsibility to free them. */
8764 parse_breakpoint_sals (char **address,
8765 struct linespec_result *canonical)
8767 char *addr_start = *address;
8769 /* If no arg given, or if first arg is 'if ', use the default
8771 if ((*address) == NULL
8772 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
8774 /* The last displayed codepoint, if it's valid, is our default breakpoint
8776 if (last_displayed_sal_is_valid ())
8778 struct linespec_sals lsal;
8779 struct symtab_and_line sal;
8781 init_sal (&sal); /* Initialize to zeroes. */
8782 lsal.sals.sals = (struct symtab_and_line *)
8783 xmalloc (sizeof (struct symtab_and_line));
8785 /* Set sal's pspace, pc, symtab, and line to the values
8786 corresponding to the last call to print_frame_info. */
8787 get_last_displayed_sal (&sal);
8788 sal.section = find_pc_overlay (sal.pc);
8790 /* "break" without arguments is equivalent to "break *PC"
8791 where PC is the last displayed codepoint's address. So
8792 make sure to set sal.explicit_pc to prevent GDB from
8793 trying to expand the list of sals to include all other
8794 instances with the same symtab and line. */
8795 sal.explicit_pc = 1;
8797 lsal.sals.sals[0] = sal;
8798 lsal.sals.nelts = 1;
8799 lsal.canonical = NULL;
8801 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
8804 error (_("No default breakpoint address now."));
8808 /* Force almost all breakpoints to be in terms of the
8809 current_source_symtab (which is decode_line_1's default).
8810 This should produce the results we want almost all of the
8811 time while leaving default_breakpoint_* alone. */
8812 if (last_displayed_sal_is_valid ())
8813 decode_line_full (address, DECODE_LINE_FUNFIRSTLINE,
8814 get_last_displayed_symtab (),
8815 get_last_displayed_line (),
8816 canonical, NULL, NULL);
8818 decode_line_full (address, DECODE_LINE_FUNFIRSTLINE,
8819 (struct symtab *) NULL, 0,
8820 canonical, NULL, NULL);
8825 /* Convert each SAL into a real PC. Verify that the PC can be
8826 inserted as a breakpoint. If it can't throw an error. */
8829 breakpoint_sals_to_pc (struct symtabs_and_lines *sals)
8833 for (i = 0; i < sals->nelts; i++)
8834 resolve_sal_pc (&sals->sals[i]);
8837 /* Fast tracepoints may have restrictions on valid locations. For
8838 instance, a fast tracepoint using a jump instead of a trap will
8839 likely have to overwrite more bytes than a trap would, and so can
8840 only be placed where the instruction is longer than the jump, or a
8841 multi-instruction sequence does not have a jump into the middle of
8845 check_fast_tracepoint_sals (struct gdbarch *gdbarch,
8846 struct symtabs_and_lines *sals)
8849 struct symtab_and_line *sal;
8851 struct cleanup *old_chain;
8853 for (i = 0; i < sals->nelts; i++)
8855 struct gdbarch *sarch;
8857 sal = &sals->sals[i];
8859 sarch = get_sal_arch (*sal);
8860 /* We fall back to GDBARCH if there is no architecture
8861 associated with SAL. */
8864 rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc,
8866 old_chain = make_cleanup (xfree, msg);
8869 error (_("May not have a fast tracepoint at 0x%s%s"),
8870 paddress (sarch, sal->pc), (msg ? msg : ""));
8872 do_cleanups (old_chain);
8876 /* Given TOK, a string specification of condition and thread, as
8877 accepted by the 'break' command, extract the condition
8878 string and thread number and set *COND_STRING and *THREAD.
8879 PC identifies the context at which the condition should be parsed.
8880 If no condition is found, *COND_STRING is set to NULL.
8881 If no thread is found, *THREAD is set to -1. */
8884 find_condition_and_thread (char *tok, CORE_ADDR pc,
8885 char **cond_string, int *thread, int *task,
8888 *cond_string = NULL;
8894 char *cond_start = NULL;
8895 char *cond_end = NULL;
8897 tok = skip_spaces (tok);
8899 if ((*tok == '"' || *tok == ',') && rest)
8901 *rest = savestring (tok, strlen (tok));
8905 end_tok = skip_to_space (tok);
8907 toklen = end_tok - tok;
8909 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
8911 struct expression *expr;
8913 tok = cond_start = end_tok + 1;
8914 expr = parse_exp_1 (&tok, block_for_pc (pc), 0);
8917 *cond_string = savestring (cond_start, cond_end - cond_start);
8919 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
8925 *thread = strtol (tok, &tok, 0);
8927 error (_("Junk after thread keyword."));
8928 if (!valid_thread_id (*thread))
8929 error (_("Unknown thread %d."), *thread);
8931 else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0)
8937 *task = strtol (tok, &tok, 0);
8939 error (_("Junk after task keyword."));
8940 if (!valid_task_id (*task))
8941 error (_("Unknown task %d."), *task);
8945 *rest = savestring (tok, strlen (tok));
8949 error (_("Junk at end of arguments."));
8953 /* Decode a static tracepoint marker spec. */
8955 static struct symtabs_and_lines
8956 decode_static_tracepoint_spec (char **arg_p)
8958 VEC(static_tracepoint_marker_p) *markers = NULL;
8959 struct symtabs_and_lines sals;
8960 struct symtab_and_line sal;
8962 struct cleanup *old_chain;
8963 char *p = &(*arg_p)[3];
8968 p = skip_spaces (p);
8970 endp = skip_to_space (p);
8972 marker_str = savestring (p, endp - p);
8973 old_chain = make_cleanup (xfree, marker_str);
8975 markers = target_static_tracepoint_markers_by_strid (marker_str);
8976 if (VEC_empty(static_tracepoint_marker_p, markers))
8977 error (_("No known static tracepoint marker named %s"), marker_str);
8979 sals.nelts = VEC_length(static_tracepoint_marker_p, markers);
8980 sals.sals = xmalloc (sizeof *sals.sals * sals.nelts);
8982 for (i = 0; i < sals.nelts; i++)
8984 struct static_tracepoint_marker *marker;
8986 marker = VEC_index (static_tracepoint_marker_p, markers, i);
8988 init_sal (&sals.sals[i]);
8990 sals.sals[i] = find_pc_line (marker->address, 0);
8991 sals.sals[i].pc = marker->address;
8993 release_static_tracepoint_marker (marker);
8996 do_cleanups (old_chain);
9002 /* Set a breakpoint. This function is shared between CLI and MI
9003 functions for setting a breakpoint. This function has two major
9004 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
9005 parameter. If non-zero, the function will parse arg, extracting
9006 breakpoint location, address and thread. Otherwise, ARG is just
9007 the location of breakpoint, with condition and thread specified by
9008 the COND_STRING and THREAD parameters. If INTERNAL is non-zero,
9009 the breakpoint number will be allocated from the internal
9010 breakpoint count. Returns true if any breakpoint was created;
9014 create_breakpoint (struct gdbarch *gdbarch,
9015 char *arg, char *cond_string,
9016 int thread, char *extra_string,
9017 int parse_condition_and_thread,
9018 int tempflag, enum bptype type_wanted,
9020 enum auto_boolean pending_break_support,
9021 const struct breakpoint_ops *ops,
9022 int from_tty, int enabled, int internal,
9025 volatile struct gdb_exception e;
9026 char *copy_arg = NULL;
9027 char *addr_start = arg;
9028 struct linespec_result canonical;
9029 struct cleanup *old_chain;
9030 struct cleanup *bkpt_chain = NULL;
9034 int prev_bkpt_count = breakpoint_count;
9036 gdb_assert (ops != NULL);
9038 init_linespec_result (&canonical);
9040 TRY_CATCH (e, RETURN_MASK_ALL)
9042 ops->create_sals_from_address (&arg, &canonical, type_wanted,
9043 addr_start, ©_arg);
9046 /* If caller is interested in rc value from parse, set value. */
9050 if (VEC_empty (linespec_sals, canonical.sals))
9056 case NOT_FOUND_ERROR:
9058 /* If pending breakpoint support is turned off, throw
9061 if (pending_break_support == AUTO_BOOLEAN_FALSE)
9062 throw_exception (e);
9064 exception_print (gdb_stderr, e);
9066 /* If pending breakpoint support is auto query and the user
9067 selects no, then simply return the error code. */
9068 if (pending_break_support == AUTO_BOOLEAN_AUTO
9069 && !nquery (_("Make %s pending on future shared library load? "),
9070 bptype_string (type_wanted)))
9073 /* At this point, either the user was queried about setting
9074 a pending breakpoint and selected yes, or pending
9075 breakpoint behavior is on and thus a pending breakpoint
9076 is defaulted on behalf of the user. */
9078 struct linespec_sals lsal;
9080 copy_arg = xstrdup (addr_start);
9081 lsal.canonical = xstrdup (copy_arg);
9082 lsal.sals.nelts = 1;
9083 lsal.sals.sals = XNEW (struct symtab_and_line);
9084 init_sal (&lsal.sals.sals[0]);
9086 VEC_safe_push (linespec_sals, canonical.sals, &lsal);
9090 throw_exception (e);
9094 throw_exception (e);
9097 /* Create a chain of things that always need to be cleaned up. */
9098 old_chain = make_cleanup_destroy_linespec_result (&canonical);
9100 /* ----------------------------- SNIP -----------------------------
9101 Anything added to the cleanup chain beyond this point is assumed
9102 to be part of a breakpoint. If the breakpoint create succeeds
9103 then the memory is not reclaimed. */
9104 bkpt_chain = make_cleanup (null_cleanup, 0);
9106 /* Resolve all line numbers to PC's and verify that the addresses
9107 are ok for the target. */
9111 struct linespec_sals *iter;
9113 for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
9114 breakpoint_sals_to_pc (&iter->sals);
9117 /* Fast tracepoints may have additional restrictions on location. */
9118 if (!pending && type_wanted == bp_fast_tracepoint)
9121 struct linespec_sals *iter;
9123 for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
9124 check_fast_tracepoint_sals (gdbarch, &iter->sals);
9127 /* Verify that condition can be parsed, before setting any
9128 breakpoints. Allocate a separate condition expression for each
9132 struct linespec_sals *lsal;
9134 lsal = VEC_index (linespec_sals, canonical.sals, 0);
9136 if (parse_condition_and_thread)
9139 /* Here we only parse 'arg' to separate condition
9140 from thread number, so parsing in context of first
9141 sal is OK. When setting the breakpoint we'll
9142 re-parse it in context of each sal. */
9146 find_condition_and_thread (arg, lsal->sals.sals[0].pc, &cond_string,
9147 &thread, &task, &rest);
9149 make_cleanup (xfree, cond_string);
9151 make_cleanup (xfree, rest);
9153 extra_string = rest;
9157 /* Create a private copy of condition string. */
9160 cond_string = xstrdup (cond_string);
9161 make_cleanup (xfree, cond_string);
9163 /* Create a private copy of any extra string. */
9166 extra_string = xstrdup (extra_string);
9167 make_cleanup (xfree, extra_string);
9171 ops->create_breakpoints_sal (gdbarch, &canonical, lsal,
9172 cond_string, extra_string, type_wanted,
9173 tempflag ? disp_del : disp_donttouch,
9174 thread, task, ignore_count, ops,
9175 from_tty, enabled, internal, flags);
9179 struct breakpoint *b;
9181 make_cleanup (xfree, copy_arg);
9183 if (is_tracepoint_type (type_wanted))
9185 struct tracepoint *t;
9187 t = XCNEW (struct tracepoint);
9191 b = XNEW (struct breakpoint);
9193 init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops);
9195 b->addr_string = copy_arg;
9196 b->cond_string = NULL;
9197 b->extra_string = NULL;
9198 b->ignore_count = ignore_count;
9199 b->disposition = tempflag ? disp_del : disp_donttouch;
9200 b->condition_not_parsed = 1;
9201 b->enable_state = enabled ? bp_enabled : bp_disabled;
9202 if ((type_wanted != bp_breakpoint
9203 && type_wanted != bp_hardware_breakpoint) || thread != -1)
9204 b->pspace = current_program_space;
9206 install_breakpoint (internal, b, 0);
9209 if (VEC_length (linespec_sals, canonical.sals) > 1)
9211 warning (_("Multiple breakpoints were set.\nUse the "
9212 "\"delete\" command to delete unwanted breakpoints."));
9213 prev_breakpoint_count = prev_bkpt_count;
9216 /* That's it. Discard the cleanups for data inserted into the
9218 discard_cleanups (bkpt_chain);
9219 /* But cleanup everything else. */
9220 do_cleanups (old_chain);
9222 /* error call may happen here - have BKPT_CHAIN already discarded. */
9223 update_global_location_list (1);
9228 /* Set a breakpoint.
9229 ARG is a string describing breakpoint address,
9230 condition, and thread.
9231 FLAG specifies if a breakpoint is hardware on,
9232 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9236 break_command_1 (char *arg, int flag, int from_tty)
9238 int tempflag = flag & BP_TEMPFLAG;
9239 enum bptype type_wanted = (flag & BP_HARDWAREFLAG
9240 ? bp_hardware_breakpoint
9242 struct breakpoint_ops *ops;
9243 const char *arg_cp = arg;
9245 /* Matching breakpoints on probes. */
9246 if (arg && probe_linespec_to_ops (&arg_cp) != NULL)
9247 ops = &bkpt_probe_breakpoint_ops;
9249 ops = &bkpt_breakpoint_ops;
9251 create_breakpoint (get_current_arch (),
9253 NULL, 0, NULL, 1 /* parse arg */,
9254 tempflag, type_wanted,
9255 0 /* Ignore count */,
9256 pending_break_support,
9264 /* Helper function for break_command_1 and disassemble_command. */
9267 resolve_sal_pc (struct symtab_and_line *sal)
9271 if (sal->pc == 0 && sal->symtab != NULL)
9273 if (!find_line_pc (sal->symtab, sal->line, &pc))
9274 error (_("No line %d in file \"%s\"."),
9275 sal->line, sal->symtab->filename);
9278 /* If this SAL corresponds to a breakpoint inserted using a line
9279 number, then skip the function prologue if necessary. */
9280 if (sal->explicit_line)
9281 skip_prologue_sal (sal);
9284 if (sal->section == 0 && sal->symtab != NULL)
9286 struct blockvector *bv;
9290 bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab);
9293 sym = block_linkage_function (b);
9296 fixup_symbol_section (sym, sal->symtab->objfile);
9297 sal->section = SYMBOL_OBJ_SECTION (sym);
9301 /* It really is worthwhile to have the section, so we'll
9302 just have to look harder. This case can be executed
9303 if we have line numbers but no functions (as can
9304 happen in assembly source). */
9306 struct minimal_symbol *msym;
9307 struct cleanup *old_chain = save_current_space_and_thread ();
9309 switch_to_program_space_and_thread (sal->pspace);
9311 msym = lookup_minimal_symbol_by_pc (sal->pc);
9313 sal->section = SYMBOL_OBJ_SECTION (msym);
9315 do_cleanups (old_chain);
9322 break_command (char *arg, int from_tty)
9324 break_command_1 (arg, 0, from_tty);
9328 tbreak_command (char *arg, int from_tty)
9330 break_command_1 (arg, BP_TEMPFLAG, from_tty);
9334 hbreak_command (char *arg, int from_tty)
9336 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
9340 thbreak_command (char *arg, int from_tty)
9342 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
9346 stop_command (char *arg, int from_tty)
9348 printf_filtered (_("Specify the type of breakpoint to set.\n\
9349 Usage: stop in <function | address>\n\
9350 stop at <line>\n"));
9354 stopin_command (char *arg, int from_tty)
9358 if (arg == (char *) NULL)
9360 else if (*arg != '*')
9365 /* Look for a ':'. If this is a line number specification, then
9366 say it is bad, otherwise, it should be an address or
9367 function/method name. */
9368 while (*argptr && !hasColon)
9370 hasColon = (*argptr == ':');
9375 badInput = (*argptr != ':'); /* Not a class::method */
9377 badInput = isdigit (*arg); /* a simple line number */
9381 printf_filtered (_("Usage: stop in <function | address>\n"));
9383 break_command_1 (arg, 0, from_tty);
9387 stopat_command (char *arg, int from_tty)
9391 if (arg == (char *) NULL || *arg == '*') /* no line number */
9398 /* Look for a ':'. If there is a '::' then get out, otherwise
9399 it is probably a line number. */
9400 while (*argptr && !hasColon)
9402 hasColon = (*argptr == ':');
9407 badInput = (*argptr == ':'); /* we have class::method */
9409 badInput = !isdigit (*arg); /* not a line number */
9413 printf_filtered (_("Usage: stop at <line>\n"));
9415 break_command_1 (arg, 0, from_tty);
9418 void dprintf_command (char *arg, int from_tty);
9420 /* The dynamic printf command is mostly like a regular breakpoint, but
9421 with a prewired command list consisting of a single output command,
9422 built from extra arguments supplied on the dprintf command
9426 dprintf_command (char *arg, int from_tty)
9428 create_breakpoint (get_current_arch (),
9430 NULL, 0, NULL, 1 /* parse arg */,
9432 0 /* Ignore count */,
9433 pending_break_support,
9434 &dprintf_breakpoint_ops,
9441 /* Implement the "breakpoint_hit" breakpoint_ops method for
9442 ranged breakpoints. */
9445 breakpoint_hit_ranged_breakpoint (const struct bp_location *bl,
9446 struct address_space *aspace,
9448 const struct target_waitstatus *ws)
9450 if (ws->kind != TARGET_WAITKIND_STOPPED
9451 || ws->value.sig != TARGET_SIGNAL_TRAP)
9454 return breakpoint_address_match_range (bl->pspace->aspace, bl->address,
9455 bl->length, aspace, bp_addr);
9458 /* Implement the "resources_needed" breakpoint_ops method for
9459 ranged breakpoints. */
9462 resources_needed_ranged_breakpoint (const struct bp_location *bl)
9464 return target_ranged_break_num_registers ();
9467 /* Implement the "print_it" breakpoint_ops method for
9468 ranged breakpoints. */
9470 static enum print_stop_action
9471 print_it_ranged_breakpoint (bpstat bs)
9473 struct breakpoint *b = bs->breakpoint_at;
9474 struct bp_location *bl = b->loc;
9475 struct ui_out *uiout = current_uiout;
9477 gdb_assert (b->type == bp_hardware_breakpoint);
9479 /* Ranged breakpoints have only one location. */
9480 gdb_assert (bl && bl->next == NULL);
9482 annotate_breakpoint (b->number);
9483 if (b->disposition == disp_del)
9484 ui_out_text (uiout, "\nTemporary ranged breakpoint ");
9486 ui_out_text (uiout, "\nRanged breakpoint ");
9487 if (ui_out_is_mi_like_p (uiout))
9489 ui_out_field_string (uiout, "reason",
9490 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
9491 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
9493 ui_out_field_int (uiout, "bkptno", b->number);
9494 ui_out_text (uiout, ", ");
9496 return PRINT_SRC_AND_LOC;
9499 /* Implement the "print_one" breakpoint_ops method for
9500 ranged breakpoints. */
9503 print_one_ranged_breakpoint (struct breakpoint *b,
9504 struct bp_location **last_loc)
9506 struct bp_location *bl = b->loc;
9507 struct value_print_options opts;
9508 struct ui_out *uiout = current_uiout;
9510 /* Ranged breakpoints have only one location. */
9511 gdb_assert (bl && bl->next == NULL);
9513 get_user_print_options (&opts);
9515 if (opts.addressprint)
9516 /* We don't print the address range here, it will be printed later
9517 by print_one_detail_ranged_breakpoint. */
9518 ui_out_field_skip (uiout, "addr");
9520 print_breakpoint_location (b, bl);
9524 /* Implement the "print_one_detail" breakpoint_ops method for
9525 ranged breakpoints. */
9528 print_one_detail_ranged_breakpoint (const struct breakpoint *b,
9529 struct ui_out *uiout)
9531 CORE_ADDR address_start, address_end;
9532 struct bp_location *bl = b->loc;
9533 struct ui_file *stb = mem_fileopen ();
9534 struct cleanup *cleanup = make_cleanup_ui_file_delete (stb);
9538 address_start = bl->address;
9539 address_end = address_start + bl->length - 1;
9541 ui_out_text (uiout, "\taddress range: ");
9542 fprintf_unfiltered (stb, "[%s, %s]",
9543 print_core_address (bl->gdbarch, address_start),
9544 print_core_address (bl->gdbarch, address_end));
9545 ui_out_field_stream (uiout, "addr", stb);
9546 ui_out_text (uiout, "\n");
9548 do_cleanups (cleanup);
9551 /* Implement the "print_mention" breakpoint_ops method for
9552 ranged breakpoints. */
9555 print_mention_ranged_breakpoint (struct breakpoint *b)
9557 struct bp_location *bl = b->loc;
9558 struct ui_out *uiout = current_uiout;
9561 gdb_assert (b->type == bp_hardware_breakpoint);
9563 if (ui_out_is_mi_like_p (uiout))
9566 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
9567 b->number, paddress (bl->gdbarch, bl->address),
9568 paddress (bl->gdbarch, bl->address + bl->length - 1));
9571 /* Implement the "print_recreate" breakpoint_ops method for
9572 ranged breakpoints. */
9575 print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp)
9577 fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string,
9578 b->addr_string_range_end);
9579 print_recreate_thread (b, fp);
9582 /* The breakpoint_ops structure to be used in ranged breakpoints. */
9584 static struct breakpoint_ops ranged_breakpoint_ops;
9586 /* Find the address where the end of the breakpoint range should be
9587 placed, given the SAL of the end of the range. This is so that if
9588 the user provides a line number, the end of the range is set to the
9589 last instruction of the given line. */
9592 find_breakpoint_range_end (struct symtab_and_line sal)
9596 /* If the user provided a PC value, use it. Otherwise,
9597 find the address of the end of the given location. */
9598 if (sal.explicit_pc)
9605 ret = find_line_pc_range (sal, &start, &end);
9607 error (_("Could not find location of the end of the range."));
9609 /* find_line_pc_range returns the start of the next line. */
9616 /* Implement the "break-range" CLI command. */
9619 break_range_command (char *arg, int from_tty)
9621 char *arg_start, *addr_string_start, *addr_string_end;
9622 struct linespec_result canonical_start, canonical_end;
9623 int bp_count, can_use_bp, length;
9625 struct breakpoint *b;
9626 struct symtab_and_line sal_start, sal_end;
9627 struct cleanup *cleanup_bkpt;
9628 struct linespec_sals *lsal_start, *lsal_end;
9630 /* We don't support software ranged breakpoints. */
9631 if (target_ranged_break_num_registers () < 0)
9632 error (_("This target does not support hardware ranged breakpoints."));
9634 bp_count = hw_breakpoint_used_count ();
9635 bp_count += target_ranged_break_num_registers ();
9636 can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
9639 error (_("Hardware breakpoints used exceeds limit."));
9641 arg = skip_spaces (arg);
9642 if (arg == NULL || arg[0] == '\0')
9643 error(_("No address range specified."));
9645 init_linespec_result (&canonical_start);
9648 parse_breakpoint_sals (&arg, &canonical_start);
9650 cleanup_bkpt = make_cleanup_destroy_linespec_result (&canonical_start);
9653 error (_("Too few arguments."));
9654 else if (VEC_empty (linespec_sals, canonical_start.sals))
9655 error (_("Could not find location of the beginning of the range."));
9657 lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0);
9659 if (VEC_length (linespec_sals, canonical_start.sals) > 1
9660 || lsal_start->sals.nelts != 1)
9661 error (_("Cannot create a ranged breakpoint with multiple locations."));
9663 sal_start = lsal_start->sals.sals[0];
9664 addr_string_start = savestring (arg_start, arg - arg_start);
9665 make_cleanup (xfree, addr_string_start);
9667 arg++; /* Skip the comma. */
9668 arg = skip_spaces (arg);
9670 /* Parse the end location. */
9672 init_linespec_result (&canonical_end);
9675 /* We call decode_line_full directly here instead of using
9676 parse_breakpoint_sals because we need to specify the start location's
9677 symtab and line as the default symtab and line for the end of the
9678 range. This makes it possible to have ranges like "foo.c:27, +14",
9679 where +14 means 14 lines from the start location. */
9680 decode_line_full (&arg, DECODE_LINE_FUNFIRSTLINE,
9681 sal_start.symtab, sal_start.line,
9682 &canonical_end, NULL, NULL);
9684 make_cleanup_destroy_linespec_result (&canonical_end);
9686 if (VEC_empty (linespec_sals, canonical_end.sals))
9687 error (_("Could not find location of the end of the range."));
9689 lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0);
9690 if (VEC_length (linespec_sals, canonical_end.sals) > 1
9691 || lsal_end->sals.nelts != 1)
9692 error (_("Cannot create a ranged breakpoint with multiple locations."));
9694 sal_end = lsal_end->sals.sals[0];
9695 addr_string_end = savestring (arg_start, arg - arg_start);
9696 make_cleanup (xfree, addr_string_end);
9698 end = find_breakpoint_range_end (sal_end);
9699 if (sal_start.pc > end)
9700 error (_("Invalid address range, end precedes start."));
9702 length = end - sal_start.pc + 1;
9704 /* Length overflowed. */
9705 error (_("Address range too large."));
9706 else if (length == 1)
9708 /* This range is simple enough to be handled by
9709 the `hbreak' command. */
9710 hbreak_command (addr_string_start, 1);
9712 do_cleanups (cleanup_bkpt);
9717 /* Now set up the breakpoint. */
9718 b = set_raw_breakpoint (get_current_arch (), sal_start,
9719 bp_hardware_breakpoint, &ranged_breakpoint_ops);
9720 set_breakpoint_count (breakpoint_count + 1);
9721 b->number = breakpoint_count;
9722 b->disposition = disp_donttouch;
9723 b->addr_string = xstrdup (addr_string_start);
9724 b->addr_string_range_end = xstrdup (addr_string_end);
9725 b->loc->length = length;
9727 do_cleanups (cleanup_bkpt);
9730 observer_notify_breakpoint_created (b);
9731 update_global_location_list (1);
9734 /* Return non-zero if EXP is verified as constant. Returned zero
9735 means EXP is variable. Also the constant detection may fail for
9736 some constant expressions and in such case still falsely return
9740 watchpoint_exp_is_const (const struct expression *exp)
9748 /* We are only interested in the descriptor of each element. */
9749 operator_length (exp, i, &oplenp, &argsp);
9752 switch (exp->elts[i].opcode)
9762 case BINOP_LOGICAL_AND:
9763 case BINOP_LOGICAL_OR:
9764 case BINOP_BITWISE_AND:
9765 case BINOP_BITWISE_IOR:
9766 case BINOP_BITWISE_XOR:
9768 case BINOP_NOTEQUAL:
9784 case TERNOP_SLICE_COUNT:
9796 case OP_OBJC_NSSTRING:
9799 case UNOP_LOGICAL_NOT:
9800 case UNOP_COMPLEMENT:
9804 /* Unary, binary and ternary operators: We have to check
9805 their operands. If they are constant, then so is the
9806 result of that operation. For instance, if A and B are
9807 determined to be constants, then so is "A + B".
9809 UNOP_IND is one exception to the rule above, because the
9810 value of *ADDR is not necessarily a constant, even when
9815 /* Check whether the associated symbol is a constant.
9817 We use SYMBOL_CLASS rather than TYPE_CONST because it's
9818 possible that a buggy compiler could mark a variable as
9819 constant even when it is not, and TYPE_CONST would return
9820 true in this case, while SYMBOL_CLASS wouldn't.
9822 We also have to check for function symbols because they
9823 are always constant. */
9825 struct symbol *s = exp->elts[i + 2].symbol;
9827 if (SYMBOL_CLASS (s) != LOC_BLOCK
9828 && SYMBOL_CLASS (s) != LOC_CONST
9829 && SYMBOL_CLASS (s) != LOC_CONST_BYTES)
9834 /* The default action is to return 0 because we are using
9835 the optimistic approach here: If we don't know something,
9836 then it is not a constant. */
9845 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
9848 dtor_watchpoint (struct breakpoint *self)
9850 struct watchpoint *w = (struct watchpoint *) self;
9852 xfree (w->cond_exp);
9854 xfree (w->exp_string);
9855 xfree (w->exp_string_reparse);
9856 value_free (w->val);
9858 base_breakpoint_ops.dtor (self);
9861 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
9864 re_set_watchpoint (struct breakpoint *b)
9866 struct watchpoint *w = (struct watchpoint *) b;
9868 /* Watchpoint can be either on expression using entirely global
9869 variables, or it can be on local variables.
9871 Watchpoints of the first kind are never auto-deleted, and even
9872 persist across program restarts. Since they can use variables
9873 from shared libraries, we need to reparse expression as libraries
9874 are loaded and unloaded.
9876 Watchpoints on local variables can also change meaning as result
9877 of solib event. For example, if a watchpoint uses both a local
9878 and a global variables in expression, it's a local watchpoint,
9879 but unloading of a shared library will make the expression
9880 invalid. This is not a very common use case, but we still
9881 re-evaluate expression, to avoid surprises to the user.
9883 Note that for local watchpoints, we re-evaluate it only if
9884 watchpoints frame id is still valid. If it's not, it means the
9885 watchpoint is out of scope and will be deleted soon. In fact,
9886 I'm not sure we'll ever be called in this case.
9888 If a local watchpoint's frame id is still valid, then
9889 w->exp_valid_block is likewise valid, and we can safely use it.
9891 Don't do anything about disabled watchpoints, since they will be
9892 reevaluated again when enabled. */
9893 update_watchpoint (w, 1 /* reparse */);
9896 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
9899 insert_watchpoint (struct bp_location *bl)
9901 struct watchpoint *w = (struct watchpoint *) bl->owner;
9902 int length = w->exact ? 1 : bl->length;
9904 return target_insert_watchpoint (bl->address, length, bl->watchpoint_type,
9908 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
9911 remove_watchpoint (struct bp_location *bl)
9913 struct watchpoint *w = (struct watchpoint *) bl->owner;
9914 int length = w->exact ? 1 : bl->length;
9916 return target_remove_watchpoint (bl->address, length, bl->watchpoint_type,
9921 breakpoint_hit_watchpoint (const struct bp_location *bl,
9922 struct address_space *aspace, CORE_ADDR bp_addr,
9923 const struct target_waitstatus *ws)
9925 struct breakpoint *b = bl->owner;
9926 struct watchpoint *w = (struct watchpoint *) b;
9928 /* Continuable hardware watchpoints are treated as non-existent if the
9929 reason we stopped wasn't a hardware watchpoint (we didn't stop on
9930 some data address). Otherwise gdb won't stop on a break instruction
9931 in the code (not from a breakpoint) when a hardware watchpoint has
9932 been defined. Also skip watchpoints which we know did not trigger
9933 (did not match the data address). */
9934 if (is_hardware_watchpoint (b)
9935 && w->watchpoint_triggered == watch_triggered_no)
9942 check_status_watchpoint (bpstat bs)
9944 gdb_assert (is_watchpoint (bs->breakpoint_at));
9946 bpstat_check_watchpoint (bs);
9949 /* Implement the "resources_needed" breakpoint_ops method for
9950 hardware watchpoints. */
9953 resources_needed_watchpoint (const struct bp_location *bl)
9955 struct watchpoint *w = (struct watchpoint *) bl->owner;
9956 int length = w->exact? 1 : bl->length;
9958 return target_region_ok_for_hw_watchpoint (bl->address, length);
9961 /* Implement the "works_in_software_mode" breakpoint_ops method for
9962 hardware watchpoints. */
9965 works_in_software_mode_watchpoint (const struct breakpoint *b)
9967 /* Read and access watchpoints only work with hardware support. */
9968 return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint;
9971 static enum print_stop_action
9972 print_it_watchpoint (bpstat bs)
9974 struct cleanup *old_chain;
9975 struct breakpoint *b;
9976 const struct bp_location *bl;
9977 struct ui_file *stb;
9978 enum print_stop_action result;
9979 struct watchpoint *w;
9980 struct ui_out *uiout = current_uiout;
9982 gdb_assert (bs->bp_location_at != NULL);
9984 bl = bs->bp_location_at;
9985 b = bs->breakpoint_at;
9986 w = (struct watchpoint *) b;
9988 stb = mem_fileopen ();
9989 old_chain = make_cleanup_ui_file_delete (stb);
9994 case bp_hardware_watchpoint:
9995 annotate_watchpoint (b->number);
9996 if (ui_out_is_mi_like_p (uiout))
9999 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
10001 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10002 ui_out_text (uiout, "\nOld value = ");
10003 watchpoint_value_print (bs->old_val, stb);
10004 ui_out_field_stream (uiout, "old", stb);
10005 ui_out_text (uiout, "\nNew value = ");
10006 watchpoint_value_print (w->val, stb);
10007 ui_out_field_stream (uiout, "new", stb);
10008 ui_out_text (uiout, "\n");
10009 /* More than one watchpoint may have been triggered. */
10010 result = PRINT_UNKNOWN;
10013 case bp_read_watchpoint:
10014 if (ui_out_is_mi_like_p (uiout))
10015 ui_out_field_string
10017 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
10019 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10020 ui_out_text (uiout, "\nValue = ");
10021 watchpoint_value_print (w->val, stb);
10022 ui_out_field_stream (uiout, "value", stb);
10023 ui_out_text (uiout, "\n");
10024 result = PRINT_UNKNOWN;
10027 case bp_access_watchpoint:
10028 if (bs->old_val != NULL)
10030 annotate_watchpoint (b->number);
10031 if (ui_out_is_mi_like_p (uiout))
10032 ui_out_field_string
10034 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10036 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10037 ui_out_text (uiout, "\nOld value = ");
10038 watchpoint_value_print (bs->old_val, stb);
10039 ui_out_field_stream (uiout, "old", stb);
10040 ui_out_text (uiout, "\nNew value = ");
10045 if (ui_out_is_mi_like_p (uiout))
10046 ui_out_field_string
10048 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10049 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10050 ui_out_text (uiout, "\nValue = ");
10052 watchpoint_value_print (w->val, stb);
10053 ui_out_field_stream (uiout, "new", stb);
10054 ui_out_text (uiout, "\n");
10055 result = PRINT_UNKNOWN;
10058 result = PRINT_UNKNOWN;
10061 do_cleanups (old_chain);
10065 /* Implement the "print_mention" breakpoint_ops method for hardware
10069 print_mention_watchpoint (struct breakpoint *b)
10071 struct cleanup *ui_out_chain;
10072 struct watchpoint *w = (struct watchpoint *) b;
10073 struct ui_out *uiout = current_uiout;
10077 case bp_watchpoint:
10078 ui_out_text (uiout, "Watchpoint ");
10079 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
10081 case bp_hardware_watchpoint:
10082 ui_out_text (uiout, "Hardware watchpoint ");
10083 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
10085 case bp_read_watchpoint:
10086 ui_out_text (uiout, "Hardware read watchpoint ");
10087 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
10089 case bp_access_watchpoint:
10090 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
10091 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
10094 internal_error (__FILE__, __LINE__,
10095 _("Invalid hardware watchpoint type."));
10098 ui_out_field_int (uiout, "number", b->number);
10099 ui_out_text (uiout, ": ");
10100 ui_out_field_string (uiout, "exp", w->exp_string);
10101 do_cleanups (ui_out_chain);
10104 /* Implement the "print_recreate" breakpoint_ops method for
10108 print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp)
10110 struct watchpoint *w = (struct watchpoint *) b;
10114 case bp_watchpoint:
10115 case bp_hardware_watchpoint:
10116 fprintf_unfiltered (fp, "watch");
10118 case bp_read_watchpoint:
10119 fprintf_unfiltered (fp, "rwatch");
10121 case bp_access_watchpoint:
10122 fprintf_unfiltered (fp, "awatch");
10125 internal_error (__FILE__, __LINE__,
10126 _("Invalid watchpoint type."));
10129 fprintf_unfiltered (fp, " %s", w->exp_string);
10130 print_recreate_thread (b, fp);
10133 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10135 static struct breakpoint_ops watchpoint_breakpoint_ops;
10137 /* Implement the "insert" breakpoint_ops method for
10138 masked hardware watchpoints. */
10141 insert_masked_watchpoint (struct bp_location *bl)
10143 struct watchpoint *w = (struct watchpoint *) bl->owner;
10145 return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask,
10146 bl->watchpoint_type);
10149 /* Implement the "remove" breakpoint_ops method for
10150 masked hardware watchpoints. */
10153 remove_masked_watchpoint (struct bp_location *bl)
10155 struct watchpoint *w = (struct watchpoint *) bl->owner;
10157 return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask,
10158 bl->watchpoint_type);
10161 /* Implement the "resources_needed" breakpoint_ops method for
10162 masked hardware watchpoints. */
10165 resources_needed_masked_watchpoint (const struct bp_location *bl)
10167 struct watchpoint *w = (struct watchpoint *) bl->owner;
10169 return target_masked_watch_num_registers (bl->address, w->hw_wp_mask);
10172 /* Implement the "works_in_software_mode" breakpoint_ops method for
10173 masked hardware watchpoints. */
10176 works_in_software_mode_masked_watchpoint (const struct breakpoint *b)
10181 /* Implement the "print_it" breakpoint_ops method for
10182 masked hardware watchpoints. */
10184 static enum print_stop_action
10185 print_it_masked_watchpoint (bpstat bs)
10187 struct breakpoint *b = bs->breakpoint_at;
10188 struct ui_out *uiout = current_uiout;
10190 /* Masked watchpoints have only one location. */
10191 gdb_assert (b->loc && b->loc->next == NULL);
10195 case bp_hardware_watchpoint:
10196 annotate_watchpoint (b->number);
10197 if (ui_out_is_mi_like_p (uiout))
10198 ui_out_field_string
10200 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
10203 case bp_read_watchpoint:
10204 if (ui_out_is_mi_like_p (uiout))
10205 ui_out_field_string
10207 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
10210 case bp_access_watchpoint:
10211 if (ui_out_is_mi_like_p (uiout))
10212 ui_out_field_string
10214 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10217 internal_error (__FILE__, __LINE__,
10218 _("Invalid hardware watchpoint type."));
10222 ui_out_text (uiout, _("\n\
10223 Check the underlying instruction at PC for the memory\n\
10224 address and value which triggered this watchpoint.\n"));
10225 ui_out_text (uiout, "\n");
10227 /* More than one watchpoint may have been triggered. */
10228 return PRINT_UNKNOWN;
10231 /* Implement the "print_one_detail" breakpoint_ops method for
10232 masked hardware watchpoints. */
10235 print_one_detail_masked_watchpoint (const struct breakpoint *b,
10236 struct ui_out *uiout)
10238 struct watchpoint *w = (struct watchpoint *) b;
10240 /* Masked watchpoints have only one location. */
10241 gdb_assert (b->loc && b->loc->next == NULL);
10243 ui_out_text (uiout, "\tmask ");
10244 ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask);
10245 ui_out_text (uiout, "\n");
10248 /* Implement the "print_mention" breakpoint_ops method for
10249 masked hardware watchpoints. */
10252 print_mention_masked_watchpoint (struct breakpoint *b)
10254 struct watchpoint *w = (struct watchpoint *) b;
10255 struct ui_out *uiout = current_uiout;
10256 struct cleanup *ui_out_chain;
10260 case bp_hardware_watchpoint:
10261 ui_out_text (uiout, "Masked hardware watchpoint ");
10262 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
10264 case bp_read_watchpoint:
10265 ui_out_text (uiout, "Masked hardware read watchpoint ");
10266 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
10268 case bp_access_watchpoint:
10269 ui_out_text (uiout, "Masked hardware access (read/write) watchpoint ");
10270 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
10273 internal_error (__FILE__, __LINE__,
10274 _("Invalid hardware watchpoint type."));
10277 ui_out_field_int (uiout, "number", b->number);
10278 ui_out_text (uiout, ": ");
10279 ui_out_field_string (uiout, "exp", w->exp_string);
10280 do_cleanups (ui_out_chain);
10283 /* Implement the "print_recreate" breakpoint_ops method for
10284 masked hardware watchpoints. */
10287 print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp)
10289 struct watchpoint *w = (struct watchpoint *) b;
10294 case bp_hardware_watchpoint:
10295 fprintf_unfiltered (fp, "watch");
10297 case bp_read_watchpoint:
10298 fprintf_unfiltered (fp, "rwatch");
10300 case bp_access_watchpoint:
10301 fprintf_unfiltered (fp, "awatch");
10304 internal_error (__FILE__, __LINE__,
10305 _("Invalid hardware watchpoint type."));
10308 sprintf_vma (tmp, w->hw_wp_mask);
10309 fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp);
10310 print_recreate_thread (b, fp);
10313 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10315 static struct breakpoint_ops masked_watchpoint_breakpoint_ops;
10317 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10320 is_masked_watchpoint (const struct breakpoint *b)
10322 return b->ops == &masked_watchpoint_breakpoint_ops;
10325 /* accessflag: hw_write: watch write,
10326 hw_read: watch read,
10327 hw_access: watch access (read or write) */
10329 watch_command_1 (char *arg, int accessflag, int from_tty,
10330 int just_location, int internal)
10332 volatile struct gdb_exception e;
10333 struct breakpoint *b, *scope_breakpoint = NULL;
10334 struct expression *exp;
10335 struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL;
10336 struct value *val, *mark, *result;
10337 struct frame_info *frame;
10338 char *exp_start = NULL;
10339 char *exp_end = NULL;
10340 char *tok, *end_tok;
10342 char *cond_start = NULL;
10343 char *cond_end = NULL;
10344 enum bptype bp_type;
10347 /* Flag to indicate whether we are going to use masks for
10348 the hardware watchpoint. */
10350 CORE_ADDR mask = 0;
10351 struct watchpoint *w;
10353 /* Make sure that we actually have parameters to parse. */
10354 if (arg != NULL && arg[0] != '\0')
10358 /* Look for "parameter value" pairs at the end
10359 of the arguments string. */
10360 for (tok = arg + strlen (arg) - 1; tok > arg; tok--)
10362 /* Skip whitespace at the end of the argument list. */
10363 while (tok > arg && (*tok == ' ' || *tok == '\t'))
10366 /* Find the beginning of the last token.
10367 This is the value of the parameter. */
10368 while (tok > arg && (*tok != ' ' && *tok != '\t'))
10370 value_start = tok + 1;
10372 /* Skip whitespace. */
10373 while (tok > arg && (*tok == ' ' || *tok == '\t'))
10378 /* Find the beginning of the second to last token.
10379 This is the parameter itself. */
10380 while (tok > arg && (*tok != ' ' && *tok != '\t'))
10383 toklen = end_tok - tok + 1;
10385 if (toklen == 6 && !strncmp (tok, "thread", 6))
10387 /* At this point we've found a "thread" token, which means
10388 the user is trying to set a watchpoint that triggers
10389 only in a specific thread. */
10393 error(_("You can specify only one thread."));
10395 /* Extract the thread ID from the next token. */
10396 thread = strtol (value_start, &endp, 0);
10398 /* Check if the user provided a valid numeric value for the
10400 if (*endp != ' ' && *endp != '\t' && *endp != '\0')
10401 error (_("Invalid thread ID specification %s."), value_start);
10403 /* Check if the thread actually exists. */
10404 if (!valid_thread_id (thread))
10405 error (_("Unknown thread %d."), thread);
10407 else if (toklen == 4 && !strncmp (tok, "mask", 4))
10409 /* We've found a "mask" token, which means the user wants to
10410 create a hardware watchpoint that is going to have the mask
10412 struct value *mask_value, *mark;
10415 error(_("You can specify only one mask."));
10417 use_mask = just_location = 1;
10419 mark = value_mark ();
10420 mask_value = parse_to_comma_and_eval (&value_start);
10421 mask = value_as_address (mask_value);
10422 value_free_to_mark (mark);
10425 /* We didn't recognize what we found. We should stop here. */
10428 /* Truncate the string and get rid of the "parameter value" pair before
10429 the arguments string is parsed by the parse_exp_1 function. */
10434 /* Parse the rest of the arguments. */
10435 innermost_block = NULL;
10437 exp = parse_exp_1 (&arg, 0, 0);
10439 /* Remove trailing whitespace from the expression before saving it.
10440 This makes the eventual display of the expression string a bit
10442 while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t'))
10445 /* Checking if the expression is not constant. */
10446 if (watchpoint_exp_is_const (exp))
10450 len = exp_end - exp_start;
10451 while (len > 0 && isspace (exp_start[len - 1]))
10453 error (_("Cannot watch constant value `%.*s'."), len, exp_start);
10456 exp_valid_block = innermost_block;
10457 mark = value_mark ();
10458 fetch_subexp_value (exp, &pc, &val, &result, NULL);
10464 exp_valid_block = NULL;
10465 val = value_addr (result);
10466 release_value (val);
10467 value_free_to_mark (mark);
10471 ret = target_masked_watch_num_registers (value_as_address (val),
10474 error (_("This target does not support masked watchpoints."));
10475 else if (ret == -2)
10476 error (_("Invalid mask or memory region."));
10479 else if (val != NULL)
10480 release_value (val);
10482 tok = skip_spaces (arg);
10483 end_tok = skip_to_space (tok);
10485 toklen = end_tok - tok;
10486 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
10488 struct expression *cond;
10490 innermost_block = NULL;
10491 tok = cond_start = end_tok + 1;
10492 cond = parse_exp_1 (&tok, 0, 0);
10494 /* The watchpoint expression may not be local, but the condition
10495 may still be. E.g.: `watch global if local > 0'. */
10496 cond_exp_valid_block = innermost_block;
10502 error (_("Junk at end of command."));
10504 if (accessflag == hw_read)
10505 bp_type = bp_read_watchpoint;
10506 else if (accessflag == hw_access)
10507 bp_type = bp_access_watchpoint;
10509 bp_type = bp_hardware_watchpoint;
10511 frame = block_innermost_frame (exp_valid_block);
10513 /* If the expression is "local", then set up a "watchpoint scope"
10514 breakpoint at the point where we've left the scope of the watchpoint
10515 expression. Create the scope breakpoint before the watchpoint, so
10516 that we will encounter it first in bpstat_stop_status. */
10517 if (exp_valid_block && frame)
10519 if (frame_id_p (frame_unwind_caller_id (frame)))
10522 = create_internal_breakpoint (frame_unwind_caller_arch (frame),
10523 frame_unwind_caller_pc (frame),
10524 bp_watchpoint_scope,
10525 &momentary_breakpoint_ops);
10527 scope_breakpoint->enable_state = bp_enabled;
10529 /* Automatically delete the breakpoint when it hits. */
10530 scope_breakpoint->disposition = disp_del;
10532 /* Only break in the proper frame (help with recursion). */
10533 scope_breakpoint->frame_id = frame_unwind_caller_id (frame);
10535 /* Set the address at which we will stop. */
10536 scope_breakpoint->loc->gdbarch
10537 = frame_unwind_caller_arch (frame);
10538 scope_breakpoint->loc->requested_address
10539 = frame_unwind_caller_pc (frame);
10540 scope_breakpoint->loc->address
10541 = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch,
10542 scope_breakpoint->loc->requested_address,
10543 scope_breakpoint->type);
10547 /* Now set up the breakpoint. */
10549 w = XCNEW (struct watchpoint);
10552 init_raw_breakpoint_without_location (b, NULL, bp_type,
10553 &masked_watchpoint_breakpoint_ops);
10555 init_raw_breakpoint_without_location (b, NULL, bp_type,
10556 &watchpoint_breakpoint_ops);
10557 b->thread = thread;
10558 b->disposition = disp_donttouch;
10559 b->pspace = current_program_space;
10561 w->exp_valid_block = exp_valid_block;
10562 w->cond_exp_valid_block = cond_exp_valid_block;
10565 struct type *t = value_type (val);
10566 CORE_ADDR addr = value_as_address (val);
10569 t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t)));
10570 name = type_to_string (t);
10572 w->exp_string_reparse = xstrprintf ("* (%s *) %s", name,
10573 core_addr_to_string (addr));
10576 w->exp_string = xstrprintf ("-location %.*s",
10577 (int) (exp_end - exp_start), exp_start);
10579 /* The above expression is in C. */
10580 b->language = language_c;
10583 w->exp_string = savestring (exp_start, exp_end - exp_start);
10587 w->hw_wp_mask = mask;
10596 b->cond_string = savestring (cond_start, cond_end - cond_start);
10598 b->cond_string = 0;
10602 w->watchpoint_frame = get_frame_id (frame);
10603 w->watchpoint_thread = inferior_ptid;
10607 w->watchpoint_frame = null_frame_id;
10608 w->watchpoint_thread = null_ptid;
10611 if (scope_breakpoint != NULL)
10613 /* The scope breakpoint is related to the watchpoint. We will
10614 need to act on them together. */
10615 b->related_breakpoint = scope_breakpoint;
10616 scope_breakpoint->related_breakpoint = b;
10619 if (!just_location)
10620 value_free_to_mark (mark);
10622 TRY_CATCH (e, RETURN_MASK_ALL)
10624 /* Finally update the new watchpoint. This creates the locations
10625 that should be inserted. */
10626 update_watchpoint (w, 1);
10630 delete_breakpoint (b);
10631 throw_exception (e);
10634 install_breakpoint (internal, b, 1);
10637 /* Return count of debug registers needed to watch the given expression.
10638 If the watchpoint cannot be handled in hardware return zero. */
10641 can_use_hardware_watchpoint (struct value *v)
10643 int found_memory_cnt = 0;
10644 struct value *head = v;
10646 /* Did the user specifically forbid us to use hardware watchpoints? */
10647 if (!can_use_hw_watchpoints)
10650 /* Make sure that the value of the expression depends only upon
10651 memory contents, and values computed from them within GDB. If we
10652 find any register references or function calls, we can't use a
10653 hardware watchpoint.
10655 The idea here is that evaluating an expression generates a series
10656 of values, one holding the value of every subexpression. (The
10657 expression a*b+c has five subexpressions: a, b, a*b, c, and
10658 a*b+c.) GDB's values hold almost enough information to establish
10659 the criteria given above --- they identify memory lvalues,
10660 register lvalues, computed values, etcetera. So we can evaluate
10661 the expression, and then scan the chain of values that leaves
10662 behind to decide whether we can detect any possible change to the
10663 expression's final value using only hardware watchpoints.
10665 However, I don't think that the values returned by inferior
10666 function calls are special in any way. So this function may not
10667 notice that an expression involving an inferior function call
10668 can't be watched with hardware watchpoints. FIXME. */
10669 for (; v; v = value_next (v))
10671 if (VALUE_LVAL (v) == lval_memory)
10673 if (v != head && value_lazy (v))
10674 /* A lazy memory lvalue in the chain is one that GDB never
10675 needed to fetch; we either just used its address (e.g.,
10676 `a' in `a.b') or we never needed it at all (e.g., `a'
10677 in `a,b'). This doesn't apply to HEAD; if that is
10678 lazy then it was not readable, but watch it anyway. */
10682 /* Ahh, memory we actually used! Check if we can cover
10683 it with hardware watchpoints. */
10684 struct type *vtype = check_typedef (value_type (v));
10686 /* We only watch structs and arrays if user asked for it
10687 explicitly, never if they just happen to appear in a
10688 middle of some value chain. */
10690 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
10691 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
10693 CORE_ADDR vaddr = value_address (v);
10697 len = (target_exact_watchpoints
10698 && is_scalar_type_recursive (vtype))?
10699 1 : TYPE_LENGTH (value_type (v));
10701 num_regs = target_region_ok_for_hw_watchpoint (vaddr, len);
10705 found_memory_cnt += num_regs;
10709 else if (VALUE_LVAL (v) != not_lval
10710 && deprecated_value_modifiable (v) == 0)
10711 return 0; /* These are values from the history (e.g., $1). */
10712 else if (VALUE_LVAL (v) == lval_register)
10713 return 0; /* Cannot watch a register with a HW watchpoint. */
10716 /* The expression itself looks suitable for using a hardware
10717 watchpoint, but give the target machine a chance to reject it. */
10718 return found_memory_cnt;
10722 watch_command_wrapper (char *arg, int from_tty, int internal)
10724 watch_command_1 (arg, hw_write, from_tty, 0, internal);
10727 /* A helper function that looks for an argument at the start of a
10728 string. The argument must also either be at the end of the string,
10729 or be followed by whitespace. Returns 1 if it finds the argument,
10730 0 otherwise. If the argument is found, it updates *STR. */
10733 check_for_argument (char **str, char *arg, int arg_len)
10735 if (strncmp (*str, arg, arg_len) == 0
10736 && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len])))
10744 /* A helper function that looks for the "-location" argument and then
10745 calls watch_command_1. */
10748 watch_maybe_just_location (char *arg, int accessflag, int from_tty)
10750 int just_location = 0;
10753 && (check_for_argument (&arg, "-location", sizeof ("-location") - 1)
10754 || check_for_argument (&arg, "-l", sizeof ("-l") - 1)))
10756 arg = skip_spaces (arg);
10760 watch_command_1 (arg, accessflag, from_tty, just_location, 0);
10764 watch_command (char *arg, int from_tty)
10766 watch_maybe_just_location (arg, hw_write, from_tty);
10770 rwatch_command_wrapper (char *arg, int from_tty, int internal)
10772 watch_command_1 (arg, hw_read, from_tty, 0, internal);
10776 rwatch_command (char *arg, int from_tty)
10778 watch_maybe_just_location (arg, hw_read, from_tty);
10782 awatch_command_wrapper (char *arg, int from_tty, int internal)
10784 watch_command_1 (arg, hw_access, from_tty, 0, internal);
10788 awatch_command (char *arg, int from_tty)
10790 watch_maybe_just_location (arg, hw_access, from_tty);
10794 /* Helper routines for the until_command routine in infcmd.c. Here
10795 because it uses the mechanisms of breakpoints. */
10797 struct until_break_command_continuation_args
10799 struct breakpoint *breakpoint;
10800 struct breakpoint *breakpoint2;
10804 /* This function is called by fetch_inferior_event via the
10805 cmd_continuation pointer, to complete the until command. It takes
10806 care of cleaning up the temporary breakpoints set up by the until
10809 until_break_command_continuation (void *arg, int err)
10811 struct until_break_command_continuation_args *a = arg;
10813 delete_breakpoint (a->breakpoint);
10814 if (a->breakpoint2)
10815 delete_breakpoint (a->breakpoint2);
10816 delete_longjmp_breakpoint (a->thread_num);
10820 until_break_command (char *arg, int from_tty, int anywhere)
10822 struct symtabs_and_lines sals;
10823 struct symtab_and_line sal;
10824 struct frame_info *frame = get_selected_frame (NULL);
10825 struct gdbarch *frame_gdbarch = get_frame_arch (frame);
10826 struct frame_id stack_frame_id = get_stack_frame_id (frame);
10827 struct frame_id caller_frame_id = frame_unwind_caller_id (frame);
10828 struct breakpoint *breakpoint;
10829 struct breakpoint *breakpoint2 = NULL;
10830 struct cleanup *old_chain;
10832 struct thread_info *tp;
10834 clear_proceed_status ();
10836 /* Set a breakpoint where the user wants it and at return from
10839 if (last_displayed_sal_is_valid ())
10840 sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE,
10841 get_last_displayed_symtab (),
10842 get_last_displayed_line ());
10844 sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE,
10845 (struct symtab *) NULL, 0);
10847 if (sals.nelts != 1)
10848 error (_("Couldn't get information on specified line."));
10850 sal = sals.sals[0];
10851 xfree (sals.sals); /* malloc'd, so freed. */
10854 error (_("Junk at end of arguments."));
10856 resolve_sal_pc (&sal);
10858 tp = inferior_thread ();
10861 old_chain = make_cleanup (null_cleanup, NULL);
10863 /* Installing a breakpoint invalidates the frame chain (as it may
10864 need to switch threads), so do any frame handling first. */
10866 /* Keep within the current frame, or in frames called by the current
10869 if (frame_id_p (caller_frame_id))
10871 struct symtab_and_line sal2;
10873 sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0);
10874 sal2.pc = frame_unwind_caller_pc (frame);
10875 breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame),
10879 make_cleanup_delete_breakpoint (breakpoint2);
10881 set_longjmp_breakpoint (tp, caller_frame_id);
10882 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
10885 /* set_momentary_breakpoint could invalidate FRAME. */
10889 /* If the user told us to continue until a specified location,
10890 we don't specify a frame at which we need to stop. */
10891 breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
10892 null_frame_id, bp_until);
10894 /* Otherwise, specify the selected frame, because we want to stop
10895 only at the very same frame. */
10896 breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
10897 stack_frame_id, bp_until);
10898 make_cleanup_delete_breakpoint (breakpoint);
10900 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
10902 /* If we are running asynchronously, and proceed call above has
10903 actually managed to start the target, arrange for breakpoints to
10904 be deleted when the target stops. Otherwise, we're already
10905 stopped and delete breakpoints via cleanup chain. */
10907 if (target_can_async_p () && is_running (inferior_ptid))
10909 struct until_break_command_continuation_args *args;
10910 args = xmalloc (sizeof (*args));
10912 args->breakpoint = breakpoint;
10913 args->breakpoint2 = breakpoint2;
10914 args->thread_num = thread;
10916 discard_cleanups (old_chain);
10917 add_continuation (inferior_thread (),
10918 until_break_command_continuation, args,
10922 do_cleanups (old_chain);
10925 /* This function attempts to parse an optional "if <cond>" clause
10926 from the arg string. If one is not found, it returns NULL.
10928 Else, it returns a pointer to the condition string. (It does not
10929 attempt to evaluate the string against a particular block.) And,
10930 it updates arg to point to the first character following the parsed
10931 if clause in the arg string. */
10934 ep_parse_optional_if_clause (char **arg)
10938 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
10941 /* Skip the "if" keyword. */
10944 /* Skip any extra leading whitespace, and record the start of the
10945 condition string. */
10946 *arg = skip_spaces (*arg);
10947 cond_string = *arg;
10949 /* Assume that the condition occupies the remainder of the arg
10951 (*arg) += strlen (cond_string);
10953 return cond_string;
10956 /* Commands to deal with catching events, such as signals, exceptions,
10957 process start/exit, etc. */
10961 catch_fork_temporary, catch_vfork_temporary,
10962 catch_fork_permanent, catch_vfork_permanent
10967 catch_fork_command_1 (char *arg, int from_tty,
10968 struct cmd_list_element *command)
10970 struct gdbarch *gdbarch = get_current_arch ();
10971 char *cond_string = NULL;
10972 catch_fork_kind fork_kind;
10975 fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command);
10976 tempflag = (fork_kind == catch_fork_temporary
10977 || fork_kind == catch_vfork_temporary);
10981 arg = skip_spaces (arg);
10983 /* The allowed syntax is:
10985 catch [v]fork if <cond>
10987 First, check if there's an if clause. */
10988 cond_string = ep_parse_optional_if_clause (&arg);
10990 if ((*arg != '\0') && !isspace (*arg))
10991 error (_("Junk at end of arguments."));
10993 /* If this target supports it, create a fork or vfork catchpoint
10994 and enable reporting of such events. */
10997 case catch_fork_temporary:
10998 case catch_fork_permanent:
10999 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
11000 &catch_fork_breakpoint_ops);
11002 case catch_vfork_temporary:
11003 case catch_vfork_permanent:
11004 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
11005 &catch_vfork_breakpoint_ops);
11008 error (_("unsupported or unknown fork kind; cannot catch it"));
11014 catch_exec_command_1 (char *arg, int from_tty,
11015 struct cmd_list_element *command)
11017 struct exec_catchpoint *c;
11018 struct gdbarch *gdbarch = get_current_arch ();
11020 char *cond_string = NULL;
11022 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11026 arg = skip_spaces (arg);
11028 /* The allowed syntax is:
11030 catch exec if <cond>
11032 First, check if there's an if clause. */
11033 cond_string = ep_parse_optional_if_clause (&arg);
11035 if ((*arg != '\0') && !isspace (*arg))
11036 error (_("Junk at end of arguments."));
11038 c = XNEW (struct exec_catchpoint);
11039 init_catchpoint (&c->base, gdbarch, tempflag, cond_string,
11040 &catch_exec_breakpoint_ops);
11041 c->exec_pathname = NULL;
11043 install_breakpoint (0, &c->base, 1);
11046 static enum print_stop_action
11047 print_it_exception_catchpoint (bpstat bs)
11049 struct ui_out *uiout = current_uiout;
11050 struct breakpoint *b = bs->breakpoint_at;
11051 int bp_temp, bp_throw;
11053 annotate_catchpoint (b->number);
11055 bp_throw = strstr (b->addr_string, "throw") != NULL;
11056 if (b->loc->address != b->loc->requested_address)
11057 breakpoint_adjustment_warning (b->loc->requested_address,
11060 bp_temp = b->disposition == disp_del;
11061 ui_out_text (uiout,
11062 bp_temp ? "Temporary catchpoint "
11064 if (!ui_out_is_mi_like_p (uiout))
11065 ui_out_field_int (uiout, "bkptno", b->number);
11066 ui_out_text (uiout,
11067 bp_throw ? " (exception thrown), "
11068 : " (exception caught), ");
11069 if (ui_out_is_mi_like_p (uiout))
11071 ui_out_field_string (uiout, "reason",
11072 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
11073 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
11074 ui_out_field_int (uiout, "bkptno", b->number);
11076 return PRINT_SRC_AND_LOC;
11080 print_one_exception_catchpoint (struct breakpoint *b,
11081 struct bp_location **last_loc)
11083 struct value_print_options opts;
11084 struct ui_out *uiout = current_uiout;
11086 get_user_print_options (&opts);
11087 if (opts.addressprint)
11089 annotate_field (4);
11090 if (b->loc == NULL || b->loc->shlib_disabled)
11091 ui_out_field_string (uiout, "addr", "<PENDING>");
11093 ui_out_field_core_addr (uiout, "addr",
11094 b->loc->gdbarch, b->loc->address);
11096 annotate_field (5);
11098 *last_loc = b->loc;
11099 if (strstr (b->addr_string, "throw") != NULL)
11100 ui_out_field_string (uiout, "what", "exception throw");
11102 ui_out_field_string (uiout, "what", "exception catch");
11106 print_mention_exception_catchpoint (struct breakpoint *b)
11108 struct ui_out *uiout = current_uiout;
11112 bp_temp = b->disposition == disp_del;
11113 bp_throw = strstr (b->addr_string, "throw") != NULL;
11114 ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ")
11115 : _("Catchpoint "));
11116 ui_out_field_int (uiout, "bkptno", b->number);
11117 ui_out_text (uiout, bp_throw ? _(" (throw)")
11121 /* Implement the "print_recreate" breakpoint_ops method for throw and
11122 catch catchpoints. */
11125 print_recreate_exception_catchpoint (struct breakpoint *b,
11126 struct ui_file *fp)
11131 bp_temp = b->disposition == disp_del;
11132 bp_throw = strstr (b->addr_string, "throw") != NULL;
11133 fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch ");
11134 fprintf_unfiltered (fp, bp_throw ? "throw" : "catch");
11135 print_recreate_thread (b, fp);
11138 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops;
11141 handle_gnu_v3_exceptions (int tempflag, char *cond_string,
11142 enum exception_event_kind ex_event, int from_tty)
11144 char *trigger_func_name;
11146 if (ex_event == EX_EVENT_CATCH)
11147 trigger_func_name = "__cxa_begin_catch";
11149 trigger_func_name = "__cxa_throw";
11151 create_breakpoint (get_current_arch (),
11152 trigger_func_name, cond_string, -1, NULL,
11153 0 /* condition and thread are valid. */,
11154 tempflag, bp_breakpoint,
11156 AUTO_BOOLEAN_TRUE /* pending */,
11157 &gnu_v3_exception_catchpoint_ops, from_tty,
11165 /* Deal with "catch catch" and "catch throw" commands. */
11168 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
11169 int tempflag, int from_tty)
11171 char *cond_string = NULL;
11175 arg = skip_spaces (arg);
11177 cond_string = ep_parse_optional_if_clause (&arg);
11179 if ((*arg != '\0') && !isspace (*arg))
11180 error (_("Junk at end of arguments."));
11182 if (ex_event != EX_EVENT_THROW
11183 && ex_event != EX_EVENT_CATCH)
11184 error (_("Unsupported or unknown exception event; cannot catch it"));
11186 if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
11189 warning (_("Unsupported with this platform/compiler combination."));
11192 /* Implementation of "catch catch" command. */
11195 catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command)
11197 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11199 catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty);
11202 /* Implementation of "catch throw" command. */
11205 catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command)
11207 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11209 catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty);
11213 init_ada_exception_breakpoint (struct breakpoint *b,
11214 struct gdbarch *gdbarch,
11215 struct symtab_and_line sal,
11217 const struct breakpoint_ops *ops,
11223 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
11225 loc_gdbarch = gdbarch;
11227 describe_other_breakpoints (loc_gdbarch,
11228 sal.pspace, sal.pc, sal.section, -1);
11229 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11230 version for exception catchpoints, because two catchpoints
11231 used for different exception names will use the same address.
11232 In this case, a "breakpoint ... also set at..." warning is
11233 unproductive. Besides, the warning phrasing is also a bit
11234 inappropriate, we should use the word catchpoint, and tell
11235 the user what type of catchpoint it is. The above is good
11236 enough for now, though. */
11239 init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops);
11241 b->enable_state = bp_enabled;
11242 b->disposition = tempflag ? disp_del : disp_donttouch;
11243 b->addr_string = addr_string;
11244 b->language = language_ada;
11247 /* Splits the argument using space as delimiter. Returns an xmalloc'd
11248 filter list, or NULL if no filtering is required. */
11250 catch_syscall_split_args (char *arg)
11252 VEC(int) *result = NULL;
11253 struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result);
11255 while (*arg != '\0')
11257 int i, syscall_number;
11259 char cur_name[128];
11262 /* Skip whitespace. */
11263 while (isspace (*arg))
11266 for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i)
11267 cur_name[i] = arg[i];
11268 cur_name[i] = '\0';
11271 /* Check if the user provided a syscall name or a number. */
11272 syscall_number = (int) strtol (cur_name, &endptr, 0);
11273 if (*endptr == '\0')
11274 get_syscall_by_number (syscall_number, &s);
11277 /* We have a name. Let's check if it's valid and convert it
11279 get_syscall_by_name (cur_name, &s);
11281 if (s.number == UNKNOWN_SYSCALL)
11282 /* Here we have to issue an error instead of a warning,
11283 because GDB cannot do anything useful if there's no
11284 syscall number to be caught. */
11285 error (_("Unknown syscall name '%s'."), cur_name);
11288 /* Ok, it's valid. */
11289 VEC_safe_push (int, result, s.number);
11292 discard_cleanups (cleanup);
11296 /* Implement the "catch syscall" command. */
11299 catch_syscall_command_1 (char *arg, int from_tty,
11300 struct cmd_list_element *command)
11305 struct gdbarch *gdbarch = get_current_arch ();
11307 /* Checking if the feature if supported. */
11308 if (gdbarch_get_syscall_number_p (gdbarch) == 0)
11309 error (_("The feature 'catch syscall' is not supported on \
11310 this architecture yet."));
11312 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11314 arg = skip_spaces (arg);
11316 /* We need to do this first "dummy" translation in order
11317 to get the syscall XML file loaded or, most important,
11318 to display a warning to the user if there's no XML file
11319 for his/her architecture. */
11320 get_syscall_by_number (0, &s);
11322 /* The allowed syntax is:
11324 catch syscall <name | number> [<name | number> ... <name | number>]
11326 Let's check if there's a syscall name. */
11329 filter = catch_syscall_split_args (arg);
11333 create_syscall_event_catchpoint (tempflag, filter,
11334 &catch_syscall_breakpoint_ops);
11338 catch_command (char *arg, int from_tty)
11340 error (_("Catch requires an event name."));
11345 tcatch_command (char *arg, int from_tty)
11347 error (_("Catch requires an event name."));
11350 /* A qsort comparison function that sorts breakpoints in order. */
11353 compare_breakpoints (const void *a, const void *b)
11355 const breakpoint_p *ba = a;
11356 uintptr_t ua = (uintptr_t) *ba;
11357 const breakpoint_p *bb = b;
11358 uintptr_t ub = (uintptr_t) *bb;
11360 if ((*ba)->number < (*bb)->number)
11362 else if ((*ba)->number > (*bb)->number)
11365 /* Now sort by address, in case we see, e..g, two breakpoints with
11369 return ub > ub ? 1 : 0;
11372 /* Delete breakpoints by address or line. */
11375 clear_command (char *arg, int from_tty)
11377 struct breakpoint *b, *prev;
11378 VEC(breakpoint_p) *found = 0;
11381 struct symtabs_and_lines sals;
11382 struct symtab_and_line sal;
11384 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
11388 sals = decode_line_spec (arg, (DECODE_LINE_FUNFIRSTLINE
11389 | DECODE_LINE_LIST_MODE));
11394 sals.sals = (struct symtab_and_line *)
11395 xmalloc (sizeof (struct symtab_and_line));
11396 make_cleanup (xfree, sals.sals);
11397 init_sal (&sal); /* Initialize to zeroes. */
11399 /* Set sal's line, symtab, pc, and pspace to the values
11400 corresponding to the last call to print_frame_info. If the
11401 codepoint is not valid, this will set all the fields to 0. */
11402 get_last_displayed_sal (&sal);
11403 if (sal.symtab == 0)
11404 error (_("No source file specified."));
11406 sals.sals[0] = sal;
11412 /* We don't call resolve_sal_pc here. That's not as bad as it
11413 seems, because all existing breakpoints typically have both
11414 file/line and pc set. So, if clear is given file/line, we can
11415 match this to existing breakpoint without obtaining pc at all.
11417 We only support clearing given the address explicitly
11418 present in breakpoint table. Say, we've set breakpoint
11419 at file:line. There were several PC values for that file:line,
11420 due to optimization, all in one block.
11422 We've picked one PC value. If "clear" is issued with another
11423 PC corresponding to the same file:line, the breakpoint won't
11424 be cleared. We probably can still clear the breakpoint, but
11425 since the other PC value is never presented to user, user
11426 can only find it by guessing, and it does not seem important
11427 to support that. */
11429 /* For each line spec given, delete bps which correspond to it. Do
11430 it in two passes, solely to preserve the current behavior that
11431 from_tty is forced true if we delete more than one
11435 make_cleanup (VEC_cleanup (breakpoint_p), &found);
11436 for (i = 0; i < sals.nelts; i++)
11438 int is_abs, sal_name_len;
11440 /* If exact pc given, clear bpts at that pc.
11441 If line given (pc == 0), clear all bpts on specified line.
11442 If defaulting, clear all bpts on default line
11445 defaulting sal.pc != 0 tests to do
11450 1 0 <can't happen> */
11452 sal = sals.sals[i];
11453 is_abs = sal.symtab == NULL ? 1 : IS_ABSOLUTE_PATH (sal.symtab->filename);
11454 sal_name_len = is_abs ? 0 : strlen (sal.symtab->filename);
11456 /* Find all matching breakpoints and add them to 'found'. */
11457 ALL_BREAKPOINTS (b)
11460 /* Are we going to delete b? */
11461 if (b->type != bp_none && !is_watchpoint (b))
11463 struct bp_location *loc = b->loc;
11464 for (; loc; loc = loc->next)
11466 /* If the user specified file:line, don't allow a PC
11467 match. This matches historical gdb behavior. */
11468 int pc_match = (!sal.explicit_line
11470 && (loc->pspace == sal.pspace)
11471 && (loc->address == sal.pc)
11472 && (!section_is_overlay (loc->section)
11473 || loc->section == sal.section));
11474 int line_match = 0;
11476 if ((default_match || sal.explicit_line)
11477 && loc->source_file != NULL
11478 && sal.symtab != NULL
11479 && sal.pspace == loc->pspace
11480 && loc->line_number == sal.line)
11482 if (filename_cmp (loc->source_file,
11483 sal.symtab->filename) == 0)
11485 else if (!IS_ABSOLUTE_PATH (sal.symtab->filename)
11486 && compare_filenames_for_search (loc->source_file,
11487 sal.symtab->filename,
11492 if (pc_match || line_match)
11501 VEC_safe_push(breakpoint_p, found, b);
11505 /* Now go thru the 'found' chain and delete them. */
11506 if (VEC_empty(breakpoint_p, found))
11509 error (_("No breakpoint at %s."), arg);
11511 error (_("No breakpoint at this line."));
11514 /* Remove duplicates from the vec. */
11515 qsort (VEC_address (breakpoint_p, found),
11516 VEC_length (breakpoint_p, found),
11517 sizeof (breakpoint_p),
11518 compare_breakpoints);
11519 prev = VEC_index (breakpoint_p, found, 0);
11520 for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix)
11524 VEC_ordered_remove (breakpoint_p, found, ix);
11529 if (VEC_length(breakpoint_p, found) > 1)
11530 from_tty = 1; /* Always report if deleted more than one. */
11533 if (VEC_length(breakpoint_p, found) == 1)
11534 printf_unfiltered (_("Deleted breakpoint "));
11536 printf_unfiltered (_("Deleted breakpoints "));
11538 breakpoints_changed ();
11540 for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++)
11543 printf_unfiltered ("%d ", b->number);
11544 delete_breakpoint (b);
11547 putchar_unfiltered ('\n');
11549 do_cleanups (cleanups);
11552 /* Delete breakpoint in BS if they are `delete' breakpoints and
11553 all breakpoints that are marked for deletion, whether hit or not.
11554 This is called after any breakpoint is hit, or after errors. */
11557 breakpoint_auto_delete (bpstat bs)
11559 struct breakpoint *b, *b_tmp;
11561 for (; bs; bs = bs->next)
11562 if (bs->breakpoint_at
11563 && bs->breakpoint_at->disposition == disp_del
11565 delete_breakpoint (bs->breakpoint_at);
11567 ALL_BREAKPOINTS_SAFE (b, b_tmp)
11569 if (b->disposition == disp_del_at_next_stop)
11570 delete_breakpoint (b);
11574 /* A comparison function for bp_location AP and BP being interfaced to
11575 qsort. Sort elements primarily by their ADDRESS (no matter what
11576 does breakpoint_address_is_meaningful say for its OWNER),
11577 secondarily by ordering first bp_permanent OWNERed elements and
11578 terciarily just ensuring the array is sorted stable way despite
11579 qsort being an unstable algorithm. */
11582 bp_location_compare (const void *ap, const void *bp)
11584 struct bp_location *a = *(void **) ap;
11585 struct bp_location *b = *(void **) bp;
11586 /* A and B come from existing breakpoints having non-NULL OWNER. */
11587 int a_perm = a->owner->enable_state == bp_permanent;
11588 int b_perm = b->owner->enable_state == bp_permanent;
11590 if (a->address != b->address)
11591 return (a->address > b->address) - (a->address < b->address);
11593 /* Sort locations at the same address by their pspace number, keeping
11594 locations of the same inferior (in a multi-inferior environment)
11597 if (a->pspace->num != b->pspace->num)
11598 return ((a->pspace->num > b->pspace->num)
11599 - (a->pspace->num < b->pspace->num));
11601 /* Sort permanent breakpoints first. */
11602 if (a_perm != b_perm)
11603 return (a_perm < b_perm) - (a_perm > b_perm);
11605 /* Make the internal GDB representation stable across GDB runs
11606 where A and B memory inside GDB can differ. Breakpoint locations of
11607 the same type at the same address can be sorted in arbitrary order. */
11609 if (a->owner->number != b->owner->number)
11610 return ((a->owner->number > b->owner->number)
11611 - (a->owner->number < b->owner->number));
11613 return (a > b) - (a < b);
11616 /* Set bp_location_placed_address_before_address_max and
11617 bp_location_shadow_len_after_address_max according to the current
11618 content of the bp_location array. */
11621 bp_location_target_extensions_update (void)
11623 struct bp_location *bl, **blp_tmp;
11625 bp_location_placed_address_before_address_max = 0;
11626 bp_location_shadow_len_after_address_max = 0;
11628 ALL_BP_LOCATIONS (bl, blp_tmp)
11630 CORE_ADDR start, end, addr;
11632 if (!bp_location_has_shadow (bl))
11635 start = bl->target_info.placed_address;
11636 end = start + bl->target_info.shadow_len;
11638 gdb_assert (bl->address >= start);
11639 addr = bl->address - start;
11640 if (addr > bp_location_placed_address_before_address_max)
11641 bp_location_placed_address_before_address_max = addr;
11643 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11645 gdb_assert (bl->address < end);
11646 addr = end - bl->address;
11647 if (addr > bp_location_shadow_len_after_address_max)
11648 bp_location_shadow_len_after_address_max = addr;
11652 /* Download tracepoint locations if they haven't been. */
11655 download_tracepoint_locations (void)
11657 struct bp_location *bl, **blp_tmp;
11658 struct cleanup *old_chain;
11660 if (!target_can_download_tracepoint ())
11663 old_chain = save_current_space_and_thread ();
11665 ALL_BP_LOCATIONS (bl, blp_tmp)
11667 struct tracepoint *t;
11669 if (!is_tracepoint (bl->owner))
11672 if ((bl->owner->type == bp_fast_tracepoint
11673 ? !may_insert_fast_tracepoints
11674 : !may_insert_tracepoints))
11677 /* In tracepoint, locations are _never_ duplicated, so
11678 should_be_inserted is equivalent to
11679 unduplicated_should_be_inserted. */
11680 if (!should_be_inserted (bl) || bl->inserted)
11683 switch_to_program_space_and_thread (bl->pspace);
11685 target_download_tracepoint (bl);
11688 t = (struct tracepoint *) bl->owner;
11689 t->number_on_target = bl->owner->number;
11692 do_cleanups (old_chain);
11695 /* Swap the insertion/duplication state between two locations. */
11698 swap_insertion (struct bp_location *left, struct bp_location *right)
11700 const int left_inserted = left->inserted;
11701 const int left_duplicate = left->duplicate;
11702 const int left_needs_update = left->needs_update;
11703 const struct bp_target_info left_target_info = left->target_info;
11705 /* Locations of tracepoints can never be duplicated. */
11706 if (is_tracepoint (left->owner))
11707 gdb_assert (!left->duplicate);
11708 if (is_tracepoint (right->owner))
11709 gdb_assert (!right->duplicate);
11711 left->inserted = right->inserted;
11712 left->duplicate = right->duplicate;
11713 left->needs_update = right->needs_update;
11714 left->target_info = right->target_info;
11715 right->inserted = left_inserted;
11716 right->duplicate = left_duplicate;
11717 right->needs_update = left_needs_update;
11718 right->target_info = left_target_info;
11721 /* Force the re-insertion of the locations at ADDRESS. This is called
11722 once a new/deleted/modified duplicate location is found and we are evaluating
11723 conditions on the target's side. Such conditions need to be updated on
11727 force_breakpoint_reinsertion (struct bp_location *bl)
11729 struct bp_location **locp = NULL, **loc2p;
11730 struct bp_location *loc;
11731 CORE_ADDR address = 0;
11734 address = bl->address;
11735 pspace_num = bl->pspace->num;
11737 /* This is only meaningful if the target is
11738 evaluating conditions and if the user has
11739 opted for condition evaluation on the target's
11741 if (gdb_evaluates_breakpoint_condition_p ()
11742 || !target_supports_evaluation_of_breakpoint_conditions ())
11745 /* Flag all breakpoint locations with this address and
11746 the same program space as the location
11747 as "its condition has changed". We need to
11748 update the conditions on the target's side. */
11749 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address)
11753 if (!is_breakpoint (loc->owner)
11754 || pspace_num != loc->pspace->num)
11757 /* Flag the location appropriately. We use a different state to
11758 let everyone know that we already updated the set of locations
11759 with addr bl->address and program space bl->pspace. This is so
11760 we don't have to keep calling these functions just to mark locations
11761 that have already been marked. */
11762 loc->condition_changed = condition_updated;
11764 /* Free the agent expression bytecode as well. We will compute
11766 if (loc->cond_bytecode)
11768 free_agent_expr (loc->cond_bytecode);
11769 loc->cond_bytecode = NULL;
11774 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
11775 into the inferior, only remove already-inserted locations that no
11776 longer should be inserted. Functions that delete a breakpoint or
11777 breakpoints should pass false, so that deleting a breakpoint
11778 doesn't have the side effect of inserting the locations of other
11779 breakpoints that are marked not-inserted, but should_be_inserted
11780 returns true on them.
11782 This behaviour is useful is situations close to tear-down -- e.g.,
11783 after an exec, while the target still has execution, but breakpoint
11784 shadows of the previous executable image should *NOT* be restored
11785 to the new image; or before detaching, where the target still has
11786 execution and wants to delete breakpoints from GDB's lists, and all
11787 breakpoints had already been removed from the inferior. */
11790 update_global_location_list (int should_insert)
11792 struct breakpoint *b;
11793 struct bp_location **locp, *loc;
11794 struct cleanup *cleanups;
11795 /* Last breakpoint location address that was marked for update. */
11796 CORE_ADDR last_addr = 0;
11797 /* Last breakpoint location program space that was marked for update. */
11798 int last_pspace_num = -1;
11800 /* Used in the duplicates detection below. When iterating over all
11801 bp_locations, points to the first bp_location of a given address.
11802 Breakpoints and watchpoints of different types are never
11803 duplicates of each other. Keep one pointer for each type of
11804 breakpoint/watchpoint, so we only need to loop over all locations
11806 struct bp_location *bp_loc_first; /* breakpoint */
11807 struct bp_location *wp_loc_first; /* hardware watchpoint */
11808 struct bp_location *awp_loc_first; /* access watchpoint */
11809 struct bp_location *rwp_loc_first; /* read watchpoint */
11811 /* Saved former bp_location array which we compare against the newly
11812 built bp_location from the current state of ALL_BREAKPOINTS. */
11813 struct bp_location **old_location, **old_locp;
11814 unsigned old_location_count;
11816 old_location = bp_location;
11817 old_location_count = bp_location_count;
11818 bp_location = NULL;
11819 bp_location_count = 0;
11820 cleanups = make_cleanup (xfree, old_location);
11822 ALL_BREAKPOINTS (b)
11823 for (loc = b->loc; loc; loc = loc->next)
11824 bp_location_count++;
11826 bp_location = xmalloc (sizeof (*bp_location) * bp_location_count);
11827 locp = bp_location;
11828 ALL_BREAKPOINTS (b)
11829 for (loc = b->loc; loc; loc = loc->next)
11831 qsort (bp_location, bp_location_count, sizeof (*bp_location),
11832 bp_location_compare);
11834 bp_location_target_extensions_update ();
11836 /* Identify bp_location instances that are no longer present in the
11837 new list, and therefore should be freed. Note that it's not
11838 necessary that those locations should be removed from inferior --
11839 if there's another location at the same address (previously
11840 marked as duplicate), we don't need to remove/insert the
11843 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11844 and former bp_location array state respectively. */
11846 locp = bp_location;
11847 for (old_locp = old_location; old_locp < old_location + old_location_count;
11850 struct bp_location *old_loc = *old_locp;
11851 struct bp_location **loc2p;
11853 /* Tells if 'old_loc' is found among the new locations. If
11854 not, we have to free it. */
11855 int found_object = 0;
11856 /* Tells if the location should remain inserted in the target. */
11857 int keep_in_target = 0;
11860 /* Skip LOCP entries which will definitely never be needed.
11861 Stop either at or being the one matching OLD_LOC. */
11862 while (locp < bp_location + bp_location_count
11863 && (*locp)->address < old_loc->address)
11867 (loc2p < bp_location + bp_location_count
11868 && (*loc2p)->address == old_loc->address);
11871 /* Check if this is a new/duplicated location or a duplicated
11872 location that had its condition modified. If so, we want to send
11873 its condition to the target if evaluation of conditions is taking
11875 if ((*loc2p)->condition_changed == condition_modified
11876 && (last_addr != old_loc->address
11877 || last_pspace_num != old_loc->pspace->num))
11879 force_breakpoint_reinsertion (*loc2p);
11880 last_pspace_num = old_loc->pspace->num;
11883 if (*loc2p == old_loc)
11887 /* We have already handled this address, update it so that we don't
11888 have to go through updates again. */
11889 last_addr = old_loc->address;
11891 /* Target-side condition evaluation: Handle deleted locations. */
11893 force_breakpoint_reinsertion (old_loc);
11895 /* If this location is no longer present, and inserted, look if
11896 there's maybe a new location at the same address. If so,
11897 mark that one inserted, and don't remove this one. This is
11898 needed so that we don't have a time window where a breakpoint
11899 at certain location is not inserted. */
11901 if (old_loc->inserted)
11903 /* If the location is inserted now, we might have to remove
11906 if (found_object && should_be_inserted (old_loc))
11908 /* The location is still present in the location list,
11909 and still should be inserted. Don't do anything. */
11910 keep_in_target = 1;
11914 /* This location still exists, but it won't be kept in the
11915 target since it may have been disabled. We proceed to
11916 remove its target-side condition. */
11918 /* The location is either no longer present, or got
11919 disabled. See if there's another location at the
11920 same address, in which case we don't need to remove
11921 this one from the target. */
11923 /* OLD_LOC comes from existing struct breakpoint. */
11924 if (breakpoint_address_is_meaningful (old_loc->owner))
11927 (loc2p < bp_location + bp_location_count
11928 && (*loc2p)->address == old_loc->address);
11931 struct bp_location *loc2 = *loc2p;
11933 if (breakpoint_locations_match (loc2, old_loc))
11935 /* Read watchpoint locations are switched to
11936 access watchpoints, if the former are not
11937 supported, but the latter are. */
11938 if (is_hardware_watchpoint (old_loc->owner))
11940 gdb_assert (is_hardware_watchpoint (loc2->owner));
11941 loc2->watchpoint_type = old_loc->watchpoint_type;
11944 /* loc2 is a duplicated location. We need to check
11945 if it should be inserted in case it will be
11947 if (loc2 != old_loc
11948 && unduplicated_should_be_inserted (loc2))
11950 swap_insertion (old_loc, loc2);
11951 keep_in_target = 1;
11959 if (!keep_in_target)
11961 if (remove_breakpoint (old_loc, mark_uninserted))
11963 /* This is just about all we can do. We could keep
11964 this location on the global list, and try to
11965 remove it next time, but there's no particular
11966 reason why we will succeed next time.
11968 Note that at this point, old_loc->owner is still
11969 valid, as delete_breakpoint frees the breakpoint
11970 only after calling us. */
11971 printf_filtered (_("warning: Error removing "
11972 "breakpoint %d\n"),
11973 old_loc->owner->number);
11981 if (removed && non_stop
11982 && breakpoint_address_is_meaningful (old_loc->owner)
11983 && !is_hardware_watchpoint (old_loc->owner))
11985 /* This location was removed from the target. In
11986 non-stop mode, a race condition is possible where
11987 we've removed a breakpoint, but stop events for that
11988 breakpoint are already queued and will arrive later.
11989 We apply an heuristic to be able to distinguish such
11990 SIGTRAPs from other random SIGTRAPs: we keep this
11991 breakpoint location for a bit, and will retire it
11992 after we see some number of events. The theory here
11993 is that reporting of events should, "on the average",
11994 be fair, so after a while we'll see events from all
11995 threads that have anything of interest, and no longer
11996 need to keep this breakpoint location around. We
11997 don't hold locations forever so to reduce chances of
11998 mistaking a non-breakpoint SIGTRAP for a breakpoint
12001 The heuristic failing can be disastrous on
12002 decr_pc_after_break targets.
12004 On decr_pc_after_break targets, like e.g., x86-linux,
12005 if we fail to recognize a late breakpoint SIGTRAP,
12006 because events_till_retirement has reached 0 too
12007 soon, we'll fail to do the PC adjustment, and report
12008 a random SIGTRAP to the user. When the user resumes
12009 the inferior, it will most likely immediately crash
12010 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12011 corrupted, because of being resumed e.g., in the
12012 middle of a multi-byte instruction, or skipped a
12013 one-byte instruction. This was actually seen happen
12014 on native x86-linux, and should be less rare on
12015 targets that do not support new thread events, like
12016 remote, due to the heuristic depending on
12019 Mistaking a random SIGTRAP for a breakpoint trap
12020 causes similar symptoms (PC adjustment applied when
12021 it shouldn't), but then again, playing with SIGTRAPs
12022 behind the debugger's back is asking for trouble.
12024 Since hardware watchpoint traps are always
12025 distinguishable from other traps, so we don't need to
12026 apply keep hardware watchpoint moribund locations
12027 around. We simply always ignore hardware watchpoint
12028 traps we can no longer explain. */
12030 old_loc->events_till_retirement = 3 * (thread_count () + 1);
12031 old_loc->owner = NULL;
12033 VEC_safe_push (bp_location_p, moribund_locations, old_loc);
12037 old_loc->owner = NULL;
12038 decref_bp_location (&old_loc);
12043 /* Rescan breakpoints at the same address and section, marking the
12044 first one as "first" and any others as "duplicates". This is so
12045 that the bpt instruction is only inserted once. If we have a
12046 permanent breakpoint at the same place as BPT, make that one the
12047 official one, and the rest as duplicates. Permanent breakpoints
12048 are sorted first for the same address.
12050 Do the same for hardware watchpoints, but also considering the
12051 watchpoint's type (regular/access/read) and length. */
12053 bp_loc_first = NULL;
12054 wp_loc_first = NULL;
12055 awp_loc_first = NULL;
12056 rwp_loc_first = NULL;
12057 ALL_BP_LOCATIONS (loc, locp)
12059 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12061 struct bp_location **loc_first_p;
12064 if (!should_be_inserted (loc)
12065 || !breakpoint_address_is_meaningful (b)
12066 /* Don't detect duplicate for tracepoint locations because they are
12067 never duplicated. See the comments in field `duplicate' of
12068 `struct bp_location'. */
12069 || is_tracepoint (b))
12071 /* Clear the condition modification flag. */
12072 loc->condition_changed = condition_unchanged;
12076 /* Permanent breakpoint should always be inserted. */
12077 if (b->enable_state == bp_permanent && ! loc->inserted)
12078 internal_error (__FILE__, __LINE__,
12079 _("allegedly permanent breakpoint is not "
12080 "actually inserted"));
12082 if (b->type == bp_hardware_watchpoint)
12083 loc_first_p = &wp_loc_first;
12084 else if (b->type == bp_read_watchpoint)
12085 loc_first_p = &rwp_loc_first;
12086 else if (b->type == bp_access_watchpoint)
12087 loc_first_p = &awp_loc_first;
12089 loc_first_p = &bp_loc_first;
12091 if (*loc_first_p == NULL
12092 || (overlay_debugging && loc->section != (*loc_first_p)->section)
12093 || !breakpoint_locations_match (loc, *loc_first_p))
12095 *loc_first_p = loc;
12096 loc->duplicate = 0;
12098 if (is_breakpoint (loc->owner) && loc->condition_changed)
12100 loc->needs_update = 1;
12101 /* Clear the condition modification flag. */
12102 loc->condition_changed = condition_unchanged;
12108 /* This and the above ensure the invariant that the first location
12109 is not duplicated, and is the inserted one.
12110 All following are marked as duplicated, and are not inserted. */
12112 swap_insertion (loc, *loc_first_p);
12113 loc->duplicate = 1;
12115 /* Clear the condition modification flag. */
12116 loc->condition_changed = condition_unchanged;
12118 if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted
12119 && b->enable_state != bp_permanent)
12120 internal_error (__FILE__, __LINE__,
12121 _("another breakpoint was inserted on top of "
12122 "a permanent breakpoint"));
12125 if (breakpoints_always_inserted_mode ()
12126 && (have_live_inferiors ()
12127 || (gdbarch_has_global_breakpoints (target_gdbarch))))
12130 insert_breakpoint_locations ();
12133 /* Though should_insert is false, we may need to update conditions
12134 on the target's side if it is evaluating such conditions. We
12135 only update conditions for locations that are marked
12137 update_inserted_breakpoint_locations ();
12142 download_tracepoint_locations ();
12144 do_cleanups (cleanups);
12148 breakpoint_retire_moribund (void)
12150 struct bp_location *loc;
12153 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
12154 if (--(loc->events_till_retirement) == 0)
12156 decref_bp_location (&loc);
12157 VEC_unordered_remove (bp_location_p, moribund_locations, ix);
12163 update_global_location_list_nothrow (int inserting)
12165 volatile struct gdb_exception e;
12167 TRY_CATCH (e, RETURN_MASK_ERROR)
12168 update_global_location_list (inserting);
12171 /* Clear BKP from a BPS. */
12174 bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt)
12178 for (bs = bps; bs; bs = bs->next)
12179 if (bs->breakpoint_at == bpt)
12181 bs->breakpoint_at = NULL;
12182 bs->old_val = NULL;
12183 /* bs->commands will be freed later. */
12187 /* Callback for iterate_over_threads. */
12189 bpstat_remove_breakpoint_callback (struct thread_info *th, void *data)
12191 struct breakpoint *bpt = data;
12193 bpstat_remove_bp_location (th->control.stop_bpstat, bpt);
12197 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12201 say_where (struct breakpoint *b)
12203 struct ui_out *uiout = current_uiout;
12204 struct value_print_options opts;
12206 get_user_print_options (&opts);
12208 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12210 if (b->loc == NULL)
12212 printf_filtered (_(" (%s) pending."), b->addr_string);
12216 if (opts.addressprint || b->loc->source_file == NULL)
12218 printf_filtered (" at ");
12219 fputs_filtered (paddress (b->loc->gdbarch, b->loc->address),
12222 if (b->loc->source_file)
12224 /* If there is a single location, we can print the location
12226 if (b->loc->next == NULL)
12227 printf_filtered (": file %s, line %d.",
12228 b->loc->source_file, b->loc->line_number);
12230 /* This is not ideal, but each location may have a
12231 different file name, and this at least reflects the
12232 real situation somewhat. */
12233 printf_filtered (": %s.", b->addr_string);
12238 struct bp_location *loc = b->loc;
12240 for (; loc; loc = loc->next)
12242 printf_filtered (" (%d locations)", n);
12247 /* Default bp_location_ops methods. */
12250 bp_location_dtor (struct bp_location *self)
12252 xfree (self->cond);
12253 if (self->cond_bytecode)
12254 free_agent_expr (self->cond_bytecode);
12255 xfree (self->function_name);
12256 xfree (self->source_file);
12259 static const struct bp_location_ops bp_location_ops =
12264 /* Default breakpoint_ops methods all breakpoint_ops ultimately
12268 base_breakpoint_dtor (struct breakpoint *self)
12270 decref_counted_command_line (&self->commands);
12271 xfree (self->cond_string);
12272 xfree (self->addr_string);
12273 xfree (self->filter);
12274 xfree (self->addr_string_range_end);
12277 static struct bp_location *
12278 base_breakpoint_allocate_location (struct breakpoint *self)
12280 struct bp_location *loc;
12282 loc = XNEW (struct bp_location);
12283 init_bp_location (loc, &bp_location_ops, self);
12288 base_breakpoint_re_set (struct breakpoint *b)
12290 /* Nothing to re-set. */
12293 #define internal_error_pure_virtual_called() \
12294 gdb_assert_not_reached ("pure virtual function called")
12297 base_breakpoint_insert_location (struct bp_location *bl)
12299 internal_error_pure_virtual_called ();
12303 base_breakpoint_remove_location (struct bp_location *bl)
12305 internal_error_pure_virtual_called ();
12309 base_breakpoint_breakpoint_hit (const struct bp_location *bl,
12310 struct address_space *aspace,
12312 const struct target_waitstatus *ws)
12314 internal_error_pure_virtual_called ();
12318 base_breakpoint_check_status (bpstat bs)
12323 /* A "works_in_software_mode" breakpoint_ops method that just internal
12327 base_breakpoint_works_in_software_mode (const struct breakpoint *b)
12329 internal_error_pure_virtual_called ();
12332 /* A "resources_needed" breakpoint_ops method that just internal
12336 base_breakpoint_resources_needed (const struct bp_location *bl)
12338 internal_error_pure_virtual_called ();
12341 static enum print_stop_action
12342 base_breakpoint_print_it (bpstat bs)
12344 internal_error_pure_virtual_called ();
12348 base_breakpoint_print_one_detail (const struct breakpoint *self,
12349 struct ui_out *uiout)
12355 base_breakpoint_print_mention (struct breakpoint *b)
12357 internal_error_pure_virtual_called ();
12361 base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp)
12363 internal_error_pure_virtual_called ();
12367 base_breakpoint_create_sals_from_address (char **arg,
12368 struct linespec_result *canonical,
12369 enum bptype type_wanted,
12373 internal_error_pure_virtual_called ();
12377 base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch,
12378 struct linespec_result *c,
12379 struct linespec_sals *lsal,
12381 char *extra_string,
12382 enum bptype type_wanted,
12383 enum bpdisp disposition,
12385 int task, int ignore_count,
12386 const struct breakpoint_ops *o,
12387 int from_tty, int enabled,
12388 int internal, unsigned flags)
12390 internal_error_pure_virtual_called ();
12394 base_breakpoint_decode_linespec (struct breakpoint *b, char **s,
12395 struct symtabs_and_lines *sals)
12397 internal_error_pure_virtual_called ();
12400 static struct breakpoint_ops base_breakpoint_ops =
12402 base_breakpoint_dtor,
12403 base_breakpoint_allocate_location,
12404 base_breakpoint_re_set,
12405 base_breakpoint_insert_location,
12406 base_breakpoint_remove_location,
12407 base_breakpoint_breakpoint_hit,
12408 base_breakpoint_check_status,
12409 base_breakpoint_resources_needed,
12410 base_breakpoint_works_in_software_mode,
12411 base_breakpoint_print_it,
12413 base_breakpoint_print_one_detail,
12414 base_breakpoint_print_mention,
12415 base_breakpoint_print_recreate,
12416 base_breakpoint_create_sals_from_address,
12417 base_breakpoint_create_breakpoints_sal,
12418 base_breakpoint_decode_linespec,
12421 /* Default breakpoint_ops methods. */
12424 bkpt_re_set (struct breakpoint *b)
12426 /* FIXME: is this still reachable? */
12427 if (b->addr_string == NULL)
12429 /* Anything without a string can't be re-set. */
12430 delete_breakpoint (b);
12434 breakpoint_re_set_default (b);
12438 bkpt_insert_location (struct bp_location *bl)
12440 if (bl->loc_type == bp_loc_hardware_breakpoint)
12441 return target_insert_hw_breakpoint (bl->gdbarch,
12444 return target_insert_breakpoint (bl->gdbarch,
12449 bkpt_remove_location (struct bp_location *bl)
12451 if (bl->loc_type == bp_loc_hardware_breakpoint)
12452 return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info);
12454 return target_remove_breakpoint (bl->gdbarch, &bl->target_info);
12458 bkpt_breakpoint_hit (const struct bp_location *bl,
12459 struct address_space *aspace, CORE_ADDR bp_addr,
12460 const struct target_waitstatus *ws)
12462 struct breakpoint *b = bl->owner;
12464 if (ws->kind != TARGET_WAITKIND_STOPPED
12465 || ws->value.sig != TARGET_SIGNAL_TRAP)
12468 if (!breakpoint_address_match (bl->pspace->aspace, bl->address,
12472 if (overlay_debugging /* unmapped overlay section */
12473 && section_is_overlay (bl->section)
12474 && !section_is_mapped (bl->section))
12481 bkpt_resources_needed (const struct bp_location *bl)
12483 gdb_assert (bl->owner->type == bp_hardware_breakpoint);
12488 static enum print_stop_action
12489 bkpt_print_it (bpstat bs)
12491 struct breakpoint *b;
12492 const struct bp_location *bl;
12494 struct ui_out *uiout = current_uiout;
12496 gdb_assert (bs->bp_location_at != NULL);
12498 bl = bs->bp_location_at;
12499 b = bs->breakpoint_at;
12501 bp_temp = b->disposition == disp_del;
12502 if (bl->address != bl->requested_address)
12503 breakpoint_adjustment_warning (bl->requested_address,
12506 annotate_breakpoint (b->number);
12508 ui_out_text (uiout, "\nTemporary breakpoint ");
12510 ui_out_text (uiout, "\nBreakpoint ");
12511 if (ui_out_is_mi_like_p (uiout))
12513 ui_out_field_string (uiout, "reason",
12514 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
12515 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
12517 ui_out_field_int (uiout, "bkptno", b->number);
12518 ui_out_text (uiout, ", ");
12520 return PRINT_SRC_AND_LOC;
12524 bkpt_print_mention (struct breakpoint *b)
12526 if (ui_out_is_mi_like_p (current_uiout))
12531 case bp_breakpoint:
12532 case bp_gnu_ifunc_resolver:
12533 if (b->disposition == disp_del)
12534 printf_filtered (_("Temporary breakpoint"));
12536 printf_filtered (_("Breakpoint"));
12537 printf_filtered (_(" %d"), b->number);
12538 if (b->type == bp_gnu_ifunc_resolver)
12539 printf_filtered (_(" at gnu-indirect-function resolver"));
12541 case bp_hardware_breakpoint:
12542 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
12545 printf_filtered (_("Dprintf %d"), b->number);
12553 bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp)
12555 if (tp->type == bp_breakpoint && tp->disposition == disp_del)
12556 fprintf_unfiltered (fp, "tbreak");
12557 else if (tp->type == bp_breakpoint)
12558 fprintf_unfiltered (fp, "break");
12559 else if (tp->type == bp_hardware_breakpoint
12560 && tp->disposition == disp_del)
12561 fprintf_unfiltered (fp, "thbreak");
12562 else if (tp->type == bp_hardware_breakpoint)
12563 fprintf_unfiltered (fp, "hbreak");
12565 internal_error (__FILE__, __LINE__,
12566 _("unhandled breakpoint type %d"), (int) tp->type);
12568 fprintf_unfiltered (fp, " %s", tp->addr_string);
12569 print_recreate_thread (tp, fp);
12573 bkpt_create_sals_from_address (char **arg,
12574 struct linespec_result *canonical,
12575 enum bptype type_wanted,
12576 char *addr_start, char **copy_arg)
12578 create_sals_from_address_default (arg, canonical, type_wanted,
12579 addr_start, copy_arg);
12583 bkpt_create_breakpoints_sal (struct gdbarch *gdbarch,
12584 struct linespec_result *canonical,
12585 struct linespec_sals *lsal,
12587 char *extra_string,
12588 enum bptype type_wanted,
12589 enum bpdisp disposition,
12591 int task, int ignore_count,
12592 const struct breakpoint_ops *ops,
12593 int from_tty, int enabled,
12594 int internal, unsigned flags)
12596 create_breakpoints_sal_default (gdbarch, canonical, lsal,
12597 cond_string, extra_string,
12599 disposition, thread, task,
12600 ignore_count, ops, from_tty,
12601 enabled, internal, flags);
12605 bkpt_decode_linespec (struct breakpoint *b, char **s,
12606 struct symtabs_and_lines *sals)
12608 decode_linespec_default (b, s, sals);
12611 /* Virtual table for internal breakpoints. */
12614 internal_bkpt_re_set (struct breakpoint *b)
12618 /* Delete overlay event and longjmp master breakpoints; they
12619 will be reset later by breakpoint_re_set. */
12620 case bp_overlay_event:
12621 case bp_longjmp_master:
12622 case bp_std_terminate_master:
12623 case bp_exception_master:
12624 delete_breakpoint (b);
12627 /* This breakpoint is special, it's set up when the inferior
12628 starts and we really don't want to touch it. */
12629 case bp_shlib_event:
12631 /* Like bp_shlib_event, this breakpoint type is special. Once
12632 it is set up, we do not want to touch it. */
12633 case bp_thread_event:
12639 internal_bkpt_check_status (bpstat bs)
12641 if (bs->breakpoint_at->type == bp_shlib_event)
12643 /* If requested, stop when the dynamic linker notifies GDB of
12644 events. This allows the user to get control and place
12645 breakpoints in initializer routines for dynamically loaded
12646 objects (among other things). */
12647 bs->stop = stop_on_solib_events;
12648 bs->print = stop_on_solib_events;
12654 static enum print_stop_action
12655 internal_bkpt_print_it (bpstat bs)
12657 struct ui_out *uiout = current_uiout;
12658 struct breakpoint *b;
12660 b = bs->breakpoint_at;
12664 case bp_shlib_event:
12665 /* Did we stop because the user set the stop_on_solib_events
12666 variable? (If so, we report this as a generic, "Stopped due
12667 to shlib event" message.) */
12668 print_solib_event (0);
12671 case bp_thread_event:
12672 /* Not sure how we will get here.
12673 GDB should not stop for these breakpoints. */
12674 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
12677 case bp_overlay_event:
12678 /* By analogy with the thread event, GDB should not stop for these. */
12679 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
12682 case bp_longjmp_master:
12683 /* These should never be enabled. */
12684 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
12687 case bp_std_terminate_master:
12688 /* These should never be enabled. */
12689 printf_filtered (_("std::terminate Master Breakpoint: "
12690 "gdb should not stop!\n"));
12693 case bp_exception_master:
12694 /* These should never be enabled. */
12695 printf_filtered (_("Exception Master Breakpoint: "
12696 "gdb should not stop!\n"));
12700 return PRINT_NOTHING;
12704 internal_bkpt_print_mention (struct breakpoint *b)
12706 /* Nothing to mention. These breakpoints are internal. */
12709 /* Virtual table for momentary breakpoints */
12712 momentary_bkpt_re_set (struct breakpoint *b)
12714 /* Keep temporary breakpoints, which can be encountered when we step
12715 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
12716 Otherwise these should have been blown away via the cleanup chain
12717 or by breakpoint_init_inferior when we rerun the executable. */
12721 momentary_bkpt_check_status (bpstat bs)
12723 /* Nothing. The point of these breakpoints is causing a stop. */
12726 static enum print_stop_action
12727 momentary_bkpt_print_it (bpstat bs)
12729 struct ui_out *uiout = current_uiout;
12731 if (ui_out_is_mi_like_p (uiout))
12733 struct breakpoint *b = bs->breakpoint_at;
12738 ui_out_field_string
12740 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED));
12744 ui_out_field_string
12746 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED));
12751 return PRINT_UNKNOWN;
12755 momentary_bkpt_print_mention (struct breakpoint *b)
12757 /* Nothing to mention. These breakpoints are internal. */
12760 /* Specific methods for probe breakpoints. */
12763 bkpt_probe_insert_location (struct bp_location *bl)
12765 int v = bkpt_insert_location (bl);
12769 /* The insertion was successful, now let's set the probe's semaphore
12771 bl->probe->pops->set_semaphore (bl->probe, bl->gdbarch);
12778 bkpt_probe_remove_location (struct bp_location *bl)
12780 /* Let's clear the semaphore before removing the location. */
12781 bl->probe->pops->clear_semaphore (bl->probe, bl->gdbarch);
12783 return bkpt_remove_location (bl);
12787 bkpt_probe_create_sals_from_address (char **arg,
12788 struct linespec_result *canonical,
12789 enum bptype type_wanted,
12790 char *addr_start, char **copy_arg)
12792 struct linespec_sals lsal;
12794 lsal.sals = parse_probes (arg, canonical);
12796 *copy_arg = xstrdup (canonical->addr_string);
12797 lsal.canonical = xstrdup (*copy_arg);
12799 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
12803 bkpt_probe_decode_linespec (struct breakpoint *b, char **s,
12804 struct symtabs_and_lines *sals)
12806 *sals = parse_probes (s, NULL);
12808 error (_("probe not found"));
12811 /* The breakpoint_ops structure to be used in tracepoints. */
12814 tracepoint_re_set (struct breakpoint *b)
12816 breakpoint_re_set_default (b);
12820 tracepoint_breakpoint_hit (const struct bp_location *bl,
12821 struct address_space *aspace, CORE_ADDR bp_addr,
12822 const struct target_waitstatus *ws)
12824 /* By definition, the inferior does not report stops at
12830 tracepoint_print_one_detail (const struct breakpoint *self,
12831 struct ui_out *uiout)
12833 struct tracepoint *tp = (struct tracepoint *) self;
12834 if (tp->static_trace_marker_id)
12836 gdb_assert (self->type == bp_static_tracepoint);
12838 ui_out_text (uiout, "\tmarker id is ");
12839 ui_out_field_string (uiout, "static-tracepoint-marker-string-id",
12840 tp->static_trace_marker_id);
12841 ui_out_text (uiout, "\n");
12846 tracepoint_print_mention (struct breakpoint *b)
12848 if (ui_out_is_mi_like_p (current_uiout))
12853 case bp_tracepoint:
12854 printf_filtered (_("Tracepoint"));
12855 printf_filtered (_(" %d"), b->number);
12857 case bp_fast_tracepoint:
12858 printf_filtered (_("Fast tracepoint"));
12859 printf_filtered (_(" %d"), b->number);
12861 case bp_static_tracepoint:
12862 printf_filtered (_("Static tracepoint"));
12863 printf_filtered (_(" %d"), b->number);
12866 internal_error (__FILE__, __LINE__,
12867 _("unhandled tracepoint type %d"), (int) b->type);
12874 tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp)
12876 struct tracepoint *tp = (struct tracepoint *) self;
12878 if (self->type == bp_fast_tracepoint)
12879 fprintf_unfiltered (fp, "ftrace");
12880 if (self->type == bp_static_tracepoint)
12881 fprintf_unfiltered (fp, "strace");
12882 else if (self->type == bp_tracepoint)
12883 fprintf_unfiltered (fp, "trace");
12885 internal_error (__FILE__, __LINE__,
12886 _("unhandled tracepoint type %d"), (int) self->type);
12888 fprintf_unfiltered (fp, " %s", self->addr_string);
12889 print_recreate_thread (self, fp);
12891 if (tp->pass_count)
12892 fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count);
12896 tracepoint_create_sals_from_address (char **arg,
12897 struct linespec_result *canonical,
12898 enum bptype type_wanted,
12899 char *addr_start, char **copy_arg)
12901 create_sals_from_address_default (arg, canonical, type_wanted,
12902 addr_start, copy_arg);
12906 tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch,
12907 struct linespec_result *canonical,
12908 struct linespec_sals *lsal,
12910 char *extra_string,
12911 enum bptype type_wanted,
12912 enum bpdisp disposition,
12914 int task, int ignore_count,
12915 const struct breakpoint_ops *ops,
12916 int from_tty, int enabled,
12917 int internal, unsigned flags)
12919 create_breakpoints_sal_default (gdbarch, canonical, lsal,
12920 cond_string, extra_string,
12922 disposition, thread, task,
12923 ignore_count, ops, from_tty,
12924 enabled, internal, flags);
12928 tracepoint_decode_linespec (struct breakpoint *b, char **s,
12929 struct symtabs_and_lines *sals)
12931 decode_linespec_default (b, s, sals);
12934 struct breakpoint_ops tracepoint_breakpoint_ops;
12936 /* The breakpoint_ops structure to be use on tracepoints placed in a
12940 tracepoint_probe_create_sals_from_address (char **arg,
12941 struct linespec_result *canonical,
12942 enum bptype type_wanted,
12943 char *addr_start, char **copy_arg)
12945 /* We use the same method for breakpoint on probes. */
12946 bkpt_probe_create_sals_from_address (arg, canonical, type_wanted,
12947 addr_start, copy_arg);
12951 tracepoint_probe_decode_linespec (struct breakpoint *b, char **s,
12952 struct symtabs_and_lines *sals)
12954 /* We use the same method for breakpoint on probes. */
12955 bkpt_probe_decode_linespec (b, s, sals);
12958 static struct breakpoint_ops tracepoint_probe_breakpoint_ops;
12960 /* The breakpoint_ops structure to be used on static tracepoints with
12964 strace_marker_create_sals_from_address (char **arg,
12965 struct linespec_result *canonical,
12966 enum bptype type_wanted,
12967 char *addr_start, char **copy_arg)
12969 struct linespec_sals lsal;
12971 lsal.sals = decode_static_tracepoint_spec (arg);
12973 *copy_arg = savestring (addr_start, *arg - addr_start);
12975 canonical->addr_string = xstrdup (*copy_arg);
12976 lsal.canonical = xstrdup (*copy_arg);
12977 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
12981 strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch,
12982 struct linespec_result *canonical,
12983 struct linespec_sals *lsal,
12985 char *extra_string,
12986 enum bptype type_wanted,
12987 enum bpdisp disposition,
12989 int task, int ignore_count,
12990 const struct breakpoint_ops *ops,
12991 int from_tty, int enabled,
12992 int internal, unsigned flags)
12996 /* If the user is creating a static tracepoint by marker id
12997 (strace -m MARKER_ID), then store the sals index, so that
12998 breakpoint_re_set can try to match up which of the newly
12999 found markers corresponds to this one, and, don't try to
13000 expand multiple locations for each sal, given than SALS
13001 already should contain all sals for MARKER_ID. */
13003 for (i = 0; i < lsal->sals.nelts; ++i)
13005 struct symtabs_and_lines expanded;
13006 struct tracepoint *tp;
13007 struct cleanup *old_chain;
13010 expanded.nelts = 1;
13011 expanded.sals = &lsal->sals.sals[i];
13013 addr_string = xstrdup (canonical->addr_string);
13014 old_chain = make_cleanup (xfree, addr_string);
13016 tp = XCNEW (struct tracepoint);
13017 init_breakpoint_sal (&tp->base, gdbarch, expanded,
13019 cond_string, extra_string,
13020 type_wanted, disposition,
13021 thread, task, ignore_count, ops,
13022 from_tty, enabled, internal, flags,
13023 canonical->special_display);
13024 /* Given that its possible to have multiple markers with
13025 the same string id, if the user is creating a static
13026 tracepoint by marker id ("strace -m MARKER_ID"), then
13027 store the sals index, so that breakpoint_re_set can
13028 try to match up which of the newly found markers
13029 corresponds to this one */
13030 tp->static_trace_marker_id_idx = i;
13032 install_breakpoint (internal, &tp->base, 0);
13034 discard_cleanups (old_chain);
13039 strace_marker_decode_linespec (struct breakpoint *b, char **s,
13040 struct symtabs_and_lines *sals)
13042 struct tracepoint *tp = (struct tracepoint *) b;
13044 *sals = decode_static_tracepoint_spec (s);
13045 if (sals->nelts > tp->static_trace_marker_id_idx)
13047 sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx];
13051 error (_("marker %s not found"), tp->static_trace_marker_id);
13054 static struct breakpoint_ops strace_marker_breakpoint_ops;
13057 strace_marker_p (struct breakpoint *b)
13059 return b->ops == &strace_marker_breakpoint_ops;
13062 /* Delete a breakpoint and clean up all traces of it in the data
13066 delete_breakpoint (struct breakpoint *bpt)
13068 struct breakpoint *b;
13070 gdb_assert (bpt != NULL);
13072 /* Has this bp already been deleted? This can happen because
13073 multiple lists can hold pointers to bp's. bpstat lists are
13076 One example of this happening is a watchpoint's scope bp. When
13077 the scope bp triggers, we notice that the watchpoint is out of
13078 scope, and delete it. We also delete its scope bp. But the
13079 scope bp is marked "auto-deleting", and is already on a bpstat.
13080 That bpstat is then checked for auto-deleting bp's, which are
13083 A real solution to this problem might involve reference counts in
13084 bp's, and/or giving them pointers back to their referencing
13085 bpstat's, and teaching delete_breakpoint to only free a bp's
13086 storage when no more references were extent. A cheaper bandaid
13088 if (bpt->type == bp_none)
13091 /* At least avoid this stale reference until the reference counting
13092 of breakpoints gets resolved. */
13093 if (bpt->related_breakpoint != bpt)
13095 struct breakpoint *related;
13096 struct watchpoint *w;
13098 if (bpt->type == bp_watchpoint_scope)
13099 w = (struct watchpoint *) bpt->related_breakpoint;
13100 else if (bpt->related_breakpoint->type == bp_watchpoint_scope)
13101 w = (struct watchpoint *) bpt;
13105 watchpoint_del_at_next_stop (w);
13107 /* Unlink bpt from the bpt->related_breakpoint ring. */
13108 for (related = bpt; related->related_breakpoint != bpt;
13109 related = related->related_breakpoint);
13110 related->related_breakpoint = bpt->related_breakpoint;
13111 bpt->related_breakpoint = bpt;
13114 /* watch_command_1 creates a watchpoint but only sets its number if
13115 update_watchpoint succeeds in creating its bp_locations. If there's
13116 a problem in that process, we'll be asked to delete the half-created
13117 watchpoint. In that case, don't announce the deletion. */
13119 observer_notify_breakpoint_deleted (bpt);
13121 if (breakpoint_chain == bpt)
13122 breakpoint_chain = bpt->next;
13124 ALL_BREAKPOINTS (b)
13125 if (b->next == bpt)
13127 b->next = bpt->next;
13131 /* Be sure no bpstat's are pointing at the breakpoint after it's
13133 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13134 in all threads for now. Note that we cannot just remove bpstats
13135 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13136 commands are associated with the bpstat; if we remove it here,
13137 then the later call to bpstat_do_actions (&stop_bpstat); in
13138 event-top.c won't do anything, and temporary breakpoints with
13139 commands won't work. */
13141 iterate_over_threads (bpstat_remove_breakpoint_callback, bpt);
13143 /* Now that breakpoint is removed from breakpoint list, update the
13144 global location list. This will remove locations that used to
13145 belong to this breakpoint. Do this before freeing the breakpoint
13146 itself, since remove_breakpoint looks at location's owner. It
13147 might be better design to have location completely
13148 self-contained, but it's not the case now. */
13149 update_global_location_list (0);
13151 bpt->ops->dtor (bpt);
13152 /* On the chance that someone will soon try again to delete this
13153 same bp, we mark it as deleted before freeing its storage. */
13154 bpt->type = bp_none;
13159 do_delete_breakpoint_cleanup (void *b)
13161 delete_breakpoint (b);
13165 make_cleanup_delete_breakpoint (struct breakpoint *b)
13167 return make_cleanup (do_delete_breakpoint_cleanup, b);
13170 /* Iterator function to call a user-provided callback function once
13171 for each of B and its related breakpoints. */
13174 iterate_over_related_breakpoints (struct breakpoint *b,
13175 void (*function) (struct breakpoint *,
13179 struct breakpoint *related;
13184 struct breakpoint *next;
13186 /* FUNCTION may delete RELATED. */
13187 next = related->related_breakpoint;
13189 if (next == related)
13191 /* RELATED is the last ring entry. */
13192 function (related, data);
13194 /* FUNCTION may have deleted it, so we'd never reach back to
13195 B. There's nothing left to do anyway, so just break
13200 function (related, data);
13204 while (related != b);
13208 do_delete_breakpoint (struct breakpoint *b, void *ignore)
13210 delete_breakpoint (b);
13213 /* A callback for map_breakpoint_numbers that calls
13214 delete_breakpoint. */
13217 do_map_delete_breakpoint (struct breakpoint *b, void *ignore)
13219 iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL);
13223 delete_command (char *arg, int from_tty)
13225 struct breakpoint *b, *b_tmp;
13231 int breaks_to_delete = 0;
13233 /* Delete all breakpoints if no argument. Do not delete
13234 internal breakpoints, these have to be deleted with an
13235 explicit breakpoint number argument. */
13236 ALL_BREAKPOINTS (b)
13237 if (user_breakpoint_p (b))
13239 breaks_to_delete = 1;
13243 /* Ask user only if there are some breakpoints to delete. */
13245 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
13247 ALL_BREAKPOINTS_SAFE (b, b_tmp)
13248 if (user_breakpoint_p (b))
13249 delete_breakpoint (b);
13253 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
13257 all_locations_are_pending (struct bp_location *loc)
13259 for (; loc; loc = loc->next)
13260 if (!loc->shlib_disabled
13261 && !loc->pspace->executing_startup)
13266 /* Subroutine of update_breakpoint_locations to simplify it.
13267 Return non-zero if multiple fns in list LOC have the same name.
13268 Null names are ignored. */
13271 ambiguous_names_p (struct bp_location *loc)
13273 struct bp_location *l;
13274 htab_t htab = htab_create_alloc (13, htab_hash_string,
13275 (int (*) (const void *,
13276 const void *)) streq,
13277 NULL, xcalloc, xfree);
13279 for (l = loc; l != NULL; l = l->next)
13282 const char *name = l->function_name;
13284 /* Allow for some names to be NULL, ignore them. */
13288 slot = (const char **) htab_find_slot (htab, (const void *) name,
13290 /* NOTE: We can assume slot != NULL here because xcalloc never
13294 htab_delete (htab);
13300 htab_delete (htab);
13304 /* When symbols change, it probably means the sources changed as well,
13305 and it might mean the static tracepoint markers are no longer at
13306 the same address or line numbers they used to be at last we
13307 checked. Losing your static tracepoints whenever you rebuild is
13308 undesirable. This function tries to resync/rematch gdb static
13309 tracepoints with the markers on the target, for static tracepoints
13310 that have not been set by marker id. Static tracepoint that have
13311 been set by marker id are reset by marker id in breakpoint_re_set.
13314 1) For a tracepoint set at a specific address, look for a marker at
13315 the old PC. If one is found there, assume to be the same marker.
13316 If the name / string id of the marker found is different from the
13317 previous known name, assume that means the user renamed the marker
13318 in the sources, and output a warning.
13320 2) For a tracepoint set at a given line number, look for a marker
13321 at the new address of the old line number. If one is found there,
13322 assume to be the same marker. If the name / string id of the
13323 marker found is different from the previous known name, assume that
13324 means the user renamed the marker in the sources, and output a
13327 3) If a marker is no longer found at the same address or line, it
13328 may mean the marker no longer exists. But it may also just mean
13329 the code changed a bit. Maybe the user added a few lines of code
13330 that made the marker move up or down (in line number terms). Ask
13331 the target for info about the marker with the string id as we knew
13332 it. If found, update line number and address in the matching
13333 static tracepoint. This will get confused if there's more than one
13334 marker with the same ID (possible in UST, although unadvised
13335 precisely because it confuses tools). */
13337 static struct symtab_and_line
13338 update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal)
13340 struct tracepoint *tp = (struct tracepoint *) b;
13341 struct static_tracepoint_marker marker;
13347 find_line_pc (sal.symtab, sal.line, &pc);
13349 if (target_static_tracepoint_marker_at (pc, &marker))
13351 if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0)
13352 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13354 tp->static_trace_marker_id, marker.str_id);
13356 xfree (tp->static_trace_marker_id);
13357 tp->static_trace_marker_id = xstrdup (marker.str_id);
13358 release_static_tracepoint_marker (&marker);
13363 /* Old marker wasn't found on target at lineno. Try looking it up
13365 if (!sal.explicit_pc
13367 && sal.symtab != NULL
13368 && tp->static_trace_marker_id != NULL)
13370 VEC(static_tracepoint_marker_p) *markers;
13373 = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id);
13375 if (!VEC_empty(static_tracepoint_marker_p, markers))
13377 struct symtab_and_line sal2;
13378 struct symbol *sym;
13379 struct static_tracepoint_marker *tpmarker;
13380 struct ui_out *uiout = current_uiout;
13382 tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0);
13384 xfree (tp->static_trace_marker_id);
13385 tp->static_trace_marker_id = xstrdup (tpmarker->str_id);
13387 warning (_("marker for static tracepoint %d (%s) not "
13388 "found at previous line number"),
13389 b->number, tp->static_trace_marker_id);
13393 sal2.pc = tpmarker->address;
13395 sal2 = find_pc_line (tpmarker->address, 0);
13396 sym = find_pc_sect_function (tpmarker->address, NULL);
13397 ui_out_text (uiout, "Now in ");
13400 ui_out_field_string (uiout, "func",
13401 SYMBOL_PRINT_NAME (sym));
13402 ui_out_text (uiout, " at ");
13404 ui_out_field_string (uiout, "file", sal2.symtab->filename);
13405 ui_out_text (uiout, ":");
13407 if (ui_out_is_mi_like_p (uiout))
13409 char *fullname = symtab_to_fullname (sal2.symtab);
13412 ui_out_field_string (uiout, "fullname", fullname);
13415 ui_out_field_int (uiout, "line", sal2.line);
13416 ui_out_text (uiout, "\n");
13418 b->loc->line_number = sal2.line;
13420 xfree (b->loc->source_file);
13422 b->loc->source_file = xstrdup (sal2.symtab->filename);
13424 b->loc->source_file = NULL;
13426 xfree (b->addr_string);
13427 b->addr_string = xstrprintf ("%s:%d",
13428 sal2.symtab->filename,
13429 b->loc->line_number);
13431 /* Might be nice to check if function changed, and warn if
13434 release_static_tracepoint_marker (tpmarker);
13440 /* Returns 1 iff locations A and B are sufficiently same that
13441 we don't need to report breakpoint as changed. */
13444 locations_are_equal (struct bp_location *a, struct bp_location *b)
13448 if (a->address != b->address)
13451 if (a->shlib_disabled != b->shlib_disabled)
13454 if (a->enabled != b->enabled)
13461 if ((a == NULL) != (b == NULL))
13467 /* Create new breakpoint locations for B (a hardware or software breakpoint)
13468 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
13469 a ranged breakpoint. */
13472 update_breakpoint_locations (struct breakpoint *b,
13473 struct symtabs_and_lines sals,
13474 struct symtabs_and_lines sals_end)
13477 struct bp_location *existing_locations = b->loc;
13479 if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1))
13481 /* Ranged breakpoints have only one start location and one end
13483 b->enable_state = bp_disabled;
13484 update_global_location_list (1);
13485 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
13486 "multiple locations found\n"),
13491 /* If there's no new locations, and all existing locations are
13492 pending, don't do anything. This optimizes the common case where
13493 all locations are in the same shared library, that was unloaded.
13494 We'd like to retain the location, so that when the library is
13495 loaded again, we don't loose the enabled/disabled status of the
13496 individual locations. */
13497 if (all_locations_are_pending (existing_locations) && sals.nelts == 0)
13502 for (i = 0; i < sals.nelts; ++i)
13504 struct bp_location *new_loc;
13506 switch_to_program_space_and_thread (sals.sals[i].pspace);
13508 new_loc = add_location_to_breakpoint (b, &(sals.sals[i]));
13510 /* Reparse conditions, they might contain references to the
13512 if (b->cond_string != NULL)
13515 volatile struct gdb_exception e;
13517 s = b->cond_string;
13518 TRY_CATCH (e, RETURN_MASK_ERROR)
13520 new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc),
13525 warning (_("failed to reevaluate condition "
13526 "for breakpoint %d: %s"),
13527 b->number, e.message);
13528 new_loc->enabled = 0;
13532 if (sals_end.nelts)
13534 CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]);
13536 new_loc->length = end - sals.sals[0].pc + 1;
13540 /* Update locations of permanent breakpoints. */
13541 if (b->enable_state == bp_permanent)
13542 make_breakpoint_permanent (b);
13544 /* If possible, carry over 'disable' status from existing
13547 struct bp_location *e = existing_locations;
13548 /* If there are multiple breakpoints with the same function name,
13549 e.g. for inline functions, comparing function names won't work.
13550 Instead compare pc addresses; this is just a heuristic as things
13551 may have moved, but in practice it gives the correct answer
13552 often enough until a better solution is found. */
13553 int have_ambiguous_names = ambiguous_names_p (b->loc);
13555 for (; e; e = e->next)
13557 if (!e->enabled && e->function_name)
13559 struct bp_location *l = b->loc;
13560 if (have_ambiguous_names)
13562 for (; l; l = l->next)
13563 if (breakpoint_locations_match (e, l))
13571 for (; l; l = l->next)
13572 if (l->function_name
13573 && strcmp (e->function_name, l->function_name) == 0)
13583 if (!locations_are_equal (existing_locations, b->loc))
13584 observer_notify_breakpoint_modified (b);
13586 update_global_location_list (1);
13589 /* Find the SaL locations corresponding to the given ADDR_STRING.
13590 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
13592 static struct symtabs_and_lines
13593 addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found)
13596 struct symtabs_and_lines sals = {0};
13597 volatile struct gdb_exception e;
13599 gdb_assert (b->ops != NULL);
13602 TRY_CATCH (e, RETURN_MASK_ERROR)
13604 b->ops->decode_linespec (b, &s, &sals);
13608 int not_found_and_ok = 0;
13609 /* For pending breakpoints, it's expected that parsing will
13610 fail until the right shared library is loaded. User has
13611 already told to create pending breakpoints and don't need
13612 extra messages. If breakpoint is in bp_shlib_disabled
13613 state, then user already saw the message about that
13614 breakpoint being disabled, and don't want to see more
13616 if (e.error == NOT_FOUND_ERROR
13617 && (b->condition_not_parsed
13618 || (b->loc && b->loc->shlib_disabled)
13619 || (b->loc && b->loc->pspace->executing_startup)
13620 || b->enable_state == bp_disabled))
13621 not_found_and_ok = 1;
13623 if (!not_found_and_ok)
13625 /* We surely don't want to warn about the same breakpoint
13626 10 times. One solution, implemented here, is disable
13627 the breakpoint on error. Another solution would be to
13628 have separate 'warning emitted' flag. Since this
13629 happens only when a binary has changed, I don't know
13630 which approach is better. */
13631 b->enable_state = bp_disabled;
13632 throw_exception (e);
13636 if (e.reason == 0 || e.error != NOT_FOUND_ERROR)
13640 for (i = 0; i < sals.nelts; ++i)
13641 resolve_sal_pc (&sals.sals[i]);
13642 if (b->condition_not_parsed && s && s[0])
13644 char *cond_string = 0;
13647 char *extra_string = NULL;
13649 find_condition_and_thread (s, sals.sals[0].pc,
13650 &cond_string, &thread, &task,
13653 b->cond_string = cond_string;
13654 b->thread = thread;
13657 b->extra_string = extra_string;
13658 b->condition_not_parsed = 0;
13661 if (b->type == bp_static_tracepoint && !strace_marker_p (b))
13662 sals.sals[0] = update_static_tracepoint (b, sals.sals[0]);
13672 /* The default re_set method, for typical hardware or software
13673 breakpoints. Reevaluate the breakpoint and recreate its
13677 breakpoint_re_set_default (struct breakpoint *b)
13680 struct symtabs_and_lines sals, sals_end;
13681 struct symtabs_and_lines expanded = {0};
13682 struct symtabs_and_lines expanded_end = {0};
13684 sals = addr_string_to_sals (b, b->addr_string, &found);
13687 make_cleanup (xfree, sals.sals);
13691 if (b->addr_string_range_end)
13693 sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found);
13696 make_cleanup (xfree, sals_end.sals);
13697 expanded_end = sals_end;
13701 update_breakpoint_locations (b, expanded, expanded_end);
13704 /* Default method for creating SALs from an address string. It basically
13705 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
13708 create_sals_from_address_default (char **arg,
13709 struct linespec_result *canonical,
13710 enum bptype type_wanted,
13711 char *addr_start, char **copy_arg)
13713 parse_breakpoint_sals (arg, canonical);
13716 /* Call create_breakpoints_sal for the given arguments. This is the default
13717 function for the `create_breakpoints_sal' method of
13721 create_breakpoints_sal_default (struct gdbarch *gdbarch,
13722 struct linespec_result *canonical,
13723 struct linespec_sals *lsal,
13725 char *extra_string,
13726 enum bptype type_wanted,
13727 enum bpdisp disposition,
13729 int task, int ignore_count,
13730 const struct breakpoint_ops *ops,
13731 int from_tty, int enabled,
13732 int internal, unsigned flags)
13734 create_breakpoints_sal (gdbarch, canonical, cond_string,
13736 type_wanted, disposition,
13737 thread, task, ignore_count, ops, from_tty,
13738 enabled, internal, flags);
13741 /* Decode the line represented by S by calling decode_line_full. This is the
13742 default function for the `decode_linespec' method of breakpoint_ops. */
13745 decode_linespec_default (struct breakpoint *b, char **s,
13746 struct symtabs_and_lines *sals)
13748 struct linespec_result canonical;
13750 init_linespec_result (&canonical);
13751 decode_line_full (s, DECODE_LINE_FUNFIRSTLINE,
13752 (struct symtab *) NULL, 0,
13753 &canonical, multiple_symbols_all,
13756 /* We should get 0 or 1 resulting SALs. */
13757 gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2);
13759 if (VEC_length (linespec_sals, canonical.sals) > 0)
13761 struct linespec_sals *lsal;
13763 lsal = VEC_index (linespec_sals, canonical.sals, 0);
13764 *sals = lsal->sals;
13765 /* Arrange it so the destructor does not free the
13767 lsal->sals.sals = NULL;
13770 destroy_linespec_result (&canonical);
13773 /* Prepare the global context for a re-set of breakpoint B. */
13775 static struct cleanup *
13776 prepare_re_set_context (struct breakpoint *b)
13778 struct cleanup *cleanups;
13780 input_radix = b->input_radix;
13781 cleanups = save_current_space_and_thread ();
13782 if (b->pspace != NULL)
13783 switch_to_program_space_and_thread (b->pspace);
13784 set_language (b->language);
13789 /* Reset a breakpoint given it's struct breakpoint * BINT.
13790 The value we return ends up being the return value from catch_errors.
13791 Unused in this case. */
13794 breakpoint_re_set_one (void *bint)
13796 /* Get past catch_errs. */
13797 struct breakpoint *b = (struct breakpoint *) bint;
13798 struct cleanup *cleanups;
13800 cleanups = prepare_re_set_context (b);
13801 b->ops->re_set (b);
13802 do_cleanups (cleanups);
13806 /* Re-set all breakpoints after symbols have been re-loaded. */
13808 breakpoint_re_set (void)
13810 struct breakpoint *b, *b_tmp;
13811 enum language save_language;
13812 int save_input_radix;
13813 struct cleanup *old_chain;
13815 save_language = current_language->la_language;
13816 save_input_radix = input_radix;
13817 old_chain = save_current_program_space ();
13819 ALL_BREAKPOINTS_SAFE (b, b_tmp)
13821 /* Format possible error msg. */
13822 char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
13824 struct cleanup *cleanups = make_cleanup (xfree, message);
13825 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
13826 do_cleanups (cleanups);
13828 set_language (save_language);
13829 input_radix = save_input_radix;
13831 jit_breakpoint_re_set ();
13833 do_cleanups (old_chain);
13835 create_overlay_event_breakpoint ();
13836 create_longjmp_master_breakpoint ();
13837 create_std_terminate_master_breakpoint ();
13838 create_exception_master_breakpoint ();
13840 /* While we're at it, reset the skip list too. */
13844 /* Reset the thread number of this breakpoint:
13846 - If the breakpoint is for all threads, leave it as-is.
13847 - Else, reset it to the current thread for inferior_ptid. */
13849 breakpoint_re_set_thread (struct breakpoint *b)
13851 if (b->thread != -1)
13853 if (in_thread_list (inferior_ptid))
13854 b->thread = pid_to_thread_id (inferior_ptid);
13856 /* We're being called after following a fork. The new fork is
13857 selected as current, and unless this was a vfork will have a
13858 different program space from the original thread. Reset that
13860 b->loc->pspace = current_program_space;
13864 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
13865 If from_tty is nonzero, it prints a message to that effect,
13866 which ends with a period (no newline). */
13869 set_ignore_count (int bptnum, int count, int from_tty)
13871 struct breakpoint *b;
13876 ALL_BREAKPOINTS (b)
13877 if (b->number == bptnum)
13879 if (is_tracepoint (b))
13881 if (from_tty && count != 0)
13882 printf_filtered (_("Ignore count ignored for tracepoint %d."),
13887 b->ignore_count = count;
13891 printf_filtered (_("Will stop next time "
13892 "breakpoint %d is reached."),
13894 else if (count == 1)
13895 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
13898 printf_filtered (_("Will ignore next %d "
13899 "crossings of breakpoint %d."),
13902 breakpoints_changed ();
13903 observer_notify_breakpoint_modified (b);
13907 error (_("No breakpoint number %d."), bptnum);
13910 /* Command to set ignore-count of breakpoint N to COUNT. */
13913 ignore_command (char *args, int from_tty)
13919 error_no_arg (_("a breakpoint number"));
13921 num = get_number (&p);
13923 error (_("bad breakpoint number: '%s'"), args);
13925 error (_("Second argument (specified ignore-count) is missing."));
13927 set_ignore_count (num,
13928 longest_to_int (value_as_long (parse_and_eval (p))),
13931 printf_filtered ("\n");
13934 /* Call FUNCTION on each of the breakpoints
13935 whose numbers are given in ARGS. */
13938 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *,
13943 struct breakpoint *b, *tmp;
13945 struct get_number_or_range_state state;
13948 error_no_arg (_("one or more breakpoint numbers"));
13950 init_number_or_range (&state, args);
13952 while (!state.finished)
13954 char *p = state.string;
13958 num = get_number_or_range (&state);
13961 warning (_("bad breakpoint number at or near '%s'"), p);
13965 ALL_BREAKPOINTS_SAFE (b, tmp)
13966 if (b->number == num)
13969 function (b, data);
13973 printf_unfiltered (_("No breakpoint number %d.\n"), num);
13978 static struct bp_location *
13979 find_location_by_number (char *number)
13981 char *dot = strchr (number, '.');
13985 struct breakpoint *b;
13986 struct bp_location *loc;
13991 bp_num = get_number (&p1);
13993 error (_("Bad breakpoint number '%s'"), number);
13995 ALL_BREAKPOINTS (b)
13996 if (b->number == bp_num)
14001 if (!b || b->number != bp_num)
14002 error (_("Bad breakpoint number '%s'"), number);
14005 loc_num = get_number (&p1);
14007 error (_("Bad breakpoint location number '%s'"), number);
14011 for (;loc_num && loc; --loc_num, loc = loc->next)
14014 error (_("Bad breakpoint location number '%s'"), dot+1);
14020 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14021 If from_tty is nonzero, it prints a message to that effect,
14022 which ends with a period (no newline). */
14025 disable_breakpoint (struct breakpoint *bpt)
14027 /* Never disable a watchpoint scope breakpoint; we want to
14028 hit them when we leave scope so we can delete both the
14029 watchpoint and its scope breakpoint at that time. */
14030 if (bpt->type == bp_watchpoint_scope)
14033 /* You can't disable permanent breakpoints. */
14034 if (bpt->enable_state == bp_permanent)
14037 bpt->enable_state = bp_disabled;
14039 /* Mark breakpoint locations modified. */
14040 mark_breakpoint_modified (bpt);
14042 if (target_supports_enable_disable_tracepoint ()
14043 && current_trace_status ()->running && is_tracepoint (bpt))
14045 struct bp_location *location;
14047 for (location = bpt->loc; location; location = location->next)
14048 target_disable_tracepoint (location);
14051 update_global_location_list (0);
14053 observer_notify_breakpoint_modified (bpt);
14056 /* A callback for iterate_over_related_breakpoints. */
14059 do_disable_breakpoint (struct breakpoint *b, void *ignore)
14061 disable_breakpoint (b);
14064 /* A callback for map_breakpoint_numbers that calls
14065 disable_breakpoint. */
14068 do_map_disable_breakpoint (struct breakpoint *b, void *ignore)
14070 iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL);
14074 disable_command (char *args, int from_tty)
14078 struct breakpoint *bpt;
14080 ALL_BREAKPOINTS (bpt)
14081 if (user_breakpoint_p (bpt))
14082 disable_breakpoint (bpt);
14084 else if (strchr (args, '.'))
14086 struct bp_location *loc = find_location_by_number (args);
14092 mark_breakpoint_location_modified (loc);
14094 if (target_supports_enable_disable_tracepoint ()
14095 && current_trace_status ()->running && loc->owner
14096 && is_tracepoint (loc->owner))
14097 target_disable_tracepoint (loc);
14099 update_global_location_list (0);
14102 map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL);
14106 enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition,
14109 int target_resources_ok;
14111 if (bpt->type == bp_hardware_breakpoint)
14114 i = hw_breakpoint_used_count ();
14115 target_resources_ok =
14116 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
14118 if (target_resources_ok == 0)
14119 error (_("No hardware breakpoint support in the target."));
14120 else if (target_resources_ok < 0)
14121 error (_("Hardware breakpoints used exceeds limit."));
14124 if (is_watchpoint (bpt))
14126 /* Initialize it just to avoid a GCC false warning. */
14127 enum enable_state orig_enable_state = 0;
14128 volatile struct gdb_exception e;
14130 TRY_CATCH (e, RETURN_MASK_ALL)
14132 struct watchpoint *w = (struct watchpoint *) bpt;
14134 orig_enable_state = bpt->enable_state;
14135 bpt->enable_state = bp_enabled;
14136 update_watchpoint (w, 1 /* reparse */);
14140 bpt->enable_state = orig_enable_state;
14141 exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
14147 if (bpt->enable_state != bp_permanent)
14148 bpt->enable_state = bp_enabled;
14150 bpt->enable_state = bp_enabled;
14152 /* Mark breakpoint locations modified. */
14153 mark_breakpoint_modified (bpt);
14155 if (target_supports_enable_disable_tracepoint ()
14156 && current_trace_status ()->running && is_tracepoint (bpt))
14158 struct bp_location *location;
14160 for (location = bpt->loc; location; location = location->next)
14161 target_enable_tracepoint (location);
14164 bpt->disposition = disposition;
14165 bpt->enable_count = count;
14166 update_global_location_list (1);
14167 breakpoints_changed ();
14169 observer_notify_breakpoint_modified (bpt);
14174 enable_breakpoint (struct breakpoint *bpt)
14176 enable_breakpoint_disp (bpt, bpt->disposition, 0);
14180 do_enable_breakpoint (struct breakpoint *bpt, void *arg)
14182 enable_breakpoint (bpt);
14185 /* A callback for map_breakpoint_numbers that calls
14186 enable_breakpoint. */
14189 do_map_enable_breakpoint (struct breakpoint *b, void *ignore)
14191 iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL);
14194 /* The enable command enables the specified breakpoints (or all defined
14195 breakpoints) so they once again become (or continue to be) effective
14196 in stopping the inferior. */
14199 enable_command (char *args, int from_tty)
14203 struct breakpoint *bpt;
14205 ALL_BREAKPOINTS (bpt)
14206 if (user_breakpoint_p (bpt))
14207 enable_breakpoint (bpt);
14209 else if (strchr (args, '.'))
14211 struct bp_location *loc = find_location_by_number (args);
14217 mark_breakpoint_location_modified (loc);
14219 if (target_supports_enable_disable_tracepoint ()
14220 && current_trace_status ()->running && loc->owner
14221 && is_tracepoint (loc->owner))
14222 target_enable_tracepoint (loc);
14224 update_global_location_list (1);
14227 map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL);
14230 /* This struct packages up disposition data for application to multiple
14240 do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg)
14242 struct disp_data disp_data = *(struct disp_data *) arg;
14244 enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count);
14248 do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore)
14250 struct disp_data disp = { disp_disable, 1 };
14252 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
14256 enable_once_command (char *args, int from_tty)
14258 map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL);
14262 do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr)
14264 struct disp_data disp = { disp_disable, *(int *) countptr };
14266 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
14270 enable_count_command (char *args, int from_tty)
14272 int count = get_number (&args);
14274 map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count);
14278 do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore)
14280 struct disp_data disp = { disp_del, 1 };
14282 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
14286 enable_delete_command (char *args, int from_tty)
14288 map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL);
14292 set_breakpoint_cmd (char *args, int from_tty)
14297 show_breakpoint_cmd (char *args, int from_tty)
14301 /* Invalidate last known value of any hardware watchpoint if
14302 the memory which that value represents has been written to by
14306 invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len,
14307 const bfd_byte *data)
14309 struct breakpoint *bp;
14311 ALL_BREAKPOINTS (bp)
14312 if (bp->enable_state == bp_enabled
14313 && bp->type == bp_hardware_watchpoint)
14315 struct watchpoint *wp = (struct watchpoint *) bp;
14317 if (wp->val_valid && wp->val)
14319 struct bp_location *loc;
14321 for (loc = bp->loc; loc != NULL; loc = loc->next)
14322 if (loc->loc_type == bp_loc_hardware_watchpoint
14323 && loc->address + loc->length > addr
14324 && addr + len > loc->address)
14326 value_free (wp->val);
14334 /* Use the last displayed codepoint's values, or nothing
14335 if they aren't valid. */
14337 struct symtabs_and_lines
14338 decode_line_spec_1 (char *string, int flags)
14340 struct symtabs_and_lines sals;
14343 error (_("Empty line specification."));
14344 if (last_displayed_sal_is_valid ())
14345 sals = decode_line_1 (&string, flags,
14346 get_last_displayed_symtab (),
14347 get_last_displayed_line ());
14349 sals = decode_line_1 (&string, flags, (struct symtab *) NULL, 0);
14351 error (_("Junk at end of line specification: %s"), string);
14355 /* Create and insert a raw software breakpoint at PC. Return an
14356 identifier, which should be used to remove the breakpoint later.
14357 In general, places which call this should be using something on the
14358 breakpoint chain instead; this function should be eliminated
14362 deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch,
14363 struct address_space *aspace, CORE_ADDR pc)
14365 struct bp_target_info *bp_tgt;
14367 bp_tgt = XZALLOC (struct bp_target_info);
14369 bp_tgt->placed_address_space = aspace;
14370 bp_tgt->placed_address = pc;
14372 if (target_insert_breakpoint (gdbarch, bp_tgt) != 0)
14374 /* Could not insert the breakpoint. */
14382 /* Remove a breakpoint BP inserted by
14383 deprecated_insert_raw_breakpoint. */
14386 deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp)
14388 struct bp_target_info *bp_tgt = bp;
14391 ret = target_remove_breakpoint (gdbarch, bp_tgt);
14397 /* One (or perhaps two) breakpoints used for software single
14400 static void *single_step_breakpoints[2];
14401 static struct gdbarch *single_step_gdbarch[2];
14403 /* Create and insert a breakpoint for software single step. */
14406 insert_single_step_breakpoint (struct gdbarch *gdbarch,
14407 struct address_space *aspace,
14412 if (single_step_breakpoints[0] == NULL)
14414 bpt_p = &single_step_breakpoints[0];
14415 single_step_gdbarch[0] = gdbarch;
14419 gdb_assert (single_step_breakpoints[1] == NULL);
14420 bpt_p = &single_step_breakpoints[1];
14421 single_step_gdbarch[1] = gdbarch;
14424 /* NOTE drow/2006-04-11: A future improvement to this function would
14425 be to only create the breakpoints once, and actually put them on
14426 the breakpoint chain. That would let us use set_raw_breakpoint.
14427 We could adjust the addresses each time they were needed. Doing
14428 this requires corresponding changes elsewhere where single step
14429 breakpoints are handled, however. So, for now, we use this. */
14431 *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc);
14432 if (*bpt_p == NULL)
14433 error (_("Could not insert single-step breakpoint at %s"),
14434 paddress (gdbarch, next_pc));
14437 /* Check if the breakpoints used for software single stepping
14438 were inserted or not. */
14441 single_step_breakpoints_inserted (void)
14443 return (single_step_breakpoints[0] != NULL
14444 || single_step_breakpoints[1] != NULL);
14447 /* Remove and delete any breakpoints used for software single step. */
14450 remove_single_step_breakpoints (void)
14452 gdb_assert (single_step_breakpoints[0] != NULL);
14454 /* See insert_single_step_breakpoint for more about this deprecated
14456 deprecated_remove_raw_breakpoint (single_step_gdbarch[0],
14457 single_step_breakpoints[0]);
14458 single_step_gdbarch[0] = NULL;
14459 single_step_breakpoints[0] = NULL;
14461 if (single_step_breakpoints[1] != NULL)
14463 deprecated_remove_raw_breakpoint (single_step_gdbarch[1],
14464 single_step_breakpoints[1]);
14465 single_step_gdbarch[1] = NULL;
14466 single_step_breakpoints[1] = NULL;
14470 /* Delete software single step breakpoints without removing them from
14471 the inferior. This is intended to be used if the inferior's address
14472 space where they were inserted is already gone, e.g. after exit or
14476 cancel_single_step_breakpoints (void)
14480 for (i = 0; i < 2; i++)
14481 if (single_step_breakpoints[i])
14483 xfree (single_step_breakpoints[i]);
14484 single_step_breakpoints[i] = NULL;
14485 single_step_gdbarch[i] = NULL;
14489 /* Detach software single-step breakpoints from INFERIOR_PTID without
14493 detach_single_step_breakpoints (void)
14497 for (i = 0; i < 2; i++)
14498 if (single_step_breakpoints[i])
14499 target_remove_breakpoint (single_step_gdbarch[i],
14500 single_step_breakpoints[i]);
14503 /* Check whether a software single-step breakpoint is inserted at
14507 single_step_breakpoint_inserted_here_p (struct address_space *aspace,
14512 for (i = 0; i < 2; i++)
14514 struct bp_target_info *bp_tgt = single_step_breakpoints[i];
14516 && breakpoint_address_match (bp_tgt->placed_address_space,
14517 bp_tgt->placed_address,
14525 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
14526 non-zero otherwise. */
14528 is_syscall_catchpoint_enabled (struct breakpoint *bp)
14530 if (syscall_catchpoint_p (bp)
14531 && bp->enable_state != bp_disabled
14532 && bp->enable_state != bp_call_disabled)
14539 catch_syscall_enabled (void)
14541 struct catch_syscall_inferior_data *inf_data
14542 = get_catch_syscall_inferior_data (current_inferior ());
14544 return inf_data->total_syscalls_count != 0;
14548 catching_syscall_number (int syscall_number)
14550 struct breakpoint *bp;
14552 ALL_BREAKPOINTS (bp)
14553 if (is_syscall_catchpoint_enabled (bp))
14555 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp;
14557 if (c->syscalls_to_be_caught)
14561 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
14563 if (syscall_number == iter)
14573 /* Complete syscall names. Used by "catch syscall". */
14575 catch_syscall_completer (struct cmd_list_element *cmd,
14576 char *text, char *word)
14578 const char **list = get_syscall_names ();
14580 = (list == NULL) ? NULL : complete_on_enum (list, text, word);
14586 /* Tracepoint-specific operations. */
14588 /* Set tracepoint count to NUM. */
14590 set_tracepoint_count (int num)
14592 tracepoint_count = num;
14593 set_internalvar_integer (lookup_internalvar ("tpnum"), num);
14597 trace_command (char *arg, int from_tty)
14599 struct breakpoint_ops *ops;
14600 const char *arg_cp = arg;
14602 if (arg && probe_linespec_to_ops (&arg_cp))
14603 ops = &tracepoint_probe_breakpoint_ops;
14605 ops = &tracepoint_breakpoint_ops;
14607 if (create_breakpoint (get_current_arch (),
14609 NULL, 0, NULL, 1 /* parse arg */,
14611 bp_tracepoint /* type_wanted */,
14612 0 /* Ignore count */,
14613 pending_break_support,
14617 0 /* internal */, 0))
14618 set_tracepoint_count (breakpoint_count);
14622 ftrace_command (char *arg, int from_tty)
14624 if (create_breakpoint (get_current_arch (),
14626 NULL, 0, NULL, 1 /* parse arg */,
14628 bp_fast_tracepoint /* type_wanted */,
14629 0 /* Ignore count */,
14630 pending_break_support,
14631 &tracepoint_breakpoint_ops,
14634 0 /* internal */, 0))
14635 set_tracepoint_count (breakpoint_count);
14638 /* strace command implementation. Creates a static tracepoint. */
14641 strace_command (char *arg, int from_tty)
14643 struct breakpoint_ops *ops;
14645 /* Decide if we are dealing with a static tracepoint marker (`-m'),
14646 or with a normal static tracepoint. */
14647 if (arg && strncmp (arg, "-m", 2) == 0 && isspace (arg[2]))
14648 ops = &strace_marker_breakpoint_ops;
14650 ops = &tracepoint_breakpoint_ops;
14652 if (create_breakpoint (get_current_arch (),
14654 NULL, 0, NULL, 1 /* parse arg */,
14656 bp_static_tracepoint /* type_wanted */,
14657 0 /* Ignore count */,
14658 pending_break_support,
14662 0 /* internal */, 0))
14663 set_tracepoint_count (breakpoint_count);
14666 /* Set up a fake reader function that gets command lines from a linked
14667 list that was acquired during tracepoint uploading. */
14669 static struct uploaded_tp *this_utp;
14670 static int next_cmd;
14673 read_uploaded_action (void)
14677 VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt);
14684 /* Given information about a tracepoint as recorded on a target (which
14685 can be either a live system or a trace file), attempt to create an
14686 equivalent GDB tracepoint. This is not a reliable process, since
14687 the target does not necessarily have all the information used when
14688 the tracepoint was originally defined. */
14690 struct tracepoint *
14691 create_tracepoint_from_upload (struct uploaded_tp *utp)
14693 char *addr_str, small_buf[100];
14694 struct tracepoint *tp;
14696 if (utp->at_string)
14697 addr_str = utp->at_string;
14700 /* In the absence of a source location, fall back to raw
14701 address. Since there is no way to confirm that the address
14702 means the same thing as when the trace was started, warn the
14704 warning (_("Uploaded tracepoint %d has no "
14705 "source location, using raw address"),
14707 sprintf (small_buf, "*%s", hex_string (utp->addr));
14708 addr_str = small_buf;
14711 /* There's not much we can do with a sequence of bytecodes. */
14712 if (utp->cond && !utp->cond_string)
14713 warning (_("Uploaded tracepoint %d condition "
14714 "has no source form, ignoring it"),
14717 if (!create_breakpoint (get_current_arch (),
14719 utp->cond_string, -1, NULL,
14720 0 /* parse cond/thread */,
14722 utp->type /* type_wanted */,
14723 0 /* Ignore count */,
14724 pending_break_support,
14725 &tracepoint_breakpoint_ops,
14727 utp->enabled /* enabled */,
14729 CREATE_BREAKPOINT_FLAGS_INSERTED))
14732 set_tracepoint_count (breakpoint_count);
14734 /* Get the tracepoint we just created. */
14735 tp = get_tracepoint (tracepoint_count);
14736 gdb_assert (tp != NULL);
14740 sprintf (small_buf, "%d %d", utp->pass, tp->base.number);
14742 trace_pass_command (small_buf, 0);
14745 /* If we have uploaded versions of the original commands, set up a
14746 special-purpose "reader" function and call the usual command line
14747 reader, then pass the result to the breakpoint command-setting
14749 if (!VEC_empty (char_ptr, utp->cmd_strings))
14751 struct command_line *cmd_list;
14756 cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL);
14758 breakpoint_set_commands (&tp->base, cmd_list);
14760 else if (!VEC_empty (char_ptr, utp->actions)
14761 || !VEC_empty (char_ptr, utp->step_actions))
14762 warning (_("Uploaded tracepoint %d actions "
14763 "have no source form, ignoring them"),
14766 /* Copy any status information that might be available. */
14767 tp->base.hit_count = utp->hit_count;
14768 tp->traceframe_usage = utp->traceframe_usage;
14773 /* Print information on tracepoint number TPNUM_EXP, or all if
14777 tracepoints_info (char *args, int from_tty)
14779 struct ui_out *uiout = current_uiout;
14782 num_printed = breakpoint_1 (args, 0, is_tracepoint);
14784 if (num_printed == 0)
14786 if (args == NULL || *args == '\0')
14787 ui_out_message (uiout, 0, "No tracepoints.\n");
14789 ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args);
14792 default_collect_info ();
14795 /* The 'enable trace' command enables tracepoints.
14796 Not supported by all targets. */
14798 enable_trace_command (char *args, int from_tty)
14800 enable_command (args, from_tty);
14803 /* The 'disable trace' command disables tracepoints.
14804 Not supported by all targets. */
14806 disable_trace_command (char *args, int from_tty)
14808 disable_command (args, from_tty);
14811 /* Remove a tracepoint (or all if no argument). */
14813 delete_trace_command (char *arg, int from_tty)
14815 struct breakpoint *b, *b_tmp;
14821 int breaks_to_delete = 0;
14823 /* Delete all breakpoints if no argument.
14824 Do not delete internal or call-dummy breakpoints, these
14825 have to be deleted with an explicit breakpoint number
14827 ALL_TRACEPOINTS (b)
14828 if (is_tracepoint (b) && user_breakpoint_p (b))
14830 breaks_to_delete = 1;
14834 /* Ask user only if there are some breakpoints to delete. */
14836 || (breaks_to_delete && query (_("Delete all tracepoints? "))))
14838 ALL_BREAKPOINTS_SAFE (b, b_tmp)
14839 if (is_tracepoint (b) && user_breakpoint_p (b))
14840 delete_breakpoint (b);
14844 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
14847 /* Helper function for trace_pass_command. */
14850 trace_pass_set_count (struct tracepoint *tp, int count, int from_tty)
14852 tp->pass_count = count;
14853 observer_notify_tracepoint_modified (tp->base.number);
14855 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
14856 tp->base.number, count);
14859 /* Set passcount for tracepoint.
14861 First command argument is passcount, second is tracepoint number.
14862 If tracepoint number omitted, apply to most recently defined.
14863 Also accepts special argument "all". */
14866 trace_pass_command (char *args, int from_tty)
14868 struct tracepoint *t1;
14869 unsigned int count;
14871 if (args == 0 || *args == 0)
14872 error (_("passcount command requires an "
14873 "argument (count + optional TP num)"));
14875 count = strtoul (args, &args, 10); /* Count comes first, then TP num. */
14877 while (*args && isspace ((int) *args))
14880 if (*args && strncasecmp (args, "all", 3) == 0)
14882 struct breakpoint *b;
14884 args += 3; /* Skip special argument "all". */
14886 error (_("Junk at end of arguments."));
14888 ALL_TRACEPOINTS (b)
14890 t1 = (struct tracepoint *) b;
14891 trace_pass_set_count (t1, count, from_tty);
14894 else if (*args == '\0')
14896 t1 = get_tracepoint_by_number (&args, NULL, 1);
14898 trace_pass_set_count (t1, count, from_tty);
14902 struct get_number_or_range_state state;
14904 init_number_or_range (&state, args);
14905 while (!state.finished)
14907 t1 = get_tracepoint_by_number (&args, &state, 1);
14909 trace_pass_set_count (t1, count, from_tty);
14914 struct tracepoint *
14915 get_tracepoint (int num)
14917 struct breakpoint *t;
14919 ALL_TRACEPOINTS (t)
14920 if (t->number == num)
14921 return (struct tracepoint *) t;
14926 /* Find the tracepoint with the given target-side number (which may be
14927 different from the tracepoint number after disconnecting and
14930 struct tracepoint *
14931 get_tracepoint_by_number_on_target (int num)
14933 struct breakpoint *b;
14935 ALL_TRACEPOINTS (b)
14937 struct tracepoint *t = (struct tracepoint *) b;
14939 if (t->number_on_target == num)
14946 /* Utility: parse a tracepoint number and look it up in the list.
14947 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
14948 If OPTIONAL_P is true, then if the argument is missing, the most
14949 recent tracepoint (tracepoint_count) is returned. */
14950 struct tracepoint *
14951 get_tracepoint_by_number (char **arg,
14952 struct get_number_or_range_state *state,
14955 extern int tracepoint_count;
14956 struct breakpoint *t;
14958 char *instring = arg == NULL ? NULL : *arg;
14962 gdb_assert (!state->finished);
14963 tpnum = get_number_or_range (state);
14965 else if (arg == NULL || *arg == NULL || ! **arg)
14968 tpnum = tracepoint_count;
14970 error_no_arg (_("tracepoint number"));
14973 tpnum = get_number (arg);
14977 if (instring && *instring)
14978 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
14981 printf_filtered (_("Tracepoint argument missing "
14982 "and no previous tracepoint\n"));
14986 ALL_TRACEPOINTS (t)
14987 if (t->number == tpnum)
14989 return (struct tracepoint *) t;
14992 printf_unfiltered ("No tracepoint number %d.\n", tpnum);
14997 print_recreate_thread (struct breakpoint *b, struct ui_file *fp)
14999 if (b->thread != -1)
15000 fprintf_unfiltered (fp, " thread %d", b->thread);
15003 fprintf_unfiltered (fp, " task %d", b->task);
15005 fprintf_unfiltered (fp, "\n");
15008 /* Save information on user settable breakpoints (watchpoints, etc) to
15009 a new script file named FILENAME. If FILTER is non-NULL, call it
15010 on each breakpoint and only include the ones for which it returns
15014 save_breakpoints (char *filename, int from_tty,
15015 int (*filter) (const struct breakpoint *))
15017 struct breakpoint *tp;
15020 struct cleanup *cleanup;
15021 struct ui_file *fp;
15022 int extra_trace_bits = 0;
15024 if (filename == 0 || *filename == 0)
15025 error (_("Argument required (file name in which to save)"));
15027 /* See if we have anything to save. */
15028 ALL_BREAKPOINTS (tp)
15030 /* Skip internal and momentary breakpoints. */
15031 if (!user_breakpoint_p (tp))
15034 /* If we have a filter, only save the breakpoints it accepts. */
15035 if (filter && !filter (tp))
15040 if (is_tracepoint (tp))
15042 extra_trace_bits = 1;
15044 /* We can stop searching. */
15051 warning (_("Nothing to save."));
15055 pathname = tilde_expand (filename);
15056 cleanup = make_cleanup (xfree, pathname);
15057 fp = gdb_fopen (pathname, "w");
15059 error (_("Unable to open file '%s' for saving (%s)"),
15060 filename, safe_strerror (errno));
15061 make_cleanup_ui_file_delete (fp);
15063 if (extra_trace_bits)
15064 save_trace_state_variables (fp);
15066 ALL_BREAKPOINTS (tp)
15068 /* Skip internal and momentary breakpoints. */
15069 if (!user_breakpoint_p (tp))
15072 /* If we have a filter, only save the breakpoints it accepts. */
15073 if (filter && !filter (tp))
15076 tp->ops->print_recreate (tp, fp);
15078 /* Note, we can't rely on tp->number for anything, as we can't
15079 assume the recreated breakpoint numbers will match. Use $bpnum
15082 if (tp->cond_string)
15083 fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string);
15085 if (tp->ignore_count)
15086 fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count);
15090 volatile struct gdb_exception ex;
15092 fprintf_unfiltered (fp, " commands\n");
15094 ui_out_redirect (current_uiout, fp);
15095 TRY_CATCH (ex, RETURN_MASK_ALL)
15097 print_command_lines (current_uiout, tp->commands->commands, 2);
15099 ui_out_redirect (current_uiout, NULL);
15102 throw_exception (ex);
15104 fprintf_unfiltered (fp, " end\n");
15107 if (tp->enable_state == bp_disabled)
15108 fprintf_unfiltered (fp, "disable\n");
15110 /* If this is a multi-location breakpoint, check if the locations
15111 should be individually disabled. Watchpoint locations are
15112 special, and not user visible. */
15113 if (!is_watchpoint (tp) && tp->loc && tp->loc->next)
15115 struct bp_location *loc;
15118 for (loc = tp->loc; loc != NULL; loc = loc->next, n++)
15120 fprintf_unfiltered (fp, "disable $bpnum.%d\n", n);
15124 if (extra_trace_bits && *default_collect)
15125 fprintf_unfiltered (fp, "set default-collect %s\n", default_collect);
15127 do_cleanups (cleanup);
15129 printf_filtered (_("Saved to file '%s'.\n"), filename);
15132 /* The `save breakpoints' command. */
15135 save_breakpoints_command (char *args, int from_tty)
15137 save_breakpoints (args, from_tty, NULL);
15140 /* The `save tracepoints' command. */
15143 save_tracepoints_command (char *args, int from_tty)
15145 save_breakpoints (args, from_tty, is_tracepoint);
15148 /* Create a vector of all tracepoints. */
15150 VEC(breakpoint_p) *
15151 all_tracepoints (void)
15153 VEC(breakpoint_p) *tp_vec = 0;
15154 struct breakpoint *tp;
15156 ALL_TRACEPOINTS (tp)
15158 VEC_safe_push (breakpoint_p, tp_vec, tp);
15165 /* This help string is used for the break, hbreak, tbreak and thbreak
15166 commands. It is defined as a macro to prevent duplication.
15167 COMMAND should be a string constant containing the name of the
15169 #define BREAK_ARGS_HELP(command) \
15170 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15171 LOCATION may be a line number, function name, or \"*\" and an address.\n\
15172 If a line number is specified, break at start of code for that line.\n\
15173 If a function is specified, break at start of code for that function.\n\
15174 If an address is specified, break at that exact address.\n\
15175 With no LOCATION, uses current execution address of the selected\n\
15176 stack frame. This is useful for breaking on return to a stack frame.\n\
15178 THREADNUM is the number from \"info threads\".\n\
15179 CONDITION is a boolean expression.\n\
15181 Multiple breakpoints at one place are permitted, and useful if their\n\
15182 conditions are different.\n\
15184 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15186 /* List of subcommands for "catch". */
15187 static struct cmd_list_element *catch_cmdlist;
15189 /* List of subcommands for "tcatch". */
15190 static struct cmd_list_element *tcatch_cmdlist;
15193 add_catch_command (char *name, char *docstring,
15194 void (*sfunc) (char *args, int from_tty,
15195 struct cmd_list_element *command),
15196 char **(*completer) (struct cmd_list_element *cmd,
15197 char *text, char *word),
15198 void *user_data_catch,
15199 void *user_data_tcatch)
15201 struct cmd_list_element *command;
15203 command = add_cmd (name, class_breakpoint, NULL, docstring,
15205 set_cmd_sfunc (command, sfunc);
15206 set_cmd_context (command, user_data_catch);
15207 set_cmd_completer (command, completer);
15209 command = add_cmd (name, class_breakpoint, NULL, docstring,
15211 set_cmd_sfunc (command, sfunc);
15212 set_cmd_context (command, user_data_tcatch);
15213 set_cmd_completer (command, completer);
15217 clear_syscall_counts (struct inferior *inf)
15219 struct catch_syscall_inferior_data *inf_data
15220 = get_catch_syscall_inferior_data (inf);
15222 inf_data->total_syscalls_count = 0;
15223 inf_data->any_syscall_count = 0;
15224 VEC_free (int, inf_data->syscalls_counts);
15228 save_command (char *arg, int from_tty)
15230 printf_unfiltered (_("\"save\" must be followed by "
15231 "the name of a save subcommand.\n"));
15232 help_list (save_cmdlist, "save ", -1, gdb_stdout);
15235 struct breakpoint *
15236 iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *),
15239 struct breakpoint *b, *b_tmp;
15241 ALL_BREAKPOINTS_SAFE (b, b_tmp)
15243 if ((*callback) (b, data))
15250 /* Zero if any of the breakpoint's locations could be a location where
15251 functions have been inlined, nonzero otherwise. */
15254 is_non_inline_function (struct breakpoint *b)
15256 /* The shared library event breakpoint is set on the address of a
15257 non-inline function. */
15258 if (b->type == bp_shlib_event)
15264 /* Nonzero if the specified PC cannot be a location where functions
15265 have been inlined. */
15268 pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc,
15269 const struct target_waitstatus *ws)
15271 struct breakpoint *b;
15272 struct bp_location *bl;
15274 ALL_BREAKPOINTS (b)
15276 if (!is_non_inline_function (b))
15279 for (bl = b->loc; bl != NULL; bl = bl->next)
15281 if (!bl->shlib_disabled
15282 && bpstat_check_location (bl, aspace, pc, ws))
15291 initialize_breakpoint_ops (void)
15293 static int initialized = 0;
15295 struct breakpoint_ops *ops;
15301 /* The breakpoint_ops structure to be inherit by all kinds of
15302 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15303 internal and momentary breakpoints, etc.). */
15304 ops = &bkpt_base_breakpoint_ops;
15305 *ops = base_breakpoint_ops;
15306 ops->re_set = bkpt_re_set;
15307 ops->insert_location = bkpt_insert_location;
15308 ops->remove_location = bkpt_remove_location;
15309 ops->breakpoint_hit = bkpt_breakpoint_hit;
15310 ops->create_sals_from_address = bkpt_create_sals_from_address;
15311 ops->create_breakpoints_sal = bkpt_create_breakpoints_sal;
15312 ops->decode_linespec = bkpt_decode_linespec;
15314 /* The breakpoint_ops structure to be used in regular breakpoints. */
15315 ops = &bkpt_breakpoint_ops;
15316 *ops = bkpt_base_breakpoint_ops;
15317 ops->re_set = bkpt_re_set;
15318 ops->resources_needed = bkpt_resources_needed;
15319 ops->print_it = bkpt_print_it;
15320 ops->print_mention = bkpt_print_mention;
15321 ops->print_recreate = bkpt_print_recreate;
15323 /* Ranged breakpoints. */
15324 ops = &ranged_breakpoint_ops;
15325 *ops = bkpt_breakpoint_ops;
15326 ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint;
15327 ops->resources_needed = resources_needed_ranged_breakpoint;
15328 ops->print_it = print_it_ranged_breakpoint;
15329 ops->print_one = print_one_ranged_breakpoint;
15330 ops->print_one_detail = print_one_detail_ranged_breakpoint;
15331 ops->print_mention = print_mention_ranged_breakpoint;
15332 ops->print_recreate = print_recreate_ranged_breakpoint;
15334 /* Internal breakpoints. */
15335 ops = &internal_breakpoint_ops;
15336 *ops = bkpt_base_breakpoint_ops;
15337 ops->re_set = internal_bkpt_re_set;
15338 ops->check_status = internal_bkpt_check_status;
15339 ops->print_it = internal_bkpt_print_it;
15340 ops->print_mention = internal_bkpt_print_mention;
15342 /* Momentary breakpoints. */
15343 ops = &momentary_breakpoint_ops;
15344 *ops = bkpt_base_breakpoint_ops;
15345 ops->re_set = momentary_bkpt_re_set;
15346 ops->check_status = momentary_bkpt_check_status;
15347 ops->print_it = momentary_bkpt_print_it;
15348 ops->print_mention = momentary_bkpt_print_mention;
15350 /* Probe breakpoints. */
15351 ops = &bkpt_probe_breakpoint_ops;
15352 *ops = bkpt_breakpoint_ops;
15353 ops->insert_location = bkpt_probe_insert_location;
15354 ops->remove_location = bkpt_probe_remove_location;
15355 ops->create_sals_from_address = bkpt_probe_create_sals_from_address;
15356 ops->decode_linespec = bkpt_probe_decode_linespec;
15358 /* GNU v3 exception catchpoints. */
15359 ops = &gnu_v3_exception_catchpoint_ops;
15360 *ops = bkpt_breakpoint_ops;
15361 ops->print_it = print_it_exception_catchpoint;
15362 ops->print_one = print_one_exception_catchpoint;
15363 ops->print_mention = print_mention_exception_catchpoint;
15364 ops->print_recreate = print_recreate_exception_catchpoint;
15367 ops = &watchpoint_breakpoint_ops;
15368 *ops = base_breakpoint_ops;
15369 ops->dtor = dtor_watchpoint;
15370 ops->re_set = re_set_watchpoint;
15371 ops->insert_location = insert_watchpoint;
15372 ops->remove_location = remove_watchpoint;
15373 ops->breakpoint_hit = breakpoint_hit_watchpoint;
15374 ops->check_status = check_status_watchpoint;
15375 ops->resources_needed = resources_needed_watchpoint;
15376 ops->works_in_software_mode = works_in_software_mode_watchpoint;
15377 ops->print_it = print_it_watchpoint;
15378 ops->print_mention = print_mention_watchpoint;
15379 ops->print_recreate = print_recreate_watchpoint;
15381 /* Masked watchpoints. */
15382 ops = &masked_watchpoint_breakpoint_ops;
15383 *ops = watchpoint_breakpoint_ops;
15384 ops->insert_location = insert_masked_watchpoint;
15385 ops->remove_location = remove_masked_watchpoint;
15386 ops->resources_needed = resources_needed_masked_watchpoint;
15387 ops->works_in_software_mode = works_in_software_mode_masked_watchpoint;
15388 ops->print_it = print_it_masked_watchpoint;
15389 ops->print_one_detail = print_one_detail_masked_watchpoint;
15390 ops->print_mention = print_mention_masked_watchpoint;
15391 ops->print_recreate = print_recreate_masked_watchpoint;
15394 ops = &tracepoint_breakpoint_ops;
15395 *ops = base_breakpoint_ops;
15396 ops->re_set = tracepoint_re_set;
15397 ops->breakpoint_hit = tracepoint_breakpoint_hit;
15398 ops->print_one_detail = tracepoint_print_one_detail;
15399 ops->print_mention = tracepoint_print_mention;
15400 ops->print_recreate = tracepoint_print_recreate;
15401 ops->create_sals_from_address = tracepoint_create_sals_from_address;
15402 ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal;
15403 ops->decode_linespec = tracepoint_decode_linespec;
15405 /* Probe tracepoints. */
15406 ops = &tracepoint_probe_breakpoint_ops;
15407 *ops = tracepoint_breakpoint_ops;
15408 ops->create_sals_from_address = tracepoint_probe_create_sals_from_address;
15409 ops->decode_linespec = tracepoint_probe_decode_linespec;
15411 /* Static tracepoints with marker (`-m'). */
15412 ops = &strace_marker_breakpoint_ops;
15413 *ops = tracepoint_breakpoint_ops;
15414 ops->create_sals_from_address = strace_marker_create_sals_from_address;
15415 ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal;
15416 ops->decode_linespec = strace_marker_decode_linespec;
15418 /* Fork catchpoints. */
15419 ops = &catch_fork_breakpoint_ops;
15420 *ops = base_breakpoint_ops;
15421 ops->insert_location = insert_catch_fork;
15422 ops->remove_location = remove_catch_fork;
15423 ops->breakpoint_hit = breakpoint_hit_catch_fork;
15424 ops->print_it = print_it_catch_fork;
15425 ops->print_one = print_one_catch_fork;
15426 ops->print_mention = print_mention_catch_fork;
15427 ops->print_recreate = print_recreate_catch_fork;
15429 /* Vfork catchpoints. */
15430 ops = &catch_vfork_breakpoint_ops;
15431 *ops = base_breakpoint_ops;
15432 ops->insert_location = insert_catch_vfork;
15433 ops->remove_location = remove_catch_vfork;
15434 ops->breakpoint_hit = breakpoint_hit_catch_vfork;
15435 ops->print_it = print_it_catch_vfork;
15436 ops->print_one = print_one_catch_vfork;
15437 ops->print_mention = print_mention_catch_vfork;
15438 ops->print_recreate = print_recreate_catch_vfork;
15440 /* Exec catchpoints. */
15441 ops = &catch_exec_breakpoint_ops;
15442 *ops = base_breakpoint_ops;
15443 ops->dtor = dtor_catch_exec;
15444 ops->insert_location = insert_catch_exec;
15445 ops->remove_location = remove_catch_exec;
15446 ops->breakpoint_hit = breakpoint_hit_catch_exec;
15447 ops->print_it = print_it_catch_exec;
15448 ops->print_one = print_one_catch_exec;
15449 ops->print_mention = print_mention_catch_exec;
15450 ops->print_recreate = print_recreate_catch_exec;
15452 /* Syscall catchpoints. */
15453 ops = &catch_syscall_breakpoint_ops;
15454 *ops = base_breakpoint_ops;
15455 ops->dtor = dtor_catch_syscall;
15456 ops->insert_location = insert_catch_syscall;
15457 ops->remove_location = remove_catch_syscall;
15458 ops->breakpoint_hit = breakpoint_hit_catch_syscall;
15459 ops->print_it = print_it_catch_syscall;
15460 ops->print_one = print_one_catch_syscall;
15461 ops->print_mention = print_mention_catch_syscall;
15462 ops->print_recreate = print_recreate_catch_syscall;
15464 /* Solib-related catchpoints. */
15465 ops = &catch_solib_breakpoint_ops;
15466 *ops = base_breakpoint_ops;
15467 ops->dtor = dtor_catch_solib;
15468 ops->insert_location = insert_catch_solib;
15469 ops->remove_location = remove_catch_solib;
15470 ops->breakpoint_hit = breakpoint_hit_catch_solib;
15471 ops->check_status = check_status_catch_solib;
15472 ops->print_it = print_it_catch_solib;
15473 ops->print_one = print_one_catch_solib;
15474 ops->print_mention = print_mention_catch_solib;
15475 ops->print_recreate = print_recreate_catch_solib;
15477 ops = &dprintf_breakpoint_ops;
15478 *ops = bkpt_base_breakpoint_ops;
15479 ops->re_set = bkpt_re_set;
15480 ops->resources_needed = bkpt_resources_needed;
15481 ops->print_it = bkpt_print_it;
15482 ops->print_mention = bkpt_print_mention;
15483 ops->print_recreate = bkpt_print_recreate;
15487 _initialize_breakpoint (void)
15489 struct cmd_list_element *c;
15491 initialize_breakpoint_ops ();
15493 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
15494 observer_attach_inferior_exit (clear_syscall_counts);
15495 observer_attach_memory_changed (invalidate_bp_value_on_memory_change);
15497 breakpoint_objfile_key
15498 = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes);
15500 catch_syscall_inferior_data
15501 = register_inferior_data_with_cleanup (catch_syscall_inferior_data_cleanup);
15503 breakpoint_chain = 0;
15504 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
15505 before a breakpoint is set. */
15506 breakpoint_count = 0;
15508 tracepoint_count = 0;
15510 add_com ("ignore", class_breakpoint, ignore_command, _("\
15511 Set ignore-count of breakpoint number N to COUNT.\n\
15512 Usage is `ignore N COUNT'."));
15514 add_com_alias ("bc", "ignore", class_breakpoint, 1);
15516 add_com ("commands", class_breakpoint, commands_command, _("\
15517 Set commands to be executed when a breakpoint is hit.\n\
15518 Give breakpoint number as argument after \"commands\".\n\
15519 With no argument, the targeted breakpoint is the last one set.\n\
15520 The commands themselves follow starting on the next line.\n\
15521 Type a line containing \"end\" to indicate the end of them.\n\
15522 Give \"silent\" as the first line to make the breakpoint silent;\n\
15523 then no output is printed when it is hit, except what the commands print."));
15525 add_com ("condition", class_breakpoint, condition_command, _("\
15526 Specify breakpoint number N to break only if COND is true.\n\
15527 Usage is `condition N COND', where N is an integer and COND is an\n\
15528 expression to be evaluated whenever breakpoint N is reached."));
15530 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
15531 Set a temporary breakpoint.\n\
15532 Like \"break\" except the breakpoint is only temporary,\n\
15533 so it will be deleted when hit. Equivalent to \"break\" followed\n\
15534 by using \"enable delete\" on the breakpoint number.\n\
15536 BREAK_ARGS_HELP ("tbreak")));
15537 set_cmd_completer (c, location_completer);
15539 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
15540 Set a hardware assisted breakpoint.\n\
15541 Like \"break\" except the breakpoint requires hardware support,\n\
15542 some target hardware may not have this support.\n\
15544 BREAK_ARGS_HELP ("hbreak")));
15545 set_cmd_completer (c, location_completer);
15547 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
15548 Set a temporary hardware assisted breakpoint.\n\
15549 Like \"hbreak\" except the breakpoint is only temporary,\n\
15550 so it will be deleted when hit.\n\
15552 BREAK_ARGS_HELP ("thbreak")));
15553 set_cmd_completer (c, location_completer);
15555 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
15556 Enable some breakpoints.\n\
15557 Give breakpoint numbers (separated by spaces) as arguments.\n\
15558 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15559 This is used to cancel the effect of the \"disable\" command.\n\
15560 With a subcommand you can enable temporarily."),
15561 &enablelist, "enable ", 1, &cmdlist);
15563 add_com ("ab", class_breakpoint, enable_command, _("\
15564 Enable some breakpoints.\n\
15565 Give breakpoint numbers (separated by spaces) as arguments.\n\
15566 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15567 This is used to cancel the effect of the \"disable\" command.\n\
15568 With a subcommand you can enable temporarily."));
15570 add_com_alias ("en", "enable", class_breakpoint, 1);
15572 add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
15573 Enable some breakpoints.\n\
15574 Give breakpoint numbers (separated by spaces) as arguments.\n\
15575 This is used to cancel the effect of the \"disable\" command.\n\
15576 May be abbreviated to simply \"enable\".\n"),
15577 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
15579 add_cmd ("once", no_class, enable_once_command, _("\
15580 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15581 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15584 add_cmd ("delete", no_class, enable_delete_command, _("\
15585 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15586 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15589 add_cmd ("count", no_class, enable_count_command, _("\
15590 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15591 If a breakpoint is hit while enabled in this fashion,\n\
15592 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15595 add_cmd ("delete", no_class, enable_delete_command, _("\
15596 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15597 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15600 add_cmd ("once", no_class, enable_once_command, _("\
15601 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15602 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15605 add_cmd ("count", no_class, enable_count_command, _("\
15606 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15607 If a breakpoint is hit while enabled in this fashion,\n\
15608 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15611 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
15612 Disable some breakpoints.\n\
15613 Arguments are breakpoint numbers with spaces in between.\n\
15614 To disable all breakpoints, give no argument.\n\
15615 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
15616 &disablelist, "disable ", 1, &cmdlist);
15617 add_com_alias ("dis", "disable", class_breakpoint, 1);
15618 add_com_alias ("disa", "disable", class_breakpoint, 1);
15620 add_com ("sb", class_breakpoint, disable_command, _("\
15621 Disable some breakpoints.\n\
15622 Arguments are breakpoint numbers with spaces in between.\n\
15623 To disable all breakpoints, give no argument.\n\
15624 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
15626 add_cmd ("breakpoints", class_alias, disable_command, _("\
15627 Disable some breakpoints.\n\
15628 Arguments are breakpoint numbers with spaces in between.\n\
15629 To disable all breakpoints, give no argument.\n\
15630 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
15631 This command may be abbreviated \"disable\"."),
15634 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
15635 Delete some breakpoints or auto-display expressions.\n\
15636 Arguments are breakpoint numbers with spaces in between.\n\
15637 To delete all breakpoints, give no argument.\n\
15639 Also a prefix command for deletion of other GDB objects.\n\
15640 The \"unset\" command is also an alias for \"delete\"."),
15641 &deletelist, "delete ", 1, &cmdlist);
15642 add_com_alias ("d", "delete", class_breakpoint, 1);
15643 add_com_alias ("del", "delete", class_breakpoint, 1);
15645 add_com ("db", class_breakpoint, delete_command, _("\
15646 Delete some breakpoints.\n\
15647 Arguments are breakpoint numbers with spaces in between.\n\
15648 To delete all breakpoints, give no argument.\n"));
15650 add_cmd ("breakpoints", class_alias, delete_command, _("\
15651 Delete some breakpoints or auto-display expressions.\n\
15652 Arguments are breakpoint numbers with spaces in between.\n\
15653 To delete all breakpoints, give no argument.\n\
15654 This command may be abbreviated \"delete\"."),
15657 add_com ("clear", class_breakpoint, clear_command, _("\
15658 Clear breakpoint at specified line or function.\n\
15659 Argument may be line number, function name, or \"*\" and an address.\n\
15660 If line number is specified, all breakpoints in that line are cleared.\n\
15661 If function is specified, breakpoints at beginning of function are cleared.\n\
15662 If an address is specified, breakpoints at that address are cleared.\n\
15664 With no argument, clears all breakpoints in the line that the selected frame\n\
15665 is executing in.\n\
15667 See also the \"delete\" command which clears breakpoints by number."));
15668 add_com_alias ("cl", "clear", class_breakpoint, 1);
15670 c = add_com ("break", class_breakpoint, break_command, _("\
15671 Set breakpoint at specified line or function.\n"
15672 BREAK_ARGS_HELP ("break")));
15673 set_cmd_completer (c, location_completer);
15675 add_com_alias ("b", "break", class_run, 1);
15676 add_com_alias ("br", "break", class_run, 1);
15677 add_com_alias ("bre", "break", class_run, 1);
15678 add_com_alias ("brea", "break", class_run, 1);
15681 add_com_alias ("ba", "break", class_breakpoint, 1);
15685 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
15686 Break in function/address or break at a line in the current file."),
15687 &stoplist, "stop ", 1, &cmdlist);
15688 add_cmd ("in", class_breakpoint, stopin_command,
15689 _("Break in function or address."), &stoplist);
15690 add_cmd ("at", class_breakpoint, stopat_command,
15691 _("Break at a line in the current file."), &stoplist);
15692 add_com ("status", class_info, breakpoints_info, _("\
15693 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15694 The \"Type\" column indicates one of:\n\
15695 \tbreakpoint - normal breakpoint\n\
15696 \twatchpoint - watchpoint\n\
15697 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15698 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15699 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15700 address and file/line number respectively.\n\
15702 Convenience variable \"$_\" and default examine address for \"x\"\n\
15703 are set to the address of the last breakpoint listed unless the command\n\
15704 is prefixed with \"server \".\n\n\
15705 Convenience variable \"$bpnum\" contains the number of the last\n\
15706 breakpoint set."));
15709 add_info ("breakpoints", breakpoints_info, _("\
15710 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
15711 The \"Type\" column indicates one of:\n\
15712 \tbreakpoint - normal breakpoint\n\
15713 \twatchpoint - watchpoint\n\
15714 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15715 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15716 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15717 address and file/line number respectively.\n\
15719 Convenience variable \"$_\" and default examine address for \"x\"\n\
15720 are set to the address of the last breakpoint listed unless the command\n\
15721 is prefixed with \"server \".\n\n\
15722 Convenience variable \"$bpnum\" contains the number of the last\n\
15723 breakpoint set."));
15725 add_info_alias ("b", "breakpoints", 1);
15728 add_com ("lb", class_breakpoint, breakpoints_info, _("\
15729 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15730 The \"Type\" column indicates one of:\n\
15731 \tbreakpoint - normal breakpoint\n\
15732 \twatchpoint - watchpoint\n\
15733 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15734 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15735 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15736 address and file/line number respectively.\n\
15738 Convenience variable \"$_\" and default examine address for \"x\"\n\
15739 are set to the address of the last breakpoint listed unless the command\n\
15740 is prefixed with \"server \".\n\n\
15741 Convenience variable \"$bpnum\" contains the number of the last\n\
15742 breakpoint set."));
15744 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
15745 Status of all breakpoints, or breakpoint number NUMBER.\n\
15746 The \"Type\" column indicates one of:\n\
15747 \tbreakpoint - normal breakpoint\n\
15748 \twatchpoint - watchpoint\n\
15749 \tlongjmp - internal breakpoint used to step through longjmp()\n\
15750 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
15751 \tuntil - internal breakpoint used by the \"until\" command\n\
15752 \tfinish - internal breakpoint used by the \"finish\" command\n\
15753 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15754 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15755 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15756 address and file/line number respectively.\n\
15758 Convenience variable \"$_\" and default examine address for \"x\"\n\
15759 are set to the address of the last breakpoint listed unless the command\n\
15760 is prefixed with \"server \".\n\n\
15761 Convenience variable \"$bpnum\" contains the number of the last\n\
15763 &maintenanceinfolist);
15765 add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\
15766 Set catchpoints to catch events."),
15767 &catch_cmdlist, "catch ",
15768 0/*allow-unknown*/, &cmdlist);
15770 add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\
15771 Set temporary catchpoints to catch events."),
15772 &tcatch_cmdlist, "tcatch ",
15773 0/*allow-unknown*/, &cmdlist);
15775 /* Add catch and tcatch sub-commands. */
15776 add_catch_command ("catch", _("\
15777 Catch an exception, when caught."),
15778 catch_catch_command,
15782 add_catch_command ("throw", _("\
15783 Catch an exception, when thrown."),
15784 catch_throw_command,
15788 add_catch_command ("fork", _("Catch calls to fork."),
15789 catch_fork_command_1,
15791 (void *) (uintptr_t) catch_fork_permanent,
15792 (void *) (uintptr_t) catch_fork_temporary);
15793 add_catch_command ("vfork", _("Catch calls to vfork."),
15794 catch_fork_command_1,
15796 (void *) (uintptr_t) catch_vfork_permanent,
15797 (void *) (uintptr_t) catch_vfork_temporary);
15798 add_catch_command ("exec", _("Catch calls to exec."),
15799 catch_exec_command_1,
15803 add_catch_command ("load", _("Catch loads of shared libraries.\n\
15804 Usage: catch load [REGEX]\n\
15805 If REGEX is given, only stop for libraries matching the regular expression."),
15806 catch_load_command_1,
15810 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
15811 Usage: catch unload [REGEX]\n\
15812 If REGEX is given, only stop for libraries matching the regular expression."),
15813 catch_unload_command_1,
15817 add_catch_command ("syscall", _("\
15818 Catch system calls by their names and/or numbers.\n\
15819 Arguments say which system calls to catch. If no arguments\n\
15820 are given, every system call will be caught.\n\
15821 Arguments, if given, should be one or more system call names\n\
15822 (if your system supports that), or system call numbers."),
15823 catch_syscall_command_1,
15824 catch_syscall_completer,
15828 c = add_com ("watch", class_breakpoint, watch_command, _("\
15829 Set a watchpoint for an expression.\n\
15830 Usage: watch [-l|-location] EXPRESSION\n\
15831 A watchpoint stops execution of your program whenever the value of\n\
15832 an expression changes.\n\
15833 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15834 the memory to which it refers."));
15835 set_cmd_completer (c, expression_completer);
15837 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
15838 Set a read watchpoint for an expression.\n\
15839 Usage: rwatch [-l|-location] EXPRESSION\n\
15840 A watchpoint stops execution of your program whenever the value of\n\
15841 an expression is read.\n\
15842 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15843 the memory to which it refers."));
15844 set_cmd_completer (c, expression_completer);
15846 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
15847 Set a watchpoint for an expression.\n\
15848 Usage: awatch [-l|-location] EXPRESSION\n\
15849 A watchpoint stops execution of your program whenever the value of\n\
15850 an expression is either read or written.\n\
15851 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15852 the memory to which it refers."));
15853 set_cmd_completer (c, expression_completer);
15855 add_info ("watchpoints", watchpoints_info, _("\
15856 Status of specified watchpoints (all watchpoints if no argument)."));
15858 /* XXX: cagney/2005-02-23: This should be a boolean, and should
15859 respond to changes - contrary to the description. */
15860 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
15861 &can_use_hw_watchpoints, _("\
15862 Set debugger's willingness to use watchpoint hardware."), _("\
15863 Show debugger's willingness to use watchpoint hardware."), _("\
15864 If zero, gdb will not use hardware for new watchpoints, even if\n\
15865 such is available. (However, any hardware watchpoints that were\n\
15866 created before setting this to nonzero, will continue to use watchpoint\n\
15869 show_can_use_hw_watchpoints,
15870 &setlist, &showlist);
15872 can_use_hw_watchpoints = 1;
15874 /* Tracepoint manipulation commands. */
15876 c = add_com ("trace", class_breakpoint, trace_command, _("\
15877 Set a tracepoint at specified line or function.\n\
15879 BREAK_ARGS_HELP ("trace") "\n\
15880 Do \"help tracepoints\" for info on other tracepoint commands."));
15881 set_cmd_completer (c, location_completer);
15883 add_com_alias ("tp", "trace", class_alias, 0);
15884 add_com_alias ("tr", "trace", class_alias, 1);
15885 add_com_alias ("tra", "trace", class_alias, 1);
15886 add_com_alias ("trac", "trace", class_alias, 1);
15888 c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\
15889 Set a fast tracepoint at specified line or function.\n\
15891 BREAK_ARGS_HELP ("ftrace") "\n\
15892 Do \"help tracepoints\" for info on other tracepoint commands."));
15893 set_cmd_completer (c, location_completer);
15895 c = add_com ("strace", class_breakpoint, strace_command, _("\
15896 Set a static tracepoint at specified line, function or marker.\n\
15898 strace [LOCATION] [if CONDITION]\n\
15899 LOCATION may be a line number, function name, \"*\" and an address,\n\
15900 or -m MARKER_ID.\n\
15901 If a line number is specified, probe the marker at start of code\n\
15902 for that line. If a function is specified, probe the marker at start\n\
15903 of code for that function. If an address is specified, probe the marker\n\
15904 at that exact address. If a marker id is specified, probe the marker\n\
15905 with that name. With no LOCATION, uses current execution address of\n\
15906 the selected stack frame.\n\
15907 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
15908 This collects arbitrary user data passed in the probe point call to the\n\
15909 tracing library. You can inspect it when analyzing the trace buffer,\n\
15910 by printing the $_sdata variable like any other convenience variable.\n\
15912 CONDITION is a boolean expression.\n\
15914 Multiple tracepoints at one place are permitted, and useful if their\n\
15915 conditions are different.\n\
15917 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
15918 Do \"help tracepoints\" for info on other tracepoint commands."));
15919 set_cmd_completer (c, location_completer);
15921 add_info ("tracepoints", tracepoints_info, _("\
15922 Status of specified tracepoints (all tracepoints if no argument).\n\
15923 Convenience variable \"$tpnum\" contains the number of the\n\
15924 last tracepoint set."));
15926 add_info_alias ("tp", "tracepoints", 1);
15928 add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
15929 Delete specified tracepoints.\n\
15930 Arguments are tracepoint numbers, separated by spaces.\n\
15931 No argument means delete all tracepoints."),
15934 c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
15935 Disable specified tracepoints.\n\
15936 Arguments are tracepoint numbers, separated by spaces.\n\
15937 No argument means disable all tracepoints."),
15939 deprecate_cmd (c, "disable");
15941 c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\
15942 Enable specified tracepoints.\n\
15943 Arguments are tracepoint numbers, separated by spaces.\n\
15944 No argument means enable all tracepoints."),
15946 deprecate_cmd (c, "enable");
15948 add_com ("passcount", class_trace, trace_pass_command, _("\
15949 Set the passcount for a tracepoint.\n\
15950 The trace will end when the tracepoint has been passed 'count' times.\n\
15951 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
15952 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
15954 add_prefix_cmd ("save", class_breakpoint, save_command,
15955 _("Save breakpoint definitions as a script."),
15956 &save_cmdlist, "save ",
15957 0/*allow-unknown*/, &cmdlist);
15959 c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\
15960 Save current breakpoint definitions as a script.\n\
15961 This includes all types of breakpoints (breakpoints, watchpoints,\n\
15962 catchpoints, tracepoints). Use the 'source' command in another debug\n\
15963 session to restore them."),
15965 set_cmd_completer (c, filename_completer);
15967 c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\
15968 Save current tracepoint definitions as a script.\n\
15969 Use the 'source' command in another debug session to restore them."),
15971 set_cmd_completer (c, filename_completer);
15973 c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0);
15974 deprecate_cmd (c, "save tracepoints");
15976 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
15977 Breakpoint specific settings\n\
15978 Configure various breakpoint-specific variables such as\n\
15979 pending breakpoint behavior"),
15980 &breakpoint_set_cmdlist, "set breakpoint ",
15981 0/*allow-unknown*/, &setlist);
15982 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
15983 Breakpoint specific settings\n\
15984 Configure various breakpoint-specific variables such as\n\
15985 pending breakpoint behavior"),
15986 &breakpoint_show_cmdlist, "show breakpoint ",
15987 0/*allow-unknown*/, &showlist);
15989 add_setshow_auto_boolean_cmd ("pending", no_class,
15990 &pending_break_support, _("\
15991 Set debugger's behavior regarding pending breakpoints."), _("\
15992 Show debugger's behavior regarding pending breakpoints."), _("\
15993 If on, an unrecognized breakpoint location will cause gdb to create a\n\
15994 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
15995 an error. If auto, an unrecognized breakpoint location results in a\n\
15996 user-query to see if a pending breakpoint should be created."),
15998 show_pending_break_support,
15999 &breakpoint_set_cmdlist,
16000 &breakpoint_show_cmdlist);
16002 pending_break_support = AUTO_BOOLEAN_AUTO;
16004 add_setshow_boolean_cmd ("auto-hw", no_class,
16005 &automatic_hardware_breakpoints, _("\
16006 Set automatic usage of hardware breakpoints."), _("\
16007 Show automatic usage of hardware breakpoints."), _("\
16008 If set, the debugger will automatically use hardware breakpoints for\n\
16009 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16010 a warning will be emitted for such breakpoints."),
16012 show_automatic_hardware_breakpoints,
16013 &breakpoint_set_cmdlist,
16014 &breakpoint_show_cmdlist);
16016 add_setshow_enum_cmd ("always-inserted", class_support,
16017 always_inserted_enums, &always_inserted_mode, _("\
16018 Set mode for inserting breakpoints."), _("\
16019 Show mode for inserting breakpoints."), _("\
16020 When this mode is off, breakpoints are inserted in inferior when it is\n\
16021 resumed, and removed when execution stops. When this mode is on,\n\
16022 breakpoints are inserted immediately and removed only when the user\n\
16023 deletes the breakpoint. When this mode is auto (which is the default),\n\
16024 the behaviour depends on the non-stop setting (see help set non-stop).\n\
16025 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
16026 behaves as if always-inserted mode is on; if gdb is controlling the\n\
16027 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
16029 &show_always_inserted_mode,
16030 &breakpoint_set_cmdlist,
16031 &breakpoint_show_cmdlist);
16033 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint,
16034 condition_evaluation_enums,
16035 &condition_evaluation_mode_1, _("\
16036 Set mode of breakpoint condition evaluation."), _("\
16037 Show mode of breakpoint condition evaluation."), _("\
16038 When this is set to \"host\", breakpoint conditions will be\n\
16039 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16040 breakpoint conditions will be downloaded to the target (if the target\n\
16041 supports such feature) and conditions will be evaluated on the target's side.\n\
16042 If this is set to \"auto\" (default), this will be automatically set to\n\
16043 \"target\" if it supports condition evaluation, otherwise it will\n\
16044 be set to \"gdb\""),
16045 &set_condition_evaluation_mode,
16046 &show_condition_evaluation_mode,
16047 &breakpoint_set_cmdlist,
16048 &breakpoint_show_cmdlist);
16050 add_com ("break-range", class_breakpoint, break_range_command, _("\
16051 Set a breakpoint for an address range.\n\
16052 break-range START-LOCATION, END-LOCATION\n\
16053 where START-LOCATION and END-LOCATION can be one of the following:\n\
16054 LINENUM, for that line in the current file,\n\
16055 FILE:LINENUM, for that line in that file,\n\
16056 +OFFSET, for that number of lines after the current line\n\
16057 or the start of the range\n\
16058 FUNCTION, for the first line in that function,\n\
16059 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16060 *ADDRESS, for the instruction at that address.\n\
16062 The breakpoint will stop execution of the inferior whenever it executes\n\
16063 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16064 range (including START-LOCATION and END-LOCATION)."));
16066 c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\
16067 Set a dynamic printf at specified line or function.\n\
16068 dprintf location,format string,arg1,arg2,...\n\
16069 location may be a line number, function name, or \"*\" and an address.\n\
16070 If a line number is specified, break at start of code for that line.\n\
16071 If a function is specified, break at start of code for that function.\n\
16073 set_cmd_completer (c, location_completer);
16075 add_setshow_enum_cmd ("dprintf-style", class_support,
16076 dprintf_style_enums, &dprintf_style, _("\
16077 Set the style of usage for dynamic printf."), _("\
16078 Show the style of usage for dynamic printf."), _("\
16079 This setting chooses how GDB will do a dynamic printf.\n\
16080 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16081 console, as with the \"printf\" command.\n\
16082 If the value is \"call\", the print is done by calling a function in your\n\
16083 program; by default printf(), but you can choose a different function or\n\
16084 output stream by setting dprintf-function and dprintf-channel."),
16085 update_dprintf_commands, NULL,
16086 &setlist, &showlist);
16088 dprintf_function = xstrdup ("printf");
16089 add_setshow_string_cmd ("dprintf-function", class_support,
16090 &dprintf_function, _("\
16091 Set the function to use for dynamic printf"), _("\
16092 Show the function to use for dynamic printf"), NULL,
16093 update_dprintf_commands, NULL,
16094 &setlist, &showlist);
16096 dprintf_channel = xstrdup ("");
16097 add_setshow_string_cmd ("dprintf-channel", class_support,
16098 &dprintf_channel, _("\
16099 Set the channel to use for dynamic printf"), _("\
16100 Show the channel to use for dynamic printf"), NULL,
16101 update_dprintf_commands, NULL,
16102 &setlist, &showlist);
16104 automatic_hardware_breakpoints = 1;
16106 observer_attach_about_to_proceed (breakpoint_about_to_proceed);